From eac0ffd257f804b773cd471271f02b646e1b157f Mon Sep 17 00:00:00 2001 From: Adrian Servy Date: Thu, 27 Sep 2012 04:42:12 +0300 Subject: [PATCH 001/882] Live authorization endpoints changed --- src/main/java/org/scribe/builder/api/LiveApi.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/scribe/builder/api/LiveApi.java b/src/main/java/org/scribe/builder/api/LiveApi.java index 18140f603..125b88048 100644 --- a/src/main/java/org/scribe/builder/api/LiveApi.java +++ b/src/main/java/org/scribe/builder/api/LiveApi.java @@ -7,13 +7,13 @@ public class LiveApi extends DefaultApi20 { - private static final String AUTHORIZE_URL = "https://oauth.live.com/authorize?client_id=%s&redirect_uri=%s&response_type=code"; + private static final String AUTHORIZE_URL = "https://login.live.com/oauth20_authorize.srf?client_id=%s&redirect_uri=%s&response_type=code"; private static final String SCOPED_AUTHORIZE_URL = AUTHORIZE_URL + "&scope=%s"; @Override public String getAccessTokenEndpoint() { - return "https://oauth.live.com/token?grant_type=authorization_code"; + return "https://login.live.com/oauth20_token.srf?grant_type=authorization_code"; } @Override From 7b4ebc3a728ef9614c2f2946d21664130c32a8df Mon Sep 17 00:00:00 2001 From: Matthias Miltz Date: Thu, 13 Dec 2012 11:59:42 +0100 Subject: [PATCH 002/882] added API for xing.com incl. example --- .../java/org/scribe/builder/api/XingApi.java | 27 +++++++++ .../java/org/scribe/examples/XingExample.java | 59 +++++++++++++++++++ 2 files changed, 86 insertions(+) create mode 100755 src/main/java/org/scribe/builder/api/XingApi.java create mode 100755 src/test/java/org/scribe/examples/XingExample.java diff --git a/src/main/java/org/scribe/builder/api/XingApi.java b/src/main/java/org/scribe/builder/api/XingApi.java new file mode 100755 index 000000000..ec8823e67 --- /dev/null +++ b/src/main/java/org/scribe/builder/api/XingApi.java @@ -0,0 +1,27 @@ +package org.scribe.builder.api; + +import org.scribe.model.*; + +public class XingApi extends DefaultApi10a +{ + private static final String AUTHORIZE_URL = "https://api.xing.com/v1/authorize?oauth_token=%s"; + + @Override + public String getAccessTokenEndpoint() + { + return "https://api.xing.com/v1/access_token"; + } + + @Override + public String getRequestTokenEndpoint() + { + return "https://api.xing.com/v1/request_token"; + } + + @Override + public String getAuthorizationUrl(Token requestToken) + { + return String.format(AUTHORIZE_URL, requestToken.getToken()); + } + +} diff --git a/src/test/java/org/scribe/examples/XingExample.java b/src/test/java/org/scribe/examples/XingExample.java new file mode 100755 index 000000000..93d7080c4 --- /dev/null +++ b/src/test/java/org/scribe/examples/XingExample.java @@ -0,0 +1,59 @@ +package org.scribe.examples; + +import java.util.Scanner; + +import org.scribe.builder.*; +import org.scribe.builder.api.*; +import org.scribe.model.*; +import org.scribe.oauth.*; + +public class XingExample +{ + private static final String PROTECTED_RESOURCE_URL = "https://api.xing.com/v1/users/me"; + + public static void main(String[] args) + { + OAuthService service = new ServiceBuilder() + .provider(XingApi.class) + .apiKey("097ccfd3ef25a1cb6d75") + .apiSecret("e43364b2afd5d92f2ec28951a75bd8075f9cc221") + .build(); + Scanner in = new Scanner(System.in); + + System.out.println("=== Xing's OAuth Workflow ==="); + System.out.println(); + + // Obtain the Request Token + System.out.println("Fetching the Request Token..."); + Token requestToken = service.getRequestToken(); + System.out.println("Got the Request Token!"); + System.out.println(); + + System.out.println("Now go and authorize Scribe here:"); + System.out.println(service.getAuthorizationUrl(requestToken)); + System.out.println("And paste the verifier here"); + System.out.print(">>"); + Verifier verifier = new Verifier(in.nextLine()); + System.out.println(); + + // Trade the Request Token and Verfier for the Access Token + System.out.println("Trading the Request Token for an Access Token..."); + Token accessToken = service.getAccessToken(requestToken, verifier); + System.out.println("Got the Access Token!"); + System.out.println("(if your curious it looks like this: " + accessToken + " )"); + System.out.println(); + + // Now let's go and ask for a protected resource! + System.out.println("Now we're going to access a protected resource..."); + OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); + service.signRequest(accessToken, request); + Response response = request.send(); + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getBody()); + + System.out.println(); + System.out.println("Thats it man! Go and build something awesome with Scribe! :)"); + } + +} From 877bcb7fa23edf30b755b2ce43821fb1c047ce5a Mon Sep 17 00:00:00 2001 From: Pablo Fernandez Date: Sat, 15 Dec 2012 23:13:18 -0300 Subject: [PATCH 003/882] bounce version numbers for release 1.3.3 --- README.textile | 2 +- changelog.txt | 1 + pom.xml | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/README.textile b/README.textile index a20bccaa7..392be1208 100644 --- a/README.textile +++ b/README.textile @@ -65,7 +65,7 @@ You can pull scribe from a maven repository, just add this to your __pom.xml__ f @@ @org.scribe@ @scribe@ - @1.3.2@ + @1.3.3@ @@ h1. Getting started in less than 2 minutes diff --git a/changelog.txt b/changelog.txt index 617567805..5423c6237 100644 --- a/changelog.txt +++ b/changelog.txt @@ -95,3 +95,4 @@ [1.3.3] * FEATURE: accessToken and requestToken timeouts default to 2 seconds and can be specified. + * FEATURE: New Apis. diff --git a/pom.xml b/pom.xml index dbee18cf6..1813aba24 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ org.scribe scribe jar - 1.3.2 + 1.3.3 Scribe OAuth Library The best OAuth library out there http://github.com/fernandezpablo85/scribe-java From 479bfe6a425bd4b66f018417c247d52cc91216b8 Mon Sep 17 00:00:00 2001 From: Pablo Fernandez Date: Tue, 25 Dec 2012 16:52:15 -0200 Subject: [PATCH 004/882] Update README.textile Remove my address from the readme hoping people will first dig a bit trough the docs instead of just sending email. --- README.textile | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.textile b/README.textile index 392be1208..ab7deab88 100644 --- a/README.textile +++ b/README.textile @@ -90,6 +90,4 @@ h1. About me "LinkedIn profile":http://www.linkedin.com/in/fernandezpablo85 -Email me: fernandezpablo85 at gmail.com - Follow me: "@fernandezpablo":http://twitter.com/fernandezpablo From 0359c853e2e248ab5b1422e436b37e3e1086fbb8 Mon Sep 17 00:00:00 2001 From: Darko Zelic Date: Thu, 7 Feb 2013 15:57:16 +0100 Subject: [PATCH 005/882] Added ViadeoApi and example --- .../org/scribe/builder/api/ViadeoApi.java | 42 ++++++++++++ .../org/scribe/examples/ViadeoExample.java | 64 +++++++++++++++++++ 2 files changed, 106 insertions(+) create mode 100644 src/main/java/org/scribe/builder/api/ViadeoApi.java create mode 100644 src/test/java/org/scribe/examples/ViadeoExample.java diff --git a/src/main/java/org/scribe/builder/api/ViadeoApi.java b/src/main/java/org/scribe/builder/api/ViadeoApi.java new file mode 100644 index 000000000..0f5e77e76 --- /dev/null +++ b/src/main/java/org/scribe/builder/api/ViadeoApi.java @@ -0,0 +1,42 @@ +package org.scribe.builder.api; + +import org.scribe.extractors.AccessTokenExtractor; +import org.scribe.model.OAuthConfig; +import org.scribe.utils.OAuthEncoder; +import org.scribe.utils.Preconditions; + +import org.scribe.extractors.JsonTokenExtractor; + +public class ViadeoApi extends DefaultApi20 +{ + private static final String AUTHORIZE_URL = "https://secure.viadeo.com/oauth-provider/authorize2?client_id=%s&redirect_uri=%s&response_type=code"; + private static final String SCOPED_AUTHORIZE_URL = AUTHORIZE_URL + "&scope=%s"; + + @Override + public AccessTokenExtractor getAccessTokenExtractor() + { + return new JsonTokenExtractor(); + } + + @Override + public String getAccessTokenEndpoint() + { + return "https://secure.viadeo.com/oauth-provider/access_token2?grant_type=authorization_code"; + } + + @Override + public String getAuthorizationUrl(OAuthConfig config) + { + Preconditions.checkValidUrl(config.getCallback(), "Must provide a valid url as callback. Viadeo does not support OOB"); + + // Append scope if present + if(config.hasScope()) + { + return String.format(SCOPED_AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()), OAuthEncoder.encode(config.getScope())); + } + else + { + return String.format(AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback())); + } + } +} diff --git a/src/test/java/org/scribe/examples/ViadeoExample.java b/src/test/java/org/scribe/examples/ViadeoExample.java new file mode 100644 index 000000000..ebb438532 --- /dev/null +++ b/src/test/java/org/scribe/examples/ViadeoExample.java @@ -0,0 +1,64 @@ +package org.scribe.examples; + +import java.util.*; + +import org.scribe.builder.*; +import org.scribe.builder.api.*; +import org.scribe.model.*; +import org.scribe.oauth.*; + +public class ViadeoExample +{ + private static final String NETWORK_NAME = "Viadeo"; + private static final String PROTECTED_RESOURCE_URL = "https://api.viadeo.com/me?user_detail=full"; + private static final Token EMPTY_TOKEN = null; + + public static void main(String[] args) + { + // Replace these with your own api key and secret + String apiKey = "your_app_id"; + String apiSecret = "your_api_secret"; + OAuthService service = new ServiceBuilder() + .provider(ViadeoApi.class) + .apiKey(apiKey) + .apiSecret(apiSecret) + .callback("http://www.example.com/oauth_callback/") + .build(); + 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..."); + String authorizationUrl = service.getAuthorizationUrl(EMPTY_TOKEN); + System.out.println("Got the Authorization URL!"); + System.out.println("Now go and authorize Scribe here:"); + System.out.println(authorizationUrl); + System.out.println("And paste the authorization code here"); + System.out.print(">>"); + Verifier verifier = new Verifier(in.nextLine()); + System.out.println(); + + // Trade the Request Token and Verfier for the Access Token + System.out.println("Trading the Request Token for an Access Token..."); + Token accessToken = service.getAccessToken(EMPTY_TOKEN, verifier); + System.out.println("Got the Access Token!"); + System.out.println("(if your curious it looks like this: " + accessToken + " )"); + System.out.println(); + + // Now let's go and ask for a protected resource! + System.out.println("Now we're going to access a protected resource..."); + OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); + service.signRequest(accessToken, request); + Response response = request.send(); + 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 Scribe! :)"); + + } +} From 0cb3301b8e07a54c7ff8bdd99961de421e6a49f2 Mon Sep 17 00:00:00 2001 From: Pablo Fernandez Date: Tue, 12 Feb 2013 18:54:43 -0300 Subject: [PATCH 006/882] add support for LinekdIn scopes --- .../org/scribe/builder/api/LinkedInApi.java | 34 ++++++++++- .../examples/LinkedInExampleWithScopes.java | 59 +++++++++++++++++++ 2 files changed, 91 insertions(+), 2 deletions(-) create mode 100644 src/test/java/org/scribe/examples/LinkedInExampleWithScopes.java diff --git a/src/main/java/org/scribe/builder/api/LinkedInApi.java b/src/main/java/org/scribe/builder/api/LinkedInApi.java index dc3e58327..a39bf70da 100644 --- a/src/main/java/org/scribe/builder/api/LinkedInApi.java +++ b/src/main/java/org/scribe/builder/api/LinkedInApi.java @@ -1,10 +1,24 @@ package org.scribe.builder.api; import org.scribe.model.*; +import java.util.*; public class LinkedInApi extends DefaultApi10a { private static final String AUTHORIZE_URL = "https://api.linkedin.com/uas/oauth/authenticate?oauth_token=%s"; + private static final String REQUEST_TOKEN_URL = "https://api.linkedin.com/uas/oauth/requestToken"; + + private final Set scopes; + + public LinkedInApi() + { + scopes = Collections.EMPTY_SET; + } + + public LinkedInApi(Set scopes) + { + this.scopes = Collections.unmodifiableSet(scopes); + } @Override public String getAccessTokenEndpoint() @@ -15,13 +29,29 @@ public String getAccessTokenEndpoint() @Override public String getRequestTokenEndpoint() { - return "https://api.linkedin.com/uas/oauth/requestToken"; + return scopes.isEmpty() ? REQUEST_TOKEN_URL : REQUEST_TOKEN_URL + "?scopes=" + scopesAsString(); } - + + private String scopesAsString() + { + StringBuilder builder = new StringBuilder(); + for(String scope : scopes) + { + builder.append("+" + scope); + } + return builder.substring(1); + } + @Override public String getAuthorizationUrl(Token requestToken) { return String.format(AUTHORIZE_URL, requestToken.getToken()); } + + public static LinkedInApi withScopes(String... scopes) + { + Set scopeSet = new HashSet(Arrays.asList(scopes)); + return new LinkedInApi(scopeSet); + } } diff --git a/src/test/java/org/scribe/examples/LinkedInExampleWithScopes.java b/src/test/java/org/scribe/examples/LinkedInExampleWithScopes.java new file mode 100644 index 000000000..b8e8b2881 --- /dev/null +++ b/src/test/java/org/scribe/examples/LinkedInExampleWithScopes.java @@ -0,0 +1,59 @@ +package org.scribe.examples; + +import java.util.Scanner; + +import org.scribe.builder.*; +import org.scribe.builder.api.*; +import org.scribe.model.*; +import org.scribe.oauth.*; + +public class LinkedInExampleWithScopes +{ + private static final String PROTECTED_RESOURCE_URL = "http://api.linkedin.com/v1/people/~/connections:(id,last-name)"; + + public static void main(String[] args) + { + OAuthService service = new ServiceBuilder() + .provider(LinkedInApi.withScopes("foo", "bar", "baz")) + .apiKey("CiEgwWDkA5BFpNrc0RfGyVuSlOh4tig5kOTZ9q97qcXNrFl7zqk-Ts7DqRGaKDCV") + .apiSecret("dhho4dfoCmiQXrkw4yslork5XWLFnPSuMR-8gscPVjY4jqFFHPYWJKgpFl4uLTM6") + .build(); + Scanner in = new Scanner(System.in); + + System.out.println("=== LinkedIn's OAuth Workflow ==="); + System.out.println(); + + // Obtain the Request Token + System.out.println("Fetching the Request Token..."); + Token requestToken = service.getRequestToken(); + System.out.println("Got the Request Token!"); + System.out.println(); + + System.out.println("Now go and authorize Scribe here:"); + System.out.println(service.getAuthorizationUrl(requestToken)); + System.out.println("And paste the verifier here"); + System.out.print(">>"); + Verifier verifier = new Verifier(in.nextLine()); + System.out.println(); + + // Trade the Request Token and Verfier for the Access Token + System.out.println("Trading the Request Token for an Access Token..."); + Token accessToken = service.getAccessToken(requestToken, verifier); + System.out.println("Got the Access Token!"); + System.out.println("(if your curious it looks like this: " + accessToken + " )"); + System.out.println(); + + // Now let's go and ask for a protected resource! + System.out.println("Now we're going to access a protected resource..."); + OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); + service.signRequest(accessToken, request); + Response response = request.send(); + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getBody()); + + System.out.println(); + System.out.println("Thats it man! Go and build something awesome with Scribe! :)"); + } + +} From 69eee25cacb270abe78ce1771694df5a68538c78 Mon Sep 17 00:00:00 2001 From: Pablo Fernandez Date: Wed, 13 Feb 2013 09:37:38 -0300 Subject: [PATCH 007/882] typo --- src/main/java/org/scribe/builder/api/LinkedInApi.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/scribe/builder/api/LinkedInApi.java b/src/main/java/org/scribe/builder/api/LinkedInApi.java index a39bf70da..a3dcc3d83 100644 --- a/src/main/java/org/scribe/builder/api/LinkedInApi.java +++ b/src/main/java/org/scribe/builder/api/LinkedInApi.java @@ -29,7 +29,7 @@ public String getAccessTokenEndpoint() @Override public String getRequestTokenEndpoint() { - return scopes.isEmpty() ? REQUEST_TOKEN_URL : REQUEST_TOKEN_URL + "?scopes=" + scopesAsString(); + return scopes.isEmpty() ? REQUEST_TOKEN_URL : REQUEST_TOKEN_URL + "?scope=" + scopesAsString(); } private String scopesAsString() From e0a13c80504cf052260b4ac6f64f9fbe53846edf Mon Sep 17 00:00:00 2001 From: Pablo Fernandez Date: Wed, 13 Feb 2013 14:03:20 -0300 Subject: [PATCH 008/882] added findbugs + maven task to check at compile time --- pom.xml | 23 +++++++++++++++++-- .../java/org/scribe/builder/api/PlurkApi.java | 2 +- .../extractors/HeaderExtractorImpl.java | 4 ++-- src/main/java/org/scribe/model/Request.java | 4 ++-- .../services/HMACSha1SignatureService.java | 2 +- .../services/RSASha1SignatureService.java | 5 ++-- .../scribe/services/TimestampServiceImpl.java | 3 ++- 7 files changed, 32 insertions(+), 11 deletions(-) diff --git a/pom.xml b/pom.xml index 1813aba24..1371ab52f 100644 --- a/pom.xml +++ b/pom.xml @@ -49,19 +49,20 @@ commons-codec 1.4 - + junit junit 4.8.1 test - + maven-compiler-plugin + 3.0 1.5 1.5 @@ -70,6 +71,7 @@ org.apache.maven.plugins maven-gpg-plugin + 1.4 sign-artifacts @@ -80,6 +82,23 @@ + + org.codehaus.mojo + findbugs-maven-plugin + 2.5.2 + + + failing-on-high + compile + + check + + + Low + + + + diff --git a/src/main/java/org/scribe/builder/api/PlurkApi.java b/src/main/java/org/scribe/builder/api/PlurkApi.java index 323ad2cf4..22b1ddb75 100644 --- a/src/main/java/org/scribe/builder/api/PlurkApi.java +++ b/src/main/java/org/scribe/builder/api/PlurkApi.java @@ -26,7 +26,7 @@ public String getAccessTokenEndpoint() return ACCESS_TOKEN_URL; } - public class Mobile extends PlurkApi + public static class Mobile extends PlurkApi { private static final String AUTHORIZATION_URL = "http://www.plurk.com/m/authorize?oauth_token=%s"; diff --git a/src/main/java/org/scribe/extractors/HeaderExtractorImpl.java b/src/main/java/org/scribe/extractors/HeaderExtractorImpl.java index 73c4ada35..460f23b2b 100644 --- a/src/main/java/org/scribe/extractors/HeaderExtractorImpl.java +++ b/src/main/java/org/scribe/extractors/HeaderExtractorImpl.java @@ -26,13 +26,13 @@ public String extract(OAuthRequest request) Map parameters = request.getOauthParameters(); StringBuffer header = new StringBuffer(parameters.size() * 20); header.append(PREAMBLE); - for (String key : parameters.keySet()) + for (Map.Entry entry : parameters.entrySet()) { if(header.length() > PREAMBLE.length()) { header.append(PARAM_SEPARATOR); } - header.append(String.format("%s=\"%s\"", key, OAuthEncoder.encode(parameters.get(key)))); + header.append(String.format("%s=\"%s\"", entry.getKey(), OAuthEncoder.encode(entry.getValue()))); } return header.toString(); } diff --git a/src/main/java/org/scribe/model/Request.java b/src/main/java/org/scribe/model/Request.java index b19e4a80d..e0cac2b01 100644 --- a/src/main/java/org/scribe/model/Request.java +++ b/src/main/java/org/scribe/model/Request.java @@ -4,7 +4,7 @@ import java.net.*; import java.nio.charset.*; import java.util.*; -import java.util.concurrent.TimeUnit; +import java.util.concurrent.*; import org.scribe.exceptions.*; @@ -189,7 +189,7 @@ public void addPayload(String payload) */ public void addPayload(byte[] payload) { - this.bytePayload = payload; + this.bytePayload = payload.clone(); } /** diff --git a/src/main/java/org/scribe/services/HMACSha1SignatureService.java b/src/main/java/org/scribe/services/HMACSha1SignatureService.java index cadda6812..34754ba45 100644 --- a/src/main/java/org/scribe/services/HMACSha1SignatureService.java +++ b/src/main/java/org/scribe/services/HMACSha1SignatureService.java @@ -44,7 +44,7 @@ private String doSign(String toSign, String keyString) throws Exception Mac mac = Mac.getInstance(HMAC_SHA1); mac.init(key); byte[] bytes = mac.doFinal(toSign.getBytes(UTF8)); - return new String(Base64.encodeBase64(bytes)).replace(CARRIAGE_RETURN, EMPTY_STRING); + return new String(Base64.encodeBase64(bytes), UTF8).replace(CARRIAGE_RETURN, EMPTY_STRING); } /** diff --git a/src/main/java/org/scribe/services/RSASha1SignatureService.java b/src/main/java/org/scribe/services/RSASha1SignatureService.java index 3b996f5c6..1622cc0d1 100644 --- a/src/main/java/org/scribe/services/RSASha1SignatureService.java +++ b/src/main/java/org/scribe/services/RSASha1SignatureService.java @@ -11,6 +11,7 @@ public class RSASha1SignatureService implements SignatureService { private static final String METHOD = "RSA-SHA1"; private static final String RSA_SHA1 = "SHA1withRSA"; + private static final String UTF8 = "UTF-8"; private PrivateKey privateKey; @@ -28,8 +29,8 @@ public String getSignature(String baseString, String apiSecret, String tokenSecr { Signature signature = Signature.getInstance(RSA_SHA1); signature.initSign(privateKey); - signature.update(baseString.getBytes()); - return new String(Base64.encodeBase64(signature.sign(), false)); + signature.update(baseString.getBytes(UTF8)); + return new String(Base64.encodeBase64(signature.sign(), false), UTF8); } catch (Exception e) { diff --git a/src/main/java/org/scribe/services/TimestampServiceImpl.java b/src/main/java/org/scribe/services/TimestampServiceImpl.java index 4aa27e026..486e93c64 100644 --- a/src/main/java/org/scribe/services/TimestampServiceImpl.java +++ b/src/main/java/org/scribe/services/TimestampServiceImpl.java @@ -53,6 +53,7 @@ void setTimer(Timer timer) */ static class Timer { + private final Random rand = new Random(); Long getMilis() { return System.currentTimeMillis(); @@ -60,7 +61,7 @@ Long getMilis() Integer getRandomInteger() { - return new Random().nextInt(); + return rand.nextInt(); } } From 28cd1740c1874627b58fe99f126a7cfb3d729a05 Mon Sep 17 00:00:00 2001 From: Pablo Fernandez Date: Thu, 14 Feb 2013 10:30:29 -0300 Subject: [PATCH 009/882] make constructors private since these classes aren't meant for creating instances --- src/main/java/org/scribe/model/OAuthConstants.java | 2 ++ src/main/java/org/scribe/utils/MapUtils.java | 2 ++ src/main/java/org/scribe/utils/OAuthEncoder.java | 2 ++ src/main/java/org/scribe/utils/Preconditions.java | 2 ++ src/main/java/org/scribe/utils/StreamUtils.java | 2 ++ 5 files changed, 10 insertions(+) diff --git a/src/main/java/org/scribe/model/OAuthConstants.java b/src/main/java/org/scribe/model/OAuthConstants.java index c93c31c71..1719c54d5 100644 --- a/src/main/java/org/scribe/model/OAuthConstants.java +++ b/src/main/java/org/scribe/model/OAuthConstants.java @@ -22,6 +22,8 @@ */ public class OAuthConstants { + private OAuthConstants(){} + public static final String TIMESTAMP = "oauth_timestamp"; public static final String SIGN_METHOD = "oauth_signature_method"; public static final String SIGNATURE = "oauth_signature"; diff --git a/src/main/java/org/scribe/utils/MapUtils.java b/src/main/java/org/scribe/utils/MapUtils.java index 9e461b803..ee09d16b3 100644 --- a/src/main/java/org/scribe/utils/MapUtils.java +++ b/src/main/java/org/scribe/utils/MapUtils.java @@ -7,6 +7,8 @@ */ public class MapUtils { + private MapUtils(){} + public static String toString(Map map) { if (map == null) return ""; diff --git a/src/main/java/org/scribe/utils/OAuthEncoder.java b/src/main/java/org/scribe/utils/OAuthEncoder.java index 10beabd4f..7fdbc84cc 100644 --- a/src/main/java/org/scribe/utils/OAuthEncoder.java +++ b/src/main/java/org/scribe/utils/OAuthEncoder.java @@ -23,6 +23,8 @@ public class OAuthEncoder ENCODING_RULES = Collections.unmodifiableMap(rules); } + private OAuthEncoder(){} + public static String encode(String plain) { Preconditions.checkNotNull(plain, "Cannot encode null object"); diff --git a/src/main/java/org/scribe/utils/Preconditions.java b/src/main/java/org/scribe/utils/Preconditions.java index 0ac134e3c..d4dd1be8c 100644 --- a/src/main/java/org/scribe/utils/Preconditions.java +++ b/src/main/java/org/scribe/utils/Preconditions.java @@ -16,6 +16,8 @@ public class Preconditions // scheme = alpha *( alpha | digit | "+" | "-" | "." ) private static final Pattern URL_PATTERN = Pattern.compile("^[a-zA-Z][a-zA-Z0-9+.-]*://\\S+"); + private Preconditions(){} + /** * Checks that an object is not null. * diff --git a/src/main/java/org/scribe/utils/StreamUtils.java b/src/main/java/org/scribe/utils/StreamUtils.java index 0799b9c1e..30dd8bc54 100644 --- a/src/main/java/org/scribe/utils/StreamUtils.java +++ b/src/main/java/org/scribe/utils/StreamUtils.java @@ -9,6 +9,8 @@ */ public class StreamUtils { + private StreamUtils(){} + /** * Returns the stream contents as an UTF-8 encoded string * From 045914d2c0b1a049509fd9ddcdc77efff075985a Mon Sep 17 00:00:00 2001 From: Pablo Fernandez Date: Thu, 14 Feb 2013 10:41:32 -0300 Subject: [PATCH 010/882] minor fixes --- src/main/java/org/scribe/extractors/HeaderExtractorImpl.java | 3 ++- src/main/java/org/scribe/model/Parameter.java | 5 +---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/scribe/extractors/HeaderExtractorImpl.java b/src/main/java/org/scribe/extractors/HeaderExtractorImpl.java index 460f23b2b..02094693f 100644 --- a/src/main/java/org/scribe/extractors/HeaderExtractorImpl.java +++ b/src/main/java/org/scribe/extractors/HeaderExtractorImpl.java @@ -16,6 +16,7 @@ public class HeaderExtractorImpl implements HeaderExtractor { private static final String PARAM_SEPARATOR = ", "; private static final String PREAMBLE = "OAuth "; + public static final int ESTIMATED_PARAM_LENGTH = 20; /** * {@inheritDoc} @@ -24,7 +25,7 @@ public String extract(OAuthRequest request) { checkPreconditions(request); Map parameters = request.getOauthParameters(); - StringBuffer header = new StringBuffer(parameters.size() * 20); + StringBuilder header = new StringBuilder(parameters.size() * ESTIMATED_PARAM_LENGTH); header.append(PREAMBLE); for (Map.Entry entry : parameters.entrySet()) { diff --git a/src/main/java/org/scribe/model/Parameter.java b/src/main/java/org/scribe/model/Parameter.java index 9fe610b43..f8f3b81f6 100644 --- a/src/main/java/org/scribe/model/Parameter.java +++ b/src/main/java/org/scribe/model/Parameter.java @@ -1,9 +1,6 @@ package org.scribe.model; -import java.io.UnsupportedEncodingException; -import java.net.URLEncoder; -import org.scribe.exceptions.OAuthException; -import org.scribe.utils.OAuthEncoder; +import org.scribe.utils.*; /** * @author: Pablo Fernandez From b3d83739980aa214bd93ed6c1a6a7ce4a4ce4077 Mon Sep 17 00:00:00 2001 From: Pablo Fernandez Date: Wed, 20 Feb 2013 12:56:03 -0300 Subject: [PATCH 011/882] removed apache commons dependencies since there is a way to base64-encode an array of bytes in the JDK (though it's hidden) --- pom.xml | 5 ----- .../org/scribe/services/HMACSha1SignatureService.java | 11 +++++++++-- .../org/scribe/services/RSASha1SignatureService.java | 11 +++++++++-- .../scribe/services/RSASha1SignatureServiceTest.java | 5 +++-- 4 files changed, 21 insertions(+), 11 deletions(-) diff --git a/pom.xml b/pom.xml index 1371ab52f..3e9e5ce2c 100644 --- a/pom.xml +++ b/pom.xml @@ -44,11 +44,6 @@ - - commons-codec - commons-codec - 1.4 - junit diff --git a/src/main/java/org/scribe/services/HMACSha1SignatureService.java b/src/main/java/org/scribe/services/HMACSha1SignatureService.java index 34754ba45..7068eb53d 100644 --- a/src/main/java/org/scribe/services/HMACSha1SignatureService.java +++ b/src/main/java/org/scribe/services/HMACSha1SignatureService.java @@ -3,10 +3,12 @@ import javax.crypto.*; import javax.crypto.spec.*; -import org.apache.commons.codec.binary.*; import org.scribe.exceptions.*; import org.scribe.utils.*; +// implementation of base64 encoding lives here. +import javax.xml.bind.DatatypeConverter; + /** * HMAC-SHA1 implementation of {@SignatureService} * @@ -44,7 +46,12 @@ private String doSign(String toSign, String keyString) throws Exception Mac mac = Mac.getInstance(HMAC_SHA1); mac.init(key); byte[] bytes = mac.doFinal(toSign.getBytes(UTF8)); - return new String(Base64.encodeBase64(bytes), UTF8).replace(CARRIAGE_RETURN, EMPTY_STRING); + return bytesToBase64String(bytes).replace(CARRIAGE_RETURN, EMPTY_STRING); + } + + private String bytesToBase64String(byte[] bytes) + { + return DatatypeConverter.printBase64Binary(bytes); } /** diff --git a/src/main/java/org/scribe/services/RSASha1SignatureService.java b/src/main/java/org/scribe/services/RSASha1SignatureService.java index 1622cc0d1..6f4c25d57 100644 --- a/src/main/java/org/scribe/services/RSASha1SignatureService.java +++ b/src/main/java/org/scribe/services/RSASha1SignatureService.java @@ -1,9 +1,11 @@ package org.scribe.services; -import org.apache.commons.codec.binary.*; import org.scribe.exceptions.*; import java.security.*; +// implementation of base64 encoding lives here. +import javax.xml.bind.DatatypeConverter; + /** * A signature service that uses the RSA-SHA1 algorithm. */ @@ -30,7 +32,7 @@ public String getSignature(String baseString, String apiSecret, String tokenSecr Signature signature = Signature.getInstance(RSA_SHA1); signature.initSign(privateKey); signature.update(baseString.getBytes(UTF8)); - return new String(Base64.encodeBase64(signature.sign(), false), UTF8); + return bytesToBase64String(signature); } catch (Exception e) { @@ -38,6 +40,11 @@ public String getSignature(String baseString, String apiSecret, String tokenSecr } } + private String bytesToBase64String(Signature signature) throws SignatureException + { + return DatatypeConverter.printBase64Binary(signature.sign()); + } + /** * {@inheritDoc} */ diff --git a/src/test/java/org/scribe/services/RSASha1SignatureServiceTest.java b/src/test/java/org/scribe/services/RSASha1SignatureServiceTest.java index 9e375c5be..2e78e8492 100644 --- a/src/test/java/org/scribe/services/RSASha1SignatureServiceTest.java +++ b/src/test/java/org/scribe/services/RSASha1SignatureServiceTest.java @@ -3,7 +3,8 @@ import static org.junit.Assert.*; import org.junit.*; -import org.apache.commons.codec.binary.*; + +import javax.xml.bind.DatatypeConverter; import java.security.*; import java.security.spec.*; @@ -55,7 +56,7 @@ private static PrivateKey getPrivateKey() try { KeyFactory fac = KeyFactory.getInstance("RSA"); - PKCS8EncodedKeySpec privKeySpec = new PKCS8EncodedKeySpec(Base64.decodeBase64(str.getBytes())); + PKCS8EncodedKeySpec privKeySpec = new PKCS8EncodedKeySpec(DatatypeConverter.parseBase64Binary(str)); return fac.generatePrivate(privKeySpec); } catch (Exception e) From b85ca334ccda499ca7f7f02f0555c8f4a107151d Mon Sep 17 00:00:00 2001 From: Pablo Fernandez Date: Wed, 20 Feb 2013 13:05:55 -0300 Subject: [PATCH 012/882] remove generic warning --- src/main/java/org/scribe/builder/api/LinkedInApi.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/scribe/builder/api/LinkedInApi.java b/src/main/java/org/scribe/builder/api/LinkedInApi.java index a3dcc3d83..ee6becd85 100644 --- a/src/main/java/org/scribe/builder/api/LinkedInApi.java +++ b/src/main/java/org/scribe/builder/api/LinkedInApi.java @@ -12,7 +12,7 @@ public class LinkedInApi extends DefaultApi10a public LinkedInApi() { - scopes = Collections.EMPTY_SET; + scopes = Collections.emptySet(); } public LinkedInApi(Set scopes) From e7f578deafc49cfef39cc7df365291ce7517c76c Mon Sep 17 00:00:00 2001 From: Pablo Fernandez Date: Wed, 20 Feb 2013 13:07:42 -0300 Subject: [PATCH 013/882] version bump for release --- README.textile | 2 +- pom.xml | 8 +------- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/README.textile b/README.textile index ab7deab88..cd676f6dc 100644 --- a/README.textile +++ b/README.textile @@ -65,7 +65,7 @@ You can pull scribe from a maven repository, just add this to your __pom.xml__ f @@ @org.scribe@ @scribe@ - @1.3.3@ + @1.3.4@ @@ h1. Getting started in less than 2 minutes diff --git a/pom.xml b/pom.xml index 3e9e5ce2c..120856bcb 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ org.scribe scribe jar - 1.3.3 + 1.3.4 Scribe OAuth Library The best OAuth library out there http://github.com/fernandezpablo85/scribe-java @@ -22,12 +22,6 @@ fernandezpablo85@gmail.com -3 - - diegossilveira - Diego Silveira - diegossilveira@gmail.com - -3 - From 6eb9208064630014ca2a99cfb30d89a06661ed89 Mon Sep 17 00:00:00 2001 From: stevee Date: Fri, 22 Feb 2013 11:04:35 -0500 Subject: [PATCH 014/882] Create an AWeber example. --- .../org/scribe/builder/api/AWeberApi.java | 28 ++++++++ .../org/scribe/examples/AWeberExample.java | 65 +++++++++++++++++++ 2 files changed, 93 insertions(+) create mode 100644 src/main/java/org/scribe/builder/api/AWeberApi.java create mode 100644 src/test/java/org/scribe/examples/AWeberExample.java diff --git a/src/main/java/org/scribe/builder/api/AWeberApi.java b/src/main/java/org/scribe/builder/api/AWeberApi.java new file mode 100644 index 000000000..53ae1fc7f --- /dev/null +++ b/src/main/java/org/scribe/builder/api/AWeberApi.java @@ -0,0 +1,28 @@ +package org.scribe.builder.api; + +import org.scribe.model.Token; + +public class AWeberApi extends DefaultApi10a +{ + private static final String AUTHORIZE_URL = "https://auth.aweber.com/1.0/oauth/authorize?oauth_token=%s"; + private static final String REQUEST_TOKEN_ENDPOINT = "https://auth.aweber.com/1.0/oauth/request_token"; + private static final String ACCESS_TOKEN_ENDPOINT = "https://auth.aweber.com/1.0/oauth/access_token"; + + @Override + public String getAccessTokenEndpoint() + { + return ACCESS_TOKEN_ENDPOINT; + } + + @Override + public String getRequestTokenEndpoint() + { + return REQUEST_TOKEN_ENDPOINT; + } + + @Override + public String getAuthorizationUrl(Token requestToken) + { + return String.format(AUTHORIZE_URL, requestToken.getToken()); + } +} diff --git a/src/test/java/org/scribe/examples/AWeberExample.java b/src/test/java/org/scribe/examples/AWeberExample.java new file mode 100644 index 000000000..2d86d6130 --- /dev/null +++ b/src/test/java/org/scribe/examples/AWeberExample.java @@ -0,0 +1,65 @@ +package org.scribe.examples; + +import java.util.Scanner; + +import org.scribe.builder.*; +import org.scribe.builder.api.*; +import org.scribe.model.*; +import org.scribe.oauth.*; + +public class AWeberExample +{ + + //To get your consumer key/secret, and view API docs, see https://labs.aweber.com/docs + private static final String ACCOUNT_RESOURCE_URL = "https://api.aweber.com/1.0/accounts/"; + + private static final String CONSUMER_KEY = ""; + private static final String CONSUMER_SECRET = ""; + + public static void main(String[] args) + { + OAuthService service = new ServiceBuilder() + .provider(AWeberApi.class) + .apiKey(CONSUMER_KEY) + .apiSecret(CONSUMER_SECRET) + .build(); + + Scanner in = new Scanner(System.in); + + System.out.println("=== AWeber's OAuth Workflow ==="); + System.out.println(); + + // Obtain the Request Token + System.out.println("Fetching the Request Token..."); + Token requestToken = service.getRequestToken(); + System.out.println("Got the Request Token!"); + System.out.println(); + + System.out.println("Now go and authorize Scribe here:"); + System.out.println(service.getAuthorizationUrl(requestToken)); + System.out.println("And paste the verifier here"); + System.out.print(">>"); + Verifier verifier = new Verifier(in.nextLine()); + System.out.println(); + + // Trade the Request Token and Verfier for the Access Token + System.out.println("Trading the Request Token for an Access Token..."); + Token accessToken = service.getAccessToken(requestToken, verifier); + System.out.println("Got the Access Token!"); + System.out.println("(if your curious it looks like this: " + accessToken + " )"); + System.out.println(); + + // Now let's go and ask for a protected resource! + System.out.println("Now we're going to access a protected resource..."); + OAuthRequest request = new OAuthRequest(Verb.GET, ACCOUNT_RESOURCE_URL); + service.signRequest(accessToken, request); + Response response = request.send(); + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getBody()); + + System.out.println(); + System.out.println("Thats it man! Go and build something awesome with AWeber and Scribe! :)"); + } + +} \ No newline at end of file From 86f12eb5bcc1059833c0b8b19d5eb0c2a1726eaa Mon Sep 17 00:00:00 2001 From: Pablo Fernandez Date: Thu, 28 Feb 2013 20:08:28 -0300 Subject: [PATCH 015/882] added optional commons-codec dependency there are some platforms (e.g. android) that do not have by default the java.xml.bind package. The solution is to use the commons-codec implementation if it's on the classpath and fallback to java.xml.bind --- pom.xml | 9 +++- .../org/scribe/oauth/OAuth10aServiceImpl.java | 2 + .../org/scribe/services/Base64Encoder.java | 36 ++++++++++++++++ .../org/scribe/services/CommonsEncoder.java | 42 +++++++++++++++++++ .../services/DatatypeConverterEncoder.java | 18 ++++++++ .../services/HMACSha1SignatureService.java | 5 +-- .../services/RSASha1SignatureService.java | 5 +-- 7 files changed, 107 insertions(+), 10 deletions(-) create mode 100644 src/main/java/org/scribe/services/Base64Encoder.java create mode 100644 src/main/java/org/scribe/services/CommonsEncoder.java create mode 100644 src/main/java/org/scribe/services/DatatypeConverterEncoder.java diff --git a/pom.xml b/pom.xml index 120856bcb..7418220ef 100644 --- a/pom.xml +++ b/pom.xml @@ -38,14 +38,19 @@ - junit junit 4.8.1 test - + + commons-codec + commons-codec + 1.4 + compile + true + diff --git a/src/main/java/org/scribe/oauth/OAuth10aServiceImpl.java b/src/main/java/org/scribe/oauth/OAuth10aServiceImpl.java index ff5b5d642..abde25399 100644 --- a/src/main/java/org/scribe/oauth/OAuth10aServiceImpl.java +++ b/src/main/java/org/scribe/oauth/OAuth10aServiceImpl.java @@ -4,6 +4,7 @@ import org.scribe.builder.api.*; import org.scribe.model.*; +import org.scribe.services.*; import org.scribe.utils.*; import java.util.concurrent.TimeUnit; @@ -139,6 +140,7 @@ public String getAuthorizationUrl(Token requestToken) private String getSignature(OAuthRequest request, Token token) { config.log("generating signature..."); + config.log("using base64 encoder: " + Base64Encoder.type()); String baseString = api.getBaseStringExtractor().extract(request); String signature = api.getSignatureService().getSignature(baseString, config.getApiSecret(), token.getSecret()); diff --git a/src/main/java/org/scribe/services/Base64Encoder.java b/src/main/java/org/scribe/services/Base64Encoder.java new file mode 100644 index 000000000..4a091c176 --- /dev/null +++ b/src/main/java/org/scribe/services/Base64Encoder.java @@ -0,0 +1,36 @@ +package org.scribe.services; + +public abstract class Base64Encoder +{ + private static Base64Encoder instance; + + public static synchronized Base64Encoder getInstance() + { + if (instance == null) + { + instance = createEncoderInstance(); + } + return instance; + } + + private static Base64Encoder createEncoderInstance() + { + if (CommonsEncoder.isPresent()) + { + return new CommonsEncoder(); + } + else + { + return new DatatypeConverterEncoder(); + } + } + + public static String type() + { + return getInstance().getType(); + } + + public abstract String encode(byte[] bytes); + + public abstract String getType(); +} diff --git a/src/main/java/org/scribe/services/CommonsEncoder.java b/src/main/java/org/scribe/services/CommonsEncoder.java new file mode 100644 index 000000000..4269a69cc --- /dev/null +++ b/src/main/java/org/scribe/services/CommonsEncoder.java @@ -0,0 +1,42 @@ +package org.scribe.services; + +import org.apache.commons.codec.binary.*; +import org.scribe.exceptions.*; + +import java.io.UnsupportedEncodingException; + +public class CommonsEncoder extends Base64Encoder +{ + + @Override + public String encode(byte[] bytes) + { + try + { + return new String(Base64.encodeBase64(bytes), "UTF-8"); + } + catch (UnsupportedEncodingException e) + { + throw new OAuthSignatureException("Can't perform base64 encoding", e); + } + } + + @Override + public String getType() + { + return "CommonsCodec"; + } + + public static boolean isPresent() + { + try + { + Class.forName("org.apache.commons.codec.binary.Base64"); + return true; + } + catch (ClassNotFoundException e) + { + return false; + } + } +} diff --git a/src/main/java/org/scribe/services/DatatypeConverterEncoder.java b/src/main/java/org/scribe/services/DatatypeConverterEncoder.java new file mode 100644 index 000000000..d147eba50 --- /dev/null +++ b/src/main/java/org/scribe/services/DatatypeConverterEncoder.java @@ -0,0 +1,18 @@ +package org.scribe.services; + +import javax.xml.bind.*; + +public class DatatypeConverterEncoder extends Base64Encoder +{ + @Override + public String encode(byte[] bytes) + { + return DatatypeConverter.printBase64Binary(bytes); + } + + @Override + public String getType() + { + return "DatatypeConverter"; + } +} diff --git a/src/main/java/org/scribe/services/HMACSha1SignatureService.java b/src/main/java/org/scribe/services/HMACSha1SignatureService.java index 7068eb53d..560c2e676 100644 --- a/src/main/java/org/scribe/services/HMACSha1SignatureService.java +++ b/src/main/java/org/scribe/services/HMACSha1SignatureService.java @@ -6,9 +6,6 @@ import org.scribe.exceptions.*; import org.scribe.utils.*; -// implementation of base64 encoding lives here. -import javax.xml.bind.DatatypeConverter; - /** * HMAC-SHA1 implementation of {@SignatureService} * @@ -51,7 +48,7 @@ private String doSign(String toSign, String keyString) throws Exception private String bytesToBase64String(byte[] bytes) { - return DatatypeConverter.printBase64Binary(bytes); + return Base64Encoder.getInstance().encode(bytes); } /** diff --git a/src/main/java/org/scribe/services/RSASha1SignatureService.java b/src/main/java/org/scribe/services/RSASha1SignatureService.java index 6f4c25d57..c427611fb 100644 --- a/src/main/java/org/scribe/services/RSASha1SignatureService.java +++ b/src/main/java/org/scribe/services/RSASha1SignatureService.java @@ -3,9 +3,6 @@ import org.scribe.exceptions.*; import java.security.*; -// implementation of base64 encoding lives here. -import javax.xml.bind.DatatypeConverter; - /** * A signature service that uses the RSA-SHA1 algorithm. */ @@ -42,7 +39,7 @@ public String getSignature(String baseString, String apiSecret, String tokenSecr private String bytesToBase64String(Signature signature) throws SignatureException { - return DatatypeConverter.printBase64Binary(signature.sign()); + return Base64Encoder.getInstance().encode(signature.sign()); } /** From 9b6a5ec1a82a65a563fc940f36d44d4d40c1b00d Mon Sep 17 00:00:00 2001 From: Daan de Wit Date: Fri, 1 Mar 2013 13:30:04 +0100 Subject: [PATCH 016/882] make status message available on response --- src/main/java/org/scribe/model/Response.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/main/java/org/scribe/model/Response.java b/src/main/java/org/scribe/model/Response.java index 9835a05a6..d433922c6 100644 --- a/src/main/java/org/scribe/model/Response.java +++ b/src/main/java/org/scribe/model/Response.java @@ -17,6 +17,7 @@ public class Response private static final String EMPTY = ""; private int code; + private String message; private String body; private InputStream stream; private Map headers; @@ -27,6 +28,7 @@ public class Response { connection.connect(); code = connection.getResponseCode(); + message = connection.getResponseMessage(); headers = parseHeaders(connection); stream = isSuccessful() ? connection.getInputStream() : connection.getErrorStream(); } @@ -87,6 +89,17 @@ public int getCode() { return code; } + + /** + * Obtains the HTTP status message. + * Returns null if the message can not be discerned from the response (not valid HTTP) + * + * @return the status message + */ + public String getMessage() + { + return message; + } /** * Obtains a {@link Map} containing the HTTP Response Headers From a4851d8d9f6845b43d94f1ac4528ae63e3385fd8 Mon Sep 17 00:00:00 2001 From: Justin Plock Date: Wed, 5 Jun 2013 08:34:35 -0400 Subject: [PATCH 017/882] Added setFollowRedirects() method to Request object to handle following HTTP redirects or not --- src/main/java/org/scribe/model/Request.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/main/java/org/scribe/model/Request.java b/src/main/java/org/scribe/model/Request.java index e0cac2b01..0202db0a2 100644 --- a/src/main/java/org/scribe/model/Request.java +++ b/src/main/java/org/scribe/model/Request.java @@ -32,6 +32,7 @@ public class Request private String charset; private byte[] bytePayload = null; private boolean connectionKeepAlive = false; + private boolean followRedirects = true; private Long connectTimeout = null; private Long readTimeout = null; @@ -82,6 +83,7 @@ private void createConnection() throws IOException { System.setProperty("http.keepAlive", connectionKeepAlive ? "true" : "false"); connection = (HttpURLConnection) new URL(completeUrl).openConnection(); + connection.setInstanceFollowRedirects(followRedirects); } } @@ -351,6 +353,19 @@ public void setConnectionKeepAlive(boolean connectionKeepAlive) this.connectionKeepAlive = connectionKeepAlive; } + /** + * Sets whether the underlying Http Connection follows redirects or not. + * + * Defaults to true (follow redirects) + * + * @see http://docs.oracle.com/javase/6/docs/api/java/net/HttpURLConnection.html#setInstanceFollowRedirects(boolean) + * @param followRedirects + */ + public void setFollowRedirects(boolean followRedirects) + { + this.followRedirects = followRedirects; + } + /* * We need this in order to stub the connection object for test cases */ From 53fd69aa9e855de9f7061fbfdb039268632051e7 Mon Sep 17 00:00:00 2001 From: Pablo Fernandez Date: Thu, 20 Jun 2013 17:42:48 -0300 Subject: [PATCH 018/882] Update README.textile --- README.textile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.textile b/README.textile index cd676f6dc..e1aea3ab0 100644 --- a/README.textile +++ b/README.textile @@ -2,6 +2,8 @@ h2. Welcome to the home of Scribe, the simple OAuth Java lib! !https://secure.travis-ci.org/fernandezpablo85/scribe-java.png?branch=master(travis-ci-status)! +h2. Before submitting a pull request "please read this":https://github.com/fernandezpablo85/scribe-java/wiki/Scribe-scope-revised + h1. Why use Scribe? h3. Dead Simple From cafa2fd69f70bfbf81324c83528b196ca7c14998 Mon Sep 17 00:00:00 2001 From: Pablo Fernandez Date: Sat, 22 Jun 2013 19:06:01 -0300 Subject: [PATCH 019/882] version bump for release --- README.textile | 2 +- pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.textile b/README.textile index e1aea3ab0..e1726c94f 100644 --- a/README.textile +++ b/README.textile @@ -67,7 +67,7 @@ You can pull scribe from a maven repository, just add this to your __pom.xml__ f @@ @org.scribe@ @scribe@ - @1.3.4@ + @1.3.5@ @@ h1. Getting started in less than 2 minutes diff --git a/pom.xml b/pom.xml index 7418220ef..a276ae1bb 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ org.scribe scribe jar - 1.3.4 + 1.3.5 Scribe OAuth Library The best OAuth library out there http://github.com/fernandezpablo85/scribe-java From f661af08c016f710329040c677710b0a96385ed3 Mon Sep 17 00:00:00 2001 From: denis Date: Fri, 23 Aug 2013 17:20:19 +0200 Subject: [PATCH 020/882] Changing the Twitter URL corresponding with the 1.1 API --- src/test/java/org/scribe/examples/TwitterExample.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/test/java/org/scribe/examples/TwitterExample.java b/src/test/java/org/scribe/examples/TwitterExample.java index 28d9bea54..b68aee087 100644 --- a/src/test/java/org/scribe/examples/TwitterExample.java +++ b/src/test/java/org/scribe/examples/TwitterExample.java @@ -9,10 +9,11 @@ public class TwitterExample { - private static final String PROTECTED_RESOURCE_URL = "https://api.twitter.com/1/statuses/update.json"; + private static final String PROTECTED_RESOURCE_URL = "http://api.twitter.com/1.1/account/verify_credentials.json"; public static void main(String[] args) { + // If you choose to use a callback, "oauth_verifier" will be the return value by Twitter (request param) OAuthService service = new ServiceBuilder() .provider(TwitterApi.class) .apiKey("6icbcAXyZx67r8uTAUM5Qw") From 0fe6578ad7200365116953a06001e3a1a659be2a Mon Sep 17 00:00:00 2001 From: Fabien Vauchelles Date: Fri, 22 Nov 2013 12:10:03 +0100 Subject: [PATCH 021/882] added TumblrExample --- .../org/scribe/examples/TumblrExample.java | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 src/test/java/org/scribe/examples/TumblrExample.java diff --git a/src/test/java/org/scribe/examples/TumblrExample.java b/src/test/java/org/scribe/examples/TumblrExample.java new file mode 100644 index 000000000..d024efbc0 --- /dev/null +++ b/src/test/java/org/scribe/examples/TumblrExample.java @@ -0,0 +1,62 @@ +package org.scribe.examples; + +import java.util.Scanner; + +import org.scribe.builder.*; +import org.scribe.builder.api.*; +import org.scribe.model.*; +import org.scribe.oauth.*; + +public class TumblrExample +{ + private static final String PROTECTED_RESOURCE_URL = "http://api.tumblr.com/v2/user/info"; + + public static void main( String[] args ) + { + OAuthService service = new ServiceBuilder() + .provider( TumblrApi.class ) + .apiKey( "MY_CONSUMER_KEY" ) + .apiSecret( "MY_CONSUMER_SECRET" ) + .callback( "http://www.tumblr.com/connect/login_success.html" ) // OOB forbidden. We need an url and the better is on the tumblr website ! + .build(); + Scanner in = new Scanner( System.in ); + + System.out.println( "=== Tumblr's OAuth Workflow ===" ); + System.out.println(); + + // Obtain the Request Token + System.out.println( "Fetching the Request Token..." ); + Token requestToken = service.getRequestToken(); + System.out.println( "Got the Request Token!" ); + System.out.println(); + + System.out.println( "Now go and authorize Scribe here:" ); + System.out.println( service.getAuthorizationUrl( requestToken ) ); + System.out.println( "And paste the verifier here" ); + System.out.print( ">>" ); + Verifier verifier = new Verifier( in.nextLine() ); + System.out.println(); + + // Trade the Request Token and Verfier for the Access Token + System.out.println( "Trading the Request Token for an Access Token..." ); + Token accessToken = service.getAccessToken( requestToken , + verifier ); + System.out.println( "Got the Access Token!" ); + System.out.println( "(if your curious it looks like this: " + accessToken + " )" ); + System.out.println(); + + // Now let's go and ask for a protected resource! + System.out.println( "Now we're going to access a protected resource..." ); + OAuthRequest request = new OAuthRequest( Verb.GET , + PROTECTED_RESOURCE_URL ); + service.signRequest( accessToken , + request ); + Response response = request.send(); + System.out.println( "Got it! Lets see what we found..." ); + System.out.println(); + System.out.println( response.getBody() ); + + System.out.println(); + System.out.println( "Thats it man! Go and build something awesome with Scribe! :)" ); + } +} From 8fb4d5d4fd23d66e1840bc9da85aec1c771e2e25 Mon Sep 17 00:00:00 2001 From: Angelo Date: Sat, 23 Nov 2013 15:58:02 -0500 Subject: [PATCH 022/882] Remove port 80 and 443 from base string --- src/main/java/org/scribe/model/Request.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/scribe/model/Request.java b/src/main/java/org/scribe/model/Request.java index 0202db0a2..e48578e21 100644 --- a/src/main/java/org/scribe/model/Request.java +++ b/src/main/java/org/scribe/model/Request.java @@ -237,14 +237,22 @@ public String getUrl() } /** - * Returns the URL without the port and the query string part. + * Returns the URL without the default port and the query string part. * * @return the OAuth-sanitized URL */ public String getSanitizedUrl() { - return url.replaceAll("\\?.*", "").replace("\\:\\d{4}", ""); - } + if(url.startsWith("http://") && (url.endsWith(":80") || url.contains(":80/"))){ + return url.replaceAll("\\?.*", "").replaceAll(":80", ""); + } + else if(url.startsWith("https://") && (url.endsWith(":443") || url.contains(":443/"))){ + return url.replaceAll("\\?.*", "").replaceAll(":443", ""); + } + else{ + return url.replaceAll("\\?.*", ""); + } + } /** * Returns the body of the request From d1274eb001b310b2d6674e42c096a32475b6559a Mon Sep 17 00:00:00 2001 From: Angelo Date: Mon, 25 Nov 2013 21:05:08 -0500 Subject: [PATCH 023/882] Added test cases for port 80 and 443 in basestring --- .../extractors/BaseStringExtractorTest.java | 50 +++++++++++++++++++ .../org/scribe/test/helpers/ObjectMother.java | 50 +++++++++++++++++++ 2 files changed, 100 insertions(+) diff --git a/src/test/java/org/scribe/extractors/BaseStringExtractorTest.java b/src/test/java/org/scribe/extractors/BaseStringExtractorTest.java index edc101d15..0fac0823c 100644 --- a/src/test/java/org/scribe/extractors/BaseStringExtractorTest.java +++ b/src/test/java/org/scribe/extractors/BaseStringExtractorTest.java @@ -12,11 +12,21 @@ public class BaseStringExtractorTest private BaseStringExtractorImpl extractor; private OAuthRequest request; + private OAuthRequest requestPort80; + private OAuthRequest requestPort80_2; + private OAuthRequest requestPort8080; + private OAuthRequest requestPort443; + private OAuthRequest requestPort443_2; @Before public void setup() { request = ObjectMother.createSampleOAuthRequest(); + requestPort80 = ObjectMother.createSampleOAuthRequestPort80(); + requestPort80_2 = ObjectMother.createSampleOAuthRequestPort80_2(); + requestPort8080 = ObjectMother.createSampleOAuthRequestPort8080(); + requestPort443 = ObjectMother.createSampleOAuthRequestPort443(); + requestPort443_2 = ObjectMother.createSampleOAuthRequestPort443_2(); extractor = new BaseStringExtractorImpl(); } @@ -27,7 +37,47 @@ public void shouldExtractBaseStringFromOAuthRequest() String baseString = extractor.extract(request); assertEquals(expected, baseString); } + + @Test + public void shouldExcludePort80() + { + String expected = "GET&http%3A%2F%2Fexample.com&oauth_callback%3Dhttp%253A%252F%252Fexample%252Fcallback%26oauth_consumer_key%3DAS%2523%2524%255E%252A%2540%2526%26oauth_signature%3DOAuth-Signature%26oauth_timestamp%3D123456"; + String baseString = extractor.extract(requestPort80); + assertEquals(expected, baseString); + } + + @Test + public void shouldExcludePort80_2() + { + String expected = "GET&http%3A%2F%2Fexample.com%2Ftest&oauth_callback%3Dhttp%253A%252F%252Fexample%252Fcallback%26oauth_consumer_key%3DAS%2523%2524%255E%252A%2540%2526%26oauth_signature%3DOAuth-Signature%26oauth_timestamp%3D123456"; + String baseString = extractor.extract(requestPort80_2); + assertEquals(expected, baseString); + } + + @Test + public void shouldIncludePort8080() + { + String expected = "GET&http%3A%2F%2Fexample.com%3A8080&oauth_callback%3Dhttp%253A%252F%252Fexample%252Fcallback%26oauth_consumer_key%3DAS%2523%2524%255E%252A%2540%2526%26oauth_signature%3DOAuth-Signature%26oauth_timestamp%3D123456"; + String baseString = extractor.extract(requestPort8080); + assertEquals(expected, baseString); + } + @Test + public void shouldExcludePort443() + { + String expected = "GET&https%3A%2F%2Fexample.com&oauth_callback%3Dhttp%253A%252F%252Fexample%252Fcallback%26oauth_consumer_key%3DAS%2523%2524%255E%252A%2540%2526%26oauth_signature%3DOAuth-Signature%26oauth_timestamp%3D123456"; + String baseString = extractor.extract(requestPort443); + assertEquals(expected, baseString); + } + + @Test + public void shouldExcludePort443_2() + { + String expected = "GET&https%3A%2F%2Fexample.com%2Ftest&oauth_callback%3Dhttp%253A%252F%252Fexample%252Fcallback%26oauth_consumer_key%3DAS%2523%2524%255E%252A%2540%2526%26oauth_signature%3DOAuth-Signature%26oauth_timestamp%3D123456"; + String baseString = extractor.extract(requestPort443_2); + assertEquals(expected, baseString); + } + @Test(expected = IllegalArgumentException.class) public void shouldThrowExceptionIfRquestIsNull() { diff --git a/src/test/java/org/scribe/test/helpers/ObjectMother.java b/src/test/java/org/scribe/test/helpers/ObjectMother.java index a69a3c13a..abd75cc18 100644 --- a/src/test/java/org/scribe/test/helpers/ObjectMother.java +++ b/src/test/java/org/scribe/test/helpers/ObjectMother.java @@ -14,4 +14,54 @@ public static OAuthRequest createSampleOAuthRequest() request.addOAuthParameter(OAuthConstants.SIGNATURE, "OAuth-Signature"); return request; } + + public static OAuthRequest createSampleOAuthRequestPort80() + { + OAuthRequest request = new OAuthRequest(Verb.GET, "http://example.com:80"); + request.addOAuthParameter(OAuthConstants.TIMESTAMP, "123456"); + request.addOAuthParameter(OAuthConstants.CONSUMER_KEY, "AS#$^*@&"); + request.addOAuthParameter(OAuthConstants.CALLBACK, "http://example/callback"); + request.addOAuthParameter(OAuthConstants.SIGNATURE, "OAuth-Signature"); + return request; + } + + public static OAuthRequest createSampleOAuthRequestPort80_2() + { + OAuthRequest request = new OAuthRequest(Verb.GET, "http://example.com:80/test"); + request.addOAuthParameter(OAuthConstants.TIMESTAMP, "123456"); + request.addOAuthParameter(OAuthConstants.CONSUMER_KEY, "AS#$^*@&"); + request.addOAuthParameter(OAuthConstants.CALLBACK, "http://example/callback"); + request.addOAuthParameter(OAuthConstants.SIGNATURE, "OAuth-Signature"); + return request; + } + + public static OAuthRequest createSampleOAuthRequestPort8080() + { + OAuthRequest request = new OAuthRequest(Verb.GET, "http://example.com:8080"); + request.addOAuthParameter(OAuthConstants.TIMESTAMP, "123456"); + request.addOAuthParameter(OAuthConstants.CONSUMER_KEY, "AS#$^*@&"); + request.addOAuthParameter(OAuthConstants.CALLBACK, "http://example/callback"); + request.addOAuthParameter(OAuthConstants.SIGNATURE, "OAuth-Signature"); + return request; + } + + public static OAuthRequest createSampleOAuthRequestPort443() + { + OAuthRequest request = new OAuthRequest(Verb.GET, "https://example.com:443"); + request.addOAuthParameter(OAuthConstants.TIMESTAMP, "123456"); + request.addOAuthParameter(OAuthConstants.CONSUMER_KEY, "AS#$^*@&"); + request.addOAuthParameter(OAuthConstants.CALLBACK, "http://example/callback"); + request.addOAuthParameter(OAuthConstants.SIGNATURE, "OAuth-Signature"); + return request; + } + + public static OAuthRequest createSampleOAuthRequestPort443_2() + { + OAuthRequest request = new OAuthRequest(Verb.GET, "https://example.com:443/test"); + request.addOAuthParameter(OAuthConstants.TIMESTAMP, "123456"); + request.addOAuthParameter(OAuthConstants.CONSUMER_KEY, "AS#$^*@&"); + request.addOAuthParameter(OAuthConstants.CALLBACK, "http://example/callback"); + request.addOAuthParameter(OAuthConstants.SIGNATURE, "OAuth-Signature"); + return request; + } } From 94add5a8dc5e14e06f3f10108a3e33f7825d56e6 Mon Sep 17 00:00:00 2001 From: Pablo Fernandez Date: Fri, 6 Dec 2013 02:18:52 -0200 Subject: [PATCH 024/882] Update TwitterExample.java --- src/test/java/org/scribe/examples/TwitterExample.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/org/scribe/examples/TwitterExample.java b/src/test/java/org/scribe/examples/TwitterExample.java index b68aee087..c387cb93c 100644 --- a/src/test/java/org/scribe/examples/TwitterExample.java +++ b/src/test/java/org/scribe/examples/TwitterExample.java @@ -46,7 +46,7 @@ public static void main(String[] args) // Now let's go and ask for a protected resource! System.out.println("Now we're going to access a protected resource..."); - OAuthRequest request = new OAuthRequest(Verb.POST, PROTECTED_RESOURCE_URL); + OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); request.addBodyParameter("status", "this is sparta! *"); service.signRequest(accessToken, request); Response response = request.send(); @@ -58,4 +58,4 @@ public static void main(String[] args) System.out.println("Thats it man! Go and build something awesome with Scribe! :)"); } -} \ No newline at end of file +} From f000558883403da839df73b33796825a3c626c48 Mon Sep 17 00:00:00 2001 From: Joe Littlejohn Date: Tue, 10 Dec 2013 13:46:39 +0000 Subject: [PATCH 025/882] Add support for the Authorization parameter 'realm' --- .../org/scribe/extractors/HeaderExtractorImpl.java | 7 +++++++ src/main/java/org/scribe/model/OAuthConstants.java | 1 + src/main/java/org/scribe/model/OAuthRequest.java | 13 ++++++++++++- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/scribe/extractors/HeaderExtractorImpl.java b/src/main/java/org/scribe/extractors/HeaderExtractorImpl.java index 02094693f..85f452640 100644 --- a/src/main/java/org/scribe/extractors/HeaderExtractorImpl.java +++ b/src/main/java/org/scribe/extractors/HeaderExtractorImpl.java @@ -35,6 +35,13 @@ public String extract(OAuthRequest request) } header.append(String.format("%s=\"%s\"", entry.getKey(), OAuthEncoder.encode(entry.getValue()))); } + + if (request.getRealm() != null && !request.getRealm().isEmpty()) + { + header.append(PARAM_SEPARATOR); + header.append(String.format("%s=\"%s\"", OAuthConstants.REALM, request.getRealm())); + } + return header.toString(); } diff --git a/src/main/java/org/scribe/model/OAuthConstants.java b/src/main/java/org/scribe/model/OAuthConstants.java index 1719c54d5..c442deeb7 100644 --- a/src/main/java/org/scribe/model/OAuthConstants.java +++ b/src/main/java/org/scribe/model/OAuthConstants.java @@ -32,6 +32,7 @@ private OAuthConstants(){} public static final String CALLBACK = "oauth_callback"; public static final String VERSION = "oauth_version"; public static final String NONCE = "oauth_nonce"; + public static final String REALM = "realm"; public static final String PARAM_PREFIX = "oauth_"; public static final String TOKEN = "oauth_token"; public static final String TOKEN_SECRET = "oauth_token_secret"; diff --git a/src/main/java/org/scribe/model/OAuthRequest.java b/src/main/java/org/scribe/model/OAuthRequest.java index 43892278f..d3b2e5ac4 100644 --- a/src/main/java/org/scribe/model/OAuthRequest.java +++ b/src/main/java/org/scribe/model/OAuthRequest.java @@ -13,7 +13,8 @@ public class OAuthRequest extends Request { private static final String OAUTH_PREFIX = "oauth_"; private Map oauthParameters; - + private String realm; + /** * Default constructor. * @@ -61,6 +62,16 @@ public Map getOauthParameters() return oauthParameters; } + public void setRealm(String realm) + { + this.realm = realm; + } + + public String getRealm() + { + return realm; + } + @Override public String toString() { From d25432be0517fa6b058a66fb1286e1a037582494 Mon Sep 17 00:00:00 2001 From: Dave Brosius Date: Wed, 25 Dec 2013 15:00:10 -0500 Subject: [PATCH 026/882] no need to use .toLowerCase() and .equalsIgnoreCase() on the same string --- src/main/java/org/scribe/utils/Preconditions.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/scribe/utils/Preconditions.java b/src/main/java/org/scribe/utils/Preconditions.java index d4dd1be8c..f6e5b1572 100644 --- a/src/main/java/org/scribe/utils/Preconditions.java +++ b/src/main/java/org/scribe/utils/Preconditions.java @@ -65,7 +65,7 @@ public static void checkValidUrl(String url, String errorMsg) public static void checkValidOAuthCallback(String url, String errorMsg) { checkEmptyString(url, errorMsg); - if(url.toLowerCase().compareToIgnoreCase(OAuthConstants.OUT_OF_BAND) != 0) + if(url.compareToIgnoreCase(OAuthConstants.OUT_OF_BAND) != 0) { check(isUrl(url), errorMsg); } From b1878c44375761e77ca3720f35480f8188dc988d Mon Sep 17 00:00:00 2001 From: Chris Arriola Date: Tue, 7 Jan 2014 13:49:43 -0800 Subject: [PATCH 027/882] Updated README for Android include instructions. Missing colon. --- README.textile | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.textile b/README.textile index e1726c94f..6a52b52b8 100644 --- a/README.textile +++ b/README.textile @@ -52,7 +52,11 @@ Scribe's code is small (about 1k LOC) and simple to understand. No smart-ass or h3. Android-Ready -Works out of the box with android(TM) applications. +Works out of the box with android(TM) applications. Just include the following in your _build.gradle_ file: + +@dependencies {@ + @compile 'org.scribe:scribe:1.3.5'@ +@}@ h3. Stable & bulletproof From 71022007663ce4480c1e7ec79d762330d4e4207c Mon Sep 17 00:00:00 2001 From: Abby M Date: Thu, 9 Jan 2014 19:24:13 +0000 Subject: [PATCH 028/882] Added request logging to OAuth10aServiceImpl getAccessToken --- src/main/java/org/scribe/oauth/OAuth10aServiceImpl.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/scribe/oauth/OAuth10aServiceImpl.java b/src/main/java/org/scribe/oauth/OAuth10aServiceImpl.java index abde25399..2b207f566 100644 --- a/src/main/java/org/scribe/oauth/OAuth10aServiceImpl.java +++ b/src/main/java/org/scribe/oauth/OAuth10aServiceImpl.java @@ -100,8 +100,14 @@ public Token getAccessToken(Token requestToken, Verifier verifier, RequestTuner config.log("setting token to: " + requestToken + " and verifier to: " + verifier); addOAuthParams(request, requestToken); appendSignature(request); + + config.log("sending request..."); Response response = request.send(tuner); - return api.getAccessTokenExtractor().extract(response.getBody()); + String body = response.getBody(); + + config.log("response status code: " + response.getCode()); + config.log("response body: " + body); + return api.getAccessTokenExtractor().extract(body); } /** From 65ae79d2702ccb192161db8fc6d1edaa5df07be8 Mon Sep 17 00:00:00 2001 From: Pablo Fernandez Date: Tue, 14 Jan 2014 21:27:55 -0200 Subject: [PATCH 029/882] remove patch verb, not supported by HttpUrlConnection --- src/main/java/org/scribe/model/Verb.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/scribe/model/Verb.java b/src/main/java/org/scribe/model/Verb.java index 0c22f6690..ec0573131 100644 --- a/src/main/java/org/scribe/model/Verb.java +++ b/src/main/java/org/scribe/model/Verb.java @@ -7,5 +7,5 @@ */ public enum Verb { - GET, POST, PUT, DELETE, HEAD, OPTIONS, TRACE, PATCH + GET, POST, PUT, DELETE, HEAD, OPTIONS, TRACE } From f46114f0fc0e1d1aa137f62b8493ed68afb56383 Mon Sep 17 00:00:00 2001 From: Pablo Fernandez Date: Sun, 19 Jan 2014 16:47:56 -0300 Subject: [PATCH 030/882] deploy to github instead of central --- pom.xml | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index a276ae1bb..6a3e38449 100644 --- a/pom.xml +++ b/pom.xml @@ -15,6 +15,10 @@ 5 + + github + + fernandezpablo85 @@ -37,6 +41,14 @@ http://github.com/fernandezpablo85/scribe-java.git + + + internal.repo + Temporary Staging Repository + file://${project.build.directory}/mvn-repo + + + junit @@ -63,19 +75,27 @@ - org.apache.maven.plugins - maven-gpg-plugin - 1.4 + com.github.github + site-maven-plugin + 0.9 + + Maven artifacts for ${project.version} + true + ${project.build.directory}/mvn-repo + refs/heads/mvn-repo + **/* + scribe-java + fernandezpablo85 + - sign-artifacts - verify - sign + site + deploy - + org.codehaus.mojo findbugs-maven-plugin @@ -95,4 +115,4 @@ - + From e675441b943731a60ce4c0f2da2251631ff25f3c Mon Sep 17 00:00:00 2001 From: Pablo Fernandez Date: Sun, 19 Jan 2014 17:06:19 -0300 Subject: [PATCH 031/882] update readme to markdown, add information for the new maven repo --- README.md | 109 +++++++++++++++++++++++++++++++++++++++++++++++++ README.textile | 99 -------------------------------------------- 2 files changed, 109 insertions(+), 99 deletions(-) create mode 100644 README.md delete mode 100644 README.textile diff --git a/README.md b/README.md new file mode 100644 index 000000000..77991c6c2 --- /dev/null +++ b/README.md @@ -0,0 +1,109 @@ +# Welcome to the home of Scribe, the simple OAuth Java lib! + +![travis ci](https://secure.travis-ci.org/fernandezpablo85/scribe-java.png?branch=master) + +### Before submitting a pull request [please read this](https://github.com/fernandezpablo85/scribe-java/wiki/Scribe-scope-revised) + +# Why use Scribe? + +### Dead Simple + +Who said OAuth was difficult? Configuring scribe is __so easy your grandma can do it__! check it out: + +```java +OAuthService service = new ServiceBuilder() + .provider(LinkedInApi.class) + .apiKey(YOUR_API_KEY) + .apiSecret(YOUR_API_SECRET) + .build(); +``` + +That **single line** (added newlines for readability) is the only thing you need to configure scribe with LinkedIn's OAuth API for example. + +### Threadsafe + +Hit Scribe as hard and with many threads as you like. + +### Supports all major 1.0a and 2.0 OAuth APIs out-of-the-box + +* Google + +* Facebook + +* Yahoo + +* LinkedIn + +* Twitter + +* Foursquare + +* Evernote + +* Vimeo + +* Yammer + +* Windows Live + +* and many more! check the "examples folder":http://github.com/fernandezpablo85/scribe-java/tree/master/src/test/java/org/scribe/examples + +### Small and modular + +Scribe's code is small (about 1k LOC) and simple to understand. No smart-ass or "clever" hacks here. + +### Android-Ready + +Works out of the box with android(TM) applications. + +### Stable & bulletproof + +Good test coverage to keep you safe from harm. + +When something bad actually happens, Scribe's meaningful error messages will tell you exactly what went wrong, when and where. + +### Pull it from Maven! + +You can pull scribe from my maven repository, just add these to your __pom.xml__ file: + +```xml + + + + + scribe-java-mvn-repo + https://raw.github.com/fernandezpablo85/scribe-java/mvn-repo/ + + true + always + + + + + + + org.scribe + scribe + 1.3.5 + +``` + +## Getting started in less than 2 minutes + +Check the [Getting Started](http://wiki.github.com/fernandezpablo85/scribe-java/getting-started) page and start rocking! Please Read the [FAQ](http://wiki.github.com/fernandezpablo85/scribe-java/faq) before creating an issue :) + +## Questions? + +Feel free to drop me an email, but there's already a [StackOverflow](http://stackoverflow.com) tag for [scribe](http://stackoverflow.com/questions/tagged/scribe) you should use. I'm subscribed to it so I'll pick the question immediately. + +## Forks + +Looking for a scribe variation? check the [Fork List](https://github.com/fernandezpablo85/scribe-java/wiki/Forks) + +If you have a useful fork that should be listed there please contact me (see About me). + +## About me + +[LinkedIn profile](http://www.linkedin.com/in/fernandezpablo85) + +Follow me: [@fernandezpablo](http://twitter.com/fernandezpablo) diff --git a/README.textile b/README.textile deleted file mode 100644 index 6a52b52b8..000000000 --- a/README.textile +++ /dev/null @@ -1,99 +0,0 @@ -h2. Welcome to the home of Scribe, the simple OAuth Java lib! - -!https://secure.travis-ci.org/fernandezpablo85/scribe-java.png?branch=master(travis-ci-status)! - -h2. Before submitting a pull request "please read this":https://github.com/fernandezpablo85/scribe-java/wiki/Scribe-scope-revised - -h1. Why use Scribe? - -h3. Dead Simple - -Who said OAuth was difficult? Configuring scribe is __so easy your grandma can do it__! check it out: - -@OAuthService service = new ServiceBuilder()@ - @.provider(LinkedInApi.class)@ - @.apiKey(YOUR_API_KEY)@ - @.apiSecret(YOUR_API_SECRET)@ - @.build();@ - -That **single line** (added newlines for readability) is the only thing you need to configure scribe with LinkedIn's OAuth API for example. - -h3. Threadsafe - -Hit Scribe as hard and with many threads as you like. - -h3. Supports all major 1.0a and 2.0 OAuth APIs out-of-the-box - -* Google - -* Facebook - -* Yahoo - -* LinkedIn - -* Twitter - -* Foursquare - -* Evernote - -* Vimeo - -* Yammer - -* Windows Live - -* and many more! check the "examples folder":http://github.com/fernandezpablo85/scribe-java/tree/master/src/test/java/org/scribe/examples - -h3. Small and modular - -Scribe's code is small (about 1k LOC) and simple to understand. No smart-ass or "clever" hacks here. - -h3. Android-Ready - -Works out of the box with android(TM) applications. Just include the following in your _build.gradle_ file: - -@dependencies {@ - @compile 'org.scribe:scribe:1.3.5'@ -@}@ - -h3. Stable & bulletproof - -Good test coverage to keep you safe from harm. - -When something bad actually happens, Scribe's meaningful error messages will tell you exactly what went wrong, when and where. - -h3. Pull it from Maven! (new) - -You can pull scribe from a maven repository, just add this to your __pom.xml__ file: - -@@ - @org.scribe@ - @scribe@ - @1.3.5@ -@@ - -h1. Getting started in less than 2 minutes - -Check the "Getting Started":http://wiki.github.com/fernandezpablo85/scribe-java/getting-started page and start rocking! - -h1. Please Read the "FAQ":http://wiki.github.com/fernandezpablo85/scribe-java/faq before creating an issue :) - -h1. Questions? - -Feel free to drop me an email, but there's already a "StackOverflow":http://stackoverflow.com tag for "scribe":http://stackoverflow.com/questions/tagged/scribe you should use. I'm subscribed to it so I'll pick the question immediately. - -Note that it really helps to run scribe on "debug mode":https://github.com/fernandezpablo85/scribe-java/wiki/debug-mode (since 1.3.0), to get additional info. To do this simply call the @.debug()@ method on the @ServiceBuilder@. - -h1. Forks - -Looking for a scribe variation? check the "Fork List":https://github.com/fernandezpablo85/scribe-java/wiki/Forks - -If you have a useful fork that should be listed there please contact me (see About me). - -h1. About me - -"LinkedIn profile":http://www.linkedin.com/in/fernandezpablo85 - -Follow me: "@fernandezpablo":http://twitter.com/fernandezpablo From 929d36f136f758bf7f016572881169510683bad3 Mon Sep 17 00:00:00 2001 From: Pablo Fernandez Date: Sun, 19 Jan 2014 19:58:44 -0200 Subject: [PATCH 032/882] missing link --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 77991c6c2..81d2b2fe7 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ Hit Scribe as hard and with many threads as you like. * Windows Live -* and many more! check the "examples folder":http://github.com/fernandezpablo85/scribe-java/tree/master/src/test/java/org/scribe/examples +* and many more! check the [examples folder](http://github.com/fernandezpablo85/scribe-java/tree/master/src/test/java/org/scribe/examples) ### Small and modular From 33a89bd002ae88422ef00583ff7fbb7f9deb9790 Mon Sep 17 00:00:00 2001 From: robindrost Date: Mon, 27 Jan 2014 17:27:40 +0100 Subject: [PATCH 033/882] Update TwitterApi.java - Changed the request and access token endpoints to https. - Removed the inner SSL class since Twitter now forces to use https instead of http. - Removed the extend SSL from the Authenticate class since it no longer exists anymore. --- .../org/scribe/builder/api/TwitterApi.java | 30 ++----------------- 1 file changed, 3 insertions(+), 27 deletions(-) diff --git a/src/main/java/org/scribe/builder/api/TwitterApi.java b/src/main/java/org/scribe/builder/api/TwitterApi.java index a83c28e71..1c8a8f164 100644 --- a/src/main/java/org/scribe/builder/api/TwitterApi.java +++ b/src/main/java/org/scribe/builder/api/TwitterApi.java @@ -11,13 +11,13 @@ public class TwitterApi extends DefaultApi10a @Override public String getAccessTokenEndpoint() { - return "http://" + ACCESS_TOKEN_RESOURCE; + return "https://" + ACCESS_TOKEN_RESOURCE; } @Override public String getRequestTokenEndpoint() { - return "http://" + REQUEST_TOKEN_RESOURCE; + return "https://" + REQUEST_TOKEN_RESOURCE; } @Override @@ -26,27 +26,10 @@ public String getAuthorizationUrl(Token requestToken) return String.format(AUTHORIZE_URL, requestToken.getToken()); } - public static class SSL extends TwitterApi - { - @Override - public String getAccessTokenEndpoint() - { - return "https://" + ACCESS_TOKEN_RESOURCE; - } - - @Override - public String getRequestTokenEndpoint() - { - return "https://" + REQUEST_TOKEN_RESOURCE; - } - } - /** * Twitter 'friendlier' authorization endpoint for OAuth. - * - * Uses SSL. */ - public static class Authenticate extends SSL + public static class Authenticate { private static final String AUTHENTICATE_URL = "https://api.twitter.com/oauth/authenticate?oauth_token=%s"; @@ -56,11 +39,4 @@ public String getAuthorizationUrl(Token requestToken) return String.format(AUTHENTICATE_URL, requestToken.getToken()); } } - - /** - * Just an alias to the default (SSL) authorization endpoint. - * - * Need to include this for symmetry with 'Authenticate' only. - */ - public static class Authorize extends SSL{} } From 7afdb1f8a0636e6c6db9d7f6c6ee44728417908d Mon Sep 17 00:00:00 2001 From: robindrost Date: Mon, 27 Jan 2014 17:57:30 +0100 Subject: [PATCH 034/882] Update TwitterApi.java - Authenticate now extends the TwitterApi class so the @Override annotation is used correctly. --- src/main/java/org/scribe/builder/api/TwitterApi.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/scribe/builder/api/TwitterApi.java b/src/main/java/org/scribe/builder/api/TwitterApi.java index 1c8a8f164..86494c54d 100644 --- a/src/main/java/org/scribe/builder/api/TwitterApi.java +++ b/src/main/java/org/scribe/builder/api/TwitterApi.java @@ -29,7 +29,7 @@ public String getAuthorizationUrl(Token requestToken) /** * Twitter 'friendlier' authorization endpoint for OAuth. */ - public static class Authenticate + public static class Authenticate extends TwitterApi { private static final String AUTHENTICATE_URL = "https://api.twitter.com/oauth/authenticate?oauth_token=%s"; From 7947eb0efff774ef6251f39cd0319c67d5bc0597 Mon Sep 17 00:00:00 2001 From: Doug Roper Date: Mon, 27 Jan 2014 16:40:00 -0500 Subject: [PATCH 035/882] Fix spelling in OAuthException message. --- src/main/java/org/scribe/extractors/JsonTokenExtractor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/scribe/extractors/JsonTokenExtractor.java b/src/main/java/org/scribe/extractors/JsonTokenExtractor.java index 801cd6296..b51091f0b 100644 --- a/src/main/java/org/scribe/extractors/JsonTokenExtractor.java +++ b/src/main/java/org/scribe/extractors/JsonTokenExtractor.java @@ -20,7 +20,7 @@ public Token extract(String response) } else { - throw new OAuthException("Cannot extract an acces token. Response was: " + response); + throw new OAuthException("Cannot extract an access token. Response was: " + response); } } From 1f8b7375aa6e4e819aaa5c90393f14e25f48e185 Mon Sep 17 00:00:00 2001 From: richarth Date: Tue, 28 Jan 2014 16:00:06 +0000 Subject: [PATCH 036/882] Update TwitterExample.java Changed the protected resource URL to a secure URL now that Twitter always require HTTPS --- src/test/java/org/scribe/examples/TwitterExample.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/org/scribe/examples/TwitterExample.java b/src/test/java/org/scribe/examples/TwitterExample.java index c387cb93c..4f3435b39 100644 --- a/src/test/java/org/scribe/examples/TwitterExample.java +++ b/src/test/java/org/scribe/examples/TwitterExample.java @@ -9,7 +9,7 @@ public class TwitterExample { - private static final String PROTECTED_RESOURCE_URL = "http://api.twitter.com/1.1/account/verify_credentials.json"; + private static final String PROTECTED_RESOURCE_URL = "https://api.twitter.com/1.1/account/verify_credentials.json"; public static void main(String[] args) { From 76d6810e85fd62f8561c1b95c85edfad2c241afe Mon Sep 17 00:00:00 2001 From: Pablo Fernandez Date: Mon, 17 Mar 2014 15:57:56 -0300 Subject: [PATCH 037/882] bump for version release --- README.md | 2 +- pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 81d2b2fe7..fddf1da19 100644 --- a/README.md +++ b/README.md @@ -84,7 +84,7 @@ You can pull scribe from my maven repository, just add these to your __pom.xml__ org.scribe scribe - 1.3.5 + 1.3.6 ``` diff --git a/pom.xml b/pom.xml index 6a3e38449..9cd54e371 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ org.scribe scribe jar - 1.3.5 + 1.3.6 Scribe OAuth Library The best OAuth library out there http://github.com/fernandezpablo85/scribe-java From 271b1d66c1ee21695968cbed90be200135def808 Mon Sep 17 00:00:00 2001 From: Pablo Fernandez Date: Wed, 19 Mar 2014 20:25:39 -0300 Subject: [PATCH 038/882] typo on string --- src/test/java/org/scribe/examples/TwitterExample.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/org/scribe/examples/TwitterExample.java b/src/test/java/org/scribe/examples/TwitterExample.java index 4f3435b39..7573ed603 100644 --- a/src/test/java/org/scribe/examples/TwitterExample.java +++ b/src/test/java/org/scribe/examples/TwitterExample.java @@ -55,7 +55,7 @@ public static void main(String[] args) System.out.println(response.getBody()); System.out.println(); - System.out.println("Thats it man! Go and build something awesome with Scribe! :)"); + System.out.println("That's it man! Go and build something awesome with Scribe! :)"); } } From 9bcb7a478c73832725e35fe8d5f354dbae9381e0 Mon Sep 17 00:00:00 2001 From: Norbert Potocki Date: Fri, 4 Apr 2014 00:30:20 -0700 Subject: [PATCH 039/882] various documentation/spelling fixes --- .../java/org/scribe/exceptions/OAuthConnectionException.java | 2 +- .../java/org/scribe/extractors/BaseStringExtractorImpl.java | 2 +- src/main/java/org/scribe/extractors/TokenExtractor20Impl.java | 3 +-- src/main/java/org/scribe/extractors/TokenExtractorImpl.java | 2 +- src/main/java/org/scribe/model/OAuthConfig.java | 2 +- src/main/java/org/scribe/model/Parameter.java | 2 +- src/main/java/org/scribe/model/ParameterList.java | 2 +- .../java/org/scribe/services/HMACSha1SignatureService.java | 2 +- .../java/org/scribe/services/PlaintextSignatureService.java | 2 +- src/main/java/org/scribe/services/SignatureService.java | 2 +- src/main/java/org/scribe/utils/MapUtils.java | 2 +- src/main/java/org/scribe/utils/OAuthEncoder.java | 2 +- 12 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/main/java/org/scribe/exceptions/OAuthConnectionException.java b/src/main/java/org/scribe/exceptions/OAuthConnectionException.java index 918de810c..8b1716754 100644 --- a/src/main/java/org/scribe/exceptions/OAuthConnectionException.java +++ b/src/main/java/org/scribe/exceptions/OAuthConnectionException.java @@ -1,7 +1,7 @@ package org.scribe.exceptions; /** - * @author: Pablo Fernandez + * @author Pablo Fernandez */ public class OAuthConnectionException extends OAuthException { diff --git a/src/main/java/org/scribe/extractors/BaseStringExtractorImpl.java b/src/main/java/org/scribe/extractors/BaseStringExtractorImpl.java index ca21a0d1f..5e28ce276 100644 --- a/src/main/java/org/scribe/extractors/BaseStringExtractorImpl.java +++ b/src/main/java/org/scribe/extractors/BaseStringExtractorImpl.java @@ -38,7 +38,7 @@ private String getSortedAndEncodedParams(OAuthRequest request) private void checkPreconditions(OAuthRequest request) { - Preconditions.checkNotNull(request, "Cannot extract base string from null object"); + Preconditions.checkNotNull(request, "Cannot extract base string from a null object"); if (request.getOauthParameters() == null || request.getOauthParameters().size() <= 0) { diff --git a/src/main/java/org/scribe/extractors/TokenExtractor20Impl.java b/src/main/java/org/scribe/extractors/TokenExtractor20Impl.java index 1eb22ad63..daa58b93f 100644 --- a/src/main/java/org/scribe/extractors/TokenExtractor20Impl.java +++ b/src/main/java/org/scribe/extractors/TokenExtractor20Impl.java @@ -7,8 +7,7 @@ import org.scribe.utils.*; /** - * Default implementation of {@AccessTokenExtractor}. Conforms to OAuth 2.0 - * + * Default implementation of {@link AccessTokenExtractor}. Conforms to OAuth 2.0 */ public class TokenExtractor20Impl implements AccessTokenExtractor { diff --git a/src/main/java/org/scribe/extractors/TokenExtractorImpl.java b/src/main/java/org/scribe/extractors/TokenExtractorImpl.java index ba1784b9b..165a0e680 100644 --- a/src/main/java/org/scribe/extractors/TokenExtractorImpl.java +++ b/src/main/java/org/scribe/extractors/TokenExtractorImpl.java @@ -7,7 +7,7 @@ import org.scribe.utils.*; /** - * Default implementation of {@RequestTokenExtractor} and {@AccessTokenExtractor}. Conforms to OAuth 1.0a + * Default implementation of {@link RequestTokenExtractor} and {@link AccessTokenExtractor}. Conforms to OAuth 1.0a * * The process for extracting access and request tokens is similar so this class can do both things. * diff --git a/src/main/java/org/scribe/model/OAuthConfig.java b/src/main/java/org/scribe/model/OAuthConfig.java index 374c95894..51811d765 100644 --- a/src/main/java/org/scribe/model/OAuthConfig.java +++ b/src/main/java/org/scribe/model/OAuthConfig.java @@ -72,7 +72,7 @@ public void log(String message) } catch (Exception e) { - throw new RuntimeException("there were problems while writting to the debug stream", e); + throw new RuntimeException("there were problems while writing to the debug stream", e); } } } diff --git a/src/main/java/org/scribe/model/Parameter.java b/src/main/java/org/scribe/model/Parameter.java index f8f3b81f6..f22e30066 100644 --- a/src/main/java/org/scribe/model/Parameter.java +++ b/src/main/java/org/scribe/model/Parameter.java @@ -3,7 +3,7 @@ import org.scribe.utils.*; /** - * @author: Pablo Fernandez + * @author Pablo Fernandez */ public class Parameter implements Comparable { diff --git a/src/main/java/org/scribe/model/ParameterList.java b/src/main/java/org/scribe/model/ParameterList.java index b365cbaf6..747b399f6 100644 --- a/src/main/java/org/scribe/model/ParameterList.java +++ b/src/main/java/org/scribe/model/ParameterList.java @@ -8,7 +8,7 @@ import org.scribe.utils.Preconditions; /** - * @author: Pablo Fernandez + * @author Pablo Fernandez */ public class ParameterList { diff --git a/src/main/java/org/scribe/services/HMACSha1SignatureService.java b/src/main/java/org/scribe/services/HMACSha1SignatureService.java index 560c2e676..dcb8289a7 100644 --- a/src/main/java/org/scribe/services/HMACSha1SignatureService.java +++ b/src/main/java/org/scribe/services/HMACSha1SignatureService.java @@ -7,7 +7,7 @@ import org.scribe.utils.*; /** - * HMAC-SHA1 implementation of {@SignatureService} + * HMAC-SHA1 implementation of {@link SignatureService} * * @author Pablo Fernandez * diff --git a/src/main/java/org/scribe/services/PlaintextSignatureService.java b/src/main/java/org/scribe/services/PlaintextSignatureService.java index 03306e8e3..e8c352095 100644 --- a/src/main/java/org/scribe/services/PlaintextSignatureService.java +++ b/src/main/java/org/scribe/services/PlaintextSignatureService.java @@ -4,7 +4,7 @@ import org.scribe.utils.*; /** - * plaintext implementation of {@SignatureService} + * plaintext implementation of {@link SignatureService} * * @author Pablo Fernandez * diff --git a/src/main/java/org/scribe/services/SignatureService.java b/src/main/java/org/scribe/services/SignatureService.java index 229c2f60e..6843d1cdc 100644 --- a/src/main/java/org/scribe/services/SignatureService.java +++ b/src/main/java/org/scribe/services/SignatureService.java @@ -22,7 +22,7 @@ public interface SignatureService /** * Returns the signature method/algorithm * - * @return + * @return signature method/algorithm */ public String getSignatureMethod(); } diff --git a/src/main/java/org/scribe/utils/MapUtils.java b/src/main/java/org/scribe/utils/MapUtils.java index ee09d16b3..4ece95816 100644 --- a/src/main/java/org/scribe/utils/MapUtils.java +++ b/src/main/java/org/scribe/utils/MapUtils.java @@ -3,7 +3,7 @@ import java.util.Map; /** - * @author: Pablo Fernandez + * @author Pablo Fernandez */ public class MapUtils { diff --git a/src/main/java/org/scribe/utils/OAuthEncoder.java b/src/main/java/org/scribe/utils/OAuthEncoder.java index 7fdbc84cc..523f31172 100644 --- a/src/main/java/org/scribe/utils/OAuthEncoder.java +++ b/src/main/java/org/scribe/utils/OAuthEncoder.java @@ -7,7 +7,7 @@ import org.scribe.exceptions.*; /** - * @author: Pablo Fernandez + * @author Pablo Fernandez */ public class OAuthEncoder { From 32c37cde6903f632d592bca0e279cf59e5f8fa6f Mon Sep 17 00:00:00 2001 From: Norbert Potocki Date: Fri, 4 Apr 2014 00:51:53 -0700 Subject: [PATCH 040/882] add Chinese Evernote (Yinxiang) endpoint --- .../org/scribe/builder/api/EvernoteApi.java | 97 ++++++++++++------- 1 file changed, 63 insertions(+), 34 deletions(-) diff --git a/src/main/java/org/scribe/builder/api/EvernoteApi.java b/src/main/java/org/scribe/builder/api/EvernoteApi.java index 007f48b1e..4042595b8 100644 --- a/src/main/java/org/scribe/builder/api/EvernoteApi.java +++ b/src/main/java/org/scribe/builder/api/EvernoteApi.java @@ -2,48 +2,77 @@ import org.scribe.model.Token; +/** + * OAuth API for Evernote + * + * @author Pablo Fernandez + * @author Norbert Potocki + */ public class EvernoteApi extends DefaultApi10a { private static final String AUTHORIZATION_URL = "https://www.evernote.com/OAuth.action?oauth_token=%s"; @Override - public String getRequestTokenEndpoint() + public String getRequestTokenEndpoint() { return "https://www.evernote.com/oauth"; } - @Override - public String getAccessTokenEndpoint() - { - return "https://www.evernote.com/oauth"; - } - - @Override - public String getAuthorizationUrl(Token requestToken) - { - return String.format(AUTHORIZATION_URL, requestToken.getToken()); - } - - public static class Sandbox extends EvernoteApi - { - private static final String SANDBOX_URL = "https://sandbox.evernote.com"; - - @Override - public String getRequestTokenEndpoint() - { - return SANDBOX_URL + "/oauth"; - } - - @Override - public String getAccessTokenEndpoint() - { + @Override + public String getAccessTokenEndpoint() + { + return "https://www.evernote.com/oauth"; + } + + @Override + public String getAuthorizationUrl(Token requestToken) + { + return String.format(AUTHORIZATION_URL, requestToken.getToken()); + } + + public static class Sandbox extends EvernoteApi + { + private static final String SANDBOX_URL = "https://sandbox.evernote.com"; + + @Override + public String getRequestTokenEndpoint() + { return SANDBOX_URL + "/oauth"; - } - - @Override - public String getAuthorizationUrl(Token requestToken) - { - return String.format(SANDBOX_URL + "/OAuth.action?oauth_token=%s", requestToken.getToken()); - } - } + } + + @Override + public String getAccessTokenEndpoint() + { + return SANDBOX_URL + "/oauth"; + } + + @Override + public String getAuthorizationUrl(Token requestToken) + { + return String.format(SANDBOX_URL + "/OAuth.action?oauth_token=%s", requestToken.getToken()); + } + } + + public static class Yinxiang extends EvernoteApi + { + private static final String SANDBOX_URL = "https://app.yinxiang.com"; + + @Override + public String getRequestTokenEndpoint() + { + return SANDBOX_URL + "/oauth"; + } + + @Override + public String getAccessTokenEndpoint() + { + return SANDBOX_URL + "/oauth"; + } + + @Override + public String getAuthorizationUrl(Token requestToken) + { + return String.format(SANDBOX_URL + "/OAuth.action?oauth_token=%s", requestToken.getToken()); + } + } } From bb6435dda17cad428ca03518c111f8b79550e72c Mon Sep 17 00:00:00 2001 From: Norbert Potocki Date: Fri, 4 Apr 2014 01:03:48 -0700 Subject: [PATCH 041/882] refactor EvernoteApi getting rid of duplicate code --- .../org/scribe/builder/api/EvernoteApi.java | 55 ++++++------------- 1 file changed, 16 insertions(+), 39 deletions(-) diff --git a/src/main/java/org/scribe/builder/api/EvernoteApi.java b/src/main/java/org/scribe/builder/api/EvernoteApi.java index 4042595b8..05ee502ff 100644 --- a/src/main/java/org/scribe/builder/api/EvernoteApi.java +++ b/src/main/java/org/scribe/builder/api/EvernoteApi.java @@ -5,74 +5,51 @@ /** * OAuth API for Evernote * - * @author Pablo Fernandez * @author Norbert Potocki */ public class EvernoteApi extends DefaultApi10a { - private static final String AUTHORIZATION_URL = "https://www.evernote.com/OAuth.action?oauth_token=%s"; + protected String serviceUrl() { + return "https://www.evernote.com"; + } @Override public String getRequestTokenEndpoint() { - return "https://www.evernote.com/oauth"; + return serviceUrl() + "/oauth"; } @Override public String getAccessTokenEndpoint() { - return "https://www.evernote.com/oauth"; + return serviceUrl() + "/oauth"; } @Override public String getAuthorizationUrl(Token requestToken) { - return String.format(AUTHORIZATION_URL, requestToken.getToken()); + return String.format(serviceUrl() + "/OAuth.action?oauth_token=%s", requestToken.getToken()); } + /** + * Sandbox endpoint + */ public static class Sandbox extends EvernoteApi { - private static final String SANDBOX_URL = "https://sandbox.evernote.com"; - - @Override - public String getRequestTokenEndpoint() - { - return SANDBOX_URL + "/oauth"; - } - - @Override - public String getAccessTokenEndpoint() - { - return SANDBOX_URL + "/oauth"; - } - @Override - public String getAuthorizationUrl(Token requestToken) - { - return String.format(SANDBOX_URL + "/OAuth.action?oauth_token=%s", requestToken.getToken()); + protected String serviceUrl() { + return "https://sandbox.evernote.com"; } } + /** + * Yinxiang Biji endpoint + */ public static class Yinxiang extends EvernoteApi { - private static final String SANDBOX_URL = "https://app.yinxiang.com"; - - @Override - public String getRequestTokenEndpoint() - { - return SANDBOX_URL + "/oauth"; - } - - @Override - public String getAccessTokenEndpoint() - { - return SANDBOX_URL + "/oauth"; - } - @Override - public String getAuthorizationUrl(Token requestToken) - { - return String.format(SANDBOX_URL + "/OAuth.action?oauth_token=%s", requestToken.getToken()); + protected String serviceUrl() { + return "https://app.yinxiang.com"; } } } From ed359d36f2d49c412c929ce1fbca824f26c07b34 Mon Sep 17 00:00:00 2001 From: Pablo Fernandez Date: Tue, 20 May 2014 12:44:13 -0300 Subject: [PATCH 042/882] bump version for release, add javadocs and source artifacts. --- pom.xml | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 9cd54e371..db0afd1e9 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ org.scribe scribe jar - 1.3.6 + 1.3.7 Scribe OAuth Library The best OAuth library out there http://github.com/fernandezpablo85/scribe-java @@ -74,6 +74,30 @@ 1.5 + + org.apache.maven.plugins + maven-source-plugin + + + attach-sources + + jar + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + + + attach-javadocs + + jar + + + + com.github.github site-maven-plugin From 3e974d7375c0697eb464fdb1c0149b5f41495bc8 Mon Sep 17 00:00:00 2001 From: lethalbrains Date: Sat, 24 May 2014 12:53:21 +0530 Subject: [PATCH 043/882] Fixed grammar. --- src/test/java/org/scribe/examples/TwitterExample.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/org/scribe/examples/TwitterExample.java b/src/test/java/org/scribe/examples/TwitterExample.java index 7573ed603..9a810d78c 100644 --- a/src/test/java/org/scribe/examples/TwitterExample.java +++ b/src/test/java/org/scribe/examples/TwitterExample.java @@ -41,7 +41,7 @@ public static void main(String[] args) System.out.println("Trading the Request Token for an Access Token..."); Token accessToken = service.getAccessToken(requestToken, verifier); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken + " )"); + System.out.println("(if you're curious, it looks like this: " + accessToken + " )"); System.out.println(); // Now let's go and ask for a protected resource! From f5edc0718da0abb83b26c8cf6797090e64fc8114 Mon Sep 17 00:00:00 2001 From: Pablo Fernandez Date: Sat, 24 May 2014 16:24:53 -0300 Subject: [PATCH 044/882] travis ignore mvn-repo --- .travis.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.travis.yml b/.travis.yml index c966b9e63..6ecb86aa8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,3 +3,7 @@ language: java # need to override travis 'install' since it will try gpg sign and fail. install: mvn clean package -DskipTests=true + +branches: + except: + - mvn-repo From 5eeb6fe8b3914f7fd4961bed26bd8b4c66b082b9 Mon Sep 17 00:00:00 2001 From: jeremybrooks Date: Fri, 4 Jul 2014 20:49:15 -0700 Subject: [PATCH 045/882] updated the FlickrApi to use https --- src/main/java/org/scribe/builder/api/FlickrApi.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/scribe/builder/api/FlickrApi.java b/src/main/java/org/scribe/builder/api/FlickrApi.java index a63043610..2e900de5f 100644 --- a/src/main/java/org/scribe/builder/api/FlickrApi.java +++ b/src/main/java/org/scribe/builder/api/FlickrApi.java @@ -17,7 +17,7 @@ public class FlickrApi extends DefaultApi10a @Override public String getAccessTokenEndpoint() { - return "http://www.flickr.com/services/oauth/access_token"; + return "https://www.flickr.com/services/oauth/access_token"; } /** @@ -26,7 +26,7 @@ public String getAccessTokenEndpoint() @Override public String getAuthorizationUrl(Token requestToken) { - return "http://www.flickr.com/services/oauth/authorize?oauth_token=" + requestToken.getToken(); + return "https://www.flickr.com/services/oauth/authorize?oauth_token=" + requestToken.getToken(); } /** @@ -35,6 +35,6 @@ public String getAuthorizationUrl(Token requestToken) @Override public String getRequestTokenEndpoint() { - return "http://www.flickr.com/services/oauth/request_token"; + return "https://www.flickr.com/services/oauth/request_token"; } } From cc55615470101c272bacf1fecd3dfa2a9b0692e9 Mon Sep 17 00:00:00 2001 From: jeremybrooks Date: Fri, 4 Jul 2014 20:54:34 -0700 Subject: [PATCH 046/882] updated the FlickrExample to use https --- src/test/java/org/scribe/examples/FlickrExample.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/test/java/org/scribe/examples/FlickrExample.java b/src/test/java/org/scribe/examples/FlickrExample.java index ac38ad32f..92e9e6b82 100644 --- a/src/test/java/org/scribe/examples/FlickrExample.java +++ b/src/test/java/org/scribe/examples/FlickrExample.java @@ -9,12 +9,12 @@ public class FlickrExample { - private static final String PROTECTED_RESOURCE_URL = "http://api.flickr.com/services/rest/"; + private static final String PROTECTED_RESOURCE_URL = "https://api.flickr.com/services/rest/"; public static void main(String[] args) { // Replace these with your own api key and secret - String apiKey = "your_app_id"; + String apiKey = "your_api_key"; String apiSecret = "your_api_secret"; OAuthService service = new ServiceBuilder().provider(FlickrApi.class).apiKey(apiKey).apiSecret(apiSecret).build(); Scanner in = new Scanner(System.in); @@ -41,6 +41,7 @@ public static void main(String[] args) Token accessToken = service.getAccessToken(requestToken, verifier); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + " )"); + System.out.println("(you can get the username, full name, and nsid by parsing the rawResponse: " + accessToken.getRawResponse() + ")"); System.out.println(); // Now let's go and ask for a protected resource! From 60aa4bb714a291a4694fc27085017ed83b00bbc3 Mon Sep 17 00:00:00 2001 From: Pablo Fernandez Date: Thu, 7 Aug 2014 17:51:32 -0300 Subject: [PATCH 047/882] remove body parameter it was previously used since the sample request was sending a twit, now twitter validation got stricter and it's making the sample get request fail. thanks @witbrock for noticing! --- src/test/java/org/scribe/examples/TwitterExample.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/test/java/org/scribe/examples/TwitterExample.java b/src/test/java/org/scribe/examples/TwitterExample.java index 9a810d78c..0cfbdfb6b 100644 --- a/src/test/java/org/scribe/examples/TwitterExample.java +++ b/src/test/java/org/scribe/examples/TwitterExample.java @@ -47,7 +47,6 @@ public static void main(String[] args) // Now let's go and ask for a protected resource! System.out.println("Now we're going to access a protected resource..."); OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); - request.addBodyParameter("status", "this is sparta! *"); service.signRequest(accessToken, request); Response response = request.send(); System.out.println("Got it! Lets see what we found..."); From 3fb9fa83ccdee8f1d67332fed6d0bd79b4f827a2 Mon Sep 17 00:00:00 2001 From: Pablo Fernandez Date: Mon, 1 Sep 2014 23:19:21 -0300 Subject: [PATCH 048/882] allow 'realm' parameter in OAuthParameters --- .../java/org/scribe/model/OAuthRequest.java | 30 +++++++++---------- .../org/scribe/model/OAuthRequestTest.java | 3 +- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/main/java/org/scribe/model/OAuthRequest.java b/src/main/java/org/scribe/model/OAuthRequest.java index d3b2e5ac4..8d241a4c0 100644 --- a/src/main/java/org/scribe/model/OAuthRequest.java +++ b/src/main/java/org/scribe/model/OAuthRequest.java @@ -4,9 +4,9 @@ /** * The representation of an OAuth HttpRequest. - * - * Adds OAuth-related functionality to the {@link Request} - * + * + * Adds OAuth-related functionality to the {@link Request} + * * @author Pablo Fernandez */ public class OAuthRequest extends Request @@ -14,10 +14,10 @@ public class OAuthRequest extends Request private static final String OAUTH_PREFIX = "oauth_"; private Map oauthParameters; private String realm; - + /** * Default constructor. - * + * * @param verb Http verb/method * @param url resource URL */ @@ -29,10 +29,10 @@ public OAuthRequest(Verb verb, String url) /** * Adds an OAuth parameter. - * + * * @param key name of the parameter * @param value value of the parameter - * + * * @throws IllegalArgumentException if the parameter is not an OAuth parameter */ public void addOAuthParameter(String key, String value) @@ -42,19 +42,19 @@ public void addOAuthParameter(String key, String value) private String checkKey(String key) { - if (key.startsWith(OAUTH_PREFIX) || key.equals(OAuthConstants.SCOPE)) + if (key.startsWith(OAUTH_PREFIX) || key.equals(OAuthConstants.SCOPE) || key.equals(OAuthConstants.REALM)) { return key; - } + } else { - throw new IllegalArgumentException(String.format("OAuth parameters must either be '%s' or start with '%s'", OAuthConstants.SCOPE, OAUTH_PREFIX)); + throw new IllegalArgumentException(String.format("OAuth parameters must either be '%s', '%s' or start with '%s'", OAuthConstants.SCOPE, OAuthConstants.REALM, OAUTH_PREFIX)); } } /** * Returns the {@link Map} containing the key-value pair of parameters. - * + * * @return parameters as map */ public Map getOauthParameters() @@ -62,16 +62,16 @@ public Map getOauthParameters() return oauthParameters; } - public void setRealm(String realm) + public void setRealm(String realm) { this.realm = realm; } - - public String getRealm() + + public String getRealm() { return realm; } - + @Override public String toString() { diff --git a/src/test/java/org/scribe/model/OAuthRequestTest.java b/src/test/java/org/scribe/model/OAuthRequestTest.java index 1ea2f2fb9..685c34c9f 100644 --- a/src/test/java/org/scribe/model/OAuthRequestTest.java +++ b/src/test/java/org/scribe/model/OAuthRequestTest.java @@ -22,8 +22,9 @@ public void shouldAddOAuthParamters() request.addOAuthParameter(OAuthConstants.NONCE, "nonce"); request.addOAuthParameter(OAuthConstants.TIMESTAMP, "ts"); request.addOAuthParameter(OAuthConstants.SCOPE, "feeds"); + request.addOAuthParameter(OAuthConstants.REALM, "some-realm"); - assertEquals(4, request.getOauthParameters().size()); + assertEquals(5, request.getOauthParameters().size()); } @Test(expected = IllegalArgumentException.class) From a01963ec7c4f5bb40f998107df52b662a0610400 Mon Sep 17 00:00:00 2001 From: Leandro Doctors Date: Mon, 22 Sep 2014 22:05:21 +0200 Subject: [PATCH 049/882] Use FindBugs 3.0.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index db0afd1e9..fcd6a4b85 100644 --- a/pom.xml +++ b/pom.xml @@ -123,7 +123,7 @@ org.codehaus.mojo findbugs-maven-plugin - 2.5.2 + 3.0.0 failing-on-high From b1813fdd186fa8581e9a89653cfeba495ed0569c Mon Sep 17 00:00:00 2001 From: stevepeak Date: Fri, 3 Oct 2014 21:46:53 +0000 Subject: [PATCH 050/882] Added Codecov.io coverage reporting --- .travis.yml | 2 ++ README.md | 3 ++- pom.xml | 19 +++++++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 6ecb86aa8..2e6f88bae 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,7 @@ # kickstart travis. language: java +before_install: sudo pip install codecov +after_success: codecov # need to override travis 'install' since it will try gpg sign and fail. install: mvn clean package -DskipTests=true diff --git a/README.md b/README.md index fddf1da19..4d8527c0e 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ -# Welcome to the home of Scribe, the simple OAuth Java lib! +# Welcome to the home of Scribe, the simple OAuth Java lib! ![travis ci](https://secure.travis-ci.org/fernandezpablo85/scribe-java.png?branch=master) +[![codecov.io](https://codecov.io/github/fernandezpablo85/scribe-java/coverage.svg?branch=master)](https://codecov.io/github/fernandezpablo85/scribe-java?branch=master) ### Before submitting a pull request [please read this](https://github.com/fernandezpablo85/scribe-java/wiki/Scribe-scope-revised) diff --git a/pom.xml b/pom.xml index fcd6a4b85..ac6ed35ce 100644 --- a/pom.xml +++ b/pom.xml @@ -137,6 +137,25 @@ + + org.jacoco + jacoco-maven-plugin + 0.5.8.201207111220 + + + + prepare-agent + + + + report + test + + report + + + + From b48d5d68d1116bc3f43b22d381f8bf97112d5b8b Mon Sep 17 00:00:00 2001 From: markjamesbutler Date: Fri, 9 Jan 2015 14:44:21 +0000 Subject: [PATCH 051/882] Updated Facebook URL's in relation to Facebook breaking changes. [https://developers.facebook.com/docs/apps/upgrading?locale=en_GB] --- src/main/java/org/scribe/builder/api/FacebookApi.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/scribe/builder/api/FacebookApi.java b/src/main/java/org/scribe/builder/api/FacebookApi.java index 996a651e1..f2bfcd5bc 100644 --- a/src/main/java/org/scribe/builder/api/FacebookApi.java +++ b/src/main/java/org/scribe/builder/api/FacebookApi.java @@ -6,13 +6,13 @@ public class FacebookApi extends DefaultApi20 { - private static final String AUTHORIZE_URL = "https://www.facebook.com/dialog/oauth?client_id=%s&redirect_uri=%s"; + private static final String AUTHORIZE_URL = "https://www.facebook.com/v2.0/dialog/oauth?client_id=%s&redirect_uri=%s"; private static final String SCOPED_AUTHORIZE_URL = AUTHORIZE_URL + "&scope=%s"; @Override public String getAccessTokenEndpoint() { - return "https://graph.facebook.com/oauth/access_token"; + return "https://graph.facebook.com/v2.0/oauth/access_token"; } @Override From a7235c84f4c09a5952aa382944897533b20f3ce6 Mon Sep 17 00:00:00 2001 From: Pablo Fernandez Date: Wed, 11 Feb 2015 13:11:50 -0300 Subject: [PATCH 052/882] remove yammer api --- .../org/scribe/builder/api/YammerApi.java | 33 ------------------- 1 file changed, 33 deletions(-) delete mode 100644 src/main/java/org/scribe/builder/api/YammerApi.java diff --git a/src/main/java/org/scribe/builder/api/YammerApi.java b/src/main/java/org/scribe/builder/api/YammerApi.java deleted file mode 100644 index e06543d97..000000000 --- a/src/main/java/org/scribe/builder/api/YammerApi.java +++ /dev/null @@ -1,33 +0,0 @@ -package org.scribe.builder.api; - -import org.scribe.model.*; -import org.scribe.services.*; - -public class YammerApi extends DefaultApi10a -{ - private static final String AUTHORIZATION_URL = "https://www.yammer.com/oauth/authorize?oauth_token=%s"; - - @Override - public String getRequestTokenEndpoint() - { - return "https://www.yammer.com/oauth/request_token"; - } - - @Override - public String getAccessTokenEndpoint() - { - return "https://www.yammer.com/oauth/access_token"; - } - - @Override - public String getAuthorizationUrl(Token requestToken) - { - return String.format(AUTHORIZATION_URL, requestToken.getToken()); - } - - @Override - public SignatureService getSignatureService() - { - return new PlaintextSignatureService(); - } -} From 6135a0bd0f51bc247f8e0465ee9bcd4ce35a16f8 Mon Sep 17 00:00:00 2001 From: antony Date: Tue, 10 Mar 2015 11:07:55 +0000 Subject: [PATCH 053/882] Fix assertions on oauth response as map ordering has changed due to JDK8 but ordering isn't important. --- README.md | 2 -- pom.xml | 6 ++++++ .../org/scribe/extractors/HeaderExtractorTest.java | 10 +++++++--- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 4d8527c0e..4bf5e52be 100644 --- a/README.md +++ b/README.md @@ -43,8 +43,6 @@ Hit Scribe as hard and with many threads as you like. * Vimeo -* Yammer - * Windows Live * and many more! check the [examples folder](http://github.com/fernandezpablo85/scribe-java/tree/master/src/test/java/org/scribe/examples) diff --git a/pom.xml b/pom.xml index ac6ed35ce..3f0d6da56 100644 --- a/pom.xml +++ b/pom.xml @@ -50,6 +50,12 @@ + + org.hamcrest + hamcrest-junit + 2.0.0.0 + test + junit junit diff --git a/src/test/java/org/scribe/extractors/HeaderExtractorTest.java b/src/test/java/org/scribe/extractors/HeaderExtractorTest.java index bdc727cd8..8caf4a047 100644 --- a/src/test/java/org/scribe/extractors/HeaderExtractorTest.java +++ b/src/test/java/org/scribe/extractors/HeaderExtractorTest.java @@ -6,6 +6,8 @@ import org.scribe.exceptions.*; import org.scribe.model.*; import org.scribe.test.helpers.*; +import static org.hamcrest.core.StringContains.containsString; +import static org.hamcrest.MatcherAssert.assertThat; public class HeaderExtractorTest { @@ -23,10 +25,12 @@ public void setup() @Test public void shouldExtractStandardHeader() { - String expected = "OAuth oauth_callback=\"http%3A%2F%2Fexample%2Fcallback\", " + "oauth_signature=\"OAuth-Signature\", " - + "oauth_consumer_key=\"AS%23%24%5E%2A%40%26\", " + "oauth_timestamp=\"123456\""; String header = extractor.extract(request); - assertEquals(expected, header); + + assertThat(header, containsString("oauth_callback=\"http%3A%2F%2Fexample%2Fcallback\"")); + assertThat(header, containsString("oauth_signature=\"OAuth-Signature\"")); + assertThat(header, containsString("oauth_consumer_key=\"AS%23%24%5E%2A%40%26\"")); + assertThat(header, containsString("oauth_timestamp=\"123456\"")); } @Test(expected = IllegalArgumentException.class) From 02dfe8563f94181271cce94c22c3adaeda23b1ff Mon Sep 17 00:00:00 2001 From: Pablo Fernandez Date: Tue, 16 Jun 2015 10:51:55 -0300 Subject: [PATCH 054/882] closes #558 --- src/main/java/org/scribe/model/Verb.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/scribe/model/Verb.java b/src/main/java/org/scribe/model/Verb.java index ec0573131..0c22f6690 100644 --- a/src/main/java/org/scribe/model/Verb.java +++ b/src/main/java/org/scribe/model/Verb.java @@ -7,5 +7,5 @@ */ public enum Verb { - GET, POST, PUT, DELETE, HEAD, OPTIONS, TRACE + GET, POST, PUT, DELETE, HEAD, OPTIONS, TRACE, PATCH } From b88b9ddf805954be6abf3b0e4c0641a9f6edd803 Mon Sep 17 00:00:00 2001 From: Pablo Fernandez Date: Mon, 13 Jul 2015 12:17:21 -0300 Subject: [PATCH 055/882] remove apache license header, it's wrong, license is MIT --- .../java/org/scribe/model/OAuthConstants.java | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/src/main/java/org/scribe/model/OAuthConstants.java b/src/main/java/org/scribe/model/OAuthConstants.java index c442deeb7..03789bc6f 100644 --- a/src/main/java/org/scribe/model/OAuthConstants.java +++ b/src/main/java/org/scribe/model/OAuthConstants.java @@ -1,23 +1,8 @@ -/* -Copyright 2010 Pablo Fernandez - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - -http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. - */ package org.scribe.model; /** * This class contains OAuth constants, used project-wide - * + * * @author Pablo Fernandez */ public class OAuthConstants @@ -48,5 +33,5 @@ private OAuthConstants(){} public static final String CLIENT_SECRET = "client_secret"; public static final String REDIRECT_URI = "redirect_uri"; public static final String CODE = "code"; - + } From 9984446d07043d1e221d198bf44f7a30220bce4d Mon Sep 17 00:00:00 2001 From: Akos Kemives Date: Thu, 30 Jul 2015 12:45:25 +0200 Subject: [PATCH 056/882] add getParameter method for easier query parameter access --- src/main/java/org/scribe/model/Token.java | 17 +++++++++++++++++ src/test/java/org/scribe/model/TokenTest.java | 10 ++++++++++ 2 files changed, 27 insertions(+) diff --git a/src/main/java/org/scribe/model/Token.java b/src/main/java/org/scribe/model/Token.java index 4d8c0eeb5..c93752a84 100644 --- a/src/main/java/org/scribe/model/Token.java +++ b/src/main/java/org/scribe/model/Token.java @@ -56,6 +56,23 @@ public String getRawResponse() return rawResponse; } + public String getParameter(String parameter) + { + String value = null; + for (String str : this.getRawResponse().split("&")) + { + if (str.startsWith(parameter + '=')) + { + String [] part = str.split("="); + if (part.length > 1) { + value = part[1].trim(); + } + break; + } + } + return value; + } + @Override public String toString() { diff --git a/src/test/java/org/scribe/model/TokenTest.java b/src/test/java/org/scribe/model/TokenTest.java index dff59ccf7..7e533ea76 100644 --- a/src/test/java/org/scribe/model/TokenTest.java +++ b/src/test/java/org/scribe/model/TokenTest.java @@ -41,4 +41,14 @@ public void shouldNotBeEqualToNullOrOtherObjects() throws Exception assertNotSame(expected, null); assertNotSame(expected, new Object()); } + + @Test + public void shouldReturnUrlParam() throws Exception + { + Token actual = new Token("acccess", "secret", "user_id=3107154759&screen_name=someuser&empty=&="); + assertEquals("someuser", actual.getParameter("screen_name")); + assertEquals("3107154759", actual.getParameter("user_id")); + assertEquals(null, actual.getParameter("empty")); + assertEquals(null, actual.getParameter(null)); + } } From b36b161d3680c04ac560e05973c97ebb6ce55e09 Mon Sep 17 00:00:00 2001 From: Pablo Fernandez Date: Thu, 6 Aug 2015 19:25:04 -0300 Subject: [PATCH 057/882] link to akoskm tutorial --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4bf5e52be..af585c643 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Welcome to the home of Scribe, the simple OAuth Java lib! +# Welcome to the home of Scribe, the simple OAuth Java lib! ![travis ci](https://secure.travis-ci.org/fernandezpablo85/scribe-java.png?branch=master) [![codecov.io](https://codecov.io/github/fernandezpablo85/scribe-java/coverage.svg?branch=master)](https://codecov.io/github/fernandezpablo85/scribe-java?branch=master) @@ -91,6 +91,8 @@ You can pull scribe from my maven repository, just add these to your __pom.xml__ Check the [Getting Started](http://wiki.github.com/fernandezpablo85/scribe-java/getting-started) page and start rocking! Please Read the [FAQ](http://wiki.github.com/fernandezpablo85/scribe-java/faq) before creating an issue :) +Also, remember to read the [fantastic tutorial](http://akoskm.github.io/2015/07/31/twitter-sign-in-for-web-apps.html) that [@akoskm](https://twitter.com/akoskm) wrote to easily integrate a server side app with an API (twitter in this case). + ## Questions? Feel free to drop me an email, but there's already a [StackOverflow](http://stackoverflow.com) tag for [scribe](http://stackoverflow.com/questions/tagged/scribe) you should use. I'm subscribed to it so I'll pick the question immediately. From 80f780bdc173af0f499170684aa12805d9ebd423 Mon Sep 17 00:00:00 2001 From: Vladislav Bauer Date: Sat, 22 Aug 2015 22:53:46 +0600 Subject: [PATCH 058/882] Add negative test for StreamUtils.getStreamContents --- .../java/org/scribe/utils/StreamUtilsTest.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/test/java/org/scribe/utils/StreamUtilsTest.java b/src/test/java/org/scribe/utils/StreamUtilsTest.java index 976914d05..e3e675db1 100644 --- a/src/test/java/org/scribe/utils/StreamUtilsTest.java +++ b/src/test/java/org/scribe/utils/StreamUtilsTest.java @@ -1,6 +1,7 @@ package org.scribe.utils; import java.io.ByteArrayInputStream; +import java.io.IOException; import java.io.InputStream; import org.junit.Test; @@ -26,4 +27,21 @@ public void shouldFailForNullParameter() StreamUtils.getStreamContents(is); fail("Must throw exception before getting here"); } + + @Test(expected = IllegalStateException.class) + public void shouldFailWithBrokenStream() + { + // This object simulates problems with input stream. + final InputStream is = new InputStream() + { + @Override + public int read() throws IOException + { + throw new IOException(); + } + }; + StreamUtils.getStreamContents(is); + fail("Must throw exception before getting here"); + } + } From a1fad2b4c1c61242d4c84b968f5565358cfaf536 Mon Sep 17 00:00:00 2001 From: Matyas Novy Date: Wed, 23 Sep 2015 20:24:08 +0200 Subject: [PATCH 059/882] Made BaseStringExtractorImpl extensible by changing method access of all private methods to protected and by moving HTTP verb and URL extraction to separate auxiliary methods. --- .../extractors/BaseStringExtractorImpl.java | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/scribe/extractors/BaseStringExtractorImpl.java b/src/main/java/org/scribe/extractors/BaseStringExtractorImpl.java index 5e28ce276..532e881ef 100644 --- a/src/main/java/org/scribe/extractors/BaseStringExtractorImpl.java +++ b/src/main/java/org/scribe/extractors/BaseStringExtractorImpl.java @@ -13,7 +13,7 @@ public class BaseStringExtractorImpl implements BaseStringExtractor { - private static final String AMPERSAND_SEPARATED_STRING = "%s&%s&%s"; + protected static final String AMPERSAND_SEPARATED_STRING = "%s&%s&%s"; /** * {@inheritDoc} @@ -21,13 +21,23 @@ public class BaseStringExtractorImpl implements BaseStringExtractor public String extract(OAuthRequest request) { checkPreconditions(request); - String verb = OAuthEncoder.encode(request.getVerb().name()); - String url = OAuthEncoder.encode(request.getSanitizedUrl()); + String verb = OAuthEncoder.encode(getVerb(request)); + String url = OAuthEncoder.encode(getUrl(request)); String params = getSortedAndEncodedParams(request); return String.format(AMPERSAND_SEPARATED_STRING, verb, url, params); } - private String getSortedAndEncodedParams(OAuthRequest request) + protected String getVerb(OAuthRequest request) + { + return request.getVerb().name(); + } + + protected String getUrl(OAuthRequest request) + { + return request.getSanitizedUrl(); + } + + protected String getSortedAndEncodedParams(OAuthRequest request) { ParameterList params = new ParameterList(); params.addAll(request.getQueryStringParams()); @@ -36,7 +46,7 @@ private String getSortedAndEncodedParams(OAuthRequest request) return params.sort().asOauthBaseString(); } - private void checkPreconditions(OAuthRequest request) + protected void checkPreconditions(OAuthRequest request) { Preconditions.checkNotNull(request, "Cannot extract base string from a null object"); From 04195020558ea17ba1c271b85ef40977055942c8 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 13 Nov 2015 15:16:37 +0300 Subject: [PATCH 060/882] HH-55803 merge back the SubScribe fork [i.garanina] --- .gitignore | 12 +- .travis.yml | 11 - LICENSE.txt | 1 + README.md | 79 ++-- bundle | 2 - changelog | 7 + pom.xml | 353 ++++++++-------- scribejava-apis/pom.xml | 46 +++ .../com/github/scribejava/apis/AWeberApi.java | 26 ++ .../scribejava/apis/ConstantContactApi.java | 24 ++ .../scribejava/apis/ConstantContactApi2.java | 54 +++ .../com/github/scribejava/apis/DiggApi.java | 26 ++ .../scribejava/apis/DoktornaraboteApi.java | 59 +++ .../github/scribejava/apis/DropBoxApi.java | 23 ++ .../github/scribejava/apis/EvernoteApi.java | 48 +++ .../github/scribejava/apis/FacebookApi.java | 34 ++ .../com/github/scribejava/apis/FlickrApi.java | 37 ++ .../scribejava/apis/Foursquare2Api.java | 30 ++ .../github/scribejava/apis/FoursquareApi.java | 24 ++ .../github/scribejava/apis/FreelancerApi.java | 55 +++ .../github/scribejava/apis/GetGlueApi.java | 27 ++ .../com/github/scribejava/apis/GitHubApi.java | 31 ++ .../com/github/scribejava/apis/GoogleApi.java | 35 ++ .../github/scribejava/apis/GoogleApi20.java | 53 +++ .../com/github/scribejava/apis/HHApi.java | 41 ++ .../com/github/scribejava/apis/ImgUrApi.java | 28 ++ .../com/github/scribejava/apis/KaixinApi.java | 37 ++ .../github/scribejava/apis/KaixinApi20.java | 38 ++ .../github/scribejava/apis/LinkedInApi.java | 53 +++ .../github/scribejava/apis/LinkedInApi20.java | 53 +++ .../com/github/scribejava/apis/LiveApi.java | 38 ++ .../github/scribejava/apis/LoveFilmApi.java | 26 ++ .../com/github/scribejava/apis/MailruApi.java | 48 +++ .../com/github/scribejava/apis/MeetupApi.java | 27 ++ .../github/scribejava/apis/MendeleyApi.java | 39 ++ .../com/github/scribejava/apis/MisoApi.java | 27 ++ .../github/scribejava/apis/NetProspexApi.java | 26 ++ .../scribejava/apis/NeteaseWeibooApi.java | 44 ++ .../scribejava/apis/OdnoklassnikiApi.java | 48 +++ .../com/github/scribejava/apis/PlurkApi.java | 36 ++ .../com/github/scribejava/apis/Px500Api.java | 24 ++ .../com/github/scribejava/apis/QWeiboApi.java | 26 ++ .../com/github/scribejava/apis/RenrenApi.java | 38 ++ .../com/github/scribejava/apis/SapoApi.java | 37 ++ .../github/scribejava/apis/SimpleGeoApi.java | 27 ++ .../github/scribejava/apis/SinaWeiboApi.java | 26 ++ .../scribejava/apis/SinaWeiboApi20.java | 44 ++ .../github/scribejava/apis/SkyrockApi.java | 33 ++ .../github/scribejava/apis/SohuWeiboApi.java | 26 ++ .../com/github/scribejava/apis/TrelloApi.java | 25 ++ .../com/github/scribejava/apis/TumblrApi.java | 26 ++ .../com/github/scribejava/apis/TutByApi.java | 42 ++ .../github/scribejava/apis/TwitterApi.java | 41 ++ .../github/scribejava/apis/UbuntuOneApi.java | 37 ++ .../com/github/scribejava/apis/ViadeoApi.java | 38 ++ .../com/github/scribejava/apis/VimeoApi.java | 24 ++ .../github/scribejava/apis/VkontakteApi.java | 39 ++ .../com/github/scribejava/apis/XingApi.java | 25 ++ .../com/github/scribejava/apis/YahooApi.java | 24 ++ .../com/github/scribejava/apis/YammerApi.java | 31 ++ .../apis/google/GoogleJsonTokenExtractor.java | 26 ++ .../scribejava/apis/google/GoogleToken.java | 26 ++ .../DoktornaraboteOAuthServiceImpl.java | 19 + .../apis/service/GoogleOAuthServiceImpl.java | 24 ++ .../apis/service/HHOAuthServiceImpl.java | 19 + .../apis/service/LinkedIn20ServiceImpl.java | 30 ++ .../apis/service/MailruOAuthServiceImpl.java | 62 +++ .../service/OdnoklassnikiServiceImpl.java | 37 ++ .../apis/service/TutByOAuthServiceImpl.java | 21 + .../apis/examples/AWeberExample.java | 66 +++ .../scribejava/apis/examples/DiggExample.java | 67 +++ .../apis/examples/FacebookAsyncExample.java | 96 +++++ .../apis/examples/FacebookExample.java | 81 ++++ .../apis/examples/FlickrExample.java | 62 +++ .../apis/examples/Foursquare2Example.java | 65 +++ .../apis/examples/FoursquareExample.java | 61 +++ .../apis/examples/FreelancerExample.java | 70 ++++ .../apis/examples/GitHubExample.java | 80 ++++ .../apis/examples/Google20Example.java | 95 +++++ .../apis/examples/GoogleExample.java | 68 +++ .../scribejava/apis/examples/HHExample.java | 66 +++ .../apis/examples/ImgUrExample.java | 60 +++ .../apis/examples/Kaixin20Example.java | 66 +++ .../apis/examples/LinkedIn20Example.java | 72 ++++ .../apis/examples/LinkedInExample.java | 62 +++ .../examples/LinkedInExampleWithScopes.java | 66 +++ .../scribejava/apis/examples/LiveExample.java | 66 +++ .../apis/examples/LoveFilmExample.java | 67 +++ .../apis/examples/MailruAsyncExample.java | 79 ++++ .../apis/examples/MailruExample.java | 65 +++ .../apis/examples/MeetupExample.java | 60 +++ .../apis/examples/NeteaseWeiboExample.java | 70 ++++ .../apis/examples/OdnoklassnikiExample.java | 70 ++++ .../apis/examples/Px500Example.java | 62 +++ .../apis/examples/RenrenExample.java | 111 +++++ .../apis/examples/SinaWeibo2Example.java | 66 +++ .../apis/examples/SinaWeiboExample.java | 70 ++++ .../apis/examples/SkyrockExample.java | 63 +++ .../apis/examples/SohuWeiboExample.java | 70 ++++ .../apis/examples/TrelloExample.java | 63 +++ .../apis/examples/TumblrExample.java | 62 +++ .../apis/examples/TutByExample.java | 68 +++ .../apis/examples/TwitterExample.java | 59 +++ .../apis/examples/ViadeoExample.java | 66 +++ .../apis/examples/VkontakteExample.java | 70 ++++ .../scribejava/apis/examples/XingExample.java | 61 +++ .../apis/examples/YahooExample.java | 63 +++ scribejava-core/pom.xml | 37 ++ .../core/builder/AbstractServiceBuilder.java | 185 +++++++++ .../core/builder/ServiceBuilder.java | 41 ++ .../core/builder/ServiceBuilderAsync.java | 39 ++ .../scribejava/core/builder/api/Api.java | 20 + .../core/builder/api/DefaultApi10a.java | 133 ++++++ .../core/builder/api/DefaultApi20.java | 65 +++ .../exceptions/OAuthConnectionException.java | 13 + .../core/exceptions/OAuthException.java | 40 ++ .../OAuthParametersMissingException.java | 24 ++ .../exceptions/OAuthSignatureException.java | 23 ++ .../core/extractors/AccessTokenExtractor.java | 19 + .../core/extractors/BaseStringExtractor.java | 23 ++ .../extractors/BaseStringExtractorImpl.java | 45 ++ .../core/extractors/HeaderExtractor.java | 19 + .../core/extractors/HeaderExtractorImpl.java | 54 +++ .../core/extractors/JsonTokenExtractor.java | 27 ++ .../extractors/RequestTokenExtractor.java | 19 + .../core/extractors/TokenExtractor20Impl.java | 36 ++ .../core/extractors/TokenExtractorImpl.java | 43 ++ .../core/model/AbstractRequest.java | 295 +++++++++++++ .../core/model/ForceTypeOfHttpRequest.java | 10 + .../core/model/OAuthAsyncRequestCallback.java | 8 + .../scribejava/core/model/OAuthConfig.java | 106 +++++ .../core/model/OAuthConfigAsync.java | 32 ++ .../scribejava/core/model/OAuthConstants.java | 37 ++ .../scribejava/core/model/OAuthRequest.java | 88 ++++ .../core/model/OAuthRequestAsync.java | 108 +++++ .../scribejava/core/model/Parameter.java | 59 +++ .../scribejava/core/model/ParameterList.java | 101 +++++ .../scribejava/core/model/Response.java | 122 ++++++ .../core/model/ScribeJavaConfig.java | 14 + .../scribejava/core/model/SignatureType.java | 7 + .../github/scribejava/core/model/Token.java | 108 +++++ .../github/scribejava/core/model/Verb.java | 11 + .../scribejava/core/model/Verifier.java | 27 ++ .../core/oauth/OAuth10aServiceImpl.java | 183 ++++++++ .../core/oauth/OAuth20ServiceImpl.java | 109 +++++ .../scribejava/core/oauth/OAuthService.java | 110 +++++ .../core/services/Base64Encoder.java | 29 ++ .../core/services/CommonsEncoder.java | 31 ++ .../services/DatatypeConverterEncoder.java | 16 + .../services/HMACSha1SignatureService.java | 60 +++ .../services/PlaintextSignatureService.java | 37 ++ .../services/RSASha1SignatureService.java | 47 +++ .../core/services/SignatureService.java | 23 ++ .../core/services/TimestampService.java | 25 ++ .../core/services/TimestampServiceImpl.java | 62 +++ .../scribejava/core/utils/MapUtils.java | 24 ++ .../scribejava/core/utils/OAuthEncoder.java | 54 +++ .../scribejava/core/utils/Preconditions.java | 77 ++++ .../scribejava/core/utils/StreamUtils.java | 40 ++ .../github/scribejava/core/ObjectMother.java | 70 ++++ .../core/builder/ServiceBuilderTest.java | 68 +++ .../extractors/BaseStringExtractorTest.java | 102 +++++ .../core/extractors/HeaderExtractorTest.java | 49 +++ .../extractors/JsonTokenExtractorTest.java | 27 ++ .../core/extractors/TokenExtractor20Test.java | 59 +++ .../core/extractors/TokenExtractorTest.java | 73 ++++ .../scribejava/core/model/ConnectionStub.java | 80 ++++ .../model/ForceTypeOfHttpRequestTest.java | 46 +++ .../core/model/OAuthRequestTest.java | 32 ++ .../core/model/ParameterListTest.java | 82 ++++ .../scribejava/core/model/RequestTest.java | 120 ++++++ .../scribejava/core/model/ResponseTest.java | 66 +++ .../scribejava/core/model/TokenTest.java | 50 +++ .../HMACSha1SignatureServiceTest.java | 51 +++ .../services/RSASha1SignatureServiceTest.java | 59 +++ .../core/services/TimestampServiceTest.java | 43 ++ .../scribejava/core/utils/MapUtilsTest.java | 33 ++ .../core/utils/OAuthEncoderTest.java | 63 +++ .../core/utils/PreconditionsTest.java | 73 ++++ .../core/utils/StreamUtilsTest.java | 39 ++ src/main/config/scribe-eclipse-formatter.xml | 290 ------------- src/main/config/scribe-eclipse.importorder | 7 - .../org/scribe/builder/ServiceBuilder.java | 169 -------- .../org/scribe/builder/api/AWeberApi.java | 28 -- src/main/java/org/scribe/builder/api/Api.java | 25 -- .../builder/api/ConstantContactApi.java | 26 -- .../builder/api/ConstantContactApi2.java | 55 --- .../org/scribe/builder/api/DefaultApi10a.java | 141 ------- .../org/scribe/builder/api/DefaultApi20.java | 70 ---- .../java/org/scribe/builder/api/DiggApi.java | 29 -- .../org/scribe/builder/api/DropBoxApi.java | 25 -- .../org/scribe/builder/api/EvernoteApi.java | 55 --- .../org/scribe/builder/api/FacebookApi.java | 33 -- .../org/scribe/builder/api/FlickrApi.java | 40 -- .../scribe/builder/api/Foursquare2Api.java | 29 -- .../org/scribe/builder/api/FoursquareApi.java | 26 -- .../org/scribe/builder/api/FreelancerApi.java | 61 --- .../org/scribe/builder/api/GetGlueApi.java | 29 -- .../org/scribe/builder/api/GoogleApi.java | 38 -- .../java/org/scribe/builder/api/ImgUrApi.java | 32 -- .../org/scribe/builder/api/KaixinApi.java | 40 -- .../org/scribe/builder/api/KaixinApi20.java | 41 -- .../org/scribe/builder/api/LinkedInApi.java | 57 --- .../java/org/scribe/builder/api/LiveApi.java | 40 -- .../org/scribe/builder/api/LoveFilmApi.java | 28 -- .../org/scribe/builder/api/MeetupApi.java | 30 -- .../org/scribe/builder/api/MendeleyApi.java | 43 -- .../java/org/scribe/builder/api/MisoApi.java | 29 -- .../org/scribe/builder/api/NetProspexApi.java | 28 -- .../scribe/builder/api/NeteaseWeibooApi.java | 47 --- .../java/org/scribe/builder/api/PlurkApi.java | 39 -- .../java/org/scribe/builder/api/Px500Api.java | 26 -- .../org/scribe/builder/api/QWeiboApi.java | 28 -- .../org/scribe/builder/api/RenrenApi.java | 40 -- .../java/org/scribe/builder/api/SapoApi.java | 40 -- .../org/scribe/builder/api/SimpleGeoApi.java | 29 -- .../org/scribe/builder/api/SinaWeiboApi.java | 28 -- .../scribe/builder/api/SinaWeiboApi20.java | 46 --- .../org/scribe/builder/api/SkyrockApi.java | 35 -- .../org/scribe/builder/api/SohuWeiboApi.java | 28 -- .../org/scribe/builder/api/TrelloApi.java | 27 -- .../org/scribe/builder/api/TumblrApi.java | 28 -- .../org/scribe/builder/api/TwitterApi.java | 42 -- .../org/scribe/builder/api/UbuntuOneApi.java | 40 -- .../org/scribe/builder/api/ViadeoApi.java | 42 -- .../java/org/scribe/builder/api/VimeoApi.java | 26 -- .../org/scribe/builder/api/VkontakteApi.java | 41 -- .../java/org/scribe/builder/api/XingApi.java | 27 -- .../java/org/scribe/builder/api/YahooApi.java | 26 -- .../exceptions/OAuthConnectionException.java | 14 - .../org/scribe/exceptions/OAuthException.java | 33 -- .../OAuthParametersMissingException.java | 26 -- .../exceptions/OAuthSignatureException.java | 24 -- .../extractors/AccessTokenExtractor.java | 19 - .../extractors/BaseStringExtractor.java | 21 - .../extractors/BaseStringExtractorImpl.java | 48 --- .../scribe/extractors/HeaderExtractor.java | 19 - .../extractors/HeaderExtractorImpl.java | 58 --- .../scribe/extractors/JsonTokenExtractor.java | 27 -- .../extractors/RequestTokenExtractor.java | 19 - .../extractors/TokenExtractor20Impl.java | 35 -- .../scribe/extractors/TokenExtractorImpl.java | 44 -- .../java/org/scribe/model/OAuthConfig.java | 79 ---- .../java/org/scribe/model/OAuthConstants.java | 37 -- .../java/org/scribe/model/OAuthRequest.java | 80 ---- src/main/java/org/scribe/model/Parameter.java | 47 --- .../java/org/scribe/model/ParameterList.java | 114 ----- src/main/java/org/scribe/model/Request.java | 390 ------------------ .../java/org/scribe/model/RequestTuner.java | 6 - src/main/java/org/scribe/model/Response.java | 126 ------ .../java/org/scribe/model/SignatureType.java | 7 - src/main/java/org/scribe/model/Token.java | 115 ------ src/main/java/org/scribe/model/Verb.java | 11 - src/main/java/org/scribe/model/Verifier.java | 30 -- .../org/scribe/oauth/OAuth10aServiceImpl.java | 196 --------- .../org/scribe/oauth/OAuth20ServiceImpl.java | 72 ---- .../java/org/scribe/oauth/OAuthService.java | 53 --- .../org/scribe/services/Base64Encoder.java | 36 -- .../org/scribe/services/CommonsEncoder.java | 42 -- .../services/DatatypeConverterEncoder.java | 18 - .../services/HMACSha1SignatureService.java | 61 --- .../services/PlaintextSignatureService.java | 40 -- .../services/RSASha1SignatureService.java | 52 --- .../org/scribe/services/SignatureService.java | 28 -- .../org/scribe/services/TimestampService.java | 25 -- .../scribe/services/TimestampServiceImpl.java | 68 --- src/main/java/org/scribe/utils/MapUtils.java | 24 -- .../java/org/scribe/utils/OAuthEncoder.java | 64 --- .../java/org/scribe/utils/Preconditions.java | 88 ---- .../java/org/scribe/utils/StreamUtils.java | 44 -- .../scribe/builder/ServiceBuilderTest.java | 73 ---- .../org/scribe/examples/AWeberExample.java | 65 --- .../java/org/scribe/examples/DiggExample.java | 65 --- .../org/scribe/examples/FacebookExample.java | 64 --- .../org/scribe/examples/FlickrExample.java | 60 --- .../scribe/examples/Foursquare2Example.java | 63 --- .../scribe/examples/FoursquareExample.java | 59 --- .../scribe/examples/FreelancerExample.java | 66 --- .../org/scribe/examples/GoogleExample.java | 66 --- .../org/scribe/examples/ImgUrExample.java | 58 --- .../org/scribe/examples/Kaixin20Example.java | 63 --- .../org/scribe/examples/LinkedInExample.java | 59 --- .../examples/LinkedInExampleWithScopes.java | 59 --- .../java/org/scribe/examples/LiveExample.java | 64 --- .../org/scribe/examples/LoveFilmExample.java | 64 --- .../org/scribe/examples/MeetupExample.java | 62 --- .../scribe/examples/NeteaseWeiboExample.java | 68 --- .../org/scribe/examples/Px500Example.java | 60 --- .../org/scribe/examples/RenrenExample.java | 108 ----- .../scribe/examples/SinaWeibo2Example.java | 63 --- .../org/scribe/examples/SinaWeiboExample.java | 68 --- .../org/scribe/examples/SkyrockExample.java | 61 --- .../org/scribe/examples/SohuWeiboExample.java | 68 --- .../org/scribe/examples/TrelloExample.java | 60 --- .../org/scribe/examples/TumblrExample.java | 62 --- .../org/scribe/examples/TwitterExample.java | 60 --- .../org/scribe/examples/ViadeoExample.java | 64 --- .../org/scribe/examples/VkontakteExample.java | 68 --- .../java/org/scribe/examples/XingExample.java | 59 --- .../org/scribe/examples/YahooExample.java | 60 --- .../extractors/BaseStringExtractorTest.java | 102 ----- .../extractors/HeaderExtractorTest.java | 49 --- .../extractors/JsonTokenExtractorTest.java | 31 -- .../extractors/TokenExtractor20Test.java | 67 --- .../scribe/extractors/TokenExtractorTest.java | 83 ---- .../java/org/scribe/model/ConnectionStub.java | 86 ---- .../org/scribe/model/OAuthRequestTest.java | 35 -- .../org/scribe/model/ParameterListTest.java | 91 ---- .../java/org/scribe/model/RequestTest.java | 128 ------ .../java/org/scribe/model/ResponseTest.java | 75 ---- src/test/java/org/scribe/model/TokenTest.java | 54 --- .../HMACSha1SignatureServiceTest.java | 59 --- .../services/RSASha1SignatureServiceTest.java | 67 --- .../scribe/services/TimestampServiceTest.java | 50 --- .../org/scribe/test/helpers/ObjectMother.java | 67 --- .../java/org/scribe/utils/MapUtilsTest.java | 35 -- .../org/scribe/utils/OAuthEncoderTest.java | 70 ---- .../org/scribe/utils/PreconditionsTest.java | 87 ---- .../org/scribe/utils/StreamUtilsTest.java | 47 --- changelog.txt => v1-changelog | 0 v2pre-changelog | 57 +++ 321 files changed, 9324 insertions(+), 8011 deletions(-) delete mode 100644 .travis.yml delete mode 100755 bundle create mode 100644 changelog create mode 100644 scribejava-apis/pom.xml create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/AWeberApi.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/ConstantContactApi.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/ConstantContactApi2.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/DiggApi.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/DoktornaraboteApi.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/DropBoxApi.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/EvernoteApi.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/FlickrApi.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/Foursquare2Api.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/FoursquareApi.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/FreelancerApi.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/GetGlueApi.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/GitHubApi.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/GoogleApi.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/GoogleApi20.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/HHApi.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/ImgUrApi.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/KaixinApi.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/KaixinApi20.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi20.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/LiveApi.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/LoveFilmApi.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/MeetupApi.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/MendeleyApi.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/MisoApi.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/NetProspexApi.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/NeteaseWeibooApi.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/PlurkApi.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/Px500Api.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/QWeiboApi.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/RenrenApi.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/SapoApi.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/SimpleGeoApi.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/SinaWeiboApi.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/SinaWeiboApi20.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/SkyrockApi.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/SohuWeiboApi.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/TrelloApi.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/TumblrApi.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/TutByApi.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/TwitterApi.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/UbuntuOneApi.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/ViadeoApi.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/VimeoApi.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/VkontakteApi.java create mode 100755 scribejava-apis/src/main/java/com/github/scribejava/apis/XingApi.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/YahooApi.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/YammerApi.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/google/GoogleJsonTokenExtractor.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/google/GoogleToken.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/service/DoktornaraboteOAuthServiceImpl.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/service/GoogleOAuthServiceImpl.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/service/HHOAuthServiceImpl.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/service/LinkedIn20ServiceImpl.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthServiceImpl.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiServiceImpl.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/service/TutByOAuthServiceImpl.java create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AWeberExample.java create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiggExample.java create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncExample.java create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExample.java create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FoursquareExample.java create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubExample.java create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GoogleExample.java create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HHExample.java create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ImgUrExample.java create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Kaixin20Example.java create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedIn20Example.java create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LoveFilmExample.java create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NeteaseWeiboExample.java create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Px500Example.java create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeibo2Example.java create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeiboExample.java create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SkyrockExample.java create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SohuWeiboExample.java create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TrelloExample.java create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TumblrExample.java create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TutByExample.java create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TwitterExample.java create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ViadeoExample.java create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExample.java create mode 100755 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XingExample.java create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/YahooExample.java create mode 100644 scribejava-core/pom.xml create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/builder/AbstractServiceBuilder.java create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilder.java create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilderAsync.java create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/builder/api/Api.java create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi10a.java create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/exceptions/OAuthConnectionException.java create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/exceptions/OAuthException.java create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/exceptions/OAuthParametersMissingException.java create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/exceptions/OAuthSignatureException.java create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/extractors/AccessTokenExtractor.java create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/extractors/BaseStringExtractor.java create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/extractors/BaseStringExtractorImpl.java create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/extractors/HeaderExtractor.java create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/extractors/HeaderExtractorImpl.java create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/extractors/JsonTokenExtractor.java create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/extractors/RequestTokenExtractor.java create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/extractors/TokenExtractor20Impl.java create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/extractors/TokenExtractorImpl.java create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/model/AbstractRequest.java create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/model/ForceTypeOfHttpRequest.java create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthAsyncRequestCallback.java create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConfig.java create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConfigAsync.java create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConstants.java create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequest.java create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequestAsync.java create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/model/Parameter.java create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/model/ParameterList.java create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/model/Response.java create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/model/ScribeJavaConfig.java create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/model/SignatureType.java create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/model/Token.java create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/model/Verb.java create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/model/Verifier.java create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aServiceImpl.java create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20ServiceImpl.java create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/services/Base64Encoder.java create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/services/CommonsEncoder.java create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/services/DatatypeConverterEncoder.java create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/services/HMACSha1SignatureService.java create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/services/PlaintextSignatureService.java create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/services/RSASha1SignatureService.java create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/services/SignatureService.java create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/services/TimestampService.java create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/services/TimestampServiceImpl.java create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/utils/MapUtils.java create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/utils/OAuthEncoder.java create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/utils/Preconditions.java create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/utils/StreamUtils.java create mode 100644 scribejava-core/src/test/java/com/github/scribejava/core/ObjectMother.java create mode 100644 scribejava-core/src/test/java/com/github/scribejava/core/builder/ServiceBuilderTest.java create mode 100644 scribejava-core/src/test/java/com/github/scribejava/core/extractors/BaseStringExtractorTest.java create mode 100644 scribejava-core/src/test/java/com/github/scribejava/core/extractors/HeaderExtractorTest.java create mode 100644 scribejava-core/src/test/java/com/github/scribejava/core/extractors/JsonTokenExtractorTest.java create mode 100644 scribejava-core/src/test/java/com/github/scribejava/core/extractors/TokenExtractor20Test.java create mode 100644 scribejava-core/src/test/java/com/github/scribejava/core/extractors/TokenExtractorTest.java create mode 100644 scribejava-core/src/test/java/com/github/scribejava/core/model/ConnectionStub.java create mode 100644 scribejava-core/src/test/java/com/github/scribejava/core/model/ForceTypeOfHttpRequestTest.java create mode 100644 scribejava-core/src/test/java/com/github/scribejava/core/model/OAuthRequestTest.java create mode 100644 scribejava-core/src/test/java/com/github/scribejava/core/model/ParameterListTest.java create mode 100644 scribejava-core/src/test/java/com/github/scribejava/core/model/RequestTest.java create mode 100644 scribejava-core/src/test/java/com/github/scribejava/core/model/ResponseTest.java create mode 100644 scribejava-core/src/test/java/com/github/scribejava/core/model/TokenTest.java create mode 100644 scribejava-core/src/test/java/com/github/scribejava/core/services/HMACSha1SignatureServiceTest.java create mode 100644 scribejava-core/src/test/java/com/github/scribejava/core/services/RSASha1SignatureServiceTest.java create mode 100644 scribejava-core/src/test/java/com/github/scribejava/core/services/TimestampServiceTest.java create mode 100644 scribejava-core/src/test/java/com/github/scribejava/core/utils/MapUtilsTest.java create mode 100644 scribejava-core/src/test/java/com/github/scribejava/core/utils/OAuthEncoderTest.java create mode 100644 scribejava-core/src/test/java/com/github/scribejava/core/utils/PreconditionsTest.java create mode 100644 scribejava-core/src/test/java/com/github/scribejava/core/utils/StreamUtilsTest.java delete mode 100644 src/main/config/scribe-eclipse-formatter.xml delete mode 100644 src/main/config/scribe-eclipse.importorder delete mode 100644 src/main/java/org/scribe/builder/ServiceBuilder.java delete mode 100644 src/main/java/org/scribe/builder/api/AWeberApi.java delete mode 100644 src/main/java/org/scribe/builder/api/Api.java delete mode 100644 src/main/java/org/scribe/builder/api/ConstantContactApi.java delete mode 100644 src/main/java/org/scribe/builder/api/ConstantContactApi2.java delete mode 100644 src/main/java/org/scribe/builder/api/DefaultApi10a.java delete mode 100644 src/main/java/org/scribe/builder/api/DefaultApi20.java delete mode 100644 src/main/java/org/scribe/builder/api/DiggApi.java delete mode 100644 src/main/java/org/scribe/builder/api/DropBoxApi.java delete mode 100644 src/main/java/org/scribe/builder/api/EvernoteApi.java delete mode 100644 src/main/java/org/scribe/builder/api/FacebookApi.java delete mode 100644 src/main/java/org/scribe/builder/api/FlickrApi.java delete mode 100644 src/main/java/org/scribe/builder/api/Foursquare2Api.java delete mode 100644 src/main/java/org/scribe/builder/api/FoursquareApi.java delete mode 100644 src/main/java/org/scribe/builder/api/FreelancerApi.java delete mode 100644 src/main/java/org/scribe/builder/api/GetGlueApi.java delete mode 100644 src/main/java/org/scribe/builder/api/GoogleApi.java delete mode 100644 src/main/java/org/scribe/builder/api/ImgUrApi.java delete mode 100644 src/main/java/org/scribe/builder/api/KaixinApi.java delete mode 100644 src/main/java/org/scribe/builder/api/KaixinApi20.java delete mode 100644 src/main/java/org/scribe/builder/api/LinkedInApi.java delete mode 100644 src/main/java/org/scribe/builder/api/LiveApi.java delete mode 100644 src/main/java/org/scribe/builder/api/LoveFilmApi.java delete mode 100644 src/main/java/org/scribe/builder/api/MeetupApi.java delete mode 100644 src/main/java/org/scribe/builder/api/MendeleyApi.java delete mode 100644 src/main/java/org/scribe/builder/api/MisoApi.java delete mode 100644 src/main/java/org/scribe/builder/api/NetProspexApi.java delete mode 100644 src/main/java/org/scribe/builder/api/NeteaseWeibooApi.java delete mode 100644 src/main/java/org/scribe/builder/api/PlurkApi.java delete mode 100644 src/main/java/org/scribe/builder/api/Px500Api.java delete mode 100644 src/main/java/org/scribe/builder/api/QWeiboApi.java delete mode 100644 src/main/java/org/scribe/builder/api/RenrenApi.java delete mode 100644 src/main/java/org/scribe/builder/api/SapoApi.java delete mode 100644 src/main/java/org/scribe/builder/api/SimpleGeoApi.java delete mode 100644 src/main/java/org/scribe/builder/api/SinaWeiboApi.java delete mode 100644 src/main/java/org/scribe/builder/api/SinaWeiboApi20.java delete mode 100644 src/main/java/org/scribe/builder/api/SkyrockApi.java delete mode 100644 src/main/java/org/scribe/builder/api/SohuWeiboApi.java delete mode 100644 src/main/java/org/scribe/builder/api/TrelloApi.java delete mode 100644 src/main/java/org/scribe/builder/api/TumblrApi.java delete mode 100644 src/main/java/org/scribe/builder/api/TwitterApi.java delete mode 100644 src/main/java/org/scribe/builder/api/UbuntuOneApi.java delete mode 100644 src/main/java/org/scribe/builder/api/ViadeoApi.java delete mode 100644 src/main/java/org/scribe/builder/api/VimeoApi.java delete mode 100644 src/main/java/org/scribe/builder/api/VkontakteApi.java delete mode 100755 src/main/java/org/scribe/builder/api/XingApi.java delete mode 100644 src/main/java/org/scribe/builder/api/YahooApi.java delete mode 100644 src/main/java/org/scribe/exceptions/OAuthConnectionException.java delete mode 100644 src/main/java/org/scribe/exceptions/OAuthException.java delete mode 100644 src/main/java/org/scribe/exceptions/OAuthParametersMissingException.java delete mode 100644 src/main/java/org/scribe/exceptions/OAuthSignatureException.java delete mode 100644 src/main/java/org/scribe/extractors/AccessTokenExtractor.java delete mode 100644 src/main/java/org/scribe/extractors/BaseStringExtractor.java delete mode 100644 src/main/java/org/scribe/extractors/BaseStringExtractorImpl.java delete mode 100644 src/main/java/org/scribe/extractors/HeaderExtractor.java delete mode 100644 src/main/java/org/scribe/extractors/HeaderExtractorImpl.java delete mode 100644 src/main/java/org/scribe/extractors/JsonTokenExtractor.java delete mode 100644 src/main/java/org/scribe/extractors/RequestTokenExtractor.java delete mode 100644 src/main/java/org/scribe/extractors/TokenExtractor20Impl.java delete mode 100644 src/main/java/org/scribe/extractors/TokenExtractorImpl.java delete mode 100644 src/main/java/org/scribe/model/OAuthConfig.java delete mode 100644 src/main/java/org/scribe/model/OAuthConstants.java delete mode 100644 src/main/java/org/scribe/model/OAuthRequest.java delete mode 100644 src/main/java/org/scribe/model/Parameter.java delete mode 100644 src/main/java/org/scribe/model/ParameterList.java delete mode 100644 src/main/java/org/scribe/model/Request.java delete mode 100644 src/main/java/org/scribe/model/RequestTuner.java delete mode 100644 src/main/java/org/scribe/model/Response.java delete mode 100644 src/main/java/org/scribe/model/SignatureType.java delete mode 100644 src/main/java/org/scribe/model/Token.java delete mode 100644 src/main/java/org/scribe/model/Verb.java delete mode 100644 src/main/java/org/scribe/model/Verifier.java delete mode 100644 src/main/java/org/scribe/oauth/OAuth10aServiceImpl.java delete mode 100644 src/main/java/org/scribe/oauth/OAuth20ServiceImpl.java delete mode 100644 src/main/java/org/scribe/oauth/OAuthService.java delete mode 100644 src/main/java/org/scribe/services/Base64Encoder.java delete mode 100644 src/main/java/org/scribe/services/CommonsEncoder.java delete mode 100644 src/main/java/org/scribe/services/DatatypeConverterEncoder.java delete mode 100644 src/main/java/org/scribe/services/HMACSha1SignatureService.java delete mode 100644 src/main/java/org/scribe/services/PlaintextSignatureService.java delete mode 100644 src/main/java/org/scribe/services/RSASha1SignatureService.java delete mode 100644 src/main/java/org/scribe/services/SignatureService.java delete mode 100644 src/main/java/org/scribe/services/TimestampService.java delete mode 100644 src/main/java/org/scribe/services/TimestampServiceImpl.java delete mode 100644 src/main/java/org/scribe/utils/MapUtils.java delete mode 100644 src/main/java/org/scribe/utils/OAuthEncoder.java delete mode 100644 src/main/java/org/scribe/utils/Preconditions.java delete mode 100644 src/main/java/org/scribe/utils/StreamUtils.java delete mode 100644 src/test/java/org/scribe/builder/ServiceBuilderTest.java delete mode 100644 src/test/java/org/scribe/examples/AWeberExample.java delete mode 100644 src/test/java/org/scribe/examples/DiggExample.java delete mode 100644 src/test/java/org/scribe/examples/FacebookExample.java delete mode 100644 src/test/java/org/scribe/examples/FlickrExample.java delete mode 100644 src/test/java/org/scribe/examples/Foursquare2Example.java delete mode 100644 src/test/java/org/scribe/examples/FoursquareExample.java delete mode 100644 src/test/java/org/scribe/examples/FreelancerExample.java delete mode 100644 src/test/java/org/scribe/examples/GoogleExample.java delete mode 100644 src/test/java/org/scribe/examples/ImgUrExample.java delete mode 100644 src/test/java/org/scribe/examples/Kaixin20Example.java delete mode 100644 src/test/java/org/scribe/examples/LinkedInExample.java delete mode 100644 src/test/java/org/scribe/examples/LinkedInExampleWithScopes.java delete mode 100644 src/test/java/org/scribe/examples/LiveExample.java delete mode 100644 src/test/java/org/scribe/examples/LoveFilmExample.java delete mode 100644 src/test/java/org/scribe/examples/MeetupExample.java delete mode 100644 src/test/java/org/scribe/examples/NeteaseWeiboExample.java delete mode 100644 src/test/java/org/scribe/examples/Px500Example.java delete mode 100644 src/test/java/org/scribe/examples/RenrenExample.java delete mode 100644 src/test/java/org/scribe/examples/SinaWeibo2Example.java delete mode 100644 src/test/java/org/scribe/examples/SinaWeiboExample.java delete mode 100644 src/test/java/org/scribe/examples/SkyrockExample.java delete mode 100644 src/test/java/org/scribe/examples/SohuWeiboExample.java delete mode 100644 src/test/java/org/scribe/examples/TrelloExample.java delete mode 100644 src/test/java/org/scribe/examples/TumblrExample.java delete mode 100644 src/test/java/org/scribe/examples/TwitterExample.java delete mode 100644 src/test/java/org/scribe/examples/ViadeoExample.java delete mode 100644 src/test/java/org/scribe/examples/VkontakteExample.java delete mode 100755 src/test/java/org/scribe/examples/XingExample.java delete mode 100644 src/test/java/org/scribe/examples/YahooExample.java delete mode 100644 src/test/java/org/scribe/extractors/BaseStringExtractorTest.java delete mode 100644 src/test/java/org/scribe/extractors/HeaderExtractorTest.java delete mode 100644 src/test/java/org/scribe/extractors/JsonTokenExtractorTest.java delete mode 100644 src/test/java/org/scribe/extractors/TokenExtractor20Test.java delete mode 100644 src/test/java/org/scribe/extractors/TokenExtractorTest.java delete mode 100644 src/test/java/org/scribe/model/ConnectionStub.java delete mode 100644 src/test/java/org/scribe/model/OAuthRequestTest.java delete mode 100644 src/test/java/org/scribe/model/ParameterListTest.java delete mode 100644 src/test/java/org/scribe/model/RequestTest.java delete mode 100644 src/test/java/org/scribe/model/ResponseTest.java delete mode 100644 src/test/java/org/scribe/model/TokenTest.java delete mode 100644 src/test/java/org/scribe/services/HMACSha1SignatureServiceTest.java delete mode 100644 src/test/java/org/scribe/services/RSASha1SignatureServiceTest.java delete mode 100644 src/test/java/org/scribe/services/TimestampServiceTest.java delete mode 100644 src/test/java/org/scribe/test/helpers/ObjectMother.java delete mode 100644 src/test/java/org/scribe/utils/MapUtilsTest.java delete mode 100644 src/test/java/org/scribe/utils/OAuthEncoderTest.java delete mode 100644 src/test/java/org/scribe/utils/PreconditionsTest.java delete mode 100644 src/test/java/org/scribe/utils/StreamUtilsTest.java rename changelog.txt => v1-changelog (100%) create mode 100644 v2pre-changelog diff --git a/.gitignore b/.gitignore index a9a50de0e..5c3b031d8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,15 +1,15 @@ - # Eclipse specific settings - .classpath .project .settings # IntelliJ Idea settings - .idea -scribe.iml +*.iml -# Binaries +# Netbeans settings +nb-configuration.xml +nbproject -target \ No newline at end of file +# Binaries +target diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 2e6f88bae..000000000 --- a/.travis.yml +++ /dev/null @@ -1,11 +0,0 @@ -# kickstart travis. -language: java -before_install: sudo pip install codecov -after_success: codecov - -# need to override travis 'install' since it will try gpg sign and fail. -install: mvn clean package -DskipTests=true - -branches: - except: - - mvn-repo diff --git a/LICENSE.txt b/LICENSE.txt index 53b46da96..8cde51fa9 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,5 +1,6 @@ The MIT License +Copyright (c) 2013 hh.ru Copyright (c) 2010 Pablo Fernandez Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/README.md b/README.md index af585c643..6859f94ad 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,10 @@ -# Welcome to the home of Scribe, the simple OAuth Java lib! +# Welcome to the home of ScribeJava, the simple OAuth Java lib! -![travis ci](https://secure.travis-ci.org/fernandezpablo85/scribe-java.png?branch=master) -[![codecov.io](https://codecov.io/github/fernandezpablo85/scribe-java/coverage.svg?branch=master)](https://codecov.io/github/fernandezpablo85/scribe-java?branch=master) - -### Before submitting a pull request [please read this](https://github.com/fernandezpablo85/scribe-java/wiki/Scribe-scope-revised) - -# Why use Scribe? +# Why use ScribeJava? ### Dead Simple -Who said OAuth was difficult? Configuring scribe is __so easy your grandma can do it__! check it out: +Who said OAuth/OAuth2 was difficult? Configuring scribe is __so easy your grandma can do it__! check it out: ```java OAuthService service = new ServiceBuilder() @@ -23,7 +18,11 @@ That **single line** (added newlines for readability) is the only thing you need ### Threadsafe -Hit Scribe as hard and with many threads as you like. +Hit ScribeJava as hard and with many threads as you like. + +### Async + +You can user ning async http client out-of-box, just use ServiceBuilderAsync ### Supports all major 1.0a and 2.0 OAuth APIs out-of-the-box @@ -45,11 +44,22 @@ Hit Scribe as hard and with many threads as you like. * Windows Live -* and many more! check the [examples folder](http://github.com/fernandezpablo85/scribe-java/tree/master/src/test/java/org/scribe/examples) +* Odnoklassniki + +* Mail.ru + +* LinkedIn2.0 + +* Google2.0 + +* GitHub + +* and many more! check the [examples folder](http://github.com/scribejava/scribejava/tree/master/src/test/java/com/github/scribejava/apis/examples) ### Small and modular -Scribe's code is small (about 1k LOC) and simple to understand. No smart-ass or "clever" hacks here. +ScribeJava's code is small (about 1k LOC) and simple to understand. No smart-ass or "clever" hacks here. +You can use only 'core' or 'with apis' maven modules ### Android-Ready @@ -59,52 +69,41 @@ Works out of the box with android(TM) applications. Good test coverage to keep you safe from harm. -When something bad actually happens, Scribe's meaningful error messages will tell you exactly what went wrong, when and where. +When something bad actually happens, ScribeJava's meaningful error messages will tell you exactly what went wrong, when and where. -### Pull it from Maven! +### Pull it from Maven Central! -You can pull scribe from my maven repository, just add these to your __pom.xml__ file: +You can pull ScribeJava from the central maven repository, just add these to your __pom.xml__ file: ```xml + + com.github.scribejava + scribejava-apis + 2.0 + +``` - - - - scribe-java-mvn-repo - https://raw.github.com/fernandezpablo85/scribe-java/mvn-repo/ - - true - always - - - - - +And in case you need just core classes (that's it, without any external API (FB, VK, GitHub, Google etc) specific code), you could pull just 'core' artifact. +```xml - org.scribe - scribe - 1.3.6 + com.github.scribejava + scribejava-core + 2.0 ``` ## Getting started in less than 2 minutes -Check the [Getting Started](http://wiki.github.com/fernandezpablo85/scribe-java/getting-started) page and start rocking! Please Read the [FAQ](http://wiki.github.com/fernandezpablo85/scribe-java/faq) before creating an issue :) +Check the [Getting Started](https://github.com/scribejava/scribejava/wiki/getting-started) page and start rocking! Please Read the [FAQ](https://github.com/scribejava/scribejava/wiki/faq) before creating an issue :) Also, remember to read the [fantastic tutorial](http://akoskm.github.io/2015/07/31/twitter-sign-in-for-web-apps.html) that [@akoskm](https://twitter.com/akoskm) wrote to easily integrate a server side app with an API (twitter in this case). ## Questions? -Feel free to drop me an email, but there's already a [StackOverflow](http://stackoverflow.com) tag for [scribe](http://stackoverflow.com/questions/tagged/scribe) you should use. I'm subscribed to it so I'll pick the question immediately. +Feel free to drop us an email or create issue right here on github.com ## Forks -Looking for a scribe variation? check the [Fork List](https://github.com/fernandezpablo85/scribe-java/wiki/Forks) - -If you have a useful fork that should be listed there please contact me (see About me). - -## About me - -[LinkedIn profile](http://www.linkedin.com/in/fernandezpablo85) +Looking for a ScribeJava variation? check the [Fork List](https://github.com/scribejava/scribejava/wiki/Forks) -Follow me: [@fernandezpablo](http://twitter.com/fernandezpablo) +If you have a useful fork that should be listed there please contact us diff --git a/bundle b/bundle deleted file mode 100755 index bae51557d..000000000 --- a/bundle +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -mvn source:jar javadoc:jar package gpg:sign repository:bundle-create -Dgpg.passphrase=$1 \ No newline at end of file diff --git a/changelog b/changelog new file mode 100644 index 000000000..4a9ebddf5 --- /dev/null +++ b/changelog @@ -0,0 +1,7 @@ +[2.0] + * merge back SubScribe fork to the ScribeJava + +for previous changes see +v1-changelog - changelog for 1.x version +v2pre-changelog - changelog for SubScribe fork + diff --git a/pom.xml b/pom.xml index 3f0d6da56..bdad5d555 100644 --- a/pom.xml +++ b/pom.xml @@ -1,167 +1,198 @@ - - 4.0.0 - org.scribe - scribe - jar - 1.3.7 - Scribe OAuth Library - The best OAuth library out there - http://github.com/fernandezpablo85/scribe-java + + 4.0.0 + com.github.scribejava + scribejava + pom + 2.0-SNAPSHOT + ScribeJava OAuth Library + The best OAuth library out there + https://github.com/scribejava/scribejava - - org.sonatype.oss - oss-parent - 5 - + + org.sonatype.oss + oss-parent + 9 + - - github - + + scribejava-core + scribejava-apis + - - - fernandezpablo85 - Pablo Fernandez - fernandezpablo85@gmail.com - -3 - - + + + MIT + https://github.com/scribejava/scribejava/blob/master/LICENSE.txt + + - - - MIT - http://github.com/fernandezpablo85/scribe-java/blob/master/LICENSE.txt - - + + scm:git:git://github.com/scribejava/scribejava.git + scm:git:git@github.com:scribejava/scribejava.git + https://github.com/scribejava/scribejava + - - scm:http://github.com/fernandezpablo85/scribe-java.git - scm:http://github.com/fernandezpablo85/scribe-java.git - http://github.com/fernandezpablo85/scribe-java.git - + + + kullfar + Stas Gromov + s.gromov@hh.ru + hh.ru + http://hh.ru + + all + + +3 + + kullfar@jabber.ru + kullfar@gmail.com + +7-909-677-11-16 + + + + chernatkin + Sergey Chernatkin + s.chernatkin@hh.ru + hh.ru + http://hh.ru + + all + + +3 + + + igaranina + Irina Garanina + i.garanina@hh.ru + hh.ru + http://hh.ru + + all + + +3 + + - - - internal.repo - Temporary Staging Repository - file://${project.build.directory}/mvn-repo - - - - - - org.hamcrest - hamcrest-junit - 2.0.0.0 - test - - - junit - junit - 4.8.1 - test - - - commons-codec - commons-codec - 1.4 - compile - true - - - - - - maven-compiler-plugin - 3.0 - - 1.5 - 1.5 - - - - org.apache.maven.plugins - maven-source-plugin - - - attach-sources - - jar - - - - - - org.apache.maven.plugins - maven-javadoc-plugin - - - attach-javadocs - - jar - - - - - - com.github.github - site-maven-plugin - 0.9 - - Maven artifacts for ${project.version} - true - ${project.build.directory}/mvn-repo - refs/heads/mvn-repo - **/* - scribe-java - fernandezpablo85 - - - - - site - - deploy - - - - - org.codehaus.mojo - findbugs-maven-plugin - 3.0.0 - - - failing-on-high - compile - - check - - - Low - - - - - - org.jacoco - jacoco-maven-plugin - 0.5.8.201207111220 - - - - prepare-agent - - - - report - test - - report - - - - - - - + + + junit + junit + 4.12 + test + + + commons-codec + commons-codec + 1.10 + compile + true + + + com.ning + async-http-client + 1.9.31 + provided + + + + + + org.apache.maven.wagon + wagon-webdav + 1.0-beta-2 + + + + + maven-compiler-plugin + 3.3 + + UTF-8 + 1.7 + 1.7 + true + + + + maven-deploy-plugin + 2.8.2 + + + default-deploy + deploy + + deploy + + + + + + org.apache.maven.plugins + maven-resources-plugin + 2.7 + + UTF-8 + + + + org.apache.maven.plugins + maven-source-plugin + 2.4 + + + attach-sources + + jar + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 2.10.3 + + UTF-8 + + + + attach-javadoc + + jar + + + + + + + + + + release-sign-artifacts + + + performRelease + true + + + + + + org.apache.maven.plugins + maven-gpg-plugin + 1.6 + + + sign-artifacts + verify + + sign + + + + + + + + + diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml new file mode 100644 index 000000000..701bd7f82 --- /dev/null +++ b/scribejava-apis/pom.xml @@ -0,0 +1,46 @@ + + + 4.0.0 + + + com.github.scribejava + scribejava + 2.0-SNAPSHOT + ../pom.xml + + + com.github.scribejava + scribejava-apis + ScribeJava APIs + jar + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.3 + + true + + + + org.apache.maven.plugins + maven-resources-plugin + 2.7 + + UTF-8 + + + + + + + + com.github.scribejava + scribejava-core + ${project.version} + + + + diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/AWeberApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/AWeberApi.java new file mode 100644 index 000000000..06a1ecc69 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/AWeberApi.java @@ -0,0 +1,26 @@ +package com.github.scribejava.apis; + +import com.github.scribejava.core.builder.api.DefaultApi10a; +import com.github.scribejava.core.model.Token; + +public class AWeberApi extends DefaultApi10a { + + private static final String AUTHORIZE_URL = "https://auth.aweber.com/1.0/oauth/authorize?oauth_token=%s"; + private static final String REQUEST_TOKEN_ENDPOINT = "https://auth.aweber.com/1.0/oauth/request_token"; + private static final String ACCESS_TOKEN_ENDPOINT = "https://auth.aweber.com/1.0/oauth/access_token"; + + @Override + public String getAccessTokenEndpoint() { + return ACCESS_TOKEN_ENDPOINT; + } + + @Override + public String getRequestTokenEndpoint() { + return REQUEST_TOKEN_ENDPOINT; + } + + @Override + public String getAuthorizationUrl(Token requestToken) { + return String.format(AUTHORIZE_URL, requestToken.getToken()); + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/ConstantContactApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/ConstantContactApi.java new file mode 100644 index 000000000..d20b9a5e0 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/ConstantContactApi.java @@ -0,0 +1,24 @@ +package com.github.scribejava.apis; + +import com.github.scribejava.core.builder.api.DefaultApi10a; +import com.github.scribejava.core.model.Token; + +public class ConstantContactApi extends DefaultApi10a { + + private static final String AUTHORIZE_URL = "https://oauth.constantcontact.com/ws/oauth/confirm_access?oauth_token=%s"; + + @Override + public String getAccessTokenEndpoint() { + return "https://oauth.constantcontact.com/ws/oauth/access_token"; + } + + @Override + public String getAuthorizationUrl(Token requestToken) { + return String.format(AUTHORIZE_URL, requestToken.getToken()); + } + + @Override + public String getRequestTokenEndpoint() { + return "https://oauth.constantcontact.com/ws/oauth/request_token"; + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/ConstantContactApi2.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/ConstantContactApi2.java new file mode 100644 index 000000000..4c61106b0 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/ConstantContactApi2.java @@ -0,0 +1,54 @@ +package com.github.scribejava.apis; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.exceptions.OAuthException; +import com.github.scribejava.core.extractors.AccessTokenExtractor; +import com.github.scribejava.core.model.OAuthConfig; +import com.github.scribejava.core.model.OAuthConstants; +import com.github.scribejava.core.model.Token; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.utils.OAuthEncoder; +import com.github.scribejava.core.utils.Preconditions; + +public class ConstantContactApi2 extends DefaultApi20 { + + private static final String AUTHORIZE_URL + = "https://oauth2.constantcontact.com/oauth2/oauth/siteowner/authorize?client_id=%s&response_type=code&redirect_uri=%s"; + + @Override + public String getAccessTokenEndpoint() { + return "https://oauth2.constantcontact.com/oauth2/oauth/token?grant_type=" + OAuthConstants.AUTHORIZATION_CODE; + } + + @Override + public String getAuthorizationUrl(OAuthConfig config) { + return String.format(AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback())); + } + + @Override + public Verb getAccessTokenVerb() { + return Verb.POST; + } + + @Override + public AccessTokenExtractor getAccessTokenExtractor() { + return new AccessTokenExtractor() { + + public Token extract(String response) { + Preconditions.checkEmptyString(response, "Response body is incorrect. Can't extract a token from an empty string"); + + String regex = "\"access_token\"\\s*:\\s*\"([^&\"]+)\""; + Matcher matcher = Pattern.compile(regex).matcher(response); + if (matcher.find()) { + String token = OAuthEncoder.decode(matcher.group(1)); + return new Token(token, "", response); + } else { + throw new OAuthException("Response body is incorrect. Can't extract a token from this: '" + response + "'", null); + } + } + }; + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/DiggApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/DiggApi.java new file mode 100644 index 000000000..4a6d6c6c5 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/DiggApi.java @@ -0,0 +1,26 @@ +package com.github.scribejava.apis; + +import com.github.scribejava.core.builder.api.DefaultApi10a; +import com.github.scribejava.core.model.Token; + +public class DiggApi extends DefaultApi10a { + + private static final String AUTHORIZATION_URL = "http://digg.com/oauth/authorize?oauth_token=%s"; + private static final String BASE_URL = "http://services.digg.com/oauth/"; + + @Override + public String getRequestTokenEndpoint() { + return BASE_URL + "request_token"; + } + + @Override + public String getAccessTokenEndpoint() { + return BASE_URL + "access_token"; + } + + @Override + public String getAuthorizationUrl(Token requestToken) { + return String.format(AUTHORIZATION_URL, requestToken.getToken()); + } + +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/DoktornaraboteApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/DoktornaraboteApi.java new file mode 100644 index 000000000..aa9244f9c --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/DoktornaraboteApi.java @@ -0,0 +1,59 @@ +package com.github.scribejava.apis; + +import com.github.scribejava.apis.service.DoktornaraboteOAuthServiceImpl; +import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.extractors.AccessTokenExtractor; +import com.github.scribejava.core.extractors.JsonTokenExtractor; +import com.github.scribejava.core.model.OAuthConfig; +import com.github.scribejava.core.model.OAuthConstants; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.oauth.OAuthService; +import com.github.scribejava.core.utils.OAuthEncoder; +import com.github.scribejava.core.utils.Preconditions; + +public class DoktornaraboteApi extends DefaultApi20 { + + private static final String AUTHORIZE_URL = "http://auth.doktornarabote.ru/OAuth/Authorize?response_type=code&client_id=%s&redirect_uri=%s&scope=%s"; + private static final String TOKEN_URL = "http://auth.doktornarabote.ru/OAuth/Token"; + + @Override + public Verb getAccessTokenVerb() { + return Verb.POST; + } + + @Override + public String getAccessTokenEndpoint() { + return TOKEN_URL; + } + + @Override + public String getAuthorizationUrl(OAuthConfig config) { + Preconditions.checkValidUrl( + config.getCallback(), + "Must provide a valid url as callback. Doktornarabote does not support OOB"); + final StringBuilder sb = new StringBuilder( + String.format( + AUTHORIZE_URL, + config.getApiKey(), + OAuthEncoder.encode(config.getCallback()), + OAuthEncoder.encode(config.getScope()) + ) + ); + + final String state = config.getState(); + if (state != null) { + sb.append('&').append(OAuthConstants.STATE).append('=').append(OAuthEncoder.encode(state)); + } + return sb.toString(); + } + + @Override + public AccessTokenExtractor getAccessTokenExtractor() { + return new JsonTokenExtractor(); + } + + @Override + public OAuthService createService(OAuthConfig config) { + return new DoktornaraboteOAuthServiceImpl(this, config); + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/DropBoxApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/DropBoxApi.java new file mode 100644 index 000000000..ffec0b307 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/DropBoxApi.java @@ -0,0 +1,23 @@ +package com.github.scribejava.apis; + +import com.github.scribejava.core.builder.api.DefaultApi10a; +import com.github.scribejava.core.model.Token; + +public class DropBoxApi extends DefaultApi10a { + + @Override + public String getAccessTokenEndpoint() { + return "https://api.dropbox.com/1/oauth/access_token"; + } + + @Override + public String getAuthorizationUrl(Token requestToken) { + return "https://www.dropbox.com/1/oauth/authorize?oauth_token=" + requestToken.getToken(); + } + + @Override + public String getRequestTokenEndpoint() { + return "https://api.dropbox.com/1/oauth/request_token"; + } + +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/EvernoteApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/EvernoteApi.java new file mode 100644 index 000000000..e5a39b115 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/EvernoteApi.java @@ -0,0 +1,48 @@ +package com.github.scribejava.apis; + +import com.github.scribejava.core.builder.api.DefaultApi10a; +import com.github.scribejava.core.model.Token; + +public class EvernoteApi extends DefaultApi10a { + + protected String serviceUrl() { + return "https://www.evernote.com"; + } + + @Override + public String getRequestTokenEndpoint() { + return serviceUrl() + "/oauth"; + } + + @Override + public String getAccessTokenEndpoint() { + return serviceUrl() + "/oauth"; + } + + @Override + public String getAuthorizationUrl(Token requestToken) { + return String.format(serviceUrl() + "/OAuth.action?oauth_token=%s", requestToken.getToken()); + } + + /** + * Sandbox endpoint + */ + public static class Sandbox extends EvernoteApi { + + @Override + protected String serviceUrl() { + return "https://sandbox.evernote.com"; + } + } + + /** + * Yinxiang Biji endpoint + */ + public static class Yinxiang extends EvernoteApi { + + @Override + protected String serviceUrl() { + return "https://app.yinxiang.com"; + } + } +} 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 new file mode 100644 index 000000000..c6994a43e --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java @@ -0,0 +1,34 @@ +package com.github.scribejava.apis; + +import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.model.OAuthConfig; +import com.github.scribejava.core.model.OAuthConstants; +import com.github.scribejava.core.utils.OAuthEncoder; +import com.github.scribejava.core.utils.Preconditions; + +public class FacebookApi extends DefaultApi20 { + + private static final String AUTHORIZE_URL = "https://www.facebook.com/v2.2/dialog/oauth?client_id=%s&redirect_uri=%s"; + + @Override + public String getAccessTokenEndpoint() { + return "https://graph.facebook.com/v2.2/oauth/access_token"; + } + + @Override + public String getAuthorizationUrl(final OAuthConfig config) { + Preconditions.checkValidUrl(config.getCallback(), + "Must provide a valid url as callback. Facebook does not support OOB"); + final StringBuilder sb = new StringBuilder(String.format(AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode( + config.getCallback()))); + if (config.hasScope()) { + sb.append('&').append(OAuthConstants.SCOPE).append('=').append(OAuthEncoder.encode(config.getScope())); + } + + final String state = config.getState(); + if (state != null) { + sb.append('&').append(OAuthConstants.STATE).append('=').append(OAuthEncoder.encode(state)); + } + return sb.toString(); + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/FlickrApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/FlickrApi.java new file mode 100644 index 000000000..3417cb7c7 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/FlickrApi.java @@ -0,0 +1,37 @@ +package com.github.scribejava.apis; + +import com.github.scribejava.core.builder.api.DefaultApi10a; +import com.github.scribejava.core.model.Token; + +/** + * OAuth API for Flickr. + * + * @author Darren Greaves + * @see Flickr API + */ +public class FlickrApi extends DefaultApi10a { + + /** + * {@inheritDoc} + */ + @Override + public String getAccessTokenEndpoint() { + return "https://www.flickr.com/services/oauth/access_token"; + } + + /** + * {@inheritDoc} + */ + @Override + public String getAuthorizationUrl(Token requestToken) { + return "https://www.flickr.com/services/oauth/authorize?oauth_token=" + requestToken.getToken(); + } + + /** + * {@inheritDoc} + */ + @Override + public String getRequestTokenEndpoint() { + return "https://www.flickr.com/services/oauth/request_token"; + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/Foursquare2Api.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/Foursquare2Api.java new file mode 100644 index 000000000..b80ab6f0e --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/Foursquare2Api.java @@ -0,0 +1,30 @@ +package com.github.scribejava.apis; + +import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.extractors.AccessTokenExtractor; +import com.github.scribejava.core.extractors.JsonTokenExtractor; +import com.github.scribejava.core.model.OAuthConfig; +import com.github.scribejava.core.model.OAuthConstants; +import com.github.scribejava.core.utils.OAuthEncoder; +import com.github.scribejava.core.utils.Preconditions; + +public class Foursquare2Api extends DefaultApi20 { + + private static final String AUTHORIZATION_URL = "https://foursquare.com/oauth2/authenticate?client_id=%s&response_type=code&redirect_uri=%s"; + + @Override + public String getAccessTokenEndpoint() { + return "https://foursquare.com/oauth2/access_token?grant_type=" + OAuthConstants.AUTHORIZATION_CODE; + } + + @Override + public String getAuthorizationUrl(OAuthConfig config) { + Preconditions.checkValidUrl(config.getCallback(), "Must provide a valid url as callback. Foursquare2 does not support OOB"); + return String.format(AUTHORIZATION_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback())); + } + + @Override + public AccessTokenExtractor getAccessTokenExtractor() { + return new JsonTokenExtractor(); + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/FoursquareApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/FoursquareApi.java new file mode 100644 index 000000000..108b8cf39 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/FoursquareApi.java @@ -0,0 +1,24 @@ +package com.github.scribejava.apis; + +import com.github.scribejava.core.builder.api.DefaultApi10a; +import com.github.scribejava.core.model.Token; + +public class FoursquareApi extends DefaultApi10a { + + private static final String AUTHORIZATION_URL = "http://foursquare.com/oauth/authorize?oauth_token=%s"; + + @Override + public String getAccessTokenEndpoint() { + return "http://foursquare.com/oauth/access_token"; + } + + @Override + public String getRequestTokenEndpoint() { + return "http://foursquare.com/oauth/request_token"; + } + + @Override + public String getAuthorizationUrl(Token requestToken) { + return String.format(AUTHORIZATION_URL, requestToken.getToken()); + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/FreelancerApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/FreelancerApi.java new file mode 100644 index 000000000..793fbd24b --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/FreelancerApi.java @@ -0,0 +1,55 @@ +package com.github.scribejava.apis; + +import com.github.scribejava.core.builder.api.DefaultApi10a; +import com.github.scribejava.core.model.Token; +import com.github.scribejava.core.model.Verb; + +public class FreelancerApi extends DefaultApi10a { + + private static final String AUTHORIZATION_URL = "http://www.freelancer.com/users/api-token/auth.php?oauth_token=%s"; + + @Override + public String getAccessTokenEndpoint() { + return "http://api.freelancer.com/RequestAccessToken/requestAccessToken.xml?"; + } + + @Override + public String getRequestTokenEndpoint() { + return "http://api.freelancer.com/RequestRequestToken/requestRequestToken.xml"; + } + + @Override + public Verb getAccessTokenVerb() { + return Verb.GET; + } + + @Override + public Verb getRequestTokenVerb() { + return Verb.GET; + } + + @Override + public String getAuthorizationUrl(Token requestToken) { + return String.format(AUTHORIZATION_URL, requestToken.getToken()); + } + + public static class Sandbox extends FreelancerApi { + + private static final String SANDBOX_AUTHORIZATION_URL = "http://www.sandbox.freelancer.com/users/api-token/auth.php"; + + @Override + public String getRequestTokenEndpoint() { + return "http://api.sandbox.freelancer.com/RequestRequestToken/requestRequestToken.xml"; + } + + @Override + public String getAccessTokenEndpoint() { + return "http://api.sandbox.freelancer.com/RequestAccessToken/requestAccessToken.xml?"; + } + + @Override + public String getAuthorizationUrl(Token requestToken) { + return String.format(SANDBOX_AUTHORIZATION_URL + "?oauth_token=%s", requestToken.getToken()); + } + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/GetGlueApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/GetGlueApi.java new file mode 100644 index 000000000..575c67100 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/GetGlueApi.java @@ -0,0 +1,27 @@ +package com.github.scribejava.apis; + +import com.github.scribejava.core.builder.api.DefaultApi10a; +import com.github.scribejava.core.model.Token; + +public class GetGlueApi extends DefaultApi10a { + + private static final String AUTHORIZE_URL = "http://getglue.com/oauth/authorize?oauth_token=%s"; + private static final String REQUEST_TOKEN_RESOURCE = "https://api.getglue.com/oauth/request_token"; + private static final String ACCESS_TOKEN_RESOURCE = "https://api.getglue.com/oauth/access_token"; + + @Override + public String getAccessTokenEndpoint() { + return ACCESS_TOKEN_RESOURCE; + } + + @Override + public String getRequestTokenEndpoint() { + return REQUEST_TOKEN_RESOURCE; + } + + @Override + public String getAuthorizationUrl(Token requestToken) { + return String.format(AUTHORIZE_URL, requestToken.getToken()); + } + +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/GitHubApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/GitHubApi.java new file mode 100644 index 000000000..8f8821cdd --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/GitHubApi.java @@ -0,0 +1,31 @@ +package com.github.scribejava.apis; + +import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.model.OAuthConfig; +import com.github.scribejava.core.model.OAuthConstants; +import com.github.scribejava.core.utils.OAuthEncoder; +import com.github.scribejava.core.utils.Preconditions; + +public class GitHubApi extends DefaultApi20 { + + private static final String AUTHORIZE_URL = "https://github.com/login/oauth/authorize?client_id=%s&redirect_uri=%s"; + + @Override + public String getAccessTokenEndpoint() { + return "https://github.com/login/oauth/access_token"; + } + + @Override + public String getAuthorizationUrl(OAuthConfig config) { + Preconditions.checkValidUrl(config.getCallback(), "Must provide a valid url as callback. GitHub does not support OOB"); + final StringBuilder sb = new StringBuilder(String.format(AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()))); + if (config.hasScope()) { + sb.append('&').append(OAuthConstants.SCOPE).append('=').append(OAuthEncoder.encode(config.getScope())); + } + final String state = config.getState(); + if (state != null) { + sb.append('&').append(OAuthConstants.STATE).append('=').append(OAuthEncoder.encode(state)); + } + return sb.toString(); + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/GoogleApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/GoogleApi.java new file mode 100644 index 000000000..fd5b33fd0 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/GoogleApi.java @@ -0,0 +1,35 @@ +package com.github.scribejava.apis; + +import com.github.scribejava.core.builder.api.DefaultApi10a; +import com.github.scribejava.core.model.Token; +import com.github.scribejava.core.model.Verb; + +public class GoogleApi extends DefaultApi10a { + + private static final String AUTHORIZATION_URL = "https://www.google.com/accounts/OAuthAuthorizeToken?oauth_token=%s"; + + @Override + public String getAccessTokenEndpoint() { + return "https://www.google.com/accounts/OAuthGetAccessToken"; + } + + @Override + public String getRequestTokenEndpoint() { + return "https://www.google.com/accounts/OAuthGetRequestToken"; + } + + @Override + public Verb getAccessTokenVerb() { + return Verb.GET; + } + + @Override + public Verb getRequestTokenVerb() { + return Verb.GET; + } + + @Override + public String getAuthorizationUrl(Token requestToken) { + return String.format(AUTHORIZATION_URL, requestToken.getToken()); + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/GoogleApi20.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/GoogleApi20.java new file mode 100644 index 000000000..5bf9a2691 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/GoogleApi20.java @@ -0,0 +1,53 @@ +package com.github.scribejava.apis; + +import com.github.scribejava.apis.google.GoogleJsonTokenExtractor; +import com.github.scribejava.apis.service.GoogleOAuthServiceImpl; +import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.extractors.AccessTokenExtractor; +import com.github.scribejava.core.model.OAuthConfig; +import com.github.scribejava.core.model.OAuthConstants; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.oauth.OAuthService; +import com.github.scribejava.core.utils.OAuthEncoder; +import com.github.scribejava.core.utils.Preconditions; + +public class GoogleApi20 extends DefaultApi20 { + + private static final String AUTHORIZE_URL + = "https://accounts.google.com/o/oauth2/auth?response_type=code&client_id=%s&redirect_uri=%s&scope=%s"; + + @Override + public Verb getAccessTokenVerb() { + return Verb.POST; + } + + @Override + public String getAccessTokenEndpoint() { + return "https://accounts.google.com/o/oauth2/token"; + } + + @Override + public String getAuthorizationUrl(final OAuthConfig config) { + Preconditions.checkValidUrl(config.getCallback(), + "Must provide a valid url as callback. Google+ does not support OOB"); + final StringBuilder sb = new StringBuilder(String.format(AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode( + config.getCallback()), OAuthEncoder.encode(config.getScope()))); + + final String state = config.getState(); + if (state != null) { + sb.append('&').append(OAuthConstants.STATE).append('=').append(OAuthEncoder.encode(state)); + } + return sb.toString(); + } + + @Override + public AccessTokenExtractor getAccessTokenExtractor() { + return new GoogleJsonTokenExtractor(); + } + + @Override + public OAuthService createService(OAuthConfig config) { + return new GoogleOAuthServiceImpl(this, config); + } + +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/HHApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/HHApi.java new file mode 100644 index 000000000..c05980cc4 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/HHApi.java @@ -0,0 +1,41 @@ +package com.github.scribejava.apis; + +import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.extractors.AccessTokenExtractor; +import com.github.scribejava.core.extractors.JsonTokenExtractor; +import com.github.scribejava.core.model.OAuthConfig; +import com.github.scribejava.core.model.OAuthConstants; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.oauth.OAuthService; + +import com.github.scribejava.apis.service.HHOAuthServiceImpl; + +public class HHApi extends DefaultApi20 { + + private static final String AUTHORIZE_URL = "https://m.hh.ru/oauth/authorize?response_type=code&client_id=%s"; + private static final String TOKEN_URL = "https://m.hh.ru/oauth/token?grant_type=" + OAuthConstants.AUTHORIZATION_CODE; + + public Verb getAccessTokenVerb() { + return Verb.POST; + } + + @Override + public String getAccessTokenEndpoint() { + return TOKEN_URL; + } + + @Override + public String getAuthorizationUrl(OAuthConfig config) { + return String.format(AUTHORIZE_URL, config.getApiKey()); + } + + @Override + public AccessTokenExtractor getAccessTokenExtractor() { + return new JsonTokenExtractor(); + } + + @Override + public OAuthService createService(OAuthConfig config) { + return new HHOAuthServiceImpl(this, config); + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgUrApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgUrApi.java new file mode 100644 index 000000000..a46d3f28c --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgUrApi.java @@ -0,0 +1,28 @@ +package com.github.scribejava.apis; + +import com.github.scribejava.core.builder.api.DefaultApi10a; +import com.github.scribejava.core.model.Token; + +/** + * OAuth API for ImgUr + * + * @author David Wursteisen + * @see ImgUr API + */ +public class ImgUrApi extends DefaultApi10a { + + @Override + public String getRequestTokenEndpoint() { + return "https://api.imgur.com/oauth/request_token"; + } + + @Override + public String getAccessTokenEndpoint() { + return "https://api.imgur.com/oauth/access_token"; + } + + @Override + public String getAuthorizationUrl(Token requestToken) { + return String.format("https://api.imgur.com/oauth/authorize?oauth_token=%s", requestToken.getToken()); + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/KaixinApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/KaixinApi.java new file mode 100644 index 000000000..b0be0f553 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/KaixinApi.java @@ -0,0 +1,37 @@ +package com.github.scribejava.apis; + +import com.github.scribejava.core.builder.api.DefaultApi10a; +import com.github.scribejava.core.model.Token; +import com.github.scribejava.core.model.Verb; + +public class KaixinApi extends DefaultApi10a { + + private static final String REQUEST_TOKEN_URL = "http://api.kaixin001.com/oauth/request_token"; + private static final String ACCESS_TOKEN_URL = "http://api.kaixin001.com/oauth/access_token"; + private static final String AUTHORIZE_URL = "http://api.kaixin001.com/oauth/authorize?oauth_token=%s"; + + @Override + public String getRequestTokenEndpoint() { + return REQUEST_TOKEN_URL; + } + + @Override + public String getAccessTokenEndpoint() { + return ACCESS_TOKEN_URL; + } + + @Override + public String getAuthorizationUrl(Token requestToken) { + return String.format(AUTHORIZE_URL, requestToken.getToken()); + } + + @Override + public Verb getRequestTokenVerb() { + return Verb.GET; + } + + @Override + public Verb getAccessTokenVerb() { + return Verb.GET; + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/KaixinApi20.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/KaixinApi20.java new file mode 100644 index 000000000..54f5d9505 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/KaixinApi20.java @@ -0,0 +1,38 @@ +package com.github.scribejava.apis; + +import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.extractors.AccessTokenExtractor; +import com.github.scribejava.core.extractors.JsonTokenExtractor; +import com.github.scribejava.core.model.OAuthConfig; +import com.github.scribejava.core.model.OAuthConstants; +import com.github.scribejava.core.utils.OAuthEncoder; + +/** + * Kaixin(http://www.kaixin001.com/) open platform api based on OAuth 2.0. + */ +public class KaixinApi20 extends DefaultApi20 { + + private static final String AUTHORIZE_URL = "http://api.kaixin001.com/oauth2/authorize?client_id=%s&redirect_uri=%s&response_type=code"; + private static final String SCOPED_AUTHORIZE_URL = AUTHORIZE_URL + "&scope=%s"; + + @Override + public AccessTokenExtractor getAccessTokenExtractor() { + return new JsonTokenExtractor(); + } + + @Override + public String getAccessTokenEndpoint() { + return "https://api.kaixin001.com/oauth2/access_token?grant_type=" + OAuthConstants.AUTHORIZATION_CODE; + } + + @Override + public String getAuthorizationUrl(OAuthConfig config) { + // Append scope if present + if (config.hasScope()) { + return String.format(SCOPED_AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()), OAuthEncoder.encode(config. + getScope())); + } else { + return String.format(AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback())); + } + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi.java new file mode 100644 index 000000000..5e9a94617 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi.java @@ -0,0 +1,53 @@ +package com.github.scribejava.apis; + +import java.util.Arrays; +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; +import com.github.scribejava.core.builder.api.DefaultApi10a; +import com.github.scribejava.core.model.Token; + +public class LinkedInApi extends DefaultApi10a { + + private static final String AUTHORIZE_URL = "https://api.linkedin.com/uas/oauth/authenticate?oauth_token=%s"; + private static final String REQUEST_TOKEN_URL = "https://api.linkedin.com/uas/oauth/requestToken"; + + private final Set scopes; + + public LinkedInApi() { + scopes = Collections.emptySet(); + } + + public LinkedInApi(Set scopes) { + this.scopes = Collections.unmodifiableSet(scopes); + } + + @Override + public String getAccessTokenEndpoint() { + return "https://api.linkedin.com/uas/oauth/accessToken"; + } + + @Override + public String getRequestTokenEndpoint() { + return scopes.isEmpty() ? REQUEST_TOKEN_URL : REQUEST_TOKEN_URL + "?scope=" + scopesAsString(); + } + + private String scopesAsString() { + StringBuilder builder = new StringBuilder(); + for (String scope : scopes) { + builder.append("+" + scope); + } + return builder.substring(1); + } + + @Override + public String getAuthorizationUrl(Token requestToken) { + return String.format(AUTHORIZE_URL, requestToken.getToken()); + } + + public static LinkedInApi withScopes(String... scopes) { + Set scopeSet = new HashSet(Arrays.asList(scopes)); + return new LinkedInApi(scopeSet); + } + +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi20.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi20.java new file mode 100644 index 000000000..3a50ad45d --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi20.java @@ -0,0 +1,53 @@ +package com.github.scribejava.apis; + +import com.github.scribejava.apis.service.LinkedIn20ServiceImpl; +import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.extractors.AccessTokenExtractor; +import com.github.scribejava.core.extractors.JsonTokenExtractor; +import com.github.scribejava.core.model.OAuthConfig; +import com.github.scribejava.core.model.OAuthConstants; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.oauth.OAuthService; +import com.github.scribejava.core.utils.OAuthEncoder; +import com.github.scribejava.core.utils.Preconditions; + +public class LinkedInApi20 extends DefaultApi20 { + + private static final String AUTHORIZE_URL + = "https://www.linkedin.com/uas/oauth2/authorization?response_type=code&client_id=%s&redirect_uri=%s&" + OAuthConstants.STATE + "=%s"; + + private static final String SCOPED_AUTHORIZE_URL = AUTHORIZE_URL + "&scope=%s"; + + @Override + public Verb getAccessTokenVerb() { + return Verb.GET; + } + + @Override + public String getAccessTokenEndpoint() { + return "https://www.linkedin.com/uas/oauth2/accessToken"; + } + + @Override + public String getAuthorizationUrl(final OAuthConfig config) { + Preconditions.checkValidUrl(config.getCallback(), "Must provide a valid url as callback. LinkedIn does not support OOB"); + + if (config.hasScope()) { + return String.format( + SCOPED_AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()), config.getState(), OAuthEncoder.encode( + config.getScope())); + } else { + return String.format(AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()), config.getState()); + } + } + + @Override + public AccessTokenExtractor getAccessTokenExtractor() { + return new JsonTokenExtractor(); + } + + @Override + public OAuthService createService(final OAuthConfig config) { + return new LinkedIn20ServiceImpl(this, config); + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/LiveApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/LiveApi.java new file mode 100644 index 000000000..c5bd8108d --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/LiveApi.java @@ -0,0 +1,38 @@ +package com.github.scribejava.apis; + +import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.extractors.AccessTokenExtractor; +import com.github.scribejava.core.extractors.JsonTokenExtractor; +import com.github.scribejava.core.model.OAuthConfig; +import com.github.scribejava.core.model.OAuthConstants; +import com.github.scribejava.core.utils.OAuthEncoder; +import com.github.scribejava.core.utils.Preconditions; + +public class LiveApi extends DefaultApi20 { + + private static final String AUTHORIZE_URL = "https://oauth.live.com/authorize?client_id=%s&redirect_uri=%s&response_type=code"; + private static final String SCOPED_AUTHORIZE_URL = AUTHORIZE_URL + "&scope=%s"; + + @Override + public String getAccessTokenEndpoint() { + return "https://login.live.com/oauth20_token.srf?grant_type=" + OAuthConstants.AUTHORIZATION_CODE; + } + + @Override + public String getAuthorizationUrl(OAuthConfig config) { + Preconditions.checkValidUrl(config.getCallback(), "Must provide a valid url as callback. Live does not support OOB"); + + // Append scope if present + if (config.hasScope()) { + return String.format(SCOPED_AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()), OAuthEncoder.encode(config. + getScope())); + } else { + return String.format(AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback())); + } + } + + @Override + public AccessTokenExtractor getAccessTokenExtractor() { + return new JsonTokenExtractor(); + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/LoveFilmApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/LoveFilmApi.java new file mode 100644 index 000000000..40b235f7b --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/LoveFilmApi.java @@ -0,0 +1,26 @@ +package com.github.scribejava.apis; + +import com.github.scribejava.core.builder.api.DefaultApi10a; +import com.github.scribejava.core.model.Token; + +public class LoveFilmApi extends DefaultApi10a { + + private static final String REQUEST_TOKEN_URL = "http://openapi.lovefilm.com/oauth/request_token"; + private static final String ACCESS_TOKEN_URL = "http://openapi.lovefilm.com/oauth/access_token"; + private static final String AUTHORIZE_URL = "https://www.lovefilm.com/activate?oauth_token=%s"; + + @Override + public String getRequestTokenEndpoint() { + return REQUEST_TOKEN_URL; + } + + @Override + public String getAccessTokenEndpoint() { + return ACCESS_TOKEN_URL; + } + + @Override + public String getAuthorizationUrl(Token requestToken) { + return String.format(AUTHORIZE_URL, requestToken.getToken()); + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java new file mode 100644 index 000000000..c208efd91 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java @@ -0,0 +1,48 @@ +package com.github.scribejava.apis; + +import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.extractors.AccessTokenExtractor; +import com.github.scribejava.core.extractors.JsonTokenExtractor; +import com.github.scribejava.core.model.OAuthConfig; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.oauth.OAuthService; +import com.github.scribejava.core.utils.OAuthEncoder; +import com.github.scribejava.core.utils.Preconditions; +import com.github.scribejava.apis.service.MailruOAuthServiceImpl; + +public class MailruApi extends DefaultApi20 { + + private static final String AUTHORIZE_URL = "https://connect.mail.ru/oauth/authorize?client_id=%s&redirect_uri=%s&response_type=code"; + private static final String SCOPED_AUTHORIZE_URL = AUTHORIZE_URL + "&scope=%s"; + + @Override + public Verb getAccessTokenVerb() { + return Verb.POST; + } + + @Override + public String getAccessTokenEndpoint() { + return "https://connect.mail.ru/oauth/token"; + } + + @Override + public String getAuthorizationUrl(OAuthConfig config) { + Preconditions.checkValidUrl(config.getCallback(), "Valid url is required for a callback. Mail.ru does not support OOB"); + if (config.hasScope()) { // Appending scope if present + return String.format(SCOPED_AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()), OAuthEncoder.encode(config. + getScope())); + } else { + return String.format(AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback())); + } + } + + @Override + public OAuthService createService(OAuthConfig config) { + return new MailruOAuthServiceImpl(this, config); + } + + @Override + public AccessTokenExtractor getAccessTokenExtractor() { + return new JsonTokenExtractor(); + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/MeetupApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/MeetupApi.java new file mode 100644 index 000000000..cf030526c --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/MeetupApi.java @@ -0,0 +1,27 @@ +package com.github.scribejava.apis; + +import com.github.scribejava.core.builder.api.DefaultApi10a; +import com.github.scribejava.core.model.Token; + +/** + * OAuth access to the Meetup.com API. For more information visit http://www.meetup.com/api + */ +public class MeetupApi extends DefaultApi10a { + + private static final String AUTHORIZE_URL = "http://www.meetup.com/authenticate?oauth_token=%s"; + + @Override + public String getRequestTokenEndpoint() { + return "http://api.meetup.com/oauth/request/"; + } + + @Override + public String getAccessTokenEndpoint() { + return "http://api.meetup.com/oauth/access/"; + } + + @Override + public String getAuthorizationUrl(Token requestToken) { + return String.format(AUTHORIZE_URL, requestToken.getToken()); + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/MendeleyApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/MendeleyApi.java new file mode 100644 index 000000000..e2d8e443f --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/MendeleyApi.java @@ -0,0 +1,39 @@ +package com.github.scribejava.apis; + +import com.github.scribejava.core.builder.api.DefaultApi10a; +import com.github.scribejava.core.model.Token; +import com.github.scribejava.core.model.Verb; + +/** + * @author Arieh "Vainolo" Bibliowicz + * @see http://apidocs.mendeley.com/home/authentication + */ +public class MendeleyApi extends DefaultApi10a { + + private static final String AUTHORIZATION_URL = "http://api.mendeley.com/oauth/authorize?oauth_token=%s"; + + @Override + public String getRequestTokenEndpoint() { + return "http://api.mendeley.com/oauth/request_token/"; + } + + @Override + public String getAccessTokenEndpoint() { + return "http://api.mendeley.com/oauth/access_token/"; + } + + @Override + public String getAuthorizationUrl(final Token requestToken) { + return String.format(AUTHORIZATION_URL, requestToken.getToken()); + } + + @Override + public Verb getAccessTokenVerb() { + return Verb.GET; + } + + @Override + public Verb getRequestTokenVerb() { + return Verb.GET; + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/MisoApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/MisoApi.java new file mode 100644 index 000000000..9dbbfeb1d --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/MisoApi.java @@ -0,0 +1,27 @@ +package com.github.scribejava.apis; + +import com.github.scribejava.core.builder.api.DefaultApi10a; +import com.github.scribejava.core.model.Token; + +public class MisoApi extends DefaultApi10a { + + private static final String AUTHORIZE_URL = "http://gomiso.com/oauth/authorize?oauth_token=%s"; + private static final String REQUEST_TOKEN_RESOURCE = "http://gomiso.com/oauth/request_token"; + private static final String ACCESS_TOKEN_RESOURCE = "http://gomiso.com/oauth/access_token"; + + @Override + public String getAccessTokenEndpoint() { + return ACCESS_TOKEN_RESOURCE; + } + + @Override + public String getRequestTokenEndpoint() { + return REQUEST_TOKEN_RESOURCE; + } + + @Override + public String getAuthorizationUrl(Token requestToken) { + return String.format(AUTHORIZE_URL, requestToken.getToken()); + } + +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/NetProspexApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/NetProspexApi.java new file mode 100644 index 000000000..3118fb1ff --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/NetProspexApi.java @@ -0,0 +1,26 @@ +package com.github.scribejava.apis; + +import com.github.scribejava.core.builder.api.DefaultApi10a; +import com.github.scribejava.core.model.Token; + +public class NetProspexApi extends DefaultApi10a { + + private static final String REQUEST_TOKEN_URL = "https://api.netprospex.com/1.0/oauth/request-token"; + private static final String ACCESS_TOKEN_URL = "https://api.netprospex.com/1.0/oauth/access-token"; + private static final String AUTHORIZE_URL = "https://api.netprospex.com/1.0/oauth/authorize?oauth_token=%s"; + + @Override + public String getRequestTokenEndpoint() { + return REQUEST_TOKEN_URL; + } + + @Override + public String getAccessTokenEndpoint() { + return ACCESS_TOKEN_URL; + } + + @Override + public String getAuthorizationUrl(Token requestToken) { + return String.format(AUTHORIZE_URL, requestToken.getToken()); + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/NeteaseWeibooApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/NeteaseWeibooApi.java new file mode 100644 index 000000000..75ff524f9 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/NeteaseWeibooApi.java @@ -0,0 +1,44 @@ +package com.github.scribejava.apis; + +import com.github.scribejava.core.builder.api.DefaultApi10a; +import com.github.scribejava.core.model.Token; + +public class NeteaseWeibooApi extends DefaultApi10a { + + private static final String REQUEST_TOKEN_URL = "http://api.t.163.com/oauth/request_token"; + private static final String ACCESS_TOKEN_URL = "http://api.t.163.com/oauth/access_token"; + private static final String AUTHORIZE_URL = "http://api.t.163.com/oauth/authorize?oauth_token=%s"; + private static final String AUTHENTICATE_URL = "http://api.t.163.com/oauth/authenticate?oauth_token=%s"; + + @Override + public String getRequestTokenEndpoint() { + return REQUEST_TOKEN_URL; + } + + @Override + public String getAccessTokenEndpoint() { + return ACCESS_TOKEN_URL; + } + + @Override + /** + * this method will ignore your callback if you're creating a desktop client please choose this url else your can call getAuthenticateUrl + * + * via http://open.t.163.com/wiki/index.php?title=%E8%AF%B7%E6%B1%82%E7%94%A8%E6%88%B7%E6%8E%88%E6%9D%83Token(oauth/authorize) + */ + public String getAuthorizationUrl(final Token requestToken) { + return String.format(AUTHORIZE_URL, requestToken.getToken()); + } + + /** + * this method is for web client with callback url if you're creating a desktop client please call getAuthorizationUrl + * + * via http://open.t.163.com/wiki/index.php?title=%E8%AF%B7%E6%B1%82%E7%94%A8%E6%88%B7%E6%8E%88%E6%9D%83Token(oauth/authenticate) + * + * @param requestToken Token + * @return String + */ + public String getAuthenticateUrl(final Token requestToken) { + return String.format(AUTHENTICATE_URL, requestToken.getToken()); + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java new file mode 100644 index 000000000..de23a3a37 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java @@ -0,0 +1,48 @@ +package com.github.scribejava.apis; + +import com.github.scribejava.apis.service.OdnoklassnikiServiceImpl; +import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.extractors.AccessTokenExtractor; +import com.github.scribejava.core.extractors.JsonTokenExtractor; +import com.github.scribejava.core.model.OAuthConfig; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.oauth.OAuthService; +import com.github.scribejava.core.utils.OAuthEncoder; +import com.github.scribejava.core.utils.Preconditions; + +public class OdnoklassnikiApi extends DefaultApi20 { + + private static final String AUTHORIZE_URL = "http://www.odnoklassniki.ru/oauth/authorize?client_id=%s&response_type=code&redirect_uri=%s"; + private static final String SCOPED_AUTHORIZE_URL = String.format("%s&scope=%%s", AUTHORIZE_URL); + + @Override + public String getAccessTokenEndpoint() { + return "http://api.odnoklassniki.ru/oauth/token.do"; + } + + @Override + public Verb getAccessTokenVerb() { + return Verb.POST; + } + + @Override + public String getAuthorizationUrl(OAuthConfig config) { + Preconditions.checkValidUrl(config.getCallback(), "Valid url is required for a callback. Odnoklassniki does not support OOB"); + if (config.hasScope()) { + return String.format( + SCOPED_AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()), OAuthEncoder.encode(config.getScope())); + } else { + return String.format(AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback())); + } + } + + @Override + public OAuthService createService(OAuthConfig config) { + return new OdnoklassnikiServiceImpl(this, config); + } + + @Override + public AccessTokenExtractor getAccessTokenExtractor() { + return new JsonTokenExtractor(); + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/PlurkApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/PlurkApi.java new file mode 100644 index 000000000..a1cc67782 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/PlurkApi.java @@ -0,0 +1,36 @@ +package com.github.scribejava.apis; + +import com.github.scribejava.core.builder.api.DefaultApi10a; +import com.github.scribejava.core.model.Token; + +public class PlurkApi extends DefaultApi10a { + + private static final String REQUEST_TOKEN_URL = "http://www.plurk.com/OAuth/request_token"; + private static final String AUTHORIZATION_URL = "http://www.plurk.com/OAuth/authorize?oauth_token=%s"; + private static final String ACCESS_TOKEN_URL = "http://www.plurk.com/OAuth/access_token"; + + @Override + public String getRequestTokenEndpoint() { + return REQUEST_TOKEN_URL; + } + + @Override + public String getAuthorizationUrl(Token requestToken) { + return String.format(AUTHORIZATION_URL, requestToken.getToken()); + } + + @Override + public String getAccessTokenEndpoint() { + return ACCESS_TOKEN_URL; + } + + public static class Mobile extends PlurkApi { + + private static final String AUTHORIZATION_URL = "http://www.plurk.com/m/authorize?oauth_token=%s"; + + @Override + public String getAuthorizationUrl(Token requestToken) { + return String.format(AUTHORIZATION_URL, requestToken.getToken()); + } + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/Px500Api.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/Px500Api.java new file mode 100644 index 000000000..a6a407111 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/Px500Api.java @@ -0,0 +1,24 @@ +package com.github.scribejava.apis; + +import com.github.scribejava.core.builder.api.DefaultApi10a; +import com.github.scribejava.core.model.Token; + +public class Px500Api extends DefaultApi10a { + + private static final String AUTHORIZATION_URL = "https://api.500px.com/v1/oauth/authorize?oauth_token=%s"; + + @Override + public String getAccessTokenEndpoint() { + return "https://api.500px.com/v1/oauth/access_token"; + } + + @Override + public String getRequestTokenEndpoint() { + return "https://api.500px.com/v1/oauth/request_token"; + } + + @Override + public String getAuthorizationUrl(Token requestToken) { + return String.format(AUTHORIZATION_URL, requestToken.getToken()); + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/QWeiboApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/QWeiboApi.java new file mode 100644 index 000000000..bac788b91 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/QWeiboApi.java @@ -0,0 +1,26 @@ +package com.github.scribejava.apis; + +import com.github.scribejava.core.builder.api.DefaultApi10a; +import com.github.scribejava.core.model.Token; + +public class QWeiboApi extends DefaultApi10a { + + private static final String REQUEST_TOKEN_URL = "https://open.t.qq.com/cgi-bin/request_token"; + private static final String ACCESS_TOKEN_URL = "https://open.t.qq.com/cgi-bin/access_token"; + private static final String AUTHORIZE_URL = "https://open.t.qq.com/cgi-bin/authorize?oauth_token=%s"; + + @Override + public String getRequestTokenEndpoint() { + return REQUEST_TOKEN_URL; + } + + @Override + public String getAccessTokenEndpoint() { + return ACCESS_TOKEN_URL; + } + + @Override + public String getAuthorizationUrl(Token requestToken) { + return String.format(AUTHORIZE_URL, requestToken.getToken()); + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/RenrenApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/RenrenApi.java new file mode 100644 index 000000000..903b53bcb --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/RenrenApi.java @@ -0,0 +1,38 @@ +package com.github.scribejava.apis; + +import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.extractors.AccessTokenExtractor; +import com.github.scribejava.core.extractors.JsonTokenExtractor; +import com.github.scribejava.core.model.OAuthConfig; +import com.github.scribejava.core.model.OAuthConstants; +import com.github.scribejava.core.utils.OAuthEncoder; + +/** + * Renren(http://www.renren.com/) OAuth 2.0 based api. + */ +public class RenrenApi extends DefaultApi20 { + + private static final String AUTHORIZE_URL = "https://graph.renren.com/oauth/authorize?client_id=%s&redirect_uri=%s&response_type=code"; + private static final String SCOPED_AUTHORIZE_URL = AUTHORIZE_URL + "&scope=%s"; + + @Override + public AccessTokenExtractor getAccessTokenExtractor() { + return new JsonTokenExtractor(); + } + + @Override + public String getAccessTokenEndpoint() { + return "https://graph.renren.com/oauth/token?grant_type=" + OAuthConstants.AUTHORIZATION_CODE; + } + + @Override + public String getAuthorizationUrl(OAuthConfig config) { + // Append scope if present + if (config.hasScope()) { + return String.format(SCOPED_AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()), OAuthEncoder.encode(config. + getScope())); + } else { + return String.format(AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback())); + } + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/SapoApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/SapoApi.java new file mode 100644 index 000000000..de21a248e --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/SapoApi.java @@ -0,0 +1,37 @@ +package com.github.scribejava.apis; + +import com.github.scribejava.core.builder.api.DefaultApi10a; +import com.github.scribejava.core.model.Token; +import com.github.scribejava.core.model.Verb; + +public class SapoApi extends DefaultApi10a { + + private static final String AUTHORIZE_URL = "https://id.sapo.pt/oauth/authorize?oauth_token=%s"; + private static final String ACCESS_URL = "https://id.sapo.pt/oauth/access_token"; + private static final String REQUEST_URL = "https://id.sapo.pt/oauth/request_token"; + + @Override + public String getAccessTokenEndpoint() { + return ACCESS_URL; + } + + @Override + public String getRequestTokenEndpoint() { + return REQUEST_URL; + } + + @Override + public String getAuthorizationUrl(Token requestToken) { + return String.format(AUTHORIZE_URL, requestToken.getToken()); + } + + @Override + public Verb getRequestTokenVerb() { + return Verb.GET; + } + + @Override + public Verb getAccessTokenVerb() { + return Verb.GET; + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/SimpleGeoApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/SimpleGeoApi.java new file mode 100644 index 000000000..d5b2d50f8 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/SimpleGeoApi.java @@ -0,0 +1,27 @@ +package com.github.scribejava.apis; + +import com.github.scribejava.core.builder.api.DefaultApi10a; +import com.github.scribejava.core.model.Token; + +/** + * @author Pablo Fernandez + */ +public class SimpleGeoApi extends DefaultApi10a { + + private static final String ENDPOINT = "these are not used since SimpleGeo uses 2 legged OAuth"; + + @Override + public String getRequestTokenEndpoint() { + return ENDPOINT; + } + + @Override + public String getAccessTokenEndpoint() { + return ENDPOINT; + } + + @Override + public String getAuthorizationUrl(final Token requestToken) { + return ENDPOINT; + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/SinaWeiboApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/SinaWeiboApi.java new file mode 100644 index 000000000..7f796eb47 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/SinaWeiboApi.java @@ -0,0 +1,26 @@ +package com.github.scribejava.apis; + +import com.github.scribejava.core.builder.api.DefaultApi10a; +import com.github.scribejava.core.model.Token; + +public class SinaWeiboApi extends DefaultApi10a { + + private static final String REQUEST_TOKEN_URL = "http://api.t.sina.com.cn/oauth/request_token"; + private static final String ACCESS_TOKEN_URL = "http://api.t.sina.com.cn/oauth/access_token"; + private static final String AUTHORIZE_URL = "http://api.t.sina.com.cn/oauth/authorize?oauth_token=%s"; + + @Override + public String getRequestTokenEndpoint() { + return REQUEST_TOKEN_URL; + } + + @Override + public String getAccessTokenEndpoint() { + return ACCESS_TOKEN_URL; + } + + @Override + public String getAuthorizationUrl(Token requestToken) { + return String.format(AUTHORIZE_URL, requestToken.getToken()); + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/SinaWeiboApi20.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/SinaWeiboApi20.java new file mode 100644 index 000000000..8f1ce73b2 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/SinaWeiboApi20.java @@ -0,0 +1,44 @@ +package com.github.scribejava.apis; + +import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.extractors.AccessTokenExtractor; +import com.github.scribejava.core.extractors.JsonTokenExtractor; +import com.github.scribejava.core.model.OAuthConfig; +import com.github.scribejava.core.model.OAuthConstants; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.utils.OAuthEncoder; + +/** + * SinaWeibo OAuth 2.0 api. + */ +public class SinaWeiboApi20 extends DefaultApi20 { + + private static final String AUTHORIZE_URL = "https://api.weibo.com/oauth2/authorize?client_id=%s&redirect_uri=%s&response_type=code"; + private static final String SCOPED_AUTHORIZE_URL = AUTHORIZE_URL + "&scope=%s"; + + @Override + public Verb getAccessTokenVerb() { + return Verb.POST; + } + + @Override + public AccessTokenExtractor getAccessTokenExtractor() { + return new JsonTokenExtractor(); + } + + @Override + public String getAccessTokenEndpoint() { + return "https://api.weibo.com/oauth2/access_token?grant_type=" + OAuthConstants.AUTHORIZATION_CODE; + } + + @Override + public String getAuthorizationUrl(OAuthConfig config) { + // Append scope if present + if (config.hasScope()) { + return String.format(SCOPED_AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()), OAuthEncoder.encode(config. + getScope())); + } else { + return String.format(AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback())); + } + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/SkyrockApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/SkyrockApi.java new file mode 100644 index 000000000..74c368ca0 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/SkyrockApi.java @@ -0,0 +1,33 @@ +package com.github.scribejava.apis; + +import com.github.scribejava.core.builder.api.DefaultApi10a; +import com.github.scribejava.core.model.Token; + +/** + * OAuth API for Skyrock. + * + * @author Nicolas Quiénot + * @see Skyrock.com API + */ +public class SkyrockApi extends DefaultApi10a { + + private static final String API_ENDPOINT = "https://api.skyrock.com/v2"; + private static final String REQUEST_TOKEN_RESOURCE = "/oauth/initiate"; + private static final String AUTHORIZE_URL = "/oauth/authorize?oauth_token=%s"; + private static final String ACCESS_TOKEN_RESOURCE = "/oauth/token"; + + @Override + public String getAccessTokenEndpoint() { + return API_ENDPOINT + ACCESS_TOKEN_RESOURCE; + } + + @Override + public String getRequestTokenEndpoint() { + return API_ENDPOINT + REQUEST_TOKEN_RESOURCE; + } + + @Override + public String getAuthorizationUrl(Token requestToken) { + return String.format(API_ENDPOINT + AUTHORIZE_URL, requestToken.getToken()); + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/SohuWeiboApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/SohuWeiboApi.java new file mode 100644 index 000000000..6d56d5906 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/SohuWeiboApi.java @@ -0,0 +1,26 @@ +package com.github.scribejava.apis; + +import com.github.scribejava.core.builder.api.DefaultApi10a; +import com.github.scribejava.core.model.Token; + +public class SohuWeiboApi extends DefaultApi10a { + + private static final String REQUEST_TOKEN_URL = "http://api.t.sohu.com/oauth/request_token"; + private static final String ACCESS_TOKEN_URL = "http://api.t.sohu.com/oauth/access_token"; + private static final String AUTHORIZE_URL = "http://api.t.sohu.com/oauth/authorize?oauth_token=%s"; + + @Override + public String getRequestTokenEndpoint() { + return REQUEST_TOKEN_URL; + } + + @Override + public String getAccessTokenEndpoint() { + return ACCESS_TOKEN_URL; + } + + @Override + public String getAuthorizationUrl(Token requestToken) { + return String.format(AUTHORIZE_URL, requestToken.getToken()); + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/TrelloApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/TrelloApi.java new file mode 100644 index 000000000..d3ce8372b --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/TrelloApi.java @@ -0,0 +1,25 @@ +package com.github.scribejava.apis; + +import com.github.scribejava.core.builder.api.DefaultApi10a; +import com.github.scribejava.core.model.Token; + +public class TrelloApi extends DefaultApi10a { + + private static final String AUTHORIZE_URL = "https://trello.com/1/OAuthAuthorizeToken?oauth_token=%s"; + + @Override + public String getAccessTokenEndpoint() { + return "https://trello.com/1/OAuthGetAccessToken"; + } + + @Override + public String getRequestTokenEndpoint() { + return "https://trello.com/1/OAuthGetRequestToken"; + } + + @Override + public String getAuthorizationUrl(Token requestToken) { + return String.format(AUTHORIZE_URL, requestToken.getToken()); + } + +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/TumblrApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/TumblrApi.java new file mode 100644 index 000000000..3330c2320 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/TumblrApi.java @@ -0,0 +1,26 @@ +package com.github.scribejava.apis; + +import com.github.scribejava.core.builder.api.DefaultApi10a; +import com.github.scribejava.core.model.Token; + +public class TumblrApi extends DefaultApi10a { + + private static final String AUTHORIZE_URL = "https://www.tumblr.com/oauth/authorize?oauth_token=%s"; + private static final String REQUEST_TOKEN_RESOURCE = "http://www.tumblr.com/oauth/request_token"; + private static final String ACCESS_TOKEN_RESOURCE = "http://www.tumblr.com/oauth/access_token"; + + @Override + public String getAccessTokenEndpoint() { + return ACCESS_TOKEN_RESOURCE; + } + + @Override + public String getRequestTokenEndpoint() { + return REQUEST_TOKEN_RESOURCE; + } + + @Override + public String getAuthorizationUrl(Token requestToken) { + return String.format(AUTHORIZE_URL, requestToken.getToken()); + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/TutByApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/TutByApi.java new file mode 100644 index 000000000..6bd46476b --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/TutByApi.java @@ -0,0 +1,42 @@ +package com.github.scribejava.apis; + +import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.extractors.AccessTokenExtractor; +import com.github.scribejava.core.extractors.JsonTokenExtractor; +import com.github.scribejava.core.model.OAuthConfig; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.oauth.OAuthService; +import com.github.scribejava.core.utils.OAuthEncoder; +import com.github.scribejava.core.utils.Preconditions; +import com.github.scribejava.apis.service.TutByOAuthServiceImpl; + +public class TutByApi extends DefaultApi20 { + + private static final String AUTHORIZE_URL = "http://profile.tut.by/auth?client_id=%s&response_type=code&redirect_uri=%s"; + + @Override + public String getAccessTokenEndpoint() { + return "http://profile.tut.by/getToken"; + } + + @Override + public Verb getAccessTokenVerb() { + return Verb.POST; + } + + @Override + public String getAuthorizationUrl(OAuthConfig config) { + Preconditions.checkValidUrl(config.getCallback(), "Valid url is required for a callback. Tut.by does not support OOB"); + return String.format(AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback())); + } + + @Override + public OAuthService createService(OAuthConfig config) { + return new TutByOAuthServiceImpl(this, config); + } + + @Override + public AccessTokenExtractor getAccessTokenExtractor() { + return new JsonTokenExtractor(); + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/TwitterApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/TwitterApi.java new file mode 100644 index 000000000..e9fad1ca9 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/TwitterApi.java @@ -0,0 +1,41 @@ +package com.github.scribejava.apis; + +import com.github.scribejava.core.builder.api.DefaultApi10a; +import com.github.scribejava.core.model.Token; + +public class TwitterApi extends DefaultApi10a { + + private static final String AUTHORIZE_URL = "https://api.twitter.com/oauth/authorize?oauth_token=%s"; + private static final String REQUEST_TOKEN_RESOURCE = "api.twitter.com/oauth/request_token"; + private static final String ACCESS_TOKEN_RESOURCE = "api.twitter.com/oauth/access_token"; + + @Override + public String getAccessTokenEndpoint() { + return "https://" + ACCESS_TOKEN_RESOURCE; + } + + @Override + public String getRequestTokenEndpoint() { + return "https://" + REQUEST_TOKEN_RESOURCE; + } + + @Override + public String getAuthorizationUrl(Token requestToken) { + return String.format(AUTHORIZE_URL, requestToken.getToken()); + } + + /** + * Twitter 'friendlier' authorization endpoint for OAuth. + * + * Uses SSL. + */ + public static class Authenticate extends TwitterApi { + + private static final String AUTHENTICATE_URL = "https://api.twitter.com/oauth/authenticate?oauth_token=%s"; + + @Override + public String getAuthorizationUrl(Token requestToken) { + return String.format(AUTHENTICATE_URL, requestToken.getToken()); + } + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/UbuntuOneApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/UbuntuOneApi.java new file mode 100644 index 000000000..1ae973524 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/UbuntuOneApi.java @@ -0,0 +1,37 @@ +package com.github.scribejava.apis; + +import com.github.scribejava.core.builder.api.DefaultApi10a; +import com.github.scribejava.core.model.Token; +import com.github.scribejava.core.services.PlaintextSignatureService; +import com.github.scribejava.core.services.SignatureService; + +/** + * @author Julio Gutierrez + * + * Sep 6, 2012 + */ +public class UbuntuOneApi extends DefaultApi10a { + + private static final String AUTHORIZATION_URL = "https://one.ubuntu.com/oauth/authorize/?oauth_token=%s"; + + @Override + public String getAccessTokenEndpoint() { + return "https://one.ubuntu.com/oauth/access/"; + } + + @Override + public String getAuthorizationUrl(Token requestToken) { + return String.format(AUTHORIZATION_URL, requestToken.getToken()); + } + + @Override + public String getRequestTokenEndpoint() { + return "https://one.ubuntu.com/oauth/request/"; + } + + @Override + public SignatureService getSignatureService() { + return new PlaintextSignatureService(); + } + +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/ViadeoApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/ViadeoApi.java new file mode 100644 index 000000000..c4d558500 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/ViadeoApi.java @@ -0,0 +1,38 @@ +package com.github.scribejava.apis; + +import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.extractors.AccessTokenExtractor; +import com.github.scribejava.core.extractors.JsonTokenExtractor; +import com.github.scribejava.core.model.OAuthConfig; +import com.github.scribejava.core.model.OAuthConstants; +import com.github.scribejava.core.utils.OAuthEncoder; +import com.github.scribejava.core.utils.Preconditions; + +public class ViadeoApi extends DefaultApi20 { + + private static final String AUTHORIZE_URL = "https://secure.viadeo.com/oauth-provider/authorize2?client_id=%s&redirect_uri=%s&response_type=code"; + private static final String SCOPED_AUTHORIZE_URL = AUTHORIZE_URL + "&scope=%s"; + + @Override + public AccessTokenExtractor getAccessTokenExtractor() { + return new JsonTokenExtractor(); + } + + @Override + public String getAccessTokenEndpoint() { + return "https://secure.viadeo.com/oauth-provider/access_token2?grant_type=" + OAuthConstants.AUTHORIZATION_CODE; + } + + @Override + public String getAuthorizationUrl(OAuthConfig config) { + Preconditions.checkValidUrl(config.getCallback(), "Must provide a valid url as callback. Viadeo does not support OOB"); + + // Append scope if present + if (config.hasScope()) { + return String.format(SCOPED_AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()), OAuthEncoder.encode(config. + getScope())); + } else { + return String.format(AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback())); + } + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/VimeoApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/VimeoApi.java new file mode 100644 index 000000000..ccc6d3239 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/VimeoApi.java @@ -0,0 +1,24 @@ +package com.github.scribejava.apis; + +import com.github.scribejava.core.builder.api.DefaultApi10a; +import com.github.scribejava.core.model.Token; + +public class VimeoApi extends DefaultApi10a { + + private static final String AUTHORIZATION_URL = "http://vimeo.com/oauth/authorize?oauth_token=%s"; + + @Override + public String getAccessTokenEndpoint() { + return "http://vimeo.com/oauth/access_token"; + } + + @Override + public String getRequestTokenEndpoint() { + return "http://vimeo.com/oauth/request_token"; + } + + @Override + public String getAuthorizationUrl(Token requestToken) { + return String.format(AUTHORIZATION_URL, requestToken.getToken()); + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/VkontakteApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/VkontakteApi.java new file mode 100644 index 000000000..021f52fa0 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/VkontakteApi.java @@ -0,0 +1,39 @@ +package com.github.scribejava.apis; + +import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.extractors.AccessTokenExtractor; +import com.github.scribejava.core.extractors.JsonTokenExtractor; +import com.github.scribejava.core.model.OAuthConfig; +import com.github.scribejava.core.utils.OAuthEncoder; +import com.github.scribejava.core.utils.Preconditions; + +/** + * @author Boris G. Tsirkin <mail@dotbg.name> + * @since 20.4.2011 + */ +public class VkontakteApi extends DefaultApi20 { + + private static final String AUTHORIZE_URL = "https://oauth.vk.com/authorize?client_id=%s&redirect_uri=%s&response_type=code"; + private static final String SCOPED_AUTHORIZE_URL = String.format("%s&scope=%%s", AUTHORIZE_URL); + + @Override + public String getAccessTokenEndpoint() { + return "https://oauth.vk.com/access_token"; + } + + @Override + public String getAuthorizationUrl(final OAuthConfig config) { + Preconditions.checkValidUrl(config.getCallback(), "Valid url is required for a callback. Vkontakte does not support OOB"); + if (config.hasScope()) { // Appending scope if present + return String.format( + SCOPED_AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()), OAuthEncoder.encode(config.getScope())); + } else { + return String.format(AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback())); + } + } + + @Override + public AccessTokenExtractor getAccessTokenExtractor() { + return new JsonTokenExtractor(); + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/XingApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/XingApi.java new file mode 100755 index 000000000..6621bee81 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/XingApi.java @@ -0,0 +1,25 @@ +package com.github.scribejava.apis; + +import com.github.scribejava.core.builder.api.DefaultApi10a; +import com.github.scribejava.core.model.Token; + +public class XingApi extends DefaultApi10a { + + private static final String AUTHORIZE_URL = "https://api.xing.com/v1/authorize?oauth_token=%s"; + + @Override + public String getAccessTokenEndpoint() { + return "https://api.xing.com/v1/access_token"; + } + + @Override + public String getRequestTokenEndpoint() { + return "https://api.xing.com/v1/request_token"; + } + + @Override + public String getAuthorizationUrl(Token requestToken) { + return String.format(AUTHORIZE_URL, requestToken.getToken()); + } + +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/YahooApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/YahooApi.java new file mode 100644 index 000000000..5a080d915 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/YahooApi.java @@ -0,0 +1,24 @@ +package com.github.scribejava.apis; + +import com.github.scribejava.core.builder.api.DefaultApi10a; +import com.github.scribejava.core.model.Token; + +public class YahooApi extends DefaultApi10a { + + private static final String AUTHORIZE_URL = "https://api.login.yahoo.com/oauth/v2/request_auth?oauth_token=%s"; + + @Override + public String getAccessTokenEndpoint() { + return "https://api.login.yahoo.com/oauth/v2/get_token"; + } + + @Override + public String getRequestTokenEndpoint() { + return "https://api.login.yahoo.com/oauth/v2/get_request_token"; + } + + @Override + public String getAuthorizationUrl(Token requestToken) { + return String.format(AUTHORIZE_URL, requestToken.getToken()); + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/YammerApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/YammerApi.java new file mode 100644 index 000000000..c31ebc1dc --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/YammerApi.java @@ -0,0 +1,31 @@ +package com.github.scribejava.apis; + +import com.github.scribejava.core.builder.api.DefaultApi10a; +import com.github.scribejava.core.model.Token; +import com.github.scribejava.core.services.PlaintextSignatureService; +import com.github.scribejava.core.services.SignatureService; + +public class YammerApi extends DefaultApi10a { + + private static final String AUTHORIZATION_URL = "https://www.yammer.com/oauth/authorize?oauth_token=%s"; + + @Override + public String getRequestTokenEndpoint() { + return "https://www.yammer.com/oauth/request_token"; + } + + @Override + public String getAccessTokenEndpoint() { + return "https://www.yammer.com/oauth/access_token"; + } + + @Override + public String getAuthorizationUrl(Token requestToken) { + return String.format(AUTHORIZATION_URL, requestToken.getToken()); + } + + @Override + public SignatureService getSignatureService() { + return new PlaintextSignatureService(); + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/google/GoogleJsonTokenExtractor.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/google/GoogleJsonTokenExtractor.java new file mode 100644 index 000000000..7c8a326c4 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/google/GoogleJsonTokenExtractor.java @@ -0,0 +1,26 @@ +package com.github.scribejava.apis.google; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import com.github.scribejava.core.extractors.JsonTokenExtractor; + +/** + * additionally parses OpenID id_token + */ +public class GoogleJsonTokenExtractor extends JsonTokenExtractor { + + private static final Pattern ID_TOKEN_PATTERN = Pattern.compile("\"id_token\"\\s*:\\s*\"(\\S*?)\""); + + @Override + public GoogleToken extract(final String response) { + return new GoogleToken(extractAccessToken(response), "", response, extractOpenIdToken(response)); + } + + private String extractOpenIdToken(final String response) { + final Matcher matcher = ID_TOKEN_PATTERN.matcher(response); + if (matcher.find()) { + return matcher.group(1); + } + return null; + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/google/GoogleToken.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/google/GoogleToken.java new file mode 100644 index 000000000..a8af3782a --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/google/GoogleToken.java @@ -0,0 +1,26 @@ +package com.github.scribejava.apis.google; + +import com.github.scribejava.core.model.Token; + +public class GoogleToken extends Token { + + /** + * Id_token is part of OpenID Connect specification. It can hold user information that you can directly extract without additional request to + * provider. See http://openid.net/specs/openid-connect-core-1_0.html#id_token-tokenExample and + * https://bitbucket.org/nimbusds/nimbus-jose-jwt/wiki/Home + * + * Here will be encoded and signed id token in JWT format or null, if not defined. + */ + private final String openIdToken; + + public GoogleToken(final String token, final String secret, final String rawResponse, final String openIdToken) { + super(token, secret, rawResponse); + this.openIdToken = openIdToken; + } + + @Override + public String toString() { + return String.format("GoogleToken{'token'='%s', 'secret'='%s', 'openIdToken'='%s']", getToken(), getSecret(), + openIdToken); + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/DoktornaraboteOAuthServiceImpl.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/DoktornaraboteOAuthServiceImpl.java new file mode 100644 index 000000000..983f65feb --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/DoktornaraboteOAuthServiceImpl.java @@ -0,0 +1,19 @@ +package com.github.scribejava.apis.service; + +import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.model.AbstractRequest; +import com.github.scribejava.core.model.OAuthConfig; +import com.github.scribejava.core.model.Token; +import com.github.scribejava.core.oauth.OAuth20ServiceImpl; + +public class DoktornaraboteOAuthServiceImpl extends OAuth20ServiceImpl { + + public DoktornaraboteOAuthServiceImpl(DefaultApi20 api, OAuthConfig config) { + super(api, config); + } + + @Override + public void signRequest(Token accessToken, AbstractRequest request) { + request.addHeader("Authorization", "Bearer " + accessToken.getToken()); + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/GoogleOAuthServiceImpl.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/GoogleOAuthServiceImpl.java new file mode 100644 index 000000000..fe8f9f241 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/GoogleOAuthServiceImpl.java @@ -0,0 +1,24 @@ +package com.github.scribejava.apis.service; + +import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.model.AbstractRequest; +import com.github.scribejava.core.model.OAuthConfig; +import com.github.scribejava.core.model.OAuthConstants; +import com.github.scribejava.core.model.Verifier; +import com.github.scribejava.core.oauth.OAuth20ServiceImpl; + +public class GoogleOAuthServiceImpl extends OAuth20ServiceImpl { + + public GoogleOAuthServiceImpl(DefaultApi20 api, OAuthConfig config) { + super(api, config); + } + + @Override + protected T createAccessTokenRequest(final Verifier verifier, T request) { + super.createAccessTokenRequest(verifier, request); + if (!getConfig().hasGrantType()) { + request.addParameter(OAuthConstants.GRANT_TYPE, "authorization_code"); + } + return (T) request; + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/HHOAuthServiceImpl.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/HHOAuthServiceImpl.java new file mode 100644 index 000000000..03b7fc457 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/HHOAuthServiceImpl.java @@ -0,0 +1,19 @@ +package com.github.scribejava.apis.service; + +import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.model.AbstractRequest; +import com.github.scribejava.core.model.OAuthConfig; +import com.github.scribejava.core.model.Token; +import com.github.scribejava.core.oauth.OAuth20ServiceImpl; + +public class HHOAuthServiceImpl extends OAuth20ServiceImpl { + + public HHOAuthServiceImpl(DefaultApi20 api, OAuthConfig config) { + super(api, config); + } + + @Override + public void signRequest(Token accessToken, AbstractRequest request) { + request.addHeader("Authorization", "Bearer " + accessToken.getToken()); + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/LinkedIn20ServiceImpl.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/LinkedIn20ServiceImpl.java new file mode 100644 index 000000000..d72495487 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/LinkedIn20ServiceImpl.java @@ -0,0 +1,30 @@ +package com.github.scribejava.apis.service; + +import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.model.AbstractRequest; +import com.github.scribejava.core.model.OAuthConfig; +import com.github.scribejava.core.model.OAuthConstants; +import com.github.scribejava.core.model.Token; +import com.github.scribejava.core.model.Verifier; +import com.github.scribejava.core.oauth.OAuth20ServiceImpl; + +public class LinkedIn20ServiceImpl extends OAuth20ServiceImpl { + + public LinkedIn20ServiceImpl(final DefaultApi20 api, final OAuthConfig config) { + super(api, config); + } + + @Override + public void signRequest(Token accessToken, AbstractRequest request) { + request.addQuerystringParameter("oauth2_access_token", accessToken.getToken()); + } + + @Override + protected T createAccessTokenRequest(final Verifier verifier, T request) { + super.createAccessTokenRequest(verifier, request); + if (!getConfig().hasGrantType()) { + request.addParameter(OAuthConstants.GRANT_TYPE, "authorization_code"); + } + return (T) request; + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthServiceImpl.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthServiceImpl.java new file mode 100644 index 000000000..745aa6478 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthServiceImpl.java @@ -0,0 +1,62 @@ +package com.github.scribejava.apis.service; + +import java.io.UnsupportedEncodingException; +import java.net.URLDecoder; +import java.util.Map; +import java.util.TreeMap; +import org.apache.commons.codec.CharEncoding; +import static org.apache.commons.codec.digest.DigestUtils.md5Hex; +import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.model.AbstractRequest; +import com.github.scribejava.core.model.OAuthConfig; +import com.github.scribejava.core.model.OAuthConstants; +import com.github.scribejava.core.model.Token; +import com.github.scribejava.core.model.Verifier; +import com.github.scribejava.core.oauth.OAuth20ServiceImpl; + +public class MailruOAuthServiceImpl extends OAuth20ServiceImpl { + + public MailruOAuthServiceImpl(DefaultApi20 api, OAuthConfig config) { + super(api, config); + } + + @Override + public void signRequest(final Token accessToken, final AbstractRequest request) { + // sig = md5(params + secret_key) + request.addQuerystringParameter("session_key", accessToken.getToken()); + request.addQuerystringParameter("app_id", getConfig().getApiKey()); + String completeUrl = request.getCompleteUrl(); + + try { + final String clientSecret = getConfig().getApiSecret(); + final int queryIndex = completeUrl.indexOf('?'); + if (queryIndex != -1) { + String urlPart = completeUrl.substring(queryIndex + 1); + Map map = new TreeMap<>(); + for (String param : urlPart.split("&")) { + String[] parts = param.split("="); + map.put(parts[0], (parts.length == 1) ? "" : parts[1]); + } + StringBuilder urlNew = new StringBuilder(); + for (Map.Entry entry : map.entrySet()) { + urlNew.append(entry.getKey()); + urlNew.append('='); + urlNew.append(entry.getValue()); + } + final String sigSource = URLDecoder.decode(urlNew.toString(), CharEncoding.UTF_8) + clientSecret; + request.addQuerystringParameter("sig", md5Hex(sigSource)); + } + } catch (UnsupportedEncodingException e) { + throw new IllegalStateException(e); + } + } + + @Override + protected T createAccessTokenRequest(final Verifier verifier, T request) { + super.createAccessTokenRequest(verifier, request); + if (!getConfig().hasGrantType()) { + request.addParameter(OAuthConstants.GRANT_TYPE, "authorization_code"); + } + return (T) request; + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiServiceImpl.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiServiceImpl.java new file mode 100644 index 000000000..357d03dce --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiServiceImpl.java @@ -0,0 +1,37 @@ +package com.github.scribejava.apis.service; + +import java.io.UnsupportedEncodingException; +import java.net.URLDecoder; +import org.apache.commons.codec.CharEncoding; +import static org.apache.commons.codec.digest.DigestUtils.md5Hex; +import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.model.AbstractRequest; +import com.github.scribejava.core.model.OAuthConfig; +import com.github.scribejava.core.model.Token; +import com.github.scribejava.core.oauth.OAuth20ServiceImpl; + +public class OdnoklassnikiServiceImpl extends OAuth20ServiceImpl { + + public OdnoklassnikiServiceImpl(final DefaultApi20 api, final OAuthConfig config) { + super(api, config); + } + + @Override + public void signRequest(final Token accessToken, final AbstractRequest request) { + // sig = md5( request_params_composed_string+ md5(access_token + application_secret_key) ) + try { + final String tokenDigest = md5Hex((accessToken.getToken() + getConfig().getApiSecret())); + + final String completeUrl = request.getCompleteUrl(); + final int queryIndex = completeUrl.indexOf('?'); + if (queryIndex != -1) { + final String sigSource = URLDecoder.decode(completeUrl.substring(queryIndex + 1).replace("&", ""), CharEncoding.UTF_8) + tokenDigest; + request.addQuerystringParameter("sig", md5Hex(sigSource)); + } + + super.signRequest(accessToken, request); + } catch (UnsupportedEncodingException unex) { + throw new IllegalStateException(unex); + } + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/TutByOAuthServiceImpl.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/TutByOAuthServiceImpl.java new file mode 100644 index 000000000..08ebbce0e --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/TutByOAuthServiceImpl.java @@ -0,0 +1,21 @@ +package com.github.scribejava.apis.service; + +import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.model.AbstractRequest; +import com.github.scribejava.core.model.OAuthConfig; +import com.github.scribejava.core.model.OAuthConstants; +import com.github.scribejava.core.model.Token; +import com.github.scribejava.core.oauth.OAuth20ServiceImpl; + +public class TutByOAuthServiceImpl extends OAuth20ServiceImpl { + + public TutByOAuthServiceImpl(DefaultApi20 api, OAuthConfig config) { + super(api, config); + } + + @Override + public void signRequest(Token accessToken, AbstractRequest request) { + request.addQuerystringParameter(OAuthConstants.TOKEN, accessToken.getToken()); + } + +} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AWeberExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AWeberExample.java new file mode 100644 index 000000000..4776cf3ef --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AWeberExample.java @@ -0,0 +1,66 @@ +package com.github.scribejava.apis.examples; + +import java.util.Scanner; +import com.github.scribejava.core.builder.ServiceBuilder; +import com.github.scribejava.apis.AWeberApi; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.Token; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.model.Verifier; +import com.github.scribejava.core.oauth.OAuthService; + +public class AWeberExample { + + //To get your consumer key/secret, and view API docs, see https://labs.aweber.com/docs + private static final String ACCOUNT_RESOURCE_URL = "https://api.aweber.com/1.0/accounts/"; + + private static final String CONSUMER_KEY = ""; + private static final String CONSUMER_SECRET = ""; + + public static void main(String[] args) { + OAuthService service = new ServiceBuilder() + .provider(AWeberApi.class) + .apiKey(CONSUMER_KEY) + .apiSecret(CONSUMER_SECRET) + .build(); + + Scanner in = new Scanner(System.in); + + System.out.println("=== AWeber's OAuth Workflow ==="); + System.out.println(); + + // Obtain the Request Token + System.out.println("Fetching the Request Token..."); + Token requestToken = service.getRequestToken(); + System.out.println("Got the Request Token!"); + System.out.println(); + + System.out.println("Now go and authorize ScribeJava here:"); + System.out.println(service.getAuthorizationUrl(requestToken)); + System.out.println("And paste the verifier here"); + System.out.print(">>"); + Verifier verifier = new Verifier(in.nextLine()); + System.out.println(); + + // Trade the Request Token and Verfier for the Access Token + System.out.println("Trading the Request Token for an Access Token..."); + Token accessToken = service.getAccessToken(requestToken, verifier); + System.out.println("Got the Access Token!"); + System.out.println("(if your curious it looks like this: " + accessToken + " )"); + System.out.println(); + + // Now let's go and ask for a protected resource! + System.out.println("Now we're going to access a protected resource..."); + OAuthRequest request = new OAuthRequest(Verb.GET, ACCOUNT_RESOURCE_URL, service); + service.signRequest(accessToken, request); + Response response = request.send(); + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getBody()); + + System.out.println(); + System.out.println("Thats it man! Go and build something awesome with AWeber and ScribeJava! :)"); + } + +} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiggExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiggExample.java new file mode 100644 index 000000000..c095d4284 --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiggExample.java @@ -0,0 +1,67 @@ +package com.github.scribejava.apis.examples; + +import java.util.Scanner; +import com.github.scribejava.core.builder.ServiceBuilder; +import com.github.scribejava.apis.DiggApi; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.Token; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.model.Verifier; +import com.github.scribejava.core.oauth.OAuthService; + +public class DiggExample { + + private static final String NETWORK_NAME = "Digg"; + private static final String PROTECTED_RESOURCE_URL = "http://services.digg.com/2.0/comment.digg"; + + public static void main(String[] args) { + // Replace these with your own api key and secret + String apiKey = "myKey"; + String apiSecret = "mySecret"; + OAuthService service = new ServiceBuilder().provider(DiggApi.class).apiKey(apiKey).apiSecret(apiSecret).build(); + Scanner in = new Scanner(System.in); + + System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); + System.out.println(); + + // Obtain the Request Token + System.out.println("Fetching the Request Token..."); + Token requestToken = service.getRequestToken(); + System.out.println("Got the Request Token!"); + System.out.println(); + + // Obtain the Authorization URL + System.out.println("Fetching the Authorization URL..."); + String authorizationUrl = service.getAuthorizationUrl(requestToken); + System.out.println("Got the Authorization URL!"); + System.out.println("Now go and authorize ScribeJava here:"); + System.out.println(authorizationUrl); + System.out.println("And paste the authorization code here"); + System.out.print(">>"); + Verifier verifier = new Verifier(in.nextLine()); + System.out.println(); + + // Trade the Request Token and Verfier for the Access Token + System.out.println("Trading the Request Token for an Access Token..."); + Token accessToken = service.getAccessToken(requestToken, verifier); + System.out.println("Got the Access Token!"); + System.out.println("(if your curious it looks like this: " + accessToken + " )"); + System.out.println(); + + // Now let's go and ask for a protected resource! + System.out.println("Now we're going to access a protected resource..."); + OAuthRequest request = new OAuthRequest(Verb.POST, PROTECTED_RESOURCE_URL, service); + request.addBodyParameter("comment_id", "20100729223726:4fef610331ee46a3b5cbd740bf71313e"); + service.signRequest(accessToken, request); + Response response = request.send(); + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + + System.out.println(); + System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); + + } +} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncExample.java new file mode 100644 index 000000000..0c7663bbb --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncExample.java @@ -0,0 +1,96 @@ +package com.github.scribejava.apis.examples; + +import com.ning.http.client.AsyncHttpClientConfig; +import java.util.Random; +import java.util.Scanner; +import java.util.concurrent.ExecutionException; +import com.github.scribejava.apis.FacebookApi; +import com.github.scribejava.core.builder.ServiceBuilderAsync; +import com.github.scribejava.core.model.ForceTypeOfHttpRequest; +import com.github.scribejava.core.model.OAuthRequestAsync; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.ScribeJavaConfig; +import com.github.scribejava.core.model.Token; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.model.Verifier; +import com.github.scribejava.core.oauth.OAuthService; + +public abstract class FacebookAsyncExample { + + private static final String NETWORK_NAME = "Facebook"; + private static final String PROTECTED_RESOURCE_URL = "https://graph.facebook.com/v2.2/me"; + private static final Token EMPTY_TOKEN = null; + + public static void main(final String... args) throws InterruptedException, ExecutionException { + // Replace these with your client id and secret + final String clientId = "your client id"; + final String clientSecret = "your client secret"; + final String secretState = "secret" + new Random().nextInt(999_999); + ScribeJavaConfig.setForceTypeOfHttpRequests(ForceTypeOfHttpRequest.FORCE_ASYNC_ONLY_HTTP_REQUESTS); + final AsyncHttpClientConfig clientConfig = new AsyncHttpClientConfig.Builder() + .setMaxConnections(5) + .setRequestTimeout(10000) + .setAllowPoolingConnections(false) + .setPooledConnectionIdleTimeout(1000) + .setReadTimeout(1000) + .build(); + + final OAuthService service = new ServiceBuilderAsync() + .provider(FacebookApi.class) + .apiKey(clientId) + .apiSecret(clientSecret) + .state(secretState) + .callback("http://www.example.com/oauth_callback/") + .asyncHttpClientConfig(clientConfig) + .build(); + + final Scanner in = new Scanner(System.in, "UTF-8"); + + System.out.println("=== " + NETWORK_NAME + "'s Async OAuth Workflow ==="); + System.out.println(); + + // Obtain the Authorization URL + System.out.println("Fetching the Authorization URL..."); + final String authorizationUrl = service.getAuthorizationUrl(EMPTY_TOKEN); + 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 Verifier verifier = new Verifier(in.nextLine()); + System.out.println(); + + System.out.println("And paste the state from server here. We have set 'secretState'='" + secretState + "'."); + System.out.print(">>"); + final String value = in.nextLine(); + if (secretState.equals(value)) { + System.out.println("State value does match!"); + } else { + System.out.println("Ooops, state value does not match!"); + System.out.println("Expected = " + secretState); + System.out.println("Got = " + value); + System.out.println(); + } + + // Trade the Request Token and Verfier for the Access Token + System.out.println("Trading the Request Token for an Access Token..."); + final Token accessToken = service.getAccessTokenAsync(EMPTY_TOKEN, verifier, null).get(); + System.out.println("Got the Access Token!"); + System.out.println("(if your curious it looks like this: " + accessToken + " )"); + 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 OAuthRequestAsync request = new OAuthRequestAsync(Verb.GET, PROTECTED_RESOURCE_URL, service); + service.signRequest(accessToken, request); + final Response response = request.sendAsync(null).get(); + 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! :)"); + service.closeAsyncClient(); + } +} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java new file mode 100644 index 000000000..0d87dd7a2 --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java @@ -0,0 +1,81 @@ +package com.github.scribejava.apis.examples; + +import java.util.Random; +import java.util.Scanner; +import com.github.scribejava.apis.FacebookApi; +import com.github.scribejava.core.builder.ServiceBuilder; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.Token; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.model.Verifier; +import com.github.scribejava.core.oauth.OAuthService; + +public abstract class FacebookExample { + + private static final String NETWORK_NAME = "Facebook"; + private static final String PROTECTED_RESOURCE_URL = "https://graph.facebook.com/v2.2/me"; + private static final Token EMPTY_TOKEN = null; + + public static void main(final String... args) { + // Replace these with your client id and secret + final String clientId = "your client id"; + final String clientSecret = "your client secret"; + final String secretState = "secret" + new Random().nextInt(999_999); + final OAuthService service = new ServiceBuilder() + .provider(FacebookApi.class) + .apiKey(clientId) + .apiSecret(clientSecret) + .state(secretState) + .callback("http://www.example.com/oauth_callback/") + .build(); + 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(EMPTY_TOKEN); + 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 Verifier verifier = new Verifier(in.nextLine()); + System.out.println(); + + System.out.println("And paste the state from server here. We have set 'secretState'='" + secretState + "'."); + System.out.print(">>"); + final String value = in.nextLine(); + if (secretState.equals(value)) { + System.out.println("State value does match!"); + } else { + System.out.println("Ooops, state value does not match!"); + System.out.println("Expected = " + secretState); + System.out.println("Got = " + value); + System.out.println(); + } + + // Trade the Request Token and Verfier for the Access Token + System.out.println("Trading the Request Token for an Access Token..."); + final Token accessToken = service.getAccessToken(EMPTY_TOKEN, verifier); + System.out.println("Got the Access Token!"); + System.out.println("(if your curious it looks like this: " + accessToken + " )"); + 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); + service.signRequest(accessToken, request); + final Response response = request.send(); + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + + System.out.println(); + System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); + + } +} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExample.java new file mode 100644 index 000000000..39c96547e --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExample.java @@ -0,0 +1,62 @@ +package com.github.scribejava.apis.examples; + +import java.util.Scanner; +import com.github.scribejava.core.builder.ServiceBuilder; +import com.github.scribejava.apis.FlickrApi; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.Token; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.model.Verifier; +import com.github.scribejava.core.oauth.OAuthService; + +public class FlickrExample { + + private static final String PROTECTED_RESOURCE_URL = "http://api.flickr.com/services/rest/"; + + public static void main(String[] args) { + // Replace these with your own api key and secret + String apiKey = "your_app_id"; + String apiSecret = "your_api_secret"; + OAuthService service = new ServiceBuilder().provider(FlickrApi.class).apiKey(apiKey).apiSecret(apiSecret). + build(); + Scanner in = new Scanner(System.in); + + System.out.println("=== Flickr's OAuth Workflow ==="); + System.out.println(); + + // Obtain the Request Token + System.out.println("Fetching the Request Token..."); + Token requestToken = service.getRequestToken(); + System.out.println("Got the Request Token!"); + System.out.println(); + + System.out.println("Now go and authorize ScribeJava here:"); + String authorizationUrl = service.getAuthorizationUrl(requestToken); + System.out.println(authorizationUrl + "&perms=read"); + System.out.println("And paste the verifier here"); + System.out.print(">>"); + Verifier verifier = new Verifier(in.nextLine()); + System.out.println(); + + // Trade the Request Token and Verfier for the Access Token + System.out.println("Trading the Request Token for an Access Token..."); + Token accessToken = service.getAccessToken(requestToken, verifier); + System.out.println("Got the Access Token!"); + System.out.println("(if your curious it looks like this: " + accessToken + " )"); + System.out.println(); + + // Now let's go and ask for a protected resource! + System.out.println("Now we're going to access a protected resource..."); + OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service); + request.addQuerystringParameter("method", "flickr.test.login"); + service.signRequest(accessToken, request); + Response response = request.send(); + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getBody()); + + System.out.println(); + System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); + } +} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java new file mode 100644 index 000000000..fc36713c8 --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java @@ -0,0 +1,65 @@ +package com.github.scribejava.apis.examples; + +import java.util.Scanner; +import com.github.scribejava.core.builder.ServiceBuilder; +import com.github.scribejava.apis.Foursquare2Api; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.Token; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.model.Verifier; +import com.github.scribejava.core.oauth.OAuthService; + +public class Foursquare2Example { + + private static final String PROTECTED_RESOURCE_URL = "https://api.foursquare.com/v2/users/self/friends?oauth_token="; + private static final Token EMPTY_TOKEN = null; + + public static void main(String[] args) { + // Replace these with your own api key and secret + String apiKey = "FEGFXJUFANVVDHVSNUAMUKTTXCP1AJQD53E33XKJ44YP1S4I"; + String apiSecret = "AYWKUL5SWPNC0CTQ202QXRUG2NLZYXMRA34ZSDW4AUYBG2RC"; + OAuthService service = new ServiceBuilder() + .provider(Foursquare2Api.class) + .apiKey(apiKey) + .apiSecret(apiSecret) + .callback("http://localhost:9000/") + .build(); + Scanner in = new Scanner(System.in); + + System.out.println("=== Foursquare2's OAuth Workflow ==="); + System.out.println(); + + // Obtain the Authorization URL + System.out.println("Fetching the Authorization URL..."); + String authorizationUrl = service.getAuthorizationUrl(EMPTY_TOKEN); + 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(">>"); + Verifier verifier = new Verifier(in.nextLine()); + System.out.println(); + + // Trade the Request Token and Verfier for the Access Token + System.out.println("Trading the Request Token for an Access Token..."); + Token accessToken = service.getAccessToken(EMPTY_TOKEN, verifier); + System.out.println("Got the Access Token!"); + System.out.println("(if your curious it looks like this: " + accessToken + " )"); + System.out.println(); + + // Now let's go and ask for a protected resource! + System.out.println("Now we're going to access a protected resource..."); + OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL + accessToken.getToken(), service); + service.signRequest(accessToken, request); + Response response = request.send(); + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + + System.out.println(); + System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); + + } +} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FoursquareExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FoursquareExample.java new file mode 100644 index 000000000..73ad37d7f --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FoursquareExample.java @@ -0,0 +1,61 @@ +package com.github.scribejava.apis.examples; + +import java.util.Scanner; +import com.github.scribejava.core.builder.ServiceBuilder; +import com.github.scribejava.apis.FoursquareApi; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.Token; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.model.Verifier; +import com.github.scribejava.core.oauth.OAuthService; + +public class FoursquareExample { + + private static final String PROTECTED_RESOURCE_URL = "http://api.foursquare.com/v1/user"; + + public static void main(String[] args) { + OAuthService service = new ServiceBuilder() + .provider(FoursquareApi.class) + .apiKey("FEGFXJUFANVVDHVSNUAMUKTTXCP1AJQD53E33XKJ44YP1S4I") + .apiSecret("AYWKUL5SWPNC0CTQ202QXRUG2NLZYXMRA34ZSDW4AUYBG2RC") + .build(); + Scanner in = new Scanner(System.in); + + System.out.println("=== Foursquare's OAuth Workflow ==="); + System.out.println(); + + // Obtain the Request Token + System.out.println("Fetching the Request Token..."); + Token requestToken = service.getRequestToken(); + System.out.println("Got the Request Token!"); + System.out.println(); + + System.out.println("Now go and authorize ScribeJava here:"); + System.out.println(service.getAuthorizationUrl(requestToken)); + System.out.println("And paste the verifier here"); + System.out.print(">>"); + Verifier verifier = new Verifier(in.nextLine()); + System.out.println(); + + // Trade the Request Token and Verfier for the Access Token + System.out.println("Trading the Request Token for an Access Token..."); + Token accessToken = service.getAccessToken(requestToken, verifier); + System.out.println("Got the Access Token!"); + System.out.println("(if your curious it looks like this: " + accessToken + " )"); + System.out.println(); + + // Now let's go and ask for a protected resource! + System.out.println("Now we're going to access a protected resource..."); + OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service); + service.signRequest(accessToken, request); + Response response = request.send(); + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getBody()); + + System.out.println(); + System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); + } + +} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java new file mode 100644 index 000000000..1683c8f72 --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java @@ -0,0 +1,70 @@ +package com.github.scribejava.apis.examples; + +import java.util.Scanner; +import com.github.scribejava.core.builder.ServiceBuilder; +import com.github.scribejava.apis.FreelancerApi; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.SignatureType; +import com.github.scribejava.core.model.Token; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.model.Verifier; +import com.github.scribejava.core.oauth.OAuthService; + +public class FreelancerExample { + + private static final String NETWORK_NAME = "Freelancer"; + private static final String AUTHORIZE_URL + = "http://www.sandbox.freelancer.com/users/api-token/auth.php?oauth_token="; + private static final String PROTECTED_RESOURCE_URL = "http://api.sandbox.freelancer.com/Job/getJobList.json"; + private static final String SCOPE = "http://api.sandbox.freelancer.com"; + + public static void main(String[] args) { + OAuthService service = new ServiceBuilder() + .provider(FreelancerApi.Sandbox.class) + .signatureType(SignatureType.QueryString) + .apiKey("7f5a168a0bfdbd15b4a9ea2a969661c731cdea56") + .apiSecret("7bb8961b94873802f1c5344f671a518e087f5785") + .scope(SCOPE) + .build(); + Scanner in = new Scanner(System.in); + + System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); + System.out.println(); + + // Obtain the Request Token + System.out.println("Fetching the Request Token..."); + Token requestToken = service.getRequestToken(); + System.out.println("Got the Request Token!"); + System.out.println("(if your curious it looks like this: " + requestToken + " )"); + System.out.println(); + + System.out.println("Now go and authorize ScribeJava here:"); + System.out.println(AUTHORIZE_URL + requestToken.getToken()); + System.out.println("And paste the verifier here"); + System.out.print(">>"); + Verifier verifier = new Verifier(in.nextLine()); + System.out.println(); + + // Trade the Request Token and Verfier for the Access Token + System.out.println("Trading the Request Token for an Access Token..."); + Token accessToken = service.getAccessToken(requestToken, verifier); + System.out.println("Got the Access Token!"); + System.out.println("(if your curious it looks like this: " + accessToken + " )"); + System.out.println(); + + // Now let's go and ask for a protected resource! + System.out.println("Now we're going to access a protected resource..."); + OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service); + service.signRequest(accessToken, request); + request.addHeader("GData-Version", "3.0"); + Response response = request.send(); + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + + System.out.println(); + System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); + } +} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubExample.java new file mode 100644 index 000000000..bcbb6b8e4 --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubExample.java @@ -0,0 +1,80 @@ +package com.github.scribejava.apis.examples; + +import java.util.Random; +import java.util.Scanner; +import com.github.scribejava.apis.GitHubApi; +import com.github.scribejava.core.builder.ServiceBuilder; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.Token; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.model.Verifier; +import com.github.scribejava.core.oauth.OAuthService; + +public class GitHubExample { + + private static final String NETWORK_NAME = "GitHub"; + private static final String PROTECTED_RESOURCE_URL = "https://api.github.com/user"; + private static final Token EMPTY_TOKEN = null; + + public static void main(String[] args) { + // Replace these with your client id and secret + final String clientId = "your client id"; + final String clientSecret = "your client secret"; + final String secretState = "secret" + new Random().nextInt(999_999); + final OAuthService service = new ServiceBuilder() + .provider(GitHubApi.class) + .apiKey(clientId) + .apiSecret(clientSecret) + .state(secretState) + .callback("http://www.example.com/oauth_callback/") + .build(); + 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(EMPTY_TOKEN); + 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 Verifier verifier = new Verifier(in.nextLine()); + System.out.println(); + + System.out.println("And paste the state from server here. We have set 'secretState'='" + secretState + "'."); + System.out.print(">>"); + final String value = in.nextLine(); + if (secretState.equals(value)) { + System.out.println("State value does match!"); + } else { + System.out.println("Ooops, state value does not match!"); + System.out.println("Expected = " + secretState); + System.out.println("Got = " + value); + System.out.println(); + } + + // Trade the Request Token and Verfier for the Access Token + System.out.println("Trading the Request Token for an Access Token..."); + final Token accessToken = service.getAccessToken(EMPTY_TOKEN, verifier); + System.out.println("Got the Access Token!"); + System.out.println("(if your curious it looks like this: " + accessToken + " )"); + 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); + service.signRequest(accessToken, request); + final Response response = request.send(); + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + + System.out.println(); + System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); + } +} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java new file mode 100644 index 000000000..60f2a606a --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java @@ -0,0 +1,95 @@ +package com.github.scribejava.apis.examples; + +import java.util.Random; +import java.util.Scanner; +import com.github.scribejava.core.builder.ServiceBuilder; +import com.github.scribejava.apis.GoogleApi20; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.Token; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.model.Verifier; +import com.github.scribejava.core.oauth.OAuth20ServiceImpl; + +public abstract class Google20Example { + + private static final String NETWORK_NAME = "G+"; + private static final String PROTECTED_RESOURCE_URL = "https://www.googleapis.com/plus/v1/people/me"; + private static final Token EMPTY_TOKEN = null; + + public static void main(final String[] args) { + // Replace these with your client id and secret + final String clientId = "your client id"; + final String clientSecret = "your client secret"; + final String secretState = "secret" + new Random().nextInt(999_999); + final OAuth20ServiceImpl service = (OAuth20ServiceImpl) new ServiceBuilder() + .provider(GoogleApi20.class) + .apiKey(clientId) + .apiSecret(clientSecret) + .scope("profile") // replace with desired scope + .state(secretState) + .callback("http://example.com/callback") + .build(); + 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(EMPTY_TOKEN); + 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 Verifier verifier = new Verifier(in.nextLine()); + System.out.println(); + + System.out.println("And paste the state from server here. We have set 'secretState'='" + secretState + "'."); + System.out.print(">>"); + final String value = in.nextLine(); + if (secretState.equals(value)) { + System.out.println("State value does match!"); + } else { + System.out.println("Ooops, state value does not match!"); + System.out.println("Expected = " + secretState); + System.out.println("Got = " + value); + System.out.println(); + } + + // Trade the Request Token and Verfier for the Access Token + System.out.println("Trading the Request Token for an Access Token..."); + final Token accessToken = service.getAccessToken(EMPTY_TOKEN, verifier); + System.out.println("Got the Access Token!"); + System.out.println("(if your curious it looks like this: " + accessToken + " )"); + System.out.println(); + + // Now let's go and ask for a protected resource! + System.out.println("Now we're going to access a protected resource..."); + while (true) { + System.out.println("Paste fieldnames to fetch (leave empty to get profile, 'exit' to stop example)"); + System.out.print(">>"); + final String query = in.nextLine(); + System.out.println(); + + final String requestUrl; + if ("exit".equals(query)) { + break; + } else if (query == null || query.isEmpty()) { + requestUrl = PROTECTED_RESOURCE_URL; + } else { + requestUrl = PROTECTED_RESOURCE_URL + "?fields=" + query; + } + + final OAuthRequest request = new OAuthRequest(Verb.GET, requestUrl, service); + service.signRequest(accessToken, request); + final Response response = request.send(); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + + System.out.println(); + } + } +} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GoogleExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GoogleExample.java new file mode 100644 index 000000000..9a3a12a2c --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GoogleExample.java @@ -0,0 +1,68 @@ +package com.github.scribejava.apis.examples; + +import java.util.Scanner; +import com.github.scribejava.core.builder.ServiceBuilder; +import com.github.scribejava.apis.GoogleApi; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.Token; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.model.Verifier; +import com.github.scribejava.core.oauth.OAuthService; + +public class GoogleExample { + + private static final String NETWORK_NAME = "Google"; + private static final String AUTHORIZE_URL = "https://www.google.com/accounts/OAuthAuthorizeToken?oauth_token="; + private static final String PROTECTED_RESOURCE_URL = "https://docs.google.com/feeds/default/private/full/"; + private static final String SCOPE = "https://docs.google.com/feeds/"; + + public static void main(String[] args) { + OAuthService service = new ServiceBuilder() + .provider(GoogleApi.class) + .apiKey("anonymous") + .apiSecret("anonymous") + .scope(SCOPE) + .build(); + Scanner in = new Scanner(System.in); + + System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); + System.out.println(); + + // Obtain the Request Token + System.out.println("Fetching the Request Token..."); + Token requestToken = service.getRequestToken(); + System.out.println("Got the Request Token!"); + System.out.println("(if your curious it looks like this: " + requestToken + " )"); + System.out.println(); + + System.out.println("Now go and authorize ScribeJava here:"); + System.out.println(AUTHORIZE_URL + requestToken.getToken()); + System.out.println("And paste the verifier here"); + System.out.print(">>"); + Verifier verifier = new Verifier(in.nextLine()); + System.out.println(); + + // Trade the Request Token and Verfier for the Access Token + System.out.println("Trading the Request Token for an Access Token..."); + Token accessToken = service.getAccessToken(requestToken, verifier); + System.out.println("Got the Access Token!"); + System.out.println("(if your curious it looks like this: " + accessToken + " )"); + System.out.println(); + + // Now let's go and ask for a protected resource! + System.out.println("Now we're going to access a protected resource..."); + OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service); + service.signRequest(accessToken, request); + request.addHeader("GData-Version", "3.0"); + Response response = request.send(); + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + + System.out.println(); + System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); + + } +} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HHExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HHExample.java new file mode 100644 index 000000000..31c3df314 --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HHExample.java @@ -0,0 +1,66 @@ +package com.github.scribejava.apis.examples; + +import java.util.Scanner; + +import com.github.scribejava.core.builder.ServiceBuilder; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.Token; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.model.Verifier; +import com.github.scribejava.core.oauth.OAuthService; + +import com.github.scribejava.apis.HHApi; + +public class HHExample { + + private static final String NETWORK_NAME = "hh.ru"; + private static final String PROTECTED_RESOURCE_URL = "https://api.hh.ru/me"; + private static final Token EMPTY_TOKEN = null; + + public static void main(String[] args) { + // Replace these with your own client id and secret + final String clientId = "your client id"; + final String clientSecret = "your client secret"; + OAuthService service = new ServiceBuilder() + .provider(HHApi.class) + .apiKey(clientId) + .apiSecret(clientSecret) + .callback("http://your.site.com/callback") + .build(); + Scanner in = new Scanner(System.in); + + System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); + System.out.println(); + + // Obtain the Authorization URL + System.out.println("Fetching the Authorization URL..."); + final String authorizationUrl = service.getAuthorizationUrl(EMPTY_TOKEN); + 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 Verifier verifier = new Verifier(in.nextLine()); + System.out.println(); + + // Trade the Request Token and Verfier for the Access Token + System.out.println("Trading the Request Token for an Access Token..."); + final Token accessToken = service.getAccessToken(EMPTY_TOKEN, verifier); + System.out.println("Got the Access Token!"); + System.out.println("(if your curious it looks like this: " + accessToken + " )"); + System.out.println(); + + System.out.println("Now we're going to access a protected resource..."); + OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service); + service.signRequest(accessToken, request); + Response response = request.send(); + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + + System.out.println(); + System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); + } +} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ImgUrExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ImgUrExample.java new file mode 100644 index 000000000..11aa7c78d --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ImgUrExample.java @@ -0,0 +1,60 @@ +package com.github.scribejava.apis.examples; + +import java.util.Scanner; +import com.github.scribejava.core.builder.ServiceBuilder; +import com.github.scribejava.apis.ImgUrApi; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.Token; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.model.Verifier; +import com.github.scribejava.core.oauth.OAuthService; + +public class ImgUrExample { + + private static final String PROTECTED_RESOURCE_URL = "http://api.imgur.com/2/account.json"; + + public static void main(String[] args) { + // Replace these with your own api key and secret (you'll need an read/write api key) + String apiKey = "your_app_id"; + String apiSecret = "your_api_secret"; + OAuthService service = new ServiceBuilder().provider(ImgUrApi.class).apiKey(apiKey).apiSecret(apiSecret).build(); + Scanner in = new Scanner(System.in); + + System.out.println("=== ImgUr's OAuth Workflow ==="); + System.out.println(); + + // Obtain the Request Token + System.out.println("Fetching the Request Token..."); + Token requestToken = service.getRequestToken(); + System.out.println("Got the Request Token!"); + System.out.println(); + + System.out.println("Now go and authorize ScribeJava here:"); + String authorizationUrl = service.getAuthorizationUrl(requestToken); + System.out.println(authorizationUrl); + System.out.println("And paste the verifier here"); + System.out.print(">>"); + Verifier verifier = new Verifier(in.nextLine()); + System.out.println(); + + // Trade the Request Token and Verfier for the Access Token + System.out.println("Trading the Request Token for an Access Token..."); + Token accessToken = service.getAccessToken(requestToken, verifier); + System.out.println("Got the Access Token!"); + System.out.println("(if your curious it looks like this: " + accessToken + " )"); + System.out.println(); + + // Now let's go and ask for a protected resource! + System.out.println("Now we're going to access a protected resource..."); + OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service); + service.signRequest(accessToken, request); + Response response = request.send(); + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getBody()); + + System.out.println(); + System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); + } +} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Kaixin20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Kaixin20Example.java new file mode 100644 index 000000000..21daa0a3f --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Kaixin20Example.java @@ -0,0 +1,66 @@ +package com.github.scribejava.apis.examples; + +import java.util.Scanner; +import com.github.scribejava.core.builder.ServiceBuilder; +import com.github.scribejava.apis.KaixinApi20; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.Token; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.model.Verifier; +import com.github.scribejava.core.oauth.OAuthService; + +public class Kaixin20Example { + + private static final String NETWORK_NAME = "Kaixin"; + private static final String PROTECTED_RESOURCE_URL = "https://api.kaixin001.com/users/me.json"; + private static final Token EMPTY_TOKEN = null; + + public static void main(String[] args) { + // Replace these with your own api key and secret + String apiKey = "your api key"; + String apiSecret = "your api secret"; + OAuthService service = new ServiceBuilder() + .provider(KaixinApi20.class) + .apiKey(apiKey) + .apiSecret(apiSecret) + .callback("http://your.domain.com/handle") + .build(); + 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..."); + String authorizationUrl = service.getAuthorizationUrl(EMPTY_TOKEN); + 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(">>"); + Verifier verifier = new Verifier(in.nextLine()); + System.out.println(); + + // Trade the Request Token and Verifier for the Access Token + System.out.println("Trading the Request Token for an Access Token..."); + Token accessToken = service.getAccessToken(EMPTY_TOKEN, verifier); + System.out.println("Got the Access Token!"); + System.out.println("(if your curious it looks like this: " + accessToken + " )"); + System.out.println(); + + // Now let's go and ask for a protected resource! + System.out.println("Now we're going to access a protected resource..."); + OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service); + service.signRequest(accessToken, request); + Response response = request.send(); + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + + System.out.println(); + System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); + + } +} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedIn20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedIn20Example.java new file mode 100644 index 000000000..66e1bf297 --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedIn20Example.java @@ -0,0 +1,72 @@ +package com.github.scribejava.apis.examples; + +import java.util.Scanner; +import com.github.scribejava.core.builder.ServiceBuilder; +import com.github.scribejava.apis.LinkedInApi20; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.Token; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.model.Verifier; +import com.github.scribejava.core.oauth.OAuth20ServiceImpl; + +public class LinkedIn20Example { + + private static final String NETWORK_NAME = "LinkedIn"; + private static final String PROTECTED_RESOURCE_URL = "https://api.linkedin.com/v1/people/~:(%s)"; + private static final Token EMPTY_TOKEN = null; + + public static void main(String[] args) { + // Replace these with your client id and secret + final String clientId = "your client id"; + final String clientSecret = "your client secret"; + final OAuth20ServiceImpl service = (OAuth20ServiceImpl) new ServiceBuilder().provider(LinkedInApi20.class). + apiKey(clientId).apiSecret(clientSecret) + .scope("r_fullprofile,r_emailaddress,r_contactinfo") // replace with desired scope + .callback("http://example.com/callback") + .state("some_params") + .build(); + Scanner in = new Scanner(System.in); + + System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); + System.out.println(); + + // Obtain the Authorization URL + System.out.println("Fetching the Authorization URL..."); + final String authorizationUrl = service.getAuthorizationUrl(EMPTY_TOKEN); + 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(">>"); + Verifier verifier = new Verifier(in.nextLine()); + System.out.println(); + + // Trade the Request Token and Verfier for the Access Token + System.out.println("Trading the Request Token for an Access Token..."); + Token accessToken = service.getAccessToken(EMPTY_TOKEN, verifier); + System.out.println("Got the Access Token!"); + System.out.println("(if your curious it looks like this: " + accessToken + " )"); + System.out.println(); + + // Now let's go and ask for a protected resource! + System.out.println("Now we're going to access a protected resource..."); + while (true) { + System.out.println("Paste profile query for fetch"); + System.out.print(">>"); + final String query = in.nextLine(); + System.out.println(); + + final OAuthRequest request = new OAuthRequest(Verb.GET, String.format(PROTECTED_RESOURCE_URL, query), service); + request.addHeader("x-li-format", "json"); + request.addHeader("Accept-Language", "ru-RU"); + service.signRequest(accessToken, request); + final Response response = request.send(); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + + System.out.println(); + } + } +} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java new file mode 100644 index 000000000..f26cdaf4b --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java @@ -0,0 +1,62 @@ +package com.github.scribejava.apis.examples; + +import java.util.Scanner; +import com.github.scribejava.core.builder.ServiceBuilder; +import com.github.scribejava.apis.LinkedInApi; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.Token; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.model.Verifier; +import com.github.scribejava.core.oauth.OAuthService; + +public class LinkedInExample { + + private static final String PROTECTED_RESOURCE_URL + = "http://api.linkedin.com/v1/people/~/connections:(id,last-name)"; + + public static void main(String[] args) { + OAuthService service = new ServiceBuilder() + .provider(LinkedInApi.class) + .apiKey("CiEgwWDkA5BFpNrc0RfGyVuSlOh4tig5kOTZ9q97qcXNrFl7zqk-Ts7DqRGaKDCV") + .apiSecret("dhho4dfoCmiQXrkw4yslork5XWLFnPSuMR-8gscPVjY4jqFFHPYWJKgpFl4uLTM6") + .build(); + Scanner in = new Scanner(System.in); + + System.out.println("=== LinkedIn's OAuth Workflow ==="); + System.out.println(); + + // Obtain the Request Token + System.out.println("Fetching the Request Token..."); + Token requestToken = service.getRequestToken(); + System.out.println("Got the Request Token!"); + System.out.println(); + + System.out.println("Now go and authorize ScribeJava here:"); + System.out.println(service.getAuthorizationUrl(requestToken)); + System.out.println("And paste the verifier here"); + System.out.print(">>"); + Verifier verifier = new Verifier(in.nextLine()); + System.out.println(); + + // Trade the Request Token and Verfier for the Access Token + System.out.println("Trading the Request Token for an Access Token..."); + Token accessToken = service.getAccessToken(requestToken, verifier); + System.out.println("Got the Access Token!"); + System.out.println("(if your curious it looks like this: " + accessToken + " )"); + System.out.println(); + + // Now let's go and ask for a protected resource! + System.out.println("Now we're going to access a protected resource..."); + OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service); + service.signRequest(accessToken, request); + Response response = request.send(); + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getBody()); + + System.out.println(); + System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); + } + +} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java new file mode 100644 index 000000000..14bbd655b --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java @@ -0,0 +1,66 @@ +package com.github.scribejava.apis.examples; + +import java.util.Scanner; +import com.github.scribejava.core.builder.ServiceBuilder; +import com.github.scribejava.apis.LinkedInApi; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.Token; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.model.Verifier; +import com.github.scribejava.core.oauth.OAuthService; + +public class LinkedInExampleWithScopes { + + private static final String PROTECTED_RESOURCE_URL + = "http://api.linkedin.com/v1/people/~/connections:(id,last-name)"; + + public static void main(String[] args) { + // Replace these with your client id and secret + final String clientId = "your client id"; + final String clientSecret = "your client id"; + + OAuthService service = new ServiceBuilder() + .provider(LinkedInApi.withScopes("foo", "bar", "baz")) + .apiKey(clientId) + .apiSecret(clientSecret) + .build(); + Scanner in = new Scanner(System.in); + + System.out.println("=== LinkedIn's OAuth Workflow ==="); + System.out.println(); + + // Obtain the Request Token + System.out.println("Fetching the Request Token..."); + Token requestToken = service.getRequestToken(); + System.out.println("Got the Request Token!"); + System.out.println(); + + System.out.println("Now go and authorize ScribeJava here:"); + System.out.println(service.getAuthorizationUrl(requestToken)); + System.out.println("And paste the verifier here"); + System.out.print(">>"); + Verifier verifier = new Verifier(in.nextLine()); + System.out.println(); + + // Trade the Request Token and Verfier for the Access Token + System.out.println("Trading the Request Token for an Access Token..."); + Token accessToken = service.getAccessToken(requestToken, verifier); + System.out.println("Got the Access Token!"); + System.out.println("(if your curious it looks like this: " + accessToken + " )"); + System.out.println(); + + // Now let's go and ask for a protected resource! + System.out.println("Now we're going to access a protected resource..."); + OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service); + service.signRequest(accessToken, request); + Response response = request.send(); + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getBody()); + + System.out.println(); + System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); + } + +} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java new file mode 100644 index 000000000..e050b65ca --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java @@ -0,0 +1,66 @@ +package com.github.scribejava.apis.examples; + +import java.util.Scanner; +import com.github.scribejava.core.builder.ServiceBuilder; +import com.github.scribejava.apis.LiveApi; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.Token; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.model.Verifier; +import com.github.scribejava.core.oauth.OAuthService; + +public class LiveExample { + + private static final String PROTECTED_RESOURCE_URL = "https://api.foursquare.com/v2/users/self/friends?oauth_token="; + private static final Token EMPTY_TOKEN = null; + + public static void main(String[] args) { + // Replace these with your own api key and secret + String apiKey = ""; + String apiSecret = ""; + OAuthService service = new ServiceBuilder() + .provider(LiveApi.class) + .apiKey(apiKey) + .apiSecret(apiSecret) + .scope("wl.basic") + .callback("http://localhost:9000/") + .build(); + Scanner in = new Scanner(System.in); + + System.out.println("=== Windows Live's OAuth Workflow ==="); + System.out.println(); + + // Obtain the Authorization URL + System.out.println("Fetching the Authorization URL..."); + String authorizationUrl = service.getAuthorizationUrl(EMPTY_TOKEN); + 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(">>"); + Verifier verifier = new Verifier(in.nextLine()); + System.out.println(); + + // Trade the Request Token and Verfier for the Access Token + System.out.println("Trading the Request Token for an Access Token..."); + Token accessToken = service.getAccessToken(EMPTY_TOKEN, verifier); + System.out.println("Got the Access Token!"); + System.out.println("(if your curious it looks like this: " + accessToken + " )"); + System.out.println(); + + // Now let's go and ask for a protected resource! + System.out.println("Now we're going to access a protected resource..."); + OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL + accessToken.getToken(), service); + service.signRequest(accessToken, request); + Response response = request.send(); + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + + System.out.println(); + System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); + + } +} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LoveFilmExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LoveFilmExample.java new file mode 100644 index 000000000..44b4a6faa --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LoveFilmExample.java @@ -0,0 +1,67 @@ +package com.github.scribejava.apis.examples; + +import java.util.Scanner; +import com.github.scribejava.core.builder.ServiceBuilder; +import com.github.scribejava.apis.LoveFilmApi; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.Token; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.model.Verifier; +import com.github.scribejava.core.oauth.OAuthService; + +public class LoveFilmExample { + + private static final String NETWORK_NAME = "LoveFilm"; + private static final String PROTECTED_RESOURCE_URL = "https://api.lovefilm.com/users"; + + public static void main(String[] args) { + // Replace these with your own api key and secret + String apiKey = "your_key"; + String apiSecret = "your_secret"; + OAuthService service = new ServiceBuilder().provider(LoveFilmApi.class).apiKey(apiKey).apiSecret(apiSecret). + build(); + Scanner in = new Scanner(System.in); + + System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); + System.out.println(); + + // Grab a request token. + System.out.println("Fetching request token."); + Token requestToken = service.getRequestToken(); + System.out.println("Got it ... "); + System.out.println(requestToken.getToken()); + + // Obtain the Authorization URL + System.out.println("Fetching the Authorization URL..."); + String authorizationUrl = service.getAuthorizationUrl(requestToken); + System.out.println("Got the Authorization URL!"); + System.out.println("Now go and authorize ScribeJava here:"); + System.out.println(authorizationUrl); + System.out.println("And paste the authorization code here"); + System.out.print(">>"); + Verifier verifier = new Verifier(in.nextLine()); + System.out.println(); + + // Trade the Request Token and Verfier for the Access Token + System.out.println("Trading the Request Token for an Access Token..."); + Token accessToken = service.getAccessToken(requestToken, verifier); + System.out.println("Got the Access Token!"); + System.out.println("(if your curious it looks like this: " + accessToken + " )"); + System.out.println(); + + // Now let's go and ask for a protected resource! + System.out.println("Now we're going to access a protected resource..."); + OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service); + service.signRequest(accessToken, request); + Response response = request.send(); + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + + System.out.println(); + System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); + + } +} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java new file mode 100644 index 000000000..dc32020d0 --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java @@ -0,0 +1,79 @@ +package com.github.scribejava.apis.examples; + +import com.ning.http.client.AsyncHttpClientConfig; +import java.util.Scanner; +import java.util.concurrent.ExecutionException; +import com.github.scribejava.apis.MailruApi; +import com.github.scribejava.core.builder.ServiceBuilderAsync; +import com.github.scribejava.core.model.OAuthRequestAsync; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.Token; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.model.Verifier; +import com.github.scribejava.core.oauth.OAuthService; + +public abstract class MailruAsyncExample { + + private static final String NETWORK_NAME = "Mail.ru"; + private static final String PROTECTED_RESOURCE_URL = "http://www.appsmail.ru/platform/api?method=users.getInfo&secure=1"; + private static final Token EMPTY_TOKEN = null; + + public static void main(final String... args) throws InterruptedException, ExecutionException { + // Replace these with your client id and secret + final String clientId = "your client id"; + final String clientSecret = "your client secret"; + + final AsyncHttpClientConfig clientConfig = new AsyncHttpClientConfig.Builder() + .setMaxConnections(5) + .setRequestTimeout(10000) + .setAllowPoolingConnections(false) + .setPooledConnectionIdleTimeout(1000) + .setReadTimeout(1000) + .build(); + + final OAuthService service = new ServiceBuilderAsync() + .provider(MailruApi.class) + .apiKey(clientId) + .apiSecret(clientSecret) + .callback("http://www.example.com/oauth_callback/") + .asyncHttpClientConfig(clientConfig) + .build(); + + final Scanner in = new Scanner(System.in, "UTF-8"); + + System.out.println("=== " + NETWORK_NAME + "'s Async OAuth Workflow ==="); + System.out.println(); + + // Obtain the Authorization URL + System.out.println("Fetching the Authorization URL..."); + final String authorizationUrl = service.getAuthorizationUrl(EMPTY_TOKEN); + 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 Verifier verifier = new Verifier(in.nextLine()); + System.out.println(); + + // Trade the Request Token and Verfier for the Access Token + System.out.println("Trading the Request Token for an Access Token..."); + final Token accessToken = service.getAccessTokenAsync(EMPTY_TOKEN, verifier, null).get(); + System.out.println("Got the Access Token!"); + System.out.println("(if your curious it looks like this: " + accessToken + " )"); + System.out.println(); + + System.out.println("Now we're going to access a protected resource..."); + final OAuthRequestAsync request = new OAuthRequestAsync(Verb.GET, PROTECTED_RESOURCE_URL, service); + service.signRequest(accessToken, request); + final Response response = request.sendAsync(null).get(); + + 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! :)"); + service.closeAsyncClient(); + } +} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java new file mode 100644 index 000000000..4ca60b1db --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java @@ -0,0 +1,65 @@ +package com.github.scribejava.apis.examples; + +import java.util.Scanner; +import com.github.scribejava.core.builder.ServiceBuilder; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.Token; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.model.Verifier; +import com.github.scribejava.core.oauth.OAuthService; +import com.github.scribejava.apis.MailruApi; + +public class MailruExample { + + private static final String NETWORK_NAME = "Mail.ru"; + private static final String PROTECTED_RESOURCE_URL = "http://www.appsmail.ru/platform/api?method=users.getInfo&secure=1"; + private static final Token EMPTY_TOKEN = null; + + public static void main(String[] args) { + // Replace these with your client id and secret + final String clientId = "your client id"; + final String clientSecret = "your client secret"; + OAuthService service = new ServiceBuilder() + .provider(MailruApi.class) + .apiKey(clientId) + .apiSecret(clientSecret) + .callback("http://www.example.com/oauth_callback/") + .build(); + + Scanner in = new Scanner(System.in); + + System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); + System.out.println(); + + // Obtain the Authorization URL + System.out.println("Fetching the Authorization URL..."); + final String authorizationUrl = service.getAuthorizationUrl(EMPTY_TOKEN); + 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 Verifier verifier = new Verifier(in.nextLine()); + System.out.println(); + + // Trade the Request Token and Verfier for the Access Token + System.out.println("Trading the Request Token for an Access Token..."); + final Token accessToken = service.getAccessToken(EMPTY_TOKEN, verifier); + System.out.println("Got the Access Token!"); + System.out.println("(if your curious it looks like this: " + accessToken + " )"); + System.out.println(); + + System.out.println("Now we're going to access a protected resource..."); + OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service); + service.signRequest(accessToken, request); + Response response = request.send(); + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + + System.out.println(); + System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); + } +} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java new file mode 100644 index 000000000..d0d98ddbc --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java @@ -0,0 +1,60 @@ +package com.github.scribejava.apis.examples; + +import java.util.Scanner; +import com.github.scribejava.core.builder.ServiceBuilder; +import com.github.scribejava.apis.MeetupApi; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.Token; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.model.Verifier; +import com.github.scribejava.core.oauth.OAuthService; + +public class MeetupExample { + + private static final String PROTECTED_RESOURCE_URL = "http://api.meetup.com/2/member/self"; + + public static void main(String[] args) { + OAuthService service = new ServiceBuilder() + .provider(MeetupApi.class) + .apiKey("j1khkp0dus323ftve0sdcv6ffe") + .apiSecret("6s6gt6q59gvfjtsvgcmht62gq4") + .build(); + Scanner in = new Scanner(System.in); + + System.out.println("=== Meetup's OAuth Workflow ==="); + System.out.println(); + + // Obtain the Request Token + System.out.println("Fetching the Request Token..."); + Token requestToken = service.getRequestToken(); + System.out.println("Got the Request Token!"); + System.out.println(); + + System.out.println("Now go and authorize ScribeJava here:"); + System.out.println(service.getAuthorizationUrl(requestToken)); + System.out.println("And paste the verifier here"); + System.out.print(">>"); + Verifier verifier = new Verifier(in.nextLine()); + System.out.println(); + + // Trade the Request Token and Verfier for the Access Token + System.out.println("Trading the Request Token for an Access Token..."); + Token accessToken = service.getAccessToken(requestToken, verifier); + System.out.println("Got the Access Token!"); + System.out.println("(if your curious it looks like this: " + accessToken + " )"); + System.out.println(); + + // Now let's go and ask for a protected resource! + System.out.println("Now we're going to access a protected resource..."); + OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service); + service.signRequest(accessToken, request); + Response response = request.send(); + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getBody()); + + System.out.println(); + System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); + } +} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NeteaseWeiboExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NeteaseWeiboExample.java new file mode 100644 index 000000000..dbb4dc0b3 --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NeteaseWeiboExample.java @@ -0,0 +1,70 @@ +package com.github.scribejava.apis.examples; + +import java.util.Scanner; +import com.github.scribejava.core.builder.ServiceBuilder; +import com.github.scribejava.apis.NeteaseWeibooApi; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.Token; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.model.Verifier; +import com.github.scribejava.core.oauth.OAuthService; + +public class NeteaseWeiboExample { + + private static final String NETWORK_NAME = "NetEase(163.com) Weibo"; + private static final String PROTECTED_RESOURCE_URL = "http://api.t.163.com/account/verify_credentials.json"; + + public static void main(String[] args) { + // Replace these with your own api key and secret + String apiKey = "your key"; + String apiSecret = "your secret"; + OAuthService service = new ServiceBuilder() + .provider(NeteaseWeibooApi.class) + .apiKey(apiKey) + .apiSecret(apiSecret) + .build(); + Scanner in = new Scanner(System.in); + + System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); + System.out.println(); + + // Grab a request token. + System.out.println("Fetching request token."); + Token requestToken = service.getRequestToken(); + System.out.println("Got it ... "); + System.out.println(requestToken.getToken()); + + // Obtain the Authorization URL + System.out.println("Fetching the Authorization URL..."); + String authorizationUrl = service.getAuthorizationUrl(requestToken); + System.out.println("Got the Authorization URL!"); + System.out.println("Now go and authorize ScribeJava here:"); + System.out.println(authorizationUrl); + System.out.println("And paste the authorization code here"); + System.out.print(">>"); + Verifier verifier = new Verifier(in.nextLine()); + System.out.println(); + + // Trade the Request Token and Verfier for the Access Token + System.out.println("Trading the Request Token for an Access Token..."); + Token accessToken = service.getAccessToken(requestToken, verifier); + System.out.println("Got the Access Token!"); + System.out.println("(if your curious it looks like this: " + + accessToken + " )"); + System.out.println(); + + // Now let's go and ask for a protected resource! + System.out.println("Now we're going to access a protected resource..."); + OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service); + service.signRequest(accessToken, request); + Response response = request.send(); + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + + System.out.println(); + System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); + } +} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java new file mode 100644 index 000000000..dbb8bde5c --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java @@ -0,0 +1,70 @@ +package com.github.scribejava.apis.examples; + +import java.util.Scanner; +import com.github.scribejava.core.builder.ServiceBuilder; +import com.github.scribejava.apis.OdnoklassnikiApi; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.Token; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.model.Verifier; +import com.github.scribejava.core.oauth.OAuthService; + +public class OdnoklassnikiExample { + + private static final String NETWORK_NAME = "Odnoklassniki.ru"; + private static final String PROTECTED_RESOURCE_URL + = "http://api.odnoklassniki.ru/api/users/getCurrentUser?application_key=%1$s&format=JSON"; + private static final Token EMPTY_TOKEN = null; + + public static void main(String[] args) { + // Replace these with your client id and secret + final String clientId = "your client id"; + final String publicKey = "your api secret"; + final String clientSecret = "your client secret"; + + OAuthService service = new ServiceBuilder().provider(OdnoklassnikiApi.class) + .apiKey(clientId) + .apiSecret(clientSecret) + .scope("VALUABLE ACCESS") + .callback("http://your.site.com/callback") + .build(); + + 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..."); + String authorizationUrl = service.getAuthorizationUrl(EMPTY_TOKEN); + 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(">>"); + Verifier verifier = new Verifier(in.nextLine()); + System.out.println(); + + // Trade the Request Token and Verfier for the Access Token + System.out.println("Trading the Request Token for an Access Token..."); + + Token accessToken = service.getAccessToken(EMPTY_TOKEN, verifier); + System.out.println("Got the Access Token!"); + System.out.println("(if your curious it looks like this: " + accessToken + " )"); + System.out.println(); + + // Now let's go and ask for a protected resource! + System.out.println("Now we're going to access a protected resource..."); + OAuthRequest request = new OAuthRequest(Verb.GET, String.format(PROTECTED_RESOURCE_URL, publicKey), service); + service.signRequest(accessToken, request); + Response response = request.send(); + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + + System.out.println(); + System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); + } +} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Px500Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Px500Example.java new file mode 100644 index 000000000..c54c6c897 --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Px500Example.java @@ -0,0 +1,62 @@ +package com.github.scribejava.apis.examples; + +import java.util.Scanner; +import com.github.scribejava.core.builder.ServiceBuilder; +import com.github.scribejava.apis.Px500Api; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.Token; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.model.Verifier; +import com.github.scribejava.core.oauth.OAuthService; + +public class Px500Example { + + private static final String PROTECTED_RESOURCE_URL = "https://api.500px.com/v1/"; + + public static void main(String[] args) { + OAuthService service = new ServiceBuilder() + .provider(Px500Api.class) + .apiKey("your-api-key") + .apiSecret("your-api-secret") + .build(); + Scanner in = new Scanner(System.in); + + System.out.println("=== 500Px's OAuth Workflow ==="); + System.out.println(); + + // Obtain the Request Token + System.out.println("Fetching the Request Token..."); + Token requestToken = service.getRequestToken(); + System.out.println("Got the Request Token!"); + System.out.println(); + + System.out.println("Now go and authorize ScribeJava here:"); + System.out.println(service.getAuthorizationUrl(requestToken)); + System.out.println("And paste the verifier here"); + System.out.print(">>"); + Verifier verifier = new Verifier(in.nextLine()); + System.out.println(); + + // Trade the Request Token and Verfier for the Access Token + System.out.println("Trading the Request Token for an Access Token..."); + Token accessToken = service.getAccessToken(requestToken, verifier); + System.out.println("Got the Access Token!"); + System.out.println("(if your curious it looks like this: " + accessToken + " )"); + System.out.println(); + + // Now let's go and ask for a protected resource! + System.out.println("Now we're going to access a protected resource..."); + OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service); + service.signRequest(accessToken, request); + Response response = request.send(); + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getBody()); + + System.out.println(); + System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); + + } + +} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java new file mode 100644 index 000000000..5e61715d2 --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java @@ -0,0 +1,111 @@ +package com.github.scribejava.apis.examples; + +import java.nio.charset.Charset; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Scanner; +import com.github.scribejava.core.builder.ServiceBuilder; +import com.github.scribejava.apis.RenrenApi; +import com.github.scribejava.core.model.OAuthConstants; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.Token; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.model.Verifier; +import com.github.scribejava.core.oauth.OAuthService; + +public class RenrenExample { + + private static final String NETWORK_NAME = "Renren"; + private static final String PROTECTED_RESOURCE_URL = "http://api.renren.com/restserver.do"; + private static final Token EMPTY_TOKEN = null; + + public static void main(String[] args) { + // Replace these with your own api key and secret + String apiKey = "your api key"; + String apiSecret = "your api secret"; + OAuthService service = new ServiceBuilder() + .provider(RenrenApi.class) + .apiKey(apiKey) + .apiSecret(apiSecret) + .scope("status_update publish_feed") + .callback("http://your.doman.com/oauth/renren") + .build(); + 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..."); + String authorizationUrl = service.getAuthorizationUrl(EMPTY_TOKEN); + 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(">>"); + Verifier verifier = new Verifier(in.nextLine()); + System.out.println(); + + // Trade the Request Token and Verfier for the Access Token + System.out.println("Trading the Request Token for an Access Token..."); + Token accessToken = service.getAccessToken(EMPTY_TOKEN, verifier); + System.out.println("Got the Access Token!"); + System.out.println("(if your curious it looks like this: " + accessToken + " )"); + System.out.println(); + + // Now let's go and ask for a protected resource! + System.out.println("Now we're going to access a protected resource..."); + OAuthRequest request = new OAuthRequest(Verb.POST, PROTECTED_RESOURCE_URL, service); + Map parameters = new HashMap(); + parameters.put("method", "users.getInfo"); + parameters.put("format", "json"); + parameters.put("v", "1.0"); + + List sigString = new ArrayList(parameters.size() + 1); + for (Map.Entry entry : parameters.entrySet()) { + request.addQuerystringParameter(entry.getKey(), entry.getValue()); + sigString.add(String.format("%s=%s", entry.getKey(), entry.getValue())); + } + sigString.add(String.format("%s=%s", OAuthConstants.ACCESS_TOKEN, accessToken.getToken())); + Collections.sort(sigString); + StringBuilder b = new StringBuilder(); + for (String param : sigString) { + b.append(param); + } + b.append(apiSecret); + System.out.println("Sig string: " + b.toString()); + request.addQuerystringParameter("sig", md5(b.toString())); + service.signRequest(accessToken, request); + Response response = request.send(); + 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! :)"); + + } + + public static String md5(String orgString) { + try { + java.security.MessageDigest md = MessageDigest.getInstance("MD5"); + byte[] array = md.digest(orgString.getBytes(Charset.forName("UTF-8"))); + StringBuffer sb = new StringBuffer(); + for (int i = 0; i < array.length; ++i) { + sb.append(Integer.toHexString((array[i] & 0xFF) | 0x100).substring(1, 3)); + } + return sb.toString(); + } catch (NoSuchAlgorithmException e) { + e.printStackTrace(); + } + return null; + } + +} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeibo2Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeibo2Example.java new file mode 100644 index 000000000..3a80e70d7 --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeibo2Example.java @@ -0,0 +1,66 @@ +package com.github.scribejava.apis.examples; + +import java.util.Scanner; +import com.github.scribejava.core.builder.ServiceBuilder; +import com.github.scribejava.apis.SinaWeiboApi20; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.Token; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.model.Verifier; +import com.github.scribejava.core.oauth.OAuthService; + +public class SinaWeibo2Example { + + private static final String NETWORK_NAME = "SinaWeibo"; + private static final String PROTECTED_RESOURCE_URL = "https://api.weibo.com/2/account/get_uid.json"; + private static final Token EMPTY_TOKEN = null; + + public static void main(String[] args) { + // Replace these with your own api key and secret + String apiKey = "your_api_key"; + String apiSecret = "your_api_secret"; + OAuthService service = new ServiceBuilder() + .provider(SinaWeiboApi20.class) + .apiKey(apiKey) + .apiSecret(apiSecret) + .callback("http://www.dajie.com/oauth/sina") + .build(); + 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..."); + String authorizationUrl = service.getAuthorizationUrl(EMPTY_TOKEN); + 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(">>"); + Verifier verifier = new Verifier(in.nextLine()); + System.out.println(); + + // Trade the Request Token and Verifier for the Access Token + System.out.println("Trading the Request Token for an Access Token..."); + Token accessToken = service.getAccessToken(EMPTY_TOKEN, verifier); + System.out.println("Got the Access Token!"); + System.out.println("(if your curious it looks like this: " + accessToken + " )"); + System.out.println(); + + // Now let's go and ask for a protected resource! + System.out.println("Now we're going to access a protected resource..."); + OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service); + service.signRequest(accessToken, request); + Response response = request.send(); + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + + System.out.println(); + System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); + + } +} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeiboExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeiboExample.java new file mode 100644 index 000000000..3fa625045 --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeiboExample.java @@ -0,0 +1,70 @@ +package com.github.scribejava.apis.examples; + +import java.util.Scanner; +import com.github.scribejava.core.builder.ServiceBuilder; +import com.github.scribejava.apis.SinaWeiboApi; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.Token; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.model.Verifier; +import com.github.scribejava.core.oauth.OAuthService; + +public class SinaWeiboExample { + + private static final String NETWORK_NAME = "SinaWeibo"; + private static final String PROTECTED_RESOURCE_URL = "http://api.t.sina.com.cn/account/verify_credentials.json"; + + public static void main(String[] args) { + // Replace these with your own api key and secret + String apiKey = "your key"; + String apiSecret = "your secret"; + OAuthService service = new ServiceBuilder() + .provider(SinaWeiboApi.class) + .apiKey(apiKey) + .apiSecret(apiSecret) + .build(); + Scanner in = new Scanner(System.in); + + System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); + System.out.println(); + + // Grab a request token. + System.out.println("Fetching request token."); + Token requestToken = service.getRequestToken(); + System.out.println("Got it ... "); + System.out.println(requestToken.getToken()); + + // Obtain the Authorization URL + System.out.println("Fetching the Authorization URL..."); + String authorizationUrl = service.getAuthorizationUrl(requestToken); + System.out.println("Got the Authorization URL!"); + System.out.println("Now go and authorize ScribeJava here:"); + System.out.println(authorizationUrl); + System.out.println("And paste the authorization code here"); + System.out.print(">>"); + Verifier verifier = new Verifier(in.nextLine()); + System.out.println(); + + // Trade the Request Token and Verfier for the Access Token + System.out.println("Trading the Request Token for an Access Token..."); + Token accessToken = service.getAccessToken(requestToken, verifier); + System.out.println("Got the Access Token!"); + System.out.println("(if your curious it looks like this: " + + accessToken + " )"); + System.out.println(); + + // Now let's go and ask for a protected resource! + System.out.println("Now we're going to access a protected resource..."); + OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service); + service.signRequest(accessToken, request); + Response response = request.send(); + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + + System.out.println(); + System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); + } +} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SkyrockExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SkyrockExample.java new file mode 100644 index 000000000..35fd4379e --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SkyrockExample.java @@ -0,0 +1,63 @@ +package com.github.scribejava.apis.examples; + +import java.util.Scanner; +import com.github.scribejava.core.builder.ServiceBuilder; +import com.github.scribejava.apis.SkyrockApi; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.Token; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.model.Verifier; +import com.github.scribejava.core.oauth.OAuthService; + +public class SkyrockExample { + + private static final String PROTECTED_RESOURCE_URL = "https://api.skyrock.com/v2/user/get.json"; + + public static void main(String[] args) { + OAuthService service = new ServiceBuilder() + .provider(SkyrockApi.class) + .apiKey("your-api-key") + .apiSecret("your-api-secret") + .build(); + Scanner in = new Scanner(System.in); + + System.out.println("=== Skyrock's OAuth Workflow ==="); + System.out.println(); + + // Obtain the Request Token + System.out.println("Fetching the Request Token..."); + Token requestToken = service.getRequestToken(); + System.out.println("Got the Request Token!"); + System.out.println(); + + System.out.println("Now go and authorize ScribeJava here:"); + System.out.println(service.getAuthorizationUrl(requestToken)); + System.out.println("And paste the verifier here"); + System.out.print(">>"); + Verifier verifier = new Verifier(in.nextLine()); + System.out.println(); + + // Trade the Request Token and Verfier for the Access Token + System.out.println("Trading the Request Token for an Access Token..."); + Token accessToken = service.getAccessToken(requestToken, verifier); + System.out.println("Got the Access Token!"); + System.out.println("(if your curious it looks like this: " + accessToken + " )"); + System.out.println(); + + // Now let's go and ask for a protected resource! + System.out.println("Now we're going to access a protected resource..."); + OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service); + service.signRequest(accessToken, request); + Response response = request.send(); + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + + System.out.println(); + System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); + + } + +} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SohuWeiboExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SohuWeiboExample.java new file mode 100644 index 000000000..cbb4746ca --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SohuWeiboExample.java @@ -0,0 +1,70 @@ +package com.github.scribejava.apis.examples; + +import java.util.Scanner; +import com.github.scribejava.core.builder.ServiceBuilder; +import com.github.scribejava.apis.SohuWeiboApi; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.Token; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.model.Verifier; +import com.github.scribejava.core.oauth.OAuthService; + +public class SohuWeiboExample { + + private static final String NETWORK_NAME = "SohuWeibo"; + private static final String PROTECTED_RESOURCE_URL = "http://api.t.sohu.com/account/verify_credentials.json"; + + public static void main(String[] args) { + // Replace these with your own api key and secret + String apiKey = "your_key"; + String apiSecret = "your_secret"; + OAuthService service = new ServiceBuilder() + .provider(SohuWeiboApi.class) + .apiKey(apiKey) + .apiSecret(apiSecret) + .build(); + Scanner in = new Scanner(System.in); + + System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); + System.out.println(); + + // Grab a request token. + System.out.println("Fetching request token."); + Token requestToken = service.getRequestToken(); + System.out.println("Got it ... "); + System.out.println(requestToken.getToken()); + + // Obtain the Authorization URL + System.out.println("Fetching the Authorization URL..."); + String authorizationUrl = service.getAuthorizationUrl(requestToken); + System.out.println("Got the Authorization URL!"); + System.out.println("Now go and authorize ScribeJava here:"); + System.out.println(authorizationUrl); + System.out.println("And paste the authorization code here"); + System.out.print(">>"); + Verifier verifier = new Verifier(in.nextLine()); + System.out.println(); + + // Trade the Request Token and Verfier for the Access Token + System.out.println("Trading the Request Token for an Access Token..."); + Token accessToken = service.getAccessToken(requestToken, verifier); + System.out.println("Got the Access Token!"); + System.out.println("(if your curious it looks like this: " + + accessToken + " )"); + System.out.println(); + + // Now let's go and ask for a protected resource! + System.out.println("Now we're going to access a protected resource..."); + OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service); + service.signRequest(accessToken, request); + Response response = request.send(); + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + + System.out.println(); + System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); + } +} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TrelloExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TrelloExample.java new file mode 100644 index 000000000..76d61d915 --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TrelloExample.java @@ -0,0 +1,63 @@ +package com.github.scribejava.apis.examples; + +import java.util.Scanner; +import com.github.scribejava.core.builder.ServiceBuilder; +import com.github.scribejava.apis.TrelloApi; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.Token; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.model.Verifier; +import com.github.scribejava.core.oauth.OAuthService; + +public class TrelloExample { + + private static final String API_KEY = "your_api_key"; + private static final String API_SECRET = "your_api_secret"; + private static final String PROTECTED_RESOURCE_URL = "https://trello.com/1/members/me"; + + public static void main(String[] args) { + OAuthService service = new ServiceBuilder() + .provider(TrelloApi.class) + .apiKey(API_KEY) + .apiSecret(API_SECRET) + .build(); + Scanner in = new Scanner(System.in); + + System.out.println("=== Trello's OAuth Workflow ==="); + System.out.println(); + + // Obtain the Request Token + System.out.println("Fetching the Request Token..."); + Token requestToken = service.getRequestToken(); + System.out.println("Got the Request Token!"); + System.out.println(); + + System.out.println("Now go and authorize ScribeJava here:"); + System.out.println(service.getAuthorizationUrl(requestToken)); + System.out.println("And paste the verifier here"); + System.out.print(">>"); + Verifier verifier = new Verifier(in.nextLine()); + System.out.println(); + + // Trade the Request Token and Verfier for the Access Token + System.out.println("Trading the Request Token for an Access Token..."); + Token accessToken = service.getAccessToken(requestToken, verifier); + System.out.println("Got the Access Token!"); + System.out.println("(if your curious it looks like this: " + accessToken + " )"); + System.out.println(); + + // Now let's go and ask for a protected resource! + System.out.println("Now we're going to access a protected resource..."); + OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service); + service.signRequest(accessToken, request); + Response response = request.send(); + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getBody()); + + System.out.println(); + System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); + } + +} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TumblrExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TumblrExample.java new file mode 100644 index 000000000..87c975f74 --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TumblrExample.java @@ -0,0 +1,62 @@ +package com.github.scribejava.apis.examples; + +import java.util.Scanner; +import com.github.scribejava.core.builder.ServiceBuilder; +import com.github.scribejava.apis.TumblrApi; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.Token; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.model.Verifier; +import com.github.scribejava.core.oauth.OAuthService; + +public class TumblrExample { + + private static final String PROTECTED_RESOURCE_URL = "http://api.tumblr.com/v2/user/info"; + + public static void main(String[] args) { + OAuthService service = new ServiceBuilder() + .provider(TumblrApi.class) + .apiKey("MY_CONSUMER_KEY") + .apiSecret("MY_CONSUMER_SECRET") + .callback("http://www.tumblr.com/connect/login_success.html") // OOB forbidden. We need an url and the better is on the tumblr website ! + .build(); + Scanner in = new Scanner(System.in); + + System.out.println("=== Tumblr's OAuth Workflow ==="); + System.out.println(); + + // Obtain the Request Token + System.out.println("Fetching the Request Token..."); + Token requestToken = service.getRequestToken(); + System.out.println("Got the Request Token!"); + System.out.println(); + + System.out.println("Now go and authorize Scribe here:"); + System.out.println(service.getAuthorizationUrl(requestToken)); + System.out.println("And paste the verifier here"); + System.out.print(">>"); + Verifier verifier = new Verifier(in.nextLine()); + System.out.println(); + + // Trade the Request Token and Verfier for the Access Token + System.out.println("Trading the Request Token for an Access Token..."); + Token accessToken = service.getAccessToken(requestToken, + verifier); + System.out.println("Got the Access Token!"); + System.out.println("(if your curious it looks like this: " + accessToken + " )"); + System.out.println(); + + // Now let's go and ask for a protected resource! + System.out.println("Now we're going to access a protected resource..."); + OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service); + service.signRequest(accessToken, request); + Response response = request.send(); + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getBody()); + + System.out.println(); + System.out.println("Thats it man! Go and build something awesome with Scribe! :)"); + } +} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TutByExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TutByExample.java new file mode 100644 index 000000000..0ec229553 --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TutByExample.java @@ -0,0 +1,68 @@ +package com.github.scribejava.apis.examples; + +import java.util.Scanner; + +import com.github.scribejava.core.builder.ServiceBuilder; +import com.github.scribejava.core.model.OAuthConstants; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.Token; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.model.Verifier; +import com.github.scribejava.core.oauth.OAuthService; + +import com.github.scribejava.apis.TutByApi; + +public class TutByExample { + + private static final String NETWORK_NAME = "Tut.by"; + private static final String PROTECTED_RESOURCE_URL = "http://profile.tut.by/getInfo"; + private static final Token EMPTY_TOKEN = null; + + public static void main(String[] args) { + // Replace these with your client id and secret + final String clientId = "your client id"; + final String clientSecret = "your client secret"; + final OAuthService service = new ServiceBuilder() + .provider(TutByApi.class) + .apiKey(clientId) + .apiSecret(clientSecret) + .grantType(OAuthConstants.AUTHORIZATION_CODE) + .callback("http://www.example.com/oauth_callback/") + .build(); + final Scanner in = new Scanner(System.in, "UTF-8"); + + System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); + System.out.println(); + + System.out.println("Fetching the Authorization URL..."); + final String authorizationUrl = service.getAuthorizationUrl(EMPTY_TOKEN); + 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 Verifier verifier = new Verifier(in.nextLine()); + System.out.println(); + + // Trade the Request Token and Verfier for the Access Token + System.out.println("Trading the Request Token for an Access Token..."); + final Token accessToken = service.getAccessToken(EMPTY_TOKEN, verifier); + System.out.println("Got the Access Token!"); + System.out.println("(if your curious it looks like this: " + accessToken + " )"); + 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); + service.signRequest(accessToken, request); + final Response response = request.send(); + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + + System.out.println(); + System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); + } +} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TwitterExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TwitterExample.java new file mode 100644 index 000000000..1ebecb79a --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TwitterExample.java @@ -0,0 +1,59 @@ +package com.github.scribejava.apis.examples; + +import java.util.Scanner; +import com.github.scribejava.core.builder.ServiceBuilder; +import com.github.scribejava.apis.TwitterApi; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.Token; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.model.Verifier; +import com.github.scribejava.core.oauth.OAuthService; + +public class TwitterExample { + + private static final String PROTECTED_RESOURCE_URL = "https://api.twitter.com/1.1/account/verify_credentials.json"; + + public static void main(String[] args) { + OAuthService service = new ServiceBuilder().provider(TwitterApi.class) + .apiKey("6icbcAXyZx67r8uTAUM5Qw") + .apiSecret("SCCAdUUc6LXxiazxH3N0QfpNUvlUy84mZ2XZKiv39s") + .build(); + Scanner in = new Scanner(System.in); + + System.out.println("=== Twitter's OAuth Workflow ==="); + System.out.println(); + + // Obtain the Request Token + System.out.println("Fetching the Request Token..."); + Token requestToken = service.getRequestToken(); + System.out.println("Got the Request Token!"); + System.out.println(); + + System.out.println("Now go and authorize ScribeJava here:"); + System.out.println(service.getAuthorizationUrl(requestToken)); + System.out.println("And paste the verifier here"); + System.out.print(">>"); + Verifier verifier = new Verifier(in.nextLine()); + System.out.println(); + + // Trade the Request Token and Verfier for the Access Token + System.out.println("Trading the Request Token for an Access Token..."); + Token accessToken = service.getAccessToken(requestToken, verifier); + System.out.println("Got the Access Token!"); + System.out.println("(if you're curious it looks like this: " + accessToken + " )"); + System.out.println(); + + // Now let's go and ask for a protected resource! + System.out.println("Now we're going to access a protected resource..."); + OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service); + service.signRequest(accessToken, request); + Response response = request.send(); + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getBody()); + + System.out.println(); + System.out.println("That's it man! Go and build something awesome with ScribeJava! :)"); + } +} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ViadeoExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ViadeoExample.java new file mode 100644 index 000000000..cacfca993 --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ViadeoExample.java @@ -0,0 +1,66 @@ +package com.github.scribejava.apis.examples; + +import java.util.Scanner; +import com.github.scribejava.core.builder.ServiceBuilder; +import com.github.scribejava.apis.ViadeoApi; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.Token; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.model.Verifier; +import com.github.scribejava.core.oauth.OAuthService; + +public class ViadeoExample { + + private static final String NETWORK_NAME = "Viadeo"; + private static final String PROTECTED_RESOURCE_URL = "https://api.viadeo.com/me?user_detail=full"; + private static final Token EMPTY_TOKEN = null; + + public static void main(String[] args) { + // Replace these with your own api key and secret + String apiKey = "your_app_id"; + String apiSecret = "your_api_secret"; + OAuthService service = new ServiceBuilder() + .provider(ViadeoApi.class) + .apiKey(apiKey) + .apiSecret(apiSecret) + .callback("http://www.example.com/oauth_callback/") + .build(); + 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..."); + String authorizationUrl = service.getAuthorizationUrl(EMPTY_TOKEN); + 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(">>"); + Verifier verifier = new Verifier(in.nextLine()); + System.out.println(); + + // Trade the Request Token and Verfier for the Access Token + System.out.println("Trading the Request Token for an Access Token..."); + Token accessToken = service.getAccessToken(EMPTY_TOKEN, verifier); + System.out.println("Got the Access Token!"); + System.out.println("(if your curious it looks like this: " + accessToken + " )"); + System.out.println(); + + // Now let's go and ask for a protected resource! + System.out.println("Now we're going to access a protected resource..."); + OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service); + service.signRequest(accessToken, request); + Response response = request.send(); + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + + System.out.println(); + System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); + + } +} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExample.java new file mode 100644 index 000000000..e608c956c --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExample.java @@ -0,0 +1,70 @@ +package com.github.scribejava.apis.examples; + +import java.util.Scanner; +import com.github.scribejava.core.builder.ServiceBuilder; +import com.github.scribejava.apis.VkontakteApi; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.Token; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.model.Verifier; +import com.github.scribejava.core.oauth.OAuthService; + +/** + * @author Boris G. Tsirkin + * @since 20.4.2011 + */ +public class VkontakteExample { + + private static final String NETWORK_NAME = "Vkontakte.ru"; + private static final String PROTECTED_RESOURCE_URL = "https://api.vk.com/method/friends.get"; + private static final Token EMPTY_TOKEN = null; + + public static void main(String[] args) { + // Replace these with your client id and secret + final String clientId = "your client id"; + final String clientSecret = "your client secret"; + OAuthService service = new ServiceBuilder() + .provider(VkontakteApi.class) + .apiKey(clientId) + .apiSecret(clientSecret) + .scope("friends,wall,offline") // replace with desired scope + .callback("http://your.site.com/callback") + .build(); + 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..."); + String authorizationUrl = service.getAuthorizationUrl(EMPTY_TOKEN); + 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(">>"); + Verifier verifier = new Verifier(in.nextLine()); + System.out.println(); + + // Trade the Request Token and Verfier for the Access Token + System.out.println("Trading the Request Token for an Access Token..."); + Token accessToken = service.getAccessToken(EMPTY_TOKEN, verifier); + System.out.println("Got the Access Token!"); + System.out.println("(if your curious it looks like this: " + accessToken + " )"); + System.out.println(); + + // Now let's go and ask for a protected resource! + System.out.println("Now we're going to access a protected resource..."); + OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service); + service.signRequest(accessToken, request); + Response response = request.send(); + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + + System.out.println(); + System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); + } +} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XingExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XingExample.java new file mode 100755 index 000000000..c02aa98de --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XingExample.java @@ -0,0 +1,61 @@ +package com.github.scribejava.apis.examples; + +import java.util.Scanner; +import com.github.scribejava.core.builder.ServiceBuilder; +import com.github.scribejava.apis.XingApi; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.Token; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.model.Verifier; +import com.github.scribejava.core.oauth.OAuthService; + +public class XingExample { + + private static final String PROTECTED_RESOURCE_URL = "https://api.xing.com/v1/users/me"; + + public static void main(String[] args) { + OAuthService service = new ServiceBuilder() + .provider(XingApi.class) + .apiKey("097ccfd3ef25a1cb6d75") + .apiSecret("e43364b2afd5d92f2ec28951a75bd8075f9cc221") + .build(); + Scanner in = new Scanner(System.in); + + System.out.println("=== Xing's OAuth Workflow ==="); + System.out.println(); + + // Obtain the Request Token + System.out.println("Fetching the Request Token..."); + Token requestToken = service.getRequestToken(); + System.out.println("Got the Request Token!"); + System.out.println(); + + System.out.println("Now go and authorize ScribeJava here:"); + System.out.println(service.getAuthorizationUrl(requestToken)); + System.out.println("And paste the verifier here"); + System.out.print(">>"); + Verifier verifier = new Verifier(in.nextLine()); + System.out.println(); + + // Trade the Request Token and Verfier for the Access Token + System.out.println("Trading the Request Token for an Access Token..."); + Token accessToken = service.getAccessToken(requestToken, verifier); + System.out.println("Got the Access Token!"); + System.out.println("(if your curious it looks like this: " + accessToken + " )"); + System.out.println(); + + // Now let's go and ask for a protected resource! + System.out.println("Now we're going to access a protected resource..."); + OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service); + service.signRequest(accessToken, request); + Response response = request.send(); + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getBody()); + + System.out.println(); + System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); + } + +} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/YahooExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/YahooExample.java new file mode 100644 index 000000000..b10fe03b8 --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/YahooExample.java @@ -0,0 +1,63 @@ +package com.github.scribejava.apis.examples; + +import java.util.Scanner; +import com.github.scribejava.core.builder.ServiceBuilder; +import com.github.scribejava.apis.YahooApi; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.Token; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.model.Verifier; +import com.github.scribejava.core.oauth.OAuthService; + +public class YahooExample { + + private static final String PROTECTED_RESOURCE_URL + = "http://social.yahooapis.com/v1/user/A6ROU63MXWDCW3Y5MGCYWVHDJI/profile/status?format=json"; + + public static void main(String[] args) { + OAuthService service = new ServiceBuilder() + .provider(YahooApi.class) + .apiKey("dj0yJmk9TXZDWVpNVVdGaVFmJmQ9WVdrOWMweHZXbkZLTkhVbWNHbzlNVEl5TWprd05qUTJNZy0tJnM9Y29uc3VtZXJzZWNyZXQmeD0wMw--"). + apiSecret("262be559f92a2be20c4c039419018f2b48cdfce9") + .build(); + Scanner in = new Scanner(System.in); + + System.out.println("=== Yahoo's OAuth Workflow ==="); + System.out.println(); + + // Obtain the Request Token + System.out.println("Fetching the Request Token..."); + Token requestToken = service.getRequestToken(); + System.out.println("Got the Request Token!"); + System.out.println(); + + System.out.println("Now go and authorize ScribeJava here:"); + System.out.println(service.getAuthorizationUrl(requestToken)); + System.out.println("And paste the verifier here"); + System.out.print(">>"); + Verifier verifier = new Verifier(in.nextLine()); + System.out.println(); + + // Trade the Request Token and Verfier for the Access Token + System.out.println("Trading the Request Token for an Access Token..."); + Token accessToken = service.getAccessToken(requestToken, verifier); + System.out.println("Got the Access Token!"); + System.out.println("(if your curious it looks like this: " + accessToken + " )"); + System.out.println(); + + // Now let's go and ask for a protected resource! + System.out.println("Now we're going to access a protected resource..."); + OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service); + service.signRequest(accessToken, request); + Response response = request.send(); + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + + System.out.println(); + System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); + + } +} diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml new file mode 100644 index 000000000..8ead9d7b6 --- /dev/null +++ b/scribejava-core/pom.xml @@ -0,0 +1,37 @@ + + + 4.0.0 + + + com.github.scribejava + scribejava + 2.0-SNAPSHOT + ../pom.xml + + + com.github.scribejava + scribejava-core + ScribeJava Core + jar + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.3 + + true + + + + org.apache.maven.plugins + maven-resources-plugin + 2.7 + + UTF-8 + + + + + \ No newline at end of file diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/AbstractServiceBuilder.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/AbstractServiceBuilder.java new file mode 100644 index 000000000..481098321 --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/AbstractServiceBuilder.java @@ -0,0 +1,185 @@ +package com.github.scribejava.core.builder; + +import java.io.OutputStream; +import com.github.scribejava.core.builder.api.Api; +import com.github.scribejava.core.exceptions.OAuthException; +import com.github.scribejava.core.model.OAuthConstants; +import com.github.scribejava.core.model.SignatureType; +import com.github.scribejava.core.utils.Preconditions; + +abstract class AbstractServiceBuilder { + + private Api api; + private String callback; + private String apiKey; + private String apiSecret; + private String scope; + private String state; + private SignatureType signatureType; + private OutputStream debugStream; + private String grantType; + + public AbstractServiceBuilder() { + this.callback = OAuthConstants.OUT_OF_BAND; + this.signatureType = SignatureType.Header; + } + + /** + * Configures the {@link Api} + * + * @param apiClass the class of one of the existent {@link Api}s on org.scribe.api package + * @return the {@link ServiceBuilder} instance for method chaining + */ + public T provider(final Class apiClass) { + Preconditions.checkNotNull(apiClass, "Api class cannot be null"); + try { + api = apiClass.newInstance(); + } catch (IllegalAccessException | InstantiationException | RuntimeException e) { + throw new OAuthException("Error while creating the Api object", e); + } + return (T) this; + } + + /** + * Configures the {@link Api} Overloaded version. Let's you use an instance instead of a class. + * + * @param api instance of {@link Api}s + * @return the {@link ServiceBuilder} instance for method chaining + */ + public T provider(final Api api) { + Preconditions.checkNotNull(api, "Api cannot be null"); + this.api = api; + return (T) this; + } + + /** + * Adds an OAuth callback url + * + * @param callback callback url. Must be a valid url or 'oob' for out of band OAuth + * @return the {@link ServiceBuilder} instance for method chaining + */ + public T callback(final String callback) { + Preconditions.checkNotNull(callback, "Callback can't be null"); + this.callback = callback; + return (T) this; + } + + /** + * Configures the api key + * + * @param apiKey The api key for your application + * @return the {@link ServiceBuilder} instance for method chaining + */ + public T apiKey(final String apiKey) { + Preconditions.checkEmptyString(apiKey, "Invalid Api key"); + this.apiKey = apiKey; + return (T) this; + } + + /** + * Configures the api secret + * + * @param apiSecret The api secret for your application + * @return the {@link ServiceBuilder} instance for method chaining + */ + public T apiSecret(final String apiSecret) { + Preconditions.checkEmptyString(apiSecret, "Invalid Api secret"); + this.apiSecret = apiSecret; + return (T) this; + } + + /** + * Configures the OAuth scope. This is only necessary in some APIs (like Google's). + * + * @param scope The OAuth scope + * @return the {@link ServiceBuilder} instance for method chaining + */ + public T scope(final String scope) { + Preconditions.checkEmptyString(scope, "Invalid OAuth scope"); + this.scope = scope; + return (T) this; + } + + /** + * Configures the anti forgery session state. This is available in some APIs (like Google's). + * + * @param state The OAuth state + * @return the {@link ServiceBuilder} instance for method chaining + */ + public T state(final String state) { + Preconditions.checkEmptyString(state, "Invalid OAuth state"); + this.state = state; + return (T) this; + } + + /** + * Configures the signature type, choose between header, querystring, etc. Defaults to Header + * + * @param type SignatureType + * @return the {@link ServiceBuilder} instance for method chaining + */ + public T signatureType(final SignatureType type) { + Preconditions.checkNotNull(type, "Signature type can't be null"); + this.signatureType = type; + return (T) this; + } + + public T debugStream(final OutputStream stream) { + Preconditions.checkNotNull(stream, "debug stream can't be null"); + this.debugStream = stream; + return (T) this; + } + + public T grantType(final String grantType) { + Preconditions.checkEmptyString(grantType, "Invalid OAuth grantType"); + this.grantType = grantType; + return (T) this; + } + + public T debug() { + debugStream(System.out); + return (T) this; + } + + public void checkPreconditions() { + Preconditions.checkNotNull(api, "You must specify a valid api through the provider() method"); + Preconditions.checkEmptyString(apiKey, "You must provide an api key"); + Preconditions.checkEmptyString(apiSecret, "You must provide an api secret"); + } + + public Api getApi() { + return api; + } + + public String getCallback() { + return callback; + } + + public String getApiKey() { + return apiKey; + } + + public String getApiSecret() { + return apiSecret; + } + + public String getScope() { + return scope; + } + + public String getState() { + return state; + } + + public SignatureType getSignatureType() { + return signatureType; + } + + public OutputStream getDebugStream() { + return debugStream; + } + + public String getGrantType() { + return grantType; + } +} 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 new file mode 100644 index 000000000..cec32603c --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilder.java @@ -0,0 +1,41 @@ +package com.github.scribejava.core.builder; + +import com.github.scribejava.core.model.OAuthConfig; +import com.github.scribejava.core.oauth.OAuthService; +import com.github.scribejava.core.utils.Preconditions; + +/** + * Implementation of the Builder pattern, with a fluent interface that creates a {@link OAuthService} + * + * @author Pablo Fernandez + */ +public class ServiceBuilder extends AbstractServiceBuilder { + + private Integer connectTimeout; + private Integer readTimeout; + + public ServiceBuilder connectTimeout(final Integer connectTimeout) { + Preconditions.checkNotNull(connectTimeout, "Connection timeout can't be null"); + this.connectTimeout = connectTimeout; + return this; + } + + public ServiceBuilder readTimeout(final Integer readTimeout) { + Preconditions.checkNotNull(readTimeout, "Read timeout can't be null"); + this.readTimeout = readTimeout; + return this; + } + + /** + * Returns the fully configured {@link OAuthService} + * + * @return fully configured {@link OAuthService} + */ + public OAuthService build() { + super.checkPreconditions(); + final OAuthConfig config = new OAuthConfig(getApiKey(), getApiSecret(), getCallback(), getSignatureType(), getScope(), getDebugStream(), + connectTimeout, readTimeout, getGrantType()); + config.setState(getState()); + return getApi().createService(config); + } +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilderAsync.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilderAsync.java new file mode 100644 index 000000000..1ea3f816b --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilderAsync.java @@ -0,0 +1,39 @@ +package com.github.scribejava.core.builder; + +import com.ning.http.client.AsyncHttpClientConfig; +import com.github.scribejava.core.model.OAuthConfigAsync; +import com.github.scribejava.core.oauth.OAuthService; +import com.github.scribejava.core.utils.Preconditions; + +public class ServiceBuilderAsync extends AbstractServiceBuilder { + + private AsyncHttpClientConfig asyncHttpClientConfig; + private String asyncHttpProviderClassName; + + public ServiceBuilderAsync asyncHttpClientConfig(final AsyncHttpClientConfig asyncHttpClientConfig) { + Preconditions.checkNotNull(asyncHttpClientConfig, "asyncHttpClientConfig can't be null"); + this.asyncHttpClientConfig = asyncHttpClientConfig; + return this; + } + + @Override + public void checkPreconditions() { + super.checkPreconditions(); + Preconditions.checkNotNull(asyncHttpClientConfig, "You must provide an asyncHttpClientConfig"); + } + + public OAuthService build() { + checkPreconditions(); + final OAuthConfigAsync configAsync = new OAuthConfigAsync(getApiKey(), getApiSecret(), getCallback(), getSignatureType(), getScope(), + getGrantType(), getDebugStream(), asyncHttpClientConfig); + configAsync.setState(getState()); + configAsync.setAsyncHttpProviderClassName(asyncHttpProviderClassName); + + return getApi().createService(configAsync); + } + + public ServiceBuilderAsync asyncHttpProviderClassName(final String asyncHttpProviderClassName) { + this.asyncHttpProviderClassName = asyncHttpProviderClassName; + return this; + } +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/Api.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/Api.java new file mode 100644 index 000000000..0c7c53ad7 --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/Api.java @@ -0,0 +1,20 @@ +package com.github.scribejava.core.builder.api; + +import com.github.scribejava.core.model.OAuthConfig; +import com.github.scribejava.core.oauth.OAuthService; + +/** + * Contains all the configuration needed to instantiate a valid {@link OAuthService} + * + * @author Pablo Fernandez + * + */ +public interface Api { + + /** + * + * @param config config to build the Service from + * @return fully configured {@link OAuthService} + */ + OAuthService createService(OAuthConfig config); +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi10a.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi10a.java new file mode 100644 index 000000000..6075d93ef --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi10a.java @@ -0,0 +1,133 @@ +package com.github.scribejava.core.builder.api; + +import com.github.scribejava.core.extractors.AccessTokenExtractor; +import com.github.scribejava.core.extractors.BaseStringExtractor; +import com.github.scribejava.core.extractors.BaseStringExtractorImpl; +import com.github.scribejava.core.extractors.HeaderExtractor; +import com.github.scribejava.core.extractors.HeaderExtractorImpl; +import com.github.scribejava.core.extractors.RequestTokenExtractor; +import com.github.scribejava.core.extractors.TokenExtractorImpl; +import com.github.scribejava.core.model.OAuthConfig; +import com.github.scribejava.core.model.Token; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.oauth.OAuth10aServiceImpl; +import com.github.scribejava.core.oauth.OAuthService; +import com.github.scribejava.core.services.HMACSha1SignatureService; +import com.github.scribejava.core.services.SignatureService; +import com.github.scribejava.core.services.TimestampService; +import com.github.scribejava.core.services.TimestampServiceImpl; + +/** + * Default implementation of the OAuth protocol, version 1.0a + * + * This class is meant to be extended by concrete implementations of the API, providing the endpoints and endpoint-http-verbs. + * + * If your Api adheres to the 1.0a protocol correctly, you just need to extend this class and define the getters for your endpoints. + * + * If your Api does something a bit different, you can override the different extractors or services, in order to fine-tune the process. Please read + * the javadocs of the interfaces to get an idea of what to do. + * + * @author Pablo Fernandez + * + */ +public abstract class DefaultApi10a implements Api { + + /** + * Returns the access token extractor. + * + * @return access token extractor + */ + public AccessTokenExtractor getAccessTokenExtractor() { + return new TokenExtractorImpl(); + } + + /** + * Returns the base string extractor. + * + * @return base string extractor + */ + public BaseStringExtractor getBaseStringExtractor() { + return new BaseStringExtractorImpl(); + } + + /** + * Returns the header extractor. + * + * @return header extractor + */ + public HeaderExtractor getHeaderExtractor() { + return new HeaderExtractorImpl(); + } + + /** + * Returns the request token extractor. + * + * @return request token extractor + */ + public RequestTokenExtractor getRequestTokenExtractor() { + return new TokenExtractorImpl(); + } + + /** + * Returns the signature service. + * + * @return signature service + */ + public SignatureService getSignatureService() { + return new HMACSha1SignatureService(); + } + + /** + * Returns the timestamp service. + * + * @return timestamp service + */ + public TimestampService getTimestampService() { + return new TimestampServiceImpl(); + } + + /** + * Returns the verb for the access token endpoint (defaults to POST) + * + * @return access token endpoint verb + */ + public Verb getAccessTokenVerb() { + return Verb.POST; + } + + /** + * Returns the verb for the request token endpoint (defaults to POST) + * + * @return request token endpoint verb + */ + public Verb getRequestTokenVerb() { + return Verb.POST; + } + + /** + * Returns the URL that receives the request token requests. + * + * @return request token URL + */ + public abstract String getRequestTokenEndpoint(); + + /** + * Returns the URL that receives the access token requests. + * + * @return access token URL + */ + public abstract String getAccessTokenEndpoint(); + + /** + * Returns the URL where you should redirect your users to authenticate your application. + * + * @param requestToken the request token you need to authorize + * @return the URL where you should redirect your users + */ + public abstract String getAuthorizationUrl(Token requestToken); + + @Override + public OAuthService createService(final OAuthConfig config) { + return new OAuth10aServiceImpl(this, config); + } +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java new file mode 100644 index 000000000..be0a328e5 --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java @@ -0,0 +1,65 @@ +package com.github.scribejava.core.builder.api; + +import com.github.scribejava.core.extractors.AccessTokenExtractor; +import com.github.scribejava.core.extractors.TokenExtractor20Impl; +import com.github.scribejava.core.model.OAuthConfig; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.oauth.OAuth20ServiceImpl; +import com.github.scribejava.core.oauth.OAuthService; + +/** + * Default implementation of the OAuth protocol, version 2.0 (draft 11) + * + * This class is meant to be extended by concrete implementations of the API, providing the endpoints and endpoint-http-verbs. + * + * If your Api adheres to the 2.0 (draft 11) protocol correctly, you just need to extend this class and define the getters for your endpoints. + * + * If your Api does something a bit different, you can override the different extractors or services, in order to fine-tune the process. Please read + * the javadocs of the interfaces to get an idea of what to do. + * + * @author Diego Silveira + * + */ +public abstract class DefaultApi20 implements Api { + + /** + * Returns the access token extractor. + * + * @return access token extractor + */ + public AccessTokenExtractor getAccessTokenExtractor() { + return new TokenExtractor20Impl(); + } + + /** + * Returns the verb for the access token endpoint (defaults to GET) + * + * @return access token endpoint verb + */ + public Verb getAccessTokenVerb() { + return Verb.GET; + } + + /** + * Returns the URL that receives the access token requests. + * + * @return access token URL + */ + public abstract String getAccessTokenEndpoint(); + + /** + * Returns the URL where you should redirect your users to authenticate your application. + * + * @param config OAuth 2.0 configuration param object + * @return the URL where you should redirect your users + */ + public abstract String getAuthorizationUrl(OAuthConfig config); + + /** + * {@inheritDoc} + */ + public OAuthService createService(OAuthConfig config) { + return new OAuth20ServiceImpl(this, config); + } + +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/exceptions/OAuthConnectionException.java b/scribejava-core/src/main/java/com/github/scribejava/core/exceptions/OAuthConnectionException.java new file mode 100644 index 000000000..01aebe236 --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/exceptions/OAuthConnectionException.java @@ -0,0 +1,13 @@ +package com.github.scribejava.core.exceptions; + +/** + * @author Pablo Fernandez + */ +public class OAuthConnectionException extends OAuthException { + + private static final String MSG = "There was a problem while creating a connection to the remote service: "; + + public OAuthConnectionException(final String url, final Exception e) { + super(MSG + url, e); + } +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/exceptions/OAuthException.java b/scribejava-core/src/main/java/com/github/scribejava/core/exceptions/OAuthException.java new file mode 100644 index 000000000..030545f4e --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/exceptions/OAuthException.java @@ -0,0 +1,40 @@ +package com.github.scribejava.core.exceptions; + +/** + * Default ScribeJava exception. Represents a problem in the OAuth signing + * process + * + * @author Pablo Fernandez + */ +public class OAuthException extends RuntimeException { + + /** + * Default constructor + * + * @param message message explaining what went wrong + * @param e original exception + */ + public OAuthException(String message, Exception e) { + super(message, e); + } + + /** + * No-exception constructor. Used when there is no original exception + * + * @param message message explaining what went wrong + */ + public OAuthException(String message) { + super(message, null); + } + + /** + * Exception constructor. Used to simply wrap an exception. + * + * @param e original exception + */ + public OAuthException(Exception e) { + super(e); + } + + private static final long serialVersionUID = 1L; +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/exceptions/OAuthParametersMissingException.java b/scribejava-core/src/main/java/com/github/scribejava/core/exceptions/OAuthParametersMissingException.java new file mode 100644 index 000000000..90da23f9c --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/exceptions/OAuthParametersMissingException.java @@ -0,0 +1,24 @@ +package com.github.scribejava.core.exceptions; + +import com.github.scribejava.core.model.AbstractRequest; + +/** + * Specialized exception that represents a missing OAuth parameter. + * + * @author Pablo Fernandez + */ +public class OAuthParametersMissingException extends OAuthException { + + private static final long serialVersionUID = 1745308760111976671L; + private static final String MSG = "Could not find oauth parameters in request: %s. " + + "OAuth parameters must be specified with the addOAuthParameter() method"; + + /** + * Default constructor. + * + * @param request OAuthRequest that caused the error + */ + public OAuthParametersMissingException(AbstractRequest request) { + super(String.format(MSG, request)); + } +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/exceptions/OAuthSignatureException.java b/scribejava-core/src/main/java/com/github/scribejava/core/exceptions/OAuthSignatureException.java new file mode 100644 index 000000000..4fbf98c52 --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/exceptions/OAuthSignatureException.java @@ -0,0 +1,23 @@ +package com.github.scribejava.core.exceptions; + +/** + * Specialized exception that represents a problem in the signature + * + * @author Pablo Fernandez + */ +public class OAuthSignatureException extends OAuthException { + + private static final long serialVersionUID = 1L; + private static final String MSG = "Error while signing string: %s"; + + /** + * Default constructor + * + * @param stringToSign plain string that gets signed (HMAC-SHA, etc) + * @param e original exception + */ + public OAuthSignatureException(String stringToSign, Exception e) { + super(String.format(MSG, stringToSign), e); + } + +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/AccessTokenExtractor.java b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/AccessTokenExtractor.java new file mode 100644 index 000000000..dcf7b1657 --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/AccessTokenExtractor.java @@ -0,0 +1,19 @@ +package com.github.scribejava.core.extractors; + +import com.github.scribejava.core.model.Token; + +/** + * Simple command object that extracts a {@link Token} from a String + * + * @author Pablo Fernandez + */ +public interface AccessTokenExtractor { + + /** + * Extracts the access token from the contents of an Http Response + * + * @param response the contents of the response + * @return OAuth access token + */ + public Token extract(String response); +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/BaseStringExtractor.java b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/BaseStringExtractor.java new file mode 100644 index 000000000..f929135c8 --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/BaseStringExtractor.java @@ -0,0 +1,23 @@ +package com.github.scribejava.core.extractors; + +import com.github.scribejava.core.model.AbstractRequest; + +/** + * Simple command object that extracts a base string from a + * {@link com.github.scribejava.core.model.AbstractRequest} + * + * @author Pablo Fernandez + */ +public interface BaseStringExtractor { + + /** + * Extracts an url-encoded base string from the + * {@link com.github.scribejava.core.model.AbstractRequest}. + * + * See the oauth spec for more info on this. + * + * @param request the OAuthRequest + * @return the url-encoded base string + */ + String extract(AbstractRequest request); +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/BaseStringExtractorImpl.java b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/BaseStringExtractorImpl.java new file mode 100644 index 000000000..68f7402ec --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/BaseStringExtractorImpl.java @@ -0,0 +1,45 @@ +package com.github.scribejava.core.extractors; + +import com.github.scribejava.core.exceptions.OAuthParametersMissingException; +import com.github.scribejava.core.model.AbstractRequest; +import com.github.scribejava.core.model.ParameterList; +import com.github.scribejava.core.utils.OAuthEncoder; +import com.github.scribejava.core.utils.Preconditions; + +/** + * Default implementation of {@link BaseStringExtractor}. Conforms to OAuth 1.0a + * + * @author Pablo Fernandez + * + */ +public class BaseStringExtractorImpl implements BaseStringExtractor { + + private static final String AMPERSAND_SEPARATED_STRING = "%s&%s&%s"; + + /** + * {@inheritDoc} + */ + public String extract(AbstractRequest request) { + checkPreconditions(request); + String verb = OAuthEncoder.encode(request.getVerb().name()); + String url = OAuthEncoder.encode(request.getSanitizedUrl()); + String params = getSortedAndEncodedParams(request); + return String.format(AMPERSAND_SEPARATED_STRING, verb, url, params); + } + + private String getSortedAndEncodedParams(AbstractRequest request) { + ParameterList params = new ParameterList(); + params.addAll(request.getQueryStringParams()); + params.addAll(request.getBodyParams()); + params.addAll(new ParameterList(request.getOauthParameters())); + return params.sort().asOauthBaseString(); + } + + private void checkPreconditions(AbstractRequest request) { + Preconditions.checkNotNull(request, "Cannot extract base string from a null object"); + + if (request.getOauthParameters() == null || request.getOauthParameters().size() <= 0) { + throw new OAuthParametersMissingException(request); + } + } +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/HeaderExtractor.java b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/HeaderExtractor.java new file mode 100644 index 000000000..0b31eb60e --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/HeaderExtractor.java @@ -0,0 +1,19 @@ +package com.github.scribejava.core.extractors; + +import com.github.scribejava.core.model.AbstractRequest; + +/** + * Simple command object that generates an OAuth Authorization header to include in the request. + * + * @author Pablo Fernandez + */ +public interface HeaderExtractor { + + /** + * Generates an OAuth 'Authorization' Http header to include in requests as the signature. + * + * @param request the AbstractRequest to inspect and generate the header + * @return the Http header value + */ + String extract(AbstractRequest request); +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/HeaderExtractorImpl.java b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/HeaderExtractorImpl.java new file mode 100644 index 000000000..8222cc846 --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/HeaderExtractorImpl.java @@ -0,0 +1,54 @@ +package com.github.scribejava.core.extractors; + +import java.util.Map; +import com.github.scribejava.core.exceptions.OAuthParametersMissingException; +import com.github.scribejava.core.model.OAuthConstants; +import com.github.scribejava.core.model.AbstractRequest; +import com.github.scribejava.core.utils.OAuthEncoder; +import com.github.scribejava.core.utils.Preconditions; + +/** + * Default implementation of {@link HeaderExtractor}. Conforms to OAuth 1.0a + * + * @author Pablo Fernandez + * + */ +public class HeaderExtractorImpl implements HeaderExtractor { + + private static final String PARAM_SEPARATOR = ", "; + private static final String PREAMBLE = "OAuth "; + public static final int ESTIMATED_PARAM_LENGTH = 20; + + /** + * {@inheritDoc} + */ + @Override + public String extract(final AbstractRequest request) { + checkPreconditions(request); + final Map parameters = request.getOauthParameters(); + final StringBuilder header = new StringBuilder(parameters.size() * ESTIMATED_PARAM_LENGTH); + header.append(PREAMBLE); + for (final Map.Entry entry : parameters.entrySet()) { + if (header.length() > PREAMBLE.length()) { + header.append(PARAM_SEPARATOR); + } + header.append(String.format("%s=\"%s\"", entry.getKey(), OAuthEncoder.encode(entry.getValue()))); + } + + if (request.getRealm() != null && !request.getRealm().isEmpty()) { + header.append(PARAM_SEPARATOR); + header.append(String.format("%s=\"%s\"", OAuthConstants.REALM, request.getRealm())); + } + + return header.toString(); + } + + private void checkPreconditions(final AbstractRequest request) { + Preconditions.checkNotNull(request, "Cannot extract a header from a null object"); + + if (request.getOauthParameters() == null || request.getOauthParameters().size() <= 0) { + throw new OAuthParametersMissingException(request); + } + } + +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/JsonTokenExtractor.java b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/JsonTokenExtractor.java new file mode 100644 index 000000000..e1854f1d0 --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/JsonTokenExtractor.java @@ -0,0 +1,27 @@ +package com.github.scribejava.core.extractors; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import com.github.scribejava.core.exceptions.OAuthException; +import com.github.scribejava.core.model.Token; +import com.github.scribejava.core.utils.Preconditions; + +public class JsonTokenExtractor implements AccessTokenExtractor { + + private static final Pattern ACCESS_TOKEN_PATTERN = Pattern.compile("\"access_token\"\\s*:\\s*\"(\\S*?)\""); + + @Override + public Token extract(final String response) { + return new Token(extractAccessToken(response), "", response); + } + + protected String extractAccessToken(final String response) { + Preconditions.checkEmptyString(response, "Cannot extract a token from a null or empty String"); + final Matcher matcher = ACCESS_TOKEN_PATTERN.matcher(response); + if (matcher.find()) { + return matcher.group(1); + } else { + throw new OAuthException("Cannot extract an access token. Response was: " + response); + } + } +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/RequestTokenExtractor.java b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/RequestTokenExtractor.java new file mode 100644 index 000000000..bc054713c --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/RequestTokenExtractor.java @@ -0,0 +1,19 @@ +package com.github.scribejava.core.extractors; + +import com.github.scribejava.core.model.Token; + +/** + * Simple command object that extracts a {@link Token} from a String + * + * @author Pablo Fernandez + */ +public interface RequestTokenExtractor { + + /** + * Extracts the request token from the contents of an Http Response + * + * @param response the contents of the response + * @return OAuth access token + */ + public Token extract(String response); +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/TokenExtractor20Impl.java b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/TokenExtractor20Impl.java new file mode 100644 index 000000000..23d5dd1fc --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/TokenExtractor20Impl.java @@ -0,0 +1,36 @@ +package com.github.scribejava.core.extractors; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import com.github.scribejava.core.exceptions.OAuthException; +import com.github.scribejava.core.model.Token; +import com.github.scribejava.core.utils.OAuthEncoder; +import com.github.scribejava.core.utils.Preconditions; + +/** + * Default implementation of {@link AccessTokenExtractor}. Conforms to OAuth 2.0 + * + */ +public class TokenExtractor20Impl implements AccessTokenExtractor { + + private static final String TOKEN_REGEX = "access_token=([^&]+)"; + private static final String EMPTY_SECRET = ""; + + /** + * {@inheritDoc} + */ + @Override + public Token extract(final String response) { + Preconditions.checkEmptyString(response, + "Response body is incorrect. Can't extract a token from an empty string"); + + final Matcher matcher = Pattern.compile(TOKEN_REGEX).matcher(response); + if (matcher.find()) { + final String token = OAuthEncoder.decode(matcher.group(1)); + return new Token(token, EMPTY_SECRET, response); + } else { + throw new OAuthException("Response body is incorrect. Can't extract a token from this: '" + response + "'", + null); + } + } +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/TokenExtractorImpl.java b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/TokenExtractorImpl.java new file mode 100644 index 000000000..62b630dc1 --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/TokenExtractorImpl.java @@ -0,0 +1,43 @@ +package com.github.scribejava.core.extractors; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import com.github.scribejava.core.exceptions.OAuthException; +import com.github.scribejava.core.model.Token; +import com.github.scribejava.core.utils.OAuthEncoder; +import com.github.scribejava.core.utils.Preconditions; + +/** + * Default implementation of {@link RequestTokenExtractor} and {@link AccessTokenExtractor}. Conforms to OAuth 1.0a + * + * The process for extracting access and request tokens is similar so this class can do both things. + * + * @author Pablo Fernandez + */ +public class TokenExtractorImpl implements RequestTokenExtractor, AccessTokenExtractor { + + private static final Pattern TOKEN_REGEX = Pattern.compile("oauth_token=([^&]+)"); + private static final Pattern SECRET_REGEX = Pattern.compile("oauth_token_secret=([^&]*)"); + + /** + * {@inheritDoc} + */ + @Override + public Token extract(final String response) { + Preconditions.checkEmptyString(response, + "Response body is incorrect. Can't extract a token from an empty string"); + final String token = extract(response, TOKEN_REGEX); + final String secret = extract(response, SECRET_REGEX); + return new Token(token, secret, response); + } + + private String extract(final String response, final Pattern p) { + final Matcher matcher = p.matcher(response); + if (matcher.find() && matcher.groupCount() >= 1) { + return OAuthEncoder.decode(matcher.group(1)); + } else { + throw new OAuthException("Response body is incorrect. Can't extract token and secret from this: '" + + response + "'", null); + } + } +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/AbstractRequest.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/AbstractRequest.java new file mode 100644 index 000000000..5f51c17ca --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/AbstractRequest.java @@ -0,0 +1,295 @@ +package com.github.scribejava.core.model; + +import java.io.UnsupportedEncodingException; +import java.net.MalformedURLException; +import java.net.URL; +import java.nio.charset.Charset; +import java.util.HashMap; +import java.util.Map; +import com.github.scribejava.core.exceptions.OAuthException; +import com.github.scribejava.core.oauth.OAuthService; + +/** + * The representation of an OAuth HttpRequest. + * + * @author Pablo Fernandez + */ +public abstract class AbstractRequest { + + protected static final String CONTENT_LENGTH = "Content-Length"; + protected static final String CONTENT_TYPE = "Content-Type"; + public static final String DEFAULT_CONTENT_TYPE = "application/x-www-form-urlencoded"; + private static final String OAUTH_PREFIX = "oauth_"; + + private final String url; + private final Verb verb; + private final ParameterList querystringParams = new ParameterList(); + private final ParameterList bodyParams = new ParameterList(); + private final Map headers = new HashMap<>(); + private boolean connectionKeepAlive; + private boolean followRedirects = true; + private OAuthService service; + + private String payload; + private String charset; + private byte[] bytePayload; + private final Map oauthParameters = new HashMap<>(); + + private String realm; + + /** + * Default constructor. + * + * @param verb Http verb/method + * @param url resource URL + * @param service OAuthService + */ + public AbstractRequest(final Verb verb, final String url, final OAuthService service) { + this.verb = verb; + this.url = url; + this.service = service; + } + + /** + * Adds an OAuth parameter. + * + * @param key name of the parameter + * @param value value of the parameter + * @throws IllegalArgumentException if the parameter is not an OAuth parameter + */ + public void addOAuthParameter(final String key, final String value) { + oauthParameters.put(checkKey(key), value); + } + + private String checkKey(final String key) { + if (key.startsWith(OAUTH_PREFIX) || key.equals(OAuthConstants.SCOPE) || key.equals(OAuthConstants.REALM)) { + return key; + } else { + throw new IllegalArgumentException( + String.format("OAuth parameters must either be '%s', '%s' or start with '%s'", OAuthConstants.SCOPE, OAuthConstants.REALM, OAUTH_PREFIX)); + } + } + + public Map getOauthParameters() { + return oauthParameters; + } + + public void setRealm(final String realm) { + this.realm = realm; + } + + public String getRealm() { + return realm; + } + + /** + * Returns the complete url (host + resource + encoded querystring parameters). + * + * @return the complete url. + */ + public String getCompleteUrl() { + return querystringParams.appendTo(url); + } + + /** + * Add an HTTP Header to the Request + * + * @param key the header name + * @param value the header value + */ + public void addHeader(final String key, final String value) { + this.headers.put(key, value); + } + + /** + * Add a body Parameter (for POST/ PUT Requests) + * + * @param key the parameter name + * @param value the parameter value + */ + public void addBodyParameter(final String key, final String value) { + this.bodyParams.add(key, value); + } + + /** + * Add a QueryString parameter + * + * @param key the parameter name + * @param value the parameter value + */ + public void addQuerystringParameter(final String key, final String value) { + this.querystringParams.add(key, value); + } + + public void addParameter(final String key, final String value) { + if (hasBodyContent()) { + bodyParams.add(key, value); + } else { + querystringParams.add(key, value); + } + } + + protected boolean hasBodyContent() { + return verb == Verb.PUT || verb == Verb.POST; + } + + /** + * Add body payload. This method is used when the HTTP body is not a form-url-encoded string, but another thing. Like for example XML. Note: The + * contents are not part of the OAuth signature + * + * @param payload the body of the request + */ + public void addPayload(final String payload) { + this.payload = payload; + } + + /** + * Overloaded version for byte arrays + * + * @param payload byte[] + */ + public void addPayload(final byte[] payload) { + this.bytePayload = payload.clone(); + } + + /** + * Get a {@link ParameterList} with the query string parameters. + * + * @return a {@link ParameterList} containing the query string parameters. + * @throws OAuthException if the request URL is not valid. + */ + public ParameterList getQueryStringParams() { + try { + final ParameterList result = new ParameterList(); + final String queryString = new URL(url).getQuery(); + result.addQuerystring(queryString); + result.addAll(querystringParams); + return result; + } catch (MalformedURLException mue) { + throw new OAuthException("Malformed URL", mue); + } + } + + /** + * Obtains a {@link ParameterList} of the body parameters. + * + * @return a {@link ParameterList}containing the body parameters. + */ + public ParameterList getBodyParams() { + return bodyParams; + } + + /** + * Obtains the URL of the HTTP Request. + * + * @return the original URL of the HTTP Request + */ + public String getUrl() { + return url; + } + + /** + * Returns the URL without the port and the query string part. + * + * @return the OAuth-sanitized URL + */ + public String getSanitizedUrl() { + if (url.startsWith("http://") && (url.endsWith(":80") || url.contains(":80/"))) { + return url.replaceAll("\\?.*", "").replaceAll(":80", ""); + } else if (url.startsWith("https://") && (url.endsWith(":443") || url.contains(":443/"))) { + return url.replaceAll("\\?.*", "").replaceAll(":443", ""); + } else { + return url.replaceAll("\\?.*", ""); + } + } + + /** + * Returns the body of the request + * + * @return form encoded string + * + * @throws OAuthException if the charset chosen is not supported + */ + public String getBodyContents() { + try { + return new String(getByteBodyContents(), getCharset()); + } catch (UnsupportedEncodingException uee) { + throw new OAuthException("Unsupported Charset: " + charset, uee); + } + } + + byte[] getByteBodyContents() { + if (bytePayload != null) { + return bytePayload; + } + final String body = (payload == null) ? bodyParams.asFormUrlEncodedString() : payload; + try { + return body.getBytes(getCharset()); + } catch (UnsupportedEncodingException uee) { + throw new OAuthException("Unsupported Charset: " + getCharset(), uee); + } + } + + @Override + public String toString() { + return String.format("@Request(%s %s)", getVerb(), getUrl()); + } + + public Verb getVerb() { + return verb; + } + + public Map getHeaders() { + return headers; + } + + public String getCharset() { + return charset == null ? Charset.defaultCharset().name() : charset; + } + + /** + * Set the charset of the body of the request + * + * @param charsetName name of the charset of the request + */ + public void setCharset(final String charsetName) { + charset = charsetName; + } + + /** + * Sets whether the underlying Http Connection is persistent or not. + * + * @param connectionKeepAlive boolean + * + * @see http://download.oracle.com/javase/1.5.0/docs/guide/net/http-keepalive.html + */ + public void setConnectionKeepAlive(final boolean connectionKeepAlive) { + this.connectionKeepAlive = connectionKeepAlive; + } + + /** + * Sets whether the underlying Http Connection follows redirects or not. + * + * Defaults to true (follow redirects) + * + * @see http://docs.oracle.com/javase/6/docs/api/java/net/HttpURLConnection.html#setInstanceFollowRedirects(boolean) + * @param followRedirects boolean + */ + public void setFollowRedirects(final boolean followRedirects) { + this.followRedirects = followRedirects; + } + + public boolean isConnectionKeepAlive() { + return connectionKeepAlive; + } + + public boolean isFollowRedirects() { + return followRedirects; + } + + public OAuthService getService() { + return service; + } +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/ForceTypeOfHttpRequest.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/ForceTypeOfHttpRequest.java new file mode 100644 index 000000000..b0387a535 --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/ForceTypeOfHttpRequest.java @@ -0,0 +1,10 @@ +package com.github.scribejava.core.model; + +public enum ForceTypeOfHttpRequest { + + NONE, + FORCE_ASYNC_ONLY_HTTP_REQUESTS, + FORCE_SYNC_ONLY_HTTP_REQUESTS, + PREFER_ASYNC_ONLY_HTTP_REQUESTS, + PREFER_SYNC_ONLY_HTTP_REQUESTS +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthAsyncRequestCallback.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthAsyncRequestCallback.java new file mode 100644 index 000000000..10f398fc4 --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthAsyncRequestCallback.java @@ -0,0 +1,8 @@ +package com.github.scribejava.core.model; + +public interface OAuthAsyncRequestCallback { + + void onCompleted(T response); + + void onThrowable(Throwable t); +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConfig.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConfig.java new file mode 100644 index 000000000..adec2c7c0 --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConfig.java @@ -0,0 +1,106 @@ +package com.github.scribejava.core.model; + +import java.io.IOException; +import java.io.OutputStream; + +/** + * Parameter object that groups OAuth config values + * + * @author Pablo Fernandez + */ +public class OAuthConfig { + + private final String apiKey; + private final String apiSecret; + private final String callback; + private final SignatureType signatureType; + private final String scope; + private final String grantType; + private final OutputStream debugStream; + private final Integer connectTimeout; + private final Integer readTimeout; + private String state; + + public OAuthConfig(final String key, final String secret) { + this(key, secret, null, null, null, null, null, null, null); + } + + public OAuthConfig(final String key, final String secret, final String callback, final SignatureType type, + final String scope, final OutputStream stream, final Integer connectTimeout, final Integer readTimeout, + final String grantType) { + this.apiKey = key; + this.apiSecret = secret; + this.callback = callback; + this.signatureType = type; + this.scope = scope; + this.debugStream = stream; + this.connectTimeout = connectTimeout; + this.readTimeout = readTimeout; + this.grantType = grantType; + } + + public String getApiKey() { + return apiKey; + } + + public String getApiSecret() { + return apiSecret; + } + + public String getCallback() { + return callback; + } + + public SignatureType getSignatureType() { + return signatureType; + } + + public String getScope() { + return scope; + } + + public boolean hasScope() { + return scope != null; + } + + public String getGrantType() { + return grantType; + } + + public boolean hasGrantType() { + return grantType != null; + } + + public Integer getConnectTimeout() { + return connectTimeout; + } + + public Integer getReadTimeout() { + return readTimeout; + } + + public void log(String message) { + if (debugStream != null) { + message += '\n'; + try { + debugStream.write(message.getBytes("UTF8")); + } catch (IOException | RuntimeException e) { + throw new RuntimeException("there were problems while writting to the debug stream", e); + } + } + } + + /** + * Sets optional value used by some provider implementations that is exchanged with provider to avoid CSRF attacks. + * + * @param state some secret key that client side shall never receive + */ + public void setState(final String state) { + this.state = state; + } + + public String getState() { + return state; + } + +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConfigAsync.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConfigAsync.java new file mode 100644 index 000000000..e02dc54ce --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConfigAsync.java @@ -0,0 +1,32 @@ +package com.github.scribejava.core.model; + +import com.ning.http.client.AsyncHttpClientConfig; +import java.io.OutputStream; + +public class OAuthConfigAsync extends OAuthConfig { + + private AsyncHttpClientConfig asyncHttpClientConfig; + private String asyncHttpProviderClassName; + + public OAuthConfigAsync(final String key, final String secret) { + super(key, secret); + } + + public OAuthConfigAsync(final String key, final String secret, final String callback, final SignatureType type, + final String scope, final String grantType, final OutputStream stream, final AsyncHttpClientConfig asyncHttpClientConfig) { + super(key, secret, callback, type, scope, stream, null, null, grantType); + this.asyncHttpClientConfig = asyncHttpClientConfig; + } + + public AsyncHttpClientConfig getAsyncHttpClientConfig() { + return asyncHttpClientConfig; + } + + public void setAsyncHttpProviderClassName(final String asyncHttpProviderClassName) { + this.asyncHttpProviderClassName = asyncHttpProviderClassName; + } + + public String getAsyncHttpProviderClassName() { + return asyncHttpProviderClassName; + } +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConstants.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConstants.java new file mode 100644 index 000000000..879dc5eec --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConstants.java @@ -0,0 +1,37 @@ +package com.github.scribejava.core.model; + +/** + * This class contains OAuth constants, used project-wide + * + * @author Pablo Fernandez + */ +public interface OAuthConstants { + + String TIMESTAMP = "oauth_timestamp"; + String SIGN_METHOD = "oauth_signature_method"; + String SIGNATURE = "oauth_signature"; + String CONSUMER_SECRET = "oauth_consumer_secret"; + String CONSUMER_KEY = "oauth_consumer_key"; + String CALLBACK = "oauth_callback"; + String VERSION = "oauth_version"; + String NONCE = "oauth_nonce"; + String REALM = "realm"; + String PARAM_PREFIX = "oauth_"; + String TOKEN = "oauth_token"; + String TOKEN_SECRET = "oauth_token_secret"; + String OUT_OF_BAND = "oob"; + String VERIFIER = "oauth_verifier"; + String HEADER = "Authorization"; + Token EMPTY_TOKEN = new Token("", ""); + String SCOPE = "scope"; + + // OAuth 2.0 + String ACCESS_TOKEN = "access_token"; + String CLIENT_ID = "client_id"; + String CLIENT_SECRET = "client_secret"; + String REDIRECT_URI = "redirect_uri"; + String CODE = "code"; + String GRANT_TYPE = "grant_type"; + String AUTHORIZATION_CODE = "authorization_code"; + String STATE = "state"; +} 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 new file mode 100644 index 000000000..2e3a69f24 --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequest.java @@ -0,0 +1,88 @@ +package com.github.scribejava.core.model; + +import java.io.IOException; +import java.net.HttpURLConnection; +import java.net.URL; +import java.util.Map; +import com.github.scribejava.core.exceptions.OAuthConnectionException; +import com.github.scribejava.core.exceptions.OAuthException; +import com.github.scribejava.core.oauth.OAuthService; + +public class OAuthRequest extends AbstractRequest { + + private HttpURLConnection connection; + + public OAuthRequest(Verb verb, String url, OAuthService service) { + super(verb, url, service); + } + + /** + * Execute the request and return a {@link Response} + * + * @return Http Response + * + * @throws RuntimeException if the connection cannot be created. + */ + public Response send() { + final ForceTypeOfHttpRequest forceTypeOfHttpRequest = ScribeJavaConfig.getForceTypeOfHttpRequests(); + + if (ForceTypeOfHttpRequest.FORCE_ASYNC_ONLY_HTTP_REQUESTS == forceTypeOfHttpRequest) { + throw new OAuthException("Cannot use sync operations, only async"); + } + if (ForceTypeOfHttpRequest.PREFER_ASYNC_ONLY_HTTP_REQUESTS == forceTypeOfHttpRequest) { + getService().getConfig().log("Cannot use sync operations, only async"); + } + try { + createConnection(); + return doSend(); + } catch (IOException | RuntimeException e) { + throw new OAuthConnectionException(getCompleteUrl(), e); + } + } + + Response doSend() throws IOException { + final Verb verb = getVerb(); + connection.setRequestMethod(verb.name()); + final OAuthConfig config = getService().getConfig(); + if (config.getConnectTimeout() != null) { + connection.setConnectTimeout(config.getConnectTimeout().intValue()); + } + if (config.getReadTimeout() != null) { + connection.setReadTimeout(config.getReadTimeout().intValue()); + } + addHeaders(); + if (hasBodyContent()) { + addBody(getByteBodyContents()); + } + return new Response(connection); + } + + private void createConnection() throws IOException { + final String completeUrl = getCompleteUrl(); + if (connection == null) { + System.setProperty("http.keepAlive", isConnectionKeepAlive() ? "true" : "false"); + connection = (HttpURLConnection) new URL(completeUrl).openConnection(); + connection.setInstanceFollowRedirects(isFollowRedirects()); + } + } + + void addHeaders() { + for (final Map.Entry entry : getHeaders().entrySet()) { + connection.setRequestProperty(entry.getKey(), entry.getValue()); + } + } + + void addBody(final byte[] content) throws IOException { + connection.setRequestProperty(CONTENT_LENGTH, String.valueOf(content.length)); + + if (connection.getRequestProperty(CONTENT_TYPE) == null) { + connection.setRequestProperty(CONTENT_TYPE, DEFAULT_CONTENT_TYPE); + } + connection.setDoOutput(true); + connection.getOutputStream().write(content); + } + + void setConnection(final HttpURLConnection connection) { + this.connection = connection; + } +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequestAsync.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequestAsync.java new file mode 100644 index 000000000..f0cc42b19 --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequestAsync.java @@ -0,0 +1,108 @@ +package com.github.scribejava.core.model; + +import com.ning.http.client.AsyncCompletionHandler; +import com.ning.http.client.AsyncHttpClient; +import com.ning.http.client.FluentCaseInsensitiveStringsMap; +import com.ning.http.client.ProxyServer; +import java.io.IOException; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.Future; +import com.github.scribejava.core.exceptions.OAuthException; +import com.github.scribejava.core.oauth.OAuthService; + +public class OAuthRequestAsync extends AbstractRequest { + + public static final ResponseConverter RESPONSE_CONVERTER = new ResponseConverter() { + @Override + public Response convert(final com.ning.http.client.Response response) throws IOException { + final FluentCaseInsensitiveStringsMap map = response.getHeaders(); + final Map headersMap = new HashMap<>(); + for (final FluentCaseInsensitiveStringsMap.Entry> header : map) { + final StringBuilder value = new StringBuilder(); + for (final String str : header.getValue()) { + value.append(str); + } + headersMap.put(header.getKey(), value.toString()); + } + return new Response(response.getStatusCode(), response.getStatusText(), headersMap, response.getResponseBody(), response. + getResponseBodyAsStream()); + } + }; + + public OAuthRequestAsync(final Verb verb, final String url, final OAuthService service) { + super(verb, url, service); + } + + public Future sendAsync(final OAuthAsyncRequestCallback callback, final ResponseConverter converter) { + return sendAsync(callback, converter, null); + } + + public Future sendAsync(final OAuthAsyncRequestCallback callback, final ResponseConverter converter, final ProxyServer proxyServer) { + final ForceTypeOfHttpRequest forceTypeOfHttpRequest = ScribeJavaConfig.getForceTypeOfHttpRequests(); + if (ForceTypeOfHttpRequest.FORCE_SYNC_ONLY_HTTP_REQUESTS == forceTypeOfHttpRequest) { + throw new OAuthException("Cannot use async operations, only sync"); + } + final OAuthService service = getService(); + if (ForceTypeOfHttpRequest.PREFER_SYNC_ONLY_HTTP_REQUESTS == forceTypeOfHttpRequest) { + service.getConfig().log("Cannot use async operations, only sync"); + } + final String completeUrl = getCompleteUrl(); + final AsyncHttpClient.BoundRequestBuilder boundRequestBuilder; + switch (getVerb()) { + case GET: + boundRequestBuilder = service.getAsyncHttpClient().prepareGet(completeUrl); + break; + case POST: + boundRequestBuilder = service.getAsyncHttpClient().preparePost(completeUrl).setBody(getBodyContents()); + break; + default: + throw new IllegalArgumentException("message build error: unknown verb type"); + } + if (proxyServer != null) { + boundRequestBuilder.setProxyServer(proxyServer); + } + return boundRequestBuilder.execute(new OAuthAsyncCompletionHandler<>(callback, converter)); + } + + private static class OAuthAsyncCompletionHandler extends AsyncCompletionHandler { + + private final OAuthAsyncRequestCallback callback; + private final ResponseConverter converter; + + OAuthAsyncCompletionHandler(final OAuthAsyncRequestCallback callback, final ResponseConverter converter) { + this.callback = callback; + this.converter = converter; + } + + @Override + public T onCompleted(final com.ning.http.client.Response response) throws IOException { + final T t = converter.convert(response); + if (callback != null) { + callback.onCompleted(t); + } + return t; + } + + @Override + public void onThrowable(final Throwable t) { + if (callback != null) { + callback.onThrowable(t); + } + } + }; + + public Future sendAsync(final OAuthAsyncRequestCallback callback) { + return sendAsync(callback, RESPONSE_CONVERTER, null); + } + + public Future sendAsync(final OAuthAsyncRequestCallback callback, final ProxyServer proxyServer) { + return sendAsync(callback, RESPONSE_CONVERTER, proxyServer); + } + + public interface ResponseConverter { + + T convert(com.ning.http.client.Response response) throws IOException; + } +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/Parameter.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/Parameter.java new file mode 100644 index 000000000..8eb23ba62 --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/Parameter.java @@ -0,0 +1,59 @@ +package com.github.scribejava.core.model; + +import com.github.scribejava.core.utils.OAuthEncoder; + +/** + * @author Pablo Fernandez + */ +public class Parameter implements Comparable { + + private static final String UTF = "UTF8"; + + private final String key; + private final String value; + + public Parameter(final String key, final String value) { + this.key = key; + this.value = value; + } + + public String asUrlEncodedPair() { + return OAuthEncoder.encode(key).concat("=").concat(OAuthEncoder.encode(value)); + } + + @Override + public boolean equals(final Object other) { + if (other == null) { + return false; + } + if (other == this) { + return true; + } + if (!(other instanceof Parameter)) { + return false; + } + + final Parameter otherParam = (Parameter) other; + return otherParam.getKey().equals(key) && otherParam.getValue().equals(value); + } + + public String getKey() { + return key; + } + + public String getValue() { + return value; + } + + @Override + public int hashCode() { + return key.hashCode() + value.hashCode(); + } + + @Override + public int compareTo(final Parameter parameter) { + final int keyDiff = key.compareTo(parameter.getKey()); + + return keyDiff == 0 ? value.compareTo(parameter.getValue()) : keyDiff; + } +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/ParameterList.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/ParameterList.java new file mode 100644 index 000000000..38f219650 --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/ParameterList.java @@ -0,0 +1,101 @@ +package com.github.scribejava.core.model; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import com.github.scribejava.core.utils.OAuthEncoder; +import com.github.scribejava.core.utils.Preconditions; + +/** + * @author Pablo Fernandez + */ +public class ParameterList { + + private static final char QUERY_STRING_SEPARATOR = '?'; + private static final String PARAM_SEPARATOR = "&"; + private static final String PAIR_SEPARATOR = "="; + private static final String EMPTY_STRING = ""; + + private final List params; + + public ParameterList() { + params = new ArrayList<>(); + } + + ParameterList(final List params) { + this.params = new ArrayList<>(params); + } + + public ParameterList(final Map map) { + this(); + for (final Map.Entry entry : map.entrySet()) { + params.add(new Parameter(entry.getKey(), entry.getValue())); + } + } + + public void add(final String key, final String value) { + params.add(new Parameter(key, value)); + } + + public String appendTo(String url) { + Preconditions.checkNotNull(url, "Cannot append to null URL"); + final String queryString = asFormUrlEncodedString(); + if (queryString.equals(EMPTY_STRING)) { + return url; + } else { + url += url.indexOf(QUERY_STRING_SEPARATOR) == -1 ? QUERY_STRING_SEPARATOR : PARAM_SEPARATOR; + url += queryString; + return url; + } + } + + public String asOauthBaseString() { + return OAuthEncoder.encode(asFormUrlEncodedString()); + } + + public String asFormUrlEncodedString() { + if (params.isEmpty()) { + return EMPTY_STRING; + } + + final StringBuilder builder = new StringBuilder(); + for (final Parameter p : params) { + builder.append('&').append(p.asUrlEncodedPair()); + } + return builder.toString().substring(1); + } + + public void addAll(final ParameterList other) { + params.addAll(other.getParams()); + } + + public void addQuerystring(final String queryString) { + if (queryString != null && queryString.length() > 0) { + for (final String param : queryString.split(PARAM_SEPARATOR)) { + final String pair[] = param.split(PAIR_SEPARATOR); + final String key = OAuthEncoder.decode(pair[0]); + final String value = pair.length > 1 ? OAuthEncoder.decode(pair[1]) : EMPTY_STRING; + params.add(new Parameter(key, value)); + } + } + } + + public boolean contains(final Parameter param) { + return params.contains(param); + } + + public int size() { + return params.size(); + } + + public List getParams() { + return params; + } + + public ParameterList sort() { + final ParameterList sorted = new ParameterList(params); + Collections.sort(sorted.getParams()); + return sorted; + } +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/Response.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/Response.java new file mode 100644 index 000000000..f78908a72 --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/Response.java @@ -0,0 +1,122 @@ +package com.github.scribejava.core.model; + +import java.io.IOException; +import java.io.InputStream; +import java.net.HttpURLConnection; +import java.net.UnknownHostException; +import java.util.HashMap; +import java.util.Map; +import com.github.scribejava.core.exceptions.OAuthException; +import com.github.scribejava.core.utils.StreamUtils; + +public class Response { + + private int code; + private String message; + private String body; + private InputStream stream; + private Map headers; + + public Response(final int code, final String message, final Map headers, final String body, final InputStream stream) { + this.code = code; + this.headers = headers; + this.body = body; + this.message = message; + this.stream = stream; + } + + Response(final HttpURLConnection connection) throws IOException { + try { + connection.connect(); + code = connection.getResponseCode(); + message = connection.getResponseMessage(); + headers = parseHeaders(connection); + stream = isSuccessful() ? connection.getInputStream() : connection.getErrorStream(); + } catch (UnknownHostException e) { + throw new OAuthException("The IP address of a host could not be determined.", e); + } + } + + private String parseBodyContents() { + body = StreamUtils.getStreamContents(getStream()); + return body; + } + + private Map parseHeaders(final HttpURLConnection conn) { + final Map headers = new HashMap<>(); + for (final String key : conn.getHeaderFields().keySet()) { + headers.put(key, conn.getHeaderFields().get(key).get(0)); + } + return headers; + } + + public final boolean isSuccessful() { + return getCode() >= 200 && getCode() < 400; + } + + /** + * Obtains the HTTP Response body + * + * @return response body + */ + public String getBody() { + return body == null ? parseBodyContents() : body; + } + + /** + * Obtains the meaningful stream of the HttpUrlConnection, either inputStream or errorInputStream, depending on the status code + * + * @return input stream / error stream + */ + private InputStream getStream() { + return stream; + } + + /** + * Obtains the HTTP status code + * + * @return the status code + */ + public final int getCode() { + return code; + } + + /** + * Obtains the HTTP status message. Returns null if the message can not be discerned from the response (not valid HTTP) + * + * @return the status message + */ + public String getMessage() { + return message; + } + + /** + * Obtains a {@link Map} containing the HTTP Response Headers + * + * @return headers + */ + public Map getHeaders() { + return headers; + } + + /** + * Obtains a single HTTP Header value, or null if undefined + * + * @param name the header name. + * + * @return header value or null. + */ + public String getHeader(final String name) { + return headers.get(name); + } + + @Override + public String toString() { + return "Response{" + + "code=" + code + + ", message='" + message + '\'' + + ", body='" + body + '\'' + + ", headers=" + headers + + '}'; + } +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/ScribeJavaConfig.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/ScribeJavaConfig.java new file mode 100644 index 000000000..171bbac1a --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/ScribeJavaConfig.java @@ -0,0 +1,14 @@ +package com.github.scribejava.core.model; + +public abstract class ScribeJavaConfig { + + private static ForceTypeOfHttpRequest forceTypeOfHttpRequests = ForceTypeOfHttpRequest.NONE; + + public static ForceTypeOfHttpRequest getForceTypeOfHttpRequests() { + return forceTypeOfHttpRequests; + } + + public static void setForceTypeOfHttpRequests(ForceTypeOfHttpRequest forceTypeOfHttpRequests) { + ScribeJavaConfig.forceTypeOfHttpRequests = forceTypeOfHttpRequests; + } +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/SignatureType.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/SignatureType.java new file mode 100644 index 000000000..26ffe054e --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/SignatureType.java @@ -0,0 +1,7 @@ +package com.github.scribejava.core.model; + +public enum SignatureType { + + Header, + QueryString +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/Token.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/Token.java new file mode 100644 index 000000000..816c06902 --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/Token.java @@ -0,0 +1,108 @@ +package com.github.scribejava.core.model; + +import java.io.Serializable; +import com.github.scribejava.core.utils.Preconditions; + +/** + * Represents an OAuth token (either request or access token) and its secret + * + * @author Pablo Fernandez + */ +public class Token implements Serializable { + + private static final long serialVersionUID = 715000866082812683L; + + private final String token; + private final String secret; + private final String rawResponse; + + /** + * Default constructor + * + * @param token token value. Can't be null. + * @param secret token secret. Can't be null. + */ + public Token(final String token, final String secret) { + this(token, secret, null); + } + + public Token(final String token, final String secret, final String rawResponse) { + Preconditions.checkNotNull(token, "Token can't be null"); + Preconditions.checkNotNull(secret, "Secret can't be null"); + + this.token = token; + this.secret = secret; + this.rawResponse = rawResponse; + } + + public String getToken() { + return token; + } + + public String getSecret() { + return secret; + } + + public String getRawResponse() { + if (rawResponse == null) { + throw new IllegalStateException( + "This token object was not constructed by ScribeJava and does not have a rawResponse"); + } + return rawResponse; + } + + public String getParameter(String parameter) { + String value = null; + for (String str : this.getRawResponse().split("&")) { + if (str.startsWith(parameter + '=')) { + String[] part = str.split("="); + if (part.length > 1) { + value = part[1].trim(); + } + break; + } + } + return value; + } + + @Override + public String toString() { + return String.format("Token[%s , %s]", token, secret); + } + + /** + * @return true if the token is empty (token = "", secret = "") + */ + public boolean isEmpty() { + return "".equals(this.token) && "".equals(this.secret); + } + + /** + * Factory method + * + * Useful for two legged OAuth. + * + * @return empty token (token = "", secret = "") + */ + public static Token empty() { + return new Token("", ""); + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + + final Token that = (Token) o; + return token.equals(that.getToken()) && secret.equals(that.getSecret()); + } + + @Override + public int hashCode() { + return 31 * token.hashCode() + secret.hashCode(); + } +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/Verb.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/Verb.java new file mode 100644 index 000000000..943459700 --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/Verb.java @@ -0,0 +1,11 @@ +package com.github.scribejava.core.model; + +/** + * An enumeration containing the most common HTTP Verbs. + * + * @author Pablo Fernandez + */ +public enum Verb { + + GET, POST, PUT, DELETE, HEAD, OPTIONS, TRACE, PATCH +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/Verifier.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/Verifier.java new file mode 100644 index 000000000..2f2ef21da --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/Verifier.java @@ -0,0 +1,27 @@ +package com.github.scribejava.core.model; + +import com.github.scribejava.core.utils.Preconditions; + +/** + * Represents an OAuth verifier code. + * + * @author Pablo Fernandez + */ +public class Verifier { + + private final String value; + + /** + * Default constructor. + * + * @param value verifier value + */ + public Verifier(String value) { + Preconditions.checkNotNull(value, "Must provide a valid string as verifier"); + this.value = value; + } + + public String getValue() { + return value; + } +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aServiceImpl.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aServiceImpl.java new file mode 100644 index 000000000..87b0dccf6 --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aServiceImpl.java @@ -0,0 +1,183 @@ +package com.github.scribejava.core.oauth; + +import com.ning.http.client.ProxyServer; +import java.io.IOException; +import java.util.Map; +import java.util.concurrent.Future; +import com.github.scribejava.core.builder.api.DefaultApi10a; +import com.github.scribejava.core.model.AbstractRequest; +import com.github.scribejava.core.model.OAuthAsyncRequestCallback; +import com.github.scribejava.core.model.OAuthConfig; +import com.github.scribejava.core.model.OAuthConstants; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.OAuthRequestAsync; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.Token; +import com.github.scribejava.core.model.Verifier; +import com.github.scribejava.core.services.Base64Encoder; +import com.github.scribejava.core.utils.MapUtils; + +/** + * OAuth 1.0a implementation of {@link OAuthService} + * + * @author Pablo Fernandez + */ +public class OAuth10aServiceImpl extends OAuthService { + + private static final String VERSION = "1.0"; + private final DefaultApi10a api; + + /** + * Default constructor + * + * @param api OAuth1.0a api information + * @param config OAuth 1.0a configuration param object + */ + public OAuth10aServiceImpl(final DefaultApi10a api, final OAuthConfig config) { + super(config); + this.api = api; + } + + @Override + public Token getRequestToken() { + final OAuthConfig config = getConfig(); + config.log("obtaining request token from " + api.getRequestTokenEndpoint()); + final OAuthRequest request = new OAuthRequest(api.getRequestTokenVerb(), api.getRequestTokenEndpoint(), this); + + config.log("setting oauth_callback to " + config.getCallback()); + request.addOAuthParameter(OAuthConstants.CALLBACK, config.getCallback()); + addOAuthParams(request, OAuthConstants.EMPTY_TOKEN); + appendSignature(request); + + config.log("sending request..."); + final Response response = request.send(); + final String body = response.getBody(); + + config.log("response status code: " + response.getCode()); + config.log("response body: " + body); + return api.getRequestTokenExtractor().extract(body); + } + + private void addOAuthParams(final AbstractRequest request, final Token token) { + final OAuthConfig config = getConfig(); + request.addOAuthParameter(OAuthConstants.TIMESTAMP, api.getTimestampService().getTimestampInSeconds()); + request.addOAuthParameter(OAuthConstants.NONCE, api.getTimestampService().getNonce()); + request.addOAuthParameter(OAuthConstants.CONSUMER_KEY, config.getApiKey()); + request.addOAuthParameter(OAuthConstants.SIGN_METHOD, api.getSignatureService().getSignatureMethod()); + request.addOAuthParameter(OAuthConstants.VERSION, getVersion()); + if (config.hasScope()) { + request.addOAuthParameter(OAuthConstants.SCOPE, config.getScope()); + } + request.addOAuthParameter(OAuthConstants.SIGNATURE, getSignature(request, token)); + + config.log("appended additional OAuth parameters: " + MapUtils.toString(request.getOauthParameters())); + } + + @Override + public Token getAccessToken(final Token requestToken, final Verifier verifier) { + final OAuthConfig config = getConfig(); + config.log("obtaining access token from " + api.getAccessTokenEndpoint()); + final OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint(), this); + prepareAccessTokenRequest(request, requestToken, verifier); + final Response response = request.send(); + return api.getAccessTokenExtractor().extract(response.getBody()); + } + + @Override + public Future getAccessTokenAsync(final Token requestToken, final Verifier verifier, final OAuthAsyncRequestCallback callback) { + return getAccessTokenAsync(requestToken, verifier, callback, null); + } + + @Override + public Future getAccessTokenAsync(final Token requestToken, final Verifier verifier, final OAuthAsyncRequestCallback callback, + final ProxyServer proxyServer) { + final OAuthConfig config = getConfig(); + config.log("async obtaining access token from " + api.getAccessTokenEndpoint()); + final OAuthRequestAsync request = new OAuthRequestAsync(api.getAccessTokenVerb(), api.getAccessTokenEndpoint(), this); + prepareAccessTokenRequest(request, requestToken, verifier); + return request.sendAsync(callback, new OAuthRequestAsync.ResponseConverter() { + @Override + public Token convert(final com.ning.http.client.Response response) throws IOException { + return getApi().getAccessTokenExtractor().extract(OAuthRequestAsync.RESPONSE_CONVERTER.convert(response).getBody()); + } + }, proxyServer); + } + + private void prepareAccessTokenRequest(final AbstractRequest request, final Token requestToken, final Verifier verifier) { + final OAuthConfig config = getConfig(); + request.addOAuthParameter(OAuthConstants.TOKEN, requestToken.getToken()); + request.addOAuthParameter(OAuthConstants.VERIFIER, verifier.getValue()); + config.log("setting token to: " + requestToken + " and verifier to: " + verifier); + addOAuthParams(request, requestToken); + appendSignature(request); + } + + /** + * {@inheritDoc} + */ + @Override + public void signRequest(final Token token, final AbstractRequest request) { + final OAuthConfig config = getConfig(); + config.log("signing request: " + request.getCompleteUrl()); + + // Do not append the token if empty. This is for two legged OAuth calls. + if (!token.isEmpty()) { + request.addOAuthParameter(OAuthConstants.TOKEN, token.getToken()); + } + config.log("setting token to: " + token); + addOAuthParams(request, token); + appendSignature(request); + } + + /** + * {@inheritDoc} + */ + @Override + public String getVersion() { + return VERSION; + } + + /** + * {@inheritDoc} + */ + @Override + public String getAuthorizationUrl(final Token requestToken) { + return api.getAuthorizationUrl(requestToken); + } + + private String getSignature(final AbstractRequest request, final Token token) { + final OAuthConfig config = getConfig(); + config.log("generating signature..."); + config.log("using base64 encoder: " + Base64Encoder.type()); + final String baseString = api.getBaseStringExtractor().extract(request); + final String signature = api.getSignatureService().getSignature(baseString, config.getApiSecret(), token. + getSecret()); + + config.log("base string is: " + baseString); + config.log("signature is: " + signature); + return signature; + } + + private void appendSignature(final AbstractRequest request) { + final OAuthConfig config = getConfig(); + switch (config.getSignatureType()) { + case Header: + config.log("using Http Header signature"); + + final String oauthHeader = api.getHeaderExtractor().extract(request); + request.addHeader(OAuthConstants.HEADER, oauthHeader); + break; + case QueryString: + config.log("using Querystring signature"); + + for (final Map.Entry entry : request.getOauthParameters().entrySet()) { + request.addQuerystringParameter(entry.getKey(), entry.getValue()); + } + break; + } + } + + public DefaultApi10a getApi() { + return api; + } +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20ServiceImpl.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20ServiceImpl.java new file mode 100644 index 000000000..24a075877 --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20ServiceImpl.java @@ -0,0 +1,109 @@ +package com.github.scribejava.core.oauth; + +import com.ning.http.client.ProxyServer; +import java.io.IOException; +import java.util.concurrent.Future; +import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.model.AbstractRequest; +import com.github.scribejava.core.model.OAuthAsyncRequestCallback; +import com.github.scribejava.core.model.OAuthConfig; +import com.github.scribejava.core.model.OAuthConstants; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.OAuthRequestAsync; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.Token; +import com.github.scribejava.core.model.Verifier; + +public class OAuth20ServiceImpl extends OAuthService { + + private static final String VERSION = "2.0"; + private final DefaultApi20 api; + + /** + * Default constructor + * + * @param api OAuth2.0 api information + * @param config OAuth 2.0 configuration param object + */ + public OAuth20ServiceImpl(final DefaultApi20 api, final OAuthConfig config) { + super(config); + this.api = api; + } + + @Override + public Token getAccessToken(final Token requestToken, final Verifier verifier) { + final Response response = createAccessTokenRequest(verifier, new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint(), this)). + send(); + return api.getAccessTokenExtractor().extract(response.getBody()); + } + + @Override + public Future getAccessTokenAsync(final Token requestToken, final Verifier verifier, final OAuthAsyncRequestCallback callback) { + return getAccessTokenAsync(requestToken, verifier, callback, null); + } + + @Override + public Future getAccessTokenAsync(final Token requestToken, final Verifier verifier, final OAuthAsyncRequestCallback callback, + final ProxyServer proxyServer) { + final OAuthRequestAsync request = createAccessTokenRequest(verifier, new OAuthRequestAsync(api.getAccessTokenVerb(), api. + getAccessTokenEndpoint(), + this)); + return request.sendAsync(callback, new OAuthRequestAsync.ResponseConverter() { + @Override + public Token convert(final com.ning.http.client.Response response) throws IOException { + return getApi().getAccessTokenExtractor().extract(OAuthRequestAsync.RESPONSE_CONVERTER.convert(response).getBody()); + } + }, proxyServer); + } + + protected T createAccessTokenRequest(final Verifier verifier, final T request) { + final OAuthConfig config = getConfig(); + request.addParameter(OAuthConstants.CLIENT_ID, config.getApiKey()); + request.addParameter(OAuthConstants.CLIENT_SECRET, config.getApiSecret()); + request.addParameter(OAuthConstants.CODE, verifier.getValue()); + request.addParameter(OAuthConstants.REDIRECT_URI, config.getCallback()); + if (config.hasScope()) { + request.addParameter(OAuthConstants.SCOPE, config.getScope()); + } + if (config.hasGrantType()) { + request.addParameter(OAuthConstants.GRANT_TYPE, config.getGrantType()); + } + return request; + } + + /** + * {@inheritDoc} + */ + @Override + public Token getRequestToken() { + throw new UnsupportedOperationException("Unsupported operation, please use 'getAuthorizationUrl' and redirect your users there"); + } + + /** + * {@inheritDoc} + */ + @Override + public String getVersion() { + return VERSION; + } + + /** + * {@inheritDoc} + */ + @Override + public void signRequest(final Token accessToken, final AbstractRequest request) { + request.addQuerystringParameter(OAuthConstants.ACCESS_TOKEN, accessToken.getToken()); + } + + /** + * {@inheritDoc} + */ + @Override + public String getAuthorizationUrl(final Token requestToken) { + return api.getAuthorizationUrl(getConfig()); + } + + public DefaultApi20 getApi() { + return api; + } +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java new file mode 100644 index 000000000..dfccae2e5 --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java @@ -0,0 +1,110 @@ +package com.github.scribejava.core.oauth; + +import com.ning.http.client.AsyncHttpClient; +import com.ning.http.client.ProxyServer; +import java.util.concurrent.Future; +import com.github.scribejava.core.exceptions.OAuthException; +import com.github.scribejava.core.model.AbstractRequest; +import com.github.scribejava.core.model.ForceTypeOfHttpRequest; +import com.github.scribejava.core.model.OAuthAsyncRequestCallback; +import com.github.scribejava.core.model.OAuthConfig; +import com.github.scribejava.core.model.OAuthConfigAsync; +import com.github.scribejava.core.model.ScribeJavaConfig; +import com.github.scribejava.core.model.Token; +import com.github.scribejava.core.model.Verifier; + +/** + * The main ScribeJava object. + * + * A facade responsible for the retrieval of request and access tokens and for the signing of HTTP requests. + * + * @author Pablo Fernandez + */ +public abstract class OAuthService { + + private final OAuthConfig config; + private AsyncHttpClient asyncHttpClient; + + public OAuthService(final OAuthConfig config) { + this.config = config; + final ForceTypeOfHttpRequest forceTypeOfHttpRequest = ScribeJavaConfig.getForceTypeOfHttpRequests(); + if (config instanceof OAuthConfigAsync) { + if (ForceTypeOfHttpRequest.FORCE_SYNC_ONLY_HTTP_REQUESTS == forceTypeOfHttpRequest) { + throw new OAuthException("Cannot use async operations, only sync"); + } + if (ForceTypeOfHttpRequest.PREFER_SYNC_ONLY_HTTP_REQUESTS == forceTypeOfHttpRequest) { + config.log("Cannot use async operations, only sync"); + } + final OAuthConfigAsync asyncConfig = ((OAuthConfigAsync) config); + final String asyncHttpProviderClassName = asyncConfig.getAsyncHttpProviderClassName(); + + asyncHttpClient = asyncHttpProviderClassName == null ? new AsyncHttpClient(asyncConfig.getAsyncHttpClientConfig()) + : new AsyncHttpClient(asyncHttpProviderClassName, asyncConfig.getAsyncHttpClientConfig()); + } else { + if (ForceTypeOfHttpRequest.FORCE_ASYNC_ONLY_HTTP_REQUESTS == forceTypeOfHttpRequest) { + throw new OAuthException("Cannot use sync operations, only async"); + } + if (ForceTypeOfHttpRequest.PREFER_ASYNC_ONLY_HTTP_REQUESTS == forceTypeOfHttpRequest) { + config.log("Cannot use sync operations, only async"); + } + } + } + + public AsyncHttpClient getAsyncHttpClient() { + return asyncHttpClient; + } + + public void closeAsyncClient() { + asyncHttpClient.close(); + } + + public OAuthConfig getConfig() { + return config; + } + + /** + * Retrieve the request token. + * + * @return request token + */ + public abstract Token getRequestToken(); + + public abstract Token getAccessToken(Token requestToken, Verifier verifier); + + /** + * Signs am OAuth request + * + * @param accessToken access token (obtained previously) + * @param request request to sign + */ + public abstract void signRequest(Token accessToken, AbstractRequest request); + + /** + * Start the request to retrieve the access token. The optionally provided callback will be called with the Token when it is available. + * + * @param requestToken request token (obtained previously or null) + * @param verifier verifier code + * @param callback optional callback + * @return Future + */ + public abstract Future getAccessTokenAsync(Token requestToken, Verifier verifier, OAuthAsyncRequestCallback callback); + + public abstract Future getAccessTokenAsync(Token requestToken, Verifier verifier, OAuthAsyncRequestCallback callback, + ProxyServer proxyServer); + + /** + * Returns the OAuth version of the service. + * + * @return oauth version as string + */ + public abstract String getVersion(); + + /** + * Returns the URL where you should redirect your users to authenticate your application. + * + * @param requestToken the request token you need to authorize + * @return the URL where you should redirect your users + */ + public abstract String getAuthorizationUrl(Token requestToken); + +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/services/Base64Encoder.java b/scribejava-core/src/main/java/com/github/scribejava/core/services/Base64Encoder.java new file mode 100644 index 000000000..b5cb7d447 --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/services/Base64Encoder.java @@ -0,0 +1,29 @@ +package com.github.scribejava.core.services; + +public abstract class Base64Encoder { + + private static Base64Encoder instance; + + public static synchronized Base64Encoder getInstance() { + if (instance == null) { + instance = createEncoderInstance(); + } + return instance; + } + + private static Base64Encoder createEncoderInstance() { + if (CommonsEncoder.isPresent()) { + return new CommonsEncoder(); + } else { + return new DatatypeConverterEncoder(); + } + } + + public static String type() { + return getInstance().getType(); + } + + public abstract String encode(byte[] bytes); + + public abstract String getType(); +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/services/CommonsEncoder.java b/scribejava-core/src/main/java/com/github/scribejava/core/services/CommonsEncoder.java new file mode 100644 index 000000000..6e2afa24d --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/services/CommonsEncoder.java @@ -0,0 +1,31 @@ +package com.github.scribejava.core.services; + +import java.io.UnsupportedEncodingException; +import org.apache.commons.codec.binary.Base64; +import com.github.scribejava.core.exceptions.OAuthSignatureException; + +public class CommonsEncoder extends Base64Encoder { + + @Override + public String encode(byte[] bytes) { + try { + return new String(Base64.encodeBase64(bytes), "UTF-8"); + } catch (UnsupportedEncodingException e) { + throw new OAuthSignatureException("Can't perform base64 encoding", e); + } + } + + @Override + public String getType() { + return "CommonsCodec"; + } + + public static boolean isPresent() { + try { + Class.forName("org.apache.commons.codec.binary.Base64"); + return true; + } catch (ClassNotFoundException e) { + return false; + } + } +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/services/DatatypeConverterEncoder.java b/scribejava-core/src/main/java/com/github/scribejava/core/services/DatatypeConverterEncoder.java new file mode 100644 index 000000000..eee87714f --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/services/DatatypeConverterEncoder.java @@ -0,0 +1,16 @@ +package com.github.scribejava.core.services; + +import javax.xml.bind.DatatypeConverter; + +public class DatatypeConverterEncoder extends Base64Encoder { + + @Override + public String encode(byte[] bytes) { + return DatatypeConverter.printBase64Binary(bytes); + } + + @Override + public String getType() { + return "DatatypeConverter"; + } +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/services/HMACSha1SignatureService.java b/scribejava-core/src/main/java/com/github/scribejava/core/services/HMACSha1SignatureService.java new file mode 100644 index 000000000..960b49214 --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/services/HMACSha1SignatureService.java @@ -0,0 +1,60 @@ +package com.github.scribejava.core.services; + +import java.io.UnsupportedEncodingException; +import java.security.InvalidKeyException; +import java.security.NoSuchAlgorithmException; +import javax.crypto.Mac; +import javax.crypto.spec.SecretKeySpec; +import com.github.scribejava.core.exceptions.OAuthSignatureException; +import com.github.scribejava.core.utils.OAuthEncoder; +import com.github.scribejava.core.utils.Preconditions; + +/** + * HMAC-SHA1 implementation of {@link SignatureService} + * + * @author Pablo Fernandez + * + */ +public class HMACSha1SignatureService implements SignatureService { + + private static final String EMPTY_STRING = ""; + private static final String CARRIAGE_RETURN = "\r\n"; + private static final String UTF8 = "UTF-8"; + private static final String HMAC_SHA1 = "HmacSHA1"; + private static final String METHOD = "HMAC-SHA1"; + + /** + * {@inheritDoc} + */ + @Override + public String getSignature(final String baseString, final String apiSecret, final 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"); + return doSign(baseString, OAuthEncoder.encode(apiSecret) + '&' + OAuthEncoder.encode(tokenSecret)); + } catch (UnsupportedEncodingException | NoSuchAlgorithmException | InvalidKeyException | RuntimeException e) { + throw new OAuthSignatureException(baseString, e); + } + } + + private String doSign(final String toSign, final String keyString) throws UnsupportedEncodingException, + NoSuchAlgorithmException, InvalidKeyException { + final SecretKeySpec key = new SecretKeySpec(keyString.getBytes(UTF8), HMAC_SHA1); + final Mac mac = Mac.getInstance(HMAC_SHA1); + mac.init(key); + final byte[] bytes = mac.doFinal(toSign.getBytes(UTF8)); + return bytesToBase64String(bytes).replace(CARRIAGE_RETURN, EMPTY_STRING); + } + + private String bytesToBase64String(final byte[] bytes) { + return Base64Encoder.getInstance().encode(bytes); + } + + /** + * {@inheritDoc} + */ + @Override + public String getSignatureMethod() { + return METHOD; + } +} 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 new file mode 100644 index 000000000..ff61219e0 --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/services/PlaintextSignatureService.java @@ -0,0 +1,37 @@ +package com.github.scribejava.core.services; + +import com.github.scribejava.core.exceptions.OAuthSignatureException; +import com.github.scribejava.core.utils.OAuthEncoder; +import com.github.scribejava.core.utils.Preconditions; + +/** + * plaintext implementation of {@link SignatureService} + * + * @author Pablo Fernandez + * + */ +public class PlaintextSignatureService implements SignatureService { + + private static final String METHOD = "PLAINTEXT"; + + /** + * {@inheritDoc} + */ + @Override + public String getSignature(String baseString, String apiSecret, String tokenSecret) { + try { + Preconditions.checkEmptyString(apiSecret, "Api secret cant be null or empty string"); + return OAuthEncoder.encode(apiSecret) + '&' + OAuthEncoder.encode(tokenSecret); + } catch (Exception e) { + throw new OAuthSignatureException(baseString, e); + } + } + + /** + * {@inheritDoc} + */ + @Override + public String getSignatureMethod() { + return METHOD; + } +} 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 new file mode 100644 index 000000000..ea7cb6dc2 --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/services/RSASha1SignatureService.java @@ -0,0 +1,47 @@ +package com.github.scribejava.core.services; + +import java.security.PrivateKey; +import java.security.Signature; +import java.security.SignatureException; +import com.github.scribejava.core.exceptions.OAuthSignatureException; + +/** + * A signature service that uses the RSA-SHA1 algorithm. + */ +public class RSASha1SignatureService implements SignatureService { + + private static final String METHOD = "RSA-SHA1"; + private static final String RSA_SHA1 = "SHA1withRSA"; + private static final String UTF8 = "UTF-8"; + + private PrivateKey privateKey; + + public RSASha1SignatureService(PrivateKey privateKey) { + this.privateKey = privateKey; + } + + /** + * {@inheritDoc} + */ + public String getSignature(String baseString, String apiSecret, String tokenSecret) { + try { + Signature signature = Signature.getInstance(RSA_SHA1); + signature.initSign(privateKey); + signature.update(baseString.getBytes(UTF8)); + return bytesToBase64String(signature); + } catch (Exception e) { + throw new OAuthSignatureException(baseString, e); + } + } + + private String bytesToBase64String(Signature signature) throws SignatureException { + return Base64Encoder.getInstance().encode(signature.sign()); + } + + /** + * {@inheritDoc} + */ + public String getSignatureMethod() { + return METHOD; + } +} 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 new file mode 100644 index 000000000..34bfc2202 --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/services/SignatureService.java @@ -0,0 +1,23 @@ +package com.github.scribejava.core.services; + +/** + * Signs a base string, returning the OAuth signature + * + * @author Pablo Fernandez + * + */ +public interface SignatureService { + + /** + * Returns the signature + * + * @param baseString url-encoded string to sign + * @param apiSecret api secret for your app + * @param tokenSecret token secret (empty string for the request token step) + * + * @return signature + */ + String getSignature(String baseString, String apiSecret, String tokenSecret); + + String getSignatureMethod(); +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/services/TimestampService.java b/scribejava-core/src/main/java/com/github/scribejava/core/services/TimestampService.java new file mode 100644 index 000000000..fca170c83 --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/services/TimestampService.java @@ -0,0 +1,25 @@ +package com.github.scribejava.core.services; + +/** + * Unix epoch timestamp generator. + * + * This class is useful for stubbing in tests. + * + * @author Pablo Fernandez + */ +public interface TimestampService { + + /** + * Returns the unix epoch timestamp in seconds + * + * @return timestamp + */ + public String getTimestampInSeconds(); + + /** + * Returns a nonce (unique value for each request) + * + * @return nonce + */ + public String getNonce(); +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/services/TimestampServiceImpl.java b/scribejava-core/src/main/java/com/github/scribejava/core/services/TimestampServiceImpl.java new file mode 100644 index 000000000..c844ea6c7 --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/services/TimestampServiceImpl.java @@ -0,0 +1,62 @@ +package com.github.scribejava.core.services; + +import java.util.Random; + +/** + * Implementation of {@link TimestampService} using plain java classes. + * + * @author Pablo Fernandez + */ +public class TimestampServiceImpl implements TimestampService { + + private Timer timer; + + /** + * Default constructor. + */ + public TimestampServiceImpl() { + timer = new Timer(); + } + + /** + * {@inheritDoc} + */ + public String getNonce() { + Long ts = getTs(); + return String.valueOf(ts + timer.getRandomInteger()); + } + + /** + * {@inheritDoc} + */ + public String getTimestampInSeconds() { + return String.valueOf(getTs()); + } + + private Long getTs() { + return timer.getMilis() / 1000; + } + + void setTimer(Timer timer) { + this.timer = timer; + } + + /** + * Inner class that uses {@link System} for generating the timestamps. + * + * @author Pablo Fernandez + */ + static class Timer { + + private final Random rand = new Random(); + + Long getMilis() { + return System.currentTimeMillis(); + } + + Integer getRandomInteger() { + return rand.nextInt(); + } + } + +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/utils/MapUtils.java b/scribejava-core/src/main/java/com/github/scribejava/core/utils/MapUtils.java new file mode 100644 index 000000000..d070a76d7 --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/utils/MapUtils.java @@ -0,0 +1,24 @@ +package com.github.scribejava.core.utils; + +import java.util.Map; + +/** + * @author Pablo Fernandez + */ +public abstract class MapUtils { + + public static String toString(final Map map) { + if (map == null) { + return ""; + } + if (map.isEmpty()) { + return "{}"; + } + + final StringBuilder result = new StringBuilder(); + for (final Map.Entry entry : map.entrySet()) { + result.append(String.format(", %s -> %s ", entry.getKey().toString(), entry.getValue().toString())); + } + return "{" + result.substring(1) + "}"; + } +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/utils/OAuthEncoder.java b/scribejava-core/src/main/java/com/github/scribejava/core/utils/OAuthEncoder.java new file mode 100644 index 000000000..a9990c81e --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/utils/OAuthEncoder.java @@ -0,0 +1,54 @@ +package com.github.scribejava.core.utils; + +import java.io.UnsupportedEncodingException; +import java.net.URLDecoder; +import java.net.URLEncoder; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.regex.Pattern; +import com.github.scribejava.core.exceptions.OAuthException; + +/** + * @author Pablo Fernandez + */ +public abstract class OAuthEncoder { + + private static final String CHARSET = "UTF-8"; + private static final Map ENCODING_RULES; + + static { + final Map rules = new HashMap<>(); + rules.put("*", "%2A"); + rules.put("+", "%20"); + rules.put("%7E", "~"); + ENCODING_RULES = Collections.unmodifiableMap(rules); + } + + public static String encode(final String plain) { + Preconditions.checkNotNull(plain, "Cannot encode null object"); + String encoded = ""; + try { + encoded = URLEncoder.encode(plain, CHARSET); + } catch (UnsupportedEncodingException uee) { + throw new OAuthException("Charset not found while encoding string: " + CHARSET, uee); + } + for (final Map.Entry rule : ENCODING_RULES.entrySet()) { + encoded = applyRule(encoded, rule.getKey(), rule.getValue()); + } + return encoded; + } + + private static String applyRule(final String encoded, final String toReplace, final String replacement) { + return encoded.replaceAll(Pattern.quote(toReplace), replacement); + } + + public static String decode(final String encoded) { + Preconditions.checkNotNull(encoded, "Cannot decode null object"); + try { + return URLDecoder.decode(encoded, CHARSET); + } catch (UnsupportedEncodingException uee) { + throw new OAuthException("Charset not found while decoding string: " + CHARSET, uee); + } + } +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/utils/Preconditions.java b/scribejava-core/src/main/java/com/github/scribejava/core/utils/Preconditions.java new file mode 100644 index 000000000..505ced85b --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/utils/Preconditions.java @@ -0,0 +1,77 @@ +package com.github.scribejava.core.utils; + +import java.util.Locale; +import java.util.regex.Pattern; +import com.github.scribejava.core.model.OAuthConstants; + +/** + * Utils for checking preconditions and invariants + * + * @author Pablo Fernandez + */ +public abstract class Preconditions { + + private static final String DEFAULT_MESSAGE = "Received an invalid parameter"; + + // scheme = alpha *( alpha | digit | "+" | "-" | "." ) + private static final Pattern URL_PATTERN = Pattern.compile("^[a-zA-Z][a-zA-Z0-9+.-]*://\\S+"); + + /** + * Checks that an object is not null. + * + * @param object any object + * @param errorMsg error message + * + * @throws IllegalArgumentException if the object is null + */ + public static void checkNotNull(final Object object, final String errorMsg) { + check(object != null, errorMsg); + } + + /** + * Checks that a string is not null or empty + * + * @param string any string + * @param errorMsg error message + * + * @throws IllegalArgumentException if the string is null or empty + */ + public static void checkEmptyString(final String string, final String errorMsg) { + check(string != null && !string.trim().isEmpty(), errorMsg); + } + + /** + * Checks that a URL is valid + * + * @param url any string + * @param errorMsg error message + */ + public static void checkValidUrl(final String url, final String errorMsg) { + checkEmptyString(url, errorMsg); + check(isUrl(url), errorMsg); + } + + /** + * Checks that a URL is a valid OAuth callback + * + * @param url any string + * @param errorMsg error message + */ + public static void checkValidOAuthCallback(final String url, final String errorMsg) { + checkEmptyString(url, errorMsg); + if (url.toLowerCase(Locale.getDefault()).compareToIgnoreCase(OAuthConstants.OUT_OF_BAND) != 0) { + check(isUrl(url), errorMsg); + } + } + + private static boolean isUrl(final String url) { + return URL_PATTERN.matcher(url).matches(); + } + + private static void check(final boolean requirements, final String error) { + if (!requirements) { + throw new IllegalArgumentException(error == null || error.trim().length() <= 0 ? DEFAULT_MESSAGE : error); + } + } + +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/utils/StreamUtils.java b/scribejava-core/src/main/java/com/github/scribejava/core/utils/StreamUtils.java new file mode 100644 index 000000000..88fb392dc --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/utils/StreamUtils.java @@ -0,0 +1,40 @@ +package com.github.scribejava.core.utils; + +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; + +/** + * Utils to deal with Streams. + * + * @author Pablo Fernandez + */ +public abstract class StreamUtils { + + /** + * Returns the stream contents as an UTF-8 encoded string + * + * @param is input stream + * @return string contents + */ + public static String getStreamContents(InputStream is) { + Preconditions.checkNotNull(is, "Cannot get String from a null object"); + try { + final char[] buffer = new char[0x10000]; + StringBuilder out = new StringBuilder(); + Reader in = new InputStreamReader(is, "UTF-8"); + int read; + do { + read = in.read(buffer, 0, buffer.length); + if (read > 0) { + out.append(buffer, 0, read); + } + } while (read >= 0); + in.close(); + return out.toString(); + } catch (IOException ioe) { + throw new IllegalStateException("Error while reading response body", ioe); + } + } +} diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/ObjectMother.java b/scribejava-core/src/test/java/com/github/scribejava/core/ObjectMother.java new file mode 100644 index 000000000..1f148846d --- /dev/null +++ b/scribejava-core/src/test/java/com/github/scribejava/core/ObjectMother.java @@ -0,0 +1,70 @@ +package com.github.scribejava.core; + +import com.github.scribejava.core.model.OAuthConfig; +import com.github.scribejava.core.model.OAuthConstants; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.oauth.OAuth20ServiceImpl; + +public class ObjectMother { + + public static OAuthRequest createSampleOAuthRequest() { + OAuthRequest request = new OAuthRequest(Verb.GET, "http://example.com", new OAuth20ServiceImpl(null, new OAuthConfig("test", + "test"))); + request.addOAuthParameter(OAuthConstants.TIMESTAMP, "123456"); + request.addOAuthParameter(OAuthConstants.CONSUMER_KEY, "AS#$^*@&"); + request.addOAuthParameter(OAuthConstants.CALLBACK, "http://example/callback"); + request.addOAuthParameter(OAuthConstants.SIGNATURE, "OAuth-Signature"); + return request; + } + + public static OAuthRequest createSampleOAuthRequestPort80() { + OAuthRequest request = new OAuthRequest(Verb.GET, "http://example.com:80", new OAuth20ServiceImpl(null, new OAuthConfig("test", + "test"))); + request.addOAuthParameter(OAuthConstants.TIMESTAMP, "123456"); + request.addOAuthParameter(OAuthConstants.CONSUMER_KEY, "AS#$^*@&"); + request.addOAuthParameter(OAuthConstants.CALLBACK, "http://example/callback"); + request.addOAuthParameter(OAuthConstants.SIGNATURE, "OAuth-Signature"); + return request; + } + + public static OAuthRequest createSampleOAuthRequestPort80v2() { + OAuthRequest request = new OAuthRequest(Verb.GET, "http://example.com:80/test", new OAuth20ServiceImpl(null, new OAuthConfig( + "test", "test"))); + request.addOAuthParameter(OAuthConstants.TIMESTAMP, "123456"); + request.addOAuthParameter(OAuthConstants.CONSUMER_KEY, "AS#$^*@&"); + request.addOAuthParameter(OAuthConstants.CALLBACK, "http://example/callback"); + request.addOAuthParameter(OAuthConstants.SIGNATURE, "OAuth-Signature"); + return request; + } + + public static OAuthRequest createSampleOAuthRequestPort8080() { + OAuthRequest request = new OAuthRequest(Verb.GET, "http://example.com:8080", new OAuth20ServiceImpl(null, new OAuthConfig("test", + "test"))); + request.addOAuthParameter(OAuthConstants.TIMESTAMP, "123456"); + request.addOAuthParameter(OAuthConstants.CONSUMER_KEY, "AS#$^*@&"); + request.addOAuthParameter(OAuthConstants.CALLBACK, "http://example/callback"); + request.addOAuthParameter(OAuthConstants.SIGNATURE, "OAuth-Signature"); + return request; + } + + public static OAuthRequest createSampleOAuthRequestPort443() { + OAuthRequest request = new OAuthRequest(Verb.GET, "https://example.com:443", new OAuth20ServiceImpl(null, new OAuthConfig("test", + "test"))); + request.addOAuthParameter(OAuthConstants.TIMESTAMP, "123456"); + request.addOAuthParameter(OAuthConstants.CONSUMER_KEY, "AS#$^*@&"); + request.addOAuthParameter(OAuthConstants.CALLBACK, "http://example/callback"); + request.addOAuthParameter(OAuthConstants.SIGNATURE, "OAuth-Signature"); + return request; + } + + public static OAuthRequest createSampleOAuthRequestPort443v2() { + OAuthRequest request = new OAuthRequest(Verb.GET, "https://example.com:443/test", new OAuth20ServiceImpl(null, new OAuthConfig( + "test", "test"))); + request.addOAuthParameter(OAuthConstants.TIMESTAMP, "123456"); + request.addOAuthParameter(OAuthConstants.CONSUMER_KEY, "AS#$^*@&"); + request.addOAuthParameter(OAuthConstants.CALLBACK, "http://example/callback"); + request.addOAuthParameter(OAuthConstants.SIGNATURE, "OAuth-Signature"); + return request; + } +} diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/builder/ServiceBuilderTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/builder/ServiceBuilderTest.java new file mode 100644 index 000000000..d8e11ac88 --- /dev/null +++ b/scribejava-core/src/test/java/com/github/scribejava/core/builder/ServiceBuilderTest.java @@ -0,0 +1,68 @@ +package com.github.scribejava.core.builder; + +import static org.junit.Assert.assertEquals; +import org.junit.Before; +import org.junit.Test; +import com.github.scribejava.core.builder.api.Api; +import com.github.scribejava.core.model.OAuthConfig; +import com.github.scribejava.core.model.OAuthConstants; +import com.github.scribejava.core.model.SignatureType; +import com.github.scribejava.core.oauth.OAuthService; + +public class ServiceBuilderTest { + + private ServiceBuilder builder; + + @Before + public void setup() { + builder = new ServiceBuilder(); + } + + @Test + public void shouldReturnConfigDefaultValues() { + builder.provider(ApiMock.class).apiKey("key").apiSecret("secret").build(); + assertEquals(ApiMock.config.getApiKey(), "key"); + assertEquals(ApiMock.config.getApiSecret(), "secret"); + assertEquals(ApiMock.config.getCallback(), OAuthConstants.OUT_OF_BAND); + assertEquals(ApiMock.config.getSignatureType(), SignatureType.Header); + } + + @Test + public void shouldAcceptValidCallbackUrl() { + builder.provider(ApiMock.class).apiKey("key").apiSecret("secret").callback("http://example.com").build(); + assertEquals(ApiMock.config.getApiKey(), "key"); + assertEquals(ApiMock.config.getApiSecret(), "secret"); + assertEquals(ApiMock.config.getCallback(), "http://example.com"); + } + + @Test + public void shouldAcceptASignatureType() { + builder.provider(ApiMock.class).apiKey("key").apiSecret("secret").signatureType(SignatureType.QueryString).build(); + assertEquals(ApiMock.config.getApiKey(), "key"); + assertEquals(ApiMock.config.getApiSecret(), "secret"); + assertEquals(ApiMock.config.getSignatureType(), SignatureType.QueryString); + } + + @Test(expected = IllegalArgumentException.class) + public void shouldNotAcceptNullAsCallback() { + builder.provider(ApiMock.class).apiKey("key").apiSecret("secret").callback(null).build(); + } + + @Test + public void shouldAcceptAnScope() { + builder.provider(ApiMock.class).apiKey("key").apiSecret("secret").scope("rss-api").build(); + assertEquals(ApiMock.config.getApiKey(), "key"); + assertEquals(ApiMock.config.getApiSecret(), "secret"); + assertEquals(ApiMock.config.getScope(), "rss-api"); + } + + public static class ApiMock implements Api { + + public static OAuthConfig config; + + public OAuthService createService(OAuthConfig config) { + ApiMock.config = config; + return null; + } + } +} 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 new file mode 100644 index 000000000..3d39eff3f --- /dev/null +++ b/scribejava-core/src/test/java/com/github/scribejava/core/extractors/BaseStringExtractorTest.java @@ -0,0 +1,102 @@ +package com.github.scribejava.core.extractors; + +import static org.junit.Assert.assertEquals; +import org.junit.Before; +import org.junit.Test; +import com.github.scribejava.core.ObjectMother; +import com.github.scribejava.core.exceptions.OAuthParametersMissingException; +import com.github.scribejava.core.model.OAuthConfig; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.oauth.OAuth20ServiceImpl; + +public class BaseStringExtractorTest { + + private BaseStringExtractorImpl extractor; + private OAuthRequest request; + private OAuthRequest requestPort80; + private OAuthRequest requestPort80v2; + private OAuthRequest requestPort8080; + private OAuthRequest requestPort443; + private OAuthRequest requestPort443v2; + + @Before + public void setup() { + request = ObjectMother.createSampleOAuthRequest(); + requestPort80 = ObjectMother.createSampleOAuthRequestPort80(); + requestPort80v2 = ObjectMother.createSampleOAuthRequestPort80v2(); + requestPort8080 = ObjectMother.createSampleOAuthRequestPort8080(); + requestPort443 = ObjectMother.createSampleOAuthRequestPort443(); + requestPort443v2 = ObjectMother.createSampleOAuthRequestPort443v2(); + extractor = new BaseStringExtractorImpl(); + } + + @Test + public void shouldExtractBaseStringFromOAuthRequest() { + String expected + = "GET&http%3A%2F%2Fexample.com&oauth_callback%3Dhttp%253A%252F%252Fexample%252Fcallback%26oauth_consumer_key%3DAS%2523%2524%255E%252A%2540%2526%26oauth_signature%3DOAuth-Signature%26oauth_timestamp%3D123456"; + String baseString = extractor.extract(request); + assertEquals(expected, baseString); + } + + @Test + public void shouldExcludePort80() { + String expected + = "GET&http%3A%2F%2Fexample.com&oauth_callback%3Dhttp%253A%252F%252Fexample%252Fcallback%26oauth_consumer_key%3DAS%2523%2524%255E%252A%2540%2526%26oauth_signature%3DOAuth-Signature%26oauth_timestamp%3D123456"; + String baseString = extractor.extract(requestPort80); + assertEquals(expected, baseString); + } + + @Test + public void shouldExcludePort80v2() { + String expected + = "GET&http%3A%2F%2Fexample.com%2Ftest&oauth_callback%3Dhttp%253A%252F%252Fexample%252Fcallback%26oauth_consumer_key%3DAS%2523%2524%255E%252A%2540%2526%26oauth_signature%3DOAuth-Signature%26oauth_timestamp%3D123456"; + String baseString = extractor.extract(requestPort80v2); + assertEquals(expected, baseString); + } + + @Test + public void shouldIncludePort8080() { + String expected + = "GET&http%3A%2F%2Fexample.com%3A8080&oauth_callback%3Dhttp%253A%252F%252Fexample%252Fcallback%26oauth_consumer_key%3DAS%2523%2524%255E%252A%2540%2526%26oauth_signature%3DOAuth-Signature%26oauth_timestamp%3D123456"; + String baseString = extractor.extract(requestPort8080); + assertEquals(expected, baseString); + } + + @Test + public void shouldExcludePort443() { + String expected + = "GET&https%3A%2F%2Fexample.com&oauth_callback%3Dhttp%253A%252F%252Fexample%252Fcallback%26oauth_consumer_key%3DAS%2523%2524%255E%252A%2540%2526%26oauth_signature%3DOAuth-Signature%26oauth_timestamp%3D123456"; + String baseString = extractor.extract(requestPort443); + assertEquals(expected, baseString); + } + + @Test + public void shouldExcludePort443v2() { + String expected + = "GET&https%3A%2F%2Fexample.com%2Ftest&oauth_callback%3Dhttp%253A%252F%252Fexample%252Fcallback%26oauth_consumer_key%3DAS%2523%2524%255E%252A%2540%2526%26oauth_signature%3DOAuth-Signature%26oauth_timestamp%3D123456"; + String baseString = extractor.extract(requestPort443v2); + assertEquals(expected, baseString); + } + + @Test(expected = IllegalArgumentException.class) + public void shouldThrowExceptionIfRquestIsNull() { + OAuthRequest nullRequest = null; + extractor.extract(nullRequest); + } + + @Test(expected = OAuthParametersMissingException.class) + public void shouldThrowExceptionIfRquestHasNoOAuthParameters() { + OAuthRequest request = new OAuthRequest(Verb.GET, "http://example.com", new OAuth20ServiceImpl(null, new OAuthConfig("test", + "test"))); + extractor.extract(request); + } + + @Test + public void shouldProperlyEncodeSpaces() { + String expected + = "GET&http%3A%2F%2Fexample.com&body%3Dthis%2520param%2520has%2520whitespace%26oauth_callback%3Dhttp%253A%252F%252Fexample%252Fcallback%26oauth_consumer_key%3DAS%2523%2524%255E%252A%2540%2526%26oauth_signature%3DOAuth-Signature%26oauth_timestamp%3D123456"; + request.addBodyParameter("body", "this param has whitespace"); + assertEquals(expected, extractor.extract(request)); + } +} 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 new file mode 100644 index 000000000..f7a88d37c --- /dev/null +++ b/scribejava-core/src/test/java/com/github/scribejava/core/extractors/HeaderExtractorTest.java @@ -0,0 +1,49 @@ +package com.github.scribejava.core.extractors; + +import static org.junit.Assert.assertEquals; +import org.junit.Before; +import org.junit.Test; +import com.github.scribejava.core.exceptions.OAuthParametersMissingException; +import com.github.scribejava.core.model.OAuthConfig; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.oauth.OAuth20ServiceImpl; +import com.github.scribejava.core.ObjectMother; + +public class HeaderExtractorTest { + + private HeaderExtractorImpl extractor; + private OAuthRequest request; + + @Before + public void setUp() { + request = ObjectMother.createSampleOAuthRequest(); + extractor = new HeaderExtractorImpl(); + } + + @Test + public void shouldExtractStandardHeader() { + final String header = extractor.extract(request); + try { + assertEquals("OAuth oauth_callback=\"http%3A%2F%2Fexample%2Fcallback\", " + "oauth_signature=\"OAuth-Signature\", " + + "oauth_consumer_key=\"AS%23%24%5E%2A%40%26\", " + "oauth_timestamp=\"123456\"", header); + } catch (AssertionError ae) { + //maybe this is OpenJDK 8? Different order of elements in HashMap while iterating'em. + assertEquals("OAuth " + "oauth_signature=\"OAuth-Signature\", " + "oauth_callback=\"http%3A%2F%2Fexample%2Fcallback\", " + + "oauth_consumer_key=\"AS%23%24%5E%2A%40%26\", " + "oauth_timestamp=\"123456\"", header); + } + } + + @Test(expected = IllegalArgumentException.class) + public void shouldExceptionIfRequestIsNull() { + final OAuthRequest nullRequest = null; + extractor.extract(nullRequest); + } + + @Test(expected = OAuthParametersMissingException.class) + public void shouldExceptionIfRequestHasNoOAuthParams() { + final OAuthRequest emptyRequest = new OAuthRequest(Verb.GET, "http://example.com", new OAuth20ServiceImpl(null, new OAuthConfig( + "test", "test"))); + extractor.extract(emptyRequest); + } +} diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/extractors/JsonTokenExtractorTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/extractors/JsonTokenExtractorTest.java new file mode 100644 index 000000000..f5a278e82 --- /dev/null +++ b/scribejava-core/src/test/java/com/github/scribejava/core/extractors/JsonTokenExtractorTest.java @@ -0,0 +1,27 @@ +package com.github.scribejava.core.extractors; + +import static org.junit.Assert.assertEquals; +import org.junit.Test; +import com.github.scribejava.core.model.Token; + +public class JsonTokenExtractorTest { + + private String response = "'{ \"access_token\":\"I0122HHJKLEM21F3WLPYHDKGKZULAUO4SGMV3ABKFTDT3T3X\"}'"; + private JsonTokenExtractor extractor = new JsonTokenExtractor(); + + @Test + public void shouldParseResponse() { + Token token = extractor.extract(response); + assertEquals(token.getToken(), "I0122HHJKLEM21F3WLPYHDKGKZULAUO4SGMV3ABKFTDT3T3X"); + } + + @Test(expected = IllegalArgumentException.class) + public void shouldThrowExceptionIfForNullParameters() { + extractor.extract(null); + } + + @Test(expected = IllegalArgumentException.class) + public void shouldThrowExceptionIfForEmptyStrings() { + extractor.extract(""); + } +} diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/extractors/TokenExtractor20Test.java b/scribejava-core/src/test/java/com/github/scribejava/core/extractors/TokenExtractor20Test.java new file mode 100644 index 000000000..66af64384 --- /dev/null +++ b/scribejava-core/src/test/java/com/github/scribejava/core/extractors/TokenExtractor20Test.java @@ -0,0 +1,59 @@ +package com.github.scribejava.core.extractors; + +import static org.junit.Assert.assertEquals; +import org.junit.Before; +import org.junit.Test; +import com.github.scribejava.core.exceptions.OAuthException; +import com.github.scribejava.core.model.Token; + +public class TokenExtractor20Test { + + private TokenExtractor20Impl extractor; + + @Before + public void setup() { + extractor = new TokenExtractor20Impl(); + } + + @Test + public void shouldExtractTokenFromOAuthStandardResponse() { + String response = "access_token=166942940015970|2.2ltzWXYNDjCtg5ZDVVJJeg__.3600.1295816400-548517159|RsXNdKrpxg8L6QNLWcs2TVTmcaE"; + Token extracted = extractor.extract(response); + assertEquals("166942940015970|2.2ltzWXYNDjCtg5ZDVVJJeg__.3600.1295816400-548517159|RsXNdKrpxg8L6QNLWcs2TVTmcaE", extracted.getToken()); + assertEquals("", extracted.getSecret()); + } + + @Test + public void shouldExtractTokenFromResponseWithExpiresParam() { + String response = "access_token=166942940015970|2.2ltzWXYNDjCtg5ZDVVJJeg__.3600.1295816400-548517159|RsXNdKrpxg8L6QNLWcs2TVTmcaE&expires=5108"; + Token extracted = extractor.extract(response); + assertEquals("166942940015970|2.2ltzWXYNDjCtg5ZDVVJJeg__.3600.1295816400-548517159|RsXNdKrpxg8L6QNLWcs2TVTmcaE", extracted.getToken()); + assertEquals("", extracted.getSecret()); + } + + @Test + public void shouldExtractTokenFromResponseWithManyParameters() { + String response = "access_token=foo1234&other_stuff=yeah_we_have_this_too&number=42"; + Token extracted = extractor.extract(response); + assertEquals("foo1234", extracted.getToken()); + assertEquals("", extracted.getSecret()); + } + + @Test(expected = OAuthException.class) + public void shouldThrowExceptionIfTokenIsAbsent() { + String response = "&expires=5108"; + extractor.extract(response); + } + + @Test(expected = IllegalArgumentException.class) + public void shouldThrowExceptionIfResponseIsNull() { + String response = null; + extractor.extract(response); + } + + @Test(expected = IllegalArgumentException.class) + public void shouldThrowExceptionIfResponseIsEmptyString() { + String response = ""; + extractor.extract(response); + } +} diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/extractors/TokenExtractorTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/extractors/TokenExtractorTest.java new file mode 100644 index 000000000..ab3cab9a2 --- /dev/null +++ b/scribejava-core/src/test/java/com/github/scribejava/core/extractors/TokenExtractorTest.java @@ -0,0 +1,73 @@ +package com.github.scribejava.core.extractors; + +import static org.junit.Assert.assertEquals; +import org.junit.Before; +import org.junit.Test; +import com.github.scribejava.core.exceptions.OAuthException; +import com.github.scribejava.core.model.Token; + +public class TokenExtractorTest { + + private TokenExtractorImpl extractor; + + @Before + public void setup() { + extractor = new TokenExtractorImpl(); + } + + @Test + public void shouldExtractTokenFromOAuthStandardResponse() { + String response = "oauth_token=hh5s93j4hdidpola&oauth_token_secret=hdhd0244k9j7ao03"; + Token extracted = extractor.extract(response); + assertEquals("hh5s93j4hdidpola", extracted.getToken()); + assertEquals("hdhd0244k9j7ao03", extracted.getSecret()); + } + + @Test + public void shouldExtractTokenFromInvertedOAuthStandardResponse() { + String response = "oauth_token_secret=hh5s93j4hdidpola&oauth_token=hdhd0244k9j7ao03"; + Token extracted = extractor.extract(response); + assertEquals("hh5s93j4hdidpola", extracted.getSecret()); + assertEquals("hdhd0244k9j7ao03", extracted.getToken()); + } + + @Test + public void shouldExtractTokenFromResponseWithCallbackConfirmed() { + String response = "oauth_token=hh5s93j4hdidpola&oauth_token_secret=hdhd0244k9j7ao03&callback_confirmed=true"; + Token extracted = extractor.extract(response); + assertEquals("hh5s93j4hdidpola", extracted.getToken()); + assertEquals("hdhd0244k9j7ao03", extracted.getSecret()); + } + + @Test + public void shouldExtractTokenWithEmptySecret() { + String response = "oauth_token=hh5s93j4hdidpola&oauth_token_secret="; + Token extracted = extractor.extract(response); + assertEquals("hh5s93j4hdidpola", extracted.getToken()); + assertEquals("", extracted.getSecret()); + } + + @Test(expected = OAuthException.class) + public void shouldThrowExceptionIfTokenIsAbsent() { + String response = "oauth_secret=hh5s93j4hdidpola&callback_confirmed=true"; + extractor.extract(response); + } + + @Test(expected = OAuthException.class) + public void shouldThrowExceptionIfSecretIsAbsent() { + String response = "oauth_token=hh5s93j4hdidpola&callback_confirmed=true"; + extractor.extract(response); + } + + @Test(expected = IllegalArgumentException.class) + public void shouldThrowExceptionIfResponseIsNull() { + String response = null; + extractor.extract(response); + } + + @Test(expected = IllegalArgumentException.class) + public void shouldThrowExceptionIfResponseIsEmptyString() { + String response = ""; + extractor.extract(response); + } +} diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/model/ConnectionStub.java b/scribejava-core/src/test/java/com/github/scribejava/core/model/ConnectionStub.java new file mode 100644 index 000000000..107818ad1 --- /dev/null +++ b/scribejava-core/src/test/java/com/github/scribejava/core/model/ConnectionStub.java @@ -0,0 +1,80 @@ +package com.github.scribejava.core.model; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.HttpURLConnection; +import java.net.URL; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class ConnectionStub extends HttpURLConnection { + + private Map headers = new HashMap(); + private Map> responseHeaders = new HashMap>(); + private int inputStreamCalled = 0; + + public ConnectionStub() throws Exception { + super(new URL("http://example.com")); + } + + @Override + public void setRequestProperty(String key, String value) { + headers.put(key, value); + } + + @Override + public String getRequestProperty(String s) { + return headers.get(s); + } + + public Map getHeaders() { + return headers; + } + + @Override + public int getResponseCode() throws IOException { + return 200; + } + + @Override + public InputStream getInputStream() throws IOException { + inputStreamCalled++; + return new ByteArrayInputStream("contents".getBytes()); + } + + public int getTimesCalledInpuStream() { + return inputStreamCalled; + } + + @Override + public OutputStream getOutputStream() throws IOException { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + baos.write("contents".getBytes()); + return baos; + } + + @Override + public Map> getHeaderFields() { + return responseHeaders; + } + + public void addResponseHeader(String key, String value) { + responseHeaders.put(key, Arrays.asList(value)); + } + + public void connect() throws IOException { + } + + public void disconnect() { + } + + public boolean usingProxy() { + return false; + } + +} diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/model/ForceTypeOfHttpRequestTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/model/ForceTypeOfHttpRequestTest.java new file mode 100644 index 000000000..41e65dad0 --- /dev/null +++ b/scribejava-core/src/test/java/com/github/scribejava/core/model/ForceTypeOfHttpRequestTest.java @@ -0,0 +1,46 @@ +package com.github.scribejava.core.model; + +import java.util.concurrent.ExecutionException; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import com.github.scribejava.core.exceptions.OAuthException; +import com.github.scribejava.core.oauth.OAuth20ServiceImpl; +import com.github.scribejava.core.oauth.OAuthService; + +public class ForceTypeOfHttpRequestTest { + + private ConnectionStub connection; + private OAuthRequest request; + private OAuthRequestAsync requestAsync; + private OAuthService oAuthService; + + @Rule + public ExpectedException expectedException = ExpectedException.none(); + + @Before + public void setup() throws Exception { + connection = new ConnectionStub(); + ScribeJavaConfig.setForceTypeOfHttpRequests(ForceTypeOfHttpRequest.NONE); + oAuthService = new OAuth20ServiceImpl(null, new OAuthConfig("test", "test")); + request = new OAuthRequest(Verb.GET, "http://example.com?qsparam=value&other+param=value+with+spaces", oAuthService); + requestAsync = new OAuthRequestAsync(Verb.GET, "http://example.com?qsparam=value&other+param=value+with+spaces", oAuthService); + } + + @Test + public void shouldNotSendSyncWithForceParameter() { + expectedException.expect(OAuthException.class); + expectedException.expectMessage("Cannot use sync operations, only async"); + ScribeJavaConfig.setForceTypeOfHttpRequests(ForceTypeOfHttpRequest.FORCE_ASYNC_ONLY_HTTP_REQUESTS); + request.send(); + } + + @Test + public void shouldNotSendAsyncWithForceParameter() throws ExecutionException, InterruptedException { + expectedException.expect(OAuthException.class); + expectedException.expectMessage("Cannot use async operations, only sync"); + ScribeJavaConfig.setForceTypeOfHttpRequests(ForceTypeOfHttpRequest.FORCE_SYNC_ONLY_HTTP_REQUESTS); + requestAsync.sendAsync(null).get(); + } +} 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 new file mode 100644 index 000000000..2c8fefbfb --- /dev/null +++ b/scribejava-core/src/test/java/com/github/scribejava/core/model/OAuthRequestTest.java @@ -0,0 +1,32 @@ +package com.github.scribejava.core.model; + +import static org.junit.Assert.assertEquals; +import org.junit.Before; +import org.junit.Test; +import com.github.scribejava.core.oauth.OAuth20ServiceImpl; + +public class OAuthRequestTest { + + private OAuthRequest request; + + @Before + public void setup() { + request = new OAuthRequest(Verb.GET, "http://example.com", new OAuth20ServiceImpl(null, new OAuthConfig("test", "test"))); + } + + @Test + public void shouldAddOAuthParamters() { + request.addOAuthParameter(OAuthConstants.TOKEN, "token"); + request.addOAuthParameter(OAuthConstants.NONCE, "nonce"); + request.addOAuthParameter(OAuthConstants.TIMESTAMP, "ts"); + request.addOAuthParameter(OAuthConstants.SCOPE, "feeds"); + request.addOAuthParameter(OAuthConstants.REALM, "some-realm"); + + assertEquals(5, request.getOauthParameters().size()); + } + + @Test(expected = IllegalArgumentException.class) + public void shouldThrowExceptionIfParameterIsNotOAuth() { + request.addOAuthParameter("otherParam", "value"); + } +} 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 new file mode 100644 index 000000000..1f7ebdb6b --- /dev/null +++ b/scribejava-core/src/test/java/com/github/scribejava/core/model/ParameterListTest.java @@ -0,0 +1,82 @@ +package com.github.scribejava.core.model; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.assertNotSame; + +/** + * @author: Pablo Fernandez + */ +public class ParameterListTest { + + private ParameterList params; + + @Before + public void setup() { + this.params = new ParameterList(); + } + + @Test(expected = IllegalArgumentException.class) + public void shouldThrowExceptionWhenAppendingNullMapToQuerystring() { + String url = null; + params.appendTo(url); + } + + @Test + public void shouldAppendNothingToQuerystringIfGivenEmptyMap() { + String url = "http://www.example.com"; + Assert.assertEquals(url, params.appendTo(url)); + } + + @Test + public void shouldAppendParametersToSimpleUrl() { + String url = "http://www.example.com"; + String expectedUrl = "http://www.example.com?param1=value1¶m2=value%20with%20spaces"; + + params.add("param1", "value1"); + params.add("param2", "value with spaces"); + + url = params.appendTo(url); + Assert.assertEquals(url, expectedUrl); + } + + @Test + public void shouldAppendParametersToUrlWithQuerystring() { + String url = "http://www.example.com?already=present"; + String expectedUrl = "http://www.example.com?already=present¶m1=value1¶m2=value%20with%20spaces"; + + params.add("param1", "value1"); + params.add("param2", "value with spaces"); + + url = params.appendTo(url); + Assert.assertEquals(url, expectedUrl); + } + + @Test + public void shouldProperlySortParameters() { + params.add("param1", "v1"); + params.add("param6", "v2"); + params.add("a_param", "v3"); + params.add("param2", "v4"); + Assert.assertEquals("a_param=v3¶m1=v1¶m2=v4¶m6=v2", params.sort().asFormUrlEncodedString()); + } + + @Test + public void shouldProperlySortParametersWithTheSameName() { + params.add("param1", "v1"); + params.add("param6", "v2"); + params.add("a_param", "v3"); + params.add("param1", "v4"); + Assert.assertEquals("a_param=v3¶m1=v1¶m1=v4¶m6=v2", params.sort().asFormUrlEncodedString()); + } + + @Test + public void shouldNotModifyTheOriginalParameterList() { + params.add("param1", "v1"); + params.add("param6", "v2"); + + assertNotSame(params, params.sort()); + } +} diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/model/RequestTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/model/RequestTest.java new file mode 100644 index 000000000..841601842 --- /dev/null +++ b/scribejava-core/src/test/java/com/github/scribejava/core/model/RequestTest.java @@ -0,0 +1,120 @@ +package com.github.scribejava.core.model; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import org.junit.Before; +import org.junit.Test; +import com.github.scribejava.core.oauth.OAuth20ServiceImpl; +import com.github.scribejava.core.oauth.OAuthService; + +public class RequestTest { + + private OAuthRequest getRequest; + private OAuthRequest postRequest; + private ConnectionStub connection; + private OAuthService oAuthService; + + @Before + public void setup() throws Exception { + connection = new ConnectionStub(); + oAuthService = new OAuth20ServiceImpl(null, new OAuthConfig("test", "test")); + postRequest = new OAuthRequest(Verb.POST, "http://example.com", oAuthService); + postRequest.addBodyParameter("param", "value"); + postRequest.addBodyParameter("param with spaces", "value with spaces"); + postRequest.setConnection(connection); + getRequest = new OAuthRequest(Verb.GET, "http://example.com?qsparam=value&other+param=value+with+spaces", oAuthService); + getRequest.setConnection(connection); + } + + @Test + public void shouldSetRequestVerb() { + getRequest.send(); + assertEquals("GET", connection.getRequestMethod()); + } + + @Test + public void shouldGetQueryStringParameters() { + assertEquals(2, getRequest.getQueryStringParams().size()); + assertEquals(0, postRequest.getQueryStringParams().size()); + assertTrue(getRequest.getQueryStringParams().contains(new Parameter("qsparam", "value"))); + } + + @Test + public void shouldAddRequestHeaders() { + getRequest.addHeader("Header", "1"); + getRequest.addHeader("Header2", "2"); + getRequest.send(); + assertEquals(2, getRequest.getHeaders().size()); + assertEquals(2, connection.getHeaders().size()); + } + + @Test + public void shouldSetBodyParamsAndAddContentLength() { + assertEquals("param=value¶m%20with%20spaces=value%20with%20spaces", postRequest.getBodyContents()); + postRequest.send(); + assertTrue(connection.getHeaders().containsKey("Content-Length")); + } + + @Test + public void shouldSetPayloadAndHeaders() { + postRequest.addPayload("PAYLOAD"); + postRequest.send(); + assertEquals("PAYLOAD", postRequest.getBodyContents()); + assertTrue(connection.getHeaders().containsKey("Content-Length")); + } + + @Test + public void shouldAllowAddingQuerystringParametersAfterCreation() { + OAuthRequest request = new OAuthRequest(Verb.GET, "http://example.com?one=val", oAuthService); + request.addQuerystringParameter("two", "other val"); + request.addQuerystringParameter("more", "params"); + assertEquals(3, request.getQueryStringParams().size()); + } + + @Test + public void shouldReturnTheCompleteUrl() { + OAuthRequest request = new OAuthRequest(Verb.GET, "http://example.com?one=val", oAuthService); + request.addQuerystringParameter("two", "other val"); + request.addQuerystringParameter("more", "params"); + assertEquals("http://example.com?one=val&two=other%20val&more=params", request.getCompleteUrl()); + } + + @Test + public void shouldHandleQueryStringSpaceEncodingProperly() { + assertTrue(getRequest.getQueryStringParams().contains(new Parameter("other param", "value with spaces"))); + } + + @Test + public void shouldAutomaticallyAddContentTypeForPostRequestsWithBytePayload() { + postRequest.addPayload("PAYLOAD".getBytes()); + postRequest.send(); + assertEquals(OAuthRequest.DEFAULT_CONTENT_TYPE, connection.getHeaders().get("Content-Type")); + } + + @Test + public void shouldAutomaticallyAddContentTypeForPostRequestsWithStringPayload() { + postRequest.addPayload("PAYLOAD"); + postRequest.send(); + assertEquals(OAuthRequest.DEFAULT_CONTENT_TYPE, connection.getHeaders().get("Content-Type")); + } + + @Test + public void shouldAutomaticallyAddContentTypeForPostRequestsWithBodyParameters() { + postRequest.send(); + assertEquals(OAuthRequest.DEFAULT_CONTENT_TYPE, connection.getHeaders().get("Content-Type")); + } + + @Test + public void shouldBeAbleToOverrideItsContentType() { + postRequest.addHeader("Content-Type", "my-content-type"); + postRequest.send(); + assertEquals("my-content-type", connection.getHeaders().get("Content-Type")); + } + + @Test + public void shouldNotAddContentTypeForGetRequests() { + getRequest.send(); + assertFalse(connection.getHeaders().containsKey("Content-Type")); + } +} diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/model/ResponseTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/model/ResponseTest.java new file mode 100644 index 000000000..252a67605 --- /dev/null +++ b/scribejava-core/src/test/java/com/github/scribejava/core/model/ResponseTest.java @@ -0,0 +1,66 @@ +package com.github.scribejava.core.model; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import static org.junit.Assert.assertEquals; +import org.junit.Before; +import org.junit.Test; + +public class ResponseTest { + + private Response response; + private ConnectionStub connection; + + @Before + public void setup() throws Exception { + connection = new ConnectionStub(); + connection.addResponseHeader("one", "one"); + connection.addResponseHeader("two", "two"); + response = new Response(connection); + } + + @Test + public void shouldPopulateResponseHeaders() { + assertEquals(2, response.getHeaders().size()); + assertEquals("one", response.getHeader("one")); + } + + @Test + public void shouldParseBodyContents() { + assertEquals("contents", response.getBody()); + assertEquals(1, connection.getTimesCalledInpuStream()); + } + + @Test + public void shouldParseBodyContentsOnlyOnce() { + assertEquals("contents", response.getBody()); + assertEquals("contents", response.getBody()); + assertEquals("contents", response.getBody()); + assertEquals(1, connection.getTimesCalledInpuStream()); + } + + @Test + public void shouldHandleAConnectionWithErrors() throws Exception { + Response errResponse = new Response(new FaultyConnection()); + assertEquals(400, errResponse.getCode()); + assertEquals("errors", errResponse.getBody()); + } + + private static class FaultyConnection extends ConnectionStub { + + public FaultyConnection() throws Exception { + super(); + } + + @Override + public InputStream getErrorStream() { + return new ByteArrayInputStream("errors".getBytes()); + } + + @Override + public int getResponseCode() throws IOException { + return 400; + } + } +} diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/model/TokenTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/model/TokenTest.java new file mode 100644 index 000000000..6ba6ff0d3 --- /dev/null +++ b/scribejava-core/src/test/java/com/github/scribejava/core/model/TokenTest.java @@ -0,0 +1,50 @@ +package com.github.scribejava.core.model; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotSame; +import org.junit.Test; + +public class TokenTest { + + @Test + public void shouldTestEqualityBasedOnTokenAndSecret() { + final Token expected = new Token("access", "secret"); + final Token actual = new Token("access", "secret"); + + assertEquals(expected, actual); + assertEquals(actual, actual); + } + + @Test + public void shouldNotDependOnRawString() { + final Token expected = new Token("access", "secret", "raw_string"); + final Token actual = new Token("access", "secret", "different_raw_string"); + + assertEquals(expected, actual); + } + + @Test + public void shouldReturnSameHashCodeForEqualObjects() { + final Token expected = new Token("access", "secret"); + final Token actual = new Token("access", "secret"); + + assertEquals(expected.hashCode(), actual.hashCode()); + } + + @Test + public void shouldNotBeEqualToNullOrOtherObjects() { + final Token expected = new Token("access", "secret", "response"); + + assertNotSame(expected, null); + assertNotSame(expected, new Object()); + } + + @Test + public void shouldReturnUrlParam() throws Exception { + Token actual = new Token("acccess", "secret", "user_id=3107154759&screen_name=someuser&empty=&="); + assertEquals("someuser", actual.getParameter("screen_name")); + assertEquals("3107154759", actual.getParameter("user_id")); + assertEquals(null, actual.getParameter("empty")); + assertEquals(null, actual.getParameter(null)); + } +} 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 new file mode 100644 index 000000000..12cf01313 --- /dev/null +++ b/scribejava-core/src/test/java/com/github/scribejava/core/services/HMACSha1SignatureServiceTest.java @@ -0,0 +1,51 @@ +package com.github.scribejava.core.services; + +import static org.junit.Assert.assertEquals; +import org.junit.Before; +import org.junit.Test; +import com.github.scribejava.core.exceptions.OAuthException; + +public class HMACSha1SignatureServiceTest { + + private HMACSha1SignatureService service; + + @Before + public void setup() { + service = new HMACSha1SignatureService(); + } + + @Test + public void shouldReturnSignatureMethodString() { + String expected = "HMAC-SHA1"; + assertEquals(expected, service.getSignatureMethod()); + } + + @Test + public void shouldReturnSignature() { + String apiSecret = "api secret"; + String tokenSecret = "token secret"; + String baseString = "base string"; + String signature = "uGymw2KHOTWI699YEaoi5xyLT50="; + assertEquals(signature, service.getSignature(baseString, apiSecret, tokenSecret)); + } + + @Test(expected = OAuthException.class) + public void shouldThrowExceptionIfBaseStringIsNull() { + service.getSignature(null, "apiSecret", "tokenSecret"); + } + + @Test(expected = OAuthException.class) + public void shouldThrowExceptionIfBaseStringIsEmpty() { + service.getSignature(" ", "apiSecret", "tokenSecret"); + } + + @Test(expected = OAuthException.class) + public void shouldThrowExceptionIfApiSecretIsNull() { + service.getSignature("base string", null, "tokenSecret"); + } + + @Test(expected = OAuthException.class) + public void shouldThrowExceptionIfApiSecretIsEmpty() { + service.getSignature("base string", " ", "tokenSecret"); + } +} 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 new file mode 100644 index 000000000..f5e4d65ec --- /dev/null +++ b/scribejava-core/src/test/java/com/github/scribejava/core/services/RSASha1SignatureServiceTest.java @@ -0,0 +1,59 @@ +package com.github.scribejava.core.services; + +import java.security.KeyFactory; +import java.security.PrivateKey; +import java.security.spec.PKCS8EncodedKeySpec; +import javax.xml.bind.DatatypeConverter; +import static org.junit.Assert.assertEquals; +import org.junit.Test; + +public class RSASha1SignatureServiceTest { + + RSASha1SignatureService service = new RSASha1SignatureService(getPrivateKey()); + + @Test + public void shouldReturnSignatureMethodString() { + String expected = "RSA-SHA1"; + assertEquals(expected, service.getSignatureMethod()); + } + + @Test + public void shouldReturnSignature() { + String apiSecret = "api secret"; + String tokenSecret = "token secret"; + String baseString = "base string"; + String signature + = "LUNRzQAlpdNyM9mLXm96Va6g/qVNnEAb7p7K1KM0g8IopOFQJPoOO7cvppgt7w3QyhijWJnCmvqXaaIAGrqvdyr3fIzBULh8D/iZQUNLMi08GCOA34P81XBvsc7A5uJjPDsGhJg2MzoVJ8nWJhU/lMMk4c92S1WGskeoDofRwpo="; + assertEquals(signature, service.getSignature(baseString, apiSecret, tokenSecret)); + } + + /** + * Created primary key using openssl. + * + * openssl req -x509 -nodes -days 365 -newkey rsa:1024 -sha1 -subj '/C=GB/ST=/L=Manchester/CN=www.example.com' -keyout myrsakey.pem -out + * /tmp/myrsacert.pem openssl pkcs8 -in myrsakey.pem -topk8 -nocrypt -out myrsakey.pk8 + */ + private static PrivateKey getPrivateKey() { + String str = "MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAMPQ5BCMxlUq2TYy\n" + + "iRIoEUsz6HGTJhHuasS2nx1Se4Co3lxwxyubVdFj8AuhHNJSmJvjlpbTsGOjLZpr\n" + + "HyDEDdJmf1Fensh1MhUnBZ4a7uLrZrKzFHHJdamX9pxapB89vLeHlCot9hVXdrZH\n" + + "nNtg6FdmRKH/8gbs8iDyIayFvzYDAgMBAAECgYA+c9MpTBy9cQsR9BAvkEPjvkx2\n" + + "XL4ZnfbDgpNA4Nuu7yzsQrPjPomiXMNkkiAFHH67yVxwAlgRjyuuQlgNNTpKvyQt\n" + + "XcHxffnU0820VmE23M+L7jg2TlB3+rUnEDmDvCoyjlwGDR6lNb7t7Fgg2iR+iaov\n" + + "0iVzz+l9w0slRlyGsQJBAPWXW2m3NmFgqfDxtw8fsKC2y8o17/cnPjozRGtWb8LQ\n" + + "g3VCb8kbOFHOYNGazq3M7+wD1qILF2h/HecgK9eQrZ0CQQDMHXoJMfKKbrFrTKgE\n" + + "zyggO1gtuT5OXYeFewMEb5AbDI2FfSc2YP7SHij8iQ2HdukBrbTmi6qxh3HmIR58\n" + + "I/AfAkEA0Y9vr0tombsUB8cZv0v5OYoBZvCTbMANtzfb4AOHpiKqqbohDOevLQ7/\n" + + "SpvgVCmVaDz2PptcRAyEBZ5MCssneQJAB2pmvaDH7Ambfod5bztLfOhLCtY5EkXJ\n" + + "n6rZcDbRaHorRhdG7m3VtDKOUKZ2DF7glkQGV33phKukErVPUzlHBwJAScD9TqaG\n" + + "wJ3juUsVtujV23SnH43iMggXT7m82STpPGam1hPfmqu2Z0niePFo927ogQ7H1EMJ\n" + "UHgqXmuvk2X/Ww=="; + + try { + KeyFactory fac = KeyFactory.getInstance("RSA"); + PKCS8EncodedKeySpec privKeySpec = new PKCS8EncodedKeySpec(DatatypeConverter.parseBase64Binary(str)); + return fac.generatePrivate(privKeySpec); + } catch (Exception e) { + throw new RuntimeException(e); + } + } +} diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/services/TimestampServiceTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/services/TimestampServiceTest.java new file mode 100644 index 000000000..a9faeab4f --- /dev/null +++ b/scribejava-core/src/test/java/com/github/scribejava/core/services/TimestampServiceTest.java @@ -0,0 +1,43 @@ +package com.github.scribejava.core.services; + +import static org.junit.Assert.assertEquals; +import org.junit.Before; +import org.junit.Test; + +public class TimestampServiceTest { + + private TimestampServiceImpl service; + private TimestampServiceImpl.Timer timerStub; + + @Before + public void setup() { + service = new TimestampServiceImpl(); + timerStub = new TimerStub(); + service.setTimer(timerStub); + } + + @Test + public void shouldReturnTimestampInSeconds() { + String expected = "1000"; + assertEquals(expected, service.getTimestampInSeconds()); + } + + @Test + public void shouldReturnNonce() { + String expected = "1042"; + assertEquals(expected, service.getNonce()); + } + + private static class TimerStub extends TimestampServiceImpl.Timer { + + @Override + public Long getMilis() { + return 1000000L; + } + + @Override + public Integer getRandomInteger() { + return 42; + } + } +} diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/utils/MapUtilsTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/utils/MapUtilsTest.java new file mode 100644 index 000000000..cf5e37bc8 --- /dev/null +++ b/scribejava-core/src/test/java/com/github/scribejava/core/utils/MapUtilsTest.java @@ -0,0 +1,33 @@ +package com.github.scribejava.core.utils; + +import java.util.HashMap; +import java.util.Map; +import org.junit.Assert; +import org.junit.Test; + +/** + * @author: Pablo Fernandez + */ +public class MapUtilsTest { + + @Test + public void shouldPrettyPrintMap() { + Map map = new HashMap(); + map.put(1, "one"); + map.put(2, "two"); + map.put(3, "three"); + map.put(4, "four"); + Assert.assertEquals("{ 1 -> one , 2 -> two , 3 -> three , 4 -> four }", MapUtils.toString(map)); + } + + @Test + public void shouldHandleEmptyMap() { + Map map = new HashMap(); + Assert.assertEquals("{}", MapUtils.toString(map)); + } + + @Test + public void shouldHandleNullInputs() { + Assert.assertEquals("", MapUtils.toString(null)); + } +} 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 new file mode 100644 index 000000000..196dd222b --- /dev/null +++ b/scribejava-core/src/test/java/com/github/scribejava/core/utils/OAuthEncoderTest.java @@ -0,0 +1,63 @@ +package com.github.scribejava.core.utils; + +import org.junit.Assert; +import static org.junit.Assert.assertEquals; +import org.junit.Test; + +/** + * @author: Pablo Fernandez + */ +public class OAuthEncoderTest { + + @Test + public void shouldPercentEncodeString() { + String plain = "this is a test &^"; + String encoded = "this%20is%20a%20test%20%26%5E"; + assertEquals(encoded, OAuthEncoder.encode(plain)); + } + + @Test + public void shouldFormURLDecodeString() { + String encoded = "this+is+a+test+%26%5E"; + String plain = "this is a test &^"; + assertEquals(plain, OAuthEncoder.decode(encoded)); + } + + @Test + public void shouldPercentEncodeAllSpecialCharacters() { + String plain = "!*'();:@&=+$,/?#[]"; + String encoded = "%21%2A%27%28%29%3B%3A%40%26%3D%2B%24%2C%2F%3F%23%5B%5D"; + assertEquals(encoded, OAuthEncoder.encode(plain)); + assertEquals(plain, OAuthEncoder.decode(encoded)); + } + + @Test + public void shouldNotPercentEncodeReservedCharacters() { + String plain = "abcde123456-._~"; + String encoded = plain; + assertEquals(encoded, OAuthEncoder.encode(plain)); + } + + @Test(expected = IllegalArgumentException.class) + public void shouldThrowExceptionIfStringToEncodeIsNull() { + String toEncode = null; + OAuthEncoder.encode(toEncode); + } + + @Test(expected = IllegalArgumentException.class) + public void shouldThrowExceptionIfStringToDecodeIsNull() { + String toDecode = null; + OAuthEncoder.decode(toDecode); + } + + @Test + public void shouldPercentEncodeCorrectlyTwitterCodingExamples() { + // These tests are part of the Twitter dev examples here -> https://dev.twitter.com/docs/auth/percent-encoding-parameters + String sources[] = {"Ladies + Gentlemen", "An encoded string!", "Dogs, Cats & Mice"}; + String encoded[] = {"Ladies%20%2B%20Gentlemen", "An%20encoded%20string%21", "Dogs%2C%20Cats%20%26%20Mice"}; + + for (int i = 0; i < sources.length; i++) { + Assert.assertEquals(encoded[i], OAuthEncoder.encode(sources[i])); + } + } +} 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 new file mode 100644 index 000000000..76d64c5ba --- /dev/null +++ b/scribejava-core/src/test/java/com/github/scribejava/core/utils/PreconditionsTest.java @@ -0,0 +1,73 @@ +package com.github.scribejava.core.utils; + +import org.junit.Test; + +public class PreconditionsTest { + + private static final String ERROR_MSG = ""; + + @Test(expected = IllegalArgumentException.class) + public void shouldThrowExceptionForNullObjects() { + Preconditions.checkNotNull(null, ERROR_MSG); + } + + @Test(expected = IllegalArgumentException.class) + public void shouldThrowExceptionForNullStrings() { + Preconditions.checkEmptyString(null, ERROR_MSG); + } + + @Test(expected = IllegalArgumentException.class) + public void shouldThrowExceptionForEmptyStrings() { + Preconditions.checkEmptyString("", ERROR_MSG); + } + + @Test(expected = IllegalArgumentException.class) + public void shouldThrowExceptionForSpacesOnlyStrings() { + Preconditions.checkEmptyString(" ", ERROR_MSG); + } + + @Test(expected = IllegalArgumentException.class) + public void shouldThrowExceptionForInvalidUrls() { + Preconditions.checkValidUrl("this/is/not/a/valid/url", ERROR_MSG); + } + + @Test(expected = IllegalArgumentException.class) + public void shouldThrowExceptionForNullUrls() { + Preconditions.checkValidUrl(null, ERROR_MSG); + } + + @Test + public void shouldAllowValidUrls() { + Preconditions.checkValidUrl("http://www.example.com", ERROR_MSG); + } + + @Test + public void shouldAllowSSLUrls() { + Preconditions.checkValidUrl("https://www.example.com", ERROR_MSG); + } + + @Test + public void shouldAllowSpecialCharsInScheme() { + Preconditions.checkValidUrl("custom+9.3-1://www.example.com", ERROR_MSG); + } + + @Test + public void shouldAllowNonStandarProtocolsForAndroid() { + Preconditions.checkValidUrl("x-url-custom://www.example.com", ERROR_MSG); + } + + @Test(expected = IllegalArgumentException.class) + public void shouldNotAllowStrangeProtocolNames() { + Preconditions.checkValidUrl("$weird*://www.example.com", ERROR_MSG); + } + + @Test(expected = IllegalArgumentException.class) + public void shouldNotAllowUnderscoreInScheme() { + Preconditions.checkValidUrl("http_custom://www.example.com", ERROR_MSG); + } + + @Test + public void shouldAllowOutOfBandAsValidCallbackValue() { + Preconditions.checkValidOAuthCallback("oob", 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 new file mode 100644 index 000000000..b83ad987a --- /dev/null +++ b/scribejava-core/src/test/java/com/github/scribejava/core/utils/StreamUtilsTest.java @@ -0,0 +1,39 @@ +package com.github.scribejava.core.utils; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; +import org.junit.Test; + +public class StreamUtilsTest { + + @Test + public void shouldCorrectlyDecodeAStream() { + String value = "expected"; + InputStream is = new ByteArrayInputStream(value.getBytes()); + String decoded = StreamUtils.getStreamContents(is); + assertEquals("expected", decoded); + } + + @Test(expected = IllegalArgumentException.class) + public void shouldFailForNullParameter() { + InputStream is = null; + StreamUtils.getStreamContents(is); + fail("Must throw exception before getting here"); + } + + @Test(expected = IllegalStateException.class) + public void shouldFailWithBrokenStream() { + // This object simulates problems with input stream. + final InputStream is = new InputStream() { + @Override + public int read() throws IOException { + throw new IOException(); + } + }; + StreamUtils.getStreamContents(is); + fail("Must throw exception before getting here"); + } +} diff --git a/src/main/config/scribe-eclipse-formatter.xml b/src/main/config/scribe-eclipse-formatter.xml deleted file mode 100644 index 8ea5bc9d5..000000000 --- a/src/main/config/scribe-eclipse-formatter.xml +++ /dev/null @@ -1,290 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/main/config/scribe-eclipse.importorder b/src/main/config/scribe-eclipse.importorder deleted file mode 100644 index 1fcaf0f22..000000000 --- a/src/main/config/scribe-eclipse.importorder +++ /dev/null @@ -1,7 +0,0 @@ -#Organize Import Order -#Tue Feb 21 20:29:55 GMT 2012 -4=java -3=javax -2=org -1=org.boncey -0=com diff --git a/src/main/java/org/scribe/builder/ServiceBuilder.java b/src/main/java/org/scribe/builder/ServiceBuilder.java deleted file mode 100644 index 27f3c8f63..000000000 --- a/src/main/java/org/scribe/builder/ServiceBuilder.java +++ /dev/null @@ -1,169 +0,0 @@ -package org.scribe.builder; - -import java.io.*; -import org.scribe.builder.api.*; -import org.scribe.exceptions.*; -import org.scribe.model.*; -import org.scribe.oauth.*; -import org.scribe.utils.*; - -/** - * Implementation of the Builder pattern, with a fluent interface that creates a - * {@link OAuthService} - * - * @author Pablo Fernandez - * - */ -public class ServiceBuilder -{ - private String apiKey; - private String apiSecret; - private String callback; - private Api api; - private String scope; - private SignatureType signatureType; - private OutputStream debugStream; - - /** - * Default constructor - */ - public ServiceBuilder() - { - this.callback = OAuthConstants.OUT_OF_BAND; - this.signatureType = SignatureType.Header; - this.debugStream = null; - } - - /** - * Configures the {@link Api} - * - * @param apiClass the class of one of the existent {@link Api}s on org.scribe.api package - * @return the {@link ServiceBuilder} instance for method chaining - */ - public ServiceBuilder provider(Class apiClass) - { - this.api = createApi(apiClass); - return this; - } - - private Api createApi(Class apiClass) - { - Preconditions.checkNotNull(apiClass, "Api class cannot be null"); - Api api; - try - { - api = apiClass.newInstance(); - } - catch(Exception e) - { - throw new OAuthException("Error while creating the Api object", e); - } - return api; - } - - /** - * Configures the {@link Api} - * - * Overloaded version. Let's you use an instance instead of a class. - * - * @param api instance of {@link Api}s - * @return the {@link ServiceBuilder} instance for method chaining - */ - public ServiceBuilder provider(Api api) - { - Preconditions.checkNotNull(api, "Api cannot be null"); - this.api = api; - return this; - } - - /** - * Adds an OAuth callback url - * - * @param callback callback url. Must be a valid url or 'oob' for out of band OAuth - * @return the {@link ServiceBuilder} instance for method chaining - */ - public ServiceBuilder callback(String callback) - { - Preconditions.checkNotNull(callback, "Callback can't be null"); - this.callback = callback; - return this; - } - - /** - * Configures the api key - * - * @param apiKey The api key for your application - * @return the {@link ServiceBuilder} instance for method chaining - */ - public ServiceBuilder apiKey(String apiKey) - { - Preconditions.checkEmptyString(apiKey, "Invalid Api key"); - this.apiKey = apiKey; - return this; - } - - /** - * Configures the api secret - * - * @param apiSecret The api secret for your application - * @return the {@link ServiceBuilder} instance for method chaining - */ - public ServiceBuilder apiSecret(String apiSecret) - { - Preconditions.checkEmptyString(apiSecret, "Invalid Api secret"); - this.apiSecret = apiSecret; - return this; - } - - /** - * Configures the OAuth scope. This is only necessary in some APIs (like Google's). - * - * @param scope The OAuth scope - * @return the {@link ServiceBuilder} instance for method chaining - */ - public ServiceBuilder scope(String scope) - { - Preconditions.checkEmptyString(scope, "Invalid OAuth scope"); - this.scope = scope; - return this; - } - - /** - * Configures the signature type, choose between header, querystring, etc. Defaults to Header - * - * @param scope The OAuth scope - * @return the {@link ServiceBuilder} instance for method chaining - */ - public ServiceBuilder signatureType(SignatureType type) - { - Preconditions.checkNotNull(type, "Signature type can't be null"); - this.signatureType = type; - return this; - } - - public ServiceBuilder debugStream(OutputStream stream) - { - Preconditions.checkNotNull(stream, "debug stream can't be null"); - this.debugStream = stream; - return this; - } - - public ServiceBuilder debug() - { - this.debugStream(System.out); - return this; - } - - /** - * Returns the fully configured {@link OAuthService} - * - * @return fully configured {@link OAuthService} - */ - public OAuthService build() - { - Preconditions.checkNotNull(api, "You must specify a valid api through the provider() method"); - Preconditions.checkEmptyString(apiKey, "You must provide an api key"); - Preconditions.checkEmptyString(apiSecret, "You must provide an api secret"); - return api.createService(new OAuthConfig(apiKey, apiSecret, callback, signatureType, scope, debugStream)); - } -} diff --git a/src/main/java/org/scribe/builder/api/AWeberApi.java b/src/main/java/org/scribe/builder/api/AWeberApi.java deleted file mode 100644 index 53ae1fc7f..000000000 --- a/src/main/java/org/scribe/builder/api/AWeberApi.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.scribe.builder.api; - -import org.scribe.model.Token; - -public class AWeberApi extends DefaultApi10a -{ - private static final String AUTHORIZE_URL = "https://auth.aweber.com/1.0/oauth/authorize?oauth_token=%s"; - private static final String REQUEST_TOKEN_ENDPOINT = "https://auth.aweber.com/1.0/oauth/request_token"; - private static final String ACCESS_TOKEN_ENDPOINT = "https://auth.aweber.com/1.0/oauth/access_token"; - - @Override - public String getAccessTokenEndpoint() - { - return ACCESS_TOKEN_ENDPOINT; - } - - @Override - public String getRequestTokenEndpoint() - { - return REQUEST_TOKEN_ENDPOINT; - } - - @Override - public String getAuthorizationUrl(Token requestToken) - { - return String.format(AUTHORIZE_URL, requestToken.getToken()); - } -} diff --git a/src/main/java/org/scribe/builder/api/Api.java b/src/main/java/org/scribe/builder/api/Api.java deleted file mode 100644 index 6664296bd..000000000 --- a/src/main/java/org/scribe/builder/api/Api.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.scribe.builder.api; - -import org.scribe.model.*; -import org.scribe.oauth.*; - -/** - * Contains all the configuration needed to instantiate a valid {@link OAuthService} - * - * @author Pablo Fernandez - * - */ -public interface Api -{ - /** - * Creates an {@link OAuthService} - * - * @param apiKey your application api key - * @param apiSecret your application api secret - * @param callback the callback url (or 'oob' for out of band OAuth) - * @param scope the OAuth scope - * - * @return fully configured {@link OAuthService} - */ - OAuthService createService(OAuthConfig config); -} diff --git a/src/main/java/org/scribe/builder/api/ConstantContactApi.java b/src/main/java/org/scribe/builder/api/ConstantContactApi.java deleted file mode 100644 index 0588bc40c..000000000 --- a/src/main/java/org/scribe/builder/api/ConstantContactApi.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.scribe.builder.api; - -import org.scribe.model.*; - -public class ConstantContactApi extends DefaultApi10a -{ - private static final String AUTHORIZE_URL = "https://oauth.constantcontact.com/ws/oauth/confirm_access?oauth_token=%s"; - - @Override - public String getAccessTokenEndpoint() - { - return "https://oauth.constantcontact.com/ws/oauth/access_token"; - } - - @Override - public String getAuthorizationUrl(Token requestToken) - { - return String.format(AUTHORIZE_URL, requestToken.getToken()); - } - - @Override - public String getRequestTokenEndpoint() - { - return "https://oauth.constantcontact.com/ws/oauth/request_token"; - } -} diff --git a/src/main/java/org/scribe/builder/api/ConstantContactApi2.java b/src/main/java/org/scribe/builder/api/ConstantContactApi2.java deleted file mode 100644 index b5e4cac27..000000000 --- a/src/main/java/org/scribe/builder/api/ConstantContactApi2.java +++ /dev/null @@ -1,55 +0,0 @@ -package org.scribe.builder.api; - -import java.util.regex.*; -import org.scribe.exceptions.*; -import org.scribe.extractors.*; -import org.scribe.model.*; -import org.scribe.utils.*; - -public class ConstantContactApi2 extends DefaultApi20 -{ - private static final String AUTHORIZE_URL = "https://oauth2.constantcontact.com/oauth2/oauth/siteowner/authorize?client_id=%s&response_type=code&redirect_uri=%s"; - - @Override - public String getAccessTokenEndpoint() - { - return "https://oauth2.constantcontact.com/oauth2/oauth/token?grant_type=authorization_code"; - } - - @Override - public String getAuthorizationUrl(OAuthConfig config) - { - return String.format(AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback())); - } - - @Override - public Verb getAccessTokenVerb() - { - return Verb.POST; - } - - @Override - public AccessTokenExtractor getAccessTokenExtractor() - { - return new AccessTokenExtractor() - { - - public Token extract(String response) - { - Preconditions.checkEmptyString(response, "Response body is incorrect. Can't extract a token from an empty string"); - - String regex = "\"access_token\"\\s*:\\s*\"([^&\"]+)\""; - Matcher matcher = Pattern.compile(regex).matcher(response); - if (matcher.find()) - { - String token = OAuthEncoder.decode(matcher.group(1)); - return new Token(token, "", response); - } - else - { - throw new OAuthException("Response body is incorrect. Can't extract a token from this: '" + response + "'", null); - } - } - }; - } -} \ No newline at end of file diff --git a/src/main/java/org/scribe/builder/api/DefaultApi10a.java b/src/main/java/org/scribe/builder/api/DefaultApi10a.java deleted file mode 100644 index 7506986b1..000000000 --- a/src/main/java/org/scribe/builder/api/DefaultApi10a.java +++ /dev/null @@ -1,141 +0,0 @@ -package org.scribe.builder.api; - -import org.scribe.extractors.*; -import org.scribe.model.*; -import org.scribe.oauth.*; -import org.scribe.services.*; - -/** - * Default implementation of the OAuth protocol, version 1.0a - * - * This class is meant to be extended by concrete implementations of the API, - * providing the endpoints and endpoint-http-verbs. - * - * If your Api adheres to the 1.0a protocol correctly, you just need to extend - * this class and define the getters for your endpoints. - * - * If your Api does something a bit different, you can override the different - * extractors or services, in order to fine-tune the process. Please read the - * javadocs of the interfaces to get an idea of what to do. - * - * @author Pablo Fernandez - * - */ -public abstract class DefaultApi10a implements Api -{ - /** - * Returns the access token extractor. - * - * @return access token extractor - */ - public AccessTokenExtractor getAccessTokenExtractor() - { - return new TokenExtractorImpl(); - } - - /** - * Returns the base string extractor. - * - * @return base string extractor - */ - public BaseStringExtractor getBaseStringExtractor() - { - return new BaseStringExtractorImpl(); - } - - /** - * Returns the header extractor. - * - * @return header extractor - */ - public HeaderExtractor getHeaderExtractor() - { - return new HeaderExtractorImpl(); - } - - /** - * Returns the request token extractor. - * - * @return request token extractor - */ - public RequestTokenExtractor getRequestTokenExtractor() - { - return new TokenExtractorImpl(); - } - - /** - * Returns the signature service. - * - * @return signature service - */ - public SignatureService getSignatureService() - { - return new HMACSha1SignatureService(); - } - - /** - * Returns the timestamp service. - * - * @return timestamp service - */ - public TimestampService getTimestampService() - { - return new TimestampServiceImpl(); - } - - /** - * Returns the verb for the access token endpoint (defaults to POST) - * - * @return access token endpoint verb - */ - public Verb getAccessTokenVerb() - { - return Verb.POST; - } - - /** - * Returns the verb for the request token endpoint (defaults to POST) - * - * @return request token endpoint verb - */ - public Verb getRequestTokenVerb() - { - return Verb.POST; - } - - /** - * Returns the URL that receives the request token requests. - * - * @return request token URL - */ - public abstract String getRequestTokenEndpoint(); - - /** - * Returns the URL that receives the access token requests. - * - * @return access token URL - */ - public abstract String getAccessTokenEndpoint(); - - /** - * Returns the URL where you should redirect your users to authenticate - * your application. - * - * @param requestToken the request token you need to authorize - * @return the URL where you should redirect your users - */ - public abstract String getAuthorizationUrl(Token requestToken); - - /** - * Returns the {@link OAuthService} for this Api - * - * @param apiKey Key - * @param apiSecret Api Secret - * @param callback OAuth callback (either URL or 'oob') - * @param scope OAuth scope (optional) - */ - public OAuthService createService(OAuthConfig config) - { - return new OAuth10aServiceImpl(this, config); - } -} diff --git a/src/main/java/org/scribe/builder/api/DefaultApi20.java b/src/main/java/org/scribe/builder/api/DefaultApi20.java deleted file mode 100644 index ffb620702..000000000 --- a/src/main/java/org/scribe/builder/api/DefaultApi20.java +++ /dev/null @@ -1,70 +0,0 @@ -package org.scribe.builder.api; - -import org.scribe.extractors.*; -import org.scribe.model.*; -import org.scribe.oauth.*; - -/** - * Default implementation of the OAuth protocol, version 2.0 (draft 11) - * - * This class is meant to be extended by concrete implementations of the API, - * providing the endpoints and endpoint-http-verbs. - * - * If your Api adheres to the 2.0 (draft 11) protocol correctly, you just need to extend - * this class and define the getters for your endpoints. - * - * If your Api does something a bit different, you can override the different - * extractors or services, in order to fine-tune the process. Please read the - * javadocs of the interfaces to get an idea of what to do. - * - * @author Diego Silveira - * - */ -public abstract class DefaultApi20 implements Api -{ - - /** - * Returns the access token extractor. - * - * @return access token extractor - */ - public AccessTokenExtractor getAccessTokenExtractor() - { - return new TokenExtractor20Impl(); - } - - /** - * Returns the verb for the access token endpoint (defaults to GET) - * - * @return access token endpoint verb - */ - public Verb getAccessTokenVerb() - { - return Verb.GET; - } - - /** - * Returns the URL that receives the access token requests. - * - * @return access token URL - */ - public abstract String getAccessTokenEndpoint(); - - /** - * Returns the URL where you should redirect your users to authenticate - * your application. - * - * @param config OAuth 2.0 configuration param object - * @return the URL where you should redirect your users - */ - public abstract String getAuthorizationUrl(OAuthConfig config); - - /** - * {@inheritDoc} - */ - public OAuthService createService(OAuthConfig config) - { - return new OAuth20ServiceImpl(this, config); - } - -} diff --git a/src/main/java/org/scribe/builder/api/DiggApi.java b/src/main/java/org/scribe/builder/api/DiggApi.java deleted file mode 100644 index b69253eb9..000000000 --- a/src/main/java/org/scribe/builder/api/DiggApi.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.scribe.builder.api; - -import org.scribe.model.*; - -public class DiggApi extends DefaultApi10a -{ - - private static final String AUTHORIZATION_URL = "http://digg.com/oauth/authorize?oauth_token=%s"; - private static final String BASE_URL = "http://services.digg.com/oauth/"; - - @Override - public String getRequestTokenEndpoint() - { - return BASE_URL + "request_token"; - } - - @Override - public String getAccessTokenEndpoint() - { - return BASE_URL + "access_token"; - } - - @Override - public String getAuthorizationUrl(Token requestToken) - { - return String.format(AUTHORIZATION_URL, requestToken.getToken()); - } - -} diff --git a/src/main/java/org/scribe/builder/api/DropBoxApi.java b/src/main/java/org/scribe/builder/api/DropBoxApi.java deleted file mode 100644 index 86f4a71a1..000000000 --- a/src/main/java/org/scribe/builder/api/DropBoxApi.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.scribe.builder.api; - -import org.scribe.model.*; - -public class DropBoxApi extends DefaultApi10a -{ - @Override - public String getAccessTokenEndpoint() - { - return "https://api.dropbox.com/1/oauth/access_token"; - } - - @Override - public String getAuthorizationUrl(Token requestToken) - { - return "https://www.dropbox.com/1/oauth/authorize?oauth_token="+requestToken.getToken(); - } - - @Override - public String getRequestTokenEndpoint() - { - return "https://api.dropbox.com/1/oauth/request_token"; - } - -} \ No newline at end of file diff --git a/src/main/java/org/scribe/builder/api/EvernoteApi.java b/src/main/java/org/scribe/builder/api/EvernoteApi.java deleted file mode 100644 index 05ee502ff..000000000 --- a/src/main/java/org/scribe/builder/api/EvernoteApi.java +++ /dev/null @@ -1,55 +0,0 @@ -package org.scribe.builder.api; - -import org.scribe.model.Token; - -/** - * OAuth API for Evernote - * - * @author Norbert Potocki - */ -public class EvernoteApi extends DefaultApi10a -{ - protected String serviceUrl() { - return "https://www.evernote.com"; - } - - @Override - public String getRequestTokenEndpoint() - { - return serviceUrl() + "/oauth"; - } - - @Override - public String getAccessTokenEndpoint() - { - return serviceUrl() + "/oauth"; - } - - @Override - public String getAuthorizationUrl(Token requestToken) - { - return String.format(serviceUrl() + "/OAuth.action?oauth_token=%s", requestToken.getToken()); - } - - /** - * Sandbox endpoint - */ - public static class Sandbox extends EvernoteApi - { - @Override - protected String serviceUrl() { - return "https://sandbox.evernote.com"; - } - } - - /** - * Yinxiang Biji endpoint - */ - public static class Yinxiang extends EvernoteApi - { - @Override - protected String serviceUrl() { - return "https://app.yinxiang.com"; - } - } -} diff --git a/src/main/java/org/scribe/builder/api/FacebookApi.java b/src/main/java/org/scribe/builder/api/FacebookApi.java deleted file mode 100644 index f2bfcd5bc..000000000 --- a/src/main/java/org/scribe/builder/api/FacebookApi.java +++ /dev/null @@ -1,33 +0,0 @@ -package org.scribe.builder.api; - -import org.scribe.model.*; - -import org.scribe.utils.*; - -public class FacebookApi extends DefaultApi20 -{ - private static final String AUTHORIZE_URL = "https://www.facebook.com/v2.0/dialog/oauth?client_id=%s&redirect_uri=%s"; - private static final String SCOPED_AUTHORIZE_URL = AUTHORIZE_URL + "&scope=%s"; - - @Override - public String getAccessTokenEndpoint() - { - return "https://graph.facebook.com/v2.0/oauth/access_token"; - } - - @Override - public String getAuthorizationUrl(OAuthConfig config) - { - Preconditions.checkValidUrl(config.getCallback(), "Must provide a valid url as callback. Facebook does not support OOB"); - - // Append scope if present - if(config.hasScope()) - { - return String.format(SCOPED_AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()), OAuthEncoder.encode(config.getScope())); - } - else - { - return String.format(AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback())); - } - } -} diff --git a/src/main/java/org/scribe/builder/api/FlickrApi.java b/src/main/java/org/scribe/builder/api/FlickrApi.java deleted file mode 100644 index 2e900de5f..000000000 --- a/src/main/java/org/scribe/builder/api/FlickrApi.java +++ /dev/null @@ -1,40 +0,0 @@ -package org.scribe.builder.api; - -import org.scribe.model.*; - -/** - * OAuth API for Flickr. - * - * @author Darren Greaves - * @see Flickr API - */ -public class FlickrApi extends DefaultApi10a -{ - - /** - * {@inheritDoc} - */ - @Override - public String getAccessTokenEndpoint() - { - return "https://www.flickr.com/services/oauth/access_token"; - } - - /** - * {@inheritDoc} - */ - @Override - public String getAuthorizationUrl(Token requestToken) - { - return "https://www.flickr.com/services/oauth/authorize?oauth_token=" + requestToken.getToken(); - } - - /** - * {@inheritDoc} - */ - @Override - public String getRequestTokenEndpoint() - { - return "https://www.flickr.com/services/oauth/request_token"; - } -} diff --git a/src/main/java/org/scribe/builder/api/Foursquare2Api.java b/src/main/java/org/scribe/builder/api/Foursquare2Api.java deleted file mode 100644 index d11def9d7..000000000 --- a/src/main/java/org/scribe/builder/api/Foursquare2Api.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.scribe.builder.api; - -import org.scribe.extractors.*; -import org.scribe.model.*; -import org.scribe.utils.*; - -public class Foursquare2Api extends DefaultApi20 -{ - private static final String AUTHORIZATION_URL = "https://foursquare.com/oauth2/authenticate?client_id=%s&response_type=code&redirect_uri=%s"; - - @Override - public String getAccessTokenEndpoint() - { - return "https://foursquare.com/oauth2/access_token?grant_type=authorization_code"; - } - - @Override - public String getAuthorizationUrl(OAuthConfig config) - { - Preconditions.checkValidUrl(config.getCallback(), "Must provide a valid url as callback. Foursquare2 does not support OOB"); - return String.format(AUTHORIZATION_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback())); - } - - @Override - public AccessTokenExtractor getAccessTokenExtractor() - { - return new JsonTokenExtractor(); - } -} diff --git a/src/main/java/org/scribe/builder/api/FoursquareApi.java b/src/main/java/org/scribe/builder/api/FoursquareApi.java deleted file mode 100644 index 060a76b76..000000000 --- a/src/main/java/org/scribe/builder/api/FoursquareApi.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.scribe.builder.api; - -import org.scribe.model.Token; - -public class FoursquareApi extends DefaultApi10a -{ - private static final String AUTHORIZATION_URL = "http://foursquare.com/oauth/authorize?oauth_token=%s"; - - @Override - public String getAccessTokenEndpoint() - { - return "http://foursquare.com/oauth/access_token"; - } - - @Override - public String getRequestTokenEndpoint() - { - return "http://foursquare.com/oauth/request_token"; - } - - @Override - public String getAuthorizationUrl(Token requestToken) - { - return String.format(AUTHORIZATION_URL, requestToken.getToken()); - } -} diff --git a/src/main/java/org/scribe/builder/api/FreelancerApi.java b/src/main/java/org/scribe/builder/api/FreelancerApi.java deleted file mode 100644 index 482e66fd1..000000000 --- a/src/main/java/org/scribe/builder/api/FreelancerApi.java +++ /dev/null @@ -1,61 +0,0 @@ -package org.scribe.builder.api; - -import org.scribe.model.*; - -public class FreelancerApi extends DefaultApi10a -{ - private static final String AUTHORIZATION_URL = "http://www.freelancer.com/users/api-token/auth.php?oauth_token=%s"; - - @Override - public String getAccessTokenEndpoint() - { - return "http://api.freelancer.com/RequestAccessToken/requestAccessToken.xml?"; - } - - @Override - public String getRequestTokenEndpoint() - { - return "http://api.freelancer.com/RequestRequestToken/requestRequestToken.xml"; - } - - @Override - public Verb getAccessTokenVerb() - { - return Verb.GET; - } - - @Override - public Verb getRequestTokenVerb() - { - return Verb.GET; - } - - @Override - public String getAuthorizationUrl(Token requestToken) - { - return String.format(AUTHORIZATION_URL, requestToken.getToken()); - } - - public static class Sandbox extends FreelancerApi - { - private static final String SANDBOX_AUTHORIZATION_URL = "http://www.sandbox.freelancer.com/users/api-token/auth.php"; - - @Override - public String getRequestTokenEndpoint() - { - return "http://api.sandbox.freelancer.com/RequestRequestToken/requestRequestToken.xml"; - } - - @Override - public String getAccessTokenEndpoint() - { - return "http://api.sandbox.freelancer.com/RequestAccessToken/requestAccessToken.xml?"; - } - - @Override - public String getAuthorizationUrl(Token requestToken) - { - return String.format(SANDBOX_AUTHORIZATION_URL + "?oauth_token=%s", requestToken.getToken()); - } - } -} diff --git a/src/main/java/org/scribe/builder/api/GetGlueApi.java b/src/main/java/org/scribe/builder/api/GetGlueApi.java deleted file mode 100644 index 3a7560f0f..000000000 --- a/src/main/java/org/scribe/builder/api/GetGlueApi.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.scribe.builder.api; - -import org.scribe.model.Token; - -public class GetGlueApi extends DefaultApi10a -{ - private static final String AUTHORIZE_URL = "http://getglue.com/oauth/authorize?oauth_token=%s"; - private static final String REQUEST_TOKEN_RESOURCE = "https://api.getglue.com/oauth/request_token"; - private static final String ACCESS_TOKEN_RESOURCE = "https://api.getglue.com/oauth/access_token"; - - @Override - public String getAccessTokenEndpoint() - { - return ACCESS_TOKEN_RESOURCE; - } - - @Override - public String getRequestTokenEndpoint() - { - return REQUEST_TOKEN_RESOURCE; - } - - @Override - public String getAuthorizationUrl(Token requestToken) - { - return String.format(AUTHORIZE_URL, requestToken.getToken()); - } - -} diff --git a/src/main/java/org/scribe/builder/api/GoogleApi.java b/src/main/java/org/scribe/builder/api/GoogleApi.java deleted file mode 100644 index 9c86e5e1a..000000000 --- a/src/main/java/org/scribe/builder/api/GoogleApi.java +++ /dev/null @@ -1,38 +0,0 @@ -package org.scribe.builder.api; - -import org.scribe.model.*; - -public class GoogleApi extends DefaultApi10a -{ - private static final String AUTHORIZATION_URL = "https://www.google.com/accounts/OAuthAuthorizeToken?oauth_token=%s"; - - @Override - public String getAccessTokenEndpoint() - { - return "https://www.google.com/accounts/OAuthGetAccessToken"; - } - - @Override - public String getRequestTokenEndpoint() - { - return "https://www.google.com/accounts/OAuthGetRequestToken"; - } - - @Override - public Verb getAccessTokenVerb() - { - return Verb.GET; - } - - @Override - public Verb getRequestTokenVerb() - { - return Verb.GET; - } - - @Override - public String getAuthorizationUrl(Token requestToken) - { - return String.format(AUTHORIZATION_URL, requestToken.getToken()); - } -} diff --git a/src/main/java/org/scribe/builder/api/ImgUrApi.java b/src/main/java/org/scribe/builder/api/ImgUrApi.java deleted file mode 100644 index 06dd6910d..000000000 --- a/src/main/java/org/scribe/builder/api/ImgUrApi.java +++ /dev/null @@ -1,32 +0,0 @@ -package org.scribe.builder.api; - -import org.scribe.model.*; - -/** - * OAuth API for ImgUr - * - * @author David Wursteisen - * @see ImgUr API - */ -public class ImgUrApi extends DefaultApi10a -{ - - @Override - public String getRequestTokenEndpoint() - { - return "https://api.imgur.com/oauth/request_token"; - } - - @Override - public String getAccessTokenEndpoint() - { - return "https://api.imgur.com/oauth/access_token"; - } - - @Override - public String getAuthorizationUrl(Token requestToken) - { - return String.format("https://api.imgur.com/oauth/authorize?oauth_token=%s", requestToken.getToken()); - } -} - diff --git a/src/main/java/org/scribe/builder/api/KaixinApi.java b/src/main/java/org/scribe/builder/api/KaixinApi.java deleted file mode 100644 index 5b0e0d5dc..000000000 --- a/src/main/java/org/scribe/builder/api/KaixinApi.java +++ /dev/null @@ -1,40 +0,0 @@ -package org.scribe.builder.api; - -import org.scribe.model.*; - -public class KaixinApi extends DefaultApi10a -{ - private static final String REQUEST_TOKEN_URL = "http://api.kaixin001.com/oauth/request_token"; - private static final String ACCESS_TOKEN_URL = "http://api.kaixin001.com/oauth/access_token"; - private static final String AUTHORIZE_URL = "http://api.kaixin001.com/oauth/authorize?oauth_token=%s"; - - @Override - public String getRequestTokenEndpoint() - { - return REQUEST_TOKEN_URL; - } - - @Override - public String getAccessTokenEndpoint() - { - return ACCESS_TOKEN_URL; - } - - @Override - public String getAuthorizationUrl(Token requestToken) - { - return String.format(AUTHORIZE_URL, requestToken.getToken()); - } - - @Override - public Verb getRequestTokenVerb() - { - return Verb.GET; - } - - @Override - public Verb getAccessTokenVerb() - { - return Verb.GET; - } -} diff --git a/src/main/java/org/scribe/builder/api/KaixinApi20.java b/src/main/java/org/scribe/builder/api/KaixinApi20.java deleted file mode 100644 index 9e27bcb33..000000000 --- a/src/main/java/org/scribe/builder/api/KaixinApi20.java +++ /dev/null @@ -1,41 +0,0 @@ -package org.scribe.builder.api; - -import org.scribe.extractors.*; -import org.scribe.model.*; -import org.scribe.utils.*; - -/** - * Kaixin(http://www.kaixin001.com/) open platform api based on OAuth 2.0. - */ -public class KaixinApi20 extends DefaultApi20 -{ - - private static final String AUTHORIZE_URL = "http://api.kaixin001.com/oauth2/authorize?client_id=%s&redirect_uri=%s&response_type=code"; - private static final String SCOPED_AUTHORIZE_URL = AUTHORIZE_URL + "&scope=%s"; - - @Override - public AccessTokenExtractor getAccessTokenExtractor() - { - return new JsonTokenExtractor(); - } - - @Override - public String getAccessTokenEndpoint() - { - return "https://api.kaixin001.com/oauth2/access_token?grant_type=authorization_code"; - } - - @Override - public String getAuthorizationUrl(OAuthConfig config) - { - // Append scope if present - if (config.hasScope()) - { - return String.format(SCOPED_AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()), OAuthEncoder.encode(config.getScope())); - } - else - { - return String.format(AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback())); - } - } -} diff --git a/src/main/java/org/scribe/builder/api/LinkedInApi.java b/src/main/java/org/scribe/builder/api/LinkedInApi.java deleted file mode 100644 index ee6becd85..000000000 --- a/src/main/java/org/scribe/builder/api/LinkedInApi.java +++ /dev/null @@ -1,57 +0,0 @@ -package org.scribe.builder.api; - -import org.scribe.model.*; -import java.util.*; - -public class LinkedInApi extends DefaultApi10a -{ - private static final String AUTHORIZE_URL = "https://api.linkedin.com/uas/oauth/authenticate?oauth_token=%s"; - private static final String REQUEST_TOKEN_URL = "https://api.linkedin.com/uas/oauth/requestToken"; - - private final Set scopes; - - public LinkedInApi() - { - scopes = Collections.emptySet(); - } - - public LinkedInApi(Set scopes) - { - this.scopes = Collections.unmodifiableSet(scopes); - } - - @Override - public String getAccessTokenEndpoint() - { - return "https://api.linkedin.com/uas/oauth/accessToken"; - } - - @Override - public String getRequestTokenEndpoint() - { - return scopes.isEmpty() ? REQUEST_TOKEN_URL : REQUEST_TOKEN_URL + "?scope=" + scopesAsString(); - } - - private String scopesAsString() - { - StringBuilder builder = new StringBuilder(); - for(String scope : scopes) - { - builder.append("+" + scope); - } - return builder.substring(1); - } - - @Override - public String getAuthorizationUrl(Token requestToken) - { - return String.format(AUTHORIZE_URL, requestToken.getToken()); - } - - public static LinkedInApi withScopes(String... scopes) - { - Set scopeSet = new HashSet(Arrays.asList(scopes)); - return new LinkedInApi(scopeSet); - } - -} diff --git a/src/main/java/org/scribe/builder/api/LiveApi.java b/src/main/java/org/scribe/builder/api/LiveApi.java deleted file mode 100644 index 125b88048..000000000 --- a/src/main/java/org/scribe/builder/api/LiveApi.java +++ /dev/null @@ -1,40 +0,0 @@ -package org.scribe.builder.api; - -import org.scribe.extractors.*; -import org.scribe.model.*; -import org.scribe.utils.*; - -public class LiveApi extends DefaultApi20 -{ - - private static final String AUTHORIZE_URL = "https://login.live.com/oauth20_authorize.srf?client_id=%s&redirect_uri=%s&response_type=code"; - private static final String SCOPED_AUTHORIZE_URL = AUTHORIZE_URL + "&scope=%s"; - - @Override - public String getAccessTokenEndpoint() - { - return "https://login.live.com/oauth20_token.srf?grant_type=authorization_code"; - } - - @Override - public String getAuthorizationUrl(OAuthConfig config) - { - Preconditions.checkValidUrl(config.getCallback(), "Must provide a valid url as callback. Live does not support OOB"); - - // Append scope if present - if (config.hasScope()) - { - return String.format(SCOPED_AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()), OAuthEncoder.encode(config.getScope())); - } - else - { - return String.format(AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback())); - } - } - - @Override - public AccessTokenExtractor getAccessTokenExtractor() - { - return new JsonTokenExtractor(); - } -} \ No newline at end of file diff --git a/src/main/java/org/scribe/builder/api/LoveFilmApi.java b/src/main/java/org/scribe/builder/api/LoveFilmApi.java deleted file mode 100644 index 81a5bb874..000000000 --- a/src/main/java/org/scribe/builder/api/LoveFilmApi.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.scribe.builder.api; - -import org.scribe.model.Token; - -public class LoveFilmApi extends DefaultApi10a -{ - private static final String REQUEST_TOKEN_URL = "http://openapi.lovefilm.com/oauth/request_token"; - private static final String ACCESS_TOKEN_URL = "http://openapi.lovefilm.com/oauth/access_token"; - private static final String AUTHORIZE_URL = "https://www.lovefilm.com/activate?oauth_token=%s"; - - @Override - public String getRequestTokenEndpoint() - { - return REQUEST_TOKEN_URL; - } - - @Override - public String getAccessTokenEndpoint() - { - return ACCESS_TOKEN_URL; - } - - @Override - public String getAuthorizationUrl(Token requestToken) - { - return String.format(AUTHORIZE_URL, requestToken.getToken()); - } -} diff --git a/src/main/java/org/scribe/builder/api/MeetupApi.java b/src/main/java/org/scribe/builder/api/MeetupApi.java deleted file mode 100644 index 8f63e39e1..000000000 --- a/src/main/java/org/scribe/builder/api/MeetupApi.java +++ /dev/null @@ -1,30 +0,0 @@ -package org.scribe.builder.api; - -import org.scribe.model.Token; - -/** - * OAuth access to the Meetup.com API. - * For more information visit http://www.meetup.com/api - */ -public class MeetupApi extends DefaultApi10a -{ - private static final String AUTHORIZE_URL = "http://www.meetup.com/authenticate?oauth_token=%s"; - - @Override - public String getRequestTokenEndpoint() - { - return "http://api.meetup.com/oauth/request/"; - } - - @Override - public String getAccessTokenEndpoint() - { - return "http://api.meetup.com/oauth/access/"; - } - - @Override - public String getAuthorizationUrl(Token requestToken) - { - return String.format(AUTHORIZE_URL, requestToken.getToken()); - } -} diff --git a/src/main/java/org/scribe/builder/api/MendeleyApi.java b/src/main/java/org/scribe/builder/api/MendeleyApi.java deleted file mode 100644 index c6e0eced7..000000000 --- a/src/main/java/org/scribe/builder/api/MendeleyApi.java +++ /dev/null @@ -1,43 +0,0 @@ -package org.scribe.builder.api; - -import org.scribe.model.*; - -/** - * @author Arieh "Vainolo" Bibliowicz - * @see http://apidocs.mendeley.com/home/authentication - */ -public class MendeleyApi extends DefaultApi10a -{ - - private static final String AUTHORIZATION_URL = "http://api.mendeley.com/oauth/authorize?oauth_token=%s"; - - @Override - public String getRequestTokenEndpoint() - { - return "http://api.mendeley.com/oauth/request_token/"; - } - - @Override - public String getAccessTokenEndpoint() - { - return "http://api.mendeley.com/oauth/access_token/"; - } - - @Override - public String getAuthorizationUrl(Token requestToken) - { - return String.format(AUTHORIZATION_URL, requestToken.getToken()); - } - - @Override - public Verb getAccessTokenVerb() - { - return Verb.GET; - } - - @Override - public Verb getRequestTokenVerb() - { - return Verb.GET; - } -} diff --git a/src/main/java/org/scribe/builder/api/MisoApi.java b/src/main/java/org/scribe/builder/api/MisoApi.java deleted file mode 100644 index a6d88d3df..000000000 --- a/src/main/java/org/scribe/builder/api/MisoApi.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.scribe.builder.api; - -import org.scribe.model.Token; - -public class MisoApi extends DefaultApi10a -{ - private static final String AUTHORIZE_URL = "http://gomiso.com/oauth/authorize?oauth_token=%s"; - private static final String REQUEST_TOKEN_RESOURCE = "http://gomiso.com/oauth/request_token"; - private static final String ACCESS_TOKEN_RESOURCE = "http://gomiso.com/oauth/access_token"; - - @Override - public String getAccessTokenEndpoint() - { - return ACCESS_TOKEN_RESOURCE; - } - - @Override - public String getRequestTokenEndpoint() - { - return REQUEST_TOKEN_RESOURCE; - } - - @Override - public String getAuthorizationUrl(Token requestToken) - { - return String.format(AUTHORIZE_URL, requestToken.getToken()); - } - -} diff --git a/src/main/java/org/scribe/builder/api/NetProspexApi.java b/src/main/java/org/scribe/builder/api/NetProspexApi.java deleted file mode 100644 index 8257de751..000000000 --- a/src/main/java/org/scribe/builder/api/NetProspexApi.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.scribe.builder.api; - -import org.scribe.model.Token; - -public class NetProspexApi extends DefaultApi10a -{ - private static final String REQUEST_TOKEN_URL = "https://api.netprospex.com/1.0/oauth/request-token"; - private static final String ACCESS_TOKEN_URL = "https://api.netprospex.com/1.0/oauth/access-token"; - private static final String AUTHORIZE_URL = "https://api.netprospex.com/1.0/oauth/authorize?oauth_token=%s"; - - @Override - public String getRequestTokenEndpoint() - { - return REQUEST_TOKEN_URL; - } - - @Override - public String getAccessTokenEndpoint() - { - return ACCESS_TOKEN_URL; - } - - @Override - public String getAuthorizationUrl(Token requestToken) - { - return String.format(AUTHORIZE_URL, requestToken.getToken()); - } -} diff --git a/src/main/java/org/scribe/builder/api/NeteaseWeibooApi.java b/src/main/java/org/scribe/builder/api/NeteaseWeibooApi.java deleted file mode 100644 index fae38ac30..000000000 --- a/src/main/java/org/scribe/builder/api/NeteaseWeibooApi.java +++ /dev/null @@ -1,47 +0,0 @@ -package org.scribe.builder.api; - -import org.scribe.model.*; - -public class NeteaseWeibooApi extends DefaultApi10a -{ - private static final String REQUEST_TOKEN_URL = "http://api.t.163.com/oauth/request_token"; - private static final String ACCESS_TOKEN_URL = "http://api.t.163.com/oauth/access_token"; - private static final String AUTHORIZE_URL = "http://api.t.163.com/oauth/authorize?oauth_token=%s"; - private static final String AUTHENTICATE_URL = "http://api.t.163.com/oauth/authenticate?oauth_token=%s"; - - @Override - public String getRequestTokenEndpoint() - { - return REQUEST_TOKEN_URL; - } - - @Override - public String getAccessTokenEndpoint() - { - return ACCESS_TOKEN_URL; - } - - @Override - /** - * this method will ignore your callback - * if you're creating a desktop client please choose this url - * else your can call getAuthenticateUrl - * - * via http://open.t.163.com/wiki/index.php?title=%E8%AF%B7%E6%B1%82%E7%94%A8%E6%88%B7%E6%8E%88%E6%9D%83Token(oauth/authorize) - */ - public String getAuthorizationUrl(Token requestToken) - { - return String.format(AUTHORIZE_URL, requestToken.getToken()); - } - - /** - * this method is for web client with callback url - * if you're creating a desktop client please call getAuthorizationUrl - * - * via http://open.t.163.com/wiki/index.php?title=%E8%AF%B7%E6%B1%82%E7%94%A8%E6%88%B7%E6%8E%88%E6%9D%83Token(oauth/authenticate) - */ - public String getAuthenticateUrl(Token requestToken) - { - return String.format(AUTHENTICATE_URL, requestToken.getToken()); - } -} diff --git a/src/main/java/org/scribe/builder/api/PlurkApi.java b/src/main/java/org/scribe/builder/api/PlurkApi.java deleted file mode 100644 index 22b1ddb75..000000000 --- a/src/main/java/org/scribe/builder/api/PlurkApi.java +++ /dev/null @@ -1,39 +0,0 @@ -package org.scribe.builder.api; - -import org.scribe.model.Token; - -public class PlurkApi extends DefaultApi10a -{ - private static final String REQUEST_TOKEN_URL = "http://www.plurk.com/OAuth/request_token"; - private static final String AUTHORIZATION_URL = "http://www.plurk.com/OAuth/authorize?oauth_token=%s"; - private static final String ACCESS_TOKEN_URL = "http://www.plurk.com/OAuth/access_token"; - - @Override - public String getRequestTokenEndpoint() - { - return REQUEST_TOKEN_URL; - } - - @Override - public String getAuthorizationUrl(Token requestToken) - { - return String.format(AUTHORIZATION_URL, requestToken.getToken()); - } - - @Override - public String getAccessTokenEndpoint() - { - return ACCESS_TOKEN_URL; - } - - public static class Mobile extends PlurkApi - { - private static final String AUTHORIZATION_URL = "http://www.plurk.com/m/authorize?oauth_token=%s"; - - @Override - public String getAuthorizationUrl(Token requestToken) - { - return String.format(AUTHORIZATION_URL, requestToken.getToken()); - } - } -} diff --git a/src/main/java/org/scribe/builder/api/Px500Api.java b/src/main/java/org/scribe/builder/api/Px500Api.java deleted file mode 100644 index f7f3b0e0a..000000000 --- a/src/main/java/org/scribe/builder/api/Px500Api.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.scribe.builder.api; - -import org.scribe.model.*; - -public class Px500Api extends DefaultApi10a -{ - private static final String AUTHORIZATION_URL = "https://api.500px.com/v1/oauth/authorize?oauth_token=%s"; - - @Override - public String getAccessTokenEndpoint() - { - return "https://api.500px.com/v1/oauth/access_token"; - } - - @Override - public String getRequestTokenEndpoint() - { - return "https://api.500px.com/v1/oauth/request_token"; - } - - @Override - public String getAuthorizationUrl(Token requestToken) - { - return String.format(AUTHORIZATION_URL, requestToken.getToken()); - } -} \ No newline at end of file diff --git a/src/main/java/org/scribe/builder/api/QWeiboApi.java b/src/main/java/org/scribe/builder/api/QWeiboApi.java deleted file mode 100644 index e16f28836..000000000 --- a/src/main/java/org/scribe/builder/api/QWeiboApi.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.scribe.builder.api; - -import org.scribe.model.*; - -public class QWeiboApi extends DefaultApi10a -{ - private static final String REQUEST_TOKEN_URL = "https://open.t.qq.com/cgi-bin/request_token"; - private static final String ACCESS_TOKEN_URL = "https://open.t.qq.com/cgi-bin/access_token"; - private static final String AUTHORIZE_URL = "https://open.t.qq.com/cgi-bin/authorize?oauth_token=%s"; - - @Override - public String getRequestTokenEndpoint() - { - return REQUEST_TOKEN_URL; - } - - @Override - public String getAccessTokenEndpoint() - { - return ACCESS_TOKEN_URL; - } - - @Override - public String getAuthorizationUrl(Token requestToken) - { - return String.format(AUTHORIZE_URL, requestToken.getToken()); - } -} diff --git a/src/main/java/org/scribe/builder/api/RenrenApi.java b/src/main/java/org/scribe/builder/api/RenrenApi.java deleted file mode 100644 index b31337ba4..000000000 --- a/src/main/java/org/scribe/builder/api/RenrenApi.java +++ /dev/null @@ -1,40 +0,0 @@ -package org.scribe.builder.api; - -import org.scribe.extractors.*; -import org.scribe.model.*; -import org.scribe.utils.*; - -/** - * Renren(http://www.renren.com/) OAuth 2.0 based api. - */ -public class RenrenApi extends DefaultApi20 -{ - private static final String AUTHORIZE_URL = "https://graph.renren.com/oauth/authorize?client_id=%s&redirect_uri=%s&response_type=code"; - private static final String SCOPED_AUTHORIZE_URL = AUTHORIZE_URL + "&scope=%s"; - - @Override - public AccessTokenExtractor getAccessTokenExtractor() - { - return new JsonTokenExtractor(); - } - - @Override - public String getAccessTokenEndpoint() - { - return "https://graph.renren.com/oauth/token?grant_type=authorization_code"; - } - - @Override - public String getAuthorizationUrl(OAuthConfig config) - { - // Append scope if present - if (config.hasScope()) - { - return String.format(SCOPED_AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()), OAuthEncoder.encode(config.getScope())); - } - else - { - return String.format(AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback())); - } - } -} diff --git a/src/main/java/org/scribe/builder/api/SapoApi.java b/src/main/java/org/scribe/builder/api/SapoApi.java deleted file mode 100644 index 9771daf4c..000000000 --- a/src/main/java/org/scribe/builder/api/SapoApi.java +++ /dev/null @@ -1,40 +0,0 @@ -package org.scribe.builder.api; - -import org.scribe.model.*; - -public class SapoApi extends DefaultApi10a -{ - private static final String AUTHORIZE_URL = "https://id.sapo.pt/oauth/authorize?oauth_token=%s"; - private static final String ACCESS_URL = "https://id.sapo.pt/oauth/access_token"; - private static final String REQUEST_URL = "https://id.sapo.pt/oauth/request_token"; - - @Override - public String getAccessTokenEndpoint() - { - return ACCESS_URL; - } - - @Override - public String getRequestTokenEndpoint() - { - return REQUEST_URL; - } - - @Override - public String getAuthorizationUrl(Token requestToken) - { - return String.format(AUTHORIZE_URL, requestToken.getToken()); - } - - @Override - public Verb getRequestTokenVerb() - { - return Verb.GET; - } - - @Override - public Verb getAccessTokenVerb() - { - return Verb.GET; - } -} \ No newline at end of file diff --git a/src/main/java/org/scribe/builder/api/SimpleGeoApi.java b/src/main/java/org/scribe/builder/api/SimpleGeoApi.java deleted file mode 100644 index 3e19df70a..000000000 --- a/src/main/java/org/scribe/builder/api/SimpleGeoApi.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.scribe.builder.api; - -import org.scribe.model.Token; - -/** - * @author: Pablo Fernandez - */ -public class SimpleGeoApi extends DefaultApi10a -{ - private static final String ENDPOINT = "these are not used since SimpleGeo uses 2 legged OAuth"; - - @Override - public String getRequestTokenEndpoint() - { - return ENDPOINT; - } - - @Override - public String getAccessTokenEndpoint() - { - return ENDPOINT; - } - - @Override - public String getAuthorizationUrl(Token requestToken) - { - return ENDPOINT; - } -} diff --git a/src/main/java/org/scribe/builder/api/SinaWeiboApi.java b/src/main/java/org/scribe/builder/api/SinaWeiboApi.java deleted file mode 100644 index 14951d31b..000000000 --- a/src/main/java/org/scribe/builder/api/SinaWeiboApi.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.scribe.builder.api; - -import org.scribe.model.*; - -public class SinaWeiboApi extends DefaultApi10a -{ - private static final String REQUEST_TOKEN_URL = "http://api.t.sina.com.cn/oauth/request_token"; - private static final String ACCESS_TOKEN_URL = "http://api.t.sina.com.cn/oauth/access_token"; - private static final String AUTHORIZE_URL = "http://api.t.sina.com.cn/oauth/authorize?oauth_token=%s"; - - @Override - public String getRequestTokenEndpoint() - { - return REQUEST_TOKEN_URL; - } - - @Override - public String getAccessTokenEndpoint() - { - return ACCESS_TOKEN_URL; - } - - @Override - public String getAuthorizationUrl(Token requestToken) - { - return String.format(AUTHORIZE_URL, requestToken.getToken()); - } -} diff --git a/src/main/java/org/scribe/builder/api/SinaWeiboApi20.java b/src/main/java/org/scribe/builder/api/SinaWeiboApi20.java deleted file mode 100644 index e0744c432..000000000 --- a/src/main/java/org/scribe/builder/api/SinaWeiboApi20.java +++ /dev/null @@ -1,46 +0,0 @@ -package org.scribe.builder.api; - -import org.scribe.extractors.*; -import org.scribe.model.*; -import org.scribe.utils.*; - -/** - * SinaWeibo OAuth 2.0 api. - */ -public class SinaWeiboApi20 extends DefaultApi20 -{ - private static final String AUTHORIZE_URL = "https://api.weibo.com/oauth2/authorize?client_id=%s&redirect_uri=%s&response_type=code"; - private static final String SCOPED_AUTHORIZE_URL = AUTHORIZE_URL + "&scope=%s"; - - @Override - public Verb getAccessTokenVerb() - { - return Verb.POST; - } - - @Override - public AccessTokenExtractor getAccessTokenExtractor() - { - return new JsonTokenExtractor(); - } - - @Override - public String getAccessTokenEndpoint() - { - return "https://api.weibo.com/oauth2/access_token?grant_type=authorization_code"; - } - - @Override - public String getAuthorizationUrl(OAuthConfig config) - { - // Append scope if present - if (config.hasScope()) - { - return String.format(SCOPED_AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()), OAuthEncoder.encode(config.getScope())); - } - else - { - return String.format(AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback())); - } - } -} diff --git a/src/main/java/org/scribe/builder/api/SkyrockApi.java b/src/main/java/org/scribe/builder/api/SkyrockApi.java deleted file mode 100644 index b0e76a303..000000000 --- a/src/main/java/org/scribe/builder/api/SkyrockApi.java +++ /dev/null @@ -1,35 +0,0 @@ -package org.scribe.builder.api; - -import org.scribe.model.*; - -/** - * OAuth API for Skyrock. - * - * @author Nicolas Quiénot - * @see Skyrock.com API - */ -public class SkyrockApi extends DefaultApi10a -{ - private static final String API_ENDPOINT = "https://api.skyrock.com/v2"; - private static final String REQUEST_TOKEN_RESOURCE = "/oauth/initiate"; - private static final String AUTHORIZE_URL = "/oauth/authorize?oauth_token=%s"; - private static final String ACCESS_TOKEN_RESOURCE = "/oauth/token"; - - @Override - public String getAccessTokenEndpoint() - { - return API_ENDPOINT + ACCESS_TOKEN_RESOURCE; - } - - @Override - public String getRequestTokenEndpoint() - { - return API_ENDPOINT + REQUEST_TOKEN_RESOURCE; - } - - @Override - public String getAuthorizationUrl(Token requestToken) - { - return String.format(API_ENDPOINT + AUTHORIZE_URL, requestToken.getToken()); - } -} diff --git a/src/main/java/org/scribe/builder/api/SohuWeiboApi.java b/src/main/java/org/scribe/builder/api/SohuWeiboApi.java deleted file mode 100644 index 1f927b7a5..000000000 --- a/src/main/java/org/scribe/builder/api/SohuWeiboApi.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.scribe.builder.api; - -import org.scribe.model.*; - -public class SohuWeiboApi extends DefaultApi10a -{ - private static final String REQUEST_TOKEN_URL = "http://api.t.sohu.com/oauth/request_token"; - private static final String ACCESS_TOKEN_URL = "http://api.t.sohu.com/oauth/access_token"; - private static final String AUTHORIZE_URL = "http://api.t.sohu.com/oauth/authorize?oauth_token=%s"; - - @Override - public String getRequestTokenEndpoint() - { - return REQUEST_TOKEN_URL; - } - - @Override - public String getAccessTokenEndpoint() - { - return ACCESS_TOKEN_URL; - } - - @Override - public String getAuthorizationUrl(Token requestToken) - { - return String.format(AUTHORIZE_URL, requestToken.getToken()); - } -} diff --git a/src/main/java/org/scribe/builder/api/TrelloApi.java b/src/main/java/org/scribe/builder/api/TrelloApi.java deleted file mode 100644 index 9e46730d4..000000000 --- a/src/main/java/org/scribe/builder/api/TrelloApi.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.scribe.builder.api; - -import org.scribe.model.*; - -public class TrelloApi extends DefaultApi10a -{ - private static final String AUTHORIZE_URL = "https://trello.com/1/OAuthAuthorizeToken?oauth_token=%s"; - - @Override - public String getAccessTokenEndpoint() - { - return "https://trello.com/1/OAuthGetAccessToken"; - } - - @Override - public String getRequestTokenEndpoint() - { - return "https://trello.com/1/OAuthGetRequestToken"; - } - - @Override - public String getAuthorizationUrl(Token requestToken) - { - return String.format(AUTHORIZE_URL, requestToken.getToken()); - } - -} diff --git a/src/main/java/org/scribe/builder/api/TumblrApi.java b/src/main/java/org/scribe/builder/api/TumblrApi.java deleted file mode 100644 index ee680ee8a..000000000 --- a/src/main/java/org/scribe/builder/api/TumblrApi.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.scribe.builder.api; - -import org.scribe.model.Token; - -public class TumblrApi extends DefaultApi10a -{ - private static final String AUTHORIZE_URL = "https://www.tumblr.com/oauth/authorize?oauth_token=%s"; - private static final String REQUEST_TOKEN_RESOURCE = "http://www.tumblr.com/oauth/request_token"; - private static final String ACCESS_TOKEN_RESOURCE = "http://www.tumblr.com/oauth/access_token"; - - @Override - public String getAccessTokenEndpoint() - { - return ACCESS_TOKEN_RESOURCE; - } - - @Override - public String getRequestTokenEndpoint() - { - return REQUEST_TOKEN_RESOURCE; - } - - @Override - public String getAuthorizationUrl(Token requestToken) - { - return String.format(AUTHORIZE_URL, requestToken.getToken()); - } -} diff --git a/src/main/java/org/scribe/builder/api/TwitterApi.java b/src/main/java/org/scribe/builder/api/TwitterApi.java deleted file mode 100644 index 86494c54d..000000000 --- a/src/main/java/org/scribe/builder/api/TwitterApi.java +++ /dev/null @@ -1,42 +0,0 @@ -package org.scribe.builder.api; - -import org.scribe.model.Token; - -public class TwitterApi extends DefaultApi10a -{ - private static final String AUTHORIZE_URL = "https://api.twitter.com/oauth/authorize?oauth_token=%s"; - private static final String REQUEST_TOKEN_RESOURCE = "api.twitter.com/oauth/request_token"; - private static final String ACCESS_TOKEN_RESOURCE = "api.twitter.com/oauth/access_token"; - - @Override - public String getAccessTokenEndpoint() - { - return "https://" + ACCESS_TOKEN_RESOURCE; - } - - @Override - public String getRequestTokenEndpoint() - { - return "https://" + REQUEST_TOKEN_RESOURCE; - } - - @Override - public String getAuthorizationUrl(Token requestToken) - { - return String.format(AUTHORIZE_URL, requestToken.getToken()); - } - - /** - * Twitter 'friendlier' authorization endpoint for OAuth. - */ - public static class Authenticate extends TwitterApi - { - private static final String AUTHENTICATE_URL = "https://api.twitter.com/oauth/authenticate?oauth_token=%s"; - - @Override - public String getAuthorizationUrl(Token requestToken) - { - return String.format(AUTHENTICATE_URL, requestToken.getToken()); - } - } -} diff --git a/src/main/java/org/scribe/builder/api/UbuntuOneApi.java b/src/main/java/org/scribe/builder/api/UbuntuOneApi.java deleted file mode 100644 index 2a72c3afe..000000000 --- a/src/main/java/org/scribe/builder/api/UbuntuOneApi.java +++ /dev/null @@ -1,40 +0,0 @@ -package org.scribe.builder.api; - -import org.scribe.model.Token; -import org.scribe.services.*; - -/** - * @author Julio Gutierrez - * - * Sep 6, 2012 - */ -public class UbuntuOneApi extends DefaultApi10a -{ - - private static final String AUTHORIZATION_URL = "https://one.ubuntu.com/oauth/authorize/?oauth_token=%s"; - - @Override - public String getAccessTokenEndpoint() - { - return "https://one.ubuntu.com/oauth/access/"; - } - - @Override - public String getAuthorizationUrl(Token requestToken) - { - return String.format(AUTHORIZATION_URL, requestToken.getToken()); - } - - @Override - public String getRequestTokenEndpoint() - { - return "https://one.ubuntu.com/oauth/request/"; - } - - @Override - public SignatureService getSignatureService() - { - return new PlaintextSignatureService(); - } - -} diff --git a/src/main/java/org/scribe/builder/api/ViadeoApi.java b/src/main/java/org/scribe/builder/api/ViadeoApi.java deleted file mode 100644 index 0f5e77e76..000000000 --- a/src/main/java/org/scribe/builder/api/ViadeoApi.java +++ /dev/null @@ -1,42 +0,0 @@ -package org.scribe.builder.api; - -import org.scribe.extractors.AccessTokenExtractor; -import org.scribe.model.OAuthConfig; -import org.scribe.utils.OAuthEncoder; -import org.scribe.utils.Preconditions; - -import org.scribe.extractors.JsonTokenExtractor; - -public class ViadeoApi extends DefaultApi20 -{ - private static final String AUTHORIZE_URL = "https://secure.viadeo.com/oauth-provider/authorize2?client_id=%s&redirect_uri=%s&response_type=code"; - private static final String SCOPED_AUTHORIZE_URL = AUTHORIZE_URL + "&scope=%s"; - - @Override - public AccessTokenExtractor getAccessTokenExtractor() - { - return new JsonTokenExtractor(); - } - - @Override - public String getAccessTokenEndpoint() - { - return "https://secure.viadeo.com/oauth-provider/access_token2?grant_type=authorization_code"; - } - - @Override - public String getAuthorizationUrl(OAuthConfig config) - { - Preconditions.checkValidUrl(config.getCallback(), "Must provide a valid url as callback. Viadeo does not support OOB"); - - // Append scope if present - if(config.hasScope()) - { - return String.format(SCOPED_AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()), OAuthEncoder.encode(config.getScope())); - } - else - { - return String.format(AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback())); - } - } -} diff --git a/src/main/java/org/scribe/builder/api/VimeoApi.java b/src/main/java/org/scribe/builder/api/VimeoApi.java deleted file mode 100644 index 231895dab..000000000 --- a/src/main/java/org/scribe/builder/api/VimeoApi.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.scribe.builder.api; - -import org.scribe.model.Token; - -public class VimeoApi extends DefaultApi10a -{ - private static final String AUTHORIZATION_URL = "http://vimeo.com/oauth/authorize?oauth_token=%s"; - - @Override - public String getAccessTokenEndpoint() - { - return "http://vimeo.com/oauth/access_token"; - } - - @Override - public String getRequestTokenEndpoint() - { - return "http://vimeo.com/oauth/request_token"; - } - - @Override - public String getAuthorizationUrl(Token requestToken) - { - return String.format(AUTHORIZATION_URL, requestToken.getToken()); - } -} diff --git a/src/main/java/org/scribe/builder/api/VkontakteApi.java b/src/main/java/org/scribe/builder/api/VkontakteApi.java deleted file mode 100644 index e12f39559..000000000 --- a/src/main/java/org/scribe/builder/api/VkontakteApi.java +++ /dev/null @@ -1,41 +0,0 @@ -package org.scribe.builder.api; - -import org.scribe.extractors.*; -import org.scribe.utils.*; -import org.scribe.model.*; - -/** - * @author Boris G. Tsirkin - * @since 20.4.2011 - */ -public class VkontakteApi extends DefaultApi20 -{ - private static final String AUTHORIZE_URL = "https://oauth.vk.com/authorize?client_id=%s&redirect_uri=%s&response_type=code"; - private static final String SCOPED_AUTHORIZE_URL = String.format("%s&scope=%%s", AUTHORIZE_URL); - - @Override - public String getAccessTokenEndpoint() - { - return "https://api.vkontakte.ru/oauth/access_token"; - } - - @Override - public String getAuthorizationUrl(OAuthConfig config) - { - Preconditions.checkValidUrl(config.getCallback(), "Valid url is required for a callback. Vkontakte does not support OOB"); - if(config.hasScope())// Appending scope if present - { - return String.format(SCOPED_AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()), OAuthEncoder.encode(config.getScope())); - } - else - { - return String.format(AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback())); - } - } - - @Override - public AccessTokenExtractor getAccessTokenExtractor() - { - return new JsonTokenExtractor(); - } -} diff --git a/src/main/java/org/scribe/builder/api/XingApi.java b/src/main/java/org/scribe/builder/api/XingApi.java deleted file mode 100755 index ec8823e67..000000000 --- a/src/main/java/org/scribe/builder/api/XingApi.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.scribe.builder.api; - -import org.scribe.model.*; - -public class XingApi extends DefaultApi10a -{ - private static final String AUTHORIZE_URL = "https://api.xing.com/v1/authorize?oauth_token=%s"; - - @Override - public String getAccessTokenEndpoint() - { - return "https://api.xing.com/v1/access_token"; - } - - @Override - public String getRequestTokenEndpoint() - { - return "https://api.xing.com/v1/request_token"; - } - - @Override - public String getAuthorizationUrl(Token requestToken) - { - return String.format(AUTHORIZE_URL, requestToken.getToken()); - } - -} diff --git a/src/main/java/org/scribe/builder/api/YahooApi.java b/src/main/java/org/scribe/builder/api/YahooApi.java deleted file mode 100644 index e8a29a738..000000000 --- a/src/main/java/org/scribe/builder/api/YahooApi.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.scribe.builder.api; - -import org.scribe.model.Token; - -public class YahooApi extends DefaultApi10a -{ - private static final String AUTHORIZE_URL = "https://api.login.yahoo.com/oauth/v2/request_auth?oauth_token=%s"; - - @Override - public String getAccessTokenEndpoint() - { - return "https://api.login.yahoo.com/oauth/v2/get_token"; - } - - @Override - public String getRequestTokenEndpoint() - { - return "https://api.login.yahoo.com/oauth/v2/get_request_token"; - } - - @Override - public String getAuthorizationUrl(Token requestToken) - { - return String.format(AUTHORIZE_URL, requestToken.getToken()); - } -} diff --git a/src/main/java/org/scribe/exceptions/OAuthConnectionException.java b/src/main/java/org/scribe/exceptions/OAuthConnectionException.java deleted file mode 100644 index 8b1716754..000000000 --- a/src/main/java/org/scribe/exceptions/OAuthConnectionException.java +++ /dev/null @@ -1,14 +0,0 @@ -package org.scribe.exceptions; - -/** - * @author Pablo Fernandez - */ -public class OAuthConnectionException extends OAuthException -{ - private static final String MSG = "There was a problem while creating a connection to the remote service."; - - public OAuthConnectionException(Exception e) - { - super(MSG, e); - } -} diff --git a/src/main/java/org/scribe/exceptions/OAuthException.java b/src/main/java/org/scribe/exceptions/OAuthException.java deleted file mode 100644 index 85f49d9b4..000000000 --- a/src/main/java/org/scribe/exceptions/OAuthException.java +++ /dev/null @@ -1,33 +0,0 @@ -package org.scribe.exceptions; - -/** - * Default scribe exception. - * Represents a problem in the OAuth signing process - * - * @author Pablo Fernandez - */ -public class OAuthException extends RuntimeException -{ - - /** - * Default constructor - * @param message message explaining what went wrong - * @param e original exception - */ - public OAuthException(String message, Exception e) - { - super(message, e); - } - - /** - * No-exception constructor. Used when there is no original exception - * - * @param message message explaining what went wrong - */ - public OAuthException(String message) - { - super(message, null); - } - - private static final long serialVersionUID = 1L; -} diff --git a/src/main/java/org/scribe/exceptions/OAuthParametersMissingException.java b/src/main/java/org/scribe/exceptions/OAuthParametersMissingException.java deleted file mode 100644 index 8407ce493..000000000 --- a/src/main/java/org/scribe/exceptions/OAuthParametersMissingException.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.scribe.exceptions; - -import org.scribe.model.*; - -/** - * Specialized exception that represents a missing OAuth parameter. - * - * @author Pablo Fernandez - */ -public class OAuthParametersMissingException extends OAuthException -{ - - private static final long serialVersionUID = 1745308760111976671L; - private static final String MSG = "Could not find oauth parameters in request: %s. " - + "OAuth parameters must be specified with the addOAuthParameter() method"; - - /** - * Default constructor. - * - * @param request OAuthRequest that caused the error - */ - public OAuthParametersMissingException(OAuthRequest request) - { - super(String.format(MSG, request)); - } -} diff --git a/src/main/java/org/scribe/exceptions/OAuthSignatureException.java b/src/main/java/org/scribe/exceptions/OAuthSignatureException.java deleted file mode 100644 index 94692be5d..000000000 --- a/src/main/java/org/scribe/exceptions/OAuthSignatureException.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.scribe.exceptions; - -/** - * Specialized exception that represents a problem in the signature - * - * @author Pablo Fernandez - */ -public class OAuthSignatureException extends OAuthException -{ - private static final long serialVersionUID = 1L; - private static final String MSG = "Error while signing string: %s"; - - /** - * Default constructor - * - * @param stringToSign plain string that gets signed (HMAC-SHA, etc) - * @param e original exception - */ - public OAuthSignatureException(String stringToSign, Exception e) - { - super(String.format(MSG, stringToSign), e); - } - -} diff --git a/src/main/java/org/scribe/extractors/AccessTokenExtractor.java b/src/main/java/org/scribe/extractors/AccessTokenExtractor.java deleted file mode 100644 index 3c0dd34d6..000000000 --- a/src/main/java/org/scribe/extractors/AccessTokenExtractor.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.scribe.extractors; - -import org.scribe.model.*; - -/** - * Simple command object that extracts a {@link Token} from a String - * - * @author Pablo Fernandez - */ -public interface AccessTokenExtractor -{ - /** - * Extracts the access token from the contents of an Http Response - * - * @param response the contents of the response - * @return OAuth access token - */ - public Token extract(String response); -} diff --git a/src/main/java/org/scribe/extractors/BaseStringExtractor.java b/src/main/java/org/scribe/extractors/BaseStringExtractor.java deleted file mode 100644 index 83ddd10fc..000000000 --- a/src/main/java/org/scribe/extractors/BaseStringExtractor.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.scribe.extractors; - -import org.scribe.model.*; - -/** - * Simple command object that extracts a base string from a {@link OAuthRequest} - * - * @author Pablo Fernandez - */ -public interface BaseStringExtractor -{ - /** - * Extracts an url-encoded base string from the {@link OAuthRequest}. - * - * See the oauth spec for more info on this. - * - * @param request the OAuthRequest - * @return the url-encoded base string - */ - String extract(OAuthRequest request); -} diff --git a/src/main/java/org/scribe/extractors/BaseStringExtractorImpl.java b/src/main/java/org/scribe/extractors/BaseStringExtractorImpl.java deleted file mode 100644 index 5e28ce276..000000000 --- a/src/main/java/org/scribe/extractors/BaseStringExtractorImpl.java +++ /dev/null @@ -1,48 +0,0 @@ -package org.scribe.extractors; - -import org.scribe.exceptions.*; -import org.scribe.model.*; -import org.scribe.utils.*; - -/** - * Default implementation of {@link BaseStringExtractor}. Conforms to OAuth 1.0a - * - * @author Pablo Fernandez - * - */ -public class BaseStringExtractorImpl implements BaseStringExtractor -{ - - private static final String AMPERSAND_SEPARATED_STRING = "%s&%s&%s"; - - /** - * {@inheritDoc} - */ - public String extract(OAuthRequest request) - { - checkPreconditions(request); - String verb = OAuthEncoder.encode(request.getVerb().name()); - String url = OAuthEncoder.encode(request.getSanitizedUrl()); - String params = getSortedAndEncodedParams(request); - return String.format(AMPERSAND_SEPARATED_STRING, verb, url, params); - } - - private String getSortedAndEncodedParams(OAuthRequest request) - { - ParameterList params = new ParameterList(); - params.addAll(request.getQueryStringParams()); - params.addAll(request.getBodyParams()); - params.addAll(new ParameterList(request.getOauthParameters())); - return params.sort().asOauthBaseString(); - } - - private void checkPreconditions(OAuthRequest request) - { - Preconditions.checkNotNull(request, "Cannot extract base string from a null object"); - - if (request.getOauthParameters() == null || request.getOauthParameters().size() <= 0) - { - throw new OAuthParametersMissingException(request); - } - } -} diff --git a/src/main/java/org/scribe/extractors/HeaderExtractor.java b/src/main/java/org/scribe/extractors/HeaderExtractor.java deleted file mode 100644 index 2bc1f8bd4..000000000 --- a/src/main/java/org/scribe/extractors/HeaderExtractor.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.scribe.extractors; - -import org.scribe.model.*; - -/** - * Simple command object that generates an OAuth Authorization header to include in the request. - * - * @author Pablo Fernandez - */ -public interface HeaderExtractor -{ - /** - * Generates an OAuth 'Authorization' Http header to include in requests as the signature. - * - * @param request the OAuthRequest to inspect and generate the header - * @return the Http header value - */ - String extract(OAuthRequest request); -} diff --git a/src/main/java/org/scribe/extractors/HeaderExtractorImpl.java b/src/main/java/org/scribe/extractors/HeaderExtractorImpl.java deleted file mode 100644 index 85f452640..000000000 --- a/src/main/java/org/scribe/extractors/HeaderExtractorImpl.java +++ /dev/null @@ -1,58 +0,0 @@ -package org.scribe.extractors; - -import java.util.*; - -import org.scribe.exceptions.*; -import org.scribe.model.*; -import org.scribe.utils.*; - -/** - * Default implementation of {@link HeaderExtractor}. Conforms to OAuth 1.0a - * - * @author Pablo Fernandez - * - */ -public class HeaderExtractorImpl implements HeaderExtractor -{ - private static final String PARAM_SEPARATOR = ", "; - private static final String PREAMBLE = "OAuth "; - public static final int ESTIMATED_PARAM_LENGTH = 20; - - /** - * {@inheritDoc} - */ - public String extract(OAuthRequest request) - { - checkPreconditions(request); - Map parameters = request.getOauthParameters(); - StringBuilder header = new StringBuilder(parameters.size() * ESTIMATED_PARAM_LENGTH); - header.append(PREAMBLE); - for (Map.Entry entry : parameters.entrySet()) - { - if(header.length() > PREAMBLE.length()) - { - header.append(PARAM_SEPARATOR); - } - header.append(String.format("%s=\"%s\"", entry.getKey(), OAuthEncoder.encode(entry.getValue()))); - } - - if (request.getRealm() != null && !request.getRealm().isEmpty()) - { - header.append(PARAM_SEPARATOR); - header.append(String.format("%s=\"%s\"", OAuthConstants.REALM, request.getRealm())); - } - - return header.toString(); - } - - private void checkPreconditions(OAuthRequest request) - { - Preconditions.checkNotNull(request, "Cannot extract a header from a null object"); - - if (request.getOauthParameters() == null || request.getOauthParameters().size() <= 0) - { - throw new OAuthParametersMissingException(request); - } - } - -} diff --git a/src/main/java/org/scribe/extractors/JsonTokenExtractor.java b/src/main/java/org/scribe/extractors/JsonTokenExtractor.java deleted file mode 100644 index b51091f0b..000000000 --- a/src/main/java/org/scribe/extractors/JsonTokenExtractor.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.scribe.extractors; - -import java.util.regex.*; - -import org.scribe.exceptions.*; -import org.scribe.model.*; -import org.scribe.utils.*; - -public class JsonTokenExtractor implements AccessTokenExtractor -{ - private Pattern accessTokenPattern = Pattern.compile("\"access_token\":\\s*\"(\\S*?)\""); - - public Token extract(String response) - { - Preconditions.checkEmptyString(response, "Cannot extract a token from a null or empty String"); - Matcher matcher = accessTokenPattern.matcher(response); - if(matcher.find()) - { - return new Token(matcher.group(1), "", response); - } - else - { - throw new OAuthException("Cannot extract an access token. Response was: " + response); - } - } - -} \ No newline at end of file diff --git a/src/main/java/org/scribe/extractors/RequestTokenExtractor.java b/src/main/java/org/scribe/extractors/RequestTokenExtractor.java deleted file mode 100644 index 1830212b6..000000000 --- a/src/main/java/org/scribe/extractors/RequestTokenExtractor.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.scribe.extractors; - -import org.scribe.model.*; - -/** - * Simple command object that extracts a {@link Token} from a String - * - * @author Pablo Fernandez - */ -public interface RequestTokenExtractor -{ - /** - * Extracts the request token from the contents of an Http Response - * - * @param response the contents of the response - * @return OAuth access token - */ - public Token extract(String response); -} diff --git a/src/main/java/org/scribe/extractors/TokenExtractor20Impl.java b/src/main/java/org/scribe/extractors/TokenExtractor20Impl.java deleted file mode 100644 index daa58b93f..000000000 --- a/src/main/java/org/scribe/extractors/TokenExtractor20Impl.java +++ /dev/null @@ -1,35 +0,0 @@ -package org.scribe.extractors; - -import java.util.regex.*; - -import org.scribe.exceptions.*; -import org.scribe.model.*; -import org.scribe.utils.*; - -/** - * Default implementation of {@link AccessTokenExtractor}. Conforms to OAuth 2.0 - */ -public class TokenExtractor20Impl implements AccessTokenExtractor -{ - private static final String TOKEN_REGEX = "access_token=([^&]+)"; - private static final String EMPTY_SECRET = ""; - - /** - * {@inheritDoc} - */ - public Token extract(String response) - { - Preconditions.checkEmptyString(response, "Response body is incorrect. Can't extract a token from an empty string"); - - Matcher matcher = Pattern.compile(TOKEN_REGEX).matcher(response); - if (matcher.find()) - { - String token = OAuthEncoder.decode(matcher.group(1)); - return new Token(token, EMPTY_SECRET, response); - } - else - { - throw new OAuthException("Response body is incorrect. Can't extract a token from this: '" + response + "'", null); - } - } -} diff --git a/src/main/java/org/scribe/extractors/TokenExtractorImpl.java b/src/main/java/org/scribe/extractors/TokenExtractorImpl.java deleted file mode 100644 index 165a0e680..000000000 --- a/src/main/java/org/scribe/extractors/TokenExtractorImpl.java +++ /dev/null @@ -1,44 +0,0 @@ -package org.scribe.extractors; - -import java.util.regex.*; - -import org.scribe.exceptions.*; -import org.scribe.model.*; -import org.scribe.utils.*; - -/** - * Default implementation of {@link RequestTokenExtractor} and {@link AccessTokenExtractor}. Conforms to OAuth 1.0a - * - * The process for extracting access and request tokens is similar so this class can do both things. - * - * @author Pablo Fernandez - */ -public class TokenExtractorImpl implements RequestTokenExtractor, AccessTokenExtractor -{ - private static final Pattern TOKEN_REGEX = Pattern.compile("oauth_token=([^&]+)"); - private static final Pattern SECRET_REGEX = Pattern.compile("oauth_token_secret=([^&]*)"); - - /** - * {@inheritDoc} - */ - public Token extract(String response) - { - Preconditions.checkEmptyString(response, "Response body is incorrect. Can't extract a token from an empty string"); - String token = extract(response, TOKEN_REGEX); - String secret = extract(response, SECRET_REGEX); - return new Token(token, secret, response); - } - - private String extract(String response, Pattern p) - { - Matcher matcher = p.matcher(response); - if (matcher.find() && matcher.groupCount() >= 1) - { - return OAuthEncoder.decode(matcher.group(1)); - } - else - { - throw new OAuthException("Response body is incorrect. Can't extract token and secret from this: '" + response + "'", null); - } - } -} diff --git a/src/main/java/org/scribe/model/OAuthConfig.java b/src/main/java/org/scribe/model/OAuthConfig.java deleted file mode 100644 index 51811d765..000000000 --- a/src/main/java/org/scribe/model/OAuthConfig.java +++ /dev/null @@ -1,79 +0,0 @@ -package org.scribe.model; - -import java.io.*; - -/** - * Parameter object that groups OAuth config values - * - * @author Pablo Fernandez - */ -public class OAuthConfig -{ - private final String apiKey; - private final String apiSecret; - private final String callback; - private final SignatureType signatureType; - private final String scope; - private final OutputStream debugStream; - - public OAuthConfig(String key, String secret) - { - this(key, secret, null, null, null, null); - } - - public OAuthConfig(String key, String secret, String callback, SignatureType type, String scope, OutputStream stream) - { - this.apiKey = key; - this.apiSecret = secret; - this.callback = callback; - this.signatureType = type; - this.scope = scope; - this.debugStream = stream; - } - - public String getApiKey() - { - return apiKey; - } - - public String getApiSecret() - { - return apiSecret; - } - - public String getCallback() - { - return callback; - } - - public SignatureType getSignatureType() - { - return signatureType; - } - - public String getScope() - { - return scope; - } - - public boolean hasScope() - { - return scope != null; - } - - public void log(String message) - { - if (debugStream != null) - { - message = message + "\n"; - try - { - debugStream.write(message.getBytes("UTF8")); - } - catch (Exception e) - { - throw new RuntimeException("there were problems while writing to the debug stream", e); - } - } - } -} diff --git a/src/main/java/org/scribe/model/OAuthConstants.java b/src/main/java/org/scribe/model/OAuthConstants.java deleted file mode 100644 index 03789bc6f..000000000 --- a/src/main/java/org/scribe/model/OAuthConstants.java +++ /dev/null @@ -1,37 +0,0 @@ -package org.scribe.model; - -/** - * This class contains OAuth constants, used project-wide - * - * @author Pablo Fernandez - */ -public class OAuthConstants -{ - private OAuthConstants(){} - - public static final String TIMESTAMP = "oauth_timestamp"; - public static final String SIGN_METHOD = "oauth_signature_method"; - public static final String SIGNATURE = "oauth_signature"; - public static final String CONSUMER_SECRET = "oauth_consumer_secret"; - public static final String CONSUMER_KEY = "oauth_consumer_key"; - public static final String CALLBACK = "oauth_callback"; - public static final String VERSION = "oauth_version"; - public static final String NONCE = "oauth_nonce"; - public static final String REALM = "realm"; - public static final String PARAM_PREFIX = "oauth_"; - public static final String TOKEN = "oauth_token"; - public static final String TOKEN_SECRET = "oauth_token_secret"; - public static final String OUT_OF_BAND = "oob"; - public static final String VERIFIER = "oauth_verifier"; - public static final String HEADER = "Authorization"; - public static final Token EMPTY_TOKEN = new Token("", ""); - public static final String SCOPE = "scope"; - - //OAuth 2.0 - public static final String ACCESS_TOKEN = "access_token"; - public static final String CLIENT_ID = "client_id"; - public static final String CLIENT_SECRET = "client_secret"; - public static final String REDIRECT_URI = "redirect_uri"; - public static final String CODE = "code"; - -} diff --git a/src/main/java/org/scribe/model/OAuthRequest.java b/src/main/java/org/scribe/model/OAuthRequest.java deleted file mode 100644 index 8d241a4c0..000000000 --- a/src/main/java/org/scribe/model/OAuthRequest.java +++ /dev/null @@ -1,80 +0,0 @@ -package org.scribe.model; - -import java.util.*; - -/** - * The representation of an OAuth HttpRequest. - * - * Adds OAuth-related functionality to the {@link Request} - * - * @author Pablo Fernandez - */ -public class OAuthRequest extends Request -{ - private static final String OAUTH_PREFIX = "oauth_"; - private Map oauthParameters; - private String realm; - - /** - * Default constructor. - * - * @param verb Http verb/method - * @param url resource URL - */ - public OAuthRequest(Verb verb, String url) - { - super(verb, url); - this.oauthParameters = new HashMap(); - } - - /** - * Adds an OAuth parameter. - * - * @param key name of the parameter - * @param value value of the parameter - * - * @throws IllegalArgumentException if the parameter is not an OAuth parameter - */ - public void addOAuthParameter(String key, String value) - { - oauthParameters.put(checkKey(key), value); - } - - private String checkKey(String key) - { - if (key.startsWith(OAUTH_PREFIX) || key.equals(OAuthConstants.SCOPE) || key.equals(OAuthConstants.REALM)) - { - return key; - } - else - { - throw new IllegalArgumentException(String.format("OAuth parameters must either be '%s', '%s' or start with '%s'", OAuthConstants.SCOPE, OAuthConstants.REALM, OAUTH_PREFIX)); - } - } - - /** - * Returns the {@link Map} containing the key-value pair of parameters. - * - * @return parameters as map - */ - public Map getOauthParameters() - { - return oauthParameters; - } - - public void setRealm(String realm) - { - this.realm = realm; - } - - public String getRealm() - { - return realm; - } - - @Override - public String toString() - { - return String.format("@OAuthRequest(%s, %s)", getVerb(), getUrl()); - } -} diff --git a/src/main/java/org/scribe/model/Parameter.java b/src/main/java/org/scribe/model/Parameter.java deleted file mode 100644 index f22e30066..000000000 --- a/src/main/java/org/scribe/model/Parameter.java +++ /dev/null @@ -1,47 +0,0 @@ -package org.scribe.model; - -import org.scribe.utils.*; - -/** - * @author Pablo Fernandez - */ -public class Parameter implements Comparable -{ - private static final String UTF = "UTF8"; - - private final String key; - private final String value; - - public Parameter(String key, String value) - { - this.key = key; - this.value = value; - } - - public String asUrlEncodedPair() - { - return OAuthEncoder.encode(key).concat("=").concat(OAuthEncoder.encode(value)); - } - - public boolean equals(Object other) - { - if(other == null) return false; - if(other == this) return true; - if(!(other instanceof Parameter)) return false; - - Parameter otherParam = (Parameter) other; - return otherParam.key.equals(key) && otherParam.value.equals(value); - } - - public int hashCode() - { - return key.hashCode() + value.hashCode(); - } - - public int compareTo(Parameter parameter) - { - int keyDiff = key.compareTo(parameter.key); - - return keyDiff != 0 ? keyDiff : value.compareTo(parameter.value); - } -} diff --git a/src/main/java/org/scribe/model/ParameterList.java b/src/main/java/org/scribe/model/ParameterList.java deleted file mode 100644 index 747b399f6..000000000 --- a/src/main/java/org/scribe/model/ParameterList.java +++ /dev/null @@ -1,114 +0,0 @@ -package org.scribe.model; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import org.scribe.utils.OAuthEncoder; -import org.scribe.utils.Preconditions; - -/** - * @author Pablo Fernandez - */ -public class ParameterList -{ - private static final char QUERY_STRING_SEPARATOR = '?'; - private static final String PARAM_SEPARATOR = "&"; - private static final String PAIR_SEPARATOR = "="; - private static final String EMPTY_STRING = ""; - - private final List params; - - public ParameterList() - { - params = new ArrayList(); - } - - ParameterList(List params) - { - this.params = new ArrayList(params); - } - - public ParameterList(Map map) - { - this(); - for(Map.Entry entry : map.entrySet()) - { - params.add(new Parameter(entry.getKey(), entry.getValue())); - } - } - - public void add(String key, String value) - { - params.add(new Parameter(key, value)); - } - - public String appendTo(String url) - { - Preconditions.checkNotNull(url, "Cannot append to null URL"); - String queryString = asFormUrlEncodedString(); - if (queryString.equals(EMPTY_STRING)) - { - return url; - } - else - { - url += url.indexOf(QUERY_STRING_SEPARATOR) != -1 ? PARAM_SEPARATOR : QUERY_STRING_SEPARATOR; - url += queryString; - return url; - } - } - - public String asOauthBaseString() - { - return OAuthEncoder.encode(asFormUrlEncodedString()); - } - - public String asFormUrlEncodedString() - { - if (params.size() == 0) return EMPTY_STRING; - - StringBuilder builder = new StringBuilder(); - for(Parameter p : params) - { - builder.append('&').append(p.asUrlEncodedPair()); - } - return builder.toString().substring(1); - } - - public void addAll(ParameterList other) - { - params.addAll(other.params); - } - - public void addQuerystring(String queryString) - { - if (queryString != null && queryString.length() > 0) - { - for (String param : queryString.split(PARAM_SEPARATOR)) - { - String pair[] = param.split(PAIR_SEPARATOR); - String key = OAuthEncoder.decode(pair[0]); - String value = pair.length > 1 ? OAuthEncoder.decode(pair[1]) : EMPTY_STRING; - params.add(new Parameter(key, value)); - } - } - } - - public boolean contains(Parameter param) - { - return params.contains(param); - } - - public int size() - { - return params.size(); - } - - public ParameterList sort() - { - ParameterList sorted = new ParameterList(params); - Collections.sort(sorted.params); - return sorted; - } -} diff --git a/src/main/java/org/scribe/model/Request.java b/src/main/java/org/scribe/model/Request.java deleted file mode 100644 index e48578e21..000000000 --- a/src/main/java/org/scribe/model/Request.java +++ /dev/null @@ -1,390 +0,0 @@ -package org.scribe.model; - -import java.io.*; -import java.net.*; -import java.nio.charset.*; -import java.util.*; -import java.util.concurrent.*; - -import org.scribe.exceptions.*; - -/** - * Represents an HTTP Request object - * - * @author Pablo Fernandez - */ -public class Request -{ - private static final String CONTENT_LENGTH = "Content-Length"; - private static final String CONTENT_TYPE = "Content-Type"; - private static RequestTuner NOOP = new RequestTuner() { - @Override public void tune(Request _){} - }; - public static final String DEFAULT_CONTENT_TYPE = "application/x-www-form-urlencoded"; - - private String url; - private Verb verb; - private ParameterList querystringParams; - private ParameterList bodyParams; - private Map headers; - private String payload = null; - private HttpURLConnection connection; - private String charset; - private byte[] bytePayload = null; - private boolean connectionKeepAlive = false; - private boolean followRedirects = true; - private Long connectTimeout = null; - private Long readTimeout = null; - - /** - * Creates a new Http Request - * - * @param verb Http Verb (GET, POST, etc) - * @param url url with optional querystring parameters. - */ - public Request(Verb verb, String url) - { - this.verb = verb; - this.url = url; - this.querystringParams = new ParameterList(); - this.bodyParams = new ParameterList(); - this.headers = new HashMap(); - } - - /** - * Execute the request and return a {@link Response} - * - * @return Http Response - * @throws RuntimeException - * if the connection cannot be created. - */ - public Response send(RequestTuner tuner) - { - try - { - createConnection(); - return doSend(tuner); - } - catch (Exception e) - { - throw new OAuthConnectionException(e); - } - } - - public Response send() - { - return send(NOOP); - } - - private void createConnection() throws IOException - { - String completeUrl = getCompleteUrl(); - if (connection == null) - { - System.setProperty("http.keepAlive", connectionKeepAlive ? "true" : "false"); - connection = (HttpURLConnection) new URL(completeUrl).openConnection(); - connection.setInstanceFollowRedirects(followRedirects); - } - } - - /** - * Returns the complete url (host + resource + encoded querystring parameters). - * - * @return the complete url. - */ - public String getCompleteUrl() - { - return querystringParams.appendTo(url); - } - - Response doSend(RequestTuner tuner) throws IOException - { - connection.setRequestMethod(this.verb.name()); - if (connectTimeout != null) - { - connection.setConnectTimeout(connectTimeout.intValue()); - } - if (readTimeout != null) - { - connection.setReadTimeout(readTimeout.intValue()); - } - addHeaders(connection); - if (verb.equals(Verb.PUT) || verb.equals(Verb.POST)) - { - addBody(connection, getByteBodyContents()); - } - tuner.tune(this); - return new Response(connection); - } - - void addHeaders(HttpURLConnection conn) - { - for (String key : headers.keySet()) - conn.setRequestProperty(key, headers.get(key)); - } - - void addBody(HttpURLConnection conn, byte[] content) throws IOException - { - conn.setRequestProperty(CONTENT_LENGTH, String.valueOf(content.length)); - - // Set default content type if none is set. - if (conn.getRequestProperty(CONTENT_TYPE) == null) - { - conn.setRequestProperty(CONTENT_TYPE, DEFAULT_CONTENT_TYPE); - } - conn.setDoOutput(true); - conn.getOutputStream().write(content); - } - - /** - * Add an HTTP Header to the Request - * - * @param key the header name - * @param value the header value - */ - public void addHeader(String key, String value) - { - this.headers.put(key, value); - } - - /** - * Add a body Parameter (for POST/ PUT Requests) - * - * @param key the parameter name - * @param value the parameter value - */ - public void addBodyParameter(String key, String value) - { - this.bodyParams.add(key, value); - } - - /** - * Add a QueryString parameter - * - * @param key the parameter name - * @param value the parameter value - */ - public void addQuerystringParameter(String key, String value) - { - this.querystringParams.add(key, value); - } - - /** - * Add body payload. - * - * This method is used when the HTTP body is not a form-url-encoded string, - * but another thing. Like for example XML. - * - * Note: The contents are not part of the OAuth signature - * - * @param payload the body of the request - */ - public void addPayload(String payload) - { - this.payload = payload; - } - - /** - * Overloaded version for byte arrays - * - * @param payload - */ - public void addPayload(byte[] payload) - { - this.bytePayload = payload.clone(); - } - - /** - * Get a {@link ParameterList} with the query string parameters. - * - * @return a {@link ParameterList} containing the query string parameters. - * @throws OAuthException if the request URL is not valid. - */ - public ParameterList getQueryStringParams() - { - try - { - ParameterList result = new ParameterList(); - String queryString = new URL(url).getQuery(); - result.addQuerystring(queryString); - result.addAll(querystringParams); - return result; - } - catch (MalformedURLException mue) - { - throw new OAuthException("Malformed URL", mue); - } - } - - /** - * Obtains a {@link ParameterList} of the body parameters. - * - * @return a {@link ParameterList}containing the body parameters. - */ - public ParameterList getBodyParams() - { - return bodyParams; - } - - /** - * Obtains the URL of the HTTP Request. - * - * @return the original URL of the HTTP Request - */ - public String getUrl() - { - return url; - } - - /** - * Returns the URL without the default port and the query string part. - * - * @return the OAuth-sanitized URL - */ - public String getSanitizedUrl() - { - if(url.startsWith("http://") && (url.endsWith(":80") || url.contains(":80/"))){ - return url.replaceAll("\\?.*", "").replaceAll(":80", ""); - } - else if(url.startsWith("https://") && (url.endsWith(":443") || url.contains(":443/"))){ - return url.replaceAll("\\?.*", "").replaceAll(":443", ""); - } - else{ - return url.replaceAll("\\?.*", ""); - } - } - - /** - * Returns the body of the request - * - * @return form encoded string - * @throws OAuthException if the charset chosen is not supported - */ - public String getBodyContents() - { - try - { - return new String(getByteBodyContents(),getCharset()); - } - catch(UnsupportedEncodingException uee) - { - throw new OAuthException("Unsupported Charset: "+charset, uee); - } - } - - byte[] getByteBodyContents() - { - if (bytePayload != null) return bytePayload; - String body = (payload != null) ? payload : bodyParams.asFormUrlEncodedString(); - try - { - return body.getBytes(getCharset()); - } - catch(UnsupportedEncodingException uee) - { - throw new OAuthException("Unsupported Charset: "+getCharset(), uee); - } - } - - /** - * Returns the HTTP Verb - * - * @return the verb - */ - public Verb getVerb() - { - return verb; - } - - /** - * Returns the connection headers as a {@link Map} - * - * @return map of headers - */ - public Map getHeaders() - { - return headers; - } - - /** - * Returns the connection charset. Defaults to {@link Charset} defaultCharset if not set - * - * @return charset - */ - public String getCharset() - { - return charset == null ? Charset.defaultCharset().name() : charset; - } - - /** - * Sets the connect timeout for the underlying {@link HttpURLConnection} - * - * @param duration duration of the timeout - * - * @param unit unit of time (milliseconds, seconds, etc) - */ - public void setConnectTimeout(int duration, TimeUnit unit) - { - this.connectTimeout = unit.toMillis(duration); - } - - /** - * Sets the read timeout for the underlying {@link HttpURLConnection} - * - * @param duration duration of the timeout - * - * @param unit unit of time (milliseconds, seconds, etc) - */ - public void setReadTimeout(int duration, TimeUnit unit) - { - this.readTimeout = unit.toMillis(duration); - } - - /** - * Set the charset of the body of the request - * - * @param charsetName name of the charset of the request - */ - public void setCharset(String charsetName) - { - this.charset = charsetName; - } - - /** - * Sets whether the underlying Http Connection is persistent or not. - * - * @see http://download.oracle.com/javase/1.5.0/docs/guide/net/http-keepalive.html - * @param connectionKeepAlive - */ - public void setConnectionKeepAlive(boolean connectionKeepAlive) - { - this.connectionKeepAlive = connectionKeepAlive; - } - - /** - * Sets whether the underlying Http Connection follows redirects or not. - * - * Defaults to true (follow redirects) - * - * @see http://docs.oracle.com/javase/6/docs/api/java/net/HttpURLConnection.html#setInstanceFollowRedirects(boolean) - * @param followRedirects - */ - public void setFollowRedirects(boolean followRedirects) - { - this.followRedirects = followRedirects; - } - - /* - * We need this in order to stub the connection object for test cases - */ - void setConnection(HttpURLConnection connection) - { - this.connection = connection; - } - - @Override - public String toString() - { - return String.format("@Request(%s %s)", getVerb(), getUrl()); - } -} diff --git a/src/main/java/org/scribe/model/RequestTuner.java b/src/main/java/org/scribe/model/RequestTuner.java deleted file mode 100644 index 34ea1eb45..000000000 --- a/src/main/java/org/scribe/model/RequestTuner.java +++ /dev/null @@ -1,6 +0,0 @@ -package org.scribe.model; - -public abstract class RequestTuner -{ - public abstract void tune(Request request); -} \ No newline at end of file diff --git a/src/main/java/org/scribe/model/Response.java b/src/main/java/org/scribe/model/Response.java deleted file mode 100644 index d433922c6..000000000 --- a/src/main/java/org/scribe/model/Response.java +++ /dev/null @@ -1,126 +0,0 @@ -package org.scribe.model; - -import java.io.*; -import java.net.*; -import java.util.*; - -import org.scribe.exceptions.*; -import org.scribe.utils.*; - -/** - * Represents an HTTP Response. - * - * @author Pablo Fernandez - */ -public class Response -{ - private static final String EMPTY = ""; - - private int code; - private String message; - private String body; - private InputStream stream; - private Map headers; - - Response(HttpURLConnection connection) throws IOException - { - try - { - connection.connect(); - code = connection.getResponseCode(); - message = connection.getResponseMessage(); - headers = parseHeaders(connection); - stream = isSuccessful() ? connection.getInputStream() : connection.getErrorStream(); - } - catch (UnknownHostException e) - { - throw new OAuthException("The IP address of a host could not be determined.", e); - } - } - - private String parseBodyContents() - { - body = StreamUtils.getStreamContents(getStream()); - return body; - } - - private Map parseHeaders(HttpURLConnection conn) - { - Map headers = new HashMap(); - for (String key : conn.getHeaderFields().keySet()) - { - headers.put(key, conn.getHeaderFields().get(key).get(0)); - } - return headers; - } - - public boolean isSuccessful() - { - return getCode() >= 200 && getCode() < 400; - } - - /** - * Obtains the HTTP Response body - * - * @return response body - */ - public String getBody() - { - return body != null ? body : parseBodyContents(); - } - - /** - * Obtains the meaningful stream of the HttpUrlConnection, either inputStream - * or errorInputStream, depending on the status code - * - * @return input stream / error stream - */ - public InputStream getStream() - { - return stream; - } - - /** - * Obtains the HTTP status code - * - * @return the status code - */ - public int getCode() - { - return code; - } - - /** - * Obtains the HTTP status message. - * Returns null if the message can not be discerned from the response (not valid HTTP) - * - * @return the status message - */ - public String getMessage() - { - return message; - } - - /** - * Obtains a {@link Map} containing the HTTP Response Headers - * - * @return headers - */ - public Map getHeaders() - { - return headers; - } - - /** - * Obtains a single HTTP Header value, or null if undefined - * - * @param name the header name. - * - * @return header value or null. - */ - public String getHeader(String name) - { - return headers.get(name); - } - -} \ No newline at end of file diff --git a/src/main/java/org/scribe/model/SignatureType.java b/src/main/java/org/scribe/model/SignatureType.java deleted file mode 100644 index 3440a361f..000000000 --- a/src/main/java/org/scribe/model/SignatureType.java +++ /dev/null @@ -1,7 +0,0 @@ -package org.scribe.model; - -public enum SignatureType -{ - Header, - QueryString -} diff --git a/src/main/java/org/scribe/model/Token.java b/src/main/java/org/scribe/model/Token.java deleted file mode 100644 index c93752a84..000000000 --- a/src/main/java/org/scribe/model/Token.java +++ /dev/null @@ -1,115 +0,0 @@ -package org.scribe.model; - -import java.io.*; -import org.scribe.utils.*; - -/** - * Represents an OAuth token (either request or access token) and its secret - * - * @author Pablo Fernandez - */ -public class Token implements Serializable -{ - private static final long serialVersionUID = 715000866082812683L; - - private final String token; - private final String secret; - private final String rawResponse; - - /** - * Default constructor - * - * @param token token value. Can't be null. - * @param secret token secret. Can't be null. - */ - public Token(String token, String secret) - { - this(token, secret, null); - } - - public Token(String token, String secret, String rawResponse) - { - Preconditions.checkNotNull(token, "Token can't be null"); - Preconditions.checkNotNull(secret, "Secret can't be null"); - - this.token = token; - this.secret = secret; - this.rawResponse = rawResponse; - } - - public String getToken() - { - return token; - } - - public String getSecret() - { - return secret; - } - - public String getRawResponse() - { - if (rawResponse == null) - { - throw new IllegalStateException("This token object was not constructed by scribe and does not have a rawResponse"); - } - return rawResponse; - } - - public String getParameter(String parameter) - { - String value = null; - for (String str : this.getRawResponse().split("&")) - { - if (str.startsWith(parameter + '=')) - { - String [] part = str.split("="); - if (part.length > 1) { - value = part[1].trim(); - } - break; - } - } - return value; - } - - @Override - public String toString() - { - return String.format("Token[%s , %s]", token, secret); - } - - /** - * Returns true if the token is empty (token = "", secret = "") - */ - public boolean isEmpty() - { - return "".equals(this.token) && "".equals(this.secret); - } - - /** - * Factory method that returns an empty token (token = "", secret = ""). - * - * Useful for two legged OAuth. - */ - public static Token empty() - { - return new Token("", ""); - } - - @Override - public boolean equals(Object o) - { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - Token that = (Token) o; - return token.equals(that.token) && secret.equals(that.secret); - } - - @Override - public int hashCode() - { - return 31 * token.hashCode() + secret.hashCode(); - } -} diff --git a/src/main/java/org/scribe/model/Verb.java b/src/main/java/org/scribe/model/Verb.java deleted file mode 100644 index 0c22f6690..000000000 --- a/src/main/java/org/scribe/model/Verb.java +++ /dev/null @@ -1,11 +0,0 @@ -package org.scribe.model; - -/** - * An enumeration containing the most common HTTP Verbs. - * - * @author Pablo Fernandez - */ -public enum Verb -{ - GET, POST, PUT, DELETE, HEAD, OPTIONS, TRACE, PATCH -} diff --git a/src/main/java/org/scribe/model/Verifier.java b/src/main/java/org/scribe/model/Verifier.java deleted file mode 100644 index 45f0e4ea3..000000000 --- a/src/main/java/org/scribe/model/Verifier.java +++ /dev/null @@ -1,30 +0,0 @@ -package org.scribe.model; - -import org.scribe.utils.*; - -/** - * Represents an OAuth verifier code. - * - * @author Pablo Fernandez - */ -public class Verifier -{ - - private final String value; - - /** - * Default constructor. - * - * @param value verifier value - */ - public Verifier(String value) - { - Preconditions.checkNotNull(value, "Must provide a valid string as verifier"); - this.value = value; - } - - public String getValue() - { - return value; - } -} diff --git a/src/main/java/org/scribe/oauth/OAuth10aServiceImpl.java b/src/main/java/org/scribe/oauth/OAuth10aServiceImpl.java deleted file mode 100644 index 2b207f566..000000000 --- a/src/main/java/org/scribe/oauth/OAuth10aServiceImpl.java +++ /dev/null @@ -1,196 +0,0 @@ -package org.scribe.oauth; - -import java.util.*; - -import org.scribe.builder.api.*; -import org.scribe.model.*; -import org.scribe.services.*; -import org.scribe.utils.*; -import java.util.concurrent.TimeUnit; - -/** - * OAuth 1.0a implementation of {@link OAuthService} - * - * @author Pablo Fernandez - */ -public class OAuth10aServiceImpl implements OAuthService -{ - private static final String VERSION = "1.0"; - - private OAuthConfig config; - private DefaultApi10a api; - - /** - * Default constructor - * - * @param api OAuth1.0a api information - * @param config OAuth 1.0a configuration param object - */ - public OAuth10aServiceImpl(DefaultApi10a api, OAuthConfig config) - { - this.api = api; - this.config = config; - } - - /** - * {@inheritDoc} - */ - public Token getRequestToken(int timeout, TimeUnit unit) - { - return getRequestToken(new TimeoutTuner(timeout, unit)); - } - - public Token getRequestToken() - { - return getRequestToken(2, TimeUnit.SECONDS); - } - - public Token getRequestToken(RequestTuner tuner) - { - config.log("obtaining request token from " + api.getRequestTokenEndpoint()); - OAuthRequest request = new OAuthRequest(api.getRequestTokenVerb(), api.getRequestTokenEndpoint()); - - config.log("setting oauth_callback to " + config.getCallback()); - request.addOAuthParameter(OAuthConstants.CALLBACK, config.getCallback()); - addOAuthParams(request, OAuthConstants.EMPTY_TOKEN); - appendSignature(request); - - config.log("sending request..."); - Response response = request.send(tuner); - String body = response.getBody(); - - config.log("response status code: " + response.getCode()); - config.log("response body: " + body); - return api.getRequestTokenExtractor().extract(body); - } - - private void addOAuthParams(OAuthRequest request, Token token) - { - request.addOAuthParameter(OAuthConstants.TIMESTAMP, api.getTimestampService().getTimestampInSeconds()); - request.addOAuthParameter(OAuthConstants.NONCE, api.getTimestampService().getNonce()); - request.addOAuthParameter(OAuthConstants.CONSUMER_KEY, config.getApiKey()); - request.addOAuthParameter(OAuthConstants.SIGN_METHOD, api.getSignatureService().getSignatureMethod()); - request.addOAuthParameter(OAuthConstants.VERSION, getVersion()); - if(config.hasScope()) request.addOAuthParameter(OAuthConstants.SCOPE, config.getScope()); - request.addOAuthParameter(OAuthConstants.SIGNATURE, getSignature(request, token)); - - config.log("appended additional OAuth parameters: " + MapUtils.toString(request.getOauthParameters())); - } - - /** - * {@inheritDoc} - */ - public Token getAccessToken(Token requestToken, Verifier verifier, int timeout, TimeUnit unit) - { - return getAccessToken(requestToken, verifier, new TimeoutTuner(timeout, unit)); - } - - public Token getAccessToken(Token requestToken, Verifier verifier) - { - return getAccessToken(requestToken, verifier, 2, TimeUnit.SECONDS); - } - - public Token getAccessToken(Token requestToken, Verifier verifier, RequestTuner tuner) - { - config.log("obtaining access token from " + api.getAccessTokenEndpoint()); - OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint()); - request.addOAuthParameter(OAuthConstants.TOKEN, requestToken.getToken()); - request.addOAuthParameter(OAuthConstants.VERIFIER, verifier.getValue()); - - config.log("setting token to: " + requestToken + " and verifier to: " + verifier); - addOAuthParams(request, requestToken); - appendSignature(request); - - config.log("sending request..."); - Response response = request.send(tuner); - String body = response.getBody(); - - config.log("response status code: " + response.getCode()); - config.log("response body: " + body); - return api.getAccessTokenExtractor().extract(body); - } - - /** - * {@inheritDoc} - */ - public void signRequest(Token token, OAuthRequest request) - { - config.log("signing request: " + request.getCompleteUrl()); - - // Do not append the token if empty. This is for two legged OAuth calls. - if (!token.isEmpty()) - { - request.addOAuthParameter(OAuthConstants.TOKEN, token.getToken()); - } - config.log("setting token to: " + token); - addOAuthParams(request, token); - appendSignature(request); - } - - /** - * {@inheritDoc} - */ - public String getVersion() - { - return VERSION; - } - - /** - * {@inheritDoc} - */ - public String getAuthorizationUrl(Token requestToken) - { - return api.getAuthorizationUrl(requestToken); - } - - private String getSignature(OAuthRequest request, Token token) - { - config.log("generating signature..."); - config.log("using base64 encoder: " + Base64Encoder.type()); - String baseString = api.getBaseStringExtractor().extract(request); - String signature = api.getSignatureService().getSignature(baseString, config.getApiSecret(), token.getSecret()); - - config.log("base string is: " + baseString); - config.log("signature is: " + signature); - return signature; - } - - private void appendSignature(OAuthRequest request) - { - switch (config.getSignatureType()) - { - case Header: - config.log("using Http Header signature"); - - String oauthHeader = api.getHeaderExtractor().extract(request); - request.addHeader(OAuthConstants.HEADER, oauthHeader); - break; - case QueryString: - config.log("using Querystring signature"); - - for (Map.Entry entry : request.getOauthParameters().entrySet()) - { - request.addQuerystringParameter(entry.getKey(), entry.getValue()); - } - break; - } - } - - private static class TimeoutTuner extends RequestTuner - { - private final int duration; - private final TimeUnit unit; - - public TimeoutTuner(int duration, TimeUnit unit) - { - this.duration = duration; - this.unit = unit; - } - - @Override - public void tune(Request request) - { - request.setReadTimeout(duration, unit); - } - } -} diff --git a/src/main/java/org/scribe/oauth/OAuth20ServiceImpl.java b/src/main/java/org/scribe/oauth/OAuth20ServiceImpl.java deleted file mode 100644 index 6262c3700..000000000 --- a/src/main/java/org/scribe/oauth/OAuth20ServiceImpl.java +++ /dev/null @@ -1,72 +0,0 @@ -package org.scribe.oauth; - -import org.scribe.builder.api.*; -import org.scribe.model.*; - -public class OAuth20ServiceImpl implements OAuthService -{ - private static final String VERSION = "2.0"; - - private final DefaultApi20 api; - private final OAuthConfig config; - - /** - * Default constructor - * - * @param api OAuth2.0 api information - * @param config OAuth 2.0 configuration param object - */ - public OAuth20ServiceImpl(DefaultApi20 api, OAuthConfig config) - { - this.api = api; - this.config = config; - } - - /** - * {@inheritDoc} - */ - public Token getAccessToken(Token requestToken, Verifier verifier) - { - OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint()); - request.addQuerystringParameter(OAuthConstants.CLIENT_ID, config.getApiKey()); - request.addQuerystringParameter(OAuthConstants.CLIENT_SECRET, config.getApiSecret()); - request.addQuerystringParameter(OAuthConstants.CODE, verifier.getValue()); - request.addQuerystringParameter(OAuthConstants.REDIRECT_URI, config.getCallback()); - if(config.hasScope()) request.addQuerystringParameter(OAuthConstants.SCOPE, config.getScope()); - Response response = request.send(); - return api.getAccessTokenExtractor().extract(response.getBody()); - } - - /** - * {@inheritDoc} - */ - public Token getRequestToken() - { - throw new UnsupportedOperationException("Unsupported operation, please use 'getAuthorizationUrl' and redirect your users there"); - } - - /** - * {@inheritDoc} - */ - public String getVersion() - { - return VERSION; - } - - /** - * {@inheritDoc} - */ - public void signRequest(Token accessToken, OAuthRequest request) - { - request.addQuerystringParameter(OAuthConstants.ACCESS_TOKEN, accessToken.getToken()); - } - - /** - * {@inheritDoc} - */ - public String getAuthorizationUrl(Token requestToken) - { - return api.getAuthorizationUrl(config); - } - -} diff --git a/src/main/java/org/scribe/oauth/OAuthService.java b/src/main/java/org/scribe/oauth/OAuthService.java deleted file mode 100644 index 0c9c57e9b..000000000 --- a/src/main/java/org/scribe/oauth/OAuthService.java +++ /dev/null @@ -1,53 +0,0 @@ -package org.scribe.oauth; - -import org.scribe.model.*; - -/** - * The main Scribe object. - * - * A facade responsible for the retrieval of request and access tokens and for the signing of HTTP requests. - * - * @author Pablo Fernandez - */ -public interface OAuthService -{ - /** - * Retrieve the request token. - * - * @return request token - */ - public Token getRequestToken(); - - /** - * Retrieve the access token - * - * @param requestToken request token (obtained previously) - * @param verifier verifier code - * @return access token - */ - public Token getAccessToken(Token requestToken, Verifier verifier); - - /** - * Signs am OAuth request - * - * @param accessToken access token (obtained previously) - * @param request request to sign - */ - public void signRequest(Token accessToken, OAuthRequest request); - - /** - * Returns the OAuth version of the service. - * - * @return oauth version as string - */ - public String getVersion(); - - /** - * Returns the URL where you should redirect your users to authenticate - * your application. - * - * @param requestToken the request token you need to authorize - * @return the URL where you should redirect your users - */ - public String getAuthorizationUrl(Token requestToken); -} diff --git a/src/main/java/org/scribe/services/Base64Encoder.java b/src/main/java/org/scribe/services/Base64Encoder.java deleted file mode 100644 index 4a091c176..000000000 --- a/src/main/java/org/scribe/services/Base64Encoder.java +++ /dev/null @@ -1,36 +0,0 @@ -package org.scribe.services; - -public abstract class Base64Encoder -{ - private static Base64Encoder instance; - - public static synchronized Base64Encoder getInstance() - { - if (instance == null) - { - instance = createEncoderInstance(); - } - return instance; - } - - private static Base64Encoder createEncoderInstance() - { - if (CommonsEncoder.isPresent()) - { - return new CommonsEncoder(); - } - else - { - return new DatatypeConverterEncoder(); - } - } - - public static String type() - { - return getInstance().getType(); - } - - public abstract String encode(byte[] bytes); - - public abstract String getType(); -} diff --git a/src/main/java/org/scribe/services/CommonsEncoder.java b/src/main/java/org/scribe/services/CommonsEncoder.java deleted file mode 100644 index 4269a69cc..000000000 --- a/src/main/java/org/scribe/services/CommonsEncoder.java +++ /dev/null @@ -1,42 +0,0 @@ -package org.scribe.services; - -import org.apache.commons.codec.binary.*; -import org.scribe.exceptions.*; - -import java.io.UnsupportedEncodingException; - -public class CommonsEncoder extends Base64Encoder -{ - - @Override - public String encode(byte[] bytes) - { - try - { - return new String(Base64.encodeBase64(bytes), "UTF-8"); - } - catch (UnsupportedEncodingException e) - { - throw new OAuthSignatureException("Can't perform base64 encoding", e); - } - } - - @Override - public String getType() - { - return "CommonsCodec"; - } - - public static boolean isPresent() - { - try - { - Class.forName("org.apache.commons.codec.binary.Base64"); - return true; - } - catch (ClassNotFoundException e) - { - return false; - } - } -} diff --git a/src/main/java/org/scribe/services/DatatypeConverterEncoder.java b/src/main/java/org/scribe/services/DatatypeConverterEncoder.java deleted file mode 100644 index d147eba50..000000000 --- a/src/main/java/org/scribe/services/DatatypeConverterEncoder.java +++ /dev/null @@ -1,18 +0,0 @@ -package org.scribe.services; - -import javax.xml.bind.*; - -public class DatatypeConverterEncoder extends Base64Encoder -{ - @Override - public String encode(byte[] bytes) - { - return DatatypeConverter.printBase64Binary(bytes); - } - - @Override - public String getType() - { - return "DatatypeConverter"; - } -} diff --git a/src/main/java/org/scribe/services/HMACSha1SignatureService.java b/src/main/java/org/scribe/services/HMACSha1SignatureService.java deleted file mode 100644 index dcb8289a7..000000000 --- a/src/main/java/org/scribe/services/HMACSha1SignatureService.java +++ /dev/null @@ -1,61 +0,0 @@ -package org.scribe.services; - -import javax.crypto.*; -import javax.crypto.spec.*; - -import org.scribe.exceptions.*; -import org.scribe.utils.*; - -/** - * HMAC-SHA1 implementation of {@link SignatureService} - * - * @author Pablo Fernandez - * - */ -public class HMACSha1SignatureService implements SignatureService -{ - private static final String EMPTY_STRING = ""; - private static final String CARRIAGE_RETURN = "\r\n"; - private static final String UTF8 = "UTF-8"; - private static final String HMAC_SHA1 = "HmacSHA1"; - private static final String METHOD = "HMAC-SHA1"; - - /** - * {@inheritDoc} - */ - 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"); - return doSign(baseString, OAuthEncoder.encode(apiSecret) + '&' + OAuthEncoder.encode(tokenSecret)); - } - catch (Exception e) - { - throw new OAuthSignatureException(baseString, e); - } - } - - private String doSign(String toSign, String keyString) throws Exception - { - SecretKeySpec key = new SecretKeySpec((keyString).getBytes(UTF8), HMAC_SHA1); - Mac mac = Mac.getInstance(HMAC_SHA1); - mac.init(key); - byte[] bytes = mac.doFinal(toSign.getBytes(UTF8)); - return bytesToBase64String(bytes).replace(CARRIAGE_RETURN, EMPTY_STRING); - } - - private String bytesToBase64String(byte[] bytes) - { - return Base64Encoder.getInstance().encode(bytes); - } - - /** - * {@inheritDoc} - */ - public String getSignatureMethod() - { - return METHOD; - } -} diff --git a/src/main/java/org/scribe/services/PlaintextSignatureService.java b/src/main/java/org/scribe/services/PlaintextSignatureService.java deleted file mode 100644 index e8c352095..000000000 --- a/src/main/java/org/scribe/services/PlaintextSignatureService.java +++ /dev/null @@ -1,40 +0,0 @@ -package org.scribe.services; - -import org.scribe.exceptions.*; -import org.scribe.utils.*; - -/** - * plaintext implementation of {@link SignatureService} - * - * @author Pablo Fernandez - * - */ -public class PlaintextSignatureService implements SignatureService -{ - private static final String METHOD = "PLAINTEXT"; - - /** - * {@inheritDoc} - */ - public String getSignature(String baseString, String apiSecret, String tokenSecret) - { - try - { - Preconditions.checkEmptyString(apiSecret, "Api secret cant be null or empty string"); - return OAuthEncoder.encode(apiSecret) + '&' + OAuthEncoder.encode(tokenSecret); - } - catch (Exception e) - { - throw new OAuthSignatureException(baseString, e); - } - } - - /** - * {@inheritDoc} - */ - public String getSignatureMethod() - { - return METHOD; - } -} - diff --git a/src/main/java/org/scribe/services/RSASha1SignatureService.java b/src/main/java/org/scribe/services/RSASha1SignatureService.java deleted file mode 100644 index c427611fb..000000000 --- a/src/main/java/org/scribe/services/RSASha1SignatureService.java +++ /dev/null @@ -1,52 +0,0 @@ -package org.scribe.services; - -import org.scribe.exceptions.*; -import java.security.*; - -/** - * A signature service that uses the RSA-SHA1 algorithm. - */ -public class RSASha1SignatureService implements SignatureService -{ - private static final String METHOD = "RSA-SHA1"; - private static final String RSA_SHA1 = "SHA1withRSA"; - private static final String UTF8 = "UTF-8"; - - private PrivateKey privateKey; - - public RSASha1SignatureService(PrivateKey privateKey) - { - this.privateKey = privateKey; - } - - /** - * {@inheritDoc} - */ - public String getSignature(String baseString, String apiSecret, String tokenSecret) - { - try - { - Signature signature = Signature.getInstance(RSA_SHA1); - signature.initSign(privateKey); - signature.update(baseString.getBytes(UTF8)); - return bytesToBase64String(signature); - } - catch (Exception e) - { - throw new OAuthSignatureException(baseString, e); - } - } - - private String bytesToBase64String(Signature signature) throws SignatureException - { - return Base64Encoder.getInstance().encode(signature.sign()); - } - - /** - * {@inheritDoc} - */ - public String getSignatureMethod() - { - return METHOD; - } -} \ No newline at end of file diff --git a/src/main/java/org/scribe/services/SignatureService.java b/src/main/java/org/scribe/services/SignatureService.java deleted file mode 100644 index 6843d1cdc..000000000 --- a/src/main/java/org/scribe/services/SignatureService.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.scribe.services; - -/** - * Signs a base string, returning the OAuth signature - * - * @author Pablo Fernandez - * - */ -public interface SignatureService -{ - /** - * Returns the signature - * - * @param baseString url-encoded string to sign - * @param apiSecret api secret for your app - * @param tokenSecret token secret (empty string for the request token step) - * - * @return signature - */ - public String getSignature(String baseString, String apiSecret, String tokenSecret); - - /** - * Returns the signature method/algorithm - * - * @return signature method/algorithm - */ - public String getSignatureMethod(); -} diff --git a/src/main/java/org/scribe/services/TimestampService.java b/src/main/java/org/scribe/services/TimestampService.java deleted file mode 100644 index 221a226b4..000000000 --- a/src/main/java/org/scribe/services/TimestampService.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.scribe.services; - -/** - * Unix epoch timestamp generator. - * - * This class is useful for stubbing in tests. - * - * @author Pablo Fernandez - */ -public interface TimestampService -{ - /** - * Returns the unix epoch timestamp in seconds - * - * @return timestamp - */ - public String getTimestampInSeconds(); - - /** - * Returns a nonce (unique value for each request) - * - * @return nonce - */ - public String getNonce(); -} diff --git a/src/main/java/org/scribe/services/TimestampServiceImpl.java b/src/main/java/org/scribe/services/TimestampServiceImpl.java deleted file mode 100644 index 486e93c64..000000000 --- a/src/main/java/org/scribe/services/TimestampServiceImpl.java +++ /dev/null @@ -1,68 +0,0 @@ -package org.scribe.services; - -import java.util.*; - -/** - * Implementation of {@link TimestampService} using plain java classes. - * - * @author Pablo Fernandez - */ -public class TimestampServiceImpl implements TimestampService -{ - private Timer timer; - - /** - * Default constructor. - */ - public TimestampServiceImpl() - { - timer = new Timer(); - } - - /** - * {@inheritDoc} - */ - public String getNonce() - { - Long ts = getTs(); - return String.valueOf(ts + timer.getRandomInteger()); - } - - /** - * {@inheritDoc} - */ - public String getTimestampInSeconds() - { - return String.valueOf(getTs()); - } - - private Long getTs() - { - return timer.getMilis() / 1000; - } - - void setTimer(Timer timer) - { - this.timer = timer; - } - - /** - * Inner class that uses {@link System} for generating the timestamps. - * - * @author Pablo Fernandez - */ - static class Timer - { - private final Random rand = new Random(); - Long getMilis() - { - return System.currentTimeMillis(); - } - - Integer getRandomInteger() - { - return rand.nextInt(); - } - } - -} diff --git a/src/main/java/org/scribe/utils/MapUtils.java b/src/main/java/org/scribe/utils/MapUtils.java deleted file mode 100644 index 4ece95816..000000000 --- a/src/main/java/org/scribe/utils/MapUtils.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.scribe.utils; - -import java.util.Map; - -/** - * @author Pablo Fernandez - */ -public class MapUtils -{ - private MapUtils(){} - - public static String toString(Map map) - { - if (map == null) return ""; - if (map.isEmpty()) return "{}"; - - StringBuilder result = new StringBuilder(); - for(Map.Entry entry : map.entrySet()) - { - result.append(String.format(", %s -> %s ", entry.getKey().toString(), entry.getValue().toString())); - } - return "{" + result.substring(1) + "}"; - } -} diff --git a/src/main/java/org/scribe/utils/OAuthEncoder.java b/src/main/java/org/scribe/utils/OAuthEncoder.java deleted file mode 100644 index 523f31172..000000000 --- a/src/main/java/org/scribe/utils/OAuthEncoder.java +++ /dev/null @@ -1,64 +0,0 @@ -package org.scribe.utils; - -import java.io.*; -import java.net.*; -import java.util.*; -import java.util.regex.*; -import org.scribe.exceptions.*; - -/** - * @author Pablo Fernandez - */ -public class OAuthEncoder -{ - private static String CHARSET = "UTF-8"; - private static final Map ENCODING_RULES; - - static - { - Map rules = new HashMap(); - rules.put("*", "%2A"); - rules.put("+", "%20"); - rules.put("%7E", "~"); - ENCODING_RULES = Collections.unmodifiableMap(rules); - } - - private OAuthEncoder(){} - - public static String encode(String plain) - { - Preconditions.checkNotNull(plain, "Cannot encode null object"); - String encoded = ""; - try - { - encoded = URLEncoder.encode(plain, CHARSET); - } - catch (UnsupportedEncodingException uee) - { - throw new OAuthException("Charset not found while encoding string: " + CHARSET, uee); - } - for(Map.Entry rule : ENCODING_RULES.entrySet()) - { - encoded = applyRule(encoded, rule.getKey(), rule.getValue()); - } - return encoded; - } - - private static String applyRule(String encoded, String toReplace, String replacement) - { - return encoded.replaceAll(Pattern.quote(toReplace), replacement); - } - - public static String decode(String encoded) - { - Preconditions.checkNotNull(encoded, "Cannot decode null object"); - try - { - return URLDecoder.decode(encoded, CHARSET); - } - catch(UnsupportedEncodingException uee) - { - throw new OAuthException("Charset not found while decoding string: " + CHARSET, uee); - } - } -} diff --git a/src/main/java/org/scribe/utils/Preconditions.java b/src/main/java/org/scribe/utils/Preconditions.java deleted file mode 100644 index f6e5b1572..000000000 --- a/src/main/java/org/scribe/utils/Preconditions.java +++ /dev/null @@ -1,88 +0,0 @@ -package org.scribe.utils; - -import java.util.regex.Pattern; - -import org.scribe.model.OAuthConstants; - -/** - * Utils for checking preconditions and invariants - * - * @author Pablo Fernandez - */ -public class Preconditions -{ - private static final String DEFAULT_MESSAGE = "Received an invalid parameter"; - - // scheme = alpha *( alpha | digit | "+" | "-" | "." ) - private static final Pattern URL_PATTERN = Pattern.compile("^[a-zA-Z][a-zA-Z0-9+.-]*://\\S+"); - - private Preconditions(){} - - /** - * Checks that an object is not null. - * - * @param object any object - * @param errorMsg error message - * - * @throws IllegalArgumentException if the object is null - */ - public static void checkNotNull(Object object, String errorMsg) - { - check(object != null, errorMsg); - } - - /** - * Checks that a string is not null or empty - * - * @param string any string - * @param errorMsg error message - * - * @throws IllegalArgumentException if the string is null or empty - */ - public static void checkEmptyString(String string, String errorMsg) - { - check(string != null && !string.trim().equals(""), errorMsg); - } - - /** - * Checks that a URL is valid - * - * @param url any string - * @param errorMsg error message - */ - public static void checkValidUrl(String url, String errorMsg) - { - checkEmptyString(url, errorMsg); - check(isUrl(url), errorMsg); - } - - /** - * Checks that a URL is a valid OAuth callback - * - * @param url any string - * @param errorMsg error message - */ - public static void checkValidOAuthCallback(String url, String errorMsg) - { - checkEmptyString(url, errorMsg); - if(url.compareToIgnoreCase(OAuthConstants.OUT_OF_BAND) != 0) - { - check(isUrl(url), errorMsg); - } - } - - private static boolean isUrl(String url) - { - return URL_PATTERN.matcher(url).matches(); - } - - private static void check(boolean requirements, String error) - { - String message = (error == null || error.trim().length() <= 0) ? DEFAULT_MESSAGE : error; - if (!requirements) - { - throw new IllegalArgumentException(message); - } - } - -} diff --git a/src/main/java/org/scribe/utils/StreamUtils.java b/src/main/java/org/scribe/utils/StreamUtils.java deleted file mode 100644 index 30dd8bc54..000000000 --- a/src/main/java/org/scribe/utils/StreamUtils.java +++ /dev/null @@ -1,44 +0,0 @@ -package org.scribe.utils; - -import java.io.*; - -/** - * Utils to deal with Streams. - * - * @author Pablo Fernandez - */ -public class StreamUtils -{ - private StreamUtils(){} - - /** - * Returns the stream contents as an UTF-8 encoded string - * - * @param is input stream - * @return string contents - */ - public static String getStreamContents(InputStream is) - { - Preconditions.checkNotNull(is, "Cannot get String from a null object"); - try - { - final char[] buffer = new char[0x10000]; - StringBuilder out = new StringBuilder(); - Reader in = new InputStreamReader(is, "UTF-8"); - int read; - do - { - read = in.read(buffer, 0, buffer.length); - if (read > 0) - { - out.append(buffer, 0, read); - } - } while (read >= 0); - in.close(); - return out.toString(); - } catch (IOException ioe) - { - throw new IllegalStateException("Error while reading response body", ioe); - } - } -} diff --git a/src/test/java/org/scribe/builder/ServiceBuilderTest.java b/src/test/java/org/scribe/builder/ServiceBuilderTest.java deleted file mode 100644 index 8112d79b3..000000000 --- a/src/test/java/org/scribe/builder/ServiceBuilderTest.java +++ /dev/null @@ -1,73 +0,0 @@ -package org.scribe.builder; - -import static org.junit.Assert.*; - -import org.junit.*; -import org.scribe.builder.api.*; -import org.scribe.model.*; -import org.scribe.oauth.*; - -public class ServiceBuilderTest -{ - private ServiceBuilder builder; - - @Before - public void setup() - { - builder = new ServiceBuilder(); - } - - @Test - public void shouldReturnConfigDefaultValues() - { - builder.provider(ApiMock.class).apiKey("key").apiSecret("secret").build(); - assertEquals(ApiMock.config.getApiKey(), "key"); - assertEquals(ApiMock.config.getApiSecret(), "secret"); - assertEquals(ApiMock.config.getCallback(), OAuthConstants.OUT_OF_BAND); - assertEquals(ApiMock.config.getSignatureType(), SignatureType.Header); - } - - @Test - public void shouldAcceptValidCallbackUrl() - { - builder.provider(ApiMock.class).apiKey("key").apiSecret("secret").callback("http://example.com").build(); - assertEquals(ApiMock.config.getApiKey(), "key"); - assertEquals(ApiMock.config.getApiSecret(), "secret"); - assertEquals(ApiMock.config.getCallback(), "http://example.com"); - } - - @Test - public void shouldAcceptASignatureType() - { - builder.provider(ApiMock.class).apiKey("key").apiSecret("secret").signatureType(SignatureType.QueryString).build(); - assertEquals(ApiMock.config.getApiKey(), "key"); - assertEquals(ApiMock.config.getApiSecret(), "secret"); - assertEquals(ApiMock.config.getSignatureType(), SignatureType.QueryString); - } - - @Test(expected=IllegalArgumentException.class) - public void shouldNotAcceptNullAsCallback() - { - builder.provider(ApiMock.class).apiKey("key").apiSecret("secret").callback(null).build(); - } - - @Test - public void shouldAcceptAnScope() - { - builder.provider(ApiMock.class).apiKey("key").apiSecret("secret").scope("rss-api").build(); - assertEquals(ApiMock.config.getApiKey(), "key"); - assertEquals(ApiMock.config.getApiSecret(), "secret"); - assertEquals(ApiMock.config.getScope(), "rss-api"); - } - - public static class ApiMock implements Api - { - public static OAuthConfig config; - - public OAuthService createService(OAuthConfig config) - { - ApiMock.config = config; - return null; - } - } -} diff --git a/src/test/java/org/scribe/examples/AWeberExample.java b/src/test/java/org/scribe/examples/AWeberExample.java deleted file mode 100644 index 2d86d6130..000000000 --- a/src/test/java/org/scribe/examples/AWeberExample.java +++ /dev/null @@ -1,65 +0,0 @@ -package org.scribe.examples; - -import java.util.Scanner; - -import org.scribe.builder.*; -import org.scribe.builder.api.*; -import org.scribe.model.*; -import org.scribe.oauth.*; - -public class AWeberExample -{ - - //To get your consumer key/secret, and view API docs, see https://labs.aweber.com/docs - private static final String ACCOUNT_RESOURCE_URL = "https://api.aweber.com/1.0/accounts/"; - - private static final String CONSUMER_KEY = ""; - private static final String CONSUMER_SECRET = ""; - - public static void main(String[] args) - { - OAuthService service = new ServiceBuilder() - .provider(AWeberApi.class) - .apiKey(CONSUMER_KEY) - .apiSecret(CONSUMER_SECRET) - .build(); - - Scanner in = new Scanner(System.in); - - System.out.println("=== AWeber's OAuth Workflow ==="); - System.out.println(); - - // Obtain the Request Token - System.out.println("Fetching the Request Token..."); - Token requestToken = service.getRequestToken(); - System.out.println("Got the Request Token!"); - System.out.println(); - - System.out.println("Now go and authorize Scribe here:"); - System.out.println(service.getAuthorizationUrl(requestToken)); - System.out.println("And paste the verifier here"); - System.out.print(">>"); - Verifier verifier = new Verifier(in.nextLine()); - System.out.println(); - - // Trade the Request Token and Verfier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); - Token accessToken = service.getAccessToken(requestToken, verifier); - System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken + " )"); - System.out.println(); - - // Now let's go and ask for a protected resource! - System.out.println("Now we're going to access a protected resource..."); - OAuthRequest request = new OAuthRequest(Verb.GET, ACCOUNT_RESOURCE_URL); - service.signRequest(accessToken, request); - Response response = request.send(); - System.out.println("Got it! Lets see what we found..."); - System.out.println(); - System.out.println(response.getBody()); - - System.out.println(); - System.out.println("Thats it man! Go and build something awesome with AWeber and Scribe! :)"); - } - -} \ No newline at end of file diff --git a/src/test/java/org/scribe/examples/DiggExample.java b/src/test/java/org/scribe/examples/DiggExample.java deleted file mode 100644 index 63fea8b6a..000000000 --- a/src/test/java/org/scribe/examples/DiggExample.java +++ /dev/null @@ -1,65 +0,0 @@ -package org.scribe.examples; - -import java.util.*; - -import org.scribe.builder.*; -import org.scribe.builder.api.*; -import org.scribe.model.*; -import org.scribe.oauth.*; - -public class DiggExample -{ - private static final String NETWORK_NAME = "Digg"; - private static final String PROTECTED_RESOURCE_URL = "http://services.digg.com/2.0/comment.digg"; - - public static void main(String[] args) - { - // Replace these with your own api key and secret - String apiKey = "myKey"; - String apiSecret = "mySecret"; - OAuthService service = new ServiceBuilder().provider(DiggApi.class).apiKey(apiKey).apiSecret(apiSecret).build(); - Scanner in = new Scanner(System.in); - - System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); - System.out.println(); - - // Obtain the Request Token - System.out.println("Fetching the Request Token..."); - Token requestToken = service.getRequestToken(); - System.out.println("Got the Request Token!"); - System.out.println(); - - // Obtain the Authorization URL - System.out.println("Fetching the Authorization URL..."); - String authorizationUrl = service.getAuthorizationUrl(requestToken); - System.out.println("Got the Authorization URL!"); - System.out.println("Now go and authorize Scribe here:"); - System.out.println(authorizationUrl); - System.out.println("And paste the authorization code here"); - System.out.print(">>"); - Verifier verifier = new Verifier(in.nextLine()); - System.out.println(); - - // Trade the Request Token and Verfier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); - Token accessToken = service.getAccessToken(requestToken, verifier); - System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken + " )"); - System.out.println(); - - // Now let's go and ask for a protected resource! - System.out.println("Now we're going to access a protected resource..."); - OAuthRequest request = new OAuthRequest(Verb.POST, PROTECTED_RESOURCE_URL); - request.addBodyParameter("comment_id", "20100729223726:4fef610331ee46a3b5cbd740bf71313e"); - service.signRequest(accessToken, request); - Response response = request.send(); - 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 Scribe! :)"); - - } -} \ No newline at end of file diff --git a/src/test/java/org/scribe/examples/FacebookExample.java b/src/test/java/org/scribe/examples/FacebookExample.java deleted file mode 100644 index d5dc3cb50..000000000 --- a/src/test/java/org/scribe/examples/FacebookExample.java +++ /dev/null @@ -1,64 +0,0 @@ -package org.scribe.examples; - -import java.util.*; - -import org.scribe.builder.*; -import org.scribe.builder.api.*; -import org.scribe.model.*; -import org.scribe.oauth.*; - -public class FacebookExample -{ - private static final String NETWORK_NAME = "Facebook"; - private static final String PROTECTED_RESOURCE_URL = "https://graph.facebook.com/me"; - private static final Token EMPTY_TOKEN = null; - - public static void main(String[] args) - { - // Replace these with your own api key and secret - String apiKey = "your_app_id"; - String apiSecret = "your_api_secret"; - OAuthService service = new ServiceBuilder() - .provider(FacebookApi.class) - .apiKey(apiKey) - .apiSecret(apiSecret) - .callback("http://www.example.com/oauth_callback/") - .build(); - 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..."); - String authorizationUrl = service.getAuthorizationUrl(EMPTY_TOKEN); - System.out.println("Got the Authorization URL!"); - System.out.println("Now go and authorize Scribe here:"); - System.out.println(authorizationUrl); - System.out.println("And paste the authorization code here"); - System.out.print(">>"); - Verifier verifier = new Verifier(in.nextLine()); - System.out.println(); - - // Trade the Request Token and Verfier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); - Token accessToken = service.getAccessToken(EMPTY_TOKEN, verifier); - System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken + " )"); - System.out.println(); - - // Now let's go and ask for a protected resource! - System.out.println("Now we're going to access a protected resource..."); - OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); - service.signRequest(accessToken, request); - Response response = request.send(); - 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 Scribe! :)"); - - } -} \ No newline at end of file diff --git a/src/test/java/org/scribe/examples/FlickrExample.java b/src/test/java/org/scribe/examples/FlickrExample.java deleted file mode 100644 index 92e9e6b82..000000000 --- a/src/test/java/org/scribe/examples/FlickrExample.java +++ /dev/null @@ -1,60 +0,0 @@ -package org.scribe.examples; - -import org.scribe.builder.*; -import org.scribe.builder.api.*; -import org.scribe.model.*; -import org.scribe.oauth.*; - -import java.util.*; - -public class FlickrExample -{ - private static final String PROTECTED_RESOURCE_URL = "https://api.flickr.com/services/rest/"; - - public static void main(String[] args) - { - // Replace these with your own api key and secret - String apiKey = "your_api_key"; - String apiSecret = "your_api_secret"; - OAuthService service = new ServiceBuilder().provider(FlickrApi.class).apiKey(apiKey).apiSecret(apiSecret).build(); - Scanner in = new Scanner(System.in); - - System.out.println("=== Flickr's OAuth Workflow ==="); - System.out.println(); - - // Obtain the Request Token - System.out.println("Fetching the Request Token..."); - Token requestToken = service.getRequestToken(); - System.out.println("Got the Request Token!"); - System.out.println(); - - System.out.println("Now go and authorize Scribe here:"); - String authorizationUrl = service.getAuthorizationUrl(requestToken); - System.out.println(authorizationUrl + "&perms=read"); - System.out.println("And paste the verifier here"); - System.out.print(">>"); - Verifier verifier = new Verifier(in.nextLine()); - System.out.println(); - - // Trade the Request Token and Verfier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); - Token accessToken = service.getAccessToken(requestToken, verifier); - System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken + " )"); - System.out.println("(you can get the username, full name, and nsid by parsing the rawResponse: " + accessToken.getRawResponse() + ")"); - System.out.println(); - - // Now let's go and ask for a protected resource! - System.out.println("Now we're going to access a protected resource..."); - OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); - request.addQuerystringParameter("method", "flickr.test.login"); - service.signRequest(accessToken, request); - Response response = request.send(); - System.out.println("Got it! Lets see what we found..."); - System.out.println(); - System.out.println(response.getBody()); - - System.out.println(); - System.out.println("Thats it man! Go and build something awesome with Scribe! :)"); - } -} diff --git a/src/test/java/org/scribe/examples/Foursquare2Example.java b/src/test/java/org/scribe/examples/Foursquare2Example.java deleted file mode 100644 index 35495a895..000000000 --- a/src/test/java/org/scribe/examples/Foursquare2Example.java +++ /dev/null @@ -1,63 +0,0 @@ -package org.scribe.examples; - -import java.util.*; - -import org.scribe.builder.*; -import org.scribe.builder.api.*; -import org.scribe.model.*; -import org.scribe.oauth.*; - -public class Foursquare2Example -{ - private static final String PROTECTED_RESOURCE_URL = "https://api.foursquare.com/v2/users/self/friends?oauth_token="; - private static final Token EMPTY_TOKEN = null; - - public static void main(String[] args) - { - // Replace these with your own api key and secret - String apiKey = "FEGFXJUFANVVDHVSNUAMUKTTXCP1AJQD53E33XKJ44YP1S4I"; - String apiSecret = "AYWKUL5SWPNC0CTQ202QXRUG2NLZYXMRA34ZSDW4AUYBG2RC"; - OAuthService service = new ServiceBuilder() - .provider(Foursquare2Api.class) - .apiKey(apiKey) - .apiSecret(apiSecret) - .callback("http://localhost:9000/") - .build(); - Scanner in = new Scanner(System.in); - - System.out.println("=== Foursquare2's OAuth Workflow ==="); - System.out.println(); - - // Obtain the Authorization URL - System.out.println("Fetching the Authorization URL..."); - String authorizationUrl = service.getAuthorizationUrl(EMPTY_TOKEN); - System.out.println("Got the Authorization URL!"); - System.out.println("Now go and authorize Scribe here:"); - System.out.println(authorizationUrl); - System.out.println("And paste the authorization code here"); - System.out.print(">>"); - Verifier verifier = new Verifier(in.nextLine()); - System.out.println(); - - // Trade the Request Token and Verfier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); - Token accessToken = service.getAccessToken(EMPTY_TOKEN, verifier); - System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken + " )"); - System.out.println(); - - // Now let's go and ask for a protected resource! - System.out.println("Now we're going to access a protected resource..."); - OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL + accessToken.getToken()); - service.signRequest(accessToken, request); - Response response = request.send(); - 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 Scribe! :)"); - - } -} diff --git a/src/test/java/org/scribe/examples/FoursquareExample.java b/src/test/java/org/scribe/examples/FoursquareExample.java deleted file mode 100644 index b227488c7..000000000 --- a/src/test/java/org/scribe/examples/FoursquareExample.java +++ /dev/null @@ -1,59 +0,0 @@ -package org.scribe.examples; - -import java.util.Scanner; - -import org.scribe.builder.*; -import org.scribe.builder.api.*; -import org.scribe.model.*; -import org.scribe.oauth.*; - -public class FoursquareExample -{ - private static final String PROTECTED_RESOURCE_URL = "http://api.foursquare.com/v1/user"; - - public static void main(String[] args) - { - OAuthService service = new ServiceBuilder() - .provider(FoursquareApi.class) - .apiKey("FEGFXJUFANVVDHVSNUAMUKTTXCP1AJQD53E33XKJ44YP1S4I") - .apiSecret("AYWKUL5SWPNC0CTQ202QXRUG2NLZYXMRA34ZSDW4AUYBG2RC") - .build(); - Scanner in = new Scanner(System.in); - - System.out.println("=== Foursquare's OAuth Workflow ==="); - System.out.println(); - - // Obtain the Request Token - System.out.println("Fetching the Request Token..."); - Token requestToken = service.getRequestToken(); - System.out.println("Got the Request Token!"); - System.out.println(); - - System.out.println("Now go and authorize Scribe here:"); - System.out.println(service.getAuthorizationUrl(requestToken)); - System.out.println("And paste the verifier here"); - System.out.print(">>"); - Verifier verifier = new Verifier(in.nextLine()); - System.out.println(); - - // Trade the Request Token and Verfier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); - Token accessToken = service.getAccessToken(requestToken, verifier); - System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken + " )"); - System.out.println(); - - // Now let's go and ask for a protected resource! - System.out.println("Now we're going to access a protected resource..."); - OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); - service.signRequest(accessToken, request); - Response response = request.send(); - System.out.println("Got it! Lets see what we found..."); - System.out.println(); - System.out.println(response.getBody()); - - System.out.println(); - System.out.println("Thats it man! Go and build something awesome with Scribe! :)"); - } - -} \ No newline at end of file diff --git a/src/test/java/org/scribe/examples/FreelancerExample.java b/src/test/java/org/scribe/examples/FreelancerExample.java deleted file mode 100644 index d1d540723..000000000 --- a/src/test/java/org/scribe/examples/FreelancerExample.java +++ /dev/null @@ -1,66 +0,0 @@ -package org.scribe.examples; - -import java.util.*; -import org.scribe.builder.*; -import org.scribe.builder.api.*; -import org.scribe.model.*; -import org.scribe.oauth.*; - -public class FreelancerExample -{ - - private static final String NETWORK_NAME = "Freelancer"; - private static final String AUTHORIZE_URL = "http://www.sandbox.freelancer.com/users/api-token/auth.php?oauth_token="; - private static final String PROTECTED_RESOURCE_URL = "http://api.sandbox.freelancer.com/Job/getJobList.json"; - private static final String SCOPE = "http://api.sandbox.freelancer.com"; - - public static void main(String[] args) - { - OAuthService service = new ServiceBuilder() - .provider(FreelancerApi.Sandbox.class) - .signatureType(SignatureType.QueryString) - .apiKey("7f5a168a0bfdbd15b4a9ea2a969661c731cdea56") - .apiSecret("7bb8961b94873802f1c5344f671a518e087f5785") - .scope(SCOPE) - .build(); - Scanner in = new Scanner(System.in); - - System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); - System.out.println(); - - // Obtain the Request Token - System.out.println("Fetching the Request Token..."); - Token requestToken = service.getRequestToken(); - System.out.println("Got the Request Token!"); - System.out.println("(if your curious it looks like this: " + requestToken + " )"); - System.out.println(); - - System.out.println("Now go and authorize Scribe here:"); - System.out.println(AUTHORIZE_URL + requestToken.getToken()); - System.out.println("And paste the verifier here"); - System.out.print(">>"); - Verifier verifier = new Verifier(in.nextLine()); - System.out.println(); - - // Trade the Request Token and Verfier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); - Token accessToken = service.getAccessToken(requestToken, verifier); - System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken + " )"); - System.out.println(); - - // Now let's go and ask for a protected resource! - System.out.println("Now we're going to access a protected resource..."); - OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); - service.signRequest(accessToken, request); - request.addHeader("GData-Version", "3.0"); - Response response = request.send(); - 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 Scribe! :)"); - } -} diff --git a/src/test/java/org/scribe/examples/GoogleExample.java b/src/test/java/org/scribe/examples/GoogleExample.java deleted file mode 100644 index fef1b43c9..000000000 --- a/src/test/java/org/scribe/examples/GoogleExample.java +++ /dev/null @@ -1,66 +0,0 @@ -package org.scribe.examples; - -import java.util.*; - -import org.scribe.builder.*; -import org.scribe.builder.api.*; -import org.scribe.model.*; -import org.scribe.oauth.*; - -public class GoogleExample -{ - private static final String NETWORK_NAME = "Google"; - private static final String AUTHORIZE_URL = "https://www.google.com/accounts/OAuthAuthorizeToken?oauth_token="; - private static final String PROTECTED_RESOURCE_URL = "https://docs.google.com/feeds/default/private/full/"; - private static final String SCOPE = "https://docs.google.com/feeds/"; - - public static void main(String[] args) - { - OAuthService service = new ServiceBuilder() - .provider(GoogleApi.class) - .apiKey("anonymous") - .apiSecret("anonymous") - .scope(SCOPE) - .build(); - Scanner in = new Scanner(System.in); - - System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); - System.out.println(); - - // Obtain the Request Token - System.out.println("Fetching the Request Token..."); - Token requestToken = service.getRequestToken(); - System.out.println("Got the Request Token!"); - System.out.println("(if your curious it looks like this: " + requestToken + " )"); - System.out.println(); - - System.out.println("Now go and authorize Scribe here:"); - System.out.println(AUTHORIZE_URL + requestToken.getToken()); - System.out.println("And paste the verifier here"); - System.out.print(">>"); - Verifier verifier = new Verifier(in.nextLine()); - System.out.println(); - - // Trade the Request Token and Verfier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); - Token accessToken = service.getAccessToken(requestToken, verifier); - System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken + " )"); - System.out.println(); - - // Now let's go and ask for a protected resource! - System.out.println("Now we're going to access a protected resource..."); - OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); - service.signRequest(accessToken, request); - request.addHeader("GData-Version", "3.0"); - Response response = request.send(); - 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 Scribe! :)"); - - } -} \ No newline at end of file diff --git a/src/test/java/org/scribe/examples/ImgUrExample.java b/src/test/java/org/scribe/examples/ImgUrExample.java deleted file mode 100644 index 93fe91cb7..000000000 --- a/src/test/java/org/scribe/examples/ImgUrExample.java +++ /dev/null @@ -1,58 +0,0 @@ -package org.scribe.examples; - -import org.scribe.builder.*; -import org.scribe.builder.api.*; -import org.scribe.model.*; -import org.scribe.oauth.*; - -import java.util.*; - -public class ImgUrExample -{ - private static final String PROTECTED_RESOURCE_URL = "http://api.imgur.com/2/account.json"; - - public static void main(String[] args) - { - // Replace these with your own api key and secret (you'll need an read/write api key) - String apiKey = "your_app_id"; - String apiSecret = "your_api_secret"; - OAuthService service = new ServiceBuilder().provider(ImgUrApi.class).apiKey(apiKey).apiSecret(apiSecret).build(); - Scanner in = new Scanner(System.in); - - System.out.println("=== ImgUr's OAuth Workflow ==="); - System.out.println(); - - // Obtain the Request Token - System.out.println("Fetching the Request Token..."); - Token requestToken = service.getRequestToken(); - System.out.println("Got the Request Token!"); - System.out.println(); - - System.out.println("Now go and authorize Scribe here:"); - String authorizationUrl = service.getAuthorizationUrl(requestToken); - System.out.println(authorizationUrl); - System.out.println("And paste the verifier here"); - System.out.print(">>"); - Verifier verifier = new Verifier(in.nextLine()); - System.out.println(); - - // Trade the Request Token and Verfier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); - Token accessToken = service.getAccessToken(requestToken, verifier); - System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken + " )"); - System.out.println(); - - // Now let's go and ask for a protected resource! - System.out.println("Now we're going to access a protected resource..."); - OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); - service.signRequest(accessToken, request); - Response response = request.send(); - System.out.println("Got it! Lets see what we found..."); - System.out.println(); - System.out.println(response.getBody()); - - System.out.println(); - System.out.println("Thats it man! Go and build something awesome with Scribe! :)"); - } -} diff --git a/src/test/java/org/scribe/examples/Kaixin20Example.java b/src/test/java/org/scribe/examples/Kaixin20Example.java deleted file mode 100644 index b3e9d66ba..000000000 --- a/src/test/java/org/scribe/examples/Kaixin20Example.java +++ /dev/null @@ -1,63 +0,0 @@ -package org.scribe.examples; - -import org.scribe.builder.*; -import org.scribe.builder.api.*; -import org.scribe.model.*; -import org.scribe.oauth.*; -import java.util.*; - -public class Kaixin20Example -{ - private static final String NETWORK_NAME = "Kaixin"; - private static final String PROTECTED_RESOURCE_URL = "https://api.kaixin001.com/users/me.json"; - private static final Token EMPTY_TOKEN = null; - - public static void main(String[] args) - { - // Replace these with your own api key and secret - String apiKey = "your api key"; - String apiSecret = "your api secret"; - OAuthService service = new ServiceBuilder() - .provider(KaixinApi20.class) - .apiKey(apiKey) - .apiSecret(apiSecret) - .callback("http://your.domain.com/handle") - .build(); - 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..."); - String authorizationUrl = service.getAuthorizationUrl(EMPTY_TOKEN); - System.out.println("Got the Authorization URL!"); - System.out.println("Now go and authorize Scribe here:"); - System.out.println(authorizationUrl); - System.out.println("And paste the authorization code here"); - System.out.print(">>"); - Verifier verifier = new Verifier(in.nextLine()); - System.out.println(); - - // Trade the Request Token and Verifier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); - Token accessToken = service.getAccessToken(EMPTY_TOKEN, verifier); - System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken + " )"); - System.out.println(); - - // Now let's go and ask for a protected resource! - System.out.println("Now we're going to access a protected resource..."); - OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); - service.signRequest(accessToken, request); - Response response = request.send(); - 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 Scribe! :)"); - - } -} diff --git a/src/test/java/org/scribe/examples/LinkedInExample.java b/src/test/java/org/scribe/examples/LinkedInExample.java deleted file mode 100644 index 703cc8275..000000000 --- a/src/test/java/org/scribe/examples/LinkedInExample.java +++ /dev/null @@ -1,59 +0,0 @@ -package org.scribe.examples; - -import java.util.Scanner; - -import org.scribe.builder.*; -import org.scribe.builder.api.*; -import org.scribe.model.*; -import org.scribe.oauth.*; - -public class LinkedInExample -{ - private static final String PROTECTED_RESOURCE_URL = "http://api.linkedin.com/v1/people/~/connections:(id,last-name)"; - - public static void main(String[] args) - { - OAuthService service = new ServiceBuilder() - .provider(LinkedInApi.class) - .apiKey("CiEgwWDkA5BFpNrc0RfGyVuSlOh4tig5kOTZ9q97qcXNrFl7zqk-Ts7DqRGaKDCV") - .apiSecret("dhho4dfoCmiQXrkw4yslork5XWLFnPSuMR-8gscPVjY4jqFFHPYWJKgpFl4uLTM6") - .build(); - Scanner in = new Scanner(System.in); - - System.out.println("=== LinkedIn's OAuth Workflow ==="); - System.out.println(); - - // Obtain the Request Token - System.out.println("Fetching the Request Token..."); - Token requestToken = service.getRequestToken(); - System.out.println("Got the Request Token!"); - System.out.println(); - - System.out.println("Now go and authorize Scribe here:"); - System.out.println(service.getAuthorizationUrl(requestToken)); - System.out.println("And paste the verifier here"); - System.out.print(">>"); - Verifier verifier = new Verifier(in.nextLine()); - System.out.println(); - - // Trade the Request Token and Verfier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); - Token accessToken = service.getAccessToken(requestToken, verifier); - System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken + " )"); - System.out.println(); - - // Now let's go and ask for a protected resource! - System.out.println("Now we're going to access a protected resource..."); - OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); - service.signRequest(accessToken, request); - Response response = request.send(); - System.out.println("Got it! Lets see what we found..."); - System.out.println(); - System.out.println(response.getBody()); - - System.out.println(); - System.out.println("Thats it man! Go and build something awesome with Scribe! :)"); - } - -} diff --git a/src/test/java/org/scribe/examples/LinkedInExampleWithScopes.java b/src/test/java/org/scribe/examples/LinkedInExampleWithScopes.java deleted file mode 100644 index b8e8b2881..000000000 --- a/src/test/java/org/scribe/examples/LinkedInExampleWithScopes.java +++ /dev/null @@ -1,59 +0,0 @@ -package org.scribe.examples; - -import java.util.Scanner; - -import org.scribe.builder.*; -import org.scribe.builder.api.*; -import org.scribe.model.*; -import org.scribe.oauth.*; - -public class LinkedInExampleWithScopes -{ - private static final String PROTECTED_RESOURCE_URL = "http://api.linkedin.com/v1/people/~/connections:(id,last-name)"; - - public static void main(String[] args) - { - OAuthService service = new ServiceBuilder() - .provider(LinkedInApi.withScopes("foo", "bar", "baz")) - .apiKey("CiEgwWDkA5BFpNrc0RfGyVuSlOh4tig5kOTZ9q97qcXNrFl7zqk-Ts7DqRGaKDCV") - .apiSecret("dhho4dfoCmiQXrkw4yslork5XWLFnPSuMR-8gscPVjY4jqFFHPYWJKgpFl4uLTM6") - .build(); - Scanner in = new Scanner(System.in); - - System.out.println("=== LinkedIn's OAuth Workflow ==="); - System.out.println(); - - // Obtain the Request Token - System.out.println("Fetching the Request Token..."); - Token requestToken = service.getRequestToken(); - System.out.println("Got the Request Token!"); - System.out.println(); - - System.out.println("Now go and authorize Scribe here:"); - System.out.println(service.getAuthorizationUrl(requestToken)); - System.out.println("And paste the verifier here"); - System.out.print(">>"); - Verifier verifier = new Verifier(in.nextLine()); - System.out.println(); - - // Trade the Request Token and Verfier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); - Token accessToken = service.getAccessToken(requestToken, verifier); - System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken + " )"); - System.out.println(); - - // Now let's go and ask for a protected resource! - System.out.println("Now we're going to access a protected resource..."); - OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); - service.signRequest(accessToken, request); - Response response = request.send(); - System.out.println("Got it! Lets see what we found..."); - System.out.println(); - System.out.println(response.getBody()); - - System.out.println(); - System.out.println("Thats it man! Go and build something awesome with Scribe! :)"); - } - -} diff --git a/src/test/java/org/scribe/examples/LiveExample.java b/src/test/java/org/scribe/examples/LiveExample.java deleted file mode 100644 index ade5a6ba9..000000000 --- a/src/test/java/org/scribe/examples/LiveExample.java +++ /dev/null @@ -1,64 +0,0 @@ -package org.scribe.examples; - -import java.util.*; - -import org.scribe.builder.*; -import org.scribe.builder.api.*; -import org.scribe.model.*; -import org.scribe.oauth.*; - -public class LiveExample -{ - private static final String PROTECTED_RESOURCE_URL = "https://api.foursquare.com/v2/users/self/friends?oauth_token="; - private static final Token EMPTY_TOKEN = null; - - public static void main(String[] args) - { - // Replace these with your own api key and secret - String apiKey = ""; - String apiSecret = ""; - OAuthService service = new ServiceBuilder() - .provider(LiveApi.class) - .apiKey(apiKey) - .apiSecret(apiSecret) - .scope("wl.basic") - .callback("http://localhost:9000/") - .build(); - Scanner in = new Scanner(System.in); - - System.out.println("=== Windows Live's OAuth Workflow ==="); - System.out.println(); - - // Obtain the Authorization URL - System.out.println("Fetching the Authorization URL..."); - String authorizationUrl = service.getAuthorizationUrl(EMPTY_TOKEN); - System.out.println("Got the Authorization URL!"); - System.out.println("Now go and authorize Scribe here:"); - System.out.println(authorizationUrl); - System.out.println("And paste the authorization code here"); - System.out.print(">>"); - Verifier verifier = new Verifier(in.nextLine()); - System.out.println(); - - // Trade the Request Token and Verfier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); - Token accessToken = service.getAccessToken(EMPTY_TOKEN, verifier); - System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken + " )"); - System.out.println(); - - // Now let's go and ask for a protected resource! - System.out.println("Now we're going to access a protected resource..."); - OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL + accessToken.getToken()); - service.signRequest(accessToken, request); - Response response = request.send(); - 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 Scribe! :)"); - - } -} diff --git a/src/test/java/org/scribe/examples/LoveFilmExample.java b/src/test/java/org/scribe/examples/LoveFilmExample.java deleted file mode 100644 index 9e800161e..000000000 --- a/src/test/java/org/scribe/examples/LoveFilmExample.java +++ /dev/null @@ -1,64 +0,0 @@ -package org.scribe.examples; - -import java.util.*; - -import org.scribe.builder.*; -import org.scribe.builder.api.*; -import org.scribe.model.*; -import org.scribe.oauth.*; - -public class LoveFilmExample -{ - private static final String NETWORK_NAME = "LoveFilm"; - private static final String PROTECTED_RESOURCE_URL = "https://api.lovefilm.com/users"; - - public static void main(String[] args) - { - // Replace these with your own api key and secret - String apiKey = "your_key"; - String apiSecret = "your_secret"; - OAuthService service = new ServiceBuilder().provider(LoveFilmApi.class).apiKey(apiKey).apiSecret(apiSecret).build(); - Scanner in = new Scanner(System.in); - - System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); - System.out.println(); - - // Grab a request token. - System.out.println("Fetching request token."); - Token requestToken = service.getRequestToken(); - System.out.println("Got it ... "); - System.out.println(requestToken.getToken()); - - // Obtain the Authorization URL - System.out.println("Fetching the Authorization URL..."); - String authorizationUrl = service.getAuthorizationUrl(requestToken); - System.out.println("Got the Authorization URL!"); - System.out.println("Now go and authorize Scribe here:"); - System.out.println(authorizationUrl); - System.out.println("And paste the authorization code here"); - System.out.print(">>"); - Verifier verifier = new Verifier(in.nextLine()); - System.out.println(); - - // Trade the Request Token and Verfier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); - Token accessToken = service.getAccessToken(requestToken, verifier); - System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken + " )"); - System.out.println(); - - // Now let's go and ask for a protected resource! - System.out.println("Now we're going to access a protected resource..."); - OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); - service.signRequest(accessToken, request); - Response response = request.send(); - 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 Scribe! :)"); - - } -} diff --git a/src/test/java/org/scribe/examples/MeetupExample.java b/src/test/java/org/scribe/examples/MeetupExample.java deleted file mode 100644 index 2185b5c27..000000000 --- a/src/test/java/org/scribe/examples/MeetupExample.java +++ /dev/null @@ -1,62 +0,0 @@ -package org.scribe.examples; - -import java.util.Scanner; - -import org.scribe.builder.ServiceBuilder; -import org.scribe.builder.api.MeetupApi; -import org.scribe.model.OAuthRequest; -import org.scribe.model.Response; -import org.scribe.model.Token; -import org.scribe.model.Verb; -import org.scribe.model.Verifier; -import org.scribe.oauth.OAuthService; - -public class MeetupExample -{ - private static final String PROTECTED_RESOURCE_URL = "http://api.meetup.com/2/member/self"; - - public static void main(String[] args) - { - OAuthService service = new ServiceBuilder() - .provider(MeetupApi.class) - .apiKey("j1khkp0dus323ftve0sdcv6ffe") - .apiSecret("6s6gt6q59gvfjtsvgcmht62gq4") - .build(); - Scanner in = new Scanner(System.in); - - System.out.println("=== Meetup's OAuth Workflow ==="); - System.out.println(); - - // Obtain the Request Token - System.out.println("Fetching the Request Token..."); - Token requestToken = service.getRequestToken(); - System.out.println("Got the Request Token!"); - System.out.println(); - - System.out.println("Now go and authorize Scribe here:"); - System.out.println(service.getAuthorizationUrl(requestToken)); - System.out.println("And paste the verifier here"); - System.out.print(">>"); - Verifier verifier = new Verifier(in.nextLine()); - System.out.println(); - - // Trade the Request Token and Verfier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); - Token accessToken = service.getAccessToken(requestToken, verifier); - System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken + " )"); - System.out.println(); - - // Now let's go and ask for a protected resource! - System.out.println("Now we're going to access a protected resource..."); - OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); - service.signRequest(accessToken, request); - Response response = request.send(); - System.out.println("Got it! Lets see what we found..."); - System.out.println(); - System.out.println(response.getBody()); - - System.out.println(); - System.out.println("Thats it man! Go and build something awesome with Scribe! :)"); - } -} diff --git a/src/test/java/org/scribe/examples/NeteaseWeiboExample.java b/src/test/java/org/scribe/examples/NeteaseWeiboExample.java deleted file mode 100644 index e65335e76..000000000 --- a/src/test/java/org/scribe/examples/NeteaseWeiboExample.java +++ /dev/null @@ -1,68 +0,0 @@ -package org.scribe.examples; - -import java.util.*; - -import org.scribe.builder.*; -import org.scribe.builder.api.*; -import org.scribe.model.*; -import org.scribe.oauth.*; - -public class NeteaseWeiboExample -{ - private static final String NETWORK_NAME = "NetEase(163.com) Weibo"; - private static final String PROTECTED_RESOURCE_URL = "http://api.t.163.com/account/verify_credentials.json"; - - public static void main(String[] args) - { - // Replace these with your own api key and secret - String apiKey = "your key"; - String apiSecret = "your secret"; - OAuthService service = new ServiceBuilder() - .provider(NeteaseWeibooApi.class) - .apiKey(apiKey) - .apiSecret(apiSecret) - .build(); - Scanner in = new Scanner(System.in); - - System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); - System.out.println(); - - // Grab a request token. - System.out.println("Fetching request token."); - Token requestToken = service.getRequestToken(); - System.out.println("Got it ... "); - System.out.println(requestToken.getToken()); - - // Obtain the Authorization URL - System.out.println("Fetching the Authorization URL..."); - String authorizationUrl = service.getAuthorizationUrl(requestToken); - System.out.println("Got the Authorization URL!"); - System.out.println("Now go and authorize Scribe here:"); - System.out.println(authorizationUrl); - System.out.println("And paste the authorization code here"); - System.out.print(">>"); - Verifier verifier = new Verifier(in.nextLine()); - System.out.println(); - - // Trade the Request Token and Verfier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); - Token accessToken = service.getAccessToken(requestToken, verifier); - System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " - + accessToken + " )"); - System.out.println(); - - // Now let's go and ask for a protected resource! - System.out.println("Now we're going to access a protected resource..."); - OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); - service.signRequest(accessToken, request); - Response response = request.send(); - 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 Scribe! :)"); - } -} diff --git a/src/test/java/org/scribe/examples/Px500Example.java b/src/test/java/org/scribe/examples/Px500Example.java deleted file mode 100644 index cdbe44997..000000000 --- a/src/test/java/org/scribe/examples/Px500Example.java +++ /dev/null @@ -1,60 +0,0 @@ -package org.scribe.examples; - -import java.util.Scanner; - -import org.scribe.builder.*; -import org.scribe.builder.api.*; -import org.scribe.model.*; -import org.scribe.oauth.*; - -public class Px500Example -{ - private static final String PROTECTED_RESOURCE_URL = "https://api.500px.com/v1/"; - - public static void main(String[] args) - { - OAuthService service = new ServiceBuilder() - .provider(Px500Api.class) - .apiKey("your-api-key") - .apiSecret("your-api-secret") - .build(); - Scanner in = new Scanner(System.in); - - System.out.println("=== 500Px's OAuth Workflow ==="); - System.out.println(); - - // Obtain the Request Token - System.out.println("Fetching the Request Token..."); - Token requestToken = service.getRequestToken(); - System.out.println("Got the Request Token!"); - System.out.println(); - - System.out.println("Now go and authorize Scribe here:"); - System.out.println(service.getAuthorizationUrl(requestToken)); - System.out.println("And paste the verifier here"); - System.out.print(">>"); - Verifier verifier = new Verifier(in.nextLine()); - System.out.println(); - - // Trade the Request Token and Verfier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); - Token accessToken = service.getAccessToken(requestToken, verifier); - System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken + " )"); - System.out.println(); - - // Now let's go and ask for a protected resource! - System.out.println("Now we're going to access a protected resource..."); - OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); - service.signRequest(accessToken, request); - Response response = request.send(); - System.out.println("Got it! Lets see what we found..."); - System.out.println(); - System.out.println(response.getBody()); - - System.out.println(); - System.out.println("Thats it man! Go and build something awesome with Scribe! :)"); - - } - -} \ No newline at end of file diff --git a/src/test/java/org/scribe/examples/RenrenExample.java b/src/test/java/org/scribe/examples/RenrenExample.java deleted file mode 100644 index ae13375b8..000000000 --- a/src/test/java/org/scribe/examples/RenrenExample.java +++ /dev/null @@ -1,108 +0,0 @@ -package org.scribe.examples; - -import org.scribe.builder.*; -import org.scribe.builder.api.*; -import org.scribe.model.*; -import org.scribe.oauth.*; -import java.nio.charset.*; -import java.security.*; -import java.util.*; - -public class RenrenExample -{ - private static final String NETWORK_NAME = "Renren"; - private static final String PROTECTED_RESOURCE_URL = "http://api.renren.com/restserver.do"; - private static final Token EMPTY_TOKEN = null; - - public static void main(String[] args) - { - // Replace these with your own api key and secret - String apiKey = "your api key"; - String apiSecret = "your api secret"; - OAuthService service = new ServiceBuilder() - .provider(RenrenApi.class) - .apiKey(apiKey) - .apiSecret(apiSecret) - .scope("status_update publish_feed") - .callback("http://your.doman.com/oauth/renren") - .build(); - 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..."); - String authorizationUrl = service.getAuthorizationUrl(EMPTY_TOKEN); - System.out.println("Got the Authorization URL!"); - System.out.println("Now go and authorize Scribe here:"); - System.out.println(authorizationUrl); - System.out.println("And paste the authorization code here"); - System.out.print(">>"); - Verifier verifier = new Verifier(in.nextLine()); - System.out.println(); - - // Trade the Request Token and Verfier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); - Token accessToken = service.getAccessToken(EMPTY_TOKEN, verifier); - System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken + " )"); - System.out.println(); - - // Now let's go and ask for a protected resource! - System.out.println("Now we're going to access a protected resource..."); - OAuthRequest request = new OAuthRequest(Verb.POST, PROTECTED_RESOURCE_URL); - Map parameters = new HashMap(); - parameters.put("method", "users.getInfo"); - parameters.put("format", "json"); - parameters.put("v", "1.0"); - - List sigString = new ArrayList(parameters.size() + 1); - for (Map.Entry entry : parameters.entrySet()) - { - request.addQuerystringParameter(entry.getKey(), entry.getValue()); - sigString.add(String.format("%s=%s", entry.getKey(), entry.getValue())); - } - sigString.add(String.format("%s=%s", OAuthConstants.ACCESS_TOKEN, accessToken.getToken())); - Collections.sort(sigString); - StringBuilder b = new StringBuilder(); - for (String param : sigString) - { - b.append(param); - } - b.append(apiSecret); - System.out.println("Sig string: " + b.toString()); - request.addQuerystringParameter("sig", md5(b.toString())); - service.signRequest(accessToken, request); - Response response = request.send(); - 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 Scribe! :)"); - - } - - public static String md5(String orgString) - { - try - { - java.security.MessageDigest md = MessageDigest.getInstance("MD5"); - byte[] array = md.digest(orgString.getBytes(Charset.forName("UTF-8"))); - StringBuffer sb = new StringBuffer(); - for (int i = 0; i < array.length; ++i) - { - sb.append(Integer.toHexString((array[i] & 0xFF) | 0x100).substring(1, 3)); - } - return sb.toString(); - } - catch (NoSuchAlgorithmException e) - { - e.printStackTrace(); - } - return null; - } - -} diff --git a/src/test/java/org/scribe/examples/SinaWeibo2Example.java b/src/test/java/org/scribe/examples/SinaWeibo2Example.java deleted file mode 100644 index 89b14e117..000000000 --- a/src/test/java/org/scribe/examples/SinaWeibo2Example.java +++ /dev/null @@ -1,63 +0,0 @@ -package org.scribe.examples; - -import org.scribe.builder.*; -import org.scribe.builder.api.*; -import org.scribe.model.*; -import org.scribe.oauth.*; -import java.util.*; - -public class SinaWeibo2Example -{ - private static final String NETWORK_NAME = "SinaWeibo"; - private static final String PROTECTED_RESOURCE_URL = "https://api.weibo.com/2/account/get_uid.json"; - private static final Token EMPTY_TOKEN = null; - - public static void main(String[] args) - { - // Replace these with your own api key and secret - String apiKey = "your_api_key"; - String apiSecret = "your_api_secret"; - OAuthService service = new ServiceBuilder() - .provider(SinaWeiboApi20.class) - .apiKey(apiKey) - .apiSecret(apiSecret) - .callback("http://www.dajie.com/oauth/sina") - .build(); - 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..."); - String authorizationUrl = service.getAuthorizationUrl(EMPTY_TOKEN); - System.out.println("Got the Authorization URL!"); - System.out.println("Now go and authorize Scribe here:"); - System.out.println(authorizationUrl); - System.out.println("And paste the authorization code here"); - System.out.print(">>"); - Verifier verifier = new Verifier(in.nextLine()); - System.out.println(); - - // Trade the Request Token and Verifier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); - Token accessToken = service.getAccessToken(EMPTY_TOKEN, verifier); - System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken + " )"); - System.out.println(); - - // Now let's go and ask for a protected resource! - System.out.println("Now we're going to access a protected resource..."); - OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); - service.signRequest(accessToken, request); - Response response = request.send(); - 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 Scribe! :)"); - - } -} diff --git a/src/test/java/org/scribe/examples/SinaWeiboExample.java b/src/test/java/org/scribe/examples/SinaWeiboExample.java deleted file mode 100644 index 2dc4b7c04..000000000 --- a/src/test/java/org/scribe/examples/SinaWeiboExample.java +++ /dev/null @@ -1,68 +0,0 @@ -package org.scribe.examples; - -import java.util.*; - -import org.scribe.builder.*; -import org.scribe.builder.api.*; -import org.scribe.model.*; -import org.scribe.oauth.*; - -public class SinaWeiboExample -{ - private static final String NETWORK_NAME = "SinaWeibo"; - private static final String PROTECTED_RESOURCE_URL = "http://api.t.sina.com.cn/account/verify_credentials.json"; - - public static void main(String[] args) - { - // Replace these with your own api key and secret - String apiKey = "your key"; - String apiSecret = "your secret"; - OAuthService service = new ServiceBuilder() - .provider(SinaWeiboApi.class) - .apiKey(apiKey) - .apiSecret(apiSecret) - .build(); - Scanner in = new Scanner(System.in); - - System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); - System.out.println(); - - // Grab a request token. - System.out.println("Fetching request token."); - Token requestToken = service.getRequestToken(); - System.out.println("Got it ... "); - System.out.println(requestToken.getToken()); - - // Obtain the Authorization URL - System.out.println("Fetching the Authorization URL..."); - String authorizationUrl = service.getAuthorizationUrl(requestToken); - System.out.println("Got the Authorization URL!"); - System.out.println("Now go and authorize Scribe here:"); - System.out.println(authorizationUrl); - System.out.println("And paste the authorization code here"); - System.out.print(">>"); - Verifier verifier = new Verifier(in.nextLine()); - System.out.println(); - - // Trade the Request Token and Verfier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); - Token accessToken = service.getAccessToken(requestToken, verifier); - System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " - + accessToken + " )"); - System.out.println(); - - // Now let's go and ask for a protected resource! - System.out.println("Now we're going to access a protected resource..."); - OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); - service.signRequest(accessToken, request); - Response response = request.send(); - 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 Scribe! :)"); - } -} diff --git a/src/test/java/org/scribe/examples/SkyrockExample.java b/src/test/java/org/scribe/examples/SkyrockExample.java deleted file mode 100644 index 422d067e5..000000000 --- a/src/test/java/org/scribe/examples/SkyrockExample.java +++ /dev/null @@ -1,61 +0,0 @@ -package org.scribe.examples; - -import java.util.Scanner; - -import org.scribe.builder.*; -import org.scribe.builder.api.*; -import org.scribe.model.*; -import org.scribe.oauth.*; - -public class SkyrockExample -{ - private static final String PROTECTED_RESOURCE_URL = "https://api.skyrock.com/v2/user/get.json"; - - public static void main(String[] args) - { - OAuthService service = new ServiceBuilder() - .provider(SkyrockApi.class) - .apiKey("your-api-key") - .apiSecret("your-api-secret") - .build(); - Scanner in = new Scanner(System.in); - - System.out.println("=== Skyrock's OAuth Workflow ==="); - System.out.println(); - - // Obtain the Request Token - System.out.println("Fetching the Request Token..."); - Token requestToken = service.getRequestToken(); - System.out.println("Got the Request Token!"); - System.out.println(); - - System.out.println("Now go and authorize Scribe here:"); - System.out.println(service.getAuthorizationUrl(requestToken)); - System.out.println("And paste the verifier here"); - System.out.print(">>"); - Verifier verifier = new Verifier(in.nextLine()); - System.out.println(); - - // Trade the Request Token and Verfier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); - Token accessToken = service.getAccessToken(requestToken, verifier); - System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken + " )"); - System.out.println(); - - // Now let's go and ask for a protected resource! - System.out.println("Now we're going to access a protected resource..."); - OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); - service.signRequest(accessToken, request); - Response response = request.send(); - 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 Scribe! :)"); - - } - -} diff --git a/src/test/java/org/scribe/examples/SohuWeiboExample.java b/src/test/java/org/scribe/examples/SohuWeiboExample.java deleted file mode 100644 index 49dd9fb72..000000000 --- a/src/test/java/org/scribe/examples/SohuWeiboExample.java +++ /dev/null @@ -1,68 +0,0 @@ -package org.scribe.examples; - -import java.util.*; - -import org.scribe.builder.*; -import org.scribe.builder.api.*; -import org.scribe.model.*; -import org.scribe.oauth.*; - -public class SohuWeiboExample -{ - private static final String NETWORK_NAME = "SohuWeibo"; - private static final String PROTECTED_RESOURCE_URL = "http://api.t.sohu.com/account/verify_credentials.json"; - - public static void main(String[] args) - { - // Replace these with your own api key and secret - String apiKey = "your_key"; - String apiSecret = "your_secret"; - OAuthService service = new ServiceBuilder() - .provider(SohuWeiboApi.class) - .apiKey(apiKey) - .apiSecret(apiSecret) - .build(); - Scanner in = new Scanner(System.in); - - System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); - System.out.println(); - - // Grab a request token. - System.out.println("Fetching request token."); - Token requestToken = service.getRequestToken(); - System.out.println("Got it ... "); - System.out.println(requestToken.getToken()); - - // Obtain the Authorization URL - System.out.println("Fetching the Authorization URL..."); - String authorizationUrl = service.getAuthorizationUrl(requestToken); - System.out.println("Got the Authorization URL!"); - System.out.println("Now go and authorize Scribe here:"); - System.out.println(authorizationUrl); - System.out.println("And paste the authorization code here"); - System.out.print(">>"); - Verifier verifier = new Verifier(in.nextLine()); - System.out.println(); - - // Trade the Request Token and Verfier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); - Token accessToken = service.getAccessToken(requestToken, verifier); - System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " - + accessToken + " )"); - System.out.println(); - - // Now let's go and ask for a protected resource! - System.out.println("Now we're going to access a protected resource..."); - OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); - service.signRequest(accessToken, request); - Response response = request.send(); - 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 Scribe! :)"); - } -} diff --git a/src/test/java/org/scribe/examples/TrelloExample.java b/src/test/java/org/scribe/examples/TrelloExample.java deleted file mode 100644 index 9888f5e90..000000000 --- a/src/test/java/org/scribe/examples/TrelloExample.java +++ /dev/null @@ -1,60 +0,0 @@ -package org.scribe.examples; - -import java.util.Scanner; - -import org.scribe.builder.*; -import org.scribe.builder.api.*; -import org.scribe.model.*; -import org.scribe.oauth.*; - -public class TrelloExample -{ - private static final String API_KEY = "your_api_key"; - private static final String API_SECRET = "your_api_secret"; - private static final String PROTECTED_RESOURCE_URL = "https://trello.com/1/members/me"; - public static void main(String[] args) - { - OAuthService service = new ServiceBuilder() - .provider(TrelloApi.class) - .apiKey(API_KEY) - .apiSecret(API_SECRET) - .build(); - Scanner in = new Scanner(System.in); - - System.out.println("=== Trello's OAuth Workflow ==="); - System.out.println(); - - // Obtain the Request Token - System.out.println("Fetching the Request Token..."); - Token requestToken = service.getRequestToken(); - System.out.println("Got the Request Token!"); - System.out.println(); - - System.out.println("Now go and authorize Scribe here:"); - System.out.println(service.getAuthorizationUrl(requestToken)); - System.out.println("And paste the verifier here"); - System.out.print(">>"); - Verifier verifier = new Verifier(in.nextLine()); - System.out.println(); - - // Trade the Request Token and Verfier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); - Token accessToken = service.getAccessToken(requestToken, verifier); - System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken + " )"); - System.out.println(); - - // Now let's go and ask for a protected resource! - System.out.println("Now we're going to access a protected resource..."); - OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); - service.signRequest(accessToken, request); - Response response = request.send(); - System.out.println("Got it! Lets see what we found..."); - System.out.println(); - System.out.println(response.getBody()); - - System.out.println(); - System.out.println("Thats it man! Go and build something awesome with Scribe! :)"); - } - -} diff --git a/src/test/java/org/scribe/examples/TumblrExample.java b/src/test/java/org/scribe/examples/TumblrExample.java deleted file mode 100644 index d024efbc0..000000000 --- a/src/test/java/org/scribe/examples/TumblrExample.java +++ /dev/null @@ -1,62 +0,0 @@ -package org.scribe.examples; - -import java.util.Scanner; - -import org.scribe.builder.*; -import org.scribe.builder.api.*; -import org.scribe.model.*; -import org.scribe.oauth.*; - -public class TumblrExample -{ - private static final String PROTECTED_RESOURCE_URL = "http://api.tumblr.com/v2/user/info"; - - public static void main( String[] args ) - { - OAuthService service = new ServiceBuilder() - .provider( TumblrApi.class ) - .apiKey( "MY_CONSUMER_KEY" ) - .apiSecret( "MY_CONSUMER_SECRET" ) - .callback( "http://www.tumblr.com/connect/login_success.html" ) // OOB forbidden. We need an url and the better is on the tumblr website ! - .build(); - Scanner in = new Scanner( System.in ); - - System.out.println( "=== Tumblr's OAuth Workflow ===" ); - System.out.println(); - - // Obtain the Request Token - System.out.println( "Fetching the Request Token..." ); - Token requestToken = service.getRequestToken(); - System.out.println( "Got the Request Token!" ); - System.out.println(); - - System.out.println( "Now go and authorize Scribe here:" ); - System.out.println( service.getAuthorizationUrl( requestToken ) ); - System.out.println( "And paste the verifier here" ); - System.out.print( ">>" ); - Verifier verifier = new Verifier( in.nextLine() ); - System.out.println(); - - // Trade the Request Token and Verfier for the Access Token - System.out.println( "Trading the Request Token for an Access Token..." ); - Token accessToken = service.getAccessToken( requestToken , - verifier ); - System.out.println( "Got the Access Token!" ); - System.out.println( "(if your curious it looks like this: " + accessToken + " )" ); - System.out.println(); - - // Now let's go and ask for a protected resource! - System.out.println( "Now we're going to access a protected resource..." ); - OAuthRequest request = new OAuthRequest( Verb.GET , - PROTECTED_RESOURCE_URL ); - service.signRequest( accessToken , - request ); - Response response = request.send(); - System.out.println( "Got it! Lets see what we found..." ); - System.out.println(); - System.out.println( response.getBody() ); - - System.out.println(); - System.out.println( "Thats it man! Go and build something awesome with Scribe! :)" ); - } -} diff --git a/src/test/java/org/scribe/examples/TwitterExample.java b/src/test/java/org/scribe/examples/TwitterExample.java deleted file mode 100644 index 0cfbdfb6b..000000000 --- a/src/test/java/org/scribe/examples/TwitterExample.java +++ /dev/null @@ -1,60 +0,0 @@ -package org.scribe.examples; - -import java.util.Scanner; - -import org.scribe.builder.*; -import org.scribe.builder.api.*; -import org.scribe.model.*; -import org.scribe.oauth.*; - -public class TwitterExample -{ - private static final String PROTECTED_RESOURCE_URL = "https://api.twitter.com/1.1/account/verify_credentials.json"; - - public static void main(String[] args) - { - // If you choose to use a callback, "oauth_verifier" will be the return value by Twitter (request param) - OAuthService service = new ServiceBuilder() - .provider(TwitterApi.class) - .apiKey("6icbcAXyZx67r8uTAUM5Qw") - .apiSecret("SCCAdUUc6LXxiazxH3N0QfpNUvlUy84mZ2XZKiv39s") - .build(); - Scanner in = new Scanner(System.in); - - System.out.println("=== Twitter's OAuth Workflow ==="); - System.out.println(); - - // Obtain the Request Token - System.out.println("Fetching the Request Token..."); - Token requestToken = service.getRequestToken(); - System.out.println("Got the Request Token!"); - System.out.println(); - - System.out.println("Now go and authorize Scribe here:"); - System.out.println(service.getAuthorizationUrl(requestToken)); - System.out.println("And paste the verifier here"); - System.out.print(">>"); - Verifier verifier = new Verifier(in.nextLine()); - System.out.println(); - - // Trade the Request Token and Verfier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); - Token accessToken = service.getAccessToken(requestToken, verifier); - System.out.println("Got the Access Token!"); - System.out.println("(if you're curious, it looks like this: " + accessToken + " )"); - System.out.println(); - - // Now let's go and ask for a protected resource! - System.out.println("Now we're going to access a protected resource..."); - OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); - service.signRequest(accessToken, request); - Response response = request.send(); - System.out.println("Got it! Lets see what we found..."); - System.out.println(); - System.out.println(response.getBody()); - - System.out.println(); - System.out.println("That's it man! Go and build something awesome with Scribe! :)"); - } - -} diff --git a/src/test/java/org/scribe/examples/ViadeoExample.java b/src/test/java/org/scribe/examples/ViadeoExample.java deleted file mode 100644 index ebb438532..000000000 --- a/src/test/java/org/scribe/examples/ViadeoExample.java +++ /dev/null @@ -1,64 +0,0 @@ -package org.scribe.examples; - -import java.util.*; - -import org.scribe.builder.*; -import org.scribe.builder.api.*; -import org.scribe.model.*; -import org.scribe.oauth.*; - -public class ViadeoExample -{ - private static final String NETWORK_NAME = "Viadeo"; - private static final String PROTECTED_RESOURCE_URL = "https://api.viadeo.com/me?user_detail=full"; - private static final Token EMPTY_TOKEN = null; - - public static void main(String[] args) - { - // Replace these with your own api key and secret - String apiKey = "your_app_id"; - String apiSecret = "your_api_secret"; - OAuthService service = new ServiceBuilder() - .provider(ViadeoApi.class) - .apiKey(apiKey) - .apiSecret(apiSecret) - .callback("http://www.example.com/oauth_callback/") - .build(); - 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..."); - String authorizationUrl = service.getAuthorizationUrl(EMPTY_TOKEN); - System.out.println("Got the Authorization URL!"); - System.out.println("Now go and authorize Scribe here:"); - System.out.println(authorizationUrl); - System.out.println("And paste the authorization code here"); - System.out.print(">>"); - Verifier verifier = new Verifier(in.nextLine()); - System.out.println(); - - // Trade the Request Token and Verfier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); - Token accessToken = service.getAccessToken(EMPTY_TOKEN, verifier); - System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken + " )"); - System.out.println(); - - // Now let's go and ask for a protected resource! - System.out.println("Now we're going to access a protected resource..."); - OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); - service.signRequest(accessToken, request); - Response response = request.send(); - 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 Scribe! :)"); - - } -} diff --git a/src/test/java/org/scribe/examples/VkontakteExample.java b/src/test/java/org/scribe/examples/VkontakteExample.java deleted file mode 100644 index f9e4134e7..000000000 --- a/src/test/java/org/scribe/examples/VkontakteExample.java +++ /dev/null @@ -1,68 +0,0 @@ -package org.scribe.examples; - -import org.scribe.builder.*; -import org.scribe.builder.api.*; -import org.scribe.model.*; -import org.scribe.oauth.*; - -import java.util.*; - -/** - * @author Boris G. Tsirkin - * @since 20.4.2011 - */ -public class VkontakteExample -{ - private static final String NETWORK_NAME = "Vkontakte.ru"; - private static final String PROTECTED_RESOURCE_URL = "https://api.vkontakte.ru/method/friends.get"; - private static final Token EMPTY_TOKEN = null; - - public static void main(String[] args) - { - // Replace these with your own api key and secret - final String clientId = "your app id"; - final String apiSecret = "your api secret"; - OAuthService service = new ServiceBuilder() - .provider(VkontakteApi.class) - .apiKey(clientId) - .apiSecret(apiSecret) - .scope("friends,wall,offline") // replace with desired scope - .callback("http://your.site.com/callback") - .build(); - 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..."); - String authorizationUrl = service.getAuthorizationUrl(EMPTY_TOKEN); - System.out.println("Got the Authorization URL!"); - System.out.println("Now go and authorize Scribe here:"); - System.out.println(authorizationUrl); - System.out.println("And paste the authorization code here"); - System.out.print(">>"); - Verifier verifier = new Verifier(in.nextLine()); - System.out.println(); - - // Trade the Request Token and Verfier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); - Token accessToken = service.getAccessToken(EMPTY_TOKEN, verifier); - System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken + " )"); - System.out.println(); - - // Now let's go and ask for a protected resource! - System.out.println("Now we're going to access a protected resource..."); - OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); - service.signRequest(accessToken, request); - Response response = request.send(); - 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 Scribe! :)"); - } -} diff --git a/src/test/java/org/scribe/examples/XingExample.java b/src/test/java/org/scribe/examples/XingExample.java deleted file mode 100755 index 93d7080c4..000000000 --- a/src/test/java/org/scribe/examples/XingExample.java +++ /dev/null @@ -1,59 +0,0 @@ -package org.scribe.examples; - -import java.util.Scanner; - -import org.scribe.builder.*; -import org.scribe.builder.api.*; -import org.scribe.model.*; -import org.scribe.oauth.*; - -public class XingExample -{ - private static final String PROTECTED_RESOURCE_URL = "https://api.xing.com/v1/users/me"; - - public static void main(String[] args) - { - OAuthService service = new ServiceBuilder() - .provider(XingApi.class) - .apiKey("097ccfd3ef25a1cb6d75") - .apiSecret("e43364b2afd5d92f2ec28951a75bd8075f9cc221") - .build(); - Scanner in = new Scanner(System.in); - - System.out.println("=== Xing's OAuth Workflow ==="); - System.out.println(); - - // Obtain the Request Token - System.out.println("Fetching the Request Token..."); - Token requestToken = service.getRequestToken(); - System.out.println("Got the Request Token!"); - System.out.println(); - - System.out.println("Now go and authorize Scribe here:"); - System.out.println(service.getAuthorizationUrl(requestToken)); - System.out.println("And paste the verifier here"); - System.out.print(">>"); - Verifier verifier = new Verifier(in.nextLine()); - System.out.println(); - - // Trade the Request Token and Verfier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); - Token accessToken = service.getAccessToken(requestToken, verifier); - System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken + " )"); - System.out.println(); - - // Now let's go and ask for a protected resource! - System.out.println("Now we're going to access a protected resource..."); - OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); - service.signRequest(accessToken, request); - Response response = request.send(); - System.out.println("Got it! Lets see what we found..."); - System.out.println(); - System.out.println(response.getBody()); - - System.out.println(); - System.out.println("Thats it man! Go and build something awesome with Scribe! :)"); - } - -} diff --git a/src/test/java/org/scribe/examples/YahooExample.java b/src/test/java/org/scribe/examples/YahooExample.java deleted file mode 100644 index 2e3f336f0..000000000 --- a/src/test/java/org/scribe/examples/YahooExample.java +++ /dev/null @@ -1,60 +0,0 @@ -package org.scribe.examples; - -import java.util.Scanner; - -import org.scribe.builder.*; -import org.scribe.builder.api.*; -import org.scribe.model.*; -import org.scribe.oauth.*; - -public class YahooExample -{ - private static final String PROTECTED_RESOURCE_URL = "http://social.yahooapis.com/v1/user/A6ROU63MXWDCW3Y5MGCYWVHDJI/profile/status?format=json"; - - public static void main(String[] args) - { - OAuthService service = new ServiceBuilder() - .provider(YahooApi.class) - .apiKey("dj0yJmk9TXZDWVpNVVdGaVFmJmQ9WVdrOWMweHZXbkZLTkhVbWNHbzlNVEl5TWprd05qUTJNZy0tJnM9Y29uc3VtZXJzZWNyZXQmeD0wMw--") - .apiSecret("262be559f92a2be20c4c039419018f2b48cdfce9") - .build(); - Scanner in = new Scanner(System.in); - - System.out.println("=== Yahoo's OAuth Workflow ==="); - System.out.println(); - - // Obtain the Request Token - System.out.println("Fetching the Request Token..."); - Token requestToken = service.getRequestToken(); - System.out.println("Got the Request Token!"); - System.out.println(); - - System.out.println("Now go and authorize Scribe here:"); - System.out.println(service.getAuthorizationUrl(requestToken)); - System.out.println("And paste the verifier here"); - System.out.print(">>"); - Verifier verifier = new Verifier(in.nextLine()); - System.out.println(); - - // Trade the Request Token and Verfier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); - Token accessToken = service.getAccessToken(requestToken, verifier); - System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken + " )"); - System.out.println(); - - // Now let's go and ask for a protected resource! - System.out.println("Now we're going to access a protected resource..."); - OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); - service.signRequest(accessToken, request); - Response response = request.send(); - 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 Scribe! :)"); - - } -} diff --git a/src/test/java/org/scribe/extractors/BaseStringExtractorTest.java b/src/test/java/org/scribe/extractors/BaseStringExtractorTest.java deleted file mode 100644 index 0fac0823c..000000000 --- a/src/test/java/org/scribe/extractors/BaseStringExtractorTest.java +++ /dev/null @@ -1,102 +0,0 @@ -package org.scribe.extractors; - -import static org.junit.Assert.*; - -import org.junit.*; -import org.scribe.exceptions.*; -import org.scribe.model.*; -import org.scribe.test.helpers.*; - -public class BaseStringExtractorTest -{ - - private BaseStringExtractorImpl extractor; - private OAuthRequest request; - private OAuthRequest requestPort80; - private OAuthRequest requestPort80_2; - private OAuthRequest requestPort8080; - private OAuthRequest requestPort443; - private OAuthRequest requestPort443_2; - - @Before - public void setup() - { - request = ObjectMother.createSampleOAuthRequest(); - requestPort80 = ObjectMother.createSampleOAuthRequestPort80(); - requestPort80_2 = ObjectMother.createSampleOAuthRequestPort80_2(); - requestPort8080 = ObjectMother.createSampleOAuthRequestPort8080(); - requestPort443 = ObjectMother.createSampleOAuthRequestPort443(); - requestPort443_2 = ObjectMother.createSampleOAuthRequestPort443_2(); - extractor = new BaseStringExtractorImpl(); - } - - @Test - public void shouldExtractBaseStringFromOAuthRequest() - { - String expected = "GET&http%3A%2F%2Fexample.com&oauth_callback%3Dhttp%253A%252F%252Fexample%252Fcallback%26oauth_consumer_key%3DAS%2523%2524%255E%252A%2540%2526%26oauth_signature%3DOAuth-Signature%26oauth_timestamp%3D123456"; - String baseString = extractor.extract(request); - assertEquals(expected, baseString); - } - - @Test - public void shouldExcludePort80() - { - String expected = "GET&http%3A%2F%2Fexample.com&oauth_callback%3Dhttp%253A%252F%252Fexample%252Fcallback%26oauth_consumer_key%3DAS%2523%2524%255E%252A%2540%2526%26oauth_signature%3DOAuth-Signature%26oauth_timestamp%3D123456"; - String baseString = extractor.extract(requestPort80); - assertEquals(expected, baseString); - } - - @Test - public void shouldExcludePort80_2() - { - String expected = "GET&http%3A%2F%2Fexample.com%2Ftest&oauth_callback%3Dhttp%253A%252F%252Fexample%252Fcallback%26oauth_consumer_key%3DAS%2523%2524%255E%252A%2540%2526%26oauth_signature%3DOAuth-Signature%26oauth_timestamp%3D123456"; - String baseString = extractor.extract(requestPort80_2); - assertEquals(expected, baseString); - } - - @Test - public void shouldIncludePort8080() - { - String expected = "GET&http%3A%2F%2Fexample.com%3A8080&oauth_callback%3Dhttp%253A%252F%252Fexample%252Fcallback%26oauth_consumer_key%3DAS%2523%2524%255E%252A%2540%2526%26oauth_signature%3DOAuth-Signature%26oauth_timestamp%3D123456"; - String baseString = extractor.extract(requestPort8080); - assertEquals(expected, baseString); - } - - @Test - public void shouldExcludePort443() - { - String expected = "GET&https%3A%2F%2Fexample.com&oauth_callback%3Dhttp%253A%252F%252Fexample%252Fcallback%26oauth_consumer_key%3DAS%2523%2524%255E%252A%2540%2526%26oauth_signature%3DOAuth-Signature%26oauth_timestamp%3D123456"; - String baseString = extractor.extract(requestPort443); - assertEquals(expected, baseString); - } - - @Test - public void shouldExcludePort443_2() - { - String expected = "GET&https%3A%2F%2Fexample.com%2Ftest&oauth_callback%3Dhttp%253A%252F%252Fexample%252Fcallback%26oauth_consumer_key%3DAS%2523%2524%255E%252A%2540%2526%26oauth_signature%3DOAuth-Signature%26oauth_timestamp%3D123456"; - String baseString = extractor.extract(requestPort443_2); - assertEquals(expected, baseString); - } - - @Test(expected = IllegalArgumentException.class) - public void shouldThrowExceptionIfRquestIsNull() - { - OAuthRequest nullRequest = null; - extractor.extract(nullRequest); - } - - @Test(expected = OAuthParametersMissingException.class) - public void shouldThrowExceptionIfRquestHasNoOAuthParameters() - { - OAuthRequest request = new OAuthRequest(Verb.GET, "http://example.com"); - extractor.extract(request); - } - - @Test - public void shouldProperlyEncodeSpaces() - { - String expected = "GET&http%3A%2F%2Fexample.com&body%3Dthis%2520param%2520has%2520whitespace%26oauth_callback%3Dhttp%253A%252F%252Fexample%252Fcallback%26oauth_consumer_key%3DAS%2523%2524%255E%252A%2540%2526%26oauth_signature%3DOAuth-Signature%26oauth_timestamp%3D123456"; - request.addBodyParameter("body", "this param has whitespace"); - assertEquals(expected, extractor.extract(request)); - } -} diff --git a/src/test/java/org/scribe/extractors/HeaderExtractorTest.java b/src/test/java/org/scribe/extractors/HeaderExtractorTest.java deleted file mode 100644 index 8caf4a047..000000000 --- a/src/test/java/org/scribe/extractors/HeaderExtractorTest.java +++ /dev/null @@ -1,49 +0,0 @@ -package org.scribe.extractors; - -import static org.junit.Assert.*; - -import org.junit.*; -import org.scribe.exceptions.*; -import org.scribe.model.*; -import org.scribe.test.helpers.*; -import static org.hamcrest.core.StringContains.containsString; -import static org.hamcrest.MatcherAssert.assertThat; - -public class HeaderExtractorTest -{ - - private HeaderExtractorImpl extractor; - private OAuthRequest request; - - @Before - public void setup() - { - request = ObjectMother.createSampleOAuthRequest(); - extractor = new HeaderExtractorImpl(); - } - - @Test - public void shouldExtractStandardHeader() - { - String header = extractor.extract(request); - - assertThat(header, containsString("oauth_callback=\"http%3A%2F%2Fexample%2Fcallback\"")); - assertThat(header, containsString("oauth_signature=\"OAuth-Signature\"")); - assertThat(header, containsString("oauth_consumer_key=\"AS%23%24%5E%2A%40%26\"")); - assertThat(header, containsString("oauth_timestamp=\"123456\"")); - } - - @Test(expected = IllegalArgumentException.class) - public void shouldExceptionIfRequestIsNull() - { - OAuthRequest nullRequest = null; - extractor.extract(nullRequest); - } - - @Test(expected = OAuthParametersMissingException.class) - public void shouldExceptionIfRequestHasNoOAuthParams() - { - OAuthRequest emptyRequest = new OAuthRequest(Verb.GET, "http://example.com"); - extractor.extract(emptyRequest); - } -} diff --git a/src/test/java/org/scribe/extractors/JsonTokenExtractorTest.java b/src/test/java/org/scribe/extractors/JsonTokenExtractorTest.java deleted file mode 100644 index 412e13141..000000000 --- a/src/test/java/org/scribe/extractors/JsonTokenExtractorTest.java +++ /dev/null @@ -1,31 +0,0 @@ -package org.scribe.extractors; - -import static org.junit.Assert.*; - -import org.junit.*; -import org.scribe.model.*; - -public class JsonTokenExtractorTest -{ - private String response = "'{ \"access_token\":\"I0122HHJKLEM21F3WLPYHDKGKZULAUO4SGMV3ABKFTDT3T3X\"}'"; - private JsonTokenExtractor extractor = new JsonTokenExtractor(); - - @Test - public void shouldParseResponse() - { - Token token = extractor.extract(response); - assertEquals(token.getToken(), "I0122HHJKLEM21F3WLPYHDKGKZULAUO4SGMV3ABKFTDT3T3X"); - } - - @Test(expected=IllegalArgumentException.class) - public void shouldThrowExceptionIfForNullParameters() - { - extractor.extract(null); - } - - @Test(expected=IllegalArgumentException.class) - public void shouldThrowExceptionIfForEmptyStrings() - { - extractor.extract(""); - } -} diff --git a/src/test/java/org/scribe/extractors/TokenExtractor20Test.java b/src/test/java/org/scribe/extractors/TokenExtractor20Test.java deleted file mode 100644 index 0fde22f8e..000000000 --- a/src/test/java/org/scribe/extractors/TokenExtractor20Test.java +++ /dev/null @@ -1,67 +0,0 @@ -package org.scribe.extractors; - -import static org.junit.Assert.*; - -import org.junit.*; -import org.scribe.exceptions.*; -import org.scribe.model.*; - -public class TokenExtractor20Test -{ - - private TokenExtractor20Impl extractor; - - @Before - public void setup() - { - extractor = new TokenExtractor20Impl(); - } - - @Test - public void shouldExtractTokenFromOAuthStandardResponse() - { - String response = "access_token=166942940015970|2.2ltzWXYNDjCtg5ZDVVJJeg__.3600.1295816400-548517159|RsXNdKrpxg8L6QNLWcs2TVTmcaE"; - Token extracted = extractor.extract(response); - assertEquals("166942940015970|2.2ltzWXYNDjCtg5ZDVVJJeg__.3600.1295816400-548517159|RsXNdKrpxg8L6QNLWcs2TVTmcaE", extracted.getToken()); - assertEquals("", extracted.getSecret()); - } - - @Test - public void shouldExtractTokenFromResponseWithExpiresParam() - { - String response = "access_token=166942940015970|2.2ltzWXYNDjCtg5ZDVVJJeg__.3600.1295816400-548517159|RsXNdKrpxg8L6QNLWcs2TVTmcaE&expires=5108"; - Token extracted = extractor.extract(response); - assertEquals("166942940015970|2.2ltzWXYNDjCtg5ZDVVJJeg__.3600.1295816400-548517159|RsXNdKrpxg8L6QNLWcs2TVTmcaE", extracted.getToken()); - assertEquals("", extracted.getSecret()); - } - - @Test - public void shouldExtractTokenFromResponseWithManyParameters() - { - String response = "access_token=foo1234&other_stuff=yeah_we_have_this_too&number=42"; - Token extracted = extractor.extract(response); - assertEquals("foo1234", extracted.getToken()); - assertEquals("", extracted.getSecret()); - } - - @Test(expected = OAuthException.class) - public void shouldThrowExceptionIfTokenIsAbsent() - { - String response = "&expires=5108"; - extractor.extract(response); - } - - @Test(expected = IllegalArgumentException.class) - public void shouldThrowExceptionIfResponseIsNull() - { - String response = null; - extractor.extract(response); - } - - @Test(expected = IllegalArgumentException.class) - public void shouldThrowExceptionIfResponseIsEmptyString() - { - String response = ""; - extractor.extract(response); - } -} diff --git a/src/test/java/org/scribe/extractors/TokenExtractorTest.java b/src/test/java/org/scribe/extractors/TokenExtractorTest.java deleted file mode 100644 index aca5ad1a7..000000000 --- a/src/test/java/org/scribe/extractors/TokenExtractorTest.java +++ /dev/null @@ -1,83 +0,0 @@ -package org.scribe.extractors; - -import static org.junit.Assert.*; - -import org.junit.*; -import org.scribe.exceptions.*; -import org.scribe.model.*; - -public class TokenExtractorTest -{ - - private TokenExtractorImpl extractor; - - @Before - public void setup() - { - extractor = new TokenExtractorImpl(); - } - - @Test - public void shouldExtractTokenFromOAuthStandardResponse() - { - String response = "oauth_token=hh5s93j4hdidpola&oauth_token_secret=hdhd0244k9j7ao03"; - Token extracted = extractor.extract(response); - assertEquals("hh5s93j4hdidpola", extracted.getToken()); - assertEquals("hdhd0244k9j7ao03", extracted.getSecret()); - } - - @Test - public void shouldExtractTokenFromInvertedOAuthStandardResponse() - { - String response = "oauth_token_secret=hh5s93j4hdidpola&oauth_token=hdhd0244k9j7ao03"; - Token extracted = extractor.extract(response); - assertEquals("hh5s93j4hdidpola", extracted.getSecret()); - assertEquals("hdhd0244k9j7ao03", extracted.getToken()); - } - - @Test - public void shouldExtractTokenFromResponseWithCallbackConfirmed() - { - String response = "oauth_token=hh5s93j4hdidpola&oauth_token_secret=hdhd0244k9j7ao03&callback_confirmed=true"; - Token extracted = extractor.extract(response); - assertEquals("hh5s93j4hdidpola", extracted.getToken()); - assertEquals("hdhd0244k9j7ao03", extracted.getSecret()); - } - - @Test - public void shouldExtractTokenWithEmptySecret() - { - String response = "oauth_token=hh5s93j4hdidpola&oauth_token_secret="; - Token extracted = extractor.extract(response); - assertEquals("hh5s93j4hdidpola", extracted.getToken()); - assertEquals("", extracted.getSecret()); - } - - @Test(expected = OAuthException.class) - public void shouldThrowExceptionIfTokenIsAbsent() - { - String response = "oauth_secret=hh5s93j4hdidpola&callback_confirmed=true"; - extractor.extract(response); - } - - @Test(expected = OAuthException.class) - public void shouldThrowExceptionIfSecretIsAbsent() - { - String response = "oauth_token=hh5s93j4hdidpola&callback_confirmed=true"; - extractor.extract(response); - } - - @Test(expected = IllegalArgumentException.class) - public void shouldThrowExceptionIfResponseIsNull() - { - String response = null; - extractor.extract(response); - } - - @Test(expected = IllegalArgumentException.class) - public void shouldThrowExceptionIfResponseIsEmptyString() - { - String response = ""; - extractor.extract(response); - } -} diff --git a/src/test/java/org/scribe/model/ConnectionStub.java b/src/test/java/org/scribe/model/ConnectionStub.java deleted file mode 100644 index 7e9331397..000000000 --- a/src/test/java/org/scribe/model/ConnectionStub.java +++ /dev/null @@ -1,86 +0,0 @@ -package org.scribe.model; - -import java.io.*; -import java.net.*; -import java.util.*; - -public class ConnectionStub extends HttpURLConnection -{ - - private Map headers = new HashMap(); - private Map> responseHeaders = new HashMap>(); - private int inputStreamCalled = 0; - - public ConnectionStub() throws Exception - { - super(new URL("http://example.com")); - } - - @Override - public void setRequestProperty(String key, String value) - { - headers.put(key, value); - } - - @Override - public String getRequestProperty(String s) - { - return headers.get(s); - } - - public Map getHeaders() - { - return headers; - } - - @Override - public int getResponseCode() throws IOException - { - return 200; - } - - @Override - public InputStream getInputStream() throws IOException - { - inputStreamCalled++; - return new ByteArrayInputStream("contents".getBytes()); - } - - public int getTimesCalledInpuStream() - { - return inputStreamCalled; - } - - @Override - public OutputStream getOutputStream() throws IOException - { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - baos.write("contents".getBytes()); - return baos; - } - - @Override - public Map> getHeaderFields() - { - return responseHeaders; - } - - public void addResponseHeader(String key, String value) - { - responseHeaders.put(key, Arrays.asList(value)); - } - - public void connect() throws IOException - { - } - - public void disconnect() - { - } - - public boolean usingProxy() - { - return false; - } - -} diff --git a/src/test/java/org/scribe/model/OAuthRequestTest.java b/src/test/java/org/scribe/model/OAuthRequestTest.java deleted file mode 100644 index 685c34c9f..000000000 --- a/src/test/java/org/scribe/model/OAuthRequestTest.java +++ /dev/null @@ -1,35 +0,0 @@ -package org.scribe.model; - -import static org.junit.Assert.*; - -import org.junit.*; - -public class OAuthRequestTest -{ - - private OAuthRequest request; - - @Before - public void setup() - { - request = new OAuthRequest(Verb.GET, "http://example.com"); - } - - @Test - public void shouldAddOAuthParamters() - { - request.addOAuthParameter(OAuthConstants.TOKEN, "token"); - request.addOAuthParameter(OAuthConstants.NONCE, "nonce"); - request.addOAuthParameter(OAuthConstants.TIMESTAMP, "ts"); - request.addOAuthParameter(OAuthConstants.SCOPE, "feeds"); - request.addOAuthParameter(OAuthConstants.REALM, "some-realm"); - - assertEquals(5, request.getOauthParameters().size()); - } - - @Test(expected = IllegalArgumentException.class) - public void shouldThrowExceptionIfParameterIsNotOAuth() - { - request.addOAuthParameter("otherParam", "value"); - } -} diff --git a/src/test/java/org/scribe/model/ParameterListTest.java b/src/test/java/org/scribe/model/ParameterListTest.java deleted file mode 100644 index 657e8e218..000000000 --- a/src/test/java/org/scribe/model/ParameterListTest.java +++ /dev/null @@ -1,91 +0,0 @@ -package org.scribe.model; - -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotSame; - -/** - * @author: Pablo Fernandez - */ -public class ParameterListTest -{ - private ParameterList params; - - @Before - public void setup() - { - this.params = new ParameterList(); - } - - @Test(expected = IllegalArgumentException.class) - public void shouldThrowExceptionWhenAppendingNullMapToQuerystring() - { - String url = null; - params.appendTo(url); - } - - @Test - public void shouldAppendNothingToQuerystringIfGivenEmptyMap() - { - String url = "http://www.example.com"; - Assert.assertEquals(url, params.appendTo(url)); - } - - @Test - public void shouldAppendParametersToSimpleUrl() - { - String url = "http://www.example.com"; - String expectedUrl = "http://www.example.com?param1=value1¶m2=value%20with%20spaces"; - - params.add("param1", "value1"); - params.add("param2", "value with spaces"); - - url = params.appendTo(url); - Assert.assertEquals(url, expectedUrl); - } - - @Test - public void shouldAppendParametersToUrlWithQuerystring() - { - String url = "http://www.example.com?already=present"; - String expectedUrl = "http://www.example.com?already=present¶m1=value1¶m2=value%20with%20spaces"; - - params.add("param1", "value1"); - params.add("param2", "value with spaces"); - - url = params.appendTo(url); - Assert.assertEquals(url, expectedUrl); - } - - @Test - public void shouldProperlySortParameters() - { - params.add("param1", "v1"); - params.add("param6", "v2"); - params.add("a_param", "v3"); - params.add("param2", "v4"); - Assert.assertEquals("a_param=v3¶m1=v1¶m2=v4¶m6=v2", params.sort().asFormUrlEncodedString()); - } - - @Test - public void shouldProperlySortParametersWithTheSameName() - { - params.add("param1", "v1"); - params.add("param6", "v2"); - params.add("a_param", "v3"); - params.add("param1", "v4"); - Assert.assertEquals("a_param=v3¶m1=v1¶m1=v4¶m6=v2", params.sort().asFormUrlEncodedString()); - } - - @Test - public void shouldNotModifyTheOriginalParameterList() - { - params.add("param1", "v1"); - params.add("param6", "v2"); - - assertNotSame(params, params.sort()); - } -} diff --git a/src/test/java/org/scribe/model/RequestTest.java b/src/test/java/org/scribe/model/RequestTest.java deleted file mode 100644 index c473e779c..000000000 --- a/src/test/java/org/scribe/model/RequestTest.java +++ /dev/null @@ -1,128 +0,0 @@ -package org.scribe.model; - -import static org.junit.Assert.*; - -import org.junit.*; - -public class RequestTest -{ - private Request getRequest; - private Request postRequest; - private ConnectionStub connection; - - @Before - public void setup() throws Exception - { - connection = new ConnectionStub(); - postRequest = new Request(Verb.POST, "http://example.com"); - postRequest.addBodyParameter("param", "value"); - postRequest.addBodyParameter("param with spaces", "value with spaces"); - postRequest.setConnection(connection); - getRequest = new Request(Verb.GET, "http://example.com?qsparam=value&other+param=value+with+spaces"); - getRequest.setConnection(connection); - } - - @Test - public void shouldSetRequestVerb() - { - getRequest.send(); - assertEquals("GET", connection.getRequestMethod()); - } - - @Test - public void shouldGetQueryStringParameters() - { - assertEquals(2, getRequest.getQueryStringParams().size()); - assertEquals(0, postRequest.getQueryStringParams().size()); - assertTrue(getRequest.getQueryStringParams().contains(new Parameter("qsparam", "value"))); - } - - @Test - public void shouldAddRequestHeaders() - { - getRequest.addHeader("Header", "1"); - getRequest.addHeader("Header2", "2"); - getRequest.send(); - assertEquals(2, getRequest.getHeaders().size()); - assertEquals(2, connection.getHeaders().size()); - } - - @Test - public void shouldSetBodyParamsAndAddContentLength() - { - assertEquals("param=value¶m%20with%20spaces=value%20with%20spaces", postRequest.getBodyContents()); - postRequest.send(); - assertTrue(connection.getHeaders().containsKey("Content-Length")); - } - - @Test - public void shouldSetPayloadAndHeaders() - { - postRequest.addPayload("PAYLOAD"); - postRequest.send(); - assertEquals("PAYLOAD", postRequest.getBodyContents()); - assertTrue(connection.getHeaders().containsKey("Content-Length")); - } - - @Test - public void shouldAllowAddingQuerystringParametersAfterCreation() - { - Request request = new Request(Verb.GET, "http://example.com?one=val"); - request.addQuerystringParameter("two", "other val"); - request.addQuerystringParameter("more", "params"); - assertEquals(3, request.getQueryStringParams().size()); - } - - @Test - public void shouldReturnTheCompleteUrl() - { - Request request = new Request(Verb.GET, "http://example.com?one=val"); - request.addQuerystringParameter("two", "other val"); - request.addQuerystringParameter("more", "params"); - assertEquals("http://example.com?one=val&two=other%20val&more=params", request.getCompleteUrl()); - } - - @Test - public void shouldHandleQueryStringSpaceEncodingProperly() - { - assertTrue(getRequest.getQueryStringParams().contains(new Parameter("other param","value with spaces"))); - } - - @Test - public void shouldAutomaticallyAddContentTypeForPostRequestsWithBytePayload() - { - postRequest.addPayload("PAYLOAD".getBytes()); - postRequest.send(); - assertEquals(Request.DEFAULT_CONTENT_TYPE, connection.getHeaders().get("Content-Type")); - } - - @Test - public void shouldAutomaticallyAddContentTypeForPostRequestsWithStringPayload() - { - postRequest.addPayload("PAYLOAD"); - postRequest.send(); - assertEquals(Request.DEFAULT_CONTENT_TYPE, connection.getHeaders().get("Content-Type")); - } - - @Test - public void shouldAutomaticallyAddContentTypeForPostRequestsWithBodyParameters() - { - postRequest.send(); - assertEquals(Request.DEFAULT_CONTENT_TYPE, connection.getHeaders().get("Content-Type")); - } - - @Test - public void shouldBeAbleToOverrideItsContentType() - { - postRequest.addHeader("Content-Type", "my-content-type"); - postRequest.send(); - assertEquals("my-content-type", connection.getHeaders().get("Content-Type")); - } - - @Test - public void shouldNotAddContentTypeForGetRequests() - { - getRequest.send(); - assertFalse(connection.getHeaders().containsKey("Content-Type")); - } -} \ No newline at end of file diff --git a/src/test/java/org/scribe/model/ResponseTest.java b/src/test/java/org/scribe/model/ResponseTest.java deleted file mode 100644 index a58fc0355..000000000 --- a/src/test/java/org/scribe/model/ResponseTest.java +++ /dev/null @@ -1,75 +0,0 @@ -package org.scribe.model; - -import static org.junit.Assert.*; - -import java.io.*; - -import org.junit.*; - -public class ResponseTest -{ - - private Response response; - private ConnectionStub connection; - - @Before - public void setup() throws Exception - { - connection = new ConnectionStub(); - connection.addResponseHeader("one", "one"); - connection.addResponseHeader("two", "two"); - response = new Response(connection); - } - - @Test - public void shouldPopulateResponseHeaders() - { - assertEquals(2, response.getHeaders().size()); - assertEquals("one", response.getHeader("one")); - } - - @Test - public void shouldParseBodyContents() - { - assertEquals("contents", response.getBody()); - assertEquals(1, connection.getTimesCalledInpuStream()); - } - - @Test - public void shouldParseBodyContentsOnlyOnce() - { - assertEquals("contents", response.getBody()); - assertEquals("contents", response.getBody()); - assertEquals("contents", response.getBody()); - assertEquals(1, connection.getTimesCalledInpuStream()); - } - - @Test - public void shouldHandleAConnectionWithErrors() throws Exception - { - Response errResponse = new Response(new FaultyConnection()); - assertEquals(400, errResponse.getCode()); - assertEquals("errors", errResponse.getBody()); - } - - private static class FaultyConnection extends ConnectionStub - { - - public FaultyConnection() throws Exception - { - super(); - } - - @Override - public InputStream getErrorStream() - { - return new ByteArrayInputStream("errors".getBytes()); - } - - @Override - public int getResponseCode() throws IOException - { - return 400; - } - } -} diff --git a/src/test/java/org/scribe/model/TokenTest.java b/src/test/java/org/scribe/model/TokenTest.java deleted file mode 100644 index 7e533ea76..000000000 --- a/src/test/java/org/scribe/model/TokenTest.java +++ /dev/null @@ -1,54 +0,0 @@ -package org.scribe.model; - -import static junit.framework.Assert.*; -import org.junit.*; - -public class TokenTest -{ - @Test - public void shouldTestEqualityBasedOnTokenAndSecret() throws Exception - { - Token expected = new Token("access","secret"); - Token actual = new Token("access","secret"); - - assertEquals(expected, actual); - assertEquals(actual, actual); - } - - @Test - public void shouldNotDependOnRawString() throws Exception - { - Token expected = new Token("access","secret", "raw_string"); - Token actual = new Token("access","secret", "different_raw_string"); - - assertEquals(expected, actual); - } - - @Test - public void shouldReturnSameHashCodeForEqualObjects() throws Exception - { - Token expected = new Token("access","secret"); - Token actual = new Token("access","secret"); - - assertEquals(expected.hashCode(), actual.hashCode()); - } - - @Test - public void shouldNotBeEqualToNullOrOtherObjects() throws Exception - { - Token expected = new Token("access","secret","response"); - - assertNotSame(expected, null); - assertNotSame(expected, new Object()); - } - - @Test - public void shouldReturnUrlParam() throws Exception - { - Token actual = new Token("acccess", "secret", "user_id=3107154759&screen_name=someuser&empty=&="); - assertEquals("someuser", actual.getParameter("screen_name")); - assertEquals("3107154759", actual.getParameter("user_id")); - assertEquals(null, actual.getParameter("empty")); - assertEquals(null, actual.getParameter(null)); - } -} diff --git a/src/test/java/org/scribe/services/HMACSha1SignatureServiceTest.java b/src/test/java/org/scribe/services/HMACSha1SignatureServiceTest.java deleted file mode 100644 index ec058a773..000000000 --- a/src/test/java/org/scribe/services/HMACSha1SignatureServiceTest.java +++ /dev/null @@ -1,59 +0,0 @@ -package org.scribe.services; - -import static org.junit.Assert.*; - -import org.junit.*; -import org.scribe.exceptions.*; - -public class HMACSha1SignatureServiceTest -{ - - private HMACSha1SignatureService service; - - @Before - public void setup() - { - service = new HMACSha1SignatureService(); - } - - @Test - public void shouldReturnSignatureMethodString() - { - String expected = "HMAC-SHA1"; - assertEquals(expected, service.getSignatureMethod()); - } - - @Test - public void shouldReturnSignature() - { - String apiSecret = "api secret"; - String tokenSecret = "token secret"; - String baseString = "base string"; - String signature = "uGymw2KHOTWI699YEaoi5xyLT50="; - assertEquals(signature, service.getSignature(baseString, apiSecret, tokenSecret)); - } - - @Test(expected = OAuthException.class) - public void shouldThrowExceptionIfBaseStringIsNull() - { - service.getSignature(null, "apiSecret", "tokenSecret"); - } - - @Test(expected = OAuthException.class) - public void shouldThrowExceptionIfBaseStringIsEmpty() - { - service.getSignature(" ", "apiSecret", "tokenSecret"); - } - - @Test(expected = OAuthException.class) - public void shouldThrowExceptionIfApiSecretIsNull() - { - service.getSignature("base string", null, "tokenSecret"); - } - - @Test(expected = OAuthException.class) - public void shouldThrowExceptionIfApiSecretIsEmpty() - { - service.getSignature("base string", " ", "tokenSecret"); - } -} diff --git a/src/test/java/org/scribe/services/RSASha1SignatureServiceTest.java b/src/test/java/org/scribe/services/RSASha1SignatureServiceTest.java deleted file mode 100644 index 2e78e8492..000000000 --- a/src/test/java/org/scribe/services/RSASha1SignatureServiceTest.java +++ /dev/null @@ -1,67 +0,0 @@ -package org.scribe.services; - -import static org.junit.Assert.*; - -import org.junit.*; - -import javax.xml.bind.DatatypeConverter; -import java.security.*; -import java.security.spec.*; - -public class RSASha1SignatureServiceTest -{ - - RSASha1SignatureService service = new RSASha1SignatureService(getPrivateKey()); - - @Test - public void shouldReturnSignatureMethodString() - { - String expected = "RSA-SHA1"; - assertEquals(expected, service.getSignatureMethod()); - } - - @Test - public void shouldReturnSignature() - { - String apiSecret = "api secret"; - String tokenSecret = "token secret"; - String baseString = "base string"; - String signature = "LUNRzQAlpdNyM9mLXm96Va6g/qVNnEAb7p7K1KM0g8IopOFQJPoOO7cvppgt7w3QyhijWJnCmvqXaaIAGrqvdyr3fIzBULh8D/iZQUNLMi08GCOA34P81XBvsc7A5uJjPDsGhJg2MzoVJ8nWJhU/lMMk4c92S1WGskeoDofRwpo="; - assertEquals(signature, service.getSignature(baseString, apiSecret, tokenSecret)); - } - - /** - *Created primary key using openssl. - * - * openssl req -x509 -nodes -days 365 -newkey rsa:1024 -sha1 -subj '/C=GB/ST=/L=Manchester/CN=www.example.com' -keyout myrsakey.pem -out /tmp/myrsacert.pem - * openssl pkcs8 -in myrsakey.pem -topk8 -nocrypt -out myrsakey.pk8 - */ - private static PrivateKey getPrivateKey() - { - String str = "MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAMPQ5BCMxlUq2TYy\n"+ - "iRIoEUsz6HGTJhHuasS2nx1Se4Co3lxwxyubVdFj8AuhHNJSmJvjlpbTsGOjLZpr\n"+ - "HyDEDdJmf1Fensh1MhUnBZ4a7uLrZrKzFHHJdamX9pxapB89vLeHlCot9hVXdrZH\n"+ - "nNtg6FdmRKH/8gbs8iDyIayFvzYDAgMBAAECgYA+c9MpTBy9cQsR9BAvkEPjvkx2\n"+ - "XL4ZnfbDgpNA4Nuu7yzsQrPjPomiXMNkkiAFHH67yVxwAlgRjyuuQlgNNTpKvyQt\n"+ - "XcHxffnU0820VmE23M+L7jg2TlB3+rUnEDmDvCoyjlwGDR6lNb7t7Fgg2iR+iaov\n"+ - "0iVzz+l9w0slRlyGsQJBAPWXW2m3NmFgqfDxtw8fsKC2y8o17/cnPjozRGtWb8LQ\n"+ - "g3VCb8kbOFHOYNGazq3M7+wD1qILF2h/HecgK9eQrZ0CQQDMHXoJMfKKbrFrTKgE\n"+ - "zyggO1gtuT5OXYeFewMEb5AbDI2FfSc2YP7SHij8iQ2HdukBrbTmi6qxh3HmIR58\n"+ - "I/AfAkEA0Y9vr0tombsUB8cZv0v5OYoBZvCTbMANtzfb4AOHpiKqqbohDOevLQ7/\n"+ - "SpvgVCmVaDz2PptcRAyEBZ5MCssneQJAB2pmvaDH7Ambfod5bztLfOhLCtY5EkXJ\n"+ - "n6rZcDbRaHorRhdG7m3VtDKOUKZ2DF7glkQGV33phKukErVPUzlHBwJAScD9TqaG\n"+ - "wJ3juUsVtujV23SnH43iMggXT7m82STpPGam1hPfmqu2Z0niePFo927ogQ7H1EMJ\n"+ - "UHgqXmuvk2X/Ww=="; - - try - { - KeyFactory fac = KeyFactory.getInstance("RSA"); - PKCS8EncodedKeySpec privKeySpec = new PKCS8EncodedKeySpec(DatatypeConverter.parseBase64Binary(str)); - return fac.generatePrivate(privKeySpec); - } - catch (Exception e) - { - throw new RuntimeException(e); - } - } -} diff --git a/src/test/java/org/scribe/services/TimestampServiceTest.java b/src/test/java/org/scribe/services/TimestampServiceTest.java deleted file mode 100644 index 352b962ca..000000000 --- a/src/test/java/org/scribe/services/TimestampServiceTest.java +++ /dev/null @@ -1,50 +0,0 @@ -package org.scribe.services; - -import static org.junit.Assert.*; - -import org.junit.*; - -public class TimestampServiceTest -{ - - private TimestampServiceImpl service; - private TimestampServiceImpl.Timer timerStub; - - @Before - public void setup() - { - service = new TimestampServiceImpl(); - timerStub = new TimerStub(); - service.setTimer(timerStub); - } - - @Test - public void shouldReturnTimestampInSeconds() - { - String expected = "1000"; - assertEquals(expected, service.getTimestampInSeconds()); - } - - @Test - public void shouldReturnNonce() - { - String expected = "1042"; - assertEquals(expected, service.getNonce()); - } - - private static class TimerStub extends TimestampServiceImpl.Timer - { - - @Override - public Long getMilis() - { - return 1000000L; - } - - @Override - public Integer getRandomInteger() - { - return 42; - } - } -} diff --git a/src/test/java/org/scribe/test/helpers/ObjectMother.java b/src/test/java/org/scribe/test/helpers/ObjectMother.java deleted file mode 100644 index abd75cc18..000000000 --- a/src/test/java/org/scribe/test/helpers/ObjectMother.java +++ /dev/null @@ -1,67 +0,0 @@ -package org.scribe.test.helpers; - -import org.scribe.model.*; - -public class ObjectMother -{ - - public static OAuthRequest createSampleOAuthRequest() - { - OAuthRequest request = new OAuthRequest(Verb.GET, "http://example.com"); - request.addOAuthParameter(OAuthConstants.TIMESTAMP, "123456"); - request.addOAuthParameter(OAuthConstants.CONSUMER_KEY, "AS#$^*@&"); - request.addOAuthParameter(OAuthConstants.CALLBACK, "http://example/callback"); - request.addOAuthParameter(OAuthConstants.SIGNATURE, "OAuth-Signature"); - return request; - } - - public static OAuthRequest createSampleOAuthRequestPort80() - { - OAuthRequest request = new OAuthRequest(Verb.GET, "http://example.com:80"); - request.addOAuthParameter(OAuthConstants.TIMESTAMP, "123456"); - request.addOAuthParameter(OAuthConstants.CONSUMER_KEY, "AS#$^*@&"); - request.addOAuthParameter(OAuthConstants.CALLBACK, "http://example/callback"); - request.addOAuthParameter(OAuthConstants.SIGNATURE, "OAuth-Signature"); - return request; - } - - public static OAuthRequest createSampleOAuthRequestPort80_2() - { - OAuthRequest request = new OAuthRequest(Verb.GET, "http://example.com:80/test"); - request.addOAuthParameter(OAuthConstants.TIMESTAMP, "123456"); - request.addOAuthParameter(OAuthConstants.CONSUMER_KEY, "AS#$^*@&"); - request.addOAuthParameter(OAuthConstants.CALLBACK, "http://example/callback"); - request.addOAuthParameter(OAuthConstants.SIGNATURE, "OAuth-Signature"); - return request; - } - - public static OAuthRequest createSampleOAuthRequestPort8080() - { - OAuthRequest request = new OAuthRequest(Verb.GET, "http://example.com:8080"); - request.addOAuthParameter(OAuthConstants.TIMESTAMP, "123456"); - request.addOAuthParameter(OAuthConstants.CONSUMER_KEY, "AS#$^*@&"); - request.addOAuthParameter(OAuthConstants.CALLBACK, "http://example/callback"); - request.addOAuthParameter(OAuthConstants.SIGNATURE, "OAuth-Signature"); - return request; - } - - public static OAuthRequest createSampleOAuthRequestPort443() - { - OAuthRequest request = new OAuthRequest(Verb.GET, "https://example.com:443"); - request.addOAuthParameter(OAuthConstants.TIMESTAMP, "123456"); - request.addOAuthParameter(OAuthConstants.CONSUMER_KEY, "AS#$^*@&"); - request.addOAuthParameter(OAuthConstants.CALLBACK, "http://example/callback"); - request.addOAuthParameter(OAuthConstants.SIGNATURE, "OAuth-Signature"); - return request; - } - - public static OAuthRequest createSampleOAuthRequestPort443_2() - { - OAuthRequest request = new OAuthRequest(Verb.GET, "https://example.com:443/test"); - request.addOAuthParameter(OAuthConstants.TIMESTAMP, "123456"); - request.addOAuthParameter(OAuthConstants.CONSUMER_KEY, "AS#$^*@&"); - request.addOAuthParameter(OAuthConstants.CALLBACK, "http://example/callback"); - request.addOAuthParameter(OAuthConstants.SIGNATURE, "OAuth-Signature"); - return request; - } -} diff --git a/src/test/java/org/scribe/utils/MapUtilsTest.java b/src/test/java/org/scribe/utils/MapUtilsTest.java deleted file mode 100644 index f44a0f57b..000000000 --- a/src/test/java/org/scribe/utils/MapUtilsTest.java +++ /dev/null @@ -1,35 +0,0 @@ -package org.scribe.utils; - -import java.util.*; -import org.junit.*; - -/** - * @author: Pablo Fernandez - */ -public class MapUtilsTest -{ - - @Test - public void shouldPrettyPrintMap() - { - Map map = new HashMap(); - map.put(1, "one"); - map.put(2, "two"); - map.put(3, "three"); - map.put(4, "four"); - Assert.assertEquals("{ 1 -> one , 2 -> two , 3 -> three , 4 -> four }", MapUtils.toString(map)); - } - - @Test - public void shouldHandleEmptyMap() - { - Map map = new HashMap(); - Assert.assertEquals("{}", MapUtils.toString(map)); - } - - @Test - public void shouldHandleNullInputs() - { - Assert.assertEquals("", MapUtils.toString(null)); - } -} diff --git a/src/test/java/org/scribe/utils/OAuthEncoderTest.java b/src/test/java/org/scribe/utils/OAuthEncoderTest.java deleted file mode 100644 index cf986a295..000000000 --- a/src/test/java/org/scribe/utils/OAuthEncoderTest.java +++ /dev/null @@ -1,70 +0,0 @@ -package org.scribe.utils; - -import org.junit.*; -import static org.junit.Assert.*; - -/** - * @author: Pablo Fernandez - */ -public class OAuthEncoderTest -{ - @Test - public void shouldPercentEncodeString() - { - String plain = "this is a test &^"; - String encoded = "this%20is%20a%20test%20%26%5E"; - assertEquals(encoded, OAuthEncoder.encode(plain)); - } - - @Test - public void shouldFormURLDecodeString() - { - String encoded = "this+is+a+test+%26%5E"; - String plain = "this is a test &^"; - assertEquals(plain, OAuthEncoder.decode(encoded)); - } - - @Test - public void shouldPercentEncodeAllSpecialCharacters() - { - String plain = "!*'();:@&=+$,/?#[]"; - String encoded = "%21%2A%27%28%29%3B%3A%40%26%3D%2B%24%2C%2F%3F%23%5B%5D"; - assertEquals(encoded, OAuthEncoder.encode(plain)); - assertEquals(plain, OAuthEncoder.decode(encoded)); - } - - @Test - public void shouldNotPercentEncodeReservedCharacters() - { - String plain = "abcde123456-._~"; - String encoded = plain; - assertEquals(encoded, OAuthEncoder.encode(plain)); - } - - @Test(expected = IllegalArgumentException.class) - public void shouldThrowExceptionIfStringToEncodeIsNull() - { - String toEncode = null; - OAuthEncoder.encode(toEncode); - } - - @Test(expected = IllegalArgumentException.class) - public void shouldThrowExceptionIfStringToDecodeIsNull() - { - String toDecode = null; - OAuthEncoder.decode(toDecode); - } - - @Test - public void shouldPercentEncodeCorrectlyTwitterCodingExamples() - { - // These tests are part of the Twitter dev examples here -> https://dev.twitter.com/docs/auth/percent-encoding-parameters - String sources[] = {"Ladies + Gentlemen", "An encoded string!", "Dogs, Cats & Mice"}; - String encoded[] = {"Ladies%20%2B%20Gentlemen", "An%20encoded%20string%21", "Dogs%2C%20Cats%20%26%20Mice"}; - - for(int i = 0; i < sources.length; i++) - { - Assert.assertEquals(encoded[i], OAuthEncoder.encode(sources[i])); - } - } -} diff --git a/src/test/java/org/scribe/utils/PreconditionsTest.java b/src/test/java/org/scribe/utils/PreconditionsTest.java deleted file mode 100644 index 84bc117e9..000000000 --- a/src/test/java/org/scribe/utils/PreconditionsTest.java +++ /dev/null @@ -1,87 +0,0 @@ -package org.scribe.utils; - -import org.junit.*; - -public class PreconditionsTest -{ - - private static final String ERROR_MSG = ""; - - @Test(expected = IllegalArgumentException.class) - public void shouldThrowExceptionForNullObjects() - { - Preconditions.checkNotNull(null, ERROR_MSG); - } - - @Test(expected = IllegalArgumentException.class) - public void shouldThrowExceptionForNullStrings() - { - Preconditions.checkEmptyString(null, ERROR_MSG); - } - - @Test(expected = IllegalArgumentException.class) - public void shouldThrowExceptionForEmptyStrings() - { - Preconditions.checkEmptyString("", ERROR_MSG); - } - - @Test(expected = IllegalArgumentException.class) - public void shouldThrowExceptionForSpacesOnlyStrings() - { - Preconditions.checkEmptyString(" ", ERROR_MSG); - } - - @Test(expected = IllegalArgumentException.class) - public void shouldThrowExceptionForInvalidUrls() - { - Preconditions.checkValidUrl("this/is/not/a/valid/url", ERROR_MSG); - } - - @Test(expected = IllegalArgumentException.class) - public void shouldThrowExceptionForNullUrls() - { - Preconditions.checkValidUrl(null, ERROR_MSG); - } - - @Test - public void shouldAllowValidUrls() - { - Preconditions.checkValidUrl("http://www.example.com", ERROR_MSG); - } - - @Test - public void shouldAllowSSLUrls() - { - Preconditions.checkValidUrl("https://www.example.com", ERROR_MSG); - } - - @Test - public void shouldAllowSpecialCharsInScheme() - { - Preconditions.checkValidUrl("custom+9.3-1://www.example.com", ERROR_MSG); - } - - @Test - public void shouldAllowNonStandarProtocolsForAndroid() - { - Preconditions.checkValidUrl("x-url-custom://www.example.com", ERROR_MSG); - } - - @Test(expected = IllegalArgumentException.class) - public void shouldNotAllowStrangeProtocolNames() - { - Preconditions.checkValidUrl("$weird*://www.example.com", ERROR_MSG); - } - - @Test(expected = IllegalArgumentException.class) - public void shouldNotAllowUnderscoreInScheme() - { - Preconditions.checkValidUrl("http_custom://www.example.com", ERROR_MSG); - } - - @Test - public void shouldAllowOutOfBandAsValidCallbackValue() - { - Preconditions.checkValidOAuthCallback("oob", ERROR_MSG); - } -} diff --git a/src/test/java/org/scribe/utils/StreamUtilsTest.java b/src/test/java/org/scribe/utils/StreamUtilsTest.java deleted file mode 100644 index e3e675db1..000000000 --- a/src/test/java/org/scribe/utils/StreamUtilsTest.java +++ /dev/null @@ -1,47 +0,0 @@ -package org.scribe.utils; - -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; - -import org.junit.Test; - -import static org.junit.Assert.*; - -public class StreamUtilsTest -{ - - @Test - public void shouldCorrectlyDecodeAStream() - { - String value = "expected"; - InputStream is = new ByteArrayInputStream(value.getBytes()); - String decoded = StreamUtils.getStreamContents(is); - assertEquals("expected", decoded); - } - - @Test(expected = IllegalArgumentException.class) - public void shouldFailForNullParameter() - { - InputStream is = null; - StreamUtils.getStreamContents(is); - fail("Must throw exception before getting here"); - } - - @Test(expected = IllegalStateException.class) - public void shouldFailWithBrokenStream() - { - // This object simulates problems with input stream. - final InputStream is = new InputStream() - { - @Override - public int read() throws IOException - { - throw new IOException(); - } - }; - StreamUtils.getStreamContents(is); - fail("Must throw exception before getting here"); - } - -} diff --git a/changelog.txt b/v1-changelog similarity index 100% rename from changelog.txt rename to v1-changelog diff --git a/v2pre-changelog b/v2pre-changelog new file mode 100644 index 000000000..6f456136e --- /dev/null +++ b/v2pre-changelog @@ -0,0 +1,57 @@ +[SNAPSHOT] + * prepare to merge back to the ScribeJava + * backport 'news' from scribejava + +[3.4] + * add doktornarabote.ru API support + +[3.3] + * upgrade ning async http client 1.9.20 -> 1.9.26 + * add possibility to use ProxyServer per-request (async only) + * rename maven modules, add "subscribe-" prefix + * backport anything new from scribe-java + +[3.2] + * add possibility to set non-default httpProvider Class Name for ning async http client + +[3.1] + * update FaceBook API version from 2.0 to 2.2 + * update ning dependency for async functionality + * allow 'realm' parameter in OAuthParameters + +[3.0] + * make compilable with OpenJDK8 + * add async functionality + * add GitHub API + * split on two maven modules (+repackaging) + +[2.3] + + * add state parameter in LinkedInAPI 2.0 + * update FB Graph API to version 2.0 + * add tut.by OAuth API + * add default parameter grant_type for Google, LinkedIn and Mail.ru + * update host for requests in VkontakteExample + * add Yinxiang Biji endpoint in EvernoteApi + * switch Flickr and Twitter to https + * update domain for LiveAPI + * add support for the Authorization parameter 'realm' + * add TumblrExample + * update TwitterExample to v1.1 + * merge Request class in OAuthRequest. No need in separate Request class. + No planned usages of 'clean' http requests. + * add required OAuthService parameter in constructor for OAuthRequest, + so it can use OAuthConfig always (Default timeouts for all OAuthRequests + per OAuthService instance are now possible 'from-the-box'). + * remove messy RequestTuner. Use OAuthConfig instead of it. + +[2.1] + + * add OpenID id_token parsing from response to GoogleAPI 2.0 + * add optional OAuth 'state' request parameter + * Add hh api support + * fix Mailru API + +[2.0] + + * New release. First release. Formalizations of new project. From d6949336d5333cb6c64b9d2296205749a0b02df3 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 20 Nov 2015 18:21:18 +0300 Subject: [PATCH 061/882] HH-56459 fix small error in README http link [i.garanina] --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6859f94ad..d88754360 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,7 @@ You can user ning async http client out-of-box, just use ServiceBuilderAsync * GitHub -* and many more! check the [examples folder](http://github.com/scribejava/scribejava/tree/master/src/test/java/com/github/scribejava/apis/examples) +* and many more! check the [examples folder](https://github.com/scribejava/scribejava/tree/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples) ### Small and modular From f62a40a9324ac45aea38eb49e901328677fd8015 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 20 Nov 2015 19:41:10 +0300 Subject: [PATCH 062/882] [maven-release-plugin] prepare release scribejava-2.0 --- pom.xml | 2 +- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index bdad5d555..07dfdd799 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 2.0-SNAPSHOT + 2.0 ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 701bd7f82..cb1cbdc35 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 2.0-SNAPSHOT + 2.0 ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 8ead9d7b6..8b764104f 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 2.0-SNAPSHOT + 2.0 ../pom.xml From a8e7f2e567c05c07f2b2cf449066e4ff822c9b37 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 20 Nov 2015 19:41:17 +0300 Subject: [PATCH 063/882] [maven-release-plugin] prepare for next development iteration --- pom.xml | 2 +- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 07dfdd799..0b5b25344 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 2.0 + 2.1-SNAPSHOT ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index cb1cbdc35..3df6385c1 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 2.0 + 2.1-SNAPSHOT ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 8b764104f..f61e34a43 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 2.0 + 2.1-SNAPSHOT ../pom.xml From da1d238ade47be22a51d38ea9ae2da44707655fe Mon Sep 17 00:00:00 2001 From: chenjianjx Date: Thu, 17 Dec 2015 10:02:53 +0800 Subject: [PATCH 064/882] add a getter for GoogleToken.openIdToken. I need to send it to my backend for openId validation. --- .../java/com/github/scribejava/apis/google/GoogleToken.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/google/GoogleToken.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/google/GoogleToken.java index a8af3782a..b5c7798e1 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/google/GoogleToken.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/google/GoogleToken.java @@ -17,6 +17,10 @@ public GoogleToken(final String token, final String secret, final String rawResp super(token, secret, rawResponse); this.openIdToken = openIdToken; } + + public String getOpenIdToken() { + return openIdToken; + } @Override public String toString() { From 5e17b5a1ca6f61ed7bca3a976cb13a5d99bdd6f6 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 17 Dec 2015 11:38:16 +0300 Subject: [PATCH 065/882] reformat --- .../java/com/github/scribejava/apis/google/GoogleToken.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/google/GoogleToken.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/google/GoogleToken.java index b5c7798e1..a421f070e 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/google/GoogleToken.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/google/GoogleToken.java @@ -17,10 +17,10 @@ public GoogleToken(final String token, final String secret, final String rawResp super(token, secret, rawResponse); this.openIdToken = openIdToken; } - + public String getOpenIdToken() { - return openIdToken; - } + return openIdToken; + } @Override public String toString() { From aa5c340efe334e551c81a99f8815e039a908a0fe Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 17 Dec 2015 11:41:42 +0300 Subject: [PATCH 066/882] make getStream protected in Response --- .../main/java/com/github/scribejava/core/model/Response.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/Response.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/Response.java index f78908a72..d320d94e0 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/Response.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/Response.java @@ -68,7 +68,7 @@ public String getBody() { * * @return input stream / error stream */ - private InputStream getStream() { + protected InputStream getStream() { return stream; } From 14a1b9c0e8311e385f69c33805e8fb0f3a0ca1bb Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 17 Dec 2015 11:47:25 +0300 Subject: [PATCH 067/882] prepare to release 2.0.1 --- README.md | 4 ++-- changelog | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d88754360..a45aa6167 100644 --- a/README.md +++ b/README.md @@ -79,7 +79,7 @@ You can pull ScribeJava from the central maven repository, just add these to you com.github.scribejava scribejava-apis - 2.0 + 2.0.1 ``` @@ -88,7 +88,7 @@ And in case you need just core classes (that's it, without any external API (FB, com.github.scribejava scribejava-core - 2.0 + 2.0.1 ``` diff --git a/changelog b/changelog index 4a9ebddf5..477c5fe92 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,6 @@ +[2.0.1] + * small code enhancements + [2.0] * merge back SubScribe fork to the ScribeJava From e3b2f2b4fd27f758edc17aea978e74f926999068 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 17 Dec 2015 11:48:07 +0300 Subject: [PATCH 068/882] [maven-release-plugin] prepare release scribejava-2.0.1 --- pom.xml | 2 +- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 0b5b25344..ac8dfc5f3 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 2.1-SNAPSHOT + 2.0.1 ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 3df6385c1..65d18caf7 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 2.1-SNAPSHOT + 2.0.1 ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index f61e34a43..b7e42dc51 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 2.1-SNAPSHOT + 2.0.1 ../pom.xml From ebb28a058973912d1c3443cef90d3808545c4651 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 17 Dec 2015 11:48:11 +0300 Subject: [PATCH 069/882] [maven-release-plugin] prepare for next development iteration --- pom.xml | 2 +- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index ac8dfc5f3..8442951ae 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 2.0.1 + 2.0.2-SNAPSHOT ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 65d18caf7..a6a7e26d2 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 2.0.1 + 2.0.2-SNAPSHOT ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index b7e42dc51..890ef50b6 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 2.0.1 + 2.0.2-SNAPSHOT ../pom.xml From cd4888e2a24e4281ceaa1da0ebdfe02fc9b4128b Mon Sep 17 00:00:00 2001 From: Matyas Novy Date: Thu, 17 Dec 2015 22:24:41 +0100 Subject: [PATCH 070/882] Updated to be able to merge into master. --- .../extractors/BaseStringExtractorImpl.java | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/BaseStringExtractorImpl.java b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/BaseStringExtractorImpl.java index 68f7402ec..e4cb5370e 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/BaseStringExtractorImpl.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/BaseStringExtractorImpl.java @@ -14,20 +14,28 @@ */ public class BaseStringExtractorImpl implements BaseStringExtractor { - private static final String AMPERSAND_SEPARATED_STRING = "%s&%s&%s"; + protected static final String AMPERSAND_SEPARATED_STRING = "%s&%s&%s"; /** * {@inheritDoc} */ public String extract(AbstractRequest request) { checkPreconditions(request); - String verb = OAuthEncoder.encode(request.getVerb().name()); - String url = OAuthEncoder.encode(request.getSanitizedUrl()); + String verb = OAuthEncoder.encode(getVerb(request)); + String url = OAuthEncoder.encode(getUrl(request)); String params = getSortedAndEncodedParams(request); return String.format(AMPERSAND_SEPARATED_STRING, verb, url, params); } - private String getSortedAndEncodedParams(AbstractRequest request) { + protected String getVerb(AbstractRequest request) { + return request.getVerb().name(); + } + + protected String getUrl(AbstractRequest request) { + return request.getSanitizedUrl(); + } + + protected String getSortedAndEncodedParams(AbstractRequest request) { ParameterList params = new ParameterList(); params.addAll(request.getQueryStringParams()); params.addAll(request.getBodyParams()); @@ -35,7 +43,7 @@ private String getSortedAndEncodedParams(AbstractRequest request) { return params.sort().asOauthBaseString(); } - private void checkPreconditions(AbstractRequest request) { + protected void checkPreconditions(AbstractRequest request) { Preconditions.checkNotNull(request, "Cannot extract base string from a null object"); if (request.getOauthParameters() == null || request.getOauthParameters().size() <= 0) { From f3465822c222b2fc3f50f51fbea27b0cbbf6d7a3 Mon Sep 17 00:00:00 2001 From: Matyas Novy Date: Thu, 17 Dec 2015 22:28:36 +0100 Subject: [PATCH 071/882] Whitespace. --- .../scribejava/core/extractors/BaseStringExtractorImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/BaseStringExtractorImpl.java b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/BaseStringExtractorImpl.java index e4cb5370e..2eb2ea864 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/BaseStringExtractorImpl.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/BaseStringExtractorImpl.java @@ -14,7 +14,7 @@ */ public class BaseStringExtractorImpl implements BaseStringExtractor { - protected static final String AMPERSAND_SEPARATED_STRING = "%s&%s&%s"; + protected static final String AMPERSAND_SEPARATED_STRING = "%s&%s&%s"; /** * {@inheritDoc} From 40d2ba9098895702a798ac709401ffcb88578152 Mon Sep 17 00:00:00 2001 From: Martin Malek Date: Sat, 26 Dec 2015 17:44:47 +0100 Subject: [PATCH 072/882] Adding PinterestApi and PinterestExample --- .../github/scribejava/apis/PinterestAPI.java | 44 +++++++++++++ .../apis/examples/PinterestExample.java | 63 +++++++++++++++++++ 2 files changed, 107 insertions(+) create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/PinterestAPI.java create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/PinterestAPI.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/PinterestAPI.java new file mode 100644 index 000000000..ca439a6e3 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/PinterestAPI.java @@ -0,0 +1,44 @@ +package com.github.scribejava.apis; + +import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.extractors.AccessTokenExtractor; +import com.github.scribejava.core.extractors.JsonTokenExtractor; +import com.github.scribejava.core.model.OAuthConfig; +import com.github.scribejava.core.model.OAuthConstants; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.utils.OAuthEncoder; +import com.github.scribejava.core.utils.Preconditions; + +public class PinterestApi extends DefaultApi20 { + + private static final String AUTHORIZE_URL = "https://api.pinterest.com/oauth?response_type=code&client_id=%s&redirect_uri=%s"; + private static final String SCOPED_AUTHORIZE_URL = AUTHORIZE_URL + "&scope=%s"; + + @Override + public String getAccessTokenEndpoint() { + return "https://api.pinterest.com/v1/oauth/token?grant_type=" + OAuthConstants.AUTHORIZATION_CODE; + } + + @Override + public Verb getAccessTokenVerb() { + return Verb.POST; + } + + @Override + public String getAuthorizationUrl(OAuthConfig config) { + Preconditions.checkValidUrl(config.getCallback(), "Must provide a valid url as callback. Pinterest does not support OOB"); + + // Append scope if present + if (config.hasScope()) { + return String.format(SCOPED_AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()), OAuthEncoder.encode(config. + getScope())); + } else { + return String.format(AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback())); + } + } + + @Override + public AccessTokenExtractor getAccessTokenExtractor() { + return new JsonTokenExtractor(); + } +} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java new file mode 100644 index 000000000..ac8d01042 --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java @@ -0,0 +1,63 @@ +package com.github.scribejava.apis.examples; + +import com.github.scribejava.apis.PinterestApi; +import com.github.scribejava.core.builder.ServiceBuilder; +import com.github.scribejava.core.model.*; +import com.github.scribejava.core.oauth.OAuthService; + +import java.util.Scanner; + +public class PinterestExample { + + private static final String PROTECTED_RESOURCE_URL = "https://api.pinterest.com/v1/me/?access_token?access_token="; + private static final Token EMPTY_TOKEN = null; + + public static void main(String[] args) { + // Replace these with your own api key and secret + String apiKey = "your_app_id"; + String apiSecret = "your_app_secret"; + OAuthService service = new ServiceBuilder() + .provider(PinterestApi.class) + .apiKey(apiKey) + .apiSecret(apiSecret) + .scope("read_public,write_public,read_relationships,write_relationships") + .callback("https://localhost:9000/") // Add as valid callback in developer portal + .build(); + Scanner in = new Scanner(System.in); + + System.out.println("=== Pinterest's OAuth Workflow ==="); + System.out.println(); + + // Obtain the Authorization URL + System.out.println("Fetching the Authorization URL..."); + String authorizationUrl = service.getAuthorizationUrl(EMPTY_TOKEN); + 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(">>"); + Verifier verifier = new Verifier(in.nextLine()); + System.out.println(); + + // Trade the Request Token and Verfier for the Access Token + System.out.println("Trading the Request Token for an Access Token..."); + Token accessToken = service.getAccessToken(EMPTY_TOKEN, verifier); + System.out.println("Got the Access Token!"); + System.out.println("(if your curious it looks like this: " + accessToken + " )"); + System.out.println(); + + // Now let's go and ask for a protected resource! + System.out.println("Now we're going to access a protected resource..."); + OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL + accessToken.getToken(), service); + service.signRequest(accessToken, request); + Response response = request.send(); + 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 31e83d37d2fd2145417be1c23e34f1e60c8447ab Mon Sep 17 00:00:00 2001 From: Martin Malek Date: Mon, 28 Dec 2015 17:40:59 +0100 Subject: [PATCH 073/882] Not using star imports for PinterestExample --- .../github/scribejava/apis/examples/PinterestExample.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java index ac8d01042..217a25e89 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java @@ -2,7 +2,11 @@ import com.github.scribejava.apis.PinterestApi; import com.github.scribejava.core.builder.ServiceBuilder; -import com.github.scribejava.core.model.*; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.Token; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuthService; import java.util.Scanner; From cb6bb1a0e618b1b4fec40d216a64b6a58dcb42b1 Mon Sep 17 00:00:00 2001 From: Martin Malek Date: Mon, 28 Dec 2015 17:57:49 +0100 Subject: [PATCH 074/882] Update case for PinterestApi.java --- .../scribejava/apis/{PinterestAPI.java => PinterestApi.java} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename scribejava-apis/src/main/java/com/github/scribejava/apis/{PinterestAPI.java => PinterestApi.java} (100%) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/PinterestAPI.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/PinterestApi.java similarity index 100% rename from scribejava-apis/src/main/java/com/github/scribejava/apis/PinterestAPI.java rename to scribejava-apis/src/main/java/com/github/scribejava/apis/PinterestApi.java From bc1d50a3d2b865cf8240920aae4d30da2e127ac8 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 30 Dec 2015 17:48:16 +0300 Subject: [PATCH 075/882] update changelog --- changelog | 3 +++ 1 file changed, 3 insertions(+) diff --git a/changelog b/changelog index 477c5fe92..e8c2bd581 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,6 @@ +[SNAPSHOT] + * add Pinterest API + [2.0.1] * small code enhancements From 3da27a98786ffa3f541eeb540c00c4d90b08707e Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 30 Dec 2015 17:50:22 +0300 Subject: [PATCH 076/882] prepare to release 2.1.0 --- README.md | 4 ++-- changelog | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a45aa6167..683e7efc8 100644 --- a/README.md +++ b/README.md @@ -79,7 +79,7 @@ You can pull ScribeJava from the central maven repository, just add these to you com.github.scribejava scribejava-apis - 2.0.1 + 2.1.0 ``` @@ -88,7 +88,7 @@ And in case you need just core classes (that's it, without any external API (FB, com.github.scribejava scribejava-core - 2.0.1 + 2.1.0 ``` diff --git a/changelog b/changelog index e8c2bd581..35a1619fe 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,6 @@ [SNAPSHOT] + +[2.1.0] * add Pinterest API [2.0.1] From f0ff1dabf882c52db79b9ed840982fdb6cd20f10 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 30 Dec 2015 17:52:47 +0300 Subject: [PATCH 077/882] [maven-release-plugin] prepare release scribejava-2.1.0 --- pom.xml | 2 +- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 8442951ae..ac6da4cae 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 2.0.2-SNAPSHOT + 2.1.0 ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index a6a7e26d2..e33033816 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 2.0.2-SNAPSHOT + 2.1.0 ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 890ef50b6..200c6a6b0 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 2.0.2-SNAPSHOT + 2.1.0 ../pom.xml From dc276ed2d1f339e95944b4890486851877e7ea28 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 30 Dec 2015 17:52:56 +0300 Subject: [PATCH 078/882] [maven-release-plugin] prepare for next development iteration --- pom.xml | 2 +- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index ac6da4cae..e92f0e525 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 2.1.0 + 2.1.1-SNAPSHOT ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index e33033816..dc52a3f14 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 2.1.0 + 2.1.1-SNAPSHOT ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 200c6a6b0..9950e7268 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 2.1.0 + 2.1.1-SNAPSHOT ../pom.xml From 8df2d99136c9cd627782694349c970e7ed329a62 Mon Sep 17 00:00:00 2001 From: Brandon Elam Barker Date: Thu, 31 Dec 2015 10:37:18 -0500 Subject: [PATCH 079/882] change getStream to be public See: Support streamed responses (e.g. twitter streaming endpoints) #582 --- .../main/java/com/github/scribejava/core/model/Response.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/Response.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/Response.java index d320d94e0..dec7d0ddf 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/Response.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/Response.java @@ -68,7 +68,7 @@ public String getBody() { * * @return input stream / error stream */ - protected InputStream getStream() { + public InputStream getStream() { return stream; } From 5f68dbfe475a83f933456f4533b64972d5b75b4b Mon Sep 17 00:00:00 2001 From: shaunyip Date: Tue, 5 Jan 2016 15:20:24 +0800 Subject: [PATCH 080/882] change pom version --- pom.xml | 2 +- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index e92f0e525..3169d5889 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 2.1.1-SNAPSHOT + 2.1.1-cjx-SNAPSHOT ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index dc52a3f14..86fe7ffda 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 2.1.1-SNAPSHOT + 2.1.1-cjx-SNAPSHOT ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 9950e7268..72d097100 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 2.1.1-SNAPSHOT + 2.1.1-cjx-SNAPSHOT ../pom.xml @@ -34,4 +34,4 @@ - \ No newline at end of file + From 5b583fdb8e046fb33313b59748adb3ab2a116816 Mon Sep 17 00:00:00 2001 From: chenjianjx Date: Tue, 5 Jan 2016 15:31:27 +0800 Subject: [PATCH 081/882] let google api 2.0 supports OOB --- .../src/main/java/com/github/scribejava/apis/GoogleApi20.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/GoogleApi20.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/GoogleApi20.java index 5bf9a2691..1b006b0f0 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/GoogleApi20.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/GoogleApi20.java @@ -28,8 +28,6 @@ public String getAccessTokenEndpoint() { @Override public String getAuthorizationUrl(final OAuthConfig config) { - Preconditions.checkValidUrl(config.getCallback(), - "Must provide a valid url as callback. Google+ does not support OOB"); final StringBuilder sb = new StringBuilder(String.format(AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode( config.getCallback()), OAuthEncoder.encode(config.getScope()))); From f59243520f7e50160f2f9e5004fc64862d67abca Mon Sep 17 00:00:00 2001 From: kent Date: Tue, 5 Jan 2016 15:50:39 +0800 Subject: [PATCH 082/882] revert pom version --- pom.xml | 2 +- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 3169d5889..e92f0e525 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 2.1.1-cjx-SNAPSHOT + 2.1.1-SNAPSHOT ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 86fe7ffda..dc52a3f14 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 2.1.1-cjx-SNAPSHOT + 2.1.1-SNAPSHOT ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 72d097100..8cbcef80c 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 2.1.1-cjx-SNAPSHOT + 2.1.1-SNAPSHOT ../pom.xml From 3bc0a00fbb77f2c9520490386e46b52987b88c3a Mon Sep 17 00:00:00 2001 From: chenjianjx Date: Tue, 5 Jan 2016 15:59:06 +0800 Subject: [PATCH 083/882] pom.xml's new line problem --- scribejava-core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 8cbcef80c..9950e7268 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -34,4 +34,4 @@ - + \ No newline at end of file From 123e8ac0e2ce0ec4e8a518c6fa75ea1845a64027 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 11 Jan 2016 15:53:43 +0300 Subject: [PATCH 084/882] update changelog --- changelog | 1 + 1 file changed, 1 insertion(+) diff --git a/changelog b/changelog index 35a1619fe..2c9fcab61 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,5 @@ [SNAPSHOT] + * Let GoogleApi20 supports OOB [2.1.0] * add Pinterest API From c947de690db53b36a5e1d2155995e37fcddc607e Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 11 Jan 2016 15:55:27 +0300 Subject: [PATCH 085/882] add new line at the end of file in the pom.xml --- scribejava-core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 9950e7268..8cbcef80c 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -34,4 +34,4 @@ - \ No newline at end of file + From 228829da118bee34e6432790f6515a6f9f5d29be Mon Sep 17 00:00:00 2001 From: Ryan Greene Date: Mon, 11 Jan 2016 17:32:52 -0600 Subject: [PATCH 086/882] Removed included API keys and secrets from examples --- .../github/scribejava/apis/examples/Foursquare2Example.java | 4 ++-- .../github/scribejava/apis/examples/FoursquareExample.java | 4 ++-- .../github/scribejava/apis/examples/FreelancerExample.java | 4 ++-- .../com/github/scribejava/apis/examples/LinkedInExample.java | 4 ++-- .../com/github/scribejava/apis/examples/MeetupExample.java | 4 ++-- .../com/github/scribejava/apis/examples/TwitterExample.java | 4 ++-- .../java/com/github/scribejava/apis/examples/XingExample.java | 4 ++-- .../com/github/scribejava/apis/examples/YahooExample.java | 4 ++-- 8 files changed, 16 insertions(+), 16 deletions(-) diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java index fc36713c8..f59ccb22a 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java @@ -17,8 +17,8 @@ public class Foursquare2Example { public static void main(String[] args) { // Replace these with your own api key and secret - String apiKey = "FEGFXJUFANVVDHVSNUAMUKTTXCP1AJQD53E33XKJ44YP1S4I"; - String apiSecret = "AYWKUL5SWPNC0CTQ202QXRUG2NLZYXMRA34ZSDW4AUYBG2RC"; + String apiKey = "your client id"; + String apiSecret = "your client secret"; OAuthService service = new ServiceBuilder() .provider(Foursquare2Api.class) .apiKey(apiKey) diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FoursquareExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FoursquareExample.java index 73ad37d7f..fa3957f2c 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FoursquareExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FoursquareExample.java @@ -17,8 +17,8 @@ public class FoursquareExample { public static void main(String[] args) { OAuthService service = new ServiceBuilder() .provider(FoursquareApi.class) - .apiKey("FEGFXJUFANVVDHVSNUAMUKTTXCP1AJQD53E33XKJ44YP1S4I") - .apiSecret("AYWKUL5SWPNC0CTQ202QXRUG2NLZYXMRA34ZSDW4AUYBG2RC") + .apiKey("your client id") + .apiSecret("your client secret") .build(); Scanner in = new Scanner(System.in); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java index 1683c8f72..999ed897c 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java @@ -23,8 +23,8 @@ public static void main(String[] args) { OAuthService service = new ServiceBuilder() .provider(FreelancerApi.Sandbox.class) .signatureType(SignatureType.QueryString) - .apiKey("7f5a168a0bfdbd15b4a9ea2a969661c731cdea56") - .apiSecret("7bb8961b94873802f1c5344f671a518e087f5785") + .apiKey("your client id") + .apiSecret("your client secret") .scope(SCOPE) .build(); Scanner in = new Scanner(System.in); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java index f26cdaf4b..50ee27d7b 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java @@ -18,8 +18,8 @@ public class LinkedInExample { public static void main(String[] args) { OAuthService service = new ServiceBuilder() .provider(LinkedInApi.class) - .apiKey("CiEgwWDkA5BFpNrc0RfGyVuSlOh4tig5kOTZ9q97qcXNrFl7zqk-Ts7DqRGaKDCV") - .apiSecret("dhho4dfoCmiQXrkw4yslork5XWLFnPSuMR-8gscPVjY4jqFFHPYWJKgpFl4uLTM6") + .apiKey("your client id") + .apiSecret("your client secret") .build(); Scanner in = new Scanner(System.in); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java index d0d98ddbc..6c570d2b6 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java @@ -17,8 +17,8 @@ public class MeetupExample { public static void main(String[] args) { OAuthService service = new ServiceBuilder() .provider(MeetupApi.class) - .apiKey("j1khkp0dus323ftve0sdcv6ffe") - .apiSecret("6s6gt6q59gvfjtsvgcmht62gq4") + .apiKey("your client id") + .apiSecret("your client secret") .build(); Scanner in = new Scanner(System.in); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TwitterExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TwitterExample.java index 1ebecb79a..98acc733e 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TwitterExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TwitterExample.java @@ -16,8 +16,8 @@ public class TwitterExample { public static void main(String[] args) { OAuthService service = new ServiceBuilder().provider(TwitterApi.class) - .apiKey("6icbcAXyZx67r8uTAUM5Qw") - .apiSecret("SCCAdUUc6LXxiazxH3N0QfpNUvlUy84mZ2XZKiv39s") + .apiKey("your client id") + .apiSecret("your client secret") .build(); Scanner in = new Scanner(System.in); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XingExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XingExample.java index c02aa98de..ef721e1e0 100755 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XingExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XingExample.java @@ -17,8 +17,8 @@ public class XingExample { public static void main(String[] args) { OAuthService service = new ServiceBuilder() .provider(XingApi.class) - .apiKey("097ccfd3ef25a1cb6d75") - .apiSecret("e43364b2afd5d92f2ec28951a75bd8075f9cc221") + .apiKey("your client id") + .apiSecret("your client secret") .build(); Scanner in = new Scanner(System.in); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/YahooExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/YahooExample.java index b10fe03b8..4b5e66c17 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/YahooExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/YahooExample.java @@ -18,8 +18,8 @@ public class YahooExample { public static void main(String[] args) { OAuthService service = new ServiceBuilder() .provider(YahooApi.class) - .apiKey("dj0yJmk9TXZDWVpNVVdGaVFmJmQ9WVdrOWMweHZXbkZLTkhVbWNHbzlNVEl5TWprd05qUTJNZy0tJnM9Y29uc3VtZXJzZWNyZXQmeD0wMw--"). - apiSecret("262be559f92a2be20c4c039419018f2b48cdfce9") + .apiKey("your client id"). + apiSecret("your client secret") .build(); Scanner in = new Scanner(System.in); From 2d9915f156624fac1290edf5796063a4f9f90e29 Mon Sep 17 00:00:00 2001 From: Ryan Greene Date: Tue, 12 Jan 2016 21:54:16 -0600 Subject: [PATCH 087/882] Removed broken Imgur API --- .../com/github/scribejava/apis/ImgUrApi.java | 28 --------- .../apis/examples/ImgUrExample.java | 60 ------------------- 2 files changed, 88 deletions(-) delete mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/ImgUrApi.java delete mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ImgUrExample.java diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgUrApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgUrApi.java deleted file mode 100644 index a46d3f28c..000000000 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgUrApi.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.github.scribejava.apis; - -import com.github.scribejava.core.builder.api.DefaultApi10a; -import com.github.scribejava.core.model.Token; - -/** - * OAuth API for ImgUr - * - * @author David Wursteisen - * @see ImgUr API - */ -public class ImgUrApi extends DefaultApi10a { - - @Override - public String getRequestTokenEndpoint() { - return "https://api.imgur.com/oauth/request_token"; - } - - @Override - public String getAccessTokenEndpoint() { - return "https://api.imgur.com/oauth/access_token"; - } - - @Override - public String getAuthorizationUrl(Token requestToken) { - return String.format("https://api.imgur.com/oauth/authorize?oauth_token=%s", requestToken.getToken()); - } -} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ImgUrExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ImgUrExample.java deleted file mode 100644 index 11aa7c78d..000000000 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ImgUrExample.java +++ /dev/null @@ -1,60 +0,0 @@ -package com.github.scribejava.apis.examples; - -import java.util.Scanner; -import com.github.scribejava.core.builder.ServiceBuilder; -import com.github.scribejava.apis.ImgUrApi; -import com.github.scribejava.core.model.OAuthRequest; -import com.github.scribejava.core.model.Response; -import com.github.scribejava.core.model.Token; -import com.github.scribejava.core.model.Verb; -import com.github.scribejava.core.model.Verifier; -import com.github.scribejava.core.oauth.OAuthService; - -public class ImgUrExample { - - private static final String PROTECTED_RESOURCE_URL = "http://api.imgur.com/2/account.json"; - - public static void main(String[] args) { - // Replace these with your own api key and secret (you'll need an read/write api key) - String apiKey = "your_app_id"; - String apiSecret = "your_api_secret"; - OAuthService service = new ServiceBuilder().provider(ImgUrApi.class).apiKey(apiKey).apiSecret(apiSecret).build(); - Scanner in = new Scanner(System.in); - - System.out.println("=== ImgUr's OAuth Workflow ==="); - System.out.println(); - - // Obtain the Request Token - System.out.println("Fetching the Request Token..."); - Token requestToken = service.getRequestToken(); - System.out.println("Got the Request Token!"); - System.out.println(); - - System.out.println("Now go and authorize ScribeJava here:"); - String authorizationUrl = service.getAuthorizationUrl(requestToken); - System.out.println(authorizationUrl); - System.out.println("And paste the verifier here"); - System.out.print(">>"); - Verifier verifier = new Verifier(in.nextLine()); - System.out.println(); - - // Trade the Request Token and Verfier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); - Token accessToken = service.getAccessToken(requestToken, verifier); - System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken + " )"); - System.out.println(); - - // Now let's go and ask for a protected resource! - System.out.println("Now we're going to access a protected resource..."); - OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service); - service.signRequest(accessToken, request); - Response response = request.send(); - System.out.println("Got it! Lets see what we found..."); - System.out.println(); - System.out.println(response.getBody()); - - System.out.println(); - System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); - } -} From 7e89066a03f2ff5747110ba25cd4cc12ca15aeba Mon Sep 17 00:00:00 2001 From: Ryan Greene Date: Tue, 12 Jan 2016 21:55:10 -0600 Subject: [PATCH 088/882] Added Imgur API --- .../com/github/scribejava/apis/ImgurApi.java | 44 ++++++++++++++ .../apis/service/ImgurOAuthServiceImpl.java | 33 +++++++++++ .../apis/examples/ImgurExample.java | 57 +++++++++++++++++++ 3 files changed, 134 insertions(+) create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthServiceImpl.java create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ImgurExample.java diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java new file mode 100644 index 000000000..b3c4f6641 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java @@ -0,0 +1,44 @@ +package com.github.scribejava.apis; + +import com.github.scribejava.apis.service.ImgurOAuthServiceImpl; +import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.extractors.AccessTokenExtractor; +import com.github.scribejava.core.extractors.JsonTokenExtractor; +import com.github.scribejava.core.model.OAuthConfig; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.oauth.OAuthService; + +public final class ImgurApi extends DefaultApi20 { + + private static final String AUTHORIZATION_URL = + "https://api.imgur.com/oauth2/authorize?client_id=%s&response_type=%s"; + + @Override + public Verb getAccessTokenVerb() { + return Verb.POST; + } + + @Override + public AccessTokenExtractor getAccessTokenExtractor() { + return new JsonTokenExtractor(); + } + + @Override + public String getAccessTokenEndpoint() { + return "https://api.imgur.com/oauth2/token"; + } + + @Override + public String getAuthorizationUrl(final OAuthConfig config) { + return String.format(AUTHORIZATION_URL, config.getApiKey(), isOob(config) ? "pin" : "code"); + } + + @Override + public OAuthService createService(final OAuthConfig config) { + return new ImgurOAuthServiceImpl(this, config); + } + + public boolean isOob(final OAuthConfig config) { + return "oob".equals(config.getCallback()); + } +} \ No newline at end of file diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthServiceImpl.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthServiceImpl.java new file mode 100644 index 000000000..6dfd74992 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthServiceImpl.java @@ -0,0 +1,33 @@ +package com.github.scribejava.apis.service; + +import com.github.scribejava.apis.ImgurApi; +import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.model.*; +import com.github.scribejava.core.oauth.OAuth20ServiceImpl; + +public final class ImgurOAuthServiceImpl extends OAuth20ServiceImpl { + + public ImgurOAuthServiceImpl(final DefaultApi20 api, final OAuthConfig config) { + super(api, config); + } + + @Override + public Token getAccessToken(final Token requestToken, final Verifier verifier) { + final boolean oob = ((ImgurApi) getApi()).isOob(getConfig()); + + final OAuthRequest request = new OAuthRequest(getApi().getAccessTokenVerb(), + getApi().getAccessTokenEndpoint(), this); + request.addBodyParameter(OAuthConstants.CLIENT_ID, getConfig().getApiKey()); + request.addBodyParameter(OAuthConstants.CLIENT_SECRET, getConfig().getApiSecret()); + request.addBodyParameter(OAuthConstants.GRANT_TYPE, oob ? "pin" : OAuthConstants.AUTHORIZATION_CODE); + request.addBodyParameter(oob ? "pin" : OAuthConstants.CODE, verifier.getValue()); + + return getApi().getAccessTokenExtractor().extract(request.send().getBody()); + } + + @Override + public void signRequest(final Token accessToken, final AbstractRequest request) { + request.addHeader("Authorization", + accessToken != null ? "Bearer " + accessToken.getToken() : "Client-ID " + getConfig().getApiKey()); + } +} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ImgurExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ImgurExample.java new file mode 100644 index 000000000..969831edc --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ImgurExample.java @@ -0,0 +1,57 @@ +package com.github.scribejava.apis.examples; + +import com.github.scribejava.apis.ImgurApi; +import com.github.scribejava.core.builder.ServiceBuilder; +import com.github.scribejava.core.model.*; +import com.github.scribejava.core.oauth.OAuthService; + +import java.util.Scanner; + +public class ImgurExample { + + private static final String NETWORK_NAME = "Imgur"; + private static final String PROTECTED_RESOURCE_URL = "https://api.imgur.com/3/account/me"; + + public static void main(String[] args) { + // Replace these with your own api key and secret + String apiKey = "your client id"; + String apiSecret = "your client secret"; + OAuthService service = new ServiceBuilder().provider(ImgurApi.class).apiKey(apiKey) + .apiSecret(apiSecret).build(); + 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..."); + String authorizationUrl = service.getAuthorizationUrl(Token.empty()); + 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(">>"); + Verifier verifier = new Verifier(in.nextLine()); + System.out.println(); + + // Trade the Request Token and Verifier for the Access Token + System.out.println("Trading the Request Token for an Access Token..."); + Token accessToken = service.getAccessToken(Token.empty(), verifier); + System.out.println("Got the Access Token!"); + System.out.println("(if your curious it looks like this: " + accessToken + " )"); + System.out.println(); + + // Now let's go and ask for a protected resource! + System.out.println("Now we're going to access a protected resource..."); + OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service); + service.signRequest(accessToken, request); + Response response = request.send(); + 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 53805cbbddf72645e9bbcb0c1651b7a133cf12ba Mon Sep 17 00:00:00 2001 From: Ryan Greene Date: Wed, 13 Jan 2016 09:18:02 -0600 Subject: [PATCH 089/882] Imgur API PR fixes --- changelog | 1 + .../com/github/scribejava/apis/ImgurApi.java | 4 ++-- .../apis/service/ImgurOAuthServiceImpl.java | 19 ++++++++++++++----- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/changelog b/changelog index 2c9fcab61..eb2fbf649 100644 --- a/changelog +++ b/changelog @@ -1,5 +1,6 @@ [SNAPSHOT] * Let GoogleApi20 supports OOB + * Updated Imgur API to OAuth2 [2.1.0] * add Pinterest API diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java index b3c4f6641..6f7bdfcc6 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java @@ -38,7 +38,7 @@ public OAuthService createService(final OAuthConfig config) { return new ImgurOAuthServiceImpl(this, config); } - public boolean isOob(final OAuthConfig config) { + public static boolean isOob(final OAuthConfig config) { return "oob".equals(config.getCallback()); } -} \ No newline at end of file +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthServiceImpl.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthServiceImpl.java index 6dfd74992..fceaccbc9 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthServiceImpl.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthServiceImpl.java @@ -2,7 +2,12 @@ import com.github.scribejava.apis.ImgurApi; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.model.*; +import com.github.scribejava.core.model.AbstractRequest; +import com.github.scribejava.core.model.OAuthConfig; +import com.github.scribejava.core.model.OAuthConstants; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Token; +import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuth20ServiceImpl; public final class ImgurOAuthServiceImpl extends OAuth20ServiceImpl { @@ -13,14 +18,18 @@ public ImgurOAuthServiceImpl(final DefaultApi20 api, final OAuthConfig config) { @Override public Token getAccessToken(final Token requestToken, final Verifier verifier) { - final boolean oob = ((ImgurApi) getApi()).isOob(getConfig()); - final OAuthRequest request = new OAuthRequest(getApi().getAccessTokenVerb(), getApi().getAccessTokenEndpoint(), this); request.addBodyParameter(OAuthConstants.CLIENT_ID, getConfig().getApiKey()); request.addBodyParameter(OAuthConstants.CLIENT_SECRET, getConfig().getApiSecret()); - request.addBodyParameter(OAuthConstants.GRANT_TYPE, oob ? "pin" : OAuthConstants.AUTHORIZATION_CODE); - request.addBodyParameter(oob ? "pin" : OAuthConstants.CODE, verifier.getValue()); + + if(ImgurApi.isOob(getConfig())) { + request.addBodyParameter(OAuthConstants.GRANT_TYPE, "pin"); + request.addBodyParameter("pin", verifier.getValue()); + } else { + request.addBodyParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.AUTHORIZATION_CODE); + request.addBodyParameter(OAuthConstants.CODE, verifier.getValue()); + } return getApi().getAccessTokenExtractor().extract(request.send().getBody()); } From c27931c0c9fcbce26ad543010a6d980c760b8873 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 18 Jan 2016 17:14:49 +0300 Subject: [PATCH 090/882] fix star import --- .../com/github/scribejava/apis/examples/ImgurExample.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ImgurExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ImgurExample.java index 969831edc..ed1ad3156 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ImgurExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ImgurExample.java @@ -2,7 +2,11 @@ import com.github.scribejava.apis.ImgurApi; import com.github.scribejava.core.builder.ServiceBuilder; -import com.github.scribejava.core.model.*; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.Token; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuthService; import java.util.Scanner; From 9a261a130c31a98259a10cc85be589792680f6f3 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 19 Jan 2016 17:22:54 +0300 Subject: [PATCH 091/882] force not to instantiate stateless APIs. Use provided singletons [i.garanina] --- changelog | 1 + .../com/github/scribejava/apis/AWeberApi.java | 13 ++- .../scribejava/apis/ConstantContactApi.java | 13 ++- .../scribejava/apis/ConstantContactApi2.java | 45 ++++++---- .../com/github/scribejava/apis/DiggApi.java | 13 ++- .../scribejava/apis/DoktornaraboteApi.java | 15 +++- .../github/scribejava/apis/DropBoxApi.java | 13 ++- .../github/scribejava/apis/EvernoteApi.java | 35 +++++++- .../github/scribejava/apis/FacebookApi.java | 11 +++ .../com/github/scribejava/apis/FlickrApi.java | 13 ++- .../scribejava/apis/Foursquare2Api.java | 13 ++- .../github/scribejava/apis/FoursquareApi.java | 13 ++- .../github/scribejava/apis/FreelancerApi.java | 26 +++++- .../github/scribejava/apis/GetGlueApi.java | 13 ++- .../com/github/scribejava/apis/GitHubApi.java | 13 ++- .../com/github/scribejava/apis/GoogleApi.java | 13 ++- .../github/scribejava/apis/GoogleApi20.java | 14 ++- .../com/github/scribejava/apis/HHApi.java | 16 +++- .../com/github/scribejava/apis/ImgurApi.java | 13 ++- .../com/github/scribejava/apis/KaixinApi.java | 85 +++++++++++-------- .../github/scribejava/apis/KaixinApi20.java | 13 ++- .../github/scribejava/apis/LinkedInApi.java | 20 +++-- .../github/scribejava/apis/LinkedInApi20.java | 11 +++ .../com/github/scribejava/apis/LiveApi.java | 13 ++- .../github/scribejava/apis/LoveFilmApi.java | 13 ++- .../com/github/scribejava/apis/MailruApi.java | 15 +++- .../com/github/scribejava/apis/MeetupApi.java | 13 ++- .../github/scribejava/apis/MendeleyApi.java | 11 +++ .../com/github/scribejava/apis/MisoApi.java | 13 ++- .../github/scribejava/apis/NetProspexApi.java | 13 ++- .../scribejava/apis/NeteaseWeibooApi.java | 11 +++ .../scribejava/apis/OdnoklassnikiApi.java | 15 +++- .../github/scribejava/apis/PinterestApi.java | 13 ++- .../com/github/scribejava/apis/PlurkApi.java | 26 +++++- .../com/github/scribejava/apis/Px500Api.java | 13 ++- .../com/github/scribejava/apis/QWeiboApi.java | 63 ++++++++------ .../com/github/scribejava/apis/RenrenApi.java | 13 ++- .../com/github/scribejava/apis/SapoApi.java | 13 ++- .../github/scribejava/apis/SimpleGeoApi.java | 11 +++ .../github/scribejava/apis/SinaWeiboApi.java | 13 ++- .../scribejava/apis/SinaWeiboApi20.java | 13 ++- .../github/scribejava/apis/SkyrockApi.java | 13 ++- .../github/scribejava/apis/SohuWeiboApi.java | 13 ++- .../com/github/scribejava/apis/TrelloApi.java | 13 ++- .../com/github/scribejava/apis/TumblrApi.java | 13 ++- .../com/github/scribejava/apis/TutByApi.java | 15 +++- .../github/scribejava/apis/TwitterApi.java | 26 +++++- .../github/scribejava/apis/UbuntuOneApi.java | 13 ++- .../com/github/scribejava/apis/ViadeoApi.java | 13 ++- .../com/github/scribejava/apis/VimeoApi.java | 13 ++- .../github/scribejava/apis/VkontakteApi.java | 11 +++ .../com/github/scribejava/apis/XingApi.java | 13 ++- .../com/github/scribejava/apis/YahooApi.java | 13 ++- .../com/github/scribejava/apis/YammerApi.java | 13 ++- .../DoktornaraboteOAuthServiceImpl.java | 4 +- .../apis/service/GoogleOAuthServiceImpl.java | 6 +- .../apis/service/HHOAuthServiceImpl.java | 4 +- .../apis/service/ImgurOAuthServiceImpl.java | 4 +- .../apis/service/LinkedIn20ServiceImpl.java | 6 +- .../apis/service/MailruOAuthServiceImpl.java | 20 ++--- .../apis/service/TutByOAuthServiceImpl.java | 4 +- .../apis/examples/AWeberExample.java | 20 ++--- .../scribejava/apis/examples/DiggExample.java | 24 +++--- .../apis/examples/FacebookAsyncExample.java | 8 +- .../apis/examples/FacebookExample.java | 2 +- .../apis/examples/FlickrExample.java | 24 +++--- .../apis/examples/Foursquare2Example.java | 24 +++--- .../apis/examples/FoursquareExample.java | 20 ++--- .../apis/examples/FreelancerExample.java | 20 ++--- .../apis/examples/GitHubExample.java | 6 +- .../apis/examples/Google20Example.java | 4 +- .../apis/examples/GoogleExample.java | 20 ++--- .../scribejava/apis/examples/HHExample.java | 14 +-- .../apis/examples/ImgurExample.java | 22 ++--- .../apis/examples/Kaixin20Example.java | 24 +++--- .../apis/examples/LinkedIn20Example.java | 12 +-- .../apis/examples/LinkedInExample.java | 20 ++--- .../examples/LinkedInExampleWithScopes.java | 18 ++-- .../scribejava/apis/examples/LiveExample.java | 24 +++--- .../apis/examples/LoveFilmExample.java | 24 +++--- .../apis/examples/MailruAsyncExample.java | 8 +- .../apis/examples/MailruExample.java | 14 +-- .../apis/examples/MeetupExample.java | 20 ++--- .../apis/examples/NeteaseWeiboExample.java | 26 +++--- .../apis/examples/OdnoklassnikiExample.java | 18 ++-- .../apis/examples/PinterestExample.java | 24 +++--- .../apis/examples/Px500Example.java | 20 ++--- .../apis/examples/RenrenExample.java | 42 ++++----- .../apis/examples/SinaWeibo2Example.java | 24 +++--- .../apis/examples/SinaWeiboExample.java | 26 +++--- .../apis/examples/SkyrockExample.java | 20 ++--- .../apis/examples/SohuWeiboExample.java | 26 +++--- .../apis/examples/TrelloExample.java | 20 ++--- .../apis/examples/TumblrExample.java | 20 ++--- .../apis/examples/TutByExample.java | 6 +- .../apis/examples/TwitterExample.java | 18 ++-- .../apis/examples/ViadeoExample.java | 24 +++--- .../apis/examples/VkontakteExample.java | 20 ++--- .../scribejava/apis/examples/XingExample.java | 20 ++--- .../apis/examples/YahooExample.java | 20 ++--- .../core/builder/AbstractServiceBuilder.java | 19 +---- .../core/builder/api/DefaultApi20.java | 3 +- .../core/builder/ServiceBuilderTest.java | 65 +++++++++----- 103 files changed, 1217 insertions(+), 576 deletions(-) diff --git a/changelog b/changelog index eb2fbf649..95084896f 100644 --- a/changelog +++ b/changelog @@ -1,6 +1,7 @@ [SNAPSHOT] * Let GoogleApi20 supports OOB * Updated Imgur API to OAuth2 + * force not to instantiate stateless APIs. Use provided singletons [2.1.0] * add Pinterest API diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/AWeberApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/AWeberApi.java index 06a1ecc69..07bc0a1b4 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/AWeberApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/AWeberApi.java @@ -9,6 +9,17 @@ public class AWeberApi extends DefaultApi10a { private static final String REQUEST_TOKEN_ENDPOINT = "https://auth.aweber.com/1.0/oauth/request_token"; private static final String ACCESS_TOKEN_ENDPOINT = "https://auth.aweber.com/1.0/oauth/access_token"; + private AWeberApi() { + } + + private static class InstanceHolder { + private static final AWeberApi INSTANCE = new AWeberApi(); + } + + public static AWeberApi instance() { + return InstanceHolder.INSTANCE; + } + @Override public String getAccessTokenEndpoint() { return ACCESS_TOKEN_ENDPOINT; @@ -20,7 +31,7 @@ public String getRequestTokenEndpoint() { } @Override - public String getAuthorizationUrl(Token requestToken) { + public String getAuthorizationUrl(final Token requestToken) { return String.format(AUTHORIZE_URL, requestToken.getToken()); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/ConstantContactApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/ConstantContactApi.java index d20b9a5e0..a347303f0 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/ConstantContactApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/ConstantContactApi.java @@ -7,13 +7,24 @@ public class ConstantContactApi extends DefaultApi10a { private static final String AUTHORIZE_URL = "https://oauth.constantcontact.com/ws/oauth/confirm_access?oauth_token=%s"; + private ConstantContactApi() { + } + + private static class InstanceHolder { + private static final ConstantContactApi INSTANCE = new ConstantContactApi(); + } + + public static ConstantContactApi instance() { + return InstanceHolder.INSTANCE; + } + @Override public String getAccessTokenEndpoint() { return "https://oauth.constantcontact.com/ws/oauth/access_token"; } @Override - public String getAuthorizationUrl(Token requestToken) { + public String getAuthorizationUrl(final Token requestToken) { return String.format(AUTHORIZE_URL, requestToken.getToken()); } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/ConstantContactApi2.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/ConstantContactApi2.java index 4c61106b0..e8dbb5915 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/ConstantContactApi2.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/ConstantContactApi2.java @@ -17,6 +17,33 @@ public class ConstantContactApi2 extends DefaultApi20 { private static final String AUTHORIZE_URL = "https://oauth2.constantcontact.com/oauth2/oauth/siteowner/authorize?client_id=%s&response_type=code&redirect_uri=%s"; + private static final AccessTokenExtractor ACCESS_TOKEN_EXTRACTOR = new AccessTokenExtractor() { + + @Override + public Token extract(final String response) { + Preconditions.checkEmptyString(response, "Response body is incorrect. Can't extract a token from an empty string"); + + final String regex = "\"access_token\"\\s*:\\s*\"([^&\"]+)\""; + final Matcher matcher = Pattern.compile(regex).matcher(response); + if (matcher.find()) { + final String token = OAuthEncoder.decode(matcher.group(1)); + return new Token(token, "", response); + } else { + throw new OAuthException("Response body is incorrect. Can't extract a token from this: '" + response + "'", null); + } + } + }; + + private ConstantContactApi2() { + } + + private static class InstanceHolder { + private static final ConstantContactApi2 INSTANCE = new ConstantContactApi2(); + } + + public static ConstantContactApi2 instance() { + return InstanceHolder.INSTANCE; + } @Override public String getAccessTokenEndpoint() { @@ -24,7 +51,7 @@ public String getAccessTokenEndpoint() { } @Override - public String getAuthorizationUrl(OAuthConfig config) { + public String getAuthorizationUrl(final OAuthConfig config) { return String.format(AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback())); } @@ -35,20 +62,6 @@ public Verb getAccessTokenVerb() { @Override public AccessTokenExtractor getAccessTokenExtractor() { - return new AccessTokenExtractor() { - - public Token extract(String response) { - Preconditions.checkEmptyString(response, "Response body is incorrect. Can't extract a token from an empty string"); - - String regex = "\"access_token\"\\s*:\\s*\"([^&\"]+)\""; - Matcher matcher = Pattern.compile(regex).matcher(response); - if (matcher.find()) { - String token = OAuthEncoder.decode(matcher.group(1)); - return new Token(token, "", response); - } else { - throw new OAuthException("Response body is incorrect. Can't extract a token from this: '" + response + "'", null); - } - } - }; + return ACCESS_TOKEN_EXTRACTOR; } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/DiggApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/DiggApi.java index 4a6d6c6c5..257a659e4 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/DiggApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/DiggApi.java @@ -8,6 +8,17 @@ public class DiggApi extends DefaultApi10a { private static final String AUTHORIZATION_URL = "http://digg.com/oauth/authorize?oauth_token=%s"; private static final String BASE_URL = "http://services.digg.com/oauth/"; + private DiggApi() { + } + + private static class InstanceHolder { + private static final DiggApi INSTANCE = new DiggApi(); + } + + public static DiggApi instance() { + return InstanceHolder.INSTANCE; + } + @Override public String getRequestTokenEndpoint() { return BASE_URL + "request_token"; @@ -19,7 +30,7 @@ public String getAccessTokenEndpoint() { } @Override - public String getAuthorizationUrl(Token requestToken) { + public String getAuthorizationUrl(final Token requestToken) { return String.format(AUTHORIZATION_URL, requestToken.getToken()); } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/DoktornaraboteApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/DoktornaraboteApi.java index aa9244f9c..9bad734ed 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/DoktornaraboteApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/DoktornaraboteApi.java @@ -16,6 +16,17 @@ public class DoktornaraboteApi extends DefaultApi20 { private static final String AUTHORIZE_URL = "http://auth.doktornarabote.ru/OAuth/Authorize?response_type=code&client_id=%s&redirect_uri=%s&scope=%s"; private static final String TOKEN_URL = "http://auth.doktornarabote.ru/OAuth/Token"; + private DoktornaraboteApi() { + } + + private static class InstanceHolder { + private static final DoktornaraboteApi INSTANCE = new DoktornaraboteApi(); + } + + public static DoktornaraboteApi instance() { + return InstanceHolder.INSTANCE; + } + @Override public Verb getAccessTokenVerb() { return Verb.POST; @@ -27,7 +38,7 @@ public String getAccessTokenEndpoint() { } @Override - public String getAuthorizationUrl(OAuthConfig config) { + public String getAuthorizationUrl(final OAuthConfig config) { Preconditions.checkValidUrl( config.getCallback(), "Must provide a valid url as callback. Doktornarabote does not support OOB"); @@ -53,7 +64,7 @@ public AccessTokenExtractor getAccessTokenExtractor() { } @Override - public OAuthService createService(OAuthConfig config) { + public OAuthService createService(final OAuthConfig config) { return new DoktornaraboteOAuthServiceImpl(this, config); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/DropBoxApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/DropBoxApi.java index ffec0b307..2a78f67d3 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/DropBoxApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/DropBoxApi.java @@ -5,13 +5,24 @@ public class DropBoxApi extends DefaultApi10a { + private DropBoxApi() { + } + + private static class InstanceHolder { + private static final DropBoxApi INSTANCE = new DropBoxApi(); + } + + public static DropBoxApi instance() { + return InstanceHolder.INSTANCE; + } + @Override public String getAccessTokenEndpoint() { return "https://api.dropbox.com/1/oauth/access_token"; } @Override - public String getAuthorizationUrl(Token requestToken) { + public String getAuthorizationUrl(final Token requestToken) { return "https://www.dropbox.com/1/oauth/authorize?oauth_token=" + requestToken.getToken(); } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/EvernoteApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/EvernoteApi.java index e5a39b115..e77f092fc 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/EvernoteApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/EvernoteApi.java @@ -5,6 +5,17 @@ public class EvernoteApi extends DefaultApi10a { + private EvernoteApi() { + } + + private static class InstanceHolder { + private static final EvernoteApi INSTANCE = new EvernoteApi(); + } + + public static EvernoteApi instance() { + return InstanceHolder.INSTANCE; + } + protected String serviceUrl() { return "https://www.evernote.com"; } @@ -20,7 +31,7 @@ public String getAccessTokenEndpoint() { } @Override - public String getAuthorizationUrl(Token requestToken) { + public String getAuthorizationUrl(final Token requestToken) { return String.format(serviceUrl() + "/OAuth.action?oauth_token=%s", requestToken.getToken()); } @@ -29,6 +40,17 @@ public String getAuthorizationUrl(Token requestToken) { */ public static class Sandbox extends EvernoteApi { + private Sandbox() { + } + + private static class InstanceHolder { + private static final Sandbox INSTANCE = new Sandbox(); + } + + public static Sandbox instance() { + return InstanceHolder.INSTANCE; + } + @Override protected String serviceUrl() { return "https://sandbox.evernote.com"; @@ -40,6 +62,17 @@ protected String serviceUrl() { */ public static class Yinxiang extends EvernoteApi { + private Yinxiang() { + } + + private static class InstanceHolder { + private static final Yinxiang INSTANCE = new Yinxiang(); + } + + public static Yinxiang instance() { + return InstanceHolder.INSTANCE; + } + @Override protected String serviceUrl() { return "https://app.yinxiang.com"; 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 c6994a43e..1d6c8457a 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java @@ -10,6 +10,17 @@ public class FacebookApi extends DefaultApi20 { private static final String AUTHORIZE_URL = "https://www.facebook.com/v2.2/dialog/oauth?client_id=%s&redirect_uri=%s"; + private FacebookApi() { + } + + private static class InstanceHolder { + private static final FacebookApi INSTANCE = new FacebookApi(); + } + + public static FacebookApi instance() { + return InstanceHolder.INSTANCE; + } + @Override public String getAccessTokenEndpoint() { return "https://graph.facebook.com/v2.2/oauth/access_token"; diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/FlickrApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/FlickrApi.java index 3417cb7c7..2fb523a0d 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/FlickrApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/FlickrApi.java @@ -11,6 +11,17 @@ */ public class FlickrApi extends DefaultApi10a { + private FlickrApi() { + } + + private static class InstanceHolder { + private static final FlickrApi INSTANCE = new FlickrApi(); + } + + public static FlickrApi instance() { + return InstanceHolder.INSTANCE; + } + /** * {@inheritDoc} */ @@ -23,7 +34,7 @@ public String getAccessTokenEndpoint() { * {@inheritDoc} */ @Override - public String getAuthorizationUrl(Token requestToken) { + public String getAuthorizationUrl(final Token requestToken) { return "https://www.flickr.com/services/oauth/authorize?oauth_token=" + requestToken.getToken(); } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/Foursquare2Api.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/Foursquare2Api.java index b80ab6f0e..8c3857d84 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/Foursquare2Api.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/Foursquare2Api.java @@ -12,13 +12,24 @@ public class Foursquare2Api extends DefaultApi20 { private static final String AUTHORIZATION_URL = "https://foursquare.com/oauth2/authenticate?client_id=%s&response_type=code&redirect_uri=%s"; + private Foursquare2Api() { + } + + private static class InstanceHolder { + private static final Foursquare2Api INSTANCE = new Foursquare2Api(); + } + + public static Foursquare2Api instance() { + return InstanceHolder.INSTANCE; + } + @Override public String getAccessTokenEndpoint() { return "https://foursquare.com/oauth2/access_token?grant_type=" + OAuthConstants.AUTHORIZATION_CODE; } @Override - public String getAuthorizationUrl(OAuthConfig config) { + public String getAuthorizationUrl(final OAuthConfig config) { Preconditions.checkValidUrl(config.getCallback(), "Must provide a valid url as callback. Foursquare2 does not support OOB"); return String.format(AUTHORIZATION_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback())); } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/FoursquareApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/FoursquareApi.java index 108b8cf39..c3f55cd1d 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/FoursquareApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/FoursquareApi.java @@ -7,6 +7,17 @@ public class FoursquareApi extends DefaultApi10a { private static final String AUTHORIZATION_URL = "http://foursquare.com/oauth/authorize?oauth_token=%s"; + private FoursquareApi() { + } + + private static class InstanceHolder { + private static final FoursquareApi INSTANCE = new FoursquareApi(); + } + + public static FoursquareApi instance() { + return InstanceHolder.INSTANCE; + } + @Override public String getAccessTokenEndpoint() { return "http://foursquare.com/oauth/access_token"; @@ -18,7 +29,7 @@ public String getRequestTokenEndpoint() { } @Override - public String getAuthorizationUrl(Token requestToken) { + public String getAuthorizationUrl(final Token requestToken) { return String.format(AUTHORIZATION_URL, requestToken.getToken()); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/FreelancerApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/FreelancerApi.java index 793fbd24b..ef6a36e49 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/FreelancerApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/FreelancerApi.java @@ -8,6 +8,17 @@ public class FreelancerApi extends DefaultApi10a { private static final String AUTHORIZATION_URL = "http://www.freelancer.com/users/api-token/auth.php?oauth_token=%s"; + private FreelancerApi() { + } + + private static class InstanceHolder { + private static final FreelancerApi INSTANCE = new FreelancerApi(); + } + + public static FreelancerApi instance() { + return InstanceHolder.INSTANCE; + } + @Override public String getAccessTokenEndpoint() { return "http://api.freelancer.com/RequestAccessToken/requestAccessToken.xml?"; @@ -29,7 +40,7 @@ public Verb getRequestTokenVerb() { } @Override - public String getAuthorizationUrl(Token requestToken) { + public String getAuthorizationUrl(final Token requestToken) { return String.format(AUTHORIZATION_URL, requestToken.getToken()); } @@ -37,6 +48,17 @@ public static class Sandbox extends FreelancerApi { private static final String SANDBOX_AUTHORIZATION_URL = "http://www.sandbox.freelancer.com/users/api-token/auth.php"; + private Sandbox() { + } + + private static class InstanceHolder { + private static final Sandbox INSTANCE = new Sandbox(); + } + + public static Sandbox instance() { + return InstanceHolder.INSTANCE; + } + @Override public String getRequestTokenEndpoint() { return "http://api.sandbox.freelancer.com/RequestRequestToken/requestRequestToken.xml"; @@ -48,7 +70,7 @@ public String getAccessTokenEndpoint() { } @Override - public String getAuthorizationUrl(Token requestToken) { + public String getAuthorizationUrl(final Token requestToken) { return String.format(SANDBOX_AUTHORIZATION_URL + "?oauth_token=%s", requestToken.getToken()); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/GetGlueApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/GetGlueApi.java index 575c67100..21a40cc24 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/GetGlueApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/GetGlueApi.java @@ -9,6 +9,17 @@ public class GetGlueApi extends DefaultApi10a { private static final String REQUEST_TOKEN_RESOURCE = "https://api.getglue.com/oauth/request_token"; private static final String ACCESS_TOKEN_RESOURCE = "https://api.getglue.com/oauth/access_token"; + private GetGlueApi() { + } + + private static class InstanceHolder { + private static final GetGlueApi INSTANCE = new GetGlueApi(); + } + + public static GetGlueApi instance() { + return InstanceHolder.INSTANCE; + } + @Override public String getAccessTokenEndpoint() { return ACCESS_TOKEN_RESOURCE; @@ -20,7 +31,7 @@ public String getRequestTokenEndpoint() { } @Override - public String getAuthorizationUrl(Token requestToken) { + public String getAuthorizationUrl(final Token requestToken) { return String.format(AUTHORIZE_URL, requestToken.getToken()); } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/GitHubApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/GitHubApi.java index 8f8821cdd..7b2d0ff96 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/GitHubApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/GitHubApi.java @@ -10,13 +10,24 @@ public class GitHubApi extends DefaultApi20 { private static final String AUTHORIZE_URL = "https://github.com/login/oauth/authorize?client_id=%s&redirect_uri=%s"; + private GitHubApi() { + } + + private static class InstanceHolder { + private static final GitHubApi INSTANCE = new GitHubApi(); + } + + public static GitHubApi instance() { + return InstanceHolder.INSTANCE; + } + @Override public String getAccessTokenEndpoint() { return "https://github.com/login/oauth/access_token"; } @Override - public String getAuthorizationUrl(OAuthConfig config) { + public String getAuthorizationUrl(final OAuthConfig config) { Preconditions.checkValidUrl(config.getCallback(), "Must provide a valid url as callback. GitHub does not support OOB"); final StringBuilder sb = new StringBuilder(String.format(AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()))); if (config.hasScope()) { diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/GoogleApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/GoogleApi.java index fd5b33fd0..1dd7bfd72 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/GoogleApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/GoogleApi.java @@ -8,6 +8,17 @@ public class GoogleApi extends DefaultApi10a { private static final String AUTHORIZATION_URL = "https://www.google.com/accounts/OAuthAuthorizeToken?oauth_token=%s"; + private GoogleApi() { + } + + private static class InstanceHolder { + private static final GoogleApi INSTANCE = new GoogleApi(); + } + + public static GoogleApi instance() { + return InstanceHolder.INSTANCE; + } + @Override public String getAccessTokenEndpoint() { return "https://www.google.com/accounts/OAuthGetAccessToken"; @@ -29,7 +40,7 @@ public Verb getRequestTokenVerb() { } @Override - public String getAuthorizationUrl(Token requestToken) { + public String getAuthorizationUrl(final Token requestToken) { return String.format(AUTHORIZATION_URL, requestToken.getToken()); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/GoogleApi20.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/GoogleApi20.java index 1b006b0f0..af911782c 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/GoogleApi20.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/GoogleApi20.java @@ -9,13 +9,23 @@ import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.oauth.OAuthService; import com.github.scribejava.core.utils.OAuthEncoder; -import com.github.scribejava.core.utils.Preconditions; public class GoogleApi20 extends DefaultApi20 { private static final String AUTHORIZE_URL = "https://accounts.google.com/o/oauth2/auth?response_type=code&client_id=%s&redirect_uri=%s&scope=%s"; + private GoogleApi20() { + } + + private static class InstanceHolder { + private static final GoogleApi20 INSTANCE = new GoogleApi20(); + } + + public static GoogleApi20 instance() { + return InstanceHolder.INSTANCE; + } + @Override public Verb getAccessTokenVerb() { return Verb.POST; @@ -44,7 +54,7 @@ public AccessTokenExtractor getAccessTokenExtractor() { } @Override - public OAuthService createService(OAuthConfig config) { + public OAuthService createService(final OAuthConfig config) { return new GoogleOAuthServiceImpl(this, config); } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/HHApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/HHApi.java index c05980cc4..7c08d540c 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/HHApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/HHApi.java @@ -15,6 +15,18 @@ public class HHApi extends DefaultApi20 { private static final String AUTHORIZE_URL = "https://m.hh.ru/oauth/authorize?response_type=code&client_id=%s"; private static final String TOKEN_URL = "https://m.hh.ru/oauth/token?grant_type=" + OAuthConstants.AUTHORIZATION_CODE; + private HHApi() { + } + + private static class InstanceHolder { + private static final HHApi INSTANCE = new HHApi(); + } + + public static HHApi instance() { + return InstanceHolder.INSTANCE; + } + + @Override public Verb getAccessTokenVerb() { return Verb.POST; } @@ -25,7 +37,7 @@ public String getAccessTokenEndpoint() { } @Override - public String getAuthorizationUrl(OAuthConfig config) { + public String getAuthorizationUrl(final OAuthConfig config) { return String.format(AUTHORIZE_URL, config.getApiKey()); } @@ -35,7 +47,7 @@ public AccessTokenExtractor getAccessTokenExtractor() { } @Override - public OAuthService createService(OAuthConfig config) { + public OAuthService createService(final OAuthConfig config) { return new HHOAuthServiceImpl(this, config); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java index 6f7bdfcc6..a6ee56191 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java @@ -8,11 +8,22 @@ import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.oauth.OAuthService; -public final class ImgurApi extends DefaultApi20 { +public class ImgurApi extends DefaultApi20 { private static final String AUTHORIZATION_URL = "https://api.imgur.com/oauth2/authorize?client_id=%s&response_type=%s"; + private ImgurApi() { + } + + private static class InstanceHolder { + private static final ImgurApi INSTANCE = new ImgurApi(); + } + + public static ImgurApi instance() { + return InstanceHolder.INSTANCE; + } + @Override public Verb getAccessTokenVerb() { return Verb.POST; diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/KaixinApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/KaixinApi.java index b0be0f553..b24b99714 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/KaixinApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/KaixinApi.java @@ -1,37 +1,48 @@ -package com.github.scribejava.apis; - -import com.github.scribejava.core.builder.api.DefaultApi10a; -import com.github.scribejava.core.model.Token; -import com.github.scribejava.core.model.Verb; - -public class KaixinApi extends DefaultApi10a { - - private static final String REQUEST_TOKEN_URL = "http://api.kaixin001.com/oauth/request_token"; - private static final String ACCESS_TOKEN_URL = "http://api.kaixin001.com/oauth/access_token"; - private static final String AUTHORIZE_URL = "http://api.kaixin001.com/oauth/authorize?oauth_token=%s"; - - @Override - public String getRequestTokenEndpoint() { - return REQUEST_TOKEN_URL; - } - - @Override - public String getAccessTokenEndpoint() { - return ACCESS_TOKEN_URL; - } - - @Override - public String getAuthorizationUrl(Token requestToken) { - return String.format(AUTHORIZE_URL, requestToken.getToken()); - } - - @Override - public Verb getRequestTokenVerb() { - return Verb.GET; - } - - @Override - public Verb getAccessTokenVerb() { - return Verb.GET; - } -} +package com.github.scribejava.apis; + +import com.github.scribejava.core.builder.api.DefaultApi10a; +import com.github.scribejava.core.model.Token; +import com.github.scribejava.core.model.Verb; + +public class KaixinApi extends DefaultApi10a { + + private static final String REQUEST_TOKEN_URL = "http://api.kaixin001.com/oauth/request_token"; + private static final String ACCESS_TOKEN_URL = "http://api.kaixin001.com/oauth/access_token"; + private static final String AUTHORIZE_URL = "http://api.kaixin001.com/oauth/authorize?oauth_token=%s"; + + private KaixinApi() { + } + + private static class InstanceHolder { + private static final KaixinApi INSTANCE = new KaixinApi(); + } + + public static KaixinApi instance() { + return InstanceHolder.INSTANCE; + } + + @Override + public String getRequestTokenEndpoint() { + return REQUEST_TOKEN_URL; + } + + @Override + public String getAccessTokenEndpoint() { + return ACCESS_TOKEN_URL; + } + + @Override + public String getAuthorizationUrl(final Token requestToken) { + return String.format(AUTHORIZE_URL, requestToken.getToken()); + } + + @Override + public Verb getRequestTokenVerb() { + return Verb.GET; + } + + @Override + public Verb getAccessTokenVerb() { + return Verb.GET; + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/KaixinApi20.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/KaixinApi20.java index 54f5d9505..a30b86a5e 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/KaixinApi20.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/KaixinApi20.java @@ -15,6 +15,17 @@ public class KaixinApi20 extends DefaultApi20 { private static final String AUTHORIZE_URL = "http://api.kaixin001.com/oauth2/authorize?client_id=%s&redirect_uri=%s&response_type=code"; private static final String SCOPED_AUTHORIZE_URL = AUTHORIZE_URL + "&scope=%s"; + private KaixinApi20() { + } + + private static class InstanceHolder { + private static final KaixinApi20 INSTANCE = new KaixinApi20(); + } + + public static KaixinApi20 instance() { + return InstanceHolder.INSTANCE; + } + @Override public AccessTokenExtractor getAccessTokenExtractor() { return new JsonTokenExtractor(); @@ -26,7 +37,7 @@ public String getAccessTokenEndpoint() { } @Override - public String getAuthorizationUrl(OAuthConfig config) { + public String getAuthorizationUrl(final OAuthConfig config) { // Append scope if present if (config.hasScope()) { return String.format(SCOPED_AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()), OAuthEncoder.encode(config. diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi.java index 5e9a94617..8b269409d 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi.java @@ -12,13 +12,21 @@ public class LinkedInApi extends DefaultApi10a { private static final String AUTHORIZE_URL = "https://api.linkedin.com/uas/oauth/authenticate?oauth_token=%s"; private static final String REQUEST_TOKEN_URL = "https://api.linkedin.com/uas/oauth/requestToken"; + private static class InstanceHolder { + private static final LinkedInApi INSTANCE = new LinkedInApi(); + } + + public static LinkedInApi instance() { + return InstanceHolder.INSTANCE; + } + private final Set scopes; public LinkedInApi() { scopes = Collections.emptySet(); } - public LinkedInApi(Set scopes) { + public LinkedInApi(final Set scopes) { this.scopes = Collections.unmodifiableSet(scopes); } @@ -33,20 +41,20 @@ public String getRequestTokenEndpoint() { } private String scopesAsString() { - StringBuilder builder = new StringBuilder(); - for (String scope : scopes) { + final StringBuilder builder = new StringBuilder(); + for (final String scope : scopes) { builder.append("+" + scope); } return builder.substring(1); } @Override - public String getAuthorizationUrl(Token requestToken) { + public String getAuthorizationUrl(final Token requestToken) { return String.format(AUTHORIZE_URL, requestToken.getToken()); } - public static LinkedInApi withScopes(String... scopes) { - Set scopeSet = new HashSet(Arrays.asList(scopes)); + public static LinkedInApi withScopes(final String... scopes) { + final Set scopeSet = new HashSet<>(Arrays.asList(scopes)); return new LinkedInApi(scopeSet); } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi20.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi20.java index 3a50ad45d..415641ab9 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi20.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi20.java @@ -18,6 +18,17 @@ public class LinkedInApi20 extends DefaultApi20 { private static final String SCOPED_AUTHORIZE_URL = AUTHORIZE_URL + "&scope=%s"; + private LinkedInApi20() { + } + + private static class InstanceHolder { + private static final LinkedInApi20 INSTANCE = new LinkedInApi20(); + } + + public static LinkedInApi20 instance() { + return InstanceHolder.INSTANCE; + } + @Override public Verb getAccessTokenVerb() { return Verb.GET; diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/LiveApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/LiveApi.java index c5bd8108d..c239ea28c 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/LiveApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/LiveApi.java @@ -13,13 +13,24 @@ public class LiveApi extends DefaultApi20 { private static final String AUTHORIZE_URL = "https://oauth.live.com/authorize?client_id=%s&redirect_uri=%s&response_type=code"; private static final String SCOPED_AUTHORIZE_URL = AUTHORIZE_URL + "&scope=%s"; + private LiveApi() { + } + + private static class InstanceHolder { + private static final LiveApi INSTANCE = new LiveApi(); + } + + public static LiveApi instance() { + return InstanceHolder.INSTANCE; + } + @Override public String getAccessTokenEndpoint() { return "https://login.live.com/oauth20_token.srf?grant_type=" + OAuthConstants.AUTHORIZATION_CODE; } @Override - public String getAuthorizationUrl(OAuthConfig config) { + public String getAuthorizationUrl(final OAuthConfig config) { Preconditions.checkValidUrl(config.getCallback(), "Must provide a valid url as callback. Live does not support OOB"); // Append scope if present diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/LoveFilmApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/LoveFilmApi.java index 40b235f7b..751b51f5a 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/LoveFilmApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/LoveFilmApi.java @@ -9,6 +9,17 @@ public class LoveFilmApi extends DefaultApi10a { private static final String ACCESS_TOKEN_URL = "http://openapi.lovefilm.com/oauth/access_token"; private static final String AUTHORIZE_URL = "https://www.lovefilm.com/activate?oauth_token=%s"; + private LoveFilmApi() { + } + + private static class InstanceHolder { + private static final LoveFilmApi INSTANCE = new LoveFilmApi(); + } + + public static LoveFilmApi instance() { + return InstanceHolder.INSTANCE; + } + @Override public String getRequestTokenEndpoint() { return REQUEST_TOKEN_URL; @@ -20,7 +31,7 @@ public String getAccessTokenEndpoint() { } @Override - public String getAuthorizationUrl(Token requestToken) { + public String getAuthorizationUrl(final Token requestToken) { return String.format(AUTHORIZE_URL, requestToken.getToken()); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java index c208efd91..d76e4fb42 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java @@ -15,6 +15,17 @@ public class MailruApi extends DefaultApi20 { private static final String AUTHORIZE_URL = "https://connect.mail.ru/oauth/authorize?client_id=%s&redirect_uri=%s&response_type=code"; private static final String SCOPED_AUTHORIZE_URL = AUTHORIZE_URL + "&scope=%s"; + private MailruApi() { + } + + private static class InstanceHolder { + private static final MailruApi INSTANCE = new MailruApi(); + } + + public static MailruApi instance() { + return InstanceHolder.INSTANCE; + } + @Override public Verb getAccessTokenVerb() { return Verb.POST; @@ -26,7 +37,7 @@ public String getAccessTokenEndpoint() { } @Override - public String getAuthorizationUrl(OAuthConfig config) { + public String getAuthorizationUrl(final OAuthConfig config) { Preconditions.checkValidUrl(config.getCallback(), "Valid url is required for a callback. Mail.ru does not support OOB"); if (config.hasScope()) { // Appending scope if present return String.format(SCOPED_AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()), OAuthEncoder.encode(config. @@ -37,7 +48,7 @@ public String getAuthorizationUrl(OAuthConfig config) { } @Override - public OAuthService createService(OAuthConfig config) { + public OAuthService createService(final OAuthConfig config) { return new MailruOAuthServiceImpl(this, config); } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/MeetupApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/MeetupApi.java index cf030526c..60a2de4f1 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/MeetupApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/MeetupApi.java @@ -10,6 +10,17 @@ public class MeetupApi extends DefaultApi10a { private static final String AUTHORIZE_URL = "http://www.meetup.com/authenticate?oauth_token=%s"; + private MeetupApi() { + } + + private static class InstanceHolder { + private static final MeetupApi INSTANCE = new MeetupApi(); + } + + public static MeetupApi instance() { + return InstanceHolder.INSTANCE; + } + @Override public String getRequestTokenEndpoint() { return "http://api.meetup.com/oauth/request/"; @@ -21,7 +32,7 @@ public String getAccessTokenEndpoint() { } @Override - public String getAuthorizationUrl(Token requestToken) { + public String getAuthorizationUrl(final Token requestToken) { return String.format(AUTHORIZE_URL, requestToken.getToken()); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/MendeleyApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/MendeleyApi.java index e2d8e443f..2195dc4cf 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/MendeleyApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/MendeleyApi.java @@ -12,6 +12,17 @@ public class MendeleyApi extends DefaultApi10a { private static final String AUTHORIZATION_URL = "http://api.mendeley.com/oauth/authorize?oauth_token=%s"; + private MendeleyApi() { + } + + private static class InstanceHolder { + private static final MendeleyApi INSTANCE = new MendeleyApi(); + } + + public static MendeleyApi instance() { + return InstanceHolder.INSTANCE; + } + @Override public String getRequestTokenEndpoint() { return "http://api.mendeley.com/oauth/request_token/"; diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/MisoApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/MisoApi.java index 9dbbfeb1d..b4be35dda 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/MisoApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/MisoApi.java @@ -9,6 +9,17 @@ public class MisoApi extends DefaultApi10a { private static final String REQUEST_TOKEN_RESOURCE = "http://gomiso.com/oauth/request_token"; private static final String ACCESS_TOKEN_RESOURCE = "http://gomiso.com/oauth/access_token"; + private MisoApi() { + } + + private static class InstanceHolder { + private static final MisoApi INSTANCE = new MisoApi(); + } + + public static MisoApi instance() { + return InstanceHolder.INSTANCE; + } + @Override public String getAccessTokenEndpoint() { return ACCESS_TOKEN_RESOURCE; @@ -20,7 +31,7 @@ public String getRequestTokenEndpoint() { } @Override - public String getAuthorizationUrl(Token requestToken) { + public String getAuthorizationUrl(final Token requestToken) { return String.format(AUTHORIZE_URL, requestToken.getToken()); } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/NetProspexApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/NetProspexApi.java index 3118fb1ff..9c679edbb 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/NetProspexApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/NetProspexApi.java @@ -9,6 +9,17 @@ public class NetProspexApi extends DefaultApi10a { private static final String ACCESS_TOKEN_URL = "https://api.netprospex.com/1.0/oauth/access-token"; private static final String AUTHORIZE_URL = "https://api.netprospex.com/1.0/oauth/authorize?oauth_token=%s"; + private NetProspexApi() { + } + + private static class InstanceHolder { + private static final NetProspexApi INSTANCE = new NetProspexApi(); + } + + public static NetProspexApi instance() { + return InstanceHolder.INSTANCE; + } + @Override public String getRequestTokenEndpoint() { return REQUEST_TOKEN_URL; @@ -20,7 +31,7 @@ public String getAccessTokenEndpoint() { } @Override - public String getAuthorizationUrl(Token requestToken) { + public String getAuthorizationUrl(final Token requestToken) { return String.format(AUTHORIZE_URL, requestToken.getToken()); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/NeteaseWeibooApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/NeteaseWeibooApi.java index 75ff524f9..9a3e740bb 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/NeteaseWeibooApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/NeteaseWeibooApi.java @@ -10,6 +10,17 @@ public class NeteaseWeibooApi extends DefaultApi10a { private static final String AUTHORIZE_URL = "http://api.t.163.com/oauth/authorize?oauth_token=%s"; private static final String AUTHENTICATE_URL = "http://api.t.163.com/oauth/authenticate?oauth_token=%s"; + private NeteaseWeibooApi() { + } + + private static class InstanceHolder { + private static final NeteaseWeibooApi INSTANCE = new NeteaseWeibooApi(); + } + + public static NeteaseWeibooApi instance() { + return InstanceHolder.INSTANCE; + } + @Override public String getRequestTokenEndpoint() { return REQUEST_TOKEN_URL; diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java index de23a3a37..faabf0e94 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java @@ -15,6 +15,17 @@ public class OdnoklassnikiApi extends DefaultApi20 { private static final String AUTHORIZE_URL = "http://www.odnoklassniki.ru/oauth/authorize?client_id=%s&response_type=code&redirect_uri=%s"; private static final String SCOPED_AUTHORIZE_URL = String.format("%s&scope=%%s", AUTHORIZE_URL); + private OdnoklassnikiApi() { + } + + private static class InstanceHolder { + private static final OdnoklassnikiApi INSTANCE = new OdnoklassnikiApi(); + } + + public static OdnoklassnikiApi instance() { + return InstanceHolder.INSTANCE; + } + @Override public String getAccessTokenEndpoint() { return "http://api.odnoklassniki.ru/oauth/token.do"; @@ -26,7 +37,7 @@ public Verb getAccessTokenVerb() { } @Override - public String getAuthorizationUrl(OAuthConfig config) { + public String getAuthorizationUrl(final OAuthConfig config) { Preconditions.checkValidUrl(config.getCallback(), "Valid url is required for a callback. Odnoklassniki does not support OOB"); if (config.hasScope()) { return String.format( @@ -37,7 +48,7 @@ public String getAuthorizationUrl(OAuthConfig config) { } @Override - public OAuthService createService(OAuthConfig config) { + public OAuthService createService(final OAuthConfig config) { return new OdnoklassnikiServiceImpl(this, config); } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/PinterestApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/PinterestApi.java index ca439a6e3..1f0032ee9 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/PinterestApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/PinterestApi.java @@ -14,6 +14,17 @@ public class PinterestApi extends DefaultApi20 { private static final String AUTHORIZE_URL = "https://api.pinterest.com/oauth?response_type=code&client_id=%s&redirect_uri=%s"; private static final String SCOPED_AUTHORIZE_URL = AUTHORIZE_URL + "&scope=%s"; + private PinterestApi() { + } + + private static class InstanceHolder { + private static final PinterestApi INSTANCE = new PinterestApi(); + } + + public static PinterestApi instance() { + return InstanceHolder.INSTANCE; + } + @Override public String getAccessTokenEndpoint() { return "https://api.pinterest.com/v1/oauth/token?grant_type=" + OAuthConstants.AUTHORIZATION_CODE; @@ -25,7 +36,7 @@ public Verb getAccessTokenVerb() { } @Override - public String getAuthorizationUrl(OAuthConfig config) { + public String getAuthorizationUrl(final OAuthConfig config) { Preconditions.checkValidUrl(config.getCallback(), "Must provide a valid url as callback. Pinterest does not support OOB"); // Append scope if present diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/PlurkApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/PlurkApi.java index a1cc67782..c90b2afaf 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/PlurkApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/PlurkApi.java @@ -9,13 +9,24 @@ public class PlurkApi extends DefaultApi10a { private static final String AUTHORIZATION_URL = "http://www.plurk.com/OAuth/authorize?oauth_token=%s"; private static final String ACCESS_TOKEN_URL = "http://www.plurk.com/OAuth/access_token"; + private PlurkApi() { + } + + private static class InstanceHolder { + private static final PlurkApi INSTANCE = new PlurkApi(); + } + + public static PlurkApi instance() { + return InstanceHolder.INSTANCE; + } + @Override public String getRequestTokenEndpoint() { return REQUEST_TOKEN_URL; } @Override - public String getAuthorizationUrl(Token requestToken) { + public String getAuthorizationUrl(final Token requestToken) { return String.format(AUTHORIZATION_URL, requestToken.getToken()); } @@ -28,8 +39,19 @@ public static class Mobile extends PlurkApi { private static final String AUTHORIZATION_URL = "http://www.plurk.com/m/authorize?oauth_token=%s"; + private Mobile() { + } + + private static class InstanceHolder { + private static final Mobile INSTANCE = new Mobile(); + } + + public static Mobile instance() { + return InstanceHolder.INSTANCE; + } + @Override - public String getAuthorizationUrl(Token requestToken) { + public String getAuthorizationUrl(final Token requestToken) { return String.format(AUTHORIZATION_URL, requestToken.getToken()); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/Px500Api.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/Px500Api.java index a6a407111..006ae0b3f 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/Px500Api.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/Px500Api.java @@ -7,6 +7,17 @@ public class Px500Api extends DefaultApi10a { private static final String AUTHORIZATION_URL = "https://api.500px.com/v1/oauth/authorize?oauth_token=%s"; + private Px500Api() { + } + + private static class InstanceHolder { + private static final Px500Api INSTANCE = new Px500Api(); + } + + public static Px500Api instance() { + return InstanceHolder.INSTANCE; + } + @Override public String getAccessTokenEndpoint() { return "https://api.500px.com/v1/oauth/access_token"; @@ -18,7 +29,7 @@ public String getRequestTokenEndpoint() { } @Override - public String getAuthorizationUrl(Token requestToken) { + public String getAuthorizationUrl(final Token requestToken) { return String.format(AUTHORIZATION_URL, requestToken.getToken()); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/QWeiboApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/QWeiboApi.java index bac788b91..180207306 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/QWeiboApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/QWeiboApi.java @@ -1,26 +1,37 @@ -package com.github.scribejava.apis; - -import com.github.scribejava.core.builder.api.DefaultApi10a; -import com.github.scribejava.core.model.Token; - -public class QWeiboApi extends DefaultApi10a { - - private static final String REQUEST_TOKEN_URL = "https://open.t.qq.com/cgi-bin/request_token"; - private static final String ACCESS_TOKEN_URL = "https://open.t.qq.com/cgi-bin/access_token"; - private static final String AUTHORIZE_URL = "https://open.t.qq.com/cgi-bin/authorize?oauth_token=%s"; - - @Override - public String getRequestTokenEndpoint() { - return REQUEST_TOKEN_URL; - } - - @Override - public String getAccessTokenEndpoint() { - return ACCESS_TOKEN_URL; - } - - @Override - public String getAuthorizationUrl(Token requestToken) { - return String.format(AUTHORIZE_URL, requestToken.getToken()); - } -} +package com.github.scribejava.apis; + +import com.github.scribejava.core.builder.api.DefaultApi10a; +import com.github.scribejava.core.model.Token; + +public class QWeiboApi extends DefaultApi10a { + + private static final String REQUEST_TOKEN_URL = "https://open.t.qq.com/cgi-bin/request_token"; + private static final String ACCESS_TOKEN_URL = "https://open.t.qq.com/cgi-bin/access_token"; + private static final String AUTHORIZE_URL = "https://open.t.qq.com/cgi-bin/authorize?oauth_token=%s"; + + private QWeiboApi() { + } + + private static class InstanceHolder { + private static final QWeiboApi INSTANCE = new QWeiboApi(); + } + + public static QWeiboApi instance() { + return InstanceHolder.INSTANCE; + } + + @Override + public String getRequestTokenEndpoint() { + return REQUEST_TOKEN_URL; + } + + @Override + public String getAccessTokenEndpoint() { + return ACCESS_TOKEN_URL; + } + + @Override + public String getAuthorizationUrl(final Token requestToken) { + return String.format(AUTHORIZE_URL, requestToken.getToken()); + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/RenrenApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/RenrenApi.java index 903b53bcb..bf38bbf63 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/RenrenApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/RenrenApi.java @@ -15,6 +15,17 @@ public class RenrenApi extends DefaultApi20 { private static final String AUTHORIZE_URL = "https://graph.renren.com/oauth/authorize?client_id=%s&redirect_uri=%s&response_type=code"; private static final String SCOPED_AUTHORIZE_URL = AUTHORIZE_URL + "&scope=%s"; + private RenrenApi() { + } + + private static class InstanceHolder { + private static final RenrenApi INSTANCE = new RenrenApi(); + } + + public static RenrenApi instance() { + return InstanceHolder.INSTANCE; + } + @Override public AccessTokenExtractor getAccessTokenExtractor() { return new JsonTokenExtractor(); @@ -26,7 +37,7 @@ public String getAccessTokenEndpoint() { } @Override - public String getAuthorizationUrl(OAuthConfig config) { + public String getAuthorizationUrl(final OAuthConfig config) { // Append scope if present if (config.hasScope()) { return String.format(SCOPED_AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()), OAuthEncoder.encode(config. diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/SapoApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/SapoApi.java index de21a248e..012493268 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/SapoApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/SapoApi.java @@ -10,6 +10,17 @@ public class SapoApi extends DefaultApi10a { private static final String ACCESS_URL = "https://id.sapo.pt/oauth/access_token"; private static final String REQUEST_URL = "https://id.sapo.pt/oauth/request_token"; + private SapoApi() { + } + + private static class InstanceHolder { + private static final SapoApi INSTANCE = new SapoApi(); + } + + public static SapoApi instance() { + return InstanceHolder.INSTANCE; + } + @Override public String getAccessTokenEndpoint() { return ACCESS_URL; @@ -21,7 +32,7 @@ public String getRequestTokenEndpoint() { } @Override - public String getAuthorizationUrl(Token requestToken) { + public String getAuthorizationUrl(final Token requestToken) { return String.format(AUTHORIZE_URL, requestToken.getToken()); } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/SimpleGeoApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/SimpleGeoApi.java index d5b2d50f8..21b9c74b4 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/SimpleGeoApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/SimpleGeoApi.java @@ -10,6 +10,17 @@ public class SimpleGeoApi extends DefaultApi10a { private static final String ENDPOINT = "these are not used since SimpleGeo uses 2 legged OAuth"; + private SimpleGeoApi() { + } + + private static class InstanceHolder { + private static final SimpleGeoApi INSTANCE = new SimpleGeoApi(); + } + + public static SimpleGeoApi instance() { + return InstanceHolder.INSTANCE; + } + @Override public String getRequestTokenEndpoint() { return ENDPOINT; diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/SinaWeiboApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/SinaWeiboApi.java index 7f796eb47..e9211eb93 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/SinaWeiboApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/SinaWeiboApi.java @@ -9,6 +9,17 @@ public class SinaWeiboApi extends DefaultApi10a { private static final String ACCESS_TOKEN_URL = "http://api.t.sina.com.cn/oauth/access_token"; private static final String AUTHORIZE_URL = "http://api.t.sina.com.cn/oauth/authorize?oauth_token=%s"; + private SinaWeiboApi() { + } + + private static class InstanceHolder { + private static final SinaWeiboApi INSTANCE = new SinaWeiboApi(); + } + + public static SinaWeiboApi instance() { + return InstanceHolder.INSTANCE; + } + @Override public String getRequestTokenEndpoint() { return REQUEST_TOKEN_URL; @@ -20,7 +31,7 @@ public String getAccessTokenEndpoint() { } @Override - public String getAuthorizationUrl(Token requestToken) { + public String getAuthorizationUrl(final Token requestToken) { return String.format(AUTHORIZE_URL, requestToken.getToken()); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/SinaWeiboApi20.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/SinaWeiboApi20.java index 8f1ce73b2..5d23c5aca 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/SinaWeiboApi20.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/SinaWeiboApi20.java @@ -16,6 +16,17 @@ public class SinaWeiboApi20 extends DefaultApi20 { private static final String AUTHORIZE_URL = "https://api.weibo.com/oauth2/authorize?client_id=%s&redirect_uri=%s&response_type=code"; private static final String SCOPED_AUTHORIZE_URL = AUTHORIZE_URL + "&scope=%s"; + private SinaWeiboApi20() { + } + + private static class InstanceHolder { + private static final SinaWeiboApi20 INSTANCE = new SinaWeiboApi20(); + } + + public static SinaWeiboApi20 instance() { + return InstanceHolder.INSTANCE; + } + @Override public Verb getAccessTokenVerb() { return Verb.POST; @@ -32,7 +43,7 @@ public String getAccessTokenEndpoint() { } @Override - public String getAuthorizationUrl(OAuthConfig config) { + public String getAuthorizationUrl(final OAuthConfig config) { // Append scope if present if (config.hasScope()) { return String.format(SCOPED_AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()), OAuthEncoder.encode(config. diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/SkyrockApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/SkyrockApi.java index 74c368ca0..2c6a49c60 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/SkyrockApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/SkyrockApi.java @@ -16,6 +16,17 @@ public class SkyrockApi extends DefaultApi10a { private static final String AUTHORIZE_URL = "/oauth/authorize?oauth_token=%s"; private static final String ACCESS_TOKEN_RESOURCE = "/oauth/token"; + private SkyrockApi() { + } + + private static class InstanceHolder { + private static final SkyrockApi INSTANCE = new SkyrockApi(); + } + + public static SkyrockApi instance() { + return InstanceHolder.INSTANCE; + } + @Override public String getAccessTokenEndpoint() { return API_ENDPOINT + ACCESS_TOKEN_RESOURCE; @@ -27,7 +38,7 @@ public String getRequestTokenEndpoint() { } @Override - public String getAuthorizationUrl(Token requestToken) { + public String getAuthorizationUrl(final Token requestToken) { return String.format(API_ENDPOINT + AUTHORIZE_URL, requestToken.getToken()); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/SohuWeiboApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/SohuWeiboApi.java index 6d56d5906..8c443da4c 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/SohuWeiboApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/SohuWeiboApi.java @@ -9,6 +9,17 @@ public class SohuWeiboApi extends DefaultApi10a { private static final String ACCESS_TOKEN_URL = "http://api.t.sohu.com/oauth/access_token"; private static final String AUTHORIZE_URL = "http://api.t.sohu.com/oauth/authorize?oauth_token=%s"; + private SohuWeiboApi() { + } + + private static class InstanceHolder { + private static final SohuWeiboApi INSTANCE = new SohuWeiboApi(); + } + + public static SohuWeiboApi instance() { + return InstanceHolder.INSTANCE; + } + @Override public String getRequestTokenEndpoint() { return REQUEST_TOKEN_URL; @@ -20,7 +31,7 @@ public String getAccessTokenEndpoint() { } @Override - public String getAuthorizationUrl(Token requestToken) { + public String getAuthorizationUrl(final Token requestToken) { return String.format(AUTHORIZE_URL, requestToken.getToken()); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/TrelloApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/TrelloApi.java index d3ce8372b..97359df77 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/TrelloApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/TrelloApi.java @@ -7,6 +7,17 @@ public class TrelloApi extends DefaultApi10a { private static final String AUTHORIZE_URL = "https://trello.com/1/OAuthAuthorizeToken?oauth_token=%s"; + private TrelloApi() { + } + + private static class InstanceHolder { + private static final TrelloApi INSTANCE = new TrelloApi(); + } + + public static TrelloApi instance() { + return InstanceHolder.INSTANCE; + } + @Override public String getAccessTokenEndpoint() { return "https://trello.com/1/OAuthGetAccessToken"; @@ -18,7 +29,7 @@ public String getRequestTokenEndpoint() { } @Override - public String getAuthorizationUrl(Token requestToken) { + public String getAuthorizationUrl(final Token requestToken) { return String.format(AUTHORIZE_URL, requestToken.getToken()); } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/TumblrApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/TumblrApi.java index 3330c2320..8c2791891 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/TumblrApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/TumblrApi.java @@ -9,6 +9,17 @@ public class TumblrApi extends DefaultApi10a { private static final String REQUEST_TOKEN_RESOURCE = "http://www.tumblr.com/oauth/request_token"; private static final String ACCESS_TOKEN_RESOURCE = "http://www.tumblr.com/oauth/access_token"; + private TumblrApi() { + } + + private static class InstanceHolder { + private static final TumblrApi INSTANCE = new TumblrApi(); + } + + public static TumblrApi instance() { + return InstanceHolder.INSTANCE; + } + @Override public String getAccessTokenEndpoint() { return ACCESS_TOKEN_RESOURCE; @@ -20,7 +31,7 @@ public String getRequestTokenEndpoint() { } @Override - public String getAuthorizationUrl(Token requestToken) { + public String getAuthorizationUrl(final Token requestToken) { return String.format(AUTHORIZE_URL, requestToken.getToken()); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/TutByApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/TutByApi.java index 6bd46476b..7ce50234e 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/TutByApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/TutByApi.java @@ -14,6 +14,17 @@ public class TutByApi extends DefaultApi20 { private static final String AUTHORIZE_URL = "http://profile.tut.by/auth?client_id=%s&response_type=code&redirect_uri=%s"; + private TutByApi() { + } + + private static class InstanceHolder { + private static final TutByApi INSTANCE = new TutByApi(); + } + + public static TutByApi instance() { + return InstanceHolder.INSTANCE; + } + @Override public String getAccessTokenEndpoint() { return "http://profile.tut.by/getToken"; @@ -25,13 +36,13 @@ public Verb getAccessTokenVerb() { } @Override - public String getAuthorizationUrl(OAuthConfig config) { + public String getAuthorizationUrl(final OAuthConfig config) { Preconditions.checkValidUrl(config.getCallback(), "Valid url is required for a callback. Tut.by does not support OOB"); return String.format(AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback())); } @Override - public OAuthService createService(OAuthConfig config) { + public OAuthService createService(final OAuthConfig config) { return new TutByOAuthServiceImpl(this, config); } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/TwitterApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/TwitterApi.java index e9fad1ca9..c55a55b45 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/TwitterApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/TwitterApi.java @@ -9,6 +9,17 @@ public class TwitterApi extends DefaultApi10a { private static final String REQUEST_TOKEN_RESOURCE = "api.twitter.com/oauth/request_token"; private static final String ACCESS_TOKEN_RESOURCE = "api.twitter.com/oauth/access_token"; + private TwitterApi() { + } + + private static class InstanceHolder { + private static final TwitterApi INSTANCE = new TwitterApi(); + } + + public static TwitterApi instance() { + return InstanceHolder.INSTANCE; + } + @Override public String getAccessTokenEndpoint() { return "https://" + ACCESS_TOKEN_RESOURCE; @@ -20,7 +31,7 @@ public String getRequestTokenEndpoint() { } @Override - public String getAuthorizationUrl(Token requestToken) { + public String getAuthorizationUrl(final Token requestToken) { return String.format(AUTHORIZE_URL, requestToken.getToken()); } @@ -33,8 +44,19 @@ public static class Authenticate extends TwitterApi { private static final String AUTHENTICATE_URL = "https://api.twitter.com/oauth/authenticate?oauth_token=%s"; + private Authenticate() { + } + + private static class InstanceHolder { + private static final Authenticate INSTANCE = new Authenticate(); + } + + public static Authenticate instance() { + return InstanceHolder.INSTANCE; + } + @Override - public String getAuthorizationUrl(Token requestToken) { + public String getAuthorizationUrl(final Token requestToken) { return String.format(AUTHENTICATE_URL, requestToken.getToken()); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/UbuntuOneApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/UbuntuOneApi.java index 1ae973524..e2bbbfaf3 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/UbuntuOneApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/UbuntuOneApi.java @@ -14,13 +14,24 @@ public class UbuntuOneApi extends DefaultApi10a { private static final String AUTHORIZATION_URL = "https://one.ubuntu.com/oauth/authorize/?oauth_token=%s"; + private UbuntuOneApi() { + } + + private static class InstanceHolder { + private static final UbuntuOneApi INSTANCE = new UbuntuOneApi(); + } + + public static UbuntuOneApi instance() { + return InstanceHolder.INSTANCE; + } + @Override public String getAccessTokenEndpoint() { return "https://one.ubuntu.com/oauth/access/"; } @Override - public String getAuthorizationUrl(Token requestToken) { + public String getAuthorizationUrl(final Token requestToken) { return String.format(AUTHORIZATION_URL, requestToken.getToken()); } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/ViadeoApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/ViadeoApi.java index c4d558500..3e9c07e23 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/ViadeoApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/ViadeoApi.java @@ -13,6 +13,17 @@ public class ViadeoApi extends DefaultApi20 { private static final String AUTHORIZE_URL = "https://secure.viadeo.com/oauth-provider/authorize2?client_id=%s&redirect_uri=%s&response_type=code"; private static final String SCOPED_AUTHORIZE_URL = AUTHORIZE_URL + "&scope=%s"; + private ViadeoApi() { + } + + private static class InstanceHolder { + private static final ViadeoApi INSTANCE = new ViadeoApi(); + } + + public static ViadeoApi instance() { + return InstanceHolder.INSTANCE; + } + @Override public AccessTokenExtractor getAccessTokenExtractor() { return new JsonTokenExtractor(); @@ -24,7 +35,7 @@ public String getAccessTokenEndpoint() { } @Override - public String getAuthorizationUrl(OAuthConfig config) { + public String getAuthorizationUrl(final OAuthConfig config) { Preconditions.checkValidUrl(config.getCallback(), "Must provide a valid url as callback. Viadeo does not support OOB"); // Append scope if present diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/VimeoApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/VimeoApi.java index ccc6d3239..ed753efec 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/VimeoApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/VimeoApi.java @@ -7,6 +7,17 @@ public class VimeoApi extends DefaultApi10a { private static final String AUTHORIZATION_URL = "http://vimeo.com/oauth/authorize?oauth_token=%s"; + private VimeoApi() { + } + + private static class InstanceHolder { + private static final VimeoApi INSTANCE = new VimeoApi(); + } + + public static VimeoApi instance() { + return InstanceHolder.INSTANCE; + } + @Override public String getAccessTokenEndpoint() { return "http://vimeo.com/oauth/access_token"; @@ -18,7 +29,7 @@ public String getRequestTokenEndpoint() { } @Override - public String getAuthorizationUrl(Token requestToken) { + public String getAuthorizationUrl(final Token requestToken) { return String.format(AUTHORIZATION_URL, requestToken.getToken()); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/VkontakteApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/VkontakteApi.java index 021f52fa0..862dbd6a0 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/VkontakteApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/VkontakteApi.java @@ -16,6 +16,17 @@ public class VkontakteApi extends DefaultApi20 { private static final String AUTHORIZE_URL = "https://oauth.vk.com/authorize?client_id=%s&redirect_uri=%s&response_type=code"; private static final String SCOPED_AUTHORIZE_URL = String.format("%s&scope=%%s", AUTHORIZE_URL); + private VkontakteApi() { + } + + private static class InstanceHolder { + private static final VkontakteApi INSTANCE = new VkontakteApi(); + } + + public static VkontakteApi instance() { + return InstanceHolder.INSTANCE; + } + @Override public String getAccessTokenEndpoint() { return "https://oauth.vk.com/access_token"; diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/XingApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/XingApi.java index 6621bee81..30f70b4f1 100755 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/XingApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/XingApi.java @@ -7,6 +7,17 @@ public class XingApi extends DefaultApi10a { private static final String AUTHORIZE_URL = "https://api.xing.com/v1/authorize?oauth_token=%s"; + private XingApi() { + } + + private static class InstanceHolder { + private static final XingApi INSTANCE = new XingApi(); + } + + public static XingApi instance() { + return InstanceHolder.INSTANCE; + } + @Override public String getAccessTokenEndpoint() { return "https://api.xing.com/v1/access_token"; @@ -18,7 +29,7 @@ public String getRequestTokenEndpoint() { } @Override - public String getAuthorizationUrl(Token requestToken) { + public String getAuthorizationUrl(final Token requestToken) { return String.format(AUTHORIZE_URL, requestToken.getToken()); } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/YahooApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/YahooApi.java index 5a080d915..ff79f232b 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/YahooApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/YahooApi.java @@ -7,6 +7,17 @@ public class YahooApi extends DefaultApi10a { private static final String AUTHORIZE_URL = "https://api.login.yahoo.com/oauth/v2/request_auth?oauth_token=%s"; + private YahooApi() { + } + + private static class InstanceHolder { + private static final YahooApi INSTANCE = new YahooApi(); + } + + public static YahooApi instance() { + return InstanceHolder.INSTANCE; + } + @Override public String getAccessTokenEndpoint() { return "https://api.login.yahoo.com/oauth/v2/get_token"; @@ -18,7 +29,7 @@ public String getRequestTokenEndpoint() { } @Override - public String getAuthorizationUrl(Token requestToken) { + public String getAuthorizationUrl(final Token requestToken) { return String.format(AUTHORIZE_URL, requestToken.getToken()); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/YammerApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/YammerApi.java index c31ebc1dc..0d561b1c6 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/YammerApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/YammerApi.java @@ -9,6 +9,17 @@ public class YammerApi extends DefaultApi10a { private static final String AUTHORIZATION_URL = "https://www.yammer.com/oauth/authorize?oauth_token=%s"; + private YammerApi() { + } + + private static class InstanceHolder { + private static final YammerApi INSTANCE = new YammerApi(); + } + + public static YammerApi instance() { + return InstanceHolder.INSTANCE; + } + @Override public String getRequestTokenEndpoint() { return "https://www.yammer.com/oauth/request_token"; @@ -20,7 +31,7 @@ public String getAccessTokenEndpoint() { } @Override - public String getAuthorizationUrl(Token requestToken) { + public String getAuthorizationUrl(final Token requestToken) { return String.format(AUTHORIZATION_URL, requestToken.getToken()); } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/DoktornaraboteOAuthServiceImpl.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/DoktornaraboteOAuthServiceImpl.java index 983f65feb..7808906dd 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/DoktornaraboteOAuthServiceImpl.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/DoktornaraboteOAuthServiceImpl.java @@ -8,12 +8,12 @@ public class DoktornaraboteOAuthServiceImpl extends OAuth20ServiceImpl { - public DoktornaraboteOAuthServiceImpl(DefaultApi20 api, OAuthConfig config) { + public DoktornaraboteOAuthServiceImpl(final DefaultApi20 api, final OAuthConfig config) { super(api, config); } @Override - public void signRequest(Token accessToken, AbstractRequest request) { + public void signRequest(final Token accessToken, final AbstractRequest request) { request.addHeader("Authorization", "Bearer " + accessToken.getToken()); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/GoogleOAuthServiceImpl.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/GoogleOAuthServiceImpl.java index fe8f9f241..e51322111 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/GoogleOAuthServiceImpl.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/GoogleOAuthServiceImpl.java @@ -9,16 +9,16 @@ public class GoogleOAuthServiceImpl extends OAuth20ServiceImpl { - public GoogleOAuthServiceImpl(DefaultApi20 api, OAuthConfig config) { + public GoogleOAuthServiceImpl(final DefaultApi20 api, final OAuthConfig config) { super(api, config); } @Override - protected T createAccessTokenRequest(final Verifier verifier, T request) { + protected T createAccessTokenRequest(final Verifier verifier, final T request) { super.createAccessTokenRequest(verifier, request); if (!getConfig().hasGrantType()) { request.addParameter(OAuthConstants.GRANT_TYPE, "authorization_code"); } - return (T) request; + return request; } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/HHOAuthServiceImpl.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/HHOAuthServiceImpl.java index 03b7fc457..8566216a4 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/HHOAuthServiceImpl.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/HHOAuthServiceImpl.java @@ -8,12 +8,12 @@ public class HHOAuthServiceImpl extends OAuth20ServiceImpl { - public HHOAuthServiceImpl(DefaultApi20 api, OAuthConfig config) { + public HHOAuthServiceImpl(final DefaultApi20 api, final OAuthConfig config) { super(api, config); } @Override - public void signRequest(Token accessToken, AbstractRequest request) { + public void signRequest(final Token accessToken, final AbstractRequest request) { request.addHeader("Authorization", "Bearer " + accessToken.getToken()); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthServiceImpl.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthServiceImpl.java index fceaccbc9..fba828949 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthServiceImpl.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthServiceImpl.java @@ -10,7 +10,7 @@ import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuth20ServiceImpl; -public final class ImgurOAuthServiceImpl extends OAuth20ServiceImpl { +public class ImgurOAuthServiceImpl extends OAuth20ServiceImpl { public ImgurOAuthServiceImpl(final DefaultApi20 api, final OAuthConfig config) { super(api, config); @@ -37,6 +37,6 @@ public Token getAccessToken(final Token requestToken, final Verifier verifier) { @Override public void signRequest(final Token accessToken, final AbstractRequest request) { request.addHeader("Authorization", - accessToken != null ? "Bearer " + accessToken.getToken() : "Client-ID " + getConfig().getApiKey()); + accessToken == null ? "Client-ID " + getConfig().getApiKey() : "Bearer " + accessToken.getToken()); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/LinkedIn20ServiceImpl.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/LinkedIn20ServiceImpl.java index d72495487..767f37b68 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/LinkedIn20ServiceImpl.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/LinkedIn20ServiceImpl.java @@ -15,16 +15,16 @@ public LinkedIn20ServiceImpl(final DefaultApi20 api, final OAuthConfig config) { } @Override - public void signRequest(Token accessToken, AbstractRequest request) { + public void signRequest(final Token accessToken, final AbstractRequest request) { request.addQuerystringParameter("oauth2_access_token", accessToken.getToken()); } @Override - protected T createAccessTokenRequest(final Verifier verifier, T request) { + protected T createAccessTokenRequest(final Verifier verifier, final T request) { super.createAccessTokenRequest(verifier, request); if (!getConfig().hasGrantType()) { request.addParameter(OAuthConstants.GRANT_TYPE, "authorization_code"); } - return (T) request; + return request; } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthServiceImpl.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthServiceImpl.java index 745aa6478..76f17ca2e 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthServiceImpl.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthServiceImpl.java @@ -16,7 +16,7 @@ public class MailruOAuthServiceImpl extends OAuth20ServiceImpl { - public MailruOAuthServiceImpl(DefaultApi20 api, OAuthConfig config) { + public MailruOAuthServiceImpl(final DefaultApi20 api, final OAuthConfig config) { super(api, config); } @@ -25,20 +25,20 @@ public void signRequest(final Token accessToken, final AbstractRequest request) // sig = md5(params + secret_key) request.addQuerystringParameter("session_key", accessToken.getToken()); request.addQuerystringParameter("app_id", getConfig().getApiKey()); - String completeUrl = request.getCompleteUrl(); + final String completeUrl = request.getCompleteUrl(); try { final String clientSecret = getConfig().getApiSecret(); final int queryIndex = completeUrl.indexOf('?'); if (queryIndex != -1) { - String urlPart = completeUrl.substring(queryIndex + 1); - Map map = new TreeMap<>(); - for (String param : urlPart.split("&")) { - String[] parts = param.split("="); + final String urlPart = completeUrl.substring(queryIndex + 1); + final Map map = new TreeMap<>(); + for (final String param : urlPart.split("&")) { + final String[] parts = param.split("="); map.put(parts[0], (parts.length == 1) ? "" : parts[1]); } - StringBuilder urlNew = new StringBuilder(); - for (Map.Entry entry : map.entrySet()) { + final StringBuilder urlNew = new StringBuilder(); + for (final Map.Entry entry : map.entrySet()) { urlNew.append(entry.getKey()); urlNew.append('='); urlNew.append(entry.getValue()); @@ -52,11 +52,11 @@ public void signRequest(final Token accessToken, final AbstractRequest request) } @Override - protected T createAccessTokenRequest(final Verifier verifier, T request) { + protected T createAccessTokenRequest(final Verifier verifier, final T request) { super.createAccessTokenRequest(verifier, request); if (!getConfig().hasGrantType()) { request.addParameter(OAuthConstants.GRANT_TYPE, "authorization_code"); } - return (T) request; + return request; } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/TutByOAuthServiceImpl.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/TutByOAuthServiceImpl.java index 08ebbce0e..7a643dcbc 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/TutByOAuthServiceImpl.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/TutByOAuthServiceImpl.java @@ -9,12 +9,12 @@ public class TutByOAuthServiceImpl extends OAuth20ServiceImpl { - public TutByOAuthServiceImpl(DefaultApi20 api, OAuthConfig config) { + public TutByOAuthServiceImpl(final DefaultApi20 api, final OAuthConfig config) { super(api, config); } @Override - public void signRequest(Token accessToken, AbstractRequest request) { + public void signRequest(final Token accessToken, final AbstractRequest request) { request.addQuerystringParameter(OAuthConstants.TOKEN, accessToken.getToken()); } diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AWeberExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AWeberExample.java index 4776cf3ef..b4570d64d 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AWeberExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AWeberExample.java @@ -10,7 +10,7 @@ import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuthService; -public class AWeberExample { +public abstract class AWeberExample { //To get your consumer key/secret, and view API docs, see https://labs.aweber.com/docs private static final String ACCOUNT_RESOURCE_URL = "https://api.aweber.com/1.0/accounts/"; @@ -18,21 +18,21 @@ public class AWeberExample { private static final String CONSUMER_KEY = ""; private static final String CONSUMER_SECRET = ""; - public static void main(String[] args) { - OAuthService service = new ServiceBuilder() - .provider(AWeberApi.class) + public static void main(final String... args) { + final OAuthService service = new ServiceBuilder() + .provider(AWeberApi.instance()) .apiKey(CONSUMER_KEY) .apiSecret(CONSUMER_SECRET) .build(); - Scanner in = new Scanner(System.in); + final Scanner in = new Scanner(System.in); System.out.println("=== AWeber's OAuth Workflow ==="); System.out.println(); // Obtain the Request Token System.out.println("Fetching the Request Token..."); - Token requestToken = service.getRequestToken(); + final Token requestToken = service.getRequestToken(); System.out.println("Got the Request Token!"); System.out.println(); @@ -40,21 +40,21 @@ public static void main(String[] args) { System.out.println(service.getAuthorizationUrl(requestToken)); System.out.println("And paste the verifier here"); System.out.print(">>"); - Verifier verifier = new Verifier(in.nextLine()); + final Verifier verifier = new Verifier(in.nextLine()); System.out.println(); // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - Token accessToken = service.getAccessToken(requestToken, verifier); + final Token accessToken = service.getAccessToken(requestToken, verifier); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + " )"); System.out.println(); // Now let's go and ask for a protected resource! System.out.println("Now we're going to access a protected resource..."); - OAuthRequest request = new OAuthRequest(Verb.GET, ACCOUNT_RESOURCE_URL, service); + final OAuthRequest request = new OAuthRequest(Verb.GET, ACCOUNT_RESOURCE_URL, service); service.signRequest(accessToken, request); - Response response = request.send(); + final Response response = request.send(); System.out.println("Got it! Lets see what we found..."); System.out.println(); System.out.println(response.getBody()); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiggExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiggExample.java index c095d4284..adec304a0 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiggExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiggExample.java @@ -10,51 +10,51 @@ import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuthService; -public class DiggExample { +public abstract class DiggExample { private static final String NETWORK_NAME = "Digg"; private static final String PROTECTED_RESOURCE_URL = "http://services.digg.com/2.0/comment.digg"; - public static void main(String[] args) { + public static void main(final String... args) { // Replace these with your own api key and secret - String apiKey = "myKey"; - String apiSecret = "mySecret"; - OAuthService service = new ServiceBuilder().provider(DiggApi.class).apiKey(apiKey).apiSecret(apiSecret).build(); - Scanner in = new Scanner(System.in); + final String apiKey = "myKey"; + final String apiSecret = "mySecret"; + final OAuthService service = new ServiceBuilder().provider(DiggApi.instance()).apiKey(apiKey).apiSecret(apiSecret).build(); + final Scanner in = new Scanner(System.in); System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); System.out.println(); // Obtain the Request Token System.out.println("Fetching the Request Token..."); - Token requestToken = service.getRequestToken(); + final Token requestToken = service.getRequestToken(); System.out.println("Got the Request Token!"); System.out.println(); // Obtain the Authorization URL System.out.println("Fetching the Authorization URL..."); - String authorizationUrl = service.getAuthorizationUrl(requestToken); + final String authorizationUrl = service.getAuthorizationUrl(requestToken); System.out.println("Got the Authorization URL!"); System.out.println("Now go and authorize ScribeJava here:"); System.out.println(authorizationUrl); System.out.println("And paste the authorization code here"); System.out.print(">>"); - Verifier verifier = new Verifier(in.nextLine()); + final Verifier verifier = new Verifier(in.nextLine()); System.out.println(); // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - Token accessToken = service.getAccessToken(requestToken, verifier); + final Token accessToken = service.getAccessToken(requestToken, verifier); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + " )"); System.out.println(); // Now let's go and ask for a protected resource! System.out.println("Now we're going to access a protected resource..."); - OAuthRequest request = new OAuthRequest(Verb.POST, PROTECTED_RESOURCE_URL, service); + final OAuthRequest request = new OAuthRequest(Verb.POST, PROTECTED_RESOURCE_URL, service); request.addBodyParameter("comment_id", "20100729223726:4fef610331ee46a3b5cbd740bf71313e"); service.signRequest(accessToken, request); - Response response = request.send(); + final Response response = request.send(); 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/FacebookAsyncExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncExample.java index 0c7663bbb..db14eee96 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncExample.java @@ -29,14 +29,14 @@ public static void main(final String... args) throws InterruptedException, Execu ScribeJavaConfig.setForceTypeOfHttpRequests(ForceTypeOfHttpRequest.FORCE_ASYNC_ONLY_HTTP_REQUESTS); final AsyncHttpClientConfig clientConfig = new AsyncHttpClientConfig.Builder() .setMaxConnections(5) - .setRequestTimeout(10000) + .setRequestTimeout(10_000) .setAllowPoolingConnections(false) - .setPooledConnectionIdleTimeout(1000) - .setReadTimeout(1000) + .setPooledConnectionIdleTimeout(1_000) + .setReadTimeout(1_000) .build(); final OAuthService service = new ServiceBuilderAsync() - .provider(FacebookApi.class) + .provider(FacebookApi.instance()) .apiKey(clientId) .apiSecret(clientSecret) .state(secretState) diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java index 0d87dd7a2..a09d168e7 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java @@ -23,7 +23,7 @@ public static void main(final String... args) { final String clientSecret = "your client secret"; final String secretState = "secret" + new Random().nextInt(999_999); final OAuthService service = new ServiceBuilder() - .provider(FacebookApi.class) + .provider(FacebookApi.instance()) .apiKey(clientId) .apiSecret(clientSecret) .state(secretState) diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExample.java index 39c96547e..2b4d078c3 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExample.java @@ -10,48 +10,48 @@ import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuthService; -public class FlickrExample { +public abstract class FlickrExample { private static final String PROTECTED_RESOURCE_URL = "http://api.flickr.com/services/rest/"; - public static void main(String[] args) { + public static void main(final String... args) { // Replace these with your own api key and secret - String apiKey = "your_app_id"; - String apiSecret = "your_api_secret"; - OAuthService service = new ServiceBuilder().provider(FlickrApi.class).apiKey(apiKey).apiSecret(apiSecret). + final String apiKey = "your_app_id"; + final String apiSecret = "your_api_secret"; + final OAuthService service = new ServiceBuilder().provider(FlickrApi.instance()).apiKey(apiKey).apiSecret(apiSecret). build(); - Scanner in = new Scanner(System.in); + final Scanner in = new Scanner(System.in); System.out.println("=== Flickr's OAuth Workflow ==="); System.out.println(); // Obtain the Request Token System.out.println("Fetching the Request Token..."); - Token requestToken = service.getRequestToken(); + final Token requestToken = service.getRequestToken(); System.out.println("Got the Request Token!"); System.out.println(); System.out.println("Now go and authorize ScribeJava here:"); - String authorizationUrl = service.getAuthorizationUrl(requestToken); + final String authorizationUrl = service.getAuthorizationUrl(requestToken); System.out.println(authorizationUrl + "&perms=read"); System.out.println("And paste the verifier here"); System.out.print(">>"); - Verifier verifier = new Verifier(in.nextLine()); + final Verifier verifier = new Verifier(in.nextLine()); System.out.println(); // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - Token accessToken = service.getAccessToken(requestToken, verifier); + final Token accessToken = service.getAccessToken(requestToken, verifier); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + " )"); System.out.println(); // Now let's go and ask for a protected resource! System.out.println("Now we're going to access a protected resource..."); - OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service); request.addQuerystringParameter("method", "flickr.test.login"); service.signRequest(accessToken, request); - Response response = request.send(); + final Response response = request.send(); System.out.println("Got it! Lets see what we found..."); System.out.println(); System.out.println(response.getBody()); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java index f59ccb22a..fa9174b18 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java @@ -10,49 +10,49 @@ import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuthService; -public class Foursquare2Example { +public abstract class Foursquare2Example { private static final String PROTECTED_RESOURCE_URL = "https://api.foursquare.com/v2/users/self/friends?oauth_token="; private static final Token EMPTY_TOKEN = null; - public static void main(String[] args) { + public static void main(final String... args) { // Replace these with your own api key and secret - String apiKey = "your client id"; - String apiSecret = "your client secret"; - OAuthService service = new ServiceBuilder() - .provider(Foursquare2Api.class) + final String apiKey = "your client id"; + final String apiSecret = "your client secret"; + final OAuthService service = new ServiceBuilder() + .provider(Foursquare2Api.instance()) .apiKey(apiKey) .apiSecret(apiSecret) .callback("http://localhost:9000/") .build(); - Scanner in = new Scanner(System.in); + final Scanner in = new Scanner(System.in); System.out.println("=== Foursquare2's OAuth Workflow ==="); System.out.println(); // Obtain the Authorization URL System.out.println("Fetching the Authorization URL..."); - String authorizationUrl = service.getAuthorizationUrl(EMPTY_TOKEN); + final String authorizationUrl = service.getAuthorizationUrl(EMPTY_TOKEN); 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(">>"); - Verifier verifier = new Verifier(in.nextLine()); + final Verifier verifier = new Verifier(in.nextLine()); System.out.println(); // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - Token accessToken = service.getAccessToken(EMPTY_TOKEN, verifier); + final Token accessToken = service.getAccessToken(EMPTY_TOKEN, verifier); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + " )"); System.out.println(); // Now let's go and ask for a protected resource! System.out.println("Now we're going to access a protected resource..."); - OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL + accessToken.getToken(), service); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL + accessToken.getToken(), service); service.signRequest(accessToken, request); - Response response = request.send(); + final Response response = request.send(); 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/FoursquareExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FoursquareExample.java index fa3957f2c..fd611abe0 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FoursquareExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FoursquareExample.java @@ -10,24 +10,24 @@ import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuthService; -public class FoursquareExample { +public abstract class FoursquareExample { private static final String PROTECTED_RESOURCE_URL = "http://api.foursquare.com/v1/user"; - public static void main(String[] args) { - OAuthService service = new ServiceBuilder() - .provider(FoursquareApi.class) + public static void main(final String... args) { + final OAuthService service = new ServiceBuilder() + .provider(FoursquareApi.instance()) .apiKey("your client id") .apiSecret("your client secret") .build(); - Scanner in = new Scanner(System.in); + final Scanner in = new Scanner(System.in); System.out.println("=== Foursquare's OAuth Workflow ==="); System.out.println(); // Obtain the Request Token System.out.println("Fetching the Request Token..."); - Token requestToken = service.getRequestToken(); + final Token requestToken = service.getRequestToken(); System.out.println("Got the Request Token!"); System.out.println(); @@ -35,21 +35,21 @@ public static void main(String[] args) { System.out.println(service.getAuthorizationUrl(requestToken)); System.out.println("And paste the verifier here"); System.out.print(">>"); - Verifier verifier = new Verifier(in.nextLine()); + final Verifier verifier = new Verifier(in.nextLine()); System.out.println(); // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - Token accessToken = service.getAccessToken(requestToken, verifier); + final Token accessToken = service.getAccessToken(requestToken, verifier); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + " )"); System.out.println(); // Now let's go and ask for a protected resource! System.out.println("Now we're going to access a protected resource..."); - OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service); service.signRequest(accessToken, request); - Response response = request.send(); + final Response response = request.send(); System.out.println("Got it! Lets see what we found..."); System.out.println(); System.out.println(response.getBody()); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java index 999ed897c..ae2a2d7b9 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java @@ -11,7 +11,7 @@ import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuthService; -public class FreelancerExample { +public abstract class FreelancerExample { private static final String NETWORK_NAME = "Freelancer"; private static final String AUTHORIZE_URL @@ -19,22 +19,22 @@ public class FreelancerExample { private static final String PROTECTED_RESOURCE_URL = "http://api.sandbox.freelancer.com/Job/getJobList.json"; private static final String SCOPE = "http://api.sandbox.freelancer.com"; - public static void main(String[] args) { - OAuthService service = new ServiceBuilder() - .provider(FreelancerApi.Sandbox.class) + public static void main(final String... args) { + final OAuthService service = new ServiceBuilder() + .provider(FreelancerApi.Sandbox.instance()) .signatureType(SignatureType.QueryString) .apiKey("your client id") .apiSecret("your client secret") .scope(SCOPE) .build(); - Scanner in = new Scanner(System.in); + final Scanner in = new Scanner(System.in); System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); System.out.println(); // Obtain the Request Token System.out.println("Fetching the Request Token..."); - Token requestToken = service.getRequestToken(); + final Token requestToken = service.getRequestToken(); System.out.println("Got the Request Token!"); System.out.println("(if your curious it looks like this: " + requestToken + " )"); System.out.println(); @@ -43,22 +43,22 @@ public static void main(String[] args) { System.out.println(AUTHORIZE_URL + requestToken.getToken()); System.out.println("And paste the verifier here"); System.out.print(">>"); - Verifier verifier = new Verifier(in.nextLine()); + final Verifier verifier = new Verifier(in.nextLine()); System.out.println(); // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - Token accessToken = service.getAccessToken(requestToken, verifier); + final Token accessToken = service.getAccessToken(requestToken, verifier); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + " )"); System.out.println(); // Now let's go and ask for a protected resource! System.out.println("Now we're going to access a protected resource..."); - OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service); service.signRequest(accessToken, request); request.addHeader("GData-Version", "3.0"); - Response response = request.send(); + final Response response = request.send(); 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/GitHubExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubExample.java index bcbb6b8e4..d53782e84 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubExample.java @@ -11,19 +11,19 @@ import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuthService; -public class GitHubExample { +public abstract class GitHubExample { private static final String NETWORK_NAME = "GitHub"; private static final String PROTECTED_RESOURCE_URL = "https://api.github.com/user"; private static final Token EMPTY_TOKEN = null; - public static void main(String[] args) { + public static void main(final String... args) { // Replace these with your client id and secret final String clientId = "your client id"; final String clientSecret = "your client secret"; final String secretState = "secret" + new Random().nextInt(999_999); final OAuthService service = new ServiceBuilder() - .provider(GitHubApi.class) + .provider(GitHubApi.instance()) .apiKey(clientId) .apiSecret(clientSecret) .state(secretState) diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java index 60f2a606a..50e812f9c 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java @@ -17,13 +17,13 @@ public abstract class Google20Example { private static final String PROTECTED_RESOURCE_URL = "https://www.googleapis.com/plus/v1/people/me"; private static final Token EMPTY_TOKEN = null; - public static void main(final String[] args) { + public static void main(final String... args) { // Replace these with your client id and secret final String clientId = "your client id"; final String clientSecret = "your client secret"; final String secretState = "secret" + new Random().nextInt(999_999); final OAuth20ServiceImpl service = (OAuth20ServiceImpl) new ServiceBuilder() - .provider(GoogleApi20.class) + .provider(GoogleApi20.instance()) .apiKey(clientId) .apiSecret(clientSecret) .scope("profile") // replace with desired scope diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GoogleExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GoogleExample.java index 9a3a12a2c..a84535c3c 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GoogleExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GoogleExample.java @@ -10,28 +10,28 @@ import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuthService; -public class GoogleExample { +public abstract class GoogleExample { private static final String NETWORK_NAME = "Google"; private static final String AUTHORIZE_URL = "https://www.google.com/accounts/OAuthAuthorizeToken?oauth_token="; private static final String PROTECTED_RESOURCE_URL = "https://docs.google.com/feeds/default/private/full/"; private static final String SCOPE = "https://docs.google.com/feeds/"; - public static void main(String[] args) { - OAuthService service = new ServiceBuilder() - .provider(GoogleApi.class) + public static void main(final String... args) { + final OAuthService service = new ServiceBuilder() + .provider(GoogleApi.instance()) .apiKey("anonymous") .apiSecret("anonymous") .scope(SCOPE) .build(); - Scanner in = new Scanner(System.in); + final Scanner in = new Scanner(System.in); System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); System.out.println(); // Obtain the Request Token System.out.println("Fetching the Request Token..."); - Token requestToken = service.getRequestToken(); + final Token requestToken = service.getRequestToken(); System.out.println("Got the Request Token!"); System.out.println("(if your curious it looks like this: " + requestToken + " )"); System.out.println(); @@ -40,22 +40,22 @@ public static void main(String[] args) { System.out.println(AUTHORIZE_URL + requestToken.getToken()); System.out.println("And paste the verifier here"); System.out.print(">>"); - Verifier verifier = new Verifier(in.nextLine()); + final Verifier verifier = new Verifier(in.nextLine()); System.out.println(); // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - Token accessToken = service.getAccessToken(requestToken, verifier); + final Token accessToken = service.getAccessToken(requestToken, verifier); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + " )"); System.out.println(); // Now let's go and ask for a protected resource! System.out.println("Now we're going to access a protected resource..."); - OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service); service.signRequest(accessToken, request); request.addHeader("GData-Version", "3.0"); - Response response = request.send(); + final Response response = request.send(); 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/HHExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HHExample.java index 31c3df314..9f65d1add 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HHExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HHExample.java @@ -12,23 +12,23 @@ import com.github.scribejava.apis.HHApi; -public class HHExample { +public abstract class HHExample { private static final String NETWORK_NAME = "hh.ru"; private static final String PROTECTED_RESOURCE_URL = "https://api.hh.ru/me"; private static final Token EMPTY_TOKEN = null; - public static void main(String[] args) { + public static void main(final String... args) { // Replace these with your own client id and secret final String clientId = "your client id"; final String clientSecret = "your client secret"; - OAuthService service = new ServiceBuilder() - .provider(HHApi.class) + final OAuthService service = new ServiceBuilder() + .provider(HHApi.instance()) .apiKey(clientId) .apiSecret(clientSecret) .callback("http://your.site.com/callback") .build(); - Scanner in = new Scanner(System.in); + final Scanner in = new Scanner(System.in); System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); System.out.println(); @@ -52,9 +52,9 @@ public static void main(String[] args) { System.out.println(); System.out.println("Now we're going to access a protected resource..."); - OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service); service.signRequest(accessToken, request); - Response response = request.send(); + final Response response = request.send(); 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/ImgurExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ImgurExample.java index ed1ad3156..e975847ac 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ImgurExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ImgurExample.java @@ -11,45 +11,45 @@ import java.util.Scanner; -public class ImgurExample { +public abstract class ImgurExample { private static final String NETWORK_NAME = "Imgur"; private static final String PROTECTED_RESOURCE_URL = "https://api.imgur.com/3/account/me"; - public static void main(String[] args) { + public static void main(final String... args) { // Replace these with your own api key and secret - String apiKey = "your client id"; - String apiSecret = "your client secret"; - OAuthService service = new ServiceBuilder().provider(ImgurApi.class).apiKey(apiKey) + final String apiKey = "your client id"; + final String apiSecret = "your client secret"; + final OAuthService service = new ServiceBuilder().provider(ImgurApi.instance()).apiKey(apiKey) .apiSecret(apiSecret).build(); - Scanner in = new Scanner(System.in); + 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..."); - String authorizationUrl = service.getAuthorizationUrl(Token.empty()); + final String authorizationUrl = service.getAuthorizationUrl(Token.empty()); 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(">>"); - Verifier verifier = new Verifier(in.nextLine()); + final Verifier verifier = new Verifier(in.nextLine()); System.out.println(); // Trade the Request Token and Verifier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - Token accessToken = service.getAccessToken(Token.empty(), verifier); + final Token accessToken = service.getAccessToken(Token.empty(), verifier); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + " )"); System.out.println(); // Now let's go and ask for a protected resource! System.out.println("Now we're going to access a protected resource..."); - OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service); service.signRequest(accessToken, request); - Response response = request.send(); + final Response response = request.send(); 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/Kaixin20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Kaixin20Example.java index 21daa0a3f..b2d858776 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Kaixin20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Kaixin20Example.java @@ -10,50 +10,50 @@ import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuthService; -public class Kaixin20Example { +public abstract class Kaixin20Example { private static final String NETWORK_NAME = "Kaixin"; private static final String PROTECTED_RESOURCE_URL = "https://api.kaixin001.com/users/me.json"; private static final Token EMPTY_TOKEN = null; - public static void main(String[] args) { + public static void main(final String... args) { // Replace these with your own api key and secret - String apiKey = "your api key"; - String apiSecret = "your api secret"; - OAuthService service = new ServiceBuilder() - .provider(KaixinApi20.class) + final String apiKey = "your api key"; + final String apiSecret = "your api secret"; + final OAuthService service = new ServiceBuilder() + .provider(KaixinApi20.instance()) .apiKey(apiKey) .apiSecret(apiSecret) .callback("http://your.domain.com/handle") .build(); - Scanner in = new Scanner(System.in); + 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..."); - String authorizationUrl = service.getAuthorizationUrl(EMPTY_TOKEN); + final String authorizationUrl = service.getAuthorizationUrl(EMPTY_TOKEN); 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(">>"); - Verifier verifier = new Verifier(in.nextLine()); + final Verifier verifier = new Verifier(in.nextLine()); System.out.println(); // Trade the Request Token and Verifier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - Token accessToken = service.getAccessToken(EMPTY_TOKEN, verifier); + final Token accessToken = service.getAccessToken(EMPTY_TOKEN, verifier); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + " )"); System.out.println(); // Now let's go and ask for a protected resource! System.out.println("Now we're going to access a protected resource..."); - OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service); service.signRequest(accessToken, request); - Response response = request.send(); + final Response response = request.send(); 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/LinkedIn20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedIn20Example.java index 66e1bf297..b635fc171 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 @@ -10,23 +10,23 @@ import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuth20ServiceImpl; -public class LinkedIn20Example { +public abstract class LinkedIn20Example { private static final String NETWORK_NAME = "LinkedIn"; private static final String PROTECTED_RESOURCE_URL = "https://api.linkedin.com/v1/people/~:(%s)"; private static final Token EMPTY_TOKEN = null; - public static void main(String[] args) { + public static void main(final String... args) { // Replace these with your client id and secret final String clientId = "your client id"; final String clientSecret = "your client secret"; - final OAuth20ServiceImpl service = (OAuth20ServiceImpl) new ServiceBuilder().provider(LinkedInApi20.class). + final OAuth20ServiceImpl service = (OAuth20ServiceImpl) new ServiceBuilder().provider(LinkedInApi20.instance()). apiKey(clientId).apiSecret(clientSecret) .scope("r_fullprofile,r_emailaddress,r_contactinfo") // replace with desired scope .callback("http://example.com/callback") .state("some_params") .build(); - Scanner in = new Scanner(System.in); + final Scanner in = new Scanner(System.in); System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); System.out.println(); @@ -39,12 +39,12 @@ public static void main(String[] args) { System.out.println(authorizationUrl); System.out.println("And paste the authorization code here"); System.out.print(">>"); - Verifier verifier = new Verifier(in.nextLine()); + final Verifier verifier = new Verifier(in.nextLine()); System.out.println(); // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - Token accessToken = service.getAccessToken(EMPTY_TOKEN, verifier); + final Token accessToken = service.getAccessToken(EMPTY_TOKEN, verifier); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + " )"); System.out.println(); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java index 50ee27d7b..f30ef86f5 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java @@ -10,25 +10,25 @@ import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuthService; -public class LinkedInExample { +public abstract class LinkedInExample { private static final String PROTECTED_RESOURCE_URL = "http://api.linkedin.com/v1/people/~/connections:(id,last-name)"; - public static void main(String[] args) { - OAuthService service = new ServiceBuilder() - .provider(LinkedInApi.class) + public static void main(final String... args) { + final OAuthService service = new ServiceBuilder() + .provider(LinkedInApi.instance()) .apiKey("your client id") .apiSecret("your client secret") .build(); - Scanner in = new Scanner(System.in); + final Scanner in = new Scanner(System.in); System.out.println("=== LinkedIn's OAuth Workflow ==="); System.out.println(); // Obtain the Request Token System.out.println("Fetching the Request Token..."); - Token requestToken = service.getRequestToken(); + final Token requestToken = service.getRequestToken(); System.out.println("Got the Request Token!"); System.out.println(); @@ -36,21 +36,21 @@ public static void main(String[] args) { System.out.println(service.getAuthorizationUrl(requestToken)); System.out.println("And paste the verifier here"); System.out.print(">>"); - Verifier verifier = new Verifier(in.nextLine()); + final Verifier verifier = new Verifier(in.nextLine()); System.out.println(); // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - Token accessToken = service.getAccessToken(requestToken, verifier); + final Token accessToken = service.getAccessToken(requestToken, verifier); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + " )"); System.out.println(); // Now let's go and ask for a protected resource! System.out.println("Now we're going to access a protected resource..."); - OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service); service.signRequest(accessToken, request); - Response response = request.send(); + final Response response = request.send(); System.out.println("Got it! Lets see what we found..."); System.out.println(); System.out.println(response.getBody()); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java index 14bbd655b..c60daba90 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java @@ -10,29 +10,29 @@ import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuthService; -public class LinkedInExampleWithScopes { +public abstract class LinkedInExampleWithScopes { private static final String PROTECTED_RESOURCE_URL = "http://api.linkedin.com/v1/people/~/connections:(id,last-name)"; - public static void main(String[] args) { + public static void main(final String... args) { // Replace these with your client id and secret final String clientId = "your client id"; final String clientSecret = "your client id"; - OAuthService service = new ServiceBuilder() + final OAuthService service = new ServiceBuilder() .provider(LinkedInApi.withScopes("foo", "bar", "baz")) .apiKey(clientId) .apiSecret(clientSecret) .build(); - Scanner in = new Scanner(System.in); + final Scanner in = new Scanner(System.in); System.out.println("=== LinkedIn's OAuth Workflow ==="); System.out.println(); // Obtain the Request Token System.out.println("Fetching the Request Token..."); - Token requestToken = service.getRequestToken(); + final Token requestToken = service.getRequestToken(); System.out.println("Got the Request Token!"); System.out.println(); @@ -40,21 +40,21 @@ public static void main(String[] args) { System.out.println(service.getAuthorizationUrl(requestToken)); System.out.println("And paste the verifier here"); System.out.print(">>"); - Verifier verifier = new Verifier(in.nextLine()); + final Verifier verifier = new Verifier(in.nextLine()); System.out.println(); // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - Token accessToken = service.getAccessToken(requestToken, verifier); + final Token accessToken = service.getAccessToken(requestToken, verifier); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + " )"); System.out.println(); // Now let's go and ask for a protected resource! System.out.println("Now we're going to access a protected resource..."); - OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service); service.signRequest(accessToken, request); - Response response = request.send(); + final Response response = request.send(); System.out.println("Got it! Lets see what we found..."); System.out.println(); System.out.println(response.getBody()); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java index e050b65ca..5297441ca 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java @@ -10,50 +10,50 @@ import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuthService; -public class LiveExample { +public abstract class LiveExample { private static final String PROTECTED_RESOURCE_URL = "https://api.foursquare.com/v2/users/self/friends?oauth_token="; private static final Token EMPTY_TOKEN = null; - public static void main(String[] args) { + public static void main(final String... args) { // Replace these with your own api key and secret - String apiKey = ""; - String apiSecret = ""; - OAuthService service = new ServiceBuilder() - .provider(LiveApi.class) + final String apiKey = ""; + final String apiSecret = ""; + final OAuthService service = new ServiceBuilder() + .provider(LiveApi.instance()) .apiKey(apiKey) .apiSecret(apiSecret) .scope("wl.basic") .callback("http://localhost:9000/") .build(); - Scanner in = new Scanner(System.in); + final Scanner in = new Scanner(System.in); System.out.println("=== Windows Live's OAuth Workflow ==="); System.out.println(); // Obtain the Authorization URL System.out.println("Fetching the Authorization URL..."); - String authorizationUrl = service.getAuthorizationUrl(EMPTY_TOKEN); + final String authorizationUrl = service.getAuthorizationUrl(EMPTY_TOKEN); 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(">>"); - Verifier verifier = new Verifier(in.nextLine()); + final Verifier verifier = new Verifier(in.nextLine()); System.out.println(); // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - Token accessToken = service.getAccessToken(EMPTY_TOKEN, verifier); + final Token accessToken = service.getAccessToken(EMPTY_TOKEN, verifier); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + " )"); System.out.println(); // Now let's go and ask for a protected resource! System.out.println("Now we're going to access a protected resource..."); - OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL + accessToken.getToken(), service); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL + accessToken.getToken(), service); service.signRequest(accessToken, request); - Response response = request.send(); + final Response response = request.send(); 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/LoveFilmExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LoveFilmExample.java index 44b4a6faa..3c4e152e8 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LoveFilmExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LoveFilmExample.java @@ -10,51 +10,51 @@ import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuthService; -public class LoveFilmExample { +public abstract class LoveFilmExample { private static final String NETWORK_NAME = "LoveFilm"; private static final String PROTECTED_RESOURCE_URL = "https://api.lovefilm.com/users"; - public static void main(String[] args) { + public static void main(final String... args) { // Replace these with your own api key and secret - String apiKey = "your_key"; - String apiSecret = "your_secret"; - OAuthService service = new ServiceBuilder().provider(LoveFilmApi.class).apiKey(apiKey).apiSecret(apiSecret). + final String apiKey = "your_key"; + final String apiSecret = "your_secret"; + final OAuthService service = new ServiceBuilder().provider(LoveFilmApi.instance()).apiKey(apiKey).apiSecret(apiSecret). build(); - Scanner in = new Scanner(System.in); + final Scanner in = new Scanner(System.in); System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); System.out.println(); // Grab a request token. System.out.println("Fetching request token."); - Token requestToken = service.getRequestToken(); + final Token requestToken = service.getRequestToken(); System.out.println("Got it ... "); System.out.println(requestToken.getToken()); // Obtain the Authorization URL System.out.println("Fetching the Authorization URL..."); - String authorizationUrl = service.getAuthorizationUrl(requestToken); + final String authorizationUrl = service.getAuthorizationUrl(requestToken); System.out.println("Got the Authorization URL!"); System.out.println("Now go and authorize ScribeJava here:"); System.out.println(authorizationUrl); System.out.println("And paste the authorization code here"); System.out.print(">>"); - Verifier verifier = new Verifier(in.nextLine()); + final Verifier verifier = new Verifier(in.nextLine()); System.out.println(); // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - Token accessToken = service.getAccessToken(requestToken, verifier); + final Token accessToken = service.getAccessToken(requestToken, verifier); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + " )"); System.out.println(); // Now let's go and ask for a protected resource! System.out.println("Now we're going to access a protected resource..."); - OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service); service.signRequest(accessToken, request); - Response response = request.send(); + final Response response = request.send(); 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/MailruAsyncExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java index dc32020d0..3f4c822a9 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java @@ -25,14 +25,14 @@ public static void main(final String... args) throws InterruptedException, Execu final AsyncHttpClientConfig clientConfig = new AsyncHttpClientConfig.Builder() .setMaxConnections(5) - .setRequestTimeout(10000) + .setRequestTimeout(10_000) .setAllowPoolingConnections(false) - .setPooledConnectionIdleTimeout(1000) - .setReadTimeout(1000) + .setPooledConnectionIdleTimeout(1_000) + .setReadTimeout(1_000) .build(); final OAuthService service = new ServiceBuilderAsync() - .provider(MailruApi.class) + .provider(MailruApi.instance()) .apiKey(clientId) .apiSecret(clientSecret) .callback("http://www.example.com/oauth_callback/") diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java index 4ca60b1db..e945a062f 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java @@ -10,24 +10,24 @@ import com.github.scribejava.core.oauth.OAuthService; import com.github.scribejava.apis.MailruApi; -public class MailruExample { +public abstract class MailruExample { private static final String NETWORK_NAME = "Mail.ru"; private static final String PROTECTED_RESOURCE_URL = "http://www.appsmail.ru/platform/api?method=users.getInfo&secure=1"; private static final Token EMPTY_TOKEN = null; - public static void main(String[] args) { + public static void main(final String... args) { // Replace these with your client id and secret final String clientId = "your client id"; final String clientSecret = "your client secret"; - OAuthService service = new ServiceBuilder() - .provider(MailruApi.class) + final OAuthService service = new ServiceBuilder() + .provider(MailruApi.instance()) .apiKey(clientId) .apiSecret(clientSecret) .callback("http://www.example.com/oauth_callback/") .build(); - Scanner in = new Scanner(System.in); + final Scanner in = new Scanner(System.in); System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); System.out.println(); @@ -51,9 +51,9 @@ public static void main(String[] args) { System.out.println(); System.out.println("Now we're going to access a protected resource..."); - OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service); service.signRequest(accessToken, request); - Response response = request.send(); + final Response response = request.send(); 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/MeetupExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java index 6c570d2b6..6f1efdc09 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java @@ -10,24 +10,24 @@ import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuthService; -public class MeetupExample { +public abstract class MeetupExample { private static final String PROTECTED_RESOURCE_URL = "http://api.meetup.com/2/member/self"; - public static void main(String[] args) { - OAuthService service = new ServiceBuilder() - .provider(MeetupApi.class) + public static void main(final String... args) { + final OAuthService service = new ServiceBuilder() + .provider(MeetupApi.instance()) .apiKey("your client id") .apiSecret("your client secret") .build(); - Scanner in = new Scanner(System.in); + final Scanner in = new Scanner(System.in); System.out.println("=== Meetup's OAuth Workflow ==="); System.out.println(); // Obtain the Request Token System.out.println("Fetching the Request Token..."); - Token requestToken = service.getRequestToken(); + final Token requestToken = service.getRequestToken(); System.out.println("Got the Request Token!"); System.out.println(); @@ -35,21 +35,21 @@ public static void main(String[] args) { System.out.println(service.getAuthorizationUrl(requestToken)); System.out.println("And paste the verifier here"); System.out.print(">>"); - Verifier verifier = new Verifier(in.nextLine()); + final Verifier verifier = new Verifier(in.nextLine()); System.out.println(); // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - Token accessToken = service.getAccessToken(requestToken, verifier); + final Token accessToken = service.getAccessToken(requestToken, verifier); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + " )"); System.out.println(); // Now let's go and ask for a protected resource! System.out.println("Now we're going to access a protected resource..."); - OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service); service.signRequest(accessToken, request); - Response response = request.send(); + final Response response = request.send(); System.out.println("Got it! Lets see what we found..."); System.out.println(); System.out.println(response.getBody()); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NeteaseWeiboExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NeteaseWeiboExample.java index dbb4dc0b3..7fd178cac 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NeteaseWeiboExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NeteaseWeiboExample.java @@ -10,45 +10,45 @@ import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuthService; -public class NeteaseWeiboExample { +public abstract class NeteaseWeiboExample { private static final String NETWORK_NAME = "NetEase(163.com) Weibo"; private static final String PROTECTED_RESOURCE_URL = "http://api.t.163.com/account/verify_credentials.json"; - public static void main(String[] args) { + public static void main(final String... args) { // Replace these with your own api key and secret - String apiKey = "your key"; - String apiSecret = "your secret"; - OAuthService service = new ServiceBuilder() - .provider(NeteaseWeibooApi.class) + final String apiKey = "your key"; + final String apiSecret = "your secret"; + final OAuthService service = new ServiceBuilder() + .provider(NeteaseWeibooApi.instance()) .apiKey(apiKey) .apiSecret(apiSecret) .build(); - Scanner in = new Scanner(System.in); + final Scanner in = new Scanner(System.in); System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); System.out.println(); // Grab a request token. System.out.println("Fetching request token."); - Token requestToken = service.getRequestToken(); + final Token requestToken = service.getRequestToken(); System.out.println("Got it ... "); System.out.println(requestToken.getToken()); // Obtain the Authorization URL System.out.println("Fetching the Authorization URL..."); - String authorizationUrl = service.getAuthorizationUrl(requestToken); + final String authorizationUrl = service.getAuthorizationUrl(requestToken); System.out.println("Got the Authorization URL!"); System.out.println("Now go and authorize ScribeJava here:"); System.out.println(authorizationUrl); System.out.println("And paste the authorization code here"); System.out.print(">>"); - Verifier verifier = new Verifier(in.nextLine()); + final Verifier verifier = new Verifier(in.nextLine()); System.out.println(); // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - Token accessToken = service.getAccessToken(requestToken, verifier); + final Token accessToken = service.getAccessToken(requestToken, verifier); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + " )"); @@ -56,9 +56,9 @@ public static void main(String[] args) { // Now let's go and ask for a protected resource! System.out.println("Now we're going to access a protected resource..."); - OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service); service.signRequest(accessToken, request); - Response response = request.send(); + final Response response = request.send(); 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/OdnoklassnikiExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java index dbb8bde5c..f96bab323 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java @@ -10,55 +10,55 @@ import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuthService; -public class OdnoklassnikiExample { +public abstract class OdnoklassnikiExample { private static final String NETWORK_NAME = "Odnoklassniki.ru"; private static final String PROTECTED_RESOURCE_URL = "http://api.odnoklassniki.ru/api/users/getCurrentUser?application_key=%1$s&format=JSON"; private static final Token EMPTY_TOKEN = null; - public static void main(String[] args) { + public static void main(final String... args) { // Replace these with your client id and secret final String clientId = "your client id"; final String publicKey = "your api secret"; final String clientSecret = "your client secret"; - OAuthService service = new ServiceBuilder().provider(OdnoklassnikiApi.class) + final OAuthService service = new ServiceBuilder().provider(OdnoklassnikiApi.instance()) .apiKey(clientId) .apiSecret(clientSecret) .scope("VALUABLE ACCESS") .callback("http://your.site.com/callback") .build(); - Scanner in = new Scanner(System.in); + 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..."); - String authorizationUrl = service.getAuthorizationUrl(EMPTY_TOKEN); + final String authorizationUrl = service.getAuthorizationUrl(EMPTY_TOKEN); 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(">>"); - Verifier verifier = new Verifier(in.nextLine()); + final Verifier verifier = new Verifier(in.nextLine()); System.out.println(); // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - Token accessToken = service.getAccessToken(EMPTY_TOKEN, verifier); + final Token accessToken = service.getAccessToken(EMPTY_TOKEN, verifier); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + " )"); System.out.println(); // Now let's go and ask for a protected resource! System.out.println("Now we're going to access a protected resource..."); - OAuthRequest request = new OAuthRequest(Verb.GET, String.format(PROTECTED_RESOURCE_URL, publicKey), service); + final OAuthRequest request = new OAuthRequest(Verb.GET, String.format(PROTECTED_RESOURCE_URL, publicKey), service); service.signRequest(accessToken, request); - Response response = request.send(); + final Response response = request.send(); 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/PinterestExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java index 217a25e89..799613af6 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java @@ -11,50 +11,50 @@ import java.util.Scanner; -public class PinterestExample { +public abstract class PinterestExample { private static final String PROTECTED_RESOURCE_URL = "https://api.pinterest.com/v1/me/?access_token?access_token="; private static final Token EMPTY_TOKEN = null; - public static void main(String[] args) { + public static void main(final String... args) { // Replace these with your own api key and secret - String apiKey = "your_app_id"; - String apiSecret = "your_app_secret"; - OAuthService service = new ServiceBuilder() - .provider(PinterestApi.class) + final String apiKey = "your_app_id"; + final String apiSecret = "your_app_secret"; + final OAuthService service = new ServiceBuilder() + .provider(PinterestApi.instance()) .apiKey(apiKey) .apiSecret(apiSecret) .scope("read_public,write_public,read_relationships,write_relationships") .callback("https://localhost:9000/") // Add as valid callback in developer portal .build(); - Scanner in = new Scanner(System.in); + final Scanner in = new Scanner(System.in); System.out.println("=== Pinterest's OAuth Workflow ==="); System.out.println(); // Obtain the Authorization URL System.out.println("Fetching the Authorization URL..."); - String authorizationUrl = service.getAuthorizationUrl(EMPTY_TOKEN); + final String authorizationUrl = service.getAuthorizationUrl(EMPTY_TOKEN); 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(">>"); - Verifier verifier = new Verifier(in.nextLine()); + final Verifier verifier = new Verifier(in.nextLine()); System.out.println(); // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - Token accessToken = service.getAccessToken(EMPTY_TOKEN, verifier); + final Token accessToken = service.getAccessToken(EMPTY_TOKEN, verifier); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + " )"); System.out.println(); // Now let's go and ask for a protected resource! System.out.println("Now we're going to access a protected resource..."); - OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL + accessToken.getToken(), service); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL + accessToken.getToken(), service); service.signRequest(accessToken, request); - Response response = request.send(); + final Response response = request.send(); 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/Px500Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Px500Example.java index c54c6c897..ed6d5d34a 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Px500Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Px500Example.java @@ -10,24 +10,24 @@ import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuthService; -public class Px500Example { +public abstract class Px500Example { private static final String PROTECTED_RESOURCE_URL = "https://api.500px.com/v1/"; - public static void main(String[] args) { - OAuthService service = new ServiceBuilder() - .provider(Px500Api.class) + public static void main(final String... args) { + final OAuthService service = new ServiceBuilder() + .provider(Px500Api.instance()) .apiKey("your-api-key") .apiSecret("your-api-secret") .build(); - Scanner in = new Scanner(System.in); + final Scanner in = new Scanner(System.in); System.out.println("=== 500Px's OAuth Workflow ==="); System.out.println(); // Obtain the Request Token System.out.println("Fetching the Request Token..."); - Token requestToken = service.getRequestToken(); + final Token requestToken = service.getRequestToken(); System.out.println("Got the Request Token!"); System.out.println(); @@ -35,21 +35,21 @@ public static void main(String[] args) { System.out.println(service.getAuthorizationUrl(requestToken)); System.out.println("And paste the verifier here"); System.out.print(">>"); - Verifier verifier = new Verifier(in.nextLine()); + final Verifier verifier = new Verifier(in.nextLine()); System.out.println(); // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - Token accessToken = service.getAccessToken(requestToken, verifier); + final Token accessToken = service.getAccessToken(requestToken, verifier); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + " )"); System.out.println(); // Now let's go and ask for a protected resource! System.out.println("Now we're going to access a protected resource..."); - OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service); service.signRequest(accessToken, request); - Response response = request.send(); + final Response response = request.send(); System.out.println("Got it! Lets see what we found..."); System.out.println(); System.out.println(response.getBody()); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java index 5e61715d2..d34339129 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java @@ -19,70 +19,70 @@ import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuthService; -public class RenrenExample { +public abstract class RenrenExample { private static final String NETWORK_NAME = "Renren"; private static final String PROTECTED_RESOURCE_URL = "http://api.renren.com/restserver.do"; private static final Token EMPTY_TOKEN = null; - public static void main(String[] args) { + public static void main(final String... args) { // Replace these with your own api key and secret - String apiKey = "your api key"; - String apiSecret = "your api secret"; - OAuthService service = new ServiceBuilder() - .provider(RenrenApi.class) + final String apiKey = "your api key"; + final String apiSecret = "your api secret"; + final OAuthService service = new ServiceBuilder() + .provider(RenrenApi.instance()) .apiKey(apiKey) .apiSecret(apiSecret) .scope("status_update publish_feed") .callback("http://your.doman.com/oauth/renren") .build(); - Scanner in = new Scanner(System.in); + 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..."); - String authorizationUrl = service.getAuthorizationUrl(EMPTY_TOKEN); + final String authorizationUrl = service.getAuthorizationUrl(EMPTY_TOKEN); 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(">>"); - Verifier verifier = new Verifier(in.nextLine()); + final Verifier verifier = new Verifier(in.nextLine()); System.out.println(); // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - Token accessToken = service.getAccessToken(EMPTY_TOKEN, verifier); + final Token accessToken = service.getAccessToken(EMPTY_TOKEN, verifier); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + " )"); System.out.println(); // Now let's go and ask for a protected resource! System.out.println("Now we're going to access a protected resource..."); - OAuthRequest request = new OAuthRequest(Verb.POST, PROTECTED_RESOURCE_URL, service); - Map parameters = new HashMap(); + final OAuthRequest request = new OAuthRequest(Verb.POST, PROTECTED_RESOURCE_URL, service); + final Map parameters = new HashMap<>(); parameters.put("method", "users.getInfo"); parameters.put("format", "json"); parameters.put("v", "1.0"); - List sigString = new ArrayList(parameters.size() + 1); - for (Map.Entry entry : parameters.entrySet()) { + final List sigString = new ArrayList<>(parameters.size() + 1); + for (final Map.Entry entry : parameters.entrySet()) { request.addQuerystringParameter(entry.getKey(), entry.getValue()); sigString.add(String.format("%s=%s", entry.getKey(), entry.getValue())); } sigString.add(String.format("%s=%s", OAuthConstants.ACCESS_TOKEN, accessToken.getToken())); Collections.sort(sigString); - StringBuilder b = new StringBuilder(); - for (String param : sigString) { + final StringBuilder b = new StringBuilder(); + for (final String param : sigString) { b.append(param); } b.append(apiSecret); System.out.println("Sig string: " + b.toString()); request.addQuerystringParameter("sig", md5(b.toString())); service.signRequest(accessToken, request); - Response response = request.send(); + final Response response = request.send(); System.out.println("Got it! Lets see what we found..."); System.out.println(); System.out.println(response.getCode()); @@ -93,11 +93,11 @@ public static void main(String[] args) { } - public static String md5(String orgString) { + public static String md5(final String orgString) { try { - java.security.MessageDigest md = MessageDigest.getInstance("MD5"); - byte[] array = md.digest(orgString.getBytes(Charset.forName("UTF-8"))); - StringBuffer sb = new StringBuffer(); + final MessageDigest md = MessageDigest.getInstance("MD5"); + final byte[] array = md.digest(orgString.getBytes(Charset.forName("UTF-8"))); + final StringBuffer sb = new StringBuffer(); for (int i = 0; i < array.length; ++i) { sb.append(Integer.toHexString((array[i] & 0xFF) | 0x100).substring(1, 3)); } diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeibo2Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeibo2Example.java index 3a80e70d7..68aca10f1 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeibo2Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeibo2Example.java @@ -10,50 +10,50 @@ import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuthService; -public class SinaWeibo2Example { +public abstract class SinaWeibo2Example { private static final String NETWORK_NAME = "SinaWeibo"; private static final String PROTECTED_RESOURCE_URL = "https://api.weibo.com/2/account/get_uid.json"; private static final Token EMPTY_TOKEN = null; - public static void main(String[] args) { + public static void main(final String... args) { // Replace these with your own api key and secret - String apiKey = "your_api_key"; - String apiSecret = "your_api_secret"; - OAuthService service = new ServiceBuilder() - .provider(SinaWeiboApi20.class) + final String apiKey = "your_api_key"; + final String apiSecret = "your_api_secret"; + final OAuthService service = new ServiceBuilder() + .provider(SinaWeiboApi20.instance()) .apiKey(apiKey) .apiSecret(apiSecret) .callback("http://www.dajie.com/oauth/sina") .build(); - Scanner in = new Scanner(System.in); + 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..."); - String authorizationUrl = service.getAuthorizationUrl(EMPTY_TOKEN); + final String authorizationUrl = service.getAuthorizationUrl(EMPTY_TOKEN); 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(">>"); - Verifier verifier = new Verifier(in.nextLine()); + final Verifier verifier = new Verifier(in.nextLine()); System.out.println(); // Trade the Request Token and Verifier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - Token accessToken = service.getAccessToken(EMPTY_TOKEN, verifier); + final Token accessToken = service.getAccessToken(EMPTY_TOKEN, verifier); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + " )"); System.out.println(); // Now let's go and ask for a protected resource! System.out.println("Now we're going to access a protected resource..."); - OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service); service.signRequest(accessToken, request); - Response response = request.send(); + final Response response = request.send(); 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/SinaWeiboExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeiboExample.java index 3fa625045..622231acd 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeiboExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeiboExample.java @@ -10,45 +10,45 @@ import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuthService; -public class SinaWeiboExample { +public abstract class SinaWeiboExample { private static final String NETWORK_NAME = "SinaWeibo"; private static final String PROTECTED_RESOURCE_URL = "http://api.t.sina.com.cn/account/verify_credentials.json"; - public static void main(String[] args) { + public static void main(final String... args) { // Replace these with your own api key and secret - String apiKey = "your key"; - String apiSecret = "your secret"; - OAuthService service = new ServiceBuilder() - .provider(SinaWeiboApi.class) + final String apiKey = "your key"; + final String apiSecret = "your secret"; + final OAuthService service = new ServiceBuilder() + .provider(SinaWeiboApi.instance()) .apiKey(apiKey) .apiSecret(apiSecret) .build(); - Scanner in = new Scanner(System.in); + final Scanner in = new Scanner(System.in); System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); System.out.println(); // Grab a request token. System.out.println("Fetching request token."); - Token requestToken = service.getRequestToken(); + final Token requestToken = service.getRequestToken(); System.out.println("Got it ... "); System.out.println(requestToken.getToken()); // Obtain the Authorization URL System.out.println("Fetching the Authorization URL..."); - String authorizationUrl = service.getAuthorizationUrl(requestToken); + final String authorizationUrl = service.getAuthorizationUrl(requestToken); System.out.println("Got the Authorization URL!"); System.out.println("Now go and authorize ScribeJava here:"); System.out.println(authorizationUrl); System.out.println("And paste the authorization code here"); System.out.print(">>"); - Verifier verifier = new Verifier(in.nextLine()); + final Verifier verifier = new Verifier(in.nextLine()); System.out.println(); // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - Token accessToken = service.getAccessToken(requestToken, verifier); + final Token accessToken = service.getAccessToken(requestToken, verifier); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + " )"); @@ -56,9 +56,9 @@ public static void main(String[] args) { // Now let's go and ask for a protected resource! System.out.println("Now we're going to access a protected resource..."); - OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service); service.signRequest(accessToken, request); - Response response = request.send(); + final Response response = request.send(); 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/SkyrockExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SkyrockExample.java index 35fd4379e..3b6e41e37 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SkyrockExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SkyrockExample.java @@ -10,24 +10,24 @@ import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuthService; -public class SkyrockExample { +public abstract class SkyrockExample { private static final String PROTECTED_RESOURCE_URL = "https://api.skyrock.com/v2/user/get.json"; - public static void main(String[] args) { - OAuthService service = new ServiceBuilder() - .provider(SkyrockApi.class) + public static void main(final String... args) { + final OAuthService service = new ServiceBuilder() + .provider(SkyrockApi.instance()) .apiKey("your-api-key") .apiSecret("your-api-secret") .build(); - Scanner in = new Scanner(System.in); + final Scanner in = new Scanner(System.in); System.out.println("=== Skyrock's OAuth Workflow ==="); System.out.println(); // Obtain the Request Token System.out.println("Fetching the Request Token..."); - Token requestToken = service.getRequestToken(); + final Token requestToken = service.getRequestToken(); System.out.println("Got the Request Token!"); System.out.println(); @@ -35,21 +35,21 @@ public static void main(String[] args) { System.out.println(service.getAuthorizationUrl(requestToken)); System.out.println("And paste the verifier here"); System.out.print(">>"); - Verifier verifier = new Verifier(in.nextLine()); + final Verifier verifier = new Verifier(in.nextLine()); System.out.println(); // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - Token accessToken = service.getAccessToken(requestToken, verifier); + final Token accessToken = service.getAccessToken(requestToken, verifier); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + " )"); System.out.println(); // Now let's go and ask for a protected resource! System.out.println("Now we're going to access a protected resource..."); - OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service); service.signRequest(accessToken, request); - Response response = request.send(); + final Response response = request.send(); 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/SohuWeiboExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SohuWeiboExample.java index cbb4746ca..a488dffb3 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SohuWeiboExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SohuWeiboExample.java @@ -10,45 +10,45 @@ import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuthService; -public class SohuWeiboExample { +public abstract class SohuWeiboExample { private static final String NETWORK_NAME = "SohuWeibo"; private static final String PROTECTED_RESOURCE_URL = "http://api.t.sohu.com/account/verify_credentials.json"; - public static void main(String[] args) { + public static void main(final String... args) { // Replace these with your own api key and secret - String apiKey = "your_key"; - String apiSecret = "your_secret"; - OAuthService service = new ServiceBuilder() - .provider(SohuWeiboApi.class) + final String apiKey = "your_key"; + final String apiSecret = "your_secret"; + final OAuthService service = new ServiceBuilder() + .provider(SohuWeiboApi.instance()) .apiKey(apiKey) .apiSecret(apiSecret) .build(); - Scanner in = new Scanner(System.in); + final Scanner in = new Scanner(System.in); System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); System.out.println(); // Grab a request token. System.out.println("Fetching request token."); - Token requestToken = service.getRequestToken(); + final Token requestToken = service.getRequestToken(); System.out.println("Got it ... "); System.out.println(requestToken.getToken()); // Obtain the Authorization URL System.out.println("Fetching the Authorization URL..."); - String authorizationUrl = service.getAuthorizationUrl(requestToken); + final String authorizationUrl = service.getAuthorizationUrl(requestToken); System.out.println("Got the Authorization URL!"); System.out.println("Now go and authorize ScribeJava here:"); System.out.println(authorizationUrl); System.out.println("And paste the authorization code here"); System.out.print(">>"); - Verifier verifier = new Verifier(in.nextLine()); + final Verifier verifier = new Verifier(in.nextLine()); System.out.println(); // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - Token accessToken = service.getAccessToken(requestToken, verifier); + final Token accessToken = service.getAccessToken(requestToken, verifier); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + " )"); @@ -56,9 +56,9 @@ public static void main(String[] args) { // Now let's go and ask for a protected resource! System.out.println("Now we're going to access a protected resource..."); - OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service); service.signRequest(accessToken, request); - Response response = request.send(); + final Response response = request.send(); 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/TrelloExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TrelloExample.java index 76d61d915..6bb19c5a4 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TrelloExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TrelloExample.java @@ -10,26 +10,26 @@ import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuthService; -public class TrelloExample { +public abstract class TrelloExample { private static final String API_KEY = "your_api_key"; private static final String API_SECRET = "your_api_secret"; private static final String PROTECTED_RESOURCE_URL = "https://trello.com/1/members/me"; - public static void main(String[] args) { - OAuthService service = new ServiceBuilder() - .provider(TrelloApi.class) + public static void main(final String... args) { + final OAuthService service = new ServiceBuilder() + .provider(TrelloApi.instance()) .apiKey(API_KEY) .apiSecret(API_SECRET) .build(); - Scanner in = new Scanner(System.in); + final Scanner in = new Scanner(System.in); System.out.println("=== Trello's OAuth Workflow ==="); System.out.println(); // Obtain the Request Token System.out.println("Fetching the Request Token..."); - Token requestToken = service.getRequestToken(); + final Token requestToken = service.getRequestToken(); System.out.println("Got the Request Token!"); System.out.println(); @@ -37,21 +37,21 @@ public static void main(String[] args) { System.out.println(service.getAuthorizationUrl(requestToken)); System.out.println("And paste the verifier here"); System.out.print(">>"); - Verifier verifier = new Verifier(in.nextLine()); + final Verifier verifier = new Verifier(in.nextLine()); System.out.println(); // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - Token accessToken = service.getAccessToken(requestToken, verifier); + final Token accessToken = service.getAccessToken(requestToken, verifier); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + " )"); System.out.println(); // Now let's go and ask for a protected resource! System.out.println("Now we're going to access a protected resource..."); - OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service); service.signRequest(accessToken, request); - Response response = request.send(); + final Response response = request.send(); System.out.println("Got it! Lets see what we found..."); System.out.println(); System.out.println(response.getBody()); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TumblrExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TumblrExample.java index 87c975f74..bfe160625 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TumblrExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TumblrExample.java @@ -10,25 +10,25 @@ import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuthService; -public class TumblrExample { +public abstract class TumblrExample { private static final String PROTECTED_RESOURCE_URL = "http://api.tumblr.com/v2/user/info"; - public static void main(String[] args) { - OAuthService service = new ServiceBuilder() - .provider(TumblrApi.class) + public static void main(final String... args) { + final OAuthService service = new ServiceBuilder() + .provider(TumblrApi.instance()) .apiKey("MY_CONSUMER_KEY") .apiSecret("MY_CONSUMER_SECRET") .callback("http://www.tumblr.com/connect/login_success.html") // OOB forbidden. We need an url and the better is on the tumblr website ! .build(); - Scanner in = new Scanner(System.in); + final Scanner in = new Scanner(System.in); System.out.println("=== Tumblr's OAuth Workflow ==="); System.out.println(); // Obtain the Request Token System.out.println("Fetching the Request Token..."); - Token requestToken = service.getRequestToken(); + final Token requestToken = service.getRequestToken(); System.out.println("Got the Request Token!"); System.out.println(); @@ -36,12 +36,12 @@ public static void main(String[] args) { System.out.println(service.getAuthorizationUrl(requestToken)); System.out.println("And paste the verifier here"); System.out.print(">>"); - Verifier verifier = new Verifier(in.nextLine()); + final Verifier verifier = new Verifier(in.nextLine()); System.out.println(); // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - Token accessToken = service.getAccessToken(requestToken, + final Token accessToken = service.getAccessToken(requestToken, verifier); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + " )"); @@ -49,9 +49,9 @@ public static void main(String[] args) { // Now let's go and ask for a protected resource! System.out.println("Now we're going to access a protected resource..."); - OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service); service.signRequest(accessToken, request); - Response response = request.send(); + final Response response = request.send(); System.out.println("Got it! Lets see what we found..."); System.out.println(); System.out.println(response.getBody()); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TutByExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TutByExample.java index 0ec229553..3103eff09 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TutByExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TutByExample.java @@ -13,18 +13,18 @@ import com.github.scribejava.apis.TutByApi; -public class TutByExample { +public abstract class TutByExample { private static final String NETWORK_NAME = "Tut.by"; private static final String PROTECTED_RESOURCE_URL = "http://profile.tut.by/getInfo"; private static final Token EMPTY_TOKEN = null; - public static void main(String[] args) { + public static void main(final String... args) { // Replace these with your client id and secret final String clientId = "your client id"; final String clientSecret = "your client secret"; final OAuthService service = new ServiceBuilder() - .provider(TutByApi.class) + .provider(TutByApi.instance()) .apiKey(clientId) .apiSecret(clientSecret) .grantType(OAuthConstants.AUTHORIZATION_CODE) diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TwitterExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TwitterExample.java index 98acc733e..c713bd818 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TwitterExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TwitterExample.java @@ -10,23 +10,23 @@ import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuthService; -public class TwitterExample { +public abstract class TwitterExample { private static final String PROTECTED_RESOURCE_URL = "https://api.twitter.com/1.1/account/verify_credentials.json"; - public static void main(String[] args) { - OAuthService service = new ServiceBuilder().provider(TwitterApi.class) + public static void main(final String... args) { + final OAuthService service = new ServiceBuilder().provider(TwitterApi.instance()) .apiKey("your client id") .apiSecret("your client secret") .build(); - Scanner in = new Scanner(System.in); + final Scanner in = new Scanner(System.in); System.out.println("=== Twitter's OAuth Workflow ==="); System.out.println(); // Obtain the Request Token System.out.println("Fetching the Request Token..."); - Token requestToken = service.getRequestToken(); + final Token requestToken = service.getRequestToken(); System.out.println("Got the Request Token!"); System.out.println(); @@ -34,21 +34,21 @@ public static void main(String[] args) { System.out.println(service.getAuthorizationUrl(requestToken)); System.out.println("And paste the verifier here"); System.out.print(">>"); - Verifier verifier = new Verifier(in.nextLine()); + final Verifier verifier = new Verifier(in.nextLine()); System.out.println(); // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - Token accessToken = service.getAccessToken(requestToken, verifier); + final Token accessToken = service.getAccessToken(requestToken, verifier); System.out.println("Got the Access Token!"); System.out.println("(if you're curious it looks like this: " + accessToken + " )"); System.out.println(); // Now let's go and ask for a protected resource! System.out.println("Now we're going to access a protected resource..."); - OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service); service.signRequest(accessToken, request); - Response response = request.send(); + final Response response = request.send(); System.out.println("Got it! Lets see what we found..."); System.out.println(); System.out.println(response.getBody()); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ViadeoExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ViadeoExample.java index cacfca993..8c3a7fa6b 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ViadeoExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ViadeoExample.java @@ -10,50 +10,50 @@ import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuthService; -public class ViadeoExample { +public abstract class ViadeoExample { private static final String NETWORK_NAME = "Viadeo"; private static final String PROTECTED_RESOURCE_URL = "https://api.viadeo.com/me?user_detail=full"; private static final Token EMPTY_TOKEN = null; - public static void main(String[] args) { + public static void main(final String... args) { // Replace these with your own api key and secret - String apiKey = "your_app_id"; - String apiSecret = "your_api_secret"; - OAuthService service = new ServiceBuilder() - .provider(ViadeoApi.class) + final String apiKey = "your_app_id"; + final String apiSecret = "your_api_secret"; + final OAuthService service = new ServiceBuilder() + .provider(ViadeoApi.instance()) .apiKey(apiKey) .apiSecret(apiSecret) .callback("http://www.example.com/oauth_callback/") .build(); - Scanner in = new Scanner(System.in); + 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..."); - String authorizationUrl = service.getAuthorizationUrl(EMPTY_TOKEN); + final String authorizationUrl = service.getAuthorizationUrl(EMPTY_TOKEN); 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(">>"); - Verifier verifier = new Verifier(in.nextLine()); + final Verifier verifier = new Verifier(in.nextLine()); System.out.println(); // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - Token accessToken = service.getAccessToken(EMPTY_TOKEN, verifier); + final Token accessToken = service.getAccessToken(EMPTY_TOKEN, verifier); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + " )"); System.out.println(); // Now let's go and ask for a protected resource! System.out.println("Now we're going to access a protected resource..."); - OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service); service.signRequest(accessToken, request); - Response response = request.send(); + final Response response = request.send(); 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/VkontakteExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExample.java index e608c956c..3dba020ef 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExample.java @@ -14,51 +14,51 @@ * @author Boris G. Tsirkin * @since 20.4.2011 */ -public class VkontakteExample { +public abstract class VkontakteExample { private static final String NETWORK_NAME = "Vkontakte.ru"; private static final String PROTECTED_RESOURCE_URL = "https://api.vk.com/method/friends.get"; private static final Token EMPTY_TOKEN = null; - public static void main(String[] args) { + public static void main(final String... args) { // Replace these with your client id and secret final String clientId = "your client id"; final String clientSecret = "your client secret"; - OAuthService service = new ServiceBuilder() - .provider(VkontakteApi.class) + final OAuthService service = new ServiceBuilder() + .provider(VkontakteApi.instance()) .apiKey(clientId) .apiSecret(clientSecret) .scope("friends,wall,offline") // replace with desired scope .callback("http://your.site.com/callback") .build(); - Scanner in = new Scanner(System.in); + 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..."); - String authorizationUrl = service.getAuthorizationUrl(EMPTY_TOKEN); + final String authorizationUrl = service.getAuthorizationUrl(EMPTY_TOKEN); 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(">>"); - Verifier verifier = new Verifier(in.nextLine()); + final Verifier verifier = new Verifier(in.nextLine()); System.out.println(); // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - Token accessToken = service.getAccessToken(EMPTY_TOKEN, verifier); + final Token accessToken = service.getAccessToken(EMPTY_TOKEN, verifier); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + " )"); System.out.println(); // Now let's go and ask for a protected resource! System.out.println("Now we're going to access a protected resource..."); - OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service); service.signRequest(accessToken, request); - Response response = request.send(); + final Response response = request.send(); 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/XingExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XingExample.java index ef721e1e0..ffdac1883 100755 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XingExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XingExample.java @@ -10,24 +10,24 @@ import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuthService; -public class XingExample { +public abstract class XingExample { private static final String PROTECTED_RESOURCE_URL = "https://api.xing.com/v1/users/me"; - public static void main(String[] args) { - OAuthService service = new ServiceBuilder() - .provider(XingApi.class) + public static void main(final String... args) { + final OAuthService service = new ServiceBuilder() + .provider(XingApi.instance()) .apiKey("your client id") .apiSecret("your client secret") .build(); - Scanner in = new Scanner(System.in); + final Scanner in = new Scanner(System.in); System.out.println("=== Xing's OAuth Workflow ==="); System.out.println(); // Obtain the Request Token System.out.println("Fetching the Request Token..."); - Token requestToken = service.getRequestToken(); + final Token requestToken = service.getRequestToken(); System.out.println("Got the Request Token!"); System.out.println(); @@ -35,21 +35,21 @@ public static void main(String[] args) { System.out.println(service.getAuthorizationUrl(requestToken)); System.out.println("And paste the verifier here"); System.out.print(">>"); - Verifier verifier = new Verifier(in.nextLine()); + final Verifier verifier = new Verifier(in.nextLine()); System.out.println(); // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - Token accessToken = service.getAccessToken(requestToken, verifier); + final Token accessToken = service.getAccessToken(requestToken, verifier); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + " )"); System.out.println(); // Now let's go and ask for a protected resource! System.out.println("Now we're going to access a protected resource..."); - OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service); service.signRequest(accessToken, request); - Response response = request.send(); + final Response response = request.send(); System.out.println("Got it! Lets see what we found..."); System.out.println(); System.out.println(response.getBody()); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/YahooExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/YahooExample.java index 4b5e66c17..8efbb00b5 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/YahooExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/YahooExample.java @@ -10,25 +10,25 @@ import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuthService; -public class YahooExample { +public abstract class YahooExample { private static final String PROTECTED_RESOURCE_URL = "http://social.yahooapis.com/v1/user/A6ROU63MXWDCW3Y5MGCYWVHDJI/profile/status?format=json"; - public static void main(String[] args) { - OAuthService service = new ServiceBuilder() - .provider(YahooApi.class) + public static void main(final String... args) { + final OAuthService service = new ServiceBuilder() + .provider(YahooApi.instance()) .apiKey("your client id"). apiSecret("your client secret") .build(); - Scanner in = new Scanner(System.in); + final Scanner in = new Scanner(System.in); System.out.println("=== Yahoo's OAuth Workflow ==="); System.out.println(); // Obtain the Request Token System.out.println("Fetching the Request Token..."); - Token requestToken = service.getRequestToken(); + final Token requestToken = service.getRequestToken(); System.out.println("Got the Request Token!"); System.out.println(); @@ -36,21 +36,21 @@ public static void main(String[] args) { System.out.println(service.getAuthorizationUrl(requestToken)); System.out.println("And paste the verifier here"); System.out.print(">>"); - Verifier verifier = new Verifier(in.nextLine()); + final Verifier verifier = new Verifier(in.nextLine()); System.out.println(); // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - Token accessToken = service.getAccessToken(requestToken, verifier); + final Token accessToken = service.getAccessToken(requestToken, verifier); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + " )"); System.out.println(); // Now let's go and ask for a protected resource! System.out.println("Now we're going to access a protected resource..."); - OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service); service.signRequest(accessToken, request); - Response response = request.send(); + final Response response = request.send(); System.out.println("Got it! Lets see what we found..."); System.out.println(); System.out.println(response.getCode()); diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/AbstractServiceBuilder.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/AbstractServiceBuilder.java index 481098321..3bf806c1d 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/AbstractServiceBuilder.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/AbstractServiceBuilder.java @@ -2,7 +2,6 @@ import java.io.OutputStream; import com.github.scribejava.core.builder.api.Api; -import com.github.scribejava.core.exceptions.OAuthException; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.SignatureType; import com.github.scribejava.core.utils.Preconditions; @@ -19,27 +18,11 @@ abstract class AbstractServiceBuilder { private OutputStream debugStream; private String grantType; - public AbstractServiceBuilder() { + AbstractServiceBuilder() { this.callback = OAuthConstants.OUT_OF_BAND; this.signatureType = SignatureType.Header; } - /** - * Configures the {@link Api} - * - * @param apiClass the class of one of the existent {@link Api}s on org.scribe.api package - * @return the {@link ServiceBuilder} instance for method chaining - */ - public T provider(final Class apiClass) { - Preconditions.checkNotNull(apiClass, "Api class cannot be null"); - try { - api = apiClass.newInstance(); - } catch (IllegalAccessException | InstantiationException | RuntimeException e) { - throw new OAuthException("Error while creating the Api object", e); - } - return (T) this; - } - /** * Configures the {@link Api} Overloaded version. Let's you use an instance instead of a class. * diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java index be0a328e5..e93cccbcb 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java @@ -58,7 +58,8 @@ public Verb getAccessTokenVerb() { /** * {@inheritDoc} */ - public OAuthService createService(OAuthConfig config) { + @Override + public OAuthService createService(final OAuthConfig config) { return new OAuth20ServiceImpl(this, config); } diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/builder/ServiceBuilderTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/builder/ServiceBuilderTest.java index d8e11ac88..19d94bb27 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/builder/ServiceBuilderTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/builder/ServiceBuilderTest.java @@ -12,56 +12,75 @@ public class ServiceBuilderTest { private ServiceBuilder builder; + private ApiMock api; @Before - public void setup() { + public void setUp() { builder = new ServiceBuilder(); + api = ApiMock.instance(); } @Test public void shouldReturnConfigDefaultValues() { - builder.provider(ApiMock.class).apiKey("key").apiSecret("secret").build(); - assertEquals(ApiMock.config.getApiKey(), "key"); - assertEquals(ApiMock.config.getApiSecret(), "secret"); - assertEquals(ApiMock.config.getCallback(), OAuthConstants.OUT_OF_BAND); - assertEquals(ApiMock.config.getSignatureType(), SignatureType.Header); + builder.provider(api).apiKey("key").apiSecret("secret").build(); + + final OAuthConfig config = api.getConfig(); + assertEquals(config.getApiKey(), "key"); + assertEquals(config.getApiSecret(), "secret"); + assertEquals(config.getCallback(), OAuthConstants.OUT_OF_BAND); + assertEquals(config.getSignatureType(), SignatureType.Header); } @Test public void shouldAcceptValidCallbackUrl() { - builder.provider(ApiMock.class).apiKey("key").apiSecret("secret").callback("http://example.com").build(); - assertEquals(ApiMock.config.getApiKey(), "key"); - assertEquals(ApiMock.config.getApiSecret(), "secret"); - assertEquals(ApiMock.config.getCallback(), "http://example.com"); + builder.provider(api).apiKey("key").apiSecret("secret").callback("http://example.com").build(); + + final OAuthConfig config = api.getConfig(); + assertEquals(config.getApiKey(), "key"); + assertEquals(config.getApiSecret(), "secret"); + assertEquals(config.getCallback(), "http://example.com"); } @Test public void shouldAcceptASignatureType() { - builder.provider(ApiMock.class).apiKey("key").apiSecret("secret").signatureType(SignatureType.QueryString).build(); - assertEquals(ApiMock.config.getApiKey(), "key"); - assertEquals(ApiMock.config.getApiSecret(), "secret"); - assertEquals(ApiMock.config.getSignatureType(), SignatureType.QueryString); + builder.provider(api).apiKey("key").apiSecret("secret").signatureType(SignatureType.QueryString).build(); + + final OAuthConfig config = api.getConfig(); + assertEquals(config.getApiKey(), "key"); + assertEquals(config.getApiSecret(), "secret"); + assertEquals(config.getSignatureType(), SignatureType.QueryString); } @Test(expected = IllegalArgumentException.class) public void shouldNotAcceptNullAsCallback() { - builder.provider(ApiMock.class).apiKey("key").apiSecret("secret").callback(null).build(); + builder.provider(api).apiKey("key").apiSecret("secret").callback(null).build(); } @Test public void shouldAcceptAnScope() { - builder.provider(ApiMock.class).apiKey("key").apiSecret("secret").scope("rss-api").build(); - assertEquals(ApiMock.config.getApiKey(), "key"); - assertEquals(ApiMock.config.getApiSecret(), "secret"); - assertEquals(ApiMock.config.getScope(), "rss-api"); + builder.provider(api).apiKey("key").apiSecret("secret").scope("rss-api").build(); + + final OAuthConfig config = api.getConfig(); + assertEquals(config.getApiKey(), "key"); + assertEquals(config.getApiSecret(), "secret"); + assertEquals(config.getScope(), "rss-api"); } - public static class ApiMock implements Api { + private static class ApiMock implements Api { - public static OAuthConfig config; + private OAuthConfig config; + + private static ApiMock instance() { + return new ApiMock(); + } + + private OAuthConfig getConfig() { + return config; + } - public OAuthService createService(OAuthConfig config) { - ApiMock.config = config; + @Override + public OAuthService createService(final OAuthConfig config) { + this.config = config; return null; } } From 00d7f6775bc30887893e5d97aa26bfc60005e012 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 20 Jan 2016 12:06:29 +0300 Subject: [PATCH 092/882] differentiate oauth1 vs oauth2 [i.garanina] --- .../scribejava/apis/DoktornaraboteApi.java | 4 +- .../github/scribejava/apis/GoogleApi20.java | 5 +- .../com/github/scribejava/apis/HHApi.java | 4 +- .../com/github/scribejava/apis/ImgurApi.java | 4 +- .../github/scribejava/apis/LinkedInApi.java | 40 ++++++---------- .../github/scribejava/apis/LinkedInApi20.java | 4 +- .../com/github/scribejava/apis/MailruApi.java | 4 +- .../scribejava/apis/OdnoklassnikiApi.java | 4 +- .../com/github/scribejava/apis/TutByApi.java | 4 +- .../DoktornaraboteOAuthServiceImpl.java | 4 +- .../apis/service/GoogleOAuthServiceImpl.java | 4 +- .../apis/service/HHOAuthServiceImpl.java | 4 +- .../apis/service/ImgurOAuthServiceImpl.java | 4 +- .../apis/service/LinkedIn20ServiceImpl.java | 4 +- .../apis/service/MailruOAuthServiceImpl.java | 4 +- .../service/OdnoklassnikiServiceImpl.java | 4 +- .../apis/service/TutByOAuthServiceImpl.java | 4 +- .../apis/examples/AWeberExample.java | 3 +- .../scribejava/apis/examples/DiggExample.java | 5 +- .../apis/examples/FacebookAsyncExample.java | 3 +- .../apis/examples/FacebookExample.java | 3 +- .../apis/examples/FlickrExample.java | 6 ++- .../apis/examples/Foursquare2Example.java | 3 +- .../apis/examples/FoursquareExample.java | 3 +- .../apis/examples/FreelancerExample.java | 3 +- .../apis/examples/GitHubExample.java | 3 +- .../apis/examples/Google20Example.java | 7 ++- .../apis/examples/GoogleExample.java | 3 +- .../scribejava/apis/examples/HHExample.java | 3 +- .../apis/examples/ImgurExample.java | 6 ++- .../apis/examples/Kaixin20Example.java | 3 +- .../apis/examples/LinkedIn20Example.java | 8 ++-- .../apis/examples/LinkedInExample.java | 3 +- .../examples/LinkedInExampleWithScopes.java | 3 +- .../scribejava/apis/examples/LiveExample.java | 3 +- .../apis/examples/LoveFilmExample.java | 6 ++- .../apis/examples/MailruAsyncExample.java | 3 +- .../apis/examples/MailruExample.java | 3 +- .../apis/examples/MeetupExample.java | 3 +- .../apis/examples/NeteaseWeiboExample.java | 3 +- .../apis/examples/OdnoklassnikiExample.java | 4 +- .../apis/examples/PinterestExample.java | 3 +- .../apis/examples/Px500Example.java | 3 +- .../apis/examples/RenrenExample.java | 3 +- .../apis/examples/SinaWeibo2Example.java | 3 +- .../apis/examples/SinaWeiboExample.java | 3 +- .../apis/examples/SkyrockExample.java | 3 +- .../apis/examples/SohuWeiboExample.java | 3 +- .../apis/examples/TrelloExample.java | 3 +- .../apis/examples/TumblrExample.java | 3 +- .../apis/examples/TutByExample.java | 3 +- .../apis/examples/TwitterExample.java | 4 +- .../apis/examples/ViadeoExample.java | 3 +- .../apis/examples/VkontakteExample.java | 3 +- .../scribejava/apis/examples/XingExample.java | 3 +- .../apis/examples/YahooExample.java | 7 ++- .../core/builder/AbstractServiceBuilder.java | 46 +++++++++++-------- .../core/builder/ServiceBuilder.java | 10 ++-- .../core/builder/ServiceBuilderAsync.java | 7 ++- .../core/builder/api/DefaultApi10a.java | 7 ++- .../core/builder/api/DefaultApi20.java | 8 ++-- ...aServiceImpl.java => OAuth10aService.java} | 4 +- ...20ServiceImpl.java => OAuth20Service.java} | 4 +- .../github/scribejava/core/ObjectMother.java | 16 +++---- .../core/builder/ServiceBuilderTest.java | 28 +++++++---- .../extractors/BaseStringExtractorTest.java | 6 +-- .../core/extractors/HeaderExtractorTest.java | 4 +- .../scribejava/core/model/ConnectionStub.java | 10 ++-- .../model/ForceTypeOfHttpRequestTest.java | 8 ++-- .../core/model/OAuthRequestTest.java | 6 +-- .../scribejava/core/model/RequestTest.java | 7 +-- .../scribejava/core/model/TokenTest.java | 4 +- 72 files changed, 201 insertions(+), 222 deletions(-) rename scribejava-core/src/main/java/com/github/scribejava/core/oauth/{OAuth10aServiceImpl.java => OAuth10aService.java} (98%) rename scribejava-core/src/main/java/com/github/scribejava/core/oauth/{OAuth20ServiceImpl.java => OAuth20Service.java} (96%) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/DoktornaraboteApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/DoktornaraboteApi.java index 9bad734ed..b767f6c42 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/DoktornaraboteApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/DoktornaraboteApi.java @@ -7,7 +7,7 @@ import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.Verb; -import com.github.scribejava.core.oauth.OAuthService; +import com.github.scribejava.core.oauth.OAuth20Service; import com.github.scribejava.core.utils.OAuthEncoder; import com.github.scribejava.core.utils.Preconditions; @@ -64,7 +64,7 @@ public AccessTokenExtractor getAccessTokenExtractor() { } @Override - public OAuthService createService(final OAuthConfig config) { + public OAuth20Service createService(final OAuthConfig config) { return new DoktornaraboteOAuthServiceImpl(this, config); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/GoogleApi20.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/GoogleApi20.java index af911782c..d89f32803 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/GoogleApi20.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/GoogleApi20.java @@ -7,7 +7,7 @@ import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.Verb; -import com.github.scribejava.core.oauth.OAuthService; +import com.github.scribejava.core.oauth.OAuth20Service; import com.github.scribejava.core.utils.OAuthEncoder; public class GoogleApi20 extends DefaultApi20 { @@ -54,8 +54,7 @@ public AccessTokenExtractor getAccessTokenExtractor() { } @Override - public OAuthService createService(final OAuthConfig config) { + public OAuth20Service createService(final OAuthConfig config) { return new GoogleOAuthServiceImpl(this, config); } - } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/HHApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/HHApi.java index 7c08d540c..3a13271a8 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/HHApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/HHApi.java @@ -6,9 +6,9 @@ import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.Verb; -import com.github.scribejava.core.oauth.OAuthService; import com.github.scribejava.apis.service.HHOAuthServiceImpl; +import com.github.scribejava.core.oauth.OAuth20Service; public class HHApi extends DefaultApi20 { @@ -47,7 +47,7 @@ public AccessTokenExtractor getAccessTokenExtractor() { } @Override - public OAuthService createService(final OAuthConfig config) { + public OAuth20Service createService(final OAuthConfig config) { return new HHOAuthServiceImpl(this, config); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java index a6ee56191..f6d92904b 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java @@ -6,7 +6,7 @@ import com.github.scribejava.core.extractors.JsonTokenExtractor; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.Verb; -import com.github.scribejava.core.oauth.OAuthService; +import com.github.scribejava.core.oauth.OAuth20Service; public class ImgurApi extends DefaultApi20 { @@ -45,7 +45,7 @@ public String getAuthorizationUrl(final OAuthConfig config) { } @Override - public OAuthService createService(final OAuthConfig config) { + public OAuth20Service createService(final OAuthConfig config) { return new ImgurOAuthServiceImpl(this, config); } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi.java index 8b269409d..85e2454cf 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi.java @@ -1,9 +1,5 @@ package com.github.scribejava.apis; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashSet; -import java.util.Set; import com.github.scribejava.core.builder.api.DefaultApi10a; import com.github.scribejava.core.model.Token; @@ -20,14 +16,22 @@ public static LinkedInApi instance() { return InstanceHolder.INSTANCE; } - private final Set scopes; + private final String scopesAsString; public LinkedInApi() { - scopes = Collections.emptySet(); - } - - public LinkedInApi(final Set scopes) { - this.scopes = Collections.unmodifiableSet(scopes); + scopesAsString = null; + } + + public LinkedInApi(final String... scopes) { + if (scopes == null || scopes.length == 0) { + scopesAsString = null; + } else { + final StringBuilder builder = new StringBuilder(); + for (final String scope : scopes) { + builder.append('+').append(scope); + } + scopesAsString = "?scope=" + builder.substring(1); + } } @Override @@ -37,25 +41,11 @@ public String getAccessTokenEndpoint() { @Override public String getRequestTokenEndpoint() { - return scopes.isEmpty() ? REQUEST_TOKEN_URL : REQUEST_TOKEN_URL + "?scope=" + scopesAsString(); - } - - private String scopesAsString() { - final StringBuilder builder = new StringBuilder(); - for (final String scope : scopes) { - builder.append("+" + scope); - } - return builder.substring(1); + return scopesAsString == null ? REQUEST_TOKEN_URL : REQUEST_TOKEN_URL + scopesAsString; } @Override public String getAuthorizationUrl(final Token requestToken) { return String.format(AUTHORIZE_URL, requestToken.getToken()); } - - public static LinkedInApi withScopes(final String... scopes) { - final Set scopeSet = new HashSet<>(Arrays.asList(scopes)); - return new LinkedInApi(scopeSet); - } - } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi20.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi20.java index 415641ab9..638fae80d 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi20.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi20.java @@ -7,7 +7,7 @@ import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.Verb; -import com.github.scribejava.core.oauth.OAuthService; +import com.github.scribejava.core.oauth.OAuth20Service; import com.github.scribejava.core.utils.OAuthEncoder; import com.github.scribejava.core.utils.Preconditions; @@ -58,7 +58,7 @@ public AccessTokenExtractor getAccessTokenExtractor() { } @Override - public OAuthService createService(final OAuthConfig config) { + public OAuth20Service createService(final OAuthConfig config) { return new LinkedIn20ServiceImpl(this, config); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java index d76e4fb42..1aee71983 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java @@ -5,10 +5,10 @@ import com.github.scribejava.core.extractors.JsonTokenExtractor; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.Verb; -import com.github.scribejava.core.oauth.OAuthService; import com.github.scribejava.core.utils.OAuthEncoder; import com.github.scribejava.core.utils.Preconditions; import com.github.scribejava.apis.service.MailruOAuthServiceImpl; +import com.github.scribejava.core.oauth.OAuth20Service; public class MailruApi extends DefaultApi20 { @@ -48,7 +48,7 @@ public String getAuthorizationUrl(final OAuthConfig config) { } @Override - public OAuthService createService(final OAuthConfig config) { + public OAuth20Service createService(final OAuthConfig config) { return new MailruOAuthServiceImpl(this, config); } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java index faabf0e94..b5fcbdaec 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java @@ -6,7 +6,7 @@ import com.github.scribejava.core.extractors.JsonTokenExtractor; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.Verb; -import com.github.scribejava.core.oauth.OAuthService; +import com.github.scribejava.core.oauth.OAuth20Service; import com.github.scribejava.core.utils.OAuthEncoder; import com.github.scribejava.core.utils.Preconditions; @@ -48,7 +48,7 @@ public String getAuthorizationUrl(final OAuthConfig config) { } @Override - public OAuthService createService(final OAuthConfig config) { + public OAuth20Service createService(final OAuthConfig config) { return new OdnoklassnikiServiceImpl(this, config); } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/TutByApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/TutByApi.java index 7ce50234e..b4115da30 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/TutByApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/TutByApi.java @@ -5,10 +5,10 @@ import com.github.scribejava.core.extractors.JsonTokenExtractor; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.Verb; -import com.github.scribejava.core.oauth.OAuthService; import com.github.scribejava.core.utils.OAuthEncoder; import com.github.scribejava.core.utils.Preconditions; import com.github.scribejava.apis.service.TutByOAuthServiceImpl; +import com.github.scribejava.core.oauth.OAuth20Service; public class TutByApi extends DefaultApi20 { @@ -42,7 +42,7 @@ public String getAuthorizationUrl(final OAuthConfig config) { } @Override - public OAuthService createService(final OAuthConfig config) { + public OAuth20Service createService(final OAuthConfig config) { return new TutByOAuthServiceImpl(this, config); } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/DoktornaraboteOAuthServiceImpl.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/DoktornaraboteOAuthServiceImpl.java index 7808906dd..7a7605853 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/DoktornaraboteOAuthServiceImpl.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/DoktornaraboteOAuthServiceImpl.java @@ -4,9 +4,9 @@ import com.github.scribejava.core.model.AbstractRequest; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.Token; -import com.github.scribejava.core.oauth.OAuth20ServiceImpl; +import com.github.scribejava.core.oauth.OAuth20Service; -public class DoktornaraboteOAuthServiceImpl extends OAuth20ServiceImpl { +public class DoktornaraboteOAuthServiceImpl extends OAuth20Service { public DoktornaraboteOAuthServiceImpl(final DefaultApi20 api, final OAuthConfig config) { super(api, config); diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/GoogleOAuthServiceImpl.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/GoogleOAuthServiceImpl.java index e51322111..72ea62fa2 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/GoogleOAuthServiceImpl.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/GoogleOAuthServiceImpl.java @@ -5,9 +5,9 @@ import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.Verifier; -import com.github.scribejava.core.oauth.OAuth20ServiceImpl; +import com.github.scribejava.core.oauth.OAuth20Service; -public class GoogleOAuthServiceImpl extends OAuth20ServiceImpl { +public class GoogleOAuthServiceImpl extends OAuth20Service { public GoogleOAuthServiceImpl(final DefaultApi20 api, final OAuthConfig config) { super(api, config); diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/HHOAuthServiceImpl.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/HHOAuthServiceImpl.java index 8566216a4..5ca5349b9 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/HHOAuthServiceImpl.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/HHOAuthServiceImpl.java @@ -4,9 +4,9 @@ import com.github.scribejava.core.model.AbstractRequest; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.Token; -import com.github.scribejava.core.oauth.OAuth20ServiceImpl; +import com.github.scribejava.core.oauth.OAuth20Service; -public class HHOAuthServiceImpl extends OAuth20ServiceImpl { +public class HHOAuthServiceImpl extends OAuth20Service { public HHOAuthServiceImpl(final DefaultApi20 api, final OAuthConfig config) { super(api, config); diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthServiceImpl.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthServiceImpl.java index fba828949..16f535fb9 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthServiceImpl.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthServiceImpl.java @@ -8,9 +8,9 @@ import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Token; import com.github.scribejava.core.model.Verifier; -import com.github.scribejava.core.oauth.OAuth20ServiceImpl; +import com.github.scribejava.core.oauth.OAuth20Service; -public class ImgurOAuthServiceImpl extends OAuth20ServiceImpl { +public class ImgurOAuthServiceImpl extends OAuth20Service { public ImgurOAuthServiceImpl(final DefaultApi20 api, final OAuthConfig config) { super(api, config); diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/LinkedIn20ServiceImpl.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/LinkedIn20ServiceImpl.java index 767f37b68..9d1514dc2 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/LinkedIn20ServiceImpl.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/LinkedIn20ServiceImpl.java @@ -6,9 +6,9 @@ import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.Token; import com.github.scribejava.core.model.Verifier; -import com.github.scribejava.core.oauth.OAuth20ServiceImpl; +import com.github.scribejava.core.oauth.OAuth20Service; -public class LinkedIn20ServiceImpl extends OAuth20ServiceImpl { +public class LinkedIn20ServiceImpl extends OAuth20Service { public LinkedIn20ServiceImpl(final DefaultApi20 api, final OAuthConfig config) { super(api, config); diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthServiceImpl.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthServiceImpl.java index 76f17ca2e..cb9af537f 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthServiceImpl.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthServiceImpl.java @@ -12,9 +12,9 @@ import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.Token; import com.github.scribejava.core.model.Verifier; -import com.github.scribejava.core.oauth.OAuth20ServiceImpl; +import com.github.scribejava.core.oauth.OAuth20Service; -public class MailruOAuthServiceImpl extends OAuth20ServiceImpl { +public class MailruOAuthServiceImpl extends OAuth20Service { public MailruOAuthServiceImpl(final DefaultApi20 api, final OAuthConfig config) { super(api, config); diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiServiceImpl.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiServiceImpl.java index 357d03dce..e247252bd 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiServiceImpl.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiServiceImpl.java @@ -8,9 +8,9 @@ import com.github.scribejava.core.model.AbstractRequest; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.Token; -import com.github.scribejava.core.oauth.OAuth20ServiceImpl; +import com.github.scribejava.core.oauth.OAuth20Service; -public class OdnoklassnikiServiceImpl extends OAuth20ServiceImpl { +public class OdnoklassnikiServiceImpl extends OAuth20Service { public OdnoklassnikiServiceImpl(final DefaultApi20 api, final OAuthConfig config) { super(api, config); diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/TutByOAuthServiceImpl.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/TutByOAuthServiceImpl.java index 7a643dcbc..bb9f367c5 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/TutByOAuthServiceImpl.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/TutByOAuthServiceImpl.java @@ -5,9 +5,9 @@ import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.Token; -import com.github.scribejava.core.oauth.OAuth20ServiceImpl; +import com.github.scribejava.core.oauth.OAuth20Service; -public class TutByOAuthServiceImpl extends OAuth20ServiceImpl { +public class TutByOAuthServiceImpl extends OAuth20Service { public TutByOAuthServiceImpl(final DefaultApi20 api, final OAuthConfig config) { super(api, config); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AWeberExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AWeberExample.java index b4570d64d..2e0583a52 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AWeberExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AWeberExample.java @@ -20,10 +20,9 @@ public abstract class AWeberExample { public static void main(final String... args) { final OAuthService service = new ServiceBuilder() - .provider(AWeberApi.instance()) .apiKey(CONSUMER_KEY) .apiSecret(CONSUMER_SECRET) - .build(); + .build(AWeberApi.instance()); final Scanner in = new Scanner(System.in); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiggExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiggExample.java index adec304a0..b068c1844 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiggExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiggExample.java @@ -19,7 +19,10 @@ public static void main(final String... args) { // Replace these with your own api key and secret final String apiKey = "myKey"; final String apiSecret = "mySecret"; - final OAuthService service = new ServiceBuilder().provider(DiggApi.instance()).apiKey(apiKey).apiSecret(apiSecret).build(); + final OAuthService service = new ServiceBuilder() + .apiKey(apiKey) + .apiSecret(apiSecret) + .build(DiggApi.instance()); final Scanner in = new Scanner(System.in); System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncExample.java index db14eee96..5f08559be 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncExample.java @@ -36,13 +36,12 @@ public static void main(final String... args) throws InterruptedException, Execu .build(); final OAuthService service = new ServiceBuilderAsync() - .provider(FacebookApi.instance()) .apiKey(clientId) .apiSecret(clientSecret) .state(secretState) .callback("http://www.example.com/oauth_callback/") .asyncHttpClientConfig(clientConfig) - .build(); + .build(FacebookApi.instance()); final Scanner in = new Scanner(System.in, "UTF-8"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java index a09d168e7..f0616e43c 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java @@ -23,12 +23,11 @@ public static void main(final String... args) { final String clientSecret = "your client secret"; final String secretState = "secret" + new Random().nextInt(999_999); final OAuthService service = new ServiceBuilder() - .provider(FacebookApi.instance()) .apiKey(clientId) .apiSecret(clientSecret) .state(secretState) .callback("http://www.example.com/oauth_callback/") - .build(); + .build(FacebookApi.instance()); final Scanner in = new Scanner(System.in, "UTF-8"); System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExample.java index 2b4d078c3..26314e442 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExample.java @@ -18,8 +18,10 @@ public static void main(final String... args) { // Replace these with your own api key and secret final String apiKey = "your_app_id"; final String apiSecret = "your_api_secret"; - final OAuthService service = new ServiceBuilder().provider(FlickrApi.instance()).apiKey(apiKey).apiSecret(apiSecret). - build(); + final OAuthService service = new ServiceBuilder() + .apiKey(apiKey) + .apiSecret(apiSecret) + .build(FlickrApi.instance()); final Scanner in = new Scanner(System.in); System.out.println("=== Flickr's OAuth Workflow ==="); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java index fa9174b18..9b7579ee1 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java @@ -20,11 +20,10 @@ public static void main(final String... args) { final String apiKey = "your client id"; final String apiSecret = "your client secret"; final OAuthService service = new ServiceBuilder() - .provider(Foursquare2Api.instance()) .apiKey(apiKey) .apiSecret(apiSecret) .callback("http://localhost:9000/") - .build(); + .build(Foursquare2Api.instance()); final Scanner in = new Scanner(System.in); System.out.println("=== Foursquare2's OAuth Workflow ==="); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FoursquareExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FoursquareExample.java index fd611abe0..8b0001146 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FoursquareExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FoursquareExample.java @@ -16,10 +16,9 @@ public abstract class FoursquareExample { public static void main(final String... args) { final OAuthService service = new ServiceBuilder() - .provider(FoursquareApi.instance()) .apiKey("your client id") .apiSecret("your client secret") - .build(); + .build(FoursquareApi.instance()); final Scanner in = new Scanner(System.in); System.out.println("=== Foursquare's OAuth Workflow ==="); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java index ae2a2d7b9..c7255b7cd 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java @@ -21,12 +21,11 @@ public abstract class FreelancerExample { public static void main(final String... args) { final OAuthService service = new ServiceBuilder() - .provider(FreelancerApi.Sandbox.instance()) .signatureType(SignatureType.QueryString) .apiKey("your client id") .apiSecret("your client secret") .scope(SCOPE) - .build(); + .build(FreelancerApi.Sandbox.instance()); final Scanner in = new Scanner(System.in); System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubExample.java index d53782e84..49419e7ec 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubExample.java @@ -23,12 +23,11 @@ public static void main(final String... args) { final String clientSecret = "your client secret"; final String secretState = "secret" + new Random().nextInt(999_999); final OAuthService service = new ServiceBuilder() - .provider(GitHubApi.instance()) .apiKey(clientId) .apiSecret(clientSecret) .state(secretState) .callback("http://www.example.com/oauth_callback/") - .build(); + .build(GitHubApi.instance()); final Scanner in = new Scanner(System.in, "UTF-8"); System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java index 50e812f9c..585f8ff47 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java @@ -9,7 +9,7 @@ import com.github.scribejava.core.model.Token; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.model.Verifier; -import com.github.scribejava.core.oauth.OAuth20ServiceImpl; +import com.github.scribejava.core.oauth.OAuth20Service; public abstract class Google20Example { @@ -22,14 +22,13 @@ public static void main(final String... args) { final String clientId = "your client id"; final String clientSecret = "your client secret"; final String secretState = "secret" + new Random().nextInt(999_999); - final OAuth20ServiceImpl service = (OAuth20ServiceImpl) new ServiceBuilder() - .provider(GoogleApi20.instance()) + final OAuth20Service service = new ServiceBuilder() .apiKey(clientId) .apiSecret(clientSecret) .scope("profile") // replace with desired scope .state(secretState) .callback("http://example.com/callback") - .build(); + .build(GoogleApi20.instance()); final Scanner in = new Scanner(System.in, "UTF-8"); System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GoogleExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GoogleExample.java index a84535c3c..2aa94a885 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GoogleExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GoogleExample.java @@ -19,11 +19,10 @@ public abstract class GoogleExample { public static void main(final String... args) { final OAuthService service = new ServiceBuilder() - .provider(GoogleApi.instance()) .apiKey("anonymous") .apiSecret("anonymous") .scope(SCOPE) - .build(); + .build(GoogleApi.instance()); final Scanner in = new Scanner(System.in); System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HHExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HHExample.java index 9f65d1add..01db186fc 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HHExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HHExample.java @@ -23,11 +23,10 @@ public static void main(final String... args) { final String clientId = "your client id"; final String clientSecret = "your client secret"; final OAuthService service = new ServiceBuilder() - .provider(HHApi.instance()) .apiKey(clientId) .apiSecret(clientSecret) .callback("http://your.site.com/callback") - .build(); + .build(HHApi.instance()); final Scanner in = new Scanner(System.in); System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ImgurExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ImgurExample.java index e975847ac..ab61cad44 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ImgurExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ImgurExample.java @@ -20,8 +20,10 @@ public static void main(final String... args) { // Replace these with your own api key and secret final String apiKey = "your client id"; final String apiSecret = "your client secret"; - final OAuthService service = new ServiceBuilder().provider(ImgurApi.instance()).apiKey(apiKey) - .apiSecret(apiSecret).build(); + final OAuthService service = new ServiceBuilder() + .apiKey(apiKey) + .apiSecret(apiSecret) + .build(ImgurApi.instance()); final Scanner in = new Scanner(System.in); System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Kaixin20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Kaixin20Example.java index b2d858776..f1cb925a6 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Kaixin20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Kaixin20Example.java @@ -21,11 +21,10 @@ public static void main(final String... args) { final String apiKey = "your api key"; final String apiSecret = "your api secret"; final OAuthService service = new ServiceBuilder() - .provider(KaixinApi20.instance()) .apiKey(apiKey) .apiSecret(apiSecret) .callback("http://your.domain.com/handle") - .build(); + .build(KaixinApi20.instance()); final Scanner in = new Scanner(System.in); System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); 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 b635fc171..cbb645183 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 @@ -8,7 +8,7 @@ import com.github.scribejava.core.model.Token; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.model.Verifier; -import com.github.scribejava.core.oauth.OAuth20ServiceImpl; +import com.github.scribejava.core.oauth.OAuth20Service; public abstract class LinkedIn20Example { @@ -20,12 +20,12 @@ public static void main(final String... args) { // Replace these with your client id and secret final String clientId = "your client id"; final String clientSecret = "your client secret"; - final OAuth20ServiceImpl service = (OAuth20ServiceImpl) new ServiceBuilder().provider(LinkedInApi20.instance()). - apiKey(clientId).apiSecret(clientSecret) + final OAuth20Service service = new ServiceBuilder() + .apiKey(clientId).apiSecret(clientSecret) .scope("r_fullprofile,r_emailaddress,r_contactinfo") // replace with desired scope .callback("http://example.com/callback") .state("some_params") - .build(); + .build(LinkedInApi20.instance()); final Scanner in = new Scanner(System.in); System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java index f30ef86f5..d50144c5a 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java @@ -17,10 +17,9 @@ public abstract class LinkedInExample { public static void main(final String... args) { final OAuthService service = new ServiceBuilder() - .provider(LinkedInApi.instance()) .apiKey("your client id") .apiSecret("your client secret") - .build(); + .build(LinkedInApi.instance()); final Scanner in = new Scanner(System.in); System.out.println("=== LinkedIn's OAuth Workflow ==="); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java index c60daba90..3d2f4d7fb 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java @@ -21,10 +21,9 @@ public static void main(final String... args) { final String clientSecret = "your client id"; final OAuthService service = new ServiceBuilder() - .provider(LinkedInApi.withScopes("foo", "bar", "baz")) .apiKey(clientId) .apiSecret(clientSecret) - .build(); + .build(new LinkedInApi("foo", "bar", "baz")); final Scanner in = new Scanner(System.in); System.out.println("=== LinkedIn's OAuth Workflow ==="); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java index 5297441ca..573ca8cc7 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java @@ -20,12 +20,11 @@ public static void main(final String... args) { final String apiKey = ""; final String apiSecret = ""; final OAuthService service = new ServiceBuilder() - .provider(LiveApi.instance()) .apiKey(apiKey) .apiSecret(apiSecret) .scope("wl.basic") .callback("http://localhost:9000/") - .build(); + .build(LiveApi.instance()); final Scanner in = new Scanner(System.in); System.out.println("=== Windows Live's OAuth Workflow ==="); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LoveFilmExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LoveFilmExample.java index 3c4e152e8..5416d0e54 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LoveFilmExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LoveFilmExample.java @@ -19,8 +19,10 @@ public static void main(final String... args) { // Replace these with your own api key and secret final String apiKey = "your_key"; final String apiSecret = "your_secret"; - final OAuthService service = new ServiceBuilder().provider(LoveFilmApi.instance()).apiKey(apiKey).apiSecret(apiSecret). - build(); + final OAuthService service = new ServiceBuilder() + .apiKey(apiKey) + .apiSecret(apiSecret) + .build(LoveFilmApi.instance()); final Scanner in = new Scanner(System.in); System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java index 3f4c822a9..ceaa99894 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java @@ -32,12 +32,11 @@ public static void main(final String... args) throws InterruptedException, Execu .build(); final OAuthService service = new ServiceBuilderAsync() - .provider(MailruApi.instance()) .apiKey(clientId) .apiSecret(clientSecret) .callback("http://www.example.com/oauth_callback/") .asyncHttpClientConfig(clientConfig) - .build(); + .build(MailruApi.instance()); final Scanner in = new Scanner(System.in, "UTF-8"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java index e945a062f..fe1409145 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java @@ -21,11 +21,10 @@ public static void main(final String... args) { final String clientId = "your client id"; final String clientSecret = "your client secret"; final OAuthService service = new ServiceBuilder() - .provider(MailruApi.instance()) .apiKey(clientId) .apiSecret(clientSecret) .callback("http://www.example.com/oauth_callback/") - .build(); + .build(MailruApi.instance()); final Scanner in = new Scanner(System.in); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java index 6f1efdc09..be096c1c9 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java @@ -16,10 +16,9 @@ public abstract class MeetupExample { public static void main(final String... args) { final OAuthService service = new ServiceBuilder() - .provider(MeetupApi.instance()) .apiKey("your client id") .apiSecret("your client secret") - .build(); + .build(MeetupApi.instance()); final Scanner in = new Scanner(System.in); System.out.println("=== Meetup's OAuth Workflow ==="); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NeteaseWeiboExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NeteaseWeiboExample.java index 7fd178cac..aa6621444 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NeteaseWeiboExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NeteaseWeiboExample.java @@ -20,10 +20,9 @@ public static void main(final String... args) { final String apiKey = "your key"; final String apiSecret = "your secret"; final OAuthService service = new ServiceBuilder() - .provider(NeteaseWeibooApi.instance()) .apiKey(apiKey) .apiSecret(apiSecret) - .build(); + .build(NeteaseWeibooApi.instance()); final Scanner in = new Scanner(System.in); System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java index f96bab323..05bc0808a 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java @@ -23,12 +23,12 @@ public static void main(final String... args) { final String publicKey = "your api secret"; final String clientSecret = "your client secret"; - final OAuthService service = new ServiceBuilder().provider(OdnoklassnikiApi.instance()) + final OAuthService service = new ServiceBuilder() .apiKey(clientId) .apiSecret(clientSecret) .scope("VALUABLE ACCESS") .callback("http://your.site.com/callback") - .build(); + .build(OdnoklassnikiApi.instance()); final Scanner in = new Scanner(System.in); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java index 799613af6..e3b19eba0 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java @@ -21,12 +21,11 @@ public static void main(final String... args) { final String apiKey = "your_app_id"; final String apiSecret = "your_app_secret"; final OAuthService service = new ServiceBuilder() - .provider(PinterestApi.instance()) .apiKey(apiKey) .apiSecret(apiSecret) .scope("read_public,write_public,read_relationships,write_relationships") .callback("https://localhost:9000/") // Add as valid callback in developer portal - .build(); + .build(PinterestApi.instance()); final Scanner in = new Scanner(System.in); System.out.println("=== Pinterest's OAuth Workflow ==="); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Px500Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Px500Example.java index ed6d5d34a..c6cff4603 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Px500Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Px500Example.java @@ -16,10 +16,9 @@ public abstract class Px500Example { public static void main(final String... args) { final OAuthService service = new ServiceBuilder() - .provider(Px500Api.instance()) .apiKey("your-api-key") .apiSecret("your-api-secret") - .build(); + .build(Px500Api.instance()); final Scanner in = new Scanner(System.in); System.out.println("=== 500Px's OAuth Workflow ==="); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java index d34339129..a29e745b4 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java @@ -30,12 +30,11 @@ public static void main(final String... args) { final String apiKey = "your api key"; final String apiSecret = "your api secret"; final OAuthService service = new ServiceBuilder() - .provider(RenrenApi.instance()) .apiKey(apiKey) .apiSecret(apiSecret) .scope("status_update publish_feed") .callback("http://your.doman.com/oauth/renren") - .build(); + .build(RenrenApi.instance()); final Scanner in = new Scanner(System.in); System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeibo2Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeibo2Example.java index 68aca10f1..f9c0ba086 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeibo2Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeibo2Example.java @@ -21,11 +21,10 @@ public static void main(final String... args) { final String apiKey = "your_api_key"; final String apiSecret = "your_api_secret"; final OAuthService service = new ServiceBuilder() - .provider(SinaWeiboApi20.instance()) .apiKey(apiKey) .apiSecret(apiSecret) .callback("http://www.dajie.com/oauth/sina") - .build(); + .build(SinaWeiboApi20.instance()); final Scanner in = new Scanner(System.in); System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeiboExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeiboExample.java index 622231acd..1810a7d10 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeiboExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeiboExample.java @@ -20,10 +20,9 @@ public static void main(final String... args) { final String apiKey = "your key"; final String apiSecret = "your secret"; final OAuthService service = new ServiceBuilder() - .provider(SinaWeiboApi.instance()) .apiKey(apiKey) .apiSecret(apiSecret) - .build(); + .build(SinaWeiboApi.instance()); final Scanner in = new Scanner(System.in); System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SkyrockExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SkyrockExample.java index 3b6e41e37..162d0acc9 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SkyrockExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SkyrockExample.java @@ -16,10 +16,9 @@ public abstract class SkyrockExample { public static void main(final String... args) { final OAuthService service = new ServiceBuilder() - .provider(SkyrockApi.instance()) .apiKey("your-api-key") .apiSecret("your-api-secret") - .build(); + .build(SkyrockApi.instance()); final Scanner in = new Scanner(System.in); System.out.println("=== Skyrock's OAuth Workflow ==="); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SohuWeiboExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SohuWeiboExample.java index a488dffb3..6b437fc7c 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SohuWeiboExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SohuWeiboExample.java @@ -20,10 +20,9 @@ public static void main(final String... args) { final String apiKey = "your_key"; final String apiSecret = "your_secret"; final OAuthService service = new ServiceBuilder() - .provider(SohuWeiboApi.instance()) .apiKey(apiKey) .apiSecret(apiSecret) - .build(); + .build(SohuWeiboApi.instance()); final Scanner in = new Scanner(System.in); System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TrelloExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TrelloExample.java index 6bb19c5a4..902ad4329 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TrelloExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TrelloExample.java @@ -18,10 +18,9 @@ public abstract class TrelloExample { public static void main(final String... args) { final OAuthService service = new ServiceBuilder() - .provider(TrelloApi.instance()) .apiKey(API_KEY) .apiSecret(API_SECRET) - .build(); + .build(TrelloApi.instance()); final Scanner in = new Scanner(System.in); System.out.println("=== Trello's OAuth Workflow ==="); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TumblrExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TumblrExample.java index bfe160625..4e4584301 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TumblrExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TumblrExample.java @@ -16,11 +16,10 @@ public abstract class TumblrExample { public static void main(final String... args) { final OAuthService service = new ServiceBuilder() - .provider(TumblrApi.instance()) .apiKey("MY_CONSUMER_KEY") .apiSecret("MY_CONSUMER_SECRET") .callback("http://www.tumblr.com/connect/login_success.html") // OOB forbidden. We need an url and the better is on the tumblr website ! - .build(); + .build(TumblrApi.instance()); final Scanner in = new Scanner(System.in); System.out.println("=== Tumblr's OAuth Workflow ==="); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TutByExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TutByExample.java index 3103eff09..6a6e96cc0 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TutByExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TutByExample.java @@ -24,12 +24,11 @@ public static void main(final String... args) { final String clientId = "your client id"; final String clientSecret = "your client secret"; final OAuthService service = new ServiceBuilder() - .provider(TutByApi.instance()) .apiKey(clientId) .apiSecret(clientSecret) .grantType(OAuthConstants.AUTHORIZATION_CODE) .callback("http://www.example.com/oauth_callback/") - .build(); + .build(TutByApi.instance()); final Scanner in = new Scanner(System.in, "UTF-8"); System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TwitterExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TwitterExample.java index c713bd818..67a862ae0 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TwitterExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TwitterExample.java @@ -15,10 +15,10 @@ public abstract class TwitterExample { private static final String PROTECTED_RESOURCE_URL = "https://api.twitter.com/1.1/account/verify_credentials.json"; public static void main(final String... args) { - final OAuthService service = new ServiceBuilder().provider(TwitterApi.instance()) + final OAuthService service = new ServiceBuilder() .apiKey("your client id") .apiSecret("your client secret") - .build(); + .build(TwitterApi.instance()); final Scanner in = new Scanner(System.in); System.out.println("=== Twitter's OAuth Workflow ==="); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ViadeoExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ViadeoExample.java index 8c3a7fa6b..f6362db46 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ViadeoExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ViadeoExample.java @@ -21,11 +21,10 @@ public static void main(final String... args) { final String apiKey = "your_app_id"; final String apiSecret = "your_api_secret"; final OAuthService service = new ServiceBuilder() - .provider(ViadeoApi.instance()) .apiKey(apiKey) .apiSecret(apiSecret) .callback("http://www.example.com/oauth_callback/") - .build(); + .build(ViadeoApi.instance()); final Scanner in = new Scanner(System.in); System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); 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 3dba020ef..4e0fe25b8 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 @@ -25,12 +25,11 @@ public static void main(final String... args) { final String clientId = "your client id"; final String clientSecret = "your client secret"; final OAuthService service = new ServiceBuilder() - .provider(VkontakteApi.instance()) .apiKey(clientId) .apiSecret(clientSecret) .scope("friends,wall,offline") // replace with desired scope .callback("http://your.site.com/callback") - .build(); + .build(VkontakteApi.instance()); final Scanner in = new Scanner(System.in); System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XingExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XingExample.java index ffdac1883..9dda20499 100755 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XingExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XingExample.java @@ -16,10 +16,9 @@ public abstract class XingExample { public static void main(final String... args) { final OAuthService service = new ServiceBuilder() - .provider(XingApi.instance()) .apiKey("your client id") .apiSecret("your client secret") - .build(); + .build(XingApi.instance()); final Scanner in = new Scanner(System.in); System.out.println("=== Xing's OAuth Workflow ==="); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/YahooExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/YahooExample.java index 8efbb00b5..653b24a7d 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/YahooExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/YahooExample.java @@ -17,10 +17,9 @@ public abstract class YahooExample { public static void main(final String... args) { final OAuthService service = new ServiceBuilder() - .provider(YahooApi.instance()) - .apiKey("your client id"). - apiSecret("your client secret") - .build(); + .apiKey("your client id") + .apiSecret("your client secret") + .build(YahooApi.instance()); final Scanner in = new Scanner(System.in); System.out.println("=== Yahoo's OAuth Workflow ==="); diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/AbstractServiceBuilder.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/AbstractServiceBuilder.java index 3bf806c1d..740a053ad 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/AbstractServiceBuilder.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/AbstractServiceBuilder.java @@ -1,14 +1,17 @@ package com.github.scribejava.core.builder; +import com.github.scribejava.core.builder.api.DefaultApi10a; +import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.model.OAuthConfig; import java.io.OutputStream; -import com.github.scribejava.core.builder.api.Api; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.SignatureType; +import com.github.scribejava.core.oauth.OAuth10aService; +import com.github.scribejava.core.oauth.OAuth20Service; import com.github.scribejava.core.utils.Preconditions; abstract class AbstractServiceBuilder { - private Api api; private String callback; private String apiKey; private String apiSecret; @@ -23,18 +26,6 @@ abstract class AbstractServiceBuilder { this.signatureType = SignatureType.Header; } - /** - * Configures the {@link Api} Overloaded version. Let's you use an instance instead of a class. - * - * @param api instance of {@link Api}s - * @return the {@link ServiceBuilder} instance for method chaining - */ - public T provider(final Api api) { - Preconditions.checkNotNull(api, "Api cannot be null"); - this.api = api; - return (T) this; - } - /** * Adds an OAuth callback url * @@ -125,15 +116,10 @@ public T debug() { } public void checkPreconditions() { - Preconditions.checkNotNull(api, "You must specify a valid api through the provider() method"); Preconditions.checkEmptyString(apiKey, "You must provide an api key"); Preconditions.checkEmptyString(apiSecret, "You must provide an api secret"); } - public Api getApi() { - return api; - } - public String getCallback() { return callback; } @@ -165,4 +151,26 @@ public OutputStream getDebugStream() { public String getGrantType() { return grantType; } + + protected abstract OAuthConfig createConfig(); + + /** + * Returns the fully configured {@link OAuth10aService} + * + * @param api will build Service for this API + * @return fully configured {@link OAuth10aService} + */ + public OAuth10aService build(final DefaultApi10a api) { + return api.createService(createConfig()); + } + + /** + * Returns the fully configured {@link OAuth20Service} + * + * @param api will build Service for this API + * @return fully configured {@link OAuth20Service} + */ + public OAuth20Service build(final DefaultApi20 api) { + return api.createService(createConfig()); + } } 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 cec32603c..dd5c9ff98 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 @@ -26,16 +26,12 @@ public ServiceBuilder readTimeout(final Integer readTimeout) { return this; } - /** - * Returns the fully configured {@link OAuthService} - * - * @return fully configured {@link OAuthService} - */ - public OAuthService build() { + @Override + protected OAuthConfig createConfig() { super.checkPreconditions(); final OAuthConfig config = new OAuthConfig(getApiKey(), getApiSecret(), getCallback(), getSignatureType(), getScope(), getDebugStream(), connectTimeout, readTimeout, getGrantType()); config.setState(getState()); - return getApi().createService(config); + return config; } } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilderAsync.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilderAsync.java index 1ea3f816b..186674166 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilderAsync.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilderAsync.java @@ -2,7 +2,6 @@ import com.ning.http.client.AsyncHttpClientConfig; import com.github.scribejava.core.model.OAuthConfigAsync; -import com.github.scribejava.core.oauth.OAuthService; import com.github.scribejava.core.utils.Preconditions; public class ServiceBuilderAsync extends AbstractServiceBuilder { @@ -22,14 +21,14 @@ public void checkPreconditions() { Preconditions.checkNotNull(asyncHttpClientConfig, "You must provide an asyncHttpClientConfig"); } - public OAuthService build() { + @Override + protected OAuthConfigAsync createConfig() { checkPreconditions(); final OAuthConfigAsync configAsync = new OAuthConfigAsync(getApiKey(), getApiSecret(), getCallback(), getSignatureType(), getScope(), getGrantType(), getDebugStream(), asyncHttpClientConfig); configAsync.setState(getState()); configAsync.setAsyncHttpProviderClassName(asyncHttpProviderClassName); - - return getApi().createService(configAsync); + return configAsync; } public ServiceBuilderAsync asyncHttpProviderClassName(final String asyncHttpProviderClassName) { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi10a.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi10a.java index 6075d93ef..cf1ab991a 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi10a.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi10a.java @@ -10,8 +10,7 @@ import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.Token; import com.github.scribejava.core.model.Verb; -import com.github.scribejava.core.oauth.OAuth10aServiceImpl; -import com.github.scribejava.core.oauth.OAuthService; +import com.github.scribejava.core.oauth.OAuth10aService; import com.github.scribejava.core.services.HMACSha1SignatureService; import com.github.scribejava.core.services.SignatureService; import com.github.scribejava.core.services.TimestampService; @@ -127,7 +126,7 @@ public Verb getRequestTokenVerb() { public abstract String getAuthorizationUrl(Token requestToken); @Override - public OAuthService createService(final OAuthConfig config) { - return new OAuth10aServiceImpl(this, config); + public OAuth10aService createService(final OAuthConfig config) { + return new OAuth10aService(this, config); } } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java index e93cccbcb..7dc9853d7 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java @@ -4,8 +4,7 @@ import com.github.scribejava.core.extractors.TokenExtractor20Impl; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.Verb; -import com.github.scribejava.core.oauth.OAuth20ServiceImpl; -import com.github.scribejava.core.oauth.OAuthService; +import com.github.scribejava.core.oauth.OAuth20Service; /** * Default implementation of the OAuth protocol, version 2.0 (draft 11) @@ -59,8 +58,7 @@ public Verb getAccessTokenVerb() { * {@inheritDoc} */ @Override - public OAuthService createService(final OAuthConfig config) { - return new OAuth20ServiceImpl(this, config); + public OAuth20Service createService(final OAuthConfig config) { + return new OAuth20Service(this, config); } - } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aServiceImpl.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java similarity index 98% rename from scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aServiceImpl.java rename to scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java index 87b0dccf6..2a047affc 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aServiceImpl.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java @@ -22,7 +22,7 @@ * * @author Pablo Fernandez */ -public class OAuth10aServiceImpl extends OAuthService { +public class OAuth10aService extends OAuthService { private static final String VERSION = "1.0"; private final DefaultApi10a api; @@ -33,7 +33,7 @@ public class OAuth10aServiceImpl extends OAuthService { * @param api OAuth1.0a api information * @param config OAuth 1.0a configuration param object */ - public OAuth10aServiceImpl(final DefaultApi10a api, final OAuthConfig config) { + public OAuth10aService(final DefaultApi10a api, final OAuthConfig config) { super(config); this.api = api; } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20ServiceImpl.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java similarity index 96% rename from scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20ServiceImpl.java rename to scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java index 24a075877..7fe9bf733 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20ServiceImpl.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java @@ -14,7 +14,7 @@ import com.github.scribejava.core.model.Token; import com.github.scribejava.core.model.Verifier; -public class OAuth20ServiceImpl extends OAuthService { +public class OAuth20Service extends OAuthService { private static final String VERSION = "2.0"; private final DefaultApi20 api; @@ -25,7 +25,7 @@ public class OAuth20ServiceImpl extends OAuthService { * @param api OAuth2.0 api information * @param config OAuth 2.0 configuration param object */ - public OAuth20ServiceImpl(final DefaultApi20 api, final OAuthConfig config) { + public OAuth20Service(final DefaultApi20 api, final OAuthConfig config) { super(config); this.api = api; } diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/ObjectMother.java b/scribejava-core/src/test/java/com/github/scribejava/core/ObjectMother.java index 1f148846d..d00be0e19 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/ObjectMother.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/ObjectMother.java @@ -4,12 +4,12 @@ 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.OAuth20ServiceImpl; +import com.github.scribejava.core.oauth.OAuth20Service; -public class ObjectMother { +public abstract class ObjectMother { public static OAuthRequest createSampleOAuthRequest() { - OAuthRequest request = new OAuthRequest(Verb.GET, "http://example.com", new OAuth20ServiceImpl(null, new OAuthConfig("test", + final OAuthRequest request = new OAuthRequest(Verb.GET, "http://example.com", new OAuth20Service(null, new OAuthConfig("test", "test"))); request.addOAuthParameter(OAuthConstants.TIMESTAMP, "123456"); request.addOAuthParameter(OAuthConstants.CONSUMER_KEY, "AS#$^*@&"); @@ -19,7 +19,7 @@ public static OAuthRequest createSampleOAuthRequest() { } public static OAuthRequest createSampleOAuthRequestPort80() { - OAuthRequest request = new OAuthRequest(Verb.GET, "http://example.com:80", new OAuth20ServiceImpl(null, new OAuthConfig("test", + final OAuthRequest request = new OAuthRequest(Verb.GET, "http://example.com:80", new OAuth20Service(null, new OAuthConfig("test", "test"))); request.addOAuthParameter(OAuthConstants.TIMESTAMP, "123456"); request.addOAuthParameter(OAuthConstants.CONSUMER_KEY, "AS#$^*@&"); @@ -29,7 +29,7 @@ public static OAuthRequest createSampleOAuthRequestPort80() { } public static OAuthRequest createSampleOAuthRequestPort80v2() { - OAuthRequest request = new OAuthRequest(Verb.GET, "http://example.com:80/test", new OAuth20ServiceImpl(null, new OAuthConfig( + final OAuthRequest request = new OAuthRequest(Verb.GET, "http://example.com:80/test", new OAuth20Service(null, new OAuthConfig( "test", "test"))); request.addOAuthParameter(OAuthConstants.TIMESTAMP, "123456"); request.addOAuthParameter(OAuthConstants.CONSUMER_KEY, "AS#$^*@&"); @@ -39,7 +39,7 @@ public static OAuthRequest createSampleOAuthRequestPort80v2() { } public static OAuthRequest createSampleOAuthRequestPort8080() { - OAuthRequest request = new OAuthRequest(Verb.GET, "http://example.com:8080", new OAuth20ServiceImpl(null, new OAuthConfig("test", + final OAuthRequest request = new OAuthRequest(Verb.GET, "http://example.com:8080", new OAuth20Service(null, new OAuthConfig("test", "test"))); request.addOAuthParameter(OAuthConstants.TIMESTAMP, "123456"); request.addOAuthParameter(OAuthConstants.CONSUMER_KEY, "AS#$^*@&"); @@ -49,7 +49,7 @@ public static OAuthRequest createSampleOAuthRequestPort8080() { } public static OAuthRequest createSampleOAuthRequestPort443() { - OAuthRequest request = new OAuthRequest(Verb.GET, "https://example.com:443", new OAuth20ServiceImpl(null, new OAuthConfig("test", + final OAuthRequest request = new OAuthRequest(Verb.GET, "https://example.com:443", new OAuth20Service(null, new OAuthConfig("test", "test"))); request.addOAuthParameter(OAuthConstants.TIMESTAMP, "123456"); request.addOAuthParameter(OAuthConstants.CONSUMER_KEY, "AS#$^*@&"); @@ -59,7 +59,7 @@ public static OAuthRequest createSampleOAuthRequestPort443() { } public static OAuthRequest createSampleOAuthRequestPort443v2() { - OAuthRequest request = new OAuthRequest(Verb.GET, "https://example.com:443/test", new OAuth20ServiceImpl(null, new OAuthConfig( + final OAuthRequest request = new OAuthRequest(Verb.GET, "https://example.com:443/test", new OAuth20Service(null, new OAuthConfig( "test", "test"))); request.addOAuthParameter(OAuthConstants.TIMESTAMP, "123456"); request.addOAuthParameter(OAuthConstants.CONSUMER_KEY, "AS#$^*@&"); diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/builder/ServiceBuilderTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/builder/ServiceBuilderTest.java index 19d94bb27..134be1f7b 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/builder/ServiceBuilderTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/builder/ServiceBuilderTest.java @@ -3,11 +3,11 @@ import static org.junit.Assert.assertEquals; import org.junit.Before; import org.junit.Test; -import com.github.scribejava.core.builder.api.Api; +import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.SignatureType; -import com.github.scribejava.core.oauth.OAuthService; +import com.github.scribejava.core.oauth.OAuth20Service; public class ServiceBuilderTest { @@ -22,7 +22,7 @@ public void setUp() { @Test public void shouldReturnConfigDefaultValues() { - builder.provider(api).apiKey("key").apiSecret("secret").build(); + builder.apiKey("key").apiSecret("secret").build(api); final OAuthConfig config = api.getConfig(); assertEquals(config.getApiKey(), "key"); @@ -33,7 +33,7 @@ public void shouldReturnConfigDefaultValues() { @Test public void shouldAcceptValidCallbackUrl() { - builder.provider(api).apiKey("key").apiSecret("secret").callback("http://example.com").build(); + builder.apiKey("key").apiSecret("secret").callback("http://example.com").build(api); final OAuthConfig config = api.getConfig(); assertEquals(config.getApiKey(), "key"); @@ -43,7 +43,7 @@ public void shouldAcceptValidCallbackUrl() { @Test public void shouldAcceptASignatureType() { - builder.provider(api).apiKey("key").apiSecret("secret").signatureType(SignatureType.QueryString).build(); + builder.apiKey("key").apiSecret("secret").signatureType(SignatureType.QueryString).build(api); final OAuthConfig config = api.getConfig(); assertEquals(config.getApiKey(), "key"); @@ -53,12 +53,12 @@ public void shouldAcceptASignatureType() { @Test(expected = IllegalArgumentException.class) public void shouldNotAcceptNullAsCallback() { - builder.provider(api).apiKey("key").apiSecret("secret").callback(null).build(); + builder.apiKey("key").apiSecret("secret").callback(null).build(api); } @Test public void shouldAcceptAnScope() { - builder.provider(api).apiKey("key").apiSecret("secret").scope("rss-api").build(); + builder.apiKey("key").apiSecret("secret").scope("rss-api").build(api); final OAuthConfig config = api.getConfig(); assertEquals(config.getApiKey(), "key"); @@ -66,7 +66,7 @@ public void shouldAcceptAnScope() { assertEquals(config.getScope(), "rss-api"); } - private static class ApiMock implements Api { + private static class ApiMock extends DefaultApi20 { private OAuthConfig config; @@ -79,9 +79,19 @@ private OAuthConfig getConfig() { } @Override - public OAuthService createService(final OAuthConfig config) { + public OAuth20Service createService(final OAuthConfig config) { this.config = config; return null; } + + @Override + public String getAccessTokenEndpoint() { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public String getAuthorizationUrl(final OAuthConfig config) { + throw new UnsupportedOperationException("Not supported yet."); + } } } 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 3d39eff3f..ee27f1e28 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 @@ -8,7 +8,7 @@ import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Verb; -import com.github.scribejava.core.oauth.OAuth20ServiceImpl; +import com.github.scribejava.core.oauth.OAuth20Service; public class BaseStringExtractorTest { @@ -21,7 +21,7 @@ public class BaseStringExtractorTest { private OAuthRequest requestPort443v2; @Before - public void setup() { + public void setUp() { request = ObjectMother.createSampleOAuthRequest(); requestPort80 = ObjectMother.createSampleOAuthRequestPort80(); requestPort80v2 = ObjectMother.createSampleOAuthRequestPort80v2(); @@ -87,7 +87,7 @@ public void shouldThrowExceptionIfRquestIsNull() { @Test(expected = OAuthParametersMissingException.class) public void shouldThrowExceptionIfRquestHasNoOAuthParameters() { - OAuthRequest request = new OAuthRequest(Verb.GET, "http://example.com", new OAuth20ServiceImpl(null, new OAuthConfig("test", + OAuthRequest request = new OAuthRequest(Verb.GET, "http://example.com", new OAuth20Service(null, new OAuthConfig("test", "test"))); extractor.extract(request); } 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 f7a88d37c..4f16c01b3 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 @@ -7,7 +7,7 @@ import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Verb; -import com.github.scribejava.core.oauth.OAuth20ServiceImpl; +import com.github.scribejava.core.oauth.OAuth20Service; import com.github.scribejava.core.ObjectMother; public class HeaderExtractorTest { @@ -42,7 +42,7 @@ public void shouldExceptionIfRequestIsNull() { @Test(expected = OAuthParametersMissingException.class) public void shouldExceptionIfRequestHasNoOAuthParams() { - final OAuthRequest emptyRequest = new OAuthRequest(Verb.GET, "http://example.com", new OAuth20ServiceImpl(null, new OAuthConfig( + final OAuthRequest emptyRequest = new OAuthRequest(Verb.GET, "http://example.com", new OAuth20Service(null, new OAuthConfig( "test", "test"))); extractor.extract(emptyRequest); } diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/model/ConnectionStub.java b/scribejava-core/src/test/java/com/github/scribejava/core/model/ConnectionStub.java index 107818ad1..7a88fe14f 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/model/ConnectionStub.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/model/ConnectionStub.java @@ -6,6 +6,7 @@ import java.io.InputStream; import java.io.OutputStream; import java.net.HttpURLConnection; +import java.net.MalformedURLException; import java.net.URL; import java.util.Arrays; import java.util.HashMap; @@ -14,11 +15,11 @@ public class ConnectionStub extends HttpURLConnection { - private Map headers = new HashMap(); - private Map> responseHeaders = new HashMap>(); + private final Map headers = new HashMap<>(); + private final Map> responseHeaders = new HashMap<>(); private int inputStreamCalled = 0; - public ConnectionStub() throws Exception { + public ConnectionStub() throws MalformedURLException { super(new URL("http://example.com")); } @@ -67,12 +68,15 @@ public void addResponseHeader(String key, String value) { responseHeaders.put(key, Arrays.asList(value)); } + @Override public void connect() throws IOException { } + @Override public void disconnect() { } + @Override public boolean usingProxy() { return false; } diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/model/ForceTypeOfHttpRequestTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/model/ForceTypeOfHttpRequestTest.java index 41e65dad0..4ab58cf49 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/model/ForceTypeOfHttpRequestTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/model/ForceTypeOfHttpRequestTest.java @@ -6,12 +6,11 @@ import org.junit.Test; import org.junit.rules.ExpectedException; import com.github.scribejava.core.exceptions.OAuthException; -import com.github.scribejava.core.oauth.OAuth20ServiceImpl; +import com.github.scribejava.core.oauth.OAuth20Service; import com.github.scribejava.core.oauth.OAuthService; public class ForceTypeOfHttpRequestTest { - private ConnectionStub connection; private OAuthRequest request; private OAuthRequestAsync requestAsync; private OAuthService oAuthService; @@ -20,10 +19,9 @@ public class ForceTypeOfHttpRequestTest { public ExpectedException expectedException = ExpectedException.none(); @Before - public void setup() throws Exception { - connection = new ConnectionStub(); + public void setUp() { ScribeJavaConfig.setForceTypeOfHttpRequests(ForceTypeOfHttpRequest.NONE); - oAuthService = new OAuth20ServiceImpl(null, new OAuthConfig("test", "test")); + oAuthService = new OAuth20Service(null, new OAuthConfig("test", "test")); request = new OAuthRequest(Verb.GET, "http://example.com?qsparam=value&other+param=value+with+spaces", oAuthService); requestAsync = new OAuthRequestAsync(Verb.GET, "http://example.com?qsparam=value&other+param=value+with+spaces", oAuthService); } 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 2c8fefbfb..2f1475677 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 @@ -3,15 +3,15 @@ import static org.junit.Assert.assertEquals; import org.junit.Before; import org.junit.Test; -import com.github.scribejava.core.oauth.OAuth20ServiceImpl; +import com.github.scribejava.core.oauth.OAuth20Service; public class OAuthRequestTest { private OAuthRequest request; @Before - public void setup() { - request = new OAuthRequest(Verb.GET, "http://example.com", new OAuth20ServiceImpl(null, new OAuthConfig("test", "test"))); + public void setUp() { + request = new OAuthRequest(Verb.GET, "http://example.com", new OAuth20Service(null, new OAuthConfig("test", "test"))); } @Test diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/model/RequestTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/model/RequestTest.java index 841601842..091794f9a 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/model/RequestTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/model/RequestTest.java @@ -5,8 +5,9 @@ import static org.junit.Assert.assertTrue; import org.junit.Before; import org.junit.Test; -import com.github.scribejava.core.oauth.OAuth20ServiceImpl; +import com.github.scribejava.core.oauth.OAuth20Service; import com.github.scribejava.core.oauth.OAuthService; +import java.net.MalformedURLException; public class RequestTest { @@ -16,9 +17,9 @@ public class RequestTest { private OAuthService oAuthService; @Before - public void setup() throws Exception { + public void setUp() throws MalformedURLException { connection = new ConnectionStub(); - oAuthService = new OAuth20ServiceImpl(null, new OAuthConfig("test", "test")); + oAuthService = new OAuth20Service(null, new OAuthConfig("test", "test")); postRequest = new OAuthRequest(Verb.POST, "http://example.com", oAuthService); postRequest.addBodyParameter("param", "value"); postRequest.addBodyParameter("param with spaces", "value with spaces"); diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/model/TokenTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/model/TokenTest.java index 6ba6ff0d3..727b91b78 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/model/TokenTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/model/TokenTest.java @@ -40,8 +40,8 @@ public void shouldNotBeEqualToNullOrOtherObjects() { } @Test - public void shouldReturnUrlParam() throws Exception { - Token actual = new Token("acccess", "secret", "user_id=3107154759&screen_name=someuser&empty=&="); + public void shouldReturnUrlParam() { + final Token actual = new Token("acccess", "secret", "user_id=3107154759&screen_name=someuser&empty=&="); assertEquals("someuser", actual.getParameter("screen_name")); assertEquals("3107154759", actual.getParameter("user_id")); assertEquals(null, actual.getParameter("empty")); From 37731565027f0073953d6952b49bba39fdd076fc Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 25 Jan 2016 12:04:57 +0300 Subject: [PATCH 093/882] integrate checkstyle [i.garanina] --- checkstyle.xml | 8 ++++++++ pom.xml | 27 +++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 checkstyle.xml diff --git a/checkstyle.xml b/checkstyle.xml new file mode 100644 index 000000000..c8ac80910 --- /dev/null +++ b/checkstyle.xml @@ -0,0 +1,8 @@ + + + + + + diff --git a/pom.xml b/pom.xml index e92f0e525..c2f0b77ff 100644 --- a/pom.xml +++ b/pom.xml @@ -163,6 +163,33 @@ + + org.apache.maven.plugins + maven-checkstyle-plugin + 2.17 + + + com.puppycrawl.tools + checkstyle + 6.14.1 + + + + + validate + validate + + ${basedir}/src + checkstyle.xml + UTF-8 + true + + + check + + + + From f2da2b1d16db198dde187ed6f77997d7cdcbdcdb Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 25 Jan 2016 12:22:16 +0300 Subject: [PATCH 094/882] add checkstyle rules, fix MissingOverride rule --- checkstyle.xml | 8 ++++++++ .../core/extractors/BaseStringExtractorImpl.java | 1 + .../scribejava/core/services/RSASha1SignatureService.java | 2 ++ .../scribejava/core/services/TimestampServiceImpl.java | 2 ++ 4 files changed, 13 insertions(+) diff --git a/checkstyle.xml b/checkstyle.xml index c8ac80910..74e2839aa 100644 --- a/checkstyle.xml +++ b/checkstyle.xml @@ -5,4 +5,12 @@ + + + + + + + + diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/BaseStringExtractorImpl.java b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/BaseStringExtractorImpl.java index 2eb2ea864..123d9e1b2 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/BaseStringExtractorImpl.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/BaseStringExtractorImpl.java @@ -19,6 +19,7 @@ public class BaseStringExtractorImpl implements BaseStringExtractor { /** * {@inheritDoc} */ + @Override public String extract(AbstractRequest request) { checkPreconditions(request); String verb = OAuthEncoder.encode(getVerb(request)); 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 ea7cb6dc2..c85f2940d 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 @@ -23,6 +23,7 @@ public RSASha1SignatureService(PrivateKey privateKey) { /** * {@inheritDoc} */ + @Override public String getSignature(String baseString, String apiSecret, String tokenSecret) { try { Signature signature = Signature.getInstance(RSA_SHA1); @@ -41,6 +42,7 @@ private String bytesToBase64String(Signature signature) throws SignatureExceptio /** * {@inheritDoc} */ + @Override public String getSignatureMethod() { return METHOD; } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/services/TimestampServiceImpl.java b/scribejava-core/src/main/java/com/github/scribejava/core/services/TimestampServiceImpl.java index c844ea6c7..cef00537d 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/services/TimestampServiceImpl.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/services/TimestampServiceImpl.java @@ -21,6 +21,7 @@ public TimestampServiceImpl() { /** * {@inheritDoc} */ + @Override public String getNonce() { Long ts = getTs(); return String.valueOf(ts + timer.getRandomInteger()); @@ -29,6 +30,7 @@ public String getNonce() { /** * {@inheritDoc} */ + @Override public String getTimestampInSeconds() { return String.valueOf(getTs()); } From c652becda0968455eb91a6eed511c161ae77388b Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 25 Jan 2016 12:28:19 +0300 Subject: [PATCH 095/882] add checkstyle rules, fix VisibilityModifier --- checkstyle.xml | 11 +++++++++++ .../core/services/RSASha1SignatureServiceTest.java | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/checkstyle.xml b/checkstyle.xml index 74e2839aa..0ab945b35 100644 --- a/checkstyle.xml +++ b/checkstyle.xml @@ -12,5 +12,16 @@ + + + + + + + + + + + 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 f5e4d65ec..8adfdb8e3 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 @@ -9,7 +9,7 @@ public class RSASha1SignatureServiceTest { - RSASha1SignatureService service = new RSASha1SignatureService(getPrivateKey()); + private RSASha1SignatureService service = new RSASha1SignatureService(getPrivateKey()); @Test public void shouldReturnSignatureMethodString() { From f7aa5f1f2e14e1445fa1f26af8f437f235249f84 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 25 Jan 2016 12:32:59 +0300 Subject: [PATCH 096/882] add checkstyle rules, fix DeclarationOrder --- checkstyle.xml | 2 ++ .../com/github/scribejava/apis/LinkedInApi.java | 17 +++++++++-------- .../core/exceptions/OAuthException.java | 4 ++-- .../core/extractors/HeaderExtractorImpl.java | 2 +- .../scribejava/core/model/AbstractRequest.java | 2 +- .../core/model/ForceTypeOfHttpRequestTest.java | 6 +++--- 6 files changed, 18 insertions(+), 15 deletions(-) diff --git a/checkstyle.xml b/checkstyle.xml index 0ab945b35..bfdceb412 100644 --- a/checkstyle.xml +++ b/checkstyle.xml @@ -23,5 +23,7 @@ + + diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi.java index 85e2454cf..66567c758 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi.java @@ -8,14 +8,6 @@ public class LinkedInApi extends DefaultApi10a { private static final String AUTHORIZE_URL = "https://api.linkedin.com/uas/oauth/authenticate?oauth_token=%s"; private static final String REQUEST_TOKEN_URL = "https://api.linkedin.com/uas/oauth/requestToken"; - private static class InstanceHolder { - private static final LinkedInApi INSTANCE = new LinkedInApi(); - } - - public static LinkedInApi instance() { - return InstanceHolder.INSTANCE; - } - private final String scopesAsString; public LinkedInApi() { @@ -34,6 +26,15 @@ public LinkedInApi(final String... scopes) { } } + private static class InstanceHolder { + + private static final LinkedInApi INSTANCE = new LinkedInApi(); + } + + public static LinkedInApi instance() { + return InstanceHolder.INSTANCE; + } + @Override public String getAccessTokenEndpoint() { return "https://api.linkedin.com/uas/oauth/accessToken"; diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/exceptions/OAuthException.java b/scribejava-core/src/main/java/com/github/scribejava/core/exceptions/OAuthException.java index 030545f4e..c16213dfb 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/exceptions/OAuthException.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/exceptions/OAuthException.java @@ -8,6 +8,8 @@ */ public class OAuthException extends RuntimeException { + private static final long serialVersionUID = 1L; + /** * Default constructor * @@ -35,6 +37,4 @@ public OAuthException(String message) { public OAuthException(Exception e) { super(e); } - - private static final long serialVersionUID = 1L; } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/HeaderExtractorImpl.java b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/HeaderExtractorImpl.java index 8222cc846..3a00b4a21 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/HeaderExtractorImpl.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/HeaderExtractorImpl.java @@ -15,9 +15,9 @@ */ public class HeaderExtractorImpl implements HeaderExtractor { + public static final int ESTIMATED_PARAM_LENGTH = 20; private static final String PARAM_SEPARATOR = ", "; private static final String PREAMBLE = "OAuth "; - public static final int ESTIMATED_PARAM_LENGTH = 20; /** * {@inheritDoc} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/AbstractRequest.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/AbstractRequest.java index 5f51c17ca..bf893f926 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/AbstractRequest.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/AbstractRequest.java @@ -16,9 +16,9 @@ */ public abstract class AbstractRequest { + public static final String DEFAULT_CONTENT_TYPE = "application/x-www-form-urlencoded"; protected static final String CONTENT_LENGTH = "Content-Length"; protected static final String CONTENT_TYPE = "Content-Type"; - public static final String DEFAULT_CONTENT_TYPE = "application/x-www-form-urlencoded"; private static final String OAUTH_PREFIX = "oauth_"; private final String url; diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/model/ForceTypeOfHttpRequestTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/model/ForceTypeOfHttpRequestTest.java index 4ab58cf49..3f51ae54a 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/model/ForceTypeOfHttpRequestTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/model/ForceTypeOfHttpRequestTest.java @@ -11,13 +11,13 @@ public class ForceTypeOfHttpRequestTest { + @Rule + public ExpectedException expectedException = ExpectedException.none(); + private OAuthRequest request; private OAuthRequestAsync requestAsync; private OAuthService oAuthService; - @Rule - public ExpectedException expectedException = ExpectedException.none(); - @Before public void setUp() { ScribeJavaConfig.setForceTypeOfHttpRequests(ForceTypeOfHttpRequest.NONE); From 65be66d82922e8290f12fb0fbbef93f2774c8aea Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 25 Jan 2016 12:37:47 +0300 Subject: [PATCH 097/882] add checkstyle rules, fix ExplicitInitialization --- checkstyle.xml | 5 +++++ .../com/github/scribejava/core/model/ConnectionStub.java | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/checkstyle.xml b/checkstyle.xml index bfdceb412..e20ea1d23 100644 --- a/checkstyle.xml +++ b/checkstyle.xml @@ -25,5 +25,10 @@ + + + + + diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/model/ConnectionStub.java b/scribejava-core/src/test/java/com/github/scribejava/core/model/ConnectionStub.java index 7a88fe14f..650a71a47 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/model/ConnectionStub.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/model/ConnectionStub.java @@ -17,7 +17,7 @@ public class ConnectionStub extends HttpURLConnection { private final Map headers = new HashMap<>(); private final Map> responseHeaders = new HashMap<>(); - private int inputStreamCalled = 0; + private int inputStreamCalled; public ConnectionStub() throws MalformedURLException { super(new URL("http://example.com")); From 3cb19118c0502bd4c531e62e11df85804a8f42ee Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 25 Jan 2016 13:40:45 +0300 Subject: [PATCH 098/882] add and fix checkstyle rule FinalLocalVariable --- checkstyle.xml | 1 + .../com/github/scribejava/apis/AWeberApi.java | 2 +- .../scribejava/apis/ConstantContactApi.java | 2 +- .../scribejava/apis/ConstantContactApi2.java | 4 +-- .../com/github/scribejava/apis/DiggApi.java | 2 +- .../scribejava/apis/DoktornaraboteApi.java | 4 +-- .../github/scribejava/apis/DropBoxApi.java | 2 +- .../github/scribejava/apis/EvernoteApi.java | 2 +- .../github/scribejava/apis/FacebookApi.java | 2 +- .../com/github/scribejava/apis/FlickrApi.java | 2 +- .../scribejava/apis/Foursquare2Api.java | 2 +- .../github/scribejava/apis/FoursquareApi.java | 2 +- .../github/scribejava/apis/FreelancerApi.java | 4 +-- .../github/scribejava/apis/GetGlueApi.java | 2 +- .../com/github/scribejava/apis/GitHubApi.java | 2 +- .../com/github/scribejava/apis/GoogleApi.java | 2 +- .../github/scribejava/apis/GoogleApi20.java | 4 +-- .../com/github/scribejava/apis/HHApi.java | 4 +-- .../com/github/scribejava/apis/ImgurApi.java | 6 ++-- .../com/github/scribejava/apis/KaixinApi.java | 2 +- .../github/scribejava/apis/KaixinApi20.java | 2 +- .../github/scribejava/apis/LinkedInApi.java | 6 ++-- .../github/scribejava/apis/LinkedInApi20.java | 4 +-- .../com/github/scribejava/apis/LiveApi.java | 2 +- .../github/scribejava/apis/LoveFilmApi.java | 2 +- .../com/github/scribejava/apis/MailruApi.java | 4 +-- .../com/github/scribejava/apis/MeetupApi.java | 2 +- .../github/scribejava/apis/MendeleyApi.java | 2 +- .../com/github/scribejava/apis/MisoApi.java | 2 +- .../github/scribejava/apis/NetProspexApi.java | 2 +- .../scribejava/apis/NeteaseWeibooApi.java | 4 +-- .../scribejava/apis/OdnoklassnikiApi.java | 4 +-- .../github/scribejava/apis/PinterestApi.java | 2 +- .../com/github/scribejava/apis/PlurkApi.java | 4 +-- .../com/github/scribejava/apis/Px500Api.java | 2 +- .../com/github/scribejava/apis/QWeiboApi.java | 2 +- .../com/github/scribejava/apis/RenrenApi.java | 2 +- .../com/github/scribejava/apis/SapoApi.java | 2 +- .../github/scribejava/apis/SimpleGeoApi.java | 2 +- .../github/scribejava/apis/SinaWeiboApi.java | 2 +- .../scribejava/apis/SinaWeiboApi20.java | 2 +- .../github/scribejava/apis/SkyrockApi.java | 2 +- .../github/scribejava/apis/SohuWeiboApi.java | 2 +- .../com/github/scribejava/apis/TrelloApi.java | 2 +- .../com/github/scribejava/apis/TumblrApi.java | 2 +- .../com/github/scribejava/apis/TutByApi.java | 4 +-- .../github/scribejava/apis/TwitterApi.java | 4 +-- .../github/scribejava/apis/UbuntuOneApi.java | 2 +- .../com/github/scribejava/apis/ViadeoApi.java | 2 +- .../com/github/scribejava/apis/VimeoApi.java | 2 +- .../github/scribejava/apis/VkontakteApi.java | 2 +- .../com/github/scribejava/apis/XingApi.java | 2 +- .../com/github/scribejava/apis/YahooApi.java | 2 +- .../com/github/scribejava/apis/YammerApi.java | 2 +- .../apis/google/GoogleJsonTokenExtractor.java | 4 +-- .../scribejava/apis/google/GoogleToken.java | 2 +- .../DoktornaraboteOAuthServiceImpl.java | 4 +-- .../apis/service/GoogleOAuthServiceImpl.java | 4 +-- .../apis/service/HHOAuthServiceImpl.java | 4 +-- .../apis/service/ImgurOAuthServiceImpl.java | 6 ++-- .../apis/service/LinkedIn20ServiceImpl.java | 6 ++-- .../apis/service/MailruOAuthServiceImpl.java | 10 +++---- .../service/OdnoklassnikiServiceImpl.java | 4 +-- .../apis/service/TutByOAuthServiceImpl.java | 4 +-- .../apis/examples/AWeberExample.java | 2 +- .../scribejava/apis/examples/DiggExample.java | 2 +- .../apis/examples/FacebookAsyncExample.java | 2 +- .../apis/examples/FacebookExample.java | 2 +- .../apis/examples/FlickrExample.java | 2 +- .../apis/examples/Foursquare2Example.java | 2 +- .../apis/examples/FoursquareExample.java | 2 +- .../apis/examples/FreelancerExample.java | 2 +- .../apis/examples/GitHubExample.java | 2 +- .../apis/examples/Google20Example.java | 2 +- .../apis/examples/GoogleExample.java | 2 +- .../scribejava/apis/examples/HHExample.java | 2 +- .../apis/examples/ImgurExample.java | 2 +- .../apis/examples/Kaixin20Example.java | 2 +- .../apis/examples/LinkedIn20Example.java | 2 +- .../apis/examples/LinkedInExample.java | 2 +- .../examples/LinkedInExampleWithScopes.java | 2 +- .../scribejava/apis/examples/LiveExample.java | 2 +- .../apis/examples/LoveFilmExample.java | 2 +- .../apis/examples/MailruAsyncExample.java | 2 +- .../apis/examples/MailruExample.java | 2 +- .../apis/examples/MeetupExample.java | 2 +- .../apis/examples/NeteaseWeiboExample.java | 2 +- .../apis/examples/OdnoklassnikiExample.java | 2 +- .../apis/examples/PinterestExample.java | 2 +- .../apis/examples/Px500Example.java | 2 +- .../apis/examples/RenrenExample.java | 8 ++--- .../apis/examples/SinaWeibo2Example.java | 2 +- .../apis/examples/SinaWeiboExample.java | 2 +- .../apis/examples/SkyrockExample.java | 2 +- .../apis/examples/SohuWeiboExample.java | 2 +- .../apis/examples/TrelloExample.java | 2 +- .../apis/examples/TumblrExample.java | 2 +- .../apis/examples/TutByExample.java | 2 +- .../apis/examples/TwitterExample.java | 2 +- .../apis/examples/ViadeoExample.java | 2 +- .../apis/examples/VkontakteExample.java | 2 +- .../scribejava/apis/examples/XingExample.java | 2 +- .../apis/examples/YahooExample.java | 2 +- .../core/builder/AbstractServiceBuilder.java | 20 ++++++------- .../core/builder/ServiceBuilder.java | 4 +-- .../core/builder/ServiceBuilderAsync.java | 4 +-- .../core/builder/api/DefaultApi10a.java | 2 +- .../core/builder/api/DefaultApi20.java | 2 +- .../exceptions/OAuthConnectionException.java | 2 +- .../extractors/BaseStringExtractorImpl.java | 8 ++--- .../core/extractors/HeaderExtractorImpl.java | 6 ++-- .../core/extractors/JsonTokenExtractor.java | 4 +-- .../core/extractors/TokenExtractor20Impl.java | 2 +- .../core/extractors/TokenExtractorImpl.java | 4 +-- .../core/model/AbstractRequest.java | 26 ++++++++-------- .../scribejava/core/model/OAuthConfig.java | 9 +++--- .../core/model/OAuthConfigAsync.java | 8 ++--- .../scribejava/core/model/OAuthRequest.java | 6 ++-- .../core/model/OAuthRequestAsync.java | 22 +++++++------- .../scribejava/core/model/Parameter.java | 6 ++-- .../scribejava/core/model/ParameterList.java | 18 +++++------ .../scribejava/core/model/Response.java | 10 +++---- .../github/scribejava/core/model/Token.java | 8 ++--- .../core/oauth/OAuth10aService.java | 26 ++++++++-------- .../scribejava/core/oauth/OAuth20Service.java | 18 +++++------ .../scribejava/core/oauth/OAuthService.java | 2 +- .../services/HMACSha1SignatureService.java | 6 ++-- .../services/RSASha1SignatureService.java | 2 +- .../core/services/TimestampServiceImpl.java | 2 +- .../scribejava/core/utils/MapUtils.java | 4 +-- .../scribejava/core/utils/OAuthEncoder.java | 8 ++--- .../scribejava/core/utils/Preconditions.java | 12 ++++---- .../scribejava/core/utils/StreamUtils.java | 4 +-- .../core/builder/ServiceBuilderTest.java | 4 +-- .../extractors/BaseStringExtractorTest.java | 30 +++++++++---------- .../extractors/JsonTokenExtractorTest.java | 2 +- .../core/extractors/TokenExtractor20Test.java | 18 +++++------ .../core/extractors/TokenExtractorTest.java | 24 +++++++-------- .../scribejava/core/model/ConnectionStub.java | 2 +- .../core/model/ParameterListTest.java | 8 ++--- .../scribejava/core/model/RequestTest.java | 4 +-- .../scribejava/core/model/ResponseTest.java | 2 +- .../HMACSha1SignatureServiceTest.java | 10 +++---- .../services/RSASha1SignatureServiceTest.java | 16 +++++----- .../core/services/TimestampServiceTest.java | 4 +-- .../scribejava/core/utils/MapUtilsTest.java | 4 +-- .../core/utils/OAuthEncoderTest.java | 24 +++++++-------- .../core/utils/StreamUtilsTest.java | 8 ++--- 148 files changed, 343 insertions(+), 343 deletions(-) diff --git a/checkstyle.xml b/checkstyle.xml index e20ea1d23..527132d23 100644 --- a/checkstyle.xml +++ b/checkstyle.xml @@ -30,5 +30,6 @@ + diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/AWeberApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/AWeberApi.java index 07bc0a1b4..4c95cef93 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/AWeberApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/AWeberApi.java @@ -31,7 +31,7 @@ public String getRequestTokenEndpoint() { } @Override - public String getAuthorizationUrl(final Token requestToken) { + public String getAuthorizationUrl(Token requestToken) { return String.format(AUTHORIZE_URL, requestToken.getToken()); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/ConstantContactApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/ConstantContactApi.java index a347303f0..842c4cdca 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/ConstantContactApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/ConstantContactApi.java @@ -24,7 +24,7 @@ public String getAccessTokenEndpoint() { } @Override - public String getAuthorizationUrl(final Token requestToken) { + public String getAuthorizationUrl(Token requestToken) { return String.format(AUTHORIZE_URL, requestToken.getToken()); } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/ConstantContactApi2.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/ConstantContactApi2.java index e8dbb5915..fe443c9f6 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/ConstantContactApi2.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/ConstantContactApi2.java @@ -20,7 +20,7 @@ public class ConstantContactApi2 extends DefaultApi20 { private static final AccessTokenExtractor ACCESS_TOKEN_EXTRACTOR = new AccessTokenExtractor() { @Override - public Token extract(final String response) { + public Token extract(String response) { Preconditions.checkEmptyString(response, "Response body is incorrect. Can't extract a token from an empty string"); final String regex = "\"access_token\"\\s*:\\s*\"([^&\"]+)\""; @@ -51,7 +51,7 @@ public String getAccessTokenEndpoint() { } @Override - public String getAuthorizationUrl(final OAuthConfig config) { + public String getAuthorizationUrl(OAuthConfig config) { return String.format(AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback())); } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/DiggApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/DiggApi.java index 257a659e4..97897c76f 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/DiggApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/DiggApi.java @@ -30,7 +30,7 @@ public String getAccessTokenEndpoint() { } @Override - public String getAuthorizationUrl(final Token requestToken) { + public String getAuthorizationUrl(Token requestToken) { return String.format(AUTHORIZATION_URL, requestToken.getToken()); } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/DoktornaraboteApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/DoktornaraboteApi.java index b767f6c42..104c731a3 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/DoktornaraboteApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/DoktornaraboteApi.java @@ -38,7 +38,7 @@ public String getAccessTokenEndpoint() { } @Override - public String getAuthorizationUrl(final OAuthConfig config) { + public String getAuthorizationUrl(OAuthConfig config) { Preconditions.checkValidUrl( config.getCallback(), "Must provide a valid url as callback. Doktornarabote does not support OOB"); @@ -64,7 +64,7 @@ public AccessTokenExtractor getAccessTokenExtractor() { } @Override - public OAuth20Service createService(final OAuthConfig config) { + public OAuth20Service createService(OAuthConfig config) { return new DoktornaraboteOAuthServiceImpl(this, config); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/DropBoxApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/DropBoxApi.java index 2a78f67d3..08434e783 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/DropBoxApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/DropBoxApi.java @@ -22,7 +22,7 @@ public String getAccessTokenEndpoint() { } @Override - public String getAuthorizationUrl(final Token requestToken) { + public String getAuthorizationUrl(Token requestToken) { return "https://www.dropbox.com/1/oauth/authorize?oauth_token=" + requestToken.getToken(); } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/EvernoteApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/EvernoteApi.java index e77f092fc..9ebe1ed20 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/EvernoteApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/EvernoteApi.java @@ -31,7 +31,7 @@ public String getAccessTokenEndpoint() { } @Override - public String getAuthorizationUrl(final Token requestToken) { + public String getAuthorizationUrl(Token requestToken) { return String.format(serviceUrl() + "/OAuth.action?oauth_token=%s", requestToken.getToken()); } 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 1d6c8457a..b3d21f2e8 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 @@ -27,7 +27,7 @@ public String getAccessTokenEndpoint() { } @Override - public String getAuthorizationUrl(final OAuthConfig config) { + public String getAuthorizationUrl(OAuthConfig config) { Preconditions.checkValidUrl(config.getCallback(), "Must provide a valid url as callback. Facebook does not support OOB"); final StringBuilder sb = new StringBuilder(String.format(AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode( diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/FlickrApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/FlickrApi.java index 2fb523a0d..ef8cb6ebf 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/FlickrApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/FlickrApi.java @@ -34,7 +34,7 @@ public String getAccessTokenEndpoint() { * {@inheritDoc} */ @Override - public String getAuthorizationUrl(final Token requestToken) { + public String getAuthorizationUrl(Token requestToken) { return "https://www.flickr.com/services/oauth/authorize?oauth_token=" + requestToken.getToken(); } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/Foursquare2Api.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/Foursquare2Api.java index 8c3857d84..52328c0e3 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/Foursquare2Api.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/Foursquare2Api.java @@ -29,7 +29,7 @@ public String getAccessTokenEndpoint() { } @Override - public String getAuthorizationUrl(final OAuthConfig config) { + public String getAuthorizationUrl(OAuthConfig config) { Preconditions.checkValidUrl(config.getCallback(), "Must provide a valid url as callback. Foursquare2 does not support OOB"); return String.format(AUTHORIZATION_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback())); } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/FoursquareApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/FoursquareApi.java index c3f55cd1d..1380c4080 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/FoursquareApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/FoursquareApi.java @@ -29,7 +29,7 @@ public String getRequestTokenEndpoint() { } @Override - public String getAuthorizationUrl(final Token requestToken) { + public String getAuthorizationUrl(Token requestToken) { return String.format(AUTHORIZATION_URL, requestToken.getToken()); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/FreelancerApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/FreelancerApi.java index ef6a36e49..2ccee3d59 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/FreelancerApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/FreelancerApi.java @@ -40,7 +40,7 @@ public Verb getRequestTokenVerb() { } @Override - public String getAuthorizationUrl(final Token requestToken) { + public String getAuthorizationUrl(Token requestToken) { return String.format(AUTHORIZATION_URL, requestToken.getToken()); } @@ -70,7 +70,7 @@ public String getAccessTokenEndpoint() { } @Override - public String getAuthorizationUrl(final Token requestToken) { + public String getAuthorizationUrl(Token requestToken) { return String.format(SANDBOX_AUTHORIZATION_URL + "?oauth_token=%s", requestToken.getToken()); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/GetGlueApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/GetGlueApi.java index 21a40cc24..63e8ce4d9 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/GetGlueApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/GetGlueApi.java @@ -31,7 +31,7 @@ public String getRequestTokenEndpoint() { } @Override - public String getAuthorizationUrl(final Token requestToken) { + public String getAuthorizationUrl(Token requestToken) { return String.format(AUTHORIZE_URL, requestToken.getToken()); } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/GitHubApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/GitHubApi.java index 7b2d0ff96..491f5f852 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/GitHubApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/GitHubApi.java @@ -27,7 +27,7 @@ public String getAccessTokenEndpoint() { } @Override - public String getAuthorizationUrl(final OAuthConfig config) { + public String getAuthorizationUrl(OAuthConfig config) { Preconditions.checkValidUrl(config.getCallback(), "Must provide a valid url as callback. GitHub does not support OOB"); final StringBuilder sb = new StringBuilder(String.format(AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()))); if (config.hasScope()) { diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/GoogleApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/GoogleApi.java index 1dd7bfd72..aa293c693 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/GoogleApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/GoogleApi.java @@ -40,7 +40,7 @@ public Verb getRequestTokenVerb() { } @Override - public String getAuthorizationUrl(final Token requestToken) { + public String getAuthorizationUrl(Token requestToken) { return String.format(AUTHORIZATION_URL, requestToken.getToken()); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/GoogleApi20.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/GoogleApi20.java index d89f32803..ad68c5a7e 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/GoogleApi20.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/GoogleApi20.java @@ -37,7 +37,7 @@ public String getAccessTokenEndpoint() { } @Override - public String getAuthorizationUrl(final OAuthConfig config) { + public String getAuthorizationUrl(OAuthConfig config) { final StringBuilder sb = new StringBuilder(String.format(AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode( config.getCallback()), OAuthEncoder.encode(config.getScope()))); @@ -54,7 +54,7 @@ public AccessTokenExtractor getAccessTokenExtractor() { } @Override - public OAuth20Service createService(final OAuthConfig config) { + public OAuth20Service createService(OAuthConfig config) { return new GoogleOAuthServiceImpl(this, config); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/HHApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/HHApi.java index 3a13271a8..0325eddbc 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/HHApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/HHApi.java @@ -37,7 +37,7 @@ public String getAccessTokenEndpoint() { } @Override - public String getAuthorizationUrl(final OAuthConfig config) { + public String getAuthorizationUrl(OAuthConfig config) { return String.format(AUTHORIZE_URL, config.getApiKey()); } @@ -47,7 +47,7 @@ public AccessTokenExtractor getAccessTokenExtractor() { } @Override - public OAuth20Service createService(final OAuthConfig config) { + public OAuth20Service createService(OAuthConfig config) { return new HHOAuthServiceImpl(this, config); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java index f6d92904b..3e1d0c859 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java @@ -40,16 +40,16 @@ public String getAccessTokenEndpoint() { } @Override - public String getAuthorizationUrl(final OAuthConfig config) { + public String getAuthorizationUrl(OAuthConfig config) { return String.format(AUTHORIZATION_URL, config.getApiKey(), isOob(config) ? "pin" : "code"); } @Override - public OAuth20Service createService(final OAuthConfig config) { + public OAuth20Service createService(OAuthConfig config) { return new ImgurOAuthServiceImpl(this, config); } - public static boolean isOob(final OAuthConfig config) { + public static boolean isOob(OAuthConfig config) { return "oob".equals(config.getCallback()); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/KaixinApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/KaixinApi.java index b24b99714..1fc0515c3 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/KaixinApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/KaixinApi.java @@ -32,7 +32,7 @@ public String getAccessTokenEndpoint() { } @Override - public String getAuthorizationUrl(final Token requestToken) { + public String getAuthorizationUrl(Token requestToken) { return String.format(AUTHORIZE_URL, requestToken.getToken()); } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/KaixinApi20.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/KaixinApi20.java index a30b86a5e..8c526cb1f 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/KaixinApi20.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/KaixinApi20.java @@ -37,7 +37,7 @@ public String getAccessTokenEndpoint() { } @Override - public String getAuthorizationUrl(final OAuthConfig config) { + public String getAuthorizationUrl(OAuthConfig config) { // Append scope if present if (config.hasScope()) { return String.format(SCOPED_AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()), OAuthEncoder.encode(config. diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi.java index 66567c758..2069aade0 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi.java @@ -14,12 +14,12 @@ public LinkedInApi() { scopesAsString = null; } - public LinkedInApi(final String... scopes) { + public LinkedInApi(String... scopes) { if (scopes == null || scopes.length == 0) { scopesAsString = null; } else { final StringBuilder builder = new StringBuilder(); - for (final String scope : scopes) { + for (String scope : scopes) { builder.append('+').append(scope); } scopesAsString = "?scope=" + builder.substring(1); @@ -46,7 +46,7 @@ public String getRequestTokenEndpoint() { } @Override - public String getAuthorizationUrl(final Token requestToken) { + public String getAuthorizationUrl(Token requestToken) { return String.format(AUTHORIZE_URL, requestToken.getToken()); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi20.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi20.java index 638fae80d..11603e3d8 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi20.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi20.java @@ -40,7 +40,7 @@ public String getAccessTokenEndpoint() { } @Override - public String getAuthorizationUrl(final OAuthConfig config) { + public String getAuthorizationUrl(OAuthConfig config) { Preconditions.checkValidUrl(config.getCallback(), "Must provide a valid url as callback. LinkedIn does not support OOB"); if (config.hasScope()) { @@ -58,7 +58,7 @@ public AccessTokenExtractor getAccessTokenExtractor() { } @Override - public OAuth20Service createService(final OAuthConfig config) { + public OAuth20Service createService(OAuthConfig config) { return new LinkedIn20ServiceImpl(this, config); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/LiveApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/LiveApi.java index c239ea28c..f1b7083e7 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/LiveApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/LiveApi.java @@ -30,7 +30,7 @@ public String getAccessTokenEndpoint() { } @Override - public String getAuthorizationUrl(final OAuthConfig config) { + public String getAuthorizationUrl(OAuthConfig config) { Preconditions.checkValidUrl(config.getCallback(), "Must provide a valid url as callback. Live does not support OOB"); // Append scope if present diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/LoveFilmApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/LoveFilmApi.java index 751b51f5a..4f2c2615f 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/LoveFilmApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/LoveFilmApi.java @@ -31,7 +31,7 @@ public String getAccessTokenEndpoint() { } @Override - public String getAuthorizationUrl(final Token requestToken) { + public String getAuthorizationUrl(Token requestToken) { return String.format(AUTHORIZE_URL, requestToken.getToken()); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java index 1aee71983..19e462cc5 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java @@ -37,7 +37,7 @@ public String getAccessTokenEndpoint() { } @Override - public String getAuthorizationUrl(final OAuthConfig config) { + public String getAuthorizationUrl(OAuthConfig config) { Preconditions.checkValidUrl(config.getCallback(), "Valid url is required for a callback. Mail.ru does not support OOB"); if (config.hasScope()) { // Appending scope if present return String.format(SCOPED_AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()), OAuthEncoder.encode(config. @@ -48,7 +48,7 @@ public String getAuthorizationUrl(final OAuthConfig config) { } @Override - public OAuth20Service createService(final OAuthConfig config) { + public OAuth20Service createService(OAuthConfig config) { return new MailruOAuthServiceImpl(this, config); } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/MeetupApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/MeetupApi.java index 60a2de4f1..b39561022 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/MeetupApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/MeetupApi.java @@ -32,7 +32,7 @@ public String getAccessTokenEndpoint() { } @Override - public String getAuthorizationUrl(final Token requestToken) { + public String getAuthorizationUrl(Token requestToken) { return String.format(AUTHORIZE_URL, requestToken.getToken()); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/MendeleyApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/MendeleyApi.java index 2195dc4cf..b0d61a323 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/MendeleyApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/MendeleyApi.java @@ -34,7 +34,7 @@ public String getAccessTokenEndpoint() { } @Override - public String getAuthorizationUrl(final Token requestToken) { + public String getAuthorizationUrl(Token requestToken) { return String.format(AUTHORIZATION_URL, requestToken.getToken()); } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/MisoApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/MisoApi.java index b4be35dda..107a85d8e 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/MisoApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/MisoApi.java @@ -31,7 +31,7 @@ public String getRequestTokenEndpoint() { } @Override - public String getAuthorizationUrl(final Token requestToken) { + public String getAuthorizationUrl(Token requestToken) { return String.format(AUTHORIZE_URL, requestToken.getToken()); } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/NetProspexApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/NetProspexApi.java index 9c679edbb..0c84ab0b0 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/NetProspexApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/NetProspexApi.java @@ -31,7 +31,7 @@ public String getAccessTokenEndpoint() { } @Override - public String getAuthorizationUrl(final Token requestToken) { + public String getAuthorizationUrl(Token requestToken) { return String.format(AUTHORIZE_URL, requestToken.getToken()); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/NeteaseWeibooApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/NeteaseWeibooApi.java index 9a3e740bb..b1771d04f 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/NeteaseWeibooApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/NeteaseWeibooApi.java @@ -37,7 +37,7 @@ public String getAccessTokenEndpoint() { * * via http://open.t.163.com/wiki/index.php?title=%E8%AF%B7%E6%B1%82%E7%94%A8%E6%88%B7%E6%8E%88%E6%9D%83Token(oauth/authorize) */ - public String getAuthorizationUrl(final Token requestToken) { + public String getAuthorizationUrl(Token requestToken) { return String.format(AUTHORIZE_URL, requestToken.getToken()); } @@ -49,7 +49,7 @@ public String getAuthorizationUrl(final Token requestToken) { * @param requestToken Token * @return String */ - public String getAuthenticateUrl(final Token requestToken) { + public String getAuthenticateUrl(Token requestToken) { return String.format(AUTHENTICATE_URL, requestToken.getToken()); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java index b5fcbdaec..c92a6dd56 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java @@ -37,7 +37,7 @@ public Verb getAccessTokenVerb() { } @Override - public String getAuthorizationUrl(final OAuthConfig config) { + public String getAuthorizationUrl(OAuthConfig config) { Preconditions.checkValidUrl(config.getCallback(), "Valid url is required for a callback. Odnoklassniki does not support OOB"); if (config.hasScope()) { return String.format( @@ -48,7 +48,7 @@ public String getAuthorizationUrl(final OAuthConfig config) { } @Override - public OAuth20Service createService(final OAuthConfig config) { + public OAuth20Service createService(OAuthConfig config) { return new OdnoklassnikiServiceImpl(this, config); } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/PinterestApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/PinterestApi.java index 1f0032ee9..f67f986ad 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/PinterestApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/PinterestApi.java @@ -36,7 +36,7 @@ public Verb getAccessTokenVerb() { } @Override - public String getAuthorizationUrl(final OAuthConfig config) { + public String getAuthorizationUrl(OAuthConfig config) { Preconditions.checkValidUrl(config.getCallback(), "Must provide a valid url as callback. Pinterest does not support OOB"); // Append scope if present diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/PlurkApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/PlurkApi.java index c90b2afaf..344ca94de 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/PlurkApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/PlurkApi.java @@ -26,7 +26,7 @@ public String getRequestTokenEndpoint() { } @Override - public String getAuthorizationUrl(final Token requestToken) { + public String getAuthorizationUrl(Token requestToken) { return String.format(AUTHORIZATION_URL, requestToken.getToken()); } @@ -51,7 +51,7 @@ public static Mobile instance() { } @Override - public String getAuthorizationUrl(final Token requestToken) { + public String getAuthorizationUrl(Token requestToken) { return String.format(AUTHORIZATION_URL, requestToken.getToken()); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/Px500Api.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/Px500Api.java index 006ae0b3f..ab618dd84 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/Px500Api.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/Px500Api.java @@ -29,7 +29,7 @@ public String getRequestTokenEndpoint() { } @Override - public String getAuthorizationUrl(final Token requestToken) { + public String getAuthorizationUrl(Token requestToken) { return String.format(AUTHORIZATION_URL, requestToken.getToken()); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/QWeiboApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/QWeiboApi.java index 180207306..b1603dadc 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/QWeiboApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/QWeiboApi.java @@ -31,7 +31,7 @@ public String getAccessTokenEndpoint() { } @Override - public String getAuthorizationUrl(final Token requestToken) { + public String getAuthorizationUrl(Token requestToken) { return String.format(AUTHORIZE_URL, requestToken.getToken()); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/RenrenApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/RenrenApi.java index bf38bbf63..0a4545b15 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/RenrenApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/RenrenApi.java @@ -37,7 +37,7 @@ public String getAccessTokenEndpoint() { } @Override - public String getAuthorizationUrl(final OAuthConfig config) { + public String getAuthorizationUrl(OAuthConfig config) { // Append scope if present if (config.hasScope()) { return String.format(SCOPED_AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()), OAuthEncoder.encode(config. diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/SapoApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/SapoApi.java index 012493268..ec2ab6cf1 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/SapoApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/SapoApi.java @@ -32,7 +32,7 @@ public String getRequestTokenEndpoint() { } @Override - public String getAuthorizationUrl(final Token requestToken) { + public String getAuthorizationUrl(Token requestToken) { return String.format(AUTHORIZE_URL, requestToken.getToken()); } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/SimpleGeoApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/SimpleGeoApi.java index 21b9c74b4..99bfa5245 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/SimpleGeoApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/SimpleGeoApi.java @@ -32,7 +32,7 @@ public String getAccessTokenEndpoint() { } @Override - public String getAuthorizationUrl(final Token requestToken) { + public String getAuthorizationUrl(Token requestToken) { return ENDPOINT; } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/SinaWeiboApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/SinaWeiboApi.java index e9211eb93..780d562ad 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/SinaWeiboApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/SinaWeiboApi.java @@ -31,7 +31,7 @@ public String getAccessTokenEndpoint() { } @Override - public String getAuthorizationUrl(final Token requestToken) { + public String getAuthorizationUrl(Token requestToken) { return String.format(AUTHORIZE_URL, requestToken.getToken()); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/SinaWeiboApi20.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/SinaWeiboApi20.java index 5d23c5aca..be01534b2 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/SinaWeiboApi20.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/SinaWeiboApi20.java @@ -43,7 +43,7 @@ public String getAccessTokenEndpoint() { } @Override - public String getAuthorizationUrl(final OAuthConfig config) { + public String getAuthorizationUrl(OAuthConfig config) { // Append scope if present if (config.hasScope()) { return String.format(SCOPED_AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()), OAuthEncoder.encode(config. diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/SkyrockApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/SkyrockApi.java index 2c6a49c60..9f97be7dd 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/SkyrockApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/SkyrockApi.java @@ -38,7 +38,7 @@ public String getRequestTokenEndpoint() { } @Override - public String getAuthorizationUrl(final Token requestToken) { + public String getAuthorizationUrl(Token requestToken) { return String.format(API_ENDPOINT + AUTHORIZE_URL, requestToken.getToken()); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/SohuWeiboApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/SohuWeiboApi.java index 8c443da4c..1762b1186 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/SohuWeiboApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/SohuWeiboApi.java @@ -31,7 +31,7 @@ public String getAccessTokenEndpoint() { } @Override - public String getAuthorizationUrl(final Token requestToken) { + public String getAuthorizationUrl(Token requestToken) { return String.format(AUTHORIZE_URL, requestToken.getToken()); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/TrelloApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/TrelloApi.java index 97359df77..189809d5a 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/TrelloApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/TrelloApi.java @@ -29,7 +29,7 @@ public String getRequestTokenEndpoint() { } @Override - public String getAuthorizationUrl(final Token requestToken) { + public String getAuthorizationUrl(Token requestToken) { return String.format(AUTHORIZE_URL, requestToken.getToken()); } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/TumblrApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/TumblrApi.java index 8c2791891..c78d7d1c3 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/TumblrApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/TumblrApi.java @@ -31,7 +31,7 @@ public String getRequestTokenEndpoint() { } @Override - public String getAuthorizationUrl(final Token requestToken) { + public String getAuthorizationUrl(Token requestToken) { return String.format(AUTHORIZE_URL, requestToken.getToken()); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/TutByApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/TutByApi.java index b4115da30..944fdf858 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/TutByApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/TutByApi.java @@ -36,13 +36,13 @@ public Verb getAccessTokenVerb() { } @Override - public String getAuthorizationUrl(final OAuthConfig config) { + public String getAuthorizationUrl(OAuthConfig config) { Preconditions.checkValidUrl(config.getCallback(), "Valid url is required for a callback. Tut.by does not support OOB"); return String.format(AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback())); } @Override - public OAuth20Service createService(final OAuthConfig config) { + public OAuth20Service createService(OAuthConfig config) { return new TutByOAuthServiceImpl(this, config); } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/TwitterApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/TwitterApi.java index c55a55b45..7f967fd98 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/TwitterApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/TwitterApi.java @@ -31,7 +31,7 @@ public String getRequestTokenEndpoint() { } @Override - public String getAuthorizationUrl(final Token requestToken) { + public String getAuthorizationUrl(Token requestToken) { return String.format(AUTHORIZE_URL, requestToken.getToken()); } @@ -56,7 +56,7 @@ public static Authenticate instance() { } @Override - public String getAuthorizationUrl(final Token requestToken) { + public String getAuthorizationUrl(Token requestToken) { return String.format(AUTHENTICATE_URL, requestToken.getToken()); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/UbuntuOneApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/UbuntuOneApi.java index e2bbbfaf3..aa4f820f2 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/UbuntuOneApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/UbuntuOneApi.java @@ -31,7 +31,7 @@ public String getAccessTokenEndpoint() { } @Override - public String getAuthorizationUrl(final Token requestToken) { + public String getAuthorizationUrl(Token requestToken) { return String.format(AUTHORIZATION_URL, requestToken.getToken()); } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/ViadeoApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/ViadeoApi.java index 3e9c07e23..a3f50bf30 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/ViadeoApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/ViadeoApi.java @@ -35,7 +35,7 @@ public String getAccessTokenEndpoint() { } @Override - public String getAuthorizationUrl(final OAuthConfig config) { + public String getAuthorizationUrl(OAuthConfig config) { Preconditions.checkValidUrl(config.getCallback(), "Must provide a valid url as callback. Viadeo does not support OOB"); // Append scope if present diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/VimeoApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/VimeoApi.java index ed753efec..d3223c70a 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/VimeoApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/VimeoApi.java @@ -29,7 +29,7 @@ public String getRequestTokenEndpoint() { } @Override - public String getAuthorizationUrl(final Token requestToken) { + public String getAuthorizationUrl(Token requestToken) { return String.format(AUTHORIZATION_URL, requestToken.getToken()); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/VkontakteApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/VkontakteApi.java index 862dbd6a0..8f6ae8764 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/VkontakteApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/VkontakteApi.java @@ -33,7 +33,7 @@ public String getAccessTokenEndpoint() { } @Override - public String getAuthorizationUrl(final OAuthConfig config) { + public String getAuthorizationUrl(OAuthConfig config) { Preconditions.checkValidUrl(config.getCallback(), "Valid url is required for a callback. Vkontakte does not support OOB"); if (config.hasScope()) { // Appending scope if present return String.format( diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/XingApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/XingApi.java index 30f70b4f1..a87ccb55f 100755 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/XingApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/XingApi.java @@ -29,7 +29,7 @@ public String getRequestTokenEndpoint() { } @Override - public String getAuthorizationUrl(final Token requestToken) { + public String getAuthorizationUrl(Token requestToken) { return String.format(AUTHORIZE_URL, requestToken.getToken()); } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/YahooApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/YahooApi.java index ff79f232b..2e9403da8 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/YahooApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/YahooApi.java @@ -29,7 +29,7 @@ public String getRequestTokenEndpoint() { } @Override - public String getAuthorizationUrl(final Token requestToken) { + public String getAuthorizationUrl(Token requestToken) { return String.format(AUTHORIZE_URL, requestToken.getToken()); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/YammerApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/YammerApi.java index 0d561b1c6..9dfa0b171 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/YammerApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/YammerApi.java @@ -31,7 +31,7 @@ public String getAccessTokenEndpoint() { } @Override - public String getAuthorizationUrl(final Token requestToken) { + public String getAuthorizationUrl(Token requestToken) { return String.format(AUTHORIZATION_URL, requestToken.getToken()); } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/google/GoogleJsonTokenExtractor.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/google/GoogleJsonTokenExtractor.java index 7c8a326c4..9b54e022e 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/google/GoogleJsonTokenExtractor.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/google/GoogleJsonTokenExtractor.java @@ -12,11 +12,11 @@ public class GoogleJsonTokenExtractor extends JsonTokenExtractor { private static final Pattern ID_TOKEN_PATTERN = Pattern.compile("\"id_token\"\\s*:\\s*\"(\\S*?)\""); @Override - public GoogleToken extract(final String response) { + public GoogleToken extract(String response) { return new GoogleToken(extractAccessToken(response), "", response, extractOpenIdToken(response)); } - private String extractOpenIdToken(final String response) { + private String extractOpenIdToken(String response) { final Matcher matcher = ID_TOKEN_PATTERN.matcher(response); if (matcher.find()) { return matcher.group(1); diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/google/GoogleToken.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/google/GoogleToken.java index a421f070e..7605b60b9 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/google/GoogleToken.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/google/GoogleToken.java @@ -13,7 +13,7 @@ public class GoogleToken extends Token { */ private final String openIdToken; - public GoogleToken(final String token, final String secret, final String rawResponse, final String openIdToken) { + public GoogleToken(String token, String secret, String rawResponse, String openIdToken) { super(token, secret, rawResponse); this.openIdToken = openIdToken; } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/DoktornaraboteOAuthServiceImpl.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/DoktornaraboteOAuthServiceImpl.java index 7a7605853..afa9882a2 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/DoktornaraboteOAuthServiceImpl.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/DoktornaraboteOAuthServiceImpl.java @@ -8,12 +8,12 @@ public class DoktornaraboteOAuthServiceImpl extends OAuth20Service { - public DoktornaraboteOAuthServiceImpl(final DefaultApi20 api, final OAuthConfig config) { + public DoktornaraboteOAuthServiceImpl(DefaultApi20 api, OAuthConfig config) { super(api, config); } @Override - public void signRequest(final Token accessToken, final AbstractRequest request) { + public void signRequest(Token accessToken, AbstractRequest request) { request.addHeader("Authorization", "Bearer " + accessToken.getToken()); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/GoogleOAuthServiceImpl.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/GoogleOAuthServiceImpl.java index 72ea62fa2..44fc434a2 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/GoogleOAuthServiceImpl.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/GoogleOAuthServiceImpl.java @@ -9,12 +9,12 @@ public class GoogleOAuthServiceImpl extends OAuth20Service { - public GoogleOAuthServiceImpl(final DefaultApi20 api, final OAuthConfig config) { + public GoogleOAuthServiceImpl(DefaultApi20 api, OAuthConfig config) { super(api, config); } @Override - protected T createAccessTokenRequest(final Verifier verifier, final T request) { + protected T createAccessTokenRequest(Verifier verifier, T request) { super.createAccessTokenRequest(verifier, request); if (!getConfig().hasGrantType()) { request.addParameter(OAuthConstants.GRANT_TYPE, "authorization_code"); diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/HHOAuthServiceImpl.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/HHOAuthServiceImpl.java index 5ca5349b9..725f015be 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/HHOAuthServiceImpl.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/HHOAuthServiceImpl.java @@ -8,12 +8,12 @@ public class HHOAuthServiceImpl extends OAuth20Service { - public HHOAuthServiceImpl(final DefaultApi20 api, final OAuthConfig config) { + public HHOAuthServiceImpl(DefaultApi20 api, OAuthConfig config) { super(api, config); } @Override - public void signRequest(final Token accessToken, final AbstractRequest request) { + public void signRequest(Token accessToken, AbstractRequest request) { request.addHeader("Authorization", "Bearer " + accessToken.getToken()); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthServiceImpl.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthServiceImpl.java index 16f535fb9..969c3a517 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthServiceImpl.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthServiceImpl.java @@ -12,12 +12,12 @@ public class ImgurOAuthServiceImpl extends OAuth20Service { - public ImgurOAuthServiceImpl(final DefaultApi20 api, final OAuthConfig config) { + public ImgurOAuthServiceImpl(DefaultApi20 api, OAuthConfig config) { super(api, config); } @Override - public Token getAccessToken(final Token requestToken, final Verifier verifier) { + public Token getAccessToken(Token requestToken, Verifier verifier) { final OAuthRequest request = new OAuthRequest(getApi().getAccessTokenVerb(), getApi().getAccessTokenEndpoint(), this); request.addBodyParameter(OAuthConstants.CLIENT_ID, getConfig().getApiKey()); @@ -35,7 +35,7 @@ public Token getAccessToken(final Token requestToken, final Verifier verifier) { } @Override - public void signRequest(final Token accessToken, final AbstractRequest request) { + public void signRequest(Token accessToken, AbstractRequest request) { request.addHeader("Authorization", accessToken == null ? "Client-ID " + getConfig().getApiKey() : "Bearer " + accessToken.getToken()); } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/LinkedIn20ServiceImpl.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/LinkedIn20ServiceImpl.java index 9d1514dc2..efaf148c4 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/LinkedIn20ServiceImpl.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/LinkedIn20ServiceImpl.java @@ -10,17 +10,17 @@ public class LinkedIn20ServiceImpl extends OAuth20Service { - public LinkedIn20ServiceImpl(final DefaultApi20 api, final OAuthConfig config) { + public LinkedIn20ServiceImpl(DefaultApi20 api, OAuthConfig config) { super(api, config); } @Override - public void signRequest(final Token accessToken, final AbstractRequest request) { + public void signRequest(Token accessToken, AbstractRequest request) { request.addQuerystringParameter("oauth2_access_token", accessToken.getToken()); } @Override - protected T createAccessTokenRequest(final Verifier verifier, final T request) { + protected T createAccessTokenRequest(Verifier verifier, T request) { super.createAccessTokenRequest(verifier, request); if (!getConfig().hasGrantType()) { request.addParameter(OAuthConstants.GRANT_TYPE, "authorization_code"); diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthServiceImpl.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthServiceImpl.java index cb9af537f..2be9ee7d1 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthServiceImpl.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthServiceImpl.java @@ -16,12 +16,12 @@ public class MailruOAuthServiceImpl extends OAuth20Service { - public MailruOAuthServiceImpl(final DefaultApi20 api, final OAuthConfig config) { + public MailruOAuthServiceImpl(DefaultApi20 api, OAuthConfig config) { super(api, config); } @Override - public void signRequest(final Token accessToken, final AbstractRequest request) { + public void signRequest(Token accessToken, AbstractRequest request) { // sig = md5(params + secret_key) request.addQuerystringParameter("session_key", accessToken.getToken()); request.addQuerystringParameter("app_id", getConfig().getApiKey()); @@ -33,12 +33,12 @@ public void signRequest(final Token accessToken, final AbstractRequest request) if (queryIndex != -1) { final String urlPart = completeUrl.substring(queryIndex + 1); final Map map = new TreeMap<>(); - for (final String param : urlPart.split("&")) { + for (String param : urlPart.split("&")) { final String[] parts = param.split("="); map.put(parts[0], (parts.length == 1) ? "" : parts[1]); } final StringBuilder urlNew = new StringBuilder(); - for (final Map.Entry entry : map.entrySet()) { + for (Map.Entry entry : map.entrySet()) { urlNew.append(entry.getKey()); urlNew.append('='); urlNew.append(entry.getValue()); @@ -52,7 +52,7 @@ public void signRequest(final Token accessToken, final AbstractRequest request) } @Override - protected T createAccessTokenRequest(final Verifier verifier, final T request) { + protected T createAccessTokenRequest(Verifier verifier, T request) { super.createAccessTokenRequest(verifier, request); if (!getConfig().hasGrantType()) { request.addParameter(OAuthConstants.GRANT_TYPE, "authorization_code"); diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiServiceImpl.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiServiceImpl.java index e247252bd..eea23a9f2 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiServiceImpl.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiServiceImpl.java @@ -12,12 +12,12 @@ public class OdnoklassnikiServiceImpl extends OAuth20Service { - public OdnoklassnikiServiceImpl(final DefaultApi20 api, final OAuthConfig config) { + public OdnoklassnikiServiceImpl(DefaultApi20 api, OAuthConfig config) { super(api, config); } @Override - public void signRequest(final Token accessToken, final AbstractRequest request) { + public void signRequest(Token accessToken, AbstractRequest request) { // sig = md5( request_params_composed_string+ md5(access_token + application_secret_key) ) try { final String tokenDigest = md5Hex((accessToken.getToken() + getConfig().getApiSecret())); diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/TutByOAuthServiceImpl.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/TutByOAuthServiceImpl.java index bb9f367c5..f0958ace1 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/TutByOAuthServiceImpl.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/TutByOAuthServiceImpl.java @@ -9,12 +9,12 @@ public class TutByOAuthServiceImpl extends OAuth20Service { - public TutByOAuthServiceImpl(final DefaultApi20 api, final OAuthConfig config) { + public TutByOAuthServiceImpl(DefaultApi20 api, OAuthConfig config) { super(api, config); } @Override - public void signRequest(final Token accessToken, final AbstractRequest request) { + public void signRequest(Token accessToken, AbstractRequest request) { request.addQuerystringParameter(OAuthConstants.TOKEN, accessToken.getToken()); } diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AWeberExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AWeberExample.java index 2e0583a52..daf08eb74 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AWeberExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AWeberExample.java @@ -18,7 +18,7 @@ public abstract class AWeberExample { private static final String CONSUMER_KEY = ""; private static final String CONSUMER_SECRET = ""; - public static void main(final String... args) { + public static void main(String... args) { final OAuthService service = new ServiceBuilder() .apiKey(CONSUMER_KEY) .apiSecret(CONSUMER_SECRET) diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiggExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiggExample.java index b068c1844..8ca630dab 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiggExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiggExample.java @@ -15,7 +15,7 @@ public abstract class DiggExample { private static final String NETWORK_NAME = "Digg"; private static final String PROTECTED_RESOURCE_URL = "http://services.digg.com/2.0/comment.digg"; - public static void main(final String... args) { + public static void main(String... args) { // Replace these with your own api key and secret final String apiKey = "myKey"; final String apiSecret = "mySecret"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncExample.java index 5f08559be..17fdd0892 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncExample.java @@ -21,7 +21,7 @@ public abstract class FacebookAsyncExample { private static final String PROTECTED_RESOURCE_URL = "https://graph.facebook.com/v2.2/me"; private static final Token EMPTY_TOKEN = null; - public static void main(final String... args) throws InterruptedException, ExecutionException { + public static void main(String... args) throws InterruptedException, ExecutionException { // Replace these with your client id and secret final String clientId = "your client id"; final String clientSecret = "your client secret"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java index f0616e43c..c3604db75 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java @@ -17,7 +17,7 @@ public abstract class FacebookExample { private static final String PROTECTED_RESOURCE_URL = "https://graph.facebook.com/v2.2/me"; private static final Token EMPTY_TOKEN = null; - public static void main(final String... args) { + public static void main(String... args) { // Replace these with your client id and secret final String clientId = "your client id"; final String clientSecret = "your client secret"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExample.java index 26314e442..b7afa9128 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExample.java @@ -14,7 +14,7 @@ public abstract class FlickrExample { private static final String PROTECTED_RESOURCE_URL = "http://api.flickr.com/services/rest/"; - public static void main(final String... args) { + public static void main(String... args) { // Replace these with your own api key and secret final String apiKey = "your_app_id"; final String apiSecret = "your_api_secret"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java index 9b7579ee1..c8041fdeb 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java @@ -15,7 +15,7 @@ public abstract class Foursquare2Example { private static final String PROTECTED_RESOURCE_URL = "https://api.foursquare.com/v2/users/self/friends?oauth_token="; private static final Token EMPTY_TOKEN = null; - public static void main(final String... args) { + public static void main(String... args) { // Replace these with your own api key and secret final String apiKey = "your client id"; final String apiSecret = "your client secret"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FoursquareExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FoursquareExample.java index 8b0001146..3d894be45 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FoursquareExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FoursquareExample.java @@ -14,7 +14,7 @@ public abstract class FoursquareExample { private static final String PROTECTED_RESOURCE_URL = "http://api.foursquare.com/v1/user"; - public static void main(final String... args) { + public static void main(String... args) { final OAuthService service = new ServiceBuilder() .apiKey("your client id") .apiSecret("your client secret") diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java index c7255b7cd..c05e2611a 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java @@ -19,7 +19,7 @@ public abstract class FreelancerExample { private static final String PROTECTED_RESOURCE_URL = "http://api.sandbox.freelancer.com/Job/getJobList.json"; private static final String SCOPE = "http://api.sandbox.freelancer.com"; - public static void main(final String... args) { + public static void main(String... args) { final OAuthService service = new ServiceBuilder() .signatureType(SignatureType.QueryString) .apiKey("your client id") diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubExample.java index 49419e7ec..cbc659b4b 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubExample.java @@ -17,7 +17,7 @@ public abstract class GitHubExample { private static final String PROTECTED_RESOURCE_URL = "https://api.github.com/user"; private static final Token EMPTY_TOKEN = null; - public static void main(final String... args) { + public static void main(String... args) { // Replace these with your client id and secret final String clientId = "your client id"; final String clientSecret = "your client secret"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java index 585f8ff47..5df67d9a4 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java @@ -17,7 +17,7 @@ public abstract class Google20Example { private static final String PROTECTED_RESOURCE_URL = "https://www.googleapis.com/plus/v1/people/me"; private static final Token EMPTY_TOKEN = null; - public static void main(final String... args) { + public static void main(String... args) { // Replace these with your client id and secret final String clientId = "your client id"; final String clientSecret = "your client secret"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GoogleExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GoogleExample.java index 2aa94a885..c21721c83 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GoogleExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GoogleExample.java @@ -17,7 +17,7 @@ public abstract class GoogleExample { private static final String PROTECTED_RESOURCE_URL = "https://docs.google.com/feeds/default/private/full/"; private static final String SCOPE = "https://docs.google.com/feeds/"; - public static void main(final String... args) { + public static void main(String... args) { final OAuthService service = new ServiceBuilder() .apiKey("anonymous") .apiSecret("anonymous") diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HHExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HHExample.java index 01db186fc..6b243b2de 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HHExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HHExample.java @@ -18,7 +18,7 @@ public abstract class HHExample { private static final String PROTECTED_RESOURCE_URL = "https://api.hh.ru/me"; private static final Token EMPTY_TOKEN = null; - public static void main(final String... args) { + public static void main(String... args) { // Replace these with your own client id and secret final String clientId = "your client id"; final String clientSecret = "your client secret"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ImgurExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ImgurExample.java index ab61cad44..6c384ac4f 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ImgurExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ImgurExample.java @@ -16,7 +16,7 @@ public abstract class ImgurExample { private static final String NETWORK_NAME = "Imgur"; private static final String PROTECTED_RESOURCE_URL = "https://api.imgur.com/3/account/me"; - public static void main(final String... args) { + public static void main(String... args) { // Replace these with your own api key and secret final String apiKey = "your client id"; final String apiSecret = "your client secret"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Kaixin20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Kaixin20Example.java index f1cb925a6..fe67d93e1 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Kaixin20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Kaixin20Example.java @@ -16,7 +16,7 @@ public abstract class Kaixin20Example { private static final String PROTECTED_RESOURCE_URL = "https://api.kaixin001.com/users/me.json"; private static final Token EMPTY_TOKEN = null; - public static void main(final String... args) { + public static void main(String... args) { // Replace these with your own api key and secret final String apiKey = "your api key"; final String apiSecret = "your api secret"; 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 cbb645183..50be9536c 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 @@ -16,7 +16,7 @@ public abstract class LinkedIn20Example { private static final String PROTECTED_RESOURCE_URL = "https://api.linkedin.com/v1/people/~:(%s)"; private static final Token EMPTY_TOKEN = null; - public static void main(final String... args) { + public static void main(String... args) { // Replace these with your client id and secret final String clientId = "your client id"; final String clientSecret = "your client secret"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java index d50144c5a..6c8069f1d 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java @@ -15,7 +15,7 @@ public abstract class LinkedInExample { private static final String PROTECTED_RESOURCE_URL = "http://api.linkedin.com/v1/people/~/connections:(id,last-name)"; - public static void main(final String... args) { + public static void main(String... args) { final OAuthService service = new ServiceBuilder() .apiKey("your client id") .apiSecret("your client secret") diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java index 3d2f4d7fb..97291554c 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java @@ -15,7 +15,7 @@ public abstract class LinkedInExampleWithScopes { private static final String PROTECTED_RESOURCE_URL = "http://api.linkedin.com/v1/people/~/connections:(id,last-name)"; - public static void main(final String... args) { + public static void main(String... args) { // Replace these with your client id and secret final String clientId = "your client id"; final String clientSecret = "your client id"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java index 573ca8cc7..97ea7027c 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java @@ -15,7 +15,7 @@ public abstract class LiveExample { private static final String PROTECTED_RESOURCE_URL = "https://api.foursquare.com/v2/users/self/friends?oauth_token="; private static final Token EMPTY_TOKEN = null; - public static void main(final String... args) { + public static void main(String... args) { // Replace these with your own api key and secret final String apiKey = ""; final String apiSecret = ""; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LoveFilmExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LoveFilmExample.java index 5416d0e54..77ff89061 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LoveFilmExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LoveFilmExample.java @@ -15,7 +15,7 @@ public abstract class LoveFilmExample { private static final String NETWORK_NAME = "LoveFilm"; private static final String PROTECTED_RESOURCE_URL = "https://api.lovefilm.com/users"; - public static void main(final String... args) { + public static void main(String... args) { // Replace these with your own api key and secret final String apiKey = "your_key"; final String apiSecret = "your_secret"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java index ceaa99894..3f00ed82a 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java @@ -18,7 +18,7 @@ public abstract class MailruAsyncExample { private static final String PROTECTED_RESOURCE_URL = "http://www.appsmail.ru/platform/api?method=users.getInfo&secure=1"; private static final Token EMPTY_TOKEN = null; - public static void main(final String... args) throws InterruptedException, ExecutionException { + public static void main(String... args) throws InterruptedException, ExecutionException { // Replace these with your client id and secret final String clientId = "your client id"; final String clientSecret = "your client secret"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java index fe1409145..a3fdbde19 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java @@ -16,7 +16,7 @@ public abstract class MailruExample { private static final String PROTECTED_RESOURCE_URL = "http://www.appsmail.ru/platform/api?method=users.getInfo&secure=1"; private static final Token EMPTY_TOKEN = null; - public static void main(final String... args) { + public static void main(String... args) { // Replace these with your client id and secret final String clientId = "your client id"; final String clientSecret = "your client secret"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java index be096c1c9..477c2f5f3 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java @@ -14,7 +14,7 @@ public abstract class MeetupExample { private static final String PROTECTED_RESOURCE_URL = "http://api.meetup.com/2/member/self"; - public static void main(final String... args) { + public static void main(String... args) { final OAuthService service = new ServiceBuilder() .apiKey("your client id") .apiSecret("your client secret") diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NeteaseWeiboExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NeteaseWeiboExample.java index aa6621444..53bcf34ab 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NeteaseWeiboExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NeteaseWeiboExample.java @@ -15,7 +15,7 @@ public abstract class NeteaseWeiboExample { private static final String NETWORK_NAME = "NetEase(163.com) Weibo"; private static final String PROTECTED_RESOURCE_URL = "http://api.t.163.com/account/verify_credentials.json"; - public static void main(final String... args) { + public static void main(String... args) { // Replace these with your own api key and secret final String apiKey = "your key"; final String apiSecret = "your secret"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java index 05bc0808a..462cf272d 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java @@ -17,7 +17,7 @@ public abstract class OdnoklassnikiExample { = "http://api.odnoklassniki.ru/api/users/getCurrentUser?application_key=%1$s&format=JSON"; private static final Token EMPTY_TOKEN = null; - public static void main(final String... args) { + public static void main(String... args) { // Replace these with your client id and secret final String clientId = "your client id"; final String publicKey = "your api secret"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java index e3b19eba0..adac7e668 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java @@ -16,7 +16,7 @@ public abstract class PinterestExample { private static final String PROTECTED_RESOURCE_URL = "https://api.pinterest.com/v1/me/?access_token?access_token="; private static final Token EMPTY_TOKEN = null; - public static void main(final String... args) { + public static void main(String... args) { // Replace these with your own api key and secret final String apiKey = "your_app_id"; final String apiSecret = "your_app_secret"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Px500Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Px500Example.java index c6cff4603..893182013 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Px500Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Px500Example.java @@ -14,7 +14,7 @@ public abstract class Px500Example { private static final String PROTECTED_RESOURCE_URL = "https://api.500px.com/v1/"; - public static void main(final String... args) { + public static void main(String... args) { final OAuthService service = new ServiceBuilder() .apiKey("your-api-key") .apiSecret("your-api-secret") diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java index a29e745b4..404a1219a 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java @@ -25,7 +25,7 @@ public abstract class RenrenExample { private static final String PROTECTED_RESOURCE_URL = "http://api.renren.com/restserver.do"; private static final Token EMPTY_TOKEN = null; - public static void main(final String... args) { + public static void main(String... args) { // Replace these with your own api key and secret final String apiKey = "your api key"; final String apiSecret = "your api secret"; @@ -67,14 +67,14 @@ public static void main(final String... args) { parameters.put("v", "1.0"); final List sigString = new ArrayList<>(parameters.size() + 1); - for (final Map.Entry entry : parameters.entrySet()) { + for (Map.Entry entry : parameters.entrySet()) { request.addQuerystringParameter(entry.getKey(), entry.getValue()); sigString.add(String.format("%s=%s", entry.getKey(), entry.getValue())); } sigString.add(String.format("%s=%s", OAuthConstants.ACCESS_TOKEN, accessToken.getToken())); Collections.sort(sigString); final StringBuilder b = new StringBuilder(); - for (final String param : sigString) { + for (String param : sigString) { b.append(param); } b.append(apiSecret); @@ -92,7 +92,7 @@ public static void main(final String... args) { } - public static String md5(final String orgString) { + public static String md5(String orgString) { try { final MessageDigest md = MessageDigest.getInstance("MD5"); final byte[] array = md.digest(orgString.getBytes(Charset.forName("UTF-8"))); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeibo2Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeibo2Example.java index f9c0ba086..1e9a8f65d 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeibo2Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeibo2Example.java @@ -16,7 +16,7 @@ public abstract class SinaWeibo2Example { private static final String PROTECTED_RESOURCE_URL = "https://api.weibo.com/2/account/get_uid.json"; private static final Token EMPTY_TOKEN = null; - public static void main(final String... args) { + public static void main(String... args) { // Replace these with your own api key and secret final String apiKey = "your_api_key"; final String apiSecret = "your_api_secret"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeiboExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeiboExample.java index 1810a7d10..f7b9f091c 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeiboExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeiboExample.java @@ -15,7 +15,7 @@ public abstract class SinaWeiboExample { private static final String NETWORK_NAME = "SinaWeibo"; private static final String PROTECTED_RESOURCE_URL = "http://api.t.sina.com.cn/account/verify_credentials.json"; - public static void main(final String... args) { + public static void main(String... args) { // Replace these with your own api key and secret final String apiKey = "your key"; final String apiSecret = "your secret"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SkyrockExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SkyrockExample.java index 162d0acc9..bcd2e2b1f 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SkyrockExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SkyrockExample.java @@ -14,7 +14,7 @@ public abstract class SkyrockExample { private static final String PROTECTED_RESOURCE_URL = "https://api.skyrock.com/v2/user/get.json"; - public static void main(final String... args) { + public static void main(String... args) { final OAuthService service = new ServiceBuilder() .apiKey("your-api-key") .apiSecret("your-api-secret") diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SohuWeiboExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SohuWeiboExample.java index 6b437fc7c..8860a89ba 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SohuWeiboExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SohuWeiboExample.java @@ -15,7 +15,7 @@ public abstract class SohuWeiboExample { private static final String NETWORK_NAME = "SohuWeibo"; private static final String PROTECTED_RESOURCE_URL = "http://api.t.sohu.com/account/verify_credentials.json"; - public static void main(final String... args) { + public static void main(String... args) { // Replace these with your own api key and secret final String apiKey = "your_key"; final String apiSecret = "your_secret"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TrelloExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TrelloExample.java index 902ad4329..ad151bfec 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TrelloExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TrelloExample.java @@ -16,7 +16,7 @@ public abstract class TrelloExample { private static final String API_SECRET = "your_api_secret"; private static final String PROTECTED_RESOURCE_URL = "https://trello.com/1/members/me"; - public static void main(final String... args) { + public static void main(String... args) { final OAuthService service = new ServiceBuilder() .apiKey(API_KEY) .apiSecret(API_SECRET) diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TumblrExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TumblrExample.java index 4e4584301..04c58ed2c 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TumblrExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TumblrExample.java @@ -14,7 +14,7 @@ public abstract class TumblrExample { private static final String PROTECTED_RESOURCE_URL = "http://api.tumblr.com/v2/user/info"; - public static void main(final String... args) { + public static void main(String... args) { final OAuthService service = new ServiceBuilder() .apiKey("MY_CONSUMER_KEY") .apiSecret("MY_CONSUMER_SECRET") diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TutByExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TutByExample.java index 6a6e96cc0..fd8dcb448 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TutByExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TutByExample.java @@ -19,7 +19,7 @@ public abstract class TutByExample { private static final String PROTECTED_RESOURCE_URL = "http://profile.tut.by/getInfo"; private static final Token EMPTY_TOKEN = null; - public static void main(final String... args) { + public static void main(String... args) { // Replace these with your client id and secret final String clientId = "your client id"; final String clientSecret = "your client secret"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TwitterExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TwitterExample.java index 67a862ae0..ec34bf421 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TwitterExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TwitterExample.java @@ -14,7 +14,7 @@ public abstract class TwitterExample { private static final String PROTECTED_RESOURCE_URL = "https://api.twitter.com/1.1/account/verify_credentials.json"; - public static void main(final String... args) { + public static void main(String... args) { final OAuthService service = new ServiceBuilder() .apiKey("your client id") .apiSecret("your client secret") diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ViadeoExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ViadeoExample.java index f6362db46..3fb315198 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ViadeoExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ViadeoExample.java @@ -16,7 +16,7 @@ public abstract class ViadeoExample { private static final String PROTECTED_RESOURCE_URL = "https://api.viadeo.com/me?user_detail=full"; private static final Token EMPTY_TOKEN = null; - public static void main(final String... args) { + public static void main(String... args) { // Replace these with your own api key and secret final String apiKey = "your_app_id"; final String apiSecret = "your_api_secret"; 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 4e0fe25b8..a3c0f5065 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 @@ -20,7 +20,7 @@ public abstract class VkontakteExample { private static final String PROTECTED_RESOURCE_URL = "https://api.vk.com/method/friends.get"; private static final Token EMPTY_TOKEN = null; - public static void main(final String... args) { + public static void main(String... args) { // Replace these with your client id and secret final String clientId = "your client id"; final String clientSecret = "your client secret"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XingExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XingExample.java index 9dda20499..ffbadce53 100755 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XingExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XingExample.java @@ -14,7 +14,7 @@ public abstract class XingExample { private static final String PROTECTED_RESOURCE_URL = "https://api.xing.com/v1/users/me"; - public static void main(final String... args) { + public static void main(String... args) { final OAuthService service = new ServiceBuilder() .apiKey("your client id") .apiSecret("your client secret") diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/YahooExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/YahooExample.java index 653b24a7d..8c999ccc1 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/YahooExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/YahooExample.java @@ -15,7 +15,7 @@ public abstract class YahooExample { private static final String PROTECTED_RESOURCE_URL = "http://social.yahooapis.com/v1/user/A6ROU63MXWDCW3Y5MGCYWVHDJI/profile/status?format=json"; - public static void main(final String... args) { + public static void main(String... args) { final OAuthService service = new ServiceBuilder() .apiKey("your client id") .apiSecret("your client secret") diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/AbstractServiceBuilder.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/AbstractServiceBuilder.java index 740a053ad..7d24f5223 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/AbstractServiceBuilder.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/AbstractServiceBuilder.java @@ -32,7 +32,7 @@ abstract class AbstractServiceBuilder { * @param callback callback url. Must be a valid url or 'oob' for out of band OAuth * @return the {@link ServiceBuilder} instance for method chaining */ - public T callback(final String callback) { + public T callback(String callback) { Preconditions.checkNotNull(callback, "Callback can't be null"); this.callback = callback; return (T) this; @@ -44,7 +44,7 @@ public T callback(final String callback) { * @param apiKey The api key for your application * @return the {@link ServiceBuilder} instance for method chaining */ - public T apiKey(final String apiKey) { + public T apiKey(String apiKey) { Preconditions.checkEmptyString(apiKey, "Invalid Api key"); this.apiKey = apiKey; return (T) this; @@ -56,7 +56,7 @@ public T apiKey(final String apiKey) { * @param apiSecret The api secret for your application * @return the {@link ServiceBuilder} instance for method chaining */ - public T apiSecret(final String apiSecret) { + public T apiSecret(String apiSecret) { Preconditions.checkEmptyString(apiSecret, "Invalid Api secret"); this.apiSecret = apiSecret; return (T) this; @@ -68,7 +68,7 @@ public T apiSecret(final String apiSecret) { * @param scope The OAuth scope * @return the {@link ServiceBuilder} instance for method chaining */ - public T scope(final String scope) { + public T scope(String scope) { Preconditions.checkEmptyString(scope, "Invalid OAuth scope"); this.scope = scope; return (T) this; @@ -80,7 +80,7 @@ public T scope(final String scope) { * @param state The OAuth state * @return the {@link ServiceBuilder} instance for method chaining */ - public T state(final String state) { + public T state(String state) { Preconditions.checkEmptyString(state, "Invalid OAuth state"); this.state = state; return (T) this; @@ -92,19 +92,19 @@ public T state(final String state) { * @param type SignatureType * @return the {@link ServiceBuilder} instance for method chaining */ - public T signatureType(final SignatureType type) { + public T signatureType(SignatureType type) { Preconditions.checkNotNull(type, "Signature type can't be null"); this.signatureType = type; return (T) this; } - public T debugStream(final OutputStream stream) { + public T debugStream(OutputStream stream) { Preconditions.checkNotNull(stream, "debug stream can't be null"); this.debugStream = stream; return (T) this; } - public T grantType(final String grantType) { + public T grantType(String grantType) { Preconditions.checkEmptyString(grantType, "Invalid OAuth grantType"); this.grantType = grantType; return (T) this; @@ -160,7 +160,7 @@ public String getGrantType() { * @param api will build Service for this API * @return fully configured {@link OAuth10aService} */ - public OAuth10aService build(final DefaultApi10a api) { + public OAuth10aService build(DefaultApi10a api) { return api.createService(createConfig()); } @@ -170,7 +170,7 @@ public OAuth10aService build(final DefaultApi10a api) { * @param api will build Service for this API * @return fully configured {@link OAuth20Service} */ - public OAuth20Service build(final DefaultApi20 api) { + public OAuth20Service build(DefaultApi20 api) { return api.createService(createConfig()); } } 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 dd5c9ff98..1a32cfcff 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilder.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilder.java @@ -14,13 +14,13 @@ public class ServiceBuilder extends AbstractServiceBuilder { private Integer connectTimeout; private Integer readTimeout; - public ServiceBuilder connectTimeout(final Integer connectTimeout) { + public ServiceBuilder connectTimeout(Integer connectTimeout) { Preconditions.checkNotNull(connectTimeout, "Connection timeout can't be null"); this.connectTimeout = connectTimeout; return this; } - public ServiceBuilder readTimeout(final Integer readTimeout) { + public ServiceBuilder readTimeout(Integer readTimeout) { Preconditions.checkNotNull(readTimeout, "Read timeout can't be null"); this.readTimeout = readTimeout; return this; diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilderAsync.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilderAsync.java index 186674166..2394f3f1b 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilderAsync.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilderAsync.java @@ -9,7 +9,7 @@ public class ServiceBuilderAsync extends AbstractServiceBuilder parameters = request.getOauthParameters(); final StringBuilder header = new StringBuilder(parameters.size() * ESTIMATED_PARAM_LENGTH); header.append(PREAMBLE); - for (final Map.Entry entry : parameters.entrySet()) { + for (Map.Entry entry : parameters.entrySet()) { if (header.length() > PREAMBLE.length()) { header.append(PARAM_SEPARATOR); } @@ -43,7 +43,7 @@ public String extract(final AbstractRequest request) { return header.toString(); } - private void checkPreconditions(final AbstractRequest request) { + private void checkPreconditions(AbstractRequest request) { Preconditions.checkNotNull(request, "Cannot extract a header from a null object"); if (request.getOauthParameters() == null || request.getOauthParameters().size() <= 0) { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/JsonTokenExtractor.java b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/JsonTokenExtractor.java index e1854f1d0..b43e89f49 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/JsonTokenExtractor.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/JsonTokenExtractor.java @@ -11,11 +11,11 @@ public class JsonTokenExtractor implements AccessTokenExtractor { private static final Pattern ACCESS_TOKEN_PATTERN = Pattern.compile("\"access_token\"\\s*:\\s*\"(\\S*?)\""); @Override - public Token extract(final String response) { + public Token extract(String response) { return new Token(extractAccessToken(response), "", response); } - protected String extractAccessToken(final String response) { + protected String extractAccessToken(String response) { Preconditions.checkEmptyString(response, "Cannot extract a token from a null or empty String"); final Matcher matcher = ACCESS_TOKEN_PATTERN.matcher(response); if (matcher.find()) { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/TokenExtractor20Impl.java b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/TokenExtractor20Impl.java index 23d5dd1fc..3b8a2be2b 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/TokenExtractor20Impl.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/TokenExtractor20Impl.java @@ -20,7 +20,7 @@ public class TokenExtractor20Impl implements AccessTokenExtractor { * {@inheritDoc} */ @Override - public Token extract(final String response) { + public Token extract(String response) { Preconditions.checkEmptyString(response, "Response body is incorrect. Can't extract a token from an empty string"); diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/TokenExtractorImpl.java b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/TokenExtractorImpl.java index 62b630dc1..3494e5eb3 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/TokenExtractorImpl.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/TokenExtractorImpl.java @@ -23,7 +23,7 @@ public class TokenExtractorImpl implements RequestTokenExtractor, AccessTokenExt * {@inheritDoc} */ @Override - public Token extract(final String response) { + public Token extract(String response) { Preconditions.checkEmptyString(response, "Response body is incorrect. Can't extract a token from an empty string"); final String token = extract(response, TOKEN_REGEX); @@ -31,7 +31,7 @@ public Token extract(final String response) { return new Token(token, secret, response); } - private String extract(final String response, final Pattern p) { + private String extract(String response, Pattern p) { final Matcher matcher = p.matcher(response); if (matcher.find() && matcher.groupCount() >= 1) { return OAuthEncoder.decode(matcher.group(1)); diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/AbstractRequest.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/AbstractRequest.java index bf893f926..928ad0573 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/AbstractRequest.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/AbstractRequest.java @@ -44,7 +44,7 @@ public abstract class AbstractRequest { * @param url resource URL * @param service OAuthService */ - public AbstractRequest(final Verb verb, final String url, final OAuthService service) { + public AbstractRequest(Verb verb, String url, OAuthService service) { this.verb = verb; this.url = url; this.service = service; @@ -57,11 +57,11 @@ public AbstractRequest(final Verb verb, final String url, final OAuthService ser * @param value value of the parameter * @throws IllegalArgumentException if the parameter is not an OAuth parameter */ - public void addOAuthParameter(final String key, final String value) { + public void addOAuthParameter(String key, String value) { oauthParameters.put(checkKey(key), value); } - private String checkKey(final String key) { + private String checkKey(String key) { if (key.startsWith(OAUTH_PREFIX) || key.equals(OAuthConstants.SCOPE) || key.equals(OAuthConstants.REALM)) { return key; } else { @@ -74,7 +74,7 @@ public Map getOauthParameters() { return oauthParameters; } - public void setRealm(final String realm) { + public void setRealm(String realm) { this.realm = realm; } @@ -97,7 +97,7 @@ public String getCompleteUrl() { * @param key the header name * @param value the header value */ - public void addHeader(final String key, final String value) { + public void addHeader(String key, String value) { this.headers.put(key, value); } @@ -107,7 +107,7 @@ public void addHeader(final String key, final String value) { * @param key the parameter name * @param value the parameter value */ - public void addBodyParameter(final String key, final String value) { + public void addBodyParameter(String key, String value) { this.bodyParams.add(key, value); } @@ -117,11 +117,11 @@ public void addBodyParameter(final String key, final String value) { * @param key the parameter name * @param value the parameter value */ - public void addQuerystringParameter(final String key, final String value) { + public void addQuerystringParameter(String key, String value) { this.querystringParams.add(key, value); } - public void addParameter(final String key, final String value) { + public void addParameter(String key, String value) { if (hasBodyContent()) { bodyParams.add(key, value); } else { @@ -139,7 +139,7 @@ protected boolean hasBodyContent() { * * @param payload the body of the request */ - public void addPayload(final String payload) { + public void addPayload(String payload) { this.payload = payload; } @@ -148,7 +148,7 @@ public void addPayload(final String payload) { * * @param payload byte[] */ - public void addPayload(final byte[] payload) { + public void addPayload(byte[] payload) { this.bytePayload = payload.clone(); } @@ -252,7 +252,7 @@ public String getCharset() { * * @param charsetName name of the charset of the request */ - public void setCharset(final String charsetName) { + public void setCharset(String charsetName) { charset = charsetName; } @@ -264,7 +264,7 @@ public void setCharset(final String charsetName) { * @see http://download.oracle.com/javase/1.5.0/docs/guide/net/http-keepalive.html */ - public void setConnectionKeepAlive(final boolean connectionKeepAlive) { + public void setConnectionKeepAlive(boolean connectionKeepAlive) { this.connectionKeepAlive = connectionKeepAlive; } @@ -277,7 +277,7 @@ public void setConnectionKeepAlive(final boolean connectionKeepAlive) { * href="http://docs.oracle.com/javase/6/docs/api/java/net/HttpURLConnection.html#setInstanceFollowRedirects(boolean)">http://docs.oracle.com/javase/6/docs/api/java/net/HttpURLConnection.html#setInstanceFollowRedirects(boolean) * @param followRedirects boolean */ - public void setFollowRedirects(final boolean followRedirects) { + public void setFollowRedirects(boolean followRedirects) { this.followRedirects = followRedirects; } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConfig.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConfig.java index adec2c7c0..0a333454b 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConfig.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConfig.java @@ -21,13 +21,12 @@ public class OAuthConfig { private final Integer readTimeout; private String state; - public OAuthConfig(final String key, final String secret) { + public OAuthConfig(String key, String secret) { this(key, secret, null, null, null, null, null, null, null); } - public OAuthConfig(final String key, final String secret, final String callback, final SignatureType type, - final String scope, final OutputStream stream, final Integer connectTimeout, final Integer readTimeout, - final String grantType) { + public OAuthConfig(String key, String secret, String callback, SignatureType type, String scope, + OutputStream stream, Integer connectTimeout, Integer readTimeout, String grantType) { this.apiKey = key; this.apiSecret = secret; this.callback = callback; @@ -95,7 +94,7 @@ public void log(String message) { * * @param state some secret key that client side shall never receive */ - public void setState(final String state) { + public void setState(String state) { this.state = state; } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConfigAsync.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConfigAsync.java index e02dc54ce..1387a9b01 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConfigAsync.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConfigAsync.java @@ -8,12 +8,12 @@ public class OAuthConfigAsync extends OAuthConfig { private AsyncHttpClientConfig asyncHttpClientConfig; private String asyncHttpProviderClassName; - public OAuthConfigAsync(final String key, final String secret) { + public OAuthConfigAsync(String key, String secret) { super(key, secret); } - public OAuthConfigAsync(final String key, final String secret, final String callback, final SignatureType type, - final String scope, final String grantType, final OutputStream stream, final AsyncHttpClientConfig asyncHttpClientConfig) { + public OAuthConfigAsync(String key, String secret, String callback, SignatureType type, String scope, + String grantType, OutputStream stream, AsyncHttpClientConfig asyncHttpClientConfig) { super(key, secret, callback, type, scope, stream, null, null, grantType); this.asyncHttpClientConfig = asyncHttpClientConfig; } @@ -22,7 +22,7 @@ public AsyncHttpClientConfig getAsyncHttpClientConfig() { return asyncHttpClientConfig; } - public void setAsyncHttpProviderClassName(final String asyncHttpProviderClassName) { + public void setAsyncHttpProviderClassName(String asyncHttpProviderClassName) { this.asyncHttpProviderClassName = asyncHttpProviderClassName; } 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 2e3a69f24..bd2f38ae1 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 @@ -67,12 +67,12 @@ private void createConnection() throws IOException { } void addHeaders() { - for (final Map.Entry entry : getHeaders().entrySet()) { + for (Map.Entry entry : getHeaders().entrySet()) { connection.setRequestProperty(entry.getKey(), entry.getValue()); } } - void addBody(final byte[] content) throws IOException { + void addBody(byte[] content) throws IOException { connection.setRequestProperty(CONTENT_LENGTH, String.valueOf(content.length)); if (connection.getRequestProperty(CONTENT_TYPE) == null) { @@ -82,7 +82,7 @@ void addBody(final byte[] content) throws IOException { connection.getOutputStream().write(content); } - void setConnection(final HttpURLConnection connection) { + void setConnection(HttpURLConnection connection) { this.connection = connection; } } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequestAsync.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequestAsync.java index f0cc42b19..290be9013 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequestAsync.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequestAsync.java @@ -16,12 +16,12 @@ public class OAuthRequestAsync extends AbstractRequest { public static final ResponseConverter RESPONSE_CONVERTER = new ResponseConverter() { @Override - public Response convert(final com.ning.http.client.Response response) throws IOException { + public Response convert(com.ning.http.client.Response response) throws IOException { final FluentCaseInsensitiveStringsMap map = response.getHeaders(); final Map headersMap = new HashMap<>(); - for (final FluentCaseInsensitiveStringsMap.Entry> header : map) { + for (FluentCaseInsensitiveStringsMap.Entry> header : map) { final StringBuilder value = new StringBuilder(); - for (final String str : header.getValue()) { + for (String str : header.getValue()) { value.append(str); } headersMap.put(header.getKey(), value.toString()); @@ -31,15 +31,15 @@ public Response convert(final com.ning.http.client.Response response) throws IOE } }; - public OAuthRequestAsync(final Verb verb, final String url, final OAuthService service) { + public OAuthRequestAsync(Verb verb, String url, OAuthService service) { super(verb, url, service); } - public Future sendAsync(final OAuthAsyncRequestCallback callback, final ResponseConverter converter) { + public Future sendAsync(OAuthAsyncRequestCallback callback, ResponseConverter converter) { return sendAsync(callback, converter, null); } - public Future sendAsync(final OAuthAsyncRequestCallback callback, final ResponseConverter converter, final ProxyServer proxyServer) { + public Future sendAsync(OAuthAsyncRequestCallback callback, ResponseConverter converter, ProxyServer proxyServer) { final ForceTypeOfHttpRequest forceTypeOfHttpRequest = ScribeJavaConfig.getForceTypeOfHttpRequests(); if (ForceTypeOfHttpRequest.FORCE_SYNC_ONLY_HTTP_REQUESTS == forceTypeOfHttpRequest) { throw new OAuthException("Cannot use async operations, only sync"); @@ -71,13 +71,13 @@ private static class OAuthAsyncCompletionHandler extends AsyncCompletionHandl private final OAuthAsyncRequestCallback callback; private final ResponseConverter converter; - OAuthAsyncCompletionHandler(final OAuthAsyncRequestCallback callback, final ResponseConverter converter) { + OAuthAsyncCompletionHandler(OAuthAsyncRequestCallback callback, ResponseConverter converter) { this.callback = callback; this.converter = converter; } @Override - public T onCompleted(final com.ning.http.client.Response response) throws IOException { + public T onCompleted(com.ning.http.client.Response response) throws IOException { final T t = converter.convert(response); if (callback != null) { callback.onCompleted(t); @@ -86,18 +86,18 @@ public T onCompleted(final com.ning.http.client.Response response) throws IOExce } @Override - public void onThrowable(final Throwable t) { + public void onThrowable(Throwable t) { if (callback != null) { callback.onThrowable(t); } } }; - public Future sendAsync(final OAuthAsyncRequestCallback callback) { + public Future sendAsync(OAuthAsyncRequestCallback callback) { return sendAsync(callback, RESPONSE_CONVERTER, null); } - public Future sendAsync(final OAuthAsyncRequestCallback callback, final ProxyServer proxyServer) { + public Future sendAsync(OAuthAsyncRequestCallback callback, ProxyServer proxyServer) { return sendAsync(callback, RESPONSE_CONVERTER, proxyServer); } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/Parameter.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/Parameter.java index 8eb23ba62..0bcfb7528 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/Parameter.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/Parameter.java @@ -12,7 +12,7 @@ public class Parameter implements Comparable { private final String key; private final String value; - public Parameter(final String key, final String value) { + public Parameter(String key, String value) { this.key = key; this.value = value; } @@ -22,7 +22,7 @@ public String asUrlEncodedPair() { } @Override - public boolean equals(final Object other) { + public boolean equals(Object other) { if (other == null) { return false; } @@ -51,7 +51,7 @@ public int hashCode() { } @Override - public int compareTo(final Parameter parameter) { + public int compareTo(Parameter parameter) { final int keyDiff = key.compareTo(parameter.getKey()); return keyDiff == 0 ? value.compareTo(parameter.getValue()) : keyDiff; diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/ParameterList.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/ParameterList.java index 38f219650..52bea2266 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/ParameterList.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/ParameterList.java @@ -23,18 +23,18 @@ public ParameterList() { params = new ArrayList<>(); } - ParameterList(final List params) { + ParameterList(List params) { this.params = new ArrayList<>(params); } - public ParameterList(final Map map) { + public ParameterList(Map map) { this(); - for (final Map.Entry entry : map.entrySet()) { + for (Map.Entry entry : map.entrySet()) { params.add(new Parameter(entry.getKey(), entry.getValue())); } } - public void add(final String key, final String value) { + public void add(String key, String value) { params.add(new Parameter(key, value)); } @@ -60,19 +60,19 @@ public String asFormUrlEncodedString() { } final StringBuilder builder = new StringBuilder(); - for (final Parameter p : params) { + for (Parameter p : params) { builder.append('&').append(p.asUrlEncodedPair()); } return builder.toString().substring(1); } - public void addAll(final ParameterList other) { + public void addAll(ParameterList other) { params.addAll(other.getParams()); } - public void addQuerystring(final String queryString) { + public void addQuerystring(String queryString) { if (queryString != null && queryString.length() > 0) { - for (final String param : queryString.split(PARAM_SEPARATOR)) { + for (String param : queryString.split(PARAM_SEPARATOR)) { final String pair[] = param.split(PAIR_SEPARATOR); final String key = OAuthEncoder.decode(pair[0]); final String value = pair.length > 1 ? OAuthEncoder.decode(pair[1]) : EMPTY_STRING; @@ -81,7 +81,7 @@ public void addQuerystring(final String queryString) { } } - public boolean contains(final Parameter param) { + public boolean contains(Parameter param) { return params.contains(param); } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/Response.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/Response.java index dec7d0ddf..5cc8324f2 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/Response.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/Response.java @@ -17,7 +17,7 @@ public class Response { private InputStream stream; private Map headers; - public Response(final int code, final String message, final Map headers, final String body, final InputStream stream) { + public Response(int code, String message, Map headers, String body, InputStream stream) { this.code = code; this.headers = headers; this.body = body; @@ -25,7 +25,7 @@ public Response(final int code, final String message, final Map this.stream = stream; } - Response(final HttpURLConnection connection) throws IOException { + Response(HttpURLConnection connection) throws IOException { try { connection.connect(); code = connection.getResponseCode(); @@ -42,9 +42,9 @@ private String parseBodyContents() { return body; } - private Map parseHeaders(final HttpURLConnection conn) { + private Map parseHeaders(HttpURLConnection conn) { final Map headers = new HashMap<>(); - for (final String key : conn.getHeaderFields().keySet()) { + for (String key : conn.getHeaderFields().keySet()) { headers.put(key, conn.getHeaderFields().get(key).get(0)); } return headers; @@ -106,7 +106,7 @@ public Map getHeaders() { * * @return header value or null. */ - public String getHeader(final String name) { + public String getHeader(String name) { return headers.get(name); } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/Token.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/Token.java index 816c06902..4e51ca7c7 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/Token.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/Token.java @@ -22,11 +22,11 @@ public class Token implements Serializable { * @param token token value. Can't be null. * @param secret token secret. Can't be null. */ - public Token(final String token, final String secret) { + public Token(String token, String secret) { this(token, secret, null); } - public Token(final String token, final String secret, final String rawResponse) { + public Token(String token, String secret, String rawResponse) { Preconditions.checkNotNull(token, "Token can't be null"); Preconditions.checkNotNull(secret, "Secret can't be null"); @@ -55,7 +55,7 @@ public String getParameter(String parameter) { String value = null; for (String str : this.getRawResponse().split("&")) { if (str.startsWith(parameter + '=')) { - String[] part = str.split("="); + final String[] part = str.split("="); if (part.length > 1) { value = part[1].trim(); } @@ -89,7 +89,7 @@ public static Token empty() { } @Override - public boolean equals(final Object o) { + public boolean equals(Object o) { if (this == o) { return true; } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java index 2a047affc..94f627ef5 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java @@ -33,7 +33,7 @@ public class OAuth10aService extends OAuthService { * @param api OAuth1.0a api information * @param config OAuth 1.0a configuration param object */ - public OAuth10aService(final DefaultApi10a api, final OAuthConfig config) { + public OAuth10aService(DefaultApi10a api, OAuthConfig config) { super(config); this.api = api; } @@ -58,7 +58,7 @@ public Token getRequestToken() { return api.getRequestTokenExtractor().extract(body); } - private void addOAuthParams(final AbstractRequest request, final Token token) { + private void addOAuthParams(AbstractRequest request, Token token) { final OAuthConfig config = getConfig(); request.addOAuthParameter(OAuthConstants.TIMESTAMP, api.getTimestampService().getTimestampInSeconds()); request.addOAuthParameter(OAuthConstants.NONCE, api.getTimestampService().getNonce()); @@ -74,7 +74,7 @@ private void addOAuthParams(final AbstractRequest request, final Token token) { } @Override - public Token getAccessToken(final Token requestToken, final Verifier verifier) { + public Token getAccessToken(Token requestToken, Verifier verifier) { final OAuthConfig config = getConfig(); config.log("obtaining access token from " + api.getAccessTokenEndpoint()); final OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint(), this); @@ -84,26 +84,26 @@ public Token getAccessToken(final Token requestToken, final Verifier verifier) { } @Override - public Future getAccessTokenAsync(final Token requestToken, final Verifier verifier, final OAuthAsyncRequestCallback callback) { + public Future getAccessTokenAsync(Token requestToken, Verifier verifier, OAuthAsyncRequestCallback callback) { return getAccessTokenAsync(requestToken, verifier, callback, null); } @Override - public Future getAccessTokenAsync(final Token requestToken, final Verifier verifier, final OAuthAsyncRequestCallback callback, - final ProxyServer proxyServer) { + public Future getAccessTokenAsync(Token requestToken, Verifier verifier, OAuthAsyncRequestCallback callback, + ProxyServer proxyServer) { final OAuthConfig config = getConfig(); config.log("async obtaining access token from " + api.getAccessTokenEndpoint()); final OAuthRequestAsync request = new OAuthRequestAsync(api.getAccessTokenVerb(), api.getAccessTokenEndpoint(), this); prepareAccessTokenRequest(request, requestToken, verifier); return request.sendAsync(callback, new OAuthRequestAsync.ResponseConverter() { @Override - public Token convert(final com.ning.http.client.Response response) throws IOException { + public Token convert(com.ning.http.client.Response response) throws IOException { return getApi().getAccessTokenExtractor().extract(OAuthRequestAsync.RESPONSE_CONVERTER.convert(response).getBody()); } }, proxyServer); } - private void prepareAccessTokenRequest(final AbstractRequest request, final Token requestToken, final Verifier verifier) { + private void prepareAccessTokenRequest(AbstractRequest request, Token requestToken, Verifier verifier) { final OAuthConfig config = getConfig(); request.addOAuthParameter(OAuthConstants.TOKEN, requestToken.getToken()); request.addOAuthParameter(OAuthConstants.VERIFIER, verifier.getValue()); @@ -116,7 +116,7 @@ private void prepareAccessTokenRequest(final AbstractRequest request, final Toke * {@inheritDoc} */ @Override - public void signRequest(final Token token, final AbstractRequest request) { + public void signRequest(Token token, AbstractRequest request) { final OAuthConfig config = getConfig(); config.log("signing request: " + request.getCompleteUrl()); @@ -141,11 +141,11 @@ public String getVersion() { * {@inheritDoc} */ @Override - public String getAuthorizationUrl(final Token requestToken) { + public String getAuthorizationUrl(Token requestToken) { return api.getAuthorizationUrl(requestToken); } - private String getSignature(final AbstractRequest request, final Token token) { + private String getSignature(AbstractRequest request, Token token) { final OAuthConfig config = getConfig(); config.log("generating signature..."); config.log("using base64 encoder: " + Base64Encoder.type()); @@ -158,7 +158,7 @@ private String getSignature(final AbstractRequest request, final Token token) { return signature; } - private void appendSignature(final AbstractRequest request) { + private void appendSignature(AbstractRequest request) { final OAuthConfig config = getConfig(); switch (config.getSignatureType()) { case Header: @@ -170,7 +170,7 @@ private void appendSignature(final AbstractRequest request) { case QueryString: config.log("using Querystring signature"); - for (final Map.Entry entry : request.getOauthParameters().entrySet()) { + for (Map.Entry entry : request.getOauthParameters().entrySet()) { request.addQuerystringParameter(entry.getKey(), entry.getValue()); } break; 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 7fe9bf733..f93fd521d 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 @@ -25,38 +25,38 @@ public class OAuth20Service extends OAuthService { * @param api OAuth2.0 api information * @param config OAuth 2.0 configuration param object */ - public OAuth20Service(final DefaultApi20 api, final OAuthConfig config) { + public OAuth20Service(DefaultApi20 api, OAuthConfig config) { super(config); this.api = api; } @Override - public Token getAccessToken(final Token requestToken, final Verifier verifier) { + public Token getAccessToken(Token requestToken, Verifier verifier) { final Response response = createAccessTokenRequest(verifier, new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint(), this)). send(); return api.getAccessTokenExtractor().extract(response.getBody()); } @Override - public Future getAccessTokenAsync(final Token requestToken, final Verifier verifier, final OAuthAsyncRequestCallback callback) { + public Future getAccessTokenAsync(Token requestToken, Verifier verifier, OAuthAsyncRequestCallback callback) { return getAccessTokenAsync(requestToken, verifier, callback, null); } @Override - public Future getAccessTokenAsync(final Token requestToken, final Verifier verifier, final OAuthAsyncRequestCallback callback, - final ProxyServer proxyServer) { + public Future getAccessTokenAsync(Token requestToken, Verifier verifier, OAuthAsyncRequestCallback callback, + ProxyServer proxyServer) { final OAuthRequestAsync request = createAccessTokenRequest(verifier, new OAuthRequestAsync(api.getAccessTokenVerb(), api. getAccessTokenEndpoint(), this)); return request.sendAsync(callback, new OAuthRequestAsync.ResponseConverter() { @Override - public Token convert(final com.ning.http.client.Response response) throws IOException { + public Token convert(com.ning.http.client.Response response) throws IOException { return getApi().getAccessTokenExtractor().extract(OAuthRequestAsync.RESPONSE_CONVERTER.convert(response).getBody()); } }, proxyServer); } - protected T createAccessTokenRequest(final Verifier verifier, final T request) { + protected T createAccessTokenRequest(Verifier verifier, T request) { final OAuthConfig config = getConfig(); request.addParameter(OAuthConstants.CLIENT_ID, config.getApiKey()); request.addParameter(OAuthConstants.CLIENT_SECRET, config.getApiSecret()); @@ -91,7 +91,7 @@ public String getVersion() { * {@inheritDoc} */ @Override - public void signRequest(final Token accessToken, final AbstractRequest request) { + public void signRequest(Token accessToken, AbstractRequest request) { request.addQuerystringParameter(OAuthConstants.ACCESS_TOKEN, accessToken.getToken()); } @@ -99,7 +99,7 @@ public void signRequest(final Token accessToken, final AbstractRequest request) * {@inheritDoc} */ @Override - public String getAuthorizationUrl(final Token requestToken) { + public String getAuthorizationUrl(Token requestToken) { return api.getAuthorizationUrl(getConfig()); } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java index dfccae2e5..c8f209e94 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java @@ -25,7 +25,7 @@ public abstract class OAuthService { private final OAuthConfig config; private AsyncHttpClient asyncHttpClient; - public OAuthService(final OAuthConfig config) { + public OAuthService(OAuthConfig config) { this.config = config; final ForceTypeOfHttpRequest forceTypeOfHttpRequest = ScribeJavaConfig.getForceTypeOfHttpRequests(); if (config instanceof OAuthConfigAsync) { 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 960b49214..00a7b7869 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 @@ -27,7 +27,7 @@ public class HMACSha1SignatureService implements SignatureService { * {@inheritDoc} */ @Override - public String getSignature(final String baseString, final String apiSecret, final String tokenSecret) { + 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"); @@ -37,7 +37,7 @@ public String getSignature(final String baseString, final String apiSecret, fina } } - private String doSign(final String toSign, final String keyString) throws UnsupportedEncodingException, + private String doSign(String toSign, String keyString) throws UnsupportedEncodingException, NoSuchAlgorithmException, InvalidKeyException { final SecretKeySpec key = new SecretKeySpec(keyString.getBytes(UTF8), HMAC_SHA1); final Mac mac = Mac.getInstance(HMAC_SHA1); @@ -46,7 +46,7 @@ private String doSign(final String toSign, final String keyString) throws Unsupp return bytesToBase64String(bytes).replace(CARRIAGE_RETURN, EMPTY_STRING); } - private String bytesToBase64String(final byte[] bytes) { + private String bytesToBase64String(byte[] bytes) { return Base64Encoder.getInstance().encode(bytes); } 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 c85f2940d..5f89946c6 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 @@ -26,7 +26,7 @@ public RSASha1SignatureService(PrivateKey privateKey) { @Override public String getSignature(String baseString, String apiSecret, String tokenSecret) { try { - Signature signature = Signature.getInstance(RSA_SHA1); + final Signature signature = Signature.getInstance(RSA_SHA1); signature.initSign(privateKey); signature.update(baseString.getBytes(UTF8)); return bytesToBase64String(signature); diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/services/TimestampServiceImpl.java b/scribejava-core/src/main/java/com/github/scribejava/core/services/TimestampServiceImpl.java index cef00537d..de9fccdbe 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/services/TimestampServiceImpl.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/services/TimestampServiceImpl.java @@ -23,7 +23,7 @@ public TimestampServiceImpl() { */ @Override public String getNonce() { - Long ts = getTs(); + final Long ts = getTs(); return String.valueOf(ts + timer.getRandomInteger()); } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/utils/MapUtils.java b/scribejava-core/src/main/java/com/github/scribejava/core/utils/MapUtils.java index d070a76d7..9e4badbc3 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/utils/MapUtils.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/utils/MapUtils.java @@ -7,7 +7,7 @@ */ public abstract class MapUtils { - public static String toString(final Map map) { + public static String toString(Map map) { if (map == null) { return ""; } @@ -16,7 +16,7 @@ public static String toString(final Map map) { } final StringBuilder result = new StringBuilder(); - for (final Map.Entry entry : map.entrySet()) { + for (Map.Entry entry : map.entrySet()) { result.append(String.format(", %s -> %s ", entry.getKey().toString(), entry.getValue().toString())); } return "{" + result.substring(1) + "}"; diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/utils/OAuthEncoder.java b/scribejava-core/src/main/java/com/github/scribejava/core/utils/OAuthEncoder.java index a9990c81e..c872eb5a5 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/utils/OAuthEncoder.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/utils/OAuthEncoder.java @@ -25,7 +25,7 @@ public abstract class OAuthEncoder { ENCODING_RULES = Collections.unmodifiableMap(rules); } - public static String encode(final String plain) { + public static String encode(String plain) { Preconditions.checkNotNull(plain, "Cannot encode null object"); String encoded = ""; try { @@ -33,17 +33,17 @@ public static String encode(final String plain) { } catch (UnsupportedEncodingException uee) { throw new OAuthException("Charset not found while encoding string: " + CHARSET, uee); } - for (final Map.Entry rule : ENCODING_RULES.entrySet()) { + for (Map.Entry rule : ENCODING_RULES.entrySet()) { encoded = applyRule(encoded, rule.getKey(), rule.getValue()); } return encoded; } - private static String applyRule(final String encoded, final String toReplace, final String replacement) { + private static String applyRule(String encoded, String toReplace, String replacement) { return encoded.replaceAll(Pattern.quote(toReplace), replacement); } - public static String decode(final String encoded) { + public static String decode(String encoded) { Preconditions.checkNotNull(encoded, "Cannot decode null object"); try { return URLDecoder.decode(encoded, CHARSET); diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/utils/Preconditions.java b/scribejava-core/src/main/java/com/github/scribejava/core/utils/Preconditions.java index 505ced85b..7c6f4ad2c 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/utils/Preconditions.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/utils/Preconditions.java @@ -24,7 +24,7 @@ public abstract class Preconditions { * * @throws IllegalArgumentException if the object is null */ - public static void checkNotNull(final Object object, final String errorMsg) { + public static void checkNotNull(Object object, String errorMsg) { check(object != null, errorMsg); } @@ -36,7 +36,7 @@ public static void checkNotNull(final Object object, final String errorMsg) { * * @throws IllegalArgumentException if the string is null or empty */ - public static void checkEmptyString(final String string, final String errorMsg) { + public static void checkEmptyString(String string, String errorMsg) { check(string != null && !string.trim().isEmpty(), errorMsg); } @@ -46,7 +46,7 @@ public static void checkEmptyString(final String string, final String errorMsg) * @param url any string * @param errorMsg error message */ - public static void checkValidUrl(final String url, final String errorMsg) { + public static void checkValidUrl(String url, String errorMsg) { checkEmptyString(url, errorMsg); check(isUrl(url), errorMsg); } @@ -57,18 +57,18 @@ public static void checkValidUrl(final String url, final String errorMsg) { * @param url any string * @param errorMsg error message */ - public static void checkValidOAuthCallback(final String url, final String errorMsg) { + public static void checkValidOAuthCallback(String url, String errorMsg) { checkEmptyString(url, errorMsg); if (url.toLowerCase(Locale.getDefault()).compareToIgnoreCase(OAuthConstants.OUT_OF_BAND) != 0) { check(isUrl(url), errorMsg); } } - private static boolean isUrl(final String url) { + private static boolean isUrl(String url) { return URL_PATTERN.matcher(url).matches(); } - private static void check(final boolean requirements, final String error) { + private static void check(boolean requirements, String error) { if (!requirements) { throw new IllegalArgumentException(error == null || error.trim().length() <= 0 ? DEFAULT_MESSAGE : error); } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/utils/StreamUtils.java b/scribejava-core/src/main/java/com/github/scribejava/core/utils/StreamUtils.java index 88fb392dc..5f3fee95f 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/utils/StreamUtils.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/utils/StreamUtils.java @@ -22,8 +22,8 @@ public static String getStreamContents(InputStream is) { Preconditions.checkNotNull(is, "Cannot get String from a null object"); try { final char[] buffer = new char[0x10000]; - StringBuilder out = new StringBuilder(); - Reader in = new InputStreamReader(is, "UTF-8"); + final StringBuilder out = new StringBuilder(); + final Reader in = new InputStreamReader(is, "UTF-8"); int read; do { read = in.read(buffer, 0, buffer.length); diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/builder/ServiceBuilderTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/builder/ServiceBuilderTest.java index 134be1f7b..9bf8f386f 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/builder/ServiceBuilderTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/builder/ServiceBuilderTest.java @@ -79,7 +79,7 @@ private OAuthConfig getConfig() { } @Override - public OAuth20Service createService(final OAuthConfig config) { + public OAuth20Service createService(OAuthConfig config) { this.config = config; return null; } @@ -90,7 +90,7 @@ public String getAccessTokenEndpoint() { } @Override - public String getAuthorizationUrl(final OAuthConfig config) { + public String getAuthorizationUrl(OAuthConfig config) { throw new UnsupportedOperationException("Not supported yet."); } } 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 ee27f1e28..0dcccaa63 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 @@ -33,68 +33,68 @@ public void setUp() { @Test public void shouldExtractBaseStringFromOAuthRequest() { - String expected + final String expected = "GET&http%3A%2F%2Fexample.com&oauth_callback%3Dhttp%253A%252F%252Fexample%252Fcallback%26oauth_consumer_key%3DAS%2523%2524%255E%252A%2540%2526%26oauth_signature%3DOAuth-Signature%26oauth_timestamp%3D123456"; - String baseString = extractor.extract(request); + final String baseString = extractor.extract(request); assertEquals(expected, baseString); } @Test public void shouldExcludePort80() { - String expected + final String expected = "GET&http%3A%2F%2Fexample.com&oauth_callback%3Dhttp%253A%252F%252Fexample%252Fcallback%26oauth_consumer_key%3DAS%2523%2524%255E%252A%2540%2526%26oauth_signature%3DOAuth-Signature%26oauth_timestamp%3D123456"; - String baseString = extractor.extract(requestPort80); + final String baseString = extractor.extract(requestPort80); assertEquals(expected, baseString); } @Test public void shouldExcludePort80v2() { - String expected + final String expected = "GET&http%3A%2F%2Fexample.com%2Ftest&oauth_callback%3Dhttp%253A%252F%252Fexample%252Fcallback%26oauth_consumer_key%3DAS%2523%2524%255E%252A%2540%2526%26oauth_signature%3DOAuth-Signature%26oauth_timestamp%3D123456"; - String baseString = extractor.extract(requestPort80v2); + final String baseString = extractor.extract(requestPort80v2); assertEquals(expected, baseString); } @Test public void shouldIncludePort8080() { - String expected + final String expected = "GET&http%3A%2F%2Fexample.com%3A8080&oauth_callback%3Dhttp%253A%252F%252Fexample%252Fcallback%26oauth_consumer_key%3DAS%2523%2524%255E%252A%2540%2526%26oauth_signature%3DOAuth-Signature%26oauth_timestamp%3D123456"; - String baseString = extractor.extract(requestPort8080); + final String baseString = extractor.extract(requestPort8080); assertEquals(expected, baseString); } @Test public void shouldExcludePort443() { - String expected + final String expected = "GET&https%3A%2F%2Fexample.com&oauth_callback%3Dhttp%253A%252F%252Fexample%252Fcallback%26oauth_consumer_key%3DAS%2523%2524%255E%252A%2540%2526%26oauth_signature%3DOAuth-Signature%26oauth_timestamp%3D123456"; - String baseString = extractor.extract(requestPort443); + final String baseString = extractor.extract(requestPort443); assertEquals(expected, baseString); } @Test public void shouldExcludePort443v2() { - String expected + final String expected = "GET&https%3A%2F%2Fexample.com%2Ftest&oauth_callback%3Dhttp%253A%252F%252Fexample%252Fcallback%26oauth_consumer_key%3DAS%2523%2524%255E%252A%2540%2526%26oauth_signature%3DOAuth-Signature%26oauth_timestamp%3D123456"; - String baseString = extractor.extract(requestPort443v2); + final String baseString = extractor.extract(requestPort443v2); assertEquals(expected, baseString); } @Test(expected = IllegalArgumentException.class) public void shouldThrowExceptionIfRquestIsNull() { - OAuthRequest nullRequest = null; + final OAuthRequest nullRequest = null; extractor.extract(nullRequest); } @Test(expected = OAuthParametersMissingException.class) public void shouldThrowExceptionIfRquestHasNoOAuthParameters() { - OAuthRequest request = new OAuthRequest(Verb.GET, "http://example.com", new OAuth20Service(null, new OAuthConfig("test", + final OAuthRequest request = new OAuthRequest(Verb.GET, "http://example.com", new OAuth20Service(null, new OAuthConfig("test", "test"))); extractor.extract(request); } @Test public void shouldProperlyEncodeSpaces() { - String expected + final String expected = "GET&http%3A%2F%2Fexample.com&body%3Dthis%2520param%2520has%2520whitespace%26oauth_callback%3Dhttp%253A%252F%252Fexample%252Fcallback%26oauth_consumer_key%3DAS%2523%2524%255E%252A%2540%2526%26oauth_signature%3DOAuth-Signature%26oauth_timestamp%3D123456"; request.addBodyParameter("body", "this param has whitespace"); assertEquals(expected, extractor.extract(request)); diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/extractors/JsonTokenExtractorTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/extractors/JsonTokenExtractorTest.java index f5a278e82..07c655c32 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/extractors/JsonTokenExtractorTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/extractors/JsonTokenExtractorTest.java @@ -11,7 +11,7 @@ public class JsonTokenExtractorTest { @Test public void shouldParseResponse() { - Token token = extractor.extract(response); + final Token token = extractor.extract(response); assertEquals(token.getToken(), "I0122HHJKLEM21F3WLPYHDKGKZULAUO4SGMV3ABKFTDT3T3X"); } diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/extractors/TokenExtractor20Test.java b/scribejava-core/src/test/java/com/github/scribejava/core/extractors/TokenExtractor20Test.java index 66af64384..ed08bdf5e 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/extractors/TokenExtractor20Test.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/extractors/TokenExtractor20Test.java @@ -17,43 +17,43 @@ public void setup() { @Test public void shouldExtractTokenFromOAuthStandardResponse() { - String response = "access_token=166942940015970|2.2ltzWXYNDjCtg5ZDVVJJeg__.3600.1295816400-548517159|RsXNdKrpxg8L6QNLWcs2TVTmcaE"; - Token extracted = extractor.extract(response); + final String response = "access_token=166942940015970|2.2ltzWXYNDjCtg5ZDVVJJeg__.3600.1295816400-548517159|RsXNdKrpxg8L6QNLWcs2TVTmcaE"; + final Token extracted = extractor.extract(response); assertEquals("166942940015970|2.2ltzWXYNDjCtg5ZDVVJJeg__.3600.1295816400-548517159|RsXNdKrpxg8L6QNLWcs2TVTmcaE", extracted.getToken()); assertEquals("", extracted.getSecret()); } @Test public void shouldExtractTokenFromResponseWithExpiresParam() { - String response = "access_token=166942940015970|2.2ltzWXYNDjCtg5ZDVVJJeg__.3600.1295816400-548517159|RsXNdKrpxg8L6QNLWcs2TVTmcaE&expires=5108"; - Token extracted = extractor.extract(response); + final String response = "access_token=166942940015970|2.2ltzWXYNDjCtg5ZDVVJJeg__.3600.1295816400-548517159|RsXNdKrpxg8L6QNLWcs2TVTmcaE&expires=5108"; + final Token extracted = extractor.extract(response); assertEquals("166942940015970|2.2ltzWXYNDjCtg5ZDVVJJeg__.3600.1295816400-548517159|RsXNdKrpxg8L6QNLWcs2TVTmcaE", extracted.getToken()); assertEquals("", extracted.getSecret()); } @Test public void shouldExtractTokenFromResponseWithManyParameters() { - String response = "access_token=foo1234&other_stuff=yeah_we_have_this_too&number=42"; - Token extracted = extractor.extract(response); + final String response = "access_token=foo1234&other_stuff=yeah_we_have_this_too&number=42"; + final Token extracted = extractor.extract(response); assertEquals("foo1234", extracted.getToken()); assertEquals("", extracted.getSecret()); } @Test(expected = OAuthException.class) public void shouldThrowExceptionIfTokenIsAbsent() { - String response = "&expires=5108"; + final String response = "&expires=5108"; extractor.extract(response); } @Test(expected = IllegalArgumentException.class) public void shouldThrowExceptionIfResponseIsNull() { - String response = null; + final String response = null; extractor.extract(response); } @Test(expected = IllegalArgumentException.class) public void shouldThrowExceptionIfResponseIsEmptyString() { - String response = ""; + final String response = ""; extractor.extract(response); } } diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/extractors/TokenExtractorTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/extractors/TokenExtractorTest.java index ab3cab9a2..22aeab042 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/extractors/TokenExtractorTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/extractors/TokenExtractorTest.java @@ -17,57 +17,57 @@ public void setup() { @Test public void shouldExtractTokenFromOAuthStandardResponse() { - String response = "oauth_token=hh5s93j4hdidpola&oauth_token_secret=hdhd0244k9j7ao03"; - Token extracted = extractor.extract(response); + final String response = "oauth_token=hh5s93j4hdidpola&oauth_token_secret=hdhd0244k9j7ao03"; + final Token extracted = extractor.extract(response); assertEquals("hh5s93j4hdidpola", extracted.getToken()); assertEquals("hdhd0244k9j7ao03", extracted.getSecret()); } @Test public void shouldExtractTokenFromInvertedOAuthStandardResponse() { - String response = "oauth_token_secret=hh5s93j4hdidpola&oauth_token=hdhd0244k9j7ao03"; - Token extracted = extractor.extract(response); + final String response = "oauth_token_secret=hh5s93j4hdidpola&oauth_token=hdhd0244k9j7ao03"; + final Token extracted = extractor.extract(response); assertEquals("hh5s93j4hdidpola", extracted.getSecret()); assertEquals("hdhd0244k9j7ao03", extracted.getToken()); } @Test public void shouldExtractTokenFromResponseWithCallbackConfirmed() { - String response = "oauth_token=hh5s93j4hdidpola&oauth_token_secret=hdhd0244k9j7ao03&callback_confirmed=true"; - Token extracted = extractor.extract(response); + final String response = "oauth_token=hh5s93j4hdidpola&oauth_token_secret=hdhd0244k9j7ao03&callback_confirmed=true"; + final Token extracted = extractor.extract(response); assertEquals("hh5s93j4hdidpola", extracted.getToken()); assertEquals("hdhd0244k9j7ao03", extracted.getSecret()); } @Test public void shouldExtractTokenWithEmptySecret() { - String response = "oauth_token=hh5s93j4hdidpola&oauth_token_secret="; - Token extracted = extractor.extract(response); + final String response = "oauth_token=hh5s93j4hdidpola&oauth_token_secret="; + final Token extracted = extractor.extract(response); assertEquals("hh5s93j4hdidpola", extracted.getToken()); assertEquals("", extracted.getSecret()); } @Test(expected = OAuthException.class) public void shouldThrowExceptionIfTokenIsAbsent() { - String response = "oauth_secret=hh5s93j4hdidpola&callback_confirmed=true"; + final String response = "oauth_secret=hh5s93j4hdidpola&callback_confirmed=true"; extractor.extract(response); } @Test(expected = OAuthException.class) public void shouldThrowExceptionIfSecretIsAbsent() { - String response = "oauth_token=hh5s93j4hdidpola&callback_confirmed=true"; + final String response = "oauth_token=hh5s93j4hdidpola&callback_confirmed=true"; extractor.extract(response); } @Test(expected = IllegalArgumentException.class) public void shouldThrowExceptionIfResponseIsNull() { - String response = null; + final String response = null; extractor.extract(response); } @Test(expected = IllegalArgumentException.class) public void shouldThrowExceptionIfResponseIsEmptyString() { - String response = ""; + final String response = ""; extractor.extract(response); } } diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/model/ConnectionStub.java b/scribejava-core/src/test/java/com/github/scribejava/core/model/ConnectionStub.java index 650a71a47..21df5804c 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/model/ConnectionStub.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/model/ConnectionStub.java @@ -54,7 +54,7 @@ public int getTimesCalledInpuStream() { @Override public OutputStream getOutputStream() throws IOException { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); + final ByteArrayOutputStream baos = new ByteArrayOutputStream(); baos.write("contents".getBytes()); return baos; } 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 1f7ebdb6b..276b9bec8 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 @@ -20,20 +20,20 @@ public void setup() { @Test(expected = IllegalArgumentException.class) public void shouldThrowExceptionWhenAppendingNullMapToQuerystring() { - String url = null; + final String url = null; params.appendTo(url); } @Test public void shouldAppendNothingToQuerystringIfGivenEmptyMap() { - String url = "http://www.example.com"; + final String url = "http://www.example.com"; Assert.assertEquals(url, params.appendTo(url)); } @Test public void shouldAppendParametersToSimpleUrl() { String url = "http://www.example.com"; - String expectedUrl = "http://www.example.com?param1=value1¶m2=value%20with%20spaces"; + final String expectedUrl = "http://www.example.com?param1=value1¶m2=value%20with%20spaces"; params.add("param1", "value1"); params.add("param2", "value with spaces"); @@ -45,7 +45,7 @@ public void shouldAppendParametersToSimpleUrl() { @Test public void shouldAppendParametersToUrlWithQuerystring() { String url = "http://www.example.com?already=present"; - String expectedUrl = "http://www.example.com?already=present¶m1=value1¶m2=value%20with%20spaces"; + final String expectedUrl = "http://www.example.com?already=present¶m1=value1¶m2=value%20with%20spaces"; params.add("param1", "value1"); params.add("param2", "value with spaces"); diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/model/RequestTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/model/RequestTest.java index 091794f9a..446911162 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/model/RequestTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/model/RequestTest.java @@ -67,7 +67,7 @@ public void shouldSetPayloadAndHeaders() { @Test public void shouldAllowAddingQuerystringParametersAfterCreation() { - OAuthRequest request = new OAuthRequest(Verb.GET, "http://example.com?one=val", oAuthService); + final OAuthRequest request = new OAuthRequest(Verb.GET, "http://example.com?one=val", oAuthService); request.addQuerystringParameter("two", "other val"); request.addQuerystringParameter("more", "params"); assertEquals(3, request.getQueryStringParams().size()); @@ -75,7 +75,7 @@ public void shouldAllowAddingQuerystringParametersAfterCreation() { @Test public void shouldReturnTheCompleteUrl() { - OAuthRequest request = new OAuthRequest(Verb.GET, "http://example.com?one=val", oAuthService); + final OAuthRequest request = new OAuthRequest(Verb.GET, "http://example.com?one=val", oAuthService); request.addQuerystringParameter("two", "other val"); request.addQuerystringParameter("more", "params"); assertEquals("http://example.com?one=val&two=other%20val&more=params", request.getCompleteUrl()); diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/model/ResponseTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/model/ResponseTest.java index 252a67605..32926e8bb 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/model/ResponseTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/model/ResponseTest.java @@ -42,7 +42,7 @@ public void shouldParseBodyContentsOnlyOnce() { @Test public void shouldHandleAConnectionWithErrors() throws Exception { - Response errResponse = new Response(new FaultyConnection()); + final Response errResponse = new Response(new FaultyConnection()); assertEquals(400, errResponse.getCode()); assertEquals("errors", errResponse.getBody()); } 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 12cf01313..a84df6d26 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 @@ -16,16 +16,16 @@ public void setup() { @Test public void shouldReturnSignatureMethodString() { - String expected = "HMAC-SHA1"; + final String expected = "HMAC-SHA1"; assertEquals(expected, service.getSignatureMethod()); } @Test public void shouldReturnSignature() { - String apiSecret = "api secret"; - String tokenSecret = "token secret"; - String baseString = "base string"; - String signature = "uGymw2KHOTWI699YEaoi5xyLT50="; + final String apiSecret = "api secret"; + final String tokenSecret = "token secret"; + final String baseString = "base string"; + final String signature = "uGymw2KHOTWI699YEaoi5xyLT50="; assertEquals(signature, service.getSignature(baseString, apiSecret, tokenSecret)); } 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 8adfdb8e3..7e508a3a1 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 @@ -13,16 +13,16 @@ public class RSASha1SignatureServiceTest { @Test public void shouldReturnSignatureMethodString() { - String expected = "RSA-SHA1"; + final String expected = "RSA-SHA1"; assertEquals(expected, service.getSignatureMethod()); } @Test public void shouldReturnSignature() { - String apiSecret = "api secret"; - String tokenSecret = "token secret"; - String baseString = "base string"; - String signature + final String apiSecret = "api secret"; + final String tokenSecret = "token secret"; + final String baseString = "base string"; + final String signature = "LUNRzQAlpdNyM9mLXm96Va6g/qVNnEAb7p7K1KM0g8IopOFQJPoOO7cvppgt7w3QyhijWJnCmvqXaaIAGrqvdyr3fIzBULh8D/iZQUNLMi08GCOA34P81XBvsc7A5uJjPDsGhJg2MzoVJ8nWJhU/lMMk4c92S1WGskeoDofRwpo="; assertEquals(signature, service.getSignature(baseString, apiSecret, tokenSecret)); } @@ -34,7 +34,7 @@ public void shouldReturnSignature() { * /tmp/myrsacert.pem openssl pkcs8 -in myrsakey.pem -topk8 -nocrypt -out myrsakey.pk8 */ private static PrivateKey getPrivateKey() { - String str = "MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAMPQ5BCMxlUq2TYy\n" + final String str = "MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAMPQ5BCMxlUq2TYy\n" + "iRIoEUsz6HGTJhHuasS2nx1Se4Co3lxwxyubVdFj8AuhHNJSmJvjlpbTsGOjLZpr\n" + "HyDEDdJmf1Fensh1MhUnBZ4a7uLrZrKzFHHJdamX9pxapB89vLeHlCot9hVXdrZH\n" + "nNtg6FdmRKH/8gbs8iDyIayFvzYDAgMBAAECgYA+c9MpTBy9cQsR9BAvkEPjvkx2\n" @@ -49,8 +49,8 @@ private static PrivateKey getPrivateKey() { + "wJ3juUsVtujV23SnH43iMggXT7m82STpPGam1hPfmqu2Z0niePFo927ogQ7H1EMJ\n" + "UHgqXmuvk2X/Ww=="; try { - KeyFactory fac = KeyFactory.getInstance("RSA"); - PKCS8EncodedKeySpec privKeySpec = new PKCS8EncodedKeySpec(DatatypeConverter.parseBase64Binary(str)); + final KeyFactory fac = KeyFactory.getInstance("RSA"); + final PKCS8EncodedKeySpec privKeySpec = new PKCS8EncodedKeySpec(DatatypeConverter.parseBase64Binary(str)); return fac.generatePrivate(privKeySpec); } catch (Exception e) { throw new RuntimeException(e); diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/services/TimestampServiceTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/services/TimestampServiceTest.java index a9faeab4f..1a6b4c820 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/services/TimestampServiceTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/services/TimestampServiceTest.java @@ -18,13 +18,13 @@ public void setup() { @Test public void shouldReturnTimestampInSeconds() { - String expected = "1000"; + final String expected = "1000"; assertEquals(expected, service.getTimestampInSeconds()); } @Test public void shouldReturnNonce() { - String expected = "1042"; + final String expected = "1042"; assertEquals(expected, service.getNonce()); } diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/utils/MapUtilsTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/utils/MapUtilsTest.java index cf5e37bc8..115925bec 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/utils/MapUtilsTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/utils/MapUtilsTest.java @@ -12,7 +12,7 @@ public class MapUtilsTest { @Test public void shouldPrettyPrintMap() { - Map map = new HashMap(); + final Map map = new HashMap(); map.put(1, "one"); map.put(2, "two"); map.put(3, "three"); @@ -22,7 +22,7 @@ public void shouldPrettyPrintMap() { @Test public void shouldHandleEmptyMap() { - Map map = new HashMap(); + final Map map = new HashMap(); Assert.assertEquals("{}", MapUtils.toString(map)); } 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 196dd222b..84799c709 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 @@ -11,50 +11,50 @@ public class OAuthEncoderTest { @Test public void shouldPercentEncodeString() { - String plain = "this is a test &^"; - String encoded = "this%20is%20a%20test%20%26%5E"; + final String plain = "this is a test &^"; + final String encoded = "this%20is%20a%20test%20%26%5E"; assertEquals(encoded, OAuthEncoder.encode(plain)); } @Test public void shouldFormURLDecodeString() { - String encoded = "this+is+a+test+%26%5E"; - String plain = "this is a test &^"; + final String encoded = "this+is+a+test+%26%5E"; + final String plain = "this is a test &^"; assertEquals(plain, OAuthEncoder.decode(encoded)); } @Test public void shouldPercentEncodeAllSpecialCharacters() { - String plain = "!*'();:@&=+$,/?#[]"; - String encoded = "%21%2A%27%28%29%3B%3A%40%26%3D%2B%24%2C%2F%3F%23%5B%5D"; + final String plain = "!*'();:@&=+$,/?#[]"; + final String encoded = "%21%2A%27%28%29%3B%3A%40%26%3D%2B%24%2C%2F%3F%23%5B%5D"; assertEquals(encoded, OAuthEncoder.encode(plain)); assertEquals(plain, OAuthEncoder.decode(encoded)); } @Test public void shouldNotPercentEncodeReservedCharacters() { - String plain = "abcde123456-._~"; - String encoded = plain; + final String plain = "abcde123456-._~"; + final String encoded = plain; assertEquals(encoded, OAuthEncoder.encode(plain)); } @Test(expected = IllegalArgumentException.class) public void shouldThrowExceptionIfStringToEncodeIsNull() { - String toEncode = null; + final String toEncode = null; OAuthEncoder.encode(toEncode); } @Test(expected = IllegalArgumentException.class) public void shouldThrowExceptionIfStringToDecodeIsNull() { - String toDecode = null; + final String toDecode = null; OAuthEncoder.decode(toDecode); } @Test public void shouldPercentEncodeCorrectlyTwitterCodingExamples() { // These tests are part of the Twitter dev examples here -> https://dev.twitter.com/docs/auth/percent-encoding-parameters - String sources[] = {"Ladies + Gentlemen", "An encoded string!", "Dogs, Cats & Mice"}; - String encoded[] = {"Ladies%20%2B%20Gentlemen", "An%20encoded%20string%21", "Dogs%2C%20Cats%20%26%20Mice"}; + final String sources[] = {"Ladies + Gentlemen", "An encoded string!", "Dogs, Cats & Mice"}; + final String encoded[] = {"Ladies%20%2B%20Gentlemen", "An%20encoded%20string%21", "Dogs%2C%20Cats%20%26%20Mice"}; for (int i = 0; i < sources.length; i++) { Assert.assertEquals(encoded[i], OAuthEncoder.encode(sources[i])); 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 b83ad987a..d470edf0e 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 @@ -11,15 +11,15 @@ public class StreamUtilsTest { @Test public void shouldCorrectlyDecodeAStream() { - String value = "expected"; - InputStream is = new ByteArrayInputStream(value.getBytes()); - String decoded = StreamUtils.getStreamContents(is); + final String value = "expected"; + final InputStream is = new ByteArrayInputStream(value.getBytes()); + final String decoded = StreamUtils.getStreamContents(is); assertEquals("expected", decoded); } @Test(expected = IllegalArgumentException.class) public void shouldFailForNullParameter() { - InputStream is = null; + final InputStream is = null; StreamUtils.getStreamContents(is); fail("Must throw exception before getting here"); } From 84ea4a3e3d81e521612b01be175e69b04fe91ea6 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 25 Jan 2016 13:45:00 +0300 Subject: [PATCH 099/882] add checkstyle rules, fix MissingSwitchDefault --- checkstyle.xml | 13 +++++++++++++ .../scribejava/core/oauth/OAuth10aService.java | 2 ++ 2 files changed, 15 insertions(+) diff --git a/checkstyle.xml b/checkstyle.xml index 527132d23..8581838ea 100644 --- a/checkstyle.xml +++ b/checkstyle.xml @@ -31,5 +31,18 @@ + + + + + + + + + + + + + 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 94f627ef5..927038bab 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 @@ -174,6 +174,8 @@ private void appendSignature(AbstractRequest request) { request.addQuerystringParameter(entry.getKey(), entry.getValue()); } break; + default: + throw new IllegalStateException("Unknown new Signature Type '" + config.getSignatureType() + "'."); } } From c1fda98635048365f64eebd67c405ef66e037157 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 25 Jan 2016 13:54:26 +0300 Subject: [PATCH 100/882] add checkstyle rules, fix UnnecessaryParentheses --- checkstyle.xml | 10 ++++++++++ .../apis/service/OdnoklassnikiServiceImpl.java | 2 +- .../com/github/scribejava/core/oauth/OAuthService.java | 2 +- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/checkstyle.xml b/checkstyle.xml index 8581838ea..c78862916 100644 --- a/checkstyle.xml +++ b/checkstyle.xml @@ -44,5 +44,15 @@ + + + + + + + + + + diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiServiceImpl.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiServiceImpl.java index eea23a9f2..ddd5bc32b 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiServiceImpl.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiServiceImpl.java @@ -20,7 +20,7 @@ public OdnoklassnikiServiceImpl(DefaultApi20 api, OAuthConfig config) { public void signRequest(Token accessToken, AbstractRequest request) { // sig = md5( request_params_composed_string+ md5(access_token + application_secret_key) ) try { - final String tokenDigest = md5Hex((accessToken.getToken() + getConfig().getApiSecret())); + final String tokenDigest = md5Hex(accessToken.getToken() + getConfig().getApiSecret()); final String completeUrl = request.getCompleteUrl(); final int queryIndex = completeUrl.indexOf('?'); diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java index c8f209e94..193061a6b 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java @@ -35,7 +35,7 @@ public OAuthService(OAuthConfig config) { if (ForceTypeOfHttpRequest.PREFER_SYNC_ONLY_HTTP_REQUESTS == forceTypeOfHttpRequest) { config.log("Cannot use async operations, only sync"); } - final OAuthConfigAsync asyncConfig = ((OAuthConfigAsync) config); + final OAuthConfigAsync asyncConfig = (OAuthConfigAsync) config; final String asyncHttpProviderClassName = asyncConfig.getAsyncHttpProviderClassName(); asyncHttpClient = asyncHttpProviderClassName == null ? new AsyncHttpClient(asyncConfig.getAsyncHttpClientConfig()) From 8049d61fd5716fce82f5f41ac1bd0a94e1425f8b Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 25 Jan 2016 13:59:42 +0300 Subject: [PATCH 101/882] add checkstyle rules, fix ArrayTypeStyle --- checkstyle.xml | 7 +++++++ .../com/github/scribejava/core/model/ParameterList.java | 2 +- .../com/github/scribejava/core/utils/OAuthEncoderTest.java | 4 ++-- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/checkstyle.xml b/checkstyle.xml index c78862916..b1499a53c 100644 --- a/checkstyle.xml +++ b/checkstyle.xml @@ -54,5 +54,12 @@ + + + + + + + diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/ParameterList.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/ParameterList.java index 52bea2266..7ae849780 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/ParameterList.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/ParameterList.java @@ -73,7 +73,7 @@ public void addAll(ParameterList other) { public void addQuerystring(String queryString) { if (queryString != null && queryString.length() > 0) { for (String param : queryString.split(PARAM_SEPARATOR)) { - final String pair[] = param.split(PAIR_SEPARATOR); + final String[] pair = param.split(PAIR_SEPARATOR); final String key = OAuthEncoder.decode(pair[0]); final String value = pair.length > 1 ? OAuthEncoder.decode(pair[1]) : EMPTY_STRING; params.add(new Parameter(key, value)); 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 84799c709..59229db99 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 @@ -53,8 +53,8 @@ public void shouldThrowExceptionIfStringToDecodeIsNull() { @Test public void shouldPercentEncodeCorrectlyTwitterCodingExamples() { // These tests are part of the Twitter dev examples here -> https://dev.twitter.com/docs/auth/percent-encoding-parameters - final String sources[] = {"Ladies + Gentlemen", "An encoded string!", "Dogs, Cats & Mice"}; - final String encoded[] = {"Ladies%20%2B%20Gentlemen", "An%20encoded%20string%21", "Dogs%2C%20Cats%20%26%20Mice"}; + final String[] sources = {"Ladies + Gentlemen", "An encoded string!", "Dogs, Cats & Mice"}; + final String[] encoded = {"Ladies%20%2B%20Gentlemen", "An%20encoded%20string%21", "Dogs%2C%20Cats%20%26%20Mice"}; for (int i = 0; i < sources.length; i++) { Assert.assertEquals(encoded[i], OAuthEncoder.encode(sources[i])); From 6df23c1262ef16b539af7b0ac18d1da7bafbc694 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 25 Jan 2016 14:08:41 +0300 Subject: [PATCH 102/882] add checkstyle rules, fix RedundantModifier --- checkstyle.xml | 24 +++++++++++++++++++ .../core/extractors/AccessTokenExtractor.java | 2 +- .../extractors/RequestTokenExtractor.java | 2 +- .../core/services/TimestampService.java | 4 ++-- .../scribejava/core/model/ResponseTest.java | 2 +- 5 files changed, 29 insertions(+), 5 deletions(-) diff --git a/checkstyle.xml b/checkstyle.xml index b1499a53c..28369fed4 100644 --- a/checkstyle.xml +++ b/checkstyle.xml @@ -61,5 +61,29 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/AccessTokenExtractor.java b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/AccessTokenExtractor.java index dcf7b1657..ec14ca2f1 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/AccessTokenExtractor.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/AccessTokenExtractor.java @@ -15,5 +15,5 @@ public interface AccessTokenExtractor { * @param response the contents of the response * @return OAuth access token */ - public Token extract(String response); + Token extract(String response); } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/RequestTokenExtractor.java b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/RequestTokenExtractor.java index bc054713c..bc518c617 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/RequestTokenExtractor.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/RequestTokenExtractor.java @@ -15,5 +15,5 @@ public interface RequestTokenExtractor { * @param response the contents of the response * @return OAuth access token */ - public Token extract(String response); + Token extract(String response); } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/services/TimestampService.java b/scribejava-core/src/main/java/com/github/scribejava/core/services/TimestampService.java index fca170c83..42e97fc4f 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/services/TimestampService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/services/TimestampService.java @@ -14,12 +14,12 @@ public interface TimestampService { * * @return timestamp */ - public String getTimestampInSeconds(); + String getTimestampInSeconds(); /** * Returns a nonce (unique value for each request) * * @return nonce */ - public String getNonce(); + String getNonce(); } diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/model/ResponseTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/model/ResponseTest.java index 32926e8bb..ad84a0745 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/model/ResponseTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/model/ResponseTest.java @@ -49,7 +49,7 @@ public void shouldHandleAConnectionWithErrors() throws Exception { private static class FaultyConnection extends ConnectionStub { - public FaultyConnection() throws Exception { + private FaultyConnection() throws Exception { super(); } From 6905cdcc02b6c6e7c6fff9673aed8d63250d30a1 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 25 Jan 2016 14:19:01 +0300 Subject: [PATCH 103/882] add checkstyle rules, fix RegexpSingleline (check to find trailing whitespace at the end of a line) --- checkstyle.xml | 19 +++++++++++++++++++ .../apis/examples/AWeberExample.java | 2 +- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/checkstyle.xml b/checkstyle.xml index 28369fed4..2f07ffb50 100644 --- a/checkstyle.xml +++ b/checkstyle.xml @@ -81,9 +81,28 @@ + + + + + + + + + + + + + + + + + + + diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AWeberExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AWeberExample.java index daf08eb74..1bc8f0279 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AWeberExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AWeberExample.java @@ -12,7 +12,7 @@ public abstract class AWeberExample { - //To get your consumer key/secret, and view API docs, see https://labs.aweber.com/docs + //To get your consumer key/secret, and view API docs, see https://labs.aweber.com/docs private static final String ACCOUNT_RESOURCE_URL = "https://api.aweber.com/1.0/accounts/"; private static final String CONSUMER_KEY = ""; From 3a012b9f68e1f66223629170f5211bfb23ef47b5 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 25 Jan 2016 14:38:59 +0300 Subject: [PATCH 104/882] add and fix checkstyle rule LineLength --- checkstyle.xml | 4 ++ .../scribejava/apis/ConstantContactApi.java | 3 +- .../scribejava/apis/ConstantContactApi2.java | 9 +++-- .../scribejava/apis/DoktornaraboteApi.java | 3 +- .../github/scribejava/apis/FacebookApi.java | 7 ++-- .../scribejava/apis/Foursquare2Api.java | 6 ++- .../github/scribejava/apis/FreelancerApi.java | 3 +- .../com/github/scribejava/apis/GitHubApi.java | 6 ++- .../com/github/scribejava/apis/GoogleApi.java | 3 +- .../com/github/scribejava/apis/HHApi.java | 3 +- .../github/scribejava/apis/KaixinApi20.java | 7 ++-- .../github/scribejava/apis/LinkedInApi20.java | 14 ++++--- .../com/github/scribejava/apis/LiveApi.java | 10 +++-- .../com/github/scribejava/apis/MailruApi.java | 10 +++-- .../scribejava/apis/NeteaseWeibooApi.java | 12 ++++-- .../scribejava/apis/OdnoklassnikiApi.java | 10 +++-- .../github/scribejava/apis/PinterestApi.java | 10 +++-- .../com/github/scribejava/apis/RenrenApi.java | 7 ++-- .../scribejava/apis/SinaWeiboApi20.java | 7 ++-- .../com/github/scribejava/apis/TutByApi.java | 6 ++- .../com/github/scribejava/apis/ViadeoApi.java | 10 +++-- .../github/scribejava/apis/VkontakteApi.java | 10 +++-- .../scribejava/apis/google/GoogleToken.java | 6 ++- .../service/OdnoklassnikiServiceImpl.java | 4 +- .../apis/examples/Foursquare2Example.java | 6 ++- .../apis/examples/LinkedIn20Example.java | 3 +- .../scribejava/apis/examples/LiveExample.java | 6 ++- .../apis/examples/MailruAsyncExample.java | 3 +- .../apis/examples/MailruExample.java | 3 +- .../apis/examples/OdnoklassnikiExample.java | 3 +- .../apis/examples/PinterestExample.java | 3 +- .../apis/examples/TumblrExample.java | 3 +- .../core/builder/ServiceBuilder.java | 4 +- .../core/builder/ServiceBuilderAsync.java | 4 +- .../core/builder/api/DefaultApi10a.java | 10 +++-- .../core/builder/api/DefaultApi20.java | 10 +++-- .../core/model/AbstractRequest.java | 7 ++-- .../core/model/OAuthRequestAsync.java | 7 ++-- .../scribejava/core/model/Response.java | 6 ++- .../core/oauth/OAuth10aService.java | 13 ++++--- .../scribejava/core/oauth/OAuth20Service.java | 22 ++++++----- .../scribejava/core/oauth/OAuthService.java | 13 ++++--- .../github/scribejava/core/ObjectMother.java | 24 ++++++------ .../extractors/BaseStringExtractorTest.java | 39 +++++++++++-------- .../core/extractors/HeaderExtractorTest.java | 14 ++++--- .../core/extractors/TokenExtractor20Test.java | 12 ++++-- .../core/extractors/TokenExtractorTest.java | 3 +- .../model/ForceTypeOfHttpRequestTest.java | 6 ++- .../core/model/OAuthRequestTest.java | 3 +- .../scribejava/core/model/RequestTest.java | 3 +- .../services/RSASha1SignatureServiceTest.java | 8 ++-- .../core/utils/OAuthEncoderTest.java | 6 ++- 52 files changed, 252 insertions(+), 162 deletions(-) diff --git a/checkstyle.xml b/checkstyle.xml index 2f07ffb50..b31e3f75c 100644 --- a/checkstyle.xml +++ b/checkstyle.xml @@ -95,6 +95,10 @@ + + + + diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/ConstantContactApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/ConstantContactApi.java index 842c4cdca..f40583e5e 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/ConstantContactApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/ConstantContactApi.java @@ -5,7 +5,8 @@ public class ConstantContactApi extends DefaultApi10a { - private static final String AUTHORIZE_URL = "https://oauth.constantcontact.com/ws/oauth/confirm_access?oauth_token=%s"; + private static final String AUTHORIZE_URL + = "https://oauth.constantcontact.com/ws/oauth/confirm_access?oauth_token=%s"; private ConstantContactApi() { } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/ConstantContactApi2.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/ConstantContactApi2.java index fe443c9f6..62b2aaa19 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/ConstantContactApi2.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/ConstantContactApi2.java @@ -16,12 +16,14 @@ public class ConstantContactApi2 extends DefaultApi20 { private static final String AUTHORIZE_URL - = "https://oauth2.constantcontact.com/oauth2/oauth/siteowner/authorize?client_id=%s&response_type=code&redirect_uri=%s"; + = "https://oauth2.constantcontact.com/oauth2/oauth/siteowner/authorize?client_id=%s&response_type=code" + + "&redirect_uri=%s"; private static final AccessTokenExtractor ACCESS_TOKEN_EXTRACTOR = new AccessTokenExtractor() { @Override public Token extract(String response) { - Preconditions.checkEmptyString(response, "Response body is incorrect. Can't extract a token from an empty string"); + Preconditions.checkEmptyString(response, + "Response body is incorrect. Can't extract a token from an empty string"); final String regex = "\"access_token\"\\s*:\\s*\"([^&\"]+)\""; final Matcher matcher = Pattern.compile(regex).matcher(response); @@ -29,7 +31,8 @@ public Token extract(String response) { final String token = OAuthEncoder.decode(matcher.group(1)); return new Token(token, "", response); } else { - throw new OAuthException("Response body is incorrect. Can't extract a token from this: '" + response + "'", null); + throw new OAuthException("Response body is incorrect. Can't extract a token from this: '" + + response + "'", null); } } }; diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/DoktornaraboteApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/DoktornaraboteApi.java index 104c731a3..cb592e36f 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/DoktornaraboteApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/DoktornaraboteApi.java @@ -13,7 +13,8 @@ public class DoktornaraboteApi extends DefaultApi20 { - private static final String AUTHORIZE_URL = "http://auth.doktornarabote.ru/OAuth/Authorize?response_type=code&client_id=%s&redirect_uri=%s&scope=%s"; + private static final String AUTHORIZE_URL + = "http://auth.doktornarabote.ru/OAuth/Authorize?response_type=code&client_id=%s&redirect_uri=%s&scope=%s"; private static final String TOKEN_URL = "http://auth.doktornarabote.ru/OAuth/Token"; private DoktornaraboteApi() { 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 b3d21f2e8..b7b327ddd 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java @@ -8,7 +8,8 @@ public class FacebookApi extends DefaultApi20 { - private static final String AUTHORIZE_URL = "https://www.facebook.com/v2.2/dialog/oauth?client_id=%s&redirect_uri=%s"; + private static final String AUTHORIZE_URL + = "https://www.facebook.com/v2.2/dialog/oauth?client_id=%s&redirect_uri=%s"; private FacebookApi() { } @@ -30,8 +31,8 @@ public String getAccessTokenEndpoint() { public String getAuthorizationUrl(OAuthConfig config) { Preconditions.checkValidUrl(config.getCallback(), "Must provide a valid url as callback. Facebook does not support OOB"); - final StringBuilder sb = new StringBuilder(String.format(AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode( - config.getCallback()))); + final StringBuilder sb = new StringBuilder(String.format(AUTHORIZE_URL, config.getApiKey(), + OAuthEncoder.encode(config.getCallback()))); if (config.hasScope()) { sb.append('&').append(OAuthConstants.SCOPE).append('=').append(OAuthEncoder.encode(config.getScope())); } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/Foursquare2Api.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/Foursquare2Api.java index 52328c0e3..fee771bd8 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/Foursquare2Api.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/Foursquare2Api.java @@ -10,7 +10,8 @@ public class Foursquare2Api extends DefaultApi20 { - private static final String AUTHORIZATION_URL = "https://foursquare.com/oauth2/authenticate?client_id=%s&response_type=code&redirect_uri=%s"; + private static final String AUTHORIZATION_URL + = "https://foursquare.com/oauth2/authenticate?client_id=%s&response_type=code&redirect_uri=%s"; private Foursquare2Api() { } @@ -30,7 +31,8 @@ public String getAccessTokenEndpoint() { @Override public String getAuthorizationUrl(OAuthConfig config) { - Preconditions.checkValidUrl(config.getCallback(), "Must provide a valid url as callback. Foursquare2 does not support OOB"); + Preconditions.checkValidUrl(config.getCallback(), + "Must provide a valid url as callback. Foursquare2 does not support OOB"); return String.format(AUTHORIZATION_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback())); } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/FreelancerApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/FreelancerApi.java index 2ccee3d59..ea171d2bb 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/FreelancerApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/FreelancerApi.java @@ -46,7 +46,8 @@ public String getAuthorizationUrl(Token requestToken) { public static class Sandbox extends FreelancerApi { - private static final String SANDBOX_AUTHORIZATION_URL = "http://www.sandbox.freelancer.com/users/api-token/auth.php"; + private static final String SANDBOX_AUTHORIZATION_URL + = "http://www.sandbox.freelancer.com/users/api-token/auth.php"; private Sandbox() { } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/GitHubApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/GitHubApi.java index 491f5f852..6b15f8233 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/GitHubApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/GitHubApi.java @@ -28,8 +28,10 @@ public String getAccessTokenEndpoint() { @Override public String getAuthorizationUrl(OAuthConfig config) { - Preconditions.checkValidUrl(config.getCallback(), "Must provide a valid url as callback. GitHub does not support OOB"); - final StringBuilder sb = new StringBuilder(String.format(AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()))); + Preconditions.checkValidUrl(config.getCallback(), + "Must provide a valid url as callback. GitHub does not support OOB"); + final StringBuilder sb = new StringBuilder(String.format(AUTHORIZE_URL, config.getApiKey(), + OAuthEncoder.encode(config.getCallback()))); if (config.hasScope()) { sb.append('&').append(OAuthConstants.SCOPE).append('=').append(OAuthEncoder.encode(config.getScope())); } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/GoogleApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/GoogleApi.java index aa293c693..6191aeb43 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/GoogleApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/GoogleApi.java @@ -6,7 +6,8 @@ public class GoogleApi extends DefaultApi10a { - private static final String AUTHORIZATION_URL = "https://www.google.com/accounts/OAuthAuthorizeToken?oauth_token=%s"; + private static final String AUTHORIZATION_URL + = "https://www.google.com/accounts/OAuthAuthorizeToken?oauth_token=%s"; private GoogleApi() { } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/HHApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/HHApi.java index 0325eddbc..228b4ae10 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/HHApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/HHApi.java @@ -13,7 +13,8 @@ public class HHApi extends DefaultApi20 { private static final String AUTHORIZE_URL = "https://m.hh.ru/oauth/authorize?response_type=code&client_id=%s"; - private static final String TOKEN_URL = "https://m.hh.ru/oauth/token?grant_type=" + OAuthConstants.AUTHORIZATION_CODE; + private static final String TOKEN_URL = "https://m.hh.ru/oauth/token?grant_type=" + + OAuthConstants.AUTHORIZATION_CODE; private HHApi() { } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/KaixinApi20.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/KaixinApi20.java index 8c526cb1f..86223a3cb 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/KaixinApi20.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/KaixinApi20.java @@ -12,7 +12,8 @@ */ public class KaixinApi20 extends DefaultApi20 { - private static final String AUTHORIZE_URL = "http://api.kaixin001.com/oauth2/authorize?client_id=%s&redirect_uri=%s&response_type=code"; + private static final String AUTHORIZE_URL + = "http://api.kaixin001.com/oauth2/authorize?client_id=%s&redirect_uri=%s&response_type=code"; private static final String SCOPED_AUTHORIZE_URL = AUTHORIZE_URL + "&scope=%s"; private KaixinApi20() { @@ -40,8 +41,8 @@ public String getAccessTokenEndpoint() { public String getAuthorizationUrl(OAuthConfig config) { // Append scope if present if (config.hasScope()) { - return String.format(SCOPED_AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()), OAuthEncoder.encode(config. - getScope())); + return String.format(SCOPED_AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()), + OAuthEncoder.encode(config.getScope())); } else { return String.format(AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback())); } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi20.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi20.java index 11603e3d8..fd6c271fb 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi20.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi20.java @@ -14,7 +14,8 @@ public class LinkedInApi20 extends DefaultApi20 { private static final String AUTHORIZE_URL - = "https://www.linkedin.com/uas/oauth2/authorization?response_type=code&client_id=%s&redirect_uri=%s&" + OAuthConstants.STATE + "=%s"; + = "https://www.linkedin.com/uas/oauth2/authorization?response_type=code&client_id=%s&redirect_uri=%s&" + + OAuthConstants.STATE + "=%s"; private static final String SCOPED_AUTHORIZE_URL = AUTHORIZE_URL + "&scope=%s"; @@ -41,14 +42,15 @@ public String getAccessTokenEndpoint() { @Override public String getAuthorizationUrl(OAuthConfig config) { - Preconditions.checkValidUrl(config.getCallback(), "Must provide a valid url as callback. LinkedIn does not support OOB"); + Preconditions.checkValidUrl(config.getCallback(), + "Must provide a valid url as callback. LinkedIn does not support OOB"); if (config.hasScope()) { - return String.format( - SCOPED_AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()), config.getState(), OAuthEncoder.encode( - config.getScope())); + return String.format(SCOPED_AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()), + config.getState(), OAuthEncoder.encode(config.getScope())); } else { - return String.format(AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()), config.getState()); + return String.format(AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()), + config.getState()); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/LiveApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/LiveApi.java index f1b7083e7..d6384e0f3 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/LiveApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/LiveApi.java @@ -10,7 +10,8 @@ public class LiveApi extends DefaultApi20 { - private static final String AUTHORIZE_URL = "https://oauth.live.com/authorize?client_id=%s&redirect_uri=%s&response_type=code"; + private static final String AUTHORIZE_URL + = "https://oauth.live.com/authorize?client_id=%s&redirect_uri=%s&response_type=code"; private static final String SCOPED_AUTHORIZE_URL = AUTHORIZE_URL + "&scope=%s"; private LiveApi() { @@ -31,12 +32,13 @@ public String getAccessTokenEndpoint() { @Override public String getAuthorizationUrl(OAuthConfig config) { - Preconditions.checkValidUrl(config.getCallback(), "Must provide a valid url as callback. Live does not support OOB"); + Preconditions.checkValidUrl(config.getCallback(), + "Must provide a valid url as callback. Live does not support OOB"); // Append scope if present if (config.hasScope()) { - return String.format(SCOPED_AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()), OAuthEncoder.encode(config. - getScope())); + return String.format(SCOPED_AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()), + OAuthEncoder.encode(config.getScope())); } else { return String.format(AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback())); } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java index 19e462cc5..0348cceef 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java @@ -12,7 +12,8 @@ public class MailruApi extends DefaultApi20 { - private static final String AUTHORIZE_URL = "https://connect.mail.ru/oauth/authorize?client_id=%s&redirect_uri=%s&response_type=code"; + private static final String AUTHORIZE_URL + = "https://connect.mail.ru/oauth/authorize?client_id=%s&redirect_uri=%s&response_type=code"; private static final String SCOPED_AUTHORIZE_URL = AUTHORIZE_URL + "&scope=%s"; private MailruApi() { @@ -38,10 +39,11 @@ public String getAccessTokenEndpoint() { @Override public String getAuthorizationUrl(OAuthConfig config) { - Preconditions.checkValidUrl(config.getCallback(), "Valid url is required for a callback. Mail.ru does not support OOB"); + Preconditions.checkValidUrl(config.getCallback(), + "Valid url is required for a callback. Mail.ru does not support OOB"); if (config.hasScope()) { // Appending scope if present - return String.format(SCOPED_AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()), OAuthEncoder.encode(config. - getScope())); + return String.format(SCOPED_AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()), + OAuthEncoder.encode(config.getScope())); } else { return String.format(AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback())); } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/NeteaseWeibooApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/NeteaseWeibooApi.java index b1771d04f..5b85113a0 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/NeteaseWeibooApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/NeteaseWeibooApi.java @@ -33,18 +33,22 @@ public String getAccessTokenEndpoint() { @Override /** - * this method will ignore your callback if you're creating a desktop client please choose this url else your can call getAuthenticateUrl + * this method will ignore your callback if you're creating a desktop client please choose this url else your can + * call getAuthenticateUrl * - * via http://open.t.163.com/wiki/index.php?title=%E8%AF%B7%E6%B1%82%E7%94%A8%E6%88%B7%E6%8E%88%E6%9D%83Token(oauth/authorize) + * via + * http://open.t.163.com/wiki/index.php?title=%E8%AF%B7%E6%B1%82%E7%94%A8%E6%88%B7%E6%8E%88%E6%9D%83Token(oauth/authorize) */ public String getAuthorizationUrl(Token requestToken) { return String.format(AUTHORIZE_URL, requestToken.getToken()); } /** - * this method is for web client with callback url if you're creating a desktop client please call getAuthorizationUrl + * this method is for web client with callback url if you're creating a desktop client please call + * getAuthorizationUrl * - * via http://open.t.163.com/wiki/index.php?title=%E8%AF%B7%E6%B1%82%E7%94%A8%E6%88%B7%E6%8E%88%E6%9D%83Token(oauth/authenticate) + * via + * http://open.t.163.com/wiki/index.php?title=%E8%AF%B7%E6%B1%82%E7%94%A8%E6%88%B7%E6%8E%88%E6%9D%83Token(oauth/authenticate) * * @param requestToken Token * @return String diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java index c92a6dd56..bd3717bb4 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java @@ -12,7 +12,8 @@ public class OdnoklassnikiApi extends DefaultApi20 { - private static final String AUTHORIZE_URL = "http://www.odnoklassniki.ru/oauth/authorize?client_id=%s&response_type=code&redirect_uri=%s"; + private static final String AUTHORIZE_URL + = "http://www.odnoklassniki.ru/oauth/authorize?client_id=%s&response_type=code&redirect_uri=%s"; private static final String SCOPED_AUTHORIZE_URL = String.format("%s&scope=%%s", AUTHORIZE_URL); private OdnoklassnikiApi() { @@ -38,10 +39,11 @@ public Verb getAccessTokenVerb() { @Override public String getAuthorizationUrl(OAuthConfig config) { - Preconditions.checkValidUrl(config.getCallback(), "Valid url is required for a callback. Odnoklassniki does not support OOB"); + Preconditions.checkValidUrl(config.getCallback(), + "Valid url is required for a callback. Odnoklassniki does not support OOB"); if (config.hasScope()) { - return String.format( - SCOPED_AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()), OAuthEncoder.encode(config.getScope())); + return String.format(SCOPED_AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()), + OAuthEncoder.encode(config.getScope())); } else { return String.format(AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback())); } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/PinterestApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/PinterestApi.java index f67f986ad..92fd91917 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/PinterestApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/PinterestApi.java @@ -11,7 +11,8 @@ public class PinterestApi extends DefaultApi20 { - private static final String AUTHORIZE_URL = "https://api.pinterest.com/oauth?response_type=code&client_id=%s&redirect_uri=%s"; + private static final String AUTHORIZE_URL + = "https://api.pinterest.com/oauth?response_type=code&client_id=%s&redirect_uri=%s"; private static final String SCOPED_AUTHORIZE_URL = AUTHORIZE_URL + "&scope=%s"; private PinterestApi() { @@ -37,12 +38,13 @@ public Verb getAccessTokenVerb() { @Override public String getAuthorizationUrl(OAuthConfig config) { - Preconditions.checkValidUrl(config.getCallback(), "Must provide a valid url as callback. Pinterest does not support OOB"); + Preconditions.checkValidUrl(config.getCallback(), + "Must provide a valid url as callback. Pinterest does not support OOB"); // Append scope if present if (config.hasScope()) { - return String.format(SCOPED_AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()), OAuthEncoder.encode(config. - getScope())); + return String.format(SCOPED_AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()), + OAuthEncoder.encode(config.getScope())); } else { return String.format(AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback())); } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/RenrenApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/RenrenApi.java index 0a4545b15..3128d5a3d 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/RenrenApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/RenrenApi.java @@ -12,7 +12,8 @@ */ public class RenrenApi extends DefaultApi20 { - private static final String AUTHORIZE_URL = "https://graph.renren.com/oauth/authorize?client_id=%s&redirect_uri=%s&response_type=code"; + private static final String AUTHORIZE_URL + = "https://graph.renren.com/oauth/authorize?client_id=%s&redirect_uri=%s&response_type=code"; private static final String SCOPED_AUTHORIZE_URL = AUTHORIZE_URL + "&scope=%s"; private RenrenApi() { @@ -40,8 +41,8 @@ public String getAccessTokenEndpoint() { public String getAuthorizationUrl(OAuthConfig config) { // Append scope if present if (config.hasScope()) { - return String.format(SCOPED_AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()), OAuthEncoder.encode(config. - getScope())); + return String.format(SCOPED_AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()), + OAuthEncoder.encode(config.getScope())); } else { return String.format(AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback())); } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/SinaWeiboApi20.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/SinaWeiboApi20.java index be01534b2..06a7e8114 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/SinaWeiboApi20.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/SinaWeiboApi20.java @@ -13,7 +13,8 @@ */ public class SinaWeiboApi20 extends DefaultApi20 { - private static final String AUTHORIZE_URL = "https://api.weibo.com/oauth2/authorize?client_id=%s&redirect_uri=%s&response_type=code"; + private static final String AUTHORIZE_URL + = "https://api.weibo.com/oauth2/authorize?client_id=%s&redirect_uri=%s&response_type=code"; private static final String SCOPED_AUTHORIZE_URL = AUTHORIZE_URL + "&scope=%s"; private SinaWeiboApi20() { @@ -46,8 +47,8 @@ public String getAccessTokenEndpoint() { public String getAuthorizationUrl(OAuthConfig config) { // Append scope if present if (config.hasScope()) { - return String.format(SCOPED_AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()), OAuthEncoder.encode(config. - getScope())); + return String.format(SCOPED_AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()), + OAuthEncoder.encode(config.getScope())); } else { return String.format(AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback())); } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/TutByApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/TutByApi.java index 944fdf858..00704b792 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/TutByApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/TutByApi.java @@ -12,7 +12,8 @@ public class TutByApi extends DefaultApi20 { - private static final String AUTHORIZE_URL = "http://profile.tut.by/auth?client_id=%s&response_type=code&redirect_uri=%s"; + private static final String AUTHORIZE_URL + = "http://profile.tut.by/auth?client_id=%s&response_type=code&redirect_uri=%s"; private TutByApi() { } @@ -37,7 +38,8 @@ public Verb getAccessTokenVerb() { @Override public String getAuthorizationUrl(OAuthConfig config) { - Preconditions.checkValidUrl(config.getCallback(), "Valid url is required for a callback. Tut.by does not support OOB"); + Preconditions.checkValidUrl(config.getCallback(), + "Valid url is required for a callback. Tut.by does not support OOB"); return String.format(AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback())); } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/ViadeoApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/ViadeoApi.java index a3f50bf30..b36a451e9 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/ViadeoApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/ViadeoApi.java @@ -10,7 +10,8 @@ public class ViadeoApi extends DefaultApi20 { - private static final String AUTHORIZE_URL = "https://secure.viadeo.com/oauth-provider/authorize2?client_id=%s&redirect_uri=%s&response_type=code"; + private static final String AUTHORIZE_URL + = "https://secure.viadeo.com/oauth-provider/authorize2?client_id=%s&redirect_uri=%s&response_type=code"; private static final String SCOPED_AUTHORIZE_URL = AUTHORIZE_URL + "&scope=%s"; private ViadeoApi() { @@ -36,12 +37,13 @@ public String getAccessTokenEndpoint() { @Override public String getAuthorizationUrl(OAuthConfig config) { - Preconditions.checkValidUrl(config.getCallback(), "Must provide a valid url as callback. Viadeo does not support OOB"); + Preconditions.checkValidUrl(config.getCallback(), + "Must provide a valid url as callback. Viadeo does not support OOB"); // Append scope if present if (config.hasScope()) { - return String.format(SCOPED_AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()), OAuthEncoder.encode(config. - getScope())); + return String.format(SCOPED_AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()), + OAuthEncoder.encode(config.getScope())); } else { return String.format(AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback())); } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/VkontakteApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/VkontakteApi.java index 8f6ae8764..5df5ebfee 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/VkontakteApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/VkontakteApi.java @@ -13,7 +13,8 @@ */ public class VkontakteApi extends DefaultApi20 { - private static final String AUTHORIZE_URL = "https://oauth.vk.com/authorize?client_id=%s&redirect_uri=%s&response_type=code"; + private static final String AUTHORIZE_URL + = "https://oauth.vk.com/authorize?client_id=%s&redirect_uri=%s&response_type=code"; private static final String SCOPED_AUTHORIZE_URL = String.format("%s&scope=%%s", AUTHORIZE_URL); private VkontakteApi() { @@ -34,10 +35,11 @@ public String getAccessTokenEndpoint() { @Override public String getAuthorizationUrl(OAuthConfig config) { - Preconditions.checkValidUrl(config.getCallback(), "Valid url is required for a callback. Vkontakte does not support OOB"); + Preconditions.checkValidUrl(config.getCallback(), + "Valid url is required for a callback. Vkontakte does not support OOB"); if (config.hasScope()) { // Appending scope if present - return String.format( - SCOPED_AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()), OAuthEncoder.encode(config.getScope())); + return String.format(SCOPED_AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()), + OAuthEncoder.encode(config.getScope())); } else { return String.format(AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback())); } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/google/GoogleToken.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/google/GoogleToken.java index 7605b60b9..ade166144 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/google/GoogleToken.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/google/GoogleToken.java @@ -5,8 +5,10 @@ public class GoogleToken extends Token { /** - * Id_token is part of OpenID Connect specification. It can hold user information that you can directly extract without additional request to - * provider. See http://openid.net/specs/openid-connect-core-1_0.html#id_token-tokenExample and + * Id_token is part of OpenID Connect specification. It can hold user information that you can directly extract + * without additional request to provider. + * + * See http://openid.net/specs/openid-connect-core-1_0.html#id_token-tokenExample and * https://bitbucket.org/nimbusds/nimbus-jose-jwt/wiki/Home * * Here will be encoded and signed id token in JWT format or null, if not defined. diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiServiceImpl.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiServiceImpl.java index ddd5bc32b..d247075a7 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiServiceImpl.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiServiceImpl.java @@ -25,7 +25,9 @@ public void signRequest(Token accessToken, AbstractRequest request) { final String completeUrl = request.getCompleteUrl(); final int queryIndex = completeUrl.indexOf('?'); if (queryIndex != -1) { - final String sigSource = URLDecoder.decode(completeUrl.substring(queryIndex + 1).replace("&", ""), CharEncoding.UTF_8) + tokenDigest; + final String sigSource + = URLDecoder.decode(completeUrl.substring(queryIndex + 1).replace("&", ""), CharEncoding.UTF_8) + + tokenDigest; request.addQuerystringParameter("sig", md5Hex(sigSource)); } diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java index c8041fdeb..13e0f8a1c 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java @@ -12,7 +12,8 @@ public abstract class Foursquare2Example { - private static final String PROTECTED_RESOURCE_URL = "https://api.foursquare.com/v2/users/self/friends?oauth_token="; + private static final String PROTECTED_RESOURCE_URL + = "https://api.foursquare.com/v2/users/self/friends?oauth_token="; private static final Token EMPTY_TOKEN = null; public static void main(String... args) { @@ -49,7 +50,8 @@ public static void main(String... args) { // Now let's go and ask for a protected resource! System.out.println("Now we're going to access a protected resource..."); - final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL + accessToken.getToken(), service); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL + accessToken.getToken(), + service); service.signRequest(accessToken, request); final Response response = request.send(); System.out.println("Got it! Lets see what we found..."); 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 50be9536c..a4e5a4f48 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 @@ -57,7 +57,8 @@ public static void main(String... args) { final String query = in.nextLine(); System.out.println(); - final OAuthRequest request = new OAuthRequest(Verb.GET, String.format(PROTECTED_RESOURCE_URL, query), service); + final OAuthRequest request = new OAuthRequest(Verb.GET, String.format(PROTECTED_RESOURCE_URL, query), + service); request.addHeader("x-li-format", "json"); request.addHeader("Accept-Language", "ru-RU"); service.signRequest(accessToken, request); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java index 97ea7027c..745801b6e 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java @@ -12,7 +12,8 @@ public abstract class LiveExample { - private static final String PROTECTED_RESOURCE_URL = "https://api.foursquare.com/v2/users/self/friends?oauth_token="; + private static final String PROTECTED_RESOURCE_URL + = "https://api.foursquare.com/v2/users/self/friends?oauth_token="; private static final Token EMPTY_TOKEN = null; public static void main(String... args) { @@ -50,7 +51,8 @@ public static void main(String... args) { // Now let's go and ask for a protected resource! System.out.println("Now we're going to access a protected resource..."); - final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL + accessToken.getToken(), service); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL + accessToken.getToken(), + service); service.signRequest(accessToken, request); final Response response = request.send(); System.out.println("Got it! Lets see what we found..."); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java index 3f00ed82a..08d76a96b 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java @@ -15,7 +15,8 @@ public abstract class MailruAsyncExample { private static final String NETWORK_NAME = "Mail.ru"; - private static final String PROTECTED_RESOURCE_URL = "http://www.appsmail.ru/platform/api?method=users.getInfo&secure=1"; + private static final String PROTECTED_RESOURCE_URL + = "http://www.appsmail.ru/platform/api?method=users.getInfo&secure=1"; private static final Token EMPTY_TOKEN = null; public static void main(String... args) throws InterruptedException, ExecutionException { diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java index a3fdbde19..52371659d 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java @@ -13,7 +13,8 @@ public abstract class MailruExample { private static final String NETWORK_NAME = "Mail.ru"; - private static final String PROTECTED_RESOURCE_URL = "http://www.appsmail.ru/platform/api?method=users.getInfo&secure=1"; + private static final String PROTECTED_RESOURCE_URL + = "http://www.appsmail.ru/platform/api?method=users.getInfo&secure=1"; private static final Token EMPTY_TOKEN = null; public static void main(String... args) { diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java index 462cf272d..e5a7d540d 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java @@ -56,7 +56,8 @@ public static void main(String... args) { // 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, String.format(PROTECTED_RESOURCE_URL, publicKey), service); + final OAuthRequest request = new OAuthRequest(Verb.GET, String.format(PROTECTED_RESOURCE_URL, publicKey), + service); service.signRequest(accessToken, request); final Response response = request.send(); System.out.println("Got it! Lets see what we found..."); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java index adac7e668..e07f2bdf1 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java @@ -51,7 +51,8 @@ public static void main(String... args) { // Now let's go and ask for a protected resource! System.out.println("Now we're going to access a protected resource..."); - final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL + accessToken.getToken(), service); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL + accessToken.getToken(), + service); service.signRequest(accessToken, request); final Response response = request.send(); System.out.println("Got it! Lets see what we found..."); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TumblrExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TumblrExample.java index 04c58ed2c..c37481321 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TumblrExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TumblrExample.java @@ -18,7 +18,8 @@ public static void main(String... args) { final OAuthService service = new ServiceBuilder() .apiKey("MY_CONSUMER_KEY") .apiSecret("MY_CONSUMER_SECRET") - .callback("http://www.tumblr.com/connect/login_success.html") // OOB forbidden. We need an url and the better is on the tumblr website ! + // OOB forbidden. We need an url and the better is on the tumblr website ! + .callback("http://www.tumblr.com/connect/login_success.html") .build(TumblrApi.instance()); final Scanner in = new Scanner(System.in); diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilder.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilder.java index 1a32cfcff..9c920e281 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 @@ -29,8 +29,8 @@ public ServiceBuilder readTimeout(Integer readTimeout) { @Override protected OAuthConfig createConfig() { super.checkPreconditions(); - final OAuthConfig config = new OAuthConfig(getApiKey(), getApiSecret(), getCallback(), getSignatureType(), getScope(), getDebugStream(), - connectTimeout, readTimeout, getGrantType()); + final OAuthConfig config = new OAuthConfig(getApiKey(), getApiSecret(), getCallback(), getSignatureType(), + getScope(), getDebugStream(), connectTimeout, readTimeout, getGrantType()); config.setState(getState()); return config; } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilderAsync.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilderAsync.java index 2394f3f1b..6f5a218cb 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilderAsync.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilderAsync.java @@ -24,8 +24,8 @@ public void checkPreconditions() { @Override protected OAuthConfigAsync createConfig() { checkPreconditions(); - final OAuthConfigAsync configAsync = new OAuthConfigAsync(getApiKey(), getApiSecret(), getCallback(), getSignatureType(), getScope(), - getGrantType(), getDebugStream(), asyncHttpClientConfig); + final OAuthConfigAsync configAsync = new OAuthConfigAsync(getApiKey(), getApiSecret(), getCallback(), + getSignatureType(), getScope(), getGrantType(), getDebugStream(), asyncHttpClientConfig); configAsync.setState(getState()); configAsync.setAsyncHttpProviderClassName(asyncHttpProviderClassName); return configAsync; diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi10a.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi10a.java index 90818f91c..f4a436def 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi10a.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi10a.java @@ -19,12 +19,14 @@ /** * Default implementation of the OAuth protocol, version 1.0a * - * This class is meant to be extended by concrete implementations of the API, providing the endpoints and endpoint-http-verbs. + * This class is meant to be extended by concrete implementations of the API, providing the endpoints and + * endpoint-http-verbs. * - * If your Api adheres to the 1.0a protocol correctly, you just need to extend this class and define the getters for your endpoints. + * If your Api adheres to the 1.0a protocol correctly, you just need to extend this class and define the getters for + * your endpoints. * - * If your Api does something a bit different, you can override the different extractors or services, in order to fine-tune the process. Please read - * the javadocs of the interfaces to get an idea of what to do. + * If your Api does something a bit different, you can override the different extractors or services, in order to + * fine-tune the process. Please read the javadocs of the interfaces to get an idea of what to do. * * @author Pablo Fernandez * diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java index f469daa3e..b7ede9211 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java @@ -9,12 +9,14 @@ /** * Default implementation of the OAuth protocol, version 2.0 (draft 11) * - * This class is meant to be extended by concrete implementations of the API, providing the endpoints and endpoint-http-verbs. + * This class is meant to be extended by concrete implementations of the API, providing the endpoints and + * endpoint-http-verbs. * - * If your Api adheres to the 2.0 (draft 11) protocol correctly, you just need to extend this class and define the getters for your endpoints. + * If your Api adheres to the 2.0 (draft 11) protocol correctly, you just need to extend this class and define the + * getters for your endpoints. * - * If your Api does something a bit different, you can override the different extractors or services, in order to fine-tune the process. Please read - * the javadocs of the interfaces to get an idea of what to do. + * If your Api does something a bit different, you can override the different extractors or services, in order to + * fine-tune the process. Please read the javadocs of the interfaces to get an idea of what to do. * * @author Diego Silveira * diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/AbstractRequest.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/AbstractRequest.java index 928ad0573..42f9140d5 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/AbstractRequest.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/AbstractRequest.java @@ -66,7 +66,8 @@ private String checkKey(String key) { return key; } else { throw new IllegalArgumentException( - String.format("OAuth parameters must either be '%s', '%s' or start with '%s'", OAuthConstants.SCOPE, OAuthConstants.REALM, OAUTH_PREFIX)); + String.format("OAuth parameters must either be '%s', '%s' or start with '%s'", OAuthConstants.SCOPE, + OAuthConstants.REALM, OAUTH_PREFIX)); } } @@ -134,8 +135,8 @@ protected boolean hasBodyContent() { } /** - * Add body payload. This method is used when the HTTP body is not a form-url-encoded string, but another thing. Like for example XML. Note: The - * contents are not part of the OAuth signature + * Add body payload. This method is used when the HTTP body is not a form-url-encoded string, but another thing. + * Like for example XML. Note: The contents are not part of the OAuth signature * * @param payload the body of the request */ diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequestAsync.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequestAsync.java index 290be9013..a7dd1dce5 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequestAsync.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequestAsync.java @@ -26,8 +26,8 @@ public Response convert(com.ning.http.client.Response response) throws IOExcepti } headersMap.put(header.getKey(), value.toString()); } - return new Response(response.getStatusCode(), response.getStatusText(), headersMap, response.getResponseBody(), response. - getResponseBodyAsStream()); + return new Response(response.getStatusCode(), response.getStatusText(), headersMap, + response.getResponseBody(), response.getResponseBodyAsStream()); } }; @@ -39,7 +39,8 @@ public Future sendAsync(OAuthAsyncRequestCallback callback, ResponseCo return sendAsync(callback, converter, null); } - public Future sendAsync(OAuthAsyncRequestCallback callback, ResponseConverter converter, ProxyServer proxyServer) { + public Future sendAsync(OAuthAsyncRequestCallback callback, ResponseConverter converter, + ProxyServer proxyServer) { final ForceTypeOfHttpRequest forceTypeOfHttpRequest = ScribeJavaConfig.getForceTypeOfHttpRequests(); if (ForceTypeOfHttpRequest.FORCE_SYNC_ONLY_HTTP_REQUESTS == forceTypeOfHttpRequest) { throw new OAuthException("Cannot use async operations, only sync"); diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/Response.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/Response.java index 5cc8324f2..a8f3098d6 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/Response.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/Response.java @@ -64,7 +64,8 @@ public String getBody() { } /** - * Obtains the meaningful stream of the HttpUrlConnection, either inputStream or errorInputStream, depending on the status code + * Obtains the meaningful stream of the HttpUrlConnection, either inputStream or errorInputStream, depending on the + * status code * * @return input stream / error stream */ @@ -82,7 +83,8 @@ public final int getCode() { } /** - * Obtains the HTTP status message. Returns null if the message can not be discerned from the response (not valid HTTP) + * Obtains the HTTP status message. Returns null if the message can not be discerned from the response + * (not valid HTTP) * * @return the status message */ 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 927038bab..b6af6a211 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 @@ -84,21 +84,24 @@ public Token getAccessToken(Token requestToken, Verifier verifier) { } @Override - public Future getAccessTokenAsync(Token requestToken, Verifier verifier, OAuthAsyncRequestCallback callback) { + public Future getAccessTokenAsync(Token requestToken, Verifier verifier, + OAuthAsyncRequestCallback callback) { return getAccessTokenAsync(requestToken, verifier, callback, null); } @Override - public Future getAccessTokenAsync(Token requestToken, Verifier verifier, OAuthAsyncRequestCallback callback, - ProxyServer proxyServer) { + public Future getAccessTokenAsync(Token requestToken, Verifier verifier, + OAuthAsyncRequestCallback callback, ProxyServer proxyServer) { final OAuthConfig config = getConfig(); config.log("async obtaining access token from " + api.getAccessTokenEndpoint()); - final OAuthRequestAsync request = new OAuthRequestAsync(api.getAccessTokenVerb(), api.getAccessTokenEndpoint(), this); + final OAuthRequestAsync request + = new OAuthRequestAsync(api.getAccessTokenVerb(), api.getAccessTokenEndpoint(), this); prepareAccessTokenRequest(request, requestToken, verifier); return request.sendAsync(callback, new OAuthRequestAsync.ResponseConverter() { @Override public Token convert(com.ning.http.client.Response response) throws IOException { - return getApi().getAccessTokenExtractor().extract(OAuthRequestAsync.RESPONSE_CONVERTER.convert(response).getBody()); + return getApi().getAccessTokenExtractor() + .extract(OAuthRequestAsync.RESPONSE_CONVERTER.convert(response).getBody()); } }, proxyServer); } 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 f93fd521d..89ffb3fd8 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 @@ -32,26 +32,27 @@ public OAuth20Service(DefaultApi20 api, OAuthConfig config) { @Override public Token getAccessToken(Token requestToken, Verifier verifier) { - final Response response = createAccessTokenRequest(verifier, new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint(), this)). - send(); + final Response response = createAccessTokenRequest(verifier, + new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint(), this)).send(); return api.getAccessTokenExtractor().extract(response.getBody()); } @Override - public Future getAccessTokenAsync(Token requestToken, Verifier verifier, OAuthAsyncRequestCallback callback) { + public Future getAccessTokenAsync(Token requestToken, Verifier verifier, + OAuthAsyncRequestCallback callback) { return getAccessTokenAsync(requestToken, verifier, callback, null); } @Override - public Future getAccessTokenAsync(Token requestToken, Verifier verifier, OAuthAsyncRequestCallback callback, - ProxyServer proxyServer) { - final OAuthRequestAsync request = createAccessTokenRequest(verifier, new OAuthRequestAsync(api.getAccessTokenVerb(), api. - getAccessTokenEndpoint(), - this)); + public Future getAccessTokenAsync(Token requestToken, Verifier verifier, + OAuthAsyncRequestCallback callback, ProxyServer proxyServer) { + final OAuthRequestAsync request = createAccessTokenRequest(verifier, + new OAuthRequestAsync(api.getAccessTokenVerb(), api.getAccessTokenEndpoint(), this)); return request.sendAsync(callback, new OAuthRequestAsync.ResponseConverter() { @Override public Token convert(com.ning.http.client.Response response) throws IOException { - return getApi().getAccessTokenExtractor().extract(OAuthRequestAsync.RESPONSE_CONVERTER.convert(response).getBody()); + return getApi().getAccessTokenExtractor() + .extract(OAuthRequestAsync.RESPONSE_CONVERTER.convert(response).getBody()); } }, proxyServer); } @@ -76,7 +77,8 @@ protected T createAccessTokenRequest(Verifier verifi */ @Override public Token getRequestToken() { - throw new UnsupportedOperationException("Unsupported operation, please use 'getAuthorizationUrl' and redirect your users there"); + throw new UnsupportedOperationException("Unsupported operation, please use 'getAuthorizationUrl'" + + " and redirect your users there"); } /** diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java index 193061a6b..6e94bd78a 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java @@ -38,7 +38,8 @@ public OAuthService(OAuthConfig config) { final OAuthConfigAsync asyncConfig = (OAuthConfigAsync) config; final String asyncHttpProviderClassName = asyncConfig.getAsyncHttpProviderClassName(); - asyncHttpClient = asyncHttpProviderClassName == null ? new AsyncHttpClient(asyncConfig.getAsyncHttpClientConfig()) + asyncHttpClient = asyncHttpProviderClassName == null + ? new AsyncHttpClient(asyncConfig.getAsyncHttpClientConfig()) : new AsyncHttpClient(asyncHttpProviderClassName, asyncConfig.getAsyncHttpClientConfig()); } else { if (ForceTypeOfHttpRequest.FORCE_ASYNC_ONLY_HTTP_REQUESTS == forceTypeOfHttpRequest) { @@ -80,17 +81,19 @@ public OAuthConfig getConfig() { public abstract void signRequest(Token accessToken, AbstractRequest request); /** - * Start the request to retrieve the access token. The optionally provided callback will be called with the Token when it is available. + * Start the request to retrieve the access token. The optionally provided callback will be called with the Token + * when it is available. * * @param requestToken request token (obtained previously or null) * @param verifier verifier code * @param callback optional callback * @return Future */ - public abstract Future getAccessTokenAsync(Token requestToken, Verifier verifier, OAuthAsyncRequestCallback callback); + public abstract Future getAccessTokenAsync(Token requestToken, Verifier verifier, + OAuthAsyncRequestCallback callback); - public abstract Future getAccessTokenAsync(Token requestToken, Verifier verifier, OAuthAsyncRequestCallback callback, - ProxyServer proxyServer); + public abstract Future getAccessTokenAsync(Token requestToken, Verifier verifier, + OAuthAsyncRequestCallback callback, ProxyServer proxyServer); /** * Returns the OAuth version of the service. diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/ObjectMother.java b/scribejava-core/src/test/java/com/github/scribejava/core/ObjectMother.java index d00be0e19..30482b2c6 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/ObjectMother.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/ObjectMother.java @@ -9,8 +9,8 @@ public abstract class ObjectMother { public static OAuthRequest createSampleOAuthRequest() { - final OAuthRequest request = new OAuthRequest(Verb.GET, "http://example.com", new OAuth20Service(null, new OAuthConfig("test", - "test"))); + final OAuthRequest request = new OAuthRequest(Verb.GET, "http://example.com", + new OAuth20Service(null, new OAuthConfig("test", "test"))); request.addOAuthParameter(OAuthConstants.TIMESTAMP, "123456"); request.addOAuthParameter(OAuthConstants.CONSUMER_KEY, "AS#$^*@&"); request.addOAuthParameter(OAuthConstants.CALLBACK, "http://example/callback"); @@ -19,8 +19,8 @@ public static OAuthRequest createSampleOAuthRequest() { } public static OAuthRequest createSampleOAuthRequestPort80() { - final OAuthRequest request = new OAuthRequest(Verb.GET, "http://example.com:80", new OAuth20Service(null, new OAuthConfig("test", - "test"))); + final OAuthRequest request = new OAuthRequest(Verb.GET, "http://example.com:80", + new OAuth20Service(null, new OAuthConfig("test", "test"))); request.addOAuthParameter(OAuthConstants.TIMESTAMP, "123456"); request.addOAuthParameter(OAuthConstants.CONSUMER_KEY, "AS#$^*@&"); request.addOAuthParameter(OAuthConstants.CALLBACK, "http://example/callback"); @@ -29,8 +29,8 @@ public static OAuthRequest createSampleOAuthRequestPort80() { } public static OAuthRequest createSampleOAuthRequestPort80v2() { - final OAuthRequest request = new OAuthRequest(Verb.GET, "http://example.com:80/test", new OAuth20Service(null, new OAuthConfig( - "test", "test"))); + final OAuthRequest request = new OAuthRequest(Verb.GET, "http://example.com:80/test", + new OAuth20Service(null, new OAuthConfig("test", "test"))); request.addOAuthParameter(OAuthConstants.TIMESTAMP, "123456"); request.addOAuthParameter(OAuthConstants.CONSUMER_KEY, "AS#$^*@&"); request.addOAuthParameter(OAuthConstants.CALLBACK, "http://example/callback"); @@ -39,8 +39,8 @@ public static OAuthRequest createSampleOAuthRequestPort80v2() { } public static OAuthRequest createSampleOAuthRequestPort8080() { - final OAuthRequest request = new OAuthRequest(Verb.GET, "http://example.com:8080", new OAuth20Service(null, new OAuthConfig("test", - "test"))); + final OAuthRequest request = new OAuthRequest(Verb.GET, "http://example.com:8080", + new OAuth20Service(null, new OAuthConfig("test", "test"))); request.addOAuthParameter(OAuthConstants.TIMESTAMP, "123456"); request.addOAuthParameter(OAuthConstants.CONSUMER_KEY, "AS#$^*@&"); request.addOAuthParameter(OAuthConstants.CALLBACK, "http://example/callback"); @@ -49,8 +49,8 @@ public static OAuthRequest createSampleOAuthRequestPort8080() { } public static OAuthRequest createSampleOAuthRequestPort443() { - final OAuthRequest request = new OAuthRequest(Verb.GET, "https://example.com:443", new OAuth20Service(null, new OAuthConfig("test", - "test"))); + final OAuthRequest request = new OAuthRequest(Verb.GET, "https://example.com:443", + new OAuth20Service(null, new OAuthConfig("test", "test"))); request.addOAuthParameter(OAuthConstants.TIMESTAMP, "123456"); request.addOAuthParameter(OAuthConstants.CONSUMER_KEY, "AS#$^*@&"); request.addOAuthParameter(OAuthConstants.CALLBACK, "http://example/callback"); @@ -59,8 +59,8 @@ public static OAuthRequest createSampleOAuthRequestPort443() { } public static OAuthRequest createSampleOAuthRequestPort443v2() { - final OAuthRequest request = new OAuthRequest(Verb.GET, "https://example.com:443/test", new OAuth20Service(null, new OAuthConfig( - "test", "test"))); + final OAuthRequest request = new OAuthRequest(Verb.GET, "https://example.com:443/test", + new OAuth20Service(null, new OAuthConfig("test", "test"))); request.addOAuthParameter(OAuthConstants.TIMESTAMP, "123456"); request.addOAuthParameter(OAuthConstants.CONSUMER_KEY, "AS#$^*@&"); request.addOAuthParameter(OAuthConstants.CALLBACK, "http://example/callback"); 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 0dcccaa63..e7e39d855 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 @@ -33,48 +33,54 @@ public void setUp() { @Test public void shouldExtractBaseStringFromOAuthRequest() { - final String expected - = "GET&http%3A%2F%2Fexample.com&oauth_callback%3Dhttp%253A%252F%252Fexample%252Fcallback%26oauth_consumer_key%3DAS%2523%2524%255E%252A%2540%2526%26oauth_signature%3DOAuth-Signature%26oauth_timestamp%3D123456"; + final String expected = "GET&http%3A%2F%2Fexample.com&oauth_callback%3Dhttp%253A%252F%252Fexample%252Fcallback" + + "%26oauth_consumer_key%3DAS%2523%2524%255E%252A%2540%2526%26oauth_signature%3DOAuth-Signature" + + "%26oauth_timestamp%3D123456"; final String baseString = extractor.extract(request); assertEquals(expected, baseString); } @Test public void shouldExcludePort80() { - final String expected - = "GET&http%3A%2F%2Fexample.com&oauth_callback%3Dhttp%253A%252F%252Fexample%252Fcallback%26oauth_consumer_key%3DAS%2523%2524%255E%252A%2540%2526%26oauth_signature%3DOAuth-Signature%26oauth_timestamp%3D123456"; + final String expected = "GET&http%3A%2F%2Fexample.com&oauth_callback%3Dhttp%253A%252F%252Fexample%252Fcallback" + + "%26oauth_consumer_key%3DAS%2523%2524%255E%252A%2540%2526%26oauth_signature%3DOAuth-Signature" + + "%26oauth_timestamp%3D123456"; final String baseString = extractor.extract(requestPort80); assertEquals(expected, baseString); } @Test public void shouldExcludePort80v2() { - final String expected - = "GET&http%3A%2F%2Fexample.com%2Ftest&oauth_callback%3Dhttp%253A%252F%252Fexample%252Fcallback%26oauth_consumer_key%3DAS%2523%2524%255E%252A%2540%2526%26oauth_signature%3DOAuth-Signature%26oauth_timestamp%3D123456"; + final String expected = "GET&http%3A%2F%2Fexample.com%2Ftest&oauth_callback%3Dhttp%253A%252F%252Fexample" + + "%252Fcallback%26oauth_consumer_key%3DAS%2523%2524%255E%252A%2540%2526%26oauth_signature" + + "%3DOAuth-Signature%26oauth_timestamp%3D123456"; final String baseString = extractor.extract(requestPort80v2); assertEquals(expected, baseString); } @Test public void shouldIncludePort8080() { - final String expected - = "GET&http%3A%2F%2Fexample.com%3A8080&oauth_callback%3Dhttp%253A%252F%252Fexample%252Fcallback%26oauth_consumer_key%3DAS%2523%2524%255E%252A%2540%2526%26oauth_signature%3DOAuth-Signature%26oauth_timestamp%3D123456"; + final String expected = "GET&http%3A%2F%2Fexample.com%3A8080&oauth_callback%3Dhttp%253A%252F%252Fexample" + + "%252Fcallback%26oauth_consumer_key%3DAS%2523%2524%255E%252A%2540%2526%26oauth_signature" + + "%3DOAuth-Signature%26oauth_timestamp%3D123456"; final String baseString = extractor.extract(requestPort8080); assertEquals(expected, baseString); } @Test public void shouldExcludePort443() { - final String expected - = "GET&https%3A%2F%2Fexample.com&oauth_callback%3Dhttp%253A%252F%252Fexample%252Fcallback%26oauth_consumer_key%3DAS%2523%2524%255E%252A%2540%2526%26oauth_signature%3DOAuth-Signature%26oauth_timestamp%3D123456"; + final String expected = "GET&https%3A%2F%2Fexample.com&oauth_callback%3Dhttp%253A%252F%252Fexample%252Fcallback" + + "%26oauth_consumer_key%3DAS%2523%2524%255E%252A%2540%2526%26oauth_signature%3DOAuth-Signature" + + "%26oauth_timestamp%3D123456"; final String baseString = extractor.extract(requestPort443); assertEquals(expected, baseString); } @Test public void shouldExcludePort443v2() { - final String expected - = "GET&https%3A%2F%2Fexample.com%2Ftest&oauth_callback%3Dhttp%253A%252F%252Fexample%252Fcallback%26oauth_consumer_key%3DAS%2523%2524%255E%252A%2540%2526%26oauth_signature%3DOAuth-Signature%26oauth_timestamp%3D123456"; + final String expected = "GET&https%3A%2F%2Fexample.com%2Ftest&oauth_callback%3Dhttp%253A%252F%252Fexample" + + "%252Fcallback%26oauth_consumer_key%3DAS%2523%2524%255E%252A%2540%2526%26oauth_signature" + + "%3DOAuth-Signature%26oauth_timestamp%3D123456"; final String baseString = extractor.extract(requestPort443v2); assertEquals(expected, baseString); } @@ -87,15 +93,16 @@ public void shouldThrowExceptionIfRquestIsNull() { @Test(expected = OAuthParametersMissingException.class) public void shouldThrowExceptionIfRquestHasNoOAuthParameters() { - final OAuthRequest request = new OAuthRequest(Verb.GET, "http://example.com", new OAuth20Service(null, new OAuthConfig("test", - "test"))); + final OAuthRequest request = new OAuthRequest(Verb.GET, "http://example.com", + new OAuth20Service(null, new OAuthConfig("test", "test"))); extractor.extract(request); } @Test public void shouldProperlyEncodeSpaces() { - final String expected - = "GET&http%3A%2F%2Fexample.com&body%3Dthis%2520param%2520has%2520whitespace%26oauth_callback%3Dhttp%253A%252F%252Fexample%252Fcallback%26oauth_consumer_key%3DAS%2523%2524%255E%252A%2540%2526%26oauth_signature%3DOAuth-Signature%26oauth_timestamp%3D123456"; + final String expected = "GET&http%3A%2F%2Fexample.com&body%3Dthis%2520param%2520has%2520whitespace" + + "%26oauth_callback%3Dhttp%253A%252F%252Fexample%252Fcallback%26oauth_consumer_key" + + "%3DAS%2523%2524%255E%252A%2540%2526%26oauth_signature%3DOAuth-Signature%26oauth_timestamp%3D123456"; request.addBodyParameter("body", "this param has whitespace"); assertEquals(expected, extractor.extract(request)); } 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 4f16c01b3..832cf10e0 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 @@ -25,12 +25,14 @@ public void setUp() { public void shouldExtractStandardHeader() { final String header = extractor.extract(request); try { - assertEquals("OAuth oauth_callback=\"http%3A%2F%2Fexample%2Fcallback\", " + "oauth_signature=\"OAuth-Signature\", " - + "oauth_consumer_key=\"AS%23%24%5E%2A%40%26\", " + "oauth_timestamp=\"123456\"", header); + assertEquals("OAuth oauth_callback=\"http%3A%2F%2Fexample%2Fcallback\", " + + "oauth_signature=\"OAuth-Signature\", oauth_consumer_key=\"AS%23%24%5E%2A%40%26\", " + + "oauth_timestamp=\"123456\"", header); } catch (AssertionError ae) { //maybe this is OpenJDK 8? Different order of elements in HashMap while iterating'em. - assertEquals("OAuth " + "oauth_signature=\"OAuth-Signature\", " + "oauth_callback=\"http%3A%2F%2Fexample%2Fcallback\", " - + "oauth_consumer_key=\"AS%23%24%5E%2A%40%26\", " + "oauth_timestamp=\"123456\"", header); + assertEquals("OAuth oauth_signature=\"OAuth-Signature\", " + + "oauth_callback=\"http%3A%2F%2Fexample%2Fcallback\", " + + "oauth_consumer_key=\"AS%23%24%5E%2A%40%26\", oauth_timestamp=\"123456\"", header); } } @@ -42,8 +44,8 @@ public void shouldExceptionIfRequestIsNull() { @Test(expected = OAuthParametersMissingException.class) public void shouldExceptionIfRequestHasNoOAuthParams() { - final OAuthRequest emptyRequest = new OAuthRequest(Verb.GET, "http://example.com", new OAuth20Service(null, new OAuthConfig( - "test", "test"))); + final OAuthRequest emptyRequest = new OAuthRequest(Verb.GET, "http://example.com", + new OAuth20Service(null, new OAuthConfig("test", "test"))); extractor.extract(emptyRequest); } } diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/extractors/TokenExtractor20Test.java b/scribejava-core/src/test/java/com/github/scribejava/core/extractors/TokenExtractor20Test.java index ed08bdf5e..86b748538 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/extractors/TokenExtractor20Test.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/extractors/TokenExtractor20Test.java @@ -17,17 +17,21 @@ public void setup() { @Test public void shouldExtractTokenFromOAuthStandardResponse() { - final String response = "access_token=166942940015970|2.2ltzWXYNDjCtg5ZDVVJJeg__.3600.1295816400-548517159|RsXNdKrpxg8L6QNLWcs2TVTmcaE"; + final String response = "access_token=166942940015970|2.2ltzWXYNDjCtg5ZDVVJJeg__.3600.1295816400-548517159" + + "|RsXNdKrpxg8L6QNLWcs2TVTmcaE"; final Token extracted = extractor.extract(response); - assertEquals("166942940015970|2.2ltzWXYNDjCtg5ZDVVJJeg__.3600.1295816400-548517159|RsXNdKrpxg8L6QNLWcs2TVTmcaE", extracted.getToken()); + assertEquals("166942940015970|2.2ltzWXYNDjCtg5ZDVVJJeg__.3600.1295816400-548517159|RsXNdKrpxg8L6QNLWcs2TVTmcaE", + extracted.getToken()); assertEquals("", extracted.getSecret()); } @Test public void shouldExtractTokenFromResponseWithExpiresParam() { - final String response = "access_token=166942940015970|2.2ltzWXYNDjCtg5ZDVVJJeg__.3600.1295816400-548517159|RsXNdKrpxg8L6QNLWcs2TVTmcaE&expires=5108"; + final String response = "access_token=166942940015970|2.2ltzWXYNDjCtg5ZDVVJJeg__.3600.1295816400-548517159" + + "|RsXNdKrpxg8L6QNLWcs2TVTmcaE&expires=5108"; final Token extracted = extractor.extract(response); - assertEquals("166942940015970|2.2ltzWXYNDjCtg5ZDVVJJeg__.3600.1295816400-548517159|RsXNdKrpxg8L6QNLWcs2TVTmcaE", extracted.getToken()); + assertEquals("166942940015970|2.2ltzWXYNDjCtg5ZDVVJJeg__.3600.1295816400-548517159|RsXNdKrpxg8L6QNLWcs2TVTmcaE", + extracted.getToken()); assertEquals("", extracted.getSecret()); } diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/extractors/TokenExtractorTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/extractors/TokenExtractorTest.java index 22aeab042..ab5e0bbd0 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/extractors/TokenExtractorTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/extractors/TokenExtractorTest.java @@ -33,7 +33,8 @@ public void shouldExtractTokenFromInvertedOAuthStandardResponse() { @Test public void shouldExtractTokenFromResponseWithCallbackConfirmed() { - final String response = "oauth_token=hh5s93j4hdidpola&oauth_token_secret=hdhd0244k9j7ao03&callback_confirmed=true"; + final String response = "oauth_token=hh5s93j4hdidpola&oauth_token_secret=hdhd0244k9j7ao03" + + "&callback_confirmed=true"; final Token extracted = extractor.extract(response); assertEquals("hh5s93j4hdidpola", extracted.getToken()); assertEquals("hdhd0244k9j7ao03", extracted.getSecret()); diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/model/ForceTypeOfHttpRequestTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/model/ForceTypeOfHttpRequestTest.java index 3f51ae54a..d88398668 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/model/ForceTypeOfHttpRequestTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/model/ForceTypeOfHttpRequestTest.java @@ -22,8 +22,10 @@ public class ForceTypeOfHttpRequestTest { public void setUp() { ScribeJavaConfig.setForceTypeOfHttpRequests(ForceTypeOfHttpRequest.NONE); oAuthService = new OAuth20Service(null, new OAuthConfig("test", "test")); - request = new OAuthRequest(Verb.GET, "http://example.com?qsparam=value&other+param=value+with+spaces", oAuthService); - requestAsync = new OAuthRequestAsync(Verb.GET, "http://example.com?qsparam=value&other+param=value+with+spaces", oAuthService); + request = new OAuthRequest(Verb.GET, "http://example.com?qsparam=value&other+param=value+with+spaces", + oAuthService); + requestAsync = new OAuthRequestAsync(Verb.GET, "http://example.com?qsparam=value&other+param=value+with+spaces", + oAuthService); } @Test 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 2f1475677..d1bae5bfa 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 @@ -11,7 +11,8 @@ public class OAuthRequestTest { @Before public void setUp() { - request = new OAuthRequest(Verb.GET, "http://example.com", new OAuth20Service(null, new OAuthConfig("test", "test"))); + request = new OAuthRequest(Verb.GET, "http://example.com", + new OAuth20Service(null, new OAuthConfig("test", "test"))); } @Test diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/model/RequestTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/model/RequestTest.java index 446911162..16b060000 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/model/RequestTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/model/RequestTest.java @@ -24,7 +24,8 @@ public void setUp() throws MalformedURLException { postRequest.addBodyParameter("param", "value"); postRequest.addBodyParameter("param with spaces", "value with spaces"); postRequest.setConnection(connection); - getRequest = new OAuthRequest(Verb.GET, "http://example.com?qsparam=value&other+param=value+with+spaces", oAuthService); + getRequest = new OAuthRequest(Verb.GET, "http://example.com?qsparam=value&other+param=value+with+spaces", + oAuthService); getRequest.setConnection(connection); } 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 7e508a3a1..8ed259404 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 @@ -22,16 +22,16 @@ public void shouldReturnSignature() { final String apiSecret = "api secret"; final String tokenSecret = "token secret"; final String baseString = "base string"; - final String signature - = "LUNRzQAlpdNyM9mLXm96Va6g/qVNnEAb7p7K1KM0g8IopOFQJPoOO7cvppgt7w3QyhijWJnCmvqXaaIAGrqvdyr3fIzBULh8D/iZQUNLMi08GCOA34P81XBvsc7A5uJjPDsGhJg2MzoVJ8nWJhU/lMMk4c92S1WGskeoDofRwpo="; + final String signature = "LUNRzQAlpdNyM9mLXm96Va6g/qVNnEAb7p7K1KM0g8IopOFQJPoOO7cvppgt7w3QyhijWJnCmvqXaaIAGrqvd" + + "yr3fIzBULh8D/iZQUNLMi08GCOA34P81XBvsc7A5uJjPDsGhJg2MzoVJ8nWJhU/lMMk4c92S1WGskeoDofRwpo="; assertEquals(signature, service.getSignature(baseString, apiSecret, tokenSecret)); } /** * Created primary key using openssl. * - * openssl req -x509 -nodes -days 365 -newkey rsa:1024 -sha1 -subj '/C=GB/ST=/L=Manchester/CN=www.example.com' -keyout myrsakey.pem -out - * /tmp/myrsacert.pem openssl pkcs8 -in myrsakey.pem -topk8 -nocrypt -out myrsakey.pk8 + * openssl req -x509 -nodes -days 365 -newkey rsa:1024 -sha1 -subj '/C=GB/ST=/L=Manchester/CN=www.example.com' + * -keyout myrsakey.pem -out /tmp/myrsacert.pem openssl pkcs8 -in myrsakey.pem -topk8 -nocrypt -out myrsakey.pk8 */ private static PrivateKey getPrivateKey() { final String str = "MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAMPQ5BCMxlUq2TYy\n" 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 59229db99..4a2c3618c 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 @@ -52,9 +52,11 @@ public void shouldThrowExceptionIfStringToDecodeIsNull() { @Test public void shouldPercentEncodeCorrectlyTwitterCodingExamples() { - // These tests are part of the Twitter dev examples here -> https://dev.twitter.com/docs/auth/percent-encoding-parameters + // These tests are part of the Twitter dev examples here + // -> https://dev.twitter.com/docs/auth/percent-encoding-parameters final String[] sources = {"Ladies + Gentlemen", "An encoded string!", "Dogs, Cats & Mice"}; - final String[] encoded = {"Ladies%20%2B%20Gentlemen", "An%20encoded%20string%21", "Dogs%2C%20Cats%20%26%20Mice"}; + final String[] encoded = {"Ladies%20%2B%20Gentlemen", "An%20encoded%20string%21", + "Dogs%2C%20Cats%20%26%20Mice"}; for (int i = 0; i < sources.length; i++) { Assert.assertEquals(encoded[i], OAuthEncoder.encode(sources[i])); From 2246be5243a98b45018e80d42117b058d30eb59b Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 25 Jan 2016 15:18:44 +0300 Subject: [PATCH 105/882] add all needed checkstyle rules --- checkstyle.xml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/checkstyle.xml b/checkstyle.xml index b31e3f75c..9cba55776 100644 --- a/checkstyle.xml +++ b/checkstyle.xml @@ -99,6 +99,15 @@ + + + + + + + + + @@ -109,4 +118,7 @@ + + + From d687f3e050d8e69772515873c1c7bc102c4f0e62 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 26 Jan 2016 12:56:41 +0300 Subject: [PATCH 106/882] improve the code --- .../core/builder/AbstractServiceBuilder.java | 9 +++++++++ .../scribejava/core/model/AbstractRequest.java | 2 +- .../scribejava/core/model/OAuthRequest.java | 4 ++-- .../scribejava/core/model/Parameter.java | 2 -- .../core/services/Base64Encoder.java | 8 +++++--- .../core/services/RSASha1SignatureService.java | 2 +- .../scribejava/core/utils/OAuthEncoder.java | 2 +- .../scribejava/core/utils/StreamUtils.java | 18 +++++++++--------- .../extractors/JsonTokenExtractorTest.java | 6 +++--- .../core/extractors/TokenExtractor20Test.java | 2 +- .../core/extractors/TokenExtractorTest.java | 2 +- .../scribejava/core/model/ConnectionStub.java | 2 +- .../core/model/ForceTypeOfHttpRequestTest.java | 3 +-- .../core/model/ParameterListTest.java | 6 +++--- .../scribejava/core/model/ResponseTest.java | 7 ++++--- .../services/HMACSha1SignatureServiceTest.java | 2 +- .../services/RSASha1SignatureServiceTest.java | 2 +- .../core/services/TimestampServiceTest.java | 6 ++---- .../scribejava/core/utils/MapUtilsTest.java | 4 ++-- .../core/utils/OAuthEncoderTest.java | 3 +-- 20 files changed, 49 insertions(+), 43 deletions(-) diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/AbstractServiceBuilder.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/AbstractServiceBuilder.java index 7d24f5223..6c5283d5d 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/AbstractServiceBuilder.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/AbstractServiceBuilder.java @@ -32,6 +32,7 @@ abstract class AbstractServiceBuilder { * @param callback callback url. Must be a valid url or 'oob' for out of band OAuth * @return the {@link ServiceBuilder} instance for method chaining */ + @SuppressWarnings("unchecked") public T callback(String callback) { Preconditions.checkNotNull(callback, "Callback can't be null"); this.callback = callback; @@ -44,6 +45,7 @@ public T callback(String callback) { * @param apiKey The api key for your application * @return the {@link ServiceBuilder} instance for method chaining */ + @SuppressWarnings("unchecked") public T apiKey(String apiKey) { Preconditions.checkEmptyString(apiKey, "Invalid Api key"); this.apiKey = apiKey; @@ -56,6 +58,7 @@ public T apiKey(String apiKey) { * @param apiSecret The api secret for your application * @return the {@link ServiceBuilder} instance for method chaining */ + @SuppressWarnings("unchecked") public T apiSecret(String apiSecret) { Preconditions.checkEmptyString(apiSecret, "Invalid Api secret"); this.apiSecret = apiSecret; @@ -68,6 +71,7 @@ public T apiSecret(String apiSecret) { * @param scope The OAuth scope * @return the {@link ServiceBuilder} instance for method chaining */ + @SuppressWarnings("unchecked") public T scope(String scope) { Preconditions.checkEmptyString(scope, "Invalid OAuth scope"); this.scope = scope; @@ -80,6 +84,7 @@ public T scope(String scope) { * @param state The OAuth state * @return the {@link ServiceBuilder} instance for method chaining */ + @SuppressWarnings("unchecked") public T state(String state) { Preconditions.checkEmptyString(state, "Invalid OAuth state"); this.state = state; @@ -92,24 +97,28 @@ public T state(String state) { * @param type SignatureType * @return the {@link ServiceBuilder} instance for method chaining */ + @SuppressWarnings("unchecked") public T signatureType(SignatureType type) { Preconditions.checkNotNull(type, "Signature type can't be null"); this.signatureType = type; return (T) this; } + @SuppressWarnings("unchecked") public T debugStream(OutputStream stream) { Preconditions.checkNotNull(stream, "debug stream can't be null"); this.debugStream = stream; return (T) this; } + @SuppressWarnings("unchecked") public T grantType(String grantType) { Preconditions.checkEmptyString(grantType, "Invalid OAuth grantType"); this.grantType = grantType; return (T) this; } + @SuppressWarnings("unchecked") public T debug() { debugStream(System.out); return (T) this; diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/AbstractRequest.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/AbstractRequest.java index 42f9140d5..515136f09 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/AbstractRequest.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/AbstractRequest.java @@ -28,7 +28,7 @@ public abstract class AbstractRequest { private final Map headers = new HashMap<>(); private boolean connectionKeepAlive; private boolean followRedirects = true; - private OAuthService service; + private final OAuthService service; private String payload; private String charset; 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 bd2f38ae1..66a36415a 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 @@ -45,10 +45,10 @@ Response doSend() throws IOException { connection.setRequestMethod(verb.name()); final OAuthConfig config = getService().getConfig(); if (config.getConnectTimeout() != null) { - connection.setConnectTimeout(config.getConnectTimeout().intValue()); + connection.setConnectTimeout(config.getConnectTimeout()); } if (config.getReadTimeout() != null) { - connection.setReadTimeout(config.getReadTimeout().intValue()); + connection.setReadTimeout(config.getReadTimeout()); } addHeaders(); if (hasBodyContent()) { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/Parameter.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/Parameter.java index 0bcfb7528..0bcaa91f7 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/Parameter.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/Parameter.java @@ -7,8 +7,6 @@ */ public class Parameter implements Comparable { - private static final String UTF = "UTF8"; - private final String key; private final String value; diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/services/Base64Encoder.java b/scribejava-core/src/main/java/com/github/scribejava/core/services/Base64Encoder.java index b5cb7d447..ab564941c 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/services/Base64Encoder.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/services/Base64Encoder.java @@ -4,9 +4,11 @@ public abstract class Base64Encoder { private static Base64Encoder instance; - public static synchronized Base64Encoder getInstance() { - if (instance == null) { - instance = createEncoderInstance(); + public static Base64Encoder getInstance() { + synchronized (Base64Encoder.class) { + if (instance == null) { + instance = createEncoderInstance(); + } } return instance; } 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 5f89946c6..ebc512c61 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 @@ -14,7 +14,7 @@ public class RSASha1SignatureService implements SignatureService { private static final String RSA_SHA1 = "SHA1withRSA"; private static final String UTF8 = "UTF-8"; - private PrivateKey privateKey; + private final PrivateKey privateKey; public RSASha1SignatureService(PrivateKey privateKey) { this.privateKey = privateKey; diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/utils/OAuthEncoder.java b/scribejava-core/src/main/java/com/github/scribejava/core/utils/OAuthEncoder.java index c872eb5a5..498258863 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/utils/OAuthEncoder.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/utils/OAuthEncoder.java @@ -27,7 +27,7 @@ public abstract class OAuthEncoder { public static String encode(String plain) { Preconditions.checkNotNull(plain, "Cannot encode null object"); - String encoded = ""; + String encoded; try { encoded = URLEncoder.encode(plain, CHARSET); } catch (UnsupportedEncodingException uee) { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/utils/StreamUtils.java b/scribejava-core/src/main/java/com/github/scribejava/core/utils/StreamUtils.java index 5f3fee95f..f5db63b69 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/utils/StreamUtils.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/utils/StreamUtils.java @@ -23,15 +23,15 @@ public static String getStreamContents(InputStream is) { try { final char[] buffer = new char[0x10000]; final StringBuilder out = new StringBuilder(); - final Reader in = new InputStreamReader(is, "UTF-8"); - int read; - do { - read = in.read(buffer, 0, buffer.length); - if (read > 0) { - out.append(buffer, 0, read); - } - } while (read >= 0); - in.close(); + try (Reader in = new InputStreamReader(is, "UTF-8")) { + int read; + do { + read = in.read(buffer, 0, buffer.length); + if (read > 0) { + out.append(buffer, 0, read); + } + } while (read >= 0); + } return out.toString(); } catch (IOException ioe) { throw new IllegalStateException("Error while reading response body", ioe); diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/extractors/JsonTokenExtractorTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/extractors/JsonTokenExtractorTest.java index 07c655c32..743d0fa69 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/extractors/JsonTokenExtractorTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/extractors/JsonTokenExtractorTest.java @@ -6,12 +6,12 @@ public class JsonTokenExtractorTest { - private String response = "'{ \"access_token\":\"I0122HHJKLEM21F3WLPYHDKGKZULAUO4SGMV3ABKFTDT3T3X\"}'"; - private JsonTokenExtractor extractor = new JsonTokenExtractor(); + private static final String RESPONSE = "'{ \"access_token\":\"I0122HHJKLEM21F3WLPYHDKGKZULAUO4SGMV3ABKFTDT3T3X\"}'"; + private final JsonTokenExtractor extractor = new JsonTokenExtractor(); @Test public void shouldParseResponse() { - final Token token = extractor.extract(response); + final Token token = extractor.extract(RESPONSE); assertEquals(token.getToken(), "I0122HHJKLEM21F3WLPYHDKGKZULAUO4SGMV3ABKFTDT3T3X"); } diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/extractors/TokenExtractor20Test.java b/scribejava-core/src/test/java/com/github/scribejava/core/extractors/TokenExtractor20Test.java index 86b748538..5209966a9 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/extractors/TokenExtractor20Test.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/extractors/TokenExtractor20Test.java @@ -11,7 +11,7 @@ public class TokenExtractor20Test { private TokenExtractor20Impl extractor; @Before - public void setup() { + public void setUp() { extractor = new TokenExtractor20Impl(); } diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/extractors/TokenExtractorTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/extractors/TokenExtractorTest.java index ab5e0bbd0..12650be99 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/extractors/TokenExtractorTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/extractors/TokenExtractorTest.java @@ -11,7 +11,7 @@ public class TokenExtractorTest { private TokenExtractorImpl extractor; @Before - public void setup() { + public void setUp() { extractor = new TokenExtractorImpl(); } diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/model/ConnectionStub.java b/scribejava-core/src/test/java/com/github/scribejava/core/model/ConnectionStub.java index 21df5804c..b7465527d 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/model/ConnectionStub.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/model/ConnectionStub.java @@ -69,7 +69,7 @@ public void addResponseHeader(String key, String value) { } @Override - public void connect() throws IOException { + public void connect() { } @Override diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/model/ForceTypeOfHttpRequestTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/model/ForceTypeOfHttpRequestTest.java index d88398668..9e60f3fb2 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/model/ForceTypeOfHttpRequestTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/model/ForceTypeOfHttpRequestTest.java @@ -16,12 +16,11 @@ public class ForceTypeOfHttpRequestTest { private OAuthRequest request; private OAuthRequestAsync requestAsync; - private OAuthService oAuthService; @Before public void setUp() { ScribeJavaConfig.setForceTypeOfHttpRequests(ForceTypeOfHttpRequest.NONE); - oAuthService = new OAuth20Service(null, new OAuthConfig("test", "test")); + final OAuthService oAuthService = new OAuth20Service(null, new OAuthConfig("test", "test")); request = new OAuthRequest(Verb.GET, "http://example.com?qsparam=value&other+param=value+with+spaces", oAuthService); requestAsync = new OAuthRequestAsync(Verb.GET, "http://example.com?qsparam=value&other+param=value+with+spaces", 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 276b9bec8..6c4d95549 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 @@ -14,7 +14,7 @@ public class ParameterListTest { private ParameterList params; @Before - public void setup() { + public void setUp() { this.params = new ParameterList(); } @@ -39,7 +39,7 @@ public void shouldAppendParametersToSimpleUrl() { params.add("param2", "value with spaces"); url = params.appendTo(url); - Assert.assertEquals(url, expectedUrl); + Assert.assertEquals(expectedUrl, url); } @Test @@ -51,7 +51,7 @@ public void shouldAppendParametersToUrlWithQuerystring() { params.add("param2", "value with spaces"); url = params.appendTo(url); - Assert.assertEquals(url, expectedUrl); + Assert.assertEquals(expectedUrl, url); } @Test diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/model/ResponseTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/model/ResponseTest.java index ad84a0745..c4fe5712f 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/model/ResponseTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/model/ResponseTest.java @@ -3,6 +3,7 @@ import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; +import java.net.MalformedURLException; import static org.junit.Assert.assertEquals; import org.junit.Before; import org.junit.Test; @@ -13,7 +14,7 @@ public class ResponseTest { private ConnectionStub connection; @Before - public void setup() throws Exception { + public void setUp() throws IOException { connection = new ConnectionStub(); connection.addResponseHeader("one", "one"); connection.addResponseHeader("two", "two"); @@ -41,7 +42,7 @@ public void shouldParseBodyContentsOnlyOnce() { } @Test - public void shouldHandleAConnectionWithErrors() throws Exception { + public void shouldHandleAConnectionWithErrors() throws IOException { final Response errResponse = new Response(new FaultyConnection()); assertEquals(400, errResponse.getCode()); assertEquals("errors", errResponse.getBody()); @@ -49,7 +50,7 @@ public void shouldHandleAConnectionWithErrors() throws Exception { private static class FaultyConnection extends ConnectionStub { - private FaultyConnection() throws Exception { + private FaultyConnection() throws MalformedURLException { super(); } 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 a84df6d26..d3fba9ae2 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 @@ -10,7 +10,7 @@ public class HMACSha1SignatureServiceTest { private HMACSha1SignatureService service; @Before - public void setup() { + public void setUp() { service = new HMACSha1SignatureService(); } 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 8ed259404..72ec3104a 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 @@ -9,7 +9,7 @@ public class RSASha1SignatureServiceTest { - private RSASha1SignatureService service = new RSASha1SignatureService(getPrivateKey()); + private final RSASha1SignatureService service = new RSASha1SignatureService(getPrivateKey()); @Test public void shouldReturnSignatureMethodString() { diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/services/TimestampServiceTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/services/TimestampServiceTest.java index 1a6b4c820..4d8f27bc5 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/services/TimestampServiceTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/services/TimestampServiceTest.java @@ -7,13 +7,11 @@ public class TimestampServiceTest { private TimestampServiceImpl service; - private TimestampServiceImpl.Timer timerStub; @Before - public void setup() { + public void setUp() { service = new TimestampServiceImpl(); - timerStub = new TimerStub(); - service.setTimer(timerStub); + service.setTimer(new TimerStub()); } @Test diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/utils/MapUtilsTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/utils/MapUtilsTest.java index 115925bec..28f4a8515 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/utils/MapUtilsTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/utils/MapUtilsTest.java @@ -12,7 +12,7 @@ public class MapUtilsTest { @Test public void shouldPrettyPrintMap() { - final Map map = new HashMap(); + final Map map = new HashMap<>(); map.put(1, "one"); map.put(2, "two"); map.put(3, "three"); @@ -22,7 +22,7 @@ public void shouldPrettyPrintMap() { @Test public void shouldHandleEmptyMap() { - final Map map = new HashMap(); + final Map map = new HashMap<>(); Assert.assertEquals("{}", MapUtils.toString(map)); } 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 4a2c3618c..306720861 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,6 +1,5 @@ package com.github.scribejava.core.utils; -import org.junit.Assert; import static org.junit.Assert.assertEquals; import org.junit.Test; @@ -59,7 +58,7 @@ public void shouldPercentEncodeCorrectlyTwitterCodingExamples() { "Dogs%2C%20Cats%20%26%20Mice"}; for (int i = 0; i < sources.length; i++) { - Assert.assertEquals(encoded[i], OAuthEncoder.encode(sources[i])); + assertEquals(encoded[i], OAuthEncoder.encode(sources[i])); } } } From 7b4475fca71706952564acb14d8aebf52cf4a4c8 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 26 Jan 2016 13:18:50 +0300 Subject: [PATCH 107/882] remove the term 'requestToken' from OAuth2Service, differentiate OAuth1 and OAuth2 services in the process of retrieving of the access token (and generating request token for the OAuth1) --- .../apis/service/ImgurOAuthServiceImpl.java | 2 +- .../apis/examples/AWeberExample.java | 4 +- .../scribejava/apis/examples/DiggExample.java | 4 +- .../apis/examples/FacebookAsyncExample.java | 9 ++--- .../apis/examples/FacebookExample.java | 9 ++--- .../apis/examples/FlickrExample.java | 4 +- .../apis/examples/Foursquare2Example.java | 9 ++--- .../apis/examples/FoursquareExample.java | 4 +- .../apis/examples/FreelancerExample.java | 4 +- .../apis/examples/GitHubExample.java | 9 ++--- .../apis/examples/Google20Example.java | 5 +-- .../apis/examples/GoogleExample.java | 4 +- .../scribejava/apis/examples/HHExample.java | 9 ++--- .../apis/examples/ImgurExample.java | 8 ++-- .../apis/examples/Kaixin20Example.java | 9 ++--- .../apis/examples/LinkedIn20Example.java | 5 +-- .../apis/examples/LinkedInExample.java | 4 +- .../examples/LinkedInExampleWithScopes.java | 4 +- .../scribejava/apis/examples/LiveExample.java | 9 ++--- .../apis/examples/LoveFilmExample.java | 4 +- .../apis/examples/MailruAsyncExample.java | 9 ++--- .../apis/examples/MailruExample.java | 9 ++--- .../apis/examples/MeetupExample.java | 4 +- .../apis/examples/NeteaseWeiboExample.java | 4 +- .../apis/examples/OdnoklassnikiExample.java | 9 ++--- .../apis/examples/PinterestExample.java | 9 ++--- .../apis/examples/Px500Example.java | 4 +- .../apis/examples/RenrenExample.java | 9 ++--- .../apis/examples/SinaWeibo2Example.java | 9 ++--- .../apis/examples/SinaWeiboExample.java | 4 +- .../apis/examples/SkyrockExample.java | 4 +- .../apis/examples/SohuWeiboExample.java | 4 +- .../apis/examples/TrelloExample.java | 4 +- .../apis/examples/TumblrExample.java | 4 +- .../apis/examples/TutByExample.java | 9 ++--- .../apis/examples/TwitterExample.java | 4 +- .../apis/examples/ViadeoExample.java | 9 ++--- .../apis/examples/VkontakteExample.java | 9 ++--- .../scribejava/apis/examples/XingExample.java | 4 +- .../apis/examples/YahooExample.java | 4 +- .../core/oauth/OAuth10aService.java | 24 +++++++++--- .../scribejava/core/oauth/OAuth20Service.java | 38 +++++++++---------- .../scribejava/core/oauth/OAuthService.java | 37 ------------------ 43 files changed, 148 insertions(+), 195 deletions(-) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthServiceImpl.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthServiceImpl.java index 969c3a517..beaff274d 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthServiceImpl.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthServiceImpl.java @@ -17,7 +17,7 @@ public ImgurOAuthServiceImpl(DefaultApi20 api, OAuthConfig config) { } @Override - public Token getAccessToken(Token requestToken, Verifier verifier) { + public Token getAccessToken(Verifier verifier) { final OAuthRequest request = new OAuthRequest(getApi().getAccessTokenVerb(), getApi().getAccessTokenEndpoint(), this); request.addBodyParameter(OAuthConstants.CLIENT_ID, getConfig().getApiKey()); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AWeberExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AWeberExample.java index 1bc8f0279..3188b4b7f 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AWeberExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AWeberExample.java @@ -8,7 +8,7 @@ import com.github.scribejava.core.model.Token; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.model.Verifier; -import com.github.scribejava.core.oauth.OAuthService; +import com.github.scribejava.core.oauth.OAuth10aService; public abstract class AWeberExample { @@ -19,7 +19,7 @@ public abstract class AWeberExample { private static final String CONSUMER_SECRET = ""; public static void main(String... args) { - final OAuthService service = new ServiceBuilder() + final OAuth10aService service = new ServiceBuilder() .apiKey(CONSUMER_KEY) .apiSecret(CONSUMER_SECRET) .build(AWeberApi.instance()); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiggExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiggExample.java index 8ca630dab..4e46d9e27 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiggExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiggExample.java @@ -8,7 +8,7 @@ import com.github.scribejava.core.model.Token; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.model.Verifier; -import com.github.scribejava.core.oauth.OAuthService; +import com.github.scribejava.core.oauth.OAuth10aService; public abstract class DiggExample { @@ -19,7 +19,7 @@ public static void main(String... args) { // Replace these with your own api key and secret final String apiKey = "myKey"; final String apiSecret = "mySecret"; - final OAuthService service = new ServiceBuilder() + final OAuth10aService service = new ServiceBuilder() .apiKey(apiKey) .apiSecret(apiSecret) .build(DiggApi.instance()); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncExample.java index 17fdd0892..7198ad97e 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncExample.java @@ -13,13 +13,12 @@ import com.github.scribejava.core.model.Token; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.model.Verifier; -import com.github.scribejava.core.oauth.OAuthService; +import com.github.scribejava.core.oauth.OAuth20Service; public abstract class FacebookAsyncExample { private static final String NETWORK_NAME = "Facebook"; private static final String PROTECTED_RESOURCE_URL = "https://graph.facebook.com/v2.2/me"; - private static final Token EMPTY_TOKEN = null; public static void main(String... args) throws InterruptedException, ExecutionException { // Replace these with your client id and secret @@ -35,7 +34,7 @@ public static void main(String... args) throws InterruptedException, ExecutionEx .setReadTimeout(1_000) .build(); - final OAuthService service = new ServiceBuilderAsync() + final OAuth20Service service = new ServiceBuilderAsync() .apiKey(clientId) .apiSecret(clientSecret) .state(secretState) @@ -50,7 +49,7 @@ public static void main(String... args) throws InterruptedException, ExecutionEx // Obtain the Authorization URL System.out.println("Fetching the Authorization URL..."); - final String authorizationUrl = service.getAuthorizationUrl(EMPTY_TOKEN); + final String authorizationUrl = service.getAuthorizationUrl(); System.out.println("Got the Authorization URL!"); System.out.println("Now go and authorize ScribeJava here:"); System.out.println(authorizationUrl); @@ -73,7 +72,7 @@ public static void main(String... args) throws InterruptedException, ExecutionEx // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - final Token accessToken = service.getAccessTokenAsync(EMPTY_TOKEN, verifier, null).get(); + final Token accessToken = service.getAccessTokenAsync(verifier, null).get(); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + " )"); System.out.println(); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java index c3604db75..64f34907c 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java @@ -9,20 +9,19 @@ import com.github.scribejava.core.model.Token; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.model.Verifier; -import com.github.scribejava.core.oauth.OAuthService; +import com.github.scribejava.core.oauth.OAuth20Service; public abstract class FacebookExample { private static final String NETWORK_NAME = "Facebook"; private static final String PROTECTED_RESOURCE_URL = "https://graph.facebook.com/v2.2/me"; - private static final Token EMPTY_TOKEN = null; public static void main(String... args) { // Replace these with your client id and secret final String clientId = "your client id"; final String clientSecret = "your client secret"; final String secretState = "secret" + new Random().nextInt(999_999); - final OAuthService service = new ServiceBuilder() + final OAuth20Service service = new ServiceBuilder() .apiKey(clientId) .apiSecret(clientSecret) .state(secretState) @@ -35,7 +34,7 @@ public static void main(String... args) { // Obtain the Authorization URL System.out.println("Fetching the Authorization URL..."); - final String authorizationUrl = service.getAuthorizationUrl(EMPTY_TOKEN); + final String authorizationUrl = service.getAuthorizationUrl(); System.out.println("Got the Authorization URL!"); System.out.println("Now go and authorize ScribeJava here:"); System.out.println(authorizationUrl); @@ -58,7 +57,7 @@ public static void main(String... args) { // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - final Token accessToken = service.getAccessToken(EMPTY_TOKEN, verifier); + final Token accessToken = service.getAccessToken(verifier); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + " )"); System.out.println(); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExample.java index b7afa9128..8b67ed760 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExample.java @@ -8,7 +8,7 @@ import com.github.scribejava.core.model.Token; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.model.Verifier; -import com.github.scribejava.core.oauth.OAuthService; +import com.github.scribejava.core.oauth.OAuth10aService; public abstract class FlickrExample { @@ -18,7 +18,7 @@ public static void main(String... args) { // Replace these with your own api key and secret final String apiKey = "your_app_id"; final String apiSecret = "your_api_secret"; - final OAuthService service = new ServiceBuilder() + final OAuth10aService service = new ServiceBuilder() .apiKey(apiKey) .apiSecret(apiSecret) .build(FlickrApi.instance()); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java index 13e0f8a1c..3d44beb67 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java @@ -8,19 +8,18 @@ import com.github.scribejava.core.model.Token; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.model.Verifier; -import com.github.scribejava.core.oauth.OAuthService; +import com.github.scribejava.core.oauth.OAuth20Service; public abstract class Foursquare2Example { private static final String PROTECTED_RESOURCE_URL = "https://api.foursquare.com/v2/users/self/friends?oauth_token="; - private static final Token EMPTY_TOKEN = null; public static void main(String... args) { // Replace these with your own api key and secret final String apiKey = "your client id"; final String apiSecret = "your client secret"; - final OAuthService service = new ServiceBuilder() + final OAuth20Service service = new ServiceBuilder() .apiKey(apiKey) .apiSecret(apiSecret) .callback("http://localhost:9000/") @@ -32,7 +31,7 @@ public static void main(String... args) { // Obtain the Authorization URL System.out.println("Fetching the Authorization URL..."); - final String authorizationUrl = service.getAuthorizationUrl(EMPTY_TOKEN); + final String authorizationUrl = service.getAuthorizationUrl(); System.out.println("Got the Authorization URL!"); System.out.println("Now go and authorize ScribeJava here:"); System.out.println(authorizationUrl); @@ -43,7 +42,7 @@ public static void main(String... args) { // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - final Token accessToken = service.getAccessToken(EMPTY_TOKEN, verifier); + final Token accessToken = service.getAccessToken(verifier); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + " )"); System.out.println(); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FoursquareExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FoursquareExample.java index 3d894be45..86cabddc5 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FoursquareExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FoursquareExample.java @@ -8,14 +8,14 @@ import com.github.scribejava.core.model.Token; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.model.Verifier; -import com.github.scribejava.core.oauth.OAuthService; +import com.github.scribejava.core.oauth.OAuth10aService; public abstract class FoursquareExample { private static final String PROTECTED_RESOURCE_URL = "http://api.foursquare.com/v1/user"; public static void main(String... args) { - final OAuthService service = new ServiceBuilder() + final OAuth10aService service = new ServiceBuilder() .apiKey("your client id") .apiSecret("your client secret") .build(FoursquareApi.instance()); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java index c05e2611a..f4bf61a63 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java @@ -9,7 +9,7 @@ import com.github.scribejava.core.model.Token; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.model.Verifier; -import com.github.scribejava.core.oauth.OAuthService; +import com.github.scribejava.core.oauth.OAuth10aService; public abstract class FreelancerExample { @@ -20,7 +20,7 @@ public abstract class FreelancerExample { private static final String SCOPE = "http://api.sandbox.freelancer.com"; public static void main(String... args) { - final OAuthService service = new ServiceBuilder() + final OAuth10aService service = new ServiceBuilder() .signatureType(SignatureType.QueryString) .apiKey("your client id") .apiSecret("your client secret") diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubExample.java index cbc659b4b..bed799eb9 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubExample.java @@ -9,20 +9,19 @@ import com.github.scribejava.core.model.Token; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.model.Verifier; -import com.github.scribejava.core.oauth.OAuthService; +import com.github.scribejava.core.oauth.OAuth20Service; public abstract class GitHubExample { private static final String NETWORK_NAME = "GitHub"; private static final String PROTECTED_RESOURCE_URL = "https://api.github.com/user"; - private static final Token EMPTY_TOKEN = null; public static void main(String... args) { // Replace these with your client id and secret final String clientId = "your client id"; final String clientSecret = "your client secret"; final String secretState = "secret" + new Random().nextInt(999_999); - final OAuthService service = new ServiceBuilder() + final OAuth20Service service = new ServiceBuilder() .apiKey(clientId) .apiSecret(clientSecret) .state(secretState) @@ -35,7 +34,7 @@ public static void main(String... args) { // Obtain the Authorization URL System.out.println("Fetching the Authorization URL..."); - final String authorizationUrl = service.getAuthorizationUrl(EMPTY_TOKEN); + final String authorizationUrl = service.getAuthorizationUrl(); System.out.println("Got the Authorization URL!"); System.out.println("Now go and authorize ScribeJava here:"); System.out.println(authorizationUrl); @@ -58,7 +57,7 @@ public static void main(String... args) { // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - final Token accessToken = service.getAccessToken(EMPTY_TOKEN, verifier); + final Token accessToken = service.getAccessToken(verifier); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + " )"); System.out.println(); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java index 5df67d9a4..de90d0e51 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java @@ -15,7 +15,6 @@ public abstract class Google20Example { private static final String NETWORK_NAME = "G+"; private static final String PROTECTED_RESOURCE_URL = "https://www.googleapis.com/plus/v1/people/me"; - private static final Token EMPTY_TOKEN = null; public static void main(String... args) { // Replace these with your client id and secret @@ -36,7 +35,7 @@ public static void main(String... args) { // Obtain the Authorization URL System.out.println("Fetching the Authorization URL..."); - final String authorizationUrl = service.getAuthorizationUrl(EMPTY_TOKEN); + final String authorizationUrl = service.getAuthorizationUrl(); System.out.println("Got the Authorization URL!"); System.out.println("Now go and authorize ScribeJava here:"); System.out.println(authorizationUrl); @@ -59,7 +58,7 @@ public static void main(String... args) { // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - final Token accessToken = service.getAccessToken(EMPTY_TOKEN, verifier); + final Token accessToken = service.getAccessToken(verifier); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + " )"); System.out.println(); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GoogleExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GoogleExample.java index c21721c83..5f8d1bb47 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GoogleExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GoogleExample.java @@ -8,7 +8,7 @@ import com.github.scribejava.core.model.Token; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.model.Verifier; -import com.github.scribejava.core.oauth.OAuthService; +import com.github.scribejava.core.oauth.OAuth10aService; public abstract class GoogleExample { @@ -18,7 +18,7 @@ public abstract class GoogleExample { private static final String SCOPE = "https://docs.google.com/feeds/"; public static void main(String... args) { - final OAuthService service = new ServiceBuilder() + final OAuth10aService service = new ServiceBuilder() .apiKey("anonymous") .apiSecret("anonymous") .scope(SCOPE) diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HHExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HHExample.java index 6b243b2de..edc5cb121 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HHExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HHExample.java @@ -8,21 +8,20 @@ import com.github.scribejava.core.model.Token; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.model.Verifier; -import com.github.scribejava.core.oauth.OAuthService; import com.github.scribejava.apis.HHApi; +import com.github.scribejava.core.oauth.OAuth20Service; public abstract class HHExample { private static final String NETWORK_NAME = "hh.ru"; private static final String PROTECTED_RESOURCE_URL = "https://api.hh.ru/me"; - private static final Token EMPTY_TOKEN = null; public static void main(String... args) { // Replace these with your own client id and secret final String clientId = "your client id"; final String clientSecret = "your client secret"; - final OAuthService service = new ServiceBuilder() + final OAuth20Service service = new ServiceBuilder() .apiKey(clientId) .apiSecret(clientSecret) .callback("http://your.site.com/callback") @@ -34,7 +33,7 @@ public static void main(String... args) { // Obtain the Authorization URL System.out.println("Fetching the Authorization URL..."); - final String authorizationUrl = service.getAuthorizationUrl(EMPTY_TOKEN); + final String authorizationUrl = service.getAuthorizationUrl(); System.out.println("Got the Authorization URL!"); System.out.println("Now go and authorize ScribeJava here:"); System.out.println(authorizationUrl); @@ -45,7 +44,7 @@ public static void main(String... args) { // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - final Token accessToken = service.getAccessToken(EMPTY_TOKEN, verifier); + final Token accessToken = service.getAccessToken(verifier); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + " )"); System.out.println(); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ImgurExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ImgurExample.java index 6c384ac4f..b9f922b23 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ImgurExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ImgurExample.java @@ -7,7 +7,7 @@ import com.github.scribejava.core.model.Token; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.model.Verifier; -import com.github.scribejava.core.oauth.OAuthService; +import com.github.scribejava.core.oauth.OAuth20Service; import java.util.Scanner; @@ -20,7 +20,7 @@ public static void main(String... args) { // Replace these with your own api key and secret final String apiKey = "your client id"; final String apiSecret = "your client secret"; - final OAuthService service = new ServiceBuilder() + final OAuth20Service service = new ServiceBuilder() .apiKey(apiKey) .apiSecret(apiSecret) .build(ImgurApi.instance()); @@ -31,7 +31,7 @@ public static void main(String... args) { // Obtain the Authorization URL System.out.println("Fetching the Authorization URL..."); - final String authorizationUrl = service.getAuthorizationUrl(Token.empty()); + final String authorizationUrl = service.getAuthorizationUrl(); System.out.println("Got the Authorization URL!"); System.out.println("Now go and authorize ScribeJava here:"); System.out.println(authorizationUrl); @@ -42,7 +42,7 @@ public static void main(String... args) { // Trade the Request Token and Verifier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - final Token accessToken = service.getAccessToken(Token.empty(), verifier); + final Token accessToken = service.getAccessToken(verifier); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + " )"); System.out.println(); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Kaixin20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Kaixin20Example.java index fe67d93e1..b979168e2 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Kaixin20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Kaixin20Example.java @@ -8,19 +8,18 @@ import com.github.scribejava.core.model.Token; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.model.Verifier; -import com.github.scribejava.core.oauth.OAuthService; +import com.github.scribejava.core.oauth.OAuth20Service; public abstract class Kaixin20Example { private static final String NETWORK_NAME = "Kaixin"; private static final String PROTECTED_RESOURCE_URL = "https://api.kaixin001.com/users/me.json"; - private static final Token EMPTY_TOKEN = null; public static void main(String... args) { // Replace these with your own api key and secret final String apiKey = "your api key"; final String apiSecret = "your api secret"; - final OAuthService service = new ServiceBuilder() + final OAuth20Service service = new ServiceBuilder() .apiKey(apiKey) .apiSecret(apiSecret) .callback("http://your.domain.com/handle") @@ -32,7 +31,7 @@ public static void main(String... args) { // Obtain the Authorization URL System.out.println("Fetching the Authorization URL..."); - final String authorizationUrl = service.getAuthorizationUrl(EMPTY_TOKEN); + final String authorizationUrl = service.getAuthorizationUrl(); System.out.println("Got the Authorization URL!"); System.out.println("Now go and authorize ScribeJava here:"); System.out.println(authorizationUrl); @@ -43,7 +42,7 @@ public static void main(String... args) { // Trade the Request Token and Verifier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - final Token accessToken = service.getAccessToken(EMPTY_TOKEN, verifier); + final Token accessToken = service.getAccessToken(verifier); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + " )"); System.out.println(); 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 a4e5a4f48..51386828a 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 @@ -14,7 +14,6 @@ public abstract class LinkedIn20Example { private static final String NETWORK_NAME = "LinkedIn"; private static final String PROTECTED_RESOURCE_URL = "https://api.linkedin.com/v1/people/~:(%s)"; - private static final Token EMPTY_TOKEN = null; public static void main(String... args) { // Replace these with your client id and secret @@ -33,7 +32,7 @@ public static void main(String... args) { // Obtain the Authorization URL System.out.println("Fetching the Authorization URL..."); - final String authorizationUrl = service.getAuthorizationUrl(EMPTY_TOKEN); + final String authorizationUrl = service.getAuthorizationUrl(); System.out.println("Got the Authorization URL!"); System.out.println("Now go and authorize ScribeJava here:"); System.out.println(authorizationUrl); @@ -44,7 +43,7 @@ public static void main(String... args) { // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - final Token accessToken = service.getAccessToken(EMPTY_TOKEN, verifier); + final Token accessToken = service.getAccessToken(verifier); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + " )"); System.out.println(); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java index 6c8069f1d..5313c9894 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java @@ -8,7 +8,7 @@ import com.github.scribejava.core.model.Token; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.model.Verifier; -import com.github.scribejava.core.oauth.OAuthService; +import com.github.scribejava.core.oauth.OAuth10aService; public abstract class LinkedInExample { @@ -16,7 +16,7 @@ public abstract class LinkedInExample { = "http://api.linkedin.com/v1/people/~/connections:(id,last-name)"; public static void main(String... args) { - final OAuthService service = new ServiceBuilder() + final OAuth10aService service = new ServiceBuilder() .apiKey("your client id") .apiSecret("your client secret") .build(LinkedInApi.instance()); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java index 97291554c..9da448baf 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java @@ -8,7 +8,7 @@ import com.github.scribejava.core.model.Token; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.model.Verifier; -import com.github.scribejava.core.oauth.OAuthService; +import com.github.scribejava.core.oauth.OAuth10aService; public abstract class LinkedInExampleWithScopes { @@ -20,7 +20,7 @@ public static void main(String... args) { final String clientId = "your client id"; final String clientSecret = "your client id"; - final OAuthService service = new ServiceBuilder() + final OAuth10aService service = new ServiceBuilder() .apiKey(clientId) .apiSecret(clientSecret) .build(new LinkedInApi("foo", "bar", "baz")); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java index 745801b6e..0a3396e52 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java @@ -8,19 +8,18 @@ import com.github.scribejava.core.model.Token; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.model.Verifier; -import com.github.scribejava.core.oauth.OAuthService; +import com.github.scribejava.core.oauth.OAuth20Service; public abstract class LiveExample { private static final String PROTECTED_RESOURCE_URL = "https://api.foursquare.com/v2/users/self/friends?oauth_token="; - private static final Token EMPTY_TOKEN = null; public static void main(String... args) { // Replace these with your own api key and secret final String apiKey = ""; final String apiSecret = ""; - final OAuthService service = new ServiceBuilder() + final OAuth20Service service = new ServiceBuilder() .apiKey(apiKey) .apiSecret(apiSecret) .scope("wl.basic") @@ -33,7 +32,7 @@ public static void main(String... args) { // Obtain the Authorization URL System.out.println("Fetching the Authorization URL..."); - final String authorizationUrl = service.getAuthorizationUrl(EMPTY_TOKEN); + final String authorizationUrl = service.getAuthorizationUrl(); System.out.println("Got the Authorization URL!"); System.out.println("Now go and authorize ScribeJava here:"); System.out.println(authorizationUrl); @@ -44,7 +43,7 @@ public static void main(String... args) { // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - final Token accessToken = service.getAccessToken(EMPTY_TOKEN, verifier); + final Token accessToken = service.getAccessToken(verifier); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + " )"); System.out.println(); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LoveFilmExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LoveFilmExample.java index 77ff89061..056d3a6e9 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LoveFilmExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LoveFilmExample.java @@ -8,7 +8,7 @@ import com.github.scribejava.core.model.Token; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.model.Verifier; -import com.github.scribejava.core.oauth.OAuthService; +import com.github.scribejava.core.oauth.OAuth10aService; public abstract class LoveFilmExample { @@ -19,7 +19,7 @@ public static void main(String... args) { // Replace these with your own api key and secret final String apiKey = "your_key"; final String apiSecret = "your_secret"; - final OAuthService service = new ServiceBuilder() + final OAuth10aService service = new ServiceBuilder() .apiKey(apiKey) .apiSecret(apiSecret) .build(LoveFilmApi.instance()); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java index 08d76a96b..cf9d58ef2 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java @@ -10,14 +10,13 @@ import com.github.scribejava.core.model.Token; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.model.Verifier; -import com.github.scribejava.core.oauth.OAuthService; +import com.github.scribejava.core.oauth.OAuth20Service; public abstract class MailruAsyncExample { private static final String NETWORK_NAME = "Mail.ru"; private static final String PROTECTED_RESOURCE_URL = "http://www.appsmail.ru/platform/api?method=users.getInfo&secure=1"; - private static final Token EMPTY_TOKEN = null; public static void main(String... args) throws InterruptedException, ExecutionException { // Replace these with your client id and secret @@ -32,7 +31,7 @@ public static void main(String... args) throws InterruptedException, ExecutionEx .setReadTimeout(1_000) .build(); - final OAuthService service = new ServiceBuilderAsync() + final OAuth20Service service = new ServiceBuilderAsync() .apiKey(clientId) .apiSecret(clientSecret) .callback("http://www.example.com/oauth_callback/") @@ -46,7 +45,7 @@ public static void main(String... args) throws InterruptedException, ExecutionEx // Obtain the Authorization URL System.out.println("Fetching the Authorization URL..."); - final String authorizationUrl = service.getAuthorizationUrl(EMPTY_TOKEN); + final String authorizationUrl = service.getAuthorizationUrl(); System.out.println("Got the Authorization URL!"); System.out.println("Now go and authorize ScribeJava here:"); System.out.println(authorizationUrl); @@ -57,7 +56,7 @@ public static void main(String... args) throws InterruptedException, ExecutionEx // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - final Token accessToken = service.getAccessTokenAsync(EMPTY_TOKEN, verifier, null).get(); + final Token accessToken = service.getAccessTokenAsync(verifier, null).get(); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + " )"); System.out.println(); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java index 52371659d..e64e2635c 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java @@ -7,21 +7,20 @@ import com.github.scribejava.core.model.Token; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.model.Verifier; -import com.github.scribejava.core.oauth.OAuthService; import com.github.scribejava.apis.MailruApi; +import com.github.scribejava.core.oauth.OAuth20Service; public abstract class MailruExample { private static final String NETWORK_NAME = "Mail.ru"; private static final String PROTECTED_RESOURCE_URL = "http://www.appsmail.ru/platform/api?method=users.getInfo&secure=1"; - private static final Token EMPTY_TOKEN = null; public static void main(String... args) { // Replace these with your client id and secret final String clientId = "your client id"; final String clientSecret = "your client secret"; - final OAuthService service = new ServiceBuilder() + final OAuth20Service service = new ServiceBuilder() .apiKey(clientId) .apiSecret(clientSecret) .callback("http://www.example.com/oauth_callback/") @@ -34,7 +33,7 @@ public static void main(String... args) { // Obtain the Authorization URL System.out.println("Fetching the Authorization URL..."); - final String authorizationUrl = service.getAuthorizationUrl(EMPTY_TOKEN); + final String authorizationUrl = service.getAuthorizationUrl(); System.out.println("Got the Authorization URL!"); System.out.println("Now go and authorize ScribeJava here:"); System.out.println(authorizationUrl); @@ -45,7 +44,7 @@ public static void main(String... args) { // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - final Token accessToken = service.getAccessToken(EMPTY_TOKEN, verifier); + final Token accessToken = service.getAccessToken(verifier); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + " )"); System.out.println(); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java index 477c2f5f3..19d2dfe20 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java @@ -8,14 +8,14 @@ import com.github.scribejava.core.model.Token; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.model.Verifier; -import com.github.scribejava.core.oauth.OAuthService; +import com.github.scribejava.core.oauth.OAuth10aService; public abstract class MeetupExample { private static final String PROTECTED_RESOURCE_URL = "http://api.meetup.com/2/member/self"; public static void main(String... args) { - final OAuthService service = new ServiceBuilder() + final OAuth10aService service = new ServiceBuilder() .apiKey("your client id") .apiSecret("your client secret") .build(MeetupApi.instance()); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NeteaseWeiboExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NeteaseWeiboExample.java index 53bcf34ab..f5203070e 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NeteaseWeiboExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NeteaseWeiboExample.java @@ -8,7 +8,7 @@ import com.github.scribejava.core.model.Token; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.model.Verifier; -import com.github.scribejava.core.oauth.OAuthService; +import com.github.scribejava.core.oauth.OAuth10aService; public abstract class NeteaseWeiboExample { @@ -19,7 +19,7 @@ public static void main(String... args) { // Replace these with your own api key and secret final String apiKey = "your key"; final String apiSecret = "your secret"; - final OAuthService service = new ServiceBuilder() + final OAuth10aService service = new ServiceBuilder() .apiKey(apiKey) .apiSecret(apiSecret) .build(NeteaseWeibooApi.instance()); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java index e5a7d540d..3b703f124 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java @@ -8,14 +8,13 @@ import com.github.scribejava.core.model.Token; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.model.Verifier; -import com.github.scribejava.core.oauth.OAuthService; +import com.github.scribejava.core.oauth.OAuth20Service; public abstract class OdnoklassnikiExample { private static final String NETWORK_NAME = "Odnoklassniki.ru"; private static final String PROTECTED_RESOURCE_URL = "http://api.odnoklassniki.ru/api/users/getCurrentUser?application_key=%1$s&format=JSON"; - private static final Token EMPTY_TOKEN = null; public static void main(String... args) { // Replace these with your client id and secret @@ -23,7 +22,7 @@ public static void main(String... args) { final String publicKey = "your api secret"; final String clientSecret = "your client secret"; - final OAuthService service = new ServiceBuilder() + final OAuth20Service service = new ServiceBuilder() .apiKey(clientId) .apiSecret(clientSecret) .scope("VALUABLE ACCESS") @@ -37,7 +36,7 @@ public static void main(String... args) { // Obtain the Authorization URL System.out.println("Fetching the Authorization URL..."); - final String authorizationUrl = service.getAuthorizationUrl(EMPTY_TOKEN); + final String authorizationUrl = service.getAuthorizationUrl(); System.out.println("Got the Authorization URL!"); System.out.println("Now go and authorize ScribeJava here:"); System.out.println(authorizationUrl); @@ -49,7 +48,7 @@ public static void main(String... args) { // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - final Token accessToken = service.getAccessToken(EMPTY_TOKEN, verifier); + final Token accessToken = service.getAccessToken(verifier); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + " )"); System.out.println(); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java index e07f2bdf1..72aba4cb7 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java @@ -7,20 +7,19 @@ import com.github.scribejava.core.model.Token; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.model.Verifier; -import com.github.scribejava.core.oauth.OAuthService; +import com.github.scribejava.core.oauth.OAuth20Service; import java.util.Scanner; public abstract class PinterestExample { private static final String PROTECTED_RESOURCE_URL = "https://api.pinterest.com/v1/me/?access_token?access_token="; - private static final Token EMPTY_TOKEN = null; public static void main(String... args) { // Replace these with your own api key and secret final String apiKey = "your_app_id"; final String apiSecret = "your_app_secret"; - final OAuthService service = new ServiceBuilder() + final OAuth20Service service = new ServiceBuilder() .apiKey(apiKey) .apiSecret(apiSecret) .scope("read_public,write_public,read_relationships,write_relationships") @@ -33,7 +32,7 @@ public static void main(String... args) { // Obtain the Authorization URL System.out.println("Fetching the Authorization URL..."); - final String authorizationUrl = service.getAuthorizationUrl(EMPTY_TOKEN); + final String authorizationUrl = service.getAuthorizationUrl(); System.out.println("Got the Authorization URL!"); System.out.println("Now go and authorize ScribeJava here:"); System.out.println(authorizationUrl); @@ -44,7 +43,7 @@ public static void main(String... args) { // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - final Token accessToken = service.getAccessToken(EMPTY_TOKEN, verifier); + final Token accessToken = service.getAccessToken(verifier); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + " )"); System.out.println(); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Px500Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Px500Example.java index 893182013..5ea537229 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Px500Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Px500Example.java @@ -8,14 +8,14 @@ import com.github.scribejava.core.model.Token; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.model.Verifier; -import com.github.scribejava.core.oauth.OAuthService; +import com.github.scribejava.core.oauth.OAuth10aService; public abstract class Px500Example { private static final String PROTECTED_RESOURCE_URL = "https://api.500px.com/v1/"; public static void main(String... args) { - final OAuthService service = new ServiceBuilder() + final OAuth10aService service = new ServiceBuilder() .apiKey("your-api-key") .apiSecret("your-api-secret") .build(Px500Api.instance()); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java index 404a1219a..ba7710fd4 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java @@ -17,19 +17,18 @@ import com.github.scribejava.core.model.Token; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.model.Verifier; -import com.github.scribejava.core.oauth.OAuthService; +import com.github.scribejava.core.oauth.OAuth20Service; public abstract class RenrenExample { private static final String NETWORK_NAME = "Renren"; private static final String PROTECTED_RESOURCE_URL = "http://api.renren.com/restserver.do"; - private static final Token EMPTY_TOKEN = null; public static void main(String... args) { // Replace these with your own api key and secret final String apiKey = "your api key"; final String apiSecret = "your api secret"; - final OAuthService service = new ServiceBuilder() + final OAuth20Service service = new ServiceBuilder() .apiKey(apiKey) .apiSecret(apiSecret) .scope("status_update publish_feed") @@ -42,7 +41,7 @@ public static void main(String... args) { // Obtain the Authorization URL System.out.println("Fetching the Authorization URL..."); - final String authorizationUrl = service.getAuthorizationUrl(EMPTY_TOKEN); + final String authorizationUrl = service.getAuthorizationUrl(); System.out.println("Got the Authorization URL!"); System.out.println("Now go and authorize ScribeJava here:"); System.out.println(authorizationUrl); @@ -53,7 +52,7 @@ public static void main(String... args) { // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - final Token accessToken = service.getAccessToken(EMPTY_TOKEN, verifier); + final Token accessToken = service.getAccessToken(verifier); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + " )"); System.out.println(); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeibo2Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeibo2Example.java index 1e9a8f65d..cb84b889d 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeibo2Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeibo2Example.java @@ -8,19 +8,18 @@ import com.github.scribejava.core.model.Token; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.model.Verifier; -import com.github.scribejava.core.oauth.OAuthService; +import com.github.scribejava.core.oauth.OAuth20Service; public abstract class SinaWeibo2Example { private static final String NETWORK_NAME = "SinaWeibo"; private static final String PROTECTED_RESOURCE_URL = "https://api.weibo.com/2/account/get_uid.json"; - private static final Token EMPTY_TOKEN = null; public static void main(String... args) { // Replace these with your own api key and secret final String apiKey = "your_api_key"; final String apiSecret = "your_api_secret"; - final OAuthService service = new ServiceBuilder() + final OAuth20Service service = new ServiceBuilder() .apiKey(apiKey) .apiSecret(apiSecret) .callback("http://www.dajie.com/oauth/sina") @@ -32,7 +31,7 @@ public static void main(String... args) { // Obtain the Authorization URL System.out.println("Fetching the Authorization URL..."); - final String authorizationUrl = service.getAuthorizationUrl(EMPTY_TOKEN); + final String authorizationUrl = service.getAuthorizationUrl(); System.out.println("Got the Authorization URL!"); System.out.println("Now go and authorize ScribeJava here:"); System.out.println(authorizationUrl); @@ -43,7 +42,7 @@ public static void main(String... args) { // Trade the Request Token and Verifier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - final Token accessToken = service.getAccessToken(EMPTY_TOKEN, verifier); + final Token accessToken = service.getAccessToken(verifier); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + " )"); System.out.println(); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeiboExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeiboExample.java index f7b9f091c..26688ba97 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeiboExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeiboExample.java @@ -8,7 +8,7 @@ import com.github.scribejava.core.model.Token; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.model.Verifier; -import com.github.scribejava.core.oauth.OAuthService; +import com.github.scribejava.core.oauth.OAuth10aService; public abstract class SinaWeiboExample { @@ -19,7 +19,7 @@ public static void main(String... args) { // Replace these with your own api key and secret final String apiKey = "your key"; final String apiSecret = "your secret"; - final OAuthService service = new ServiceBuilder() + final OAuth10aService service = new ServiceBuilder() .apiKey(apiKey) .apiSecret(apiSecret) .build(SinaWeiboApi.instance()); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SkyrockExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SkyrockExample.java index bcd2e2b1f..e4709069e 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SkyrockExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SkyrockExample.java @@ -8,14 +8,14 @@ import com.github.scribejava.core.model.Token; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.model.Verifier; -import com.github.scribejava.core.oauth.OAuthService; +import com.github.scribejava.core.oauth.OAuth10aService; public abstract class SkyrockExample { private static final String PROTECTED_RESOURCE_URL = "https://api.skyrock.com/v2/user/get.json"; public static void main(String... args) { - final OAuthService service = new ServiceBuilder() + final OAuth10aService service = new ServiceBuilder() .apiKey("your-api-key") .apiSecret("your-api-secret") .build(SkyrockApi.instance()); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SohuWeiboExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SohuWeiboExample.java index 8860a89ba..3ffb76c71 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SohuWeiboExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SohuWeiboExample.java @@ -8,7 +8,7 @@ import com.github.scribejava.core.model.Token; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.model.Verifier; -import com.github.scribejava.core.oauth.OAuthService; +import com.github.scribejava.core.oauth.OAuth10aService; public abstract class SohuWeiboExample { @@ -19,7 +19,7 @@ public static void main(String... args) { // Replace these with your own api key and secret final String apiKey = "your_key"; final String apiSecret = "your_secret"; - final OAuthService service = new ServiceBuilder() + final OAuth10aService service = new ServiceBuilder() .apiKey(apiKey) .apiSecret(apiSecret) .build(SohuWeiboApi.instance()); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TrelloExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TrelloExample.java index ad151bfec..ba7684c2e 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TrelloExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TrelloExample.java @@ -8,7 +8,7 @@ import com.github.scribejava.core.model.Token; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.model.Verifier; -import com.github.scribejava.core.oauth.OAuthService; +import com.github.scribejava.core.oauth.OAuth10aService; public abstract class TrelloExample { @@ -17,7 +17,7 @@ public abstract class TrelloExample { private static final String PROTECTED_RESOURCE_URL = "https://trello.com/1/members/me"; public static void main(String... args) { - final OAuthService service = new ServiceBuilder() + final OAuth10aService service = new ServiceBuilder() .apiKey(API_KEY) .apiSecret(API_SECRET) .build(TrelloApi.instance()); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TumblrExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TumblrExample.java index c37481321..512ea2924 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TumblrExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TumblrExample.java @@ -8,14 +8,14 @@ import com.github.scribejava.core.model.Token; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.model.Verifier; -import com.github.scribejava.core.oauth.OAuthService; +import com.github.scribejava.core.oauth.OAuth10aService; public abstract class TumblrExample { private static final String PROTECTED_RESOURCE_URL = "http://api.tumblr.com/v2/user/info"; public static void main(String... args) { - final OAuthService service = new ServiceBuilder() + final OAuth10aService service = new ServiceBuilder() .apiKey("MY_CONSUMER_KEY") .apiSecret("MY_CONSUMER_SECRET") // OOB forbidden. We need an url and the better is on the tumblr website ! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TutByExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TutByExample.java index fd8dcb448..ebebcc73b 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TutByExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TutByExample.java @@ -9,21 +9,20 @@ import com.github.scribejava.core.model.Token; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.model.Verifier; -import com.github.scribejava.core.oauth.OAuthService; import com.github.scribejava.apis.TutByApi; +import com.github.scribejava.core.oauth.OAuth20Service; public abstract class TutByExample { private static final String NETWORK_NAME = "Tut.by"; private static final String PROTECTED_RESOURCE_URL = "http://profile.tut.by/getInfo"; - private static final Token EMPTY_TOKEN = null; public static void main(String... args) { // Replace these with your client id and secret final String clientId = "your client id"; final String clientSecret = "your client secret"; - final OAuthService service = new ServiceBuilder() + final OAuth20Service service = new ServiceBuilder() .apiKey(clientId) .apiSecret(clientSecret) .grantType(OAuthConstants.AUTHORIZATION_CODE) @@ -35,7 +34,7 @@ public static void main(String... args) { System.out.println(); System.out.println("Fetching the Authorization URL..."); - final String authorizationUrl = service.getAuthorizationUrl(EMPTY_TOKEN); + final String authorizationUrl = service.getAuthorizationUrl(); System.out.println("Got the Authorization URL!"); System.out.println("Now go and authorize ScribeJava here:"); System.out.println(authorizationUrl); @@ -46,7 +45,7 @@ public static void main(String... args) { // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - final Token accessToken = service.getAccessToken(EMPTY_TOKEN, verifier); + final Token accessToken = service.getAccessToken(verifier); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + " )"); System.out.println(); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TwitterExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TwitterExample.java index ec34bf421..ed4c9d1a4 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TwitterExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TwitterExample.java @@ -8,14 +8,14 @@ import com.github.scribejava.core.model.Token; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.model.Verifier; -import com.github.scribejava.core.oauth.OAuthService; +import com.github.scribejava.core.oauth.OAuth10aService; public abstract class TwitterExample { private static final String PROTECTED_RESOURCE_URL = "https://api.twitter.com/1.1/account/verify_credentials.json"; public static void main(String... args) { - final OAuthService service = new ServiceBuilder() + final OAuth10aService service = new ServiceBuilder() .apiKey("your client id") .apiSecret("your client secret") .build(TwitterApi.instance()); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ViadeoExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ViadeoExample.java index 3fb315198..e488a5d4e 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ViadeoExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ViadeoExample.java @@ -8,19 +8,18 @@ import com.github.scribejava.core.model.Token; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.model.Verifier; -import com.github.scribejava.core.oauth.OAuthService; +import com.github.scribejava.core.oauth.OAuth20Service; public abstract class ViadeoExample { private static final String NETWORK_NAME = "Viadeo"; private static final String PROTECTED_RESOURCE_URL = "https://api.viadeo.com/me?user_detail=full"; - private static final Token EMPTY_TOKEN = null; public static void main(String... args) { // Replace these with your own api key and secret final String apiKey = "your_app_id"; final String apiSecret = "your_api_secret"; - final OAuthService service = new ServiceBuilder() + final OAuth20Service service = new ServiceBuilder() .apiKey(apiKey) .apiSecret(apiSecret) .callback("http://www.example.com/oauth_callback/") @@ -32,7 +31,7 @@ public static void main(String... args) { // Obtain the Authorization URL System.out.println("Fetching the Authorization URL..."); - final String authorizationUrl = service.getAuthorizationUrl(EMPTY_TOKEN); + final String authorizationUrl = service.getAuthorizationUrl(); System.out.println("Got the Authorization URL!"); System.out.println("Now go and authorize ScribeJava here:"); System.out.println(authorizationUrl); @@ -43,7 +42,7 @@ public static void main(String... args) { // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - final Token accessToken = service.getAccessToken(EMPTY_TOKEN, verifier); + final Token accessToken = service.getAccessToken(verifier); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + " )"); System.out.println(); 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 a3c0f5065..520de97b5 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExample.java @@ -8,7 +8,7 @@ import com.github.scribejava.core.model.Token; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.model.Verifier; -import com.github.scribejava.core.oauth.OAuthService; +import com.github.scribejava.core.oauth.OAuth20Service; /** * @author Boris G. Tsirkin @@ -18,13 +18,12 @@ public abstract class VkontakteExample { private static final String NETWORK_NAME = "Vkontakte.ru"; private static final String PROTECTED_RESOURCE_URL = "https://api.vk.com/method/friends.get"; - private static final Token EMPTY_TOKEN = null; public static void main(String... args) { // Replace these with your client id and secret final String clientId = "your client id"; final String clientSecret = "your client secret"; - final OAuthService service = new ServiceBuilder() + final OAuth20Service service = new ServiceBuilder() .apiKey(clientId) .apiSecret(clientSecret) .scope("friends,wall,offline") // replace with desired scope @@ -37,7 +36,7 @@ public static void main(String... args) { // Obtain the Authorization URL System.out.println("Fetching the Authorization URL..."); - final String authorizationUrl = service.getAuthorizationUrl(EMPTY_TOKEN); + final String authorizationUrl = service.getAuthorizationUrl(); System.out.println("Got the Authorization URL!"); System.out.println("Now go and authorize ScribeJava here:"); System.out.println(authorizationUrl); @@ -48,7 +47,7 @@ public static void main(String... args) { // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - final Token accessToken = service.getAccessToken(EMPTY_TOKEN, verifier); + final Token accessToken = service.getAccessToken(verifier); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + " )"); System.out.println(); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XingExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XingExample.java index ffbadce53..9695e10d6 100755 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XingExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XingExample.java @@ -8,14 +8,14 @@ import com.github.scribejava.core.model.Token; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.model.Verifier; -import com.github.scribejava.core.oauth.OAuthService; +import com.github.scribejava.core.oauth.OAuth10aService; public abstract class XingExample { private static final String PROTECTED_RESOURCE_URL = "https://api.xing.com/v1/users/me"; public static void main(String... args) { - final OAuthService service = new ServiceBuilder() + final OAuth10aService service = new ServiceBuilder() .apiKey("your client id") .apiSecret("your client secret") .build(XingApi.instance()); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/YahooExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/YahooExample.java index 8c999ccc1..7d1bcc24e 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/YahooExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/YahooExample.java @@ -8,7 +8,7 @@ import com.github.scribejava.core.model.Token; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.model.Verifier; -import com.github.scribejava.core.oauth.OAuthService; +import com.github.scribejava.core.oauth.OAuth10aService; public abstract class YahooExample { @@ -16,7 +16,7 @@ public abstract class YahooExample { = "http://social.yahooapis.com/v1/user/A6ROU63MXWDCW3Y5MGCYWVHDJI/profile/status?format=json"; public static void main(String... args) { - final OAuthService service = new ServiceBuilder() + final OAuth10aService service = new ServiceBuilder() .apiKey("your client id") .apiSecret("your client secret") .build(YahooApi.instance()); diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java index b6af6a211..336139574 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 @@ -38,7 +38,11 @@ public OAuth10aService(DefaultApi10a api, OAuthConfig config) { this.api = api; } - @Override + /** + * Retrieve the request token. + * + * @return request token + */ public Token getRequestToken() { final OAuthConfig config = getConfig(); config.log("obtaining request token from " + api.getRequestTokenEndpoint()); @@ -73,7 +77,6 @@ private void addOAuthParams(AbstractRequest request, Token token) { config.log("appended additional OAuth parameters: " + MapUtils.toString(request.getOauthParameters())); } - @Override public Token getAccessToken(Token requestToken, Verifier verifier) { final OAuthConfig config = getConfig(); config.log("obtaining access token from " + api.getAccessTokenEndpoint()); @@ -83,13 +86,20 @@ public Token getAccessToken(Token requestToken, Verifier verifier) { return api.getAccessTokenExtractor().extract(response.getBody()); } - @Override + /** + * Start the request to retrieve the access token. The optionally provided callback will be called with the Token + * when it is available. + * + * @param requestToken request token (obtained previously or null) + * @param verifier verifier code + * @param callback optional callback + * @return Future + */ public Future getAccessTokenAsync(Token requestToken, Verifier verifier, OAuthAsyncRequestCallback callback) { return getAccessTokenAsync(requestToken, verifier, callback, null); } - @Override public Future getAccessTokenAsync(Token requestToken, Verifier verifier, OAuthAsyncRequestCallback callback, ProxyServer proxyServer) { final OAuthConfig config = getConfig(); @@ -141,9 +151,11 @@ public String getVersion() { } /** - * {@inheritDoc} + * Returns the URL where you should redirect your users to authenticate your application. + * + * @param requestToken the request token you need to authorize + * @return the URL where you should redirect your users */ - @Override public String getAuthorizationUrl(Token requestToken) { return api.getAuthorizationUrl(requestToken); } 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 89ffb3fd8..4459455a2 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 @@ -30,22 +30,26 @@ public OAuth20Service(DefaultApi20 api, OAuthConfig config) { this.api = api; } - @Override - public Token getAccessToken(Token requestToken, Verifier verifier) { + public Token getAccessToken(Verifier verifier) { final Response response = createAccessTokenRequest(verifier, new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint(), this)).send(); return api.getAccessTokenExtractor().extract(response.getBody()); } - @Override - public Future getAccessTokenAsync(Token requestToken, Verifier verifier, - OAuthAsyncRequestCallback callback) { - return getAccessTokenAsync(requestToken, verifier, callback, null); + /** + * Start the request to retrieve the access token. The optionally provided callback will be called with the Token + * when it is available. + * + * @param verifier verifier code + * @param callback optional callback + * @return Future + */ + public Future getAccessTokenAsync(Verifier verifier, OAuthAsyncRequestCallback callback) { + return getAccessTokenAsync(verifier, callback, null); } - @Override - public Future getAccessTokenAsync(Token requestToken, Verifier verifier, - OAuthAsyncRequestCallback callback, ProxyServer proxyServer) { + public Future getAccessTokenAsync(Verifier verifier, OAuthAsyncRequestCallback callback, + ProxyServer proxyServer) { final OAuthRequestAsync request = createAccessTokenRequest(verifier, new OAuthRequestAsync(api.getAccessTokenVerb(), api.getAccessTokenEndpoint(), this)); return request.sendAsync(callback, new OAuthRequestAsync.ResponseConverter() { @@ -72,15 +76,6 @@ protected T createAccessTokenRequest(Verifier verifi return request; } - /** - * {@inheritDoc} - */ - @Override - public Token getRequestToken() { - throw new UnsupportedOperationException("Unsupported operation, please use 'getAuthorizationUrl'" - + " and redirect your users there"); - } - /** * {@inheritDoc} */ @@ -98,10 +93,11 @@ public void signRequest(Token accessToken, AbstractRequest request) { } /** - * {@inheritDoc} + * Returns the URL where you should redirect your users to authenticate your application. + * + * @return the URL where you should redirect your users */ - @Override - public String getAuthorizationUrl(Token requestToken) { + public String getAuthorizationUrl() { return api.getAuthorizationUrl(getConfig()); } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java index 6e94bd78a..92fe7840b 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java @@ -1,17 +1,13 @@ package com.github.scribejava.core.oauth; import com.ning.http.client.AsyncHttpClient; -import com.ning.http.client.ProxyServer; -import java.util.concurrent.Future; import com.github.scribejava.core.exceptions.OAuthException; import com.github.scribejava.core.model.AbstractRequest; import com.github.scribejava.core.model.ForceTypeOfHttpRequest; -import com.github.scribejava.core.model.OAuthAsyncRequestCallback; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConfigAsync; import com.github.scribejava.core.model.ScribeJavaConfig; import com.github.scribejava.core.model.Token; -import com.github.scribejava.core.model.Verifier; /** * The main ScribeJava object. @@ -63,15 +59,6 @@ public OAuthConfig getConfig() { return config; } - /** - * Retrieve the request token. - * - * @return request token - */ - public abstract Token getRequestToken(); - - public abstract Token getAccessToken(Token requestToken, Verifier verifier); - /** * Signs am OAuth request * @@ -80,34 +67,10 @@ public OAuthConfig getConfig() { */ public abstract void signRequest(Token accessToken, AbstractRequest request); - /** - * Start the request to retrieve the access token. The optionally provided callback will be called with the Token - * when it is available. - * - * @param requestToken request token (obtained previously or null) - * @param verifier verifier code - * @param callback optional callback - * @return Future - */ - public abstract Future getAccessTokenAsync(Token requestToken, Verifier verifier, - OAuthAsyncRequestCallback callback); - - public abstract Future getAccessTokenAsync(Token requestToken, Verifier verifier, - OAuthAsyncRequestCallback callback, ProxyServer proxyServer); - /** * Returns the OAuth version of the service. * * @return oauth version as string */ public abstract String getVersion(); - - /** - * Returns the URL where you should redirect your users to authenticate your application. - * - * @param requestToken the request token you need to authorize - * @return the URL where you should redirect your users - */ - public abstract String getAuthorizationUrl(Token requestToken); - } From fa4f1a3edeb05e49a51e26509328fead9acf8ae4 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 26 Jan 2016 13:42:41 +0300 Subject: [PATCH 108/882] force to override createAccessTokenRequest method instead of getAccessToken[Async]. So we have async methods for any childs from the box --- .../apis/service/ImgurOAuthServiceImpl.java | 15 ++++++--------- .../scribejava/core/oauth/OAuth10aService.java | 8 ++++---- .../scribejava/core/oauth/OAuth20Service.java | 6 +++--- 3 files changed, 13 insertions(+), 16 deletions(-) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthServiceImpl.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthServiceImpl.java index beaff274d..aacb3c937 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthServiceImpl.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthServiceImpl.java @@ -5,7 +5,6 @@ import com.github.scribejava.core.model.AbstractRequest; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; -import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Token; import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuth20Service; @@ -17,21 +16,19 @@ public ImgurOAuthServiceImpl(DefaultApi20 api, OAuthConfig config) { } @Override - public Token getAccessToken(Verifier verifier) { - final OAuthRequest request = new OAuthRequest(getApi().getAccessTokenVerb(), - getApi().getAccessTokenEndpoint(), this); - request.addBodyParameter(OAuthConstants.CLIENT_ID, getConfig().getApiKey()); - request.addBodyParameter(OAuthConstants.CLIENT_SECRET, getConfig().getApiSecret()); + protected T createAccessTokenRequest(Verifier verifier, T request) { + final OAuthConfig config = getConfig(); + request.addBodyParameter(OAuthConstants.CLIENT_ID, config.getApiKey()); + request.addBodyParameter(OAuthConstants.CLIENT_SECRET, config.getApiSecret()); - if(ImgurApi.isOob(getConfig())) { + if (ImgurApi.isOob(config)) { request.addBodyParameter(OAuthConstants.GRANT_TYPE, "pin"); request.addBodyParameter("pin", verifier.getValue()); } else { request.addBodyParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.AUTHORIZATION_CODE); request.addBodyParameter(OAuthConstants.CODE, verifier.getValue()); } - - return getApi().getAccessTokenExtractor().extract(request.send().getBody()); + return request; } @Override 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 336139574..7dc2e8556 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 @@ -77,7 +77,7 @@ private void addOAuthParams(AbstractRequest request, Token token) { config.log("appended additional OAuth parameters: " + MapUtils.toString(request.getOauthParameters())); } - public Token getAccessToken(Token requestToken, Verifier verifier) { + public final Token getAccessToken(Token requestToken, Verifier verifier) { final OAuthConfig config = getConfig(); config.log("obtaining access token from " + api.getAccessTokenEndpoint()); final OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint(), this); @@ -95,12 +95,12 @@ public Token getAccessToken(Token requestToken, Verifier verifier) { * @param callback optional callback * @return Future */ - public Future getAccessTokenAsync(Token requestToken, Verifier verifier, + public final Future getAccessTokenAsync(Token requestToken, Verifier verifier, OAuthAsyncRequestCallback callback) { return getAccessTokenAsync(requestToken, verifier, callback, null); } - public Future getAccessTokenAsync(Token requestToken, Verifier verifier, + public final Future getAccessTokenAsync(Token requestToken, Verifier verifier, OAuthAsyncRequestCallback callback, ProxyServer proxyServer) { final OAuthConfig config = getConfig(); config.log("async obtaining access token from " + api.getAccessTokenEndpoint()); @@ -116,7 +116,7 @@ public Token convert(com.ning.http.client.Response response) throws IOException }, proxyServer); } - private void prepareAccessTokenRequest(AbstractRequest request, Token requestToken, Verifier verifier) { + protected void prepareAccessTokenRequest(AbstractRequest request, Token requestToken, Verifier verifier) { final OAuthConfig config = getConfig(); request.addOAuthParameter(OAuthConstants.TOKEN, requestToken.getToken()); request.addOAuthParameter(OAuthConstants.VERIFIER, verifier.getValue()); 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 4459455a2..8196ee643 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 @@ -30,7 +30,7 @@ public OAuth20Service(DefaultApi20 api, OAuthConfig config) { this.api = api; } - public Token getAccessToken(Verifier verifier) { + public final Token getAccessToken(Verifier verifier) { final Response response = createAccessTokenRequest(verifier, new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint(), this)).send(); return api.getAccessTokenExtractor().extract(response.getBody()); @@ -44,11 +44,11 @@ public Token getAccessToken(Verifier verifier) { * @param callback optional callback * @return Future */ - public Future getAccessTokenAsync(Verifier verifier, OAuthAsyncRequestCallback callback) { + public final Future getAccessTokenAsync(Verifier verifier, OAuthAsyncRequestCallback callback) { return getAccessTokenAsync(verifier, callback, null); } - public Future getAccessTokenAsync(Verifier verifier, OAuthAsyncRequestCallback callback, + public final Future getAccessTokenAsync(Verifier verifier, OAuthAsyncRequestCallback callback, ProxyServer proxyServer) { final OAuthRequestAsync request = createAccessTokenRequest(verifier, new OAuthRequestAsync(api.getAccessTokenVerb(), api.getAccessTokenEndpoint(), this)); From f3d2443d54bad15852af06a63d764931b11c2ec4 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 26 Jan 2016 14:52:29 +0300 Subject: [PATCH 109/882] update changelog --- changelog | 1 + 1 file changed, 1 insertion(+) diff --git a/changelog b/changelog index 95084896f..b94e5b31e 100644 --- a/changelog +++ b/changelog @@ -2,6 +2,7 @@ * Let GoogleApi20 supports OOB * Updated Imgur API to OAuth2 * force not to instantiate stateless APIs. Use provided singletons + * reduce OAuthService abstraction for OAuth1 and OAuth2. Separate OAuth(1|2)Services [2.1.0] * add Pinterest API From 1feb66bd47339726e7df34539b9a0ab650875f24 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 26 Jan 2016 15:11:48 +0300 Subject: [PATCH 110/882] prepare to release 2.2.0 --- README.md | 4 ++-- changelog | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 683e7efc8..529e5743e 100644 --- a/README.md +++ b/README.md @@ -79,7 +79,7 @@ You can pull ScribeJava from the central maven repository, just add these to you com.github.scribejava scribejava-apis - 2.1.0 + 2.2.0 ``` @@ -88,7 +88,7 @@ And in case you need just core classes (that's it, without any external API (FB, com.github.scribejava scribejava-core - 2.1.0 + 2.2.0 ``` diff --git a/changelog b/changelog index b94e5b31e..7760c0177 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,4 @@ -[SNAPSHOT] +[2.2.0] * Let GoogleApi20 supports OOB * Updated Imgur API to OAuth2 * force not to instantiate stateless APIs. Use provided singletons From 83698223656ba4e74ce1c1b3bdb6cff2aab4e0bb Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 26 Jan 2016 15:12:50 +0300 Subject: [PATCH 111/882] [maven-release-plugin] prepare release scribejava-2.2.0 --- pom.xml | 2 +- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index c2f0b77ff..ba4986b69 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 2.1.1-SNAPSHOT + 2.2.0 ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index dc52a3f14..a6bf47b4a 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 2.1.1-SNAPSHOT + 2.2.0 ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 8cbcef80c..e221d35c5 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 2.1.1-SNAPSHOT + 2.2.0 ../pom.xml From 2b9a7a168aec618c86c20f7e5681159d2d777b7b Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 26 Jan 2016 15:12:55 +0300 Subject: [PATCH 112/882] [maven-release-plugin] prepare for next development iteration --- pom.xml | 2 +- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index ba4986b69..5f079b348 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 2.2.0 + 2.2.1-SNAPSHOT ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index a6bf47b4a..ecc3c51c5 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 2.2.0 + 2.2.1-SNAPSHOT ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index e221d35c5..42ccd77ef 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 2.2.0 + 2.2.1-SNAPSHOT ../pom.xml From d18c12743e644975c08e8c37d6c829c7e671983d Mon Sep 17 00:00:00 2001 From: Michal Foksa Date: Sun, 31 Jan 2016 21:07:35 +0100 Subject: [PATCH 113/882] Upgrade to Facebook API Version 2.5. --- .../com/github/scribejava/apis/FacebookApi.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java index b7b327ddd..915d4010b 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java @@ -1,15 +1,21 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.extractors.AccessTokenExtractor; +import com.github.scribejava.core.extractors.JsonTokenExtractor; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.utils.OAuthEncoder; import com.github.scribejava.core.utils.Preconditions; +/*** + * Facebook v2.5 API + * + */ public class FacebookApi extends DefaultApi20 { private static final String AUTHORIZE_URL - = "https://www.facebook.com/v2.2/dialog/oauth?client_id=%s&redirect_uri=%s"; + = "https://www.facebook.com/v2.5/dialog/oauth?client_id=%s&redirect_uri=%s"; private FacebookApi() { } @@ -22,9 +28,15 @@ public static FacebookApi instance() { return InstanceHolder.INSTANCE; } + @Override + public AccessTokenExtractor getAccessTokenExtractor() { + + return new JsonTokenExtractor(); + } + @Override public String getAccessTokenEndpoint() { - return "https://graph.facebook.com/v2.2/oauth/access_token"; + return "https://graph.facebook.com/v2.5/oauth/access_token"; } @Override From 7fed77379907079f61ff4f089556210b1d60be87 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 1 Feb 2016 18:24:36 +0300 Subject: [PATCH 114/882] add changelog entry + update vsersions in the Examples for FB --- changelog | 3 +++ .../github/scribejava/apis/examples/FacebookAsyncExample.java | 2 +- .../com/github/scribejava/apis/examples/FacebookExample.java | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/changelog b/changelog index 7760c0177..fd250c9f1 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,6 @@ +[SNAPSHOT] + * Update Facebook API v2.2 -> v2.5 + [2.2.0] * Let GoogleApi20 supports OOB * Updated Imgur API to OAuth2 diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncExample.java index 7198ad97e..cf1492ba4 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncExample.java @@ -18,7 +18,7 @@ public abstract class FacebookAsyncExample { private static final String NETWORK_NAME = "Facebook"; - private static final String PROTECTED_RESOURCE_URL = "https://graph.facebook.com/v2.2/me"; + private static final String PROTECTED_RESOURCE_URL = "https://graph.facebook.com/v2.5/me"; public static void main(String... args) throws InterruptedException, ExecutionException { // Replace these with your client id and secret diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java index 64f34907c..47c62db22 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java @@ -14,7 +14,7 @@ public abstract class FacebookExample { private static final String NETWORK_NAME = "Facebook"; - private static final String PROTECTED_RESOURCE_URL = "https://graph.facebook.com/v2.2/me"; + private static final String PROTECTED_RESOURCE_URL = "https://graph.facebook.com/v2.5/me"; public static void main(String... args) { // Replace these with your client id and secret From 56ae548920bfa49b0ccb49c8c8475239f930f314 Mon Sep 17 00:00:00 2001 From: Irina Garanina Date: Tue, 2 Feb 2016 10:39:21 +0300 Subject: [PATCH 115/882] HH-57818 update HH-api --- .../main/java/com/github/scribejava/apis/HHApi.java | 11 ++++++----- .../github/scribejava/apis/examples/HHExample.java | 1 + 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/HHApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/HHApi.java index 228b4ae10..a808b03e1 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/HHApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/HHApi.java @@ -4,17 +4,18 @@ import com.github.scribejava.core.extractors.AccessTokenExtractor; import com.github.scribejava.core.extractors.JsonTokenExtractor; import com.github.scribejava.core.model.OAuthConfig; -import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.Verb; import com.github.scribejava.apis.service.HHOAuthServiceImpl; import com.github.scribejava.core.oauth.OAuth20Service; +import com.github.scribejava.core.utils.OAuthEncoder; public class HHApi extends DefaultApi20 { - private static final String AUTHORIZE_URL = "https://m.hh.ru/oauth/authorize?response_type=code&client_id=%s"; - private static final String TOKEN_URL = "https://m.hh.ru/oauth/token?grant_type=" - + OAuthConstants.AUTHORIZATION_CODE; + private static final String AUTHORIZE_URL = "https://hh.ru/oauth/authorize?response_type=code&" + + "client_id=%s&redirect_uri=%s"; + + private static final String TOKEN_URL = "https://hh.ru/oauth/token"; private HHApi() { } @@ -39,7 +40,7 @@ public String getAccessTokenEndpoint() { @Override public String getAuthorizationUrl(OAuthConfig config) { - return String.format(AUTHORIZE_URL, config.getApiKey()); + return String.format(AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback())); } @Override diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HHExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HHExample.java index edc5cb121..b30732ba4 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HHExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HHExample.java @@ -25,6 +25,7 @@ public static void main(String... args) { .apiKey(clientId) .apiSecret(clientSecret) .callback("http://your.site.com/callback") + .grantType("authorization_code") .build(HHApi.instance()); final Scanner in = new Scanner(System.in); From ffe66b92e1b3f955d2e83b5f3d82d553ad00736a Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 2 Feb 2016 11:35:48 +0300 Subject: [PATCH 116/882] prepare changelog and readme for the new release --- README.md | 4 ++-- changelog | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 529e5743e..2d9d59b6a 100644 --- a/README.md +++ b/README.md @@ -79,7 +79,7 @@ You can pull ScribeJava from the central maven repository, just add these to you com.github.scribejava scribejava-apis - 2.2.0 + 2.2.1 ``` @@ -88,7 +88,7 @@ And in case you need just core classes (that's it, without any external API (FB, com.github.scribejava scribejava-core - 2.2.0 + 2.2.1 ``` diff --git a/changelog b/changelog index fd250c9f1..e459a42b6 100644 --- a/changelog +++ b/changelog @@ -1,5 +1,6 @@ -[SNAPSHOT] +[2.2.1] * Update Facebook API v2.2 -> v2.5 + * Update hh.ru urls [2.2.0] * Let GoogleApi20 supports OOB From d570ef985ab9d0f92a83214d51452dada4b47a12 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 2 Feb 2016 11:36:33 +0300 Subject: [PATCH 117/882] [maven-release-plugin] prepare release scribejava-2.2.1 --- pom.xml | 2 +- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 5f079b348..fb79048ab 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 2.2.1-SNAPSHOT + 2.2.1 ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index ecc3c51c5..e786770f2 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 2.2.1-SNAPSHOT + 2.2.1 ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 42ccd77ef..5e6c8370a 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 2.2.1-SNAPSHOT + 2.2.1 ../pom.xml From cf504ccae567de769e73d84736b443190dac5eb0 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 2 Feb 2016 11:36:38 +0300 Subject: [PATCH 118/882] [maven-release-plugin] prepare for next development iteration --- pom.xml | 2 +- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index fb79048ab..92701b1dc 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 2.2.1 + 2.2.2-SNAPSHOT ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index e786770f2..ed13b7aeb 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 2.2.1 + 2.2.2-SNAPSHOT ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 5e6c8370a..f551ccce7 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 2.2.1 + 2.2.2-SNAPSHOT ../pom.xml From 38dfffe9811c1eef539a472569ce88321673e9ee Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 3 Feb 2016 13:37:07 +0300 Subject: [PATCH 119/882] make APIs be extendsable --- changelog | 3 +++ .../src/main/java/com/github/scribejava/apis/AWeberApi.java | 2 +- .../java/com/github/scribejava/apis/ConstantContactApi.java | 2 +- .../com/github/scribejava/apis/ConstantContactApi2.java | 2 +- .../src/main/java/com/github/scribejava/apis/DiggApi.java | 2 +- .../java/com/github/scribejava/apis/DoktornaraboteApi.java | 2 +- .../main/java/com/github/scribejava/apis/DropBoxApi.java | 2 +- .../main/java/com/github/scribejava/apis/EvernoteApi.java | 2 +- .../main/java/com/github/scribejava/apis/FacebookApi.java | 2 +- .../src/main/java/com/github/scribejava/apis/FlickrApi.java | 2 +- .../java/com/github/scribejava/apis/Foursquare2Api.java | 2 +- .../main/java/com/github/scribejava/apis/FoursquareApi.java | 2 +- .../main/java/com/github/scribejava/apis/FreelancerApi.java | 2 +- .../main/java/com/github/scribejava/apis/GetGlueApi.java | 2 +- .../src/main/java/com/github/scribejava/apis/GitHubApi.java | 2 +- .../src/main/java/com/github/scribejava/apis/GoogleApi.java | 2 +- .../main/java/com/github/scribejava/apis/GoogleApi20.java | 2 +- .../src/main/java/com/github/scribejava/apis/HHApi.java | 2 +- .../src/main/java/com/github/scribejava/apis/ImgurApi.java | 2 +- .../src/main/java/com/github/scribejava/apis/KaixinApi.java | 2 +- .../main/java/com/github/scribejava/apis/KaixinApi20.java | 2 +- .../main/java/com/github/scribejava/apis/LinkedInApi20.java | 2 +- .../src/main/java/com/github/scribejava/apis/LiveApi.java | 2 +- .../main/java/com/github/scribejava/apis/LoveFilmApi.java | 2 +- .../src/main/java/com/github/scribejava/apis/MailruApi.java | 2 +- .../src/main/java/com/github/scribejava/apis/MeetupApi.java | 2 +- .../main/java/com/github/scribejava/apis/MendeleyApi.java | 2 +- .../src/main/java/com/github/scribejava/apis/MisoApi.java | 2 +- .../main/java/com/github/scribejava/apis/NetProspexApi.java | 2 +- .../java/com/github/scribejava/apis/NeteaseWeibooApi.java | 2 +- .../java/com/github/scribejava/apis/OdnoklassnikiApi.java | 2 +- .../main/java/com/github/scribejava/apis/PinterestApi.java | 2 +- .../src/main/java/com/github/scribejava/apis/PlurkApi.java | 2 +- .../src/main/java/com/github/scribejava/apis/Px500Api.java | 2 +- .../src/main/java/com/github/scribejava/apis/QWeiboApi.java | 2 +- .../src/main/java/com/github/scribejava/apis/RenrenApi.java | 2 +- .../src/main/java/com/github/scribejava/apis/SapoApi.java | 2 +- .../main/java/com/github/scribejava/apis/SimpleGeoApi.java | 2 +- .../main/java/com/github/scribejava/apis/SinaWeiboApi.java | 2 +- .../java/com/github/scribejava/apis/SinaWeiboApi20.java | 2 +- .../main/java/com/github/scribejava/apis/SkyrockApi.java | 2 +- .../main/java/com/github/scribejava/apis/SohuWeiboApi.java | 2 +- .../src/main/java/com/github/scribejava/apis/TrelloApi.java | 2 +- .../src/main/java/com/github/scribejava/apis/TumblrApi.java | 2 +- .../src/main/java/com/github/scribejava/apis/TutByApi.java | 2 +- .../main/java/com/github/scribejava/apis/TwitterApi.java | 2 +- .../main/java/com/github/scribejava/apis/UbuntuOneApi.java | 2 +- .../src/main/java/com/github/scribejava/apis/ViadeoApi.java | 2 +- .../src/main/java/com/github/scribejava/apis/VimeoApi.java | 2 +- .../main/java/com/github/scribejava/apis/VkontakteApi.java | 2 +- .../src/main/java/com/github/scribejava/apis/XingApi.java | 2 +- .../src/main/java/com/github/scribejava/apis/YahooApi.java | 2 +- .../src/main/java/com/github/scribejava/apis/YammerApi.java | 2 +- .../java/com/github/scribejava/apis/google/GoogleToken.java | 2 ++ .../scribejava/core/builder/AbstractServiceBuilder.java | 2 +- .../core/exceptions/OAuthConnectionException.java | 1 + .../scribejava/core/extractors/BaseStringExtractorTest.java | 3 +-- .../scribejava/core/extractors/HeaderExtractorTest.java | 3 +-- .../scribejava/core/extractors/TokenExtractor20Test.java | 3 +-- .../scribejava/core/extractors/TokenExtractorTest.java | 3 +-- .../com/github/scribejava/core/model/ParameterListTest.java | 3 +-- .../com/github/scribejava/core/utils/OAuthEncoderTest.java | 6 ++---- .../com/github/scribejava/core/utils/StreamUtilsTest.java | 3 +-- 63 files changed, 67 insertions(+), 69 deletions(-) diff --git a/changelog b/changelog index e459a42b6..ce637d63b 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,6 @@ +[SNAPSHOT] + * make all APIs to be extentable (have protected constructors, useful for testing) + [2.2.1] * Update Facebook API v2.2 -> v2.5 * Update hh.ru urls diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/AWeberApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/AWeberApi.java index 4c95cef93..d35d58031 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/AWeberApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/AWeberApi.java @@ -9,7 +9,7 @@ public class AWeberApi extends DefaultApi10a { private static final String REQUEST_TOKEN_ENDPOINT = "https://auth.aweber.com/1.0/oauth/request_token"; private static final String ACCESS_TOKEN_ENDPOINT = "https://auth.aweber.com/1.0/oauth/access_token"; - private AWeberApi() { + protected AWeberApi() { } private static class InstanceHolder { diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/ConstantContactApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/ConstantContactApi.java index f40583e5e..102e2bda9 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/ConstantContactApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/ConstantContactApi.java @@ -8,7 +8,7 @@ public class ConstantContactApi extends DefaultApi10a { private static final String AUTHORIZE_URL = "https://oauth.constantcontact.com/ws/oauth/confirm_access?oauth_token=%s"; - private ConstantContactApi() { + protected ConstantContactApi() { } private static class InstanceHolder { diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/ConstantContactApi2.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/ConstantContactApi2.java index 62b2aaa19..07879e2fa 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/ConstantContactApi2.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/ConstantContactApi2.java @@ -37,7 +37,7 @@ public Token extract(String response) { } }; - private ConstantContactApi2() { + protected ConstantContactApi2() { } private static class InstanceHolder { diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/DiggApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/DiggApi.java index 97897c76f..f5d71d7dd 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/DiggApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/DiggApi.java @@ -8,7 +8,7 @@ public class DiggApi extends DefaultApi10a { private static final String AUTHORIZATION_URL = "http://digg.com/oauth/authorize?oauth_token=%s"; private static final String BASE_URL = "http://services.digg.com/oauth/"; - private DiggApi() { + protected DiggApi() { } private static class InstanceHolder { diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/DoktornaraboteApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/DoktornaraboteApi.java index cb592e36f..2a655103c 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/DoktornaraboteApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/DoktornaraboteApi.java @@ -17,7 +17,7 @@ public class DoktornaraboteApi extends DefaultApi20 { = "http://auth.doktornarabote.ru/OAuth/Authorize?response_type=code&client_id=%s&redirect_uri=%s&scope=%s"; private static final String TOKEN_URL = "http://auth.doktornarabote.ru/OAuth/Token"; - private DoktornaraboteApi() { + protected DoktornaraboteApi() { } private static class InstanceHolder { diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/DropBoxApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/DropBoxApi.java index 08434e783..1f7d23112 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/DropBoxApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/DropBoxApi.java @@ -5,7 +5,7 @@ public class DropBoxApi extends DefaultApi10a { - private DropBoxApi() { + protected DropBoxApi() { } private static class InstanceHolder { diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/EvernoteApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/EvernoteApi.java index 9ebe1ed20..e8b6ac206 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/EvernoteApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/EvernoteApi.java @@ -5,7 +5,7 @@ public class EvernoteApi extends DefaultApi10a { - private EvernoteApi() { + protected EvernoteApi() { } private static class InstanceHolder { 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 915d4010b..2ce748c8c 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 @@ -17,7 +17,7 @@ public class FacebookApi extends DefaultApi20 { private static final String AUTHORIZE_URL = "https://www.facebook.com/v2.5/dialog/oauth?client_id=%s&redirect_uri=%s"; - private FacebookApi() { + protected FacebookApi() { } private static class InstanceHolder { diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/FlickrApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/FlickrApi.java index ef8cb6ebf..3904b78c3 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/FlickrApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/FlickrApi.java @@ -11,7 +11,7 @@ */ public class FlickrApi extends DefaultApi10a { - private FlickrApi() { + protected FlickrApi() { } private static class InstanceHolder { diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/Foursquare2Api.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/Foursquare2Api.java index fee771bd8..15f46c702 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/Foursquare2Api.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/Foursquare2Api.java @@ -13,7 +13,7 @@ public class Foursquare2Api extends DefaultApi20 { private static final String AUTHORIZATION_URL = "https://foursquare.com/oauth2/authenticate?client_id=%s&response_type=code&redirect_uri=%s"; - private Foursquare2Api() { + protected Foursquare2Api() { } private static class InstanceHolder { diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/FoursquareApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/FoursquareApi.java index 1380c4080..6cb9a3833 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/FoursquareApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/FoursquareApi.java @@ -7,7 +7,7 @@ public class FoursquareApi extends DefaultApi10a { private static final String AUTHORIZATION_URL = "http://foursquare.com/oauth/authorize?oauth_token=%s"; - private FoursquareApi() { + protected FoursquareApi() { } private static class InstanceHolder { diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/FreelancerApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/FreelancerApi.java index ea171d2bb..3247e1e08 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/FreelancerApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/FreelancerApi.java @@ -8,7 +8,7 @@ public class FreelancerApi extends DefaultApi10a { private static final String AUTHORIZATION_URL = "http://www.freelancer.com/users/api-token/auth.php?oauth_token=%s"; - private FreelancerApi() { + protected FreelancerApi() { } private static class InstanceHolder { diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/GetGlueApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/GetGlueApi.java index 63e8ce4d9..1983fd871 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/GetGlueApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/GetGlueApi.java @@ -9,7 +9,7 @@ public class GetGlueApi extends DefaultApi10a { private static final String REQUEST_TOKEN_RESOURCE = "https://api.getglue.com/oauth/request_token"; private static final String ACCESS_TOKEN_RESOURCE = "https://api.getglue.com/oauth/access_token"; - private GetGlueApi() { + protected GetGlueApi() { } private static class InstanceHolder { diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/GitHubApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/GitHubApi.java index 6b15f8233..6d48a107f 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/GitHubApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/GitHubApi.java @@ -10,7 +10,7 @@ public class GitHubApi extends DefaultApi20 { private static final String AUTHORIZE_URL = "https://github.com/login/oauth/authorize?client_id=%s&redirect_uri=%s"; - private GitHubApi() { + protected GitHubApi() { } private static class InstanceHolder { diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/GoogleApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/GoogleApi.java index 6191aeb43..a7326a9d1 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/GoogleApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/GoogleApi.java @@ -9,7 +9,7 @@ public class GoogleApi extends DefaultApi10a { private static final String AUTHORIZATION_URL = "https://www.google.com/accounts/OAuthAuthorizeToken?oauth_token=%s"; - private GoogleApi() { + protected GoogleApi() { } private static class InstanceHolder { diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/GoogleApi20.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/GoogleApi20.java index ad68c5a7e..c0ccfd998 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/GoogleApi20.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/GoogleApi20.java @@ -15,7 +15,7 @@ public class GoogleApi20 extends DefaultApi20 { private static final String AUTHORIZE_URL = "https://accounts.google.com/o/oauth2/auth?response_type=code&client_id=%s&redirect_uri=%s&scope=%s"; - private GoogleApi20() { + protected GoogleApi20() { } private static class InstanceHolder { diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/HHApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/HHApi.java index a808b03e1..cae27c68d 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/HHApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/HHApi.java @@ -17,7 +17,7 @@ public class HHApi extends DefaultApi20 { private static final String TOKEN_URL = "https://hh.ru/oauth/token"; - private HHApi() { + protected HHApi() { } private static class InstanceHolder { diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java index 3e1d0c859..c9ded43e9 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java @@ -13,7 +13,7 @@ public class ImgurApi extends DefaultApi20 { private static final String AUTHORIZATION_URL = "https://api.imgur.com/oauth2/authorize?client_id=%s&response_type=%s"; - private ImgurApi() { + protected ImgurApi() { } private static class InstanceHolder { diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/KaixinApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/KaixinApi.java index 1fc0515c3..2678364a7 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/KaixinApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/KaixinApi.java @@ -10,7 +10,7 @@ public class KaixinApi extends DefaultApi10a { private static final String ACCESS_TOKEN_URL = "http://api.kaixin001.com/oauth/access_token"; private static final String AUTHORIZE_URL = "http://api.kaixin001.com/oauth/authorize?oauth_token=%s"; - private KaixinApi() { + protected KaixinApi() { } private static class InstanceHolder { diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/KaixinApi20.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/KaixinApi20.java index 86223a3cb..d4cbaa2e9 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/KaixinApi20.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/KaixinApi20.java @@ -16,7 +16,7 @@ public class KaixinApi20 extends DefaultApi20 { = "http://api.kaixin001.com/oauth2/authorize?client_id=%s&redirect_uri=%s&response_type=code"; private static final String SCOPED_AUTHORIZE_URL = AUTHORIZE_URL + "&scope=%s"; - private KaixinApi20() { + protected KaixinApi20() { } private static class InstanceHolder { diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi20.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi20.java index fd6c271fb..e7f6b4398 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi20.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi20.java @@ -19,7 +19,7 @@ public class LinkedInApi20 extends DefaultApi20 { private static final String SCOPED_AUTHORIZE_URL = AUTHORIZE_URL + "&scope=%s"; - private LinkedInApi20() { + protected LinkedInApi20() { } private static class InstanceHolder { diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/LiveApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/LiveApi.java index d6384e0f3..c3c084ce8 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/LiveApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/LiveApi.java @@ -14,7 +14,7 @@ public class LiveApi extends DefaultApi20 { = "https://oauth.live.com/authorize?client_id=%s&redirect_uri=%s&response_type=code"; private static final String SCOPED_AUTHORIZE_URL = AUTHORIZE_URL + "&scope=%s"; - private LiveApi() { + protected LiveApi() { } private static class InstanceHolder { diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/LoveFilmApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/LoveFilmApi.java index 4f2c2615f..e5cfbf742 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/LoveFilmApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/LoveFilmApi.java @@ -9,7 +9,7 @@ public class LoveFilmApi extends DefaultApi10a { private static final String ACCESS_TOKEN_URL = "http://openapi.lovefilm.com/oauth/access_token"; private static final String AUTHORIZE_URL = "https://www.lovefilm.com/activate?oauth_token=%s"; - private LoveFilmApi() { + protected LoveFilmApi() { } private static class InstanceHolder { diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java index 0348cceef..1bc70bdfa 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java @@ -16,7 +16,7 @@ public class MailruApi extends DefaultApi20 { = "https://connect.mail.ru/oauth/authorize?client_id=%s&redirect_uri=%s&response_type=code"; private static final String SCOPED_AUTHORIZE_URL = AUTHORIZE_URL + "&scope=%s"; - private MailruApi() { + protected MailruApi() { } private static class InstanceHolder { diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/MeetupApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/MeetupApi.java index b39561022..f4a0d112d 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/MeetupApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/MeetupApi.java @@ -10,7 +10,7 @@ public class MeetupApi extends DefaultApi10a { private static final String AUTHORIZE_URL = "http://www.meetup.com/authenticate?oauth_token=%s"; - private MeetupApi() { + protected MeetupApi() { } private static class InstanceHolder { diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/MendeleyApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/MendeleyApi.java index b0d61a323..528243c51 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/MendeleyApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/MendeleyApi.java @@ -12,7 +12,7 @@ public class MendeleyApi extends DefaultApi10a { private static final String AUTHORIZATION_URL = "http://api.mendeley.com/oauth/authorize?oauth_token=%s"; - private MendeleyApi() { + protected MendeleyApi() { } private static class InstanceHolder { diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/MisoApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/MisoApi.java index 107a85d8e..35eaba078 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/MisoApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/MisoApi.java @@ -9,7 +9,7 @@ public class MisoApi extends DefaultApi10a { private static final String REQUEST_TOKEN_RESOURCE = "http://gomiso.com/oauth/request_token"; private static final String ACCESS_TOKEN_RESOURCE = "http://gomiso.com/oauth/access_token"; - private MisoApi() { + protected MisoApi() { } private static class InstanceHolder { diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/NetProspexApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/NetProspexApi.java index 0c84ab0b0..e14291120 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/NetProspexApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/NetProspexApi.java @@ -9,7 +9,7 @@ public class NetProspexApi extends DefaultApi10a { private static final String ACCESS_TOKEN_URL = "https://api.netprospex.com/1.0/oauth/access-token"; private static final String AUTHORIZE_URL = "https://api.netprospex.com/1.0/oauth/authorize?oauth_token=%s"; - private NetProspexApi() { + protected NetProspexApi() { } private static class InstanceHolder { diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/NeteaseWeibooApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/NeteaseWeibooApi.java index 5b85113a0..132d4e034 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/NeteaseWeibooApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/NeteaseWeibooApi.java @@ -10,7 +10,7 @@ public class NeteaseWeibooApi extends DefaultApi10a { private static final String AUTHORIZE_URL = "http://api.t.163.com/oauth/authorize?oauth_token=%s"; private static final String AUTHENTICATE_URL = "http://api.t.163.com/oauth/authenticate?oauth_token=%s"; - private NeteaseWeibooApi() { + protected NeteaseWeibooApi() { } private static class InstanceHolder { diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java index bd3717bb4..7ad00e80b 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java @@ -16,7 +16,7 @@ public class OdnoklassnikiApi extends DefaultApi20 { = "http://www.odnoklassniki.ru/oauth/authorize?client_id=%s&response_type=code&redirect_uri=%s"; private static final String SCOPED_AUTHORIZE_URL = String.format("%s&scope=%%s", AUTHORIZE_URL); - private OdnoklassnikiApi() { + protected OdnoklassnikiApi() { } private static class InstanceHolder { diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/PinterestApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/PinterestApi.java index 92fd91917..a4535a289 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/PinterestApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/PinterestApi.java @@ -15,7 +15,7 @@ public class PinterestApi extends DefaultApi20 { = "https://api.pinterest.com/oauth?response_type=code&client_id=%s&redirect_uri=%s"; private static final String SCOPED_AUTHORIZE_URL = AUTHORIZE_URL + "&scope=%s"; - private PinterestApi() { + protected PinterestApi() { } private static class InstanceHolder { diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/PlurkApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/PlurkApi.java index 344ca94de..4d120f2a5 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/PlurkApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/PlurkApi.java @@ -9,7 +9,7 @@ public class PlurkApi extends DefaultApi10a { private static final String AUTHORIZATION_URL = "http://www.plurk.com/OAuth/authorize?oauth_token=%s"; private static final String ACCESS_TOKEN_URL = "http://www.plurk.com/OAuth/access_token"; - private PlurkApi() { + protected PlurkApi() { } private static class InstanceHolder { diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/Px500Api.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/Px500Api.java index ab618dd84..0c7d41abe 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/Px500Api.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/Px500Api.java @@ -7,7 +7,7 @@ public class Px500Api extends DefaultApi10a { private static final String AUTHORIZATION_URL = "https://api.500px.com/v1/oauth/authorize?oauth_token=%s"; - private Px500Api() { + protected Px500Api() { } private static class InstanceHolder { diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/QWeiboApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/QWeiboApi.java index b1603dadc..e6dfd00c7 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/QWeiboApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/QWeiboApi.java @@ -9,7 +9,7 @@ public class QWeiboApi extends DefaultApi10a { private static final String ACCESS_TOKEN_URL = "https://open.t.qq.com/cgi-bin/access_token"; private static final String AUTHORIZE_URL = "https://open.t.qq.com/cgi-bin/authorize?oauth_token=%s"; - private QWeiboApi() { + protected QWeiboApi() { } private static class InstanceHolder { diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/RenrenApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/RenrenApi.java index 3128d5a3d..216fd8ca8 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/RenrenApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/RenrenApi.java @@ -16,7 +16,7 @@ public class RenrenApi extends DefaultApi20 { = "https://graph.renren.com/oauth/authorize?client_id=%s&redirect_uri=%s&response_type=code"; private static final String SCOPED_AUTHORIZE_URL = AUTHORIZE_URL + "&scope=%s"; - private RenrenApi() { + protected RenrenApi() { } private static class InstanceHolder { diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/SapoApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/SapoApi.java index ec2ab6cf1..99a087fac 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/SapoApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/SapoApi.java @@ -10,7 +10,7 @@ public class SapoApi extends DefaultApi10a { private static final String ACCESS_URL = "https://id.sapo.pt/oauth/access_token"; private static final String REQUEST_URL = "https://id.sapo.pt/oauth/request_token"; - private SapoApi() { + protected SapoApi() { } private static class InstanceHolder { diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/SimpleGeoApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/SimpleGeoApi.java index 99bfa5245..aa9250b5d 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/SimpleGeoApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/SimpleGeoApi.java @@ -10,7 +10,7 @@ public class SimpleGeoApi extends DefaultApi10a { private static final String ENDPOINT = "these are not used since SimpleGeo uses 2 legged OAuth"; - private SimpleGeoApi() { + protected SimpleGeoApi() { } private static class InstanceHolder { diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/SinaWeiboApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/SinaWeiboApi.java index 780d562ad..6bb5f2e64 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/SinaWeiboApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/SinaWeiboApi.java @@ -9,7 +9,7 @@ public class SinaWeiboApi extends DefaultApi10a { private static final String ACCESS_TOKEN_URL = "http://api.t.sina.com.cn/oauth/access_token"; private static final String AUTHORIZE_URL = "http://api.t.sina.com.cn/oauth/authorize?oauth_token=%s"; - private SinaWeiboApi() { + protected SinaWeiboApi() { } private static class InstanceHolder { diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/SinaWeiboApi20.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/SinaWeiboApi20.java index 06a7e8114..87167e10a 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/SinaWeiboApi20.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/SinaWeiboApi20.java @@ -17,7 +17,7 @@ public class SinaWeiboApi20 extends DefaultApi20 { = "https://api.weibo.com/oauth2/authorize?client_id=%s&redirect_uri=%s&response_type=code"; private static final String SCOPED_AUTHORIZE_URL = AUTHORIZE_URL + "&scope=%s"; - private SinaWeiboApi20() { + protected SinaWeiboApi20() { } private static class InstanceHolder { diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/SkyrockApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/SkyrockApi.java index 9f97be7dd..9f1547c31 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/SkyrockApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/SkyrockApi.java @@ -16,7 +16,7 @@ public class SkyrockApi extends DefaultApi10a { private static final String AUTHORIZE_URL = "/oauth/authorize?oauth_token=%s"; private static final String ACCESS_TOKEN_RESOURCE = "/oauth/token"; - private SkyrockApi() { + protected SkyrockApi() { } private static class InstanceHolder { diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/SohuWeiboApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/SohuWeiboApi.java index 1762b1186..688b28a4d 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/SohuWeiboApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/SohuWeiboApi.java @@ -9,7 +9,7 @@ public class SohuWeiboApi extends DefaultApi10a { private static final String ACCESS_TOKEN_URL = "http://api.t.sohu.com/oauth/access_token"; private static final String AUTHORIZE_URL = "http://api.t.sohu.com/oauth/authorize?oauth_token=%s"; - private SohuWeiboApi() { + protected SohuWeiboApi() { } private static class InstanceHolder { diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/TrelloApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/TrelloApi.java index 189809d5a..c00771950 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/TrelloApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/TrelloApi.java @@ -7,7 +7,7 @@ public class TrelloApi extends DefaultApi10a { private static final String AUTHORIZE_URL = "https://trello.com/1/OAuthAuthorizeToken?oauth_token=%s"; - private TrelloApi() { + protected TrelloApi() { } private static class InstanceHolder { diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/TumblrApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/TumblrApi.java index c78d7d1c3..dca910d2d 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/TumblrApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/TumblrApi.java @@ -9,7 +9,7 @@ public class TumblrApi extends DefaultApi10a { private static final String REQUEST_TOKEN_RESOURCE = "http://www.tumblr.com/oauth/request_token"; private static final String ACCESS_TOKEN_RESOURCE = "http://www.tumblr.com/oauth/access_token"; - private TumblrApi() { + protected TumblrApi() { } private static class InstanceHolder { diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/TutByApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/TutByApi.java index 00704b792..25a608eef 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/TutByApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/TutByApi.java @@ -15,7 +15,7 @@ public class TutByApi extends DefaultApi20 { private static final String AUTHORIZE_URL = "http://profile.tut.by/auth?client_id=%s&response_type=code&redirect_uri=%s"; - private TutByApi() { + protected TutByApi() { } private static class InstanceHolder { diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/TwitterApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/TwitterApi.java index 7f967fd98..b730b9c1e 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/TwitterApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/TwitterApi.java @@ -9,7 +9,7 @@ public class TwitterApi extends DefaultApi10a { private static final String REQUEST_TOKEN_RESOURCE = "api.twitter.com/oauth/request_token"; private static final String ACCESS_TOKEN_RESOURCE = "api.twitter.com/oauth/access_token"; - private TwitterApi() { + protected TwitterApi() { } private static class InstanceHolder { diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/UbuntuOneApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/UbuntuOneApi.java index aa4f820f2..45b16d62b 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/UbuntuOneApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/UbuntuOneApi.java @@ -14,7 +14,7 @@ public class UbuntuOneApi extends DefaultApi10a { private static final String AUTHORIZATION_URL = "https://one.ubuntu.com/oauth/authorize/?oauth_token=%s"; - private UbuntuOneApi() { + protected UbuntuOneApi() { } private static class InstanceHolder { diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/ViadeoApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/ViadeoApi.java index b36a451e9..30059ec85 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/ViadeoApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/ViadeoApi.java @@ -14,7 +14,7 @@ public class ViadeoApi extends DefaultApi20 { = "https://secure.viadeo.com/oauth-provider/authorize2?client_id=%s&redirect_uri=%s&response_type=code"; private static final String SCOPED_AUTHORIZE_URL = AUTHORIZE_URL + "&scope=%s"; - private ViadeoApi() { + protected ViadeoApi() { } private static class InstanceHolder { diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/VimeoApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/VimeoApi.java index d3223c70a..667557fac 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/VimeoApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/VimeoApi.java @@ -7,7 +7,7 @@ public class VimeoApi extends DefaultApi10a { private static final String AUTHORIZATION_URL = "http://vimeo.com/oauth/authorize?oauth_token=%s"; - private VimeoApi() { + protected VimeoApi() { } private static class InstanceHolder { diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/VkontakteApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/VkontakteApi.java index 5df5ebfee..66f2ba918 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/VkontakteApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/VkontakteApi.java @@ -17,7 +17,7 @@ public class VkontakteApi extends DefaultApi20 { = "https://oauth.vk.com/authorize?client_id=%s&redirect_uri=%s&response_type=code"; private static final String SCOPED_AUTHORIZE_URL = String.format("%s&scope=%%s", AUTHORIZE_URL); - private VkontakteApi() { + protected VkontakteApi() { } private static class InstanceHolder { diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/XingApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/XingApi.java index a87ccb55f..5bc34a6d4 100755 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/XingApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/XingApi.java @@ -7,7 +7,7 @@ public class XingApi extends DefaultApi10a { private static final String AUTHORIZE_URL = "https://api.xing.com/v1/authorize?oauth_token=%s"; - private XingApi() { + protected XingApi() { } private static class InstanceHolder { diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/YahooApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/YahooApi.java index 2e9403da8..952508143 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/YahooApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/YahooApi.java @@ -7,7 +7,7 @@ public class YahooApi extends DefaultApi10a { private static final String AUTHORIZE_URL = "https://api.login.yahoo.com/oauth/v2/request_auth?oauth_token=%s"; - private YahooApi() { + protected YahooApi() { } private static class InstanceHolder { diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/YammerApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/YammerApi.java index 9dfa0b171..14a98c0c1 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/YammerApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/YammerApi.java @@ -9,7 +9,7 @@ public class YammerApi extends DefaultApi10a { private static final String AUTHORIZATION_URL = "https://www.yammer.com/oauth/authorize?oauth_token=%s"; - private YammerApi() { + protected YammerApi() { } private static class InstanceHolder { diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/google/GoogleToken.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/google/GoogleToken.java index ade166144..c4f98cb3a 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/google/GoogleToken.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/google/GoogleToken.java @@ -4,6 +4,8 @@ public class GoogleToken extends Token { + private static final long serialVersionUID = 5634896204924467956L; + /** * Id_token is part of OpenID Connect specification. It can hold user information that you can directly extract * without additional request to provider. diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/AbstractServiceBuilder.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/AbstractServiceBuilder.java index 6c5283d5d..41468d1c1 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/AbstractServiceBuilder.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/AbstractServiceBuilder.java @@ -10,7 +10,7 @@ import com.github.scribejava.core.oauth.OAuth20Service; import com.github.scribejava.core.utils.Preconditions; -abstract class AbstractServiceBuilder { +abstract class AbstractServiceBuilder> { private String callback; private String apiKey; diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/exceptions/OAuthConnectionException.java b/scribejava-core/src/main/java/com/github/scribejava/core/exceptions/OAuthConnectionException.java index 0038dd96e..c2db1511a 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/exceptions/OAuthConnectionException.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/exceptions/OAuthConnectionException.java @@ -5,6 +5,7 @@ */ public class OAuthConnectionException extends OAuthException { + private static final long serialVersionUID = 6901269342236961310L; private static final String MSG = "There was a problem while creating a connection to the remote service: "; public OAuthConnectionException(String url, Exception e) { 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 e7e39d855..3eb4b7404 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 @@ -87,8 +87,7 @@ public void shouldExcludePort443v2() { @Test(expected = IllegalArgumentException.class) public void shouldThrowExceptionIfRquestIsNull() { - final OAuthRequest nullRequest = null; - extractor.extract(nullRequest); + extractor.extract(null); } @Test(expected = OAuthParametersMissingException.class) 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 832cf10e0..8de9d5c50 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 @@ -38,8 +38,7 @@ public void shouldExtractStandardHeader() { @Test(expected = IllegalArgumentException.class) public void shouldExceptionIfRequestIsNull() { - final OAuthRequest nullRequest = null; - extractor.extract(nullRequest); + extractor.extract(null); } @Test(expected = OAuthParametersMissingException.class) diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/extractors/TokenExtractor20Test.java b/scribejava-core/src/test/java/com/github/scribejava/core/extractors/TokenExtractor20Test.java index 5209966a9..a3930979c 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/extractors/TokenExtractor20Test.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/extractors/TokenExtractor20Test.java @@ -51,8 +51,7 @@ public void shouldThrowExceptionIfTokenIsAbsent() { @Test(expected = IllegalArgumentException.class) public void shouldThrowExceptionIfResponseIsNull() { - final String response = null; - extractor.extract(response); + extractor.extract(null); } @Test(expected = IllegalArgumentException.class) diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/extractors/TokenExtractorTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/extractors/TokenExtractorTest.java index 12650be99..2d97b039e 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/extractors/TokenExtractorTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/extractors/TokenExtractorTest.java @@ -62,8 +62,7 @@ public void shouldThrowExceptionIfSecretIsAbsent() { @Test(expected = IllegalArgumentException.class) public void shouldThrowExceptionIfResponseIsNull() { - final String response = null; - extractor.extract(response); + extractor.extract(null); } @Test(expected = IllegalArgumentException.class) 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 6c4d95549..073aa4ead 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 @@ -20,8 +20,7 @@ public void setUp() { @Test(expected = IllegalArgumentException.class) public void shouldThrowExceptionWhenAppendingNullMapToQuerystring() { - final String url = null; - params.appendTo(url); + params.appendTo(null); } @Test 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 306720861..cc0b76f09 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 @@ -39,14 +39,12 @@ public void shouldNotPercentEncodeReservedCharacters() { @Test(expected = IllegalArgumentException.class) public void shouldThrowExceptionIfStringToEncodeIsNull() { - final String toEncode = null; - OAuthEncoder.encode(toEncode); + OAuthEncoder.encode(null); } @Test(expected = IllegalArgumentException.class) public void shouldThrowExceptionIfStringToDecodeIsNull() { - final String toDecode = null; - OAuthEncoder.decode(toDecode); + OAuthEncoder.decode(null); } @Test 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 d470edf0e..6766e7680 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 @@ -19,8 +19,7 @@ public void shouldCorrectlyDecodeAStream() { @Test(expected = IllegalArgumentException.class) public void shouldFailForNullParameter() { - final InputStream is = null; - StreamUtils.getStreamContents(is); + StreamUtils.getStreamContents(null); fail("Must throw exception before getting here"); } From 68dc0bc8a1209022c5aafc1b946ce9639561f70c Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 4 Feb 2016 14:53:35 +0300 Subject: [PATCH 120/882] prepare to release 2.2.2 --- README.md | 4 ++-- changelog | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 2d9d59b6a..9024a2478 100644 --- a/README.md +++ b/README.md @@ -79,7 +79,7 @@ You can pull ScribeJava from the central maven repository, just add these to you com.github.scribejava scribejava-apis - 2.2.1 + 2.2.2 ``` @@ -88,7 +88,7 @@ And in case you need just core classes (that's it, without any external API (FB, com.github.scribejava scribejava-core - 2.2.1 + 2.2.2 ``` diff --git a/changelog b/changelog index ce637d63b..47750f620 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,4 @@ -[SNAPSHOT] +[2.2.2] * make all APIs to be extentable (have protected constructors, useful for testing) [2.2.1] From cf3c62664e1bca36408e671a0a719f6759399daa Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 4 Feb 2016 14:54:21 +0300 Subject: [PATCH 121/882] [maven-release-plugin] prepare release scribejava-2.2.2 --- pom.xml | 2 +- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 92701b1dc..4e4bb0aab 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 2.2.2-SNAPSHOT + 2.2.2 ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index ed13b7aeb..d435c356d 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 2.2.2-SNAPSHOT + 2.2.2 ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index f551ccce7..a0c7306b9 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 2.2.2-SNAPSHOT + 2.2.2 ../pom.xml From adb5629a26b438ca8a1c2f56a99ffc726ce91099 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 4 Feb 2016 14:54:25 +0300 Subject: [PATCH 122/882] [maven-release-plugin] prepare for next development iteration --- pom.xml | 2 +- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 4e4bb0aab..b25ebf78a 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 2.2.2 + 2.2.3-SNAPSHOT ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index d435c356d..9581880a8 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 2.2.2 + 2.2.3-SNAPSHOT ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index a0c7306b9..c64504e98 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 2.2.2 + 2.2.3-SNAPSHOT ../pom.xml From 1c5f7a56da8f9c5aa315a20d66b34dc7514f54fd Mon Sep 17 00:00:00 2001 From: Michal Foksa Date: Mon, 1 Feb 2016 17:45:06 +0100 Subject: [PATCH 123/882] Support response in gzip. --- changelog | 3 +++ .../github/scribejava/core/model/Response.java | 6 +++++- .../scribejava/core/utils/StreamUtils.java | 17 +++++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/changelog b/changelog index 47750f620..a0b1466d5 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,6 @@ +[SNAPSHOT] + * Support response in gzip. + [2.2.2] * make all APIs to be extentable (have protected constructors, useful for testing) diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/Response.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/Response.java index a8f3098d6..bce6e584a 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/Response.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/Response.java @@ -38,7 +38,11 @@ public Response(int code, String message, Map headers, String bo } private String parseBodyContents() { - body = StreamUtils.getStreamContents(getStream()); + if ("gzip".equals(getHeader("Content-Encoding"))) { + body = StreamUtils.getGzipStreamContents(getStream()); + } else { + body = StreamUtils.getStreamContents(getStream()); + } return body; } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/utils/StreamUtils.java b/scribejava-core/src/main/java/com/github/scribejava/core/utils/StreamUtils.java index f5db63b69..a87a90b7e 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/utils/StreamUtils.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/utils/StreamUtils.java @@ -4,6 +4,7 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.io.Reader; +import java.util.zip.GZIPInputStream; /** * Utils to deal with Streams. @@ -37,4 +38,20 @@ public static String getStreamContents(InputStream is) { throw new IllegalStateException("Error while reading response body", ioe); } } + + /** + * Return String content from a gzip stream + * + * @param is input stream + * @return string contents + */ + public static String getGzipStreamContents(InputStream is) { + Preconditions.checkNotNull(is, "Cannot get String from a null object"); + try { + final GZIPInputStream gis = new GZIPInputStream(is); + return getStreamContents(gis); + } catch (IOException ioe) { + throw new IllegalStateException("Error while reading response body", ioe); + } + } } From 111fba3fcad5500ff7ee2649d65a980788b2aeff Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 8 Feb 2016 11:53:57 +0300 Subject: [PATCH 124/882] update some dependencies, refactor&clear pom.xml a bit --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 8 -------- scribejava-core/pom.xml | 8 -------- 3 files changed, 2 insertions(+), 18 deletions(-) diff --git a/pom.xml b/pom.xml index b25ebf78a..2a2a7abfe 100644 --- a/pom.xml +++ b/pom.xml @@ -90,7 +90,7 @@ com.ning async-http-client - 1.9.31 + 1.9.32 provided @@ -105,7 +105,7 @@ maven-compiler-plugin - 3.3 + 3.5 UTF-8 1.7 diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 9581880a8..1aabba2bb 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -16,14 +16,6 @@ - - org.apache.maven.plugins - maven-compiler-plugin - 3.3 - - true - - org.apache.maven.plugins maven-resources-plugin diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index c64504e98..b9ab0e6d4 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -16,14 +16,6 @@ - - org.apache.maven.plugins - maven-compiler-plugin - 3.3 - - true - - org.apache.maven.plugins maven-resources-plugin From 30449498b244673e9f2cac20f339133da77a30da Mon Sep 17 00:00:00 2001 From: Michal Foksa Date: Mon, 1 Feb 2016 17:48:07 +0100 Subject: [PATCH 125/882] Stack Exchange authentication via OAuth 2.0 (stackoverflow.com, askubuntu.com, etc.). --- changelog | 1 + .../scribejava/apis/StackExchangeApi.java | 59 ++++++++++++++ .../apis/examples/StackExchangeExample.java | 81 +++++++++++++++++++ 3 files changed, 141 insertions(+) create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/StackExchangeApi.java create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/StackExchangeExample.java diff --git a/changelog b/changelog index a0b1466d5..34b04799f 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,5 @@ [SNAPSHOT] + * Stack Exchange authentication via OAuth 2.0 (stackoverflow.com, askubuntu.com, etc.). * Support response in gzip. [2.2.2] diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/StackExchangeApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/StackExchangeApi.java new file mode 100644 index 000000000..89270e519 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/StackExchangeApi.java @@ -0,0 +1,59 @@ +package com.github.scribejava.apis; + +import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.model.OAuthConfig; +import com.github.scribejava.core.model.OAuthConstants; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.utils.OAuthEncoder; +import com.github.scribejava.core.utils.Preconditions; + +/*** + * Stack Exchange authentication via OAuth 2.0 (stackoverflow.com, + * askubuntu.com, etc.). + * + * @author Michal Foksa + * + */ +public class StackExchangeApi extends DefaultApi20 { + + private static final String AUTHORIZE_URL + = "https://stackexchange.com/oauth?client_id=%s&redirect_uri=%s"; + + private StackExchangeApi() { + } + + private static class InstanceHolder { + private static final StackExchangeApi INSTANCE = new StackExchangeApi(); + } + + public static StackExchangeApi instance() { + return InstanceHolder.INSTANCE; + } + + @Override + public Verb getAccessTokenVerb() { + return Verb.POST; + } + + @Override + public String getAccessTokenEndpoint() { + return "https://stackexchange.com/oauth/access_token"; + } + + @Override + public String getAuthorizationUrl(OAuthConfig config) { + Preconditions.checkValidUrl(config.getCallback(), + "Must provide a valid url as callback. StackExchange does not support OOB"); + final StringBuilder sb = new StringBuilder(String.format(AUTHORIZE_URL, config.getApiKey(), + OAuthEncoder.encode(config.getCallback()))); + if (config.hasScope()) { + sb.append('&').append(OAuthConstants.SCOPE).append('=').append(OAuthEncoder.encode(config.getScope())); + } + + final String state = config.getState(); + if (state != null) { + sb.append('&').append(OAuthConstants.STATE).append('=').append(OAuthEncoder.encode(state)); + } + return sb.toString(); + } +} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/StackExchangeExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/StackExchangeExample.java new file mode 100644 index 000000000..2aee50a1d --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/StackExchangeExample.java @@ -0,0 +1,81 @@ +package com.github.scribejava.apis.examples; + +import java.util.Random; +import java.util.Scanner; + +import com.github.scribejava.apis.StackExchangeApi; +import com.github.scribejava.core.builder.ServiceBuilder; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.Token; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.model.Verifier; +import com.github.scribejava.core.oauth.OAuth20Service; + +public abstract class StackExchangeExample { + + private static final String NETWORK_NAME = "Stack Exchange"; + private static final String PROTECTED_RESOURCE_URL = "https://api.stackexchange.com/2.2/me?site=stackoverflow&key="; + + public static void main(String... args) { + // Replace these with your client id and secret + final String clientId = "your client id"; + final String clientSecret = "your client secret"; + final String key = "your client key"; + final String secretState = "secret" + new Random().nextInt(999_999); + final OAuth20Service service = new ServiceBuilder() + .apiKey(clientId) + .apiSecret(clientSecret) + .state(secretState) + .callback("http://www.example.com/oauth_callback/") + .build(StackExchangeApi.instance()); + final Scanner in = new Scanner(System.in, "UTF-8"); + + System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); + System.out.println(); + + // Obtain the Authorization URL + System.out.println("Fetching the Authorization URL..."); + final String authorizationUrl = service.getAuthorizationUrl(); + System.out.println("Got the Authorization URL!"); + System.out.println("Now go and authorize ScribeJava here:"); + System.out.println(authorizationUrl); + System.out.println("And paste the authorization code here"); + System.out.print(">>"); + final Verifier verifier = new Verifier(in.nextLine()); + System.out.println(); + + System.out.println("And paste the state from server here. We have set 'secretState'='" + secretState + "'."); + System.out.print(">>"); + final String value = in.nextLine(); + if (secretState.equals(value)) { + System.out.println("State value does match!"); + } else { + System.out.println("Ooops, state value does not match!"); + System.out.println("Expected = " + secretState); + System.out.println("Got = " + value); + System.out.println(); + } + + // Trade the Request Token and Verfier for the Access Token + System.out.println("Trading the Request Token for an Access Token..."); + final Token accessToken = service.getAccessToken(verifier); + System.out.println("Got the Access Token!"); + System.out.println("(if your curious it looks like this: " + accessToken + " )"); + 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 + key, service); + service.signRequest(accessToken, request); + final Response response = request.send(); + 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 dc10155431c56b8d1bd9821e8269ff07fa5a016b Mon Sep 17 00:00:00 2001 From: Michal Foksa Date: Fri, 5 Feb 2016 15:46:07 +0100 Subject: [PATCH 126/882] Make API extendable. --- .../main/java/com/github/scribejava/apis/StackExchangeApi.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/StackExchangeApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/StackExchangeApi.java index 89270e519..1c3a99ee7 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/StackExchangeApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/StackExchangeApi.java @@ -19,7 +19,7 @@ public class StackExchangeApi extends DefaultApi20 { private static final String AUTHORIZE_URL = "https://stackexchange.com/oauth?client_id=%s&redirect_uri=%s"; - private StackExchangeApi() { + protected StackExchangeApi() { } private static class InstanceHolder { From 8c82c0296474b095cc4c6f1407b30a642480d7ad Mon Sep 17 00:00:00 2001 From: Michal Foksa Date: Fri, 5 Feb 2016 20:06:50 +0100 Subject: [PATCH 127/882] Variable for Stack Exchange site name. --- .../scribejava/apis/examples/StackExchangeExample.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/StackExchangeExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/StackExchangeExample.java index 2aee50a1d..09520c615 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/StackExchangeExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/StackExchangeExample.java @@ -15,13 +15,16 @@ public abstract class StackExchangeExample { private static final String NETWORK_NAME = "Stack Exchange"; - private static final String PROTECTED_RESOURCE_URL = "https://api.stackexchange.com/2.2/me?site=stackoverflow&key="; + private static final String PROTECTED_RESOURCE_URL = "https://api.stackexchange.com/2.2/me"; public static void main(String... args) { - // Replace these with your client id and secret + // Replace these with your client id, secret, application key and + // optionally site name final String clientId = "your client id"; final String clientSecret = "your client secret"; final String key = "your client key"; + // Enter one of Stack Exchange site names the user has account with. + final String site = "stackoverflow"; final String secretState = "secret" + new Random().nextInt(999_999); final OAuth20Service service = new ServiceBuilder() .apiKey(clientId) @@ -66,7 +69,7 @@ public static void main(String... args) { // 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 + key, service); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL + "?site=" + site + "&key=" + key, service); service.signRequest(accessToken, request); final Response response = request.send(); System.out.println("Got it! Lets see what we found..."); From 290d0b58aec2c39ae76d919365a956157f1f4c71 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 8 Feb 2016 12:06:56 +0300 Subject: [PATCH 128/882] fix checkstyle violations --- .../github/scribejava/apis/StackExchangeApi.java | 3 +-- .../apis/examples/StackExchangeExample.java | 13 +++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/StackExchangeApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/StackExchangeApi.java index 1c3a99ee7..2c962989f 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/StackExchangeApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/StackExchangeApi.java @@ -16,8 +16,7 @@ */ public class StackExchangeApi extends DefaultApi20 { - private static final String AUTHORIZE_URL - = "https://stackexchange.com/oauth?client_id=%s&redirect_uri=%s"; + private static final String AUTHORIZE_URL = "https://stackexchange.com/oauth?client_id=%s&redirect_uri=%s"; protected StackExchangeApi() { } diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/StackExchangeExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/StackExchangeExample.java index 09520c615..c2d985ab8 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/StackExchangeExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/StackExchangeExample.java @@ -27,11 +27,11 @@ public static void main(String... args) { final String site = "stackoverflow"; final String secretState = "secret" + new Random().nextInt(999_999); final OAuth20Service service = new ServiceBuilder() - .apiKey(clientId) - .apiSecret(clientSecret) - .state(secretState) - .callback("http://www.example.com/oauth_callback/") - .build(StackExchangeApi.instance()); + .apiKey(clientId) + .apiSecret(clientSecret) + .state(secretState) + .callback("http://www.example.com/oauth_callback/") + .build(StackExchangeApi.instance()); final Scanner in = new Scanner(System.in, "UTF-8"); System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); @@ -69,7 +69,8 @@ public static void main(String... args) { // 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 + "?site=" + site + "&key=" + key, service); + final OAuthRequest request = new OAuthRequest(Verb.GET, + PROTECTED_RESOURCE_URL + "?site=" + site + "&key=" + key, service); service.signRequest(accessToken, request); final Response response = request.send(); System.out.println("Got it! Lets see what we found..."); From 1950c3405a5a5881a27d249e8f707ebb06966c45 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 9 Feb 2016 17:28:16 +0300 Subject: [PATCH 129/882] small doc and text fixes --- README.md | 7 +++---- .../com/github/scribejava/apis/examples/TumblrExample.java | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 9024a2478..59e58dc7f 100644 --- a/README.md +++ b/README.md @@ -4,17 +4,16 @@ ### Dead Simple -Who said OAuth/OAuth2 was difficult? Configuring scribe is __so easy your grandma can do it__! check it out: +Who said OAuth/OAuth2 was difficult? Configuring ScribeJava is __so easy your grandma can do it__! check it out: ```java OAuthService service = new ServiceBuilder() - .provider(LinkedInApi.class) .apiKey(YOUR_API_KEY) .apiSecret(YOUR_API_SECRET) - .build(); + .build(LinkedInApi20.instance()); ``` -That **single line** (added newlines for readability) is the only thing you need to configure scribe with LinkedIn's OAuth API for example. +That **single line** (added newlines for readability) is the only thing you need to configure ScribeJava with LinkedIn's OAuth API for example. ### Threadsafe diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TumblrExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TumblrExample.java index 512ea2924..e0bb5660e 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TumblrExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TumblrExample.java @@ -32,7 +32,7 @@ public static void main(String... args) { System.out.println("Got the Request Token!"); System.out.println(); - System.out.println("Now go and authorize Scribe here:"); + System.out.println("Now go and authorize ScribeJava here:"); System.out.println(service.getAuthorizationUrl(requestToken)); System.out.println("And paste the verifier here"); System.out.print(">>"); From 435fff091c4f3279f21fed1a817cf15eb296b6e9 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 17 Feb 2016 19:05:33 +0300 Subject: [PATCH 130/882] differentiate OAuth1 Access token, OAuth 1 Request Token and OAuth 2 Access token --- changelog | 1 + .../scribejava/apis/ConstantContactApi2.java | 31 ++------ .../scribejava/apis/DoktornaraboteApi.java | 9 +-- .../github/scribejava/apis/FacebookApi.java | 10 +-- .../scribejava/apis/Foursquare2Api.java | 9 +-- .../github/scribejava/apis/GoogleApi20.java | 7 +- .../com/github/scribejava/apis/HHApi.java | 9 +-- .../com/github/scribejava/apis/ImgurApi.java | 9 +-- .../github/scribejava/apis/KaixinApi20.java | 9 +-- .../github/scribejava/apis/LinkedInApi20.java | 9 +-- .../com/github/scribejava/apis/LiveApi.java | 9 +-- .../com/github/scribejava/apis/MailruApi.java | 9 +-- .../scribejava/apis/OdnoklassnikiApi.java | 9 +-- .../github/scribejava/apis/PinterestApi.java | 9 +-- .../com/github/scribejava/apis/RenrenApi.java | 9 +-- .../scribejava/apis/SinaWeiboApi20.java | 9 +-- .../com/github/scribejava/apis/TutByApi.java | 9 +-- .../com/github/scribejava/apis/ViadeoApi.java | 9 +-- .../github/scribejava/apis/VkontakteApi.java | 9 +-- .../ConstantContactTokenExtractor.java | 40 +++++++++++ .../apis/google/GoogleJsonTokenExtractor.java | 18 ++++- .../scribejava/apis/google/GoogleToken.java | 13 ++-- .../DoktornaraboteOAuthServiceImpl.java | 4 +- .../apis/service/HHOAuthServiceImpl.java | 4 +- .../apis/service/ImgurOAuthServiceImpl.java | 4 +- .../apis/service/LinkedIn20ServiceImpl.java | 4 +- .../apis/service/MailruOAuthServiceImpl.java | 4 +- .../service/OdnoklassnikiServiceImpl.java | 4 +- .../apis/service/TutByOAuthServiceImpl.java | 4 +- .../apis/examples/AWeberExample.java | 7 +- .../scribejava/apis/examples/DiggExample.java | 7 +- .../apis/examples/FacebookAsyncExample.java | 4 +- .../apis/examples/FacebookExample.java | 4 +- .../apis/examples/FlickrExample.java | 7 +- .../apis/examples/Foursquare2Example.java | 4 +- .../apis/examples/FoursquareExample.java | 7 +- .../apis/examples/FreelancerExample.java | 7 +- .../apis/examples/GitHubExample.java | 4 +- .../apis/examples/Google20Example.java | 4 +- .../apis/examples/GoogleExample.java | 7 +- .../scribejava/apis/examples/HHExample.java | 4 +- .../apis/examples/ImgurExample.java | 4 +- .../apis/examples/Kaixin20Example.java | 4 +- .../apis/examples/LinkedIn20Example.java | 4 +- .../apis/examples/LinkedInExample.java | 7 +- .../examples/LinkedInExampleWithScopes.java | 7 +- .../scribejava/apis/examples/LiveExample.java | 4 +- .../apis/examples/LoveFilmExample.java | 7 +- .../apis/examples/MailruAsyncExample.java | 4 +- .../apis/examples/MailruExample.java | 4 +- .../apis/examples/MeetupExample.java | 7 +- .../apis/examples/NeteaseWeiboExample.java | 7 +- .../apis/examples/OdnoklassnikiExample.java | 4 +- .../apis/examples/PinterestExample.java | 4 +- .../apis/examples/Px500Example.java | 7 +- .../apis/examples/RenrenExample.java | 4 +- .../apis/examples/SinaWeibo2Example.java | 4 +- .../apis/examples/SinaWeiboExample.java | 7 +- .../apis/examples/SkyrockExample.java | 7 +- .../apis/examples/SohuWeiboExample.java | 7 +- .../apis/examples/StackExchangeExample.java | 4 +- .../apis/examples/TrelloExample.java | 7 +- .../apis/examples/TumblrExample.java | 8 +-- .../apis/examples/TutByExample.java | 4 +- .../apis/examples/TwitterExample.java | 7 +- .../apis/examples/ViadeoExample.java | 4 +- .../apis/examples/VkontakteExample.java | 4 +- .../scribejava/apis/examples/XingExample.java | 7 +- .../apis/examples/YahooExample.java | 7 +- .../core/builder/api/DefaultApi10a.java | 16 +++-- .../core/builder/api/DefaultApi20.java | 9 +-- ...java => AbstractOAuth1TokenExtractor.java} | 13 ++-- .../core/extractors/AccessTokenExtractor.java | 19 ----- .../core/extractors/BaseStringExtractor.java | 6 +- .../OAuth1AccessTokenExtractor.java | 24 +++++++ .../OAuth1RequestTokenExtractor.java | 23 ++++++ ...l.java => OAuth2AccessTokenExtractor.java} | 24 +++++-- ...va => OAuth2AccessTokenJsonExtractor.java} | 20 ++++-- .../extractors/RequestTokenExtractor.java | 19 ----- .../core/extractors/TokenExtractor.java | 18 +++++ .../core/model/OAuth1AccessToken.java | 17 +++++ .../core/model/OAuth1RequestToken.java | 17 +++++ .../scribejava/core/model/OAuth1Token.java | 62 ++++++++++++++++ .../core/model/OAuth2AccessToken.java | 18 +++++ .../scribejava/core/model/OAuthConstants.java | 2 +- .../github/scribejava/core/model/Token.java | 71 +++++-------------- .../core/oauth/OAuth10aService.java | 34 +++++---- .../scribejava/core/oauth/OAuth20Service.java | 19 ++--- .../scribejava/core/oauth/OAuthService.java | 4 +- .../extractors/JsonTokenExtractorTest.java | 2 +- ...va => OAuth1AccessTokenExtractorTest.java} | 18 ++--- ...va => OAuth2AccessTokenExtractorTest.java} | 11 ++- .../scribejava/core/model/TokenTest.java | 17 ++--- 93 files changed, 595 insertions(+), 392 deletions(-) create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/constantcontact/ConstantContactTokenExtractor.java rename scribejava-core/src/main/java/com/github/scribejava/core/extractors/{TokenExtractorImpl.java => AbstractOAuth1TokenExtractor.java} (74%) delete mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/extractors/AccessTokenExtractor.java create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth1AccessTokenExtractor.java create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth1RequestTokenExtractor.java rename scribejava-core/src/main/java/com/github/scribejava/core/extractors/{TokenExtractor20Impl.java => OAuth2AccessTokenExtractor.java} (59%) rename scribejava-core/src/main/java/com/github/scribejava/core/extractors/{JsonTokenExtractor.java => OAuth2AccessTokenJsonExtractor.java} (56%) delete mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/extractors/RequestTokenExtractor.java create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/extractors/TokenExtractor.java create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth1AccessToken.java create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth1RequestToken.java create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth1Token.java create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth2AccessToken.java rename scribejava-core/src/test/java/com/github/scribejava/core/extractors/{TokenExtractorTest.java => OAuth1AccessTokenExtractorTest.java} (82%) rename scribejava-core/src/test/java/com/github/scribejava/core/extractors/{TokenExtractor20Test.java => OAuth2AccessTokenExtractorTest.java} (88%) diff --git a/changelog b/changelog index 34b04799f..c2a21fa59 100644 --- a/changelog +++ b/changelog @@ -1,6 +1,7 @@ [SNAPSHOT] * Stack Exchange authentication via OAuth 2.0 (stackoverflow.com, askubuntu.com, etc.). * Support response in gzip. + * differentiate OAuth1 Access token, OAuth 1 Request Token and OAuth 2 Access token [2.2.2] * make all APIs to be extentable (have protected constructors, useful for testing) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/ConstantContactApi2.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/ConstantContactApi2.java index 07879e2fa..d910e73b9 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/ConstantContactApi2.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/ConstantContactApi2.java @@ -1,41 +1,20 @@ package com.github.scribejava.apis; -import java.util.regex.Matcher; -import java.util.regex.Pattern; +import com.github.scribejava.apis.constantcontact.ConstantContactTokenExtractor; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.exceptions.OAuthException; -import com.github.scribejava.core.extractors.AccessTokenExtractor; +import com.github.scribejava.core.extractors.TokenExtractor; +import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; -import com.github.scribejava.core.model.Token; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.utils.OAuthEncoder; -import com.github.scribejava.core.utils.Preconditions; public class ConstantContactApi2 extends DefaultApi20 { private static final String AUTHORIZE_URL = "https://oauth2.constantcontact.com/oauth2/oauth/siteowner/authorize?client_id=%s&response_type=code" + "&redirect_uri=%s"; - private static final AccessTokenExtractor ACCESS_TOKEN_EXTRACTOR = new AccessTokenExtractor() { - - @Override - public Token extract(String response) { - Preconditions.checkEmptyString(response, - "Response body is incorrect. Can't extract a token from an empty string"); - - final String regex = "\"access_token\"\\s*:\\s*\"([^&\"]+)\""; - final Matcher matcher = Pattern.compile(regex).matcher(response); - if (matcher.find()) { - final String token = OAuthEncoder.decode(matcher.group(1)); - return new Token(token, "", response); - } else { - throw new OAuthException("Response body is incorrect. Can't extract a token from this: '" - + response + "'", null); - } - } - }; protected ConstantContactApi2() { } @@ -64,7 +43,7 @@ public Verb getAccessTokenVerb() { } @Override - public AccessTokenExtractor getAccessTokenExtractor() { - return ACCESS_TOKEN_EXTRACTOR; + public TokenExtractor getAccessTokenExtractor() { + return ConstantContactTokenExtractor.instance(); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/DoktornaraboteApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/DoktornaraboteApi.java index 2a655103c..f937d62bd 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/DoktornaraboteApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/DoktornaraboteApi.java @@ -2,8 +2,9 @@ import com.github.scribejava.apis.service.DoktornaraboteOAuthServiceImpl; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.extractors.AccessTokenExtractor; -import com.github.scribejava.core.extractors.JsonTokenExtractor; +import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; +import com.github.scribejava.core.extractors.TokenExtractor; +import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.Verb; @@ -60,8 +61,8 @@ public String getAuthorizationUrl(OAuthConfig config) { } @Override - public AccessTokenExtractor getAccessTokenExtractor() { - return new JsonTokenExtractor(); + public TokenExtractor getAccessTokenExtractor() { + return OAuth2AccessTokenJsonExtractor.instance(); } @Override 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 2ce748c8c..ec0acd245 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java @@ -1,8 +1,9 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.extractors.AccessTokenExtractor; -import com.github.scribejava.core.extractors.JsonTokenExtractor; +import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; +import com.github.scribejava.core.extractors.TokenExtractor; +import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.utils.OAuthEncoder; @@ -29,9 +30,8 @@ public static FacebookApi instance() { } @Override - public AccessTokenExtractor getAccessTokenExtractor() { - - return new JsonTokenExtractor(); + public TokenExtractor getAccessTokenExtractor() { + return OAuth2AccessTokenJsonExtractor.instance(); } @Override diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/Foursquare2Api.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/Foursquare2Api.java index 15f46c702..d221dcbac 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/Foursquare2Api.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/Foursquare2Api.java @@ -1,8 +1,9 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.extractors.AccessTokenExtractor; -import com.github.scribejava.core.extractors.JsonTokenExtractor; +import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; +import com.github.scribejava.core.extractors.TokenExtractor; +import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.utils.OAuthEncoder; @@ -37,7 +38,7 @@ public String getAuthorizationUrl(OAuthConfig config) { } @Override - public AccessTokenExtractor getAccessTokenExtractor() { - return new JsonTokenExtractor(); + public TokenExtractor getAccessTokenExtractor() { + return OAuth2AccessTokenJsonExtractor.instance(); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/GoogleApi20.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/GoogleApi20.java index c0ccfd998..cde5105a0 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/GoogleApi20.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/GoogleApi20.java @@ -3,7 +3,8 @@ import com.github.scribejava.apis.google.GoogleJsonTokenExtractor; import com.github.scribejava.apis.service.GoogleOAuthServiceImpl; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.extractors.AccessTokenExtractor; +import com.github.scribejava.core.extractors.TokenExtractor; +import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.Verb; @@ -49,8 +50,8 @@ public String getAuthorizationUrl(OAuthConfig config) { } @Override - public AccessTokenExtractor getAccessTokenExtractor() { - return new GoogleJsonTokenExtractor(); + public TokenExtractor getAccessTokenExtractor() { + return GoogleJsonTokenExtractor.instance(); } @Override diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/HHApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/HHApi.java index cae27c68d..c0fd8f1e2 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/HHApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/HHApi.java @@ -1,12 +1,13 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.extractors.AccessTokenExtractor; -import com.github.scribejava.core.extractors.JsonTokenExtractor; +import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.Verb; import com.github.scribejava.apis.service.HHOAuthServiceImpl; +import com.github.scribejava.core.extractors.TokenExtractor; +import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.oauth.OAuth20Service; import com.github.scribejava.core.utils.OAuthEncoder; @@ -44,8 +45,8 @@ public String getAuthorizationUrl(OAuthConfig config) { } @Override - public AccessTokenExtractor getAccessTokenExtractor() { - return new JsonTokenExtractor(); + public TokenExtractor getAccessTokenExtractor() { + return OAuth2AccessTokenJsonExtractor.instance(); } @Override diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java index c9ded43e9..bcb95cf17 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java @@ -2,8 +2,9 @@ import com.github.scribejava.apis.service.ImgurOAuthServiceImpl; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.extractors.AccessTokenExtractor; -import com.github.scribejava.core.extractors.JsonTokenExtractor; +import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; +import com.github.scribejava.core.extractors.TokenExtractor; +import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.oauth.OAuth20Service; @@ -30,8 +31,8 @@ public Verb getAccessTokenVerb() { } @Override - public AccessTokenExtractor getAccessTokenExtractor() { - return new JsonTokenExtractor(); + public TokenExtractor getAccessTokenExtractor() { + return OAuth2AccessTokenJsonExtractor.instance(); } @Override diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/KaixinApi20.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/KaixinApi20.java index d4cbaa2e9..1d6658f21 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/KaixinApi20.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/KaixinApi20.java @@ -1,8 +1,9 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.extractors.AccessTokenExtractor; -import com.github.scribejava.core.extractors.JsonTokenExtractor; +import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; +import com.github.scribejava.core.extractors.TokenExtractor; +import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.utils.OAuthEncoder; @@ -28,8 +29,8 @@ public static KaixinApi20 instance() { } @Override - public AccessTokenExtractor getAccessTokenExtractor() { - return new JsonTokenExtractor(); + public TokenExtractor getAccessTokenExtractor() { + return OAuth2AccessTokenJsonExtractor.instance(); } @Override diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi20.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi20.java index e7f6b4398..7f829dd40 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi20.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi20.java @@ -2,8 +2,9 @@ import com.github.scribejava.apis.service.LinkedIn20ServiceImpl; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.extractors.AccessTokenExtractor; -import com.github.scribejava.core.extractors.JsonTokenExtractor; +import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; +import com.github.scribejava.core.extractors.TokenExtractor; +import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.Verb; @@ -55,8 +56,8 @@ public String getAuthorizationUrl(OAuthConfig config) { } @Override - public AccessTokenExtractor getAccessTokenExtractor() { - return new JsonTokenExtractor(); + public TokenExtractor getAccessTokenExtractor() { + return OAuth2AccessTokenJsonExtractor.instance(); } @Override diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/LiveApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/LiveApi.java index c3c084ce8..a512318f5 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/LiveApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/LiveApi.java @@ -1,8 +1,9 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.extractors.AccessTokenExtractor; -import com.github.scribejava.core.extractors.JsonTokenExtractor; +import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; +import com.github.scribejava.core.extractors.TokenExtractor; +import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.utils.OAuthEncoder; @@ -45,7 +46,7 @@ public String getAuthorizationUrl(OAuthConfig config) { } @Override - public AccessTokenExtractor getAccessTokenExtractor() { - return new JsonTokenExtractor(); + public TokenExtractor getAccessTokenExtractor() { + return OAuth2AccessTokenJsonExtractor.instance(); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java index 1bc70bdfa..3f84704b6 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java @@ -1,13 +1,14 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.extractors.AccessTokenExtractor; -import com.github.scribejava.core.extractors.JsonTokenExtractor; +import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.utils.OAuthEncoder; import com.github.scribejava.core.utils.Preconditions; import com.github.scribejava.apis.service.MailruOAuthServiceImpl; +import com.github.scribejava.core.extractors.TokenExtractor; +import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.oauth.OAuth20Service; public class MailruApi extends DefaultApi20 { @@ -55,7 +56,7 @@ public OAuth20Service createService(OAuthConfig config) { } @Override - public AccessTokenExtractor getAccessTokenExtractor() { - return new JsonTokenExtractor(); + public TokenExtractor getAccessTokenExtractor() { + return OAuth2AccessTokenJsonExtractor.instance(); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java index 7ad00e80b..1842e9faa 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java @@ -2,8 +2,9 @@ import com.github.scribejava.apis.service.OdnoklassnikiServiceImpl; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.extractors.AccessTokenExtractor; -import com.github.scribejava.core.extractors.JsonTokenExtractor; +import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; +import com.github.scribejava.core.extractors.TokenExtractor; +import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.oauth.OAuth20Service; @@ -55,7 +56,7 @@ public OAuth20Service createService(OAuthConfig config) { } @Override - public AccessTokenExtractor getAccessTokenExtractor() { - return new JsonTokenExtractor(); + public TokenExtractor getAccessTokenExtractor() { + return OAuth2AccessTokenJsonExtractor.instance(); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/PinterestApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/PinterestApi.java index a4535a289..6880cd938 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/PinterestApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/PinterestApi.java @@ -1,8 +1,9 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.extractors.AccessTokenExtractor; -import com.github.scribejava.core.extractors.JsonTokenExtractor; +import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; +import com.github.scribejava.core.extractors.TokenExtractor; +import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.Verb; @@ -51,7 +52,7 @@ public String getAuthorizationUrl(OAuthConfig config) { } @Override - public AccessTokenExtractor getAccessTokenExtractor() { - return new JsonTokenExtractor(); + public TokenExtractor getAccessTokenExtractor() { + return OAuth2AccessTokenJsonExtractor.instance(); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/RenrenApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/RenrenApi.java index 216fd8ca8..4fd12b36b 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/RenrenApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/RenrenApi.java @@ -1,8 +1,9 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.extractors.AccessTokenExtractor; -import com.github.scribejava.core.extractors.JsonTokenExtractor; +import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; +import com.github.scribejava.core.extractors.TokenExtractor; +import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.utils.OAuthEncoder; @@ -28,8 +29,8 @@ public static RenrenApi instance() { } @Override - public AccessTokenExtractor getAccessTokenExtractor() { - return new JsonTokenExtractor(); + public TokenExtractor getAccessTokenExtractor() { + return OAuth2AccessTokenJsonExtractor.instance(); } @Override diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/SinaWeiboApi20.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/SinaWeiboApi20.java index 87167e10a..a98493382 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/SinaWeiboApi20.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/SinaWeiboApi20.java @@ -1,8 +1,9 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.extractors.AccessTokenExtractor; -import com.github.scribejava.core.extractors.JsonTokenExtractor; +import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; +import com.github.scribejava.core.extractors.TokenExtractor; +import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.Verb; @@ -34,8 +35,8 @@ public Verb getAccessTokenVerb() { } @Override - public AccessTokenExtractor getAccessTokenExtractor() { - return new JsonTokenExtractor(); + public TokenExtractor getAccessTokenExtractor() { + return OAuth2AccessTokenJsonExtractor.instance(); } @Override diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/TutByApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/TutByApi.java index 25a608eef..fb1e10820 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/TutByApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/TutByApi.java @@ -1,13 +1,14 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.extractors.AccessTokenExtractor; -import com.github.scribejava.core.extractors.JsonTokenExtractor; +import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.utils.OAuthEncoder; import com.github.scribejava.core.utils.Preconditions; import com.github.scribejava.apis.service.TutByOAuthServiceImpl; +import com.github.scribejava.core.extractors.TokenExtractor; +import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.oauth.OAuth20Service; public class TutByApi extends DefaultApi20 { @@ -49,7 +50,7 @@ public OAuth20Service createService(OAuthConfig config) { } @Override - public AccessTokenExtractor getAccessTokenExtractor() { - return new JsonTokenExtractor(); + public TokenExtractor getAccessTokenExtractor() { + return OAuth2AccessTokenJsonExtractor.instance(); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/ViadeoApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/ViadeoApi.java index 30059ec85..c4f718d81 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/ViadeoApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/ViadeoApi.java @@ -1,8 +1,9 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.extractors.AccessTokenExtractor; -import com.github.scribejava.core.extractors.JsonTokenExtractor; +import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; +import com.github.scribejava.core.extractors.TokenExtractor; +import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.utils.OAuthEncoder; @@ -26,8 +27,8 @@ public static ViadeoApi instance() { } @Override - public AccessTokenExtractor getAccessTokenExtractor() { - return new JsonTokenExtractor(); + public TokenExtractor getAccessTokenExtractor() { + return OAuth2AccessTokenJsonExtractor.instance(); } @Override diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/VkontakteApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/VkontakteApi.java index 66f2ba918..b83155658 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/VkontakteApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/VkontakteApi.java @@ -1,8 +1,9 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.extractors.AccessTokenExtractor; -import com.github.scribejava.core.extractors.JsonTokenExtractor; +import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; +import com.github.scribejava.core.extractors.TokenExtractor; +import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.utils.OAuthEncoder; import com.github.scribejava.core.utils.Preconditions; @@ -46,7 +47,7 @@ public String getAuthorizationUrl(OAuthConfig config) { } @Override - public AccessTokenExtractor getAccessTokenExtractor() { - return new JsonTokenExtractor(); + public TokenExtractor getAccessTokenExtractor() { + return OAuth2AccessTokenJsonExtractor.instance(); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/constantcontact/ConstantContactTokenExtractor.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/constantcontact/ConstantContactTokenExtractor.java new file mode 100644 index 000000000..78b27b2ab --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/constantcontact/ConstantContactTokenExtractor.java @@ -0,0 +1,40 @@ +package com.github.scribejava.apis.constantcontact; + +import com.github.scribejava.core.exceptions.OAuthException; +import com.github.scribejava.core.extractors.TokenExtractor; +import com.github.scribejava.core.model.OAuth2AccessToken; +import com.github.scribejava.core.utils.OAuthEncoder; +import com.github.scribejava.core.utils.Preconditions; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class ConstantContactTokenExtractor implements TokenExtractor { + + protected ConstantContactTokenExtractor() { + } + + private static class InstanceHolder { + + private static final ConstantContactTokenExtractor INSTANCE = new ConstantContactTokenExtractor(); + } + + public static ConstantContactTokenExtractor instance() { + return InstanceHolder.INSTANCE; + } + + @Override + public OAuth2AccessToken extract(String response) { + Preconditions.checkEmptyString(response, + "Response body is incorrect. Can't extract a token from an empty string"); + + final String regex = "\"access_token\"\\s*:\\s*\"([^&\"]+)\""; + final Matcher matcher = Pattern.compile(regex).matcher(response); + if (matcher.find()) { + final String token = OAuthEncoder.decode(matcher.group(1)); + return new OAuth2AccessToken(token, response); + } else { + throw new OAuthException("Response body is incorrect. Can't extract a token from this: '" + + response + "'", null); + } + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/google/GoogleJsonTokenExtractor.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/google/GoogleJsonTokenExtractor.java index 9b54e022e..3a0ae6194 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/google/GoogleJsonTokenExtractor.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/google/GoogleJsonTokenExtractor.java @@ -2,18 +2,30 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; -import com.github.scribejava.core.extractors.JsonTokenExtractor; +import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; /** * additionally parses OpenID id_token */ -public class GoogleJsonTokenExtractor extends JsonTokenExtractor { +public class GoogleJsonTokenExtractor extends OAuth2AccessTokenJsonExtractor { private static final Pattern ID_TOKEN_PATTERN = Pattern.compile("\"id_token\"\\s*:\\s*\"(\\S*?)\""); + protected GoogleJsonTokenExtractor() { + } + + private static class InstanceHolder { + + private static final GoogleJsonTokenExtractor INSTANCE = new GoogleJsonTokenExtractor(); + } + + public static GoogleJsonTokenExtractor instance() { + return InstanceHolder.INSTANCE; + } + @Override public GoogleToken extract(String response) { - return new GoogleToken(extractAccessToken(response), "", response, extractOpenIdToken(response)); + return new GoogleToken(extractAccessToken(response), response, extractOpenIdToken(response)); } private String extractOpenIdToken(String response) { diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/google/GoogleToken.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/google/GoogleToken.java index c4f98cb3a..e58ec4c63 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/google/GoogleToken.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/google/GoogleToken.java @@ -1,10 +1,10 @@ package com.github.scribejava.apis.google; -import com.github.scribejava.core.model.Token; +import com.github.scribejava.core.model.OAuth2AccessToken; -public class GoogleToken extends Token { +public class GoogleToken extends OAuth2AccessToken { - private static final long serialVersionUID = 5634896204924467956L; + private static final long serialVersionUID = 3075266018377678771L; /** * Id_token is part of OpenID Connect specification. It can hold user information that you can directly extract @@ -17,8 +17,8 @@ public class GoogleToken extends Token { */ private final String openIdToken; - public GoogleToken(String token, String secret, String rawResponse, String openIdToken) { - super(token, secret, rawResponse); + public GoogleToken(String token, String rawResponse, String openIdToken) { + super(token, rawResponse); this.openIdToken = openIdToken; } @@ -28,7 +28,6 @@ public String getOpenIdToken() { @Override public String toString() { - return String.format("GoogleToken{'token'='%s', 'secret'='%s', 'openIdToken'='%s']", getToken(), getSecret(), - openIdToken); + return String.format("GoogleToken{'token'='%s', 'openIdToken'='%s']", getToken(), openIdToken); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/DoktornaraboteOAuthServiceImpl.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/DoktornaraboteOAuthServiceImpl.java index afa9882a2..a8a28391c 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/DoktornaraboteOAuthServiceImpl.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/DoktornaraboteOAuthServiceImpl.java @@ -2,8 +2,8 @@ import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.model.AbstractRequest; +import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthConfig; -import com.github.scribejava.core.model.Token; import com.github.scribejava.core.oauth.OAuth20Service; public class DoktornaraboteOAuthServiceImpl extends OAuth20Service { @@ -13,7 +13,7 @@ public DoktornaraboteOAuthServiceImpl(DefaultApi20 api, OAuthConfig config) { } @Override - public void signRequest(Token accessToken, AbstractRequest request) { + public void signRequest(OAuth2AccessToken accessToken, AbstractRequest request) { request.addHeader("Authorization", "Bearer " + accessToken.getToken()); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/HHOAuthServiceImpl.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/HHOAuthServiceImpl.java index 725f015be..dc009bee1 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/HHOAuthServiceImpl.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/HHOAuthServiceImpl.java @@ -2,8 +2,8 @@ import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.model.AbstractRequest; +import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthConfig; -import com.github.scribejava.core.model.Token; import com.github.scribejava.core.oauth.OAuth20Service; public class HHOAuthServiceImpl extends OAuth20Service { @@ -13,7 +13,7 @@ public HHOAuthServiceImpl(DefaultApi20 api, OAuthConfig config) { } @Override - public void signRequest(Token accessToken, AbstractRequest request) { + public void signRequest(OAuth2AccessToken accessToken, AbstractRequest request) { request.addHeader("Authorization", "Bearer " + accessToken.getToken()); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthServiceImpl.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthServiceImpl.java index aacb3c937..3ba54ad75 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthServiceImpl.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthServiceImpl.java @@ -3,9 +3,9 @@ import com.github.scribejava.apis.ImgurApi; import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.model.AbstractRequest; +import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; -import com.github.scribejava.core.model.Token; import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuth20Service; @@ -32,7 +32,7 @@ protected T createAccessTokenRequest(Verifier verifi } @Override - public void signRequest(Token accessToken, AbstractRequest request) { + public void signRequest(OAuth2AccessToken accessToken, AbstractRequest request) { request.addHeader("Authorization", accessToken == null ? "Client-ID " + getConfig().getApiKey() : "Bearer " + accessToken.getToken()); } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/LinkedIn20ServiceImpl.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/LinkedIn20ServiceImpl.java index efaf148c4..0fd9d397c 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/LinkedIn20ServiceImpl.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/LinkedIn20ServiceImpl.java @@ -2,9 +2,9 @@ import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.model.AbstractRequest; +import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; -import com.github.scribejava.core.model.Token; import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuth20Service; @@ -15,7 +15,7 @@ public LinkedIn20ServiceImpl(DefaultApi20 api, OAuthConfig config) { } @Override - public void signRequest(Token accessToken, AbstractRequest request) { + public void signRequest(OAuth2AccessToken accessToken, AbstractRequest request) { request.addQuerystringParameter("oauth2_access_token", accessToken.getToken()); } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthServiceImpl.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthServiceImpl.java index 2be9ee7d1..f4cce01c8 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthServiceImpl.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthServiceImpl.java @@ -8,9 +8,9 @@ import static org.apache.commons.codec.digest.DigestUtils.md5Hex; import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.model.AbstractRequest; +import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; -import com.github.scribejava.core.model.Token; import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuth20Service; @@ -21,7 +21,7 @@ public MailruOAuthServiceImpl(DefaultApi20 api, OAuthConfig config) { } @Override - public void signRequest(Token accessToken, AbstractRequest request) { + public void signRequest(OAuth2AccessToken accessToken, AbstractRequest request) { // sig = md5(params + secret_key) request.addQuerystringParameter("session_key", accessToken.getToken()); request.addQuerystringParameter("app_id", getConfig().getApiKey()); diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiServiceImpl.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiServiceImpl.java index d247075a7..5c7066a40 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiServiceImpl.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiServiceImpl.java @@ -6,8 +6,8 @@ import static org.apache.commons.codec.digest.DigestUtils.md5Hex; import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.model.AbstractRequest; +import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthConfig; -import com.github.scribejava.core.model.Token; import com.github.scribejava.core.oauth.OAuth20Service; public class OdnoklassnikiServiceImpl extends OAuth20Service { @@ -17,7 +17,7 @@ public OdnoklassnikiServiceImpl(DefaultApi20 api, OAuthConfig config) { } @Override - public void signRequest(Token accessToken, AbstractRequest request) { + public void signRequest(OAuth2AccessToken accessToken, AbstractRequest request) { // sig = md5( request_params_composed_string+ md5(access_token + application_secret_key) ) try { final String tokenDigest = md5Hex(accessToken.getToken() + getConfig().getApiSecret()); diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/TutByOAuthServiceImpl.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/TutByOAuthServiceImpl.java index f0958ace1..8916b3abd 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/TutByOAuthServiceImpl.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/TutByOAuthServiceImpl.java @@ -2,9 +2,9 @@ import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.model.AbstractRequest; +import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; -import com.github.scribejava.core.model.Token; import com.github.scribejava.core.oauth.OAuth20Service; public class TutByOAuthServiceImpl extends OAuth20Service { @@ -14,7 +14,7 @@ public TutByOAuthServiceImpl(DefaultApi20 api, OAuthConfig config) { } @Override - public void signRequest(Token accessToken, AbstractRequest request) { + public void signRequest(OAuth2AccessToken accessToken, AbstractRequest request) { request.addQuerystringParameter(OAuthConstants.TOKEN, accessToken.getToken()); } diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AWeberExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AWeberExample.java index 3188b4b7f..d1478b901 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AWeberExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AWeberExample.java @@ -3,9 +3,10 @@ import java.util.Scanner; import com.github.scribejava.core.builder.ServiceBuilder; import com.github.scribejava.apis.AWeberApi; +import com.github.scribejava.core.model.OAuth1AccessToken; +import com.github.scribejava.core.model.OAuth1RequestToken; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; -import com.github.scribejava.core.model.Token; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuth10aService; @@ -31,7 +32,7 @@ public static void main(String... args) { // Obtain the Request Token System.out.println("Fetching the Request Token..."); - final Token requestToken = service.getRequestToken(); + final OAuth1RequestToken requestToken = service.getRequestToken(); System.out.println("Got the Request Token!"); System.out.println(); @@ -44,7 +45,7 @@ public static void main(String... args) { // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - final Token accessToken = service.getAccessToken(requestToken, verifier); + final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, verifier); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + " )"); System.out.println(); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiggExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiggExample.java index 4e46d9e27..e0e7ae8cc 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiggExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiggExample.java @@ -3,9 +3,10 @@ import java.util.Scanner; import com.github.scribejava.core.builder.ServiceBuilder; import com.github.scribejava.apis.DiggApi; +import com.github.scribejava.core.model.OAuth1AccessToken; +import com.github.scribejava.core.model.OAuth1RequestToken; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; -import com.github.scribejava.core.model.Token; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuth10aService; @@ -30,7 +31,7 @@ public static void main(String... args) { // Obtain the Request Token System.out.println("Fetching the Request Token..."); - final Token requestToken = service.getRequestToken(); + final OAuth1RequestToken requestToken = service.getRequestToken(); System.out.println("Got the Request Token!"); System.out.println(); @@ -47,7 +48,7 @@ public static void main(String... args) { // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - final Token accessToken = service.getAccessToken(requestToken, verifier); + final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, verifier); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + " )"); System.out.println(); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncExample.java index cf1492ba4..d610596ab 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncExample.java @@ -7,10 +7,10 @@ import com.github.scribejava.apis.FacebookApi; import com.github.scribejava.core.builder.ServiceBuilderAsync; import com.github.scribejava.core.model.ForceTypeOfHttpRequest; +import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthRequestAsync; import com.github.scribejava.core.model.Response; import com.github.scribejava.core.model.ScribeJavaConfig; -import com.github.scribejava.core.model.Token; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuth20Service; @@ -72,7 +72,7 @@ public static void main(String... args) throws InterruptedException, ExecutionEx // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - final Token accessToken = service.getAccessTokenAsync(verifier, null).get(); + final OAuth2AccessToken accessToken = service.getAccessTokenAsync(verifier, null).get(); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + " )"); System.out.println(); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java index 47c62db22..137ec6507 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java @@ -4,9 +4,9 @@ import java.util.Scanner; import com.github.scribejava.apis.FacebookApi; import com.github.scribejava.core.builder.ServiceBuilder; +import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; -import com.github.scribejava.core.model.Token; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuth20Service; @@ -57,7 +57,7 @@ public static void main(String... args) { // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - final Token accessToken = service.getAccessToken(verifier); + final OAuth2AccessToken accessToken = service.getAccessToken(verifier); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + " )"); System.out.println(); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExample.java index 8b67ed760..2f6724777 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExample.java @@ -3,9 +3,10 @@ import java.util.Scanner; import com.github.scribejava.core.builder.ServiceBuilder; import com.github.scribejava.apis.FlickrApi; +import com.github.scribejava.core.model.OAuth1AccessToken; +import com.github.scribejava.core.model.OAuth1RequestToken; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; -import com.github.scribejava.core.model.Token; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuth10aService; @@ -29,7 +30,7 @@ public static void main(String... args) { // Obtain the Request Token System.out.println("Fetching the Request Token..."); - final Token requestToken = service.getRequestToken(); + final OAuth1RequestToken requestToken = service.getRequestToken(); System.out.println("Got the Request Token!"); System.out.println(); @@ -43,7 +44,7 @@ public static void main(String... args) { // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - final Token accessToken = service.getAccessToken(requestToken, verifier); + final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, verifier); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + " )"); System.out.println(); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java index 3d44beb67..fc5522544 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java @@ -3,9 +3,9 @@ import java.util.Scanner; import com.github.scribejava.core.builder.ServiceBuilder; import com.github.scribejava.apis.Foursquare2Api; +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.Token; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuth20Service; @@ -42,7 +42,7 @@ public static void main(String... args) { // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - final Token accessToken = service.getAccessToken(verifier); + final OAuth2AccessToken accessToken = service.getAccessToken(verifier); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + " )"); System.out.println(); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FoursquareExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FoursquareExample.java index 86cabddc5..fe6f60e13 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FoursquareExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FoursquareExample.java @@ -3,9 +3,10 @@ import java.util.Scanner; import com.github.scribejava.core.builder.ServiceBuilder; import com.github.scribejava.apis.FoursquareApi; +import com.github.scribejava.core.model.OAuth1AccessToken; +import com.github.scribejava.core.model.OAuth1RequestToken; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; -import com.github.scribejava.core.model.Token; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuth10aService; @@ -26,7 +27,7 @@ public static void main(String... args) { // Obtain the Request Token System.out.println("Fetching the Request Token..."); - final Token requestToken = service.getRequestToken(); + final OAuth1RequestToken requestToken = service.getRequestToken(); System.out.println("Got the Request Token!"); System.out.println(); @@ -39,7 +40,7 @@ public static void main(String... args) { // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - final Token accessToken = service.getAccessToken(requestToken, verifier); + final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, verifier); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + " )"); System.out.println(); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java index f4bf61a63..a135f94f1 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java @@ -3,10 +3,11 @@ import java.util.Scanner; import com.github.scribejava.core.builder.ServiceBuilder; import com.github.scribejava.apis.FreelancerApi; +import com.github.scribejava.core.model.OAuth1AccessToken; +import com.github.scribejava.core.model.OAuth1RequestToken; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; import com.github.scribejava.core.model.SignatureType; -import com.github.scribejava.core.model.Token; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuth10aService; @@ -33,7 +34,7 @@ public static void main(String... args) { // Obtain the Request Token System.out.println("Fetching the Request Token..."); - final Token requestToken = service.getRequestToken(); + final OAuth1RequestToken requestToken = service.getRequestToken(); System.out.println("Got the Request Token!"); System.out.println("(if your curious it looks like this: " + requestToken + " )"); System.out.println(); @@ -47,7 +48,7 @@ public static void main(String... args) { // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - final Token accessToken = service.getAccessToken(requestToken, verifier); + final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, verifier); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + " )"); System.out.println(); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubExample.java index bed799eb9..889c505a8 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubExample.java @@ -4,9 +4,9 @@ import java.util.Scanner; import com.github.scribejava.apis.GitHubApi; 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.Token; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuth20Service; @@ -57,7 +57,7 @@ public static void main(String... args) { // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - final Token accessToken = service.getAccessToken(verifier); + final OAuth2AccessToken accessToken = service.getAccessToken(verifier); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + " )"); System.out.println(); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java index de90d0e51..f4fc5dec3 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java @@ -4,9 +4,9 @@ import java.util.Scanner; import com.github.scribejava.core.builder.ServiceBuilder; import com.github.scribejava.apis.GoogleApi20; +import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; -import com.github.scribejava.core.model.Token; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuth20Service; @@ -58,7 +58,7 @@ public static void main(String... args) { // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - final Token accessToken = service.getAccessToken(verifier); + final OAuth2AccessToken accessToken = service.getAccessToken(verifier); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + " )"); System.out.println(); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GoogleExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GoogleExample.java index 5f8d1bb47..19e249d9f 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GoogleExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GoogleExample.java @@ -3,9 +3,10 @@ import java.util.Scanner; import com.github.scribejava.core.builder.ServiceBuilder; import com.github.scribejava.apis.GoogleApi; +import com.github.scribejava.core.model.OAuth1AccessToken; +import com.github.scribejava.core.model.OAuth1RequestToken; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; -import com.github.scribejava.core.model.Token; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuth10aService; @@ -30,7 +31,7 @@ public static void main(String... args) { // Obtain the Request Token System.out.println("Fetching the Request Token..."); - final Token requestToken = service.getRequestToken(); + final OAuth1RequestToken requestToken = service.getRequestToken(); System.out.println("Got the Request Token!"); System.out.println("(if your curious it looks like this: " + requestToken + " )"); System.out.println(); @@ -44,7 +45,7 @@ public static void main(String... args) { // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - final Token accessToken = service.getAccessToken(requestToken, verifier); + final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, verifier); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + " )"); System.out.println(); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HHExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HHExample.java index b30732ba4..9e91e301e 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HHExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HHExample.java @@ -5,11 +5,11 @@ import com.github.scribejava.core.builder.ServiceBuilder; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; -import com.github.scribejava.core.model.Token; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.model.Verifier; import com.github.scribejava.apis.HHApi; +import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.oauth.OAuth20Service; public abstract class HHExample { @@ -45,7 +45,7 @@ public static void main(String... args) { // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - final Token accessToken = service.getAccessToken(verifier); + final OAuth2AccessToken accessToken = service.getAccessToken(verifier); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + " )"); System.out.println(); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ImgurExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ImgurExample.java index b9f922b23..fd3870708 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ImgurExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ImgurExample.java @@ -2,9 +2,9 @@ import com.github.scribejava.apis.ImgurApi; 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.Token; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuth20Service; @@ -42,7 +42,7 @@ public static void main(String... args) { // Trade the Request Token and Verifier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - final Token accessToken = service.getAccessToken(verifier); + final OAuth2AccessToken accessToken = service.getAccessToken(verifier); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + " )"); System.out.println(); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Kaixin20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Kaixin20Example.java index b979168e2..3f79d4d51 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Kaixin20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Kaixin20Example.java @@ -3,9 +3,9 @@ import java.util.Scanner; import com.github.scribejava.core.builder.ServiceBuilder; import com.github.scribejava.apis.KaixinApi20; +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.Token; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuth20Service; @@ -42,7 +42,7 @@ public static void main(String... args) { // Trade the Request Token and Verifier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - final Token accessToken = service.getAccessToken(verifier); + final OAuth2AccessToken accessToken = service.getAccessToken(verifier); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + " )"); System.out.println(); 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 51386828a..4af541711 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,9 +3,9 @@ import java.util.Scanner; import com.github.scribejava.core.builder.ServiceBuilder; import com.github.scribejava.apis.LinkedInApi20; +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.Token; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuth20Service; @@ -43,7 +43,7 @@ public static void main(String... args) { // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - final Token accessToken = service.getAccessToken(verifier); + final OAuth2AccessToken accessToken = service.getAccessToken(verifier); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + " )"); System.out.println(); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java index 5313c9894..e026c969a 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java @@ -3,9 +3,10 @@ import java.util.Scanner; import com.github.scribejava.core.builder.ServiceBuilder; import com.github.scribejava.apis.LinkedInApi; +import com.github.scribejava.core.model.OAuth1AccessToken; +import com.github.scribejava.core.model.OAuth1RequestToken; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; -import com.github.scribejava.core.model.Token; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuth10aService; @@ -27,7 +28,7 @@ public static void main(String... args) { // Obtain the Request Token System.out.println("Fetching the Request Token..."); - final Token requestToken = service.getRequestToken(); + final OAuth1RequestToken requestToken = service.getRequestToken(); System.out.println("Got the Request Token!"); System.out.println(); @@ -40,7 +41,7 @@ public static void main(String... args) { // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - final Token accessToken = service.getAccessToken(requestToken, verifier); + final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, verifier); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + " )"); System.out.println(); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java index 9da448baf..e24d39747 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java @@ -3,9 +3,10 @@ import java.util.Scanner; import com.github.scribejava.core.builder.ServiceBuilder; import com.github.scribejava.apis.LinkedInApi; +import com.github.scribejava.core.model.OAuth1AccessToken; +import com.github.scribejava.core.model.OAuth1RequestToken; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; -import com.github.scribejava.core.model.Token; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuth10aService; @@ -31,7 +32,7 @@ public static void main(String... args) { // Obtain the Request Token System.out.println("Fetching the Request Token..."); - final Token requestToken = service.getRequestToken(); + final OAuth1RequestToken requestToken = service.getRequestToken(); System.out.println("Got the Request Token!"); System.out.println(); @@ -44,7 +45,7 @@ public static void main(String... args) { // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - final Token accessToken = service.getAccessToken(requestToken, verifier); + final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, verifier); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + " )"); System.out.println(); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java index 0a3396e52..3f2505dbd 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java @@ -3,9 +3,9 @@ import java.util.Scanner; import com.github.scribejava.core.builder.ServiceBuilder; import com.github.scribejava.apis.LiveApi; +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.Token; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuth20Service; @@ -43,7 +43,7 @@ public static void main(String... args) { // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - final Token accessToken = service.getAccessToken(verifier); + final OAuth2AccessToken accessToken = service.getAccessToken(verifier); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + " )"); System.out.println(); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LoveFilmExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LoveFilmExample.java index 056d3a6e9..46db1f3ba 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LoveFilmExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LoveFilmExample.java @@ -3,9 +3,10 @@ import java.util.Scanner; import com.github.scribejava.core.builder.ServiceBuilder; import com.github.scribejava.apis.LoveFilmApi; +import com.github.scribejava.core.model.OAuth1AccessToken; +import com.github.scribejava.core.model.OAuth1RequestToken; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; -import com.github.scribejava.core.model.Token; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuth10aService; @@ -30,7 +31,7 @@ public static void main(String... args) { // Grab a request token. System.out.println("Fetching request token."); - final Token requestToken = service.getRequestToken(); + final OAuth1RequestToken requestToken = service.getRequestToken(); System.out.println("Got it ... "); System.out.println(requestToken.getToken()); @@ -47,7 +48,7 @@ public static void main(String... args) { // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - final Token accessToken = service.getAccessToken(requestToken, verifier); + final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, verifier); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + " )"); System.out.println(); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java index cf9d58ef2..802b6e967 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java @@ -5,9 +5,9 @@ import java.util.concurrent.ExecutionException; import com.github.scribejava.apis.MailruApi; import com.github.scribejava.core.builder.ServiceBuilderAsync; +import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthRequestAsync; import com.github.scribejava.core.model.Response; -import com.github.scribejava.core.model.Token; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuth20Service; @@ -56,7 +56,7 @@ public static void main(String... args) throws InterruptedException, ExecutionEx // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - final Token accessToken = service.getAccessTokenAsync(verifier, null).get(); + final OAuth2AccessToken accessToken = service.getAccessTokenAsync(verifier, null).get(); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + " )"); System.out.println(); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java index e64e2635c..6e0ac27c8 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java @@ -4,10 +4,10 @@ import com.github.scribejava.core.builder.ServiceBuilder; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; -import com.github.scribejava.core.model.Token; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.model.Verifier; import com.github.scribejava.apis.MailruApi; +import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.oauth.OAuth20Service; public abstract class MailruExample { @@ -44,7 +44,7 @@ public static void main(String... args) { // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - final Token accessToken = service.getAccessToken(verifier); + final OAuth2AccessToken accessToken = service.getAccessToken(verifier); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + " )"); System.out.println(); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java index 19d2dfe20..6a19c459d 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java @@ -3,9 +3,10 @@ import java.util.Scanner; import com.github.scribejava.core.builder.ServiceBuilder; import com.github.scribejava.apis.MeetupApi; +import com.github.scribejava.core.model.OAuth1AccessToken; +import com.github.scribejava.core.model.OAuth1RequestToken; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; -import com.github.scribejava.core.model.Token; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuth10aService; @@ -26,7 +27,7 @@ public static void main(String... args) { // Obtain the Request Token System.out.println("Fetching the Request Token..."); - final Token requestToken = service.getRequestToken(); + final OAuth1RequestToken requestToken = service.getRequestToken(); System.out.println("Got the Request Token!"); System.out.println(); @@ -39,7 +40,7 @@ public static void main(String... args) { // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - final Token accessToken = service.getAccessToken(requestToken, verifier); + final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, verifier); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + " )"); System.out.println(); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NeteaseWeiboExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NeteaseWeiboExample.java index f5203070e..e5130908f 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NeteaseWeiboExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NeteaseWeiboExample.java @@ -3,9 +3,10 @@ import java.util.Scanner; import com.github.scribejava.core.builder.ServiceBuilder; import com.github.scribejava.apis.NeteaseWeibooApi; +import com.github.scribejava.core.model.OAuth1AccessToken; +import com.github.scribejava.core.model.OAuth1RequestToken; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; -import com.github.scribejava.core.model.Token; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuth10aService; @@ -30,7 +31,7 @@ public static void main(String... args) { // Grab a request token. System.out.println("Fetching request token."); - final Token requestToken = service.getRequestToken(); + final OAuth1RequestToken requestToken = service.getRequestToken(); System.out.println("Got it ... "); System.out.println(requestToken.getToken()); @@ -47,7 +48,7 @@ public static void main(String... args) { // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - final Token accessToken = service.getAccessToken(requestToken, verifier); + final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, verifier); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + " )"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java index 3b703f124..b00b8d696 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java @@ -3,9 +3,9 @@ import java.util.Scanner; import com.github.scribejava.core.builder.ServiceBuilder; import com.github.scribejava.apis.OdnoklassnikiApi; +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.Token; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuth20Service; @@ -48,7 +48,7 @@ public static void main(String... args) { // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - final Token accessToken = service.getAccessToken(verifier); + final OAuth2AccessToken accessToken = service.getAccessToken(verifier); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + " )"); System.out.println(); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java index 72aba4cb7..ca675d260 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java @@ -2,9 +2,9 @@ import com.github.scribejava.apis.PinterestApi; 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.Token; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuth20Service; @@ -43,7 +43,7 @@ public static void main(String... args) { // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - final Token accessToken = service.getAccessToken(verifier); + final OAuth2AccessToken accessToken = service.getAccessToken(verifier); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + " )"); System.out.println(); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Px500Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Px500Example.java index 5ea537229..9d366e38d 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Px500Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Px500Example.java @@ -3,9 +3,10 @@ import java.util.Scanner; import com.github.scribejava.core.builder.ServiceBuilder; import com.github.scribejava.apis.Px500Api; +import com.github.scribejava.core.model.OAuth1AccessToken; +import com.github.scribejava.core.model.OAuth1RequestToken; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; -import com.github.scribejava.core.model.Token; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuth10aService; @@ -26,7 +27,7 @@ public static void main(String... args) { // Obtain the Request Token System.out.println("Fetching the Request Token..."); - final Token requestToken = service.getRequestToken(); + final OAuth1RequestToken requestToken = service.getRequestToken(); System.out.println("Got the Request Token!"); System.out.println(); @@ -39,7 +40,7 @@ public static void main(String... args) { // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - final Token accessToken = service.getAccessToken(requestToken, verifier); + final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, verifier); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + " )"); System.out.println(); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java index ba7710fd4..299f9ede3 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java @@ -11,10 +11,10 @@ import java.util.Scanner; import com.github.scribejava.core.builder.ServiceBuilder; import com.github.scribejava.apis.RenrenApi; +import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; -import com.github.scribejava.core.model.Token; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuth20Service; @@ -52,7 +52,7 @@ public static void main(String... args) { // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - final Token accessToken = service.getAccessToken(verifier); + final OAuth2AccessToken accessToken = service.getAccessToken(verifier); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + " )"); System.out.println(); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeibo2Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeibo2Example.java index cb84b889d..33e46454e 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeibo2Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeibo2Example.java @@ -3,9 +3,9 @@ import java.util.Scanner; import com.github.scribejava.core.builder.ServiceBuilder; import com.github.scribejava.apis.SinaWeiboApi20; +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.Token; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuth20Service; @@ -42,7 +42,7 @@ public static void main(String... args) { // Trade the Request Token and Verifier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - final Token accessToken = service.getAccessToken(verifier); + final OAuth2AccessToken accessToken = service.getAccessToken(verifier); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + " )"); System.out.println(); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeiboExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeiboExample.java index 26688ba97..f6ddf99e2 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeiboExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeiboExample.java @@ -3,9 +3,10 @@ import java.util.Scanner; import com.github.scribejava.core.builder.ServiceBuilder; import com.github.scribejava.apis.SinaWeiboApi; +import com.github.scribejava.core.model.OAuth1AccessToken; +import com.github.scribejava.core.model.OAuth1RequestToken; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; -import com.github.scribejava.core.model.Token; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuth10aService; @@ -30,7 +31,7 @@ public static void main(String... args) { // Grab a request token. System.out.println("Fetching request token."); - final Token requestToken = service.getRequestToken(); + final OAuth1RequestToken requestToken = service.getRequestToken(); System.out.println("Got it ... "); System.out.println(requestToken.getToken()); @@ -47,7 +48,7 @@ public static void main(String... args) { // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - final Token accessToken = service.getAccessToken(requestToken, verifier); + final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, verifier); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + " )"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SkyrockExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SkyrockExample.java index e4709069e..3c0a8655a 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SkyrockExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SkyrockExample.java @@ -3,9 +3,10 @@ import java.util.Scanner; import com.github.scribejava.core.builder.ServiceBuilder; import com.github.scribejava.apis.SkyrockApi; +import com.github.scribejava.core.model.OAuth1AccessToken; +import com.github.scribejava.core.model.OAuth1RequestToken; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; -import com.github.scribejava.core.model.Token; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuth10aService; @@ -26,7 +27,7 @@ public static void main(String... args) { // Obtain the Request Token System.out.println("Fetching the Request Token..."); - final Token requestToken = service.getRequestToken(); + final OAuth1RequestToken requestToken = service.getRequestToken(); System.out.println("Got the Request Token!"); System.out.println(); @@ -39,7 +40,7 @@ public static void main(String... args) { // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - final Token accessToken = service.getAccessToken(requestToken, verifier); + final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, verifier); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + " )"); System.out.println(); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SohuWeiboExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SohuWeiboExample.java index 3ffb76c71..3f39264fa 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SohuWeiboExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SohuWeiboExample.java @@ -3,9 +3,10 @@ import java.util.Scanner; import com.github.scribejava.core.builder.ServiceBuilder; import com.github.scribejava.apis.SohuWeiboApi; +import com.github.scribejava.core.model.OAuth1AccessToken; +import com.github.scribejava.core.model.OAuth1RequestToken; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; -import com.github.scribejava.core.model.Token; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuth10aService; @@ -30,7 +31,7 @@ public static void main(String... args) { // Grab a request token. System.out.println("Fetching request token."); - final Token requestToken = service.getRequestToken(); + final OAuth1RequestToken requestToken = service.getRequestToken(); System.out.println("Got it ... "); System.out.println(requestToken.getToken()); @@ -47,7 +48,7 @@ public static void main(String... args) { // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - final Token accessToken = service.getAccessToken(requestToken, verifier); + final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, verifier); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + " )"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/StackExchangeExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/StackExchangeExample.java index c2d985ab8..c6f8a4288 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/StackExchangeExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/StackExchangeExample.java @@ -5,9 +5,9 @@ import com.github.scribejava.apis.StackExchangeApi; 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.Token; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuth20Service; @@ -62,7 +62,7 @@ public static void main(String... args) { // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - final Token accessToken = service.getAccessToken(verifier); + final OAuth2AccessToken accessToken = service.getAccessToken(verifier); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + " )"); System.out.println(); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TrelloExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TrelloExample.java index ba7684c2e..c2076371f 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TrelloExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TrelloExample.java @@ -3,9 +3,10 @@ import java.util.Scanner; import com.github.scribejava.core.builder.ServiceBuilder; import com.github.scribejava.apis.TrelloApi; +import com.github.scribejava.core.model.OAuth1AccessToken; +import com.github.scribejava.core.model.OAuth1RequestToken; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; -import com.github.scribejava.core.model.Token; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuth10aService; @@ -28,7 +29,7 @@ public static void main(String... args) { // Obtain the Request Token System.out.println("Fetching the Request Token..."); - final Token requestToken = service.getRequestToken(); + final OAuth1RequestToken requestToken = service.getRequestToken(); System.out.println("Got the Request Token!"); System.out.println(); @@ -41,7 +42,7 @@ public static void main(String... args) { // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - final Token accessToken = service.getAccessToken(requestToken, verifier); + final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, verifier); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + " )"); System.out.println(); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TumblrExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TumblrExample.java index e0bb5660e..2b1b32f9d 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TumblrExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TumblrExample.java @@ -3,9 +3,10 @@ import java.util.Scanner; import com.github.scribejava.core.builder.ServiceBuilder; import com.github.scribejava.apis.TumblrApi; +import com.github.scribejava.core.model.OAuth1AccessToken; +import com.github.scribejava.core.model.OAuth1RequestToken; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; -import com.github.scribejava.core.model.Token; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuth10aService; @@ -28,7 +29,7 @@ public static void main(String... args) { // Obtain the Request Token System.out.println("Fetching the Request Token..."); - final Token requestToken = service.getRequestToken(); + final OAuth1RequestToken requestToken = service.getRequestToken(); System.out.println("Got the Request Token!"); System.out.println(); @@ -41,8 +42,7 @@ public static void main(String... args) { // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - final Token accessToken = service.getAccessToken(requestToken, - verifier); + final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, verifier); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + " )"); System.out.println(); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TutByExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TutByExample.java index ebebcc73b..c3c7075a2 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TutByExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TutByExample.java @@ -6,11 +6,11 @@ import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; -import com.github.scribejava.core.model.Token; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.model.Verifier; import com.github.scribejava.apis.TutByApi; +import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.oauth.OAuth20Service; public abstract class TutByExample { @@ -45,7 +45,7 @@ public static void main(String... args) { // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - final Token accessToken = service.getAccessToken(verifier); + final OAuth2AccessToken accessToken = service.getAccessToken(verifier); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + " )"); System.out.println(); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TwitterExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TwitterExample.java index ed4c9d1a4..1c26e836b 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TwitterExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TwitterExample.java @@ -3,9 +3,10 @@ import java.util.Scanner; import com.github.scribejava.core.builder.ServiceBuilder; import com.github.scribejava.apis.TwitterApi; +import com.github.scribejava.core.model.OAuth1AccessToken; +import com.github.scribejava.core.model.OAuth1RequestToken; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; -import com.github.scribejava.core.model.Token; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuth10aService; @@ -26,7 +27,7 @@ public static void main(String... args) { // Obtain the Request Token System.out.println("Fetching the Request Token..."); - final Token requestToken = service.getRequestToken(); + final OAuth1RequestToken requestToken = service.getRequestToken(); System.out.println("Got the Request Token!"); System.out.println(); @@ -39,7 +40,7 @@ public static void main(String... args) { // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - final Token accessToken = service.getAccessToken(requestToken, verifier); + final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, verifier); System.out.println("Got the Access Token!"); System.out.println("(if you're curious it looks like this: " + accessToken + " )"); System.out.println(); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ViadeoExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ViadeoExample.java index e488a5d4e..76516ee91 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ViadeoExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ViadeoExample.java @@ -3,9 +3,9 @@ import java.util.Scanner; import com.github.scribejava.core.builder.ServiceBuilder; import com.github.scribejava.apis.ViadeoApi; +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.Token; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuth20Service; @@ -42,7 +42,7 @@ public static void main(String... args) { // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - final Token accessToken = service.getAccessToken(verifier); + final OAuth2AccessToken accessToken = service.getAccessToken(verifier); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + " )"); System.out.println(); 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 520de97b5..68f6390af 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExample.java @@ -3,9 +3,9 @@ import java.util.Scanner; import com.github.scribejava.core.builder.ServiceBuilder; import com.github.scribejava.apis.VkontakteApi; +import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; -import com.github.scribejava.core.model.Token; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuth20Service; @@ -47,7 +47,7 @@ public static void main(String... args) { // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - final Token accessToken = service.getAccessToken(verifier); + final OAuth2AccessToken accessToken = service.getAccessToken(verifier); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + " )"); System.out.println(); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XingExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XingExample.java index 9695e10d6..5542c34cc 100755 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XingExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XingExample.java @@ -3,9 +3,10 @@ import java.util.Scanner; import com.github.scribejava.core.builder.ServiceBuilder; import com.github.scribejava.apis.XingApi; +import com.github.scribejava.core.model.OAuth1AccessToken; +import com.github.scribejava.core.model.OAuth1RequestToken; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; -import com.github.scribejava.core.model.Token; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuth10aService; @@ -26,7 +27,7 @@ public static void main(String... args) { // Obtain the Request Token System.out.println("Fetching the Request Token..."); - final Token requestToken = service.getRequestToken(); + final OAuth1RequestToken requestToken = service.getRequestToken(); System.out.println("Got the Request Token!"); System.out.println(); @@ -39,7 +40,7 @@ public static void main(String... args) { // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - final Token accessToken = service.getAccessToken(requestToken, verifier); + final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, verifier); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + " )"); System.out.println(); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/YahooExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/YahooExample.java index 7d1bcc24e..e2cda508c 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/YahooExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/YahooExample.java @@ -3,9 +3,10 @@ import java.util.Scanner; import com.github.scribejava.core.builder.ServiceBuilder; import com.github.scribejava.apis.YahooApi; +import com.github.scribejava.core.model.OAuth1AccessToken; +import com.github.scribejava.core.model.OAuth1RequestToken; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; -import com.github.scribejava.core.model.Token; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuth10aService; @@ -27,7 +28,7 @@ public static void main(String... args) { // Obtain the Request Token System.out.println("Fetching the Request Token..."); - final Token requestToken = service.getRequestToken(); + final OAuth1RequestToken requestToken = service.getRequestToken(); System.out.println("Got the Request Token!"); System.out.println(); @@ -40,7 +41,7 @@ public static void main(String... args) { // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - final Token accessToken = service.getAccessToken(requestToken, verifier); + final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, verifier); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + " )"); System.out.println(); diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi10a.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi10a.java index f4a436def..63267dc1d 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi10a.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi10a.java @@ -1,12 +1,11 @@ package com.github.scribejava.core.builder.api; -import com.github.scribejava.core.extractors.AccessTokenExtractor; import com.github.scribejava.core.extractors.BaseStringExtractor; import com.github.scribejava.core.extractors.BaseStringExtractorImpl; import com.github.scribejava.core.extractors.HeaderExtractor; import com.github.scribejava.core.extractors.HeaderExtractorImpl; -import com.github.scribejava.core.extractors.RequestTokenExtractor; -import com.github.scribejava.core.extractors.TokenExtractorImpl; +import com.github.scribejava.core.extractors.OAuth1AccessTokenExtractor; +import com.github.scribejava.core.extractors.OAuth1RequestTokenExtractor; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.Token; import com.github.scribejava.core.model.Verb; @@ -15,6 +14,9 @@ import com.github.scribejava.core.services.SignatureService; import com.github.scribejava.core.services.TimestampService; import com.github.scribejava.core.services.TimestampServiceImpl; +import com.github.scribejava.core.extractors.TokenExtractor; +import com.github.scribejava.core.model.OAuth1AccessToken; +import com.github.scribejava.core.model.OAuth1RequestToken; /** * Default implementation of the OAuth protocol, version 1.0a @@ -38,8 +40,8 @@ public abstract class DefaultApi10a implements Api { * * @return access token extractor */ - public AccessTokenExtractor getAccessTokenExtractor() { - return new TokenExtractorImpl(); + public TokenExtractor getAccessTokenExtractor() { + return OAuth1AccessTokenExtractor.instance(); } /** @@ -65,8 +67,8 @@ public HeaderExtractor getHeaderExtractor() { * * @return request token extractor */ - public RequestTokenExtractor getRequestTokenExtractor() { - return new TokenExtractorImpl(); + public TokenExtractor getRequestTokenExtractor() { + return OAuth1RequestTokenExtractor.instance(); } /** diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java index b7ede9211..9bdb552a0 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java @@ -1,7 +1,8 @@ package com.github.scribejava.core.builder.api; -import com.github.scribejava.core.extractors.AccessTokenExtractor; -import com.github.scribejava.core.extractors.TokenExtractor20Impl; +import com.github.scribejava.core.extractors.OAuth2AccessTokenExtractor; +import com.github.scribejava.core.extractors.TokenExtractor; +import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.oauth.OAuth20Service; @@ -28,8 +29,8 @@ public abstract class DefaultApi20 implements Api { * * @return access token extractor */ - public AccessTokenExtractor getAccessTokenExtractor() { - return new TokenExtractor20Impl(); + public TokenExtractor getAccessTokenExtractor() { + return OAuth2AccessTokenExtractor.instance(); } /** diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/TokenExtractorImpl.java b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/AbstractOAuth1TokenExtractor.java similarity index 74% rename from scribejava-core/src/main/java/com/github/scribejava/core/extractors/TokenExtractorImpl.java rename to scribejava-core/src/main/java/com/github/scribejava/core/extractors/AbstractOAuth1TokenExtractor.java index 3494e5eb3..8609320c6 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/TokenExtractorImpl.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/AbstractOAuth1TokenExtractor.java @@ -3,18 +3,19 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import com.github.scribejava.core.exceptions.OAuthException; -import com.github.scribejava.core.model.Token; +import com.github.scribejava.core.model.OAuth1Token; import com.github.scribejava.core.utils.OAuthEncoder; import com.github.scribejava.core.utils.Preconditions; /** - * Default implementation of {@link RequestTokenExtractor} and {@link AccessTokenExtractor}. Conforms to OAuth 1.0a + * Default implementation of {@link TokenExtractor} for OAuth 1.0a * * The process for extracting access and request tokens is similar so this class can do both things. * * @author Pablo Fernandez + * @param concrete type of OAuth1Token. access or request */ -public class TokenExtractorImpl implements RequestTokenExtractor, AccessTokenExtractor { +public abstract class AbstractOAuth1TokenExtractor implements TokenExtractor { private static final Pattern TOKEN_REGEX = Pattern.compile("oauth_token=([^&]+)"); private static final Pattern SECRET_REGEX = Pattern.compile("oauth_token_secret=([^&]*)"); @@ -23,12 +24,12 @@ public class TokenExtractorImpl implements RequestTokenExtractor, AccessTokenExt * {@inheritDoc} */ @Override - public Token extract(String response) { + public T extract(String response) { Preconditions.checkEmptyString(response, "Response body is incorrect. Can't extract a token from an empty string"); final String token = extract(response, TOKEN_REGEX); final String secret = extract(response, SECRET_REGEX); - return new Token(token, secret, response); + return createToken(token, secret, response); } private String extract(String response, Pattern p) { @@ -40,4 +41,6 @@ private String extract(String response, Pattern p) { + response + "'", null); } } + + protected abstract T createToken(String token, String secret, String response); } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/AccessTokenExtractor.java b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/AccessTokenExtractor.java deleted file mode 100644 index ec14ca2f1..000000000 --- a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/AccessTokenExtractor.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.github.scribejava.core.extractors; - -import com.github.scribejava.core.model.Token; - -/** - * Simple command object that extracts a {@link Token} from a String - * - * @author Pablo Fernandez - */ -public interface AccessTokenExtractor { - - /** - * Extracts the access token from the contents of an Http Response - * - * @param response the contents of the response - * @return OAuth access token - */ - Token extract(String response); -} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/BaseStringExtractor.java b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/BaseStringExtractor.java index f929135c8..1d468be6f 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/BaseStringExtractor.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/BaseStringExtractor.java @@ -3,16 +3,14 @@ import com.github.scribejava.core.model.AbstractRequest; /** - * Simple command object that extracts a base string from a - * {@link com.github.scribejava.core.model.AbstractRequest} + * Simple command object that extracts a base string from a {@link AbstractRequest} * * @author Pablo Fernandez */ public interface BaseStringExtractor { /** - * Extracts an url-encoded base string from the - * {@link com.github.scribejava.core.model.AbstractRequest}. + * Extracts an url-encoded base string from the {@link AbstractRequest}. * * See the oauth spec for more info on this. * diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth1AccessTokenExtractor.java b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth1AccessTokenExtractor.java new file mode 100644 index 000000000..33c9c2e35 --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth1AccessTokenExtractor.java @@ -0,0 +1,24 @@ +package com.github.scribejava.core.extractors; + +import com.github.scribejava.core.model.OAuth1AccessToken; + +public class OAuth1AccessTokenExtractor extends AbstractOAuth1TokenExtractor { + + protected OAuth1AccessTokenExtractor() { + } + + private static class InstanceHolder { + + private static final OAuth1AccessTokenExtractor INSTANCE = new OAuth1AccessTokenExtractor(); + } + + public static OAuth1AccessTokenExtractor instance() { + return InstanceHolder.INSTANCE; + } + + @Override + protected OAuth1AccessToken createToken(String token, String secret, String response) { + return new OAuth1AccessToken(token, secret, response); + } + +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth1RequestTokenExtractor.java b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth1RequestTokenExtractor.java new file mode 100644 index 000000000..516612713 --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth1RequestTokenExtractor.java @@ -0,0 +1,23 @@ +package com.github.scribejava.core.extractors; + +import com.github.scribejava.core.model.OAuth1RequestToken; + +public class OAuth1RequestTokenExtractor extends AbstractOAuth1TokenExtractor { + + protected OAuth1RequestTokenExtractor() { + } + + private static class InstanceHolder { + + private static final OAuth1RequestTokenExtractor INSTANCE = new OAuth1RequestTokenExtractor(); + } + + public static OAuth1RequestTokenExtractor instance() { + return InstanceHolder.INSTANCE; + } + + @Override + protected OAuth1RequestToken createToken(String token, String secret, String response) { + return new OAuth1RequestToken(token, secret, response); + } +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/TokenExtractor20Impl.java b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenExtractor.java similarity index 59% rename from scribejava-core/src/main/java/com/github/scribejava/core/extractors/TokenExtractor20Impl.java rename to scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenExtractor.java index 3b8a2be2b..928f9f4d8 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/TokenExtractor20Impl.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenExtractor.java @@ -3,31 +3,41 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import com.github.scribejava.core.exceptions.OAuthException; -import com.github.scribejava.core.model.Token; +import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.utils.OAuthEncoder; import com.github.scribejava.core.utils.Preconditions; /** - * Default implementation of {@link AccessTokenExtractor}. Conforms to OAuth 2.0 - * + * Default implementation of {@link TokenExtractor} for OAuth 2.0 */ -public class TokenExtractor20Impl implements AccessTokenExtractor { +public class OAuth2AccessTokenExtractor implements TokenExtractor { private static final String TOKEN_REGEX = "access_token=([^&]+)"; - private static final String EMPTY_SECRET = ""; + + protected OAuth2AccessTokenExtractor() { + } + + private static class InstanceHolder { + + private static final OAuth2AccessTokenExtractor INSTANCE = new OAuth2AccessTokenExtractor(); + } + + public static OAuth2AccessTokenExtractor instance() { + return InstanceHolder.INSTANCE; + } /** * {@inheritDoc} */ @Override - public Token extract(String response) { + public OAuth2AccessToken extract(String response) { Preconditions.checkEmptyString(response, "Response body is incorrect. Can't extract a token from an empty string"); final Matcher matcher = Pattern.compile(TOKEN_REGEX).matcher(response); if (matcher.find()) { final String token = OAuthEncoder.decode(matcher.group(1)); - return new Token(token, EMPTY_SECRET, response); + return new OAuth2AccessToken(token, response); } else { throw new OAuthException("Response body is incorrect. Can't extract a token from this: '" + response + "'", null); diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/JsonTokenExtractor.java b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractor.java similarity index 56% rename from scribejava-core/src/main/java/com/github/scribejava/core/extractors/JsonTokenExtractor.java rename to scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractor.java index b43e89f49..dc707c8e4 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/JsonTokenExtractor.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractor.java @@ -3,16 +3,28 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import com.github.scribejava.core.exceptions.OAuthException; -import com.github.scribejava.core.model.Token; +import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.utils.Preconditions; -public class JsonTokenExtractor implements AccessTokenExtractor { +public class OAuth2AccessTokenJsonExtractor implements TokenExtractor { private static final Pattern ACCESS_TOKEN_PATTERN = Pattern.compile("\"access_token\"\\s*:\\s*\"(\\S*?)\""); + protected OAuth2AccessTokenJsonExtractor() { + } + + private static class InstanceHolder { + + private static final OAuth2AccessTokenJsonExtractor INSTANCE = new OAuth2AccessTokenJsonExtractor(); + } + + public static OAuth2AccessTokenJsonExtractor instance() { + return InstanceHolder.INSTANCE; + } + @Override - public Token extract(String response) { - return new Token(extractAccessToken(response), "", response); + public OAuth2AccessToken extract(String response) { + return new OAuth2AccessToken(extractAccessToken(response), response); } protected String extractAccessToken(String response) { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/RequestTokenExtractor.java b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/RequestTokenExtractor.java deleted file mode 100644 index bc518c617..000000000 --- a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/RequestTokenExtractor.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.github.scribejava.core.extractors; - -import com.github.scribejava.core.model.Token; - -/** - * Simple command object that extracts a {@link Token} from a String - * - * @author Pablo Fernandez - */ -public interface RequestTokenExtractor { - - /** - * Extracts the request token from the contents of an Http Response - * - * @param response the contents of the response - * @return OAuth access token - */ - Token extract(String response); -} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/TokenExtractor.java b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/TokenExtractor.java new file mode 100644 index 000000000..eec9546cc --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/TokenExtractor.java @@ -0,0 +1,18 @@ +package com.github.scribejava.core.extractors; + +import com.github.scribejava.core.model.Token; + +/** + * Simple command object that extracts a concrete {@link Token} from a String + * @param concrete type of Token + */ +public interface TokenExtractor { + + /** + * Extracts the concrete type of token from the contents of an Http Response + * + * @param response the contents of the response + * @return OAuth access token + */ + T extract(String response); +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth1AccessToken.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth1AccessToken.java new file mode 100644 index 000000000..e4d31c6c0 --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth1AccessToken.java @@ -0,0 +1,17 @@ +package com.github.scribejava.core.model; + +/** + * Represents an OAuth 1 Access Token + */ +public class OAuth1AccessToken extends OAuth1Token { + + private static final long serialVersionUID = 1344500144115482404L; + + public OAuth1AccessToken(String token, String secret) { + this(token, secret, null); + } + + public OAuth1AccessToken(String token, String secret, String rawResponse) { + super(token, secret, rawResponse); + } +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth1RequestToken.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth1RequestToken.java new file mode 100644 index 000000000..5f0e11b24 --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth1RequestToken.java @@ -0,0 +1,17 @@ +package com.github.scribejava.core.model; + +/** + * Represents an OAuth 1 Abstract Token + */ +public class OAuth1RequestToken extends OAuth1Token { + + private static final long serialVersionUID = 3910105236810537839L; + + public OAuth1RequestToken(String token, String secret) { + this(token, secret, null); + } + + public OAuth1RequestToken(String token, String secret, String rawResponse) { + super(token, secret, rawResponse); + } +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth1Token.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth1Token.java new file mode 100644 index 000000000..b6c5daa6b --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth1Token.java @@ -0,0 +1,62 @@ +package com.github.scribejava.core.model; + +import com.github.scribejava.core.utils.Preconditions; +import java.util.Objects; + +/** + * Represents an abstract OAuth 1 Access Token (either request or access token) + */ +public abstract class OAuth1Token extends Token { + + private static final long serialVersionUID = -2591380053073767654L; + + private final String secret; + + public OAuth1Token(String token, String secret, String rawResponse) { + super(token, rawResponse); + Preconditions.checkNotNull(secret, "Secret can't be null"); + this.secret = secret; + } + + public String getSecret() { + return secret; + } + + @Override + public String toString() { + return String.format("Token[%s , %s]", getToken(), secret); + } + + /** + * @return true if the token is empty (token = "", secret = "") + */ + public boolean isEmpty() { + return "".equals(this.getToken()) && "".equals(this.secret); + } + + @Override + public int hashCode() { + int hash = 7; + hash = 71 * hash + Objects.hashCode(secret); + hash = 71 * hash + Objects.hashCode(getToken()); + 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 OAuth1Token other = (OAuth1Token) obj; + if (!Objects.equals(secret, other.getSecret())) { + return false; + } + return Objects.equals(getToken(), other.getToken()); + } +} 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 new file mode 100644 index 000000000..ad903eec1 --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth2AccessToken.java @@ -0,0 +1,18 @@ +package com.github.scribejava.core.model; + +/** + * Represents an OAuth 2 Access Token + */ +public class OAuth2AccessToken extends Token { + + private static final long serialVersionUID = -7450991088697660741L; + + public OAuth2AccessToken(String token) { + super(token, null); + } + + public OAuth2AccessToken(String token, String rawResponse) { + super(token, rawResponse); + } + +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConstants.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConstants.java index 879dc5eec..0aca979e9 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConstants.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConstants.java @@ -22,7 +22,7 @@ public interface OAuthConstants { String OUT_OF_BAND = "oob"; String VERIFIER = "oauth_verifier"; String HEADER = "Authorization"; - Token EMPTY_TOKEN = new Token("", ""); + OAuth1RequestToken EMPTY_TOKEN = new OAuth1RequestToken("", ""); String SCOPE = "scope"; // OAuth 2.0 diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/Token.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/Token.java index 4e51ca7c7..7fb33f398 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/Token.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/Token.java @@ -2,36 +2,21 @@ import java.io.Serializable; import com.github.scribejava.core.utils.Preconditions; +import java.util.Objects; /** - * Represents an OAuth token (either request or access token) and its secret - * - * @author Pablo Fernandez + * Represents an abstract OAuth (1 and 2) token (either request or access token) */ -public class Token implements Serializable { +public abstract class Token implements Serializable { - private static final long serialVersionUID = 715000866082812683L; + private static final long serialVersionUID = 777818051043452947L; private final String token; - private final String secret; private final String rawResponse; - /** - * Default constructor - * - * @param token token value. Can't be null. - * @param secret token secret. Can't be null. - */ - public Token(String token, String secret) { - this(token, secret, null); - } - - public Token(String token, String secret, String rawResponse) { + public Token(String token, String rawResponse) { Preconditions.checkNotNull(token, "Token can't be null"); - Preconditions.checkNotNull(secret, "Secret can't be null"); - this.token = token; - this.secret = secret; this.rawResponse = rawResponse; } @@ -39,10 +24,6 @@ public String getToken() { return token; } - public String getSecret() { - return secret; - } - public String getRawResponse() { if (rawResponse == null) { throw new IllegalStateException( @@ -67,42 +48,28 @@ public String getParameter(String parameter) { @Override public String toString() { - return String.format("Token[%s , %s]", token, secret); - } - - /** - * @return true if the token is empty (token = "", secret = "") - */ - public boolean isEmpty() { - return "".equals(this.token) && "".equals(this.secret); + return String.format("Token[%s]", token); } - /** - * Factory method - * - * Useful for two legged OAuth. - * - * @return empty token (token = "", secret = "") - */ - public static Token empty() { - return new Token("", ""); + @Override + public int hashCode() { + int hash = 7; + hash = 59 * hash + Objects.hashCode(token); + return hash; } @Override - public boolean equals(Object o) { - if (this == o) { + public boolean equals(Object obj) { + if (this == obj) { return true; } - if (o == null || getClass() != o.getClass()) { + if (obj == null) { return false; } - - final Token that = (Token) o; - return token.equals(that.getToken()) && secret.equals(that.getSecret()); - } - - @Override - public int hashCode() { - return 31 * token.hashCode() + secret.hashCode(); + if (getClass() != obj.getClass()) { + return false; + } + final Token other = (Token) obj; + return Objects.equals(token, other.getToken()); } } 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 7dc2e8556..3a2670305 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 @@ -6,6 +6,9 @@ import java.util.concurrent.Future; import com.github.scribejava.core.builder.api.DefaultApi10a; import com.github.scribejava.core.model.AbstractRequest; +import com.github.scribejava.core.model.OAuth1AccessToken; +import com.github.scribejava.core.model.OAuth1RequestToken; +import com.github.scribejava.core.model.OAuth1Token; import com.github.scribejava.core.model.OAuthAsyncRequestCallback; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; @@ -22,7 +25,7 @@ * * @author Pablo Fernandez */ -public class OAuth10aService extends OAuthService { +public class OAuth10aService extends OAuthService { private static final String VERSION = "1.0"; private final DefaultApi10a api; @@ -43,7 +46,7 @@ public OAuth10aService(DefaultApi10a api, OAuthConfig config) { * * @return request token */ - public Token getRequestToken() { + public OAuth1RequestToken getRequestToken() { final OAuthConfig config = getConfig(); config.log("obtaining request token from " + api.getRequestTokenEndpoint()); final OAuthRequest request = new OAuthRequest(api.getRequestTokenVerb(), api.getRequestTokenEndpoint(), this); @@ -62,7 +65,7 @@ public Token getRequestToken() { return api.getRequestTokenExtractor().extract(body); } - private void addOAuthParams(AbstractRequest request, Token token) { + private void addOAuthParams(AbstractRequest request, OAuth1Token token) { final OAuthConfig config = getConfig(); request.addOAuthParameter(OAuthConstants.TIMESTAMP, api.getTimestampService().getTimestampInSeconds()); request.addOAuthParameter(OAuthConstants.NONCE, api.getTimestampService().getNonce()); @@ -77,7 +80,7 @@ private void addOAuthParams(AbstractRequest request, Token token) { config.log("appended additional OAuth parameters: " + MapUtils.toString(request.getOauthParameters())); } - public final Token getAccessToken(Token requestToken, Verifier verifier) { + public final OAuth1AccessToken getAccessToken(OAuth1RequestToken requestToken, Verifier verifier) { final OAuthConfig config = getConfig(); config.log("obtaining access token from " + api.getAccessTokenEndpoint()); final OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint(), this); @@ -95,28 +98,29 @@ public final Token getAccessToken(Token requestToken, Verifier verifier) { * @param callback optional callback * @return Future */ - public final Future getAccessTokenAsync(Token requestToken, Verifier verifier, - OAuthAsyncRequestCallback callback) { + public final Future getAccessTokenAsync(OAuth1RequestToken requestToken, Verifier verifier, + OAuthAsyncRequestCallback callback) { return getAccessTokenAsync(requestToken, verifier, callback, null); } - public final Future getAccessTokenAsync(Token requestToken, Verifier verifier, - OAuthAsyncRequestCallback callback, ProxyServer proxyServer) { + public final Future getAccessTokenAsync(OAuth1RequestToken requestToken, Verifier verifier, + OAuthAsyncRequestCallback callback, ProxyServer proxyServer) { final OAuthConfig config = getConfig(); config.log("async obtaining access token from " + api.getAccessTokenEndpoint()); final OAuthRequestAsync request = new OAuthRequestAsync(api.getAccessTokenVerb(), api.getAccessTokenEndpoint(), this); prepareAccessTokenRequest(request, requestToken, verifier); - return request.sendAsync(callback, new OAuthRequestAsync.ResponseConverter() { + return request.sendAsync(callback, new OAuthRequestAsync.ResponseConverter() { @Override - public Token convert(com.ning.http.client.Response response) throws IOException { + public OAuth1AccessToken convert(com.ning.http.client.Response response) throws IOException { return getApi().getAccessTokenExtractor() .extract(OAuthRequestAsync.RESPONSE_CONVERTER.convert(response).getBody()); } }, proxyServer); } - protected void prepareAccessTokenRequest(AbstractRequest request, Token requestToken, Verifier verifier) { + protected void prepareAccessTokenRequest(AbstractRequest request, OAuth1RequestToken requestToken, + Verifier verifier) { final OAuthConfig config = getConfig(); request.addOAuthParameter(OAuthConstants.TOKEN, requestToken.getToken()); request.addOAuthParameter(OAuthConstants.VERIFIER, verifier.getValue()); @@ -129,7 +133,7 @@ protected void prepareAccessTokenRequest(AbstractRequest request, Token requestT * {@inheritDoc} */ @Override - public void signRequest(Token token, AbstractRequest request) { + public void signRequest(OAuth1AccessToken token, AbstractRequest request) { final OAuthConfig config = getConfig(); config.log("signing request: " + request.getCompleteUrl()); @@ -160,13 +164,13 @@ public String getAuthorizationUrl(Token requestToken) { return api.getAuthorizationUrl(requestToken); } - private String getSignature(AbstractRequest request, Token token) { + private String getSignature(AbstractRequest request, OAuth1Token token) { final OAuthConfig config = getConfig(); config.log("generating signature..."); config.log("using base64 encoder: " + Base64Encoder.type()); final String baseString = api.getBaseStringExtractor().extract(request); - final String signature = api.getSignatureService().getSignature(baseString, config.getApiSecret(), token. - getSecret()); + final String signature = api.getSignatureService() + .getSignature(baseString, config.getApiSecret(), token.getSecret()); config.log("base string is: " + baseString); config.log("signature is: " + signature); diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java index 8196ee643..e0d7cfcc7 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 @@ -5,16 +5,16 @@ import java.util.concurrent.Future; import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.model.AbstractRequest; +import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthAsyncRequestCallback; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.OAuthRequestAsync; import com.github.scribejava.core.model.Response; -import com.github.scribejava.core.model.Token; import com.github.scribejava.core.model.Verifier; -public class OAuth20Service extends OAuthService { +public class OAuth20Service extends OAuthService { private static final String VERSION = "2.0"; private final DefaultApi20 api; @@ -30,7 +30,7 @@ public OAuth20Service(DefaultApi20 api, OAuthConfig config) { this.api = api; } - public final Token getAccessToken(Verifier verifier) { + public final OAuth2AccessToken getAccessToken(Verifier verifier) { final Response response = createAccessTokenRequest(verifier, new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint(), this)).send(); return api.getAccessTokenExtractor().extract(response.getBody()); @@ -44,17 +44,18 @@ public final Token getAccessToken(Verifier verifier) { * @param callback optional callback * @return Future */ - public final Future getAccessTokenAsync(Verifier verifier, OAuthAsyncRequestCallback callback) { + public final Future getAccessTokenAsync(Verifier verifier, + OAuthAsyncRequestCallback callback) { return getAccessTokenAsync(verifier, callback, null); } - public final Future getAccessTokenAsync(Verifier verifier, OAuthAsyncRequestCallback callback, - ProxyServer proxyServer) { + public final Future getAccessTokenAsync(Verifier verifier, + OAuthAsyncRequestCallback callback, ProxyServer proxyServer) { final OAuthRequestAsync request = createAccessTokenRequest(verifier, new OAuthRequestAsync(api.getAccessTokenVerb(), api.getAccessTokenEndpoint(), this)); - return request.sendAsync(callback, new OAuthRequestAsync.ResponseConverter() { + return request.sendAsync(callback, new OAuthRequestAsync.ResponseConverter() { @Override - public Token convert(com.ning.http.client.Response response) throws IOException { + public OAuth2AccessToken convert(com.ning.http.client.Response response) throws IOException { return getApi().getAccessTokenExtractor() .extract(OAuthRequestAsync.RESPONSE_CONVERTER.convert(response).getBody()); } @@ -88,7 +89,7 @@ public String getVersion() { * {@inheritDoc} */ @Override - public void signRequest(Token accessToken, AbstractRequest request) { + public void signRequest(OAuth2AccessToken accessToken, AbstractRequest request) { request.addQuerystringParameter(OAuthConstants.ACCESS_TOKEN, accessToken.getToken()); } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java index 92fe7840b..c6d94cb8f 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java @@ -16,7 +16,7 @@ * * @author Pablo Fernandez */ -public abstract class OAuthService { +public abstract class OAuthService { private final OAuthConfig config; private AsyncHttpClient asyncHttpClient; @@ -65,7 +65,7 @@ public OAuthConfig getConfig() { * @param accessToken access token (obtained previously) * @param request request to sign */ - public abstract void signRequest(Token accessToken, AbstractRequest request); + public abstract void signRequest(T accessToken, AbstractRequest request); /** * Returns the OAuth version of the service. diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/extractors/JsonTokenExtractorTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/extractors/JsonTokenExtractorTest.java index 743d0fa69..826377e85 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/extractors/JsonTokenExtractorTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/extractors/JsonTokenExtractorTest.java @@ -7,7 +7,7 @@ public class JsonTokenExtractorTest { private static final String RESPONSE = "'{ \"access_token\":\"I0122HHJKLEM21F3WLPYHDKGKZULAUO4SGMV3ABKFTDT3T3X\"}'"; - private final JsonTokenExtractor extractor = new JsonTokenExtractor(); + private final OAuth2AccessTokenJsonExtractor extractor = OAuth2AccessTokenJsonExtractor.instance(); @Test public void shouldParseResponse() { diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/extractors/TokenExtractorTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/extractors/OAuth1AccessTokenExtractorTest.java similarity index 82% rename from scribejava-core/src/test/java/com/github/scribejava/core/extractors/TokenExtractorTest.java rename to scribejava-core/src/test/java/com/github/scribejava/core/extractors/OAuth1AccessTokenExtractorTest.java index 2d97b039e..4550d6706 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/extractors/TokenExtractorTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/extractors/OAuth1AccessTokenExtractorTest.java @@ -1,24 +1,24 @@ package com.github.scribejava.core.extractors; -import static org.junit.Assert.assertEquals; import org.junit.Before; import org.junit.Test; import com.github.scribejava.core.exceptions.OAuthException; -import com.github.scribejava.core.model.Token; +import com.github.scribejava.core.model.OAuth1Token; +import static org.junit.Assert.assertEquals; -public class TokenExtractorTest { +public class OAuth1AccessTokenExtractorTest { - private TokenExtractorImpl extractor; + private OAuth1AccessTokenExtractor extractor; @Before public void setUp() { - extractor = new TokenExtractorImpl(); + extractor = OAuth1AccessTokenExtractor.instance(); } @Test public void shouldExtractTokenFromOAuthStandardResponse() { final String response = "oauth_token=hh5s93j4hdidpola&oauth_token_secret=hdhd0244k9j7ao03"; - final Token extracted = extractor.extract(response); + final OAuth1Token extracted = extractor.extract(response); assertEquals("hh5s93j4hdidpola", extracted.getToken()); assertEquals("hdhd0244k9j7ao03", extracted.getSecret()); } @@ -26,7 +26,7 @@ public void shouldExtractTokenFromOAuthStandardResponse() { @Test public void shouldExtractTokenFromInvertedOAuthStandardResponse() { final String response = "oauth_token_secret=hh5s93j4hdidpola&oauth_token=hdhd0244k9j7ao03"; - final Token extracted = extractor.extract(response); + final OAuth1Token extracted = extractor.extract(response); assertEquals("hh5s93j4hdidpola", extracted.getSecret()); assertEquals("hdhd0244k9j7ao03", extracted.getToken()); } @@ -35,7 +35,7 @@ public void shouldExtractTokenFromInvertedOAuthStandardResponse() { public void shouldExtractTokenFromResponseWithCallbackConfirmed() { final String response = "oauth_token=hh5s93j4hdidpola&oauth_token_secret=hdhd0244k9j7ao03" + "&callback_confirmed=true"; - final Token extracted = extractor.extract(response); + final OAuth1Token extracted = extractor.extract(response); assertEquals("hh5s93j4hdidpola", extracted.getToken()); assertEquals("hdhd0244k9j7ao03", extracted.getSecret()); } @@ -43,7 +43,7 @@ public void shouldExtractTokenFromResponseWithCallbackConfirmed() { @Test public void shouldExtractTokenWithEmptySecret() { final String response = "oauth_token=hh5s93j4hdidpola&oauth_token_secret="; - final Token extracted = extractor.extract(response); + final OAuth1Token extracted = extractor.extract(response); assertEquals("hh5s93j4hdidpola", extracted.getToken()); assertEquals("", extracted.getSecret()); } diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/extractors/TokenExtractor20Test.java b/scribejava-core/src/test/java/com/github/scribejava/core/extractors/OAuth2AccessTokenExtractorTest.java similarity index 88% rename from scribejava-core/src/test/java/com/github/scribejava/core/extractors/TokenExtractor20Test.java rename to scribejava-core/src/test/java/com/github/scribejava/core/extractors/OAuth2AccessTokenExtractorTest.java index a3930979c..3963309fa 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/extractors/TokenExtractor20Test.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/extractors/OAuth2AccessTokenExtractorTest.java @@ -1,18 +1,18 @@ package com.github.scribejava.core.extractors; -import static org.junit.Assert.assertEquals; import org.junit.Before; import org.junit.Test; import com.github.scribejava.core.exceptions.OAuthException; import com.github.scribejava.core.model.Token; +import static org.junit.Assert.assertEquals; -public class TokenExtractor20Test { +public class OAuth2AccessTokenExtractorTest { - private TokenExtractor20Impl extractor; + private OAuth2AccessTokenExtractor extractor; @Before public void setUp() { - extractor = new TokenExtractor20Impl(); + extractor = OAuth2AccessTokenExtractor.instance(); } @Test @@ -22,7 +22,6 @@ public void shouldExtractTokenFromOAuthStandardResponse() { final Token extracted = extractor.extract(response); assertEquals("166942940015970|2.2ltzWXYNDjCtg5ZDVVJJeg__.3600.1295816400-548517159|RsXNdKrpxg8L6QNLWcs2TVTmcaE", extracted.getToken()); - assertEquals("", extracted.getSecret()); } @Test @@ -32,7 +31,6 @@ public void shouldExtractTokenFromResponseWithExpiresParam() { final Token extracted = extractor.extract(response); assertEquals("166942940015970|2.2ltzWXYNDjCtg5ZDVVJJeg__.3600.1295816400-548517159|RsXNdKrpxg8L6QNLWcs2TVTmcaE", extracted.getToken()); - assertEquals("", extracted.getSecret()); } @Test @@ -40,7 +38,6 @@ public void shouldExtractTokenFromResponseWithManyParameters() { final String response = "access_token=foo1234&other_stuff=yeah_we_have_this_too&number=42"; final Token extracted = extractor.extract(response); assertEquals("foo1234", extracted.getToken()); - assertEquals("", extracted.getSecret()); } @Test(expected = OAuthException.class) diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/model/TokenTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/model/TokenTest.java index 727b91b78..7c988ae7b 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/model/TokenTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/model/TokenTest.java @@ -8,8 +8,8 @@ public class TokenTest { @Test public void shouldTestEqualityBasedOnTokenAndSecret() { - final Token expected = new Token("access", "secret"); - final Token actual = new Token("access", "secret"); + final Token expected = new OAuth1AccessToken("access", "secret"); + final Token actual = new OAuth1AccessToken("access", "secret"); assertEquals(expected, actual); assertEquals(actual, actual); @@ -17,23 +17,23 @@ public void shouldTestEqualityBasedOnTokenAndSecret() { @Test public void shouldNotDependOnRawString() { - final Token expected = new Token("access", "secret", "raw_string"); - final Token actual = new Token("access", "secret", "different_raw_string"); + final Token expected = new OAuth1AccessToken("access", "secret", "raw_string"); + final Token actual = new OAuth1AccessToken("access", "secret", "different_raw_string"); assertEquals(expected, actual); } @Test public void shouldReturnSameHashCodeForEqualObjects() { - final Token expected = new Token("access", "secret"); - final Token actual = new Token("access", "secret"); + final Token expected = new OAuth1AccessToken("access", "secret"); + final Token actual = new OAuth1AccessToken("access", "secret"); assertEquals(expected.hashCode(), actual.hashCode()); } @Test public void shouldNotBeEqualToNullOrOtherObjects() { - final Token expected = new Token("access", "secret", "response"); + final Token expected = new OAuth1AccessToken("access", "secret", "response"); assertNotSame(expected, null); assertNotSame(expected, new Object()); @@ -41,7 +41,8 @@ public void shouldNotBeEqualToNullOrOtherObjects() { @Test public void shouldReturnUrlParam() { - final Token actual = new Token("acccess", "secret", "user_id=3107154759&screen_name=someuser&empty=&="); + final Token actual = new OAuth1AccessToken("acccess", "secret", + "user_id=3107154759&screen_name=someuser&empty=&="); assertEquals("someuser", actual.getParameter("screen_name")); assertEquals("3107154759", actual.getParameter("user_id")); assertEquals(null, actual.getParameter("empty")); From 6eac7da83a4816190d9da389e7f5e8e16a4dec73 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 17 Feb 2016 19:05:33 +0300 Subject: [PATCH 131/882] fix small error in javadoc --- .../core/extractors/AbstractOAuth1TokenExtractor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/AbstractOAuth1TokenExtractor.java b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/AbstractOAuth1TokenExtractor.java index 8609320c6..a1b4b0d46 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/AbstractOAuth1TokenExtractor.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/AbstractOAuth1TokenExtractor.java @@ -8,7 +8,7 @@ import com.github.scribejava.core.utils.Preconditions; /** - * Default implementation of {@link TokenExtractor} for OAuth 1.0a + * Abstract base implementation of {@link TokenExtractor} for OAuth 1.0a * * The process for extracting access and request tokens is similar so this class can do both things. * From bd2d84ffdd7dc24ea4d482dd3e12026d2d775383 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 17 Feb 2016 20:34:45 +0300 Subject: [PATCH 132/882] remove unused and unneeded interface API --- .../scribejava/core/builder/api/Api.java | 20 ------------------- .../core/builder/api/DefaultApi10a.java | 3 +-- .../core/builder/api/DefaultApi20.java | 6 +----- 3 files changed, 2 insertions(+), 27 deletions(-) delete mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/builder/api/Api.java diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/Api.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/Api.java deleted file mode 100644 index 0c7c53ad7..000000000 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/Api.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.github.scribejava.core.builder.api; - -import com.github.scribejava.core.model.OAuthConfig; -import com.github.scribejava.core.oauth.OAuthService; - -/** - * Contains all the configuration needed to instantiate a valid {@link OAuthService} - * - * @author Pablo Fernandez - * - */ -public interface Api { - - /** - * - * @param config config to build the Service from - * @return fully configured {@link OAuthService} - */ - OAuthService createService(OAuthConfig config); -} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi10a.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi10a.java index 63267dc1d..ba8959de8 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi10a.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi10a.java @@ -33,7 +33,7 @@ * @author Pablo Fernandez * */ -public abstract class DefaultApi10a implements Api { +public abstract class DefaultApi10a { /** * Returns the access token extractor. @@ -129,7 +129,6 @@ public Verb getRequestTokenVerb() { */ public abstract String getAuthorizationUrl(Token requestToken); - @Override public OAuth10aService createService(OAuthConfig config) { return new OAuth10aService(this, config); } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java index 9bdb552a0..b9869c2d7 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java @@ -22,7 +22,7 @@ * @author Diego Silveira * */ -public abstract class DefaultApi20 implements Api { +public abstract class DefaultApi20 { /** * Returns the access token extractor. @@ -57,10 +57,6 @@ public Verb getAccessTokenVerb() { */ public abstract String getAuthorizationUrl(OAuthConfig config); - /** - * {@inheritDoc} - */ - @Override public OAuth20Service createService(OAuthConfig config) { return new OAuth20Service(this, config); } From b2816d8ce8f3ca93b36a2f6ea3c88059b25f9d07 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 18 Feb 2016 19:19:39 +0300 Subject: [PATCH 133/882] optimize pom.xml (remove duplicate declarations from child poms) --- scribejava-apis/pom.xml | 13 ------------- scribejava-core/pom.xml | 12 ------------ 2 files changed, 25 deletions(-) diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 1aabba2bb..f661a6b4c 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -14,19 +14,6 @@ ScribeJava APIs jar - - - - org.apache.maven.plugins - maven-resources-plugin - 2.7 - - UTF-8 - - - - - com.github.scribejava diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index b9ab0e6d4..08aa2ce57 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -14,16 +14,4 @@ ScribeJava Core jar - - - - org.apache.maven.plugins - maven-resources-plugin - 2.7 - - UTF-8 - - - - From 185e53f76edb89ce8b0c6cf86cf87dc9f00e95cc Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 19 Feb 2016 12:35:09 +0300 Subject: [PATCH 134/882] getAuthorizationUrl for OAuth1 should force to take OAuth1RequestToken --- .../src/main/java/com/github/scribejava/apis/AWeberApi.java | 4 ++-- .../java/com/github/scribejava/apis/ConstantContactApi.java | 4 ++-- .../src/main/java/com/github/scribejava/apis/DiggApi.java | 4 ++-- .../main/java/com/github/scribejava/apis/DropBoxApi.java | 4 ++-- .../main/java/com/github/scribejava/apis/EvernoteApi.java | 4 ++-- .../src/main/java/com/github/scribejava/apis/FlickrApi.java | 4 ++-- .../main/java/com/github/scribejava/apis/FoursquareApi.java | 4 ++-- .../main/java/com/github/scribejava/apis/FreelancerApi.java | 6 +++--- .../main/java/com/github/scribejava/apis/GetGlueApi.java | 4 ++-- .../src/main/java/com/github/scribejava/apis/GoogleApi.java | 4 ++-- .../src/main/java/com/github/scribejava/apis/KaixinApi.java | 4 ++-- .../main/java/com/github/scribejava/apis/LinkedInApi.java | 4 ++-- .../main/java/com/github/scribejava/apis/LoveFilmApi.java | 4 ++-- .../src/main/java/com/github/scribejava/apis/MeetupApi.java | 4 ++-- .../main/java/com/github/scribejava/apis/MendeleyApi.java | 4 ++-- .../src/main/java/com/github/scribejava/apis/MisoApi.java | 4 ++-- .../main/java/com/github/scribejava/apis/NetProspexApi.java | 4 ++-- .../java/com/github/scribejava/apis/NeteaseWeibooApi.java | 3 ++- .../src/main/java/com/github/scribejava/apis/PlurkApi.java | 6 +++--- .../src/main/java/com/github/scribejava/apis/Px500Api.java | 4 ++-- .../src/main/java/com/github/scribejava/apis/QWeiboApi.java | 4 ++-- .../src/main/java/com/github/scribejava/apis/SapoApi.java | 4 ++-- .../main/java/com/github/scribejava/apis/SimpleGeoApi.java | 4 ++-- .../main/java/com/github/scribejava/apis/SinaWeiboApi.java | 4 ++-- .../main/java/com/github/scribejava/apis/SkyrockApi.java | 4 ++-- .../main/java/com/github/scribejava/apis/SohuWeiboApi.java | 4 ++-- .../src/main/java/com/github/scribejava/apis/TrelloApi.java | 4 ++-- .../src/main/java/com/github/scribejava/apis/TumblrApi.java | 4 ++-- .../main/java/com/github/scribejava/apis/TwitterApi.java | 6 +++--- .../main/java/com/github/scribejava/apis/UbuntuOneApi.java | 4 ++-- .../src/main/java/com/github/scribejava/apis/VimeoApi.java | 4 ++-- .../src/main/java/com/github/scribejava/apis/XingApi.java | 4 ++-- .../src/main/java/com/github/scribejava/apis/YahooApi.java | 4 ++-- .../src/main/java/com/github/scribejava/apis/YammerApi.java | 4 ++-- .../github/scribejava/core/builder/api/DefaultApi10a.java | 3 +-- .../com/github/scribejava/core/oauth/OAuth10aService.java | 3 +-- 36 files changed, 73 insertions(+), 74 deletions(-) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/AWeberApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/AWeberApi.java index d35d58031..fe5d86691 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/AWeberApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/AWeberApi.java @@ -1,7 +1,7 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi10a; -import com.github.scribejava.core.model.Token; +import com.github.scribejava.core.model.OAuth1RequestToken; public class AWeberApi extends DefaultApi10a { @@ -31,7 +31,7 @@ public String getRequestTokenEndpoint() { } @Override - public String getAuthorizationUrl(Token requestToken) { + public String getAuthorizationUrl(OAuth1RequestToken requestToken) { return String.format(AUTHORIZE_URL, requestToken.getToken()); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/ConstantContactApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/ConstantContactApi.java index 102e2bda9..a9f0e196c 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/ConstantContactApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/ConstantContactApi.java @@ -1,7 +1,7 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi10a; -import com.github.scribejava.core.model.Token; +import com.github.scribejava.core.model.OAuth1RequestToken; public class ConstantContactApi extends DefaultApi10a { @@ -25,7 +25,7 @@ public String getAccessTokenEndpoint() { } @Override - public String getAuthorizationUrl(Token requestToken) { + public String getAuthorizationUrl(OAuth1RequestToken requestToken) { return String.format(AUTHORIZE_URL, requestToken.getToken()); } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/DiggApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/DiggApi.java index f5d71d7dd..047537d8a 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/DiggApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/DiggApi.java @@ -1,7 +1,7 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi10a; -import com.github.scribejava.core.model.Token; +import com.github.scribejava.core.model.OAuth1RequestToken; public class DiggApi extends DefaultApi10a { @@ -30,7 +30,7 @@ public String getAccessTokenEndpoint() { } @Override - public String getAuthorizationUrl(Token requestToken) { + public String getAuthorizationUrl(OAuth1RequestToken requestToken) { return String.format(AUTHORIZATION_URL, requestToken.getToken()); } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/DropBoxApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/DropBoxApi.java index 1f7d23112..99ae6f874 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/DropBoxApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/DropBoxApi.java @@ -1,7 +1,7 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi10a; -import com.github.scribejava.core.model.Token; +import com.github.scribejava.core.model.OAuth1RequestToken; public class DropBoxApi extends DefaultApi10a { @@ -22,7 +22,7 @@ public String getAccessTokenEndpoint() { } @Override - public String getAuthorizationUrl(Token requestToken) { + public String getAuthorizationUrl(OAuth1RequestToken requestToken) { return "https://www.dropbox.com/1/oauth/authorize?oauth_token=" + requestToken.getToken(); } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/EvernoteApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/EvernoteApi.java index e8b6ac206..0bbd2ac62 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/EvernoteApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/EvernoteApi.java @@ -1,7 +1,7 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi10a; -import com.github.scribejava.core.model.Token; +import com.github.scribejava.core.model.OAuth1RequestToken; public class EvernoteApi extends DefaultApi10a { @@ -31,7 +31,7 @@ public String getAccessTokenEndpoint() { } @Override - public String getAuthorizationUrl(Token requestToken) { + public String getAuthorizationUrl(OAuth1RequestToken requestToken) { return String.format(serviceUrl() + "/OAuth.action?oauth_token=%s", requestToken.getToken()); } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/FlickrApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/FlickrApi.java index 3904b78c3..9b5521e28 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/FlickrApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/FlickrApi.java @@ -1,7 +1,7 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi10a; -import com.github.scribejava.core.model.Token; +import com.github.scribejava.core.model.OAuth1RequestToken; /** * OAuth API for Flickr. @@ -34,7 +34,7 @@ public String getAccessTokenEndpoint() { * {@inheritDoc} */ @Override - public String getAuthorizationUrl(Token requestToken) { + public String getAuthorizationUrl(OAuth1RequestToken requestToken) { return "https://www.flickr.com/services/oauth/authorize?oauth_token=" + requestToken.getToken(); } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/FoursquareApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/FoursquareApi.java index 6cb9a3833..69111d235 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/FoursquareApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/FoursquareApi.java @@ -1,7 +1,7 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi10a; -import com.github.scribejava.core.model.Token; +import com.github.scribejava.core.model.OAuth1RequestToken; public class FoursquareApi extends DefaultApi10a { @@ -29,7 +29,7 @@ public String getRequestTokenEndpoint() { } @Override - public String getAuthorizationUrl(Token requestToken) { + public String getAuthorizationUrl(OAuth1RequestToken requestToken) { return String.format(AUTHORIZATION_URL, requestToken.getToken()); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/FreelancerApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/FreelancerApi.java index 3247e1e08..52fe4cc1f 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/FreelancerApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/FreelancerApi.java @@ -1,7 +1,7 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi10a; -import com.github.scribejava.core.model.Token; +import com.github.scribejava.core.model.OAuth1RequestToken; import com.github.scribejava.core.model.Verb; public class FreelancerApi extends DefaultApi10a { @@ -40,7 +40,7 @@ public Verb getRequestTokenVerb() { } @Override - public String getAuthorizationUrl(Token requestToken) { + public String getAuthorizationUrl(OAuth1RequestToken requestToken) { return String.format(AUTHORIZATION_URL, requestToken.getToken()); } @@ -71,7 +71,7 @@ public String getAccessTokenEndpoint() { } @Override - public String getAuthorizationUrl(Token requestToken) { + public String getAuthorizationUrl(OAuth1RequestToken requestToken) { return String.format(SANDBOX_AUTHORIZATION_URL + "?oauth_token=%s", requestToken.getToken()); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/GetGlueApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/GetGlueApi.java index 1983fd871..758214390 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/GetGlueApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/GetGlueApi.java @@ -1,7 +1,7 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi10a; -import com.github.scribejava.core.model.Token; +import com.github.scribejava.core.model.OAuth1RequestToken; public class GetGlueApi extends DefaultApi10a { @@ -31,7 +31,7 @@ public String getRequestTokenEndpoint() { } @Override - public String getAuthorizationUrl(Token requestToken) { + public String getAuthorizationUrl(OAuth1RequestToken requestToken) { return String.format(AUTHORIZE_URL, requestToken.getToken()); } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/GoogleApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/GoogleApi.java index a7326a9d1..af8448385 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/GoogleApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/GoogleApi.java @@ -1,7 +1,7 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi10a; -import com.github.scribejava.core.model.Token; +import com.github.scribejava.core.model.OAuth1RequestToken; import com.github.scribejava.core.model.Verb; public class GoogleApi extends DefaultApi10a { @@ -41,7 +41,7 @@ public Verb getRequestTokenVerb() { } @Override - public String getAuthorizationUrl(Token requestToken) { + public String getAuthorizationUrl(OAuth1RequestToken requestToken) { return String.format(AUTHORIZATION_URL, requestToken.getToken()); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/KaixinApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/KaixinApi.java index 2678364a7..e5698bdb6 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/KaixinApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/KaixinApi.java @@ -1,7 +1,7 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi10a; -import com.github.scribejava.core.model.Token; +import com.github.scribejava.core.model.OAuth1RequestToken; import com.github.scribejava.core.model.Verb; public class KaixinApi extends DefaultApi10a { @@ -32,7 +32,7 @@ public String getAccessTokenEndpoint() { } @Override - public String getAuthorizationUrl(Token requestToken) { + public String getAuthorizationUrl(OAuth1RequestToken requestToken) { return String.format(AUTHORIZE_URL, requestToken.getToken()); } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi.java index 2069aade0..2d876ec5f 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi.java @@ -1,7 +1,7 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi10a; -import com.github.scribejava.core.model.Token; +import com.github.scribejava.core.model.OAuth1RequestToken; public class LinkedInApi extends DefaultApi10a { @@ -46,7 +46,7 @@ public String getRequestTokenEndpoint() { } @Override - public String getAuthorizationUrl(Token requestToken) { + public String getAuthorizationUrl(OAuth1RequestToken requestToken) { return String.format(AUTHORIZE_URL, requestToken.getToken()); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/LoveFilmApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/LoveFilmApi.java index e5cfbf742..3c43ac309 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/LoveFilmApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/LoveFilmApi.java @@ -1,7 +1,7 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi10a; -import com.github.scribejava.core.model.Token; +import com.github.scribejava.core.model.OAuth1RequestToken; public class LoveFilmApi extends DefaultApi10a { @@ -31,7 +31,7 @@ public String getAccessTokenEndpoint() { } @Override - public String getAuthorizationUrl(Token requestToken) { + public String getAuthorizationUrl(OAuth1RequestToken requestToken) { return String.format(AUTHORIZE_URL, requestToken.getToken()); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/MeetupApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/MeetupApi.java index f4a0d112d..b00db6159 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/MeetupApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/MeetupApi.java @@ -1,7 +1,7 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi10a; -import com.github.scribejava.core.model.Token; +import com.github.scribejava.core.model.OAuth1RequestToken; /** * OAuth access to the Meetup.com API. For more information visit http://www.meetup.com/api @@ -32,7 +32,7 @@ public String getAccessTokenEndpoint() { } @Override - public String getAuthorizationUrl(Token requestToken) { + public String getAuthorizationUrl(OAuth1RequestToken requestToken) { return String.format(AUTHORIZE_URL, requestToken.getToken()); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/MendeleyApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/MendeleyApi.java index 528243c51..89bf98e56 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/MendeleyApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/MendeleyApi.java @@ -1,7 +1,7 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi10a; -import com.github.scribejava.core.model.Token; +import com.github.scribejava.core.model.OAuth1RequestToken; import com.github.scribejava.core.model.Verb; /** @@ -34,7 +34,7 @@ public String getAccessTokenEndpoint() { } @Override - public String getAuthorizationUrl(Token requestToken) { + public String getAuthorizationUrl(OAuth1RequestToken requestToken) { return String.format(AUTHORIZATION_URL, requestToken.getToken()); } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/MisoApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/MisoApi.java index 35eaba078..4f0bb3bea 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/MisoApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/MisoApi.java @@ -1,7 +1,7 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi10a; -import com.github.scribejava.core.model.Token; +import com.github.scribejava.core.model.OAuth1RequestToken; public class MisoApi extends DefaultApi10a { @@ -31,7 +31,7 @@ public String getRequestTokenEndpoint() { } @Override - public String getAuthorizationUrl(Token requestToken) { + public String getAuthorizationUrl(OAuth1RequestToken requestToken) { return String.format(AUTHORIZE_URL, requestToken.getToken()); } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/NetProspexApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/NetProspexApi.java index e14291120..aa08abc4a 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/NetProspexApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/NetProspexApi.java @@ -1,7 +1,7 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi10a; -import com.github.scribejava.core.model.Token; +import com.github.scribejava.core.model.OAuth1RequestToken; public class NetProspexApi extends DefaultApi10a { @@ -31,7 +31,7 @@ public String getAccessTokenEndpoint() { } @Override - public String getAuthorizationUrl(Token requestToken) { + public String getAuthorizationUrl(OAuth1RequestToken requestToken) { return String.format(AUTHORIZE_URL, requestToken.getToken()); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/NeteaseWeibooApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/NeteaseWeibooApi.java index 132d4e034..dd97841fc 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/NeteaseWeibooApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/NeteaseWeibooApi.java @@ -1,6 +1,7 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi10a; +import com.github.scribejava.core.model.OAuth1RequestToken; import com.github.scribejava.core.model.Token; public class NeteaseWeibooApi extends DefaultApi10a { @@ -39,7 +40,7 @@ public String getAccessTokenEndpoint() { * via * http://open.t.163.com/wiki/index.php?title=%E8%AF%B7%E6%B1%82%E7%94%A8%E6%88%B7%E6%8E%88%E6%9D%83Token(oauth/authorize) */ - public String getAuthorizationUrl(Token requestToken) { + public String getAuthorizationUrl(OAuth1RequestToken requestToken) { return String.format(AUTHORIZE_URL, requestToken.getToken()); } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/PlurkApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/PlurkApi.java index 4d120f2a5..f2b9c5ed2 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/PlurkApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/PlurkApi.java @@ -1,7 +1,7 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi10a; -import com.github.scribejava.core.model.Token; +import com.github.scribejava.core.model.OAuth1RequestToken; public class PlurkApi extends DefaultApi10a { @@ -26,7 +26,7 @@ public String getRequestTokenEndpoint() { } @Override - public String getAuthorizationUrl(Token requestToken) { + public String getAuthorizationUrl(OAuth1RequestToken requestToken) { return String.format(AUTHORIZATION_URL, requestToken.getToken()); } @@ -51,7 +51,7 @@ public static Mobile instance() { } @Override - public String getAuthorizationUrl(Token requestToken) { + public String getAuthorizationUrl(OAuth1RequestToken requestToken) { return String.format(AUTHORIZATION_URL, requestToken.getToken()); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/Px500Api.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/Px500Api.java index 0c7d41abe..2c4e6de3c 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/Px500Api.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/Px500Api.java @@ -1,7 +1,7 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi10a; -import com.github.scribejava.core.model.Token; +import com.github.scribejava.core.model.OAuth1RequestToken; public class Px500Api extends DefaultApi10a { @@ -29,7 +29,7 @@ public String getRequestTokenEndpoint() { } @Override - public String getAuthorizationUrl(Token requestToken) { + public String getAuthorizationUrl(OAuth1RequestToken requestToken) { return String.format(AUTHORIZATION_URL, requestToken.getToken()); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/QWeiboApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/QWeiboApi.java index e6dfd00c7..ed4bfdb6b 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/QWeiboApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/QWeiboApi.java @@ -1,7 +1,7 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi10a; -import com.github.scribejava.core.model.Token; +import com.github.scribejava.core.model.OAuth1RequestToken; public class QWeiboApi extends DefaultApi10a { @@ -31,7 +31,7 @@ public String getAccessTokenEndpoint() { } @Override - public String getAuthorizationUrl(Token requestToken) { + public String getAuthorizationUrl(OAuth1RequestToken requestToken) { return String.format(AUTHORIZE_URL, requestToken.getToken()); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/SapoApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/SapoApi.java index 99a087fac..524ddfcf7 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/SapoApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/SapoApi.java @@ -1,7 +1,7 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi10a; -import com.github.scribejava.core.model.Token; +import com.github.scribejava.core.model.OAuth1RequestToken; import com.github.scribejava.core.model.Verb; public class SapoApi extends DefaultApi10a { @@ -32,7 +32,7 @@ public String getRequestTokenEndpoint() { } @Override - public String getAuthorizationUrl(Token requestToken) { + public String getAuthorizationUrl(OAuth1RequestToken requestToken) { return String.format(AUTHORIZE_URL, requestToken.getToken()); } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/SimpleGeoApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/SimpleGeoApi.java index aa9250b5d..65df4bf76 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/SimpleGeoApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/SimpleGeoApi.java @@ -1,7 +1,7 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi10a; -import com.github.scribejava.core.model.Token; +import com.github.scribejava.core.model.OAuth1RequestToken; /** * @author Pablo Fernandez @@ -32,7 +32,7 @@ public String getAccessTokenEndpoint() { } @Override - public String getAuthorizationUrl(Token requestToken) { + public String getAuthorizationUrl(OAuth1RequestToken requestToken) { return ENDPOINT; } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/SinaWeiboApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/SinaWeiboApi.java index 6bb5f2e64..b91108c18 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/SinaWeiboApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/SinaWeiboApi.java @@ -1,7 +1,7 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi10a; -import com.github.scribejava.core.model.Token; +import com.github.scribejava.core.model.OAuth1RequestToken; public class SinaWeiboApi extends DefaultApi10a { @@ -31,7 +31,7 @@ public String getAccessTokenEndpoint() { } @Override - public String getAuthorizationUrl(Token requestToken) { + public String getAuthorizationUrl(OAuth1RequestToken requestToken) { return String.format(AUTHORIZE_URL, requestToken.getToken()); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/SkyrockApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/SkyrockApi.java index 9f1547c31..ad8157ccd 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/SkyrockApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/SkyrockApi.java @@ -1,7 +1,7 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi10a; -import com.github.scribejava.core.model.Token; +import com.github.scribejava.core.model.OAuth1RequestToken; /** * OAuth API for Skyrock. @@ -38,7 +38,7 @@ public String getRequestTokenEndpoint() { } @Override - public String getAuthorizationUrl(Token requestToken) { + public String getAuthorizationUrl(OAuth1RequestToken requestToken) { return String.format(API_ENDPOINT + AUTHORIZE_URL, requestToken.getToken()); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/SohuWeiboApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/SohuWeiboApi.java index 688b28a4d..6ef769c6a 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/SohuWeiboApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/SohuWeiboApi.java @@ -1,7 +1,7 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi10a; -import com.github.scribejava.core.model.Token; +import com.github.scribejava.core.model.OAuth1RequestToken; public class SohuWeiboApi extends DefaultApi10a { @@ -31,7 +31,7 @@ public String getAccessTokenEndpoint() { } @Override - public String getAuthorizationUrl(Token requestToken) { + public String getAuthorizationUrl(OAuth1RequestToken requestToken) { return String.format(AUTHORIZE_URL, requestToken.getToken()); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/TrelloApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/TrelloApi.java index c00771950..8fd95f7a2 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/TrelloApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/TrelloApi.java @@ -1,7 +1,7 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi10a; -import com.github.scribejava.core.model.Token; +import com.github.scribejava.core.model.OAuth1RequestToken; public class TrelloApi extends DefaultApi10a { @@ -29,7 +29,7 @@ public String getRequestTokenEndpoint() { } @Override - public String getAuthorizationUrl(Token requestToken) { + public String getAuthorizationUrl(OAuth1RequestToken requestToken) { return String.format(AUTHORIZE_URL, requestToken.getToken()); } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/TumblrApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/TumblrApi.java index dca910d2d..1d7a9e93f 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/TumblrApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/TumblrApi.java @@ -1,7 +1,7 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi10a; -import com.github.scribejava.core.model.Token; +import com.github.scribejava.core.model.OAuth1RequestToken; public class TumblrApi extends DefaultApi10a { @@ -31,7 +31,7 @@ public String getRequestTokenEndpoint() { } @Override - public String getAuthorizationUrl(Token requestToken) { + public String getAuthorizationUrl(OAuth1RequestToken requestToken) { return String.format(AUTHORIZE_URL, requestToken.getToken()); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/TwitterApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/TwitterApi.java index b730b9c1e..3d8a2aba7 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/TwitterApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/TwitterApi.java @@ -1,7 +1,7 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi10a; -import com.github.scribejava.core.model.Token; +import com.github.scribejava.core.model.OAuth1RequestToken; public class TwitterApi extends DefaultApi10a { @@ -31,7 +31,7 @@ public String getRequestTokenEndpoint() { } @Override - public String getAuthorizationUrl(Token requestToken) { + public String getAuthorizationUrl(OAuth1RequestToken requestToken) { return String.format(AUTHORIZE_URL, requestToken.getToken()); } @@ -56,7 +56,7 @@ public static Authenticate instance() { } @Override - public String getAuthorizationUrl(Token requestToken) { + public String getAuthorizationUrl(OAuth1RequestToken requestToken) { return String.format(AUTHENTICATE_URL, requestToken.getToken()); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/UbuntuOneApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/UbuntuOneApi.java index 45b16d62b..a9ad07e77 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/UbuntuOneApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/UbuntuOneApi.java @@ -1,7 +1,7 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi10a; -import com.github.scribejava.core.model.Token; +import com.github.scribejava.core.model.OAuth1RequestToken; import com.github.scribejava.core.services.PlaintextSignatureService; import com.github.scribejava.core.services.SignatureService; @@ -31,7 +31,7 @@ public String getAccessTokenEndpoint() { } @Override - public String getAuthorizationUrl(Token requestToken) { + public String getAuthorizationUrl(OAuth1RequestToken requestToken) { return String.format(AUTHORIZATION_URL, requestToken.getToken()); } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/VimeoApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/VimeoApi.java index 667557fac..63ecb844d 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/VimeoApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/VimeoApi.java @@ -1,7 +1,7 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi10a; -import com.github.scribejava.core.model.Token; +import com.github.scribejava.core.model.OAuth1RequestToken; public class VimeoApi extends DefaultApi10a { @@ -29,7 +29,7 @@ public String getRequestTokenEndpoint() { } @Override - public String getAuthorizationUrl(Token requestToken) { + public String getAuthorizationUrl(OAuth1RequestToken requestToken) { return String.format(AUTHORIZATION_URL, requestToken.getToken()); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/XingApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/XingApi.java index 5bc34a6d4..5bef0670b 100755 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/XingApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/XingApi.java @@ -1,7 +1,7 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi10a; -import com.github.scribejava.core.model.Token; +import com.github.scribejava.core.model.OAuth1RequestToken; public class XingApi extends DefaultApi10a { @@ -29,7 +29,7 @@ public String getRequestTokenEndpoint() { } @Override - public String getAuthorizationUrl(Token requestToken) { + public String getAuthorizationUrl(OAuth1RequestToken requestToken) { return String.format(AUTHORIZE_URL, requestToken.getToken()); } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/YahooApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/YahooApi.java index 952508143..18352fdb0 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/YahooApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/YahooApi.java @@ -1,7 +1,7 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi10a; -import com.github.scribejava.core.model.Token; +import com.github.scribejava.core.model.OAuth1RequestToken; public class YahooApi extends DefaultApi10a { @@ -29,7 +29,7 @@ public String getRequestTokenEndpoint() { } @Override - public String getAuthorizationUrl(Token requestToken) { + public String getAuthorizationUrl(OAuth1RequestToken requestToken) { return String.format(AUTHORIZE_URL, requestToken.getToken()); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/YammerApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/YammerApi.java index 14a98c0c1..269e61395 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/YammerApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/YammerApi.java @@ -1,7 +1,7 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi10a; -import com.github.scribejava.core.model.Token; +import com.github.scribejava.core.model.OAuth1RequestToken; import com.github.scribejava.core.services.PlaintextSignatureService; import com.github.scribejava.core.services.SignatureService; @@ -31,7 +31,7 @@ public String getAccessTokenEndpoint() { } @Override - public String getAuthorizationUrl(Token requestToken) { + public String getAuthorizationUrl(OAuth1RequestToken requestToken) { return String.format(AUTHORIZATION_URL, requestToken.getToken()); } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi10a.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi10a.java index ba8959de8..71320beec 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi10a.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi10a.java @@ -7,7 +7,6 @@ import com.github.scribejava.core.extractors.OAuth1AccessTokenExtractor; import com.github.scribejava.core.extractors.OAuth1RequestTokenExtractor; import com.github.scribejava.core.model.OAuthConfig; -import com.github.scribejava.core.model.Token; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.oauth.OAuth10aService; import com.github.scribejava.core.services.HMACSha1SignatureService; @@ -127,7 +126,7 @@ public Verb getRequestTokenVerb() { * @param requestToken the request token you need to authorize * @return the URL where you should redirect your users */ - public abstract String getAuthorizationUrl(Token requestToken); + public abstract String getAuthorizationUrl(OAuth1RequestToken requestToken); public OAuth10aService createService(OAuthConfig config) { return new OAuth10aService(this, config); 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 3a2670305..544c8c368 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 @@ -15,7 +15,6 @@ import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.OAuthRequestAsync; import com.github.scribejava.core.model.Response; -import com.github.scribejava.core.model.Token; import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.services.Base64Encoder; import com.github.scribejava.core.utils.MapUtils; @@ -160,7 +159,7 @@ public String getVersion() { * @param requestToken the request token you need to authorize * @return the URL where you should redirect your users */ - public String getAuthorizationUrl(Token requestToken) { + public String getAuthorizationUrl(OAuth1RequestToken requestToken) { return api.getAuthorizationUrl(requestToken); } From d734a4df8d6d1c204e26454b7fefebe295d16c0a Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 19 Feb 2016 18:32:54 +0300 Subject: [PATCH 135/882] make tokens conforms RFCs --- .../scribejava/apis/NeteaseWeibooApi.java | 4 +- .../apis/google/GoogleJsonTokenExtractor.java | 2 +- .../scribejava/apis/google/GoogleToken.java | 57 +++++++- .../DoktornaraboteOAuthServiceImpl.java | 2 +- .../apis/service/GoogleOAuthServiceImpl.java | 2 +- .../apis/service/HHOAuthServiceImpl.java | 2 +- .../apis/service/ImgurOAuthServiceImpl.java | 3 +- .../apis/service/LinkedIn20ServiceImpl.java | 4 +- .../apis/service/MailruOAuthServiceImpl.java | 4 +- .../service/OdnoklassnikiServiceImpl.java | 2 +- .../apis/service/TutByOAuthServiceImpl.java | 3 +- .../apis/examples/Foursquare2Example.java | 2 +- .../apis/examples/LinkedIn20Example.java | 8 +- .../scribejava/apis/examples/LiveExample.java | 2 +- .../apis/examples/MailruAsyncExample.java | 2 +- .../apis/examples/OdnoklassnikiExample.java | 2 + .../apis/examples/PinterestExample.java | 2 +- .../apis/examples/RenrenExample.java | 2 +- .../apis/examples/VkontakteExample.java | 4 +- .../core/model/OAuth1AccessToken.java | 47 +++++- .../core/model/OAuth1RequestToken.java | 69 ++++++++- .../scribejava/core/model/OAuth1Token.java | 68 ++++----- .../core/model/OAuth2AccessToken.java | 134 +++++++++++++++++- .../github/scribejava/core/model/Token.java | 42 +----- .../core/oauth/OAuth10aService.java | 8 +- .../scribejava/core/oauth/OAuth20Service.java | 8 +- .../scribejava/core/oauth/OAuthService.java | 14 +- .../services/RSASha1SignatureService.java | 6 +- .../OAuth1AccessTokenExtractorTest.java | 8 +- .../OAuth2AccessTokenExtractorTest.java | 14 +- ...> OAuth2AccessTokenJsonExtractorTest.java} | 10 +- .../services/RSASha1SignatureServiceTest.java | 4 +- .../core/utils/StreamUtilsTest.java | 18 ++- 33 files changed, 385 insertions(+), 174 deletions(-) rename scribejava-core/src/test/java/com/github/scribejava/core/extractors/{JsonTokenExtractorTest.java => OAuth2AccessTokenJsonExtractorTest.java} (71%) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/NeteaseWeibooApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/NeteaseWeibooApi.java index dd97841fc..317d1e74e 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/NeteaseWeibooApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/NeteaseWeibooApi.java @@ -2,7 +2,7 @@ import com.github.scribejava.core.builder.api.DefaultApi10a; import com.github.scribejava.core.model.OAuth1RequestToken; -import com.github.scribejava.core.model.Token; +import com.github.scribejava.core.model.OAuth1Token; public class NeteaseWeibooApi extends DefaultApi10a { @@ -54,7 +54,7 @@ public String getAuthorizationUrl(OAuth1RequestToken requestToken) { * @param requestToken Token * @return String */ - public String getAuthenticateUrl(Token requestToken) { + public String getAuthenticateUrl(OAuth1Token requestToken) { return String.format(AUTHENTICATE_URL, requestToken.getToken()); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/google/GoogleJsonTokenExtractor.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/google/GoogleJsonTokenExtractor.java index 3a0ae6194..f542026b5 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/google/GoogleJsonTokenExtractor.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/google/GoogleJsonTokenExtractor.java @@ -25,7 +25,7 @@ public static GoogleJsonTokenExtractor instance() { @Override public GoogleToken extract(String response) { - return new GoogleToken(extractAccessToken(response), response, extractOpenIdToken(response)); + return new GoogleToken(extractAccessToken(response), extractOpenIdToken(response), response); } private String extractOpenIdToken(String response) { diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/google/GoogleToken.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/google/GoogleToken.java index e58ec4c63..1afe0b084 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/google/GoogleToken.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/google/GoogleToken.java @@ -1,10 +1,11 @@ package com.github.scribejava.apis.google; import com.github.scribejava.core.model.OAuth2AccessToken; +import java.util.Objects; public class GoogleToken extends OAuth2AccessToken { - private static final long serialVersionUID = 3075266018377678771L; + private static final long serialVersionUID = 6150970703986214220L; /** * Id_token is part of OpenID Connect specification. It can hold user information that you can directly extract @@ -17,8 +18,8 @@ public class GoogleToken extends OAuth2AccessToken { */ private final String openIdToken; - public GoogleToken(String token, String rawResponse, String openIdToken) { - super(token, rawResponse); + public GoogleToken(String accessToken, String openIdToken, String rawResponse) { + super(accessToken, rawResponse); this.openIdToken = openIdToken; } @@ -26,8 +27,56 @@ public String getOpenIdToken() { return openIdToken; } + @Override + public int hashCode() { + int hash = 5; + hash = 37 * hash + Objects.hashCode(getAccessToken()); + hash = 37 * hash + Objects.hashCode(getTokenType()); + hash = 37 * hash + Objects.hashCode(getExpiresIn()); + hash = 37 * hash + Objects.hashCode(getRefreshToken()); + hash = 37 * hash + Objects.hashCode(getScope()); + hash = 37 * hash + Objects.hashCode(openIdToken); + 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 GoogleToken other = (GoogleToken) obj; + if (!Objects.equals(getAccessToken(), other.getAccessToken())) { + return false; + } + if (!Objects.equals(getTokenType(), other.getTokenType())) { + return false; + } + if (!Objects.equals(getRefreshToken(), other.getRefreshToken())) { + return false; + } + if (!Objects.equals(getScope(), other.getScope())) { + return false; + } + if (!Objects.equals(openIdToken, other.getOpenIdToken())) { + return false; + } + return Objects.equals(getExpiresIn(), other.getExpiresIn()); + } + @Override public String toString() { - return String.format("GoogleToken{'token'='%s', 'openIdToken'='%s']", getToken(), openIdToken); + return "GoogleToken{" + + "access_token=" + getAccessToken() + + ", token_type=" + getTokenType() + + ", expires_in=" + getExpiresIn() + + ", refresh_token=" + getRefreshToken() + + ", scope=" + getScope() + + ", open_id_token=" + openIdToken + '}'; } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/DoktornaraboteOAuthServiceImpl.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/DoktornaraboteOAuthServiceImpl.java index a8a28391c..837449436 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/DoktornaraboteOAuthServiceImpl.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/DoktornaraboteOAuthServiceImpl.java @@ -14,6 +14,6 @@ public DoktornaraboteOAuthServiceImpl(DefaultApi20 api, OAuthConfig config) { @Override public void signRequest(OAuth2AccessToken accessToken, AbstractRequest request) { - request.addHeader("Authorization", "Bearer " + accessToken.getToken()); + request.addHeader("Authorization", "Bearer " + accessToken.getAccessToken()); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/GoogleOAuthServiceImpl.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/GoogleOAuthServiceImpl.java index 44fc434a2..300872853 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/GoogleOAuthServiceImpl.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/GoogleOAuthServiceImpl.java @@ -17,7 +17,7 @@ public GoogleOAuthServiceImpl(DefaultApi20 api, OAuthConfig config) { protected T createAccessTokenRequest(Verifier verifier, T request) { super.createAccessTokenRequest(verifier, request); if (!getConfig().hasGrantType()) { - request.addParameter(OAuthConstants.GRANT_TYPE, "authorization_code"); + request.addParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.AUTHORIZATION_CODE); } return request; } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/HHOAuthServiceImpl.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/HHOAuthServiceImpl.java index dc009bee1..8d1799272 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/HHOAuthServiceImpl.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/HHOAuthServiceImpl.java @@ -14,6 +14,6 @@ public HHOAuthServiceImpl(DefaultApi20 api, OAuthConfig config) { @Override public void signRequest(OAuth2AccessToken accessToken, AbstractRequest request) { - request.addHeader("Authorization", "Bearer " + accessToken.getToken()); + request.addHeader("Authorization", "Bearer " + accessToken.getAccessToken()); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthServiceImpl.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthServiceImpl.java index 3ba54ad75..fcc791ac1 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthServiceImpl.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthServiceImpl.java @@ -34,6 +34,7 @@ protected T createAccessTokenRequest(Verifier verifi @Override public void signRequest(OAuth2AccessToken accessToken, AbstractRequest request) { request.addHeader("Authorization", - accessToken == null ? "Client-ID " + getConfig().getApiKey() : "Bearer " + accessToken.getToken()); + accessToken == null + ? "Client-ID " + getConfig().getApiKey() : "Bearer " + accessToken.getAccessToken()); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/LinkedIn20ServiceImpl.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/LinkedIn20ServiceImpl.java index 0fd9d397c..b1d61bb04 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/LinkedIn20ServiceImpl.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/LinkedIn20ServiceImpl.java @@ -16,14 +16,14 @@ public LinkedIn20ServiceImpl(DefaultApi20 api, OAuthConfig config) { @Override public void signRequest(OAuth2AccessToken accessToken, AbstractRequest request) { - request.addQuerystringParameter("oauth2_access_token", accessToken.getToken()); + request.addQuerystringParameter("oauth2_access_token", accessToken.getAccessToken()); } @Override protected T createAccessTokenRequest(Verifier verifier, T request) { super.createAccessTokenRequest(verifier, request); if (!getConfig().hasGrantType()) { - request.addParameter(OAuthConstants.GRANT_TYPE, "authorization_code"); + request.addParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.AUTHORIZATION_CODE); } return request; } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthServiceImpl.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthServiceImpl.java index f4cce01c8..4b78fc6da 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthServiceImpl.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthServiceImpl.java @@ -23,7 +23,7 @@ public MailruOAuthServiceImpl(DefaultApi20 api, OAuthConfig config) { @Override public void signRequest(OAuth2AccessToken accessToken, AbstractRequest request) { // sig = md5(params + secret_key) - request.addQuerystringParameter("session_key", accessToken.getToken()); + request.addQuerystringParameter("session_key", accessToken.getAccessToken()); request.addQuerystringParameter("app_id", getConfig().getApiKey()); final String completeUrl = request.getCompleteUrl(); @@ -55,7 +55,7 @@ public void signRequest(OAuth2AccessToken accessToken, AbstractRequest request) protected T createAccessTokenRequest(Verifier verifier, T request) { super.createAccessTokenRequest(verifier, request); if (!getConfig().hasGrantType()) { - request.addParameter(OAuthConstants.GRANT_TYPE, "authorization_code"); + request.addParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.AUTHORIZATION_CODE); } return request; } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiServiceImpl.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiServiceImpl.java index 5c7066a40..baca34604 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiServiceImpl.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiServiceImpl.java @@ -20,7 +20,7 @@ public OdnoklassnikiServiceImpl(DefaultApi20 api, OAuthConfig config) { public void signRequest(OAuth2AccessToken accessToken, AbstractRequest request) { // sig = md5( request_params_composed_string+ md5(access_token + application_secret_key) ) try { - final String tokenDigest = md5Hex(accessToken.getToken() + getConfig().getApiSecret()); + final String tokenDigest = md5Hex(accessToken.getAccessToken() + getConfig().getApiSecret()); final String completeUrl = request.getCompleteUrl(); final int queryIndex = completeUrl.indexOf('?'); diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/TutByOAuthServiceImpl.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/TutByOAuthServiceImpl.java index 8916b3abd..21a61d13e 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/TutByOAuthServiceImpl.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/TutByOAuthServiceImpl.java @@ -15,7 +15,6 @@ public TutByOAuthServiceImpl(DefaultApi20 api, OAuthConfig config) { @Override public void signRequest(OAuth2AccessToken accessToken, AbstractRequest request) { - request.addQuerystringParameter(OAuthConstants.TOKEN, accessToken.getToken()); + request.addQuerystringParameter(OAuthConstants.TOKEN, accessToken.getAccessToken()); } - } diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java index fc5522544..17c37f5a9 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java @@ -49,7 +49,7 @@ public static void main(String... args) { // Now let's go and ask for a protected resource! System.out.println("Now we're going to access a protected resource..."); - final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL + accessToken.getToken(), + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL + accessToken.getAccessToken(), service); service.signRequest(accessToken, request); final Response response = request.send(); 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 4af541711..2232e3dc8 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 @@ -21,7 +21,7 @@ public static void main(String... args) { final String clientSecret = "your client secret"; final OAuth20Service service = new ServiceBuilder() .apiKey(clientId).apiSecret(clientSecret) - .scope("r_fullprofile,r_emailaddress,r_contactinfo") // replace with desired scope + .scope("r_basicprofile,r_emailaddress") // replace with desired scope .callback("http://example.com/callback") .state("some_params") .build(LinkedInApi20.instance()); @@ -51,11 +51,15 @@ public static void main(String... args) { // Now let's go and ask for a protected resource! System.out.println("Now we're going to access a protected resource..."); while (true) { - System.out.println("Paste profile query for fetch"); + System.out.println("Paste profile query for fetch (firstName, lastName, etc) or 'exit' to stop example"); System.out.print(">>"); final String query = in.nextLine(); System.out.println(); + if ("exit".equals(query)) { + break; + } + final OAuthRequest request = new OAuthRequest(Verb.GET, String.format(PROTECTED_RESOURCE_URL, query), service); request.addHeader("x-li-format", "json"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java index 3f2505dbd..199bb111a 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java @@ -50,7 +50,7 @@ public static void main(String... args) { // Now let's go and ask for a protected resource! System.out.println("Now we're going to access a protected resource..."); - final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL + accessToken.getToken(), + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL + accessToken.getAccessToken(), service); service.signRequest(accessToken, request); final Response response = request.send(); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java index 802b6e967..f0824d2a7 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java @@ -28,7 +28,7 @@ public static void main(String... args) throws InterruptedException, ExecutionEx .setRequestTimeout(10_000) .setAllowPoolingConnections(false) .setPooledConnectionIdleTimeout(1_000) - .setReadTimeout(1_000) + .setReadTimeout(10_000) .build(); final OAuth20Service service = new ServiceBuilderAsync() diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java index b00b8d696..a7b1b9710 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java @@ -4,6 +4,7 @@ import com.github.scribejava.core.builder.ServiceBuilder; import com.github.scribejava.apis.OdnoklassnikiApi; import com.github.scribejava.core.model.OAuth2AccessToken; +import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; import com.github.scribejava.core.model.Verb; @@ -26,6 +27,7 @@ public static void main(String... args) { .apiKey(clientId) .apiSecret(clientSecret) .scope("VALUABLE ACCESS") + .grantType(OAuthConstants.AUTHORIZATION_CODE) .callback("http://your.site.com/callback") .build(OdnoklassnikiApi.instance()); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java index ca675d260..3860ebfb4 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java @@ -50,7 +50,7 @@ public static void main(String... args) { // Now let's go and ask for a protected resource! System.out.println("Now we're going to access a protected resource..."); - final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL + accessToken.getToken(), + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL + accessToken.getAccessToken(), service); service.signRequest(accessToken, request); final Response response = request.send(); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java index 299f9ede3..48f37ad17 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java @@ -70,7 +70,7 @@ public static void main(String... args) { request.addQuerystringParameter(entry.getKey(), entry.getValue()); sigString.add(String.format("%s=%s", entry.getKey(), entry.getValue())); } - sigString.add(String.format("%s=%s", OAuthConstants.ACCESS_TOKEN, accessToken.getToken())); + sigString.add(String.format("%s=%s", OAuthConstants.ACCESS_TOKEN, accessToken.getAccessToken())); Collections.sort(sigString); final StringBuilder b = new StringBuilder(); for (String param : sigString) { 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 68f6390af..4f0a885a2 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 @@ -17,7 +17,7 @@ public abstract class VkontakteExample { private static final String NETWORK_NAME = "Vkontakte.ru"; - private static final String PROTECTED_RESOURCE_URL = "https://api.vk.com/method/friends.get"; + private static final String PROTECTED_RESOURCE_URL = "https://api.vk.com/method/users.get"; public static void main(String... args) { // Replace these with your client id and secret @@ -26,7 +26,7 @@ public static void main(String... args) { final OAuth20Service service = new ServiceBuilder() .apiKey(clientId) .apiSecret(clientSecret) - .scope("friends,wall,offline") // replace with desired scope + .scope("wall,offline") // replace with desired scope .callback("http://your.site.com/callback") .build(VkontakteApi.instance()); final Scanner in = new Scanner(System.in); diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth1AccessToken.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth1AccessToken.java index e4d31c6c0..838fc2adb 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth1AccessToken.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth1AccessToken.java @@ -1,17 +1,52 @@ package com.github.scribejava.core.model; +import java.util.Objects; + /** - * Represents an OAuth 1 Access Token + * Represents an OAuth 1 Access Token http://oauth.net/core/1.0a/#rfc.section.6.3.2 */ public class OAuth1AccessToken extends OAuth1Token { - private static final long serialVersionUID = 1344500144115482404L; + private static final long serialVersionUID = -8784937061938486135L; + + public OAuth1AccessToken(String token, String tokenSecret) { + this(token, tokenSecret, null); + } + + public OAuth1AccessToken(String token, String tokenSecret, String rawResponse) { + super(token, tokenSecret, rawResponse); + } + + @Override + public int hashCode() { + int hash = 3; + hash = 73 * hash + Objects.hashCode(getToken()); + hash = 73 * hash + Objects.hashCode(getTokenSecret()); + return hash; + } - public OAuth1AccessToken(String token, String secret) { - this(token, secret, null); + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final OAuth1AccessToken other = (OAuth1AccessToken) obj; + if (!Objects.equals(getToken(), other.getToken())) { + return false; + } + return Objects.equals(getTokenSecret(), other.getTokenSecret()); } - public OAuth1AccessToken(String token, String secret, String rawResponse) { - super(token, secret, rawResponse); + @Override + public String toString() { + return "OAuth1AccessToken{" + + "oauth_token=" + getToken() + + ", oauth_token_secret=" + getTokenSecret() + '}'; } } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth1RequestToken.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth1RequestToken.java index 5f0e11b24..b7db7047b 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth1RequestToken.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth1RequestToken.java @@ -1,17 +1,74 @@ package com.github.scribejava.core.model; +import java.util.Objects; + /** - * Represents an OAuth 1 Abstract Token + * Represents an OAuth 1 Request Token http://oauth.net/core/1.0a/#rfc.section.6.1.2 */ public class OAuth1RequestToken extends OAuth1Token { - private static final long serialVersionUID = 3910105236810537839L; + private static final long serialVersionUID = 359527630020350893L; + + /** + * oauth_callback_confirmed: + *

+ * MUST be present and set to true. The Consumer MAY use this to confirm that the Service Provider received the + * callback value.

+ */ + private final boolean oauthCallbackConfirmed; + + public OAuth1RequestToken(String token, String tokenSecret) { + this(token, tokenSecret, null); + } + + public OAuth1RequestToken(String token, String tokenSecret, String rawResponse) { + this(token, tokenSecret, true, rawResponse); + } + + public OAuth1RequestToken(String token, String tokenSecret, boolean oauthCallbackConfirmed, String rawResponse) { + super(token, tokenSecret, rawResponse); + this.oauthCallbackConfirmed = oauthCallbackConfirmed; + } + + public boolean isOauthCallbackConfirmed() { + return oauthCallbackConfirmed; + } + + @Override + public int hashCode() { + int hash = 7; + hash = 83 * hash + Objects.hashCode(getToken()); + hash = 83 * hash + Objects.hashCode(getTokenSecret()); + hash = 83 * hash + (oauthCallbackConfirmed ? 1 : 0); + return hash; + } - public OAuth1RequestToken(String token, String secret) { - this(token, secret, null); + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final OAuth1RequestToken other = (OAuth1RequestToken) obj; + if (oauthCallbackConfirmed != other.isOauthCallbackConfirmed()) { + return false; + } + if (!Objects.equals(getToken(), other.getToken())) { + return false; + } + return Objects.equals(getTokenSecret(), other.getTokenSecret()); } - public OAuth1RequestToken(String token, String secret, String rawResponse) { - super(token, secret, rawResponse); + @Override + public String toString() { + return "OAuth1RequestToken{" + + "oauth_token=" + getToken() + + ", oauth_token_secret=" + getTokenSecret() + + ", oauthCallbackConfirmed=" + oauthCallbackConfirmed + '}'; } } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth1Token.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth1Token.java index b6c5daa6b..c50fbd29e 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth1Token.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth1Token.java @@ -1,62 +1,48 @@ package com.github.scribejava.core.model; import com.github.scribejava.core.utils.Preconditions; -import java.util.Objects; /** - * Represents an abstract OAuth 1 Access Token (either request or access token) + * Represents an abstract OAuth 1 Token (either request or access token) */ public abstract class OAuth1Token extends Token { - private static final long serialVersionUID = -2591380053073767654L; + private static final long serialVersionUID = 6285873427974823019L; - private final String secret; + /** + * oauth_token: + *

+ * The Request/Access Token.

+ */ + private final String token; - public OAuth1Token(String token, String secret, String rawResponse) { - super(token, rawResponse); - Preconditions.checkNotNull(secret, "Secret can't be null"); - this.secret = secret; + /** + * oauth_token_secret: + *

+ * The Token Secret.

+ */ + private final String tokenSecret; + + public OAuth1Token(String token, String tokenSecret, String rawResponse) { + super(rawResponse); + Preconditions.checkNotNull(token, "oauth_token can't be null"); + Preconditions.checkNotNull(tokenSecret, "oauth_token_secret can't be null"); + this.token = token; + this.tokenSecret = tokenSecret; } - public String getSecret() { - return secret; + public String getToken() { + return token; } - @Override - public String toString() { - return String.format("Token[%s , %s]", getToken(), secret); + public String getTokenSecret() { + return tokenSecret; } /** - * @return true if the token is empty (token = "", secret = "") + * @return true if the token is empty (oauth_token = "", oauth_token_secret = "") */ public boolean isEmpty() { - return "".equals(this.getToken()) && "".equals(this.secret); - } - - @Override - public int hashCode() { - int hash = 7; - hash = 71 * hash + Objects.hashCode(secret); - hash = 71 * hash + Objects.hashCode(getToken()); - 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 OAuth1Token other = (OAuth1Token) obj; - if (!Objects.equals(secret, other.getSecret())) { - return false; - } - return Objects.equals(getToken(), other.getToken()); + return "".equals(token) && "".equals(tokenSecret); } } 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 ad903eec1..5205aa64f 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 @@ -1,18 +1,140 @@ package com.github.scribejava.core.model; +import com.github.scribejava.core.utils.Preconditions; +import java.util.Objects; + /** - * Represents an OAuth 2 Access Token + * Represents an OAuth 2 Access Token http://tools.ietf.org/html/rfc6749#section-5.1 */ public class OAuth2AccessToken extends Token { - private static final long serialVersionUID = -7450991088697660741L; + private static final long serialVersionUID = 8901381135476613449L; + + /** + * access_token + *

+ * REQUIRED. The access token issued by the authorization server.

+ */ + private String accessToken; + + /** + * token_type + *

+ * REQUIRED. The type of the token issued as described in http://tools.ietf.org/html/rfc6749#section-7.1 Value is + * case insensitive.

+ */ + private String tokenType; + + /** + * expires_in + *

+ * RECOMMENDED. The lifetime in seconds of the access token. For example, the value "3600" denotes that the access + * token will expire in one hour from the time the response was generated. If omitted, the authorization server + * SHOULD provide the expiration time via other means or document the default value.

+ */ + private Integer expiresIn; + + /** + * refresh_token + *

+ * OPTIONAL. The refresh token, which can be used to obtain new access tokens using the same authorization grant as + * described in http://tools.ietf.org/html/rfc6749#section-6

+ */ + private String refreshToken; + + /** + * scope + *

+ * OPTIONAL, if identical to the scope requested by the client; otherwise, REQUIRED. The scope of the access token + * as described by http://tools.ietf.org/html/rfc6749#section-3.3

+ */ + private String scope; + + public OAuth2AccessToken(String accessToken) { + this(accessToken, null); + } + + public OAuth2AccessToken(String accessToken, String rawResponse) { + this(accessToken, null, null, null, null, rawResponse); + } + + public OAuth2AccessToken(String accessToken, String tokenType, Integer expiresIn, String refreshToken, String scope, + String rawResponse) { + super(rawResponse); + Preconditions.checkNotNull(accessToken, "access_token can't be null"); + this.accessToken = accessToken; + this.tokenType = tokenType; + this.expiresIn = expiresIn; + this.refreshToken = refreshToken; + this.scope = scope; + } + + + public String getAccessToken() { + return accessToken; + } + + public String getTokenType() { + return tokenType; + } + + public Integer getExpiresIn() { + return expiresIn; + } + + public String getRefreshToken() { + return refreshToken; + } - public OAuth2AccessToken(String token) { - super(token, null); + public String getScope() { + return scope; } - public OAuth2AccessToken(String token, String rawResponse) { - super(token, rawResponse); + @Override + public int hashCode() { + int hash = 7; + hash = 41 * hash + Objects.hashCode(accessToken); + hash = 41 * hash + Objects.hashCode(tokenType); + hash = 41 * hash + Objects.hashCode(expiresIn); + hash = 41 * hash + Objects.hashCode(refreshToken); + hash = 41 * hash + Objects.hashCode(scope); + 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 OAuth2AccessToken other = (OAuth2AccessToken) obj; + if (!Objects.equals(accessToken, other.getAccessToken())) { + return false; + } + if (!Objects.equals(tokenType, other.getTokenType())) { + return false; + } + if (!Objects.equals(refreshToken, other.getRefreshToken())) { + return false; + } + if (!Objects.equals(scope, other.getScope())) { + return false; + } + return Objects.equals(expiresIn, other.getExpiresIn()); + } + + @Override + public String toString() { + return "OAuth2AccessToken{" + + "access_token=" + accessToken + + ", token_type=" + tokenType + + ", expires_in=" + expiresIn + + ", refresh_token=" + refreshToken + + ", scope=" + scope + '}'; + } } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/Token.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/Token.java index 7fb33f398..ede417c03 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/Token.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/Token.java @@ -1,29 +1,20 @@ package com.github.scribejava.core.model; import java.io.Serializable; -import com.github.scribejava.core.utils.Preconditions; -import java.util.Objects; /** * Represents an abstract OAuth (1 and 2) token (either request or access token) */ public abstract class Token implements Serializable { - private static final long serialVersionUID = 777818051043452947L; + private static final long serialVersionUID = -8409640649946468092L; - private final String token; private final String rawResponse; - public Token(String token, String rawResponse) { - Preconditions.checkNotNull(token, "Token can't be null"); - this.token = token; + protected Token(String rawResponse) { this.rawResponse = rawResponse; } - public String getToken() { - return token; - } - public String getRawResponse() { if (rawResponse == null) { throw new IllegalStateException( @@ -34,7 +25,7 @@ public String getRawResponse() { public String getParameter(String parameter) { String value = null; - for (String str : this.getRawResponse().split("&")) { + for (String str : rawResponse.split("&")) { if (str.startsWith(parameter + '=')) { final String[] part = str.split("="); if (part.length > 1) { @@ -45,31 +36,4 @@ public String getParameter(String parameter) { } return value; } - - @Override - public String toString() { - return String.format("Token[%s]", token); - } - - @Override - public int hashCode() { - int hash = 7; - hash = 59 * hash + Objects.hashCode(token); - 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 Token other = (Token) obj; - return Objects.equals(token, other.getToken()); - } } 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 544c8c368..d7da4e046 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java @@ -24,7 +24,7 @@ * * @author Pablo Fernandez */ -public class OAuth10aService extends OAuthService { +public class OAuth10aService extends OAuthService { private static final String VERSION = "1.0"; private final DefaultApi10a api; @@ -128,10 +128,6 @@ protected void prepareAccessTokenRequest(AbstractRequest request, OAuth1RequestT appendSignature(request); } - /** - * {@inheritDoc} - */ - @Override public void signRequest(OAuth1AccessToken token, AbstractRequest request) { final OAuthConfig config = getConfig(); config.log("signing request: " + request.getCompleteUrl()); @@ -169,7 +165,7 @@ private String getSignature(AbstractRequest request, OAuth1Token token) { config.log("using base64 encoder: " + Base64Encoder.type()); final String baseString = api.getBaseStringExtractor().extract(request); final String signature = api.getSignatureService() - .getSignature(baseString, config.getApiSecret(), token.getSecret()); + .getSignature(baseString, config.getApiSecret(), token.getTokenSecret()); config.log("base string is: " + baseString); config.log("signature is: " + signature); diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java index e0d7cfcc7..84ae8a8ef 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 @@ -14,7 +14,7 @@ import com.github.scribejava.core.model.Response; import com.github.scribejava.core.model.Verifier; -public class OAuth20Service extends OAuthService { +public class OAuth20Service extends OAuthService { private static final String VERSION = "2.0"; private final DefaultApi20 api; @@ -85,12 +85,8 @@ public String getVersion() { return VERSION; } - /** - * {@inheritDoc} - */ - @Override public void signRequest(OAuth2AccessToken accessToken, AbstractRequest request) { - request.addQuerystringParameter(OAuthConstants.ACCESS_TOKEN, accessToken.getToken()); + request.addQuerystringParameter(OAuthConstants.ACCESS_TOKEN, accessToken.getAccessToken()); } /** diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java index c6d94cb8f..470f903b6 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java @@ -2,12 +2,10 @@ import com.ning.http.client.AsyncHttpClient; import com.github.scribejava.core.exceptions.OAuthException; -import com.github.scribejava.core.model.AbstractRequest; import com.github.scribejava.core.model.ForceTypeOfHttpRequest; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConfigAsync; import com.github.scribejava.core.model.ScribeJavaConfig; -import com.github.scribejava.core.model.Token; /** * The main ScribeJava object. @@ -16,7 +14,7 @@ * * @author Pablo Fernandez */ -public abstract class OAuthService { +public abstract class OAuthService { private final OAuthConfig config; private AsyncHttpClient asyncHttpClient; @@ -59,18 +57,10 @@ public OAuthConfig getConfig() { return config; } - /** - * Signs am OAuth request - * - * @param accessToken access token (obtained previously) - * @param request request to sign - */ - public abstract void signRequest(T accessToken, AbstractRequest request); - /** * Returns the OAuth version of the service. * - * @return oauth version as string + * @return OAuth version as string */ public abstract String getVersion(); } 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 ebc512c61..78ecfa2a1 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 @@ -4,6 +4,9 @@ import java.security.Signature; import java.security.SignatureException; import com.github.scribejava.core.exceptions.OAuthSignatureException; +import java.io.UnsupportedEncodingException; +import java.security.InvalidKeyException; +import java.security.NoSuchAlgorithmException; /** * A signature service that uses the RSA-SHA1 algorithm. @@ -30,7 +33,8 @@ public String getSignature(String baseString, String apiSecret, String tokenSecr signature.initSign(privateKey); signature.update(baseString.getBytes(UTF8)); return bytesToBase64String(signature); - } catch (Exception e) { + } catch (NoSuchAlgorithmException | InvalidKeyException | SignatureException | UnsupportedEncodingException | + RuntimeException e) { throw new OAuthSignatureException(baseString, e); } } 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 4550d6706..7cf3feb95 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 @@ -20,14 +20,14 @@ public void shouldExtractTokenFromOAuthStandardResponse() { final String response = "oauth_token=hh5s93j4hdidpola&oauth_token_secret=hdhd0244k9j7ao03"; final OAuth1Token extracted = extractor.extract(response); assertEquals("hh5s93j4hdidpola", extracted.getToken()); - assertEquals("hdhd0244k9j7ao03", extracted.getSecret()); + assertEquals("hdhd0244k9j7ao03", extracted.getTokenSecret()); } @Test public void shouldExtractTokenFromInvertedOAuthStandardResponse() { final String response = "oauth_token_secret=hh5s93j4hdidpola&oauth_token=hdhd0244k9j7ao03"; final OAuth1Token extracted = extractor.extract(response); - assertEquals("hh5s93j4hdidpola", extracted.getSecret()); + assertEquals("hh5s93j4hdidpola", extracted.getTokenSecret()); assertEquals("hdhd0244k9j7ao03", extracted.getToken()); } @@ -37,7 +37,7 @@ public void shouldExtractTokenFromResponseWithCallbackConfirmed() { + "&callback_confirmed=true"; final OAuth1Token extracted = extractor.extract(response); assertEquals("hh5s93j4hdidpola", extracted.getToken()); - assertEquals("hdhd0244k9j7ao03", extracted.getSecret()); + assertEquals("hdhd0244k9j7ao03", extracted.getTokenSecret()); } @Test @@ -45,7 +45,7 @@ public void shouldExtractTokenWithEmptySecret() { final String response = "oauth_token=hh5s93j4hdidpola&oauth_token_secret="; final OAuth1Token extracted = extractor.extract(response); assertEquals("hh5s93j4hdidpola", extracted.getToken()); - assertEquals("", extracted.getSecret()); + assertEquals("", extracted.getTokenSecret()); } @Test(expected = OAuthException.class) 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 3963309fa..8ed1707b3 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 @@ -3,7 +3,7 @@ import org.junit.Before; import org.junit.Test; import com.github.scribejava.core.exceptions.OAuthException; -import com.github.scribejava.core.model.Token; +import com.github.scribejava.core.model.OAuth2AccessToken; import static org.junit.Assert.assertEquals; public class OAuth2AccessTokenExtractorTest { @@ -19,25 +19,25 @@ public void setUp() { public void shouldExtractTokenFromOAuthStandardResponse() { final String response = "access_token=166942940015970|2.2ltzWXYNDjCtg5ZDVVJJeg__.3600.1295816400-548517159" + "|RsXNdKrpxg8L6QNLWcs2TVTmcaE"; - final Token extracted = extractor.extract(response); + final OAuth2AccessToken extracted = extractor.extract(response); assertEquals("166942940015970|2.2ltzWXYNDjCtg5ZDVVJJeg__.3600.1295816400-548517159|RsXNdKrpxg8L6QNLWcs2TVTmcaE", - extracted.getToken()); + extracted.getAccessToken()); } @Test public void shouldExtractTokenFromResponseWithExpiresParam() { final String response = "access_token=166942940015970|2.2ltzWXYNDjCtg5ZDVVJJeg__.3600.1295816400-548517159" + "|RsXNdKrpxg8L6QNLWcs2TVTmcaE&expires=5108"; - final Token extracted = extractor.extract(response); + final OAuth2AccessToken extracted = extractor.extract(response); assertEquals("166942940015970|2.2ltzWXYNDjCtg5ZDVVJJeg__.3600.1295816400-548517159|RsXNdKrpxg8L6QNLWcs2TVTmcaE", - extracted.getToken()); + extracted.getAccessToken()); } @Test public void shouldExtractTokenFromResponseWithManyParameters() { final String response = "access_token=foo1234&other_stuff=yeah_we_have_this_too&number=42"; - final Token extracted = extractor.extract(response); - assertEquals("foo1234", extracted.getToken()); + final OAuth2AccessToken extracted = extractor.extract(response); + assertEquals("foo1234", extracted.getAccessToken()); } @Test(expected = OAuthException.class) diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/extractors/JsonTokenExtractorTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractorTest.java similarity index 71% rename from scribejava-core/src/test/java/com/github/scribejava/core/extractors/JsonTokenExtractorTest.java rename to scribejava-core/src/test/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractorTest.java index 826377e85..9b2098e6c 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/extractors/JsonTokenExtractorTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractorTest.java @@ -1,18 +1,18 @@ package com.github.scribejava.core.extractors; -import static org.junit.Assert.assertEquals; +import com.github.scribejava.core.model.OAuth2AccessToken; import org.junit.Test; -import com.github.scribejava.core.model.Token; +import static org.junit.Assert.assertEquals; -public class JsonTokenExtractorTest { +public class OAuth2AccessTokenJsonExtractorTest { private static final String RESPONSE = "'{ \"access_token\":\"I0122HHJKLEM21F3WLPYHDKGKZULAUO4SGMV3ABKFTDT3T3X\"}'"; private final OAuth2AccessTokenJsonExtractor extractor = OAuth2AccessTokenJsonExtractor.instance(); @Test public void shouldParseResponse() { - final Token token = extractor.extract(RESPONSE); - assertEquals(token.getToken(), "I0122HHJKLEM21F3WLPYHDKGKZULAUO4SGMV3ABKFTDT3T3X"); + final OAuth2AccessToken token = extractor.extract(RESPONSE); + assertEquals(token.getAccessToken(), "I0122HHJKLEM21F3WLPYHDKGKZULAUO4SGMV3ABKFTDT3T3X"); } @Test(expected = IllegalArgumentException.class) 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 72ec3104a..261bc2bb4 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,7 +1,9 @@ package com.github.scribejava.core.services; import java.security.KeyFactory; +import java.security.NoSuchAlgorithmException; import java.security.PrivateKey; +import java.security.spec.InvalidKeySpecException; import java.security.spec.PKCS8EncodedKeySpec; import javax.xml.bind.DatatypeConverter; import static org.junit.Assert.assertEquals; @@ -52,7 +54,7 @@ private static PrivateKey getPrivateKey() { final KeyFactory fac = KeyFactory.getInstance("RSA"); final PKCS8EncodedKeySpec privKeySpec = new PKCS8EncodedKeySpec(DatatypeConverter.parseBase64Binary(str)); return fac.generatePrivate(privKeySpec); - } catch (Exception e) { + } catch (NoSuchAlgorithmException | InvalidKeySpecException e) { throw new RuntimeException(e); } } 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 6766e7680..322283d23 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 @@ -9,6 +9,16 @@ public class StreamUtilsTest { + private static final InputStream ALLWAYS_ERROR_INPUT_STREAM = new AllwaysErrorInputStream(); + + private static class AllwaysErrorInputStream extends InputStream { + + @Override + public int read() throws IOException { + throw new IOException(); + } + } + @Test public void shouldCorrectlyDecodeAStream() { final String value = "expected"; @@ -26,13 +36,7 @@ public void shouldFailForNullParameter() { @Test(expected = IllegalStateException.class) public void shouldFailWithBrokenStream() { // This object simulates problems with input stream. - final InputStream is = new InputStream() { - @Override - public int read() throws IOException { - throw new IOException(); - } - }; - StreamUtils.getStreamContents(is); + StreamUtils.getStreamContents(ALLWAYS_ERROR_INPUT_STREAM); fail("Must throw exception before getting here"); } } From 9d0d045e813714c41b38546ffa29d80725ebdbeb Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Sat, 20 Feb 2016 13:08:39 +0300 Subject: [PATCH 136/882] remove useless author javadoc. we have more accurate git blame) --- .../src/main/java/com/github/scribejava/apis/FlickrApi.java | 1 - .../main/java/com/github/scribejava/apis/MendeleyApi.java | 1 - .../main/java/com/github/scribejava/apis/SimpleGeoApi.java | 3 --- .../src/main/java/com/github/scribejava/apis/SkyrockApi.java | 1 - .../java/com/github/scribejava/apis/StackExchangeApi.java | 5 +---- .../main/java/com/github/scribejava/apis/UbuntuOneApi.java | 5 ----- .../main/java/com/github/scribejava/apis/VkontakteApi.java | 4 ---- .../github/scribejava/apis/examples/VkontakteExample.java | 4 ---- .../com/github/scribejava/core/builder/ServiceBuilder.java | 2 -- .../github/scribejava/core/builder/api/DefaultApi10a.java | 2 -- .../com/github/scribejava/core/builder/api/DefaultApi20.java | 2 -- .../scribejava/core/exceptions/OAuthConnectionException.java | 3 --- .../github/scribejava/core/exceptions/OAuthException.java | 2 -- .../core/exceptions/OAuthParametersMissingException.java | 2 -- .../scribejava/core/exceptions/OAuthSignatureException.java | 2 -- .../core/extractors/AbstractOAuth1TokenExtractor.java | 1 - .../scribejava/core/extractors/BaseStringExtractor.java | 2 -- .../scribejava/core/extractors/BaseStringExtractorImpl.java | 3 --- .../github/scribejava/core/extractors/HeaderExtractor.java | 2 -- .../scribejava/core/extractors/HeaderExtractorImpl.java | 3 --- .../com/github/scribejava/core/model/AbstractRequest.java | 2 -- .../java/com/github/scribejava/core/model/OAuthConfig.java | 2 -- .../com/github/scribejava/core/model/OAuthConstants.java | 2 -- .../java/com/github/scribejava/core/model/Parameter.java | 3 --- .../java/com/github/scribejava/core/model/ParameterList.java | 3 --- .../src/main/java/com/github/scribejava/core/model/Verb.java | 2 -- .../main/java/com/github/scribejava/core/model/Verifier.java | 2 -- .../com/github/scribejava/core/oauth/OAuth10aService.java | 2 -- .../java/com/github/scribejava/core/oauth/OAuthService.java | 2 -- .../scribejava/core/services/HMACSha1SignatureService.java | 3 --- .../scribejava/core/services/PlaintextSignatureService.java | 3 --- .../github/scribejava/core/services/SignatureService.java | 3 --- .../github/scribejava/core/services/TimestampService.java | 2 -- .../scribejava/core/services/TimestampServiceImpl.java | 4 ---- .../main/java/com/github/scribejava/core/utils/MapUtils.java | 3 --- .../java/com/github/scribejava/core/utils/OAuthEncoder.java | 3 --- .../java/com/github/scribejava/core/utils/Preconditions.java | 2 -- .../java/com/github/scribejava/core/utils/StreamUtils.java | 2 -- .../com/github/scribejava/core/model/ParameterListTest.java | 3 --- .../java/com/github/scribejava/core/utils/MapUtilsTest.java | 3 --- .../com/github/scribejava/core/utils/OAuthEncoderTest.java | 3 --- 41 files changed, 1 insertion(+), 103 deletions(-) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/FlickrApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/FlickrApi.java index 9b5521e28..0e1db4ea7 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/FlickrApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/FlickrApi.java @@ -6,7 +6,6 @@ /** * OAuth API for Flickr. * - * @author Darren Greaves * @see Flickr API */ public class FlickrApi extends DefaultApi10a { diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/MendeleyApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/MendeleyApi.java index 89bf98e56..9fab6e2ff 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/MendeleyApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/MendeleyApi.java @@ -5,7 +5,6 @@ import com.github.scribejava.core.model.Verb; /** - * @author Arieh "Vainolo" Bibliowicz * @see http://apidocs.mendeley.com/home/authentication */ public class MendeleyApi extends DefaultApi10a { diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/SimpleGeoApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/SimpleGeoApi.java index 65df4bf76..c8264b19b 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/SimpleGeoApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/SimpleGeoApi.java @@ -3,9 +3,6 @@ import com.github.scribejava.core.builder.api.DefaultApi10a; import com.github.scribejava.core.model.OAuth1RequestToken; -/** - * @author Pablo Fernandez - */ public class SimpleGeoApi extends DefaultApi10a { private static final String ENDPOINT = "these are not used since SimpleGeo uses 2 legged OAuth"; diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/SkyrockApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/SkyrockApi.java index ad8157ccd..02c0eb533 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/SkyrockApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/SkyrockApi.java @@ -6,7 +6,6 @@ /** * OAuth API for Skyrock. * - * @author Nicolas Quiénot * @see Skyrock.com API */ public class SkyrockApi extends DefaultApi10a { diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/StackExchangeApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/StackExchangeApi.java index 2c962989f..77e257839 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/StackExchangeApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/StackExchangeApi.java @@ -7,12 +7,9 @@ import com.github.scribejava.core.utils.OAuthEncoder; import com.github.scribejava.core.utils.Preconditions; -/*** +/** * Stack Exchange authentication via OAuth 2.0 (stackoverflow.com, * askubuntu.com, etc.). - * - * @author Michal Foksa - * */ public class StackExchangeApi extends DefaultApi20 { diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/UbuntuOneApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/UbuntuOneApi.java index a9ad07e77..867b7556a 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/UbuntuOneApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/UbuntuOneApi.java @@ -5,11 +5,6 @@ import com.github.scribejava.core.services.PlaintextSignatureService; import com.github.scribejava.core.services.SignatureService; -/** - * @author Julio Gutierrez - * - * Sep 6, 2012 - */ public class UbuntuOneApi extends DefaultApi10a { private static final String AUTHORIZATION_URL = "https://one.ubuntu.com/oauth/authorize/?oauth_token=%s"; diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/VkontakteApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/VkontakteApi.java index b83155658..b0b4e345c 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/VkontakteApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/VkontakteApi.java @@ -8,10 +8,6 @@ import com.github.scribejava.core.utils.OAuthEncoder; import com.github.scribejava.core.utils.Preconditions; -/** - * @author Boris G. Tsirkin <mail@dotbg.name> - * @since 20.4.2011 - */ public class VkontakteApi extends DefaultApi20 { private static final String AUTHORIZE_URL 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 4f0a885a2..5213a1b05 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 @@ -10,10 +10,6 @@ import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuth20Service; -/** - * @author Boris G. Tsirkin - * @since 20.4.2011 - */ public abstract class VkontakteExample { private static final String NETWORK_NAME = "Vkontakte.ru"; 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 9c920e281..02f7f3902 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 @@ -6,8 +6,6 @@ /** * Implementation of the Builder pattern, with a fluent interface that creates a {@link OAuthService} - * - * @author Pablo Fernandez */ public class ServiceBuilder extends AbstractServiceBuilder { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi10a.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi10a.java index 71320beec..89d1eb499 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi10a.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi10a.java @@ -29,8 +29,6 @@ * If your Api does something a bit different, you can override the different extractors or services, in order to * fine-tune the process. Please read the javadocs of the interfaces to get an idea of what to do. * - * @author Pablo Fernandez - * */ public abstract class DefaultApi10a { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java index b9869c2d7..c789da72a 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java @@ -19,8 +19,6 @@ * If your Api does something a bit different, you can override the different extractors or services, in order to * fine-tune the process. Please read the javadocs of the interfaces to get an idea of what to do. * - * @author Diego Silveira - * */ public abstract class DefaultApi20 { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/exceptions/OAuthConnectionException.java b/scribejava-core/src/main/java/com/github/scribejava/core/exceptions/OAuthConnectionException.java index c2db1511a..93feb8c42 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/exceptions/OAuthConnectionException.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/exceptions/OAuthConnectionException.java @@ -1,8 +1,5 @@ package com.github.scribejava.core.exceptions; -/** - * @author Pablo Fernandez - */ public class OAuthConnectionException extends OAuthException { private static final long serialVersionUID = 6901269342236961310L; diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/exceptions/OAuthException.java b/scribejava-core/src/main/java/com/github/scribejava/core/exceptions/OAuthException.java index c16213dfb..1680b2a44 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/exceptions/OAuthException.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/exceptions/OAuthException.java @@ -3,8 +3,6 @@ /** * Default ScribeJava exception. Represents a problem in the OAuth signing * process - * - * @author Pablo Fernandez */ public class OAuthException extends RuntimeException { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/exceptions/OAuthParametersMissingException.java b/scribejava-core/src/main/java/com/github/scribejava/core/exceptions/OAuthParametersMissingException.java index 90da23f9c..ddf77ab78 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/exceptions/OAuthParametersMissingException.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/exceptions/OAuthParametersMissingException.java @@ -4,8 +4,6 @@ /** * Specialized exception that represents a missing OAuth parameter. - * - * @author Pablo Fernandez */ public class OAuthParametersMissingException extends OAuthException { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/exceptions/OAuthSignatureException.java b/scribejava-core/src/main/java/com/github/scribejava/core/exceptions/OAuthSignatureException.java index 4fbf98c52..53bffbb7c 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/exceptions/OAuthSignatureException.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/exceptions/OAuthSignatureException.java @@ -2,8 +2,6 @@ /** * Specialized exception that represents a problem in the signature - * - * @author Pablo Fernandez */ public class OAuthSignatureException extends OAuthException { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/AbstractOAuth1TokenExtractor.java b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/AbstractOAuth1TokenExtractor.java index a1b4b0d46..d0203a927 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/AbstractOAuth1TokenExtractor.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/AbstractOAuth1TokenExtractor.java @@ -12,7 +12,6 @@ * * The process for extracting access and request tokens is similar so this class can do both things. * - * @author Pablo Fernandez * @param concrete type of OAuth1Token. access or request */ public abstract class AbstractOAuth1TokenExtractor implements TokenExtractor { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/BaseStringExtractor.java b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/BaseStringExtractor.java index 1d468be6f..113dc3515 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/BaseStringExtractor.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/BaseStringExtractor.java @@ -4,8 +4,6 @@ /** * Simple command object that extracts a base string from a {@link AbstractRequest} - * - * @author Pablo Fernandez */ public interface BaseStringExtractor { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/BaseStringExtractorImpl.java b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/BaseStringExtractorImpl.java index b66dbc49a..e2ba3b950 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/BaseStringExtractorImpl.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/BaseStringExtractorImpl.java @@ -8,9 +8,6 @@ /** * Default implementation of {@link BaseStringExtractor}. Conforms to OAuth 1.0a - * - * @author Pablo Fernandez - * */ public class BaseStringExtractorImpl implements BaseStringExtractor { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/HeaderExtractor.java b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/HeaderExtractor.java index 0b31eb60e..d84390a91 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/HeaderExtractor.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/HeaderExtractor.java @@ -4,8 +4,6 @@ /** * Simple command object that generates an OAuth Authorization header to include in the request. - * - * @author Pablo Fernandez */ public interface HeaderExtractor { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/HeaderExtractorImpl.java b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/HeaderExtractorImpl.java index 10f2d1ac0..a3c142a10 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/HeaderExtractorImpl.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/HeaderExtractorImpl.java @@ -9,9 +9,6 @@ /** * Default implementation of {@link HeaderExtractor}. Conforms to OAuth 1.0a - * - * @author Pablo Fernandez - * */ public class HeaderExtractorImpl implements HeaderExtractor { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/AbstractRequest.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/AbstractRequest.java index 515136f09..c48f83c74 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/AbstractRequest.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/AbstractRequest.java @@ -11,8 +11,6 @@ /** * The representation of an OAuth HttpRequest. - * - * @author Pablo Fernandez */ public abstract class AbstractRequest { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConfig.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConfig.java index 0a333454b..92b8bbbbc 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConfig.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConfig.java @@ -5,8 +5,6 @@ /** * Parameter object that groups OAuth config values - * - * @author Pablo Fernandez */ public class OAuthConfig { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConstants.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConstants.java index 0aca979e9..229392c38 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConstants.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConstants.java @@ -2,8 +2,6 @@ /** * This class contains OAuth constants, used project-wide - * - * @author Pablo Fernandez */ public interface OAuthConstants { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/Parameter.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/Parameter.java index 0bcaa91f7..9397cb773 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/Parameter.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/Parameter.java @@ -2,9 +2,6 @@ import com.github.scribejava.core.utils.OAuthEncoder; -/** - * @author Pablo Fernandez - */ public class Parameter implements Comparable { private final String key; diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/ParameterList.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/ParameterList.java index 7ae849780..c04bca9cd 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/ParameterList.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/ParameterList.java @@ -7,9 +7,6 @@ import com.github.scribejava.core.utils.OAuthEncoder; import com.github.scribejava.core.utils.Preconditions; -/** - * @author Pablo Fernandez - */ public class ParameterList { private static final char QUERY_STRING_SEPARATOR = '?'; diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/Verb.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/Verb.java index 943459700..6ca83a517 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/Verb.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/Verb.java @@ -2,8 +2,6 @@ /** * An enumeration containing the most common HTTP Verbs. - * - * @author Pablo Fernandez */ public enum Verb { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/Verifier.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/Verifier.java index 2f2ef21da..fc8a92195 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/Verifier.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/Verifier.java @@ -4,8 +4,6 @@ /** * Represents an OAuth verifier code. - * - * @author Pablo Fernandez */ public class Verifier { 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 d7da4e046..76b076935 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 @@ -21,8 +21,6 @@ /** * OAuth 1.0a implementation of {@link OAuthService} - * - * @author Pablo Fernandez */ public class OAuth10aService extends OAuthService { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java index 470f903b6..ad7c1d4b4 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java @@ -11,8 +11,6 @@ * The main ScribeJava object. * * A facade responsible for the retrieval of request and access tokens and for the signing of HTTP requests. - * - * @author Pablo Fernandez */ public abstract class OAuthService { 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 00a7b7869..824f488d7 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/services/HMACSha1SignatureService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/services/HMACSha1SignatureService.java @@ -11,9 +11,6 @@ /** * HMAC-SHA1 implementation of {@link SignatureService} - * - * @author Pablo Fernandez - * */ public class HMACSha1SignatureService implements SignatureService { 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 ff61219e0..33661f10a 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 @@ -6,9 +6,6 @@ /** * plaintext implementation of {@link SignatureService} - * - * @author Pablo Fernandez - * */ public class PlaintextSignatureService implements SignatureService { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/services/SignatureService.java b/scribejava-core/src/main/java/com/github/scribejava/core/services/SignatureService.java index 34bfc2202..cf821d089 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 @@ -2,9 +2,6 @@ /** * Signs a base string, returning the OAuth signature - * - * @author Pablo Fernandez - * */ public interface SignatureService { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/services/TimestampService.java b/scribejava-core/src/main/java/com/github/scribejava/core/services/TimestampService.java index 42e97fc4f..f062b640a 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/services/TimestampService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/services/TimestampService.java @@ -4,8 +4,6 @@ * Unix epoch timestamp generator. * * This class is useful for stubbing in tests. - * - * @author Pablo Fernandez */ public interface TimestampService { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/services/TimestampServiceImpl.java b/scribejava-core/src/main/java/com/github/scribejava/core/services/TimestampServiceImpl.java index de9fccdbe..76109f10e 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/services/TimestampServiceImpl.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/services/TimestampServiceImpl.java @@ -4,8 +4,6 @@ /** * Implementation of {@link TimestampService} using plain java classes. - * - * @author Pablo Fernandez */ public class TimestampServiceImpl implements TimestampService { @@ -45,8 +43,6 @@ void setTimer(Timer timer) { /** * Inner class that uses {@link System} for generating the timestamps. - * - * @author Pablo Fernandez */ static class Timer { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/utils/MapUtils.java b/scribejava-core/src/main/java/com/github/scribejava/core/utils/MapUtils.java index 9e4badbc3..bf48341fb 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/utils/MapUtils.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/utils/MapUtils.java @@ -2,9 +2,6 @@ import java.util.Map; -/** - * @author Pablo Fernandez - */ public abstract class MapUtils { public static String toString(Map map) { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/utils/OAuthEncoder.java b/scribejava-core/src/main/java/com/github/scribejava/core/utils/OAuthEncoder.java index 498258863..83918e7af 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/utils/OAuthEncoder.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/utils/OAuthEncoder.java @@ -9,9 +9,6 @@ import java.util.regex.Pattern; import com.github.scribejava.core.exceptions.OAuthException; -/** - * @author Pablo Fernandez - */ public abstract class OAuthEncoder { private static final String CHARSET = "UTF-8"; diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/utils/Preconditions.java b/scribejava-core/src/main/java/com/github/scribejava/core/utils/Preconditions.java index 7c6f4ad2c..001982c8d 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/utils/Preconditions.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/utils/Preconditions.java @@ -6,8 +6,6 @@ /** * Utils for checking preconditions and invariants - * - * @author Pablo Fernandez */ public abstract class Preconditions { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/utils/StreamUtils.java b/scribejava-core/src/main/java/com/github/scribejava/core/utils/StreamUtils.java index a87a90b7e..93d089489 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/utils/StreamUtils.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/utils/StreamUtils.java @@ -8,8 +8,6 @@ /** * Utils to deal with Streams. - * - * @author Pablo Fernandez */ public abstract class StreamUtils { 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 073aa4ead..78a22c9f9 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 @@ -6,9 +6,6 @@ import static org.junit.Assert.assertNotSame; -/** - * @author: Pablo Fernandez - */ public class ParameterListTest { private ParameterList params; diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/utils/MapUtilsTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/utils/MapUtilsTest.java index 28f4a8515..dc6bd38d5 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/utils/MapUtilsTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/utils/MapUtilsTest.java @@ -5,9 +5,6 @@ import org.junit.Assert; import org.junit.Test; -/** - * @author: Pablo Fernandez - */ public class MapUtilsTest { @Test 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 cc0b76f09..1a1489b41 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 @@ -3,9 +3,6 @@ import static org.junit.Assert.assertEquals; import org.junit.Test; -/** - * @author: Pablo Fernandez - */ public class OAuthEncoderTest { @Test From f5b8df91a6d49b1585a2801cf0142898ca6c0958 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Sat, 20 Feb 2016 13:14:25 +0300 Subject: [PATCH 137/882] use own compilet regexp Pattern insteand of synchronized using of the common one --- .../constantcontact/ConstantContactTokenExtractor.java | 5 +++-- .../scribejava/apis/google/GoogleJsonTokenExtractor.java | 4 ++-- .../core/extractors/AbstractOAuth1TokenExtractor.java | 8 ++++---- .../core/extractors/OAuth2AccessTokenJsonExtractor.java | 4 ++-- .../com/github/scribejava/core/utils/Preconditions.java | 4 ++-- 5 files changed, 13 insertions(+), 12 deletions(-) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/constantcontact/ConstantContactTokenExtractor.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/constantcontact/ConstantContactTokenExtractor.java index 78b27b2ab..f385eba1d 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/constantcontact/ConstantContactTokenExtractor.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/constantcontact/ConstantContactTokenExtractor.java @@ -10,6 +10,8 @@ public class ConstantContactTokenExtractor implements TokenExtractor { + private static final String REGEXP = "\"access_token\"\\s*:\\s*\"([^&\"]+)\""; + protected ConstantContactTokenExtractor() { } @@ -27,8 +29,7 @@ public OAuth2AccessToken extract(String response) { Preconditions.checkEmptyString(response, "Response body is incorrect. Can't extract a token from an empty string"); - final String regex = "\"access_token\"\\s*:\\s*\"([^&\"]+)\""; - final Matcher matcher = Pattern.compile(regex).matcher(response); + final Matcher matcher = Pattern.compile(REGEXP).matcher(response); if (matcher.find()) { final String token = OAuthEncoder.decode(matcher.group(1)); return new OAuth2AccessToken(token, response); diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/google/GoogleJsonTokenExtractor.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/google/GoogleJsonTokenExtractor.java index f542026b5..13b7cff39 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/google/GoogleJsonTokenExtractor.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/google/GoogleJsonTokenExtractor.java @@ -9,7 +9,7 @@ */ public class GoogleJsonTokenExtractor extends OAuth2AccessTokenJsonExtractor { - private static final Pattern ID_TOKEN_PATTERN = Pattern.compile("\"id_token\"\\s*:\\s*\"(\\S*?)\""); + private static final String REGEXP = "\"id_token\"\\s*:\\s*\"(\\S*?)\""; protected GoogleJsonTokenExtractor() { } @@ -29,7 +29,7 @@ public GoogleToken extract(String response) { } private String extractOpenIdToken(String response) { - final Matcher matcher = ID_TOKEN_PATTERN.matcher(response); + final Matcher matcher = Pattern.compile(REGEXP).matcher(response); if (matcher.find()) { return matcher.group(1); } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/AbstractOAuth1TokenExtractor.java b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/AbstractOAuth1TokenExtractor.java index d0203a927..4d968d83c 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/AbstractOAuth1TokenExtractor.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/AbstractOAuth1TokenExtractor.java @@ -16,8 +16,8 @@ */ public abstract class AbstractOAuth1TokenExtractor implements TokenExtractor { - private static final Pattern TOKEN_REGEX = Pattern.compile("oauth_token=([^&]+)"); - private static final Pattern SECRET_REGEX = Pattern.compile("oauth_token_secret=([^&]*)"); + private static final String OAUTH_TOKEN_REGEXP = "oauth_token=([^&]+)"; + private static final String OAUTH_TOKEN_SECRET_REGEXP = "oauth_token_secret=([^&]*)"; /** * {@inheritDoc} @@ -26,8 +26,8 @@ public abstract class AbstractOAuth1TokenExtractor implem public T extract(String response) { Preconditions.checkEmptyString(response, "Response body is incorrect. Can't extract a token from an empty string"); - final String token = extract(response, TOKEN_REGEX); - final String secret = extract(response, SECRET_REGEX); + final String token = extract(response, Pattern.compile(OAUTH_TOKEN_REGEXP)); + final String secret = extract(response, Pattern.compile(OAUTH_TOKEN_SECRET_REGEXP)); return createToken(token, secret, 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 dc707c8e4..a06e8054d 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractor.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractor.java @@ -8,7 +8,7 @@ public class OAuth2AccessTokenJsonExtractor implements TokenExtractor { - private static final Pattern ACCESS_TOKEN_PATTERN = Pattern.compile("\"access_token\"\\s*:\\s*\"(\\S*?)\""); + private static final String ACCESS_TOKENS_REGEXP = "\"access_token\"\\s*:\\s*\"(\\S*?)\""; protected OAuth2AccessTokenJsonExtractor() { } @@ -29,7 +29,7 @@ public OAuth2AccessToken extract(String response) { protected String extractAccessToken(String response) { Preconditions.checkEmptyString(response, "Cannot extract a token from a null or empty String"); - final Matcher matcher = ACCESS_TOKEN_PATTERN.matcher(response); + final Matcher matcher = Pattern.compile(ACCESS_TOKENS_REGEXP).matcher(response); if (matcher.find()) { return matcher.group(1); } else { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/utils/Preconditions.java b/scribejava-core/src/main/java/com/github/scribejava/core/utils/Preconditions.java index 001982c8d..0858fc89d 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/utils/Preconditions.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/utils/Preconditions.java @@ -12,7 +12,7 @@ public abstract class Preconditions { private static final String DEFAULT_MESSAGE = "Received an invalid parameter"; // scheme = alpha *( alpha | digit | "+" | "-" | "." ) - private static final Pattern URL_PATTERN = Pattern.compile("^[a-zA-Z][a-zA-Z0-9+.-]*://\\S+"); + private static final String URL_REGEXP = "^[a-zA-Z][a-zA-Z0-9+.-]*://\\S+"; /** * Checks that an object is not null. @@ -63,7 +63,7 @@ public static void checkValidOAuthCallback(String url, String errorMsg) { } private static boolean isUrl(String url) { - return URL_PATTERN.matcher(url).matches(); + return Pattern.compile(URL_REGEXP).matcher(url).matches(); } private static void check(boolean requirements, String error) { From de7d8849ebb8e0072f7cc599732721e4c680d035 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Sat, 20 Feb 2016 13:36:47 +0300 Subject: [PATCH 138/882] update changelog --- changelog | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog b/changelog index c2a21fa59..8e7e9690c 100644 --- a/changelog +++ b/changelog @@ -1,7 +1,7 @@ [SNAPSHOT] * Stack Exchange authentication via OAuth 2.0 (stackoverflow.com, askubuntu.com, etc.). * Support response in gzip. - * differentiate OAuth1 Access token, OAuth 1 Request Token and OAuth 2 Access token + * differentiate OAuth1 Access token, OAuth 1 Request Token and OAuth 2 Access token, make them conforms RFCs [2.2.2] * make all APIs to be extentable (have protected constructors, useful for testing) From 72d4ecf1bca4d87a5f335818eabd7639b4c32171 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 25 Feb 2016 11:21:37 +0300 Subject: [PATCH 139/882] update Forks chapter in Readme --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index 59e58dc7f..4004a29af 100644 --- a/README.md +++ b/README.md @@ -103,6 +103,4 @@ Feel free to drop us an email or create issue right here on github.com ## Forks -Looking for a ScribeJava variation? check the [Fork List](https://github.com/scribejava/scribejava/wiki/Forks) - If you have a useful fork that should be listed there please contact us From 0f3993972f62359c659edc384bf6e7c274b1a914 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 25 Feb 2016 13:09:31 +0300 Subject: [PATCH 140/882] conforms OAuth 1.0 Tokens to the last not obsolete specs --- .../core/model/OAuth1AccessToken.java | 24 +++++++++++++-- .../core/model/OAuth1RequestToken.java | 30 +++++++++++++++---- .../scribejava/core/model/OAuth1Token.java | 10 ------- 3 files changed, 47 insertions(+), 17 deletions(-) diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth1AccessToken.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth1AccessToken.java index 838fc2adb..e57a7db39 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth1AccessToken.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth1AccessToken.java @@ -3,11 +3,11 @@ import java.util.Objects; /** - * Represents an OAuth 1 Access Token http://oauth.net/core/1.0a/#rfc.section.6.3.2 + * Represents an OAuth 1 Access Token http://tools.ietf.org/html/rfc5849#section-2.3 */ public class OAuth1AccessToken extends OAuth1Token { - private static final long serialVersionUID = -8784937061938486135L; + private static final long serialVersionUID = -103999293167210966L; public OAuth1AccessToken(String token, String tokenSecret) { this(token, tokenSecret, null); @@ -17,6 +17,26 @@ public OAuth1AccessToken(String token, String tokenSecret, String rawResponse) { super(token, tokenSecret, rawResponse); } + /** + * The token identifier. + * + * @return oauth_token + */ + @Override + public String getToken() { + return super.getToken(); + } + + /** + * The token shared-secret. + * + * @return oauth_token_secret + */ + @Override + public String getTokenSecret() { + return super.getTokenSecret(); + } + @Override public int hashCode() { int hash = 3; diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth1RequestToken.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth1RequestToken.java index b7db7047b..1c53d4932 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth1RequestToken.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth1RequestToken.java @@ -3,17 +3,17 @@ import java.util.Objects; /** - * Represents an OAuth 1 Request Token http://oauth.net/core/1.0a/#rfc.section.6.1.2 + * Represents an OAuth 1 Request Token http://tools.ietf.org/html/rfc5849#section-2.1 */ public class OAuth1RequestToken extends OAuth1Token { - private static final long serialVersionUID = 359527630020350893L; + private static final long serialVersionUID = 6185104114662587991L; /** * oauth_callback_confirmed: *

- * MUST be present and set to true. The Consumer MAY use this to confirm that the Service Provider received the - * callback value.

+ * MUST be present and set to "true". The parameter is used to differentiate from previous versions of the protocol. + *

*/ private final boolean oauthCallbackConfirmed; @@ -30,6 +30,26 @@ public OAuth1RequestToken(String token, String tokenSecret, boolean oauthCallbac this.oauthCallbackConfirmed = oauthCallbackConfirmed; } + /** + * The temporary credentials identifier. + * + * @return oauth_token + */ + @Override + public String getToken() { + return super.getToken(); + } + + /** + * The temporary credentials shared-secret. + * + * @return oauth_token_secret + */ + @Override + public String getTokenSecret() { + return super.getTokenSecret(); + } + public boolean isOauthCallbackConfirmed() { return oauthCallbackConfirmed; } @@ -69,6 +89,6 @@ public String toString() { return "OAuth1RequestToken{" + "oauth_token=" + getToken() + ", oauth_token_secret=" + getTokenSecret() - + ", oauthCallbackConfirmed=" + oauthCallbackConfirmed + '}'; + + ", oauth_callback_confirmed=" + oauthCallbackConfirmed + '}'; } } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth1Token.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth1Token.java index c50fbd29e..3d02f49aa 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth1Token.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth1Token.java @@ -9,18 +9,8 @@ public abstract class OAuth1Token extends Token { private static final long serialVersionUID = 6285873427974823019L; - /** - * oauth_token: - *

- * The Request/Access Token.

- */ private final String token; - /** - * oauth_token_secret: - *

- * The Token Secret.

- */ private final String tokenSecret; public OAuth1Token(String token, String tokenSecret, String rawResponse) { From f7f390a8cfaaabcc6416a94a375e60955b31f9d0 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 25 Feb 2016 13:26:51 +0300 Subject: [PATCH 141/882] OAuth 1 APIs can choose whether to pass empty oauth_token param in requests --- changelog | 1 + .../scribejava/core/builder/api/DefaultApi10a.java | 10 ++++++++++ .../github/scribejava/core/oauth/OAuth10aService.java | 3 +-- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/changelog b/changelog index 8e7e9690c..795257fae 100644 --- a/changelog +++ b/changelog @@ -2,6 +2,7 @@ * Stack Exchange authentication via OAuth 2.0 (stackoverflow.com, askubuntu.com, etc.). * Support response in gzip. * differentiate OAuth1 Access token, OAuth 1 Request Token and OAuth 2 Access token, make them conforms RFCs + * OAuth 1 APIs can choose whether to pass empty oauth_token param in requests [2.2.2] * make all APIs to be extentable (have protected constructors, useful for testing) diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi10a.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi10a.java index 89d1eb499..f0920e103 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi10a.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi10a.java @@ -129,4 +129,14 @@ public Verb getRequestTokenVerb() { public OAuth10aService createService(OAuthConfig config) { return new OAuth10aService(this, config); } + + /** + * http://tools.ietf.org/html/rfc5849 says that "The client MAY omit the empty "oauth_token" protocol parameter from + * the request", but not all oauth servers are good boys. + * + * @return whether to inlcude empty oauth_token param to the request + */ + public boolean isEmptyOAuthTokenParamIsRequired() { + return false; + } } 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 76b076935..ad9347448 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 @@ -130,8 +130,7 @@ public void signRequest(OAuth1AccessToken token, AbstractRequest request) { final OAuthConfig config = getConfig(); config.log("signing request: " + request.getCompleteUrl()); - // Do not append the token if empty. This is for two legged OAuth calls. - if (!token.isEmpty()) { + if (!token.isEmpty() || api.isEmptyOAuthTokenParamIsRequired()) { request.addOAuthParameter(OAuthConstants.TOKEN, token.getToken()); } config.log("setting token to: " + token); From 18c1d06234015e7d2e79a9e8ac82f4b32da17de5 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 25 Feb 2016 16:30:23 +0300 Subject: [PATCH 142/882] extract all oauth token params from response --- .../apis/google/GoogleJsonTokenExtractor.java | 19 +++----- .../scribejava/apis/google/GoogleToken.java | 9 +++- .../OAuth2AccessTokenExtractor.java | 33 +++++++++++--- .../OAuth2AccessTokenJsonExtractor.java | 45 ++++++++++++++++--- .../OAuth2AccessTokenExtractorTest.java | 15 ++++++- 5 files changed, 92 insertions(+), 29 deletions(-) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/google/GoogleJsonTokenExtractor.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/google/GoogleJsonTokenExtractor.java index 13b7cff39..9cac46623 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/google/GoogleJsonTokenExtractor.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/google/GoogleJsonTokenExtractor.java @@ -1,15 +1,14 @@ package com.github.scribejava.apis.google; -import java.util.regex.Matcher; -import java.util.regex.Pattern; import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; +import com.github.scribejava.core.model.OAuth2AccessToken; /** * additionally parses OpenID id_token */ public class GoogleJsonTokenExtractor extends OAuth2AccessTokenJsonExtractor { - private static final String REGEXP = "\"id_token\"\\s*:\\s*\"(\\S*?)\""; + private static final String ID_TOKEN_REGEX = "\"id_token\"\\s*:\\s*\"(\\S*?)\""; protected GoogleJsonTokenExtractor() { } @@ -24,15 +23,9 @@ public static GoogleJsonTokenExtractor instance() { } @Override - public GoogleToken extract(String response) { - return new GoogleToken(extractAccessToken(response), extractOpenIdToken(response), response); - } - - private String extractOpenIdToken(String response) { - final Matcher matcher = Pattern.compile(REGEXP).matcher(response); - if (matcher.find()) { - return matcher.group(1); - } - return null; + protected OAuth2AccessToken createToken(String accessToken, String tokenType, Integer expiresIn, + String refreshToken, String scope, String response) { + return new GoogleToken(accessToken, tokenType, expiresIn, refreshToken, scope, + extractParameter(response, ID_TOKEN_REGEX, false), response); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/google/GoogleToken.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/google/GoogleToken.java index 1afe0b084..a47395571 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/google/GoogleToken.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/google/GoogleToken.java @@ -5,7 +5,7 @@ public class GoogleToken extends OAuth2AccessToken { - private static final long serialVersionUID = 6150970703986214220L; + private static final long serialVersionUID = 7845679917727899612L; /** * Id_token is part of OpenID Connect specification. It can hold user information that you can directly extract @@ -19,7 +19,12 @@ public class GoogleToken extends OAuth2AccessToken { private final String openIdToken; public GoogleToken(String accessToken, String openIdToken, String rawResponse) { - super(accessToken, rawResponse); + this(accessToken, null, null, null, null, openIdToken, rawResponse); + } + + public GoogleToken(String accessToken, String tokenType, Integer expiresIn, String refreshToken, String scope, + String openIdToken, String rawResponse) { + super(accessToken, tokenType, expiresIn, refreshToken, scope, rawResponse); this.openIdToken = openIdToken; } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenExtractor.java b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenExtractor.java index 928f9f4d8..dd80c0012 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenExtractor.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenExtractor.java @@ -12,7 +12,11 @@ */ public class OAuth2AccessTokenExtractor implements TokenExtractor { - private static final String TOKEN_REGEX = "access_token=([^&]+)"; + private static final String ACCESS_TOKEN_REGEX = "access_token=([^&]+)"; + private static final String TOKEN_TYPE_REGEX = "token_type=([^&]+)"; + private static final String EXPIRES_IN_REGEX = "expires_in=([^&]+)"; + private static final String REFRESH_TOKEN_REGEX = "refresh_token=([^&]+)"; + private static final String SCOPE_REGEX = "scope=([^&]+)"; protected OAuth2AccessTokenExtractor() { } @@ -34,13 +38,30 @@ public OAuth2AccessToken extract(String response) { Preconditions.checkEmptyString(response, "Response body is incorrect. Can't extract a token from an empty string"); - final Matcher matcher = Pattern.compile(TOKEN_REGEX).matcher(response); + final String accessToken = extractParameter(response, ACCESS_TOKEN_REGEX, true); + final String tokenType = extractParameter(response, TOKEN_TYPE_REGEX, false); + final String expiresInString = extractParameter(response, EXPIRES_IN_REGEX, false); + Integer expiresIn; + try { + expiresIn = expiresInString == null ? null : Integer.valueOf(expiresInString); + } catch (NumberFormatException nfe) { + expiresIn = null; + } + final String refreshToken = extractParameter(response, REFRESH_TOKEN_REGEX, false); + final String scope = extractParameter(response, SCOPE_REGEX, false); + + return new OAuth2AccessToken(accessToken, tokenType, expiresIn, refreshToken, scope, response); + } + + private static String extractParameter(String response, String regex, boolean required) throws OAuthException { + final Matcher matcher = Pattern.compile(regex).matcher(response); if (matcher.find()) { - final String token = OAuthEncoder.decode(matcher.group(1)); - return new OAuth2AccessToken(token, response); + return OAuthEncoder.decode(matcher.group(1)); + } else if (required) { + throw new OAuthException("Response body is incorrect. Can't extract a '" + regex + + "' from this: '" + response + "'", null); } else { - throw new OAuthException("Response body is incorrect. Can't extract a token from this: '" + response + "'", - null); + return null; } } } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractor.java b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractor.java index a06e8054d..514f38610 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 @@ -6,9 +6,16 @@ import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.utils.Preconditions; +/** + * JSON implementation of {@link TokenExtractor} for OAuth 2.0 + */ public class OAuth2AccessTokenJsonExtractor implements TokenExtractor { - private static final String ACCESS_TOKENS_REGEXP = "\"access_token\"\\s*:\\s*\"(\\S*?)\""; + private static final String ACCESS_TOKEN_REGEX = "\"access_token\"\\s*:\\s*\"(\\S*?)\""; + private static final String TOKEN_TYPE_REGEX = "\"token_type\"\\s*:\\s*\"(\\S*?)\""; + private static final String EXPIRES_IN_REGEX = "\"expires_in\"\\s*:\\s*\"?(\\d*?)\"?\\D"; + private static final String REFRESH_TOKEN_REGEX = "\"refresh_token\"\\s*:\\s*\"(\\S*?)\""; + private static final String SCOPE_REGEX = "\"scope\"\\s*:\\s*\"(\\S*?)\""; protected OAuth2AccessTokenJsonExtractor() { } @@ -24,16 +31,40 @@ public static OAuth2AccessTokenJsonExtractor instance() { @Override public OAuth2AccessToken extract(String response) { - return new OAuth2AccessToken(extractAccessToken(response), response); + Preconditions.checkEmptyString(response, + "Response body is incorrect. Can't extract a token from an empty string"); + + final String accessToken = extractParameter(response, ACCESS_TOKEN_REGEX, true); + final String tokenType = extractParameter(response, TOKEN_TYPE_REGEX, false); + final String expiresInString = extractParameter(response, EXPIRES_IN_REGEX, false); + Integer expiresIn; + try { + expiresIn = expiresInString == null ? null : Integer.valueOf(expiresInString); + } catch (NumberFormatException nfe) { + expiresIn = null; + } + final String refreshToken = extractParameter(response, REFRESH_TOKEN_REGEX, false); + final String scope = extractParameter(response, SCOPE_REGEX, false); + + return createToken(accessToken, tokenType, expiresIn, refreshToken, scope, response); + } + + protected OAuth2AccessToken createToken(String accessToken, String tokenType, Integer expiresIn, + String refreshToken, String scope, String response) { + return new OAuth2AccessToken(accessToken, tokenType, expiresIn, refreshToken, scope, response); } - protected String extractAccessToken(String response) { - Preconditions.checkEmptyString(response, "Cannot extract a token from a null or empty String"); - final Matcher matcher = Pattern.compile(ACCESS_TOKENS_REGEXP).matcher(response); + protected static String extractParameter(String response, String regex, boolean required) throws OAuthException { + final Matcher matcher = Pattern.compile(regex).matcher(response); if (matcher.find()) { return matcher.group(1); - } else { - throw new OAuthException("Cannot extract an access token. Response was: " + response); } + + if (required) { + throw new OAuthException("Response body is incorrect. Can't extract a '" + regex + + "' from this: '" + response + "'", null); + } + + return null; } } 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 8ed1707b3..fa66956d5 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 @@ -27,10 +27,23 @@ public void shouldExtractTokenFromOAuthStandardResponse() { @Test public void shouldExtractTokenFromResponseWithExpiresParam() { final String response = "access_token=166942940015970|2.2ltzWXYNDjCtg5ZDVVJJeg__.3600.1295816400-548517159" - + "|RsXNdKrpxg8L6QNLWcs2TVTmcaE&expires=5108"; + + "|RsXNdKrpxg8L6QNLWcs2TVTmcaE&expires_in=5108"; final OAuth2AccessToken extracted = extractor.extract(response); assertEquals("166942940015970|2.2ltzWXYNDjCtg5ZDVVJJeg__.3600.1295816400-548517159|RsXNdKrpxg8L6QNLWcs2TVTmcaE", extracted.getAccessToken()); + assertEquals(Integer.valueOf(5108), extracted.getExpiresIn()); + } + + @Test + public void shouldExtractTokenFromResponseWithExpiresAndRefreshParam() { + final String response = "access_token=166942940015970|2.2ltzWXYNDjCtg5ZDVVJJeg__.3600.1295816400-548517159" + + "|RsXNdKrpxg8L6QNLWcs2TVTmcaE&expires_in=5108&token_type=bearer&refresh_token=166942940015970"; + final OAuth2AccessToken extracted = extractor.extract(response); + assertEquals("166942940015970|2.2ltzWXYNDjCtg5ZDVVJJeg__.3600.1295816400-548517159|RsXNdKrpxg8L6QNLWcs2TVTmcaE", + extracted.getAccessToken()); + assertEquals(Integer.valueOf(5108), extracted.getExpiresIn()); + assertEquals("bearer", extracted.getTokenType()); + assertEquals("166942940015970", extracted.getRefreshToken()); } @Test From a2cea9b4fad141e9adad6e799d1257f0a91c4176 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 25 Feb 2016 16:34:41 +0300 Subject: [PATCH 143/882] show accessToken rawResponse in examples --- .../com/github/scribejava/apis/examples/AWeberExample.java | 3 ++- .../java/com/github/scribejava/apis/examples/DiggExample.java | 3 ++- .../github/scribejava/apis/examples/FacebookAsyncExample.java | 3 ++- .../com/github/scribejava/apis/examples/FacebookExample.java | 3 ++- .../com/github/scribejava/apis/examples/FlickrExample.java | 3 ++- .../github/scribejava/apis/examples/Foursquare2Example.java | 3 ++- .../github/scribejava/apis/examples/FoursquareExample.java | 3 ++- .../github/scribejava/apis/examples/FreelancerExample.java | 3 ++- .../com/github/scribejava/apis/examples/GitHubExample.java | 3 ++- .../com/github/scribejava/apis/examples/Google20Example.java | 3 ++- .../com/github/scribejava/apis/examples/GoogleExample.java | 3 ++- .../java/com/github/scribejava/apis/examples/HHExample.java | 3 ++- .../com/github/scribejava/apis/examples/ImgurExample.java | 3 ++- .../com/github/scribejava/apis/examples/Kaixin20Example.java | 3 ++- .../github/scribejava/apis/examples/LinkedIn20Example.java | 3 ++- .../com/github/scribejava/apis/examples/LinkedInExample.java | 3 ++- .../scribejava/apis/examples/LinkedInExampleWithScopes.java | 3 ++- .../java/com/github/scribejava/apis/examples/LiveExample.java | 3 ++- .../com/github/scribejava/apis/examples/LoveFilmExample.java | 3 ++- .../github/scribejava/apis/examples/MailruAsyncExample.java | 3 ++- .../com/github/scribejava/apis/examples/MailruExample.java | 3 ++- .../com/github/scribejava/apis/examples/MeetupExample.java | 3 ++- .../github/scribejava/apis/examples/NeteaseWeiboExample.java | 4 ++-- .../github/scribejava/apis/examples/OdnoklassnikiExample.java | 3 ++- .../com/github/scribejava/apis/examples/PinterestExample.java | 3 ++- .../com/github/scribejava/apis/examples/Px500Example.java | 3 ++- .../com/github/scribejava/apis/examples/RenrenExample.java | 3 ++- .../github/scribejava/apis/examples/SinaWeibo2Example.java | 3 ++- .../com/github/scribejava/apis/examples/SinaWeiboExample.java | 4 ++-- .../com/github/scribejava/apis/examples/SkyrockExample.java | 3 ++- .../com/github/scribejava/apis/examples/SohuWeiboExample.java | 4 ++-- .../github/scribejava/apis/examples/StackExchangeExample.java | 3 ++- .../com/github/scribejava/apis/examples/TrelloExample.java | 3 ++- .../com/github/scribejava/apis/examples/TumblrExample.java | 3 ++- .../com/github/scribejava/apis/examples/TutByExample.java | 3 ++- .../com/github/scribejava/apis/examples/TwitterExample.java | 3 ++- .../com/github/scribejava/apis/examples/ViadeoExample.java | 3 ++- .../com/github/scribejava/apis/examples/VkontakteExample.java | 3 ++- .../java/com/github/scribejava/apis/examples/XingExample.java | 3 ++- .../com/github/scribejava/apis/examples/YahooExample.java | 3 ++- 40 files changed, 80 insertions(+), 43 deletions(-) diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AWeberExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AWeberExample.java index d1478b901..505f29e1d 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AWeberExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AWeberExample.java @@ -47,7 +47,8 @@ public static void main(String... args) { System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, verifier); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken + " )"); + System.out.println("(if your curious it looks like this: " + accessToken + + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiggExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiggExample.java index e0e7ae8cc..f6ce3702e 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiggExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiggExample.java @@ -50,7 +50,8 @@ public static void main(String... args) { System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, verifier); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken + " )"); + System.out.println("(if your curious it looks like this: " + accessToken + + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncExample.java index d610596ab..a8075e9a1 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncExample.java @@ -74,7 +74,8 @@ public static void main(String... args) throws InterruptedException, ExecutionEx System.out.println("Trading the Request Token for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessTokenAsync(verifier, null).get(); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken + " )"); + System.out.println("(if your curious it looks like this: " + accessToken + + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java index 137ec6507..b199df0d7 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java @@ -59,7 +59,8 @@ public static void main(String... args) { System.out.println("Trading the Request Token for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(verifier); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken + " )"); + System.out.println("(if your curious it looks like this: " + accessToken + + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExample.java index 2f6724777..30a8d1a07 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExample.java @@ -46,7 +46,8 @@ public static void main(String... args) { System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, verifier); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken + " )"); + System.out.println("(if your curious it looks like this: " + accessToken + + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java index 17c37f5a9..7f5e61a6b 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java @@ -44,7 +44,8 @@ public static void main(String... args) { System.out.println("Trading the Request Token for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(verifier); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken + " )"); + System.out.println("(if your curious it looks like this: " + accessToken + + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FoursquareExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FoursquareExample.java index fe6f60e13..7c48e71d5 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FoursquareExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FoursquareExample.java @@ -42,7 +42,8 @@ public static void main(String... args) { System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, verifier); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken + " )"); + System.out.println("(if your curious it looks like this: " + accessToken + + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java index a135f94f1..46224cb3c 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java @@ -50,7 +50,8 @@ public static void main(String... args) { System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, verifier); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken + " )"); + System.out.println("(if your curious it looks like this: " + accessToken + + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubExample.java index 889c505a8..bbf78434c 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubExample.java @@ -59,7 +59,8 @@ public static void main(String... args) { System.out.println("Trading the Request Token for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(verifier); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken + " )"); + System.out.println("(if your curious it looks like this: " + accessToken + + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java index f4fc5dec3..e9d2e29fe 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java @@ -60,7 +60,8 @@ public static void main(String... args) { System.out.println("Trading the Request Token for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(verifier); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken + " )"); + System.out.println("(if your curious it looks like this: " + accessToken + + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GoogleExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GoogleExample.java index 19e249d9f..205cd37a8 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GoogleExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GoogleExample.java @@ -47,7 +47,8 @@ public static void main(String... args) { System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, verifier); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken + " )"); + System.out.println("(if your curious it looks like this: " + accessToken + + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HHExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HHExample.java index 9e91e301e..9477ea363 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HHExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HHExample.java @@ -47,7 +47,8 @@ public static void main(String... args) { System.out.println("Trading the Request Token for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(verifier); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken + " )"); + System.out.println("(if your curious it looks like this: " + accessToken + + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); System.out.println(); System.out.println("Now we're going to access a protected resource..."); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ImgurExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ImgurExample.java index fd3870708..01409fbb6 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ImgurExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ImgurExample.java @@ -44,7 +44,8 @@ public static void main(String... args) { System.out.println("Trading the Request Token for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(verifier); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken + " )"); + System.out.println("(if your curious it looks like this: " + accessToken + + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Kaixin20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Kaixin20Example.java index 3f79d4d51..17f5ac0fb 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Kaixin20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Kaixin20Example.java @@ -44,7 +44,8 @@ public static void main(String... args) { System.out.println("Trading the Request Token for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(verifier); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken + " )"); + System.out.println("(if your curious it looks like this: " + accessToken + + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! 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 2232e3dc8..e4506b374 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 @@ -45,7 +45,8 @@ public static void main(String... args) { System.out.println("Trading the Request Token for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(verifier); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken + " )"); + System.out.println("(if your curious it looks like this: " + accessToken + + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java index e026c969a..5489688c8 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java @@ -43,7 +43,8 @@ public static void main(String... args) { System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, verifier); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken + " )"); + System.out.println("(if your curious it looks like this: " + accessToken + + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java index e24d39747..17a0d6aaf 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java @@ -47,7 +47,8 @@ public static void main(String... args) { System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, verifier); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken + " )"); + System.out.println("(if your curious it looks like this: " + accessToken + + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java index 199bb111a..47536186e 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java @@ -45,7 +45,8 @@ public static void main(String... args) { System.out.println("Trading the Request Token for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(verifier); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken + " )"); + System.out.println("(if your curious it looks like this: " + accessToken + + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LoveFilmExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LoveFilmExample.java index 46db1f3ba..55a22b416 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LoveFilmExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LoveFilmExample.java @@ -50,7 +50,8 @@ public static void main(String... args) { System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, verifier); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken + " )"); + System.out.println("(if your curious it looks like this: " + accessToken + + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java index f0824d2a7..981690be6 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java @@ -58,7 +58,8 @@ public static void main(String... args) throws InterruptedException, ExecutionEx System.out.println("Trading the Request Token for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessTokenAsync(verifier, null).get(); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken + " )"); + System.out.println("(if your curious it looks like this: " + accessToken + + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); System.out.println(); System.out.println("Now we're going to access a protected resource..."); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java index 6e0ac27c8..4d25f14c2 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java @@ -46,7 +46,8 @@ public static void main(String... args) { System.out.println("Trading the Request Token for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(verifier); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken + " )"); + System.out.println("(if your curious it looks like this: " + accessToken + + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); System.out.println(); System.out.println("Now we're going to access a protected resource..."); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java index 6a19c459d..3028349ce 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java @@ -42,7 +42,8 @@ public static void main(String... args) { System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, verifier); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken + " )"); + System.out.println("(if your curious it looks like this: " + accessToken + + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NeteaseWeiboExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NeteaseWeiboExample.java index e5130908f..60f8082e3 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NeteaseWeiboExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NeteaseWeiboExample.java @@ -50,8 +50,8 @@ public static void main(String... args) { System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, verifier); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " - + accessToken + " )"); + System.out.println("(if your curious it looks like this: " + accessToken + + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java index a7b1b9710..136b05774 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java @@ -52,7 +52,8 @@ public static void main(String... args) { final OAuth2AccessToken accessToken = service.getAccessToken(verifier); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken + " )"); + System.out.println("(if your curious it looks like this: " + accessToken + + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java index 3860ebfb4..3e0d1cb4b 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java @@ -45,7 +45,8 @@ public static void main(String... args) { System.out.println("Trading the Request Token for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(verifier); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken + " )"); + System.out.println("(if your curious it looks like this: " + accessToken + + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Px500Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Px500Example.java index 9d366e38d..3e969fd06 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Px500Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Px500Example.java @@ -42,7 +42,8 @@ public static void main(String... args) { System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, verifier); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken + " )"); + System.out.println("(if your curious it looks like this: " + accessToken + + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java index 48f37ad17..392ff3881 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java @@ -54,7 +54,8 @@ public static void main(String... args) { System.out.println("Trading the Request Token for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(verifier); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken + " )"); + System.out.println("(if your curious it looks like this: " + accessToken + + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeibo2Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeibo2Example.java index 33e46454e..230f28875 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeibo2Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeibo2Example.java @@ -44,7 +44,8 @@ public static void main(String... args) { System.out.println("Trading the Request Token for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(verifier); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken + " )"); + System.out.println("(if your curious it looks like this: " + accessToken + + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeiboExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeiboExample.java index f6ddf99e2..42962c6ed 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeiboExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeiboExample.java @@ -50,8 +50,8 @@ public static void main(String... args) { System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, verifier); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " - + accessToken + " )"); + System.out.println("(if your curious it looks like this: " + accessToken + + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SkyrockExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SkyrockExample.java index 3c0a8655a..c90e658d2 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SkyrockExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SkyrockExample.java @@ -42,7 +42,8 @@ public static void main(String... args) { System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, verifier); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken + " )"); + System.out.println("(if your curious it looks like this: " + accessToken + + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SohuWeiboExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SohuWeiboExample.java index 3f39264fa..9bd89762d 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SohuWeiboExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SohuWeiboExample.java @@ -50,8 +50,8 @@ public static void main(String... args) { System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, verifier); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " - + accessToken + " )"); + System.out.println("(if your curious it looks like this: " + accessToken + + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/StackExchangeExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/StackExchangeExample.java index c6f8a4288..47d43168e 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/StackExchangeExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/StackExchangeExample.java @@ -64,7 +64,8 @@ public static void main(String... args) { System.out.println("Trading the Request Token for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(verifier); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken + " )"); + System.out.println("(if your curious it looks like this: " + accessToken + + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TrelloExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TrelloExample.java index c2076371f..1c274a060 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TrelloExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TrelloExample.java @@ -44,7 +44,8 @@ public static void main(String... args) { System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, verifier); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken + " )"); + System.out.println("(if your curious it looks like this: " + accessToken + + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TumblrExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TumblrExample.java index 2b1b32f9d..413214eec 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TumblrExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TumblrExample.java @@ -44,7 +44,8 @@ public static void main(String... args) { System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, verifier); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken + " )"); + System.out.println("(if your curious it looks like this: " + accessToken + + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TutByExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TutByExample.java index c3c7075a2..74ae83af9 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TutByExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TutByExample.java @@ -47,7 +47,8 @@ public static void main(String... args) { System.out.println("Trading the Request Token for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(verifier); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken + " )"); + System.out.println("(if your curious it looks like this: " + accessToken + + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TwitterExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TwitterExample.java index 1c26e836b..90446f8a6 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TwitterExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TwitterExample.java @@ -42,7 +42,8 @@ public static void main(String... args) { System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, verifier); System.out.println("Got the Access Token!"); - System.out.println("(if you're curious it looks like this: " + accessToken + " )"); + System.out.println("(if your curious it looks like this: " + accessToken + + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ViadeoExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ViadeoExample.java index 76516ee91..caffce403 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ViadeoExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ViadeoExample.java @@ -44,7 +44,8 @@ public static void main(String... args) { System.out.println("Trading the Request Token for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(verifier); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken + " )"); + System.out.println("(if your curious it looks like this: " + accessToken + + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! 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 5213a1b05..d9be140d5 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 @@ -45,7 +45,8 @@ public static void main(String... args) { System.out.println("Trading the Request Token for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(verifier); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken + " )"); + System.out.println("(if your curious it looks like this: " + accessToken + + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XingExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XingExample.java index 5542c34cc..c09b1ddc3 100755 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XingExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XingExample.java @@ -42,7 +42,8 @@ public static void main(String... args) { System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, verifier); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken + " )"); + System.out.println("(if your curious it looks like this: " + accessToken + + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/YahooExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/YahooExample.java index e2cda508c..d6f8e2e72 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/YahooExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/YahooExample.java @@ -43,7 +43,8 @@ public static void main(String... args) { System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, verifier); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken + " )"); + System.out.println("(if your curious it looks like this: " + accessToken + + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! From 23e7f930f5e64067669a6365bcebd06050fec856 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 26 Feb 2016 14:23:29 +0300 Subject: [PATCH 144/882] allow to pass any additional params to auth url --- .../core/builder/api/DefaultApi20.java | 29 +++++++++++++++++++ .../scribejava/core/oauth/OAuth20Service.java | 15 ++++++++-- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java index c789da72a..fe07dbf6c 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java @@ -6,6 +6,8 @@ import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.oauth.OAuth20Service; +import com.github.scribejava.core.utils.OAuthEncoder; +import java.util.Map; /** * Default implementation of the OAuth protocol, version 2.0 (draft 11) @@ -55,6 +57,33 @@ public Verb getAccessTokenVerb() { */ public abstract String getAuthorizationUrl(OAuthConfig config); + /** + * Returns the URL where you should redirect your users to authenticate your application. + * + * @param config OAuth 2.0 configuration param object + * @param additionalParams any additional GET params to add to the URL + * @return the URL where you should redirect your users + */ + public String getAuthorizationUrl(OAuthConfig config, Map additionalParams) { + String authUrl = getAuthorizationUrl(config); + + if (additionalParams != null && !additionalParams.isEmpty()) { + final StringBuilder authUrlWithParams = new StringBuilder(authUrl) + .append(authUrl.indexOf('?') == -1 ? '?' : '&'); + + for (Map.Entry param : additionalParams.entrySet()) { + authUrlWithParams.append(OAuthEncoder.encode(param.getKey())) + .append('=') + .append(OAuthEncoder.encode(param.getValue())) + .append('&'); + } + + authUrl = authUrlWithParams.substring(0, authUrlWithParams.length() - 1); + } + + return authUrl; + } + public OAuth20Service createService(OAuthConfig config) { return new OAuth20Service(this, config); } 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 84ae8a8ef..4eecefa1f 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java @@ -13,6 +13,7 @@ import com.github.scribejava.core.model.OAuthRequestAsync; import com.github.scribejava.core.model.Response; import com.github.scribejava.core.model.Verifier; +import java.util.Map; public class OAuth20Service extends OAuthService { @@ -94,8 +95,18 @@ public void signRequest(OAuth2AccessToken accessToken, AbstractRequest request) * * @return the URL where you should redirect your users */ - public String getAuthorizationUrl() { - return api.getAuthorizationUrl(getConfig()); + public final String getAuthorizationUrl() { + return getAuthorizationUrl(null); + } + + /** + * 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 api.getAuthorizationUrl(getConfig(), additionalParams); } public DefaultApi20 getApi() { From 1e4238bc1f2aa490b8c142b976e3087303f63a4a Mon Sep 17 00:00:00 2001 From: Daniel Tyreus Date: Wed, 13 Jan 2016 17:53:38 -0800 Subject: [PATCH 145/882] support OAuth 2 refresh token (+update urls for Google) --- changelog | 1 + .../github/scribejava/apis/FacebookApi.java | 4 +-- .../github/scribejava/apis/GoogleApi20.java | 2 +- .../scribejava/apis/NeteaseWeibooApi.java | 3 +- .../apis/examples/FacebookExample.java | 1 + .../apis/examples/Google20Example.java | 18 ++++++++-- .../core/model/OAuth2AccessToken.java | 6 +++- .../scribejava/core/model/OAuthConstants.java | 2 +- .../core/oauth/OAuth10aService.java | 26 ++++++-------- .../scribejava/core/oauth/OAuth20Service.java | 36 +++++++++++++++++++ 10 files changed, 76 insertions(+), 23 deletions(-) diff --git a/changelog b/changelog index 795257fae..1904d9081 100644 --- a/changelog +++ b/changelog @@ -3,6 +3,7 @@ * Support response in gzip. * differentiate OAuth1 Access token, OAuth 1 Request Token and OAuth 2 Access token, make them conforms RFCs * OAuth 1 APIs can choose whether to pass empty oauth_token param in requests + * Support refresh tokens for OAuth2 (very thanks to P. Daniel Tyreus https://github.com/pdtyreus) [2.2.2] * make all APIs to be extentable (have protected constructors, useful for testing) 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 ec0acd245..c3f3bfcea 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 @@ -9,9 +9,8 @@ import com.github.scribejava.core.utils.OAuthEncoder; import com.github.scribejava.core.utils.Preconditions; -/*** +/** * Facebook v2.5 API - * */ public class FacebookApi extends DefaultApi20 { @@ -22,6 +21,7 @@ protected FacebookApi() { } private static class InstanceHolder { + private static final FacebookApi INSTANCE = new FacebookApi(); } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/GoogleApi20.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/GoogleApi20.java index cde5105a0..9e02c0cfa 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/GoogleApi20.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/GoogleApi20.java @@ -34,7 +34,7 @@ public Verb getAccessTokenVerb() { @Override public String getAccessTokenEndpoint() { - return "https://accounts.google.com/o/oauth2/token"; + return "https://www.googleapis.com/oauth2/v4/token"; } @Override diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/NeteaseWeibooApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/NeteaseWeibooApi.java index 317d1e74e..91edb38ca 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/NeteaseWeibooApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/NeteaseWeibooApi.java @@ -32,14 +32,15 @@ public String getAccessTokenEndpoint() { return ACCESS_TOKEN_URL; } - @Override /** * this method will ignore your callback if you're creating a desktop client please choose this url else your can * call getAuthenticateUrl * * via * http://open.t.163.com/wiki/index.php?title=%E8%AF%B7%E6%B1%82%E7%94%A8%E6%88%B7%E6%8E%88%E6%9D%83Token(oauth/authorize) + * @return url to redirect user to (to get code) */ + @Override public String getAuthorizationUrl(OAuth1RequestToken requestToken) { return String.format(AUTHORIZE_URL, requestToken.getToken()); } diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java index b199df0d7..a7d4a76f4 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java @@ -27,6 +27,7 @@ public static void main(String... args) { .state(secretState) .callback("http://www.example.com/oauth_callback/") .build(FacebookApi.instance()); + final Scanner in = new Scanner(System.in, "UTF-8"); System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java index e9d2e29fe..964560044 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java @@ -10,6 +10,8 @@ import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuth20Service; +import java.util.HashMap; +import java.util.Map; public abstract class Google20Example { @@ -35,7 +37,13 @@ public static void main(String... args) { // Obtain the Authorization URL System.out.println("Fetching the Authorization URL..."); - final String authorizationUrl = service.getAuthorizationUrl(); + //pass access_type=offline to get refresh token + //https://developers.google.com/identity/protocols/OAuth2WebServer#preparing-to-start-the-oauth-20-flow + final Map additionalParams = new HashMap<>(); + additionalParams.put("access_type", "offline"); + //force to reget refresh token (if usera are asked not the first time) + additionalParams.put("prompt", "consent"); + final String authorizationUrl = service.getAuthorizationUrl(additionalParams); System.out.println("Got the Authorization URL!"); System.out.println("Now go and authorize ScribeJava here:"); System.out.println(authorizationUrl); @@ -58,8 +66,14 @@ public static void main(String... args) { // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - final OAuth2AccessToken accessToken = service.getAccessToken(verifier); + OAuth2AccessToken accessToken = service.getAccessToken(verifier); System.out.println("Got the Access Token!"); + System.out.println("(if your curious it looks like this: " + accessToken + + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + + System.out.println("Refreshing the Access Token..."); + accessToken = service.refreshAccessToken(accessToken.getRefreshToken()); + System.out.println("Refreshed the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); System.out.println(); 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 5205aa64f..b97e4e0a0 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 @@ -4,7 +4,11 @@ import java.util.Objects; /** - * Represents an OAuth 2 Access Token http://tools.ietf.org/html/rfc6749#section-5.1 + * 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 { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConstants.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConstants.java index 229392c38..4648b24e1 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConstants.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConstants.java @@ -20,7 +20,6 @@ public interface OAuthConstants { String OUT_OF_BAND = "oob"; String VERIFIER = "oauth_verifier"; String HEADER = "Authorization"; - OAuth1RequestToken EMPTY_TOKEN = new OAuth1RequestToken("", ""); String SCOPE = "scope"; // OAuth 2.0 @@ -29,6 +28,7 @@ public interface OAuthConstants { String CLIENT_SECRET = "client_secret"; String REDIRECT_URI = "redirect_uri"; String CODE = "code"; + String REFRESH_TOKEN = "refresh_token"; String GRANT_TYPE = "grant_type"; String AUTHORIZATION_CODE = "authorization_code"; String STATE = "state"; 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 ad9347448..b03001d77 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 @@ -8,7 +8,6 @@ import com.github.scribejava.core.model.AbstractRequest; import com.github.scribejava.core.model.OAuth1AccessToken; import com.github.scribejava.core.model.OAuth1RequestToken; -import com.github.scribejava.core.model.OAuth1Token; import com.github.scribejava.core.model.OAuthAsyncRequestCallback; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; @@ -50,7 +49,7 @@ public OAuth1RequestToken getRequestToken() { config.log("setting oauth_callback to " + config.getCallback()); request.addOAuthParameter(OAuthConstants.CALLBACK, config.getCallback()); - addOAuthParams(request, OAuthConstants.EMPTY_TOKEN); + addOAuthParams(request, ""); appendSignature(request); config.log("sending request..."); @@ -62,7 +61,7 @@ public OAuth1RequestToken getRequestToken() { return api.getRequestTokenExtractor().extract(body); } - private void addOAuthParams(AbstractRequest request, OAuth1Token token) { + private void addOAuthParams(AbstractRequest request, String tokenSecret) { final OAuthConfig config = getConfig(); request.addOAuthParameter(OAuthConstants.TIMESTAMP, api.getTimestampService().getTimestampInSeconds()); request.addOAuthParameter(OAuthConstants.NONCE, api.getTimestampService().getNonce()); @@ -72,7 +71,7 @@ private void addOAuthParams(AbstractRequest request, OAuth1Token token) { if (config.hasScope()) { request.addOAuthParameter(OAuthConstants.SCOPE, config.getScope()); } - request.addOAuthParameter(OAuthConstants.SIGNATURE, getSignature(request, token)); + request.addOAuthParameter(OAuthConstants.SIGNATURE, getSignature(request, tokenSecret)); config.log("appended additional OAuth parameters: " + MapUtils.toString(request.getOauthParameters())); } @@ -87,8 +86,8 @@ public final OAuth1AccessToken getAccessToken(OAuth1RequestToken requestToken, V } /** - * Start the request to retrieve the access token. The optionally provided callback will be called with the Token - * when it is available. + * Start the request to retrieve the access token. The optionally provided + * callback will be called with the Token when it is available. * * @param requestToken request token (obtained previously or null) * @param verifier verifier code @@ -122,7 +121,7 @@ protected void prepareAccessTokenRequest(AbstractRequest request, OAuth1RequestT request.addOAuthParameter(OAuthConstants.TOKEN, requestToken.getToken()); request.addOAuthParameter(OAuthConstants.VERIFIER, verifier.getValue()); config.log("setting token to: " + requestToken + " and verifier to: " + verifier); - addOAuthParams(request, requestToken); + addOAuthParams(request, requestToken.getTokenSecret()); appendSignature(request); } @@ -134,20 +133,18 @@ public void signRequest(OAuth1AccessToken token, AbstractRequest request) { request.addOAuthParameter(OAuthConstants.TOKEN, token.getToken()); } config.log("setting token to: " + token); - addOAuthParams(request, token); + addOAuthParams(request, token.getTokenSecret()); appendSignature(request); } - /** - * {@inheritDoc} - */ @Override public String getVersion() { return VERSION; } /** - * Returns the URL where you should redirect your users to authenticate your application. + * Returns the URL where you should redirect your users to authenticate your + * application. * * @param requestToken the request token you need to authorize * @return the URL where you should redirect your users @@ -156,13 +153,12 @@ public String getAuthorizationUrl(OAuth1RequestToken requestToken) { return api.getAuthorizationUrl(requestToken); } - private String getSignature(AbstractRequest request, OAuth1Token token) { + private String getSignature(AbstractRequest request, String tokenSecret) { final OAuthConfig config = getConfig(); config.log("generating signature..."); config.log("using base64 encoder: " + Base64Encoder.type()); final String baseString = api.getBaseStringExtractor().extract(request); - final String signature = api.getSignatureService() - .getSignature(baseString, config.getApiSecret(), token.getTokenSecret()); + final String signature = api.getSignatureService().getSignature(baseString, config.getApiSecret(), tokenSecret); config.log("base string is: " + baseString); config.log("signature is: " + signature); diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java index 4eecefa1f..76c680922 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 @@ -78,6 +78,42 @@ protected T createAccessTokenRequest(Verifier verifi return request; } + public final OAuth2AccessToken refreshAccessToken(String refreshToken) { + final Response response = createRefreshTokenRequest(refreshToken, + new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint(), this)).send(); + return api.getAccessTokenExtractor().extract(response.getBody()); + } + + public final Future refreshAccessTokenAsync(String refreshToken, + OAuthAsyncRequestCallback callback) { + return refreshAccessTokenAsync(refreshToken, callback, null); + } + + public final Future refreshAccessTokenAsync(String refreshToken, + OAuthAsyncRequestCallback callback, ProxyServer proxyServer) { + final OAuthRequestAsync request = createRefreshTokenRequest(refreshToken, + new OAuthRequestAsync(api.getAccessTokenVerb(), api.getAccessTokenEndpoint(), this)); + return request.sendAsync(callback, new OAuthRequestAsync.ResponseConverter() { + @Override + public OAuth2AccessToken convert(com.ning.http.client.Response response) throws IOException { + return getApi().getAccessTokenExtractor() + .extract(OAuthRequestAsync.RESPONSE_CONVERTER.convert(response).getBody()); + } + }, proxyServer); + } + + protected T createRefreshTokenRequest(String refreshToken, T request) { + if (refreshToken == null || refreshToken.isEmpty()) { + throw new IllegalArgumentException("The refreshToken cannot be null or empty"); + } + final OAuthConfig config = getConfig(); + request.addParameter(OAuthConstants.CLIENT_ID, config.getApiKey()); + request.addParameter(OAuthConstants.CLIENT_SECRET, config.getApiSecret()); + request.addParameter(OAuthConstants.REFRESH_TOKEN, refreshToken); + request.addParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.REFRESH_TOKEN); + return request; + } + /** * {@inheritDoc} */ From 8c8d9b479c4cdc464c028b848a637035ac659102 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 26 Feb 2016 18:04:30 +0300 Subject: [PATCH 146/882] prepare 2.3.0 release --- README.md | 4 ++-- changelog | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 4004a29af..3323a9dc9 100644 --- a/README.md +++ b/README.md @@ -78,7 +78,7 @@ You can pull ScribeJava from the central maven repository, just add these to you com.github.scribejava scribejava-apis - 2.2.2 + 2.3.0 ``` @@ -87,7 +87,7 @@ And in case you need just core classes (that's it, without any external API (FB, com.github.scribejava scribejava-core - 2.2.2 + 2.3.0 ``` diff --git a/changelog b/changelog index 1904d9081..75372e3b3 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,4 @@ -[SNAPSHOT] +[2.3.0] * Stack Exchange authentication via OAuth 2.0 (stackoverflow.com, askubuntu.com, etc.). * Support response in gzip. * differentiate OAuth1 Access token, OAuth 1 Request Token and OAuth 2 Access token, make them conforms RFCs From 73b46fe1640b58c37c610670b406db481a547302 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 26 Feb 2016 18:05:11 +0300 Subject: [PATCH 147/882] [maven-release-plugin] prepare release scribejava-2.3.0 --- pom.xml | 2 +- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 2a2a7abfe..b47444554 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 2.2.3-SNAPSHOT + 2.3.0 ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index f661a6b4c..64178f60a 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 2.2.3-SNAPSHOT + 2.3.0 ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 08aa2ce57..80d68f0d2 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 2.2.3-SNAPSHOT + 2.3.0 ../pom.xml From 5a9ca46254426de46f33b03d1e1da6c351d5836c Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 26 Feb 2016 18:05:16 +0300 Subject: [PATCH 148/882] [maven-release-plugin] prepare for next development iteration --- pom.xml | 2 +- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index b47444554..d34a6276f 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 2.3.0 + 2.3.1-SNAPSHOT ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 64178f60a..23e975072 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 2.3.0 + 2.3.1-SNAPSHOT ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 80d68f0d2..b4730b400 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 2.3.0 + 2.3.1-SNAPSHOT ../pom.xml From 87779522b63690140a859f20b061cb01170e5c95 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 3 Mar 2016 12:41:14 +0300 Subject: [PATCH 149/882] fix typo in README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3323a9dc9..871a543f8 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ Hit ScribeJava as hard and with many threads as you like. ### Async -You can user ning async http client out-of-box, just use ServiceBuilderAsync +You can use ning async http client out-of-box, just use ServiceBuilderAsync ### Supports all major 1.0a and 2.0 OAuth APIs out-of-the-box From 5593084434750aa24b949affd18bd94700105486 Mon Sep 17 00:00:00 2001 From: Maksim Likharev Date: Thu, 3 Mar 2016 14:45:28 -0800 Subject: [PATCH 150/882] resource owner password credentials grant --- pom.xml | 6 ++ .../scribejava/core/model/OAuthConstants.java | 3 + .../scribejava/core/oauth/OAuth20Service.java | 66 +++++++++++++++++-- .../core/utils/Uninterruptibles.java | 37 +++++++++++ .../core/oauth/CompletedFuture.java | 43 ++++++++++++ .../scribejava/core/oauth/OAuth20ApiUnit.java | 22 +++++++ .../core/oauth/OAuth20ServiceTest.java | 50 ++++++++++++++ .../core/oauth/OAuth20ServiceUnit.java | 57 ++++++++++++++++ 8 files changed, 277 insertions(+), 7 deletions(-) create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/utils/Uninterruptibles.java create mode 100644 scribejava-core/src/test/java/com/github/scribejava/core/oauth/CompletedFuture.java create mode 100644 scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ApiUnit.java create mode 100644 scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceTest.java create mode 100644 scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceUnit.java diff --git a/pom.xml b/pom.xml index d34a6276f..cca9d984b 100644 --- a/pom.xml +++ b/pom.xml @@ -80,6 +80,12 @@ 4.12 test
+ + com.google.code.gson + gson + 2.6.2 + test + commons-codec commons-codec diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConstants.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConstants.java index 4648b24e1..687970171 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConstants.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConstants.java @@ -21,6 +21,7 @@ public interface OAuthConstants { String VERIFIER = "oauth_verifier"; String HEADER = "Authorization"; String SCOPE = "scope"; + String BASIC = "Basic"; // OAuth 2.0 String ACCESS_TOKEN = "access_token"; @@ -32,4 +33,6 @@ public interface OAuthConstants { String GRANT_TYPE = "grant_type"; String AUTHORIZATION_CODE = "authorization_code"; String STATE = "state"; + String USERNAME = "username"; + String PASSWORD = "password"; } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java index 76c680922..3e6e35088 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java @@ -1,7 +1,12 @@ package com.github.scribejava.core.oauth; +import com.github.scribejava.core.exceptions.OAuthException; +import com.github.scribejava.core.services.Base64Encoder; +import com.github.scribejava.core.utils.Uninterruptibles; import com.ning.http.client.ProxyServer; import java.io.IOException; +import java.nio.charset.Charset; +import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.model.AbstractRequest; @@ -13,6 +18,8 @@ import com.github.scribejava.core.model.OAuthRequestAsync; import com.github.scribejava.core.model.Response; import com.github.scribejava.core.model.Verifier; +import org.apache.commons.codec.binary.Base64; + import java.util.Map; public class OAuth20Service extends OAuthService { @@ -32,9 +39,11 @@ public OAuth20Service(DefaultApi20 api, OAuthConfig config) { } public final OAuth2AccessToken getAccessToken(Verifier verifier) { - final Response response = createAccessTokenRequest(verifier, - new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint(), this)).send(); - return api.getAccessTokenExtractor().extract(response.getBody()); + return Uninterruptibles.getUninterruptibly( getAccessTokenAsync(verifier, null) ); + } + + public final OAuth2AccessToken getAccessTokenPasswordGrant(String uname, String password) { + return Uninterruptibles.getUninterruptibly( getAccessTokenPasswordGrantAsync(uname, password, null) ); } /** @@ -54,15 +63,60 @@ public final Future getAccessTokenAsync(Verifier verifier, OAuthAsyncRequestCallback callback, ProxyServer proxyServer) { final OAuthRequestAsync request = createAccessTokenRequest(verifier, new OAuthRequestAsync(api.getAccessTokenVerb(), api.getAccessTokenEndpoint(), this)); + + return getAccessTokenAsync(request, callback, proxyServer); + } + + public final Future getAccessTokenPasswordGrantAsync(String uname, String password, + OAuthAsyncRequestCallback callback) { + final OAuthRequestAsync request = createAccessTokenPasswordGrantRequest(uname, password, + new OAuthRequestAsync(api.getAccessTokenVerb(), api.getAccessTokenEndpoint(), this)); + + return getAccessTokenPasswordGrantAsync(uname, password, callback, null); + } + + public final Future getAccessTokenPasswordGrantAsync(String uname, String password, + OAuthAsyncRequestCallback callback, ProxyServer proxyServer) { + final OAuthRequestAsync request = createAccessTokenPasswordGrantRequest(uname, password, + new OAuthRequestAsync(api.getAccessTokenVerb(), api.getAccessTokenEndpoint(), this)); + + return getAccessTokenAsync(request, callback, proxyServer); + } + + protected Future getAccessTokenAsync(OAuthRequestAsync request, + OAuthAsyncRequestCallback callback, ProxyServer proxyServer) { + return request.sendAsync(callback, new OAuthRequestAsync.ResponseConverter() { @Override public OAuth2AccessToken convert(com.ning.http.client.Response response) throws IOException { return getApi().getAccessTokenExtractor() - .extract(OAuthRequestAsync.RESPONSE_CONVERTER.convert(response).getBody()); + .extract(OAuthRequestAsync.RESPONSE_CONVERTER.convert(response).getBody()); } }, proxyServer); } + protected T createAccessTokenPasswordGrantRequest(String username, String password, T request) { + final OAuthConfig config = getConfig(); + request.addParameter(OAuthConstants.USERNAME, username); + request.addParameter(OAuthConstants.PASSWORD, password); + + if (config.hasScope()) { + request.addParameter(OAuthConstants.SCOPE, config.getScope()); + } + + request.addParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.PASSWORD); + + request.addHeader(OAuthConstants.HEADER, OAuthConstants.BASIC + " " + + Base64Encoder.getInstance().encode( + String.format("%s:%s", config.getApiKey(), config.getApiSecret()).getBytes( + Charset.forName("UTF-8") + ) + ) + ); + + return request; + } + protected T createAccessTokenRequest(Verifier verifier, T request) { final OAuthConfig config = getConfig(); request.addParameter(OAuthConstants.CLIENT_ID, config.getApiKey()); @@ -79,9 +133,7 @@ protected T createAccessTokenRequest(Verifier verifi } public final OAuth2AccessToken refreshAccessToken(String refreshToken) { - final Response response = createRefreshTokenRequest(refreshToken, - new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint(), this)).send(); - return api.getAccessTokenExtractor().extract(response.getBody()); + return Uninterruptibles.getUninterruptibly( refreshAccessTokenAsync(refreshToken, null) ); } public final Future refreshAccessTokenAsync(String refreshToken, diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/utils/Uninterruptibles.java b/scribejava-core/src/main/java/com/github/scribejava/core/utils/Uninterruptibles.java new file mode 100644 index 000000000..c3ed57995 --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/utils/Uninterruptibles.java @@ -0,0 +1,37 @@ +package com.github.scribejava.core.utils; + +import com.github.scribejava.core.exceptions.OAuthException; + +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Future; + +public final class Uninterruptibles { + /** + * + * This is part of the code from guava, copied here as the project doesn't include one. + * + * Invokes {@code future.}{@link Future#get() get()} uninterruptibly. + */ + public static V getUninterruptibly(Future future) { + boolean interrupted = false; + try { + while (true) { + try { + return future.get(); + } catch (InterruptedException e) { + interrupted = true; + } + } + } + catch( ExecutionException e ) { + throw new OAuthException( e ); + } + finally { + if (interrupted) { + Thread.currentThread().interrupt(); + } + } + } + +} diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/CompletedFuture.java b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/CompletedFuture.java new file mode 100644 index 000000000..1c4a3f068 --- /dev/null +++ b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/CompletedFuture.java @@ -0,0 +1,43 @@ +package com.github.scribejava.core.oauth; + +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; + +/** + */ +class CompletedFuture implements Future { + private final V result; + + public CompletedFuture( V result ) { + this.result = result; + } + + @Override + public boolean cancel(boolean mayInterruptIfRunning) { + return false; + } + + @Override + public boolean isCancelled() { + return false; + } + + @Override + public boolean isDone() { + return true; + } + + @Override + public V get() throws InterruptedException, ExecutionException { + return result; + } + + @Override + public V get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, + TimeoutException { + + return result; + } +} diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ApiUnit.java b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ApiUnit.java new file mode 100644 index 000000000..398173d11 --- /dev/null +++ b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ApiUnit.java @@ -0,0 +1,22 @@ +package com.github.scribejava.core.oauth; + +import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.model.OAuthConfig; + +/** + */ +class OAuth20ApiUnit extends DefaultApi20 { + @Override + public String getAccessTokenEndpoint() { + return "http://localhost:8080/token"; + } + + @Override + public String getAuthorizationUrl(OAuthConfig config) { + return "http://localhost:8080/authorize"; + } + + public OAuth20Service createService(OAuthConfig config) { + return new OAuth20ServiceUnit(this, config); + } +} 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 new file mode 100644 index 000000000..731eba951 --- /dev/null +++ b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceTest.java @@ -0,0 +1,50 @@ +package com.github.scribejava.core.oauth; + +import com.github.scribejava.core.builder.ServiceBuilder; +import com.github.scribejava.core.model.OAuth2AccessToken; +import com.github.scribejava.core.model.OAuthConstants; +import com.github.scribejava.core.services.Base64Encoder; +import com.google.gson.Gson; +import com.google.gson.reflect.TypeToken; +import org.junit.Assert; +import org.junit.Test; + +import java.nio.charset.Charset; +import java.util.Map; + +/** + */ +public class OAuth20ServiceTest { + + @Test + public void shouldProduceCorrectRequest() { + final OAuth20Service service = new ServiceBuilder() + .apiKey("your_api_key") + .apiSecret("your_api_secret") + .build( new OAuth20ApiUnit() ); + + final OAuth2AccessToken token = service.getAccessTokenPasswordGrant("user1", "password1"); + final Gson json = new Gson(); + + Assert.assertNotNull(token); + + Map map = json.fromJson(token.getRawResponse(), + new TypeToken>(){}.getType()); + + Assert.assertEquals(OAuth20ServiceUnit.token, map.get(OAuthConstants.ACCESS_TOKEN)); + Assert.assertEquals(OAuth20ServiceUnit.state, map.get(OAuthConstants.STATE)); + Assert.assertEquals(OAuth20ServiceUnit.expires, map.get("expires_in")); + + final String authorize = Base64Encoder.getInstance().encode( + String.format("%s:%s", service.getConfig().getApiKey(), service.getConfig().getApiSecret()).getBytes( + Charset.forName("UTF-8") + ) + ); + + Assert.assertEquals(OAuthConstants.BASIC + " " + authorize, map.get(OAuthConstants.HEADER)); + + Assert.assertEquals("user1", map.get("query-username")); + Assert.assertEquals("password1", map.get("query-password")); + Assert.assertEquals("password", map.get("query-grant_type")); + } +} diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceUnit.java b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceUnit.java new file mode 100644 index 000000000..32b358746 --- /dev/null +++ b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceUnit.java @@ -0,0 +1,57 @@ +package com.github.scribejava.core.oauth; + +import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.model.OAuth2AccessToken; +import com.github.scribejava.core.model.OAuthAsyncRequestCallback; +import com.github.scribejava.core.model.OAuthConfig; +import com.github.scribejava.core.model.OAuthConstants; +import com.github.scribejava.core.model.OAuthRequestAsync; +import com.github.scribejava.core.model.Parameter; +import com.google.gson.Gson; +import com.ning.http.client.ProxyServer; + +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.Future; + +/** + */ +class OAuth20ServiceUnit extends OAuth20Service { + + final static String token = "ae82980abab675c646a070686d5558ad"; + final static String state = "123"; + final static String expires = "3600"; + + public OAuth20ServiceUnit(DefaultApi20 api, OAuthConfig config) { + super(api, config); + } + + protected Future getAccessTokenAsync(OAuthRequestAsync request, + OAuthAsyncRequestCallback callback, ProxyServer proxyServer) { + + final Gson json = new Gson(); + final Map response = new HashMap<>(); + + response.put(OAuthConstants.ACCESS_TOKEN, token); + response.put(OAuthConstants.STATE, state); + response.put("expires_in", expires); + + response.putAll( request.getHeaders() ); + response.putAll( request.getOauthParameters() ); + + for(Parameter p : request.getQueryStringParams().getParams()) { + response.put( "query-" + p.getKey(), p.getValue() ); + } + + final OAuth2AccessToken accessToken = new OAuth2AccessToken(token, json.toJson( response )); + + try { + return new CompletedFuture(accessToken); + } + finally { + if( callback != null ) { + callback.onCompleted(accessToken); + } + } + } +} From 4a2427d16b74d0b9544b3942717e14ff44b315eb Mon Sep 17 00:00:00 2001 From: Chris Wewerka Date: Wed, 9 Mar 2016 14:40:01 +0100 Subject: [PATCH 151/882] fixed issue 587: added headers to async request --- .../core/model/OAuthRequestAsync.java | 45 ++++++++++++++----- 1 file changed, 33 insertions(+), 12 deletions(-) diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequestAsync.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequestAsync.java index a7dd1dce5..42c825efb 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequestAsync.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequestAsync.java @@ -1,16 +1,19 @@ package com.github.scribejava.core.model; +import com.github.scribejava.core.exceptions.OAuthException; +import com.github.scribejava.core.oauth.OAuthService; import com.ning.http.client.AsyncCompletionHandler; import com.ning.http.client.AsyncHttpClient; import com.ning.http.client.FluentCaseInsensitiveStringsMap; import com.ning.http.client.ProxyServer; + import java.io.IOException; +import java.util.Collection; import java.util.HashMap; import java.util.List; +import java.util.ArrayList; import java.util.Map; import java.util.concurrent.Future; -import com.github.scribejava.core.exceptions.OAuthException; -import com.github.scribejava.core.oauth.OAuthService; public class OAuthRequestAsync extends AbstractRequest { @@ -53,10 +56,16 @@ public Future sendAsync(OAuthAsyncRequestCallback callback, ResponseCo final AsyncHttpClient.BoundRequestBuilder boundRequestBuilder; switch (getVerb()) { case GET: - boundRequestBuilder = service.getAsyncHttpClient().prepareGet(completeUrl); + boundRequestBuilder = service.getAsyncHttpClient() + .prepareGet(completeUrl) + .setHeaders(mapHeaders()); + break; case POST: - boundRequestBuilder = service.getAsyncHttpClient().preparePost(completeUrl).setBody(getBodyContents()); + boundRequestBuilder = service.getAsyncHttpClient().preparePost(completeUrl) + .setBody(getBodyContents()) + .setHeaders(mapHeaders()); + break; default: throw new IllegalArgumentException("message build error: unknown verb type"); @@ -67,6 +76,26 @@ public Future sendAsync(OAuthAsyncRequestCallback callback, ResponseCo return boundRequestBuilder.execute(new OAuthAsyncCompletionHandler<>(callback, converter)); } + public Future sendAsync(OAuthAsyncRequestCallback callback) { + return sendAsync(callback, RESPONSE_CONVERTER, null); + } + + public Future sendAsync(OAuthAsyncRequestCallback callback, ProxyServer proxyServer) { + return sendAsync(callback, RESPONSE_CONVERTER, proxyServer); + } + + private Map> mapHeaders() { + final Map headers = getHeaders(); + final Map> mapped = new HashMap<>(); + + for(Map.Entry entry: headers.entrySet()) { + final ArrayList list = new ArrayList<>(); + list.add(entry.getValue()); + mapped.put(entry.getKey(), list); + } + return mapped; + } + private static class OAuthAsyncCompletionHandler extends AsyncCompletionHandler { private final OAuthAsyncRequestCallback callback; @@ -94,14 +123,6 @@ public void onThrowable(Throwable t) { } }; - public Future sendAsync(OAuthAsyncRequestCallback callback) { - return sendAsync(callback, RESPONSE_CONVERTER, null); - } - - public Future sendAsync(OAuthAsyncRequestCallback callback, ProxyServer proxyServer) { - return sendAsync(callback, RESPONSE_CONVERTER, proxyServer); - } - public interface ResponseConverter { T convert(com.ning.http.client.Response response) throws IOException; From d91f6ee0dd58c09c899bfc82888b1add63905a09 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 10 Mar 2016 15:31:43 +0300 Subject: [PATCH 152/882] APIs 2.0 can define different endpoints for access token and for refresh token (the same urls by default) --- changelog | 3 +++ .../com/github/scribejava/core/builder/api/DefaultApi20.java | 4 ++++ .../java/com/github/scribejava/core/oauth/OAuth20Service.java | 4 ++-- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/changelog b/changelog index 75372e3b3..5e315bad7 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,6 @@ +[SNAPSHOT] + * APIs 2.0 can define different endpoints for access token and for refresh token (the same urls by default) + [2.3.0] * Stack Exchange authentication via OAuth 2.0 (stackoverflow.com, askubuntu.com, etc.). * Support response in gzip. diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java index fe07dbf6c..2bc3ee47e 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java @@ -49,6 +49,10 @@ public Verb getAccessTokenVerb() { */ public abstract String getAccessTokenEndpoint(); + public String getRefreshTokenEndpoint() { + return getAccessTokenEndpoint(); + } + /** * Returns the URL where you should redirect your users to authenticate your application. * 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 76c680922..57f8d09fd 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 @@ -80,7 +80,7 @@ protected T createAccessTokenRequest(Verifier verifi public final OAuth2AccessToken refreshAccessToken(String refreshToken) { final Response response = createRefreshTokenRequest(refreshToken, - new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint(), this)).send(); + new OAuthRequest(api.getAccessTokenVerb(), api.getRefreshTokenEndpoint(), this)).send(); return api.getAccessTokenExtractor().extract(response.getBody()); } @@ -92,7 +92,7 @@ public final Future refreshAccessTokenAsync(String refreshTok public final Future refreshAccessTokenAsync(String refreshToken, OAuthAsyncRequestCallback callback, ProxyServer proxyServer) { final OAuthRequestAsync request = createRefreshTokenRequest(refreshToken, - new OAuthRequestAsync(api.getAccessTokenVerb(), api.getAccessTokenEndpoint(), this)); + new OAuthRequestAsync(api.getAccessTokenVerb(), api.getRefreshTokenEndpoint(), this)); return request.sendAsync(callback, new OAuthRequestAsync.ResponseConverter() { @Override public OAuth2AccessToken convert(com.ning.http.client.Response response) throws IOException { From b0300318eb3ce7eb540a4f49dd075d382c347cda Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 10 Mar 2016 15:34:36 +0300 Subject: [PATCH 153/882] mark Facebook doesn't support refresh token by throwing UnsupportedOperationException --- changelog | 1 + .../main/java/com/github/scribejava/apis/FacebookApi.java | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/changelog b/changelog index 5e315bad7..de50fa652 100644 --- a/changelog +++ b/changelog @@ -1,5 +1,6 @@ [SNAPSHOT] * APIs 2.0 can define different endpoints for access token and for refresh token (the same urls by default) + * mark Facebook doesn't support refresh token by throwing UnsupportedOperationException [2.3.0] * Stack Exchange authentication via OAuth 2.0 (stackoverflow.com, askubuntu.com, etc.). 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 c3f3bfcea..21df3bce2 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 @@ -39,6 +39,11 @@ public String getAccessTokenEndpoint() { return "https://graph.facebook.com/v2.5/oauth/access_token"; } + @Override + public String getRefreshTokenEndpoint() { + throw new UnsupportedOperationException("Facebook doesn't support refershing tokens"); + } + @Override public String getAuthorizationUrl(OAuthConfig config) { Preconditions.checkValidUrl(config.getCallback(), From 03b3820b24d646fb010ff5c5afcd76f689158cb5 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 10 Mar 2016 15:46:26 +0300 Subject: [PATCH 154/882] make JSON Access Token Extractor be the default for OAuth 2.0 (according to RFC 6749) --- changelog | 1 + .../github/scribejava/apis/DoktornaraboteApi.java | 8 -------- .../java/com/github/scribejava/apis/FacebookApi.java | 8 -------- .../com/github/scribejava/apis/Foursquare2Api.java | 8 -------- .../java/com/github/scribejava/apis/GitHubApi.java | 8 ++++++++ .../main/java/com/github/scribejava/apis/HHApi.java | 8 -------- .../java/com/github/scribejava/apis/ImgurApi.java | 8 -------- .../java/com/github/scribejava/apis/KaixinApi20.java | 8 -------- .../com/github/scribejava/apis/LinkedInApi20.java | 8 -------- .../java/com/github/scribejava/apis/LiveApi.java | 8 -------- .../java/com/github/scribejava/apis/MailruApi.java | 8 -------- .../com/github/scribejava/apis/OdnoklassnikiApi.java | 8 -------- .../com/github/scribejava/apis/PinterestApi.java | 8 -------- .../java/com/github/scribejava/apis/RenrenApi.java | 8 -------- .../com/github/scribejava/apis/SinaWeiboApi20.java | 8 -------- .../com/github/scribejava/apis/StackExchangeApi.java | 8 ++++++++ .../java/com/github/scribejava/apis/TutByApi.java | 8 -------- .../java/com/github/scribejava/apis/ViadeoApi.java | 8 -------- .../com/github/scribejava/apis/VkontakteApi.java | 8 -------- .../scribejava/core/builder/api/DefaultApi20.java | 12 ++++++------ .../core/extractors/OAuth2AccessTokenExtractor.java | 2 +- .../extractors/OAuth2AccessTokenJsonExtractor.java | 2 +- 22 files changed, 25 insertions(+), 136 deletions(-) diff --git a/changelog b/changelog index de50fa652..dc7b1472c 100644 --- a/changelog +++ b/changelog @@ -1,6 +1,7 @@ [SNAPSHOT] * APIs 2.0 can define different endpoints for access token and for refresh token (the same urls by default) * mark Facebook doesn't support refresh token by throwing UnsupportedOperationException + * make JSON Access Token Extractor be the default for OAuth 2.0 (according to RFC 6749) [2.3.0] * Stack Exchange authentication via OAuth 2.0 (stackoverflow.com, askubuntu.com, etc.). diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/DoktornaraboteApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/DoktornaraboteApi.java index f937d62bd..41c67cc9c 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/DoktornaraboteApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/DoktornaraboteApi.java @@ -2,9 +2,6 @@ import com.github.scribejava.apis.service.DoktornaraboteOAuthServiceImpl; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; -import com.github.scribejava.core.extractors.TokenExtractor; -import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.Verb; @@ -60,11 +57,6 @@ public String getAuthorizationUrl(OAuthConfig config) { return sb.toString(); } - @Override - public TokenExtractor getAccessTokenExtractor() { - return OAuth2AccessTokenJsonExtractor.instance(); - } - @Override public OAuth20Service createService(OAuthConfig config) { return new DoktornaraboteOAuthServiceImpl(this, config); 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 21df3bce2..3412967e9 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java @@ -1,9 +1,6 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; -import com.github.scribejava.core.extractors.TokenExtractor; -import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.utils.OAuthEncoder; @@ -29,11 +26,6 @@ public static FacebookApi instance() { return InstanceHolder.INSTANCE; } - @Override - public TokenExtractor getAccessTokenExtractor() { - return OAuth2AccessTokenJsonExtractor.instance(); - } - @Override public String getAccessTokenEndpoint() { return "https://graph.facebook.com/v2.5/oauth/access_token"; diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/Foursquare2Api.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/Foursquare2Api.java index d221dcbac..b8dc4f594 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/Foursquare2Api.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/Foursquare2Api.java @@ -1,9 +1,6 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; -import com.github.scribejava.core.extractors.TokenExtractor; -import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.utils.OAuthEncoder; @@ -36,9 +33,4 @@ public String getAuthorizationUrl(OAuthConfig config) { "Must provide a valid url as callback. Foursquare2 does not support OOB"); return String.format(AUTHORIZATION_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback())); } - - @Override - public TokenExtractor getAccessTokenExtractor() { - return OAuth2AccessTokenJsonExtractor.instance(); - } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/GitHubApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/GitHubApi.java index 6d48a107f..9b3129af0 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/GitHubApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/GitHubApi.java @@ -1,6 +1,9 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.extractors.OAuth2AccessTokenExtractor; +import com.github.scribejava.core.extractors.TokenExtractor; +import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.utils.OAuthEncoder; @@ -41,4 +44,9 @@ public String getAuthorizationUrl(OAuthConfig config) { } return sb.toString(); } + + @Override + public TokenExtractor getAccessTokenExtractor() { + return OAuth2AccessTokenExtractor.instance(); + } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/HHApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/HHApi.java index c0fd8f1e2..980bd1693 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/HHApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/HHApi.java @@ -1,13 +1,10 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.Verb; import com.github.scribejava.apis.service.HHOAuthServiceImpl; -import com.github.scribejava.core.extractors.TokenExtractor; -import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.oauth.OAuth20Service; import com.github.scribejava.core.utils.OAuthEncoder; @@ -44,11 +41,6 @@ public String getAuthorizationUrl(OAuthConfig config) { return String.format(AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback())); } - @Override - public TokenExtractor getAccessTokenExtractor() { - return OAuth2AccessTokenJsonExtractor.instance(); - } - @Override public OAuth20Service createService(OAuthConfig config) { return new HHOAuthServiceImpl(this, config); diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java index bcb95cf17..c5ed43f73 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java @@ -2,9 +2,6 @@ import com.github.scribejava.apis.service.ImgurOAuthServiceImpl; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; -import com.github.scribejava.core.extractors.TokenExtractor; -import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.oauth.OAuth20Service; @@ -30,11 +27,6 @@ public Verb getAccessTokenVerb() { return Verb.POST; } - @Override - public TokenExtractor getAccessTokenExtractor() { - return OAuth2AccessTokenJsonExtractor.instance(); - } - @Override public String getAccessTokenEndpoint() { return "https://api.imgur.com/oauth2/token"; diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/KaixinApi20.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/KaixinApi20.java index 1d6658f21..08062b828 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/KaixinApi20.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/KaixinApi20.java @@ -1,9 +1,6 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; -import com.github.scribejava.core.extractors.TokenExtractor; -import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.utils.OAuthEncoder; @@ -28,11 +25,6 @@ public static KaixinApi20 instance() { return InstanceHolder.INSTANCE; } - @Override - public TokenExtractor getAccessTokenExtractor() { - return OAuth2AccessTokenJsonExtractor.instance(); - } - @Override public String getAccessTokenEndpoint() { return "https://api.kaixin001.com/oauth2/access_token?grant_type=" + OAuthConstants.AUTHORIZATION_CODE; diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi20.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi20.java index 7f829dd40..3043f2737 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi20.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi20.java @@ -2,9 +2,6 @@ import com.github.scribejava.apis.service.LinkedIn20ServiceImpl; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; -import com.github.scribejava.core.extractors.TokenExtractor; -import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.Verb; @@ -55,11 +52,6 @@ public String getAuthorizationUrl(OAuthConfig config) { } } - @Override - public TokenExtractor getAccessTokenExtractor() { - return OAuth2AccessTokenJsonExtractor.instance(); - } - @Override public OAuth20Service createService(OAuthConfig config) { return new LinkedIn20ServiceImpl(this, config); diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/LiveApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/LiveApi.java index a512318f5..d40d62cba 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/LiveApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/LiveApi.java @@ -1,9 +1,6 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; -import com.github.scribejava.core.extractors.TokenExtractor; -import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.utils.OAuthEncoder; @@ -44,9 +41,4 @@ public String getAuthorizationUrl(OAuthConfig config) { return String.format(AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback())); } } - - @Override - public TokenExtractor getAccessTokenExtractor() { - return OAuth2AccessTokenJsonExtractor.instance(); - } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java index 3f84704b6..e520309d8 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java @@ -1,14 +1,11 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.utils.OAuthEncoder; import com.github.scribejava.core.utils.Preconditions; import com.github.scribejava.apis.service.MailruOAuthServiceImpl; -import com.github.scribejava.core.extractors.TokenExtractor; -import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.oauth.OAuth20Service; public class MailruApi extends DefaultApi20 { @@ -54,9 +51,4 @@ public String getAuthorizationUrl(OAuthConfig config) { public OAuth20Service createService(OAuthConfig config) { return new MailruOAuthServiceImpl(this, config); } - - @Override - public TokenExtractor getAccessTokenExtractor() { - return OAuth2AccessTokenJsonExtractor.instance(); - } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java index 1842e9faa..42c15d31f 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java @@ -2,9 +2,6 @@ import com.github.scribejava.apis.service.OdnoklassnikiServiceImpl; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; -import com.github.scribejava.core.extractors.TokenExtractor; -import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.oauth.OAuth20Service; @@ -54,9 +51,4 @@ public String getAuthorizationUrl(OAuthConfig config) { public OAuth20Service createService(OAuthConfig config) { return new OdnoklassnikiServiceImpl(this, config); } - - @Override - public TokenExtractor getAccessTokenExtractor() { - return OAuth2AccessTokenJsonExtractor.instance(); - } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/PinterestApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/PinterestApi.java index 6880cd938..d5a1fab76 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/PinterestApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/PinterestApi.java @@ -1,9 +1,6 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; -import com.github.scribejava.core.extractors.TokenExtractor; -import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.Verb; @@ -50,9 +47,4 @@ public String getAuthorizationUrl(OAuthConfig config) { return String.format(AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback())); } } - - @Override - public TokenExtractor getAccessTokenExtractor() { - return OAuth2AccessTokenJsonExtractor.instance(); - } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/RenrenApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/RenrenApi.java index 4fd12b36b..d28f55c4d 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/RenrenApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/RenrenApi.java @@ -1,9 +1,6 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; -import com.github.scribejava.core.extractors.TokenExtractor; -import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.utils.OAuthEncoder; @@ -28,11 +25,6 @@ public static RenrenApi instance() { return InstanceHolder.INSTANCE; } - @Override - public TokenExtractor getAccessTokenExtractor() { - return OAuth2AccessTokenJsonExtractor.instance(); - } - @Override public String getAccessTokenEndpoint() { return "https://graph.renren.com/oauth/token?grant_type=" + OAuthConstants.AUTHORIZATION_CODE; diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/SinaWeiboApi20.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/SinaWeiboApi20.java index a98493382..fe9fde760 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/SinaWeiboApi20.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/SinaWeiboApi20.java @@ -1,9 +1,6 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; -import com.github.scribejava.core.extractors.TokenExtractor; -import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.Verb; @@ -34,11 +31,6 @@ public Verb getAccessTokenVerb() { return Verb.POST; } - @Override - public TokenExtractor getAccessTokenExtractor() { - return OAuth2AccessTokenJsonExtractor.instance(); - } - @Override public String getAccessTokenEndpoint() { return "https://api.weibo.com/oauth2/access_token?grant_type=" + OAuthConstants.AUTHORIZATION_CODE; diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/StackExchangeApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/StackExchangeApi.java index 77e257839..999fd5bea 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/StackExchangeApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/StackExchangeApi.java @@ -1,6 +1,9 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.extractors.OAuth2AccessTokenExtractor; +import com.github.scribejava.core.extractors.TokenExtractor; +import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.Verb; @@ -52,4 +55,9 @@ public String getAuthorizationUrl(OAuthConfig config) { } return sb.toString(); } + + @Override + public TokenExtractor getAccessTokenExtractor() { + return OAuth2AccessTokenExtractor.instance(); + } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/TutByApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/TutByApi.java index fb1e10820..7e5324644 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/TutByApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/TutByApi.java @@ -1,14 +1,11 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.utils.OAuthEncoder; import com.github.scribejava.core.utils.Preconditions; import com.github.scribejava.apis.service.TutByOAuthServiceImpl; -import com.github.scribejava.core.extractors.TokenExtractor; -import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.oauth.OAuth20Service; public class TutByApi extends DefaultApi20 { @@ -48,9 +45,4 @@ public String getAuthorizationUrl(OAuthConfig config) { public OAuth20Service createService(OAuthConfig config) { return new TutByOAuthServiceImpl(this, config); } - - @Override - public TokenExtractor getAccessTokenExtractor() { - return OAuth2AccessTokenJsonExtractor.instance(); - } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/ViadeoApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/ViadeoApi.java index c4f718d81..abe864d9a 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/ViadeoApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/ViadeoApi.java @@ -1,9 +1,6 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; -import com.github.scribejava.core.extractors.TokenExtractor; -import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.utils.OAuthEncoder; @@ -26,11 +23,6 @@ public static ViadeoApi instance() { return InstanceHolder.INSTANCE; } - @Override - public TokenExtractor getAccessTokenExtractor() { - return OAuth2AccessTokenJsonExtractor.instance(); - } - @Override public String getAccessTokenEndpoint() { return "https://secure.viadeo.com/oauth-provider/access_token2?grant_type=" + OAuthConstants.AUTHORIZATION_CODE; diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/VkontakteApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/VkontakteApi.java index b0b4e345c..6ed78fc46 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/VkontakteApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/VkontakteApi.java @@ -1,9 +1,6 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; -import com.github.scribejava.core.extractors.TokenExtractor; -import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.utils.OAuthEncoder; import com.github.scribejava.core.utils.Preconditions; @@ -41,9 +38,4 @@ public String getAuthorizationUrl(OAuthConfig config) { return String.format(AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback())); } } - - @Override - public TokenExtractor getAccessTokenExtractor() { - return OAuth2AccessTokenJsonExtractor.instance(); - } } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java index 2bc3ee47e..e70397465 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java @@ -1,6 +1,6 @@ package com.github.scribejava.core.builder.api; -import com.github.scribejava.core.extractors.OAuth2AccessTokenExtractor; +import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; import com.github.scribejava.core.extractors.TokenExtractor; import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthConfig; @@ -10,15 +10,15 @@ import java.util.Map; /** - * Default implementation of the OAuth protocol, version 2.0 (draft 11) + * Default implementation of the OAuth protocol, version 2.0 * * This class is meant to be extended by concrete implementations of the API, providing the endpoints and * endpoint-http-verbs. * - * If your Api adheres to the 2.0 (draft 11) protocol correctly, you just need to extend this class and define the - * getters for your endpoints. + * If your API adheres to the 2.0 protocol correctly, you just need to extend this class and define the getters for your + * endpoints. * - * If your Api does something a bit different, you can override the different extractors or services, in order to + * If your API does something a bit different, you can override the different extractors or services, in order to * fine-tune the process. Please read the javadocs of the interfaces to get an idea of what to do. * */ @@ -30,7 +30,7 @@ public abstract class DefaultApi20 { * @return access token extractor */ public TokenExtractor getAccessTokenExtractor() { - return OAuth2AccessTokenExtractor.instance(); + return OAuth2AccessTokenJsonExtractor.instance(); } /** diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenExtractor.java b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenExtractor.java index dd80c0012..251226338 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenExtractor.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenExtractor.java @@ -8,7 +8,7 @@ import com.github.scribejava.core.utils.Preconditions; /** - * Default implementation of {@link TokenExtractor} for OAuth 2.0 + * Custom implementation of {@link TokenExtractor} for OAuth 2.0 */ public class OAuth2AccessTokenExtractor implements TokenExtractor { 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 514f38610..f6250f9b2 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 @@ -7,7 +7,7 @@ import com.github.scribejava.core.utils.Preconditions; /** - * JSON implementation of {@link TokenExtractor} for OAuth 2.0 + * JSON (default) implementation of {@link TokenExtractor} for OAuth 2.0 */ public class OAuth2AccessTokenJsonExtractor implements TokenExtractor { From 75779efbca828542425944838a00b8c84cc339c1 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 10 Mar 2016 18:41:17 +0300 Subject: [PATCH 155/882] drop Google OAuth 1.0 support (OAuth 1.0 was officially deprecated by Google) --- changelog | 1 + .../com/github/scribejava/apis/GoogleApi.java | 47 ------------- .../apis/examples/GoogleExample.java | 69 ------------------- 3 files changed, 1 insertion(+), 116 deletions(-) delete mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/GoogleApi.java delete mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GoogleExample.java diff --git a/changelog b/changelog index dc7b1472c..658483c29 100644 --- a/changelog +++ b/changelog @@ -2,6 +2,7 @@ * APIs 2.0 can define different endpoints for access token and for refresh token (the same urls by default) * mark Facebook doesn't support refresh token by throwing UnsupportedOperationException * make JSON Access Token Extractor be the default for OAuth 2.0 (according to RFC 6749) + * drop Google OAuth 1.0 support (OAuth 1.0 was officially deprecated by Google) [2.3.0] * Stack Exchange authentication via OAuth 2.0 (stackoverflow.com, askubuntu.com, etc.). diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/GoogleApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/GoogleApi.java deleted file mode 100644 index af8448385..000000000 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/GoogleApi.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.github.scribejava.apis; - -import com.github.scribejava.core.builder.api.DefaultApi10a; -import com.github.scribejava.core.model.OAuth1RequestToken; -import com.github.scribejava.core.model.Verb; - -public class GoogleApi extends DefaultApi10a { - - private static final String AUTHORIZATION_URL - = "https://www.google.com/accounts/OAuthAuthorizeToken?oauth_token=%s"; - - protected GoogleApi() { - } - - private static class InstanceHolder { - private static final GoogleApi INSTANCE = new GoogleApi(); - } - - public static GoogleApi instance() { - return InstanceHolder.INSTANCE; - } - - @Override - public String getAccessTokenEndpoint() { - return "https://www.google.com/accounts/OAuthGetAccessToken"; - } - - @Override - public String getRequestTokenEndpoint() { - return "https://www.google.com/accounts/OAuthGetRequestToken"; - } - - @Override - public Verb getAccessTokenVerb() { - return Verb.GET; - } - - @Override - public Verb getRequestTokenVerb() { - return Verb.GET; - } - - @Override - public String getAuthorizationUrl(OAuth1RequestToken requestToken) { - return String.format(AUTHORIZATION_URL, requestToken.getToken()); - } -} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GoogleExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GoogleExample.java deleted file mode 100644 index 205cd37a8..000000000 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GoogleExample.java +++ /dev/null @@ -1,69 +0,0 @@ -package com.github.scribejava.apis.examples; - -import java.util.Scanner; -import com.github.scribejava.core.builder.ServiceBuilder; -import com.github.scribejava.apis.GoogleApi; -import com.github.scribejava.core.model.OAuth1AccessToken; -import com.github.scribejava.core.model.OAuth1RequestToken; -import com.github.scribejava.core.model.OAuthRequest; -import com.github.scribejava.core.model.Response; -import com.github.scribejava.core.model.Verb; -import com.github.scribejava.core.model.Verifier; -import com.github.scribejava.core.oauth.OAuth10aService; - -public abstract class GoogleExample { - - private static final String NETWORK_NAME = "Google"; - private static final String AUTHORIZE_URL = "https://www.google.com/accounts/OAuthAuthorizeToken?oauth_token="; - private static final String PROTECTED_RESOURCE_URL = "https://docs.google.com/feeds/default/private/full/"; - private static final String SCOPE = "https://docs.google.com/feeds/"; - - public static void main(String... args) { - final OAuth10aService service = new ServiceBuilder() - .apiKey("anonymous") - .apiSecret("anonymous") - .scope(SCOPE) - .build(GoogleApi.instance()); - final Scanner in = new Scanner(System.in); - - System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); - System.out.println(); - - // Obtain the Request Token - System.out.println("Fetching the Request Token..."); - final OAuth1RequestToken requestToken = service.getRequestToken(); - System.out.println("Got the Request Token!"); - System.out.println("(if your curious it looks like this: " + requestToken + " )"); - System.out.println(); - - System.out.println("Now go and authorize ScribeJava here:"); - System.out.println(AUTHORIZE_URL + requestToken.getToken()); - System.out.println("And paste the verifier here"); - System.out.print(">>"); - final Verifier verifier = new Verifier(in.nextLine()); - System.out.println(); - - // Trade the Request Token and Verfier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); - final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, verifier); - System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); - System.out.println(); - - // Now let's go and ask for a protected resource! - System.out.println("Now we're going to access a protected resource..."); - final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service); - service.signRequest(accessToken, request); - request.addHeader("GData-Version", "3.0"); - final Response response = request.send(); - 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 a3ff12d320b13ebfb64dff3ac406a07e9b21c34e Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 10 Mar 2016 19:03:48 +0300 Subject: [PATCH 156/882] add response_type parameter to the ServiceBuilder/OAuthConfig to use not only "code" for authorization code --- changelog | 1 + .../github/scribejava/apis/GoogleApi20.java | 6 ++--- .../core/builder/AbstractServiceBuilder.java | 12 ++++++++++ .../core/builder/ServiceBuilder.java | 4 ++-- .../core/builder/ServiceBuilderAsync.java | 4 ++-- .../scribejava/core/model/OAuthConfig.java | 22 +++++++++---------- .../core/model/OAuthConfigAsync.java | 5 +++-- 7 files changed, 33 insertions(+), 21 deletions(-) diff --git a/changelog b/changelog index 658483c29..f5324c442 100644 --- a/changelog +++ b/changelog @@ -3,6 +3,7 @@ * mark Facebook doesn't support refresh token by throwing UnsupportedOperationException * make JSON Access Token Extractor be the default for OAuth 2.0 (according to RFC 6749) * drop Google OAuth 1.0 support (OAuth 1.0 was officially deprecated by Google) + * add response_type parameter to the ServiceBuilder/OAuthConfig to use not only "code" for authorization code [2.3.0] * Stack Exchange authentication via OAuth 2.0 (stackoverflow.com, askubuntu.com, etc.). diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/GoogleApi20.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/GoogleApi20.java index 9e02c0cfa..b1abc4fe3 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/GoogleApi20.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/GoogleApi20.java @@ -14,7 +14,7 @@ public class GoogleApi20 extends DefaultApi20 { private static final String AUTHORIZE_URL - = "https://accounts.google.com/o/oauth2/auth?response_type=code&client_id=%s&redirect_uri=%s&scope=%s"; + = "https://accounts.google.com/o/oauth2/auth?response_type=%s&client_id=%s&redirect_uri=%s&scope=%s"; protected GoogleApi20() { } @@ -39,8 +39,8 @@ public String getAccessTokenEndpoint() { @Override public String getAuthorizationUrl(OAuthConfig config) { - final StringBuilder sb = new StringBuilder(String.format(AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode( - config.getCallback()), OAuthEncoder.encode(config.getScope()))); + final StringBuilder sb = new StringBuilder(String.format(AUTHORIZE_URL, config.getResponseType(), + config.getApiKey(), OAuthEncoder.encode(config.getCallback()), OAuthEncoder.encode(config.getScope()))); final String state = config.getState(); if (state != null) { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/AbstractServiceBuilder.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/AbstractServiceBuilder.java index 41468d1c1..7c34f0dae 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/AbstractServiceBuilder.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/AbstractServiceBuilder.java @@ -20,6 +20,7 @@ abstract class AbstractServiceBuilder> { private SignatureType signatureType; private OutputStream debugStream; private String grantType; + private String responseType = "code"; AbstractServiceBuilder() { this.callback = OAuthConstants.OUT_OF_BAND; @@ -118,6 +119,13 @@ public T grantType(String grantType) { return (T) this; } + @SuppressWarnings("unchecked") + public T responseType(String responseType) { + Preconditions.checkEmptyString(responseType, "Invalid OAuth responseType"); + this.responseType = responseType; + return (T) this; + } + @SuppressWarnings("unchecked") public T debug() { debugStream(System.out); @@ -161,6 +169,10 @@ public String getGrantType() { return grantType; } + public String getResponseType() { + return responseType; + } + protected abstract OAuthConfig createConfig(); /** 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 02f7f3902..7d24dbec9 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 @@ -28,8 +28,8 @@ public ServiceBuilder readTimeout(Integer readTimeout) { protected OAuthConfig createConfig() { super.checkPreconditions(); final OAuthConfig config = new OAuthConfig(getApiKey(), getApiSecret(), getCallback(), getSignatureType(), - getScope(), getDebugStream(), connectTimeout, readTimeout, getGrantType()); - config.setState(getState()); + getScope(), getDebugStream(), connectTimeout, readTimeout, getGrantType(), getState(), + getResponseType()); return config; } } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilderAsync.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilderAsync.java index 6f5a218cb..192405b6a 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilderAsync.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilderAsync.java @@ -25,8 +25,8 @@ public void checkPreconditions() { protected OAuthConfigAsync createConfig() { checkPreconditions(); final OAuthConfigAsync configAsync = new OAuthConfigAsync(getApiKey(), getApiSecret(), getCallback(), - getSignatureType(), getScope(), getGrantType(), getDebugStream(), asyncHttpClientConfig); - configAsync.setState(getState()); + getSignatureType(), getScope(), getGrantType(), getState(), getResponseType(), getDebugStream(), + asyncHttpClientConfig); configAsync.setAsyncHttpProviderClassName(asyncHttpProviderClassName); return configAsync; } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConfig.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConfig.java index 92b8bbbbc..93231ddb8 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConfig.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConfig.java @@ -17,14 +17,16 @@ public class OAuthConfig { private final OutputStream debugStream; private final Integer connectTimeout; private final Integer readTimeout; - private String state; + private final String state; + private final String responseType; public OAuthConfig(String key, String secret) { - this(key, secret, null, null, null, null, null, null, null); + this(key, secret, null, null, null, null, null, null, null, null, null); } public OAuthConfig(String key, String secret, String callback, SignatureType type, String scope, - OutputStream stream, Integer connectTimeout, Integer readTimeout, String grantType) { + OutputStream stream, Integer connectTimeout, Integer readTimeout, String grantType, String state, + String responseType) { this.apiKey = key; this.apiSecret = secret; this.callback = callback; @@ -34,6 +36,8 @@ public OAuthConfig(String key, String secret, String callback, SignatureType typ this.connectTimeout = connectTimeout; this.readTimeout = readTimeout; this.grantType = grantType; + this.state = state; + this.responseType = responseType; } public String getApiKey() { @@ -87,17 +91,11 @@ public void log(String message) { } } - /** - * Sets optional value used by some provider implementations that is exchanged with provider to avoid CSRF attacks. - * - * @param state some secret key that client side shall never receive - */ - public void setState(String state) { - this.state = state; - } - public String getState() { return state; } + public String getResponseType() { + return responseType; + } } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConfigAsync.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConfigAsync.java index 1387a9b01..346993b21 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConfigAsync.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConfigAsync.java @@ -13,8 +13,9 @@ public OAuthConfigAsync(String key, String secret) { } public OAuthConfigAsync(String key, String secret, String callback, SignatureType type, String scope, - String grantType, OutputStream stream, AsyncHttpClientConfig asyncHttpClientConfig) { - super(key, secret, callback, type, scope, stream, null, null, grantType); + String grantType, String state, String responseType, OutputStream stream, + AsyncHttpClientConfig asyncHttpClientConfig) { + super(key, secret, callback, type, scope, stream, null, null, grantType, state, responseType); this.asyncHttpClientConfig = asyncHttpClientConfig; } From e088788a982940f8f4ef7a2a41d8580eadcc3e19 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 10 Mar 2016 19:34:15 +0300 Subject: [PATCH 157/882] remove Verifier object, we just need Strings, 'code' for OAuth2 and 'oauthVerifier' for OAuth1 --- changelog | 1 + .../apis/service/GoogleOAuthServiceImpl.java | 5 ++-- .../apis/service/ImgurOAuthServiceImpl.java | 7 +++--- .../apis/service/LinkedIn20ServiceImpl.java | 5 ++-- .../apis/service/MailruOAuthServiceImpl.java | 5 ++-- .../apis/examples/AWeberExample.java | 5 ++-- .../scribejava/apis/examples/DiggExample.java | 5 ++-- .../apis/examples/FacebookAsyncExample.java | 5 ++-- .../apis/examples/FacebookExample.java | 5 ++-- .../apis/examples/FlickrExample.java | 5 ++-- .../apis/examples/Foursquare2Example.java | 5 ++-- .../apis/examples/FoursquareExample.java | 5 ++-- .../apis/examples/FreelancerExample.java | 5 ++-- .../apis/examples/GitHubExample.java | 5 ++-- .../apis/examples/Google20Example.java | 5 ++-- .../scribejava/apis/examples/HHExample.java | 5 ++-- .../apis/examples/ImgurExample.java | 5 ++-- .../apis/examples/Kaixin20Example.java | 5 ++-- .../apis/examples/LinkedIn20Example.java | 5 ++-- .../apis/examples/LinkedInExample.java | 5 ++-- .../examples/LinkedInExampleWithScopes.java | 5 ++-- .../scribejava/apis/examples/LiveExample.java | 5 ++-- .../apis/examples/LoveFilmExample.java | 5 ++-- .../apis/examples/MailruAsyncExample.java | 5 ++-- .../apis/examples/MailruExample.java | 5 ++-- .../apis/examples/MeetupExample.java | 5 ++-- .../apis/examples/NeteaseWeiboExample.java | 5 ++-- .../apis/examples/OdnoklassnikiExample.java | 5 ++-- .../apis/examples/PinterestExample.java | 5 ++-- .../apis/examples/Px500Example.java | 5 ++-- .../apis/examples/RenrenExample.java | 5 ++-- .../apis/examples/SinaWeibo2Example.java | 5 ++-- .../apis/examples/SinaWeiboExample.java | 5 ++-- .../apis/examples/SkyrockExample.java | 5 ++-- .../apis/examples/SohuWeiboExample.java | 5 ++-- .../apis/examples/StackExchangeExample.java | 5 ++-- .../apis/examples/TrelloExample.java | 5 ++-- .../apis/examples/TumblrExample.java | 5 ++-- .../apis/examples/TutByExample.java | 5 ++-- .../apis/examples/TwitterExample.java | 5 ++-- .../apis/examples/ViadeoExample.java | 5 ++-- .../apis/examples/VkontakteExample.java | 5 ++-- .../scribejava/apis/examples/XingExample.java | 5 ++-- .../apis/examples/YahooExample.java | 5 ++-- .../scribejava/core/model/Verifier.java | 25 ------------------- .../core/oauth/OAuth10aService.java | 21 ++++++++-------- .../scribejava/core/oauth/OAuth20Service.java | 19 +++++++------- 47 files changed, 107 insertions(+), 176 deletions(-) delete mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/model/Verifier.java diff --git a/changelog b/changelog index f5324c442..fce98d4ac 100644 --- a/changelog +++ b/changelog @@ -4,6 +4,7 @@ * make JSON Access Token Extractor be the default for OAuth 2.0 (according to RFC 6749) * drop Google OAuth 1.0 support (OAuth 1.0 was officially deprecated by Google) * add response_type parameter to the ServiceBuilder/OAuthConfig to use not only "code" for authorization code + * remove Verifier object, we just need Strings, 'code' for OAuth2 and 'oauthVerifier' for OAuth1 [2.3.0] * Stack Exchange authentication via OAuth 2.0 (stackoverflow.com, askubuntu.com, etc.). diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/GoogleOAuthServiceImpl.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/GoogleOAuthServiceImpl.java index 300872853..015ce3677 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/GoogleOAuthServiceImpl.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/GoogleOAuthServiceImpl.java @@ -4,7 +4,6 @@ import com.github.scribejava.core.model.AbstractRequest; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; -import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuth20Service; public class GoogleOAuthServiceImpl extends OAuth20Service { @@ -14,8 +13,8 @@ public GoogleOAuthServiceImpl(DefaultApi20 api, OAuthConfig config) { } @Override - protected T createAccessTokenRequest(Verifier verifier, T request) { - super.createAccessTokenRequest(verifier, request); + protected T createAccessTokenRequest(String code, T request) { + super.createAccessTokenRequest(code, request); if (!getConfig().hasGrantType()) { request.addParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.AUTHORIZATION_CODE); } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthServiceImpl.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthServiceImpl.java index fcc791ac1..ac80b1df6 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthServiceImpl.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthServiceImpl.java @@ -6,7 +6,6 @@ import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; -import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuth20Service; public class ImgurOAuthServiceImpl extends OAuth20Service { @@ -16,17 +15,17 @@ public ImgurOAuthServiceImpl(DefaultApi20 api, OAuthConfig config) { } @Override - protected T createAccessTokenRequest(Verifier verifier, T request) { + protected T createAccessTokenRequest(String oauthVerifier, T request) { final OAuthConfig config = getConfig(); request.addBodyParameter(OAuthConstants.CLIENT_ID, config.getApiKey()); request.addBodyParameter(OAuthConstants.CLIENT_SECRET, config.getApiSecret()); if (ImgurApi.isOob(config)) { request.addBodyParameter(OAuthConstants.GRANT_TYPE, "pin"); - request.addBodyParameter("pin", verifier.getValue()); + request.addBodyParameter("pin", oauthVerifier); } else { request.addBodyParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.AUTHORIZATION_CODE); - request.addBodyParameter(OAuthConstants.CODE, verifier.getValue()); + request.addBodyParameter(OAuthConstants.CODE, oauthVerifier); } return request; } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/LinkedIn20ServiceImpl.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/LinkedIn20ServiceImpl.java index b1d61bb04..49bae5ecf 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/LinkedIn20ServiceImpl.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/LinkedIn20ServiceImpl.java @@ -5,7 +5,6 @@ import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; -import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuth20Service; public class LinkedIn20ServiceImpl extends OAuth20Service { @@ -20,8 +19,8 @@ public void signRequest(OAuth2AccessToken accessToken, AbstractRequest request) } @Override - protected T createAccessTokenRequest(Verifier verifier, T request) { - super.createAccessTokenRequest(verifier, request); + protected T createAccessTokenRequest(String code, T request) { + super.createAccessTokenRequest(code, request); if (!getConfig().hasGrantType()) { request.addParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.AUTHORIZATION_CODE); } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthServiceImpl.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthServiceImpl.java index 4b78fc6da..a6d4f9b3a 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthServiceImpl.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthServiceImpl.java @@ -11,7 +11,6 @@ import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; -import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuth20Service; public class MailruOAuthServiceImpl extends OAuth20Service { @@ -52,8 +51,8 @@ public void signRequest(OAuth2AccessToken accessToken, AbstractRequest request) } @Override - protected T createAccessTokenRequest(Verifier verifier, T request) { - super.createAccessTokenRequest(verifier, request); + protected T createAccessTokenRequest(String code, T request) { + super.createAccessTokenRequest(code, request); if (!getConfig().hasGrantType()) { request.addParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.AUTHORIZATION_CODE); } diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AWeberExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AWeberExample.java index 505f29e1d..233d3a984 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AWeberExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AWeberExample.java @@ -8,7 +8,6 @@ import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; import com.github.scribejava.core.model.Verb; -import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuth10aService; public abstract class AWeberExample { @@ -40,12 +39,12 @@ public static void main(String... args) { System.out.println(service.getAuthorizationUrl(requestToken)); System.out.println("And paste the verifier here"); System.out.print(">>"); - final Verifier verifier = new Verifier(in.nextLine()); + final String oauthVerifier = in.nextLine(); System.out.println(); // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, verifier); + final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiggExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiggExample.java index f6ce3702e..690f95081 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiggExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiggExample.java @@ -8,7 +8,6 @@ import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; import com.github.scribejava.core.model.Verb; -import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuth10aService; public abstract class DiggExample { @@ -43,12 +42,12 @@ public static void main(String... args) { System.out.println(authorizationUrl); System.out.println("And paste the authorization code here"); System.out.print(">>"); - final Verifier verifier = new Verifier(in.nextLine()); + final String oauthVerifier = in.nextLine(); System.out.println(); // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, verifier); + final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncExample.java index a8075e9a1..e95fe7ab2 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncExample.java @@ -12,7 +12,6 @@ import com.github.scribejava.core.model.Response; import com.github.scribejava.core.model.ScribeJavaConfig; import com.github.scribejava.core.model.Verb; -import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuth20Service; public abstract class FacebookAsyncExample { @@ -55,7 +54,7 @@ public static void main(String... args) throws InterruptedException, ExecutionEx System.out.println(authorizationUrl); System.out.println("And paste the authorization code here"); System.out.print(">>"); - final Verifier verifier = new Verifier(in.nextLine()); + final String code = in.nextLine(); System.out.println(); System.out.println("And paste the state from server here. We have set 'secretState'='" + secretState + "'."); @@ -72,7 +71,7 @@ public static void main(String... args) throws InterruptedException, ExecutionEx // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - final OAuth2AccessToken accessToken = service.getAccessTokenAsync(verifier, null).get(); + final OAuth2AccessToken accessToken = service.getAccessTokenAsync(code, null).get(); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java index a7d4a76f4..28740b43a 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java @@ -8,7 +8,6 @@ import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; import com.github.scribejava.core.model.Verb; -import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuth20Service; public abstract class FacebookExample { @@ -41,7 +40,7 @@ public static void main(String... args) { System.out.println(authorizationUrl); System.out.println("And paste the authorization code here"); System.out.print(">>"); - final Verifier verifier = new Verifier(in.nextLine()); + final String code = in.nextLine(); System.out.println(); System.out.println("And paste the state from server here. We have set 'secretState'='" + secretState + "'."); @@ -58,7 +57,7 @@ public static void main(String... args) { // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - final OAuth2AccessToken accessToken = service.getAccessToken(verifier); + final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExample.java index 30a8d1a07..db08042ca 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExample.java @@ -8,7 +8,6 @@ import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; import com.github.scribejava.core.model.Verb; -import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuth10aService; public abstract class FlickrExample { @@ -39,12 +38,12 @@ public static void main(String... args) { System.out.println(authorizationUrl + "&perms=read"); System.out.println("And paste the verifier here"); System.out.print(">>"); - final Verifier verifier = new Verifier(in.nextLine()); + final String oauthVerifier = in.nextLine(); System.out.println(); // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, verifier); + final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java index 7f5e61a6b..c581aa484 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java @@ -7,7 +7,6 @@ import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; import com.github.scribejava.core.model.Verb; -import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuth20Service; public abstract class Foursquare2Example { @@ -37,12 +36,12 @@ public static void main(String... args) { System.out.println(authorizationUrl); System.out.println("And paste the authorization code here"); System.out.print(">>"); - final Verifier verifier = new Verifier(in.nextLine()); + final String code = in.nextLine(); System.out.println(); // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - final OAuth2AccessToken accessToken = service.getAccessToken(verifier); + final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FoursquareExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FoursquareExample.java index 7c48e71d5..90fa38848 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FoursquareExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FoursquareExample.java @@ -8,7 +8,6 @@ import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; import com.github.scribejava.core.model.Verb; -import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuth10aService; public abstract class FoursquareExample { @@ -35,12 +34,12 @@ public static void main(String... args) { System.out.println(service.getAuthorizationUrl(requestToken)); System.out.println("And paste the verifier here"); System.out.print(">>"); - final Verifier verifier = new Verifier(in.nextLine()); + final String oauthVerifier = in.nextLine(); System.out.println(); // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, verifier); + final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java index 46224cb3c..c72f72de0 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java @@ -9,7 +9,6 @@ import com.github.scribejava.core.model.Response; import com.github.scribejava.core.model.SignatureType; import com.github.scribejava.core.model.Verb; -import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuth10aService; public abstract class FreelancerExample { @@ -43,12 +42,12 @@ public static void main(String... args) { System.out.println(AUTHORIZE_URL + requestToken.getToken()); System.out.println("And paste the verifier here"); System.out.print(">>"); - final Verifier verifier = new Verifier(in.nextLine()); + final String oauthVerifier = in.nextLine(); System.out.println(); // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, verifier); + final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubExample.java index bbf78434c..fb12bf8f7 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubExample.java @@ -8,7 +8,6 @@ import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; import com.github.scribejava.core.model.Verb; -import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuth20Service; public abstract class GitHubExample { @@ -40,7 +39,7 @@ public static void main(String... args) { System.out.println(authorizationUrl); System.out.println("And paste the authorization code here"); System.out.print(">>"); - final Verifier verifier = new Verifier(in.nextLine()); + final String code = in.nextLine(); System.out.println(); System.out.println("And paste the state from server here. We have set 'secretState'='" + secretState + "'."); @@ -57,7 +56,7 @@ public static void main(String... args) { // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - final OAuth2AccessToken accessToken = service.getAccessToken(verifier); + final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java index 964560044..50ec20a62 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java @@ -8,7 +8,6 @@ import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; import com.github.scribejava.core.model.Verb; -import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuth20Service; import java.util.HashMap; import java.util.Map; @@ -49,7 +48,7 @@ public static void main(String... args) { System.out.println(authorizationUrl); System.out.println("And paste the authorization code here"); System.out.print(">>"); - final Verifier verifier = new Verifier(in.nextLine()); + final String code = in.nextLine(); System.out.println(); System.out.println("And paste the state from server here. We have set 'secretState'='" + secretState + "'."); @@ -66,7 +65,7 @@ public static void main(String... args) { // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - OAuth2AccessToken accessToken = service.getAccessToken(verifier); + OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HHExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HHExample.java index 9477ea363..ad9d687d1 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HHExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HHExample.java @@ -6,7 +6,6 @@ import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; import com.github.scribejava.core.model.Verb; -import com.github.scribejava.core.model.Verifier; import com.github.scribejava.apis.HHApi; import com.github.scribejava.core.model.OAuth2AccessToken; @@ -40,12 +39,12 @@ public static void main(String... args) { System.out.println(authorizationUrl); System.out.println("And paste the authorization code here"); System.out.print(">>"); - final Verifier verifier = new Verifier(in.nextLine()); + final String code = in.nextLine(); System.out.println(); // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - final OAuth2AccessToken accessToken = service.getAccessToken(verifier); + final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ImgurExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ImgurExample.java index 01409fbb6..d25acaa86 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ImgurExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ImgurExample.java @@ -6,7 +6,6 @@ import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; import com.github.scribejava.core.model.Verb; -import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuth20Service; import java.util.Scanner; @@ -37,12 +36,12 @@ public static void main(String... args) { System.out.println(authorizationUrl); System.out.println("And paste the authorization code here"); System.out.print(">>"); - final Verifier verifier = new Verifier(in.nextLine()); + final String code = in.nextLine(); System.out.println(); // Trade the Request Token and Verifier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - final OAuth2AccessToken accessToken = service.getAccessToken(verifier); + final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Kaixin20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Kaixin20Example.java index 17f5ac0fb..0034f979a 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Kaixin20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Kaixin20Example.java @@ -7,7 +7,6 @@ import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; import com.github.scribejava.core.model.Verb; -import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuth20Service; public abstract class Kaixin20Example { @@ -37,12 +36,12 @@ public static void main(String... args) { System.out.println(authorizationUrl); System.out.println("And paste the authorization code here"); System.out.print(">>"); - final Verifier verifier = new Verifier(in.nextLine()); + final String code = in.nextLine(); System.out.println(); // Trade the Request Token and Verifier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - final OAuth2AccessToken accessToken = service.getAccessToken(verifier); + final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); 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 e4506b374..d308b7c5c 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 @@ -7,7 +7,6 @@ import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; import com.github.scribejava.core.model.Verb; -import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuth20Service; public abstract class LinkedIn20Example { @@ -38,12 +37,12 @@ public static void main(String... args) { System.out.println(authorizationUrl); System.out.println("And paste the authorization code here"); System.out.print(">>"); - final Verifier verifier = new Verifier(in.nextLine()); + final String code = in.nextLine(); System.out.println(); // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - final OAuth2AccessToken accessToken = service.getAccessToken(verifier); + final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java index 5489688c8..6a8e327ec 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java @@ -8,7 +8,6 @@ import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; import com.github.scribejava.core.model.Verb; -import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuth10aService; public abstract class LinkedInExample { @@ -36,12 +35,12 @@ public static void main(String... args) { System.out.println(service.getAuthorizationUrl(requestToken)); System.out.println("And paste the verifier here"); System.out.print(">>"); - final Verifier verifier = new Verifier(in.nextLine()); + final String oauthVerifier = in.nextLine(); System.out.println(); // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, verifier); + final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java index 17a0d6aaf..a0a925cb5 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java @@ -8,7 +8,6 @@ import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; import com.github.scribejava.core.model.Verb; -import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuth10aService; public abstract class LinkedInExampleWithScopes { @@ -40,12 +39,12 @@ public static void main(String... args) { System.out.println(service.getAuthorizationUrl(requestToken)); System.out.println("And paste the verifier here"); System.out.print(">>"); - final Verifier verifier = new Verifier(in.nextLine()); + final String oauthVerifier = in.nextLine(); System.out.println(); // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, verifier); + final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java index 47536186e..c86eaa793 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java @@ -7,7 +7,6 @@ import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; import com.github.scribejava.core.model.Verb; -import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuth20Service; public abstract class LiveExample { @@ -38,12 +37,12 @@ public static void main(String... args) { System.out.println(authorizationUrl); System.out.println("And paste the authorization code here"); System.out.print(">>"); - final Verifier verifier = new Verifier(in.nextLine()); + final String code = in.nextLine(); System.out.println(); // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - final OAuth2AccessToken accessToken = service.getAccessToken(verifier); + final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LoveFilmExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LoveFilmExample.java index 55a22b416..161278ad5 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LoveFilmExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LoveFilmExample.java @@ -8,7 +8,6 @@ import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; import com.github.scribejava.core.model.Verb; -import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuth10aService; public abstract class LoveFilmExample { @@ -43,12 +42,12 @@ public static void main(String... args) { System.out.println(authorizationUrl); System.out.println("And paste the authorization code here"); System.out.print(">>"); - final Verifier verifier = new Verifier(in.nextLine()); + final String oauthVerifier = in.nextLine(); System.out.println(); // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, verifier); + final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java index 981690be6..10a787625 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java @@ -9,7 +9,6 @@ import com.github.scribejava.core.model.OAuthRequestAsync; import com.github.scribejava.core.model.Response; import com.github.scribejava.core.model.Verb; -import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuth20Service; public abstract class MailruAsyncExample { @@ -51,12 +50,12 @@ public static void main(String... args) throws InterruptedException, ExecutionEx System.out.println(authorizationUrl); System.out.println("And paste the authorization code here"); System.out.print(">>"); - final Verifier verifier = new Verifier(in.nextLine()); + final String code = in.nextLine(); System.out.println(); // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - final OAuth2AccessToken accessToken = service.getAccessTokenAsync(verifier, null).get(); + final OAuth2AccessToken accessToken = service.getAccessTokenAsync(code, null).get(); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java index 4d25f14c2..45cdb9a80 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java @@ -5,7 +5,6 @@ import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; import com.github.scribejava.core.model.Verb; -import com.github.scribejava.core.model.Verifier; import com.github.scribejava.apis.MailruApi; import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.oauth.OAuth20Service; @@ -39,12 +38,12 @@ public static void main(String... args) { System.out.println(authorizationUrl); System.out.println("And paste the authorization code here"); System.out.print(">>"); - final Verifier verifier = new Verifier(in.nextLine()); + final String code = in.nextLine(); System.out.println(); // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - final OAuth2AccessToken accessToken = service.getAccessToken(verifier); + final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java index 3028349ce..8adf45a52 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java @@ -8,7 +8,6 @@ import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; import com.github.scribejava.core.model.Verb; -import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuth10aService; public abstract class MeetupExample { @@ -35,12 +34,12 @@ public static void main(String... args) { System.out.println(service.getAuthorizationUrl(requestToken)); System.out.println("And paste the verifier here"); System.out.print(">>"); - final Verifier verifier = new Verifier(in.nextLine()); + final String oauthVerifier = in.nextLine(); System.out.println(); // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, verifier); + final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NeteaseWeiboExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NeteaseWeiboExample.java index 60f8082e3..31a210612 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NeteaseWeiboExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NeteaseWeiboExample.java @@ -8,7 +8,6 @@ import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; import com.github.scribejava.core.model.Verb; -import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuth10aService; public abstract class NeteaseWeiboExample { @@ -43,12 +42,12 @@ public static void main(String... args) { System.out.println(authorizationUrl); System.out.println("And paste the authorization code here"); System.out.print(">>"); - final Verifier verifier = new Verifier(in.nextLine()); + final String oauthVerifier = in.nextLine(); System.out.println(); // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, verifier); + final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java index 136b05774..88fb1ba93 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java @@ -8,7 +8,6 @@ import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; import com.github.scribejava.core.model.Verb; -import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuth20Service; public abstract class OdnoklassnikiExample { @@ -44,13 +43,13 @@ public static void main(String... args) { System.out.println(authorizationUrl); System.out.println("And paste the authorization code here"); System.out.print(">>"); - final Verifier verifier = new Verifier(in.nextLine()); + final String code = in.nextLine(); System.out.println(); // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - final OAuth2AccessToken accessToken = service.getAccessToken(verifier); + final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java index 3e0d1cb4b..13f7d77b4 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java @@ -6,7 +6,6 @@ import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; import com.github.scribejava.core.model.Verb; -import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuth20Service; import java.util.Scanner; @@ -38,12 +37,12 @@ public static void main(String... args) { System.out.println(authorizationUrl); System.out.println("And paste the authorization code here"); System.out.print(">>"); - final Verifier verifier = new Verifier(in.nextLine()); + final String code = in.nextLine(); System.out.println(); // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - final OAuth2AccessToken accessToken = service.getAccessToken(verifier); + final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Px500Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Px500Example.java index 3e969fd06..458aea185 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Px500Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Px500Example.java @@ -8,7 +8,6 @@ import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; import com.github.scribejava.core.model.Verb; -import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuth10aService; public abstract class Px500Example { @@ -35,12 +34,12 @@ public static void main(String... args) { System.out.println(service.getAuthorizationUrl(requestToken)); System.out.println("And paste the verifier here"); System.out.print(">>"); - final Verifier verifier = new Verifier(in.nextLine()); + final String oauthVerifier = in.nextLine(); System.out.println(); // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, verifier); + final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java index 392ff3881..75f132a4b 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java @@ -16,7 +16,6 @@ import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; import com.github.scribejava.core.model.Verb; -import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuth20Service; public abstract class RenrenExample { @@ -47,12 +46,12 @@ public static void main(String... args) { System.out.println(authorizationUrl); System.out.println("And paste the authorization code here"); System.out.print(">>"); - final Verifier verifier = new Verifier(in.nextLine()); + final String code = in.nextLine(); System.out.println(); // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - final OAuth2AccessToken accessToken = service.getAccessToken(verifier); + final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeibo2Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeibo2Example.java index 230f28875..1a67ad8ed 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeibo2Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeibo2Example.java @@ -7,7 +7,6 @@ import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; import com.github.scribejava.core.model.Verb; -import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuth20Service; public abstract class SinaWeibo2Example { @@ -37,12 +36,12 @@ public static void main(String... args) { System.out.println(authorizationUrl); System.out.println("And paste the authorization code here"); System.out.print(">>"); - final Verifier verifier = new Verifier(in.nextLine()); + final String code = in.nextLine(); System.out.println(); // Trade the Request Token and Verifier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - final OAuth2AccessToken accessToken = service.getAccessToken(verifier); + final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeiboExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeiboExample.java index 42962c6ed..1d8625059 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeiboExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeiboExample.java @@ -8,7 +8,6 @@ import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; import com.github.scribejava.core.model.Verb; -import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuth10aService; public abstract class SinaWeiboExample { @@ -43,12 +42,12 @@ public static void main(String... args) { System.out.println(authorizationUrl); System.out.println("And paste the authorization code here"); System.out.print(">>"); - final Verifier verifier = new Verifier(in.nextLine()); + final String oauthVerifier = in.nextLine(); System.out.println(); // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, verifier); + final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SkyrockExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SkyrockExample.java index c90e658d2..121a3da0f 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SkyrockExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SkyrockExample.java @@ -8,7 +8,6 @@ import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; import com.github.scribejava.core.model.Verb; -import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuth10aService; public abstract class SkyrockExample { @@ -35,12 +34,12 @@ public static void main(String... args) { System.out.println(service.getAuthorizationUrl(requestToken)); System.out.println("And paste the verifier here"); System.out.print(">>"); - final Verifier verifier = new Verifier(in.nextLine()); + final String oauthVerifier = in.nextLine(); System.out.println(); // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, verifier); + final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SohuWeiboExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SohuWeiboExample.java index 9bd89762d..c554208ab 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SohuWeiboExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SohuWeiboExample.java @@ -8,7 +8,6 @@ import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; import com.github.scribejava.core.model.Verb; -import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuth10aService; public abstract class SohuWeiboExample { @@ -43,12 +42,12 @@ public static void main(String... args) { System.out.println(authorizationUrl); System.out.println("And paste the authorization code here"); System.out.print(">>"); - final Verifier verifier = new Verifier(in.nextLine()); + final String oauthVerifier = in.nextLine(); System.out.println(); // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, verifier); + final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/StackExchangeExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/StackExchangeExample.java index 47d43168e..affa6a812 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/StackExchangeExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/StackExchangeExample.java @@ -9,7 +9,6 @@ import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; import com.github.scribejava.core.model.Verb; -import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuth20Service; public abstract class StackExchangeExample { @@ -45,7 +44,7 @@ public static void main(String... args) { System.out.println(authorizationUrl); System.out.println("And paste the authorization code here"); System.out.print(">>"); - final Verifier verifier = new Verifier(in.nextLine()); + final String code = in.nextLine(); System.out.println(); System.out.println("And paste the state from server here. We have set 'secretState'='" + secretState + "'."); @@ -62,7 +61,7 @@ public static void main(String... args) { // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - final OAuth2AccessToken accessToken = service.getAccessToken(verifier); + final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TrelloExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TrelloExample.java index 1c274a060..bc3147b34 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TrelloExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TrelloExample.java @@ -8,7 +8,6 @@ import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; import com.github.scribejava.core.model.Verb; -import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuth10aService; public abstract class TrelloExample { @@ -37,12 +36,12 @@ public static void main(String... args) { System.out.println(service.getAuthorizationUrl(requestToken)); System.out.println("And paste the verifier here"); System.out.print(">>"); - final Verifier verifier = new Verifier(in.nextLine()); + final String oauthVerifier = in.nextLine(); System.out.println(); // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, verifier); + final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TumblrExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TumblrExample.java index 413214eec..881cebd6d 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TumblrExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TumblrExample.java @@ -8,7 +8,6 @@ import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; import com.github.scribejava.core.model.Verb; -import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuth10aService; public abstract class TumblrExample { @@ -37,12 +36,12 @@ public static void main(String... args) { System.out.println(service.getAuthorizationUrl(requestToken)); System.out.println("And paste the verifier here"); System.out.print(">>"); - final Verifier verifier = new Verifier(in.nextLine()); + final String oauthVerifier = in.nextLine(); System.out.println(); // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, verifier); + final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TutByExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TutByExample.java index 74ae83af9..4f201c85e 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TutByExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TutByExample.java @@ -7,7 +7,6 @@ import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; import com.github.scribejava.core.model.Verb; -import com.github.scribejava.core.model.Verifier; import com.github.scribejava.apis.TutByApi; import com.github.scribejava.core.model.OAuth2AccessToken; @@ -40,12 +39,12 @@ public static void main(String... args) { System.out.println(authorizationUrl); System.out.println("And paste the authorization code here"); System.out.print(">>"); - final Verifier verifier = new Verifier(in.nextLine()); + final String code = in.nextLine(); System.out.println(); // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - final OAuth2AccessToken accessToken = service.getAccessToken(verifier); + final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TwitterExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TwitterExample.java index 90446f8a6..4a46982aa 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TwitterExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TwitterExample.java @@ -8,7 +8,6 @@ import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; import com.github.scribejava.core.model.Verb; -import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuth10aService; public abstract class TwitterExample { @@ -35,12 +34,12 @@ public static void main(String... args) { System.out.println(service.getAuthorizationUrl(requestToken)); System.out.println("And paste the verifier here"); System.out.print(">>"); - final Verifier verifier = new Verifier(in.nextLine()); + final String oauthVerifier = in.nextLine(); System.out.println(); // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, verifier); + final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ViadeoExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ViadeoExample.java index caffce403..3d8d12904 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ViadeoExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ViadeoExample.java @@ -7,7 +7,6 @@ import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; import com.github.scribejava.core.model.Verb; -import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuth20Service; public abstract class ViadeoExample { @@ -37,12 +36,12 @@ public static void main(String... args) { System.out.println(authorizationUrl); System.out.println("And paste the authorization code here"); System.out.print(">>"); - final Verifier verifier = new Verifier(in.nextLine()); + final String code = in.nextLine(); System.out.println(); // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - final OAuth2AccessToken accessToken = service.getAccessToken(verifier); + final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); 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 d9be140d5..f026fbbc0 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 @@ -7,7 +7,6 @@ import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; import com.github.scribejava.core.model.Verb; -import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuth20Service; public abstract class VkontakteExample { @@ -38,12 +37,12 @@ public static void main(String... args) { System.out.println(authorizationUrl); System.out.println("And paste the authorization code here"); System.out.print(">>"); - final Verifier verifier = new Verifier(in.nextLine()); + final String code = in.nextLine(); System.out.println(); // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - final OAuth2AccessToken accessToken = service.getAccessToken(verifier); + final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XingExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XingExample.java index c09b1ddc3..50ab3c6ba 100755 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XingExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XingExample.java @@ -8,7 +8,6 @@ import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; import com.github.scribejava.core.model.Verb; -import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuth10aService; public abstract class XingExample { @@ -35,12 +34,12 @@ public static void main(String... args) { System.out.println(service.getAuthorizationUrl(requestToken)); System.out.println("And paste the verifier here"); System.out.print(">>"); - final Verifier verifier = new Verifier(in.nextLine()); + final String oauthVerifier = in.nextLine(); System.out.println(); // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, verifier); + final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/YahooExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/YahooExample.java index d6f8e2e72..ee93da83a 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/YahooExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/YahooExample.java @@ -8,7 +8,6 @@ import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; import com.github.scribejava.core.model.Verb; -import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.oauth.OAuth10aService; public abstract class YahooExample { @@ -36,12 +35,12 @@ public static void main(String... args) { System.out.println(service.getAuthorizationUrl(requestToken)); System.out.println("And paste the verifier here"); System.out.print(">>"); - final Verifier verifier = new Verifier(in.nextLine()); + final String oauthVerifier = in.nextLine(); System.out.println(); // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, verifier); + final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/Verifier.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/Verifier.java deleted file mode 100644 index fc8a92195..000000000 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/Verifier.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.github.scribejava.core.model; - -import com.github.scribejava.core.utils.Preconditions; - -/** - * Represents an OAuth verifier code. - */ -public class Verifier { - - private final String value; - - /** - * Default constructor. - * - * @param value verifier value - */ - public Verifier(String value) { - Preconditions.checkNotNull(value, "Must provide a valid string as verifier"); - this.value = value; - } - - public String getValue() { - return value; - } -} 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 b03001d77..c9c99a03f 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 @@ -14,7 +14,6 @@ import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.OAuthRequestAsync; import com.github.scribejava.core.model.Response; -import com.github.scribejava.core.model.Verifier; import com.github.scribejava.core.services.Base64Encoder; import com.github.scribejava.core.utils.MapUtils; @@ -76,11 +75,11 @@ private void addOAuthParams(AbstractRequest request, String tokenSecret) { config.log("appended additional OAuth parameters: " + MapUtils.toString(request.getOauthParameters())); } - public final OAuth1AccessToken getAccessToken(OAuth1RequestToken requestToken, Verifier verifier) { + public final OAuth1AccessToken getAccessToken(OAuth1RequestToken requestToken, String oauthVerifier) { final OAuthConfig config = getConfig(); config.log("obtaining access token from " + api.getAccessTokenEndpoint()); final OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint(), this); - prepareAccessTokenRequest(request, requestToken, verifier); + prepareAccessTokenRequest(request, requestToken, oauthVerifier); final Response response = request.send(); return api.getAccessTokenExtractor().extract(response.getBody()); } @@ -90,22 +89,22 @@ public final OAuth1AccessToken getAccessToken(OAuth1RequestToken requestToken, V * callback will be called with the Token when it is available. * * @param requestToken request token (obtained previously or null) - * @param verifier verifier code + * @param oauthVerifier oauth_verifier * @param callback optional callback * @return Future */ - public final Future getAccessTokenAsync(OAuth1RequestToken requestToken, Verifier verifier, + public final Future getAccessTokenAsync(OAuth1RequestToken requestToken, String oauthVerifier, OAuthAsyncRequestCallback callback) { - return getAccessTokenAsync(requestToken, verifier, callback, null); + return getAccessTokenAsync(requestToken, oauthVerifier, callback, null); } - public final Future getAccessTokenAsync(OAuth1RequestToken requestToken, Verifier verifier, + public final Future getAccessTokenAsync(OAuth1RequestToken requestToken, String oauthVerifier, OAuthAsyncRequestCallback callback, ProxyServer proxyServer) { final OAuthConfig config = getConfig(); config.log("async obtaining access token from " + api.getAccessTokenEndpoint()); final OAuthRequestAsync request = new OAuthRequestAsync(api.getAccessTokenVerb(), api.getAccessTokenEndpoint(), this); - prepareAccessTokenRequest(request, requestToken, verifier); + prepareAccessTokenRequest(request, requestToken, oauthVerifier); return request.sendAsync(callback, new OAuthRequestAsync.ResponseConverter() { @Override public OAuth1AccessToken convert(com.ning.http.client.Response response) throws IOException { @@ -116,11 +115,11 @@ public OAuth1AccessToken convert(com.ning.http.client.Response response) throws } protected void prepareAccessTokenRequest(AbstractRequest request, OAuth1RequestToken requestToken, - Verifier verifier) { + String oauthVerifier) { final OAuthConfig config = getConfig(); request.addOAuthParameter(OAuthConstants.TOKEN, requestToken.getToken()); - request.addOAuthParameter(OAuthConstants.VERIFIER, verifier.getValue()); - config.log("setting token to: " + requestToken + " and verifier to: " + verifier); + request.addOAuthParameter(OAuthConstants.VERIFIER, oauthVerifier); + config.log("setting token to: " + requestToken + " and verifier to: " + oauthVerifier); addOAuthParams(request, requestToken.getTokenSecret()); appendSignature(request); } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java index 57f8d09fd..8f71c2ec4 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 @@ -12,7 +12,6 @@ import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.OAuthRequestAsync; import com.github.scribejava.core.model.Response; -import com.github.scribejava.core.model.Verifier; import java.util.Map; public class OAuth20Service extends OAuthService { @@ -31,8 +30,8 @@ public OAuth20Service(DefaultApi20 api, OAuthConfig config) { this.api = api; } - public final OAuth2AccessToken getAccessToken(Verifier verifier) { - final Response response = createAccessTokenRequest(verifier, + public final OAuth2AccessToken getAccessToken(String code) { + final Response response = createAccessTokenRequest(code, new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint(), this)).send(); return api.getAccessTokenExtractor().extract(response.getBody()); } @@ -41,18 +40,18 @@ public final OAuth2AccessToken getAccessToken(Verifier verifier) { * Start the request to retrieve the access token. The optionally provided callback will be called with the Token * when it is available. * - * @param verifier verifier code + * @param code code * @param callback optional callback * @return Future */ - public final Future getAccessTokenAsync(Verifier verifier, + public final Future getAccessTokenAsync(String code, OAuthAsyncRequestCallback callback) { - return getAccessTokenAsync(verifier, callback, null); + return getAccessTokenAsync(code, callback, null); } - public final Future getAccessTokenAsync(Verifier verifier, + public final Future getAccessTokenAsync(String code, OAuthAsyncRequestCallback callback, ProxyServer proxyServer) { - final OAuthRequestAsync request = createAccessTokenRequest(verifier, + final OAuthRequestAsync request = createAccessTokenRequest(code, new OAuthRequestAsync(api.getAccessTokenVerb(), api.getAccessTokenEndpoint(), this)); return request.sendAsync(callback, new OAuthRequestAsync.ResponseConverter() { @Override @@ -63,11 +62,11 @@ public OAuth2AccessToken convert(com.ning.http.client.Response response) throws }, proxyServer); } - protected T createAccessTokenRequest(Verifier verifier, T request) { + protected T createAccessTokenRequest(String code, T request) { final OAuthConfig config = getConfig(); request.addParameter(OAuthConstants.CLIENT_ID, config.getApiKey()); request.addParameter(OAuthConstants.CLIENT_SECRET, config.getApiSecret()); - request.addParameter(OAuthConstants.CODE, verifier.getValue()); + request.addParameter(OAuthConstants.CODE, code); request.addParameter(OAuthConstants.REDIRECT_URI, config.getCallback()); if (config.hasScope()) { request.addParameter(OAuthConstants.SCOPE, config.getScope()); From bbb2aaa020a2f6a12cc16b109838a097d423e8eb Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 10 Mar 2016 19:52:43 +0300 Subject: [PATCH 158/882] default HTTP verb for OAuth 2.0 Access Token EndPoint is POST (http://tools.ietf.org/html/rfc6749#section-3.2) --- changelog | 1 + .../com/github/scribejava/apis/ConstantContactApi2.java | 6 ------ .../java/com/github/scribejava/apis/DoktornaraboteApi.java | 6 ------ .../main/java/com/github/scribejava/apis/FacebookApi.java | 6 ++++++ .../java/com/github/scribejava/apis/Foursquare2Api.java | 6 ++++++ .../src/main/java/com/github/scribejava/apis/GitHubApi.java | 6 ++++++ .../main/java/com/github/scribejava/apis/GoogleApi20.java | 6 ------ .../src/main/java/com/github/scribejava/apis/HHApi.java | 6 ------ .../src/main/java/com/github/scribejava/apis/ImgurApi.java | 6 ------ .../main/java/com/github/scribejava/apis/KaixinApi20.java | 6 ++++++ .../src/main/java/com/github/scribejava/apis/LiveApi.java | 6 ++++++ .../src/main/java/com/github/scribejava/apis/MailruApi.java | 6 ------ .../java/com/github/scribejava/apis/OdnoklassnikiApi.java | 6 ------ .../main/java/com/github/scribejava/apis/PinterestApi.java | 6 ------ .../src/main/java/com/github/scribejava/apis/RenrenApi.java | 6 ++++++ .../java/com/github/scribejava/apis/SinaWeiboApi20.java | 6 ------ .../java/com/github/scribejava/apis/StackExchangeApi.java | 6 ------ .../src/main/java/com/github/scribejava/apis/TutByApi.java | 6 ------ .../src/main/java/com/github/scribejava/apis/ViadeoApi.java | 6 ++++++ .../main/java/com/github/scribejava/apis/VkontakteApi.java | 6 ++++++ .../github/scribejava/core/builder/api/DefaultApi20.java | 4 ++-- 21 files changed, 51 insertions(+), 68 deletions(-) diff --git a/changelog b/changelog index fce98d4ac..92d93940c 100644 --- a/changelog +++ b/changelog @@ -5,6 +5,7 @@ * drop Google OAuth 1.0 support (OAuth 1.0 was officially deprecated by Google) * add response_type parameter to the ServiceBuilder/OAuthConfig to use not only "code" for authorization code * remove Verifier object, we just need Strings, 'code' for OAuth2 and 'oauthVerifier' for OAuth1 + * default HTTP verb for OAuth 2.0 Access Token EndPoint is POST (http://tools.ietf.org/html/rfc6749#section-3.2) [2.3.0] * Stack Exchange authentication via OAuth 2.0 (stackoverflow.com, askubuntu.com, etc.). diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/ConstantContactApi2.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/ConstantContactApi2.java index d910e73b9..3dd0af0a2 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/ConstantContactApi2.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/ConstantContactApi2.java @@ -7,7 +7,6 @@ import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; -import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.utils.OAuthEncoder; public class ConstantContactApi2 extends DefaultApi20 { @@ -37,11 +36,6 @@ public String getAuthorizationUrl(OAuthConfig config) { return String.format(AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback())); } - @Override - public Verb getAccessTokenVerb() { - return Verb.POST; - } - @Override public TokenExtractor getAccessTokenExtractor() { return ConstantContactTokenExtractor.instance(); diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/DoktornaraboteApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/DoktornaraboteApi.java index 41c67cc9c..6332aa198 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/DoktornaraboteApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/DoktornaraboteApi.java @@ -4,7 +4,6 @@ import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; -import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.oauth.OAuth20Service; import com.github.scribejava.core.utils.OAuthEncoder; import com.github.scribejava.core.utils.Preconditions; @@ -26,11 +25,6 @@ public static DoktornaraboteApi instance() { return InstanceHolder.INSTANCE; } - @Override - public Verb getAccessTokenVerb() { - return Verb.POST; - } - @Override public String getAccessTokenEndpoint() { return TOKEN_URL; 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 3412967e9..a2c18b2d6 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 @@ -3,6 +3,7 @@ import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; +import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.utils.OAuthEncoder; import com.github.scribejava.core.utils.Preconditions; @@ -26,6 +27,11 @@ public static FacebookApi instance() { return InstanceHolder.INSTANCE; } + @Override + public Verb getAccessTokenVerb() { + return Verb.GET; + } + @Override public String getAccessTokenEndpoint() { return "https://graph.facebook.com/v2.5/oauth/access_token"; diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/Foursquare2Api.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/Foursquare2Api.java index b8dc4f594..2e65672f0 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/Foursquare2Api.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/Foursquare2Api.java @@ -3,6 +3,7 @@ import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; +import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.utils.OAuthEncoder; import com.github.scribejava.core.utils.Preconditions; @@ -22,6 +23,11 @@ public static Foursquare2Api instance() { return InstanceHolder.INSTANCE; } + @Override + public Verb getAccessTokenVerb() { + return Verb.GET; + } + @Override public String getAccessTokenEndpoint() { return "https://foursquare.com/oauth2/access_token?grant_type=" + OAuthConstants.AUTHORIZATION_CODE; diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/GitHubApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/GitHubApi.java index 9b3129af0..12ed978dd 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/GitHubApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/GitHubApi.java @@ -6,6 +6,7 @@ import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; +import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.utils.OAuthEncoder; import com.github.scribejava.core.utils.Preconditions; @@ -24,6 +25,11 @@ public static GitHubApi instance() { return InstanceHolder.INSTANCE; } + @Override + public Verb getAccessTokenVerb() { + return Verb.GET; + } + @Override public String getAccessTokenEndpoint() { return "https://github.com/login/oauth/access_token"; diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/GoogleApi20.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/GoogleApi20.java index b1abc4fe3..26d003bdd 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/GoogleApi20.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/GoogleApi20.java @@ -7,7 +7,6 @@ import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; -import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.oauth.OAuth20Service; import com.github.scribejava.core.utils.OAuthEncoder; @@ -27,11 +26,6 @@ public static GoogleApi20 instance() { return InstanceHolder.INSTANCE; } - @Override - public Verb getAccessTokenVerb() { - return Verb.POST; - } - @Override public String getAccessTokenEndpoint() { return "https://www.googleapis.com/oauth2/v4/token"; diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/HHApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/HHApi.java index 980bd1693..ca67c8fca 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/HHApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/HHApi.java @@ -2,7 +2,6 @@ import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.model.OAuthConfig; -import com.github.scribejava.core.model.Verb; import com.github.scribejava.apis.service.HHOAuthServiceImpl; import com.github.scribejava.core.oauth.OAuth20Service; @@ -26,11 +25,6 @@ public static HHApi instance() { return InstanceHolder.INSTANCE; } - @Override - public Verb getAccessTokenVerb() { - return Verb.POST; - } - @Override public String getAccessTokenEndpoint() { return TOKEN_URL; diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java index c5ed43f73..d55ad2d99 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java @@ -3,7 +3,6 @@ import com.github.scribejava.apis.service.ImgurOAuthServiceImpl; import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.model.OAuthConfig; -import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.oauth.OAuth20Service; public class ImgurApi extends DefaultApi20 { @@ -22,11 +21,6 @@ public static ImgurApi instance() { return InstanceHolder.INSTANCE; } - @Override - public Verb getAccessTokenVerb() { - return Verb.POST; - } - @Override public String getAccessTokenEndpoint() { return "https://api.imgur.com/oauth2/token"; diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/KaixinApi20.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/KaixinApi20.java index 08062b828..979a4b5a4 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/KaixinApi20.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/KaixinApi20.java @@ -3,6 +3,7 @@ import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; +import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.utils.OAuthEncoder; /** @@ -25,6 +26,11 @@ public static KaixinApi20 instance() { return InstanceHolder.INSTANCE; } + @Override + public Verb getAccessTokenVerb() { + return Verb.GET; + } + @Override public String getAccessTokenEndpoint() { return "https://api.kaixin001.com/oauth2/access_token?grant_type=" + OAuthConstants.AUTHORIZATION_CODE; diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/LiveApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/LiveApi.java index d40d62cba..8d02a199c 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/LiveApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/LiveApi.java @@ -3,6 +3,7 @@ import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; +import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.utils.OAuthEncoder; import com.github.scribejava.core.utils.Preconditions; @@ -23,6 +24,11 @@ public static LiveApi instance() { return InstanceHolder.INSTANCE; } + @Override + public Verb getAccessTokenVerb() { + return Verb.GET; + } + @Override public String getAccessTokenEndpoint() { return "https://login.live.com/oauth20_token.srf?grant_type=" + OAuthConstants.AUTHORIZATION_CODE; diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java index e520309d8..a15b45634 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java @@ -2,7 +2,6 @@ import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.model.OAuthConfig; -import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.utils.OAuthEncoder; import com.github.scribejava.core.utils.Preconditions; import com.github.scribejava.apis.service.MailruOAuthServiceImpl; @@ -25,11 +24,6 @@ public static MailruApi instance() { return InstanceHolder.INSTANCE; } - @Override - public Verb getAccessTokenVerb() { - return Verb.POST; - } - @Override public String getAccessTokenEndpoint() { return "https://connect.mail.ru/oauth/token"; diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java index 42c15d31f..de8fdfa8a 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java @@ -3,7 +3,6 @@ import com.github.scribejava.apis.service.OdnoklassnikiServiceImpl; import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.model.OAuthConfig; -import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.oauth.OAuth20Service; import com.github.scribejava.core.utils.OAuthEncoder; import com.github.scribejava.core.utils.Preconditions; @@ -30,11 +29,6 @@ public String getAccessTokenEndpoint() { return "http://api.odnoklassniki.ru/oauth/token.do"; } - @Override - public Verb getAccessTokenVerb() { - return Verb.POST; - } - @Override public String getAuthorizationUrl(OAuthConfig config) { Preconditions.checkValidUrl(config.getCallback(), diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/PinterestApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/PinterestApi.java index d5a1fab76..0e3f96c4d 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/PinterestApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/PinterestApi.java @@ -3,7 +3,6 @@ import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; -import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.utils.OAuthEncoder; import com.github.scribejava.core.utils.Preconditions; @@ -29,11 +28,6 @@ public String getAccessTokenEndpoint() { return "https://api.pinterest.com/v1/oauth/token?grant_type=" + OAuthConstants.AUTHORIZATION_CODE; } - @Override - public Verb getAccessTokenVerb() { - return Verb.POST; - } - @Override public String getAuthorizationUrl(OAuthConfig config) { Preconditions.checkValidUrl(config.getCallback(), diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/RenrenApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/RenrenApi.java index d28f55c4d..726baffd4 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/RenrenApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/RenrenApi.java @@ -3,6 +3,7 @@ import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; +import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.utils.OAuthEncoder; /** @@ -25,6 +26,11 @@ public static RenrenApi instance() { return InstanceHolder.INSTANCE; } + @Override + public Verb getAccessTokenVerb() { + return Verb.GET; + } + @Override public String getAccessTokenEndpoint() { return "https://graph.renren.com/oauth/token?grant_type=" + OAuthConstants.AUTHORIZATION_CODE; diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/SinaWeiboApi20.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/SinaWeiboApi20.java index fe9fde760..b0edb459d 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/SinaWeiboApi20.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/SinaWeiboApi20.java @@ -3,7 +3,6 @@ import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; -import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.utils.OAuthEncoder; /** @@ -26,11 +25,6 @@ public static SinaWeiboApi20 instance() { return InstanceHolder.INSTANCE; } - @Override - public Verb getAccessTokenVerb() { - return Verb.POST; - } - @Override public String getAccessTokenEndpoint() { return "https://api.weibo.com/oauth2/access_token?grant_type=" + OAuthConstants.AUTHORIZATION_CODE; diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/StackExchangeApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/StackExchangeApi.java index 999fd5bea..e2e8c5b25 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/StackExchangeApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/StackExchangeApi.java @@ -6,7 +6,6 @@ import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; -import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.utils.OAuthEncoder; import com.github.scribejava.core.utils.Preconditions; @@ -29,11 +28,6 @@ public static StackExchangeApi instance() { return InstanceHolder.INSTANCE; } - @Override - public Verb getAccessTokenVerb() { - return Verb.POST; - } - @Override public String getAccessTokenEndpoint() { return "https://stackexchange.com/oauth/access_token"; diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/TutByApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/TutByApi.java index 7e5324644..72d3e13fd 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/TutByApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/TutByApi.java @@ -2,7 +2,6 @@ import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.model.OAuthConfig; -import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.utils.OAuthEncoder; import com.github.scribejava.core.utils.Preconditions; import com.github.scribejava.apis.service.TutByOAuthServiceImpl; @@ -29,11 +28,6 @@ public String getAccessTokenEndpoint() { return "http://profile.tut.by/getToken"; } - @Override - public Verb getAccessTokenVerb() { - return Verb.POST; - } - @Override public String getAuthorizationUrl(OAuthConfig config) { Preconditions.checkValidUrl(config.getCallback(), diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/ViadeoApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/ViadeoApi.java index abe864d9a..a84c15195 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/ViadeoApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/ViadeoApi.java @@ -3,6 +3,7 @@ import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; +import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.utils.OAuthEncoder; import com.github.scribejava.core.utils.Preconditions; @@ -23,6 +24,11 @@ public static ViadeoApi instance() { return InstanceHolder.INSTANCE; } + @Override + public Verb getAccessTokenVerb() { + return Verb.GET; + } + @Override public String getAccessTokenEndpoint() { return "https://secure.viadeo.com/oauth-provider/access_token2?grant_type=" + OAuthConstants.AUTHORIZATION_CODE; diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/VkontakteApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/VkontakteApi.java index 6ed78fc46..5ee9a88fe 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/VkontakteApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/VkontakteApi.java @@ -2,6 +2,7 @@ import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.model.OAuthConfig; +import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.utils.OAuthEncoder; import com.github.scribejava.core.utils.Preconditions; @@ -22,6 +23,11 @@ public static VkontakteApi instance() { return InstanceHolder.INSTANCE; } + @Override + public Verb getAccessTokenVerb() { + return Verb.GET; + } + @Override public String getAccessTokenEndpoint() { return "https://oauth.vk.com/access_token"; diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java index e70397465..4e27aebb0 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java @@ -34,12 +34,12 @@ public TokenExtractor getAccessTokenExtractor() { } /** - * Returns the verb for the access token endpoint (defaults to GET) + * Returns the verb for the access token endpoint (defaults to POST) * * @return access token endpoint verb */ public Verb getAccessTokenVerb() { - return Verb.GET; + return Verb.POST; } /** From edec091016f149554b9defa5d35aada2bee6b185 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 10 Mar 2016 19:54:59 +0300 Subject: [PATCH 159/882] update maven dependencies --- pom.xml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index d34a6276f..c8145a713 100644 --- a/pom.xml +++ b/pom.xml @@ -90,7 +90,7 @@ com.ning async-http-client - 1.9.32 + 1.9.33 provided
@@ -105,7 +105,7 @@ maven-compiler-plugin - 3.5 + 3.5.1 UTF-8 1.7 @@ -137,7 +137,7 @@ org.apache.maven.plugins maven-source-plugin - 2.4 + 3.0.0 attach-sources @@ -171,7 +171,7 @@ com.puppycrawl.tools checkstyle - 6.14.1 + 6.16.1 From 1d9553f3f9a4943956ee7370b03556749655d28e Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 11 Mar 2016 12:41:03 +0300 Subject: [PATCH 160/882] send missed headers in async version (as in sync) --- changelog | 1 + .../core/model/OAuthRequestAsync.java | 57 ++++++++++--------- 2 files changed, 30 insertions(+), 28 deletions(-) diff --git a/changelog b/changelog index 92d93940c..efe3c7eba 100644 --- a/changelog +++ b/changelog @@ -6,6 +6,7 @@ * add response_type parameter to the ServiceBuilder/OAuthConfig to use not only "code" for authorization code * remove Verifier object, we just need Strings, 'code' for OAuth2 and 'oauthVerifier' for OAuth1 * default HTTP verb for OAuth 2.0 Access Token EndPoint is POST (http://tools.ietf.org/html/rfc6749#section-3.2) + * send missed headers in async version (as in sync) [2.3.0] * Stack Exchange authentication via OAuth 2.0 (stackoverflow.com, askubuntu.com, etc.). diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequestAsync.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequestAsync.java index 42c825efb..846320046 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequestAsync.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequestAsync.java @@ -38,6 +38,21 @@ public OAuthRequestAsync(Verb verb, String url, OAuthService service) { super(verb, url, service); } + private Map> mapHeaders() { + final Map> mapped = new HashMap<>(); + + for (Map.Entry header : getHeaders().entrySet()) { + final String headerName = header.getKey(); + Collection headerValues = mapped.get(headerName); + if (headerValues == null) { + headerValues = new ArrayList<>(); + mapped.put(headerName, headerValues); + } + headerValues.add(header.getValue()); + } + return mapped; + } + public Future sendAsync(OAuthAsyncRequestCallback callback, ResponseConverter converter) { return sendAsync(callback, converter, null); } @@ -54,48 +69,26 @@ public Future sendAsync(OAuthAsyncRequestCallback callback, ResponseCo } final String completeUrl = getCompleteUrl(); final AsyncHttpClient.BoundRequestBuilder boundRequestBuilder; + final AsyncHttpClient asyncHttpClient = service.getAsyncHttpClient(); switch (getVerb()) { case GET: - boundRequestBuilder = service.getAsyncHttpClient() - .prepareGet(completeUrl) - .setHeaders(mapHeaders()); - + boundRequestBuilder = asyncHttpClient.prepareGet(completeUrl); break; case POST: - boundRequestBuilder = service.getAsyncHttpClient().preparePost(completeUrl) - .setBody(getBodyContents()) - .setHeaders(mapHeaders()); - + boundRequestBuilder = asyncHttpClient.preparePost(completeUrl).setBody(getBodyContents()); break; default: throw new IllegalArgumentException("message build error: unknown verb type"); } + + boundRequestBuilder.setHeaders(mapHeaders()); + if (proxyServer != null) { boundRequestBuilder.setProxyServer(proxyServer); } return boundRequestBuilder.execute(new OAuthAsyncCompletionHandler<>(callback, converter)); } - public Future sendAsync(OAuthAsyncRequestCallback callback) { - return sendAsync(callback, RESPONSE_CONVERTER, null); - } - - public Future sendAsync(OAuthAsyncRequestCallback callback, ProxyServer proxyServer) { - return sendAsync(callback, RESPONSE_CONVERTER, proxyServer); - } - - private Map> mapHeaders() { - final Map headers = getHeaders(); - final Map> mapped = new HashMap<>(); - - for(Map.Entry entry: headers.entrySet()) { - final ArrayList list = new ArrayList<>(); - list.add(entry.getValue()); - mapped.put(entry.getKey(), list); - } - return mapped; - } - private static class OAuthAsyncCompletionHandler extends AsyncCompletionHandler { private final OAuthAsyncRequestCallback callback; @@ -123,6 +116,14 @@ public void onThrowable(Throwable t) { } }; + public Future sendAsync(OAuthAsyncRequestCallback callback) { + return sendAsync(callback, RESPONSE_CONVERTER, null); + } + + public Future sendAsync(OAuthAsyncRequestCallback callback, ProxyServer proxyServer) { + return sendAsync(callback, RESPONSE_CONVERTER, proxyServer); + } + public interface ResponseConverter { T convert(com.ning.http.client.Response response) throws IOException; From f0c92a3156897d0783f9ab5521205dd94b7bc785 Mon Sep 17 00:00:00 2001 From: Maksim Likharev Date: Fri, 11 Mar 2016 10:58:47 -0800 Subject: [PATCH 161/882] removal of dead code --- .../core/utils/Uninterruptibles.java | 37 ------------------- 1 file changed, 37 deletions(-) delete mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/utils/Uninterruptibles.java diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/utils/Uninterruptibles.java b/scribejava-core/src/main/java/com/github/scribejava/core/utils/Uninterruptibles.java deleted file mode 100644 index c3ed57995..000000000 --- a/scribejava-core/src/main/java/com/github/scribejava/core/utils/Uninterruptibles.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.github.scribejava.core.utils; - -import com.github.scribejava.core.exceptions.OAuthException; - -import java.util.concurrent.ExecutionException; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Future; - -public final class Uninterruptibles { - /** - * - * This is part of the code from guava, copied here as the project doesn't include one. - * - * Invokes {@code future.}{@link Future#get() get()} uninterruptibly. - */ - public static V getUninterruptibly(Future future) { - boolean interrupted = false; - try { - while (true) { - try { - return future.get(); - } catch (InterruptedException e) { - interrupted = true; - } - } - } - catch( ExecutionException e ) { - throw new OAuthException( e ); - } - finally { - if (interrupted) { - Thread.currentThread().interrupt(); - } - } - } - -} From 5e1827e8361ca47a03780b84b72d57f906b85d0d Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 14 Mar 2016 17:57:40 +0300 Subject: [PATCH 162/882] support 'password' grant_type for OAuth 2.0 --- changelog | 1 + .../scribejava/core/oauth/OAuth20Service.java | 58 ++++++------- .../core/oauth/CompletedFuture.java | 12 +-- .../scribejava/core/oauth/OAuth20ApiUnit.java | 4 +- .../core/oauth/OAuth20ServiceTest.java | 54 ++++++------ .../core/oauth/OAuth20ServiceUnit.java | 84 ++++++++----------- 6 files changed, 94 insertions(+), 119 deletions(-) diff --git a/changelog b/changelog index efe3c7eba..453d50438 100644 --- a/changelog +++ b/changelog @@ -7,6 +7,7 @@ * remove Verifier object, we just need Strings, 'code' for OAuth2 and 'oauthVerifier' for OAuth1 * default HTTP verb for OAuth 2.0 Access Token EndPoint is POST (http://tools.ietf.org/html/rfc6749#section-3.2) * send missed headers in async version (as in sync) + * support 'password' grant_type for OAuth 2.0 [2.3.0] * Stack Exchange authentication via OAuth 2.0 (stackoverflow.com, askubuntu.com, etc.). 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 946048f5a..086423cbb 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java @@ -13,7 +13,6 @@ import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.OAuthRequestAsync; -import com.github.scribejava.core.model.Response; import java.util.Map; public class OAuth20Service extends OAuthService { @@ -33,19 +32,19 @@ public OAuth20Service(DefaultApi20 api, OAuthConfig config) { } //sync version, protected to facilitate mocking - protected OAuth2AccessToken sendTokenSync(OAuthRequest request) { + protected OAuth2AccessToken sendAccessTokenRequestSync(OAuthRequest request) { return api.getAccessTokenExtractor().extract(request.send().getBody()); } //async version, protected to facilitate mocking - protected Future sendTokenAsync(OAuthRequestAsync request, + protected Future sendAccessTokenRequestAsync(OAuthRequestAsync request, OAuthAsyncRequestCallback callback, ProxyServer proxyServer) { return request.sendAsync(callback, new OAuthRequestAsync.ResponseConverter() { @Override public OAuth2AccessToken convert(com.ning.http.client.Response response) throws IOException { return getApi().getAccessTokenExtractor() - .extract(OAuthRequestAsync.RESPONSE_CONVERTER.convert(response).getBody()); + .extract(OAuthRequestAsync.RESPONSE_CONVERTER.convert(response).getBody()); } }, proxyServer); } @@ -54,7 +53,7 @@ public final OAuth2AccessToken getAccessToken(String code) { final OAuthRequest request = createAccessTokenRequest(code, new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint(), this)); - return sendTokenSync(request); + return sendAccessTokenRequestSync(request); } /** @@ -75,7 +74,7 @@ public final Future getAccessTokenAsync(String code, final OAuthRequestAsync request = createAccessTokenRequest(code, new OAuthRequestAsync(api.getAccessTokenVerb(), api.getAccessTokenEndpoint(), this)); - return sendTokenAsync(request, callback, proxyServer); + return sendAccessTokenRequestAsync(request, callback, proxyServer); } protected T createAccessTokenRequest(String code, T request) { @@ -95,9 +94,9 @@ protected T createAccessTokenRequest(String code, T public final OAuth2AccessToken refreshAccessToken(String refreshToken) { final OAuthRequest request = createRefreshTokenRequest(refreshToken, - new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint(), this)); + new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint(), this)); - return sendTokenSync(request); + return sendAccessTokenRequestSync(request); } public final Future refreshAccessTokenAsync(String refreshToken, @@ -110,7 +109,7 @@ public final Future refreshAccessTokenAsync(String refreshTok final OAuthRequestAsync request = createRefreshTokenRequest(refreshToken, new OAuthRequestAsync(api.getAccessTokenVerb(), api.getRefreshTokenEndpoint(), this)); - return sendTokenAsync(request, callback, proxyServer); + return sendAccessTokenRequestAsync(request, callback, proxyServer); } protected T createRefreshTokenRequest(String refreshToken, T request) { @@ -132,39 +131,36 @@ protected T createRefreshTokenRequest(String refresh * @param password User password * @return OAuth2AccessToken */ - public final OAuth2AccessToken getAccessTokenPasswordGrant(String uname, String password) { final OAuthRequest request = createAccessTokenPasswordGrantRequest(uname, password, - new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint(), this)); + new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint(), this)); - return sendTokenSync(request); + return sendAccessTokenRequestSync(request); } /** - * Request Access Token Password Grant async version - * - * @param uname User name - * @param password User password - * @param callback Optional callback - * @return Future - */ + * Request Access Token Password Grant async version + * + * @param uname User name + * @param password User password + * @param callback Optional callback + * @return Future + */ public final Future getAccessTokenPasswordGrantAsync(String uname, String password, OAuthAsyncRequestCallback callback) { - final OAuthRequestAsync request = createAccessTokenPasswordGrantRequest(uname, password, - new OAuthRequestAsync(api.getAccessTokenVerb(), api.getAccessTokenEndpoint(), this)); - return getAccessTokenPasswordGrantAsync(uname, password, callback, null); } public final Future getAccessTokenPasswordGrantAsync(String uname, String password, OAuthAsyncRequestCallback callback, ProxyServer proxyServer) { final OAuthRequestAsync request = createAccessTokenPasswordGrantRequest(uname, password, - new OAuthRequestAsync(api.getAccessTokenVerb(), api.getAccessTokenEndpoint(), this)); + new OAuthRequestAsync(api.getAccessTokenVerb(), api.getAccessTokenEndpoint(), this)); - return sendTokenAsync(request, callback, proxyServer); + return sendAccessTokenRequestAsync(request, callback, proxyServer); } - protected T createAccessTokenPasswordGrantRequest(String username, String password, T request) { + protected T createAccessTokenPasswordGrantRequest(String username, String password, + T request) { final OAuthConfig config = getConfig(); request.addParameter(OAuthConstants.USERNAME, username); request.addParameter(OAuthConstants.PASSWORD, password); @@ -175,12 +171,12 @@ protected T createAccessTokenPasswordGrantRequest(St request.addParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.PASSWORD); - request.addHeader(OAuthConstants.HEADER, OAuthConstants.BASIC + " " + - Base64Encoder.getInstance().encode( - String.format("%s:%s", config.getApiKey(), config.getApiSecret()).getBytes( - Charset.forName("UTF-8") - ) - ) + request.addHeader(OAuthConstants.HEADER, OAuthConstants.BASIC + " " + + Base64Encoder.getInstance().encode( + String.format("%s:%s", config.getApiKey(), config.getApiSecret()).getBytes( + Charset.forName("UTF-8") + ) + ) ); return request; diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/CompletedFuture.java b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/CompletedFuture.java index 1c4a3f068..33919d4bf 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/CompletedFuture.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/CompletedFuture.java @@ -1,16 +1,12 @@ package com.github.scribejava.core.oauth; -import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; -/** - */ class CompletedFuture implements Future { private final V result; - public CompletedFuture( V result ) { + CompletedFuture(V result) { this.result = result; } @@ -30,14 +26,12 @@ public boolean isDone() { } @Override - public V get() throws InterruptedException, ExecutionException { + public V get() { return result; } @Override - public V get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, - TimeoutException { - + public V get(long timeout, TimeUnit unit) { return result; } } diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ApiUnit.java b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ApiUnit.java index 398173d11..5d7391fb3 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ApiUnit.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ApiUnit.java @@ -3,9 +3,8 @@ import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.model.OAuthConfig; -/** - */ class OAuth20ApiUnit extends DefaultApi20 { + @Override public String getAccessTokenEndpoint() { return "http://localhost:8080/token"; @@ -16,6 +15,7 @@ public String getAuthorizationUrl(OAuthConfig config) { return "http://localhost:8080/authorize"; } + @Override public OAuth20Service createService(OAuthConfig config) { return new OAuth20ServiceUnit(this, config); } 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 1d844423d..6b2b09f0b 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 @@ -13,34 +13,29 @@ import java.util.Map; import java.util.concurrent.ExecutionException; -/** - */ public class OAuth20ServiceTest { @Test public void shouldProduceCorrectRequestSync() { final OAuth20Service service = new ServiceBuilder() - .apiKey("your_api_key") - .apiSecret("your_api_secret") - .build( new OAuth20ApiUnit() ); + .apiKey("your_api_key") + .apiSecret("your_api_secret") + .build(new OAuth20ApiUnit()); final OAuth2AccessToken token = service.getAccessTokenPasswordGrant("user1", "password1"); final Gson json = new Gson(); Assert.assertNotNull(token); - Map map = json.fromJson(token.getRawResponse(), - new TypeToken>(){}.getType()); + final Map map = json.fromJson(token.getRawResponse(), new TypeTokenImpl().getType()); - Assert.assertEquals(OAuth20ServiceUnit.token, map.get(OAuthConstants.ACCESS_TOKEN)); - Assert.assertEquals(OAuth20ServiceUnit.state, map.get(OAuthConstants.STATE)); - Assert.assertEquals(OAuth20ServiceUnit.expires, map.get("expires_in")); + Assert.assertEquals(OAuth20ServiceUnit.TOKEN, map.get(OAuthConstants.ACCESS_TOKEN)); + Assert.assertEquals(OAuth20ServiceUnit.STATE, map.get(OAuthConstants.STATE)); + Assert.assertEquals(OAuth20ServiceUnit.EXPIRES, map.get("expires_in")); - final String authorize = Base64Encoder.getInstance().encode( - String.format("%s:%s", service.getConfig().getApiKey(), service.getConfig().getApiSecret()).getBytes( - Charset.forName("UTF-8") - ) - ); + final String authorize = Base64Encoder.getInstance() + .encode(String.format("%s:%s", service.getConfig().getApiKey(), service.getConfig().getApiSecret()) + .getBytes(Charset.forName("UTF-8"))); Assert.assertEquals(OAuthConstants.BASIC + " " + authorize, map.get(OAuthConstants.HEADER)); @@ -52,27 +47,24 @@ public void shouldProduceCorrectRequestSync() { @Test public void shouldProduceCorrectRequestAsync() throws ExecutionException, InterruptedException { final OAuth20Service service = new ServiceBuilder() - .apiKey("your_api_key") - .apiSecret("your_api_secret") - .build( new OAuth20ApiUnit() ); + .apiKey("your_api_key") + .apiSecret("your_api_secret") + .build(new OAuth20ApiUnit()); final OAuth2AccessToken token = service.getAccessTokenPasswordGrantAsync("user1", "password1", null).get(); final Gson json = new Gson(); Assert.assertNotNull(token); - Map map = json.fromJson(token.getRawResponse(), - new TypeToken>(){}.getType()); + final Map map = json.fromJson(token.getRawResponse(), new TypeTokenImpl().getType()); - Assert.assertEquals(OAuth20ServiceUnit.token, map.get(OAuthConstants.ACCESS_TOKEN)); - Assert.assertEquals(OAuth20ServiceUnit.state, map.get(OAuthConstants.STATE)); - Assert.assertEquals(OAuth20ServiceUnit.expires, map.get("expires_in")); + Assert.assertEquals(OAuth20ServiceUnit.TOKEN, map.get(OAuthConstants.ACCESS_TOKEN)); + Assert.assertEquals(OAuth20ServiceUnit.STATE, map.get(OAuthConstants.STATE)); + Assert.assertEquals(OAuth20ServiceUnit.EXPIRES, map.get("expires_in")); - final String authorize = Base64Encoder.getInstance().encode( - String.format("%s:%s", service.getConfig().getApiKey(), service.getConfig().getApiSecret()).getBytes( - Charset.forName("UTF-8") - ) - ); + final String authorize = Base64Encoder.getInstance() + .encode(String.format("%s:%s", service.getConfig().getApiKey(), service.getConfig().getApiSecret()) + .getBytes(Charset.forName("UTF-8"))); Assert.assertEquals(OAuthConstants.BASIC + " " + authorize, map.get(OAuthConstants.HEADER)); @@ -81,4 +73,10 @@ public void shouldProduceCorrectRequestAsync() throws ExecutionException, Interr Assert.assertEquals("password", map.get("query-grant_type")); } + private static class TypeTokenImpl extends TypeToken> { + + private TypeTokenImpl() { + } + } + } diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceUnit.java b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceUnit.java index 7db3177d5..07fc9680c 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceUnit.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceUnit.java @@ -1,6 +1,7 @@ package com.github.scribejava.core.oauth; import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.model.AbstractRequest; import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthAsyncRequestCallback; import com.github.scribejava.core.model.OAuthConfig; @@ -15,65 +16,50 @@ import java.util.Map; import java.util.concurrent.Future; -/** - */ class OAuth20ServiceUnit extends OAuth20Service { - final static String token = "ae82980abab675c646a070686d5558ad"; - final static String state = "123"; - final static String expires = "3600"; + static final String TOKEN = "ae82980abab675c646a070686d5558ad"; + static final String STATE = "123"; + static final String EXPIRES = "3600"; - public OAuth20ServiceUnit(DefaultApi20 api, OAuthConfig config) { - super(api, config); - } - - @Override - protected OAuth2AccessToken sendTokenSync(OAuthRequest request) { - - final Gson json = new Gson(); - final Map response = new HashMap<>(); - - response.put(OAuthConstants.ACCESS_TOKEN, token); - response.put(OAuthConstants.STATE, state); - response.put("expires_in", expires); - - response.putAll( request.getHeaders() ); - response.putAll( request.getOauthParameters() ); - - for(Parameter p : request.getBodyParams().getParams()) { - response.put( "query-" + p.getKey(), p.getValue() ); + OAuth20ServiceUnit(DefaultApi20 api, OAuthConfig config) { + super(api, config); } - return new OAuth2AccessToken(token, json.toJson( response )); - } + @Override + protected OAuth2AccessToken sendAccessTokenRequestSync(OAuthRequest request) { + return new OAuth2AccessToken(TOKEN, prepareRawResponse(request)); + } - @Override - protected Future sendTokenAsync(OAuthRequestAsync request, - OAuthAsyncRequestCallback callback, ProxyServer proxyServer) { + private String prepareRawResponse(T request) { + final Gson json = new Gson(); + final Map response = new HashMap<>(); + response.put(OAuthConstants.ACCESS_TOKEN, TOKEN); + response.put(OAuthConstants.STATE, STATE); + response.put("expires_in", EXPIRES); - final Gson json = new Gson(); - final Map response = new HashMap<>(); + response.putAll(request.getHeaders()); + response.putAll(request.getOauthParameters()); - response.put(OAuthConstants.ACCESS_TOKEN, token); - response.put(OAuthConstants.STATE, state); - response.put("expires_in", expires); + for (Parameter p : request.getBodyParams().getParams()) { + response.put("query-" + p.getKey(), p.getValue()); + } - response.putAll( request.getHeaders() ); - response.putAll( request.getOauthParameters() ); + return json.toJson(response); + } - for(Parameter p : request.getBodyParams().getParams()) { - response.put( "query-" + p.getKey(), p.getValue() ); - } + @Override + protected Future sendAccessTokenRequestAsync(OAuthRequestAsync request, + OAuthAsyncRequestCallback callback, ProxyServer proxyServer) { - final OAuth2AccessToken accessToken = new OAuth2AccessToken(token, json.toJson( response )); + final OAuth2AccessToken accessToken = new OAuth2AccessToken(TOKEN, prepareRawResponse(request)); - try { - return new CompletedFuture(accessToken); - } - finally { - if( callback != null ) { - callback.onCompleted(accessToken); - } - } - } + try { + return new CompletedFuture<>(accessToken); + } finally { + if (callback != null) { + callback.onCompleted(accessToken); + } + } + } } From 802a80e13a75e588e5070e15f22edee2a1a3d5fb Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 14 Mar 2016 18:10:33 +0300 Subject: [PATCH 163/882] prepare 2.4.0 release --- README.md | 4 ++-- changelog | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 871a543f8..0ca58eb3a 100644 --- a/README.md +++ b/README.md @@ -78,7 +78,7 @@ You can pull ScribeJava from the central maven repository, just add these to you com.github.scribejava scribejava-apis - 2.3.0 + 2.4.0 ``` @@ -87,7 +87,7 @@ And in case you need just core classes (that's it, without any external API (FB, com.github.scribejava scribejava-core - 2.3.0 + 2.4.0 ``` diff --git a/changelog b/changelog index 453d50438..4902e8b71 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,4 @@ -[SNAPSHOT] +[2.4.0] * APIs 2.0 can define different endpoints for access token and for refresh token (the same urls by default) * mark Facebook doesn't support refresh token by throwing UnsupportedOperationException * make JSON Access Token Extractor be the default for OAuth 2.0 (according to RFC 6749) From afc1e356d38b1e1fc02126bf4b358ec30cbf3e7e Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 14 Mar 2016 18:11:56 +0300 Subject: [PATCH 164/882] [maven-release-plugin] prepare release scribejava-2.4.0 --- pom.xml | 2 +- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index d07fffb73..eb7122d95 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 2.3.1-SNAPSHOT + 2.4.0 ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 23e975072..35ef519b2 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 2.3.1-SNAPSHOT + 2.4.0 ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index b4730b400..8ca287fce 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 2.3.1-SNAPSHOT + 2.4.0 ../pom.xml From 139313108c181377e9aef84f2d681060762a74fd Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 14 Mar 2016 18:12:01 +0300 Subject: [PATCH 165/882] [maven-release-plugin] prepare for next development iteration --- pom.xml | 2 +- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index eb7122d95..b9a90a1c1 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 2.4.0 + 2.4.1-SNAPSHOT ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 35ef519b2..ff9faa8a3 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 2.4.0 + 2.4.1-SNAPSHOT ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 8ca287fce..860b5ef20 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 2.4.0 + 2.4.1-SNAPSHOT ../pom.xml From 22f5c38e7b08af4fb805ae64ae9ac58d6dbb0599 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andre=CC=81=20Tietz?= Date: Fri, 18 Mar 2016 17:57:54 +0100 Subject: [PATCH 166/882] service builder more generic --- .../core/builder/AbstractServiceBuilder.java | 18 +++++------------- .../scribejava/core/builder/api/BaseApi.java | 9 +++++++++ .../core/builder/api/DefaultApi10a.java | 3 ++- .../core/builder/api/DefaultApi20.java | 3 ++- 4 files changed, 18 insertions(+), 15 deletions(-) create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/builder/api/BaseApi.java diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/AbstractServiceBuilder.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/AbstractServiceBuilder.java index 7c34f0dae..cfe7f7a7a 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/AbstractServiceBuilder.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/AbstractServiceBuilder.java @@ -1,5 +1,6 @@ package com.github.scribejava.core.builder; +import com.github.scribejava.core.builder.api.BaseApi; import com.github.scribejava.core.builder.api.DefaultApi10a; import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.model.OAuthConfig; @@ -8,6 +9,7 @@ import com.github.scribejava.core.model.SignatureType; import com.github.scribejava.core.oauth.OAuth10aService; import com.github.scribejava.core.oauth.OAuth20Service; +import com.github.scribejava.core.oauth.OAuthService; import com.github.scribejava.core.utils.Preconditions; abstract class AbstractServiceBuilder> { @@ -176,22 +178,12 @@ public String getResponseType() { protected abstract OAuthConfig createConfig(); /** - * Returns the fully configured {@link OAuth10aService} + * Returns the fully configured {@link S} * * @param api will build Service for this API - * @return fully configured {@link OAuth10aService} + * @return fully configured {@link S} */ - public OAuth10aService build(DefaultApi10a api) { - return api.createService(createConfig()); - } - - /** - * Returns the fully configured {@link OAuth20Service} - * - * @param api will build Service for this API - * @return fully configured {@link OAuth20Service} - */ - public OAuth20Service build(DefaultApi20 api) { + public S build(BaseApi api) { return api.createService(createConfig()); } } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/BaseApi.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/BaseApi.java new file mode 100644 index 000000000..742a92b09 --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/BaseApi.java @@ -0,0 +1,9 @@ +package com.github.scribejava.core.builder.api; + +import com.github.scribejava.core.model.OAuthConfig; +import com.github.scribejava.core.oauth.OAuthService; + + +public interface BaseApi { + T createService(OAuthConfig config); +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi10a.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi10a.java index f0920e103..3b4b148c6 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi10a.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi10a.java @@ -30,7 +30,7 @@ * fine-tune the process. Please read the javadocs of the interfaces to get an idea of what to do. * */ -public abstract class DefaultApi10a { +public abstract class DefaultApi10a implements BaseApi { /** * Returns the access token extractor. @@ -126,6 +126,7 @@ public Verb getRequestTokenVerb() { */ public abstract String getAuthorizationUrl(OAuth1RequestToken requestToken); + @Override public OAuth10aService createService(OAuthConfig config) { return new OAuth10aService(this, config); } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java index 4e27aebb0..30095f134 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java @@ -22,7 +22,7 @@ * fine-tune the process. Please read the javadocs of the interfaces to get an idea of what to do. * */ -public abstract class DefaultApi20 { +public abstract class DefaultApi20 implements BaseApi { /** * Returns the access token extractor. @@ -88,6 +88,7 @@ public String getAuthorizationUrl(OAuthConfig config, Map additi return authUrl; } + @Override public OAuth20Service createService(OAuthConfig config) { return new OAuth20Service(this, config); } From 9c1bd235225bc158a1e9483f0c10f92ac400796c Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 21 Mar 2016 18:28:24 +0300 Subject: [PATCH 167/882] add Google Async Example --- changelog | 3 + .../apis/examples/Google20AsyncExample.java | 122 ++++++++++++++++++ .../core/model/OAuthRequestAsync.java | 25 +--- 3 files changed, 131 insertions(+), 19 deletions(-) create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncExample.java diff --git a/changelog b/changelog index 4902e8b71..f68b67042 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,6 @@ +[SNAPSHOT] + * add Google Async Exmaple (with bugfix for it to work) + [2.4.0] * APIs 2.0 can define different endpoints for access token and for refresh token (the same urls by default) * mark Facebook doesn't support refresh token by throwing UnsupportedOperationException diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncExample.java new file mode 100644 index 000000000..74e4ab708 --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncExample.java @@ -0,0 +1,122 @@ +package com.github.scribejava.apis.examples; + +import java.util.Random; +import java.util.Scanner; +import com.github.scribejava.apis.GoogleApi20; +import com.github.scribejava.core.builder.ServiceBuilderAsync; +import com.github.scribejava.core.model.ForceTypeOfHttpRequest; +import com.github.scribejava.core.model.OAuth2AccessToken; +import com.github.scribejava.core.model.OAuthRequestAsync; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.ScribeJavaConfig; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.oauth.OAuth20Service; +import com.ning.http.client.AsyncHttpClientConfig; +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.ExecutionException; + +public abstract class Google20AsyncExample { + + private static final String NETWORK_NAME = "G+ Async"; + private static final String PROTECTED_RESOURCE_URL = "https://www.googleapis.com/plus/v1/people/me"; + + public static void main(String... args) throws InterruptedException, ExecutionException { + // Replace these with your client id and secret + final String clientId = "your client id"; + final String clientSecret = "your client secret"; + final String secretState = "secret" + new Random().nextInt(999_999); + ScribeJavaConfig.setForceTypeOfHttpRequests(ForceTypeOfHttpRequest.FORCE_ASYNC_ONLY_HTTP_REQUESTS); + final AsyncHttpClientConfig clientConfig = new AsyncHttpClientConfig.Builder() + .setMaxConnections(5) + .setRequestTimeout(10_000) + .setAllowPoolingConnections(false) + .setPooledConnectionIdleTimeout(1_000) + .setReadTimeout(1_000) + .build(); + + final OAuth20Service service = new ServiceBuilderAsync() + .apiKey(clientId) + .apiSecret(clientSecret) + .scope("profile") // replace with desired scope + .state(secretState) + .callback("http://example.com/callback") + .asyncHttpClientConfig(clientConfig) + .build(GoogleApi20.instance()); + final Scanner in = new Scanner(System.in, "UTF-8"); + + System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); + System.out.println(); + + // Obtain the Authorization URL + System.out.println("Fetching the Authorization URL..."); + //pass access_type=offline to get refresh token + //https://developers.google.com/identity/protocols/OAuth2WebServer#preparing-to-start-the-oauth-20-flow + final Map additionalParams = new HashMap<>(); + additionalParams.put("access_type", "offline"); + //force to reget refresh token (if usera are asked not the first time) + additionalParams.put("prompt", "consent"); + final String authorizationUrl = service.getAuthorizationUrl(additionalParams); + System.out.println("Got the Authorization URL!"); + System.out.println("Now go and authorize ScribeJava here:"); + System.out.println(authorizationUrl); + System.out.println("And paste the authorization code here"); + System.out.print(">>"); + final String code = in.nextLine(); + System.out.println(); + + System.out.println("And paste the state from server here. We have set 'secretState'='" + secretState + "'."); + System.out.print(">>"); + final String value = in.nextLine(); + if (secretState.equals(value)) { + System.out.println("State value does match!"); + } else { + System.out.println("Ooops, state value does not match!"); + System.out.println("Expected = " + secretState); + System.out.println("Got = " + value); + System.out.println(); + } + + // Trade the Request Token and Verfier for the Access Token + System.out.println("Trading the Request Token for an Access Token..."); + OAuth2AccessToken accessToken = service.getAccessTokenAsync(code, null).get(); + System.out.println("Got the Access Token!"); + System.out.println("(if your curious it looks like this: " + accessToken + + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + + System.out.println("Refreshing the Access Token..."); + accessToken = service.refreshAccessTokenAsync(accessToken.getRefreshToken(), null).get(); + System.out.println("Refreshed the Access Token!"); + System.out.println("(if your curious it looks like this: " + accessToken + + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println(); + + // Now let's go and ask for a protected resource! + System.out.println("Now we're going to access a protected resource..."); + while (true) { + System.out.println("Paste fieldnames to fetch (leave empty to get profile, 'exit' to stop example)"); + System.out.print(">>"); + final String query = in.nextLine(); + System.out.println(); + + final String requestUrl; + if ("exit".equals(query)) { + break; + } else if (query == null || query.isEmpty()) { + requestUrl = PROTECTED_RESOURCE_URL; + } else { + requestUrl = PROTECTED_RESOURCE_URL + "?fields=" + query; + } + + final OAuthRequestAsync request = new OAuthRequestAsync(Verb.GET, requestUrl, service); + service.signRequest(accessToken, request); + final Response response = request.sendAsync(null).get(); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + + System.out.println(); + } + service.closeAsyncClient(); + } +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequestAsync.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequestAsync.java index 846320046..f01ff1776 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequestAsync.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequestAsync.java @@ -8,10 +8,8 @@ import com.ning.http.client.ProxyServer; import java.io.IOException; -import java.util.Collection; import java.util.HashMap; import java.util.List; -import java.util.ArrayList; import java.util.Map; import java.util.concurrent.Future; @@ -38,21 +36,6 @@ public OAuthRequestAsync(Verb verb, String url, OAuthService service) { super(verb, url, service); } - private Map> mapHeaders() { - final Map> mapped = new HashMap<>(); - - for (Map.Entry header : getHeaders().entrySet()) { - final String headerName = header.getKey(); - Collection headerValues = mapped.get(headerName); - if (headerValues == null) { - headerValues = new ArrayList<>(); - mapped.put(headerName, headerValues); - } - headerValues.add(header.getValue()); - } - return mapped; - } - public Future sendAsync(OAuthAsyncRequestCallback callback, ResponseConverter converter) { return sendAsync(callback, converter, null); } @@ -75,13 +58,17 @@ public Future sendAsync(OAuthAsyncRequestCallback callback, ResponseCo boundRequestBuilder = asyncHttpClient.prepareGet(completeUrl); break; case POST: - boundRequestBuilder = asyncHttpClient.preparePost(completeUrl).setBody(getBodyContents()); + boundRequestBuilder = asyncHttpClient.preparePost(completeUrl) + .addHeader(CONTENT_TYPE, DEFAULT_CONTENT_TYPE) + .setBody(getBodyContents()); break; default: throw new IllegalArgumentException("message build error: unknown verb type"); } - boundRequestBuilder.setHeaders(mapHeaders()); + for (Map.Entry header : getHeaders().entrySet()) { + boundRequestBuilder.addHeader(header.getKey(), header.getValue()); + } if (proxyServer != null) { boundRequestBuilder.setProxyServer(proxyServer); From 67972a3c24ccb4832c2d7f7838e3f954df81f70f Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 21 Mar 2016 19:09:08 +0300 Subject: [PATCH 168/882] fix coding standards --- .../scribejava/core/builder/AbstractServiceBuilder.java | 4 ---- .../java/com/github/scribejava/core/builder/api/BaseApi.java | 4 ++-- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/AbstractServiceBuilder.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/AbstractServiceBuilder.java index cfe7f7a7a..8937afc0a 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/AbstractServiceBuilder.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/AbstractServiceBuilder.java @@ -1,14 +1,10 @@ package com.github.scribejava.core.builder; import com.github.scribejava.core.builder.api.BaseApi; -import com.github.scribejava.core.builder.api.DefaultApi10a; -import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.model.OAuthConfig; import java.io.OutputStream; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.SignatureType; -import com.github.scribejava.core.oauth.OAuth10aService; -import com.github.scribejava.core.oauth.OAuth20Service; import com.github.scribejava.core.oauth.OAuthService; import com.github.scribejava.core.utils.Preconditions; diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/BaseApi.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/BaseApi.java index 742a92b09..a42fe35fa 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/BaseApi.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/BaseApi.java @@ -3,7 +3,7 @@ import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.oauth.OAuthService; - public interface BaseApi { - T createService(OAuthConfig config); + + T createService(OAuthConfig config); } From 1dc3923153be6395c146cd8a17ff8f556cdeb225 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 22 Mar 2016 11:57:28 +0300 Subject: [PATCH 169/882] add OSGI manifest metadata --- changelog | 1 + pom.xml | 34 +++++++++++++++++++++++++++++++--- scribejava-apis/pom.xml | 12 ++++++++++++ scribejava-core/pom.xml | 12 ++++++++++++ 4 files changed, 56 insertions(+), 3 deletions(-) diff --git a/changelog b/changelog index f68b67042..a29f9d59f 100644 --- a/changelog +++ b/changelog @@ -1,5 +1,6 @@ [SNAPSHOT] * add Google Async Exmaple (with bugfix for it to work) + * add OSGI manifest metadata [2.4.0] * APIs 2.0 can define different endpoints for access token and for refresh token (the same urls by default) diff --git a/pom.xml b/pom.xml index b9a90a1c1..0454b8141 100644 --- a/pom.xml +++ b/pom.xml @@ -96,11 +96,39 @@ com.ning async-http-client - 1.9.33 + 1.9.36 provided + + + + org.apache.felix + maven-bundle-plugin + 3.0.1 + + + bundle-manifest + process-classes + + manifest + + + + + + org.apache.maven.plugins + maven-jar-plugin + 2.6 + + + ${project.build.outputDirectory}/META-INF/MANIFEST.MF + + + + + org.apache.maven.wagon @@ -198,7 +226,7 @@
- + release-sign-artifacts @@ -228,4 +256,4 @@
- + diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index ff9faa8a3..65b400b77 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -22,4 +22,16 @@ + + + + org.apache.felix + maven-bundle-plugin + + + org.apache.maven.plugins + maven-jar-plugin + + + diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 860b5ef20..22d957e79 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -14,4 +14,16 @@ ScribeJava Core jar + + + + org.apache.felix + maven-bundle-plugin + + + org.apache.maven.plugins + maven-jar-plugin + + + From 62959e6c338bf607387f4380dc404e095484da4e Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 22 Mar 2016 12:57:30 +0300 Subject: [PATCH 170/882] fix javadoc issue --- .../github/scribejava/core/builder/AbstractServiceBuilder.java | 1 + 1 file changed, 1 insertion(+) diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/AbstractServiceBuilder.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/AbstractServiceBuilder.java index 8937afc0a..63ca9d816 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/AbstractServiceBuilder.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/AbstractServiceBuilder.java @@ -176,6 +176,7 @@ public String getResponseType() { /** * Returns the fully configured {@link S} * + * @param OAuthService implementation (OAuth1/OAuth2/any API specific) * @param api will build Service for this API * @return fully configured {@link S} */ From c328d5db81d97dbffa395bf9fd376f75b52dc6d5 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 22 Mar 2016 15:05:37 +0300 Subject: [PATCH 171/882] apiSecret is not mandatory parameter in config (to use on client sides and other flows without need of the API secret) --- changelog | 1 + .../github/scribejava/core/builder/AbstractServiceBuilder.java | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog b/changelog index a29f9d59f..8edc13ab6 100644 --- a/changelog +++ b/changelog @@ -1,6 +1,7 @@ [SNAPSHOT] * 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) [2.4.0] * APIs 2.0 can define different endpoints for access token and for refresh token (the same urls by default) diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/AbstractServiceBuilder.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/AbstractServiceBuilder.java index 63ca9d816..cd8fc487e 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/AbstractServiceBuilder.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/AbstractServiceBuilder.java @@ -132,7 +132,6 @@ public T debug() { public void checkPreconditions() { Preconditions.checkEmptyString(apiKey, "You must provide an api key"); - Preconditions.checkEmptyString(apiSecret, "You must provide an api secret"); } public String getCallback() { From aedc5890be77d2f50f1c2128bedb95516c397fcc Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 28 Mar 2016 13:54:07 +0300 Subject: [PATCH 172/882] implement OAuth2 Authorization Response parsing --- .../core/model/OAuth2Authorization.java | 43 ++++++++++ .../scribejava/core/oauth/OAuth20Service.java | 20 +++++ .../core/oauth/OAuth20ServiceTest.java | 85 +++++++++++++++---- 3 files changed, 131 insertions(+), 17 deletions(-) create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth2Authorization.java diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth2Authorization.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth2Authorization.java new file mode 100644 index 000000000..8c99f395b --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth2Authorization.java @@ -0,0 +1,43 @@ +package com.github.scribejava.core.model; + +/** + * represents Authorization Response http://tools.ietf.org/html/rfc6749#section-4.1.2 + * + * If the resource owner grants the access request, the authorization server issues an authorization code and delivers + * it to the client by adding the following parameters to the query component of the redirection URI using the + * "application/x-www-form-urlencoded" format. + * + */ +public class OAuth2Authorization { + + /** + * REQUIRED. The authorization code generated by the authorization server. The authorization code MUST expire + * shortly after it is issued to mitigate the risk of leaks. A maximum authorization code lifetime of 10 minutes is + * RECOMMENDED. The client MUST NOT use the authorization code more than once. If an authorization code is used more + * than once, the authorization server MUST deny the request and SHOULD revoke (when possible) all tokens previously + * issued based on that authorization code. The authorization code is bound to the client identifier and redirection + * URI. + */ + private String code; + /** + * REQUIRED if the "state" parameter was present in the client authorization request. The exact value received from + * the client. + */ + private String state; + + public String getCode() { + return code; + } + + public void setCode(String code) { + this.code = code; + } + + public String getState() { + return state; + } + + public void setState(String state) { + this.state = state; + } +} 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 086423cbb..2c7f8306b 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 @@ -8,6 +8,7 @@ import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.model.AbstractRequest; import com.github.scribejava.core.model.OAuth2AccessToken; +import com.github.scribejava.core.model.OAuth2Authorization; import com.github.scribejava.core.model.OAuthAsyncRequestCallback; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; @@ -216,4 +217,23 @@ public String getAuthorizationUrl(Map additionalParams) { public DefaultApi20 getApi() { return api; } + + public OAuth2Authorization extractAuthorization(String redirectLocation) { + final OAuth2Authorization authorization = new OAuth2Authorization(); + for (String param : redirectLocation.substring(redirectLocation.indexOf('?') + 1).split("&")) { + final String[] keyValue = param.split("="); + if (keyValue.length == 2) { + switch (keyValue[0]) { + case "code": + authorization.setCode(keyValue[1]); + break; + case "state": + authorization.setState(keyValue[1]); + break; + default: //just ignore any other param; + } + } + } + return authorization; + } } 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 6b2b09f0b..17c58087f 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,11 +2,13 @@ import com.github.scribejava.core.builder.ServiceBuilder; import com.github.scribejava.core.model.OAuth2AccessToken; +import com.github.scribejava.core.model.OAuth2Authorization; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.services.Base64Encoder; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; -import org.junit.Assert; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertEquals; import org.junit.Test; import java.nio.charset.Charset; @@ -25,23 +27,23 @@ public void shouldProduceCorrectRequestSync() { final OAuth2AccessToken token = service.getAccessTokenPasswordGrant("user1", "password1"); final Gson json = new Gson(); - Assert.assertNotNull(token); + assertNotNull(token); final Map map = json.fromJson(token.getRawResponse(), new TypeTokenImpl().getType()); - Assert.assertEquals(OAuth20ServiceUnit.TOKEN, map.get(OAuthConstants.ACCESS_TOKEN)); - Assert.assertEquals(OAuth20ServiceUnit.STATE, map.get(OAuthConstants.STATE)); - Assert.assertEquals(OAuth20ServiceUnit.EXPIRES, map.get("expires_in")); + assertEquals(OAuth20ServiceUnit.TOKEN, map.get(OAuthConstants.ACCESS_TOKEN)); + assertEquals(OAuth20ServiceUnit.STATE, map.get(OAuthConstants.STATE)); + assertEquals(OAuth20ServiceUnit.EXPIRES, map.get("expires_in")); final String authorize = Base64Encoder.getInstance() .encode(String.format("%s:%s", service.getConfig().getApiKey(), service.getConfig().getApiSecret()) .getBytes(Charset.forName("UTF-8"))); - Assert.assertEquals(OAuthConstants.BASIC + " " + authorize, map.get(OAuthConstants.HEADER)); + assertEquals(OAuthConstants.BASIC + " " + authorize, map.get(OAuthConstants.HEADER)); - Assert.assertEquals("user1", map.get("query-username")); - Assert.assertEquals("password1", map.get("query-password")); - Assert.assertEquals("password", map.get("query-grant_type")); + assertEquals("user1", map.get("query-username")); + assertEquals("password1", map.get("query-password")); + assertEquals("password", map.get("query-grant_type")); } @Test @@ -54,23 +56,72 @@ public void shouldProduceCorrectRequestAsync() throws ExecutionException, Interr final OAuth2AccessToken token = service.getAccessTokenPasswordGrantAsync("user1", "password1", null).get(); final Gson json = new Gson(); - Assert.assertNotNull(token); + assertNotNull(token); final Map map = json.fromJson(token.getRawResponse(), new TypeTokenImpl().getType()); - Assert.assertEquals(OAuth20ServiceUnit.TOKEN, map.get(OAuthConstants.ACCESS_TOKEN)); - Assert.assertEquals(OAuth20ServiceUnit.STATE, map.get(OAuthConstants.STATE)); - Assert.assertEquals(OAuth20ServiceUnit.EXPIRES, map.get("expires_in")); + assertEquals(OAuth20ServiceUnit.TOKEN, map.get(OAuthConstants.ACCESS_TOKEN)); + assertEquals(OAuth20ServiceUnit.STATE, map.get(OAuthConstants.STATE)); + assertEquals(OAuth20ServiceUnit.EXPIRES, map.get("expires_in")); final String authorize = Base64Encoder.getInstance() .encode(String.format("%s:%s", service.getConfig().getApiKey(), service.getConfig().getApiSecret()) .getBytes(Charset.forName("UTF-8"))); - Assert.assertEquals(OAuthConstants.BASIC + " " + authorize, map.get(OAuthConstants.HEADER)); + assertEquals(OAuthConstants.BASIC + " " + authorize, map.get(OAuthConstants.HEADER)); + + assertEquals("user1", map.get("query-username")); + assertEquals("password1", map.get("query-password")); + assertEquals("password", map.get("query-grant_type")); + } + + @Test + public void testOAuthExtractAuthorization() { + final OAuth20Service service = new ServiceBuilder() + .apiKey("your_api_key") + .apiSecret("your_api_secret") + .build(new OAuth20ApiUnit()); + + OAuth2Authorization authorization = service.extractAuthorization("https://cl.ex.com/cb?code=SplxlOB&state=xyz"); + assertEquals("SplxlOB", authorization.getCode()); + assertEquals("xyz", authorization.getState()); + + authorization = service.extractAuthorization("https://cl.ex.com/cb?state=xyz&code=SplxlOB"); + assertEquals("SplxlOB", authorization.getCode()); + assertEquals("xyz", authorization.getState()); + + authorization = service.extractAuthorization("https://cl.ex.com/cb?key=value&state=xyz&code=SplxlOB"); + assertEquals("SplxlOB", authorization.getCode()); + assertEquals("xyz", authorization.getState()); + + authorization = service.extractAuthorization("https://cl.ex.com/cb?state=xyz&code=SplxlOB&key=value&"); + assertEquals("SplxlOB", authorization.getCode()); + assertEquals("xyz", authorization.getState()); + + authorization = service.extractAuthorization("https://cl.ex.com/cb?code=SplxlOB&state="); + assertEquals("SplxlOB", authorization.getCode()); + assertEquals(null, authorization.getState()); + + authorization = service.extractAuthorization("https://cl.ex.com/cb?code=SplxlOB"); + assertEquals("SplxlOB", authorization.getCode()); + assertEquals(null, authorization.getState()); + + authorization = service.extractAuthorization("https://cl.ex.com/cb?code="); + assertEquals(null, authorization.getCode()); + assertEquals(null, authorization.getState()); + + authorization = service.extractAuthorization("https://cl.ex.com/cb?code"); + assertEquals(null, authorization.getCode()); + assertEquals(null, authorization.getState()); + + authorization = service.extractAuthorization("https://cl.ex.com/cb?"); + assertEquals(null, authorization.getCode()); + assertEquals(null, authorization.getState()); + + authorization = service.extractAuthorization("https://cl.ex.com/cb"); + assertEquals(null, authorization.getCode()); + assertEquals(null, authorization.getState()); - Assert.assertEquals("user1", map.get("query-username")); - Assert.assertEquals("password1", map.get("query-password")); - Assert.assertEquals("password", map.get("query-grant_type")); } private static class TypeTokenImpl extends TypeToken> { From 9dfb671520966df479264f2466c7654eca9580b7 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 28 Mar 2016 15:05:53 +0300 Subject: [PATCH 173/882] update changelog --- changelog | 1 + 1 file changed, 1 insertion(+) diff --git a/changelog b/changelog index 8edc13ab6..b8bf40849 100644 --- a/changelog +++ b/changelog @@ -2,6 +2,7 @@ * 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) [2.4.0] * APIs 2.0 can define different endpoints for access token and for refresh token (the same urls by default) From fbe4ffe953ab8784164b089c9c09ee26d565bbb9 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 28 Mar 2016 15:18:09 +0300 Subject: [PATCH 174/882] update ok.ru API urls --- changelog | 1 + .../scribejava/apis/OdnoklassnikiApi.java | 20 ++++++++++++------- .../apis/examples/OdnoklassnikiExample.java | 11 ++++++++-- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/changelog b/changelog index b8bf40849..512a4b3fe 100644 --- a/changelog +++ b/changelog @@ -3,6 +3,7 @@ * 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) + * update ok.ru API urls, add 'state' support, add refresh token to the example [2.4.0] * APIs 2.0 can define different endpoints for access token and for refresh token (the same urls by default) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java index de8fdfa8a..0651fe108 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java @@ -10,8 +10,7 @@ public class OdnoklassnikiApi extends DefaultApi20 { private static final String AUTHORIZE_URL - = "http://www.odnoklassniki.ru/oauth/authorize?client_id=%s&response_type=code&redirect_uri=%s"; - private static final String SCOPED_AUTHORIZE_URL = String.format("%s&scope=%%s", AUTHORIZE_URL); + = "https://connect.ok.ru/oauth/authorize?client_id=%s&response_type=code&redirect_uri=%s"; protected OdnoklassnikiApi() { } @@ -26,19 +25,26 @@ public static OdnoklassnikiApi instance() { @Override public String getAccessTokenEndpoint() { - return "http://api.odnoklassniki.ru/oauth/token.do"; + return "https://api.ok.ru/oauth/token.do"; } @Override public String getAuthorizationUrl(OAuthConfig config) { Preconditions.checkValidUrl(config.getCallback(), "Valid url is required for a callback. Odnoklassniki does not support OOB"); + + final StringBuilder urlBuilder = new StringBuilder(String.format(AUTHORIZE_URL, + config.getApiKey(), OAuthEncoder.encode(config.getCallback()))); + if (config.hasScope()) { - return String.format(SCOPED_AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()), - OAuthEncoder.encode(config.getScope())); - } else { - return String.format(AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback())); + urlBuilder.append("&scope=").append(OAuthEncoder.encode(config.getScope())); + } + + final String state = config.getState(); + if (state != null) { + urlBuilder.append("&state=").append(OAuthEncoder.encode(config.getState())); } + return urlBuilder.toString(); } @Override diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java index 88fb1ba93..ba88fe131 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java @@ -14,7 +14,7 @@ public abstract class OdnoklassnikiExample { private static final String NETWORK_NAME = "Odnoklassniki.ru"; private static final String PROTECTED_RESOURCE_URL - = "http://api.odnoklassniki.ru/api/users/getCurrentUser?application_key=%1$s&format=JSON"; + = "https://api.ok.ru/api/users/getCurrentUser?application_key=%1$s&format=JSON"; public static void main(String... args) { // Replace these with your client id and secret @@ -49,12 +49,19 @@ public static void main(String... args) { // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - final OAuth2AccessToken accessToken = service.getAccessToken(code); + OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); System.out.println(); + System.out.println("Refreshing the Access Token..."); + accessToken = service.refreshAccessToken(accessToken.getRefreshToken()); + System.out.println("Refreshed the Access Token!"); + System.out.println("(if your curious it looks like this: " + accessToken + + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println(); + // Now let's go and ask for a protected resource! System.out.println("Now we're going to access a protected resource..."); final OAuthRequest request = new OAuthRequest(Verb.GET, String.format(PROTECTED_RESOURCE_URL, publicKey), From 6b978a6a684904ab5be824435424ecaf19a53345 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 28 Mar 2016 15:44:00 +0300 Subject: [PATCH 175/882] [maven-release-plugin] prepare release scribejava-2.5.0 --- pom.xml | 2 +- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 0454b8141..9467288a1 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 2.4.1-SNAPSHOT + 2.5.0 ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 65b400b77..9f364ceb7 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 2.4.1-SNAPSHOT + 2.5.0 ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 22d957e79..b1e96945d 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 2.4.1-SNAPSHOT + 2.5.0 ../pom.xml From 7c1f00a44f75bd07d5af79896e0dac05b7f19c59 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 28 Mar 2016 15:44:07 +0300 Subject: [PATCH 176/882] [maven-release-plugin] prepare for next development iteration --- pom.xml | 2 +- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 9467288a1..30308eadf 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 2.5.0 + 2.5.1-SNAPSHOT ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 9f364ceb7..e50a60e51 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 2.5.0 + 2.5.1-SNAPSHOT ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index b1e96945d..62353ec0e 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 2.5.0 + 2.5.1-SNAPSHOT ../pom.xml From 826be08321647c3feced154871db38dd00d0c055 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 28 Mar 2016 15:48:47 +0300 Subject: [PATCH 177/882] Revert "[maven-release-plugin] prepare for next development iteration" This reverts commit 7c1f00a44f75bd07d5af79896e0dac05b7f19c59. --- pom.xml | 2 +- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 30308eadf..9467288a1 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 2.5.1-SNAPSHOT + 2.5.0 ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index e50a60e51..9f364ceb7 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 2.5.1-SNAPSHOT + 2.5.0 ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 62353ec0e..b1e96945d 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 2.5.1-SNAPSHOT + 2.5.0 ../pom.xml From 852bc7efed6907cb04de559b863fd5ac7b5d240e Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 28 Mar 2016 15:48:54 +0300 Subject: [PATCH 178/882] Revert "[maven-release-plugin] prepare release scribejava-2.5.0" This reverts commit 6b978a6a684904ab5be824435424ecaf19a53345. --- pom.xml | 2 +- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 9467288a1..0454b8141 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 2.5.0 + 2.4.1-SNAPSHOT ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 9f364ceb7..65b400b77 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 2.5.0 + 2.4.1-SNAPSHOT ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index b1e96945d..22d957e79 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 2.5.0 + 2.4.1-SNAPSHOT ../pom.xml From b73c42d4a335b99e280e7310172de0c0a00a4ef5 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 28 Mar 2016 15:45:54 +0300 Subject: [PATCH 179/882] prepare 2.5.2 release --- README.md | 4 ++-- changelog | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 0ca58eb3a..82cca0d59 100644 --- a/README.md +++ b/README.md @@ -78,7 +78,7 @@ You can pull ScribeJava from the central maven repository, just add these to you com.github.scribejava scribejava-apis - 2.4.0 + 2.5.2 ``` @@ -87,7 +87,7 @@ And in case you need just core classes (that's it, without any external API (FB, com.github.scribejava scribejava-core - 2.4.0 + 2.5.2 ``` diff --git a/changelog b/changelog index 512a4b3fe..15e23875b 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,4 @@ -[SNAPSHOT] +[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) From af97361e4f9c26c9c3fba29e7328c25e9ef1e651 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 28 Mar 2016 15:50:58 +0300 Subject: [PATCH 180/882] [maven-release-plugin] prepare release scribejava-2.5.2 --- pom.xml | 2 +- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 0454b8141..780711e7c 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 2.4.1-SNAPSHOT + 2.5.2 ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 65b400b77..07c92418f 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 2.4.1-SNAPSHOT + 2.5.2 ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 22d957e79..878655572 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 2.4.1-SNAPSHOT + 2.5.2 ../pom.xml From 312579950b88f8c1f9f1af74e54810952915ca87 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 28 Mar 2016 15:51:05 +0300 Subject: [PATCH 181/882] [maven-release-plugin] prepare for next development iteration --- pom.xml | 2 +- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 780711e7c..94d0f1345 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 2.5.2 + 2.5.3-SNAPSHOT ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 07c92418f..9bdd90b82 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 2.5.2 + 2.5.3-SNAPSHOT ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 878655572..bf13322cc 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 2.5.2 + 2.5.3-SNAPSHOT ../pom.xml From f8d32379e13e8e1c64e1280db5aa95fe473bad0c Mon Sep 17 00:00:00 2001 From: Ozhiganov Valery Date: Thu, 31 Mar 2016 11:10:58 +0300 Subject: [PATCH 182/882] Odnoklassniki Example improvements --- .../scribejava/apis/examples/OdnoklassnikiExample.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java index ba88fe131..8f67a49ae 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java @@ -18,14 +18,14 @@ public abstract class OdnoklassnikiExample { public static void main(String... args) { // Replace these with your client id and secret - final String clientId = "your client id"; - final String publicKey = "your api secret"; - final String clientSecret = "your client secret"; + final String clientId = "your api client id"; + final String publicKey = "your api public key"; + final String secretKey = "your api secret key"; final OAuth20Service service = new ServiceBuilder() .apiKey(clientId) - .apiSecret(clientSecret) - .scope("VALUABLE ACCESS") + .apiSecret(secretKey) + .scope("VALUABLE_ACCESS") .grantType(OAuthConstants.AUTHORIZATION_CODE) .callback("http://your.site.com/callback") .build(OdnoklassnikiApi.instance()); From 3a5f5034f1e6d0170ebb34f61d792b20a5b9b1b3 Mon Sep 17 00:00:00 2001 From: Ozhiganov Valery Date: Thu, 31 Mar 2016 11:40:22 +0300 Subject: [PATCH 183/882] fix --- .../github/scribejava/apis/examples/OdnoklassnikiExample.java | 1 - 1 file changed, 1 deletion(-) diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java index 8f67a49ae..6cdc33e7c 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java @@ -25,7 +25,6 @@ public static void main(String... args) { final OAuth20Service service = new ServiceBuilder() .apiKey(clientId) .apiSecret(secretKey) - .scope("VALUABLE_ACCESS") .grantType(OAuthConstants.AUTHORIZATION_CODE) .callback("http://your.site.com/callback") .build(OdnoklassnikiApi.instance()); From f2b1185edda92310a79b4edb5c3006f42329c875 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 13 Apr 2016 16:27:52 +0300 Subject: [PATCH 184/882] do not set Content-Type twice --- .../scribejava/core/model/OAuthRequestAsync.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequestAsync.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequestAsync.java index f01ff1776..1081f0b68 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequestAsync.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequestAsync.java @@ -53,20 +53,23 @@ public Future sendAsync(OAuthAsyncRequestCallback callback, ResponseCo final String completeUrl = getCompleteUrl(); final AsyncHttpClient.BoundRequestBuilder boundRequestBuilder; final AsyncHttpClient asyncHttpClient = service.getAsyncHttpClient(); + final Map headers = getHeaders(); switch (getVerb()) { case GET: boundRequestBuilder = asyncHttpClient.prepareGet(completeUrl); break; case POST: - boundRequestBuilder = asyncHttpClient.preparePost(completeUrl) - .addHeader(CONTENT_TYPE, DEFAULT_CONTENT_TYPE) - .setBody(getBodyContents()); + AsyncHttpClient.BoundRequestBuilder requestBuilder = asyncHttpClient.preparePost(completeUrl); + if (!headers.containsKey(CONTENT_TYPE)) { + requestBuilder = requestBuilder.addHeader(CONTENT_TYPE, DEFAULT_CONTENT_TYPE); + } + boundRequestBuilder = requestBuilder.setBody(getBodyContents()); break; default: throw new IllegalArgumentException("message build error: unknown verb type"); } - for (Map.Entry header : getHeaders().entrySet()) { + for (Map.Entry header : headers.entrySet()) { boundRequestBuilder.addHeader(header.getKey(), header.getValue()); } From 8753b67d0b45e466f25f6736f0126283b25f8e67 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 15 Apr 2016 10:59:32 +0300 Subject: [PATCH 185/882] prepare 2.5.3 release --- README.md | 4 ++-- changelog | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 82cca0d59..8f2bb934a 100644 --- a/README.md +++ b/README.md @@ -78,7 +78,7 @@ You can pull ScribeJava from the central maven repository, just add these to you com.github.scribejava scribejava-apis - 2.5.2 + 2.5.3 ``` @@ -87,7 +87,7 @@ And in case you need just core classes (that's it, without any external API (FB, com.github.scribejava scribejava-core - 2.5.2 + 2.5.3 ``` diff --git a/changelog b/changelog index 15e23875b..eb854075a 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,7 @@ +[2.5.3] + * fix - do not send two Content-Type header in async requests + * improve OK example + [2.5.2] * add Google Async Exmaple (with bugfix for it to work) * add OSGI manifest metadata From d5f0dcef7c88c759c596e4d4d5e3e643682cb148 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 15 Apr 2016 11:03:11 +0300 Subject: [PATCH 186/882] [maven-release-plugin] prepare release scribejava-2.5.3 --- pom.xml | 2 +- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 94d0f1345..f044a7c08 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 2.5.3-SNAPSHOT + 2.5.3 ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 9bdd90b82..e547680be 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 2.5.3-SNAPSHOT + 2.5.3 ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index bf13322cc..735bb1f0f 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 2.5.3-SNAPSHOT + 2.5.3 ../pom.xml From a74e9a78e402a8ca91148aee7f741efbb95cf277 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 15 Apr 2016 11:03:16 +0300 Subject: [PATCH 187/882] [maven-release-plugin] prepare for next development iteration --- pom.xml | 2 +- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index f044a7c08..be78f0cc2 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 2.5.3 + 2.5.4-SNAPSHOT ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index e547680be..958bf5563 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 2.5.3 + 2.5.4-SNAPSHOT ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 735bb1f0f..50f5e9fc0 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 2.5.3 + 2.5.4-SNAPSHOT ../pom.xml From fe5f0f39c7427e6e07a032338ab7543f381d587a Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 15 Apr 2016 16:27:56 +0300 Subject: [PATCH 188/882] update ning and checkstyle --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index be78f0cc2..a87a5c4bf 100644 --- a/pom.xml +++ b/pom.xml @@ -96,7 +96,7 @@ com.ning async-http-client - 1.9.36 + 1.9.38 provided @@ -205,7 +205,7 @@ com.puppycrawl.tools checkstyle - 6.16.1 + 6.17 From 2751f5293b75a5f62e2265802508fb721e8d72d7 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 16 May 2016 17:53:45 +0300 Subject: [PATCH 189/882] simplify async/sync usages --- changelog | 3 + .../apis/examples/FacebookAsyncExample.java | 4 +- .../apis/examples/Google20AsyncExample.java | 4 +- .../apis/examples/MailruAsyncExample.java | 4 +- .../core/builder/AbstractServiceBuilder.java | 185 ------------------ .../core/builder/ServiceBuilder.java | 158 ++++++++++++++- .../core/builder/ServiceBuilderAsync.java | 38 ---- .../scribejava/core/model/OAuthConfig.java | 54 +++-- .../core/model/OAuthConfigAsync.java | 33 ---- .../scribejava/core/oauth/OAuthService.java | 30 +-- 10 files changed, 210 insertions(+), 303 deletions(-) delete mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/builder/AbstractServiceBuilder.java delete mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilderAsync.java delete mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConfigAsync.java diff --git a/changelog b/changelog index eb854075a..dad577932 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,6 @@ +[SNAPSHOT] + * simplify async/sync usages + [2.5.3] * fix - do not send two Content-Type header in async requests * improve OK example diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncExample.java index e95fe7ab2..3768394a7 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncExample.java @@ -5,7 +5,7 @@ import java.util.Scanner; import java.util.concurrent.ExecutionException; import com.github.scribejava.apis.FacebookApi; -import com.github.scribejava.core.builder.ServiceBuilderAsync; +import com.github.scribejava.core.builder.ServiceBuilder; import com.github.scribejava.core.model.ForceTypeOfHttpRequest; import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthRequestAsync; @@ -33,7 +33,7 @@ public static void main(String... args) throws InterruptedException, ExecutionEx .setReadTimeout(1_000) .build(); - final OAuth20Service service = new ServiceBuilderAsync() + final OAuth20Service service = new ServiceBuilder() .apiKey(clientId) .apiSecret(clientSecret) .state(secretState) diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncExample.java index 74e4ab708..f8b021041 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncExample.java @@ -3,7 +3,7 @@ import java.util.Random; import java.util.Scanner; import com.github.scribejava.apis.GoogleApi20; -import com.github.scribejava.core.builder.ServiceBuilderAsync; +import com.github.scribejava.core.builder.ServiceBuilder; import com.github.scribejava.core.model.ForceTypeOfHttpRequest; import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthRequestAsync; @@ -35,7 +35,7 @@ public static void main(String... args) throws InterruptedException, ExecutionEx .setReadTimeout(1_000) .build(); - final OAuth20Service service = new ServiceBuilderAsync() + final OAuth20Service service = new ServiceBuilder() .apiKey(clientId) .apiSecret(clientSecret) .scope("profile") // replace with desired scope diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java index 10a787625..26a61a456 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java @@ -4,7 +4,7 @@ import java.util.Scanner; import java.util.concurrent.ExecutionException; import com.github.scribejava.apis.MailruApi; -import com.github.scribejava.core.builder.ServiceBuilderAsync; +import com.github.scribejava.core.builder.ServiceBuilder; import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthRequestAsync; import com.github.scribejava.core.model.Response; @@ -30,7 +30,7 @@ public static void main(String... args) throws InterruptedException, ExecutionEx .setReadTimeout(10_000) .build(); - final OAuth20Service service = new ServiceBuilderAsync() + final OAuth20Service service = new ServiceBuilder() .apiKey(clientId) .apiSecret(clientSecret) .callback("http://www.example.com/oauth_callback/") diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/AbstractServiceBuilder.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/AbstractServiceBuilder.java deleted file mode 100644 index cd8fc487e..000000000 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/AbstractServiceBuilder.java +++ /dev/null @@ -1,185 +0,0 @@ -package com.github.scribejava.core.builder; - -import com.github.scribejava.core.builder.api.BaseApi; -import com.github.scribejava.core.model.OAuthConfig; -import java.io.OutputStream; -import com.github.scribejava.core.model.OAuthConstants; -import com.github.scribejava.core.model.SignatureType; -import com.github.scribejava.core.oauth.OAuthService; -import com.github.scribejava.core.utils.Preconditions; - -abstract class AbstractServiceBuilder> { - - private String callback; - private String apiKey; - private String apiSecret; - private String scope; - private String state; - private SignatureType signatureType; - private OutputStream debugStream; - private String grantType; - private String responseType = "code"; - - AbstractServiceBuilder() { - this.callback = OAuthConstants.OUT_OF_BAND; - this.signatureType = SignatureType.Header; - } - - /** - * Adds an OAuth callback url - * - * @param callback callback url. Must be a valid url or 'oob' for out of band OAuth - * @return the {@link ServiceBuilder} instance for method chaining - */ - @SuppressWarnings("unchecked") - public T callback(String callback) { - Preconditions.checkNotNull(callback, "Callback can't be null"); - this.callback = callback; - return (T) this; - } - - /** - * Configures the api key - * - * @param apiKey The api key for your application - * @return the {@link ServiceBuilder} instance for method chaining - */ - @SuppressWarnings("unchecked") - public T apiKey(String apiKey) { - Preconditions.checkEmptyString(apiKey, "Invalid Api key"); - this.apiKey = apiKey; - return (T) this; - } - - /** - * Configures the api secret - * - * @param apiSecret The api secret for your application - * @return the {@link ServiceBuilder} instance for method chaining - */ - @SuppressWarnings("unchecked") - public T apiSecret(String apiSecret) { - Preconditions.checkEmptyString(apiSecret, "Invalid Api secret"); - this.apiSecret = apiSecret; - return (T) this; - } - - /** - * Configures the OAuth scope. This is only necessary in some APIs (like Google's). - * - * @param scope The OAuth scope - * @return the {@link ServiceBuilder} instance for method chaining - */ - @SuppressWarnings("unchecked") - public T scope(String scope) { - Preconditions.checkEmptyString(scope, "Invalid OAuth scope"); - this.scope = scope; - return (T) this; - } - - /** - * Configures the anti forgery session state. This is available in some APIs (like Google's). - * - * @param state The OAuth state - * @return the {@link ServiceBuilder} instance for method chaining - */ - @SuppressWarnings("unchecked") - public T state(String state) { - Preconditions.checkEmptyString(state, "Invalid OAuth state"); - this.state = state; - return (T) this; - } - - /** - * Configures the signature type, choose between header, querystring, etc. Defaults to Header - * - * @param type SignatureType - * @return the {@link ServiceBuilder} instance for method chaining - */ - @SuppressWarnings("unchecked") - public T signatureType(SignatureType type) { - Preconditions.checkNotNull(type, "Signature type can't be null"); - this.signatureType = type; - return (T) this; - } - - @SuppressWarnings("unchecked") - public T debugStream(OutputStream stream) { - Preconditions.checkNotNull(stream, "debug stream can't be null"); - this.debugStream = stream; - return (T) this; - } - - @SuppressWarnings("unchecked") - public T grantType(String grantType) { - Preconditions.checkEmptyString(grantType, "Invalid OAuth grantType"); - this.grantType = grantType; - return (T) this; - } - - @SuppressWarnings("unchecked") - public T responseType(String responseType) { - Preconditions.checkEmptyString(responseType, "Invalid OAuth responseType"); - this.responseType = responseType; - return (T) this; - } - - @SuppressWarnings("unchecked") - public T debug() { - debugStream(System.out); - return (T) this; - } - - public void checkPreconditions() { - Preconditions.checkEmptyString(apiKey, "You must provide an api key"); - } - - public String getCallback() { - return callback; - } - - public String getApiKey() { - return apiKey; - } - - public String getApiSecret() { - return apiSecret; - } - - public String getScope() { - return scope; - } - - public String getState() { - return state; - } - - public SignatureType getSignatureType() { - return signatureType; - } - - public OutputStream getDebugStream() { - return debugStream; - } - - public String getGrantType() { - return grantType; - } - - public String getResponseType() { - return responseType; - } - - protected abstract OAuthConfig createConfig(); - - /** - * Returns the fully configured {@link S} - * - * @param OAuthService implementation (OAuth1/OAuth2/any API specific) - * @param api will build Service for this API - * @return fully configured {@link S} - */ - public S build(BaseApi api) { - return api.createService(createConfig()); - } -} 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 7d24dbec9..93ee34526 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilder.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilder.java @@ -1,17 +1,132 @@ package com.github.scribejava.core.builder; +import com.github.scribejava.core.builder.api.BaseApi; import com.github.scribejava.core.model.OAuthConfig; +import java.io.OutputStream; +import com.github.scribejava.core.model.OAuthConstants; +import com.github.scribejava.core.model.SignatureType; import com.github.scribejava.core.oauth.OAuthService; import com.github.scribejava.core.utils.Preconditions; +import com.ning.http.client.AsyncHttpClientConfig; /** * Implementation of the Builder pattern, with a fluent interface that creates a {@link OAuthService} */ -public class ServiceBuilder extends AbstractServiceBuilder { +public class ServiceBuilder { + private String callback; + private String apiKey; + private String apiSecret; + private String scope; + private String state; + private SignatureType signatureType; + private OutputStream debugStream; + private String grantType; + private String responseType = "code"; + + //sync version only private Integer connectTimeout; private Integer readTimeout; + //async version only + private AsyncHttpClientConfig asyncHttpClientConfig; + private String asyncHttpProviderClassName; + + public ServiceBuilder() { + callback = OAuthConstants.OUT_OF_BAND; + signatureType = SignatureType.Header; + } + + /** + * Adds an OAuth callback url + * + * @param callback callback url. Must be a valid url or 'oob' for out of band OAuth + * @return the {@link ServiceBuilder} instance for method chaining + */ + public ServiceBuilder callback(String callback) { + Preconditions.checkNotNull(callback, "Callback can't be null"); + this.callback = callback; + return this; + } + + /** + * Configures the api key + * + * @param apiKey The api key for your application + * @return the {@link ServiceBuilder} instance for method chaining + */ + public ServiceBuilder apiKey(String apiKey) { + Preconditions.checkEmptyString(apiKey, "Invalid Api key"); + this.apiKey = apiKey; + return this; + } + + /** + * Configures the api secret + * + * @param apiSecret The api secret for your application + * @return the {@link ServiceBuilder} instance for method chaining + */ + public ServiceBuilder apiSecret(String apiSecret) { + Preconditions.checkEmptyString(apiSecret, "Invalid Api secret"); + this.apiSecret = apiSecret; + return this; + } + + /** + * Configures the OAuth scope. This is only necessary in some APIs (like Google's). + * + * @param scope The OAuth scope + * @return the {@link ServiceBuilder} instance for method chaining + */ + public ServiceBuilder scope(String scope) { + Preconditions.checkEmptyString(scope, "Invalid OAuth scope"); + this.scope = scope; + return this; + } + + /** + * Configures the anti forgery session state. This is available in some APIs (like Google's). + * + * @param state The OAuth state + * @return the {@link ServiceBuilder} instance for method chaining + */ + public ServiceBuilder state(String state) { + Preconditions.checkEmptyString(state, "Invalid OAuth state"); + this.state = state; + return this; + } + + /** + * Configures the signature type, choose between header, querystring, etc. Defaults to Header + * + * @param signatureType SignatureType + * @return the {@link ServiceBuilder} instance for method chaining + */ + public ServiceBuilder signatureType(SignatureType signatureType) { + Preconditions.checkNotNull(signatureType, "Signature type can't be null"); + this.signatureType = signatureType; + return this; + } + + public ServiceBuilder debugStream(OutputStream debugStream) { + Preconditions.checkNotNull(debugStream, "debug stream can't be null"); + this.debugStream = debugStream; + return this; + } + + public ServiceBuilder grantType(String grantType) { + Preconditions.checkEmptyString(grantType, "Invalid OAuth grantType"); + this.grantType = grantType; + return this; + } + + public ServiceBuilder responseType(String responseType) { + Preconditions.checkEmptyString(responseType, "Invalid OAuth responseType"); + this.responseType = responseType; + return this; + } + public ServiceBuilder connectTimeout(Integer connectTimeout) { Preconditions.checkNotNull(connectTimeout, "Connection timeout can't be null"); this.connectTimeout = connectTimeout; @@ -24,12 +139,39 @@ public ServiceBuilder readTimeout(Integer readTimeout) { return this; } - @Override - protected OAuthConfig createConfig() { - super.checkPreconditions(); - final OAuthConfig config = new OAuthConfig(getApiKey(), getApiSecret(), getCallback(), getSignatureType(), - getScope(), getDebugStream(), connectTimeout, readTimeout, getGrantType(), getState(), - getResponseType()); - return config; + public ServiceBuilder asyncHttpClientConfig(AsyncHttpClientConfig asyncHttpClientConfig) { + Preconditions.checkNotNull(asyncHttpClientConfig, "asyncHttpClientConfig can't be null"); + this.asyncHttpClientConfig = asyncHttpClientConfig; + return this; + } + + public ServiceBuilder asyncHttpProviderClassName(String asyncHttpProviderClassName) { + this.asyncHttpProviderClassName = asyncHttpProviderClassName; + return this; + } + + public ServiceBuilder debug() { + debugStream(System.out); + return this; + } + + public void checkPreconditions() { + Preconditions.checkEmptyString(apiKey, "You must provide an api key"); + } + private OAuthConfig createConfig() { + checkPreconditions(); + return new OAuthConfig(apiKey, apiSecret, callback, signatureType, scope, debugStream, grantType, state, + responseType, connectTimeout, readTimeout, asyncHttpClientConfig, asyncHttpProviderClassName); + } + + /** + * Returns the fully configured {@link S} + * + * @param OAuthService implementation (OAuth1/OAuth2/any API specific) + * @param api will build Service for this API + * @return fully configured {@link S} + */ + public S build(BaseApi api) { + return api.createService(createConfig()); } } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilderAsync.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilderAsync.java deleted file mode 100644 index 192405b6a..000000000 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilderAsync.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.github.scribejava.core.builder; - -import com.ning.http.client.AsyncHttpClientConfig; -import com.github.scribejava.core.model.OAuthConfigAsync; -import com.github.scribejava.core.utils.Preconditions; - -public class ServiceBuilderAsync extends AbstractServiceBuilder { - - private AsyncHttpClientConfig asyncHttpClientConfig; - private String asyncHttpProviderClassName; - - public ServiceBuilderAsync asyncHttpClientConfig(AsyncHttpClientConfig asyncHttpClientConfig) { - Preconditions.checkNotNull(asyncHttpClientConfig, "asyncHttpClientConfig can't be null"); - this.asyncHttpClientConfig = asyncHttpClientConfig; - return this; - } - - @Override - public void checkPreconditions() { - super.checkPreconditions(); - Preconditions.checkNotNull(asyncHttpClientConfig, "You must provide an asyncHttpClientConfig"); - } - - @Override - protected OAuthConfigAsync createConfig() { - checkPreconditions(); - final OAuthConfigAsync configAsync = new OAuthConfigAsync(getApiKey(), getApiSecret(), getCallback(), - getSignatureType(), getScope(), getGrantType(), getState(), getResponseType(), getDebugStream(), - asyncHttpClientConfig); - configAsync.setAsyncHttpProviderClassName(asyncHttpProviderClassName); - return configAsync; - } - - public ServiceBuilderAsync asyncHttpProviderClassName(String asyncHttpProviderClassName) { - this.asyncHttpProviderClassName = asyncHttpProviderClassName; - return this; - } -} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConfig.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConfig.java index 93231ddb8..a363cf915 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConfig.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConfig.java @@ -1,5 +1,6 @@ package com.github.scribejava.core.model; +import com.ning.http.client.AsyncHttpClientConfig; import java.io.IOException; import java.io.OutputStream; @@ -15,29 +16,37 @@ public class OAuthConfig { private final String scope; private final String grantType; private final OutputStream debugStream; - private final Integer connectTimeout; - private final Integer readTimeout; private final String state; private final String responseType; + //sync only version + private final Integer connectTimeout; + private final Integer readTimeout; + + //async only version + private final AsyncHttpClientConfig asyncHttpClientConfig; + private final String asyncHttpProviderClassName; + public OAuthConfig(String key, String secret) { - this(key, secret, null, null, null, null, null, null, null, null, null); + this(key, secret, null, null, null, null, null, null, null, null, null, null, null); } - public OAuthConfig(String key, String secret, String callback, SignatureType type, String scope, - OutputStream stream, Integer connectTimeout, Integer readTimeout, String grantType, String state, - String responseType) { - this.apiKey = key; - this.apiSecret = secret; + public OAuthConfig(String apiKey, String apiSecret, String callback, SignatureType signatureType, String scope, + OutputStream debugStream, String grantType, String state, String responseType, Integer connectTimeout, + Integer readTimeout, AsyncHttpClientConfig asyncHttpClientConfig, String asyncHttpProviderClassName) { + this.apiKey = apiKey; + this.apiSecret = apiSecret; this.callback = callback; - this.signatureType = type; + this.signatureType = signatureType; this.scope = scope; - this.debugStream = stream; + this.debugStream = debugStream; this.connectTimeout = connectTimeout; this.readTimeout = readTimeout; this.grantType = grantType; this.state = state; this.responseType = responseType; + this.asyncHttpClientConfig = asyncHttpClientConfig; + this.asyncHttpProviderClassName = asyncHttpProviderClassName; } public String getApiKey() { @@ -72,12 +81,12 @@ public boolean hasGrantType() { return grantType != null; } - public Integer getConnectTimeout() { - return connectTimeout; + public String getState() { + return state; } - public Integer getReadTimeout() { - return readTimeout; + public String getResponseType() { + return responseType; } public void log(String message) { @@ -91,11 +100,20 @@ public void log(String message) { } } - public String getState() { - return state; + public Integer getConnectTimeout() { + return connectTimeout; } - public String getResponseType() { - return responseType; + public Integer getReadTimeout() { + return readTimeout; + } + + public AsyncHttpClientConfig getAsyncHttpClientConfig() { + return asyncHttpClientConfig; } + + public String getAsyncHttpProviderClassName() { + return asyncHttpProviderClassName; + } + } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConfigAsync.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConfigAsync.java deleted file mode 100644 index 346993b21..000000000 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConfigAsync.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.github.scribejava.core.model; - -import com.ning.http.client.AsyncHttpClientConfig; -import java.io.OutputStream; - -public class OAuthConfigAsync extends OAuthConfig { - - private AsyncHttpClientConfig asyncHttpClientConfig; - private String asyncHttpProviderClassName; - - public OAuthConfigAsync(String key, String secret) { - super(key, secret); - } - - public OAuthConfigAsync(String key, String secret, String callback, SignatureType type, String scope, - String grantType, String state, String responseType, OutputStream stream, - AsyncHttpClientConfig asyncHttpClientConfig) { - super(key, secret, callback, type, scope, stream, null, null, grantType, state, responseType); - this.asyncHttpClientConfig = asyncHttpClientConfig; - } - - public AsyncHttpClientConfig getAsyncHttpClientConfig() { - return asyncHttpClientConfig; - } - - public void setAsyncHttpProviderClassName(String asyncHttpProviderClassName) { - this.asyncHttpProviderClassName = asyncHttpProviderClassName; - } - - public String getAsyncHttpProviderClassName() { - return asyncHttpProviderClassName; - } -} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java index ad7c1d4b4..3b0e1870e 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java @@ -4,8 +4,8 @@ import com.github.scribejava.core.exceptions.OAuthException; import com.github.scribejava.core.model.ForceTypeOfHttpRequest; import com.github.scribejava.core.model.OAuthConfig; -import com.github.scribejava.core.model.OAuthConfigAsync; import com.github.scribejava.core.model.ScribeJavaConfig; +import com.ning.http.client.AsyncHttpClientConfig; /** * The main ScribeJava object. @@ -15,31 +15,31 @@ public abstract class OAuthService { private final OAuthConfig config; - private AsyncHttpClient asyncHttpClient; + private final AsyncHttpClient asyncHttpClient; public OAuthService(OAuthConfig config) { this.config = config; final ForceTypeOfHttpRequest forceTypeOfHttpRequest = ScribeJavaConfig.getForceTypeOfHttpRequests(); - if (config instanceof OAuthConfigAsync) { + final AsyncHttpClientConfig asyncHttpClientConfig = config.getAsyncHttpClientConfig(); + if (asyncHttpClientConfig == null) { + if (ForceTypeOfHttpRequest.FORCE_ASYNC_ONLY_HTTP_REQUESTS == forceTypeOfHttpRequest) { + throw new OAuthException("Cannot use sync operations, only async"); + } + if (ForceTypeOfHttpRequest.PREFER_ASYNC_ONLY_HTTP_REQUESTS == forceTypeOfHttpRequest) { + config.log("Cannot use sync operations, only async"); + } + asyncHttpClient = null; + } else { if (ForceTypeOfHttpRequest.FORCE_SYNC_ONLY_HTTP_REQUESTS == forceTypeOfHttpRequest) { throw new OAuthException("Cannot use async operations, only sync"); } if (ForceTypeOfHttpRequest.PREFER_SYNC_ONLY_HTTP_REQUESTS == forceTypeOfHttpRequest) { config.log("Cannot use async operations, only sync"); } - final OAuthConfigAsync asyncConfig = (OAuthConfigAsync) config; - final String asyncHttpProviderClassName = asyncConfig.getAsyncHttpProviderClassName(); + final String asyncHttpProviderClassName = config.getAsyncHttpProviderClassName(); - asyncHttpClient = asyncHttpProviderClassName == null - ? new AsyncHttpClient(asyncConfig.getAsyncHttpClientConfig()) - : new AsyncHttpClient(asyncHttpProviderClassName, asyncConfig.getAsyncHttpClientConfig()); - } else { - if (ForceTypeOfHttpRequest.FORCE_ASYNC_ONLY_HTTP_REQUESTS == forceTypeOfHttpRequest) { - throw new OAuthException("Cannot use sync operations, only async"); - } - if (ForceTypeOfHttpRequest.PREFER_ASYNC_ONLY_HTTP_REQUESTS == forceTypeOfHttpRequest) { - config.log("Cannot use sync operations, only async"); - } + asyncHttpClient = asyncHttpProviderClassName == null ? new AsyncHttpClient(asyncHttpClientConfig) + : new AsyncHttpClient(asyncHttpProviderClassName, asyncHttpClientConfig); } } From c6d55483e117dfb8a5f8cc2353c5dec4d3c1cb00 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 16 May 2016 17:53:45 +0300 Subject: [PATCH 190/882] add optional "User-Agent" config option to use while making http calls --- changelog | 1 + .../core/builder/ServiceBuilder.java | 9 ++++++++- .../scribejava/core/model/OAuthConfig.java | 18 ++++++++++++------ .../scribejava/core/model/OAuthConstants.java | 4 ++++ .../scribejava/core/model/OAuthRequest.java | 4 ++++ .../core/model/OAuthRequestAsync.java | 7 ++++++- 6 files changed, 35 insertions(+), 8 deletions(-) diff --git a/changelog b/changelog index dad577932..b79af6899 100644 --- a/changelog +++ b/changelog @@ -1,5 +1,6 @@ [SNAPSHOT] * simplify async/sync usages + * add optional "User-Agent" config option to use while making http calls [2.5.3] * fix - do not send two Content-Type header in async requests 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 93ee34526..57bd54e96 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 @@ -23,6 +23,7 @@ public class ServiceBuilder { private OutputStream debugStream; private String grantType; private String responseType = "code"; + private String userAgent; //sync version only private Integer connectTimeout; @@ -150,6 +151,11 @@ public ServiceBuilder asyncHttpProviderClassName(String asyncHttpProviderClassNa return this; } + public ServiceBuilder userAgent(String userAgent) { + this.userAgent = userAgent; + return this; + } + public ServiceBuilder debug() { debugStream(System.out); return this; @@ -161,7 +167,8 @@ public void checkPreconditions() { private OAuthConfig createConfig() { checkPreconditions(); return new OAuthConfig(apiKey, apiSecret, callback, signatureType, scope, debugStream, grantType, state, - responseType, connectTimeout, readTimeout, asyncHttpClientConfig, asyncHttpProviderClassName); + responseType, userAgent, connectTimeout, readTimeout, asyncHttpClientConfig, + asyncHttpProviderClassName); } /** diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConfig.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConfig.java index a363cf915..eba9ddeba 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConfig.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConfig.java @@ -18,6 +18,7 @@ public class OAuthConfig { private final OutputStream debugStream; private final String state; private final String responseType; + private final String userAgent; //sync only version private final Integer connectTimeout; @@ -28,23 +29,25 @@ public class OAuthConfig { private final String asyncHttpProviderClassName; public OAuthConfig(String key, String secret) { - this(key, secret, null, null, null, null, null, null, null, null, null, null, null); + this(key, secret, null, null, null, null, null, null, null, null, null, null, null, null); } public OAuthConfig(String apiKey, String apiSecret, String callback, SignatureType signatureType, String scope, - OutputStream debugStream, String grantType, String state, String responseType, Integer connectTimeout, - Integer readTimeout, AsyncHttpClientConfig asyncHttpClientConfig, String asyncHttpProviderClassName) { + OutputStream debugStream, String grantType, String state, String responseType, String userAgent, + Integer connectTimeout, Integer readTimeout, AsyncHttpClientConfig asyncHttpClientConfig, + String asyncHttpProviderClassName) { this.apiKey = apiKey; this.apiSecret = apiSecret; this.callback = callback; this.signatureType = signatureType; this.scope = scope; this.debugStream = debugStream; - this.connectTimeout = connectTimeout; - this.readTimeout = readTimeout; this.grantType = grantType; this.state = state; this.responseType = responseType; + this.userAgent = userAgent; + this.connectTimeout = connectTimeout; + this.readTimeout = readTimeout; this.asyncHttpClientConfig = asyncHttpClientConfig; this.asyncHttpProviderClassName = asyncHttpProviderClassName; } @@ -89,6 +92,10 @@ public String getResponseType() { return responseType; } + public String getUserAgent() { + return userAgent; + } + public void log(String message) { if (debugStream != null) { message += '\n'; @@ -115,5 +122,4 @@ public AsyncHttpClientConfig getAsyncHttpClientConfig() { public String getAsyncHttpProviderClassName() { return asyncHttpProviderClassName; } - } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConstants.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConstants.java index 687970171..d328e2242 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConstants.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConstants.java @@ -35,4 +35,8 @@ public interface OAuthConstants { String STATE = "state"; String USERNAME = "username"; String PASSWORD = "password"; + + //not OAuth specific + String USER_AGENT_HEADER_NAME = "User-Agent"; + } 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 66a36415a..230cd15b9 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 @@ -70,6 +70,10 @@ void addHeaders() { for (Map.Entry entry : getHeaders().entrySet()) { connection.setRequestProperty(entry.getKey(), entry.getValue()); } + final String userAgent = getService().getConfig().getUserAgent(); + if (userAgent != null) { + connection.setRequestProperty(OAuthConstants.USER_AGENT_HEADER_NAME, userAgent); + } } void addBody(byte[] content) throws IOException { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequestAsync.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequestAsync.java index 1081f0b68..fc422e8e6 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequestAsync.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequestAsync.java @@ -47,8 +47,9 @@ public Future sendAsync(OAuthAsyncRequestCallback callback, ResponseCo throw new OAuthException("Cannot use async operations, only sync"); } final OAuthService service = getService(); + final OAuthConfig config = service.getConfig(); if (ForceTypeOfHttpRequest.PREFER_SYNC_ONLY_HTTP_REQUESTS == forceTypeOfHttpRequest) { - service.getConfig().log("Cannot use async operations, only sync"); + config.log("Cannot use async operations, only sync"); } final String completeUrl = getCompleteUrl(); final AsyncHttpClient.BoundRequestBuilder boundRequestBuilder; @@ -72,6 +73,10 @@ public Future sendAsync(OAuthAsyncRequestCallback callback, ResponseCo for (Map.Entry header : headers.entrySet()) { boundRequestBuilder.addHeader(header.getKey(), header.getValue()); } + final String userAgent = config.getUserAgent(); + if (userAgent != null) { + boundRequestBuilder.setHeader(OAuthConstants.USER_AGENT_HEADER_NAME, userAgent); + } if (proxyServer != null) { boundRequestBuilder.setProxyServer(proxyServer); From 53fbad022a901425fb5de8d1bd65d3d7a7afa785 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 16 May 2016 19:04:07 +0300 Subject: [PATCH 191/882] refactor usage of grant_type [authorization_code|refresh_token|password|etc] --- changelog | 1 + .../scribejava/apis/ConstantContactApi2.java | 3 +-- .../scribejava/apis/Foursquare2Api.java | 3 +-- .../github/scribejava/apis/GoogleApi20.java | 7 ------ .../github/scribejava/apis/KaixinApi20.java | 3 +-- .../com/github/scribejava/apis/LiveApi.java | 3 +-- .../github/scribejava/apis/PinterestApi.java | 3 +-- .../com/github/scribejava/apis/RenrenApi.java | 3 +-- .../scribejava/apis/SinaWeiboApi20.java | 3 +-- .../com/github/scribejava/apis/ViadeoApi.java | 3 +-- .../apis/service/GoogleOAuthServiceImpl.java | 23 ------------------- .../apis/service/LinkedIn20ServiceImpl.java | 10 -------- .../apis/service/MailruOAuthServiceImpl.java | 10 -------- .../scribejava/apis/examples/HHExample.java | 1 - .../apis/examples/OdnoklassnikiExample.java | 2 -- .../apis/examples/TutByExample.java | 2 -- .../core/builder/ServiceBuilder.java | 12 ++-------- .../scribejava/core/model/OAuthConfig.java | 17 +++----------- .../scribejava/core/oauth/OAuth20Service.java | 4 +--- 19 files changed, 15 insertions(+), 98 deletions(-) delete mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/service/GoogleOAuthServiceImpl.java diff --git a/changelog b/changelog index b79af6899..61683c6d3 100644 --- a/changelog +++ b/changelog @@ -1,6 +1,7 @@ [SNAPSHOT] * simplify async/sync usages * add optional "User-Agent" config option to use while making http calls + * refactor usage of grant_type [authorization_code|refresh_token|password|etc] [2.5.3] * fix - do not send two Content-Type header in async requests diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/ConstantContactApi2.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/ConstantContactApi2.java index 3dd0af0a2..b0bbb59eb 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/ConstantContactApi2.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/ConstantContactApi2.java @@ -6,7 +6,6 @@ import com.github.scribejava.core.extractors.TokenExtractor; import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthConfig; -import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.utils.OAuthEncoder; public class ConstantContactApi2 extends DefaultApi20 { @@ -28,7 +27,7 @@ public static ConstantContactApi2 instance() { @Override public String getAccessTokenEndpoint() { - return "https://oauth2.constantcontact.com/oauth2/oauth/token?grant_type=" + OAuthConstants.AUTHORIZATION_CODE; + return "https://oauth2.constantcontact.com/oauth2/oauth/token"; } @Override diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/Foursquare2Api.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/Foursquare2Api.java index 2e65672f0..0fc29de2b 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/Foursquare2Api.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/Foursquare2Api.java @@ -2,7 +2,6 @@ import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.model.OAuthConfig; -import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.utils.OAuthEncoder; import com.github.scribejava.core.utils.Preconditions; @@ -30,7 +29,7 @@ public Verb getAccessTokenVerb() { @Override public String getAccessTokenEndpoint() { - return "https://foursquare.com/oauth2/access_token?grant_type=" + OAuthConstants.AUTHORIZATION_CODE; + return "https://foursquare.com/oauth2/access_token"; } @Override diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/GoogleApi20.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/GoogleApi20.java index 26d003bdd..c94c143c8 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/GoogleApi20.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/GoogleApi20.java @@ -1,13 +1,11 @@ package com.github.scribejava.apis; import com.github.scribejava.apis.google.GoogleJsonTokenExtractor; -import com.github.scribejava.apis.service.GoogleOAuthServiceImpl; import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.extractors.TokenExtractor; import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; -import com.github.scribejava.core.oauth.OAuth20Service; import com.github.scribejava.core.utils.OAuthEncoder; public class GoogleApi20 extends DefaultApi20 { @@ -47,9 +45,4 @@ public String getAuthorizationUrl(OAuthConfig config) { public TokenExtractor getAccessTokenExtractor() { return GoogleJsonTokenExtractor.instance(); } - - @Override - public OAuth20Service createService(OAuthConfig config) { - return new GoogleOAuthServiceImpl(this, config); - } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/KaixinApi20.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/KaixinApi20.java index 979a4b5a4..383f1d20f 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/KaixinApi20.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/KaixinApi20.java @@ -2,7 +2,6 @@ import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.model.OAuthConfig; -import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.utils.OAuthEncoder; @@ -33,7 +32,7 @@ public Verb getAccessTokenVerb() { @Override public String getAccessTokenEndpoint() { - return "https://api.kaixin001.com/oauth2/access_token?grant_type=" + OAuthConstants.AUTHORIZATION_CODE; + return "https://api.kaixin001.com/oauth2/access_token"; } @Override diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/LiveApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/LiveApi.java index 8d02a199c..96b742bc9 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/LiveApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/LiveApi.java @@ -2,7 +2,6 @@ import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.model.OAuthConfig; -import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.utils.OAuthEncoder; import com.github.scribejava.core.utils.Preconditions; @@ -31,7 +30,7 @@ public Verb getAccessTokenVerb() { @Override public String getAccessTokenEndpoint() { - return "https://login.live.com/oauth20_token.srf?grant_type=" + OAuthConstants.AUTHORIZATION_CODE; + return "https://login.live.com/oauth20_token.srf"; } @Override diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/PinterestApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/PinterestApi.java index 0e3f96c4d..ad0151558 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/PinterestApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/PinterestApi.java @@ -2,7 +2,6 @@ import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.model.OAuthConfig; -import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.utils.OAuthEncoder; import com.github.scribejava.core.utils.Preconditions; @@ -25,7 +24,7 @@ public static PinterestApi instance() { @Override public String getAccessTokenEndpoint() { - return "https://api.pinterest.com/v1/oauth/token?grant_type=" + OAuthConstants.AUTHORIZATION_CODE; + return "https://api.pinterest.com/v1/oauth/token"; } @Override diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/RenrenApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/RenrenApi.java index 726baffd4..25430ecd6 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/RenrenApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/RenrenApi.java @@ -2,7 +2,6 @@ import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.model.OAuthConfig; -import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.utils.OAuthEncoder; @@ -33,7 +32,7 @@ public Verb getAccessTokenVerb() { @Override public String getAccessTokenEndpoint() { - return "https://graph.renren.com/oauth/token?grant_type=" + OAuthConstants.AUTHORIZATION_CODE; + return "https://graph.renren.com/oauth/token"; } @Override diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/SinaWeiboApi20.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/SinaWeiboApi20.java index b0edb459d..42860e655 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/SinaWeiboApi20.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/SinaWeiboApi20.java @@ -2,7 +2,6 @@ import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.model.OAuthConfig; -import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.utils.OAuthEncoder; /** @@ -27,7 +26,7 @@ public static SinaWeiboApi20 instance() { @Override public String getAccessTokenEndpoint() { - return "https://api.weibo.com/oauth2/access_token?grant_type=" + OAuthConstants.AUTHORIZATION_CODE; + return "https://api.weibo.com/oauth2/access_token"; } @Override diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/ViadeoApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/ViadeoApi.java index a84c15195..185d684af 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/ViadeoApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/ViadeoApi.java @@ -2,7 +2,6 @@ import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.model.OAuthConfig; -import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.utils.OAuthEncoder; import com.github.scribejava.core.utils.Preconditions; @@ -31,7 +30,7 @@ public Verb getAccessTokenVerb() { @Override public String getAccessTokenEndpoint() { - return "https://secure.viadeo.com/oauth-provider/access_token2?grant_type=" + OAuthConstants.AUTHORIZATION_CODE; + return "https://secure.viadeo.com/oauth-provider/access_token2"; } @Override diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/GoogleOAuthServiceImpl.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/GoogleOAuthServiceImpl.java deleted file mode 100644 index 015ce3677..000000000 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/GoogleOAuthServiceImpl.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.github.scribejava.apis.service; - -import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.model.AbstractRequest; -import com.github.scribejava.core.model.OAuthConfig; -import com.github.scribejava.core.model.OAuthConstants; -import com.github.scribejava.core.oauth.OAuth20Service; - -public class GoogleOAuthServiceImpl extends OAuth20Service { - - public GoogleOAuthServiceImpl(DefaultApi20 api, OAuthConfig config) { - super(api, config); - } - - @Override - protected T createAccessTokenRequest(String code, T request) { - super.createAccessTokenRequest(code, request); - if (!getConfig().hasGrantType()) { - request.addParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.AUTHORIZATION_CODE); - } - return request; - } -} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/LinkedIn20ServiceImpl.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/LinkedIn20ServiceImpl.java index 49bae5ecf..b0e6adf14 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/LinkedIn20ServiceImpl.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/LinkedIn20ServiceImpl.java @@ -4,7 +4,6 @@ import com.github.scribejava.core.model.AbstractRequest; import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthConfig; -import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.oauth.OAuth20Service; public class LinkedIn20ServiceImpl extends OAuth20Service { @@ -17,13 +16,4 @@ public LinkedIn20ServiceImpl(DefaultApi20 api, OAuthConfig config) { public void signRequest(OAuth2AccessToken accessToken, AbstractRequest request) { request.addQuerystringParameter("oauth2_access_token", accessToken.getAccessToken()); } - - @Override - protected T createAccessTokenRequest(String code, T request) { - super.createAccessTokenRequest(code, request); - if (!getConfig().hasGrantType()) { - request.addParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.AUTHORIZATION_CODE); - } - return request; - } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthServiceImpl.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthServiceImpl.java index a6d4f9b3a..d436d8244 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthServiceImpl.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthServiceImpl.java @@ -10,7 +10,6 @@ import com.github.scribejava.core.model.AbstractRequest; import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthConfig; -import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.oauth.OAuth20Service; public class MailruOAuthServiceImpl extends OAuth20Service { @@ -49,13 +48,4 @@ public void signRequest(OAuth2AccessToken accessToken, AbstractRequest request) throw new IllegalStateException(e); } } - - @Override - protected T createAccessTokenRequest(String code, T request) { - super.createAccessTokenRequest(code, request); - if (!getConfig().hasGrantType()) { - request.addParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.AUTHORIZATION_CODE); - } - return request; - } } diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HHExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HHExample.java index ad9d687d1..0ca8052e0 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HHExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HHExample.java @@ -24,7 +24,6 @@ public static void main(String... args) { .apiKey(clientId) .apiSecret(clientSecret) .callback("http://your.site.com/callback") - .grantType("authorization_code") .build(HHApi.instance()); final Scanner in = new Scanner(System.in); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java index 6cdc33e7c..1900e3f47 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java @@ -4,7 +4,6 @@ import com.github.scribejava.core.builder.ServiceBuilder; import com.github.scribejava.apis.OdnoklassnikiApi; import com.github.scribejava.core.model.OAuth2AccessToken; -import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; import com.github.scribejava.core.model.Verb; @@ -25,7 +24,6 @@ public static void main(String... args) { final OAuth20Service service = new ServiceBuilder() .apiKey(clientId) .apiSecret(secretKey) - .grantType(OAuthConstants.AUTHORIZATION_CODE) .callback("http://your.site.com/callback") .build(OdnoklassnikiApi.instance()); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TutByExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TutByExample.java index 4f201c85e..e8d82d98b 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TutByExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TutByExample.java @@ -3,7 +3,6 @@ import java.util.Scanner; import com.github.scribejava.core.builder.ServiceBuilder; -import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; import com.github.scribejava.core.model.Verb; @@ -24,7 +23,6 @@ public static void main(String... args) { final OAuth20Service service = new ServiceBuilder() .apiKey(clientId) .apiSecret(clientSecret) - .grantType(OAuthConstants.AUTHORIZATION_CODE) .callback("http://www.example.com/oauth_callback/") .build(TutByApi.instance()); final Scanner in = new Scanner(System.in, "UTF-8"); 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 57bd54e96..de5f51f03 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 @@ -21,7 +21,6 @@ public class ServiceBuilder { private String state; private SignatureType signatureType; private OutputStream debugStream; - private String grantType; private String responseType = "code"; private String userAgent; @@ -116,12 +115,6 @@ public ServiceBuilder debugStream(OutputStream debugStream) { return this; } - public ServiceBuilder grantType(String grantType) { - Preconditions.checkEmptyString(grantType, "Invalid OAuth grantType"); - this.grantType = grantType; - return this; - } - public ServiceBuilder responseType(String responseType) { Preconditions.checkEmptyString(responseType, "Invalid OAuth responseType"); this.responseType = responseType; @@ -166,9 +159,8 @@ public void checkPreconditions() { } private OAuthConfig createConfig() { checkPreconditions(); - return new OAuthConfig(apiKey, apiSecret, callback, signatureType, scope, debugStream, grantType, state, - responseType, userAgent, connectTimeout, readTimeout, asyncHttpClientConfig, - asyncHttpProviderClassName); + return new OAuthConfig(apiKey, apiSecret, callback, signatureType, scope, debugStream, state, responseType, + userAgent, connectTimeout, readTimeout, asyncHttpClientConfig, asyncHttpProviderClassName); } /** diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConfig.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConfig.java index eba9ddeba..aab9ac513 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConfig.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConfig.java @@ -14,7 +14,6 @@ public class OAuthConfig { private final String callback; private final SignatureType signatureType; private final String scope; - private final String grantType; private final OutputStream debugStream; private final String state; private final String responseType; @@ -29,20 +28,18 @@ public class OAuthConfig { private final String asyncHttpProviderClassName; public OAuthConfig(String key, String secret) { - this(key, secret, null, null, null, null, null, null, null, null, null, null, null, null); + this(key, secret, null, null, null, null, null, null, null, null, null, null, null); } public OAuthConfig(String apiKey, String apiSecret, String callback, SignatureType signatureType, String scope, - OutputStream debugStream, String grantType, String state, String responseType, String userAgent, - Integer connectTimeout, Integer readTimeout, AsyncHttpClientConfig asyncHttpClientConfig, - String asyncHttpProviderClassName) { + OutputStream debugStream, String state, String responseType, String userAgent, Integer connectTimeout, + Integer readTimeout, AsyncHttpClientConfig asyncHttpClientConfig, String asyncHttpProviderClassName) { this.apiKey = apiKey; this.apiSecret = apiSecret; this.callback = callback; this.signatureType = signatureType; this.scope = scope; this.debugStream = debugStream; - this.grantType = grantType; this.state = state; this.responseType = responseType; this.userAgent = userAgent; @@ -76,14 +73,6 @@ public boolean hasScope() { return scope != null; } - public String getGrantType() { - return grantType; - } - - public boolean hasGrantType() { - return grantType != null; - } - public String getState() { return state; } 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 2c7f8306b..275a825b5 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 @@ -87,9 +87,7 @@ protected T createAccessTokenRequest(String code, T if (config.hasScope()) { request.addParameter(OAuthConstants.SCOPE, config.getScope()); } - if (config.hasGrantType()) { - request.addParameter(OAuthConstants.GRANT_TYPE, config.getGrantType()); - } + request.addParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.AUTHORIZATION_CODE); return request; } From 338406dc2c716e15f96aae43614628f8b285502f Mon Sep 17 00:00:00 2001 From: Tomasz Szymaniec Date: Sat, 9 Apr 2016 22:30:01 +0100 Subject: [PATCH 192/882] add Genius.com API authentication (OAuth2) --- changelog | 1 + .../com/github/scribejava/apis/GeniusApi.java | 52 ++++++++++++ .../apis/service/GeniusOAuthServiceImpl.java | 19 +++++ .../apis/examples/GeniusExample.java | 85 +++++++++++++++++++ 4 files changed, 157 insertions(+) create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/GeniusApi.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/service/GeniusOAuthServiceImpl.java create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GeniusExample.java diff --git a/changelog b/changelog index 61683c6d3..226303c8e 100644 --- a/changelog +++ b/changelog @@ -2,6 +2,7 @@ * simplify async/sync usages * add optional "User-Agent" config option to use while making http calls * refactor usage of grant_type [authorization_code|refresh_token|password|etc] + * add Genius.com API authentication (OAuth2) [2.5.3] * fix - do not send two Content-Type header in async requests diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/GeniusApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/GeniusApi.java new file mode 100644 index 000000000..172138cb1 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/GeniusApi.java @@ -0,0 +1,52 @@ +package com.github.scribejava.apis; + +import com.github.scribejava.apis.service.GeniusOAuthServiceImpl; +import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.model.OAuthConfig; +import com.github.scribejava.core.oauth.OAuth20Service; +import com.github.scribejava.core.utils.OAuthEncoder; + +public class GeniusApi extends DefaultApi20 { + + private static final String AUTHORIZE_URL = "https://api.genius.com/oauth/authorize" + + "?client_id=%s" + + "&redirect_uri=%s" + + "&scope=%s" + + "&state=%s" + + "&response_type=code"; + + private static final String TOKEN_ENDPOINT_URL = "https://api.genius.com/oauth/token"; + + protected GeniusApi() { + } + + private static class InstanceHolder { + + private static final GeniusApi INSTANCE = new GeniusApi(); + } + + public static GeniusApi instance() { + return InstanceHolder.INSTANCE; + } + + @Override + public String getAccessTokenEndpoint() { + return TOKEN_ENDPOINT_URL; + } + + @Override + public String getAuthorizationUrl(OAuthConfig config) { + + // User must provide these 4 elements to the service builder + return String.format(AUTHORIZE_URL, + OAuthEncoder.encode(config.getApiKey()), + OAuthEncoder.encode(config.getCallback()), + OAuthEncoder.encode(config.getScope()), + OAuthEncoder.encode(config.getState())); + } + + @Override + public OAuth20Service createService(OAuthConfig config) { + return new GeniusOAuthServiceImpl(this, config); + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/GeniusOAuthServiceImpl.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/GeniusOAuthServiceImpl.java new file mode 100644 index 000000000..4c2aa992c --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/GeniusOAuthServiceImpl.java @@ -0,0 +1,19 @@ +package com.github.scribejava.apis.service; + +import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.model.AbstractRequest; +import com.github.scribejava.core.model.OAuth2AccessToken; +import com.github.scribejava.core.model.OAuthConfig; +import com.github.scribejava.core.oauth.OAuth20Service; + +public class GeniusOAuthServiceImpl extends OAuth20Service { + + public GeniusOAuthServiceImpl(DefaultApi20 api, OAuthConfig config) { + super(api, config); + } + + @Override + public void signRequest(OAuth2AccessToken accessToken, AbstractRequest request) { + request.addHeader("Authorization", "Bearer " + accessToken.getAccessToken()); + } +} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GeniusExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GeniusExample.java new file mode 100644 index 000000000..141cc7ebf --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GeniusExample.java @@ -0,0 +1,85 @@ +package com.github.scribejava.apis.examples; + +import java.util.Scanner; + +import com.github.scribejava.apis.GeniusApi; +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 abstract class GeniusExample { + + private static final String NETWORK_NAME = "Genius"; + private static final String PROTECTED_RESOURCE_URL = "https://api.genius.com/songs/378195"; + + public static void main(String... args) { + // Replace these with your client id and secret + final String clientId = "your client id"; + final String clientSecret = "your client secret"; + final String secretState = "100"; + final OAuth20Service service = new ServiceBuilder() + .apiKey(clientId) + .apiSecret(clientSecret) + .scope("me") + .state(secretState) + .callback("com.scribejavatest://callback") + .userAgent("ScribeJava") + .build(GeniusApi.instance()); + + System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); + System.out.println(); + + // Obtain the Authorization URL + System.out.println("Fetching the Authorization URL..."); + final String authorizationUrl = service.getAuthorizationUrl(); + System.out.println("Got the Authorization URL!"); + System.out.println("Now go and authorize ScribeJava here:"); + System.out.println(authorizationUrl); + System.out.println("And paste the authorization code here"); + System.out.print(">>"); + final String code; + final String value; + try (Scanner in = new Scanner(System.in, "UTF-8")) { + code = in.nextLine(); + System.out.println(); + + System.out.println("And paste the state from server here. We have set 'secretState'='" + secretState + + "'."); + System.out.print(">>"); + value = in.nextLine(); + } + + if (secretState.equals(value)) { + System.out.println("State value does match!"); + } else { + System.out.println("Ooops, state value does not match!"); + System.out.println("Expected = " + secretState); + System.out.println("Got = " + value); + System.out.println(); + } + + // Trade the Request Token and Verifier for the Access Token + System.out.println("Trading the Request Token for an Access Token..."); + final OAuth2AccessToken accessToken = service.getAccessToken(code); + System.out.println("Got the Access Token!"); + System.out.println("(View Access Token contents: " + accessToken + + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println(); + + // Now let's go and ask for a protected resource! + System.out.println("Accessing a protected resource..."); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service); + service.signRequest(accessToken, request); + final Response response = request.send(); + System.out.println("Got it! Viewing contents..."); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + + System.out.println(); + System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); + } +} From ca335ad2c9b836c7d2ef9933e8bedb4d4bab3578 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 23 May 2016 14:05:40 +0300 Subject: [PATCH 193/882] update maven dependencies --- pom.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index a87a5c4bf..83388dab5 100644 --- a/pom.xml +++ b/pom.xml @@ -120,7 +120,7 @@ org.apache.maven.plugins maven-jar-plugin - 2.6 + 3.0.0 ${project.build.outputDirectory}/META-INF/MANIFEST.MF @@ -163,7 +163,7 @@ org.apache.maven.plugins maven-resources-plugin - 2.7 + 3.0.0 UTF-8 @@ -205,7 +205,7 @@ com.puppycrawl.tools checkstyle - 6.17 + 6.18 From 8af489aff6504e24b05abe7cc329a2af9d03dcf6 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 23 May 2016 17:39:23 +0300 Subject: [PATCH 194/882] fix GitHubAPI --- changelog | 1 + .../src/main/java/com/github/scribejava/apis/GitHubApi.java | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/changelog b/changelog index 226303c8e..714a3024e 100644 --- a/changelog +++ b/changelog @@ -3,6 +3,7 @@ * add optional "User-Agent" config option to use while making http calls * refactor usage of grant_type [authorization_code|refresh_token|password|etc] * add Genius.com API authentication (OAuth2) + * fix GitHub API [2.5.3] * fix - do not send two Content-Type header in async requests diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/GitHubApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/GitHubApi.java index 12ed978dd..ebacda46f 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/GitHubApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/GitHubApi.java @@ -27,7 +27,7 @@ public static GitHubApi instance() { @Override public Verb getAccessTokenVerb() { - return Verb.GET; + return Verb.POST; } @Override From 4e2a9a13b4fb601cbc2c99a9703f6147dd6a2529 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 23 May 2016 17:26:40 +0300 Subject: [PATCH 195/882] standardize authorization url generation for OAuth2 --- changelog | 1 + .../scribejava/apis/ConstantContactApi2.java | 10 +---- .../scribejava/apis/DoktornaraboteApi.java | 29 ++------------ .../github/scribejava/apis/FacebookApi.java | 23 +---------- .../scribejava/apis/Foursquare2Api.java | 12 +----- .../com/github/scribejava/apis/GeniusApi.java | 22 ++--------- .../com/github/scribejava/apis/GitHubApi.java | 21 +--------- .../github/scribejava/apis/GoogleApi20.java | 17 +-------- .../com/github/scribejava/apis/HHApi.java | 12 ++---- .../com/github/scribejava/apis/ImgurApi.java | 34 ++++++++++++++--- .../github/scribejava/apis/KaixinApi20.java | 16 +------- .../github/scribejava/apis/LinkedInApi20.java | 22 +---------- .../com/github/scribejava/apis/LiveApi.java | 20 +--------- .../com/github/scribejava/apis/MailruApi.java | 17 +-------- .../scribejava/apis/OdnoklassnikiApi.java | 23 +---------- .../github/scribejava/apis/PinterestApi.java | 20 +--------- .../com/github/scribejava/apis/RenrenApi.java | 16 +------- .../scribejava/apis/SinaWeiboApi20.java | 16 +------- .../scribejava/apis/StackExchangeApi.java | 22 +---------- .../com/github/scribejava/apis/TutByApi.java | 11 +----- .../com/github/scribejava/apis/ViadeoApi.java | 20 +--------- .../github/scribejava/apis/VkontakteApi.java | 18 +-------- .../core/builder/ServiceBuilder.java | 1 + .../core/builder/api/DefaultApi20.java | 38 +++++++++---------- .../scribejava/core/model/OAuthConfig.java | 4 -- .../scribejava/core/model/OAuthConstants.java | 2 + .../scribejava/core/model/ParameterList.java | 18 +++++---- .../core/oauth/OAuth10aService.java | 5 ++- .../scribejava/core/oauth/OAuth20Service.java | 22 +++++------ .../core/builder/ServiceBuilderTest.java | 2 +- .../scribejava/core/oauth/OAuth20ApiUnit.java | 2 +- 31 files changed, 120 insertions(+), 376 deletions(-) diff --git a/changelog b/changelog index 714a3024e..117278137 100644 --- a/changelog +++ b/changelog @@ -4,6 +4,7 @@ * refactor usage of grant_type [authorization_code|refresh_token|password|etc] * add Genius.com API authentication (OAuth2) * fix GitHub API + * standardize authorization url generation for OAuth2 [2.5.3] * fix - do not send two Content-Type header in async requests diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/ConstantContactApi2.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/ConstantContactApi2.java index b0bbb59eb..94cbde0c8 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/ConstantContactApi2.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/ConstantContactApi2.java @@ -5,15 +5,9 @@ import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.extractors.TokenExtractor; import com.github.scribejava.core.model.OAuth2AccessToken; -import com.github.scribejava.core.model.OAuthConfig; -import com.github.scribejava.core.utils.OAuthEncoder; public class ConstantContactApi2 extends DefaultApi20 { - private static final String AUTHORIZE_URL - = "https://oauth2.constantcontact.com/oauth2/oauth/siteowner/authorize?client_id=%s&response_type=code" - + "&redirect_uri=%s"; - protected ConstantContactApi2() { } @@ -31,8 +25,8 @@ public String getAccessTokenEndpoint() { } @Override - public String getAuthorizationUrl(OAuthConfig config) { - return String.format(AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback())); + protected String getAuthorizationBaseUrl() { + return "https://oauth2.constantcontact.com/oauth2/oauth/siteowner/authorize"; } @Override diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/DoktornaraboteApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/DoktornaraboteApi.java index 6332aa198..8965ea07f 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/DoktornaraboteApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/DoktornaraboteApi.java @@ -3,17 +3,10 @@ import com.github.scribejava.apis.service.DoktornaraboteOAuthServiceImpl; import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.model.OAuthConfig; -import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.oauth.OAuth20Service; -import com.github.scribejava.core.utils.OAuthEncoder; -import com.github.scribejava.core.utils.Preconditions; public class DoktornaraboteApi extends DefaultApi20 { - private static final String AUTHORIZE_URL - = "http://auth.doktornarabote.ru/OAuth/Authorize?response_type=code&client_id=%s&redirect_uri=%s&scope=%s"; - private static final String TOKEN_URL = "http://auth.doktornarabote.ru/OAuth/Token"; - protected DoktornaraboteApi() { } @@ -27,28 +20,12 @@ public static DoktornaraboteApi instance() { @Override public String getAccessTokenEndpoint() { - return TOKEN_URL; + return "http://auth.doktornarabote.ru/OAuth/Token"; } @Override - public String getAuthorizationUrl(OAuthConfig config) { - Preconditions.checkValidUrl( - config.getCallback(), - "Must provide a valid url as callback. Doktornarabote does not support OOB"); - final StringBuilder sb = new StringBuilder( - String.format( - AUTHORIZE_URL, - config.getApiKey(), - OAuthEncoder.encode(config.getCallback()), - OAuthEncoder.encode(config.getScope()) - ) - ); - - final String state = config.getState(); - if (state != null) { - sb.append('&').append(OAuthConstants.STATE).append('=').append(OAuthEncoder.encode(state)); - } - return sb.toString(); + protected String getAuthorizationBaseUrl() { + return "http://auth.doktornarabote.ru/OAuth/Authorize"; } @Override 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 a2c18b2d6..ffccdd73d 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java @@ -1,20 +1,13 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.model.OAuthConfig; -import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.Verb; -import com.github.scribejava.core.utils.OAuthEncoder; -import com.github.scribejava.core.utils.Preconditions; /** * Facebook v2.5 API */ public class FacebookApi extends DefaultApi20 { - private static final String AUTHORIZE_URL - = "https://www.facebook.com/v2.5/dialog/oauth?client_id=%s&redirect_uri=%s"; - protected FacebookApi() { } @@ -43,19 +36,7 @@ public String getRefreshTokenEndpoint() { } @Override - public String getAuthorizationUrl(OAuthConfig config) { - Preconditions.checkValidUrl(config.getCallback(), - "Must provide a valid url as callback. Facebook does not support OOB"); - final StringBuilder sb = new StringBuilder(String.format(AUTHORIZE_URL, config.getApiKey(), - OAuthEncoder.encode(config.getCallback()))); - if (config.hasScope()) { - sb.append('&').append(OAuthConstants.SCOPE).append('=').append(OAuthEncoder.encode(config.getScope())); - } - - final String state = config.getState(); - if (state != null) { - sb.append('&').append(OAuthConstants.STATE).append('=').append(OAuthEncoder.encode(state)); - } - return sb.toString(); + protected String getAuthorizationBaseUrl() { + return "https://www.facebook.com/v2.5/dialog/oauth"; } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/Foursquare2Api.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/Foursquare2Api.java index 0fc29de2b..cb574618d 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/Foursquare2Api.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/Foursquare2Api.java @@ -1,16 +1,10 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.Verb; -import com.github.scribejava.core.utils.OAuthEncoder; -import com.github.scribejava.core.utils.Preconditions; public class Foursquare2Api extends DefaultApi20 { - private static final String AUTHORIZATION_URL - = "https://foursquare.com/oauth2/authenticate?client_id=%s&response_type=code&redirect_uri=%s"; - protected Foursquare2Api() { } @@ -33,9 +27,7 @@ public String getAccessTokenEndpoint() { } @Override - public String getAuthorizationUrl(OAuthConfig config) { - Preconditions.checkValidUrl(config.getCallback(), - "Must provide a valid url as callback. Foursquare2 does not support OOB"); - return String.format(AUTHORIZATION_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback())); + protected String getAuthorizationBaseUrl() { + return "https://foursquare.com/oauth2/authenticate"; } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/GeniusApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/GeniusApi.java index 172138cb1..14570697c 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/GeniusApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/GeniusApi.java @@ -4,19 +4,9 @@ import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.oauth.OAuth20Service; -import com.github.scribejava.core.utils.OAuthEncoder; public class GeniusApi extends DefaultApi20 { - private static final String AUTHORIZE_URL = "https://api.genius.com/oauth/authorize" - + "?client_id=%s" - + "&redirect_uri=%s" - + "&scope=%s" - + "&state=%s" - + "&response_type=code"; - - private static final String TOKEN_ENDPOINT_URL = "https://api.genius.com/oauth/token"; - protected GeniusApi() { } @@ -31,18 +21,12 @@ public static GeniusApi instance() { @Override public String getAccessTokenEndpoint() { - return TOKEN_ENDPOINT_URL; + return "https://api.genius.com/oauth/token"; } @Override - public String getAuthorizationUrl(OAuthConfig config) { - - // User must provide these 4 elements to the service builder - return String.format(AUTHORIZE_URL, - OAuthEncoder.encode(config.getApiKey()), - OAuthEncoder.encode(config.getCallback()), - OAuthEncoder.encode(config.getScope()), - OAuthEncoder.encode(config.getState())); + protected String getAuthorizationBaseUrl() { + return "https://api.genius.com/oauth/authorize"; } @Override diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/GitHubApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/GitHubApi.java index ebacda46f..ada35c1b3 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/GitHubApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/GitHubApi.java @@ -4,16 +4,10 @@ import com.github.scribejava.core.extractors.OAuth2AccessTokenExtractor; import com.github.scribejava.core.extractors.TokenExtractor; import com.github.scribejava.core.model.OAuth2AccessToken; -import com.github.scribejava.core.model.OAuthConfig; -import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.Verb; -import com.github.scribejava.core.utils.OAuthEncoder; -import com.github.scribejava.core.utils.Preconditions; public class GitHubApi extends DefaultApi20 { - private static final String AUTHORIZE_URL = "https://github.com/login/oauth/authorize?client_id=%s&redirect_uri=%s"; - protected GitHubApi() { } @@ -36,19 +30,8 @@ public String getAccessTokenEndpoint() { } @Override - public String getAuthorizationUrl(OAuthConfig config) { - Preconditions.checkValidUrl(config.getCallback(), - "Must provide a valid url as callback. GitHub does not support OOB"); - final StringBuilder sb = new StringBuilder(String.format(AUTHORIZE_URL, config.getApiKey(), - OAuthEncoder.encode(config.getCallback()))); - if (config.hasScope()) { - sb.append('&').append(OAuthConstants.SCOPE).append('=').append(OAuthEncoder.encode(config.getScope())); - } - final String state = config.getState(); - if (state != null) { - sb.append('&').append(OAuthConstants.STATE).append('=').append(OAuthEncoder.encode(state)); - } - return sb.toString(); + protected String getAuthorizationBaseUrl() { + return "https://github.com/login/oauth/authorize"; } @Override diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/GoogleApi20.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/GoogleApi20.java index c94c143c8..157753f6d 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/GoogleApi20.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/GoogleApi20.java @@ -4,15 +4,9 @@ import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.extractors.TokenExtractor; import com.github.scribejava.core.model.OAuth2AccessToken; -import com.github.scribejava.core.model.OAuthConfig; -import com.github.scribejava.core.model.OAuthConstants; -import com.github.scribejava.core.utils.OAuthEncoder; public class GoogleApi20 extends DefaultApi20 { - private static final String AUTHORIZE_URL - = "https://accounts.google.com/o/oauth2/auth?response_type=%s&client_id=%s&redirect_uri=%s&scope=%s"; - protected GoogleApi20() { } @@ -30,15 +24,8 @@ public String getAccessTokenEndpoint() { } @Override - public String getAuthorizationUrl(OAuthConfig config) { - final StringBuilder sb = new StringBuilder(String.format(AUTHORIZE_URL, config.getResponseType(), - config.getApiKey(), OAuthEncoder.encode(config.getCallback()), OAuthEncoder.encode(config.getScope()))); - - final String state = config.getState(); - if (state != null) { - sb.append('&').append(OAuthConstants.STATE).append('=').append(OAuthEncoder.encode(state)); - } - return sb.toString(); + protected String getAuthorizationBaseUrl() { + return "https://accounts.google.com/o/oauth2/auth"; } @Override diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/HHApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/HHApi.java index ca67c8fca..acb239fa5 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/HHApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/HHApi.java @@ -5,15 +5,9 @@ import com.github.scribejava.apis.service.HHOAuthServiceImpl; import com.github.scribejava.core.oauth.OAuth20Service; -import com.github.scribejava.core.utils.OAuthEncoder; public class HHApi extends DefaultApi20 { - private static final String AUTHORIZE_URL = "https://hh.ru/oauth/authorize?response_type=code&" + - "client_id=%s&redirect_uri=%s"; - - private static final String TOKEN_URL = "https://hh.ru/oauth/token"; - protected HHApi() { } @@ -27,12 +21,12 @@ public static HHApi instance() { @Override public String getAccessTokenEndpoint() { - return TOKEN_URL; + return "https://hh.ru/oauth/token"; } @Override - public String getAuthorizationUrl(OAuthConfig config) { - return String.format(AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback())); + protected String getAuthorizationBaseUrl() { + return "https://hh.ru/oauth/authorize"; } @Override diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java index d55ad2d99..3b14473d1 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java @@ -3,13 +3,13 @@ import com.github.scribejava.apis.service.ImgurOAuthServiceImpl; import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.model.OAuthConfig; +import com.github.scribejava.core.model.OAuthConstants; +import com.github.scribejava.core.model.ParameterList; import com.github.scribejava.core.oauth.OAuth20Service; +import java.util.Map; public class ImgurApi extends DefaultApi20 { - private static final String AUTHORIZATION_URL = - "https://api.imgur.com/oauth2/authorize?client_id=%s&response_type=%s"; - protected ImgurApi() { } @@ -27,8 +27,32 @@ public String getAccessTokenEndpoint() { } @Override - public String getAuthorizationUrl(OAuthConfig config) { - return String.format(AUTHORIZATION_URL, config.getApiKey(), isOob(config) ? "pin" : "code"); + public String getAuthorizationUrl(OAuthConfig config, Map additionalParams) { + final ParameterList parameters = new ParameterList(additionalParams); + parameters.add(OAuthConstants.RESPONSE_TYPE, isOob(config) ? "pin" : "code"); + parameters.add(OAuthConstants.CLIENT_ID, config.getApiKey()); + + final String callback = config.getCallback(); + if (callback != null) { + parameters.add(OAuthConstants.REDIRECT_URI, callback); + } + + final String scope = config.getScope(); + if (scope != null) { + parameters.add(OAuthConstants.SCOPE, scope); + } + + final String state = config.getState(); + if (state != null) { + parameters.add(OAuthConstants.STATE, state); + } + + return parameters.appendTo("https://api.imgur.com/oauth2/authorize"); + } + + @Override + protected String getAuthorizationBaseUrl() { + throw new UnsupportedOperationException("use getAuthorizationUrl instead"); } @Override diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/KaixinApi20.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/KaixinApi20.java index 383f1d20f..cd8917fd5 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/KaixinApi20.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/KaixinApi20.java @@ -1,19 +1,13 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.Verb; -import com.github.scribejava.core.utils.OAuthEncoder; /** * Kaixin(http://www.kaixin001.com/) open platform api based on OAuth 2.0. */ public class KaixinApi20 extends DefaultApi20 { - private static final String AUTHORIZE_URL - = "http://api.kaixin001.com/oauth2/authorize?client_id=%s&redirect_uri=%s&response_type=code"; - private static final String SCOPED_AUTHORIZE_URL = AUTHORIZE_URL + "&scope=%s"; - protected KaixinApi20() { } @@ -36,13 +30,7 @@ public String getAccessTokenEndpoint() { } @Override - public String getAuthorizationUrl(OAuthConfig config) { - // Append scope if present - if (config.hasScope()) { - return String.format(SCOPED_AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()), - OAuthEncoder.encode(config.getScope())); - } else { - return String.format(AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback())); - } + protected String getAuthorizationBaseUrl() { + return "http://api.kaixin001.com/oauth2/authorize"; } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi20.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi20.java index 3043f2737..b39f4a33b 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi20.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi20.java @@ -3,20 +3,11 @@ import com.github.scribejava.apis.service.LinkedIn20ServiceImpl; import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.model.OAuthConfig; -import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.oauth.OAuth20Service; -import com.github.scribejava.core.utils.OAuthEncoder; -import com.github.scribejava.core.utils.Preconditions; public class LinkedInApi20 extends DefaultApi20 { - private static final String AUTHORIZE_URL - = "https://www.linkedin.com/uas/oauth2/authorization?response_type=code&client_id=%s&redirect_uri=%s&" - + OAuthConstants.STATE + "=%s"; - - private static final String SCOPED_AUTHORIZE_URL = AUTHORIZE_URL + "&scope=%s"; - protected LinkedInApi20() { } @@ -39,17 +30,8 @@ public String getAccessTokenEndpoint() { } @Override - public String getAuthorizationUrl(OAuthConfig config) { - Preconditions.checkValidUrl(config.getCallback(), - "Must provide a valid url as callback. LinkedIn does not support OOB"); - - if (config.hasScope()) { - return String.format(SCOPED_AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()), - config.getState(), OAuthEncoder.encode(config.getScope())); - } else { - return String.format(AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()), - config.getState()); - } + protected String getAuthorizationBaseUrl() { + return "https://www.linkedin.com/uas/oauth2/authorization"; } @Override diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/LiveApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/LiveApi.java index 96b742bc9..ee6c6ba12 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/LiveApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/LiveApi.java @@ -1,17 +1,10 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.Verb; -import com.github.scribejava.core.utils.OAuthEncoder; -import com.github.scribejava.core.utils.Preconditions; public class LiveApi extends DefaultApi20 { - private static final String AUTHORIZE_URL - = "https://oauth.live.com/authorize?client_id=%s&redirect_uri=%s&response_type=code"; - private static final String SCOPED_AUTHORIZE_URL = AUTHORIZE_URL + "&scope=%s"; - protected LiveApi() { } @@ -34,16 +27,7 @@ public String getAccessTokenEndpoint() { } @Override - public String getAuthorizationUrl(OAuthConfig config) { - Preconditions.checkValidUrl(config.getCallback(), - "Must provide a valid url as callback. Live does not support OOB"); - - // Append scope if present - if (config.hasScope()) { - return String.format(SCOPED_AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()), - OAuthEncoder.encode(config.getScope())); - } else { - return String.format(AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback())); - } + protected String getAuthorizationBaseUrl() { + return "https://oauth.live.com/authorize"; } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java index a15b45634..a67e434c5 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java @@ -2,17 +2,11 @@ import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.model.OAuthConfig; -import com.github.scribejava.core.utils.OAuthEncoder; -import com.github.scribejava.core.utils.Preconditions; import com.github.scribejava.apis.service.MailruOAuthServiceImpl; import com.github.scribejava.core.oauth.OAuth20Service; public class MailruApi extends DefaultApi20 { - private static final String AUTHORIZE_URL - = "https://connect.mail.ru/oauth/authorize?client_id=%s&redirect_uri=%s&response_type=code"; - private static final String SCOPED_AUTHORIZE_URL = AUTHORIZE_URL + "&scope=%s"; - protected MailruApi() { } @@ -30,15 +24,8 @@ public String getAccessTokenEndpoint() { } @Override - public String getAuthorizationUrl(OAuthConfig config) { - Preconditions.checkValidUrl(config.getCallback(), - "Valid url is required for a callback. Mail.ru does not support OOB"); - if (config.hasScope()) { // Appending scope if present - return String.format(SCOPED_AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()), - OAuthEncoder.encode(config.getScope())); - } else { - return String.format(AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback())); - } + protected String getAuthorizationBaseUrl() { + return "https://connect.mail.ru/oauth/authorize"; } @Override diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java index 0651fe108..3144a77e0 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java @@ -4,14 +4,9 @@ import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.oauth.OAuth20Service; -import com.github.scribejava.core.utils.OAuthEncoder; -import com.github.scribejava.core.utils.Preconditions; public class OdnoklassnikiApi extends DefaultApi20 { - private static final String AUTHORIZE_URL - = "https://connect.ok.ru/oauth/authorize?client_id=%s&response_type=code&redirect_uri=%s"; - protected OdnoklassnikiApi() { } @@ -29,22 +24,8 @@ public String getAccessTokenEndpoint() { } @Override - public String getAuthorizationUrl(OAuthConfig config) { - Preconditions.checkValidUrl(config.getCallback(), - "Valid url is required for a callback. Odnoklassniki does not support OOB"); - - final StringBuilder urlBuilder = new StringBuilder(String.format(AUTHORIZE_URL, - config.getApiKey(), OAuthEncoder.encode(config.getCallback()))); - - if (config.hasScope()) { - urlBuilder.append("&scope=").append(OAuthEncoder.encode(config.getScope())); - } - - final String state = config.getState(); - if (state != null) { - urlBuilder.append("&state=").append(OAuthEncoder.encode(config.getState())); - } - return urlBuilder.toString(); + protected String getAuthorizationBaseUrl() { + return "https://connect.ok.ru/oauth/authorize"; } @Override diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/PinterestApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/PinterestApi.java index ad0151558..0f44d7b12 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/PinterestApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/PinterestApi.java @@ -1,16 +1,9 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.model.OAuthConfig; -import com.github.scribejava.core.utils.OAuthEncoder; -import com.github.scribejava.core.utils.Preconditions; public class PinterestApi extends DefaultApi20 { - private static final String AUTHORIZE_URL - = "https://api.pinterest.com/oauth?response_type=code&client_id=%s&redirect_uri=%s"; - private static final String SCOPED_AUTHORIZE_URL = AUTHORIZE_URL + "&scope=%s"; - protected PinterestApi() { } @@ -28,16 +21,7 @@ public String getAccessTokenEndpoint() { } @Override - public String getAuthorizationUrl(OAuthConfig config) { - Preconditions.checkValidUrl(config.getCallback(), - "Must provide a valid url as callback. Pinterest does not support OOB"); - - // Append scope if present - if (config.hasScope()) { - return String.format(SCOPED_AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()), - OAuthEncoder.encode(config.getScope())); - } else { - return String.format(AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback())); - } + protected String getAuthorizationBaseUrl() { + return "https://api.pinterest.com/oauth"; } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/RenrenApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/RenrenApi.java index 25430ecd6..da10760c3 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/RenrenApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/RenrenApi.java @@ -1,19 +1,13 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.Verb; -import com.github.scribejava.core.utils.OAuthEncoder; /** * Renren(http://www.renren.com/) OAuth 2.0 based api. */ public class RenrenApi extends DefaultApi20 { - private static final String AUTHORIZE_URL - = "https://graph.renren.com/oauth/authorize?client_id=%s&redirect_uri=%s&response_type=code"; - private static final String SCOPED_AUTHORIZE_URL = AUTHORIZE_URL + "&scope=%s"; - protected RenrenApi() { } @@ -36,13 +30,7 @@ public String getAccessTokenEndpoint() { } @Override - public String getAuthorizationUrl(OAuthConfig config) { - // Append scope if present - if (config.hasScope()) { - return String.format(SCOPED_AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()), - OAuthEncoder.encode(config.getScope())); - } else { - return String.format(AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback())); - } + protected String getAuthorizationBaseUrl() { + return "https://graph.renren.com/oauth/authorize"; } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/SinaWeiboApi20.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/SinaWeiboApi20.java index 42860e655..1799806f1 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/SinaWeiboApi20.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/SinaWeiboApi20.java @@ -1,18 +1,12 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.model.OAuthConfig; -import com.github.scribejava.core.utils.OAuthEncoder; /** * SinaWeibo OAuth 2.0 api. */ public class SinaWeiboApi20 extends DefaultApi20 { - private static final String AUTHORIZE_URL - = "https://api.weibo.com/oauth2/authorize?client_id=%s&redirect_uri=%s&response_type=code"; - private static final String SCOPED_AUTHORIZE_URL = AUTHORIZE_URL + "&scope=%s"; - protected SinaWeiboApi20() { } @@ -30,13 +24,7 @@ public String getAccessTokenEndpoint() { } @Override - public String getAuthorizationUrl(OAuthConfig config) { - // Append scope if present - if (config.hasScope()) { - return String.format(SCOPED_AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()), - OAuthEncoder.encode(config.getScope())); - } else { - return String.format(AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback())); - } + protected String getAuthorizationBaseUrl() { + return "https://api.weibo.com/oauth2/authorize"; } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/StackExchangeApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/StackExchangeApi.java index e2e8c5b25..c6dfcb101 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/StackExchangeApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/StackExchangeApi.java @@ -4,10 +4,6 @@ import com.github.scribejava.core.extractors.OAuth2AccessTokenExtractor; import com.github.scribejava.core.extractors.TokenExtractor; import com.github.scribejava.core.model.OAuth2AccessToken; -import com.github.scribejava.core.model.OAuthConfig; -import com.github.scribejava.core.model.OAuthConstants; -import com.github.scribejava.core.utils.OAuthEncoder; -import com.github.scribejava.core.utils.Preconditions; /** * Stack Exchange authentication via OAuth 2.0 (stackoverflow.com, @@ -15,8 +11,6 @@ */ public class StackExchangeApi extends DefaultApi20 { - private static final String AUTHORIZE_URL = "https://stackexchange.com/oauth?client_id=%s&redirect_uri=%s"; - protected StackExchangeApi() { } @@ -34,20 +28,8 @@ public String getAccessTokenEndpoint() { } @Override - public String getAuthorizationUrl(OAuthConfig config) { - Preconditions.checkValidUrl(config.getCallback(), - "Must provide a valid url as callback. StackExchange does not support OOB"); - final StringBuilder sb = new StringBuilder(String.format(AUTHORIZE_URL, config.getApiKey(), - OAuthEncoder.encode(config.getCallback()))); - if (config.hasScope()) { - sb.append('&').append(OAuthConstants.SCOPE).append('=').append(OAuthEncoder.encode(config.getScope())); - } - - final String state = config.getState(); - if (state != null) { - sb.append('&').append(OAuthConstants.STATE).append('=').append(OAuthEncoder.encode(state)); - } - return sb.toString(); + protected String getAuthorizationBaseUrl() { + return "https://stackexchange.com/oauth"; } @Override diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/TutByApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/TutByApi.java index 72d3e13fd..6928ba70a 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/TutByApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/TutByApi.java @@ -2,16 +2,11 @@ import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.model.OAuthConfig; -import com.github.scribejava.core.utils.OAuthEncoder; -import com.github.scribejava.core.utils.Preconditions; import com.github.scribejava.apis.service.TutByOAuthServiceImpl; import com.github.scribejava.core.oauth.OAuth20Service; public class TutByApi extends DefaultApi20 { - private static final String AUTHORIZE_URL - = "http://profile.tut.by/auth?client_id=%s&response_type=code&redirect_uri=%s"; - protected TutByApi() { } @@ -29,10 +24,8 @@ public String getAccessTokenEndpoint() { } @Override - public String getAuthorizationUrl(OAuthConfig config) { - Preconditions.checkValidUrl(config.getCallback(), - "Valid url is required for a callback. Tut.by does not support OOB"); - return String.format(AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback())); + protected String getAuthorizationBaseUrl() { + return "http://profile.tut.by/auth"; } @Override diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/ViadeoApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/ViadeoApi.java index 185d684af..e3143b5b4 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/ViadeoApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/ViadeoApi.java @@ -1,17 +1,10 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.Verb; -import com.github.scribejava.core.utils.OAuthEncoder; -import com.github.scribejava.core.utils.Preconditions; public class ViadeoApi extends DefaultApi20 { - private static final String AUTHORIZE_URL - = "https://secure.viadeo.com/oauth-provider/authorize2?client_id=%s&redirect_uri=%s&response_type=code"; - private static final String SCOPED_AUTHORIZE_URL = AUTHORIZE_URL + "&scope=%s"; - protected ViadeoApi() { } @@ -34,16 +27,7 @@ public String getAccessTokenEndpoint() { } @Override - public String getAuthorizationUrl(OAuthConfig config) { - Preconditions.checkValidUrl(config.getCallback(), - "Must provide a valid url as callback. Viadeo does not support OOB"); - - // Append scope if present - if (config.hasScope()) { - return String.format(SCOPED_AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()), - OAuthEncoder.encode(config.getScope())); - } else { - return String.format(AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback())); - } + protected String getAuthorizationBaseUrl() { + return "https://secure.viadeo.com/oauth-provider/authorize2"; } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/VkontakteApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/VkontakteApi.java index 5ee9a88fe..7d440d275 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/VkontakteApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/VkontakteApi.java @@ -1,17 +1,10 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.Verb; -import com.github.scribejava.core.utils.OAuthEncoder; -import com.github.scribejava.core.utils.Preconditions; public class VkontakteApi extends DefaultApi20 { - private static final String AUTHORIZE_URL - = "https://oauth.vk.com/authorize?client_id=%s&redirect_uri=%s&response_type=code"; - private static final String SCOPED_AUTHORIZE_URL = String.format("%s&scope=%%s", AUTHORIZE_URL); - protected VkontakteApi() { } @@ -34,14 +27,7 @@ public String getAccessTokenEndpoint() { } @Override - public String getAuthorizationUrl(OAuthConfig config) { - Preconditions.checkValidUrl(config.getCallback(), - "Valid url is required for a callback. Vkontakte does not support OOB"); - if (config.hasScope()) { // Appending scope if present - return String.format(SCOPED_AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()), - OAuthEncoder.encode(config.getScope())); - } else { - return String.format(AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback())); - } + protected String getAuthorizationBaseUrl() { + return "https://oauth.vk.com/authorize"; } } 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 de5f51f03..a6404043f 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 @@ -157,6 +157,7 @@ public ServiceBuilder debug() { public void checkPreconditions() { Preconditions.checkEmptyString(apiKey, "You must provide an api key"); } + private OAuthConfig createConfig() { checkPreconditions(); return new OAuthConfig(apiKey, apiSecret, callback, signatureType, scope, debugStream, state, responseType, diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java index 30095f134..480a7a34d 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java @@ -4,9 +4,10 @@ import com.github.scribejava.core.extractors.TokenExtractor; import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthConfig; +import com.github.scribejava.core.model.OAuthConstants; +import com.github.scribejava.core.model.ParameterList; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.oauth.OAuth20Service; -import com.github.scribejava.core.utils.OAuthEncoder; import java.util.Map; /** @@ -53,13 +54,7 @@ public String getRefreshTokenEndpoint() { return getAccessTokenEndpoint(); } - /** - * Returns the URL where you should redirect your users to authenticate your application. - * - * @param config OAuth 2.0 configuration param object - * @return the URL where you should redirect your users - */ - public abstract String getAuthorizationUrl(OAuthConfig config); + protected abstract String getAuthorizationBaseUrl(); /** * Returns the URL where you should redirect your users to authenticate your application. @@ -69,23 +64,26 @@ public String getRefreshTokenEndpoint() { * @return the URL where you should redirect your users */ public String getAuthorizationUrl(OAuthConfig config, Map additionalParams) { - String authUrl = getAuthorizationUrl(config); + final ParameterList parameters = new ParameterList(additionalParams); + parameters.add(OAuthConstants.RESPONSE_TYPE, config.getResponseType()); + parameters.add(OAuthConstants.CLIENT_ID, config.getApiKey()); - if (additionalParams != null && !additionalParams.isEmpty()) { - final StringBuilder authUrlWithParams = new StringBuilder(authUrl) - .append(authUrl.indexOf('?') == -1 ? '?' : '&'); + final String callback = config.getCallback(); + if (callback != null) { + parameters.add(OAuthConstants.REDIRECT_URI, callback); + } - for (Map.Entry param : additionalParams.entrySet()) { - authUrlWithParams.append(OAuthEncoder.encode(param.getKey())) - .append('=') - .append(OAuthEncoder.encode(param.getValue())) - .append('&'); - } + final String scope = config.getScope(); + if (scope != null) { + parameters.add(OAuthConstants.SCOPE, scope); + } - authUrl = authUrlWithParams.substring(0, authUrlWithParams.length() - 1); + final String state = config.getState(); + if (state != null) { + parameters.add(OAuthConstants.STATE, state); } - return authUrl; + return parameters.appendTo(getAuthorizationBaseUrl()); } @Override diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConfig.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConfig.java index aab9ac513..78358d2e3 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConfig.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConfig.java @@ -69,10 +69,6 @@ public String getScope() { return scope; } - public boolean hasScope() { - return scope != null; - } - public String getState() { return state; } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConstants.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConstants.java index d328e2242..2cf8d236a 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConstants.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConstants.java @@ -35,6 +35,8 @@ public interface OAuthConstants { String STATE = "state"; String USERNAME = "username"; String PASSWORD = "password"; + String RESPONSE_TYPE = "response_type"; + String RESPONSE_TYPE_CODE = "code"; //not OAuth specific String USER_AGENT_HEADER_NAME = "User-Agent"; diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/ParameterList.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/ParameterList.java index c04bca9cd..39d806652 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/ParameterList.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/ParameterList.java @@ -26,8 +26,10 @@ public ParameterList() { public ParameterList(Map map) { this(); - for (Map.Entry entry : map.entrySet()) { - params.add(new Parameter(entry.getKey(), entry.getValue())); + if (map != null && !map.isEmpty()) { + for (Map.Entry entry : map.entrySet()) { + params.add(new Parameter(entry.getKey(), entry.getValue())); + } } } @@ -41,9 +43,9 @@ public String appendTo(String url) { if (queryString.equals(EMPTY_STRING)) { return url; } else { - url += url.indexOf(QUERY_STRING_SEPARATOR) == -1 ? QUERY_STRING_SEPARATOR : PARAM_SEPARATOR; - url += queryString; - return url; + return url + + (url.indexOf(QUERY_STRING_SEPARATOR) == -1 ? QUERY_STRING_SEPARATOR : PARAM_SEPARATOR) + + queryString; } } @@ -58,9 +60,9 @@ public String asFormUrlEncodedString() { final StringBuilder builder = new StringBuilder(); for (Parameter p : params) { - builder.append('&').append(p.asUrlEncodedPair()); + builder.append(PARAM_SEPARATOR).append(p.asUrlEncodedPair()); } - return builder.toString().substring(1); + return builder.substring(1); } public void addAll(ParameterList other) { @@ -68,7 +70,7 @@ public void addAll(ParameterList other) { } public void addQuerystring(String queryString) { - if (queryString != null && queryString.length() > 0) { + if (queryString != null && !queryString.isEmpty()) { for (String param : queryString.split(PARAM_SEPARATOR)) { final String[] pair = param.split(PAIR_SEPARATOR); final String key = OAuthEncoder.decode(pair[0]); 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 c9c99a03f..f2516d8c2 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 @@ -67,8 +67,9 @@ private void addOAuthParams(AbstractRequest request, String tokenSecret) { request.addOAuthParameter(OAuthConstants.CONSUMER_KEY, config.getApiKey()); request.addOAuthParameter(OAuthConstants.SIGN_METHOD, api.getSignatureService().getSignatureMethod()); request.addOAuthParameter(OAuthConstants.VERSION, getVersion()); - if (config.hasScope()) { - request.addOAuthParameter(OAuthConstants.SCOPE, config.getScope()); + final String scope = config.getScope(); + if (scope != null) { + request.addOAuthParameter(OAuthConstants.SCOPE, scope); } request.addOAuthParameter(OAuthConstants.SIGNATURE, getSignature(request, tokenSecret)); diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java index 275a825b5..ef5494eac 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 @@ -84,8 +84,9 @@ protected T createAccessTokenRequest(String code, T request.addParameter(OAuthConstants.CLIENT_SECRET, config.getApiSecret()); request.addParameter(OAuthConstants.CODE, code); request.addParameter(OAuthConstants.REDIRECT_URI, config.getCallback()); - if (config.hasScope()) { - request.addParameter(OAuthConstants.SCOPE, config.getScope()); + final String scope = config.getScope(); + if (scope != null) { + request.addParameter(OAuthConstants.SCOPE, scope); } request.addParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.AUTHORIZATION_CODE); return request; @@ -164,19 +165,18 @@ protected T createAccessTokenPasswordGrantRequest(St request.addParameter(OAuthConstants.USERNAME, username); request.addParameter(OAuthConstants.PASSWORD, password); - if (config.hasScope()) { - request.addParameter(OAuthConstants.SCOPE, config.getScope()); + final String scope = config.getScope(); + if (scope != null) { + request.addParameter(OAuthConstants.SCOPE, scope); } request.addParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.PASSWORD); - request.addHeader(OAuthConstants.HEADER, OAuthConstants.BASIC + " " - + Base64Encoder.getInstance().encode( - String.format("%s:%s", config.getApiKey(), config.getApiSecret()).getBytes( - Charset.forName("UTF-8") - ) - ) - ); + request.addHeader(OAuthConstants.HEADER, + OAuthConstants.BASIC + ' ' + + Base64Encoder.getInstance() + .encode(String.format("%s:%s", config.getApiKey(), config.getApiSecret()) + .getBytes(Charset.forName("UTF-8")))); return request; } diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/builder/ServiceBuilderTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/builder/ServiceBuilderTest.java index 9bf8f386f..57f7d62e2 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/builder/ServiceBuilderTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/builder/ServiceBuilderTest.java @@ -90,7 +90,7 @@ public String getAccessTokenEndpoint() { } @Override - public String getAuthorizationUrl(OAuthConfig config) { + protected String getAuthorizationBaseUrl() { throw new UnsupportedOperationException("Not supported yet."); } } diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ApiUnit.java b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ApiUnit.java index 5d7391fb3..7b23203ac 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ApiUnit.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ApiUnit.java @@ -11,7 +11,7 @@ public String getAccessTokenEndpoint() { } @Override - public String getAuthorizationUrl(OAuthConfig config) { + protected String getAuthorizationBaseUrl() { return "http://localhost:8080/authorize"; } From a6e1cb9d3dd5c63a71e61a6e16bfad865a3172f3 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 23 May 2016 17:58:25 +0300 Subject: [PATCH 196/882] update Facebook to v2.6 --- changelog | 1 + .../main/java/com/github/scribejava/apis/FacebookApi.java | 6 +++--- .../scribejava/apis/examples/FacebookAsyncExample.java | 2 +- .../github/scribejava/apis/examples/FacebookExample.java | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/changelog b/changelog index 117278137..39853250c 100644 --- a/changelog +++ b/changelog @@ -5,6 +5,7 @@ * add Genius.com API authentication (OAuth2) * fix GitHub API * standardize authorization url generation for OAuth2 + * update Facebook to v2.6 [2.5.3] * fix - do not send two Content-Type header in async requests 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 ffccdd73d..9bf5abfc0 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 @@ -4,7 +4,7 @@ import com.github.scribejava.core.model.Verb; /** - * Facebook v2.5 API + * Facebook v2.6 API */ public class FacebookApi extends DefaultApi20 { @@ -27,7 +27,7 @@ public Verb getAccessTokenVerb() { @Override public String getAccessTokenEndpoint() { - return "https://graph.facebook.com/v2.5/oauth/access_token"; + return "https://graph.facebook.com/v2.6/oauth/access_token"; } @Override @@ -37,6 +37,6 @@ public String getRefreshTokenEndpoint() { @Override protected String getAuthorizationBaseUrl() { - return "https://www.facebook.com/v2.5/dialog/oauth"; + return "https://www.facebook.com/v2.6/dialog/oauth"; } } diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncExample.java index 3768394a7..65bee0cf9 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncExample.java @@ -17,7 +17,7 @@ public abstract class FacebookAsyncExample { private static final String NETWORK_NAME = "Facebook"; - private static final String PROTECTED_RESOURCE_URL = "https://graph.facebook.com/v2.5/me"; + private static final String PROTECTED_RESOURCE_URL = "https://graph.facebook.com/v2.6/me"; public static void main(String... args) throws InterruptedException, ExecutionException { // Replace these with your client id and secret diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java index 28740b43a..463729c17 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java @@ -13,7 +13,7 @@ public abstract class FacebookExample { private static final String NETWORK_NAME = "Facebook"; - private static final String PROTECTED_RESOURCE_URL = "https://graph.facebook.com/v2.5/me"; + private static final String PROTECTED_RESOURCE_URL = "https://graph.facebook.com/v2.6/me"; public static void main(String... args) { // Replace these with your client id and secret From b7001c219a75da37efc422d6909ca1707d945366 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 23 May 2016 18:32:34 +0300 Subject: [PATCH 197/882] cleanup: drop old APIs without exmaples --- changelog | 1 + .../scribejava/apis/ConstantContactApi.java | 36 --------- .../scribejava/apis/ConstantContactApi2.java | 36 --------- .../github/scribejava/apis/DropBoxApi.java | 34 -------- .../github/scribejava/apis/EvernoteApi.java | 81 ------------------- .../github/scribejava/apis/GetGlueApi.java | 38 --------- .../com/github/scribejava/apis/KaixinApi.java | 48 ----------- .../github/scribejava/apis/MendeleyApi.java | 49 ----------- .../com/github/scribejava/apis/MisoApi.java | 38 --------- .../github/scribejava/apis/NetProspexApi.java | 37 --------- .../com/github/scribejava/apis/PlurkApi.java | 58 ------------- .../com/github/scribejava/apis/QWeiboApi.java | 37 --------- .../com/github/scribejava/apis/SapoApi.java | 48 ----------- .../github/scribejava/apis/SimpleGeoApi.java | 35 -------- .../github/scribejava/apis/UbuntuOneApi.java | 43 ---------- .../com/github/scribejava/apis/VimeoApi.java | 35 -------- .../com/github/scribejava/apis/YammerApi.java | 42 ---------- .../ConstantContactTokenExtractor.java | 41 ---------- 18 files changed, 1 insertion(+), 736 deletions(-) delete mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/ConstantContactApi.java delete mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/ConstantContactApi2.java delete mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/DropBoxApi.java delete mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/EvernoteApi.java delete mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/GetGlueApi.java delete mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/KaixinApi.java delete mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/MendeleyApi.java delete mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/MisoApi.java delete mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/NetProspexApi.java delete mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/PlurkApi.java delete mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/QWeiboApi.java delete mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/SapoApi.java delete mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/SimpleGeoApi.java delete mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/UbuntuOneApi.java delete mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/VimeoApi.java delete mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/YammerApi.java delete mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/constantcontact/ConstantContactTokenExtractor.java diff --git a/changelog b/changelog index 39853250c..b2d8c8a00 100644 --- a/changelog +++ b/changelog @@ -6,6 +6,7 @@ * fix GitHub API * standardize authorization url generation for OAuth2 * update Facebook to v2.6 + * cleanup: drop old APIs without Examples [2.5.3] * fix - do not send two Content-Type header in async requests diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/ConstantContactApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/ConstantContactApi.java deleted file mode 100644 index a9f0e196c..000000000 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/ConstantContactApi.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.github.scribejava.apis; - -import com.github.scribejava.core.builder.api.DefaultApi10a; -import com.github.scribejava.core.model.OAuth1RequestToken; - -public class ConstantContactApi extends DefaultApi10a { - - private static final String AUTHORIZE_URL - = "https://oauth.constantcontact.com/ws/oauth/confirm_access?oauth_token=%s"; - - protected ConstantContactApi() { - } - - private static class InstanceHolder { - private static final ConstantContactApi INSTANCE = new ConstantContactApi(); - } - - public static ConstantContactApi instance() { - return InstanceHolder.INSTANCE; - } - - @Override - public String getAccessTokenEndpoint() { - return "https://oauth.constantcontact.com/ws/oauth/access_token"; - } - - @Override - public String getAuthorizationUrl(OAuth1RequestToken requestToken) { - return String.format(AUTHORIZE_URL, requestToken.getToken()); - } - - @Override - public String getRequestTokenEndpoint() { - return "https://oauth.constantcontact.com/ws/oauth/request_token"; - } -} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/ConstantContactApi2.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/ConstantContactApi2.java deleted file mode 100644 index 94cbde0c8..000000000 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/ConstantContactApi2.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.github.scribejava.apis; - -import com.github.scribejava.apis.constantcontact.ConstantContactTokenExtractor; - -import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.extractors.TokenExtractor; -import com.github.scribejava.core.model.OAuth2AccessToken; - -public class ConstantContactApi2 extends DefaultApi20 { - - protected ConstantContactApi2() { - } - - private static class InstanceHolder { - private static final ConstantContactApi2 INSTANCE = new ConstantContactApi2(); - } - - public static ConstantContactApi2 instance() { - return InstanceHolder.INSTANCE; - } - - @Override - public String getAccessTokenEndpoint() { - return "https://oauth2.constantcontact.com/oauth2/oauth/token"; - } - - @Override - protected String getAuthorizationBaseUrl() { - return "https://oauth2.constantcontact.com/oauth2/oauth/siteowner/authorize"; - } - - @Override - public TokenExtractor getAccessTokenExtractor() { - return ConstantContactTokenExtractor.instance(); - } -} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/DropBoxApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/DropBoxApi.java deleted file mode 100644 index 99ae6f874..000000000 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/DropBoxApi.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.github.scribejava.apis; - -import com.github.scribejava.core.builder.api.DefaultApi10a; -import com.github.scribejava.core.model.OAuth1RequestToken; - -public class DropBoxApi extends DefaultApi10a { - - protected DropBoxApi() { - } - - private static class InstanceHolder { - private static final DropBoxApi INSTANCE = new DropBoxApi(); - } - - public static DropBoxApi instance() { - return InstanceHolder.INSTANCE; - } - - @Override - public String getAccessTokenEndpoint() { - return "https://api.dropbox.com/1/oauth/access_token"; - } - - @Override - public String getAuthorizationUrl(OAuth1RequestToken requestToken) { - return "https://www.dropbox.com/1/oauth/authorize?oauth_token=" + requestToken.getToken(); - } - - @Override - public String getRequestTokenEndpoint() { - return "https://api.dropbox.com/1/oauth/request_token"; - } - -} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/EvernoteApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/EvernoteApi.java deleted file mode 100644 index 0bbd2ac62..000000000 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/EvernoteApi.java +++ /dev/null @@ -1,81 +0,0 @@ -package com.github.scribejava.apis; - -import com.github.scribejava.core.builder.api.DefaultApi10a; -import com.github.scribejava.core.model.OAuth1RequestToken; - -public class EvernoteApi extends DefaultApi10a { - - protected EvernoteApi() { - } - - private static class InstanceHolder { - private static final EvernoteApi INSTANCE = new EvernoteApi(); - } - - public static EvernoteApi instance() { - return InstanceHolder.INSTANCE; - } - - protected String serviceUrl() { - return "https://www.evernote.com"; - } - - @Override - public String getRequestTokenEndpoint() { - return serviceUrl() + "/oauth"; - } - - @Override - public String getAccessTokenEndpoint() { - return serviceUrl() + "/oauth"; - } - - @Override - public String getAuthorizationUrl(OAuth1RequestToken requestToken) { - return String.format(serviceUrl() + "/OAuth.action?oauth_token=%s", requestToken.getToken()); - } - - /** - * Sandbox endpoint - */ - public static class Sandbox extends EvernoteApi { - - private Sandbox() { - } - - private static class InstanceHolder { - private static final Sandbox INSTANCE = new Sandbox(); - } - - public static Sandbox instance() { - return InstanceHolder.INSTANCE; - } - - @Override - protected String serviceUrl() { - return "https://sandbox.evernote.com"; - } - } - - /** - * Yinxiang Biji endpoint - */ - public static class Yinxiang extends EvernoteApi { - - private Yinxiang() { - } - - private static class InstanceHolder { - private static final Yinxiang INSTANCE = new Yinxiang(); - } - - public static Yinxiang instance() { - return InstanceHolder.INSTANCE; - } - - @Override - protected String serviceUrl() { - return "https://app.yinxiang.com"; - } - } -} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/GetGlueApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/GetGlueApi.java deleted file mode 100644 index 758214390..000000000 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/GetGlueApi.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.github.scribejava.apis; - -import com.github.scribejava.core.builder.api.DefaultApi10a; -import com.github.scribejava.core.model.OAuth1RequestToken; - -public class GetGlueApi extends DefaultApi10a { - - private static final String AUTHORIZE_URL = "http://getglue.com/oauth/authorize?oauth_token=%s"; - private static final String REQUEST_TOKEN_RESOURCE = "https://api.getglue.com/oauth/request_token"; - private static final String ACCESS_TOKEN_RESOURCE = "https://api.getglue.com/oauth/access_token"; - - protected GetGlueApi() { - } - - private static class InstanceHolder { - private static final GetGlueApi INSTANCE = new GetGlueApi(); - } - - public static GetGlueApi instance() { - return InstanceHolder.INSTANCE; - } - - @Override - public String getAccessTokenEndpoint() { - return ACCESS_TOKEN_RESOURCE; - } - - @Override - public String getRequestTokenEndpoint() { - return REQUEST_TOKEN_RESOURCE; - } - - @Override - public String getAuthorizationUrl(OAuth1RequestToken requestToken) { - return String.format(AUTHORIZE_URL, requestToken.getToken()); - } - -} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/KaixinApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/KaixinApi.java deleted file mode 100644 index e5698bdb6..000000000 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/KaixinApi.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.github.scribejava.apis; - -import com.github.scribejava.core.builder.api.DefaultApi10a; -import com.github.scribejava.core.model.OAuth1RequestToken; -import com.github.scribejava.core.model.Verb; - -public class KaixinApi extends DefaultApi10a { - - private static final String REQUEST_TOKEN_URL = "http://api.kaixin001.com/oauth/request_token"; - private static final String ACCESS_TOKEN_URL = "http://api.kaixin001.com/oauth/access_token"; - private static final String AUTHORIZE_URL = "http://api.kaixin001.com/oauth/authorize?oauth_token=%s"; - - protected KaixinApi() { - } - - private static class InstanceHolder { - private static final KaixinApi INSTANCE = new KaixinApi(); - } - - public static KaixinApi instance() { - return InstanceHolder.INSTANCE; - } - - @Override - public String getRequestTokenEndpoint() { - return REQUEST_TOKEN_URL; - } - - @Override - public String getAccessTokenEndpoint() { - return ACCESS_TOKEN_URL; - } - - @Override - public String getAuthorizationUrl(OAuth1RequestToken requestToken) { - return String.format(AUTHORIZE_URL, requestToken.getToken()); - } - - @Override - public Verb getRequestTokenVerb() { - return Verb.GET; - } - - @Override - public Verb getAccessTokenVerb() { - return Verb.GET; - } -} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/MendeleyApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/MendeleyApi.java deleted file mode 100644 index 9fab6e2ff..000000000 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/MendeleyApi.java +++ /dev/null @@ -1,49 +0,0 @@ -package com.github.scribejava.apis; - -import com.github.scribejava.core.builder.api.DefaultApi10a; -import com.github.scribejava.core.model.OAuth1RequestToken; -import com.github.scribejava.core.model.Verb; - -/** - * @see http://apidocs.mendeley.com/home/authentication - */ -public class MendeleyApi extends DefaultApi10a { - - private static final String AUTHORIZATION_URL = "http://api.mendeley.com/oauth/authorize?oauth_token=%s"; - - protected MendeleyApi() { - } - - private static class InstanceHolder { - private static final MendeleyApi INSTANCE = new MendeleyApi(); - } - - public static MendeleyApi instance() { - return InstanceHolder.INSTANCE; - } - - @Override - public String getRequestTokenEndpoint() { - return "http://api.mendeley.com/oauth/request_token/"; - } - - @Override - public String getAccessTokenEndpoint() { - return "http://api.mendeley.com/oauth/access_token/"; - } - - @Override - public String getAuthorizationUrl(OAuth1RequestToken requestToken) { - return String.format(AUTHORIZATION_URL, requestToken.getToken()); - } - - @Override - public Verb getAccessTokenVerb() { - return Verb.GET; - } - - @Override - public Verb getRequestTokenVerb() { - return Verb.GET; - } -} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/MisoApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/MisoApi.java deleted file mode 100644 index 4f0bb3bea..000000000 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/MisoApi.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.github.scribejava.apis; - -import com.github.scribejava.core.builder.api.DefaultApi10a; -import com.github.scribejava.core.model.OAuth1RequestToken; - -public class MisoApi extends DefaultApi10a { - - private static final String AUTHORIZE_URL = "http://gomiso.com/oauth/authorize?oauth_token=%s"; - private static final String REQUEST_TOKEN_RESOURCE = "http://gomiso.com/oauth/request_token"; - private static final String ACCESS_TOKEN_RESOURCE = "http://gomiso.com/oauth/access_token"; - - protected MisoApi() { - } - - private static class InstanceHolder { - private static final MisoApi INSTANCE = new MisoApi(); - } - - public static MisoApi instance() { - return InstanceHolder.INSTANCE; - } - - @Override - public String getAccessTokenEndpoint() { - return ACCESS_TOKEN_RESOURCE; - } - - @Override - public String getRequestTokenEndpoint() { - return REQUEST_TOKEN_RESOURCE; - } - - @Override - public String getAuthorizationUrl(OAuth1RequestToken requestToken) { - return String.format(AUTHORIZE_URL, requestToken.getToken()); - } - -} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/NetProspexApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/NetProspexApi.java deleted file mode 100644 index aa08abc4a..000000000 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/NetProspexApi.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.github.scribejava.apis; - -import com.github.scribejava.core.builder.api.DefaultApi10a; -import com.github.scribejava.core.model.OAuth1RequestToken; - -public class NetProspexApi extends DefaultApi10a { - - private static final String REQUEST_TOKEN_URL = "https://api.netprospex.com/1.0/oauth/request-token"; - private static final String ACCESS_TOKEN_URL = "https://api.netprospex.com/1.0/oauth/access-token"; - private static final String AUTHORIZE_URL = "https://api.netprospex.com/1.0/oauth/authorize?oauth_token=%s"; - - protected NetProspexApi() { - } - - private static class InstanceHolder { - private static final NetProspexApi INSTANCE = new NetProspexApi(); - } - - public static NetProspexApi instance() { - return InstanceHolder.INSTANCE; - } - - @Override - public String getRequestTokenEndpoint() { - return REQUEST_TOKEN_URL; - } - - @Override - public String getAccessTokenEndpoint() { - return ACCESS_TOKEN_URL; - } - - @Override - public String getAuthorizationUrl(OAuth1RequestToken requestToken) { - return String.format(AUTHORIZE_URL, requestToken.getToken()); - } -} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/PlurkApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/PlurkApi.java deleted file mode 100644 index f2b9c5ed2..000000000 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/PlurkApi.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.github.scribejava.apis; - -import com.github.scribejava.core.builder.api.DefaultApi10a; -import com.github.scribejava.core.model.OAuth1RequestToken; - -public class PlurkApi extends DefaultApi10a { - - private static final String REQUEST_TOKEN_URL = "http://www.plurk.com/OAuth/request_token"; - private static final String AUTHORIZATION_URL = "http://www.plurk.com/OAuth/authorize?oauth_token=%s"; - private static final String ACCESS_TOKEN_URL = "http://www.plurk.com/OAuth/access_token"; - - protected PlurkApi() { - } - - private static class InstanceHolder { - private static final PlurkApi INSTANCE = new PlurkApi(); - } - - public static PlurkApi instance() { - return InstanceHolder.INSTANCE; - } - - @Override - public String getRequestTokenEndpoint() { - return REQUEST_TOKEN_URL; - } - - @Override - public String getAuthorizationUrl(OAuth1RequestToken requestToken) { - return String.format(AUTHORIZATION_URL, requestToken.getToken()); - } - - @Override - public String getAccessTokenEndpoint() { - return ACCESS_TOKEN_URL; - } - - public static class Mobile extends PlurkApi { - - private static final String AUTHORIZATION_URL = "http://www.plurk.com/m/authorize?oauth_token=%s"; - - private Mobile() { - } - - private static class InstanceHolder { - private static final Mobile INSTANCE = new Mobile(); - } - - public static Mobile instance() { - return InstanceHolder.INSTANCE; - } - - @Override - public String getAuthorizationUrl(OAuth1RequestToken requestToken) { - return String.format(AUTHORIZATION_URL, requestToken.getToken()); - } - } -} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/QWeiboApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/QWeiboApi.java deleted file mode 100644 index ed4bfdb6b..000000000 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/QWeiboApi.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.github.scribejava.apis; - -import com.github.scribejava.core.builder.api.DefaultApi10a; -import com.github.scribejava.core.model.OAuth1RequestToken; - -public class QWeiboApi extends DefaultApi10a { - - private static final String REQUEST_TOKEN_URL = "https://open.t.qq.com/cgi-bin/request_token"; - private static final String ACCESS_TOKEN_URL = "https://open.t.qq.com/cgi-bin/access_token"; - private static final String AUTHORIZE_URL = "https://open.t.qq.com/cgi-bin/authorize?oauth_token=%s"; - - protected QWeiboApi() { - } - - private static class InstanceHolder { - private static final QWeiboApi INSTANCE = new QWeiboApi(); - } - - public static QWeiboApi instance() { - return InstanceHolder.INSTANCE; - } - - @Override - public String getRequestTokenEndpoint() { - return REQUEST_TOKEN_URL; - } - - @Override - public String getAccessTokenEndpoint() { - return ACCESS_TOKEN_URL; - } - - @Override - public String getAuthorizationUrl(OAuth1RequestToken requestToken) { - return String.format(AUTHORIZE_URL, requestToken.getToken()); - } -} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/SapoApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/SapoApi.java deleted file mode 100644 index 524ddfcf7..000000000 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/SapoApi.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.github.scribejava.apis; - -import com.github.scribejava.core.builder.api.DefaultApi10a; -import com.github.scribejava.core.model.OAuth1RequestToken; -import com.github.scribejava.core.model.Verb; - -public class SapoApi extends DefaultApi10a { - - private static final String AUTHORIZE_URL = "https://id.sapo.pt/oauth/authorize?oauth_token=%s"; - private static final String ACCESS_URL = "https://id.sapo.pt/oauth/access_token"; - private static final String REQUEST_URL = "https://id.sapo.pt/oauth/request_token"; - - protected SapoApi() { - } - - private static class InstanceHolder { - private static final SapoApi INSTANCE = new SapoApi(); - } - - public static SapoApi instance() { - return InstanceHolder.INSTANCE; - } - - @Override - public String getAccessTokenEndpoint() { - return ACCESS_URL; - } - - @Override - public String getRequestTokenEndpoint() { - return REQUEST_URL; - } - - @Override - public String getAuthorizationUrl(OAuth1RequestToken requestToken) { - return String.format(AUTHORIZE_URL, requestToken.getToken()); - } - - @Override - public Verb getRequestTokenVerb() { - return Verb.GET; - } - - @Override - public Verb getAccessTokenVerb() { - return Verb.GET; - } -} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/SimpleGeoApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/SimpleGeoApi.java deleted file mode 100644 index c8264b19b..000000000 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/SimpleGeoApi.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.github.scribejava.apis; - -import com.github.scribejava.core.builder.api.DefaultApi10a; -import com.github.scribejava.core.model.OAuth1RequestToken; - -public class SimpleGeoApi extends DefaultApi10a { - - private static final String ENDPOINT = "these are not used since SimpleGeo uses 2 legged OAuth"; - - protected SimpleGeoApi() { - } - - private static class InstanceHolder { - private static final SimpleGeoApi INSTANCE = new SimpleGeoApi(); - } - - public static SimpleGeoApi instance() { - return InstanceHolder.INSTANCE; - } - - @Override - public String getRequestTokenEndpoint() { - return ENDPOINT; - } - - @Override - public String getAccessTokenEndpoint() { - return ENDPOINT; - } - - @Override - public String getAuthorizationUrl(OAuth1RequestToken requestToken) { - return ENDPOINT; - } -} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/UbuntuOneApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/UbuntuOneApi.java deleted file mode 100644 index 867b7556a..000000000 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/UbuntuOneApi.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.github.scribejava.apis; - -import com.github.scribejava.core.builder.api.DefaultApi10a; -import com.github.scribejava.core.model.OAuth1RequestToken; -import com.github.scribejava.core.services.PlaintextSignatureService; -import com.github.scribejava.core.services.SignatureService; - -public class UbuntuOneApi extends DefaultApi10a { - - private static final String AUTHORIZATION_URL = "https://one.ubuntu.com/oauth/authorize/?oauth_token=%s"; - - protected UbuntuOneApi() { - } - - private static class InstanceHolder { - private static final UbuntuOneApi INSTANCE = new UbuntuOneApi(); - } - - public static UbuntuOneApi instance() { - return InstanceHolder.INSTANCE; - } - - @Override - public String getAccessTokenEndpoint() { - return "https://one.ubuntu.com/oauth/access/"; - } - - @Override - public String getAuthorizationUrl(OAuth1RequestToken requestToken) { - return String.format(AUTHORIZATION_URL, requestToken.getToken()); - } - - @Override - public String getRequestTokenEndpoint() { - return "https://one.ubuntu.com/oauth/request/"; - } - - @Override - public SignatureService getSignatureService() { - return new PlaintextSignatureService(); - } - -} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/VimeoApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/VimeoApi.java deleted file mode 100644 index 63ecb844d..000000000 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/VimeoApi.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.github.scribejava.apis; - -import com.github.scribejava.core.builder.api.DefaultApi10a; -import com.github.scribejava.core.model.OAuth1RequestToken; - -public class VimeoApi extends DefaultApi10a { - - private static final String AUTHORIZATION_URL = "http://vimeo.com/oauth/authorize?oauth_token=%s"; - - protected VimeoApi() { - } - - private static class InstanceHolder { - private static final VimeoApi INSTANCE = new VimeoApi(); - } - - public static VimeoApi instance() { - return InstanceHolder.INSTANCE; - } - - @Override - public String getAccessTokenEndpoint() { - return "http://vimeo.com/oauth/access_token"; - } - - @Override - public String getRequestTokenEndpoint() { - return "http://vimeo.com/oauth/request_token"; - } - - @Override - public String getAuthorizationUrl(OAuth1RequestToken requestToken) { - return String.format(AUTHORIZATION_URL, requestToken.getToken()); - } -} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/YammerApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/YammerApi.java deleted file mode 100644 index 269e61395..000000000 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/YammerApi.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.github.scribejava.apis; - -import com.github.scribejava.core.builder.api.DefaultApi10a; -import com.github.scribejava.core.model.OAuth1RequestToken; -import com.github.scribejava.core.services.PlaintextSignatureService; -import com.github.scribejava.core.services.SignatureService; - -public class YammerApi extends DefaultApi10a { - - private static final String AUTHORIZATION_URL = "https://www.yammer.com/oauth/authorize?oauth_token=%s"; - - protected YammerApi() { - } - - private static class InstanceHolder { - private static final YammerApi INSTANCE = new YammerApi(); - } - - public static YammerApi instance() { - return InstanceHolder.INSTANCE; - } - - @Override - public String getRequestTokenEndpoint() { - return "https://www.yammer.com/oauth/request_token"; - } - - @Override - public String getAccessTokenEndpoint() { - return "https://www.yammer.com/oauth/access_token"; - } - - @Override - public String getAuthorizationUrl(OAuth1RequestToken requestToken) { - return String.format(AUTHORIZATION_URL, requestToken.getToken()); - } - - @Override - public SignatureService getSignatureService() { - return new PlaintextSignatureService(); - } -} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/constantcontact/ConstantContactTokenExtractor.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/constantcontact/ConstantContactTokenExtractor.java deleted file mode 100644 index f385eba1d..000000000 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/constantcontact/ConstantContactTokenExtractor.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.github.scribejava.apis.constantcontact; - -import com.github.scribejava.core.exceptions.OAuthException; -import com.github.scribejava.core.extractors.TokenExtractor; -import com.github.scribejava.core.model.OAuth2AccessToken; -import com.github.scribejava.core.utils.OAuthEncoder; -import com.github.scribejava.core.utils.Preconditions; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -public class ConstantContactTokenExtractor implements TokenExtractor { - - private static final String REGEXP = "\"access_token\"\\s*:\\s*\"([^&\"]+)\""; - - protected ConstantContactTokenExtractor() { - } - - private static class InstanceHolder { - - private static final ConstantContactTokenExtractor INSTANCE = new ConstantContactTokenExtractor(); - } - - public static ConstantContactTokenExtractor instance() { - return InstanceHolder.INSTANCE; - } - - @Override - public OAuth2AccessToken extract(String response) { - Preconditions.checkEmptyString(response, - "Response body is incorrect. Can't extract a token from an empty string"); - - final Matcher matcher = Pattern.compile(REGEXP).matcher(response); - if (matcher.find()) { - final String token = OAuthEncoder.decode(matcher.group(1)); - return new OAuth2AccessToken(token, response); - } else { - throw new OAuthException("Response body is incorrect. Can't extract a token from this: '" - + response + "'", null); - } - } -} From 1e21fd1e6ccca1f0cf4af7177bacc223a31d9eec Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 23 May 2016 18:51:23 +0300 Subject: [PATCH 198/882] remove old APIs with outdated domains --- changelog | 2 +- .../github/scribejava/apis/LoveFilmApi.java | 37 ---------- .../apis/examples/LoveFilmExample.java | 70 ------------------- 3 files changed, 1 insertion(+), 108 deletions(-) delete mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/LoveFilmApi.java delete mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LoveFilmExample.java diff --git a/changelog b/changelog index b2d8c8a00..7a7c8540b 100644 --- a/changelog +++ b/changelog @@ -6,7 +6,7 @@ * fix GitHub API * standardize authorization url generation for OAuth2 * update Facebook to v2.6 - * cleanup: drop old APIs without Examples + * cleanup: drop old APIs without Examples and with outdated domains [2.5.3] * fix - do not send two Content-Type header in async requests diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/LoveFilmApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/LoveFilmApi.java deleted file mode 100644 index 3c43ac309..000000000 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/LoveFilmApi.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.github.scribejava.apis; - -import com.github.scribejava.core.builder.api.DefaultApi10a; -import com.github.scribejava.core.model.OAuth1RequestToken; - -public class LoveFilmApi extends DefaultApi10a { - - private static final String REQUEST_TOKEN_URL = "http://openapi.lovefilm.com/oauth/request_token"; - private static final String ACCESS_TOKEN_URL = "http://openapi.lovefilm.com/oauth/access_token"; - private static final String AUTHORIZE_URL = "https://www.lovefilm.com/activate?oauth_token=%s"; - - protected LoveFilmApi() { - } - - private static class InstanceHolder { - private static final LoveFilmApi INSTANCE = new LoveFilmApi(); - } - - public static LoveFilmApi instance() { - return InstanceHolder.INSTANCE; - } - - @Override - public String getRequestTokenEndpoint() { - return REQUEST_TOKEN_URL; - } - - @Override - public String getAccessTokenEndpoint() { - return ACCESS_TOKEN_URL; - } - - @Override - public String getAuthorizationUrl(OAuth1RequestToken requestToken) { - return String.format(AUTHORIZE_URL, requestToken.getToken()); - } -} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LoveFilmExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LoveFilmExample.java deleted file mode 100644 index 161278ad5..000000000 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LoveFilmExample.java +++ /dev/null @@ -1,70 +0,0 @@ -package com.github.scribejava.apis.examples; - -import java.util.Scanner; -import com.github.scribejava.core.builder.ServiceBuilder; -import com.github.scribejava.apis.LoveFilmApi; -import com.github.scribejava.core.model.OAuth1AccessToken; -import com.github.scribejava.core.model.OAuth1RequestToken; -import com.github.scribejava.core.model.OAuthRequest; -import com.github.scribejava.core.model.Response; -import com.github.scribejava.core.model.Verb; -import com.github.scribejava.core.oauth.OAuth10aService; - -public abstract class LoveFilmExample { - - private static final String NETWORK_NAME = "LoveFilm"; - private static final String PROTECTED_RESOURCE_URL = "https://api.lovefilm.com/users"; - - public static void main(String... args) { - // Replace these with your own api key and secret - final String apiKey = "your_key"; - final String apiSecret = "your_secret"; - final OAuth10aService service = new ServiceBuilder() - .apiKey(apiKey) - .apiSecret(apiSecret) - .build(LoveFilmApi.instance()); - final Scanner in = new Scanner(System.in); - - System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); - System.out.println(); - - // Grab a request token. - System.out.println("Fetching request token."); - final OAuth1RequestToken requestToken = service.getRequestToken(); - System.out.println("Got it ... "); - System.out.println(requestToken.getToken()); - - // Obtain the Authorization URL - System.out.println("Fetching the Authorization URL..."); - final String authorizationUrl = service.getAuthorizationUrl(requestToken); - System.out.println("Got the Authorization URL!"); - System.out.println("Now go and authorize ScribeJava here:"); - System.out.println(authorizationUrl); - System.out.println("And paste the authorization code here"); - System.out.print(">>"); - final String oauthVerifier = in.nextLine(); - System.out.println(); - - // Trade the Request Token and Verfier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); - final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); - System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); - System.out.println(); - - // Now let's go and ask for a protected resource! - System.out.println("Now we're going to access a protected resource..."); - final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service); - service.signRequest(accessToken, request); - final Response response = request.send(); - 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 b279cf6d0bdd2c7d66be03cb220484650c01c696 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 23 May 2016 19:07:37 +0300 Subject: [PATCH 199/882] update list of APIs in the Readme (on the main github page) --- README.md | 64 ++++++++++++++++++++++++++++++------------------------- 1 file changed, 35 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index 8f2bb934a..59121b5ad 100644 --- a/README.md +++ b/README.md @@ -25,35 +25,41 @@ You can use ning async http client out-of-box, just use ServiceBuilderAsync ### Supports all major 1.0a and 2.0 OAuth APIs out-of-the-box -* Google - -* Facebook - -* Yahoo - -* LinkedIn - -* Twitter - -* Foursquare - -* Evernote - -* Vimeo - -* Windows Live - -* Odnoklassniki - -* Mail.ru - -* LinkedIn2.0 - -* Google2.0 - -* GitHub - -* and many more! check the [examples folder](https://github.com/scribejava/scribejava/tree/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples) +* AWeber (http://www.aweber.com/) +* Digg (http://digg.com/) +* Доктор на работе (http://www.doktornarabote.ru/) +* Facebook (https://www.facebook.com/) +* Flickr (https://www.flickr.com/) +* Foursquare (https://foursquare.com/) +* Freelancer (https://www.freelancer.com/) +* Genius (http://genius.com/) +* GitHub (https://github.com/) +* Google (https://www.google.ru/) +* HeadHunter ХэдХантер (https://hh.ru/) +* Imgur (http://imgur.com/) +* Kaixin 开心网 (http://www.kaixin001.com/) +* LinkedIn (https://www.linkedin.com/) +* Microsoft Live (https://login.live.com/) +* Mail.Ru (https://mail.ru/) +* Meetup (http://www.meetup.com/) +* NetEase (http://www.163.com/) +* Odnoklassniki Одноклассники (http://ok.ru/) +* Pinterest (https://www.pinterest.com/) +* 500px (https://500px.com/) +* Renren (http://renren.com/) +* Sina (http://www.sina.com.cn/ http://weibo.com/login.php) +* Skyrock (http://skyrock.com/) +* sohu 搜狐 (http://www.sohu.com/) +* StackExchange (http://stackexchange.com/) +* Trello (https://trello.com/) +* Tumblr (https://www.tumblr.com/) +* TUT.BY (http://www.tut.by/) +* Twitter (https://twitter.com/) +* Viadeo (http://viadeo.com/) +* VK ВКонтакте (http://vk.com/) +* XING (https://www.xing.com/) +* Yahoo (https://www.yahoo.com/) +* check the [examples folder](https://github.com/scribejava/scribejava/tree/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples) ### Small and modular From abc4b5bc554fc8ede2fd2dfcc8441d5cbeb78d65 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 23 May 2016 19:29:55 +0300 Subject: [PATCH 200/882] send client credentials in grant_type=password optionally (in case they were issued and are not nulls) --- .../scribejava/core/oauth/OAuth20Service.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 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 ef5494eac..3813d28ba 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 @@ -172,11 +172,14 @@ protected T createAccessTokenPasswordGrantRequest(St request.addParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.PASSWORD); - request.addHeader(OAuthConstants.HEADER, - OAuthConstants.BASIC + ' ' - + Base64Encoder.getInstance() - .encode(String.format("%s:%s", config.getApiKey(), config.getApiSecret()) - .getBytes(Charset.forName("UTF-8")))); + final String apiKey = config.getApiKey(); + final String apiSecret = config.getApiSecret(); + if (apiKey != null && apiSecret != null) { + request.addHeader(OAuthConstants.HEADER, + OAuthConstants.BASIC + ' ' + + Base64Encoder.getInstance() + .encode(String.format("%s:%s", apiKey, apiSecret).getBytes(Charset.forName("UTF-8")))); + } return request; } From ceb06d1491b63b2d150f06e613e26d4960b62d5c Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 23 May 2016 19:41:48 +0300 Subject: [PATCH 201/882] prepare 2.6.0 release --- README.md | 4 ++-- changelog | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 59121b5ad..031c4dd53 100644 --- a/README.md +++ b/README.md @@ -84,7 +84,7 @@ You can pull ScribeJava from the central maven repository, just add these to you com.github.scribejava scribejava-apis - 2.5.3 + 2.6.0 ``` @@ -93,7 +93,7 @@ And in case you need just core classes (that's it, without any external API (FB, com.github.scribejava scribejava-core - 2.5.3 + 2.6.0 ``` diff --git a/changelog b/changelog index 7a7c8540b..0540b4dd9 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,4 @@ -[SNAPSHOT] +[2.6.0] * simplify async/sync usages * add optional "User-Agent" config option to use while making http calls * refactor usage of grant_type [authorization_code|refresh_token|password|etc] From 3ca5c9f2df3c89d8eaefb8d0fc22b147f8eaec98 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 23 May 2016 19:42:41 +0300 Subject: [PATCH 202/882] [maven-release-plugin] prepare release scribejava-2.6.0 --- pom.xml | 2 +- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 83388dab5..c1d553280 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 2.5.4-SNAPSHOT + 2.6.0 ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 958bf5563..a9da5b88e 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 2.5.4-SNAPSHOT + 2.6.0 ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 50f5e9fc0..c9a743078 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 2.5.4-SNAPSHOT + 2.6.0 ../pom.xml From 9a83b6cfeb7f2245a10ac579563c73c2c4024f7d Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 23 May 2016 19:42:46 +0300 Subject: [PATCH 203/882] [maven-release-plugin] prepare for next development iteration --- pom.xml | 2 +- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index c1d553280..a5a66b89f 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 2.6.0 + 2.6.1-SNAPSHOT ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index a9da5b88e..6a8f03dfc 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 2.6.0 + 2.6.1-SNAPSHOT ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index c9a743078..b4a2894c9 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 2.6.0 + 2.6.1-SNAPSHOT ../pom.xml From 010b37a4e0f3f3b8e8207a110b879943e6096694 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 25 May 2016 16:55:18 +0300 Subject: [PATCH 204/882] make http async client implementation be more pluggable --- changelog | 3 + .../ning/OAuthAsyncCompletionHandler.java | 52 ++++++++++ .../core/model/AbstractRequest.java | 2 +- .../core/model/OAuthRequestAsync.java | 96 +------------------ .../core/oauth/OAuth10aService.java | 13 +-- .../scribejava/core/oauth/OAuth20Service.java | 32 ++----- .../scribejava/core/oauth/OAuthService.java | 43 ++++++++- .../core/oauth/OAuth20ServiceUnit.java | 3 +- 8 files changed, 110 insertions(+), 134 deletions(-) create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/async/ning/OAuthAsyncCompletionHandler.java diff --git a/changelog b/changelog index 0540b4dd9..6d1d5fea4 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,6 @@ +[SNAPSHOT] + * make http async client implementation be more pluggable + [2.6.0] * simplify async/sync usages * add optional "User-Agent" config option to use while making http calls diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/async/ning/OAuthAsyncCompletionHandler.java b/scribejava-core/src/main/java/com/github/scribejava/core/async/ning/OAuthAsyncCompletionHandler.java new file mode 100644 index 000000000..adbcf10bb --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/async/ning/OAuthAsyncCompletionHandler.java @@ -0,0 +1,52 @@ +package com.github.scribejava.core.async.ning; + +import com.github.scribejava.core.model.OAuthAsyncRequestCallback; +import com.github.scribejava.core.model.OAuthRequestAsync; +import com.github.scribejava.core.model.Response; +import com.ning.http.client.AsyncCompletionHandler; +import com.ning.http.client.FluentCaseInsensitiveStringsMap; +import java.io.IOException; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class OAuthAsyncCompletionHandler extends AsyncCompletionHandler { + + private final OAuthAsyncRequestCallback callback; + private final OAuthRequestAsync.ResponseConverter converter; + + public OAuthAsyncCompletionHandler(OAuthAsyncRequestCallback callback, + OAuthRequestAsync.ResponseConverter converter) { + this.callback = callback; + this.converter = converter; + } + + @Override + public T onCompleted(com.ning.http.client.Response ningResponse) throws IOException { + final FluentCaseInsensitiveStringsMap map = ningResponse.getHeaders(); + final Map headersMap = new HashMap<>(); + for (FluentCaseInsensitiveStringsMap.Entry> header : map) { + final StringBuilder value = new StringBuilder(); + for (String str : header.getValue()) { + value.append(str); + } + headersMap.put(header.getKey(), value.toString()); + } + final Response response = new Response(ningResponse.getStatusCode(), ningResponse.getStatusText(), headersMap, + ningResponse.getResponseBody(), ningResponse.getResponseBodyAsStream()); + + @SuppressWarnings("unchecked") + final T t = converter == null ? (T) response : converter.convert(response); + if (callback != null) { + callback.onCompleted(t); + } + return t; + } + + @Override + public void onThrowable(Throwable t) { + if (callback != null) { + callback.onThrowable(t); + } + } +}; diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/AbstractRequest.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/AbstractRequest.java index c48f83c74..4db6ccec7 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/AbstractRequest.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/AbstractRequest.java @@ -15,8 +15,8 @@ public abstract class AbstractRequest { public static final String DEFAULT_CONTENT_TYPE = "application/x-www-form-urlencoded"; + public static final String CONTENT_TYPE = "Content-Type"; protected static final String CONTENT_LENGTH = "Content-Length"; - protected static final String CONTENT_TYPE = "Content-Type"; private static final String OAUTH_PREFIX = "oauth_"; private final String url; diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequestAsync.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequestAsync.java index fc422e8e6..1a92f0699 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequestAsync.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequestAsync.java @@ -2,46 +2,17 @@ import com.github.scribejava.core.exceptions.OAuthException; import com.github.scribejava.core.oauth.OAuthService; -import com.ning.http.client.AsyncCompletionHandler; -import com.ning.http.client.AsyncHttpClient; -import com.ning.http.client.FluentCaseInsensitiveStringsMap; -import com.ning.http.client.ProxyServer; import java.io.IOException; -import java.util.HashMap; -import java.util.List; -import java.util.Map; import java.util.concurrent.Future; public class OAuthRequestAsync extends AbstractRequest { - public static final ResponseConverter RESPONSE_CONVERTER = new ResponseConverter() { - @Override - public Response convert(com.ning.http.client.Response response) throws IOException { - final FluentCaseInsensitiveStringsMap map = response.getHeaders(); - final Map headersMap = new HashMap<>(); - for (FluentCaseInsensitiveStringsMap.Entry> header : map) { - final StringBuilder value = new StringBuilder(); - for (String str : header.getValue()) { - value.append(str); - } - headersMap.put(header.getKey(), value.toString()); - } - return new Response(response.getStatusCode(), response.getStatusText(), headersMap, - response.getResponseBody(), response.getResponseBodyAsStream()); - } - }; - public OAuthRequestAsync(Verb verb, String url, OAuthService service) { super(verb, url, service); } public Future sendAsync(OAuthAsyncRequestCallback callback, ResponseConverter converter) { - return sendAsync(callback, converter, null); - } - - public Future sendAsync(OAuthAsyncRequestCallback callback, ResponseConverter converter, - ProxyServer proxyServer) { final ForceTypeOfHttpRequest forceTypeOfHttpRequest = ScribeJavaConfig.getForceTypeOfHttpRequests(); if (ForceTypeOfHttpRequest.FORCE_SYNC_ONLY_HTTP_REQUESTS == forceTypeOfHttpRequest) { throw new OAuthException("Cannot use async operations, only sync"); @@ -51,76 +22,15 @@ public Future sendAsync(OAuthAsyncRequestCallback callback, ResponseCo if (ForceTypeOfHttpRequest.PREFER_SYNC_ONLY_HTTP_REQUESTS == forceTypeOfHttpRequest) { config.log("Cannot use async operations, only sync"); } - final String completeUrl = getCompleteUrl(); - final AsyncHttpClient.BoundRequestBuilder boundRequestBuilder; - final AsyncHttpClient asyncHttpClient = service.getAsyncHttpClient(); - final Map headers = getHeaders(); - switch (getVerb()) { - case GET: - boundRequestBuilder = asyncHttpClient.prepareGet(completeUrl); - break; - case POST: - AsyncHttpClient.BoundRequestBuilder requestBuilder = asyncHttpClient.preparePost(completeUrl); - if (!headers.containsKey(CONTENT_TYPE)) { - requestBuilder = requestBuilder.addHeader(CONTENT_TYPE, DEFAULT_CONTENT_TYPE); - } - boundRequestBuilder = requestBuilder.setBody(getBodyContents()); - break; - default: - throw new IllegalArgumentException("message build error: unknown verb type"); - } - - for (Map.Entry header : headers.entrySet()) { - boundRequestBuilder.addHeader(header.getKey(), header.getValue()); - } - final String userAgent = config.getUserAgent(); - if (userAgent != null) { - boundRequestBuilder.setHeader(OAuthConstants.USER_AGENT_HEADER_NAME, userAgent); - } - - if (proxyServer != null) { - boundRequestBuilder.setProxyServer(proxyServer); - } - return boundRequestBuilder.execute(new OAuthAsyncCompletionHandler<>(callback, converter)); + return service.executeAsync(getHeaders(), getVerb(), getCompleteUrl(), getBodyContents(), callback, converter); } - private static class OAuthAsyncCompletionHandler extends AsyncCompletionHandler { - - private final OAuthAsyncRequestCallback callback; - private final ResponseConverter converter; - - OAuthAsyncCompletionHandler(OAuthAsyncRequestCallback callback, ResponseConverter converter) { - this.callback = callback; - this.converter = converter; - } - - @Override - public T onCompleted(com.ning.http.client.Response response) throws IOException { - final T t = converter.convert(response); - if (callback != null) { - callback.onCompleted(t); - } - return t; - } - - @Override - public void onThrowable(Throwable t) { - if (callback != null) { - callback.onThrowable(t); - } - } - }; - public Future sendAsync(OAuthAsyncRequestCallback callback) { - return sendAsync(callback, RESPONSE_CONVERTER, null); - } - - public Future sendAsync(OAuthAsyncRequestCallback callback, ProxyServer proxyServer) { - return sendAsync(callback, RESPONSE_CONVERTER, proxyServer); + return sendAsync(callback, null); } public interface ResponseConverter { - T convert(com.ning.http.client.Response response) throws IOException; + T convert(Response response) throws IOException; } } 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 f2516d8c2..a93c4c3ec 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java @@ -1,6 +1,5 @@ package com.github.scribejava.core.oauth; -import com.ning.http.client.ProxyServer; import java.io.IOException; import java.util.Map; import java.util.concurrent.Future; @@ -96,11 +95,6 @@ public final OAuth1AccessToken getAccessToken(OAuth1RequestToken requestToken, S */ public final Future getAccessTokenAsync(OAuth1RequestToken requestToken, String oauthVerifier, OAuthAsyncRequestCallback callback) { - return getAccessTokenAsync(requestToken, oauthVerifier, callback, null); - } - - public final Future getAccessTokenAsync(OAuth1RequestToken requestToken, String oauthVerifier, - OAuthAsyncRequestCallback callback, ProxyServer proxyServer) { final OAuthConfig config = getConfig(); config.log("async obtaining access token from " + api.getAccessTokenEndpoint()); final OAuthRequestAsync request @@ -108,11 +102,10 @@ public final Future getAccessTokenAsync(OAuth1RequestToken re prepareAccessTokenRequest(request, requestToken, oauthVerifier); return request.sendAsync(callback, new OAuthRequestAsync.ResponseConverter() { @Override - public OAuth1AccessToken convert(com.ning.http.client.Response response) throws IOException { - return getApi().getAccessTokenExtractor() - .extract(OAuthRequestAsync.RESPONSE_CONVERTER.convert(response).getBody()); + public OAuth1AccessToken convert(Response response) throws IOException { + return getApi().getAccessTokenExtractor().extract(response.getBody()); } - }, proxyServer); + }); } protected void prepareAccessTokenRequest(AbstractRequest request, OAuth1RequestToken requestToken, 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 3813d28ba..b9efbf0f3 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java @@ -1,7 +1,6 @@ package com.github.scribejava.core.oauth; import com.github.scribejava.core.services.Base64Encoder; -import com.ning.http.client.ProxyServer; import java.io.IOException; import java.nio.charset.Charset; import java.util.concurrent.Future; @@ -14,6 +13,7 @@ import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.OAuthRequestAsync; +import com.github.scribejava.core.model.Response; import java.util.Map; public class OAuth20Service extends OAuthService { @@ -39,15 +39,14 @@ protected OAuth2AccessToken sendAccessTokenRequestSync(OAuthRequest request) { //async version, protected to facilitate mocking protected Future sendAccessTokenRequestAsync(OAuthRequestAsync request, - OAuthAsyncRequestCallback callback, ProxyServer proxyServer) { + OAuthAsyncRequestCallback callback) { return request.sendAsync(callback, new OAuthRequestAsync.ResponseConverter() { @Override - public OAuth2AccessToken convert(com.ning.http.client.Response response) throws IOException { - return getApi().getAccessTokenExtractor() - .extract(OAuthRequestAsync.RESPONSE_CONVERTER.convert(response).getBody()); + public OAuth2AccessToken convert(Response response) throws IOException { + return getApi().getAccessTokenExtractor().extract(response.getBody()); } - }, proxyServer); + }); } public final OAuth2AccessToken getAccessToken(String code) { @@ -67,15 +66,10 @@ public final OAuth2AccessToken getAccessToken(String code) { */ public final Future getAccessTokenAsync(String code, OAuthAsyncRequestCallback callback) { - return getAccessTokenAsync(code, callback, null); - } - - public final Future getAccessTokenAsync(String code, - OAuthAsyncRequestCallback callback, ProxyServer proxyServer) { final OAuthRequestAsync request = createAccessTokenRequest(code, new OAuthRequestAsync(api.getAccessTokenVerb(), api.getAccessTokenEndpoint(), this)); - return sendAccessTokenRequestAsync(request, callback, proxyServer); + return sendAccessTokenRequestAsync(request, callback); } protected T createAccessTokenRequest(String code, T request) { @@ -101,15 +95,10 @@ public final OAuth2AccessToken refreshAccessToken(String refreshToken) { public final Future refreshAccessTokenAsync(String refreshToken, OAuthAsyncRequestCallback callback) { - return refreshAccessTokenAsync(refreshToken, callback, null); - } - - public final Future refreshAccessTokenAsync(String refreshToken, - OAuthAsyncRequestCallback callback, ProxyServer proxyServer) { final OAuthRequestAsync request = createRefreshTokenRequest(refreshToken, new OAuthRequestAsync(api.getAccessTokenVerb(), api.getRefreshTokenEndpoint(), this)); - return sendAccessTokenRequestAsync(request, callback, proxyServer); + return sendAccessTokenRequestAsync(request, callback); } protected T createRefreshTokenRequest(String refreshToken, T request) { @@ -148,15 +137,10 @@ public final OAuth2AccessToken getAccessTokenPasswordGrant(String uname, String */ public final Future getAccessTokenPasswordGrantAsync(String uname, String password, OAuthAsyncRequestCallback callback) { - return getAccessTokenPasswordGrantAsync(uname, password, callback, null); - } - - public final Future getAccessTokenPasswordGrantAsync(String uname, String password, - OAuthAsyncRequestCallback callback, ProxyServer proxyServer) { final OAuthRequestAsync request = createAccessTokenPasswordGrantRequest(uname, password, new OAuthRequestAsync(api.getAccessTokenVerb(), api.getAccessTokenEndpoint(), this)); - return sendAccessTokenRequestAsync(request, callback, proxyServer); + return sendAccessTokenRequestAsync(request, callback); } protected T createAccessTokenPasswordGrantRequest(String username, String password, diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java index 3b0e1870e..b1d8c8eee 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java @@ -1,11 +1,20 @@ package com.github.scribejava.core.oauth; +import com.github.scribejava.core.async.ning.OAuthAsyncCompletionHandler; import com.ning.http.client.AsyncHttpClient; import com.github.scribejava.core.exceptions.OAuthException; +import com.github.scribejava.core.model.AbstractRequest; +import static com.github.scribejava.core.model.AbstractRequest.DEFAULT_CONTENT_TYPE; import com.github.scribejava.core.model.ForceTypeOfHttpRequest; +import com.github.scribejava.core.model.OAuthAsyncRequestCallback; import com.github.scribejava.core.model.OAuthConfig; +import com.github.scribejava.core.model.OAuthConstants; +import com.github.scribejava.core.model.OAuthRequestAsync; import com.github.scribejava.core.model.ScribeJavaConfig; +import com.github.scribejava.core.model.Verb; import com.ning.http.client.AsyncHttpClientConfig; +import java.util.Map; +import java.util.concurrent.Future; /** * The main ScribeJava object. @@ -43,10 +52,6 @@ public OAuthService(OAuthConfig config) { } } - public AsyncHttpClient getAsyncHttpClient() { - return asyncHttpClient; - } - public void closeAsyncClient() { asyncHttpClient.close(); } @@ -61,4 +66,34 @@ public OAuthConfig getConfig() { * @return OAuth version as string */ public abstract String getVersion(); + + public Future executeAsync(Map headers, Verb httpVerb, String completeUrl, + String bodyContents, OAuthAsyncRequestCallback callback, + OAuthRequestAsync.ResponseConverter converter) { + final AsyncHttpClient.BoundRequestBuilder boundRequestBuilder; + switch (httpVerb) { + case GET: + boundRequestBuilder = asyncHttpClient.prepareGet(completeUrl); + break; + case POST: + AsyncHttpClient.BoundRequestBuilder requestBuilder = asyncHttpClient.preparePost(completeUrl); + if (!headers.containsKey(AbstractRequest.CONTENT_TYPE)) { + requestBuilder = requestBuilder.addHeader(AbstractRequest.CONTENT_TYPE, DEFAULT_CONTENT_TYPE); + } + boundRequestBuilder = requestBuilder.setBody(bodyContents); + break; + default: + throw new IllegalArgumentException("message build error: unknown verb type"); + } + + for (Map.Entry header : headers.entrySet()) { + boundRequestBuilder.addHeader(header.getKey(), header.getValue()); + } + final String userAgent = config.getUserAgent(); + if (userAgent != null) { + boundRequestBuilder.setHeader(OAuthConstants.USER_AGENT_HEADER_NAME, userAgent); + } + + return boundRequestBuilder.execute(new OAuthAsyncCompletionHandler<>(callback, converter)); + } } diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceUnit.java b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceUnit.java index 07fc9680c..4d75c5ece 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceUnit.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceUnit.java @@ -10,7 +10,6 @@ import com.github.scribejava.core.model.OAuthRequestAsync; import com.github.scribejava.core.model.Parameter; import com.google.gson.Gson; -import com.ning.http.client.ProxyServer; import java.util.HashMap; import java.util.Map; @@ -50,7 +49,7 @@ private String prepareRawResponse(T request) { @Override protected Future sendAccessTokenRequestAsync(OAuthRequestAsync request, - OAuthAsyncRequestCallback callback, ProxyServer proxyServer) { + OAuthAsyncRequestCallback callback) { final OAuth2AccessToken accessToken = new OAuth2AccessToken(TOKEN, prepareRawResponse(request)); From 34b33ecac84da4dbab8dc71593d314c3bc9cb790 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 25 May 2016 16:55:18 +0300 Subject: [PATCH 205/882] add async-http-client 2.0 support (thanks to Sai Chandrasekharan https://github.com/saichand) --- changelog | 1 + pom.xml | 6 ++ ...ple.java => FacebookAsyncNingExample.java} | 5 +- ...mple.java => Google20AsyncAHCExample.java} | 11 +-- .../apis/examples/MailruAsyncExample.java | 3 +- .../ahc/OAuthAsyncCompletionHandler.java | 47 ++++++++++ .../core/builder/ServiceBuilder.java | 27 ++++-- .../scribejava/core/model/OAuthConfig.java | 32 ++++--- .../scribejava/core/oauth/OAuthService.java | 88 +++++++++++++++---- 9 files changed, 177 insertions(+), 43 deletions(-) rename scribejava-apis/src/test/java/com/github/scribejava/apis/examples/{FacebookAsyncExample.java => FacebookAsyncNingExample.java} (97%) rename scribejava-apis/src/test/java/com/github/scribejava/apis/examples/{Google20AsyncExample.java => Google20AsyncAHCExample.java} (94%) create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/async/ahc/OAuthAsyncCompletionHandler.java diff --git a/changelog b/changelog index 6d1d5fea4..2080cb59f 100644 --- a/changelog +++ b/changelog @@ -1,5 +1,6 @@ [SNAPSHOT] * make http async client implementation be more pluggable + * add async-http-client 2.0 support (thanks to Sai Chandrasekharan https://github.com/saichand) [2.6.0] * simplify async/sync usages diff --git a/pom.xml b/pom.xml index a5a66b89f..e72fe52e7 100644 --- a/pom.xml +++ b/pom.xml @@ -99,6 +99,12 @@ 1.9.38 provided + + org.asynchttpclient + async-http-client + 2.0.3 + provided + diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java similarity index 97% rename from scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncExample.java rename to scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java index 65bee0cf9..ae0d1d09a 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java @@ -13,13 +13,14 @@ import com.github.scribejava.core.model.ScribeJavaConfig; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.oauth.OAuth20Service; +import java.io.IOException; -public abstract class FacebookAsyncExample { +public abstract class FacebookAsyncNingExample { private static final String NETWORK_NAME = "Facebook"; private static final String PROTECTED_RESOURCE_URL = "https://graph.facebook.com/v2.6/me"; - public static void main(String... args) throws InterruptedException, ExecutionException { + public static void main(String... args) throws InterruptedException, ExecutionException, IOException { // Replace these with your client id and secret final String clientId = "your client id"; final String clientSecret = "your client secret"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java similarity index 94% rename from scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncExample.java rename to scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java index f8b021041..bfd88430a 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java @@ -11,26 +11,27 @@ import com.github.scribejava.core.model.ScribeJavaConfig; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.oauth.OAuth20Service; -import com.ning.http.client.AsyncHttpClientConfig; +import java.io.IOException; import java.util.HashMap; import java.util.Map; import java.util.concurrent.ExecutionException; +import org.asynchttpclient.AsyncHttpClientConfig; +import org.asynchttpclient.DefaultAsyncHttpClientConfig; -public abstract class Google20AsyncExample { +public abstract class Google20AsyncAHCExample { private static final String NETWORK_NAME = "G+ Async"; private static final String PROTECTED_RESOURCE_URL = "https://www.googleapis.com/plus/v1/people/me"; - public static void main(String... args) throws InterruptedException, ExecutionException { + public static void main(String... args) throws InterruptedException, ExecutionException, IOException { // Replace these with your client id and secret final String clientId = "your client id"; final String clientSecret = "your client secret"; final String secretState = "secret" + new Random().nextInt(999_999); ScribeJavaConfig.setForceTypeOfHttpRequests(ForceTypeOfHttpRequest.FORCE_ASYNC_ONLY_HTTP_REQUESTS); - final AsyncHttpClientConfig clientConfig = new AsyncHttpClientConfig.Builder() + final AsyncHttpClientConfig clientConfig = new DefaultAsyncHttpClientConfig.Builder() .setMaxConnections(5) .setRequestTimeout(10_000) - .setAllowPoolingConnections(false) .setPooledConnectionIdleTimeout(1_000) .setReadTimeout(1_000) .build(); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java index 26a61a456..c53e5d856 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java @@ -10,6 +10,7 @@ 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; public abstract class MailruAsyncExample { @@ -17,7 +18,7 @@ public abstract class MailruAsyncExample { private static final String PROTECTED_RESOURCE_URL = "http://www.appsmail.ru/platform/api?method=users.getInfo&secure=1"; - public static void main(String... args) throws InterruptedException, ExecutionException { + public static void main(String... args) throws InterruptedException, ExecutionException, IOException { // Replace these with your client id and secret final String clientId = "your client id"; final String clientSecret = "your client secret"; diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/async/ahc/OAuthAsyncCompletionHandler.java b/scribejava-core/src/main/java/com/github/scribejava/core/async/ahc/OAuthAsyncCompletionHandler.java new file mode 100644 index 000000000..b556fb6ad --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/async/ahc/OAuthAsyncCompletionHandler.java @@ -0,0 +1,47 @@ +package com.github.scribejava.core.async.ahc; + +import com.github.scribejava.core.model.OAuthAsyncRequestCallback; +import com.github.scribejava.core.model.OAuthRequestAsync; +import com.github.scribejava.core.model.Response; +import io.netty.handler.codec.http.HttpHeaders; +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; +import org.asynchttpclient.AsyncCompletionHandler; + +public class OAuthAsyncCompletionHandler extends AsyncCompletionHandler { + + private final OAuthAsyncRequestCallback callback; + private final OAuthRequestAsync.ResponseConverter converter; + + public OAuthAsyncCompletionHandler(OAuthAsyncRequestCallback callback, + OAuthRequestAsync.ResponseConverter converter) { + this.callback = callback; + this.converter = converter; + } + + @Override + public T onCompleted(org.asynchttpclient.Response ahcResponse) throws IOException { + final HttpHeaders map = ahcResponse.getHeaders(); + final Map headersMap = new HashMap<>(); + for (Map.Entry header : map) { + headersMap.put(header.getKey(), header.getValue()); + } + final Response response = new Response(ahcResponse.getStatusCode(), ahcResponse.getStatusText(), headersMap, + ahcResponse.getResponseBody(), ahcResponse.getResponseBodyAsStream()); + + @SuppressWarnings("unchecked") + final T t = converter == null ? (T) response : converter.convert(response); + if (callback != null) { + callback.onCompleted(t); + } + return t; + } + + @Override + public void onThrowable(Throwable t) { + if (callback != null) { + callback.onThrowable(t); + } + } +}; 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 a6404043f..57f99cc0a 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 @@ -7,7 +7,6 @@ import com.github.scribejava.core.model.SignatureType; import com.github.scribejava.core.oauth.OAuthService; import com.github.scribejava.core.utils.Preconditions; -import com.ning.http.client.AsyncHttpClientConfig; /** * Implementation of the Builder pattern, with a fluent interface that creates a {@link OAuthService} @@ -29,8 +28,11 @@ public class ServiceBuilder { private Integer readTimeout; //async version only - private AsyncHttpClientConfig asyncHttpClientConfig; - private String asyncHttpProviderClassName; + //ning 1.9 + private com.ning.http.client.AsyncHttpClientConfig ningAsyncHttpClientConfig; + private String ningAsyncHttpProviderClassName; + //AHC 2.0 + private org.asynchttpclient.AsyncHttpClientConfig ahcAsyncHttpClientConfig; public ServiceBuilder() { callback = OAuthConstants.OUT_OF_BAND; @@ -133,14 +135,24 @@ public ServiceBuilder readTimeout(Integer readTimeout) { return this; } - public ServiceBuilder asyncHttpClientConfig(AsyncHttpClientConfig asyncHttpClientConfig) { + public ServiceBuilder asyncHttpClientConfig(com.ning.http.client.AsyncHttpClientConfig asyncHttpClientConfig) { Preconditions.checkNotNull(asyncHttpClientConfig, "asyncHttpClientConfig can't be null"); - this.asyncHttpClientConfig = asyncHttpClientConfig; + ningAsyncHttpClientConfig = asyncHttpClientConfig; + ahcAsyncHttpClientConfig = null; + return this; + } + + public ServiceBuilder asyncHttpClientConfig(org.asynchttpclient.AsyncHttpClientConfig asyncHttpClientConfig) { + Preconditions.checkNotNull(asyncHttpClientConfig, "asyncHttpClientConfig can't be null"); + ahcAsyncHttpClientConfig = asyncHttpClientConfig; + ningAsyncHttpClientConfig = null; + ningAsyncHttpProviderClassName = null; return this; } public ServiceBuilder asyncHttpProviderClassName(String asyncHttpProviderClassName) { - this.asyncHttpProviderClassName = asyncHttpProviderClassName; + this.ningAsyncHttpProviderClassName = asyncHttpProviderClassName; + ahcAsyncHttpClientConfig = null; return this; } @@ -161,7 +173,8 @@ public void checkPreconditions() { private OAuthConfig createConfig() { checkPreconditions(); return new OAuthConfig(apiKey, apiSecret, callback, signatureType, scope, debugStream, state, responseType, - userAgent, connectTimeout, readTimeout, asyncHttpClientConfig, asyncHttpProviderClassName); + userAgent, connectTimeout, readTimeout, ningAsyncHttpClientConfig, ningAsyncHttpProviderClassName, + ahcAsyncHttpClientConfig); } /** diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConfig.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConfig.java index 78358d2e3..d5bba4899 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConfig.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConfig.java @@ -1,6 +1,5 @@ package com.github.scribejava.core.model; -import com.ning.http.client.AsyncHttpClientConfig; import java.io.IOException; import java.io.OutputStream; @@ -23,17 +22,21 @@ public class OAuthConfig { private final Integer connectTimeout; private final Integer readTimeout; - //async only version - private final AsyncHttpClientConfig asyncHttpClientConfig; - private final String asyncHttpProviderClassName; + //async version only + //ning 1.9 + private com.ning.http.client.AsyncHttpClientConfig ningAsyncHttpClientConfig; + private String ningAsyncHttpProviderClassName; + //AHC 2.0 + private org.asynchttpclient.AsyncHttpClientConfig ahcAsyncHttpClientConfig; public OAuthConfig(String key, String secret) { - this(key, secret, null, null, null, null, null, null, null, null, null, null, null); + this(key, secret, null, null, null, null, null, null, null, null, null, null, null, null); } public OAuthConfig(String apiKey, String apiSecret, String callback, SignatureType signatureType, String scope, OutputStream debugStream, String state, String responseType, String userAgent, Integer connectTimeout, - Integer readTimeout, AsyncHttpClientConfig asyncHttpClientConfig, String asyncHttpProviderClassName) { + Integer readTimeout, com.ning.http.client.AsyncHttpClientConfig ningAsyncHttpClientConfig, + String ningAsyncHttpProviderClassName, org.asynchttpclient.AsyncHttpClientConfig ahcAsyncHttpClientConfig) { this.apiKey = apiKey; this.apiSecret = apiSecret; this.callback = callback; @@ -45,8 +48,9 @@ public OAuthConfig(String apiKey, String apiSecret, String callback, SignatureTy this.userAgent = userAgent; this.connectTimeout = connectTimeout; this.readTimeout = readTimeout; - this.asyncHttpClientConfig = asyncHttpClientConfig; - this.asyncHttpProviderClassName = asyncHttpProviderClassName; + this.ningAsyncHttpClientConfig = ningAsyncHttpClientConfig; + this.ningAsyncHttpProviderClassName = ningAsyncHttpProviderClassName; + this.ahcAsyncHttpClientConfig = ahcAsyncHttpClientConfig; } public String getApiKey() { @@ -100,11 +104,15 @@ public Integer getReadTimeout() { return readTimeout; } - public AsyncHttpClientConfig getAsyncHttpClientConfig() { - return asyncHttpClientConfig; + public com.ning.http.client.AsyncHttpClientConfig getNingAsyncHttpClientConfig() { + return ningAsyncHttpClientConfig; } - public String getAsyncHttpProviderClassName() { - return asyncHttpProviderClassName; + public String getNingAsyncHttpProviderClassName() { + return ningAsyncHttpProviderClassName; + } + + public org.asynchttpclient.AsyncHttpClientConfig getAhcAsyncHttpClientConfig() { + return ahcAsyncHttpClientConfig; } } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java index b1d8c8eee..f6922224e 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java @@ -1,7 +1,5 @@ package com.github.scribejava.core.oauth; -import com.github.scribejava.core.async.ning.OAuthAsyncCompletionHandler; -import com.ning.http.client.AsyncHttpClient; import com.github.scribejava.core.exceptions.OAuthException; import com.github.scribejava.core.model.AbstractRequest; import static com.github.scribejava.core.model.AbstractRequest.DEFAULT_CONTENT_TYPE; @@ -12,7 +10,7 @@ import com.github.scribejava.core.model.OAuthRequestAsync; import com.github.scribejava.core.model.ScribeJavaConfig; import com.github.scribejava.core.model.Verb; -import com.ning.http.client.AsyncHttpClientConfig; +import java.io.IOException; import java.util.Map; import java.util.concurrent.Future; @@ -24,20 +22,24 @@ public abstract class OAuthService { private final OAuthConfig config; - private final AsyncHttpClient asyncHttpClient; + private final com.ning.http.client.AsyncHttpClient ningAsyncHttpClient; + private final org.asynchttpclient.AsyncHttpClient ahcAsyncHttpClient; public OAuthService(OAuthConfig config) { this.config = config; final ForceTypeOfHttpRequest forceTypeOfHttpRequest = ScribeJavaConfig.getForceTypeOfHttpRequests(); - final AsyncHttpClientConfig asyncHttpClientConfig = config.getAsyncHttpClientConfig(); - if (asyncHttpClientConfig == null) { + final com.ning.http.client.AsyncHttpClientConfig ningConfig = config.getNingAsyncHttpClientConfig(); + final org.asynchttpclient.AsyncHttpClientConfig ahcConfig = config.getAhcAsyncHttpClientConfig(); + + if (ningConfig == null && ahcConfig == null) { if (ForceTypeOfHttpRequest.FORCE_ASYNC_ONLY_HTTP_REQUESTS == forceTypeOfHttpRequest) { throw new OAuthException("Cannot use sync operations, only async"); } if (ForceTypeOfHttpRequest.PREFER_ASYNC_ONLY_HTTP_REQUESTS == forceTypeOfHttpRequest) { config.log("Cannot use sync operations, only async"); } - asyncHttpClient = null; + ningAsyncHttpClient = null; + ahcAsyncHttpClient = null; } else { if (ForceTypeOfHttpRequest.FORCE_SYNC_ONLY_HTTP_REQUESTS == forceTypeOfHttpRequest) { throw new OAuthException("Cannot use async operations, only sync"); @@ -45,15 +47,26 @@ public OAuthService(OAuthConfig config) { if (ForceTypeOfHttpRequest.PREFER_SYNC_ONLY_HTTP_REQUESTS == forceTypeOfHttpRequest) { config.log("Cannot use async operations, only sync"); } - final String asyncHttpProviderClassName = config.getAsyncHttpProviderClassName(); - asyncHttpClient = asyncHttpProviderClassName == null ? new AsyncHttpClient(asyncHttpClientConfig) - : new AsyncHttpClient(asyncHttpProviderClassName, asyncHttpClientConfig); + if (ahcConfig == null) { + final String ningAsyncHttpProviderClassName = config.getNingAsyncHttpProviderClassName(); + ningAsyncHttpClient = ningAsyncHttpProviderClassName == null + ? new com.ning.http.client.AsyncHttpClient(ningConfig) + : new com.ning.http.client.AsyncHttpClient(ningAsyncHttpProviderClassName, ningConfig); + ahcAsyncHttpClient = null; + } else { + ahcAsyncHttpClient = new org.asynchttpclient.DefaultAsyncHttpClient(ahcConfig); + ningAsyncHttpClient = null; + } } } - public void closeAsyncClient() { - asyncHttpClient.close(); + public void closeAsyncClient() throws IOException { + if (ahcAsyncHttpClient == null) { + ningAsyncHttpClient.close(); + } else { + ahcAsyncHttpClient.close(); + } } public OAuthConfig getConfig() { @@ -70,13 +83,55 @@ public OAuthConfig getConfig() { public Future executeAsync(Map headers, Verb httpVerb, String completeUrl, String bodyContents, OAuthAsyncRequestCallback callback, OAuthRequestAsync.ResponseConverter converter) { - final AsyncHttpClient.BoundRequestBuilder boundRequestBuilder; + if (ahcAsyncHttpClient == null) { + return ningExecuteAsync(headers, httpVerb, completeUrl, bodyContents, callback, converter); + } else { + return ahcExecuteAsync(headers, httpVerb, completeUrl, bodyContents, callback, converter); + } + } + + private Future ningExecuteAsync(Map headers, Verb httpVerb, String completeUrl, + String bodyContents, OAuthAsyncRequestCallback callback, + OAuthRequestAsync.ResponseConverter converter) { + final com.ning.http.client.AsyncHttpClient.BoundRequestBuilder boundRequestBuilder; + switch (httpVerb) { + case GET: + boundRequestBuilder = ningAsyncHttpClient.prepareGet(completeUrl); + break; + case POST: + com.ning.http.client.AsyncHttpClient.BoundRequestBuilder requestBuilder + = ningAsyncHttpClient.preparePost(completeUrl); + if (!headers.containsKey(AbstractRequest.CONTENT_TYPE)) { + requestBuilder = requestBuilder.addHeader(AbstractRequest.CONTENT_TYPE, DEFAULT_CONTENT_TYPE); + } + boundRequestBuilder = requestBuilder.setBody(bodyContents); + break; + default: + throw new IllegalArgumentException("message build error: unknown verb type"); + } + + for (Map.Entry header : headers.entrySet()) { + boundRequestBuilder.addHeader(header.getKey(), header.getValue()); + } + final String userAgent = config.getUserAgent(); + if (userAgent != null) { + boundRequestBuilder.setHeader(OAuthConstants.USER_AGENT_HEADER_NAME, userAgent); + } + + return boundRequestBuilder + .execute(new com.github.scribejava.core.async.ning.OAuthAsyncCompletionHandler<>(callback, converter)); + } + + private Future ahcExecuteAsync(Map headers, Verb httpVerb, String completeUrl, + String bodyContents, OAuthAsyncRequestCallback callback, + OAuthRequestAsync.ResponseConverter converter) { + final org.asynchttpclient.BoundRequestBuilder boundRequestBuilder; switch (httpVerb) { case GET: - boundRequestBuilder = asyncHttpClient.prepareGet(completeUrl); + boundRequestBuilder = ahcAsyncHttpClient.prepareGet(completeUrl); break; case POST: - AsyncHttpClient.BoundRequestBuilder requestBuilder = asyncHttpClient.preparePost(completeUrl); + org.asynchttpclient.BoundRequestBuilder requestBuilder = ahcAsyncHttpClient.preparePost(completeUrl); if (!headers.containsKey(AbstractRequest.CONTENT_TYPE)) { requestBuilder = requestBuilder.addHeader(AbstractRequest.CONTENT_TYPE, DEFAULT_CONTENT_TYPE); } @@ -94,6 +149,7 @@ public Future executeAsync(Map headers, Verb httpVerb, St boundRequestBuilder.setHeader(OAuthConstants.USER_AGENT_HEADER_NAME, userAgent); } - return boundRequestBuilder.execute(new OAuthAsyncCompletionHandler<>(callback, converter)); + return boundRequestBuilder + .execute(new com.github.scribejava.core.async.ahc.OAuthAsyncCompletionHandler<>(callback, converter)); } } From d5582f28091fd6f3dd7a1ef7f04d6e06e70a8092 Mon Sep 17 00:00:00 2001 From: Arto Toppi Date: Mon, 30 May 2016 10:20:17 +0800 Subject: [PATCH 206/882] Add Misfit API Add support for Misfit API. See https://build.misfit.com for details --- .../com/github/scribejava/apis/MisfitApi.java | 56 ++++++++++++++++ .../apis/examples/MisfitExample.java | 65 +++++++++++++++++++ 2 files changed, 121 insertions(+) create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/MisfitApi.java create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MisfitExample.java diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/MisfitApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/MisfitApi.java new file mode 100644 index 000000000..8ef6d6224 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/MisfitApi.java @@ -0,0 +1,56 @@ +package com.github.scribejava.apis; + +import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.model.OAuthConfig; +import com.github.scribejava.core.model.OAuthConstants; +import com.github.scribejava.core.model.ParameterList; +import com.github.scribejava.core.oauth.OAuth20Service; +import java.util.Map; + +public class MisfitApi extends DefaultApi20 { + + protected MisfitApi() { + } + + private static class InstanceHolder { + private static final MisfitApi INSTANCE = new MisfitApi(); + } + + public static MisfitApi instance() { + return InstanceHolder.INSTANCE; + } + + @Override + public String getAccessTokenEndpoint() { + return "https://api.misfitwearables.com/auth/tokens/exchange"; + } + + @Override + public String getAuthorizationUrl(OAuthConfig config, Map additionalParams) { + final ParameterList parameters = new ParameterList(additionalParams); + parameters.add(OAuthConstants.RESPONSE_TYPE, "code"); + parameters.add(OAuthConstants.CLIENT_ID, config.getApiKey()); + + final String callback = config.getCallback(); + if (callback != null) { + parameters.add(OAuthConstants.REDIRECT_URI, callback); + } + + final String scope = config.getScope(); + if (scope != null) { + parameters.add(OAuthConstants.SCOPE, scope); + } + + final String state = config.getState(); + if (state != null) { + parameters.add(OAuthConstants.STATE, state); + } + + return parameters.appendTo("https://api.misfitwearables.com/auth/dialog/authorize"); + } + + @Override + protected String getAuthorizationBaseUrl() { + throw new UnsupportedOperationException("use getAuthorizationUrl instead"); + } +} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MisfitExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MisfitExample.java new file mode 100644 index 000000000..15feb6aee --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MisfitExample.java @@ -0,0 +1,65 @@ +package com.github.scribejava.apis.examples; + +import com.github.scribejava.apis.MisfitApi; +import com.github.scribejava.core.builder.ServiceBuilder; +import com.github.scribejava.core.model.OAuth2AccessToken; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.oauth.OAuth20Service; + +import java.util.Scanner; + +public abstract class MisfitExample { + + private static final String NETWORK_NAME = "Misfit"; + private static final String PROTECTED_RESOURCE_URL = "https://api.misfitwearables.com/move/resource/v1/user/me/profile"; + + public static void main(String... args) { + // Replace these with your own api key and secret + final String apiKey = "your client id"; + final String apiSecret = "your client secret"; + final OAuth20Service service = new ServiceBuilder() + .apiKey(apiKey) + .apiSecret(apiSecret) + .callback("http://example.com/callback/") + .scope("public,birthday,email,tracking,session,sleep") + .build(MisfitApi.instance()); + final Scanner in = new Scanner(System.in); + + System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); + System.out.println(); + + // Obtain the Authorization URL + System.out.println("Fetching the Authorization URL..."); + final String authorizationUrl = service.getAuthorizationUrl(); + System.out.println("Got the Authorization URL!"); + System.out.println("Now go and authorize ScribeJava here:"); + System.out.println(authorizationUrl); + System.out.println("And paste the authorization code here"); + System.out.print(">>"); + final String code = in.nextLine(); + System.out.println(); + + // Trade the Request Token and Verifier for the Access Token + System.out.println("Trading the Request Token for an Access Token..."); + final OAuth2AccessToken accessToken = service.getAccessToken(code); + System.out.println("Got the Access Token!"); + System.out.println("(if your curious it looks like this: " + accessToken + + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println(); + + // Now let's go and ask for a protected resource! + System.out.println("Now we're going to access a protected resource..."); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service); + service.signRequest(accessToken, request); + final Response response = request.send(); + 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 dd300b14eeca046deabb7eb9b467084600371ed4 Mon Sep 17 00:00:00 2001 From: Arto Toppi Date: Mon, 30 May 2016 10:56:44 +0800 Subject: [PATCH 207/882] Update indenting on the MisfitExample Tabs to spaces on two lines --- .../com/github/scribejava/apis/examples/MisfitExample.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MisfitExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MisfitExample.java index 15feb6aee..ef07f8460 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MisfitExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MisfitExample.java @@ -22,8 +22,8 @@ public static void main(String... args) { final OAuth20Service service = new ServiceBuilder() .apiKey(apiKey) .apiSecret(apiSecret) - .callback("http://example.com/callback/") - .scope("public,birthday,email,tracking,session,sleep") + .callback("http://example.com/callback/") + .scope("public,birthday,email,tracking,session,sleep") .build(MisfitApi.instance()); final Scanner in = new Scanner(System.in); From d014b52252a3c6d44ea64200f72d508a935f6867 Mon Sep 17 00:00:00 2001 From: Arto Toppi Date: Tue, 31 May 2016 13:41:50 +0800 Subject: [PATCH 208/882] MisfitApi - Implement getAuthorizationBaseUrl Updates based on the code review: Removed unnecessary override for getAuthorizationUrl Implement method getAuthorizationBaseUrl --- .../com/github/scribejava/apis/MisfitApi.java | 26 +------------------ 1 file changed, 1 insertion(+), 25 deletions(-) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/MisfitApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/MisfitApi.java index 8ef6d6224..b8761373c 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/MisfitApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/MisfitApi.java @@ -25,32 +25,8 @@ public String getAccessTokenEndpoint() { return "https://api.misfitwearables.com/auth/tokens/exchange"; } - @Override - public String getAuthorizationUrl(OAuthConfig config, Map additionalParams) { - final ParameterList parameters = new ParameterList(additionalParams); - parameters.add(OAuthConstants.RESPONSE_TYPE, "code"); - parameters.add(OAuthConstants.CLIENT_ID, config.getApiKey()); - - final String callback = config.getCallback(); - if (callback != null) { - parameters.add(OAuthConstants.REDIRECT_URI, callback); - } - - final String scope = config.getScope(); - if (scope != null) { - parameters.add(OAuthConstants.SCOPE, scope); - } - - final String state = config.getState(); - if (state != null) { - parameters.add(OAuthConstants.STATE, state); - } - - return parameters.appendTo("https://api.misfitwearables.com/auth/dialog/authorize"); - } - @Override protected String getAuthorizationBaseUrl() { - throw new UnsupportedOperationException("use getAuthorizationUrl instead"); + return "https://api.misfitwearables.com/auth/dialog/authorize"; } } From 3e3e6c746db33e69cdb876a7238d675b24fc8a68 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 6 Jun 2016 15:35:43 +0300 Subject: [PATCH 209/882] add Misfit (http://misfit.com/) API --- README.md | 1 + changelog | 1 + .../main/java/com/github/scribejava/apis/MisfitApi.java | 8 ++------ .../github/scribejava/apis/examples/MisfitExample.java | 5 +++-- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 031c4dd53..157d9202c 100644 --- a/README.md +++ b/README.md @@ -59,6 +59,7 @@ You can use ning async http client out-of-box, just use ServiceBuilderAsync * VK ВКонтакте (http://vk.com/) * XING (https://www.xing.com/) * Yahoo (https://www.yahoo.com/) +* Misfit (http://misfit.com/) * check the [examples folder](https://github.com/scribejava/scribejava/tree/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples) ### Small and modular diff --git a/changelog b/changelog index 2080cb59f..486f5372d 100644 --- a/changelog +++ b/changelog @@ -1,6 +1,7 @@ [SNAPSHOT] * make http async client implementation be more pluggable * add async-http-client 2.0 support (thanks to Sai Chandrasekharan https://github.com/saichand) + * add Misfit (http://misfit.com/) API [2.6.0] * simplify async/sync usages diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/MisfitApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/MisfitApi.java index b8761373c..f6d2fc706 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/MisfitApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/MisfitApi.java @@ -1,11 +1,6 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.model.OAuthConfig; -import com.github.scribejava.core.model.OAuthConstants; -import com.github.scribejava.core.model.ParameterList; -import com.github.scribejava.core.oauth.OAuth20Service; -import java.util.Map; public class MisfitApi extends DefaultApi20 { @@ -13,6 +8,7 @@ protected MisfitApi() { } private static class InstanceHolder { + private static final MisfitApi INSTANCE = new MisfitApi(); } @@ -22,7 +18,7 @@ public static MisfitApi instance() { @Override public String getAccessTokenEndpoint() { - return "https://api.misfitwearables.com/auth/tokens/exchange"; + return "https://api.misfitwearables.com/auth/tokens/exchange"; } @Override diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MisfitExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MisfitExample.java index ef07f8460..edb362fd2 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MisfitExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MisfitExample.java @@ -12,8 +12,9 @@ public abstract class MisfitExample { - private static final String NETWORK_NAME = "Misfit"; - private static final String PROTECTED_RESOURCE_URL = "https://api.misfitwearables.com/move/resource/v1/user/me/profile"; + private static final String NETWORK_NAME = "Misfit"; + private static final String PROTECTED_RESOURCE_URL + = "https://api.misfitwearables.com/move/resource/v1/user/me/profile"; public static void main(String... args) { // Replace these with your own api key and secret From 545f2d55288c31941a01b2b8daef27dad1206b9b Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 6 Jun 2016 15:52:52 +0300 Subject: [PATCH 210/882] implement async version getting Request Token for OAuth 1.0a --- changelog | 1 + .../core/oauth/OAuth10aService.java | 30 +++++++++++++++---- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/changelog b/changelog index 486f5372d..6c05721b2 100644 --- a/changelog +++ b/changelog @@ -2,6 +2,7 @@ * make http async client implementation be more pluggable * add async-http-client 2.0 support (thanks to Sai Chandrasekharan https://github.com/saichand) * add Misfit (http://misfit.com/) API + * implement async version getting Request Token for OAuth 1.0a [2.6.0] * simplify async/sync usages 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 a93c4c3ec..186541c39 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 @@ -40,15 +40,12 @@ public OAuth10aService(DefaultApi10a api, OAuthConfig config) { * * @return request token */ - public OAuth1RequestToken getRequestToken() { + public final OAuth1RequestToken getRequestToken() { final OAuthConfig config = getConfig(); config.log("obtaining request token from " + api.getRequestTokenEndpoint()); final OAuthRequest request = new OAuthRequest(api.getRequestTokenVerb(), api.getRequestTokenEndpoint(), this); - config.log("setting oauth_callback to " + config.getCallback()); - request.addOAuthParameter(OAuthConstants.CALLBACK, config.getCallback()); - addOAuthParams(request, ""); - appendSignature(request); + prepareRequestTokenRequest(request); config.log("sending request..."); final Response response = request.send(); @@ -59,6 +56,29 @@ public OAuth1RequestToken getRequestToken() { return api.getRequestTokenExtractor().extract(body); } + public final Future getRequestTokenAsync( + OAuthAsyncRequestCallback callback) { + final OAuthConfig config = getConfig(); + config.log("async obtaining request token from " + api.getRequestTokenEndpoint()); + final OAuthRequestAsync request + = new OAuthRequestAsync(api.getRequestTokenVerb(), api.getRequestTokenEndpoint(), this); + prepareRequestTokenRequest(request); + return request.sendAsync(callback, new OAuthRequestAsync.ResponseConverter() { + @Override + public OAuth1RequestToken convert(Response response) throws IOException { + return getApi().getRequestTokenExtractor().extract(response.getBody()); + } + }); + } + + protected void prepareRequestTokenRequest(AbstractRequest request) { + final OAuthConfig config = getConfig(); + config.log("setting oauth_callback to " + config.getCallback()); + request.addOAuthParameter(OAuthConstants.CALLBACK, config.getCallback()); + addOAuthParams(request, ""); + appendSignature(request); + } + private void addOAuthParams(AbstractRequest request, String tokenSecret) { final OAuthConfig config = getConfig(); request.addOAuthParameter(OAuthConstants.TIMESTAMP, api.getTimestampService().getTimestampInSeconds()); From 2a1671c1a8cad2b9a9e9bd463b34dc11bbbddb95 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 6 Jun 2016 15:59:03 +0300 Subject: [PATCH 211/882] prepare 2.7.0 release --- README.md | 4 ++-- changelog | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 157d9202c..6fac2c8ce 100644 --- a/README.md +++ b/README.md @@ -85,7 +85,7 @@ You can pull ScribeJava from the central maven repository, just add these to you com.github.scribejava scribejava-apis - 2.6.0 + 2.7.0 ``` @@ -94,7 +94,7 @@ And in case you need just core classes (that's it, without any external API (FB, com.github.scribejava scribejava-core - 2.6.0 + 2.7.0 ``` diff --git a/changelog b/changelog index 6c05721b2..cc207737e 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,4 @@ -[SNAPSHOT] +[2.7.0] * make http async client implementation be more pluggable * add async-http-client 2.0 support (thanks to Sai Chandrasekharan https://github.com/saichand) * add Misfit (http://misfit.com/) API From 9ab3986f1b101659f4e5a83b48a657f0711af1aa Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 6 Jun 2016 17:53:39 +0300 Subject: [PATCH 212/882] [maven-release-plugin] prepare release scribejava-2.7.0 --- pom.xml | 2 +- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index e72fe52e7..8a4640ce0 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 2.6.1-SNAPSHOT + 2.7.0 ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 6a8f03dfc..08295e37b 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 2.6.1-SNAPSHOT + 2.7.0 ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index b4a2894c9..c2230b028 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 2.6.1-SNAPSHOT + 2.7.0 ../pom.xml From 832ebd3e351edc3b07e55f3a347e3018b18448f7 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 6 Jun 2016 17:53:44 +0300 Subject: [PATCH 213/882] [maven-release-plugin] prepare for next development iteration --- pom.xml | 2 +- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 8a4640ce0..e4aa054f5 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 2.7.0 + 2.7.1-SNAPSHOT ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 08295e37b..c2de94306 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 2.7.0 + 2.7.1-SNAPSHOT ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index c2230b028..c6b9b52ca 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 2.7.0 + 2.7.1-SNAPSHOT ../pom.xml From 1f6d1da303c502061269b8b29a463818830a594e Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 8 Jun 2016 15:40:30 +0300 Subject: [PATCH 214/882] do not hide checked IOException in unchecked IllegalArgumentException --- changelog | 3 ++ .../apis/examples/AWeberExample.java | 3 +- .../scribejava/apis/examples/DiggExample.java | 3 +- .../apis/examples/FacebookExample.java | 3 +- .../apis/examples/FlickrExample.java | 3 +- .../apis/examples/Foursquare2Example.java | 3 +- .../apis/examples/FoursquareExample.java | 3 +- .../apis/examples/FreelancerExample.java | 3 +- .../apis/examples/GeniusExample.java | 3 +- .../apis/examples/GitHubExample.java | 3 +- .../apis/examples/Google20Example.java | 3 +- .../scribejava/apis/examples/HHExample.java | 3 +- .../apis/examples/ImgurExample.java | 3 +- .../apis/examples/Kaixin20Example.java | 3 +- .../apis/examples/LinkedIn20Example.java | 3 +- .../apis/examples/LinkedInExample.java | 3 +- .../examples/LinkedInExampleWithScopes.java | 3 +- .../scribejava/apis/examples/LiveExample.java | 3 +- .../apis/examples/MailruExample.java | 3 +- .../apis/examples/MeetupExample.java | 3 +- .../apis/examples/MisfitExample.java | 3 +- .../apis/examples/NeteaseWeiboExample.java | 3 +- .../apis/examples/OdnoklassnikiExample.java | 3 +- .../apis/examples/PinterestExample.java | 3 +- .../apis/examples/Px500Example.java | 3 +- .../apis/examples/RenrenExample.java | 3 +- .../apis/examples/SinaWeibo2Example.java | 3 +- .../apis/examples/SinaWeiboExample.java | 3 +- .../apis/examples/SkyrockExample.java | 3 +- .../apis/examples/SohuWeiboExample.java | 3 +- .../apis/examples/StackExchangeExample.java | 3 +- .../apis/examples/TrelloExample.java | 3 +- .../apis/examples/TumblrExample.java | 3 +- .../apis/examples/TutByExample.java | 3 +- .../apis/examples/TwitterExample.java | 3 +- .../apis/examples/ViadeoExample.java | 3 +- .../apis/examples/VkontakteExample.java | 3 +- .../scribejava/apis/examples/XingExample.java | 3 +- .../apis/examples/YahooExample.java | 3 +- .../scribejava/core/model/Response.java | 9 +---- .../core/oauth/OAuth10aService.java | 10 ++--- .../scribejava/core/oauth/OAuth20Service.java | 15 ++----- .../scribejava/core/utils/StreamUtils.java | 40 ++++++++----------- .../scribejava/core/model/ResponseTest.java | 4 +- .../core/oauth/OAuth20ServiceTest.java | 3 +- .../core/utils/StreamUtilsTest.java | 8 ++-- 46 files changed, 113 insertions(+), 93 deletions(-) diff --git a/changelog b/changelog index cc207737e..cbf92b6da 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,6 @@ +[SNAPSHOT] + * do not hide checked IOException in unchecked IllegalArgumentException + [2.7.0] * make http async client implementation be more pluggable * add async-http-client 2.0 support (thanks to Sai Chandrasekharan https://github.com/saichand) diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AWeberExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AWeberExample.java index 233d3a984..b17637c13 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AWeberExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AWeberExample.java @@ -9,6 +9,7 @@ import com.github.scribejava.core.model.Response; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.oauth.OAuth10aService; +import java.io.IOException; public abstract class AWeberExample { @@ -18,7 +19,7 @@ public abstract class AWeberExample { private static final String CONSUMER_KEY = ""; private static final String CONSUMER_SECRET = ""; - public static void main(String... args) { + public static void main(String... args) throws IOException { final OAuth10aService service = new ServiceBuilder() .apiKey(CONSUMER_KEY) .apiSecret(CONSUMER_SECRET) diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiggExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiggExample.java index 690f95081..f55c105a0 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiggExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiggExample.java @@ -9,13 +9,14 @@ import com.github.scribejava.core.model.Response; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.oauth.OAuth10aService; +import java.io.IOException; public abstract class DiggExample { private static final String NETWORK_NAME = "Digg"; private static final String PROTECTED_RESOURCE_URL = "http://services.digg.com/2.0/comment.digg"; - public static void main(String... args) { + public static void main(String... args) throws IOException { // Replace these with your own api key and secret final String apiKey = "myKey"; final String apiSecret = "mySecret"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java index 463729c17..7a1772aec 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java @@ -9,13 +9,14 @@ 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; public abstract class FacebookExample { private static final String NETWORK_NAME = "Facebook"; private static final String PROTECTED_RESOURCE_URL = "https://graph.facebook.com/v2.6/me"; - public static void main(String... args) { + public static void main(String... args) throws IOException { // Replace these with your client id and secret final String clientId = "your client id"; final String clientSecret = "your client secret"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExample.java index db08042ca..ed03b906d 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExample.java @@ -9,12 +9,13 @@ import com.github.scribejava.core.model.Response; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.oauth.OAuth10aService; +import java.io.IOException; public abstract class FlickrExample { private static final String PROTECTED_RESOURCE_URL = "http://api.flickr.com/services/rest/"; - public static void main(String... args) { + public static void main(String... args) throws IOException { // Replace these with your own api key and secret final String apiKey = "your_app_id"; final String apiSecret = "your_api_secret"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java index c581aa484..c9b317911 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java @@ -8,13 +8,14 @@ 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; public abstract class Foursquare2Example { private static final String PROTECTED_RESOURCE_URL = "https://api.foursquare.com/v2/users/self/friends?oauth_token="; - public static void main(String... args) { + public static void main(String... args) throws IOException { // Replace these with your own api key and secret final String apiKey = "your client id"; final String apiSecret = "your client secret"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FoursquareExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FoursquareExample.java index 90fa38848..639aaec0a 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FoursquareExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FoursquareExample.java @@ -9,12 +9,13 @@ import com.github.scribejava.core.model.Response; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.oauth.OAuth10aService; +import java.io.IOException; public abstract class FoursquareExample { private static final String PROTECTED_RESOURCE_URL = "http://api.foursquare.com/v1/user"; - public static void main(String... args) { + public static void main(String... args) throws IOException { final OAuth10aService service = new ServiceBuilder() .apiKey("your client id") .apiSecret("your client secret") diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java index c72f72de0..54e0a7d8d 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java @@ -10,6 +10,7 @@ import com.github.scribejava.core.model.SignatureType; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.oauth.OAuth10aService; +import java.io.IOException; public abstract class FreelancerExample { @@ -19,7 +20,7 @@ public abstract class FreelancerExample { private static final String PROTECTED_RESOURCE_URL = "http://api.sandbox.freelancer.com/Job/getJobList.json"; private static final String SCOPE = "http://api.sandbox.freelancer.com"; - public static void main(String... args) { + public static void main(String... args) throws IOException { final OAuth10aService service = new ServiceBuilder() .signatureType(SignatureType.QueryString) .apiKey("your client id") diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GeniusExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GeniusExample.java index 141cc7ebf..0db6ddc05 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GeniusExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GeniusExample.java @@ -9,13 +9,14 @@ 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; public abstract class GeniusExample { private static final String NETWORK_NAME = "Genius"; private static final String PROTECTED_RESOURCE_URL = "https://api.genius.com/songs/378195"; - public static void main(String... args) { + public static void main(String... args) throws IOException { // Replace these with your client id and secret final String clientId = "your client id"; final String clientSecret = "your client secret"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubExample.java index fb12bf8f7..0a07c9709 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubExample.java @@ -9,13 +9,14 @@ 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; public abstract class GitHubExample { private static final String NETWORK_NAME = "GitHub"; private static final String PROTECTED_RESOURCE_URL = "https://api.github.com/user"; - public static void main(String... args) { + public static void main(String... args) throws IOException { // Replace these with your client id and secret final String clientId = "your client id"; final String clientSecret = "your client secret"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java index 50ec20a62..2e6800c19 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java @@ -9,6 +9,7 @@ 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; @@ -17,7 +18,7 @@ public abstract class Google20Example { private static final String NETWORK_NAME = "G+"; private static final String PROTECTED_RESOURCE_URL = "https://www.googleapis.com/plus/v1/people/me"; - public static void main(String... args) { + public static void main(String... args) throws IOException { // Replace these with your client id and secret final String clientId = "your client id"; final String clientSecret = "your client secret"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HHExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HHExample.java index 0ca8052e0..add150d1f 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HHExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HHExample.java @@ -10,13 +10,14 @@ import com.github.scribejava.apis.HHApi; import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.oauth.OAuth20Service; +import java.io.IOException; public abstract class HHExample { private static final String NETWORK_NAME = "hh.ru"; private static final String PROTECTED_RESOURCE_URL = "https://api.hh.ru/me"; - public static void main(String... args) { + public static void main(String... args) throws IOException { // Replace these with your own client id and secret final String clientId = "your client id"; final String clientSecret = "your client secret"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ImgurExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ImgurExample.java index d25acaa86..1d3f24a44 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ImgurExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ImgurExample.java @@ -7,6 +7,7 @@ import com.github.scribejava.core.model.Response; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.oauth.OAuth20Service; +import java.io.IOException; import java.util.Scanner; @@ -15,7 +16,7 @@ public abstract class ImgurExample { private static final String NETWORK_NAME = "Imgur"; private static final String PROTECTED_RESOURCE_URL = "https://api.imgur.com/3/account/me"; - public static void main(String... args) { + public static void main(String... args) throws IOException { // Replace these with your own api key and secret final String apiKey = "your client id"; final String apiSecret = "your client secret"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Kaixin20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Kaixin20Example.java index 0034f979a..4551370d6 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Kaixin20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Kaixin20Example.java @@ -8,13 +8,14 @@ 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; public abstract class Kaixin20Example { private static final String NETWORK_NAME = "Kaixin"; private static final String PROTECTED_RESOURCE_URL = "https://api.kaixin001.com/users/me.json"; - public static void main(String... args) { + public static void main(String... args) throws IOException { // Replace these with your own api key and secret final String apiKey = "your api key"; final String apiSecret = "your api secret"; 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 d308b7c5c..a39c79890 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 @@ -8,13 +8,14 @@ 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; public abstract class LinkedIn20Example { private static final String NETWORK_NAME = "LinkedIn"; private static final String PROTECTED_RESOURCE_URL = "https://api.linkedin.com/v1/people/~:(%s)"; - public static void main(String... args) { + public static void main(String... args) throws IOException { // Replace these with your client id and secret final String clientId = "your client id"; final String clientSecret = "your client secret"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java index 6a8e327ec..81324377b 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java @@ -9,13 +9,14 @@ import com.github.scribejava.core.model.Response; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.oauth.OAuth10aService; +import java.io.IOException; public abstract class LinkedInExample { private static final String PROTECTED_RESOURCE_URL = "http://api.linkedin.com/v1/people/~/connections:(id,last-name)"; - public static void main(String... args) { + public static void main(String... args) throws IOException { final OAuth10aService service = new ServiceBuilder() .apiKey("your client id") .apiSecret("your client secret") diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java index a0a925cb5..2e951fa5f 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java @@ -9,13 +9,14 @@ import com.github.scribejava.core.model.Response; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.oauth.OAuth10aService; +import java.io.IOException; public abstract class LinkedInExampleWithScopes { private static final String PROTECTED_RESOURCE_URL = "http://api.linkedin.com/v1/people/~/connections:(id,last-name)"; - public static void main(String... args) { + public static void main(String... args) throws IOException { // Replace these with your client id and secret final String clientId = "your client id"; final String clientSecret = "your client id"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java index c86eaa793..0540a26db 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java @@ -8,13 +8,14 @@ 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; public abstract class LiveExample { private static final String PROTECTED_RESOURCE_URL = "https://api.foursquare.com/v2/users/self/friends?oauth_token="; - public static void main(String... args) { + public static void main(String... args) throws IOException { // Replace these with your own api key and secret final String apiKey = ""; final String apiSecret = ""; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java index 45cdb9a80..ae4ad4856 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java @@ -8,6 +8,7 @@ import com.github.scribejava.apis.MailruApi; import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.oauth.OAuth20Service; +import java.io.IOException; public abstract class MailruExample { @@ -15,7 +16,7 @@ public abstract class MailruExample { private static final String PROTECTED_RESOURCE_URL = "http://www.appsmail.ru/platform/api?method=users.getInfo&secure=1"; - public static void main(String... args) { + public static void main(String... args) throws IOException { // Replace these with your client id and secret final String clientId = "your client id"; final String clientSecret = "your client secret"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java index 8adf45a52..64180b980 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java @@ -9,12 +9,13 @@ import com.github.scribejava.core.model.Response; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.oauth.OAuth10aService; +import java.io.IOException; public abstract class MeetupExample { private static final String PROTECTED_RESOURCE_URL = "http://api.meetup.com/2/member/self"; - public static void main(String... args) { + public static void main(String... args) throws IOException { final OAuth10aService service = new ServiceBuilder() .apiKey("your client id") .apiSecret("your client secret") diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MisfitExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MisfitExample.java index edb362fd2..66e5901c9 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MisfitExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MisfitExample.java @@ -7,6 +7,7 @@ import com.github.scribejava.core.model.Response; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.oauth.OAuth20Service; +import java.io.IOException; import java.util.Scanner; @@ -16,7 +17,7 @@ public abstract class MisfitExample { private static final String PROTECTED_RESOURCE_URL = "https://api.misfitwearables.com/move/resource/v1/user/me/profile"; - public static void main(String... args) { + public static void main(String... args) throws IOException { // Replace these with your own api key and secret final String apiKey = "your client id"; final String apiSecret = "your client secret"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NeteaseWeiboExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NeteaseWeiboExample.java index 31a210612..08f782b13 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NeteaseWeiboExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NeteaseWeiboExample.java @@ -9,13 +9,14 @@ import com.github.scribejava.core.model.Response; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.oauth.OAuth10aService; +import java.io.IOException; public abstract class NeteaseWeiboExample { private static final String NETWORK_NAME = "NetEase(163.com) Weibo"; private static final String PROTECTED_RESOURCE_URL = "http://api.t.163.com/account/verify_credentials.json"; - public static void main(String... args) { + public static void main(String... args) throws IOException { // Replace these with your own api key and secret final String apiKey = "your key"; final String apiSecret = "your secret"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java index 1900e3f47..9996484a4 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java @@ -8,6 +8,7 @@ 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; public abstract class OdnoklassnikiExample { @@ -15,7 +16,7 @@ public abstract class OdnoklassnikiExample { private static final String PROTECTED_RESOURCE_URL = "https://api.ok.ru/api/users/getCurrentUser?application_key=%1$s&format=JSON"; - public static void main(String... args) { + public static void main(String... args) throws IOException { // Replace these with your client id and secret final String clientId = "your api client id"; final String publicKey = "your api public key"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java index 13f7d77b4..ca0359611 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java @@ -7,6 +7,7 @@ import com.github.scribejava.core.model.Response; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.oauth.OAuth20Service; +import java.io.IOException; import java.util.Scanner; @@ -14,7 +15,7 @@ public abstract class PinterestExample { private static final String PROTECTED_RESOURCE_URL = "https://api.pinterest.com/v1/me/?access_token?access_token="; - public static void main(String... args) { + public static void main(String... args) throws IOException { // Replace these with your own api key and secret final String apiKey = "your_app_id"; final String apiSecret = "your_app_secret"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Px500Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Px500Example.java index 458aea185..4fbda56ff 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Px500Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Px500Example.java @@ -9,12 +9,13 @@ import com.github.scribejava.core.model.Response; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.oauth.OAuth10aService; +import java.io.IOException; public abstract class Px500Example { private static final String PROTECTED_RESOURCE_URL = "https://api.500px.com/v1/"; - public static void main(String... args) { + public static void main(String... args) throws IOException { final OAuth10aService service = new ServiceBuilder() .apiKey("your-api-key") .apiSecret("your-api-secret") diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java index 75f132a4b..42f99eb6d 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java @@ -17,13 +17,14 @@ 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; public abstract class RenrenExample { private static final String NETWORK_NAME = "Renren"; private static final String PROTECTED_RESOURCE_URL = "http://api.renren.com/restserver.do"; - public static void main(String... args) { + public static void main(String... args) throws IOException { // Replace these with your own api key and secret final String apiKey = "your api key"; final String apiSecret = "your api secret"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeibo2Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeibo2Example.java index 1a67ad8ed..815f19ba2 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeibo2Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeibo2Example.java @@ -8,13 +8,14 @@ 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; public abstract class SinaWeibo2Example { private static final String NETWORK_NAME = "SinaWeibo"; private static final String PROTECTED_RESOURCE_URL = "https://api.weibo.com/2/account/get_uid.json"; - public static void main(String... args) { + public static void main(String... args) throws IOException { // Replace these with your own api key and secret final String apiKey = "your_api_key"; final String apiSecret = "your_api_secret"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeiboExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeiboExample.java index 1d8625059..8c3fccbd7 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeiboExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeiboExample.java @@ -9,13 +9,14 @@ import com.github.scribejava.core.model.Response; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.oauth.OAuth10aService; +import java.io.IOException; public abstract class SinaWeiboExample { private static final String NETWORK_NAME = "SinaWeibo"; private static final String PROTECTED_RESOURCE_URL = "http://api.t.sina.com.cn/account/verify_credentials.json"; - public static void main(String... args) { + public static void main(String... args) throws IOException { // Replace these with your own api key and secret final String apiKey = "your key"; final String apiSecret = "your secret"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SkyrockExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SkyrockExample.java index 121a3da0f..440058d57 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SkyrockExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SkyrockExample.java @@ -9,12 +9,13 @@ import com.github.scribejava.core.model.Response; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.oauth.OAuth10aService; +import java.io.IOException; public abstract class SkyrockExample { private static final String PROTECTED_RESOURCE_URL = "https://api.skyrock.com/v2/user/get.json"; - public static void main(String... args) { + public static void main(String... args) throws IOException { final OAuth10aService service = new ServiceBuilder() .apiKey("your-api-key") .apiSecret("your-api-secret") diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SohuWeiboExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SohuWeiboExample.java index c554208ab..d91829387 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SohuWeiboExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SohuWeiboExample.java @@ -9,13 +9,14 @@ import com.github.scribejava.core.model.Response; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.oauth.OAuth10aService; +import java.io.IOException; public abstract class SohuWeiboExample { private static final String NETWORK_NAME = "SohuWeibo"; private static final String PROTECTED_RESOURCE_URL = "http://api.t.sohu.com/account/verify_credentials.json"; - public static void main(String... args) { + public static void main(String... args) throws IOException { // Replace these with your own api key and secret final String apiKey = "your_key"; final String apiSecret = "your_secret"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/StackExchangeExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/StackExchangeExample.java index affa6a812..d7d2341a2 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/StackExchangeExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/StackExchangeExample.java @@ -10,13 +10,14 @@ 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; public abstract class StackExchangeExample { private static final String NETWORK_NAME = "Stack Exchange"; private static final String PROTECTED_RESOURCE_URL = "https://api.stackexchange.com/2.2/me"; - public static void main(String... args) { + public static void main(String... args) throws IOException { // Replace these with your client id, secret, application key and // optionally site name final String clientId = "your client id"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TrelloExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TrelloExample.java index bc3147b34..a72821cb2 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TrelloExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TrelloExample.java @@ -9,6 +9,7 @@ import com.github.scribejava.core.model.Response; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.oauth.OAuth10aService; +import java.io.IOException; public abstract class TrelloExample { @@ -16,7 +17,7 @@ public abstract class TrelloExample { private static final String API_SECRET = "your_api_secret"; private static final String PROTECTED_RESOURCE_URL = "https://trello.com/1/members/me"; - public static void main(String... args) { + public static void main(String... args) throws IOException { final OAuth10aService service = new ServiceBuilder() .apiKey(API_KEY) .apiSecret(API_SECRET) diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TumblrExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TumblrExample.java index 881cebd6d..10ae13e71 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TumblrExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TumblrExample.java @@ -9,12 +9,13 @@ import com.github.scribejava.core.model.Response; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.oauth.OAuth10aService; +import java.io.IOException; public abstract class TumblrExample { private static final String PROTECTED_RESOURCE_URL = "http://api.tumblr.com/v2/user/info"; - public static void main(String... args) { + public static void main(String... args) throws IOException { final OAuth10aService service = new ServiceBuilder() .apiKey("MY_CONSUMER_KEY") .apiSecret("MY_CONSUMER_SECRET") diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TutByExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TutByExample.java index e8d82d98b..769270d37 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TutByExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TutByExample.java @@ -10,13 +10,14 @@ import com.github.scribejava.apis.TutByApi; import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.oauth.OAuth20Service; +import java.io.IOException; public abstract class TutByExample { private static final String NETWORK_NAME = "Tut.by"; private static final String PROTECTED_RESOURCE_URL = "http://profile.tut.by/getInfo"; - public static void main(String... args) { + public static void main(String... args) throws IOException { // Replace these with your client id and secret final String clientId = "your client id"; final String clientSecret = "your client secret"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TwitterExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TwitterExample.java index 4a46982aa..66d8cefae 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TwitterExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TwitterExample.java @@ -9,12 +9,13 @@ import com.github.scribejava.core.model.Response; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.oauth.OAuth10aService; +import java.io.IOException; public abstract class TwitterExample { private static final String PROTECTED_RESOURCE_URL = "https://api.twitter.com/1.1/account/verify_credentials.json"; - public static void main(String... args) { + public static void main(String... args) throws IOException { final OAuth10aService service = new ServiceBuilder() .apiKey("your client id") .apiSecret("your client secret") diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ViadeoExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ViadeoExample.java index 3d8d12904..1a9887217 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ViadeoExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ViadeoExample.java @@ -8,13 +8,14 @@ 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; public abstract class ViadeoExample { private static final String NETWORK_NAME = "Viadeo"; private static final String PROTECTED_RESOURCE_URL = "https://api.viadeo.com/me?user_detail=full"; - public static void main(String... args) { + public static void main(String... args) throws IOException { // Replace these with your own api key and secret final String apiKey = "your_app_id"; final String apiSecret = "your_api_secret"; 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 f026fbbc0..5e50158bd 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExample.java @@ -8,13 +8,14 @@ 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; public abstract class VkontakteExample { private static final String NETWORK_NAME = "Vkontakte.ru"; private static final String PROTECTED_RESOURCE_URL = "https://api.vk.com/method/users.get"; - public static void main(String... args) { + public static void main(String... args) throws IOException { // Replace these with your client id and secret final String clientId = "your client id"; final String clientSecret = "your client secret"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XingExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XingExample.java index 50ab3c6ba..04a3668fd 100755 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XingExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XingExample.java @@ -9,12 +9,13 @@ import com.github.scribejava.core.model.Response; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.oauth.OAuth10aService; +import java.io.IOException; public abstract class XingExample { private static final String PROTECTED_RESOURCE_URL = "https://api.xing.com/v1/users/me"; - public static void main(String... args) { + public static void main(String... args) throws IOException { final OAuth10aService service = new ServiceBuilder() .apiKey("your client id") .apiSecret("your client secret") diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/YahooExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/YahooExample.java index ee93da83a..3d020d59d 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/YahooExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/YahooExample.java @@ -9,13 +9,14 @@ import com.github.scribejava.core.model.Response; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.oauth.OAuth10aService; +import java.io.IOException; public abstract class YahooExample { private static final String PROTECTED_RESOURCE_URL = "http://social.yahooapis.com/v1/user/A6ROU63MXWDCW3Y5MGCYWVHDJI/profile/status?format=json"; - public static void main(String... args) { + public static void main(String... args) throws IOException { final OAuth10aService service = new ServiceBuilder() .apiKey("your client id") .apiSecret("your client secret") diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/Response.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/Response.java index bce6e584a..869066788 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/Response.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/Response.java @@ -37,7 +37,7 @@ public Response(int code, String message, Map headers, String bo } } - private String parseBodyContents() { + private String parseBodyContents() throws IOException { if ("gzip".equals(getHeader("Content-Encoding"))) { body = StreamUtils.getGzipStreamContents(getStream()); } else { @@ -58,12 +58,7 @@ public final boolean isSuccessful() { return getCode() >= 200 && getCode() < 400; } - /** - * Obtains the HTTP Response body - * - * @return response body - */ - public String getBody() { + public String getBody() throws IOException { return body == null ? parseBodyContents() : body; } 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 186541c39..e707486bc 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 @@ -35,12 +35,7 @@ public OAuth10aService(DefaultApi10a api, OAuthConfig config) { this.api = api; } - /** - * Retrieve the request token. - * - * @return request token - */ - public final OAuth1RequestToken getRequestToken() { + public final OAuth1RequestToken getRequestToken() throws IOException { final OAuthConfig config = getConfig(); config.log("obtaining request token from " + api.getRequestTokenEndpoint()); final OAuthRequest request = new OAuthRequest(api.getRequestTokenVerb(), api.getRequestTokenEndpoint(), this); @@ -95,7 +90,8 @@ private void addOAuthParams(AbstractRequest request, String tokenSecret) { config.log("appended additional OAuth parameters: " + MapUtils.toString(request.getOauthParameters())); } - public final OAuth1AccessToken getAccessToken(OAuth1RequestToken requestToken, String oauthVerifier) { + public final OAuth1AccessToken getAccessToken(OAuth1RequestToken requestToken, String oauthVerifier) + throws IOException { final OAuthConfig config = getConfig(); config.log("obtaining access token from " + api.getAccessTokenEndpoint()); final OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint(), this); 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 b9efbf0f3..43bf4c7fa 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 @@ -33,7 +33,7 @@ public OAuth20Service(DefaultApi20 api, OAuthConfig config) { } //sync version, protected to facilitate mocking - protected OAuth2AccessToken sendAccessTokenRequestSync(OAuthRequest request) { + protected OAuth2AccessToken sendAccessTokenRequestSync(OAuthRequest request) throws IOException { return api.getAccessTokenExtractor().extract(request.send().getBody()); } @@ -49,7 +49,7 @@ public OAuth2AccessToken convert(Response response) throws IOException { }); } - public final OAuth2AccessToken getAccessToken(String code) { + public final OAuth2AccessToken getAccessToken(String code) throws IOException { final OAuthRequest request = createAccessTokenRequest(code, new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint(), this)); @@ -86,7 +86,7 @@ protected T createAccessTokenRequest(String code, T return request; } - public final OAuth2AccessToken refreshAccessToken(String refreshToken) { + public final OAuth2AccessToken refreshAccessToken(String refreshToken) throws IOException { final OAuthRequest request = createRefreshTokenRequest(refreshToken, new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint(), this)); @@ -113,14 +113,7 @@ protected T createRefreshTokenRequest(String refresh return request; } - /** - * Request Access Token Password Grant sync version - * - * @param uname User name - * @param password User password - * @return OAuth2AccessToken - */ - public final OAuth2AccessToken getAccessTokenPasswordGrant(String uname, String password) { + public final OAuth2AccessToken getAccessTokenPasswordGrant(String uname, String password) throws IOException { final OAuthRequest request = createAccessTokenPasswordGrantRequest(uname, password, new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint(), this)); diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/utils/StreamUtils.java b/scribejava-core/src/main/java/com/github/scribejava/core/utils/StreamUtils.java index 93d089489..65cea62ee 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/utils/StreamUtils.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/utils/StreamUtils.java @@ -16,25 +16,22 @@ public abstract class StreamUtils { * * @param is input stream * @return string contents + * @throws java.io.IOException */ - public static String getStreamContents(InputStream is) { + public static String getStreamContents(InputStream is) throws IOException { Preconditions.checkNotNull(is, "Cannot get String from a null object"); - try { - final char[] buffer = new char[0x10000]; - final StringBuilder out = new StringBuilder(); - try (Reader in = new InputStreamReader(is, "UTF-8")) { - int read; - do { - read = in.read(buffer, 0, buffer.length); - if (read > 0) { - out.append(buffer, 0, read); - } - } while (read >= 0); - } - return out.toString(); - } catch (IOException ioe) { - throw new IllegalStateException("Error while reading response body", ioe); + final char[] buffer = new char[0x10000]; + final StringBuilder out = new StringBuilder(); + try (Reader in = new InputStreamReader(is, "UTF-8")) { + int read; + do { + read = in.read(buffer, 0, buffer.length); + if (read > 0) { + out.append(buffer, 0, read); + } + } while (read >= 0); } + return out.toString(); } /** @@ -42,14 +39,11 @@ public static String getStreamContents(InputStream is) { * * @param is input stream * @return string contents + * @throws java.io.IOException */ - public static String getGzipStreamContents(InputStream is) { + public static String getGzipStreamContents(InputStream is) throws IOException { Preconditions.checkNotNull(is, "Cannot get String from a null object"); - try { - final GZIPInputStream gis = new GZIPInputStream(is); - return getStreamContents(gis); - } catch (IOException ioe) { - throw new IllegalStateException("Error while reading response body", ioe); - } + final GZIPInputStream gis = new GZIPInputStream(is); + return getStreamContents(gis); } } diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/model/ResponseTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/model/ResponseTest.java index c4fe5712f..1f7b0a4fe 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/model/ResponseTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/model/ResponseTest.java @@ -28,13 +28,13 @@ public void shouldPopulateResponseHeaders() { } @Test - public void shouldParseBodyContents() { + public void shouldParseBodyContents() throws IOException { assertEquals("contents", response.getBody()); assertEquals(1, connection.getTimesCalledInpuStream()); } @Test - public void shouldParseBodyContentsOnlyOnce() { + public void shouldParseBodyContentsOnlyOnce() throws IOException { assertEquals("contents", response.getBody()); assertEquals("contents", response.getBody()); assertEquals("contents", response.getBody()); 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 17c58087f..050b0ae4d 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 @@ -7,6 +7,7 @@ import com.github.scribejava.core.services.Base64Encoder; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; +import java.io.IOException; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertEquals; import org.junit.Test; @@ -18,7 +19,7 @@ public class OAuth20ServiceTest { @Test - public void shouldProduceCorrectRequestSync() { + public void shouldProduceCorrectRequestSync() throws IOException { final OAuth20Service service = new ServiceBuilder() .apiKey("your_api_key") .apiSecret("your_api_secret") 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 322283d23..cb5c6c7c9 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 @@ -20,7 +20,7 @@ public int read() throws IOException { } @Test - public void shouldCorrectlyDecodeAStream() { + public void shouldCorrectlyDecodeAStream() throws IOException { final String value = "expected"; final InputStream is = new ByteArrayInputStream(value.getBytes()); final String decoded = StreamUtils.getStreamContents(is); @@ -28,13 +28,13 @@ public void shouldCorrectlyDecodeAStream() { } @Test(expected = IllegalArgumentException.class) - public void shouldFailForNullParameter() { + public void shouldFailForNullParameter() throws IOException { StreamUtils.getStreamContents(null); fail("Must throw exception before getting here"); } - @Test(expected = IllegalStateException.class) - public void shouldFailWithBrokenStream() { + @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"); From 36dc0f663558541102011908e8b878bed1582d6d Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 8 Jun 2016 15:47:00 +0300 Subject: [PATCH 215/882] update some dependencies --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index e4aa054f5..1b3bde7d0 100644 --- a/pom.xml +++ b/pom.xml @@ -102,7 +102,7 @@ org.asynchttpclient async-http-client - 2.0.3 + 2.0.4 provided @@ -211,7 +211,7 @@ com.puppycrawl.tools checkstyle - 6.18 + 6.19 From 86d59c209e8fddd006e4a75a99e81e822e2d44b2 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 8 Jun 2016 15:53:54 +0300 Subject: [PATCH 216/882] prepare 2.7.1 release --- README.md | 4 ++-- changelog | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 6fac2c8ce..a75bb1a9b 100644 --- a/README.md +++ b/README.md @@ -85,7 +85,7 @@ You can pull ScribeJava from the central maven repository, just add these to you com.github.scribejava scribejava-apis - 2.7.0 + 2.7.1 ``` @@ -94,7 +94,7 @@ And in case you need just core classes (that's it, without any external API (FB, com.github.scribejava scribejava-core - 2.7.0 + 2.7.1 ``` diff --git a/changelog b/changelog index cbf92b6da..70d1a8b87 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,4 @@ -[SNAPSHOT] +[2.7.1] * do not hide checked IOException in unchecked IllegalArgumentException [2.7.0] From de5fef31ec803abc4684b2e91554c774d44fe976 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 8 Jun 2016 15:54:50 +0300 Subject: [PATCH 217/882] [maven-release-plugin] prepare release scribejava-2.7.1 --- pom.xml | 2 +- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 1b3bde7d0..dc799268f 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 2.7.1-SNAPSHOT + 2.7.1 ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index c2de94306..370dea0a8 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 2.7.1-SNAPSHOT + 2.7.1 ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index c6b9b52ca..03d7552e8 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 2.7.1-SNAPSHOT + 2.7.1 ../pom.xml From 42deb8da74e8ae321be4c070cac1c823e7edff0c Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 8 Jun 2016 15:54:55 +0300 Subject: [PATCH 218/882] [maven-release-plugin] prepare for next development iteration --- pom.xml | 2 +- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index dc799268f..465f2c181 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 2.7.1 + 2.7.2-SNAPSHOT ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 370dea0a8..81a290229 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 2.7.1 + 2.7.2-SNAPSHOT ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 03d7552e8..ba553129a 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 2.7.1 + 2.7.2-SNAPSHOT ../pom.xml From d34c3b0d457f9d8278cd4b7c26a3c7f35ef655e3 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 8 Jun 2016 19:42:04 +0300 Subject: [PATCH 219/882] ScribeJava shouldn't require any async http client provider to be on the classpath (neither ning neither AHC) --- changelog | 3 + .../scribejava/core/oauth/OAuthService.java | 138 ++++++++++-------- .../scribejava/core/utils/StreamUtils.java | 4 +- 3 files changed, 83 insertions(+), 62 deletions(-) diff --git a/changelog b/changelog index 70d1a8b87..0140e0565 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,6 @@ +[SNAPSHOT] + * FIX: ScribeJava shouldn't require any async http client provider to be on the classpath (neither ning neither AHC) + [2.7.1] * do not hide checked IOException in unchecked IllegalArgumentException diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java index f6922224e..47b40b497 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java @@ -49,13 +49,10 @@ public OAuthService(OAuthConfig config) { } if (ahcConfig == null) { - final String ningAsyncHttpProviderClassName = config.getNingAsyncHttpProviderClassName(); - ningAsyncHttpClient = ningAsyncHttpProviderClassName == null - ? new com.ning.http.client.AsyncHttpClient(ningConfig) - : new com.ning.http.client.AsyncHttpClient(ningAsyncHttpProviderClassName, ningConfig); + ningAsyncHttpClient = NingProvider.createClient(config.getNingAsyncHttpProviderClassName(), ningConfig); ahcAsyncHttpClient = null; } else { - ahcAsyncHttpClient = new org.asynchttpclient.DefaultAsyncHttpClient(ahcConfig); + ahcAsyncHttpClient = AHCProvider.createClient(ahcConfig); ningAsyncHttpClient = null; } } @@ -84,72 +81,93 @@ public Future executeAsync(Map headers, Verb httpVerb, St String bodyContents, OAuthAsyncRequestCallback callback, OAuthRequestAsync.ResponseConverter converter) { if (ahcAsyncHttpClient == null) { - return ningExecuteAsync(headers, httpVerb, completeUrl, bodyContents, callback, converter); + return NingProvider.ningExecuteAsync(ningAsyncHttpClient, config.getUserAgent(), headers, httpVerb, + completeUrl, bodyContents, callback, converter); } else { - return ahcExecuteAsync(headers, httpVerb, completeUrl, bodyContents, callback, converter); + return AHCProvider.ahcExecuteAsync(ahcAsyncHttpClient, config.getUserAgent(), headers, httpVerb, + completeUrl, bodyContents, callback, converter); } } - private Future ningExecuteAsync(Map headers, Verb httpVerb, String completeUrl, - String bodyContents, OAuthAsyncRequestCallback callback, - OAuthRequestAsync.ResponseConverter converter) { - final com.ning.http.client.AsyncHttpClient.BoundRequestBuilder boundRequestBuilder; - switch (httpVerb) { - case GET: - boundRequestBuilder = ningAsyncHttpClient.prepareGet(completeUrl); - break; - case POST: - com.ning.http.client.AsyncHttpClient.BoundRequestBuilder requestBuilder - = ningAsyncHttpClient.preparePost(completeUrl); - if (!headers.containsKey(AbstractRequest.CONTENT_TYPE)) { - requestBuilder = requestBuilder.addHeader(AbstractRequest.CONTENT_TYPE, DEFAULT_CONTENT_TYPE); - } - boundRequestBuilder = requestBuilder.setBody(bodyContents); - break; - default: - throw new IllegalArgumentException("message build error: unknown verb type"); - } + private static class NingProvider { - for (Map.Entry header : headers.entrySet()) { - boundRequestBuilder.addHeader(header.getKey(), header.getValue()); - } - final String userAgent = config.getUserAgent(); - if (userAgent != null) { - boundRequestBuilder.setHeader(OAuthConstants.USER_AGENT_HEADER_NAME, userAgent); + private static com.ning.http.client.AsyncHttpClient createClient(String ningAsyncHttpProviderClassName, + com.ning.http.client.AsyncHttpClientConfig ningConfig) { + return ningAsyncHttpProviderClassName == null + ? new com.ning.http.client.AsyncHttpClient(ningConfig) + : new com.ning.http.client.AsyncHttpClient(ningAsyncHttpProviderClassName, ningConfig); } - return boundRequestBuilder - .execute(new com.github.scribejava.core.async.ning.OAuthAsyncCompletionHandler<>(callback, converter)); - } + private static Future ningExecuteAsync(com.ning.http.client.AsyncHttpClient ningAsyncHttpClient, + String userAgent, Map headers, Verb httpVerb, String completeUrl, String bodyContents, + OAuthAsyncRequestCallback callback, OAuthRequestAsync.ResponseConverter converter) { + final com.ning.http.client.AsyncHttpClient.BoundRequestBuilder boundRequestBuilder; + switch (httpVerb) { + case GET: + boundRequestBuilder = ningAsyncHttpClient.prepareGet(completeUrl); + break; + case POST: + com.ning.http.client.AsyncHttpClient.BoundRequestBuilder requestBuilder + = ningAsyncHttpClient.preparePost(completeUrl); + if (!headers.containsKey(AbstractRequest.CONTENT_TYPE)) { + requestBuilder = requestBuilder.addHeader(AbstractRequest.CONTENT_TYPE, DEFAULT_CONTENT_TYPE); + } + boundRequestBuilder = requestBuilder.setBody(bodyContents); + break; + default: + throw new IllegalArgumentException("message build error: unknown verb type"); + } - private Future ahcExecuteAsync(Map headers, Verb httpVerb, String completeUrl, - String bodyContents, OAuthAsyncRequestCallback callback, - OAuthRequestAsync.ResponseConverter converter) { - final org.asynchttpclient.BoundRequestBuilder boundRequestBuilder; - switch (httpVerb) { - case GET: - boundRequestBuilder = ahcAsyncHttpClient.prepareGet(completeUrl); - break; - case POST: - org.asynchttpclient.BoundRequestBuilder requestBuilder = ahcAsyncHttpClient.preparePost(completeUrl); - if (!headers.containsKey(AbstractRequest.CONTENT_TYPE)) { - requestBuilder = requestBuilder.addHeader(AbstractRequest.CONTENT_TYPE, DEFAULT_CONTENT_TYPE); - } - boundRequestBuilder = requestBuilder.setBody(bodyContents); - break; - default: - throw new IllegalArgumentException("message build error: unknown verb type"); - } + for (Map.Entry header : headers.entrySet()) { + boundRequestBuilder.addHeader(header.getKey(), header.getValue()); + } + if (userAgent != null) { + boundRequestBuilder.setHeader(OAuthConstants.USER_AGENT_HEADER_NAME, userAgent); + } - for (Map.Entry header : headers.entrySet()) { - boundRequestBuilder.addHeader(header.getKey(), header.getValue()); + return boundRequestBuilder + .execute(new com.github.scribejava.core.async.ning.OAuthAsyncCompletionHandler<>( + callback, converter)); } - final String userAgent = config.getUserAgent(); - if (userAgent != null) { - boundRequestBuilder.setHeader(OAuthConstants.USER_AGENT_HEADER_NAME, userAgent); + } + + private static class AHCProvider { + + private static org.asynchttpclient.AsyncHttpClient createClient( + org.asynchttpclient.AsyncHttpClientConfig ahcConfig) { + return new org.asynchttpclient.DefaultAsyncHttpClient(ahcConfig); } - return boundRequestBuilder - .execute(new com.github.scribejava.core.async.ahc.OAuthAsyncCompletionHandler<>(callback, converter)); + private static Future ahcExecuteAsync(org.asynchttpclient.AsyncHttpClient ahcAsyncHttpClient, + String userAgent, Map headers, Verb httpVerb, String completeUrl, String bodyContents, + OAuthAsyncRequestCallback callback, OAuthRequestAsync.ResponseConverter converter) { + final org.asynchttpclient.BoundRequestBuilder boundRequestBuilder; + switch (httpVerb) { + case GET: + boundRequestBuilder = ahcAsyncHttpClient.prepareGet(completeUrl); + break; + case POST: + org.asynchttpclient.BoundRequestBuilder requestBuilder + = ahcAsyncHttpClient.preparePost(completeUrl); + if (!headers.containsKey(AbstractRequest.CONTENT_TYPE)) { + requestBuilder = requestBuilder.addHeader(AbstractRequest.CONTENT_TYPE, DEFAULT_CONTENT_TYPE); + } + boundRequestBuilder = requestBuilder.setBody(bodyContents); + break; + default: + throw new IllegalArgumentException("message build error: unknown verb type"); + } + + for (Map.Entry header : headers.entrySet()) { + boundRequestBuilder.addHeader(header.getKey(), header.getValue()); + } + if (userAgent != null) { + boundRequestBuilder.setHeader(OAuthConstants.USER_AGENT_HEADER_NAME, userAgent); + } + + return boundRequestBuilder + .execute(new com.github.scribejava.core.async.ahc.OAuthAsyncCompletionHandler<>( + callback, converter)); + } } } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/utils/StreamUtils.java b/scribejava-core/src/main/java/com/github/scribejava/core/utils/StreamUtils.java index 65cea62ee..7a86318d2 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/utils/StreamUtils.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/utils/StreamUtils.java @@ -16,7 +16,7 @@ public abstract class StreamUtils { * * @param is input stream * @return string contents - * @throws java.io.IOException + * @throws java.io.IOException in any. SocketTimeout in example */ public static String getStreamContents(InputStream is) throws IOException { Preconditions.checkNotNull(is, "Cannot get String from a null object"); @@ -39,7 +39,7 @@ public static String getStreamContents(InputStream is) throws IOException { * * @param is input stream * @return string contents - * @throws java.io.IOException + * @throws java.io.IOException in any. SocketTimeout in example */ public static String getGzipStreamContents(InputStream is) throws IOException { Preconditions.checkNotNull(is, "Cannot get String from a null object"); From f04b458b38200eed3a88a39d851464874fdecb40 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 8 Jun 2016 19:50:34 +0300 Subject: [PATCH 220/882] prepare 2.7.2 release --- README.md | 4 ++-- changelog | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index a75bb1a9b..9e8c0ba2d 100644 --- a/README.md +++ b/README.md @@ -85,7 +85,7 @@ You can pull ScribeJava from the central maven repository, just add these to you com.github.scribejava scribejava-apis - 2.7.1 + 2.7.2 ``` @@ -94,7 +94,7 @@ And in case you need just core classes (that's it, without any external API (FB, com.github.scribejava scribejava-core - 2.7.1 + 2.7.2 ``` diff --git a/changelog b/changelog index 0140e0565..8dcb9f891 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,4 @@ -[SNAPSHOT] +[2.7.2] * FIX: ScribeJava shouldn't require any async http client provider to be on the classpath (neither ning neither AHC) [2.7.1] From 7b7aedf586d131d88ac0d50d14390314bc386ae1 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 8 Jun 2016 19:51:19 +0300 Subject: [PATCH 221/882] [maven-release-plugin] prepare release scribejava-2.7.2 --- pom.xml | 2 +- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 465f2c181..cd6670a82 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 2.7.2-SNAPSHOT + 2.7.2 ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 81a290229..93923ad1f 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 2.7.2-SNAPSHOT + 2.7.2 ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index ba553129a..2ca766e51 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 2.7.2-SNAPSHOT + 2.7.2 ../pom.xml From 11b76c4fcec553f0452e288bf807af53ac599d3a Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 8 Jun 2016 19:51:25 +0300 Subject: [PATCH 222/882] [maven-release-plugin] prepare for next development iteration --- pom.xml | 2 +- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index cd6670a82..d7e832f02 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 2.7.2 + 2.7.3-SNAPSHOT ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 93923ad1f..15b9fd5e6 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 2.7.2 + 2.7.3-SNAPSHOT ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 2ca766e51..a84868b76 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 2.7.2 + 2.7.3-SNAPSHOT ../pom.xml From 96217e534a46926e7e6f00dceb1ed4512c795699 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 9 Jun 2016 18:06:04 +0300 Subject: [PATCH 223/882] FIX: ScribeJava shouldn't require all async http client provider to be on the classpath if using only one of them --- changelog | 3 +++ .../apis/examples/FacebookAsyncNingExample.java | 2 +- .../apis/examples/Google20AsyncAHCExample.java | 2 +- .../apis/examples/MailruAsyncExample.java | 2 +- .../scribejava/core/builder/ServiceBuilder.java | 16 ++++++++-------- 5 files changed, 14 insertions(+), 11 deletions(-) diff --git a/changelog b/changelog index 8dcb9f891..2f776a80f 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,6 @@ +[SNAPSHOT] + * FIX: ScribeJava shouldn't require all async http client provider to be on the classpath if using only one of them + [2.7.2] * FIX: ScribeJava shouldn't require any async http client provider to be on the classpath (neither ning neither AHC) diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java index ae0d1d09a..373759c35 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java @@ -39,7 +39,7 @@ public static void main(String... args) throws InterruptedException, ExecutionEx .apiSecret(clientSecret) .state(secretState) .callback("http://www.example.com/oauth_callback/") - .asyncHttpClientConfig(clientConfig) + .asyncNingHttpClientConfig(clientConfig) .build(FacebookApi.instance()); final Scanner in = new Scanner(System.in, "UTF-8"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java index bfd88430a..6ad067acf 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java @@ -42,7 +42,7 @@ public static void main(String... args) throws InterruptedException, ExecutionEx .scope("profile") // replace with desired scope .state(secretState) .callback("http://example.com/callback") - .asyncHttpClientConfig(clientConfig) + .asyncAHCHttpClientConfig(clientConfig) .build(GoogleApi20.instance()); final Scanner in = new Scanner(System.in, "UTF-8"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java index c53e5d856..6ca98d697 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java @@ -35,7 +35,7 @@ public static void main(String... args) throws InterruptedException, ExecutionEx .apiKey(clientId) .apiSecret(clientSecret) .callback("http://www.example.com/oauth_callback/") - .asyncHttpClientConfig(clientConfig) + .asyncNingHttpClientConfig(clientConfig) .build(MailruApi.instance()); final Scanner in = new Scanner(System.in, "UTF-8"); 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 57f99cc0a..12195ab56 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 @@ -135,14 +135,20 @@ public ServiceBuilder readTimeout(Integer readTimeout) { return this; } - public ServiceBuilder asyncHttpClientConfig(com.ning.http.client.AsyncHttpClientConfig asyncHttpClientConfig) { + public ServiceBuilder asyncNingHttpClientConfig(com.ning.http.client.AsyncHttpClientConfig asyncHttpClientConfig) { Preconditions.checkNotNull(asyncHttpClientConfig, "asyncHttpClientConfig can't be null"); ningAsyncHttpClientConfig = asyncHttpClientConfig; ahcAsyncHttpClientConfig = null; return this; } - public ServiceBuilder asyncHttpClientConfig(org.asynchttpclient.AsyncHttpClientConfig asyncHttpClientConfig) { + public ServiceBuilder asyncNingHttpProviderClassName(String asyncHttpProviderClassName) { + this.ningAsyncHttpProviderClassName = asyncHttpProviderClassName; + ahcAsyncHttpClientConfig = null; + return this; + } + + public ServiceBuilder asyncAHCHttpClientConfig(org.asynchttpclient.AsyncHttpClientConfig asyncHttpClientConfig) { Preconditions.checkNotNull(asyncHttpClientConfig, "asyncHttpClientConfig can't be null"); ahcAsyncHttpClientConfig = asyncHttpClientConfig; ningAsyncHttpClientConfig = null; @@ -150,12 +156,6 @@ public ServiceBuilder asyncHttpClientConfig(org.asynchttpclient.AsyncHttpClientC return this; } - public ServiceBuilder asyncHttpProviderClassName(String asyncHttpProviderClassName) { - this.ningAsyncHttpProviderClassName = asyncHttpProviderClassName; - ahcAsyncHttpClientConfig = null; - return this; - } - public ServiceBuilder userAgent(String userAgent) { this.userAgent = userAgent; return this; From 7830badc8780793be0f3e87983f7c82881da0c48 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 9 Jun 2016 18:11:23 +0300 Subject: [PATCH 224/882] prepare 2.7.3 release --- README.md | 4 ++-- changelog | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 9e8c0ba2d..f1706f4cb 100644 --- a/README.md +++ b/README.md @@ -85,7 +85,7 @@ You can pull ScribeJava from the central maven repository, just add these to you com.github.scribejava scribejava-apis - 2.7.2 + 2.7.3 ``` @@ -94,7 +94,7 @@ And in case you need just core classes (that's it, without any external API (FB, com.github.scribejava scribejava-core - 2.7.2 + 2.7.3 ``` diff --git a/changelog b/changelog index 2f776a80f..43f21ea34 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,4 @@ -[SNAPSHOT] +[2.7.3] * FIX: ScribeJava shouldn't require all async http client provider to be on the classpath if using only one of them [2.7.2] From d9554a6492b0039f37265420c0be5724f805f91c Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 9 Jun 2016 18:12:04 +0300 Subject: [PATCH 225/882] [maven-release-plugin] prepare release scribejava-2.7.3 --- pom.xml | 2 +- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index d7e832f02..ba96fe26f 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 2.7.3-SNAPSHOT + 2.7.3 ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 15b9fd5e6..385bebf7f 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 2.7.3-SNAPSHOT + 2.7.3 ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index a84868b76..c466b1e37 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 2.7.3-SNAPSHOT + 2.7.3 ../pom.xml From 8865ea15c1edf9e5a9fa196e3e54c5ac01543b8e Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 9 Jun 2016 18:12:11 +0300 Subject: [PATCH 226/882] [maven-release-plugin] prepare for next development iteration --- pom.xml | 2 +- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index ba96fe26f..723b1b5e1 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 2.7.3 + 2.7.4-SNAPSHOT ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 385bebf7f..465b17303 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 2.7.3 + 2.7.4-SNAPSHOT ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index c466b1e37..50e937547 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 2.7.3 + 2.7.4-SNAPSHOT ../pom.xml From 36940c4eae90c51cd25c398422a576a64e1cff75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Winkelmeyer?= Date: Fri, 10 Jun 2016 11:22:23 -0700 Subject: [PATCH 227/882] Addes API provider for Salesforce --- .../github/scribejava/apis/SalesforceApi.java | 72 ++++++++++++++ .../SalesforceJsonTokenExtractor.java | 31 ++++++ .../apis/salesforce/SalesforceToken.java | 81 ++++++++++++++++ .../apis/examples/SalesforceExample.java | 95 +++++++++++++++++++ 4 files changed, 279 insertions(+) create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/SalesforceApi.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/salesforce/SalesforceJsonTokenExtractor.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/salesforce/SalesforceToken.java create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceExample.java diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/SalesforceApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/SalesforceApi.java new file mode 100644 index 000000000..08f814c92 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/SalesforceApi.java @@ -0,0 +1,72 @@ +package com.github.scribejava.apis; + +import java.security.KeyManagementException; +import java.security.NoSuchAlgorithmException; + +import javax.net.ssl.HttpsURLConnection; +import javax.net.ssl.SSLContext; + +import com.github.scribejava.apis.salesforce.SalesforceJsonTokenExtractor; + +/** + * This class is an implementation of the Salesforce OAuth2 API. + */ + +import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.extractors.TokenExtractor; +import com.github.scribejava.core.model.OAuth2AccessToken; +import com.github.scribejava.core.model.Verb; + +public class SalesforceApi extends DefaultApi20 { + + // Constants + private static final String BASE_URL = "https://login.salesforce.com/services/oauth2"; + private static final String ACCESS_URL = BASE_URL + "/token?grant_type=authorization_code"; + private static final String AUTHORIZE_URL = BASE_URL + "/authorize"; + + protected SalesforceApi() { + SSLContext sc; + try { + String protocol = SSLContext.getDefault().getProtocol(); + if (!protocol.equals("TLSv1.2") || !protocol.equals("TLSv1.1")) { // This is important! + sc = SSLContext.getInstance("TLSv1.2"); + sc.init(null, null, null); + HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); + } + } catch (NoSuchAlgorithmException e) { + e.printStackTrace(); + } + catch (KeyManagementException e) { + e.printStackTrace(); + } + } + + private static class InstanceHolder { + private static final SalesforceApi INSTANCE = new SalesforceApi(); + } + + public static SalesforceApi instance() { + return InstanceHolder.INSTANCE; + } + + @Override + public Verb getAccessTokenVerb(){ + return Verb.POST; + } + + @Override + public String getAccessTokenEndpoint() { + return ACCESS_URL; + } + + @Override + protected String getAuthorizationBaseUrl() { + return AUTHORIZE_URL; + } + + @Override + public TokenExtractor getAccessTokenExtractor() { + return SalesforceJsonTokenExtractor.instance(); + } + +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/salesforce/SalesforceJsonTokenExtractor.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/salesforce/SalesforceJsonTokenExtractor.java new file mode 100644 index 000000000..6b5f612c1 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/salesforce/SalesforceJsonTokenExtractor.java @@ -0,0 +1,31 @@ +package com.github.scribejava.apis.salesforce; + +import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; +import com.github.scribejava.core.model.OAuth2AccessToken; + +/** + * This extractor parses in addition to the standard Extractor the instance_url of the used Salesforce organization. + */ +public class SalesforceJsonTokenExtractor extends OAuth2AccessTokenJsonExtractor { + + private static final String INSTANCE_URL_REGEX = "\"instance_url\"\\s*:\\s*\"(\\S*?)\""; + + protected SalesforceJsonTokenExtractor() { + } + + private static class InstanceHolder { + + private static final SalesforceJsonTokenExtractor INSTANCE = new SalesforceJsonTokenExtractor(); + } + + public static SalesforceJsonTokenExtractor instance() { + return InstanceHolder.INSTANCE; + } + + @Override + protected OAuth2AccessToken createToken(String accessToken, String tokenType, Integer expiresIn, + String refreshToken, String scope, String response) { + return new SalesforceToken(accessToken, tokenType, expiresIn, refreshToken, scope, + extractParameter(response, INSTANCE_URL_REGEX, true), response); + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/salesforce/SalesforceToken.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/salesforce/SalesforceToken.java new file mode 100644 index 000000000..ae9e84b24 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/salesforce/SalesforceToken.java @@ -0,0 +1,81 @@ +package com.github.scribejava.apis.salesforce; + +import com.github.scribejava.core.model.OAuth2AccessToken; +import java.util.Objects; + +public class SalesforceToken extends OAuth2AccessToken { + + private static final long serialVersionUID = 7845679917727899612L; + + /** + * This token model includes the instance_url to address the needed Salesforce organization instance. + */ + private final String instanceUrl; + + public SalesforceToken(String accessToken, String instanceUrl, String rawResponse) { + this(accessToken, null, null, null, null, instanceUrl, rawResponse); + } + + public SalesforceToken(String accessToken, String tokenType, Integer expiresIn, String refreshToken, String scope, + String instanceUrl, String rawResponse) { + super(accessToken, tokenType, expiresIn, refreshToken, scope, rawResponse); + this.instanceUrl = instanceUrl; + } + + public String getInstanceUrl() { + return instanceUrl; + } + + @Override + public int hashCode() { + int hash = 5; + hash = 37 * hash + Objects.hashCode(getAccessToken()); + hash = 37 * hash + Objects.hashCode(getTokenType()); + hash = 37 * hash + Objects.hashCode(getExpiresIn()); + hash = 37 * hash + Objects.hashCode(getRefreshToken()); + hash = 37 * hash + Objects.hashCode(getScope()); + hash = 37 * hash + Objects.hashCode(getInstanceUrl()); + 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 SalesforceToken other = (SalesforceToken) obj; + if (!Objects.equals(getAccessToken(), other.getAccessToken())) { + return false; + } + if (!Objects.equals(getTokenType(), other.getTokenType())) { + return false; + } + if (!Objects.equals(getRefreshToken(), other.getRefreshToken())) { + return false; + } + if (!Objects.equals(getScope(), other.getScope())) { + return false; + } + if (!Objects.equals(instanceUrl, other.getInstanceUrl())) { + return false; + } + return Objects.equals(getExpiresIn(), other.getExpiresIn()); + } + + @Override + public String toString() { + return "SalesforceToken{" + + "access_token=" + getAccessToken() + + ", token_type=" + getTokenType() + + ", expires_in=" + getExpiresIn() + + ", refresh_token=" + getRefreshToken() + + ", scope=" + getScope() + + ", instance_url=" + instanceUrl + '}'; + } +} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceExample.java new file mode 100644 index 000000000..56e818294 --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceExample.java @@ -0,0 +1,95 @@ +package com.github.scribejava.apis.examples; + +import java.io.UnsupportedEncodingException; +import java.net.URLDecoder; +import java.net.URLEncoder; +import java.util.Scanner; + +import com.github.scribejava.core.builder.ServiceBuilder; +import com.github.scribejava.apis.SalesforceApi; +import com.github.scribejava.apis.salesforce.SalesforceToken; +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 SalesforceExample { + + private static final String NETWORK_NAME = "Salesforce"; + + public static void main(String[] args) { + // Replace these with your client id and secret + final String clientId = "your client id"; + final String clientSecret = "your client secret"; + final OAuth20Service service = new ServiceBuilder() + .apiKey(clientId) + .apiSecret(clientSecret) + .callback("https://www.example.com/callback") // Salesforce only accepts secured callbacks + .build(SalesforceApi.instance()); + final Scanner in = new Scanner(System.in); + + System.out.println("=== " + NETWORK_NAME + "'s OAuth20 Workflow ==="); + System.out.println(); + + // Obtain the Authorization URL + System.out.println("Fetching the Authorization URL..."); + final String authorizationUrl = service.getAuthorizationUrl(); + System.out.println("Got the Authorization URL!"); + System.out.println("Now go and authorize ScribeJava here:"); + System.out.println(authorizationUrl); + System.out.println("And paste the authorization code here"); + System.out.print(">>"); + final String code = in.nextLine(); + System.out.println(); + in.close(); + + String codeEncoded = code; + + // The code needs to be URL decoded + try { + codeEncoded = URLDecoder.decode(code, "UTF-8"); + } catch (UnsupportedEncodingException e1) { + e1.printStackTrace(); + } + + // Trade the Request Token and Verifier for the Access Token + System.out.println("Trading the Request Token for an Access Token..."); + final SalesforceToken accessToken = (SalesforceToken) service.getAccessToken(codeEncoded); + System.out.println("Got the Access Token!"); + System.out.println("(if your curious it looks like this: " + accessToken + + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println(); + + System.out.println("Instance is: " + accessToken.getInstanceUrl()); + + // Now let's go and ask for a protected resource! + System.out.println("Now we're reading accounts from the Salesforce org (maxing them to 10)."); + + // Sample SOQL statement + String queryEncoded = "Select Id, Name from Account LIMIT 10"; + + try { + queryEncoded = URLEncoder.encode(queryEncoded, "UTF-8"); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + queryEncoded = ""; + } + + if (!queryEncoded.isEmpty()) { + // Building the query URI. We've parsed the instance URL from the accessToken request. + String url = accessToken.getInstanceUrl() + "/services/data/v36.0/query?q=" + queryEncoded; + + System.out.println(); + System.out.println("Full URL: " + url); + + final OAuthRequest request = new OAuthRequest(Verb.GET, url, service); + request.addHeader("Authorization", "Bearer " + accessToken.getAccessToken()); + final Response response = request.send(); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + } + + + } +} From d27b48ebbd83b0474b307d0964f1d966e27247a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Winkelmeyer?= Date: Tue, 14 Jun 2016 11:57:08 +0200 Subject: [PATCH 228/882] Changed variable calls to getters --- .../github/scribejava/apis/salesforce/SalesforceToken.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/salesforce/SalesforceToken.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/salesforce/SalesforceToken.java index ae9e84b24..6f6961e83 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/salesforce/SalesforceToken.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/salesforce/SalesforceToken.java @@ -62,7 +62,7 @@ public boolean equals(Object obj) { if (!Objects.equals(getScope(), other.getScope())) { return false; } - if (!Objects.equals(instanceUrl, other.getInstanceUrl())) { + if (!Objects.equals(getInstanceUrl(), other.getInstanceUrl())) { return false; } return Objects.equals(getExpiresIn(), other.getExpiresIn()); @@ -76,6 +76,6 @@ public String toString() { + ", expires_in=" + getExpiresIn() + ", refresh_token=" + getRefreshToken() + ", scope=" + getScope() - + ", instance_url=" + instanceUrl + '}'; + + ", instance_url=" + getInstanceUrl() + '}'; } } From e173b649d653d518b37a38e8cc64a302480f425a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Winkelmeyer?= Date: Tue, 14 Jun 2016 11:57:34 +0200 Subject: [PATCH 229/882] Throws new exception / removed tabs --- .../com/github/scribejava/apis/SalesforceApi.java | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/SalesforceApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/SalesforceApi.java index 08f814c92..83075f67b 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/SalesforceApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/SalesforceApi.java @@ -20,9 +20,9 @@ public class SalesforceApi extends DefaultApi20 { // Constants - private static final String BASE_URL = "https://login.salesforce.com/services/oauth2"; - private static final String ACCESS_URL = BASE_URL + "/token?grant_type=authorization_code"; - private static final String AUTHORIZE_URL = BASE_URL + "/authorize"; + private static final String BASE_URL = "https://login.salesforce.com/services/oauth2"; + private static final String ACCESS_URL = BASE_URL + "/token?grant_type=authorization_code"; + private static final String AUTHORIZE_URL = BASE_URL + "/authorize"; protected SalesforceApi() { SSLContext sc; @@ -33,12 +33,9 @@ protected SalesforceApi() { sc.init(null, null, null); HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); } - } catch (NoSuchAlgorithmException e) { - e.printStackTrace(); + } catch (Exception e) { + throw new IllegalStateException("Unexpected JVM without TLS 1.2 support", e); } - catch (KeyManagementException e) { - e.printStackTrace(); - } } private static class InstanceHolder { From bdca89680d0ff6d919e3ff1f1f072069f9356904 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Winkelmeyer?= Date: Tue, 14 Jun 2016 12:00:15 +0200 Subject: [PATCH 230/882] Set required TLS protocol to TLS v1.2 --- .../src/main/java/com/github/scribejava/apis/SalesforceApi.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/SalesforceApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/SalesforceApi.java index 83075f67b..a40fea3dc 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/SalesforceApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/SalesforceApi.java @@ -28,7 +28,7 @@ protected SalesforceApi() { SSLContext sc; try { String protocol = SSLContext.getDefault().getProtocol(); - if (!protocol.equals("TLSv1.2") || !protocol.equals("TLSv1.1")) { // This is important! + if (!protocol.equals("TLSv1.2")) { // This is important! sc = SSLContext.getInstance("TLSv1.2"); sc.init(null, null, null); HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); From 97c8ea456b687b9ff39b62dd98e834548b35c986 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Winkelmeyer?= Date: Tue, 14 Jun 2016 12:07:03 +0200 Subject: [PATCH 231/882] Removed not needed imports --- .../main/java/com/github/scribejava/apis/SalesforceApi.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/SalesforceApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/SalesforceApi.java index a40fea3dc..71f7e2206 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/SalesforceApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/SalesforceApi.java @@ -1,8 +1,5 @@ package com.github.scribejava.apis; -import java.security.KeyManagementException; -import java.security.NoSuchAlgorithmException; - import javax.net.ssl.HttpsURLConnection; import javax.net.ssl.SSLContext; From 7b60d77a8d79a62b923aab175be7e55800939bf7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Winkelmeyer?= Date: Tue, 14 Jun 2016 17:22:16 +0200 Subject: [PATCH 232/882] Added example of Async Salesforce usage --- .../apis/examples/SalesforceAsyncExample.java | 124 ++++++++++++++++++ 1 file changed, 124 insertions(+) create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceAsyncExample.java diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceAsyncExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceAsyncExample.java new file mode 100644 index 000000000..6175fdca1 --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceAsyncExample.java @@ -0,0 +1,124 @@ +package com.github.scribejava.apis.examples; + +import java.io.UnsupportedEncodingException; +import java.net.URLDecoder; +import java.net.URLEncoder; +import java.util.Scanner; +import java.util.concurrent.ExecutionException; + +import com.github.scribejava.core.builder.ServiceBuilder; +import com.github.scribejava.apis.SalesforceApi; +import com.github.scribejava.apis.salesforce.SalesforceToken; +import com.github.scribejava.core.model.ForceTypeOfHttpRequest; +import com.github.scribejava.core.model.OAuthAsyncRequestCallback; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.OAuthRequestAsync; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.ScribeJavaConfig; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.oauth.OAuth20Service; +import com.ning.http.client.AsyncHttpClientConfig; + +public class SalesforceAsyncExample { + + private static final String NETWORK_NAME = "Salesforce"; + + @SuppressWarnings({ "unchecked", "rawtypes" }) + public static void main(String[] args) throws InterruptedException, ExecutionException { + // Replace these with your client id and secret + final String clientId = "your client id"; + final String clientSecret = "your client secret"; + + ScribeJavaConfig.setForceTypeOfHttpRequests(ForceTypeOfHttpRequest.FORCE_ASYNC_ONLY_HTTP_REQUESTS); + final AsyncHttpClientConfig clientConfig = new AsyncHttpClientConfig.Builder() + .setMaxConnections(5) + .setRequestTimeout(10_000) + .setAllowPoolingConnections(false) + .setPooledConnectionIdleTimeout(1_000) + .setReadTimeout(10_000) + .build(); + + final OAuth20Service service = new ServiceBuilder() + .apiKey(clientId) + .apiSecret(clientSecret) + .asyncHttpClientConfig(clientConfig) + .callback("https://www.example.com/callback") // Salesforce only accepts secured callbacks + .build(SalesforceApi.instance()); + final Scanner in = new Scanner(System.in); + + System.out.println("=== " + NETWORK_NAME + "'s OAuth20 Workflow ==="); + System.out.println(); + + // Obtain the Authorization URL + System.out.println("Fetching the Authorization URL..."); + final String authorizationUrl = service.getAuthorizationUrl(); + System.out.println("Got the Authorization URL!"); + System.out.println("Now go and authorize ScribeJava here:"); + System.out.println(authorizationUrl); + System.out.println("And paste the authorization code here"); + System.out.print(">>"); + final String code = in.nextLine(); + System.out.println(); + in.close(); + + String codeEncoded = code; + + // The code needs to be URL decoded + try { + codeEncoded = URLDecoder.decode(code, "UTF-8"); + } catch (UnsupportedEncodingException e1) { + e1.printStackTrace(); + } + + // Trade the Request Token and Verifier for the Access Token + System.out.println("Trading the Request Token for an Access Token..."); + final SalesforceToken accessToken = (SalesforceToken) service.getAccessTokenAsync(codeEncoded, null).get(); + System.out.println("Got the Access Token!"); + System.out.println("(if your curious it looks like this: " + accessToken + + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println(); + + System.out.println("Instance is: " + accessToken.getInstanceUrl()); + + // Now let's go and ask for a protected resource! + System.out.println("Now we're reading accounts from the Salesforce org (maxing them to 10)."); + + // Sample SOQL statement + String queryEncoded = "Select Id, Name from Account LIMIT 10"; + + try { + queryEncoded = URLEncoder.encode(queryEncoded, "UTF-8"); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + queryEncoded = ""; + } + + if (!queryEncoded.isEmpty()) { + // Building the query URI. We've parsed the instance URL from the accessToken request. + String url = accessToken.getInstanceUrl() + "/services/data/v36.0/query?q=" + queryEncoded; + + System.out.println(); + System.out.println("Full URL: " + url); + + final OAuthRequestAsync request = new OAuthRequestAsync(Verb.GET, url, service); + request.addHeader("Authorization", "Bearer " + accessToken.getAccessToken()); + request.sendAsync(new OAuthAsyncRequestCallback() { + + @Override + public void onThrowable(Throwable t) { + // TODO Auto-generated method stub + + } + + @Override + public void onCompleted(Object response) { + System.out.println(); + System.out.println(((Response)response).getCode()); + System.out.println(((Response)response).getBody()); + } + }); + } + + + } +} From 0383fe40bd56815723ebd0b30b1d41b9a26540ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Winkelmeyer?= Date: Tue, 14 Jun 2016 17:23:34 +0200 Subject: [PATCH 233/882] Addes Salesforce to API provider list --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 031c4dd53..1027f8a3a 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,7 @@ You can use ning async http client out-of-box, just use ServiceBuilderAsync * Pinterest (https://www.pinterest.com/) * 500px (https://500px.com/) * Renren (http://renren.com/) +* Salesforce (https://www.salesforce.com/) * Sina (http://www.sina.com.cn/ http://weibo.com/login.php) * Skyrock (http://skyrock.com/) * sohu 搜狐 (http://www.sohu.com/) From 23166418bc6b760c59b173856dc5259aacb9f114 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Winkelmeyer?= Date: Wed, 15 Jun 2016 13:21:45 +0200 Subject: [PATCH 234/882] Applied checkstyle rules --- .../github/scribejava/apis/SalesforceApi.java | 52 ++--- .../SalesforceJsonTokenExtractor.java | 3 +- .../apis/salesforce/SalesforceToken.java | 6 +- .../apis/examples/SalesforceAsyncExample.java | 187 +++++++++--------- .../apis/examples/SalesforceExample.java | 160 +++++++-------- 5 files changed, 205 insertions(+), 203 deletions(-) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/SalesforceApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/SalesforceApi.java index 71f7e2206..fff03defc 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/SalesforceApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/SalesforceApi.java @@ -6,7 +6,7 @@ import com.github.scribejava.apis.salesforce.SalesforceJsonTokenExtractor; /** - * This class is an implementation of the Salesforce OAuth2 API. + * This class is an implementation of the Salesforce OAuth2 API. */ import com.github.scribejava.core.builder.api.DefaultApi20; @@ -15,24 +15,24 @@ import com.github.scribejava.core.model.Verb; public class SalesforceApi extends DefaultApi20 { - - // Constants + + // Constants private static final String BASE_URL = "https://login.salesforce.com/services/oauth2"; private static final String ACCESS_URL = BASE_URL + "/token?grant_type=authorization_code"; private static final String AUTHORIZE_URL = BASE_URL + "/authorize"; protected SalesforceApi() { - SSLContext sc; - try { - String protocol = SSLContext.getDefault().getProtocol(); - if (!protocol.equals("TLSv1.2")) { // This is important! - sc = SSLContext.getInstance("TLSv1.2"); - sc.init(null, null, null); - HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); - } - } catch (Exception e) { - throw new IllegalStateException("Unexpected JVM without TLS 1.2 support", e); - } + final SSLContext sc; + try { + final String protocol = SSLContext.getDefault().getProtocol(); + if (!"TLSv1.2".equals(protocol)) { // This is important! + sc = SSLContext.getInstance("TLSv1.2"); + sc.init(null, null, null); + HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); + } + } catch (Exception e) { + throw new IllegalStateException("Unexpected JVM without TLS 1.2 support", e); + } } private static class InstanceHolder { @@ -42,22 +42,22 @@ private static class InstanceHolder { public static SalesforceApi instance() { return InstanceHolder.INSTANCE; } - + @Override - public Verb getAccessTokenVerb(){ - return Verb.POST; + public Verb getAccessTokenVerb() { + return Verb.POST; } - @Override - public String getAccessTokenEndpoint() { - return ACCESS_URL; - } + @Override + public String getAccessTokenEndpoint() { + return ACCESS_URL; + } + + @Override + protected String getAuthorizationBaseUrl() { + return AUTHORIZE_URL; + } - @Override - protected String getAuthorizationBaseUrl() { - return AUTHORIZE_URL; - } - @Override public TokenExtractor getAccessTokenExtractor() { return SalesforceJsonTokenExtractor.instance(); diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/salesforce/SalesforceJsonTokenExtractor.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/salesforce/SalesforceJsonTokenExtractor.java index 6b5f612c1..c3915470f 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/salesforce/SalesforceJsonTokenExtractor.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/salesforce/SalesforceJsonTokenExtractor.java @@ -4,7 +4,8 @@ import com.github.scribejava.core.model.OAuth2AccessToken; /** - * This extractor parses in addition to the standard Extractor the instance_url of the used Salesforce organization. + * This extractor parses in addition to the standard Extractor the instance_url + * of the used Salesforce organization. */ public class SalesforceJsonTokenExtractor extends OAuth2AccessTokenJsonExtractor { diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/salesforce/SalesforceToken.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/salesforce/SalesforceToken.java index 6f6961e83..f558ace0b 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/salesforce/SalesforceToken.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/salesforce/SalesforceToken.java @@ -1,14 +1,16 @@ package com.github.scribejava.apis.salesforce; -import com.github.scribejava.core.model.OAuth2AccessToken; import java.util.Objects; +import com.github.scribejava.core.model.OAuth2AccessToken; + public class SalesforceToken extends OAuth2AccessToken { private static final long serialVersionUID = 7845679917727899612L; /** - * This token model includes the instance_url to address the needed Salesforce organization instance. + * This token model includes the instance_url to address the needed + * Salesforce organization instance. */ private final String instanceUrl; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceAsyncExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceAsyncExample.java index 6175fdca1..2bff9ce64 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceAsyncExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceAsyncExample.java @@ -6,12 +6,11 @@ import java.util.Scanner; import java.util.concurrent.ExecutionException; -import com.github.scribejava.core.builder.ServiceBuilder; import com.github.scribejava.apis.SalesforceApi; import com.github.scribejava.apis.salesforce.SalesforceToken; +import com.github.scribejava.core.builder.ServiceBuilder; import com.github.scribejava.core.model.ForceTypeOfHttpRequest; import com.github.scribejava.core.model.OAuthAsyncRequestCallback; -import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.OAuthRequestAsync; import com.github.scribejava.core.model.Response; import com.github.scribejava.core.model.ScribeJavaConfig; @@ -19,16 +18,16 @@ import com.github.scribejava.core.oauth.OAuth20Service; import com.ning.http.client.AsyncHttpClientConfig; -public class SalesforceAsyncExample { +public abstract class SalesforceAsyncExample { - private static final String NETWORK_NAME = "Salesforce"; + private static final String NETWORK_NAME = "Salesforce"; + + @SuppressWarnings({ "unchecked", "rawtypes" }) + public static void main(String[] args) throws InterruptedException, ExecutionException { + // Replace these with your client id and secret + final String clientId = "your client id"; + final String clientSecret = "your client secret"; - @SuppressWarnings({ "unchecked", "rawtypes" }) - public static void main(String[] args) throws InterruptedException, ExecutionException { - // Replace these with your client id and secret - final String clientId = "your client id"; - final String clientSecret = "your client secret"; - ScribeJavaConfig.setForceTypeOfHttpRequests(ForceTypeOfHttpRequest.FORCE_ASYNC_ONLY_HTTP_REQUESTS); final AsyncHttpClientConfig clientConfig = new AsyncHttpClientConfig.Builder() .setMaxConnections(5) @@ -37,88 +36,88 @@ public static void main(String[] args) throws InterruptedException, ExecutionExc .setPooledConnectionIdleTimeout(1_000) .setReadTimeout(10_000) .build(); - - final OAuth20Service service = new ServiceBuilder() - .apiKey(clientId) - .apiSecret(clientSecret) - .asyncHttpClientConfig(clientConfig) - .callback("https://www.example.com/callback") // Salesforce only accepts secured callbacks - .build(SalesforceApi.instance()); - final Scanner in = new Scanner(System.in); - - System.out.println("=== " + NETWORK_NAME + "'s OAuth20 Workflow ==="); - System.out.println(); - - // Obtain the Authorization URL - System.out.println("Fetching the Authorization URL..."); - final String authorizationUrl = service.getAuthorizationUrl(); - System.out.println("Got the Authorization URL!"); - System.out.println("Now go and authorize ScribeJava here:"); - System.out.println(authorizationUrl); - System.out.println("And paste the authorization code here"); - System.out.print(">>"); - final String code = in.nextLine(); - System.out.println(); - in.close(); - - String codeEncoded = code; - - // The code needs to be URL decoded - try { - codeEncoded = URLDecoder.decode(code, "UTF-8"); - } catch (UnsupportedEncodingException e1) { - e1.printStackTrace(); - } - - // Trade the Request Token and Verifier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); - final SalesforceToken accessToken = (SalesforceToken) service.getAccessTokenAsync(codeEncoded, null).get(); - System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); - System.out.println(); - - System.out.println("Instance is: " + accessToken.getInstanceUrl()); - - // Now let's go and ask for a protected resource! - System.out.println("Now we're reading accounts from the Salesforce org (maxing them to 10)."); - - // Sample SOQL statement - String queryEncoded = "Select Id, Name from Account LIMIT 10"; - - try { - queryEncoded = URLEncoder.encode(queryEncoded, "UTF-8"); - } catch (UnsupportedEncodingException e) { - e.printStackTrace(); - queryEncoded = ""; - } - - if (!queryEncoded.isEmpty()) { - // Building the query URI. We've parsed the instance URL from the accessToken request. - String url = accessToken.getInstanceUrl() + "/services/data/v36.0/query?q=" + queryEncoded; - - System.out.println(); - System.out.println("Full URL: " + url); - - final OAuthRequestAsync request = new OAuthRequestAsync(Verb.GET, url, service); - request.addHeader("Authorization", "Bearer " + accessToken.getAccessToken()); - request.sendAsync(new OAuthAsyncRequestCallback() { - - @Override - public void onThrowable(Throwable t) { - // TODO Auto-generated method stub - - } - - @Override - public void onCompleted(Object response) { - System.out.println(); - System.out.println(((Response)response).getCode()); - System.out.println(((Response)response).getBody()); - } - }); - } - - - } + + final OAuth20Service service = new ServiceBuilder() + .apiKey(clientId) + .apiSecret(clientSecret) + .asyncHttpClientConfig(clientConfig) + .callback("https://www.example.com/callback") + .build(SalesforceApi.instance()); + final Scanner in = new Scanner(System.in); + + System.out.println("=== " + NETWORK_NAME + "'s OAuth20 Workflow ==="); + System.out.println(); + + // Obtain the Authorization URL + System.out.println("Fetching the Authorization URL..."); + final String authorizationUrl = service.getAuthorizationUrl(); + System.out.println("Got the Authorization URL!"); + System.out.println("Now go and authorize ScribeJava here:"); + System.out.println(authorizationUrl); + System.out.println("And paste the authorization code here"); + System.out.print(">>"); + final String code = in.nextLine(); + System.out.println(); + in.close(); + + String codeEncoded = code; + + // The code needs to be URL decoded + try { + codeEncoded = URLDecoder.decode(code, "UTF-8"); + } catch (UnsupportedEncodingException e1) { + e1.printStackTrace(); + } + + // Trade the Request Token and Verifier for the Access Token + System.out.println("Trading the Request Token for an Access Token..."); + final SalesforceToken accessToken = (SalesforceToken) service.getAccessTokenAsync(codeEncoded, null).get(); + System.out.println("Got the Access Token!"); + System.out.println("(if your curious it looks like this: " + accessToken + + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println(); + + System.out.println("Instance is: " + accessToken.getInstanceUrl()); + + // Now let's go and ask for a protected resource! + System.out.println("Now we're reading accounts from the Salesforce org (maxing them to 10)."); + + // Sample SOQL statement + String queryEncoded = "Select Id, Name from Account LIMIT 10"; + + try { + queryEncoded = URLEncoder.encode(queryEncoded, "UTF-8"); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + queryEncoded = ""; + } + + if (!queryEncoded.isEmpty()) { + // Building the query URI. We've parsed the instance URL from the + // accessToken request. + final String url = accessToken.getInstanceUrl() + "/services/data/v36.0/query?q=" + queryEncoded; + + System.out.println(); + System.out.println("Full URL: " + url); + + final OAuthRequestAsync request = new OAuthRequestAsync(Verb.GET, url, service); + request.addHeader("Authorization", "Bearer " + accessToken.getAccessToken()); + request.sendAsync(new OAuthAsyncRequestCallback() { + + @Override + public void onThrowable(Throwable t) { + // TODO Auto-generated method stub + + } + + @Override + public void onCompleted(Object response) { + System.out.println(); + System.out.println(((Response) response).getCode()); + System.out.println(((Response) response).getBody()); + } + }); + } + + } } diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceExample.java index 56e818294..58e4c2262 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceExample.java @@ -5,91 +5,91 @@ import java.net.URLEncoder; import java.util.Scanner; -import com.github.scribejava.core.builder.ServiceBuilder; import com.github.scribejava.apis.SalesforceApi; import com.github.scribejava.apis.salesforce.SalesforceToken; +import com.github.scribejava.core.builder.ServiceBuilder; 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 SalesforceExample { - - private static final String NETWORK_NAME = "Salesforce"; - - public static void main(String[] args) { - // Replace these with your client id and secret - final String clientId = "your client id"; - final String clientSecret = "your client secret"; - final OAuth20Service service = new ServiceBuilder() - .apiKey(clientId) - .apiSecret(clientSecret) - .callback("https://www.example.com/callback") // Salesforce only accepts secured callbacks - .build(SalesforceApi.instance()); - final Scanner in = new Scanner(System.in); - - System.out.println("=== " + NETWORK_NAME + "'s OAuth20 Workflow ==="); - System.out.println(); - - // Obtain the Authorization URL - System.out.println("Fetching the Authorization URL..."); - final String authorizationUrl = service.getAuthorizationUrl(); - System.out.println("Got the Authorization URL!"); - System.out.println("Now go and authorize ScribeJava here:"); - System.out.println(authorizationUrl); - System.out.println("And paste the authorization code here"); - System.out.print(">>"); - final String code = in.nextLine(); - System.out.println(); - in.close(); - - String codeEncoded = code; - - // The code needs to be URL decoded - try { - codeEncoded = URLDecoder.decode(code, "UTF-8"); - } catch (UnsupportedEncodingException e1) { - e1.printStackTrace(); - } - - // Trade the Request Token and Verifier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); - final SalesforceToken accessToken = (SalesforceToken) service.getAccessToken(codeEncoded); - System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); - System.out.println(); - - System.out.println("Instance is: " + accessToken.getInstanceUrl()); - - // Now let's go and ask for a protected resource! - System.out.println("Now we're reading accounts from the Salesforce org (maxing them to 10)."); - - // Sample SOQL statement - String queryEncoded = "Select Id, Name from Account LIMIT 10"; - - try { - queryEncoded = URLEncoder.encode(queryEncoded, "UTF-8"); - } catch (UnsupportedEncodingException e) { - e.printStackTrace(); - queryEncoded = ""; - } - - if (!queryEncoded.isEmpty()) { - // Building the query URI. We've parsed the instance URL from the accessToken request. - String url = accessToken.getInstanceUrl() + "/services/data/v36.0/query?q=" + queryEncoded; - - System.out.println(); - System.out.println("Full URL: " + url); - - final OAuthRequest request = new OAuthRequest(Verb.GET, url, service); - request.addHeader("Authorization", "Bearer " + accessToken.getAccessToken()); - final Response response = request.send(); - System.out.println(); - System.out.println(response.getCode()); - System.out.println(response.getBody()); - } - - - } +public abstract class SalesforceExample { + + private static final String NETWORK_NAME = "Salesforce"; + + public static void main(String[] args) { + // Replace these with your client id and secret + final String clientId = "your client id"; + final String clientSecret = "your client secret"; + final OAuth20Service service = new ServiceBuilder() + .apiKey(clientId) + .apiSecret(clientSecret) + .callback("https://www.example.com/callback") + .build(SalesforceApi.instance()); + final Scanner in = new Scanner(System.in); + + System.out.println("=== " + NETWORK_NAME + "'s OAuth20 Workflow ==="); + System.out.println(); + + // Obtain the Authorization URL + System.out.println("Fetching the Authorization URL..."); + final String authorizationUrl = service.getAuthorizationUrl(); + System.out.println("Got the Authorization URL!"); + System.out.println("Now go and authorize ScribeJava here:"); + System.out.println(authorizationUrl); + System.out.println("And paste the authorization code here"); + System.out.print(">>"); + final String code = in.nextLine(); + System.out.println(); + in.close(); + + String codeEncoded = code; + + // The code needs to be URL decoded + try { + codeEncoded = URLDecoder.decode(code, "UTF-8"); + } catch (UnsupportedEncodingException e1) { + e1.printStackTrace(); + } + + // Trade the Request Token and Verifier for the Access Token + System.out.println("Trading the Request Token for an Access Token..."); + final SalesforceToken accessToken = (SalesforceToken) service.getAccessToken(codeEncoded); + System.out.println("Got the Access Token!"); + System.out.println("(if your curious it looks like this: " + accessToken + ", 'rawResponse'='" + + accessToken.getRawResponse() + "')"); + System.out.println(); + + System.out.println("Instance is: " + accessToken.getInstanceUrl()); + + // Now let's go and ask for a protected resource! + System.out.println("Now we're reading accounts from the Salesforce org (maxing them to 10)."); + + // Sample SOQL statement + String queryEncoded = "Select Id, Name from Account LIMIT 10"; + + try { + queryEncoded = URLEncoder.encode(queryEncoded, "UTF-8"); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + queryEncoded = ""; + } + + if (!queryEncoded.isEmpty()) { + // Building the query URI. We've parsed the instance URL from the + // accessToken request. + final String url = accessToken.getInstanceUrl() + "/services/data/v36.0/query?q=" + queryEncoded; + + System.out.println(); + System.out.println("Full URL: " + url); + + final OAuthRequest request = new OAuthRequest(Verb.GET, url, service); + request.addHeader("Authorization", "Bearer " + accessToken.getAccessToken()); + final Response response = request.send(); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + } + + } } From 7a445e16a8641771fd1d1e1a35e9d7f19f65141d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Winkelmeyer?= Date: Wed, 15 Jun 2016 14:58:45 +0200 Subject: [PATCH 235/882] Changed examples to conform with current master --- .../apis/examples/SalesforceAsyncExample.java | 10 ++++++++-- .../scribejava/apis/examples/SalesforceExample.java | 3 ++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceAsyncExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceAsyncExample.java index 2bff9ce64..09f5a0569 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceAsyncExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceAsyncExample.java @@ -1,5 +1,6 @@ package com.github.scribejava.apis.examples; +import java.io.IOException; import java.io.UnsupportedEncodingException; import java.net.URLDecoder; import java.net.URLEncoder; @@ -40,7 +41,7 @@ public static void main(String[] args) throws InterruptedException, ExecutionExc final OAuth20Service service = new ServiceBuilder() .apiKey(clientId) .apiSecret(clientSecret) - .asyncHttpClientConfig(clientConfig) + .asyncNingHttpClientConfig(clientConfig) .callback("https://www.example.com/callback") .build(SalesforceApi.instance()); final Scanner in = new Scanner(System.in); @@ -114,7 +115,12 @@ public void onThrowable(Throwable t) { public void onCompleted(Object response) { System.out.println(); System.out.println(((Response) response).getCode()); - System.out.println(((Response) response).getBody()); + try { + System.out.println(((Response) response).getBody()); + } catch (IOException e) { + System.out.println("Error on reading body from async response."); + e.printStackTrace(); + } } }); } diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceExample.java index 58e4c2262..1b2ebf695 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceExample.java @@ -1,5 +1,6 @@ package com.github.scribejava.apis.examples; +import java.io.IOException; import java.io.UnsupportedEncodingException; import java.net.URLDecoder; import java.net.URLEncoder; @@ -17,7 +18,7 @@ public abstract class SalesforceExample { private static final String NETWORK_NAME = "Salesforce"; - public static void main(String[] args) { + public static void main(String[] args) throws IOException { // Replace these with your client id and secret final String clientId = "your client id"; final String clientSecret = "your client secret"; From 821bc7ce67ccddc240642a496a6cb469ceac4761 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Winkelmeyer?= Date: Fri, 10 Jun 2016 11:22:23 -0700 Subject: [PATCH 236/882] Add Salesforce API --- README.md | 1 + changelog | 3 + .../github/scribejava/apis/SalesforceApi.java | 115 ++++++++++++++++++ .../apis/google/GoogleJsonTokenExtractor.java | 3 +- .../scribejava/apis/google/GoogleToken.java | 25 +--- .../SalesforceJsonTokenExtractor.java | 31 +++++ .../apis/salesforce/SalesforceToken.java | 65 ++++++++++ .../apis/examples/SalesforceExample.java | 83 +++++++++++++ .../examples/SalesforceNingAsyncExample.java | 103 ++++++++++++++++ 9 files changed, 406 insertions(+), 23 deletions(-) create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/SalesforceApi.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/salesforce/SalesforceJsonTokenExtractor.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/salesforce/SalesforceToken.java create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceExample.java create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceNingAsyncExample.java diff --git a/README.md b/README.md index f1706f4cb..a521eb3e9 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,7 @@ You can use ning async http client out-of-box, just use ServiceBuilderAsync * Pinterest (https://www.pinterest.com/) * 500px (https://500px.com/) * Renren (http://renren.com/) +* Salesforce (https://www.salesforce.com/) * Sina (http://www.sina.com.cn/ http://weibo.com/login.php) * Skyrock (http://skyrock.com/) * sohu 搜狐 (http://www.sohu.com/) diff --git a/changelog b/changelog index 43f21ea34..93e37cba1 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,6 @@ +[SNAPSHOT] + * add Salesforce API + [2.7.3] * FIX: ScribeJava shouldn't require all async http client provider to be on the classpath if using only one of them diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/SalesforceApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/SalesforceApi.java new file mode 100644 index 000000000..49c5f7ec6 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/SalesforceApi.java @@ -0,0 +1,115 @@ +package com.github.scribejava.apis; + +import javax.net.ssl.SSLContext; + +import com.github.scribejava.apis.salesforce.SalesforceJsonTokenExtractor; +import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.extractors.TokenExtractor; +import com.github.scribejava.core.model.OAuth2AccessToken; +import com.github.scribejava.core.model.Verb; +import java.io.IOException; +import java.security.KeyManagementException; +import java.security.NoSuchAlgorithmException; +import javax.net.ssl.SSLSocket; + +/** + * This class is an implementation of the Salesforce OAuth2 API. + */ +public class SalesforceApi extends DefaultApi20 { + + private static final String BASE_URL = "https://login.salesforce.com/services/oauth2"; + private static final String ACCESS_URL = BASE_URL + "/token"; + private static final String AUTHORIZE_URL = BASE_URL + "/authorize"; + + protected SalesforceApi() { + + try { + final SSLSocket socket = (SSLSocket) SSLContext.getDefault().getSocketFactory().createSocket(); + if (!isTLSv11orUpperEnabled(socket)) { + throw new IllegalStateException("Salesforce API required to use TLSv1.1 or upper. " + + "Enabled it by invoking method initTLSv11orUpper or somehow else"); + } + } catch (NoSuchAlgorithmException | IOException ex) { + throw new IllegalStateException("Salesforce API required to use TLSv1.1 or upper. " + + "Enabled it by invoking method initTLSv11orUpper or somehow else"); + } + } + + private static class InstanceHolder { + + private static final SalesforceApi INSTANCE = new SalesforceApi(); + } + + public static SalesforceApi instance() { + return InstanceHolder.INSTANCE; + } + + @Override + public Verb getAccessTokenVerb() { + return Verb.POST; + } + + @Override + public String getAccessTokenEndpoint() { + return ACCESS_URL; + } + + @Override + protected String getAuthorizationBaseUrl() { + return AUTHORIZE_URL; + } + + @Override + public TokenExtractor getAccessTokenExtractor() { + return SalesforceJsonTokenExtractor.instance(); + } + + private static boolean isTLSv11orUpperEnabled(final SSLSocket socket) { + for (String protocol : socket.getEnabledProtocols()) { + if ("TLSv1.2".equals(protocol) || "TLSv1.1".equals(protocol)) { + return true; + } + } + return false; + } + + /** + * Salesforce API required to use TLSv1.1 or upper. + *

+ * Java 8 have TLS 1.2 enabled by default. java 7 - no, you should invoke this method or turn TLS>=1.1 somehow + * else

+ * + * @throws java.security.NoSuchAlgorithmException in case your jvm doesn't support TLSv1.1 and TLSv1.2 + * @throws java.security.KeyManagementException + * @throws java.io.IOException + */ + public static void initTLSv11orUpper() throws NoSuchAlgorithmException, KeyManagementException, IOException { + final SSLSocket socket = (SSLSocket) SSLContext.getDefault().getSocketFactory().createSocket(); + if (isTLSv11orUpperEnabled(socket)) { + return; + } + boolean supportTLSv11 = false; + boolean supportTLSv12 = false; + for (String protocol : socket.getSupportedProtocols()) { + if ("TLSv1.2".equals(protocol)) { + supportTLSv12 = true; + break; + } + if ("TLSv1.1".equals(protocol)) { + supportTLSv11 = true; + } + } + + final SSLContext context; + if (supportTLSv12) { + context = SSLContext.getInstance("TLSv1.2"); + } else if (supportTLSv11) { + context = SSLContext.getInstance("TLSv1.1"); + } else { + throw new NoSuchAlgorithmException("for Salesforce API to work you need jvm with TLS 1.1 or 1.2 support"); + } + + context.init(null, null, null); + SSLContext.setDefault(context); + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/google/GoogleJsonTokenExtractor.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/google/GoogleJsonTokenExtractor.java index 9cac46623..8295ddc3f 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/google/GoogleJsonTokenExtractor.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/google/GoogleJsonTokenExtractor.java @@ -1,7 +1,6 @@ package com.github.scribejava.apis.google; import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; -import com.github.scribejava.core.model.OAuth2AccessToken; /** * additionally parses OpenID id_token @@ -23,7 +22,7 @@ public static GoogleJsonTokenExtractor instance() { } @Override - protected OAuth2AccessToken createToken(String accessToken, String tokenType, Integer expiresIn, + protected GoogleToken createToken(String accessToken, String tokenType, Integer expiresIn, String refreshToken, String scope, String response) { return new GoogleToken(accessToken, tokenType, expiresIn, refreshToken, scope, extractParameter(response, ID_TOKEN_REGEX, false), response); diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/google/GoogleToken.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/google/GoogleToken.java index a47395571..68ec31f82 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/google/GoogleToken.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/google/GoogleToken.java @@ -34,12 +34,7 @@ public String getOpenIdToken() { @Override public int hashCode() { - int hash = 5; - hash = 37 * hash + Objects.hashCode(getAccessToken()); - hash = 37 * hash + Objects.hashCode(getTokenType()); - hash = 37 * hash + Objects.hashCode(getExpiresIn()); - hash = 37 * hash + Objects.hashCode(getRefreshToken()); - hash = 37 * hash + Objects.hashCode(getScope()); + int hash = super.hashCode(); hash = 37 * hash + Objects.hashCode(openIdToken); return hash; } @@ -55,23 +50,11 @@ public boolean equals(Object obj) { if (getClass() != obj.getClass()) { return false; } - final GoogleToken other = (GoogleToken) obj; - if (!Objects.equals(getAccessToken(), other.getAccessToken())) { + if (!super.equals(obj)) { return false; } - if (!Objects.equals(getTokenType(), other.getTokenType())) { - return false; - } - if (!Objects.equals(getRefreshToken(), other.getRefreshToken())) { - return false; - } - if (!Objects.equals(getScope(), other.getScope())) { - return false; - } - if (!Objects.equals(openIdToken, other.getOpenIdToken())) { - return false; - } - return Objects.equals(getExpiresIn(), other.getExpiresIn()); + + return Objects.equals(openIdToken, ((GoogleToken) obj).getOpenIdToken()); } @Override diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/salesforce/SalesforceJsonTokenExtractor.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/salesforce/SalesforceJsonTokenExtractor.java new file mode 100644 index 000000000..2f219163a --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/salesforce/SalesforceJsonTokenExtractor.java @@ -0,0 +1,31 @@ +package com.github.scribejava.apis.salesforce; + +import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; + +/** + * This extractor parses in addition to the standard Extractor the instance_url + * of the used Salesforce organization. + */ +public class SalesforceJsonTokenExtractor extends OAuth2AccessTokenJsonExtractor { + + private static final String INSTANCE_URL_REGEX = "\"instance_url\"\\s*:\\s*\"(\\S*?)\""; + + protected SalesforceJsonTokenExtractor() { + } + + private static class InstanceHolder { + + private static final SalesforceJsonTokenExtractor INSTANCE = new SalesforceJsonTokenExtractor(); + } + + public static SalesforceJsonTokenExtractor instance() { + return InstanceHolder.INSTANCE; + } + + @Override + protected SalesforceToken createToken(String accessToken, String tokenType, Integer expiresIn, + String refreshToken, String scope, String response) { + return new SalesforceToken(accessToken, tokenType, expiresIn, refreshToken, scope, + extractParameter(response, INSTANCE_URL_REGEX, true), response); + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/salesforce/SalesforceToken.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/salesforce/SalesforceToken.java new file mode 100644 index 000000000..548e374ab --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/salesforce/SalesforceToken.java @@ -0,0 +1,65 @@ +package com.github.scribejava.apis.salesforce; + +import java.util.Objects; + +import com.github.scribejava.core.model.OAuth2AccessToken; + +public class SalesforceToken extends OAuth2AccessToken { + + private static final long serialVersionUID = 7845679917727899612L; + + /** + * This token model includes the instance_url to address the needed + * Salesforce organization instance. + */ + private final String instanceUrl; + + public SalesforceToken(String accessToken, String instanceUrl, String rawResponse) { + this(accessToken, null, null, null, null, instanceUrl, rawResponse); + } + + public SalesforceToken(String accessToken, String tokenType, Integer expiresIn, String refreshToken, String scope, + String instanceUrl, String rawResponse) { + super(accessToken, tokenType, expiresIn, refreshToken, scope, rawResponse); + this.instanceUrl = instanceUrl; + } + + public String getInstanceUrl() { + return instanceUrl; + } + + @Override + public int hashCode() { + int hash = super.hashCode(); + hash = 37 * hash + Objects.hashCode(instanceUrl); + 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(instanceUrl, ((SalesforceToken) obj).getInstanceUrl()); + } + + @Override + public String toString() { + return "SalesforceToken{" + + "access_token=" + getAccessToken() + + ", token_type=" + getTokenType() + + ", expires_in=" + getExpiresIn() + + ", refresh_token=" + getRefreshToken() + + ", scope=" + getScope() + + ", instance_url=" + instanceUrl + '}'; + } +} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceExample.java new file mode 100644 index 000000000..3d89c23fb --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceExample.java @@ -0,0 +1,83 @@ +package com.github.scribejava.apis.examples; + +import java.io.IOException; +import java.net.URLDecoder; +import java.net.URLEncoder; +import java.util.Scanner; + +import com.github.scribejava.apis.SalesforceApi; +import com.github.scribejava.apis.salesforce.SalesforceToken; +import com.github.scribejava.core.builder.ServiceBuilder; +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.security.KeyManagementException; +import java.security.NoSuchAlgorithmException; + +public abstract class SalesforceExample { + + private static final String NETWORK_NAME = "Salesforce"; + + public static void main(String... args) throws IOException, NoSuchAlgorithmException, KeyManagementException { + // Replace these with your client id and secret + final String clientId = "your client id"; + final String clientSecret = "your client secret"; + //IT's important! Salesforce upper require TLS v1.1 or 1.2 + SalesforceApi.initTLSv11orUpper(); + final OAuth20Service service = new ServiceBuilder() + .apiKey(clientId) + .apiSecret(clientSecret) + .callback("https://www.example.com/callback") + .build(SalesforceApi.instance()); + + System.out.println("=== " + NETWORK_NAME + "'s OAuth20 Workflow ==="); + System.out.println(); + + // Obtain the Authorization URL + System.out.println("Fetching the Authorization URL..."); + final String authorizationUrl = service.getAuthorizationUrl(); + System.out.println("Got the Authorization URL!"); + System.out.println("Now go and authorize ScribeJava here:"); + System.out.println(authorizationUrl); + System.out.println("And paste the authorization code here"); + System.out.print(">>"); + final String code; + try (Scanner in = new Scanner(System.in)) { + code = in.nextLine(); + } + System.out.println(); + + // The code needs to be URL decoded + final String codeEncoded = URLDecoder.decode(code, "UTF-8"); + + // Trade the Request Token and Verifier for the Access Token + System.out.println("Trading the Request Token for an Access Token..."); + final SalesforceToken accessToken = (SalesforceToken) service.getAccessToken(codeEncoded); + System.out.println("Got the Access Token!"); + System.out.println("(if your curious it looks like this: " + accessToken + ", 'rawResponse'='" + + accessToken.getRawResponse() + "')"); + System.out.println(); + + System.out.println("instance_url is: " + accessToken.getInstanceUrl()); + + // Now let's go and ask for a protected resource! + System.out.println("Now we're reading accounts from the Salesforce org (maxing them to 10)."); + + // Sample SOQL statement + final String queryEncoded = URLEncoder.encode("Select Id, Name from Account LIMIT 10", "UTF-8"); + + // Building the query URI. We've parsed the instance URL from the accessToken request. + final String url = accessToken.getInstanceUrl() + "/services/data/v36.0/query?q=" + queryEncoded; + + System.out.println(); + System.out.println("Full URL: " + url); + + final OAuthRequest request = new OAuthRequest(Verb.GET, url, service); + request.addHeader("Authorization", "Bearer " + accessToken.getAccessToken()); + final Response response = request.send(); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + } +} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceNingAsyncExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceNingAsyncExample.java new file mode 100644 index 000000000..40d72f9da --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceNingAsyncExample.java @@ -0,0 +1,103 @@ +package com.github.scribejava.apis.examples; + +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.net.URLDecoder; +import java.net.URLEncoder; +import java.util.Scanner; +import java.util.concurrent.ExecutionException; + +import com.github.scribejava.apis.SalesforceApi; +import com.github.scribejava.apis.salesforce.SalesforceToken; +import com.github.scribejava.core.builder.ServiceBuilder; +import com.github.scribejava.core.model.ForceTypeOfHttpRequest; +import com.github.scribejava.core.model.OAuthRequestAsync; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.ScribeJavaConfig; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.oauth.OAuth20Service; +import com.ning.http.client.AsyncHttpClientConfig; +import java.security.KeyManagementException; +import java.security.NoSuchAlgorithmException; + +public abstract class SalesforceNingAsyncExample { + + private static final String NETWORK_NAME = "Salesforce"; + + @SuppressWarnings({"unchecked", "rawtypes"}) + public static void main(String... args) throws InterruptedException, ExecutionException, + UnsupportedEncodingException, IOException, NoSuchAlgorithmException, KeyManagementException { + // Replace these with your client id and secret + final String clientId = "your client id"; + final String clientSecret = "your client secret"; + + ScribeJavaConfig.setForceTypeOfHttpRequests(ForceTypeOfHttpRequest.FORCE_ASYNC_ONLY_HTTP_REQUESTS); + final AsyncHttpClientConfig clientConfig = new AsyncHttpClientConfig.Builder() + .setMaxConnections(5) + .setRequestTimeout(10_000) + .setAllowPoolingConnections(false) + .setPooledConnectionIdleTimeout(1_000) + .setReadTimeout(10_000) + .build(); + + //IT's important! Salesforce upper require TLS v1.1 or 1.2 + SalesforceApi.initTLSv11orUpper(); + final OAuth20Service service = new ServiceBuilder() + .apiKey(clientId) + .apiSecret(clientSecret) + .asyncNingHttpClientConfig(clientConfig) + .callback("https://www.example.com/callback") + .build(SalesforceApi.instance()); + + System.out.println("=== " + NETWORK_NAME + "'s OAuth20 Workflow ==="); + System.out.println(); + + // Obtain the Authorization URL + System.out.println("Fetching the Authorization URL..."); + final String authorizationUrl = service.getAuthorizationUrl(); + System.out.println("Got the Authorization URL!"); + System.out.println("Now go and authorize ScribeJava here:"); + System.out.println(authorizationUrl); + System.out.println("And paste the authorization code here"); + System.out.print(">>"); + final String code; + try (Scanner in = new Scanner(System.in)) { + code = in.nextLine(); + } + System.out.println(); + + final String codeEncoded = URLDecoder.decode(code, "UTF-8"); + + // Trade the Request Token and Verifier for the Access Token + System.out.println("Trading the Request Token for an Access Token..."); + final SalesforceToken accessToken = (SalesforceToken) service.getAccessTokenAsync(codeEncoded, null).get(); + System.out.println("Got the Access Token!"); + System.out.println("(if your curious it looks like this: " + accessToken + + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println(); + + System.out.println("Instance is: " + accessToken.getInstanceUrl()); + + // Now let's go and ask for a protected resource! + System.out.println("Now we're reading accounts from the Salesforce org (maxing them to 10)."); + + // Sample SOQL statement + final String queryEncoded = URLEncoder.encode("Select Id, Name from Account LIMIT 10", "UTF-8"); + + // Building the query URI. We've parsed the instance URL from the + // accessToken request. + final String url = accessToken.getInstanceUrl() + "/services/data/v36.0/query?q=" + queryEncoded; + + System.out.println(); + System.out.println("Full URL: " + url); + + final OAuthRequestAsync request = new OAuthRequestAsync(Verb.GET, url, service); + request.addHeader("Authorization", "Bearer " + accessToken.getAccessToken()); + final Response response = request.sendAsync(null).get(); + + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + service.closeAsyncClient(); + } +} From 8dc38d9f0435375de0b47781a1723265cc8e48dd Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 16 Jun 2016 13:51:55 +0400 Subject: [PATCH 237/882] Revert "Adds API provider for Salesforce" --- README.md | 1 - .../github/scribejava/apis/SalesforceApi.java | 66 --------- .../SalesforceJsonTokenExtractor.java | 32 ----- .../apis/salesforce/SalesforceToken.java | 83 ----------- .../apis/examples/SalesforceAsyncExample.java | 129 ------------------ .../apis/examples/SalesforceExample.java | 96 ------------- 6 files changed, 407 deletions(-) delete mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/SalesforceApi.java delete mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/salesforce/SalesforceJsonTokenExtractor.java delete mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/salesforce/SalesforceToken.java delete mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceAsyncExample.java delete mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceExample.java diff --git a/README.md b/README.md index a521eb3e9..f1706f4cb 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,6 @@ You can use ning async http client out-of-box, just use ServiceBuilderAsync * Pinterest (https://www.pinterest.com/) * 500px (https://500px.com/) * Renren (http://renren.com/) -* Salesforce (https://www.salesforce.com/) * Sina (http://www.sina.com.cn/ http://weibo.com/login.php) * Skyrock (http://skyrock.com/) * sohu 搜狐 (http://www.sohu.com/) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/SalesforceApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/SalesforceApi.java deleted file mode 100644 index fff03defc..000000000 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/SalesforceApi.java +++ /dev/null @@ -1,66 +0,0 @@ -package com.github.scribejava.apis; - -import javax.net.ssl.HttpsURLConnection; -import javax.net.ssl.SSLContext; - -import com.github.scribejava.apis.salesforce.SalesforceJsonTokenExtractor; - -/** - * This class is an implementation of the Salesforce OAuth2 API. - */ - -import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.extractors.TokenExtractor; -import com.github.scribejava.core.model.OAuth2AccessToken; -import com.github.scribejava.core.model.Verb; - -public class SalesforceApi extends DefaultApi20 { - - // Constants - private static final String BASE_URL = "https://login.salesforce.com/services/oauth2"; - private static final String ACCESS_URL = BASE_URL + "/token?grant_type=authorization_code"; - private static final String AUTHORIZE_URL = BASE_URL + "/authorize"; - - protected SalesforceApi() { - final SSLContext sc; - try { - final String protocol = SSLContext.getDefault().getProtocol(); - if (!"TLSv1.2".equals(protocol)) { // This is important! - sc = SSLContext.getInstance("TLSv1.2"); - sc.init(null, null, null); - HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); - } - } catch (Exception e) { - throw new IllegalStateException("Unexpected JVM without TLS 1.2 support", e); - } - } - - private static class InstanceHolder { - private static final SalesforceApi INSTANCE = new SalesforceApi(); - } - - public static SalesforceApi instance() { - return InstanceHolder.INSTANCE; - } - - @Override - public Verb getAccessTokenVerb() { - return Verb.POST; - } - - @Override - public String getAccessTokenEndpoint() { - return ACCESS_URL; - } - - @Override - protected String getAuthorizationBaseUrl() { - return AUTHORIZE_URL; - } - - @Override - public TokenExtractor getAccessTokenExtractor() { - return SalesforceJsonTokenExtractor.instance(); - } - -} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/salesforce/SalesforceJsonTokenExtractor.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/salesforce/SalesforceJsonTokenExtractor.java deleted file mode 100644 index c3915470f..000000000 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/salesforce/SalesforceJsonTokenExtractor.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.github.scribejava.apis.salesforce; - -import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; -import com.github.scribejava.core.model.OAuth2AccessToken; - -/** - * This extractor parses in addition to the standard Extractor the instance_url - * of the used Salesforce organization. - */ -public class SalesforceJsonTokenExtractor extends OAuth2AccessTokenJsonExtractor { - - private static final String INSTANCE_URL_REGEX = "\"instance_url\"\\s*:\\s*\"(\\S*?)\""; - - protected SalesforceJsonTokenExtractor() { - } - - private static class InstanceHolder { - - private static final SalesforceJsonTokenExtractor INSTANCE = new SalesforceJsonTokenExtractor(); - } - - public static SalesforceJsonTokenExtractor instance() { - return InstanceHolder.INSTANCE; - } - - @Override - protected OAuth2AccessToken createToken(String accessToken, String tokenType, Integer expiresIn, - String refreshToken, String scope, String response) { - return new SalesforceToken(accessToken, tokenType, expiresIn, refreshToken, scope, - extractParameter(response, INSTANCE_URL_REGEX, true), response); - } -} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/salesforce/SalesforceToken.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/salesforce/SalesforceToken.java deleted file mode 100644 index f558ace0b..000000000 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/salesforce/SalesforceToken.java +++ /dev/null @@ -1,83 +0,0 @@ -package com.github.scribejava.apis.salesforce; - -import java.util.Objects; - -import com.github.scribejava.core.model.OAuth2AccessToken; - -public class SalesforceToken extends OAuth2AccessToken { - - private static final long serialVersionUID = 7845679917727899612L; - - /** - * This token model includes the instance_url to address the needed - * Salesforce organization instance. - */ - private final String instanceUrl; - - public SalesforceToken(String accessToken, String instanceUrl, String rawResponse) { - this(accessToken, null, null, null, null, instanceUrl, rawResponse); - } - - public SalesforceToken(String accessToken, String tokenType, Integer expiresIn, String refreshToken, String scope, - String instanceUrl, String rawResponse) { - super(accessToken, tokenType, expiresIn, refreshToken, scope, rawResponse); - this.instanceUrl = instanceUrl; - } - - public String getInstanceUrl() { - return instanceUrl; - } - - @Override - public int hashCode() { - int hash = 5; - hash = 37 * hash + Objects.hashCode(getAccessToken()); - hash = 37 * hash + Objects.hashCode(getTokenType()); - hash = 37 * hash + Objects.hashCode(getExpiresIn()); - hash = 37 * hash + Objects.hashCode(getRefreshToken()); - hash = 37 * hash + Objects.hashCode(getScope()); - hash = 37 * hash + Objects.hashCode(getInstanceUrl()); - 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 SalesforceToken other = (SalesforceToken) obj; - if (!Objects.equals(getAccessToken(), other.getAccessToken())) { - return false; - } - if (!Objects.equals(getTokenType(), other.getTokenType())) { - return false; - } - if (!Objects.equals(getRefreshToken(), other.getRefreshToken())) { - return false; - } - if (!Objects.equals(getScope(), other.getScope())) { - return false; - } - if (!Objects.equals(getInstanceUrl(), other.getInstanceUrl())) { - return false; - } - return Objects.equals(getExpiresIn(), other.getExpiresIn()); - } - - @Override - public String toString() { - return "SalesforceToken{" - + "access_token=" + getAccessToken() - + ", token_type=" + getTokenType() - + ", expires_in=" + getExpiresIn() - + ", refresh_token=" + getRefreshToken() - + ", scope=" + getScope() - + ", instance_url=" + getInstanceUrl() + '}'; - } -} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceAsyncExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceAsyncExample.java deleted file mode 100644 index 09f5a0569..000000000 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceAsyncExample.java +++ /dev/null @@ -1,129 +0,0 @@ -package com.github.scribejava.apis.examples; - -import java.io.IOException; -import java.io.UnsupportedEncodingException; -import java.net.URLDecoder; -import java.net.URLEncoder; -import java.util.Scanner; -import java.util.concurrent.ExecutionException; - -import com.github.scribejava.apis.SalesforceApi; -import com.github.scribejava.apis.salesforce.SalesforceToken; -import com.github.scribejava.core.builder.ServiceBuilder; -import com.github.scribejava.core.model.ForceTypeOfHttpRequest; -import com.github.scribejava.core.model.OAuthAsyncRequestCallback; -import com.github.scribejava.core.model.OAuthRequestAsync; -import com.github.scribejava.core.model.Response; -import com.github.scribejava.core.model.ScribeJavaConfig; -import com.github.scribejava.core.model.Verb; -import com.github.scribejava.core.oauth.OAuth20Service; -import com.ning.http.client.AsyncHttpClientConfig; - -public abstract class SalesforceAsyncExample { - - private static final String NETWORK_NAME = "Salesforce"; - - @SuppressWarnings({ "unchecked", "rawtypes" }) - public static void main(String[] args) throws InterruptedException, ExecutionException { - // Replace these with your client id and secret - final String clientId = "your client id"; - final String clientSecret = "your client secret"; - - ScribeJavaConfig.setForceTypeOfHttpRequests(ForceTypeOfHttpRequest.FORCE_ASYNC_ONLY_HTTP_REQUESTS); - final AsyncHttpClientConfig clientConfig = new AsyncHttpClientConfig.Builder() - .setMaxConnections(5) - .setRequestTimeout(10_000) - .setAllowPoolingConnections(false) - .setPooledConnectionIdleTimeout(1_000) - .setReadTimeout(10_000) - .build(); - - final OAuth20Service service = new ServiceBuilder() - .apiKey(clientId) - .apiSecret(clientSecret) - .asyncNingHttpClientConfig(clientConfig) - .callback("https://www.example.com/callback") - .build(SalesforceApi.instance()); - final Scanner in = new Scanner(System.in); - - System.out.println("=== " + NETWORK_NAME + "'s OAuth20 Workflow ==="); - System.out.println(); - - // Obtain the Authorization URL - System.out.println("Fetching the Authorization URL..."); - final String authorizationUrl = service.getAuthorizationUrl(); - System.out.println("Got the Authorization URL!"); - System.out.println("Now go and authorize ScribeJava here:"); - System.out.println(authorizationUrl); - System.out.println("And paste the authorization code here"); - System.out.print(">>"); - final String code = in.nextLine(); - System.out.println(); - in.close(); - - String codeEncoded = code; - - // The code needs to be URL decoded - try { - codeEncoded = URLDecoder.decode(code, "UTF-8"); - } catch (UnsupportedEncodingException e1) { - e1.printStackTrace(); - } - - // Trade the Request Token and Verifier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); - final SalesforceToken accessToken = (SalesforceToken) service.getAccessTokenAsync(codeEncoded, null).get(); - System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); - System.out.println(); - - System.out.println("Instance is: " + accessToken.getInstanceUrl()); - - // Now let's go and ask for a protected resource! - System.out.println("Now we're reading accounts from the Salesforce org (maxing them to 10)."); - - // Sample SOQL statement - String queryEncoded = "Select Id, Name from Account LIMIT 10"; - - try { - queryEncoded = URLEncoder.encode(queryEncoded, "UTF-8"); - } catch (UnsupportedEncodingException e) { - e.printStackTrace(); - queryEncoded = ""; - } - - if (!queryEncoded.isEmpty()) { - // Building the query URI. We've parsed the instance URL from the - // accessToken request. - final String url = accessToken.getInstanceUrl() + "/services/data/v36.0/query?q=" + queryEncoded; - - System.out.println(); - System.out.println("Full URL: " + url); - - final OAuthRequestAsync request = new OAuthRequestAsync(Verb.GET, url, service); - request.addHeader("Authorization", "Bearer " + accessToken.getAccessToken()); - request.sendAsync(new OAuthAsyncRequestCallback() { - - @Override - public void onThrowable(Throwable t) { - // TODO Auto-generated method stub - - } - - @Override - public void onCompleted(Object response) { - System.out.println(); - System.out.println(((Response) response).getCode()); - try { - System.out.println(((Response) response).getBody()); - } catch (IOException e) { - System.out.println("Error on reading body from async response."); - e.printStackTrace(); - } - } - }); - } - - } -} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceExample.java deleted file mode 100644 index 1b2ebf695..000000000 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceExample.java +++ /dev/null @@ -1,96 +0,0 @@ -package com.github.scribejava.apis.examples; - -import java.io.IOException; -import java.io.UnsupportedEncodingException; -import java.net.URLDecoder; -import java.net.URLEncoder; -import java.util.Scanner; - -import com.github.scribejava.apis.SalesforceApi; -import com.github.scribejava.apis.salesforce.SalesforceToken; -import com.github.scribejava.core.builder.ServiceBuilder; -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 abstract class SalesforceExample { - - private static final String NETWORK_NAME = "Salesforce"; - - public static void main(String[] args) throws IOException { - // Replace these with your client id and secret - final String clientId = "your client id"; - final String clientSecret = "your client secret"; - final OAuth20Service service = new ServiceBuilder() - .apiKey(clientId) - .apiSecret(clientSecret) - .callback("https://www.example.com/callback") - .build(SalesforceApi.instance()); - final Scanner in = new Scanner(System.in); - - System.out.println("=== " + NETWORK_NAME + "'s OAuth20 Workflow ==="); - System.out.println(); - - // Obtain the Authorization URL - System.out.println("Fetching the Authorization URL..."); - final String authorizationUrl = service.getAuthorizationUrl(); - System.out.println("Got the Authorization URL!"); - System.out.println("Now go and authorize ScribeJava here:"); - System.out.println(authorizationUrl); - System.out.println("And paste the authorization code here"); - System.out.print(">>"); - final String code = in.nextLine(); - System.out.println(); - in.close(); - - String codeEncoded = code; - - // The code needs to be URL decoded - try { - codeEncoded = URLDecoder.decode(code, "UTF-8"); - } catch (UnsupportedEncodingException e1) { - e1.printStackTrace(); - } - - // Trade the Request Token and Verifier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); - final SalesforceToken accessToken = (SalesforceToken) service.getAccessToken(codeEncoded); - System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken + ", 'rawResponse'='" - + accessToken.getRawResponse() + "')"); - System.out.println(); - - System.out.println("Instance is: " + accessToken.getInstanceUrl()); - - // Now let's go and ask for a protected resource! - System.out.println("Now we're reading accounts from the Salesforce org (maxing them to 10)."); - - // Sample SOQL statement - String queryEncoded = "Select Id, Name from Account LIMIT 10"; - - try { - queryEncoded = URLEncoder.encode(queryEncoded, "UTF-8"); - } catch (UnsupportedEncodingException e) { - e.printStackTrace(); - queryEncoded = ""; - } - - if (!queryEncoded.isEmpty()) { - // Building the query URI. We've parsed the instance URL from the - // accessToken request. - final String url = accessToken.getInstanceUrl() + "/services/data/v36.0/query?q=" + queryEncoded; - - System.out.println(); - System.out.println("Full URL: " + url); - - final OAuthRequest request = new OAuthRequest(Verb.GET, url, service); - request.addHeader("Authorization", "Bearer " + accessToken.getAccessToken()); - final Response response = request.send(); - System.out.println(); - System.out.println(response.getCode()); - System.out.println(response.getBody()); - } - - } -} From 8aa7913a5dcf859dbd0585750cc43a56a5ba167c Mon Sep 17 00:00:00 2001 From: Alex Gyori Date: Mon, 20 Jun 2016 16:57:13 -0500 Subject: [PATCH 238/882] Fixed shouldExtractStandardHeader to not rely on the unguaranteed order of HashMap and make it work cross platform. --- .../core/extractors/HeaderExtractorTest.java | 29 ++++++++++++------- 1 file changed, 19 insertions(+), 10 deletions(-) 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 8de9d5c50..abad45f7e 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 @@ -1,6 +1,7 @@ package com.github.scribejava.core.extractors; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import org.junit.Before; import org.junit.Test; import com.github.scribejava.core.exceptions.OAuthParametersMissingException; @@ -24,16 +25,24 @@ public void setUp() { @Test public void shouldExtractStandardHeader() { final String header = extractor.extract(request); - try { - assertEquals("OAuth oauth_callback=\"http%3A%2F%2Fexample%2Fcallback\", " - + "oauth_signature=\"OAuth-Signature\", oauth_consumer_key=\"AS%23%24%5E%2A%40%26\", " - + "oauth_timestamp=\"123456\"", header); - } catch (AssertionError ae) { - //maybe this is OpenJDK 8? Different order of elements in HashMap while iterating'em. - assertEquals("OAuth oauth_signature=\"OAuth-Signature\", " - + "oauth_callback=\"http%3A%2F%2Fexample%2Fcallback\", " - + "oauth_consumer_key=\"AS%23%24%5E%2A%40%26\", oauth_timestamp=\"123456\"", header); - } + final String oauth = "OAuth "; + final String callback = "oauth_callback=\"http%3A%2F%2Fexample%2Fcallback\""; + final String signature = "oauth_signature=\"OAuth-Signature\""; + final String key = "oauth_consumer_key=\"AS%23%24%5E%2A%40%26\""; + final String timestamp = "oauth_timestamp=\"123456\""; + + assertTrue(header.contains(oauth)); + assertTrue(header.contains(callback)); + assertTrue(header.contains(signature)); + assertTrue(header.contains(key)); + 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, "")); } @Test(expected = IllegalArgumentException.class) From a0ea48fea9da283d5c0525601793957856c3d095 Mon Sep 17 00:00:00 2001 From: Alex Gyori Date: Mon, 20 Jun 2016 17:27:50 -0500 Subject: [PATCH 239/882] the string should start with oauth --- .../github/scribejava/core/extractors/HeaderExtractorTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 abad45f7e..356a1fbba 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 @@ -31,7 +31,7 @@ public void shouldExtractStandardHeader() { final String key = "oauth_consumer_key=\"AS%23%24%5E%2A%40%26\""; final String timestamp = "oauth_timestamp=\"123456\""; - assertTrue(header.contains(oauth)); + assertTrue(header.startsWith(oauth)); assertTrue(header.contains(callback)); assertTrue(header.contains(signature)); assertTrue(header.contains(key)); From b4aa3c4355fa9bee04e713581a4d5fc24cc98435 Mon Sep 17 00:00:00 2001 From: Alex Gyori Date: Tue, 21 Jun 2016 11:44:27 -0500 Subject: [PATCH 240/882] fixed test to not rely on HashMap's internal ordering --- .../java/com/github/scribejava/core/utils/MapUtilsTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/utils/MapUtilsTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/utils/MapUtilsTest.java index dc6bd38d5..9ce36c76f 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/utils/MapUtilsTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/utils/MapUtilsTest.java @@ -1,5 +1,6 @@ package com.github.scribejava.core.utils; +import java.util.LinkedHashMap; import java.util.HashMap; import java.util.Map; import org.junit.Assert; @@ -9,7 +10,7 @@ public class MapUtilsTest { @Test public void shouldPrettyPrintMap() { - final Map map = new HashMap<>(); + final Map map = new LinkedHashMap<>(); map.put(1, "one"); map.put(2, "two"); map.put(3, "three"); From f4cf3049a0cec179660df7d0189599c081a0c690 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 22 Jun 2016 11:40:07 +0300 Subject: [PATCH 241/882] small performance boost in MapUtils --- .../java/com/github/scribejava/core/utils/MapUtils.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/utils/MapUtils.java b/scribejava-core/src/main/java/com/github/scribejava/core/utils/MapUtils.java index bf48341fb..9cb217cb9 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/utils/MapUtils.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/utils/MapUtils.java @@ -14,8 +14,12 @@ public static String toString(Map map) { final StringBuilder result = new StringBuilder(); for (Map.Entry entry : map.entrySet()) { - result.append(String.format(", %s -> %s ", entry.getKey().toString(), entry.getValue().toString())); + result.append(", ") + .append(entry.getKey().toString()) + .append(" -> ") + .append(entry.getValue().toString()) + .append(' '); } - return "{" + result.substring(1) + "}"; + return "{" + result.append('}').substring(1); } } From 9b7751af9954a7e8f89e77f5d19a8ba618fc35cb Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 22 Jun 2016 12:16:46 +0300 Subject: [PATCH 242/882] update LinkedIn API --- changelog | 1 + .../java/com/github/scribejava/apis/LinkedInApi20.java | 10 ++-------- .../scribejava/apis/salesforce/SalesforceToken.java | 2 +- .../scribejava/apis/examples/LinkedIn20Example.java | 2 +- 4 files changed, 5 insertions(+), 10 deletions(-) diff --git a/changelog b/changelog index 93e37cba1..a1ec2596f 100644 --- a/changelog +++ b/changelog @@ -1,5 +1,6 @@ [SNAPSHOT] * add Salesforce API + * update Linked In API [2.7.3] * FIX: ScribeJava shouldn't require all async http client provider to be on the classpath if using only one of them diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi20.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi20.java index b39f4a33b..88dc30e7f 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi20.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi20.java @@ -3,7 +3,6 @@ import com.github.scribejava.apis.service.LinkedIn20ServiceImpl; import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.model.OAuthConfig; -import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.oauth.OAuth20Service; public class LinkedInApi20 extends DefaultApi20 { @@ -19,19 +18,14 @@ public static LinkedInApi20 instance() { return InstanceHolder.INSTANCE; } - @Override - public Verb getAccessTokenVerb() { - return Verb.GET; - } - @Override public String getAccessTokenEndpoint() { - return "https://www.linkedin.com/uas/oauth2/accessToken"; + return "https://www.linkedin.com/oauth/v2/accessToken"; } @Override protected String getAuthorizationBaseUrl() { - return "https://www.linkedin.com/uas/oauth2/authorization"; + return "https://www.linkedin.com/oauth/v2/authorization"; } @Override diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/salesforce/SalesforceToken.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/salesforce/SalesforceToken.java index 548e374ab..14a0911cd 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/salesforce/SalesforceToken.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/salesforce/SalesforceToken.java @@ -6,7 +6,7 @@ public class SalesforceToken extends OAuth2AccessToken { - private static final long serialVersionUID = 7845679917727899612L; + private static final long serialVersionUID = 7496092256264195577L; /** * This token model includes the instance_url to address the needed 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 a39c79890..f29d1907b 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 @@ -21,7 +21,7 @@ public static void main(String... args) throws IOException { final String clientSecret = "your client secret"; final OAuth20Service service = new ServiceBuilder() .apiKey(clientId).apiSecret(clientSecret) - .scope("r_basicprofile,r_emailaddress") // replace with desired scope + .scope("r_basicprofile r_emailaddress") // replace with desired scope .callback("http://example.com/callback") .state("some_params") .build(LinkedInApi20.instance()); From f3feb933e76079639bdf21d2ceaa95c046c59da7 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 23 Jun 2016 10:24:45 +0300 Subject: [PATCH 243/882] prepare 2.8.0 release --- README.md | 4 ++-- changelog | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index a521eb3e9..2c7e892eb 100644 --- a/README.md +++ b/README.md @@ -86,7 +86,7 @@ You can pull ScribeJava from the central maven repository, just add these to you com.github.scribejava scribejava-apis - 2.7.3 + 2.8.0 ``` @@ -95,7 +95,7 @@ And in case you need just core classes (that's it, without any external API (FB, com.github.scribejava scribejava-core - 2.7.3 + 2.8.0 ``` diff --git a/changelog b/changelog index a1ec2596f..b510e4e8c 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,4 @@ -[SNAPSHOT] +[2.8.0] * add Salesforce API * update Linked In API From 8b9365c91a9c4ff543cf9ec87c785efe93e5c9f1 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 23 Jun 2016 10:25:43 +0300 Subject: [PATCH 244/882] [maven-release-plugin] prepare release scribejava-2.8.0 --- pom.xml | 2 +- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 723b1b5e1..31c270adf 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 2.7.4-SNAPSHOT + 2.8.0 ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 465b17303..484a798a8 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 2.7.4-SNAPSHOT + 2.8.0 ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 50e937547..87e01242a 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 2.7.4-SNAPSHOT + 2.8.0 ../pom.xml From 9d93c5b0e2e12ad7926c959cd48ec10b9e258a25 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 23 Jun 2016 10:25:47 +0300 Subject: [PATCH 245/882] [maven-release-plugin] prepare for next development iteration --- pom.xml | 2 +- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 31c270adf..225b9e8c2 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 2.8.0 + 2.8.1-SNAPSHOT ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 484a798a8..5f91a25f1 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 2.8.0 + 2.8.1-SNAPSHOT ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 87e01242a..ee3233c85 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 2.8.0 + 2.8.1-SNAPSHOT ../pom.xml From 4bc60b0b7a9f874dfc2bd18b8f592a95794f0e7b Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 29 Jun 2016 12:44:43 +0300 Subject: [PATCH 246/882] improve comment verbosity a bit for SalesForce and TLS (java7 vs java8) --- .../com/github/scribejava/apis/examples/SalesforceExample.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceExample.java index 3d89c23fb..e17615c99 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceExample.java @@ -23,7 +23,8 @@ public static void main(String... args) throws IOException, NoSuchAlgorithmExcep // Replace these with your client id and secret final String clientId = "your client id"; final String clientSecret = "your client secret"; - //IT's important! Salesforce upper require TLS v1.1 or 1.2 + //IT's important! Salesforce upper require TLS v1.1 or 1.2. + //They are enabled in Java 8 by default, but not in Java 7 SalesforceApi.initTLSv11orUpper(); final OAuth20Service service = new ServiceBuilder() .apiKey(clientId) From 2a94b585835e4f1b1eafea93e988837496f80cfc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Winkelmeyer?= Date: Fri, 1 Jul 2016 16:32:42 +0200 Subject: [PATCH 247/882] Added Salesforce Sandbox support Salesforce differences between access to production systems and sandbox (testing) systems. For that another login/API url must be used. --- .../github/scribejava/apis/SalesforceApi.java | 39 +++++++++++++------ .../apis/examples/SalesforceExample.java | 7 ++++ 2 files changed, 35 insertions(+), 11 deletions(-) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/SalesforceApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/SalesforceApi.java index 49c5f7ec6..95e5e2816 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/SalesforceApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/SalesforceApi.java @@ -14,15 +14,28 @@ /** * This class is an implementation of the Salesforce OAuth2 API. + * The default implementation connects to the Salesforce + * production environment. + * If you want to connect to a Sandbox environment you've to use {@link #sandbox()} method to + * get sandbox instance of this API */ public class SalesforceApi extends DefaultApi20 { - private static final String BASE_URL = "https://login.salesforce.com/services/oauth2"; - private static final String ACCESS_URL = BASE_URL + "/token"; - private static final String AUTHORIZE_URL = BASE_URL + "/authorize"; + private static final String PRODUCTION_HOST = "login.salesforce.com"; + private static final String SANDBOX_HOST = "test.salesforce.com"; + private static final String PROTOCOL = "https://"; + private static final String ACCESS_PATH = "/services/oauth2/token"; + private static final String AUTHORIZE_PATH = "/services/oauth2/authorize"; - protected SalesforceApi() { + private final String accessTokenUrl; + private final String authorizationBaseUrl; + /** + * @param hostName The hostname to be used, which is either {@link #PRODUCTION_HOST} or {@link #SANDBOX_HOST}. + */ + protected SalesforceApi(String hostName) { + accessTokenUrl = PROTOCOL + hostName + ACCESS_PATH; + authorizationBaseUrl = PROTOCOL + hostName + AUTHORIZE_PATH; try { final SSLSocket socket = (SSLSocket) SSLContext.getDefault().getSocketFactory().createSocket(); if (!isTLSv11orUpperEnabled(socket)) { @@ -36,14 +49,17 @@ protected SalesforceApi() { } private static class InstanceHolder { - - private static final SalesforceApi INSTANCE = new SalesforceApi(); + private static final SalesforceApi INSTANCE = new SalesforceApi(PRODUCTION_HOST); } public static SalesforceApi instance() { return InstanceHolder.INSTANCE; } + public static SalesforceApi sandbox() { + return new SalesforceApi(SANDBOX_HOST); + } + @Override public Verb getAccessTokenVerb() { return Verb.POST; @@ -51,12 +67,12 @@ public Verb getAccessTokenVerb() { @Override public String getAccessTokenEndpoint() { - return ACCESS_URL; + return accessTokenUrl; } @Override protected String getAuthorizationBaseUrl() { - return AUTHORIZE_URL; + return authorizationBaseUrl; } @Override @@ -74,14 +90,15 @@ private static boolean isTLSv11orUpperEnabled(final SSLSocket socket) { } /** - * Salesforce API required to use TLSv1.1 or upper. + * Salesforce API requires to use TLSv1.1 or upper. *

* Java 8 have TLS 1.2 enabled by default. java 7 - no, you should invoke this method or turn TLS>=1.1 somehow * else

* * @throws java.security.NoSuchAlgorithmException in case your jvm doesn't support TLSv1.1 and TLSv1.2 - * @throws java.security.KeyManagementException - * @throws java.io.IOException + * @throws java.security.KeyManagementException unexpected Exception from + * {@link SSLContext#init(javax.net.ssl.KeyManager[], javax.net.ssl.TrustManager[], java.security.SecureRandom)} + * @throws java.io.IOException unexpected Exception from {@link javax.net.ssl.SSLSocketFactory#createSocket()} */ public static void initTLSv11orUpper() throws NoSuchAlgorithmException, KeyManagementException, IOException { final SSLSocket socket = (SSLSocket) SSLContext.getDefault().getSocketFactory().createSocket(); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceExample.java index e17615c99..1189fa30c 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceExample.java @@ -26,6 +26,13 @@ public static void main(String... args) throws IOException, NoSuchAlgorithmExcep //IT's important! Salesforce upper require TLS v1.1 or 1.2. //They are enabled in Java 8 by default, but not in Java 7 SalesforceApi.initTLSv11orUpper(); + + // The below used ServiceBuilder connects to login.salesforce.com + // (production environment). + // + // When you plan to connect to a Sandbox environment you've to use SalesforceApi.sandbox() API instance + // new ServiceBuilder.....build(SalesforceApi.sandbox()); + final OAuth20Service service = new ServiceBuilder() .apiKey(clientId) .apiSecret(clientSecret) From b1ccc51c0f3f9a3d08c5894430b101f4f2ad8120 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 4 Jul 2016 19:19:39 +0300 Subject: [PATCH 248/882] update POM dependency versions and remove unused wagon webdav extension --- pom.xml | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/pom.xml b/pom.xml index 225b9e8c2..99b2c216f 100644 --- a/pom.xml +++ b/pom.xml @@ -83,7 +83,7 @@ com.google.code.gson gson - 2.6.2 + 2.7 test @@ -102,7 +102,7 @@ org.asynchttpclient async-http-client - 2.0.4 + 2.0.9 provided @@ -126,7 +126,7 @@ org.apache.maven.plugins maven-jar-plugin - 3.0.0 + 3.0.2 ${project.build.outputDirectory}/META-INF/MANIFEST.MF @@ -135,13 +135,6 @@
- - - org.apache.maven.wagon - wagon-webdav - 1.0-beta-2 - - maven-compiler-plugin @@ -169,7 +162,7 @@ org.apache.maven.plugins maven-resources-plugin - 3.0.0 + 3.0.1 UTF-8 @@ -177,7 +170,7 @@ org.apache.maven.plugins maven-source-plugin - 3.0.0 + 3.0.1 attach-sources @@ -190,7 +183,7 @@ org.apache.maven.plugins maven-javadoc-plugin - 2.10.3 + 2.10.4 UTF-8 @@ -211,7 +204,7 @@ com.puppycrawl.tools checkstyle - 6.19 + 7.0 From 3e4f2ea2bba53c247f7d9062e500873cc2a0d345 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 4 Jul 2016 19:20:44 +0300 Subject: [PATCH 249/882] prepare 2.8.1 release --- README.md | 4 ++-- changelog | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2c7e892eb..993ff954a 100644 --- a/README.md +++ b/README.md @@ -86,7 +86,7 @@ You can pull ScribeJava from the central maven repository, just add these to you com.github.scribejava scribejava-apis - 2.8.0 + 2.8.1 ``` @@ -95,7 +95,7 @@ And in case you need just core classes (that's it, without any external API (FB, com.github.scribejava scribejava-core - 2.8.0 + 2.8.1 ``` diff --git a/changelog b/changelog index b510e4e8c..eee7f1cad 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,6 @@ +[2.8.1] + * add Salesforce sandbox API support + [2.8.0] * add Salesforce API * update Linked In API From 7783dc8333bdfb27ae408f13fe6be7a96e78beaf Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 4 Jul 2016 19:22:33 +0300 Subject: [PATCH 250/882] [maven-release-plugin] prepare release scribejava-2.8.1 --- pom.xml | 2 +- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 99b2c216f..a269e17be 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 2.8.1-SNAPSHOT + 2.8.1 ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 5f91a25f1..f3703d59f 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 2.8.1-SNAPSHOT + 2.8.1 ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index ee3233c85..a276d26ac 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 2.8.1-SNAPSHOT + 2.8.1 ../pom.xml From ce8bc70c75bb9bfac33514c90ee402f4bdd4d7c2 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 4 Jul 2016 19:22:38 +0300 Subject: [PATCH 251/882] [maven-release-plugin] prepare for next development iteration --- pom.xml | 2 +- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index a269e17be..7eeeecff9 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 2.8.1 + 2.8.2-SNAPSHOT ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index f3703d59f..095ecbd2d 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 2.8.1 + 2.8.2-SNAPSHOT ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index a276d26ac..62e072945 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 2.8.1 + 2.8.2-SNAPSHOT ../pom.xml From fd632097101f105c8b8d95a4d5c14725fbb03c0f Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 5 Jul 2016 16:22:35 +0300 Subject: [PATCH 252/882] drop unused Jabber contact --- pom.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/pom.xml b/pom.xml index 7eeeecff9..68bf28a27 100644 --- a/pom.xml +++ b/pom.xml @@ -44,7 +44,6 @@ +3 - kullfar@jabber.ru kullfar@gmail.com +7-909-677-11-16 From c9464faaa18160152848f823eacdb1c732a990a6 Mon Sep 17 00:00:00 2001 From: Julien Herr Date: Tue, 12 Jul 2016 16:38:48 +0200 Subject: [PATCH 253/882] Fix #683 - Extract HTTP client logic into providers --- pom.xml | 14 +- scribejava-apis/pom.xml | 12 ++ .../examples/FacebookAsyncNingExample.java | 7 +- .../examples/Google20AsyncAHCExample.java | 9 +- .../apis/examples/MailruAsyncExample.java | 7 +- .../examples/SalesforceNingAsyncExample.java | 7 +- .../core/builder/ServiceBuilder.java | 36 ++--- .../core/httpclient/HttpClientProvider.java | 8 ++ .../scribejava/core/model/HttpClient.java | 16 +++ .../scribejava/core/model/OAuthConfig.java | 27 +--- .../scribejava/core/oauth/OAuthService.java | 129 +++--------------- scribejava-httpclient-ahc/pom.xml | 42 ++++++ .../httpclient/ahc/AhcHttpClient.java | 63 +++++++++ .../httpclient/ahc/AhcHttpClientConfig.java | 17 +++ .../httpclient/ahc/AhcProvider.java | 15 ++ .../ahc/OAuthAsyncCompletionHandler.java | 2 +- ...ibejava.core.httpclient.HttpClientProvider | 1 + scribejava-httpclient-ning/pom.xml | 42 ++++++ .../httpclient/ning/NingHttpClient.java | 64 +++++++++ .../httpclient/ning/NingHttpClientConfig.java | 26 ++++ .../httpclient/ning/NingProvider.java | 15 ++ .../ning/OAuthAsyncCompletionHandler.java | 2 +- ...ibejava.core.httpclient.HttpClientProvider | 1 + 23 files changed, 378 insertions(+), 184 deletions(-) create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/httpclient/HttpClientProvider.java create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/model/HttpClient.java create mode 100644 scribejava-httpclient-ahc/pom.xml create mode 100644 scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/AhcHttpClient.java create mode 100644 scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/AhcHttpClientConfig.java create mode 100644 scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/AhcProvider.java rename {scribejava-core/src/main/java/com/github/scribejava/core/async => scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient}/ahc/OAuthAsyncCompletionHandler.java (97%) create mode 100644 scribejava-httpclient-ahc/src/main/resources/META-INF/services/com.github.scribejava.core.httpclient.HttpClientProvider create mode 100644 scribejava-httpclient-ning/pom.xml create mode 100644 scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/NingHttpClient.java create mode 100644 scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/NingHttpClientConfig.java create mode 100644 scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/NingProvider.java rename {scribejava-core/src/main/java/com/github/scribejava/core/async => scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient}/ning/OAuthAsyncCompletionHandler.java (97%) create mode 100644 scribejava-httpclient-ning/src/main/resources/META-INF/services/com.github.scribejava.core.httpclient.HttpClientProvider diff --git a/pom.xml b/pom.xml index 68bf28a27..f14895e91 100644 --- a/pom.xml +++ b/pom.xml @@ -17,6 +17,8 @@ scribejava-core scribejava-apis + scribejava-httpclient-ahc + scribejava-httpclient-ning @@ -92,18 +94,6 @@ compile true - - com.ning - async-http-client - 1.9.38 - provided - - - org.asynchttpclient - async-http-client - 2.0.9 - provided - diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 095ecbd2d..703c30f30 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -20,6 +20,18 @@ scribejava-core ${project.version} + + com.github.scribejava + scribejava-ahc + ${project.version} + test + + + com.github.scribejava + scribejava-ning + ${project.version} + test + diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java index 373759c35..a3c99e114 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java @@ -1,5 +1,6 @@ package com.github.scribejava.apis.examples; +import com.github.scribejava.httpclient.ning.NingHttpClientConfig; import com.ning.http.client.AsyncHttpClientConfig; import java.util.Random; import java.util.Scanner; @@ -26,20 +27,20 @@ public static void main(String... args) throws InterruptedException, ExecutionEx final String clientSecret = "your client secret"; final String secretState = "secret" + new Random().nextInt(999_999); ScribeJavaConfig.setForceTypeOfHttpRequests(ForceTypeOfHttpRequest.FORCE_ASYNC_ONLY_HTTP_REQUESTS); - final AsyncHttpClientConfig clientConfig = new AsyncHttpClientConfig.Builder() + final NingHttpClientConfig clientConfig = new NingHttpClientConfig(new AsyncHttpClientConfig.Builder() .setMaxConnections(5) .setRequestTimeout(10_000) .setAllowPoolingConnections(false) .setPooledConnectionIdleTimeout(1_000) .setReadTimeout(1_000) - .build(); + .build()); final OAuth20Service service = new ServiceBuilder() .apiKey(clientId) .apiSecret(clientSecret) .state(secretState) .callback("http://www.example.com/oauth_callback/") - .asyncNingHttpClientConfig(clientConfig) + .httpClientConfig(clientConfig) .build(FacebookApi.instance()); final Scanner in = new Scanner(System.in, "UTF-8"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java index 6ad067acf..abe2fc789 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java @@ -3,8 +3,10 @@ import java.util.Random; import java.util.Scanner; import com.github.scribejava.apis.GoogleApi20; +import com.github.scribejava.httpclient.ahc.AhcHttpClientConfig; import com.github.scribejava.core.builder.ServiceBuilder; import com.github.scribejava.core.model.ForceTypeOfHttpRequest; +import com.github.scribejava.core.model.HttpClient; import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthRequestAsync; import com.github.scribejava.core.model.Response; @@ -15,7 +17,6 @@ import java.util.HashMap; import java.util.Map; import java.util.concurrent.ExecutionException; -import org.asynchttpclient.AsyncHttpClientConfig; import org.asynchttpclient.DefaultAsyncHttpClientConfig; public abstract class Google20AsyncAHCExample { @@ -29,12 +30,12 @@ public static void main(String... args) throws InterruptedException, ExecutionEx final String clientSecret = "your client secret"; final String secretState = "secret" + new Random().nextInt(999_999); ScribeJavaConfig.setForceTypeOfHttpRequests(ForceTypeOfHttpRequest.FORCE_ASYNC_ONLY_HTTP_REQUESTS); - final AsyncHttpClientConfig clientConfig = new DefaultAsyncHttpClientConfig.Builder() + final HttpClient.Config clientConfig = new AhcHttpClientConfig(new DefaultAsyncHttpClientConfig.Builder() .setMaxConnections(5) .setRequestTimeout(10_000) .setPooledConnectionIdleTimeout(1_000) .setReadTimeout(1_000) - .build(); + .build()); final OAuth20Service service = new ServiceBuilder() .apiKey(clientId) @@ -42,7 +43,7 @@ public static void main(String... args) throws InterruptedException, ExecutionEx .scope("profile") // replace with desired scope .state(secretState) .callback("http://example.com/callback") - .asyncAHCHttpClientConfig(clientConfig) + .httpClientConfig(clientConfig) .build(GoogleApi20.instance()); final Scanner in = new Scanner(System.in, "UTF-8"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java index 6ca98d697..a32946ba5 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java @@ -1,5 +1,6 @@ package com.github.scribejava.apis.examples; +import com.github.scribejava.httpclient.ning.NingHttpClientConfig; import com.ning.http.client.AsyncHttpClientConfig; import java.util.Scanner; import java.util.concurrent.ExecutionException; @@ -23,19 +24,19 @@ public static void main(String... args) throws InterruptedException, ExecutionEx final String clientId = "your client id"; final String clientSecret = "your client secret"; - final AsyncHttpClientConfig clientConfig = new AsyncHttpClientConfig.Builder() + final NingHttpClientConfig clientConfig = new NingHttpClientConfig(new AsyncHttpClientConfig.Builder() .setMaxConnections(5) .setRequestTimeout(10_000) .setAllowPoolingConnections(false) .setPooledConnectionIdleTimeout(1_000) .setReadTimeout(10_000) - .build(); + .build()); final OAuth20Service service = new ServiceBuilder() .apiKey(clientId) .apiSecret(clientSecret) .callback("http://www.example.com/oauth_callback/") - .asyncNingHttpClientConfig(clientConfig) + .httpClientConfig(clientConfig) .build(MailruApi.instance()); final Scanner in = new Scanner(System.in, "UTF-8"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceNingAsyncExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceNingAsyncExample.java index 40d72f9da..8b113c399 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceNingAsyncExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceNingAsyncExample.java @@ -9,6 +9,7 @@ import com.github.scribejava.apis.SalesforceApi; import com.github.scribejava.apis.salesforce.SalesforceToken; +import com.github.scribejava.httpclient.ning.NingHttpClientConfig; import com.github.scribejava.core.builder.ServiceBuilder; import com.github.scribejava.core.model.ForceTypeOfHttpRequest; import com.github.scribejava.core.model.OAuthRequestAsync; @@ -32,20 +33,20 @@ public static void main(String... args) throws InterruptedException, ExecutionEx final String clientSecret = "your client secret"; ScribeJavaConfig.setForceTypeOfHttpRequests(ForceTypeOfHttpRequest.FORCE_ASYNC_ONLY_HTTP_REQUESTS); - final AsyncHttpClientConfig clientConfig = new AsyncHttpClientConfig.Builder() + final NingHttpClientConfig clientConfig = new NingHttpClientConfig(new AsyncHttpClientConfig.Builder() .setMaxConnections(5) .setRequestTimeout(10_000) .setAllowPoolingConnections(false) .setPooledConnectionIdleTimeout(1_000) .setReadTimeout(10_000) - .build(); + .build()); //IT's important! Salesforce upper require TLS v1.1 or 1.2 SalesforceApi.initTLSv11orUpper(); final OAuth20Service service = new ServiceBuilder() .apiKey(clientId) .apiSecret(clientSecret) - .asyncNingHttpClientConfig(clientConfig) + .httpClientConfig(clientConfig) .callback("https://www.example.com/callback") .build(SalesforceApi.instance()); diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilder.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilder.java index 12195ab56..143487b1a 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilder.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilder.java @@ -1,13 +1,15 @@ package com.github.scribejava.core.builder; import com.github.scribejava.core.builder.api.BaseApi; +import com.github.scribejava.core.model.HttpClient; import com.github.scribejava.core.model.OAuthConfig; -import java.io.OutputStream; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.SignatureType; import com.github.scribejava.core.oauth.OAuthService; import com.github.scribejava.core.utils.Preconditions; +import java.io.OutputStream; + /** * Implementation of the Builder pattern, with a fluent interface that creates a {@link OAuthService} */ @@ -27,12 +29,8 @@ public class ServiceBuilder { private Integer connectTimeout; private Integer readTimeout; - //async version only - //ning 1.9 - private com.ning.http.client.AsyncHttpClientConfig ningAsyncHttpClientConfig; - private String ningAsyncHttpProviderClassName; - //AHC 2.0 - private org.asynchttpclient.AsyncHttpClientConfig ahcAsyncHttpClientConfig; + //not-default httpclient only + private HttpClient.Config httpClientConfig; public ServiceBuilder() { callback = OAuthConstants.OUT_OF_BAND; @@ -135,24 +133,9 @@ public ServiceBuilder readTimeout(Integer readTimeout) { return this; } - public ServiceBuilder asyncNingHttpClientConfig(com.ning.http.client.AsyncHttpClientConfig asyncHttpClientConfig) { - Preconditions.checkNotNull(asyncHttpClientConfig, "asyncHttpClientConfig can't be null"); - ningAsyncHttpClientConfig = asyncHttpClientConfig; - ahcAsyncHttpClientConfig = null; - return this; - } - - public ServiceBuilder asyncNingHttpProviderClassName(String asyncHttpProviderClassName) { - this.ningAsyncHttpProviderClassName = asyncHttpProviderClassName; - ahcAsyncHttpClientConfig = null; - return this; - } - - public ServiceBuilder asyncAHCHttpClientConfig(org.asynchttpclient.AsyncHttpClientConfig asyncHttpClientConfig) { - Preconditions.checkNotNull(asyncHttpClientConfig, "asyncHttpClientConfig can't be null"); - ahcAsyncHttpClientConfig = asyncHttpClientConfig; - ningAsyncHttpClientConfig = null; - ningAsyncHttpProviderClassName = null; + public ServiceBuilder httpClientConfig(HttpClient.Config httpClientConfig) { + Preconditions.checkNotNull(httpClientConfig, "httpClientConfig can't be null"); + this.httpClientConfig = httpClientConfig; return this; } @@ -173,8 +156,7 @@ public void checkPreconditions() { private OAuthConfig createConfig() { checkPreconditions(); return new OAuthConfig(apiKey, apiSecret, callback, signatureType, scope, debugStream, state, responseType, - userAgent, connectTimeout, readTimeout, ningAsyncHttpClientConfig, ningAsyncHttpProviderClassName, - ahcAsyncHttpClientConfig); + userAgent, connectTimeout, readTimeout, httpClientConfig); } /** diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/HttpClientProvider.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/HttpClientProvider.java new file mode 100644 index 000000000..d7667ee20 --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/HttpClientProvider.java @@ -0,0 +1,8 @@ +package com.github.scribejava.core.httpclient; + +import com.github.scribejava.core.model.HttpClient; + +public interface HttpClientProvider { + + HttpClient createClient(HttpClient.Config httpClientConfig); +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/HttpClient.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/HttpClient.java new file mode 100644 index 000000000..3762f7083 --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/HttpClient.java @@ -0,0 +1,16 @@ +package com.github.scribejava.core.model; + +import java.io.IOException; +import java.util.Map; +import java.util.concurrent.Future; + +public interface HttpClient { + void close() throws IOException; + + Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, + String bodyContents, OAuthAsyncRequestCallback callback, + OAuthRequestAsync.ResponseConverter converter); + + interface Config { + } +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConfig.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConfig.java index d5bba4899..43c23826b 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConfig.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConfig.java @@ -23,20 +23,15 @@ public class OAuthConfig { private final Integer readTimeout; //async version only - //ning 1.9 - private com.ning.http.client.AsyncHttpClientConfig ningAsyncHttpClientConfig; - private String ningAsyncHttpProviderClassName; - //AHC 2.0 - private org.asynchttpclient.AsyncHttpClientConfig ahcAsyncHttpClientConfig; + private HttpClient.Config httpClientConfig; public OAuthConfig(String key, String secret) { - this(key, secret, null, null, null, null, null, null, null, null, null, null, null, null); + this(key, secret, null, null, null, null, null, null, null, null, null, null); } public OAuthConfig(String apiKey, String apiSecret, String callback, SignatureType signatureType, String scope, OutputStream debugStream, String state, String responseType, String userAgent, Integer connectTimeout, - Integer readTimeout, com.ning.http.client.AsyncHttpClientConfig ningAsyncHttpClientConfig, - String ningAsyncHttpProviderClassName, org.asynchttpclient.AsyncHttpClientConfig ahcAsyncHttpClientConfig) { + Integer readTimeout, HttpClient.Config httpClientConfig) { this.apiKey = apiKey; this.apiSecret = apiSecret; this.callback = callback; @@ -48,9 +43,7 @@ public OAuthConfig(String apiKey, String apiSecret, String callback, SignatureTy this.userAgent = userAgent; this.connectTimeout = connectTimeout; this.readTimeout = readTimeout; - this.ningAsyncHttpClientConfig = ningAsyncHttpClientConfig; - this.ningAsyncHttpProviderClassName = ningAsyncHttpProviderClassName; - this.ahcAsyncHttpClientConfig = ahcAsyncHttpClientConfig; + this.httpClientConfig = httpClientConfig; } public String getApiKey() { @@ -104,15 +97,7 @@ public Integer getReadTimeout() { return readTimeout; } - public com.ning.http.client.AsyncHttpClientConfig getNingAsyncHttpClientConfig() { - return ningAsyncHttpClientConfig; - } - - public String getNingAsyncHttpProviderClassName() { - return ningAsyncHttpProviderClassName; - } - - public org.asynchttpclient.AsyncHttpClientConfig getAhcAsyncHttpClientConfig() { - return ahcAsyncHttpClientConfig; + public HttpClient.Config getHttpClientConfig() { + return httpClientConfig; } } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java index 47b40b497..3d8850cde 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java @@ -1,17 +1,18 @@ package com.github.scribejava.core.oauth; import com.github.scribejava.core.exceptions.OAuthException; -import com.github.scribejava.core.model.AbstractRequest; -import static com.github.scribejava.core.model.AbstractRequest.DEFAULT_CONTENT_TYPE; +import com.github.scribejava.core.httpclient.HttpClientProvider; import com.github.scribejava.core.model.ForceTypeOfHttpRequest; +import com.github.scribejava.core.model.HttpClient; import com.github.scribejava.core.model.OAuthAsyncRequestCallback; import com.github.scribejava.core.model.OAuthConfig; -import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.OAuthRequestAsync; import com.github.scribejava.core.model.ScribeJavaConfig; import com.github.scribejava.core.model.Verb; + import java.io.IOException; import java.util.Map; +import java.util.ServiceLoader; import java.util.concurrent.Future; /** @@ -22,24 +23,21 @@ public abstract class OAuthService { private final OAuthConfig config; - private final com.ning.http.client.AsyncHttpClient ningAsyncHttpClient; - private final org.asynchttpclient.AsyncHttpClient ahcAsyncHttpClient; + private final HttpClient httpClient; public OAuthService(OAuthConfig config) { this.config = config; final ForceTypeOfHttpRequest forceTypeOfHttpRequest = ScribeJavaConfig.getForceTypeOfHttpRequests(); - final com.ning.http.client.AsyncHttpClientConfig ningConfig = config.getNingAsyncHttpClientConfig(); - final org.asynchttpclient.AsyncHttpClientConfig ahcConfig = config.getAhcAsyncHttpClientConfig(); + final HttpClient.Config httpClientConfig = config.getHttpClientConfig(); - if (ningConfig == null && ahcConfig == null) { + if (httpClientConfig == null) { if (ForceTypeOfHttpRequest.FORCE_ASYNC_ONLY_HTTP_REQUESTS == forceTypeOfHttpRequest) { throw new OAuthException("Cannot use sync operations, only async"); } if (ForceTypeOfHttpRequest.PREFER_ASYNC_ONLY_HTTP_REQUESTS == forceTypeOfHttpRequest) { config.log("Cannot use sync operations, only async"); } - ningAsyncHttpClient = null; - ahcAsyncHttpClient = null; + httpClient = null; } else { if (ForceTypeOfHttpRequest.FORCE_SYNC_ONLY_HTTP_REQUESTS == forceTypeOfHttpRequest) { throw new OAuthException("Cannot use async operations, only sync"); @@ -48,22 +46,22 @@ public OAuthService(OAuthConfig config) { config.log("Cannot use async operations, only sync"); } - if (ahcConfig == null) { - ningAsyncHttpClient = NingProvider.createClient(config.getNingAsyncHttpProviderClassName(), ningConfig); - ahcAsyncHttpClient = null; - } else { - ahcAsyncHttpClient = AHCProvider.createClient(ahcConfig); - ningAsyncHttpClient = null; + httpClient = getClient(httpClientConfig); + } + } + + private static HttpClient getClient(HttpClient.Config config) { + for (HttpClientProvider provider : ServiceLoader.load(HttpClientProvider.class)) { + final HttpClient client = provider.createClient(config); + if (client != null) { + return client; } } + return null; } public void closeAsyncClient() throws IOException { - if (ahcAsyncHttpClient == null) { - ningAsyncHttpClient.close(); - } else { - ahcAsyncHttpClient.close(); - } + httpClient.close(); } public OAuthConfig getConfig() { @@ -80,94 +78,7 @@ public OAuthConfig getConfig() { public Future executeAsync(Map headers, Verb httpVerb, String completeUrl, String bodyContents, OAuthAsyncRequestCallback callback, OAuthRequestAsync.ResponseConverter converter) { - if (ahcAsyncHttpClient == null) { - return NingProvider.ningExecuteAsync(ningAsyncHttpClient, config.getUserAgent(), headers, httpVerb, - completeUrl, bodyContents, callback, converter); - } else { - return AHCProvider.ahcExecuteAsync(ahcAsyncHttpClient, config.getUserAgent(), headers, httpVerb, + return httpClient.executeAsync(config.getUserAgent(), headers, httpVerb, completeUrl, bodyContents, callback, converter); - } - } - - private static class NingProvider { - - private static com.ning.http.client.AsyncHttpClient createClient(String ningAsyncHttpProviderClassName, - com.ning.http.client.AsyncHttpClientConfig ningConfig) { - return ningAsyncHttpProviderClassName == null - ? new com.ning.http.client.AsyncHttpClient(ningConfig) - : new com.ning.http.client.AsyncHttpClient(ningAsyncHttpProviderClassName, ningConfig); - } - - private static Future ningExecuteAsync(com.ning.http.client.AsyncHttpClient ningAsyncHttpClient, - String userAgent, Map headers, Verb httpVerb, String completeUrl, String bodyContents, - OAuthAsyncRequestCallback callback, OAuthRequestAsync.ResponseConverter converter) { - final com.ning.http.client.AsyncHttpClient.BoundRequestBuilder boundRequestBuilder; - switch (httpVerb) { - case GET: - boundRequestBuilder = ningAsyncHttpClient.prepareGet(completeUrl); - break; - case POST: - com.ning.http.client.AsyncHttpClient.BoundRequestBuilder requestBuilder - = ningAsyncHttpClient.preparePost(completeUrl); - if (!headers.containsKey(AbstractRequest.CONTENT_TYPE)) { - requestBuilder = requestBuilder.addHeader(AbstractRequest.CONTENT_TYPE, DEFAULT_CONTENT_TYPE); - } - boundRequestBuilder = requestBuilder.setBody(bodyContents); - break; - default: - throw new IllegalArgumentException("message build error: unknown verb type"); - } - - for (Map.Entry header : headers.entrySet()) { - boundRequestBuilder.addHeader(header.getKey(), header.getValue()); - } - if (userAgent != null) { - boundRequestBuilder.setHeader(OAuthConstants.USER_AGENT_HEADER_NAME, userAgent); - } - - return boundRequestBuilder - .execute(new com.github.scribejava.core.async.ning.OAuthAsyncCompletionHandler<>( - callback, converter)); - } - } - - private static class AHCProvider { - - private static org.asynchttpclient.AsyncHttpClient createClient( - org.asynchttpclient.AsyncHttpClientConfig ahcConfig) { - return new org.asynchttpclient.DefaultAsyncHttpClient(ahcConfig); - } - - private static Future ahcExecuteAsync(org.asynchttpclient.AsyncHttpClient ahcAsyncHttpClient, - String userAgent, Map headers, Verb httpVerb, String completeUrl, String bodyContents, - OAuthAsyncRequestCallback callback, OAuthRequestAsync.ResponseConverter converter) { - final org.asynchttpclient.BoundRequestBuilder boundRequestBuilder; - switch (httpVerb) { - case GET: - boundRequestBuilder = ahcAsyncHttpClient.prepareGet(completeUrl); - break; - case POST: - org.asynchttpclient.BoundRequestBuilder requestBuilder - = ahcAsyncHttpClient.preparePost(completeUrl); - if (!headers.containsKey(AbstractRequest.CONTENT_TYPE)) { - requestBuilder = requestBuilder.addHeader(AbstractRequest.CONTENT_TYPE, DEFAULT_CONTENT_TYPE); - } - boundRequestBuilder = requestBuilder.setBody(bodyContents); - break; - default: - throw new IllegalArgumentException("message build error: unknown verb type"); - } - - for (Map.Entry header : headers.entrySet()) { - boundRequestBuilder.addHeader(header.getKey(), header.getValue()); - } - if (userAgent != null) { - boundRequestBuilder.setHeader(OAuthConstants.USER_AGENT_HEADER_NAME, userAgent); - } - - return boundRequestBuilder - .execute(new com.github.scribejava.core.async.ahc.OAuthAsyncCompletionHandler<>( - callback, converter)); - } } } diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml new file mode 100644 index 000000000..46c56143a --- /dev/null +++ b/scribejava-httpclient-ahc/pom.xml @@ -0,0 +1,42 @@ + + + 4.0.0 + + + com.github.scribejava + scribejava + 2.8.2-SNAPSHOT + ../pom.xml + + + com.github.scribejava + scribejava-ahc + ScribeJava Async Http Client support + jar + + + + com.github.scribejava + scribejava-core + ${project.version} + + + org.asynchttpclient + async-http-client + 2.0.9 + + + + + + + org.apache.felix + maven-bundle-plugin + + + org.apache.maven.plugins + maven-jar-plugin + + + + 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 new file mode 100644 index 000000000..69913ac18 --- /dev/null +++ b/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/AhcHttpClient.java @@ -0,0 +1,63 @@ +package com.github.scribejava.httpclient.ahc; + +import com.github.scribejava.core.model.AbstractRequest; +import com.github.scribejava.core.model.HttpClient; +import com.github.scribejava.core.model.OAuthAsyncRequestCallback; +import com.github.scribejava.core.model.OAuthConstants; +import com.github.scribejava.core.model.OAuthRequestAsync; +import com.github.scribejava.core.model.Verb; +import org.asynchttpclient.AsyncHttpClient; +import org.asynchttpclient.DefaultAsyncHttpClient; + +import java.io.IOException; +import java.util.Map; +import java.util.concurrent.Future; + +import static com.github.scribejava.core.model.AbstractRequest.DEFAULT_CONTENT_TYPE; + +public class AhcHttpClient implements HttpClient { + + private final AsyncHttpClient client; + + public AhcHttpClient(AhcHttpClientConfig ahcConfig) { + client = new DefaultAsyncHttpClient(ahcConfig.getClientConfig()); + } + + @Override + public void close() throws IOException { + client.close(); + } + + @Override + public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, + String bodyContents, OAuthAsyncRequestCallback callback, + OAuthRequestAsync.ResponseConverter converter) { + final org.asynchttpclient.BoundRequestBuilder boundRequestBuilder; + switch (httpVerb) { + case GET: + boundRequestBuilder = client.prepareGet(completeUrl); + break; + case POST: + org.asynchttpclient.BoundRequestBuilder requestBuilder + = client.preparePost(completeUrl); + if (!headers.containsKey(AbstractRequest.CONTENT_TYPE)) { + requestBuilder = requestBuilder.addHeader(AbstractRequest.CONTENT_TYPE, DEFAULT_CONTENT_TYPE); + } + boundRequestBuilder = requestBuilder.setBody(bodyContents); + break; + default: + throw new IllegalArgumentException("message build error: unknown verb type"); + } + + for (Map.Entry header : headers.entrySet()) { + boundRequestBuilder.addHeader(header.getKey(), header.getValue()); + } + if (userAgent != null) { + boundRequestBuilder.setHeader(OAuthConstants.USER_AGENT_HEADER_NAME, userAgent); + } + + return boundRequestBuilder + .execute(new OAuthAsyncCompletionHandler<>( + callback, converter)); + } +} diff --git a/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/AhcHttpClientConfig.java b/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/AhcHttpClientConfig.java new file mode 100644 index 000000000..bc6820281 --- /dev/null +++ b/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/AhcHttpClientConfig.java @@ -0,0 +1,17 @@ +package com.github.scribejava.httpclient.ahc; + +import com.github.scribejava.core.model.HttpClient; +import org.asynchttpclient.AsyncHttpClientConfig; + +public class AhcHttpClientConfig implements HttpClient.Config { + + private final AsyncHttpClientConfig clientConfig; + + public AhcHttpClientConfig(AsyncHttpClientConfig clientConfig) { + this.clientConfig = clientConfig; + } + + public AsyncHttpClientConfig getClientConfig() { + return clientConfig; + } +} diff --git a/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/AhcProvider.java b/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/AhcProvider.java new file mode 100644 index 000000000..835ba5f03 --- /dev/null +++ b/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/AhcProvider.java @@ -0,0 +1,15 @@ +package com.github.scribejava.httpclient.ahc; + +import com.github.scribejava.core.httpclient.HttpClientProvider; +import com.github.scribejava.core.model.HttpClient; + +public class AhcProvider implements HttpClientProvider { + + @Override + public HttpClient createClient(HttpClient.Config config) { + if (config instanceof AhcHttpClientConfig) { + return new AhcHttpClient((AhcHttpClientConfig) config); + } + return null; + } +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/async/ahc/OAuthAsyncCompletionHandler.java b/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/OAuthAsyncCompletionHandler.java similarity index 97% rename from scribejava-core/src/main/java/com/github/scribejava/core/async/ahc/OAuthAsyncCompletionHandler.java rename to scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/OAuthAsyncCompletionHandler.java index b556fb6ad..b19e3c3a7 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/async/ahc/OAuthAsyncCompletionHandler.java +++ b/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/OAuthAsyncCompletionHandler.java @@ -1,4 +1,4 @@ -package com.github.scribejava.core.async.ahc; +package com.github.scribejava.httpclient.ahc; import com.github.scribejava.core.model.OAuthAsyncRequestCallback; import com.github.scribejava.core.model.OAuthRequestAsync; diff --git a/scribejava-httpclient-ahc/src/main/resources/META-INF/services/com.github.scribejava.core.httpclient.HttpClientProvider b/scribejava-httpclient-ahc/src/main/resources/META-INF/services/com.github.scribejava.core.httpclient.HttpClientProvider new file mode 100644 index 000000000..5de919067 --- /dev/null +++ b/scribejava-httpclient-ahc/src/main/resources/META-INF/services/com.github.scribejava.core.httpclient.HttpClientProvider @@ -0,0 +1 @@ +com.github.scribejava.httpclient.ahc.AhcProvider \ No newline at end of file diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml new file mode 100644 index 000000000..b5690232d --- /dev/null +++ b/scribejava-httpclient-ning/pom.xml @@ -0,0 +1,42 @@ + + + 4.0.0 + + + com.github.scribejava + scribejava + 2.8.2-SNAPSHOT + ../pom.xml + + + com.github.scribejava + scribejava-ning + ScribeJava Ning Async client support + jar + + + + com.github.scribejava + scribejava-core + ${project.version} + + + com.ning + async-http-client + 1.9.38 + + + + + + + org.apache.felix + maven-bundle-plugin + + + org.apache.maven.plugins + maven-jar-plugin + + + + 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 new file mode 100644 index 000000000..6916315fc --- /dev/null +++ b/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/NingHttpClient.java @@ -0,0 +1,64 @@ +package com.github.scribejava.httpclient.ning; + +import com.github.scribejava.core.model.AbstractRequest; +import com.github.scribejava.core.model.HttpClient; +import com.github.scribejava.core.model.OAuthAsyncRequestCallback; +import com.github.scribejava.core.model.OAuthConstants; +import com.github.scribejava.core.model.OAuthRequestAsync; +import com.github.scribejava.core.model.Verb; +import com.ning.http.client.AsyncHttpClient; + +import java.util.Map; +import java.util.concurrent.Future; + +import static com.github.scribejava.core.model.AbstractRequest.DEFAULT_CONTENT_TYPE; + +public class NingHttpClient implements HttpClient { + + private final AsyncHttpClient client; + + public NingHttpClient(NingHttpClientConfig ningConfig) { + final String ningAsyncHttpProviderClassName = ningConfig.getNingAsyncHttpProviderClassName(); + client = ningAsyncHttpProviderClassName == null + ? new com.ning.http.client.AsyncHttpClient(ningConfig.getConfig()) + : new com.ning.http.client.AsyncHttpClient(ningAsyncHttpProviderClassName, ningConfig.getConfig()); + } + + @Override + public void close() { + client.close(); + } + + @Override + public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, + String bodyContents, OAuthAsyncRequestCallback callback, + OAuthRequestAsync.ResponseConverter converter) { + final com.ning.http.client.AsyncHttpClient.BoundRequestBuilder boundRequestBuilder; + switch (httpVerb) { + case GET: + boundRequestBuilder = client.prepareGet(completeUrl); + break; + case POST: + com.ning.http.client.AsyncHttpClient.BoundRequestBuilder requestBuilder + = client.preparePost(completeUrl); + if (!headers.containsKey(AbstractRequest.CONTENT_TYPE)) { + requestBuilder = requestBuilder.addHeader(AbstractRequest.CONTENT_TYPE, DEFAULT_CONTENT_TYPE); + } + boundRequestBuilder = requestBuilder.setBody(bodyContents); + break; + default: + throw new IllegalArgumentException("message build error: unknown verb type"); + } + + for (Map.Entry header : headers.entrySet()) { + boundRequestBuilder.addHeader(header.getKey(), header.getValue()); + } + if (userAgent != null) { + boundRequestBuilder.setHeader(OAuthConstants.USER_AGENT_HEADER_NAME, userAgent); + } + + return boundRequestBuilder + .execute(new OAuthAsyncCompletionHandler<>( + callback, converter)); + } +} diff --git a/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/NingHttpClientConfig.java b/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/NingHttpClientConfig.java new file mode 100644 index 000000000..f25d91e54 --- /dev/null +++ b/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/NingHttpClientConfig.java @@ -0,0 +1,26 @@ +package com.github.scribejava.httpclient.ning; + +import com.github.scribejava.core.model.HttpClient; +import com.ning.http.client.AsyncHttpClientConfig; + +public class NingHttpClientConfig implements HttpClient.Config { + + private final AsyncHttpClientConfig config; + private String ningAsyncHttpProviderClassName; + + public NingHttpClientConfig(AsyncHttpClientConfig config) { + this.config = config; + } + + public String getNingAsyncHttpProviderClassName() { + return ningAsyncHttpProviderClassName; + } + + public void setNingAsyncHttpProviderClassName(String ningAsyncHttpProviderClassName) { + this.ningAsyncHttpProviderClassName = ningAsyncHttpProviderClassName; + } + + public AsyncHttpClientConfig getConfig() { + return config; + } +} diff --git a/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/NingProvider.java b/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/NingProvider.java new file mode 100644 index 000000000..bfd4bce96 --- /dev/null +++ b/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/NingProvider.java @@ -0,0 +1,15 @@ +package com.github.scribejava.httpclient.ning; + +import com.github.scribejava.core.httpclient.HttpClientProvider; +import com.github.scribejava.core.model.HttpClient; + +public class NingProvider implements HttpClientProvider { + + @Override + public HttpClient createClient(HttpClient.Config httpClientConfig) { + if (httpClientConfig instanceof NingHttpClientConfig) { + return new NingHttpClient((NingHttpClientConfig) httpClientConfig); + } + return null; + } +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/async/ning/OAuthAsyncCompletionHandler.java b/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/OAuthAsyncCompletionHandler.java similarity index 97% rename from scribejava-core/src/main/java/com/github/scribejava/core/async/ning/OAuthAsyncCompletionHandler.java rename to scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/OAuthAsyncCompletionHandler.java index adbcf10bb..2f176e6b0 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/async/ning/OAuthAsyncCompletionHandler.java +++ b/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/OAuthAsyncCompletionHandler.java @@ -1,4 +1,4 @@ -package com.github.scribejava.core.async.ning; +package com.github.scribejava.httpclient.ning; import com.github.scribejava.core.model.OAuthAsyncRequestCallback; import com.github.scribejava.core.model.OAuthRequestAsync; diff --git a/scribejava-httpclient-ning/src/main/resources/META-INF/services/com.github.scribejava.core.httpclient.HttpClientProvider b/scribejava-httpclient-ning/src/main/resources/META-INF/services/com.github.scribejava.core.httpclient.HttpClientProvider new file mode 100644 index 000000000..7d8903d80 --- /dev/null +++ b/scribejava-httpclient-ning/src/main/resources/META-INF/services/com.github.scribejava.core.httpclient.HttpClientProvider @@ -0,0 +1 @@ +com.github.scribejava.httpclient.ning.NingProvider \ No newline at end of file From 8c2f85bcc269e85c9609ad78a65bf5ebcc7d4ebe Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 13 Jul 2016 14:50:10 +0300 Subject: [PATCH 254/882] improve some small issues in prev. commit --- README.md | 4 ++-- changelog | 3 +++ scribejava-apis/pom.xml | 4 ++-- scribejava-httpclient-ahc/pom.xml | 4 ++-- .../scribejava/httpclient/ahc/AhcHttpClient.java | 6 +++--- ...ithub.scribejava.core.httpclient.HttpClientProvider | 2 +- scribejava-httpclient-ning/pom.xml | 4 ++-- .../scribejava/httpclient/ning/NingHttpClient.java | 10 ++++------ ...ithub.scribejava.core.httpclient.HttpClientProvider | 2 +- 9 files changed, 20 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 993ff954a..8324bfd87 100644 --- a/README.md +++ b/README.md @@ -19,9 +19,9 @@ That **single line** (added newlines for readability) is the only thing you need Hit ScribeJava as hard and with many threads as you like. -### Async +### Async and other HTTP clients -You can use ning async http client out-of-box, just use ServiceBuilderAsync +You can use ning async http client 1.9.x or asynchttpclient 2.x out-of-box, just add maven modules scribejava-httpclient-ning or scribejava-httpclient-ahc to your pom ### Supports all major 1.0a and 2.0 OAuth APIs out-of-the-box diff --git a/changelog b/changelog index eee7f1cad..9cb5fda5f 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,6 @@ +[SNAPSHOT] + * create abstract HTTP Client layer to support different HTTP clients as plugins (AHC and Ning support becames maven submodules) + [2.8.1] * add Salesforce sandbox API support diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 703c30f30..c466847e6 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -22,13 +22,13 @@ com.github.scribejava - scribejava-ahc + scribejava-httpclient-ahc ${project.version} test com.github.scribejava - scribejava-ning + scribejava-httpclient-ning ${project.version} test diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 46c56143a..d47cc3c1c 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -10,8 +10,8 @@ com.github.scribejava - scribejava-ahc - ScribeJava Async Http Client support + scribejava-httpclient-ahc + ScribeJava Async Http Http Client support jar 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 69913ac18..a6950b51e 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 @@ -14,6 +14,7 @@ import java.util.concurrent.Future; import static com.github.scribejava.core.model.AbstractRequest.DEFAULT_CONTENT_TYPE; +import org.asynchttpclient.BoundRequestBuilder; public class AhcHttpClient implements HttpClient { @@ -32,14 +33,13 @@ public void close() throws IOException { public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, String bodyContents, OAuthAsyncRequestCallback callback, OAuthRequestAsync.ResponseConverter converter) { - final org.asynchttpclient.BoundRequestBuilder boundRequestBuilder; + final BoundRequestBuilder boundRequestBuilder; switch (httpVerb) { case GET: boundRequestBuilder = client.prepareGet(completeUrl); break; case POST: - org.asynchttpclient.BoundRequestBuilder requestBuilder - = client.preparePost(completeUrl); + BoundRequestBuilder requestBuilder = client.preparePost(completeUrl); if (!headers.containsKey(AbstractRequest.CONTENT_TYPE)) { requestBuilder = requestBuilder.addHeader(AbstractRequest.CONTENT_TYPE, DEFAULT_CONTENT_TYPE); } diff --git a/scribejava-httpclient-ahc/src/main/resources/META-INF/services/com.github.scribejava.core.httpclient.HttpClientProvider b/scribejava-httpclient-ahc/src/main/resources/META-INF/services/com.github.scribejava.core.httpclient.HttpClientProvider index 5de919067..bbe752ff6 100644 --- a/scribejava-httpclient-ahc/src/main/resources/META-INF/services/com.github.scribejava.core.httpclient.HttpClientProvider +++ b/scribejava-httpclient-ahc/src/main/resources/META-INF/services/com.github.scribejava.core.httpclient.HttpClientProvider @@ -1 +1 @@ -com.github.scribejava.httpclient.ahc.AhcProvider \ No newline at end of file +com.github.scribejava.httpclient.ahc.AhcProvider diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index b5690232d..b286741ac 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -10,8 +10,8 @@ com.github.scribejava - scribejava-ning - ScribeJava Ning Async client support + scribejava-httpclient-ning + ScribeJava Ning Async Http Client support jar 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 6916315fc..62c56be81 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 @@ -19,9 +19,8 @@ public class NingHttpClient implements HttpClient { public NingHttpClient(NingHttpClientConfig ningConfig) { final String ningAsyncHttpProviderClassName = ningConfig.getNingAsyncHttpProviderClassName(); - client = ningAsyncHttpProviderClassName == null - ? new com.ning.http.client.AsyncHttpClient(ningConfig.getConfig()) - : new com.ning.http.client.AsyncHttpClient(ningAsyncHttpProviderClassName, ningConfig.getConfig()); + client = ningAsyncHttpProviderClassName == null ? new AsyncHttpClient(ningConfig.getConfig()) + : new AsyncHttpClient(ningAsyncHttpProviderClassName, ningConfig.getConfig()); } @Override @@ -33,14 +32,13 @@ public void close() { public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, String bodyContents, OAuthAsyncRequestCallback callback, OAuthRequestAsync.ResponseConverter converter) { - final com.ning.http.client.AsyncHttpClient.BoundRequestBuilder boundRequestBuilder; + final AsyncHttpClient.BoundRequestBuilder boundRequestBuilder; switch (httpVerb) { case GET: boundRequestBuilder = client.prepareGet(completeUrl); break; case POST: - com.ning.http.client.AsyncHttpClient.BoundRequestBuilder requestBuilder - = client.preparePost(completeUrl); + AsyncHttpClient.BoundRequestBuilder requestBuilder = client.preparePost(completeUrl); if (!headers.containsKey(AbstractRequest.CONTENT_TYPE)) { requestBuilder = requestBuilder.addHeader(AbstractRequest.CONTENT_TYPE, DEFAULT_CONTENT_TYPE); } diff --git a/scribejava-httpclient-ning/src/main/resources/META-INF/services/com.github.scribejava.core.httpclient.HttpClientProvider b/scribejava-httpclient-ning/src/main/resources/META-INF/services/com.github.scribejava.core.httpclient.HttpClientProvider index 7d8903d80..9f6843994 100644 --- a/scribejava-httpclient-ning/src/main/resources/META-INF/services/com.github.scribejava.core.httpclient.HttpClientProvider +++ b/scribejava-httpclient-ning/src/main/resources/META-INF/services/com.github.scribejava.core.httpclient.HttpClientProvider @@ -1 +1 @@ -com.github.scribejava.httpclient.ning.NingProvider \ No newline at end of file +com.github.scribejava.httpclient.ning.NingProvider From 12d7a0d209d53dc21050e0bc32a8472eb2799645 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 13 Jul 2016 17:30:26 +0300 Subject: [PATCH 255/882] fix README (info about artifacts not released to the maven central yet) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8324bfd87..8471ae9a7 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ Hit ScribeJava as hard and with many threads as you like. ### Async and other HTTP clients -You can use ning async http client 1.9.x or asynchttpclient 2.x out-of-box, just add maven modules scribejava-httpclient-ning or scribejava-httpclient-ahc to your pom +You can use ning async http client 1.9.x or asynchttpclient 2.x out-of-box, just add maven modules scribejava-httpclient-ning or scribejava-httpclient-ahc to your pom (not in maven central yet, wait for next relase after 2.8.1) ### Supports all major 1.0a and 2.0 OAuth APIs out-of-the-box From 7ece09d891cbd7f2eef3a162b9a9846ad389d326 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 22 Jul 2016 12:39:12 +0300 Subject: [PATCH 256/882] remove changing global JVM property http.keepAlive, deprecate controlling this property inside of ScribeJava (thanks to wldaunfr and rockihack) --- changelog | 1 + .../github/scribejava/core/model/AbstractRequest.java | 9 +++------ .../com/github/scribejava/core/model/OAuthRequest.java | 1 - 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/changelog b/changelog index 9cb5fda5f..b22949039 100644 --- a/changelog +++ b/changelog @@ -1,5 +1,6 @@ [SNAPSHOT] * 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 diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/AbstractRequest.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/AbstractRequest.java index 4db6ccec7..3c994c1d9 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/AbstractRequest.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/AbstractRequest.java @@ -24,7 +24,6 @@ public abstract class AbstractRequest { private final ParameterList querystringParams = new ParameterList(); private final ParameterList bodyParams = new ParameterList(); private final Map headers = new HashMap<>(); - private boolean connectionKeepAlive; private boolean followRedirects = true; private final OAuthService service; @@ -262,9 +261,11 @@ public void setCharset(String charsetName) { * * @see http://download.oracle.com/javase/1.5.0/docs/guide/net/http-keepalive.html + * @deprecated does nothing - JVM default is left untouched. Set {@code http.keepAlive} system property to + * {@code false} for pre-deprecation behavior. */ + @Deprecated public void setConnectionKeepAlive(boolean connectionKeepAlive) { - this.connectionKeepAlive = connectionKeepAlive; } /** @@ -280,10 +281,6 @@ public void setFollowRedirects(boolean followRedirects) { this.followRedirects = followRedirects; } - public boolean isConnectionKeepAlive() { - return connectionKeepAlive; - } - public boolean isFollowRedirects() { return followRedirects; } 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 230cd15b9..fa7212a9e 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 @@ -60,7 +60,6 @@ Response doSend() throws IOException { private void createConnection() throws IOException { final String completeUrl = getCompleteUrl(); if (connection == null) { - System.setProperty("http.keepAlive", isConnectionKeepAlive() ? "true" : "false"); connection = (HttpURLConnection) new URL(completeUrl).openConnection(); connection.setInstanceFollowRedirects(isFollowRedirects()); } From 6b19f7ba1bb3c034a61ffa755689d3fc5fd040f2 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 22 Jul 2016 12:42:49 +0300 Subject: [PATCH 257/882] update AHC http client --- scribejava-httpclient-ahc/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index d47cc3c1c..3528e59c1 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -23,7 +23,7 @@ org.asynchttpclient async-http-client - 2.0.9 + 2.0.10 From eea19428964a17a792fecdc0b11a9d0fcc6b9929 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 22 Jul 2016 12:49:11 +0300 Subject: [PATCH 258/882] prepare to release 3.0.0 --- README.md | 6 +++--- changelog | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 8471ae9a7..c790a7e9e 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ Hit ScribeJava as hard and with many threads as you like. ### Async and other HTTP clients -You can use ning async http client 1.9.x or asynchttpclient 2.x out-of-box, just add maven modules scribejava-httpclient-ning or scribejava-httpclient-ahc to your pom (not in maven central yet, wait for next relase after 2.8.1) +You can use ning async http client 1.9.x or asynchttpclient 2.x out-of-box, just add maven modules scribejava-httpclient-ning or scribejava-httpclient-ahc to your pom ### Supports all major 1.0a and 2.0 OAuth APIs out-of-the-box @@ -86,7 +86,7 @@ You can pull ScribeJava from the central maven repository, just add these to you com.github.scribejava scribejava-apis - 2.8.1 + 3.0.0 ``` @@ -95,7 +95,7 @@ And in case you need just core classes (that's it, without any external API (FB, com.github.scribejava scribejava-core - 2.8.1 + 3.0.0 ``` diff --git a/changelog b/changelog index b22949039..3a6b7b42c 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,4 @@ -[SNAPSHOT] +[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) From 81b68520e3455e347cf7e2fbe2f7c156c20e56a8 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 22 Jul 2016 12:50:21 +0300 Subject: [PATCH 259/882] [maven-release-plugin] prepare release scribejava-3.0.0 --- pom.xml | 2 +- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index f14895e91..08d5b34b1 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 2.8.2-SNAPSHOT + 3.0.0 ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index c466847e6..7d1de1f45 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 2.8.2-SNAPSHOT + 3.0.0 ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 62e072945..4caa80b69 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 2.8.2-SNAPSHOT + 3.0.0 ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 3528e59c1..019190a60 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 2.8.2-SNAPSHOT + 3.0.0 ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index b286741ac..53ec3aba0 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 2.8.2-SNAPSHOT + 3.0.0 ../pom.xml From 196ef1d6397e1c6dfa8149ce0d73735dd1df70a0 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 22 Jul 2016 12:50:26 +0300 Subject: [PATCH 260/882] [maven-release-plugin] prepare for next development iteration --- pom.xml | 2 +- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index 08d5b34b1..96d232e96 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 3.0.0 + 3.0.1-SNAPSHOT ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 7d1de1f45..9d8462956 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 3.0.0 + 3.0.1-SNAPSHOT ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 4caa80b69..26857c334 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 3.0.0 + 3.0.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 019190a60..ca25a40d0 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 3.0.0 + 3.0.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index 53ec3aba0..16f10c65b 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 3.0.0 + 3.0.1-SNAPSHOT ../pom.xml From c5885c498b358bf091eb8815fdf2c848c9de49b9 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 25 Jul 2016 17:06:33 +0300 Subject: [PATCH 261/882] fix google url in the README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c790a7e9e..c4cb8862b 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ You can use ning async http client 1.9.x or asynchttpclient 2.x out-of-box, just * Freelancer (https://www.freelancer.com/) * Genius (http://genius.com/) * GitHub (https://github.com/) -* Google (https://www.google.ru/) +* Google (https://www.google.com/) * HeadHunter ХэдХантер (https://hh.ru/) * Imgur (http://imgur.com/) * Kaixin 开心网 (http://www.kaixin001.com/) From 15d4bf38c7b4d2750cd6bcacf336c5e4a51f788a Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 12 Aug 2016 17:08:54 +0300 Subject: [PATCH 262/882] make ScribeJava compilable under jdk7 (checkstyle downgraded for jdk 1.7) --- pom.xml | 44 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 36 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index 96d232e96..14244c926 100644 --- a/pom.xml +++ b/pom.xml @@ -122,6 +122,18 @@ + + org.apache.maven.plugins + maven-checkstyle-plugin + 2.17 + + + com.puppycrawl.tools + checkstyle + 7.1 + + + @@ -188,14 +200,6 @@ org.apache.maven.plugins maven-checkstyle-plugin - 2.17 - - - com.puppycrawl.tools - checkstyle - 7.0 - - validate @@ -216,6 +220,30 @@ + + jdk-1.7 + + 1.7 + + + + + + org.apache.maven.plugins + maven-checkstyle-plugin + 2.17 + + + com.puppycrawl.tools + checkstyle + 6.19 + + + + + + + release-sign-artifacts From 74ce58569678927dded44f772449207a5364c890 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 12 Aug 2016 17:12:15 +0300 Subject: [PATCH 263/882] update maven deps --- pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 14244c926..6f09b33da 100644 --- a/pom.xml +++ b/pom.xml @@ -101,7 +101,7 @@ org.apache.felix maven-bundle-plugin - 3.0.1 + 3.2.0 bundle-manifest diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index ca25a40d0..2a9ec4778 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -23,7 +23,7 @@ org.asynchttpclient async-http-client - 2.0.10 + 2.0.11 diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index 16f10c65b..da076a3e5 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -23,7 +23,7 @@ com.ning async-http-client - 1.9.38 + 1.9.39 From 7a24f820bae63e2baadebc26723fa69133c2bba1 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 12 Aug 2016 17:51:45 +0300 Subject: [PATCH 264/882] add travis CI (check [oracle|open]jdk7 oraclejdk8) --- .travis.yml | 8 ++++++++ README.md | 4 ++++ changelog | 4 ++++ 3 files changed, 16 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 000000000..a79954ad5 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,8 @@ +language: java +script: mvn clean package +jdk: + - oraclejdk8 + - oraclejdk7 + - openjdk7 +os: + - linux diff --git a/README.md b/README.md index c4cb8862b..7327d33e8 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,9 @@ # Welcome to the home of ScribeJava, the simple OAuth Java lib! +[![Build Status](https://travis-ci.org/scribejava/scribejava.svg?branch=master)](https://travis-ci.org/scribejava/scribejava) +[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.github.scribejava/scribejava/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.github.scribejava/scribejava) + + # Why use ScribeJava? ### Dead Simple diff --git a/changelog b/changelog index 3a6b7b42c..e46cced96 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,7 @@ +[SNAPSHOT] + * 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) From 5aea73380a13ab740211184e313c05a89d7188f8 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 26 Aug 2016 18:56:52 +0300 Subject: [PATCH 265/882] update async-http-client --- scribejava-httpclient-ahc/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 2a9ec4778..dfc65bd97 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -23,7 +23,7 @@ org.asynchttpclient async-http-client - 2.0.11 + 2.0.12 From 33deb8d9fd7f49bd33224a517c234b4e081027f4 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 26 Aug 2016 18:59:34 +0300 Subject: [PATCH 266/882] improve main README --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7327d33e8..11155e6cf 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Welcome to the home of ScribeJava, the simple OAuth Java lib! +# Welcome to the home of ScribeJava, the simple OAuth client Java lib! [![Build Status](https://travis-ci.org/scribejava/scribejava.svg?branch=master)](https://travis-ci.org/scribejava/scribejava) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.github.scribejava/scribejava/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.github.scribejava/scribejava) @@ -19,6 +19,8 @@ OAuthService service = new ServiceBuilder() That **single line** (added newlines for readability) is the only thing you need to configure ScribeJava with LinkedIn's OAuth API for example. +Working runnable examples are [here](https://github.com/scribejava/scribejava/tree/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples) + ### Threadsafe Hit ScribeJava as hard and with many threads as you like. From 56029523e7853764560a113ca4ee67e356d2443a Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 26 Aug 2016 19:37:13 +0300 Subject: [PATCH 267/882] do not misuse abstract keyword --- .../com/github/scribejava/apis/examples/AWeberExample.java | 5 ++++- .../com/github/scribejava/apis/examples/DiggExample.java | 5 ++++- .../scribejava/apis/examples/FacebookAsyncNingExample.java | 5 ++++- .../com/github/scribejava/apis/examples/FacebookExample.java | 5 ++++- .../com/github/scribejava/apis/examples/FlickrExample.java | 5 ++++- .../github/scribejava/apis/examples/Foursquare2Example.java | 5 ++++- .../github/scribejava/apis/examples/FoursquareExample.java | 5 ++++- .../github/scribejava/apis/examples/FreelancerExample.java | 5 ++++- .../com/github/scribejava/apis/examples/GeniusExample.java | 5 ++++- .../com/github/scribejava/apis/examples/GitHubExample.java | 5 ++++- .../scribejava/apis/examples/Google20AsyncAHCExample.java | 5 ++++- .../com/github/scribejava/apis/examples/Google20Example.java | 5 ++++- .../java/com/github/scribejava/apis/examples/HHExample.java | 5 ++++- .../com/github/scribejava/apis/examples/ImgurExample.java | 5 ++++- .../com/github/scribejava/apis/examples/Kaixin20Example.java | 5 ++++- .../github/scribejava/apis/examples/LinkedIn20Example.java | 5 ++++- .../com/github/scribejava/apis/examples/LinkedInExample.java | 5 ++++- .../scribejava/apis/examples/LinkedInExampleWithScopes.java | 5 ++++- .../com/github/scribejava/apis/examples/LiveExample.java | 5 ++++- .../github/scribejava/apis/examples/MailruAsyncExample.java | 5 ++++- .../com/github/scribejava/apis/examples/MailruExample.java | 5 ++++- .../com/github/scribejava/apis/examples/MeetupExample.java | 5 ++++- .../com/github/scribejava/apis/examples/MisfitExample.java | 5 ++++- .../github/scribejava/apis/examples/NeteaseWeiboExample.java | 5 ++++- .../scribejava/apis/examples/OdnoklassnikiExample.java | 5 ++++- .../github/scribejava/apis/examples/PinterestExample.java | 5 ++++- .../com/github/scribejava/apis/examples/Px500Example.java | 5 ++++- .../com/github/scribejava/apis/examples/RenrenExample.java | 5 ++++- .../github/scribejava/apis/examples/SalesforceExample.java | 5 ++++- .../scribejava/apis/examples/SalesforceNingAsyncExample.java | 5 ++++- .../github/scribejava/apis/examples/SinaWeibo2Example.java | 5 ++++- .../github/scribejava/apis/examples/SinaWeiboExample.java | 5 ++++- .../com/github/scribejava/apis/examples/SkyrockExample.java | 5 ++++- .../github/scribejava/apis/examples/SohuWeiboExample.java | 5 ++++- .../scribejava/apis/examples/StackExchangeExample.java | 5 ++++- .../com/github/scribejava/apis/examples/TrelloExample.java | 5 ++++- .../com/github/scribejava/apis/examples/TumblrExample.java | 5 ++++- .../com/github/scribejava/apis/examples/TutByExample.java | 5 ++++- .../com/github/scribejava/apis/examples/TwitterExample.java | 5 ++++- .../com/github/scribejava/apis/examples/ViadeoExample.java | 5 ++++- .../github/scribejava/apis/examples/VkontakteExample.java | 5 ++++- .../com/github/scribejava/apis/examples/XingExample.java | 5 ++++- .../com/github/scribejava/apis/examples/YahooExample.java | 5 ++++- 43 files changed, 172 insertions(+), 43 deletions(-) diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AWeberExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AWeberExample.java index b17637c13..19a5f5b1f 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AWeberExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AWeberExample.java @@ -11,7 +11,7 @@ import com.github.scribejava.core.oauth.OAuth10aService; import java.io.IOException; -public abstract class AWeberExample { +public final class AWeberExample { //To get your consumer key/secret, and view API docs, see https://labs.aweber.com/docs private static final String ACCOUNT_RESOURCE_URL = "https://api.aweber.com/1.0/accounts/"; @@ -19,6 +19,9 @@ public abstract class AWeberExample { private static final String CONSUMER_KEY = ""; private static final String CONSUMER_SECRET = ""; + private AWeberExample() { + } + public static void main(String... args) throws IOException { final OAuth10aService service = new ServiceBuilder() .apiKey(CONSUMER_KEY) diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiggExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiggExample.java index f55c105a0..0e81446bb 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiggExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiggExample.java @@ -11,11 +11,14 @@ import com.github.scribejava.core.oauth.OAuth10aService; import java.io.IOException; -public abstract class DiggExample { +public final class DiggExample { private static final String NETWORK_NAME = "Digg"; private static final String PROTECTED_RESOURCE_URL = "http://services.digg.com/2.0/comment.digg"; + private DiggExample() { + } + public static void main(String... args) throws IOException { // Replace these with your own api key and secret final String apiKey = "myKey"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java index a3c99e114..9cddb3b85 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java @@ -16,11 +16,14 @@ import com.github.scribejava.core.oauth.OAuth20Service; import java.io.IOException; -public abstract class FacebookAsyncNingExample { +public final class FacebookAsyncNingExample { private static final String NETWORK_NAME = "Facebook"; private static final String PROTECTED_RESOURCE_URL = "https://graph.facebook.com/v2.6/me"; + private FacebookAsyncNingExample() { + } + public static void main(String... args) throws InterruptedException, ExecutionException, IOException { // Replace these with your client id and secret final String clientId = "your client id"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java index 7a1772aec..9da9c874b 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java @@ -11,11 +11,14 @@ import com.github.scribejava.core.oauth.OAuth20Service; import java.io.IOException; -public abstract class FacebookExample { +public final class FacebookExample { private static final String NETWORK_NAME = "Facebook"; private static final String PROTECTED_RESOURCE_URL = "https://graph.facebook.com/v2.6/me"; + private FacebookExample() { + } + public static void main(String... args) throws IOException { // Replace these with your client id and secret final String clientId = "your client id"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExample.java index ed03b906d..b3fd7912a 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExample.java @@ -11,10 +11,13 @@ import com.github.scribejava.core.oauth.OAuth10aService; import java.io.IOException; -public abstract class FlickrExample { +public final class FlickrExample { private static final String PROTECTED_RESOURCE_URL = "http://api.flickr.com/services/rest/"; + private FlickrExample() { + } + public static void main(String... args) throws IOException { // Replace these with your own api key and secret final String apiKey = "your_app_id"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java index c9b317911..44d471537 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java @@ -10,11 +10,14 @@ import com.github.scribejava.core.oauth.OAuth20Service; import java.io.IOException; -public abstract class Foursquare2Example { +public final class Foursquare2Example { private static final String PROTECTED_RESOURCE_URL = "https://api.foursquare.com/v2/users/self/friends?oauth_token="; + private Foursquare2Example() { + } + public static void main(String... args) throws IOException { // Replace these with your own api key and secret final String apiKey = "your client id"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FoursquareExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FoursquareExample.java index 639aaec0a..645985c75 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FoursquareExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FoursquareExample.java @@ -11,10 +11,13 @@ import com.github.scribejava.core.oauth.OAuth10aService; import java.io.IOException; -public abstract class FoursquareExample { +public final class FoursquareExample { private static final String PROTECTED_RESOURCE_URL = "http://api.foursquare.com/v1/user"; + private FoursquareExample() { + } + public static void main(String... args) throws IOException { final OAuth10aService service = new ServiceBuilder() .apiKey("your client id") diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java index 54e0a7d8d..a4c843ea4 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java @@ -12,7 +12,7 @@ import com.github.scribejava.core.oauth.OAuth10aService; import java.io.IOException; -public abstract class FreelancerExample { +public final class FreelancerExample { private static final String NETWORK_NAME = "Freelancer"; private static final String AUTHORIZE_URL @@ -20,6 +20,9 @@ public abstract class FreelancerExample { private static final String PROTECTED_RESOURCE_URL = "http://api.sandbox.freelancer.com/Job/getJobList.json"; private static final String SCOPE = "http://api.sandbox.freelancer.com"; + private FreelancerExample() { + } + public static void main(String... args) throws IOException { final OAuth10aService service = new ServiceBuilder() .signatureType(SignatureType.QueryString) diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GeniusExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GeniusExample.java index 0db6ddc05..04cf9f1d4 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GeniusExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GeniusExample.java @@ -11,11 +11,14 @@ import com.github.scribejava.core.oauth.OAuth20Service; import java.io.IOException; -public abstract class GeniusExample { +public final class GeniusExample { private static final String NETWORK_NAME = "Genius"; private static final String PROTECTED_RESOURCE_URL = "https://api.genius.com/songs/378195"; + private GeniusExample() { + } + public static void main(String... args) throws IOException { // Replace these with your client id and secret final String clientId = "your client id"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubExample.java index 0a07c9709..88adcd597 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubExample.java @@ -11,11 +11,14 @@ import com.github.scribejava.core.oauth.OAuth20Service; import java.io.IOException; -public abstract class GitHubExample { +public final class GitHubExample { private static final String NETWORK_NAME = "GitHub"; private static final String PROTECTED_RESOURCE_URL = "https://api.github.com/user"; + private GitHubExample() { + } + public static void main(String... args) throws IOException { // Replace these with your client id and secret final String clientId = "your client id"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java index abe2fc789..855cf6e50 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java @@ -19,11 +19,14 @@ import java.util.concurrent.ExecutionException; import org.asynchttpclient.DefaultAsyncHttpClientConfig; -public abstract class Google20AsyncAHCExample { +public final class Google20AsyncAHCExample { private static final String NETWORK_NAME = "G+ Async"; private static final String PROTECTED_RESOURCE_URL = "https://www.googleapis.com/plus/v1/people/me"; + private Google20AsyncAHCExample() { + } + public static void main(String... args) throws InterruptedException, ExecutionException, IOException { // Replace these with your client id and secret final String clientId = "your client id"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java index 2e6800c19..530de206d 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java @@ -13,11 +13,14 @@ import java.util.HashMap; import java.util.Map; -public abstract class Google20Example { +public final class Google20Example { private static final String NETWORK_NAME = "G+"; private static final String PROTECTED_RESOURCE_URL = "https://www.googleapis.com/plus/v1/people/me"; + private Google20Example() { + } + public static void main(String... args) throws IOException { // Replace these with your client id and secret final String clientId = "your client id"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HHExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HHExample.java index add150d1f..91bd52966 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HHExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HHExample.java @@ -12,11 +12,14 @@ import com.github.scribejava.core.oauth.OAuth20Service; import java.io.IOException; -public abstract class HHExample { +public final class HHExample { private static final String NETWORK_NAME = "hh.ru"; private static final String PROTECTED_RESOURCE_URL = "https://api.hh.ru/me"; + private HHExample() { + } + public static void main(String... args) throws IOException { // Replace these with your own client id and secret final String clientId = "your client id"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ImgurExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ImgurExample.java index 1d3f24a44..484142322 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ImgurExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ImgurExample.java @@ -11,11 +11,14 @@ import java.util.Scanner; -public abstract class ImgurExample { +public final class ImgurExample { private static final String NETWORK_NAME = "Imgur"; private static final String PROTECTED_RESOURCE_URL = "https://api.imgur.com/3/account/me"; + private ImgurExample() { + } + public static void main(String... args) throws IOException { // Replace these with your own api key and secret final String apiKey = "your client id"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Kaixin20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Kaixin20Example.java index 4551370d6..50fa30139 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Kaixin20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Kaixin20Example.java @@ -10,11 +10,14 @@ import com.github.scribejava.core.oauth.OAuth20Service; import java.io.IOException; -public abstract class Kaixin20Example { +public final class Kaixin20Example { private static final String NETWORK_NAME = "Kaixin"; private static final String PROTECTED_RESOURCE_URL = "https://api.kaixin001.com/users/me.json"; + private Kaixin20Example() { + } + public static void main(String... args) throws IOException { // Replace these with your own api key and secret final String apiKey = "your api key"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedIn20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedIn20Example.java index f29d1907b..95b2c5118 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 @@ -10,11 +10,14 @@ import com.github.scribejava.core.oauth.OAuth20Service; import java.io.IOException; -public abstract class LinkedIn20Example { +public final class LinkedIn20Example { private static final String NETWORK_NAME = "LinkedIn"; private static final String PROTECTED_RESOURCE_URL = "https://api.linkedin.com/v1/people/~:(%s)"; + private LinkedIn20Example() { + } + public static void main(String... args) throws IOException { // Replace these with your client id and secret final String clientId = "your client id"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java index 81324377b..927d89524 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java @@ -11,11 +11,14 @@ import com.github.scribejava.core.oauth.OAuth10aService; import java.io.IOException; -public abstract class LinkedInExample { +public final class LinkedInExample { private static final String PROTECTED_RESOURCE_URL = "http://api.linkedin.com/v1/people/~/connections:(id,last-name)"; + private LinkedInExample() { + } + public static void main(String... args) throws IOException { final OAuth10aService service = new ServiceBuilder() .apiKey("your client id") diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java index 2e951fa5f..0888cab5e 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java @@ -11,11 +11,14 @@ import com.github.scribejava.core.oauth.OAuth10aService; import java.io.IOException; -public abstract class LinkedInExampleWithScopes { +public final class LinkedInExampleWithScopes { private static final String PROTECTED_RESOURCE_URL = "http://api.linkedin.com/v1/people/~/connections:(id,last-name)"; + private LinkedInExampleWithScopes() { + } + public static void main(String... args) throws IOException { // Replace these with your client id and secret final String clientId = "your client id"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java index 0540a26db..d449355b4 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java @@ -10,11 +10,14 @@ import com.github.scribejava.core.oauth.OAuth20Service; import java.io.IOException; -public abstract class LiveExample { +public final class LiveExample { private static final String PROTECTED_RESOURCE_URL = "https://api.foursquare.com/v2/users/self/friends?oauth_token="; + private LiveExample() { + } + public static void main(String... args) throws IOException { // Replace these with your own api key and secret final String apiKey = ""; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java index a32946ba5..547a8bd57 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java @@ -13,12 +13,15 @@ import com.github.scribejava.core.oauth.OAuth20Service; import java.io.IOException; -public abstract class MailruAsyncExample { +public final class MailruAsyncExample { private static final String NETWORK_NAME = "Mail.ru"; private static final String PROTECTED_RESOURCE_URL = "http://www.appsmail.ru/platform/api?method=users.getInfo&secure=1"; + private MailruAsyncExample() { + } + public static void main(String... args) throws InterruptedException, ExecutionException, IOException { // Replace these with your client id and secret final String clientId = "your client id"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java index ae4ad4856..391adcd25 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java @@ -10,12 +10,15 @@ import com.github.scribejava.core.oauth.OAuth20Service; import java.io.IOException; -public abstract class MailruExample { +public final class MailruExample { private static final String NETWORK_NAME = "Mail.ru"; private static final String PROTECTED_RESOURCE_URL = "http://www.appsmail.ru/platform/api?method=users.getInfo&secure=1"; + private MailruExample() { + } + public static void main(String... args) throws IOException { // Replace these with your client id and secret final String clientId = "your client id"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java index 64180b980..9b3efce58 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java @@ -11,10 +11,13 @@ import com.github.scribejava.core.oauth.OAuth10aService; import java.io.IOException; -public abstract class MeetupExample { +public final class MeetupExample { private static final String PROTECTED_RESOURCE_URL = "http://api.meetup.com/2/member/self"; + private MeetupExample() { + } + public static void main(String... args) throws IOException { final OAuth10aService service = new ServiceBuilder() .apiKey("your client id") diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MisfitExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MisfitExample.java index 66e5901c9..451d55539 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MisfitExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MisfitExample.java @@ -11,12 +11,15 @@ import java.util.Scanner; -public abstract class MisfitExample { +public final class MisfitExample { private static final String NETWORK_NAME = "Misfit"; private static final String PROTECTED_RESOURCE_URL = "https://api.misfitwearables.com/move/resource/v1/user/me/profile"; + private MisfitExample() { + } + public static void main(String... args) throws IOException { // Replace these with your own api key and secret final String apiKey = "your client id"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NeteaseWeiboExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NeteaseWeiboExample.java index 08f782b13..e40715ae9 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NeteaseWeiboExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NeteaseWeiboExample.java @@ -11,11 +11,14 @@ import com.github.scribejava.core.oauth.OAuth10aService; import java.io.IOException; -public abstract class NeteaseWeiboExample { +public final class NeteaseWeiboExample { private static final String NETWORK_NAME = "NetEase(163.com) Weibo"; private static final String PROTECTED_RESOURCE_URL = "http://api.t.163.com/account/verify_credentials.json"; + private NeteaseWeiboExample() { + } + public static void main(String... args) throws IOException { // Replace these with your own api key and secret final String apiKey = "your key"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java index 9996484a4..6180595d7 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java @@ -10,12 +10,15 @@ import com.github.scribejava.core.oauth.OAuth20Service; import java.io.IOException; -public abstract class OdnoklassnikiExample { +public final class OdnoklassnikiExample { private static final String NETWORK_NAME = "Odnoklassniki.ru"; private static final String PROTECTED_RESOURCE_URL = "https://api.ok.ru/api/users/getCurrentUser?application_key=%1$s&format=JSON"; + private OdnoklassnikiExample() { + } + public static void main(String... args) throws IOException { // Replace these with your client id and secret final String clientId = "your api client id"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java index ca0359611..b49f1d451 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java @@ -11,10 +11,13 @@ import java.util.Scanner; -public abstract class PinterestExample { +public final class PinterestExample { private static final String PROTECTED_RESOURCE_URL = "https://api.pinterest.com/v1/me/?access_token?access_token="; + private PinterestExample() { + } + public static void main(String... args) throws IOException { // Replace these with your own api key and secret final String apiKey = "your_app_id"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Px500Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Px500Example.java index 4fbda56ff..fa84b773e 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Px500Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Px500Example.java @@ -11,10 +11,13 @@ import com.github.scribejava.core.oauth.OAuth10aService; import java.io.IOException; -public abstract class Px500Example { +public final class Px500Example { private static final String PROTECTED_RESOURCE_URL = "https://api.500px.com/v1/"; + private Px500Example() { + } + public static void main(String... args) throws IOException { final OAuth10aService service = new ServiceBuilder() .apiKey("your-api-key") diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java index 42f99eb6d..0a22eba37 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java @@ -19,11 +19,14 @@ import com.github.scribejava.core.oauth.OAuth20Service; import java.io.IOException; -public abstract class RenrenExample { +public final class RenrenExample { private static final String NETWORK_NAME = "Renren"; private static final String PROTECTED_RESOURCE_URL = "http://api.renren.com/restserver.do"; + private RenrenExample() { + } + public static void main(String... args) throws IOException { // Replace these with your own api key and secret final String apiKey = "your api key"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceExample.java index 1189fa30c..71cc8b0f8 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceExample.java @@ -15,10 +15,13 @@ import java.security.KeyManagementException; import java.security.NoSuchAlgorithmException; -public abstract class SalesforceExample { +public final class SalesforceExample { private static final String NETWORK_NAME = "Salesforce"; + private SalesforceExample() { + } + public static void main(String... args) throws IOException, NoSuchAlgorithmException, KeyManagementException { // Replace these with your client id and secret final String clientId = "your client id"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceNingAsyncExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceNingAsyncExample.java index 8b113c399..09f8e8dd0 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceNingAsyncExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceNingAsyncExample.java @@ -21,10 +21,13 @@ import java.security.KeyManagementException; import java.security.NoSuchAlgorithmException; -public abstract class SalesforceNingAsyncExample { +public final class SalesforceNingAsyncExample { private static final String NETWORK_NAME = "Salesforce"; + private SalesforceNingAsyncExample() { + } + @SuppressWarnings({"unchecked", "rawtypes"}) public static void main(String... args) throws InterruptedException, ExecutionException, UnsupportedEncodingException, IOException, NoSuchAlgorithmException, KeyManagementException { diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeibo2Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeibo2Example.java index 815f19ba2..5a720717a 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeibo2Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeibo2Example.java @@ -10,11 +10,14 @@ import com.github.scribejava.core.oauth.OAuth20Service; import java.io.IOException; -public abstract class SinaWeibo2Example { +public final class SinaWeibo2Example { private static final String NETWORK_NAME = "SinaWeibo"; private static final String PROTECTED_RESOURCE_URL = "https://api.weibo.com/2/account/get_uid.json"; + private SinaWeibo2Example() { + } + public static void main(String... args) throws IOException { // Replace these with your own api key and secret final String apiKey = "your_api_key"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeiboExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeiboExample.java index 8c3fccbd7..3a2ea9249 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeiboExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeiboExample.java @@ -11,11 +11,14 @@ import com.github.scribejava.core.oauth.OAuth10aService; import java.io.IOException; -public abstract class SinaWeiboExample { +public final class SinaWeiboExample { private static final String NETWORK_NAME = "SinaWeibo"; private static final String PROTECTED_RESOURCE_URL = "http://api.t.sina.com.cn/account/verify_credentials.json"; + private SinaWeiboExample() { + } + public static void main(String... args) throws IOException { // Replace these with your own api key and secret final String apiKey = "your key"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SkyrockExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SkyrockExample.java index 440058d57..a1c0fa6dc 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SkyrockExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SkyrockExample.java @@ -11,10 +11,13 @@ import com.github.scribejava.core.oauth.OAuth10aService; import java.io.IOException; -public abstract class SkyrockExample { +public final class SkyrockExample { private static final String PROTECTED_RESOURCE_URL = "https://api.skyrock.com/v2/user/get.json"; + private SkyrockExample() { + } + public static void main(String... args) throws IOException { final OAuth10aService service = new ServiceBuilder() .apiKey("your-api-key") diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SohuWeiboExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SohuWeiboExample.java index d91829387..1333fb0bb 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SohuWeiboExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SohuWeiboExample.java @@ -11,11 +11,14 @@ import com.github.scribejava.core.oauth.OAuth10aService; import java.io.IOException; -public abstract class SohuWeiboExample { +public final class SohuWeiboExample { private static final String NETWORK_NAME = "SohuWeibo"; private static final String PROTECTED_RESOURCE_URL = "http://api.t.sohu.com/account/verify_credentials.json"; + private SohuWeiboExample() { + } + public static void main(String... args) throws IOException { // Replace these with your own api key and secret final String apiKey = "your_key"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/StackExchangeExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/StackExchangeExample.java index d7d2341a2..c4c1b2f46 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/StackExchangeExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/StackExchangeExample.java @@ -12,11 +12,14 @@ import com.github.scribejava.core.oauth.OAuth20Service; import java.io.IOException; -public abstract class StackExchangeExample { +public final class StackExchangeExample { private static final String NETWORK_NAME = "Stack Exchange"; private static final String PROTECTED_RESOURCE_URL = "https://api.stackexchange.com/2.2/me"; + private StackExchangeExample() { + } + public static void main(String... args) throws IOException { // Replace these with your client id, secret, application key and // optionally site name diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TrelloExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TrelloExample.java index a72821cb2..80094c46c 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TrelloExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TrelloExample.java @@ -11,12 +11,15 @@ import com.github.scribejava.core.oauth.OAuth10aService; import java.io.IOException; -public abstract class TrelloExample { +public final class TrelloExample { private static final String API_KEY = "your_api_key"; private static final String API_SECRET = "your_api_secret"; private static final String PROTECTED_RESOURCE_URL = "https://trello.com/1/members/me"; + private TrelloExample() { + } + public static void main(String... args) throws IOException { final OAuth10aService service = new ServiceBuilder() .apiKey(API_KEY) diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TumblrExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TumblrExample.java index 10ae13e71..9dde7b284 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TumblrExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TumblrExample.java @@ -11,10 +11,13 @@ import com.github.scribejava.core.oauth.OAuth10aService; import java.io.IOException; -public abstract class TumblrExample { +public final class TumblrExample { private static final String PROTECTED_RESOURCE_URL = "http://api.tumblr.com/v2/user/info"; + private TumblrExample() { + } + public static void main(String... args) throws IOException { final OAuth10aService service = new ServiceBuilder() .apiKey("MY_CONSUMER_KEY") diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TutByExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TutByExample.java index 769270d37..74b867939 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TutByExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TutByExample.java @@ -12,11 +12,14 @@ import com.github.scribejava.core.oauth.OAuth20Service; import java.io.IOException; -public abstract class TutByExample { +public final class TutByExample { private static final String NETWORK_NAME = "Tut.by"; private static final String PROTECTED_RESOURCE_URL = "http://profile.tut.by/getInfo"; + private TutByExample() { + } + public static void main(String... args) throws IOException { // Replace these with your client id and secret final String clientId = "your client id"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TwitterExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TwitterExample.java index 66d8cefae..bae89f34a 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TwitterExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TwitterExample.java @@ -11,10 +11,13 @@ import com.github.scribejava.core.oauth.OAuth10aService; import java.io.IOException; -public abstract class TwitterExample { +public final class TwitterExample { private static final String PROTECTED_RESOURCE_URL = "https://api.twitter.com/1.1/account/verify_credentials.json"; + private TwitterExample() { + } + public static void main(String... args) throws IOException { final OAuth10aService service = new ServiceBuilder() .apiKey("your client id") diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ViadeoExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ViadeoExample.java index 1a9887217..c27cb7458 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ViadeoExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ViadeoExample.java @@ -10,11 +10,14 @@ import com.github.scribejava.core.oauth.OAuth20Service; import java.io.IOException; -public abstract class ViadeoExample { +public final class ViadeoExample { private static final String NETWORK_NAME = "Viadeo"; private static final String PROTECTED_RESOURCE_URL = "https://api.viadeo.com/me?user_detail=full"; + private ViadeoExample() { + } + public static void main(String... args) throws IOException { // Replace these with your own api key and secret final String apiKey = "your_app_id"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExample.java index 5e50158bd..703e580fc 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 @@ -10,11 +10,14 @@ import com.github.scribejava.core.oauth.OAuth20Service; import java.io.IOException; -public abstract class VkontakteExample { +public final class VkontakteExample { private static final String NETWORK_NAME = "Vkontakte.ru"; private static final String PROTECTED_RESOURCE_URL = "https://api.vk.com/method/users.get"; + private VkontakteExample() { + } + public static void main(String... args) throws IOException { // Replace these with your client id and secret final String clientId = "your client id"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XingExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XingExample.java index 04a3668fd..6133f80cb 100755 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XingExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XingExample.java @@ -11,10 +11,13 @@ import com.github.scribejava.core.oauth.OAuth10aService; import java.io.IOException; -public abstract class XingExample { +public final class XingExample { private static final String PROTECTED_RESOURCE_URL = "https://api.xing.com/v1/users/me"; + private XingExample() { + } + public static void main(String... args) throws IOException { final OAuth10aService service = new ServiceBuilder() .apiKey("your client id") diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/YahooExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/YahooExample.java index 3d020d59d..3779ed782 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/YahooExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/YahooExample.java @@ -11,11 +11,14 @@ import com.github.scribejava.core.oauth.OAuth10aService; import java.io.IOException; -public abstract class YahooExample { +public final class YahooExample { private static final String PROTECTED_RESOURCE_URL = "http://social.yahooapis.com/v1/user/A6ROU63MXWDCW3Y5MGCYWVHDJI/profile/status?format=json"; + private YahooExample() { + } + public static void main(String... args) throws IOException { final OAuth10aService service = new ServiceBuilder() .apiKey("your client id") From 1433630ce9cd7a5c0c2a0d57eb8370ec564f75b3 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 26 Aug 2016 19:24:47 +0300 Subject: [PATCH 268/882] add posibility to use externally created http client --- changelog | 1 + .../VkontakteExternalHttpExample.java | 90 +++++++++++++++++++ .../core/builder/ServiceBuilder.java | 14 ++- .../scribejava/core/model/OAuthConfig.java | 10 ++- .../scribejava/core/oauth/OAuthService.java | 5 +- .../httpclient/ahc/AhcHttpClient.java | 4 + .../httpclient/ning/NingHttpClient.java | 4 + 7 files changed, 123 insertions(+), 5 deletions(-) create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExternalHttpExample.java diff --git a/changelog b/changelog index e46cced96..bce9f079e 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,5 @@ [SNAPSHOT] + * 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) 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 new file mode 100644 index 000000000..9221fae44 --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExternalHttpExample.java @@ -0,0 +1,90 @@ +package com.github.scribejava.apis.examples; + +import java.util.Scanner; +import com.github.scribejava.core.builder.ServiceBuilder; +import com.github.scribejava.apis.VkontakteApi; +import com.github.scribejava.core.model.ForceTypeOfHttpRequest; +import com.github.scribejava.core.model.OAuth2AccessToken; +import com.github.scribejava.core.model.OAuthRequestAsync; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.ScribeJavaConfig; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.oauth.OAuth20Service; +import com.github.scribejava.httpclient.ahc.AhcHttpClient; +import java.io.IOException; +import java.util.concurrent.ExecutionException; +import org.asynchttpclient.DefaultAsyncHttpClient; +import org.asynchttpclient.DefaultAsyncHttpClientConfig; + +public final class VkontakteExternalHttpExample { + + private static final String NETWORK_NAME = "Vkontakte.ru"; + private static final String PROTECTED_RESOURCE_URL = "https://api.vk.com/method/users.get"; + + private VkontakteExternalHttpExample() { + } + + public static void main(String... args) throws IOException, InterruptedException, ExecutionException { + // Replace these with your client id and secret + final String clientId = "your client id"; + final String clientSecret = "your client secret"; + ScribeJavaConfig.setForceTypeOfHttpRequests(ForceTypeOfHttpRequest.FORCE_ASYNC_ONLY_HTTP_REQUESTS); + + //create any http cleint externally + final DefaultAsyncHttpClientConfig httpClientConfig = new DefaultAsyncHttpClientConfig.Builder() + .setMaxConnections(5) + .setRequestTimeout(10_000) + .setPooledConnectionIdleTimeout(1_000) + .setReadTimeout(1_000) + .build(); + //wrap it + try (DefaultAsyncHttpClient ahcHttpClient = new DefaultAsyncHttpClient(httpClientConfig)) { + //wrap it + final AhcHttpClient wrappedAHCHttpClient = new AhcHttpClient(ahcHttpClient); + + final OAuth20Service service = new ServiceBuilder() + .httpClient(wrappedAHCHttpClient) + .apiKey(clientId) + .apiSecret(clientSecret) + .scope("wall,offline") // replace with desired scope + .callback("http://your.site.com/callback") + .build(VkontakteApi.instance()); + final Scanner in = new Scanner(System.in); + + System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); + System.out.println(); + + // Obtain the Authorization URL + System.out.println("Fetching the Authorization URL..."); + final String authorizationUrl = service.getAuthorizationUrl(); + System.out.println("Got the Authorization URL!"); + System.out.println("Now go and authorize ScribeJava here:"); + System.out.println(authorizationUrl); + System.out.println("And paste the authorization code here"); + System.out.print(">>"); + final String code = in.nextLine(); + System.out.println(); + + // Trade the Request Token and Verfier for the Access Token + System.out.println("Trading the Request Token for an Access Token..."); + final OAuth2AccessToken accessToken = service.getAccessTokenAsync(code, null).get(); + System.out.println("Got the Access Token!"); + System.out.println("(if your curious it looks like this: " + accessToken + + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println(); + + // Now let's go and ask for a protected resource! + System.out.println("Now we're going to access a protected resource..."); + final OAuthRequestAsync request = new OAuthRequestAsync(Verb.GET, PROTECTED_RESOURCE_URL, service); + service.signRequest(accessToken, request); + final Response response = request.sendAsync(null).get(); + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + + System.out.println(); + System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); + } + } +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilder.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilder.java index 143487b1a..aa994d0a1 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 @@ -31,6 +31,7 @@ public class ServiceBuilder { //not-default httpclient only private HttpClient.Config httpClientConfig; + private HttpClient httpClient; public ServiceBuilder() { callback = OAuthConstants.OUT_OF_BAND; @@ -139,6 +140,17 @@ public ServiceBuilder httpClientConfig(HttpClient.Config httpClientConfig) { return this; } + /** + * takes precedence over httpClientConfig + * + * @param httpClient externally created HTTP client + * @return the {@link ServiceBuilder} instance for method chaining + */ + public ServiceBuilder httpClient(HttpClient httpClient) { + this.httpClient = httpClient; + return this; + } + public ServiceBuilder userAgent(String userAgent) { this.userAgent = userAgent; return this; @@ -156,7 +168,7 @@ public void checkPreconditions() { private OAuthConfig createConfig() { checkPreconditions(); return new OAuthConfig(apiKey, apiSecret, callback, signatureType, scope, debugStream, state, responseType, - userAgent, connectTimeout, readTimeout, httpClientConfig); + userAgent, connectTimeout, readTimeout, httpClientConfig, httpClient); } /** diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConfig.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConfig.java index 43c23826b..0a6e44894 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConfig.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConfig.java @@ -24,14 +24,15 @@ public class OAuthConfig { //async version only private HttpClient.Config httpClientConfig; + private HttpClient httpClient; public OAuthConfig(String key, String secret) { - this(key, secret, null, null, null, null, null, null, null, null, null, null); + this(key, secret, null, null, null, null, null, null, null, null, null, null, null); } public OAuthConfig(String apiKey, String apiSecret, String callback, SignatureType signatureType, String scope, OutputStream debugStream, String state, String responseType, String userAgent, Integer connectTimeout, - Integer readTimeout, HttpClient.Config httpClientConfig) { + Integer readTimeout, HttpClient.Config httpClientConfig, HttpClient httpClient) { this.apiKey = apiKey; this.apiSecret = apiSecret; this.callback = callback; @@ -44,6 +45,7 @@ public OAuthConfig(String apiKey, String apiSecret, String callback, SignatureTy this.connectTimeout = connectTimeout; this.readTimeout = readTimeout; this.httpClientConfig = httpClientConfig; + this.httpClient = httpClient; } public String getApiKey() { @@ -100,4 +102,8 @@ public Integer getReadTimeout() { public HttpClient.Config getHttpClientConfig() { return httpClientConfig; } + + public HttpClient getHttpClient() { + return httpClient; + } } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java index 3d8850cde..172ed26ff 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java @@ -29,8 +29,9 @@ public OAuthService(OAuthConfig config) { this.config = config; final ForceTypeOfHttpRequest forceTypeOfHttpRequest = ScribeJavaConfig.getForceTypeOfHttpRequests(); final HttpClient.Config httpClientConfig = config.getHttpClientConfig(); + final HttpClient externalHttpClient = config.getHttpClient(); - if (httpClientConfig == null) { + if (httpClientConfig == null && externalHttpClient == null) { if (ForceTypeOfHttpRequest.FORCE_ASYNC_ONLY_HTTP_REQUESTS == forceTypeOfHttpRequest) { throw new OAuthException("Cannot use sync operations, only async"); } @@ -46,7 +47,7 @@ public OAuthService(OAuthConfig config) { config.log("Cannot use async operations, only sync"); } - httpClient = getClient(httpClientConfig); + httpClient = externalHttpClient == null ? getClient(httpClientConfig) : externalHttpClient; } } 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 a6950b51e..14d88ea31 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 @@ -24,6 +24,10 @@ public AhcHttpClient(AhcHttpClientConfig ahcConfig) { client = new DefaultAsyncHttpClient(ahcConfig.getClientConfig()); } + public AhcHttpClient(DefaultAsyncHttpClient ahcClient) { + client = ahcClient; + } + @Override public void close() throws IOException { client.close(); 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 62c56be81..9d4bccffd 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 @@ -23,6 +23,10 @@ public NingHttpClient(NingHttpClientConfig ningConfig) { : new AsyncHttpClient(ningAsyncHttpProviderClassName, ningConfig.getConfig()); } + public NingHttpClient(AsyncHttpClient client) { + this.client = client; + } + @Override public void close() { client.close(); From 33cf3f5f15215429883bdcac596f9f47e2091c8d Mon Sep 17 00:00:00 2001 From: alex Date: Mon, 22 Aug 2016 22:52:33 +0300 Subject: [PATCH 269/882] fix OdnoklassnikiServiceImpl signature, params for hash must be sorted in lexicographic order, see http://new.apiok.ru/dev/methods/ --- changelog | 1 + .../service/OdnoklassnikiServiceImpl.java | 16 ++++--- .../service/OdnoklassnikiServiceTest.java | 43 +++++++++++++++++++ 3 files changed, 55 insertions(+), 5 deletions(-) create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/service/OdnoklassnikiServiceTest.java diff --git a/changelog b/changelog index bce9f079e..8ab8158d2 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,5 @@ [SNAPSHOT] + * 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) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiServiceImpl.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiServiceImpl.java index baca34604..2a6e01339 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiServiceImpl.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiServiceImpl.java @@ -9,6 +9,7 @@ import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.oauth.OAuth20Service; +import java.util.Arrays; public class OdnoklassnikiServiceImpl extends OAuth20Service { @@ -18,17 +19,22 @@ public OdnoklassnikiServiceImpl(DefaultApi20 api, OAuthConfig config) { @Override public void signRequest(OAuth2AccessToken accessToken, AbstractRequest request) { - // sig = md5( request_params_composed_string+ md5(access_token + application_secret_key) ) + //sig = lower(md5( sorted_request_params_composed_string + md5(access_token + application_secret_key))) try { final String tokenDigest = md5Hex(accessToken.getAccessToken() + getConfig().getApiSecret()); final String completeUrl = request.getCompleteUrl(); final int queryIndex = completeUrl.indexOf('?'); if (queryIndex != -1) { - final String sigSource - = URLDecoder.decode(completeUrl.substring(queryIndex + 1).replace("&", ""), CharEncoding.UTF_8) - + tokenDigest; - request.addQuerystringParameter("sig", md5Hex(sigSource)); + final String[] params = completeUrl.substring(queryIndex + 1).split("&"); + Arrays.sort(params); + final StringBuilder builder = new StringBuilder(); + for (String param : params) { + builder.append(param); + } + + final String sigSource = URLDecoder.decode(builder.toString(), CharEncoding.UTF_8) + tokenDigest; + request.addQuerystringParameter("sig", md5Hex(sigSource).toLowerCase()); } super.signRequest(accessToken, request); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/service/OdnoklassnikiServiceTest.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/service/OdnoklassnikiServiceTest.java new file mode 100644 index 000000000..3adbafd02 --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/service/OdnoklassnikiServiceTest.java @@ -0,0 +1,43 @@ +package com.github.scribejava.apis.service; + +import com.github.scribejava.apis.OdnoklassnikiApi; +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.ParameterList; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.model.Parameter; +import com.github.scribejava.core.oauth.OAuth20Service; +import static org.junit.Assert.assertEquals; +import org.junit.Test; + +public class OdnoklassnikiServiceTest { + + private static final String URL = "https://api.ok.ru/fb.do?method=friends.get&fields=uid%2C" + + "first_name%2Clast_name%2Cpic_2&application_key=AAAAAAAAAAAAAAAA&format=json"; + + private final OAuth20Service service = new ServiceBuilder() + .apiKey("0000000000") + .apiSecret("CCCCCCCCCCCCCCCCCCCCCCCC") + .scope("VALUABLE_ACCESS") + .callback("http://your.site.com/callback") + .build(OdnoklassnikiApi.instance()); + + @Test + public void testSigGeneration() { + final OAuth2AccessToken accessToken = new OAuth2AccessToken("d3iwa.403gvrs194740652m1k4w2a503k3c"); + final OAuthRequest request = new OAuthRequest(Verb.GET, URL, service); + service.signRequest(accessToken, request); + assertEquals("96127f5ca29a8351399e94bbd284ab16", findParam(request.getQueryStringParams(), "sig")); + } + + private static String findParam(ParameterList list, String key) { + for (Parameter param : list.getParams()) { + if (param.getKey().equals(key)) { + return param.getValue(); + } + } + return null; + } +} From 623b0ec9df21f988942b30608846c2cdf1aad8a4 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 26 Aug 2016 20:21:03 +0300 Subject: [PATCH 270/882] prepare to release 3.1.0 --- README.md | 4 ++-- changelog | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 11155e6cf..50e37cffe 100644 --- a/README.md +++ b/README.md @@ -92,7 +92,7 @@ You can pull ScribeJava from the central maven repository, just add these to you com.github.scribejava scribejava-apis - 3.0.0 + 3.1.0 ``` @@ -101,7 +101,7 @@ And in case you need just core classes (that's it, without any external API (FB, com.github.scribejava scribejava-core - 3.0.0 + 3.1.0 ``` diff --git a/changelog b/changelog index 8ab8158d2..4f2d28b7c 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,4 @@ -[SNAPSHOT] +[3.1.0] * 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) From efca28b5c4f623e32d35257461fc6f8ce8a24101 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 26 Aug 2016 20:22:13 +0300 Subject: [PATCH 271/882] [maven-release-plugin] prepare release scribejava-3.1.0 --- pom.xml | 2 +- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index 6f09b33da..4707744f1 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 3.0.1-SNAPSHOT + 3.1.0 ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 9d8462956..e63c8a636 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 3.0.1-SNAPSHOT + 3.1.0 ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 26857c334..e8df520d8 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 3.0.1-SNAPSHOT + 3.1.0 ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index dfc65bd97..eeb83a9c7 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 3.0.1-SNAPSHOT + 3.1.0 ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index da076a3e5..7dd4c3ca8 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 3.0.1-SNAPSHOT + 3.1.0 ../pom.xml From 96c1ea78ebbb334ce838729880f2a4b7f47f47a1 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 26 Aug 2016 20:22:18 +0300 Subject: [PATCH 272/882] [maven-release-plugin] prepare for next development iteration --- pom.xml | 2 +- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index 4707744f1..226256246 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 3.1.0 + 3.1.1-SNAPSHOT ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index e63c8a636..0fc7155a3 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 3.1.0 + 3.1.1-SNAPSHOT ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index e8df520d8..ceabc6b76 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 3.1.0 + 3.1.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index eeb83a9c7..1161c406d 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 3.1.0 + 3.1.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index 7dd4c3ca8..af7aa4794 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 3.1.0 + 3.1.1-SNAPSHOT ../pom.xml From 1fcff0e41ed25cd6de431e4723a318542ec3ad63 Mon Sep 17 00:00:00 2001 From: chooco Date: Thu, 8 Sep 2016 21:49:42 +0900 Subject: [PATCH 273/882] Add Naver API (#701) Add Naver API --- .../com/github/scribejava/apis/NaverApi.java | 27 ++++++ .../apis/examples/NaverExample.java | 85 +++++++++++++++++++ 2 files changed, 112 insertions(+) create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/NaverApi.java create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NaverExample.java diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/NaverApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/NaverApi.java new file mode 100644 index 000000000..1f021fe03 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/NaverApi.java @@ -0,0 +1,27 @@ +package com.github.scribejava.apis; + +import com.github.scribejava.core.builder.api.DefaultApi20; + +public class NaverApi extends DefaultApi20 { + protected NaverApi() { + } + + private static class InstanceHolder { + private static final NaverApi INSTANCE = new NaverApi(); + + private InstanceHolder() { + } + } + + public static NaverApi instance() { + return NaverApi.InstanceHolder.INSTANCE; + } + + public String getAccessTokenEndpoint() { + return "https://nid.naver.com/oauth2.0/token?grant_type=authorization_code"; + } + + protected String getAuthorizationBaseUrl() { + return "https://nid.naver.com/oauth2.0/authorize"; + } +} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NaverExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NaverExample.java new file mode 100644 index 000000000..98eab65df --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NaverExample.java @@ -0,0 +1,85 @@ +package com.github.scribejava.apis.examples; + +import com.github.scribejava.apis.NaverApi; +import com.github.scribejava.core.builder.ServiceBuilder; +import com.github.scribejava.core.model.OAuth2AccessToken; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.oauth.OAuth20Service; + +import java.io.IOException; +import java.util.Random; +import java.util.Scanner; + +public final class NaverExample { + + private static final String NETWORK_NAME = "Naver"; + private static final String PROTECTED_RESOURCE_URL = "https://openapi.naver.com/v1/nid/me"; + + private NaverExample() { + } + + public static void main(String... args) throws IOException { + // Replace these with your client id and secret + final String clientId = "your client id"; + final String clientSecret = "your client secret"; + final String secretState = "secret" + new Random().nextInt(999_999); + final OAuth20Service service = new ServiceBuilder() + .apiKey(clientId) + .apiSecret(clientSecret) + .state(secretState) + .callback("http://www.example.com/oauth_callback/") + .build(NaverApi.instance()); + + final Scanner in = new Scanner(System.in, "UTF-8"); + + System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); + System.out.println(); + + // Obtain the Authorization URL + System.out.println("Fetching the Authorization URL..."); + final String authorizationUrl = service.getAuthorizationUrl(); + System.out.println("Got the Authorization URL!"); + System.out.println("Now go and authorize ScribeJava here:"); + System.out.println(authorizationUrl); + System.out.println("And paste the authorization code here"); + System.out.print(">>"); + final String code = in.nextLine(); + System.out.println(); + + System.out.println("And paste the state from server here. We have set 'secretState'='" + secretState + "'."); + System.out.print(">>"); + final String value = in.nextLine(); + if (secretState.equals(value)) { + System.out.println("State value does match!"); + } else { + System.out.println("Ooops, state value does not match!"); + System.out.println("Expected = " + secretState); + System.out.println("Got = " + value); + System.out.println(); + } + + // Trade the Request Token and Verfier for the Access Token + System.out.println("Trading the Request Token for an Access Token..."); + final OAuth2AccessToken accessToken = service.getAccessToken(code); + System.out.println("Got the Access Token!"); + System.out.println("(if your curious it looks like this: " + accessToken + + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println(); + + // Now let's go and ask for a protected resource! + System.out.println("Now we're going to access a protected resource..."); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service); + service.signRequest(accessToken, request); + final Response response = request.send(); + 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 9fd62eaaaf9c2f5d382e27bf59a399c6d96c675e Mon Sep 17 00:00:00 2001 From: choo_co Date: Thu, 8 Sep 2016 12:16:37 +0900 Subject: [PATCH 274/882] Add Naver API --- README.md | 1 + changelog | 3 +++ 2 files changed, 4 insertions(+) diff --git a/README.md b/README.md index 50e37cffe..0e74d2d6b 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,7 @@ You can use ning async http client 1.9.x or asynchttpclient 2.x out-of-box, just * Microsoft Live (https://login.live.com/) * Mail.Ru (https://mail.ru/) * Meetup (http://www.meetup.com/) +* NAVER (http://www.naver.com/) * NetEase (http://www.163.com/) * Odnoklassniki Одноклассники (http://ok.ru/) * Pinterest (https://www.pinterest.com/) diff --git a/changelog b/changelog index 4f2d28b7c..4b6fc922d 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,6 @@ +[SNAPSHOT] + * Add Naver API + [3.1.0] * 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 From e01064d909e962d6d80905d077258c6e9ed9da70 Mon Sep 17 00:00:00 2001 From: Julien Herr Date: Thu, 8 Sep 2016 16:07:13 +0200 Subject: [PATCH 275/882] Manage OAuth2 error response for access token request (#696) --- .../exceptions/OAuthRequestException.java | 17 +++++++ .../AbstractOAuth1TokenExtractor.java | 13 +++-- .../OAuth2AccessTokenExtractor.java | 19 ++++--- .../OAuth2AccessTokenJsonExtractor.java | 35 ++++++++++++- .../core/extractors/TokenExtractor.java | 6 ++- .../core/model/OAuth2ErrorResponse.java | 51 +++++++++++++++++++ .../core/oauth/OAuth10aService.java | 8 +-- .../scribejava/core/oauth/OAuth20Service.java | 4 +- .../OAuth1AccessTokenExtractorTest.java | 42 +++++++++------ .../OAuth2AccessTokenExtractorTest.java | 38 +++++++++----- .../OAuth2AccessTokenJsonExtractorTest.java | 46 ++++++++++++++--- 11 files changed, 221 insertions(+), 58 deletions(-) create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/exceptions/OAuthRequestException.java create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth2ErrorResponse.java diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/exceptions/OAuthRequestException.java b/scribejava-core/src/main/java/com/github/scribejava/core/exceptions/OAuthRequestException.java new file mode 100644 index 000000000..409a51501 --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/exceptions/OAuthRequestException.java @@ -0,0 +1,17 @@ +package com.github.scribejava.core.exceptions; + +import com.github.scribejava.core.model.OAuth2ErrorResponse; + +public class OAuthRequestException extends OAuthException { + + private final OAuth2ErrorResponse error; + + public OAuthRequestException(String message, OAuth2ErrorResponse error) { + super(message); + this.error = error; + } + + public OAuth2ErrorResponse getError() { + return error; + } +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/AbstractOAuth1TokenExtractor.java b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/AbstractOAuth1TokenExtractor.java index 4d968d83c..36285c2c1 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/AbstractOAuth1TokenExtractor.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/AbstractOAuth1TokenExtractor.java @@ -1,9 +1,11 @@ package com.github.scribejava.core.extractors; +import java.io.IOException; import java.util.regex.Matcher; import java.util.regex.Pattern; import com.github.scribejava.core.exceptions.OAuthException; import com.github.scribejava.core.model.OAuth1Token; +import com.github.scribejava.core.model.Response; import com.github.scribejava.core.utils.OAuthEncoder; import com.github.scribejava.core.utils.Preconditions; @@ -23,12 +25,13 @@ public abstract class AbstractOAuth1TokenExtractor implem * {@inheritDoc} */ @Override - public T extract(String response) { - Preconditions.checkEmptyString(response, + public T extract(Response response) throws IOException { + final String body = response.getBody(); + Preconditions.checkEmptyString(body, "Response body is incorrect. Can't extract a token from an empty string"); - final String token = extract(response, Pattern.compile(OAUTH_TOKEN_REGEXP)); - final String secret = extract(response, Pattern.compile(OAUTH_TOKEN_SECRET_REGEXP)); - return createToken(token, secret, response); + final String token = extract(body, Pattern.compile(OAUTH_TOKEN_REGEXP)); + final String secret = extract(body, Pattern.compile(OAUTH_TOKEN_SECRET_REGEXP)); + return createToken(token, secret, body); } private String extract(String response, Pattern p) { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenExtractor.java b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenExtractor.java index 251226338..67de27299 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenExtractor.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenExtractor.java @@ -1,9 +1,11 @@ package com.github.scribejava.core.extractors; +import java.io.IOException; import java.util.regex.Matcher; import java.util.regex.Pattern; import com.github.scribejava.core.exceptions.OAuthException; import com.github.scribejava.core.model.OAuth2AccessToken; +import com.github.scribejava.core.model.Response; import com.github.scribejava.core.utils.OAuthEncoder; import com.github.scribejava.core.utils.Preconditions; @@ -34,23 +36,24 @@ public static OAuth2AccessTokenExtractor instance() { * {@inheritDoc} */ @Override - public OAuth2AccessToken extract(String response) { - Preconditions.checkEmptyString(response, + public OAuth2AccessToken extract(Response response) throws IOException { + final String body = response.getBody(); + Preconditions.checkEmptyString(body, "Response body is incorrect. Can't extract a token from an empty string"); - final String accessToken = extractParameter(response, ACCESS_TOKEN_REGEX, true); - final String tokenType = extractParameter(response, TOKEN_TYPE_REGEX, false); - final String expiresInString = extractParameter(response, EXPIRES_IN_REGEX, false); + final String accessToken = extractParameter(body, ACCESS_TOKEN_REGEX, true); + final String tokenType = extractParameter(body, TOKEN_TYPE_REGEX, false); + final String expiresInString = extractParameter(body, EXPIRES_IN_REGEX, false); Integer expiresIn; try { expiresIn = expiresInString == null ? null : Integer.valueOf(expiresInString); } catch (NumberFormatException nfe) { expiresIn = null; } - final String refreshToken = extractParameter(response, REFRESH_TOKEN_REGEX, false); - final String scope = extractParameter(response, SCOPE_REGEX, false); + final String refreshToken = extractParameter(body, REFRESH_TOKEN_REGEX, false); + final String scope = extractParameter(body, SCOPE_REGEX, false); - return new OAuth2AccessToken(accessToken, tokenType, expiresIn, refreshToken, scope, response); + return new OAuth2AccessToken(accessToken, tokenType, expiresIn, refreshToken, scope, body); } private static String extractParameter(String response, String regex, boolean required) throws OAuthException { 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 f6250f9b2..465b31c04 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,9 +1,13 @@ package com.github.scribejava.core.extractors; +import java.io.IOException; +import java.net.URI; import java.util.regex.Matcher; import java.util.regex.Pattern; import com.github.scribejava.core.exceptions.OAuthException; import com.github.scribejava.core.model.OAuth2AccessToken; +import com.github.scribejava.core.model.OAuth2ErrorResponse; +import com.github.scribejava.core.model.Response; import com.github.scribejava.core.utils.Preconditions; /** @@ -16,6 +20,9 @@ public class OAuth2AccessTokenJsonExtractor implements TokenExtractor concrete type of Token @@ -14,5 +18,5 @@ public interface TokenExtractor { * @param response the contents of the response * @return OAuth access token */ - T extract(String response); + T extract(Response response) throws IOException, OAuthException; } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth2ErrorResponse.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth2ErrorResponse.java new file mode 100644 index 000000000..d39ffa55b --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth2ErrorResponse.java @@ -0,0 +1,51 @@ +package com.github.scribejava.core.model; + +import com.github.scribejava.core.exceptions.OAuthException; + +import java.net.URI; + +/** + * Representing "5.2. Error Response" + */ +public class OAuth2ErrorResponse extends OAuthException { + + public enum OAuthError { + invalid_request, invalid_client, invalid_grant, unauthorized_client, unsupported_grant_type, invalid_scope + } + + private final OAuthError error; + private final String errorDescription; + private final URI errorUri; + private final String rawResponse; + + public OAuth2ErrorResponse(OAuthError error, String errorDescription, URI errorUri, String rawResponse) { + super(generateMessage(error, errorDescription, errorUri, rawResponse)); + if (error == null) { + throw new IllegalArgumentException("error must not be null"); + } + this.error = error; + this.errorDescription = errorDescription; + this.errorUri = errorUri; + this.rawResponse = rawResponse; + } + + private static String generateMessage(OAuthError error, String errorDescription, URI errorUri, String rawResponse) { + return rawResponse; + } + + public OAuthError getError() { + return error; + } + + public String getErrorDescription() { + return errorDescription; + } + + public URI getErrorUri() { + return errorUri; + } + + public String getRawResponse() { + return rawResponse; + } +} 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 e707486bc..e1cc5bf5d 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 @@ -48,7 +48,7 @@ public final OAuth1RequestToken getRequestToken() throws IOException { config.log("response status code: " + response.getCode()); config.log("response body: " + body); - return api.getRequestTokenExtractor().extract(body); + return api.getRequestTokenExtractor().extract(response); } public final Future getRequestTokenAsync( @@ -61,7 +61,7 @@ public final Future getRequestTokenAsync( return request.sendAsync(callback, new OAuthRequestAsync.ResponseConverter() { @Override public OAuth1RequestToken convert(Response response) throws IOException { - return getApi().getRequestTokenExtractor().extract(response.getBody()); + return getApi().getRequestTokenExtractor().extract(response); } }); } @@ -97,7 +97,7 @@ public final OAuth1AccessToken getAccessToken(OAuth1RequestToken requestToken, S final OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint(), this); prepareAccessTokenRequest(request, requestToken, oauthVerifier); final Response response = request.send(); - return api.getAccessTokenExtractor().extract(response.getBody()); + return api.getAccessTokenExtractor().extract(response); } /** @@ -119,7 +119,7 @@ public final Future getAccessTokenAsync(OAuth1RequestToken re return request.sendAsync(callback, new OAuthRequestAsync.ResponseConverter() { @Override public OAuth1AccessToken convert(Response response) throws IOException { - return getApi().getAccessTokenExtractor().extract(response.getBody()); + return getApi().getAccessTokenExtractor().extract(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 43bf4c7fa..a6ecc0019 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 @@ -34,7 +34,7 @@ public OAuth20Service(DefaultApi20 api, OAuthConfig config) { //sync version, protected to facilitate mocking protected OAuth2AccessToken sendAccessTokenRequestSync(OAuthRequest request) throws IOException { - return api.getAccessTokenExtractor().extract(request.send().getBody()); + return api.getAccessTokenExtractor().extract(request.send()); } //async version, protected to facilitate mocking @@ -44,7 +44,7 @@ protected Future sendAccessTokenRequestAsync(OAuthRequestAsyn return request.sendAsync(callback, new OAuthRequestAsync.ResponseConverter() { @Override public OAuth2AccessToken convert(Response response) throws IOException { - return getApi().getAccessTokenExtractor().extract(response.getBody()); + return getApi().getAccessTokenExtractor().extract(response); } }); } 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 7cf3feb95..b810d25b3 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 @@ -1,9 +1,14 @@ package com.github.scribejava.core.extractors; +import com.github.scribejava.core.model.Response; import org.junit.Before; import org.junit.Test; import com.github.scribejava.core.exceptions.OAuthException; import com.github.scribejava.core.model.OAuth1Token; + +import java.io.IOException; +import java.util.Collections; + import static org.junit.Assert.assertEquals; public class OAuth1AccessTokenExtractorTest { @@ -16,58 +21,63 @@ public void setUp() { } @Test - public void shouldExtractTokenFromOAuthStandardResponse() { + public void shouldExtractTokenFromOAuthStandardResponse() throws IOException { final String response = "oauth_token=hh5s93j4hdidpola&oauth_token_secret=hdhd0244k9j7ao03"; - final OAuth1Token extracted = extractor.extract(response); + final OAuth1Token extracted = extractor.extract(ok(response)); assertEquals("hh5s93j4hdidpola", extracted.getToken()); assertEquals("hdhd0244k9j7ao03", extracted.getTokenSecret()); } @Test - public void shouldExtractTokenFromInvertedOAuthStandardResponse() { + public void shouldExtractTokenFromInvertedOAuthStandardResponse() throws IOException { final String response = "oauth_token_secret=hh5s93j4hdidpola&oauth_token=hdhd0244k9j7ao03"; - final OAuth1Token extracted = extractor.extract(response); + final OAuth1Token extracted = extractor.extract(ok(response)); assertEquals("hh5s93j4hdidpola", extracted.getTokenSecret()); assertEquals("hdhd0244k9j7ao03", extracted.getToken()); } @Test - public void shouldExtractTokenFromResponseWithCallbackConfirmed() { + public void shouldExtractTokenFromResponseWithCallbackConfirmed() throws IOException { final String response = "oauth_token=hh5s93j4hdidpola&oauth_token_secret=hdhd0244k9j7ao03" + "&callback_confirmed=true"; - final OAuth1Token extracted = extractor.extract(response); + final OAuth1Token extracted = extractor.extract(ok(response)); assertEquals("hh5s93j4hdidpola", extracted.getToken()); assertEquals("hdhd0244k9j7ao03", extracted.getTokenSecret()); } @Test - public void shouldExtractTokenWithEmptySecret() { + public void shouldExtractTokenWithEmptySecret() throws IOException { final String response = "oauth_token=hh5s93j4hdidpola&oauth_token_secret="; - final OAuth1Token extracted = extractor.extract(response); + final OAuth1Token extracted = extractor.extract(ok(response)); assertEquals("hh5s93j4hdidpola", extracted.getToken()); assertEquals("", extracted.getTokenSecret()); } @Test(expected = OAuthException.class) - public void shouldThrowExceptionIfTokenIsAbsent() { + public void shouldThrowExceptionIfTokenIsAbsent() throws IOException { final String response = "oauth_secret=hh5s93j4hdidpola&callback_confirmed=true"; - extractor.extract(response); + extractor.extract(ok(response)); } @Test(expected = OAuthException.class) - public void shouldThrowExceptionIfSecretIsAbsent() { + public void shouldThrowExceptionIfSecretIsAbsent() throws IOException { final String response = "oauth_token=hh5s93j4hdidpola&callback_confirmed=true"; - extractor.extract(response); + extractor.extract(ok(response)); } @Test(expected = IllegalArgumentException.class) - public void shouldThrowExceptionIfResponseIsNull() { - extractor.extract(null); + public void shouldThrowExceptionIfResponseIsNull() throws IOException { + extractor.extract(ok(null)); } @Test(expected = IllegalArgumentException.class) - public void shouldThrowExceptionIfResponseIsEmptyString() { + public void shouldThrowExceptionIfResponseIsEmptyString() throws IOException { final String response = ""; - extractor.extract(response); + extractor.extract(ok(response)); + } + + private static Response ok(String body) { + return new Response(200, /* message */ null, /* headers */ Collections.emptyMap(), + body, /* stream */ null); } } 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 fa66956d5..eb88b583f 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 @@ -1,9 +1,14 @@ package com.github.scribejava.core.extractors; +import com.github.scribejava.core.model.Response; import org.junit.Before; import org.junit.Test; import com.github.scribejava.core.exceptions.OAuthException; import com.github.scribejava.core.model.OAuth2AccessToken; + +import java.io.IOException; +import java.util.Collections; + import static org.junit.Assert.assertEquals; public class OAuth2AccessTokenExtractorTest { @@ -16,29 +21,29 @@ public void setUp() { } @Test - public void shouldExtractTokenFromOAuthStandardResponse() { + public void shouldExtractTokenFromOAuthStandardResponse() throws IOException { final String response = "access_token=166942940015970|2.2ltzWXYNDjCtg5ZDVVJJeg__.3600.1295816400-548517159" + "|RsXNdKrpxg8L6QNLWcs2TVTmcaE"; - final OAuth2AccessToken extracted = extractor.extract(response); + final OAuth2AccessToken extracted = extractor.extract(ok(response)); assertEquals("166942940015970|2.2ltzWXYNDjCtg5ZDVVJJeg__.3600.1295816400-548517159|RsXNdKrpxg8L6QNLWcs2TVTmcaE", extracted.getAccessToken()); } @Test - public void shouldExtractTokenFromResponseWithExpiresParam() { + public void shouldExtractTokenFromResponseWithExpiresParam() throws IOException { final String response = "access_token=166942940015970|2.2ltzWXYNDjCtg5ZDVVJJeg__.3600.1295816400-548517159" + "|RsXNdKrpxg8L6QNLWcs2TVTmcaE&expires_in=5108"; - final OAuth2AccessToken extracted = extractor.extract(response); + final OAuth2AccessToken extracted = extractor.extract(ok(response)); assertEquals("166942940015970|2.2ltzWXYNDjCtg5ZDVVJJeg__.3600.1295816400-548517159|RsXNdKrpxg8L6QNLWcs2TVTmcaE", extracted.getAccessToken()); assertEquals(Integer.valueOf(5108), extracted.getExpiresIn()); } @Test - public void shouldExtractTokenFromResponseWithExpiresAndRefreshParam() { + public void shouldExtractTokenFromResponseWithExpiresAndRefreshParam() throws IOException { final String response = "access_token=166942940015970|2.2ltzWXYNDjCtg5ZDVVJJeg__.3600.1295816400-548517159" + "|RsXNdKrpxg8L6QNLWcs2TVTmcaE&expires_in=5108&token_type=bearer&refresh_token=166942940015970"; - final OAuth2AccessToken extracted = extractor.extract(response); + final OAuth2AccessToken extracted = extractor.extract(ok(response)); assertEquals("166942940015970|2.2ltzWXYNDjCtg5ZDVVJJeg__.3600.1295816400-548517159|RsXNdKrpxg8L6QNLWcs2TVTmcaE", extracted.getAccessToken()); assertEquals(Integer.valueOf(5108), extracted.getExpiresIn()); @@ -47,26 +52,31 @@ public void shouldExtractTokenFromResponseWithExpiresAndRefreshParam() { } @Test - public void shouldExtractTokenFromResponseWithManyParameters() { + public void shouldExtractTokenFromResponseWithManyParameters() throws IOException { final String response = "access_token=foo1234&other_stuff=yeah_we_have_this_too&number=42"; - final OAuth2AccessToken extracted = extractor.extract(response); + final OAuth2AccessToken extracted = extractor.extract(ok(response)); assertEquals("foo1234", extracted.getAccessToken()); } @Test(expected = OAuthException.class) - public void shouldThrowExceptionIfTokenIsAbsent() { + public void shouldThrowExceptionIfTokenIsAbsent() throws IOException { final String response = "&expires=5108"; - extractor.extract(response); + extractor.extract(ok(response)); } @Test(expected = IllegalArgumentException.class) - public void shouldThrowExceptionIfResponseIsNull() { - extractor.extract(null); + public void shouldThrowExceptionIfResponseIsNull() throws IOException { + extractor.extract(ok(null)); } @Test(expected = IllegalArgumentException.class) - public void shouldThrowExceptionIfResponseIsEmptyString() { + public void shouldThrowExceptionIfResponseIsEmptyString() throws IOException { final String response = ""; - extractor.extract(response); + extractor.extract(ok(response)); + } + + private static Response ok(String body) { + return new Response(200, /* message */ null, /* headers */ Collections.emptyMap(), + body, /* stream */ null); } } 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 9b2098e6c..a92c9ba1d 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 @@ -1,8 +1,15 @@ package com.github.scribejava.core.extractors; import com.github.scribejava.core.model.OAuth2AccessToken; +import com.github.scribejava.core.model.OAuth2ErrorResponse; +import com.github.scribejava.core.model.Response; import org.junit.Test; + +import java.io.IOException; +import java.util.Collections; + import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; public class OAuth2AccessTokenJsonExtractorTest { @@ -10,18 +17,45 @@ public class OAuth2AccessTokenJsonExtractorTest { private final OAuth2AccessTokenJsonExtractor extractor = OAuth2AccessTokenJsonExtractor.instance(); @Test - public void shouldParseResponse() { - final OAuth2AccessToken token = extractor.extract(RESPONSE); + public void shouldParseResponse() throws IOException { + final OAuth2AccessToken token = extractor.extract(ok(RESPONSE)); assertEquals(token.getAccessToken(), "I0122HHJKLEM21F3WLPYHDKGKZULAUO4SGMV3ABKFTDT3T3X"); } @Test(expected = IllegalArgumentException.class) - public void shouldThrowExceptionIfForNullParameters() { - extractor.extract(null); + public void shouldThrowExceptionIfForNullParameters() throws IOException { + extractor.extract(ok(null)); } @Test(expected = IllegalArgumentException.class) - public void shouldThrowExceptionIfForEmptyStrings() { - extractor.extract(""); + public void shouldThrowExceptionIfForEmptyStrings() throws IOException { + extractor.extract(ok("")); + } + + @Test + public void shouldThrowExceptionIfResponseIsError() throws IOException { + final String body = "{" + + "\"error_description\":\"unknown, invalid, or expired refresh token\"," + + "\"error\":\"invalid_grant\"" + + "}"; + boolean hadException = false; + try { + extractor.extract(error(body)); + } catch (OAuth2ErrorResponse oaer) { + hadException = true; + assertEquals(OAuth2ErrorResponse.OAuthError.invalid_grant, oaer.getError()); + assertEquals("unknown, invalid, or expired refresh token", oaer.getErrorDescription()); + } + assertTrue(hadException); + } + + private static Response ok(String body) { + return new Response(200, /* message */ null, /* headers */ Collections.emptyMap(), + body, /* stream */ null); + } + + private static Response error(String body) { + return new Response(400, /* message */ null, /* headers */ Collections.emptyMap(), + body, /* stream */ null); } } From aa4e6188b07a814b006a03ab3cdc0cdddfb061aa Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 8 Sep 2016 17:43:01 +0300 Subject: [PATCH 276/882] some fixes --- changelog | 3 ++- .../com/github/scribejava/apis/NaverApi.java | 2 ++ .../exceptions/OAuthRequestException.java | 17 ------------ .../OAuth2AccessTokenJsonExtractor.java | 10 ++++--- .../core/extractors/TokenExtractor.java | 3 ++- ...va => OAuth2AccessTokenErrorResponse.java} | 27 +++++++++---------- .../OAuth2AccessTokenJsonExtractorTest.java | 12 ++++----- 7 files changed, 30 insertions(+), 44 deletions(-) delete mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/exceptions/OAuthRequestException.java rename scribejava-core/src/main/java/com/github/scribejava/core/model/{OAuth2ErrorResponse.java => OAuth2AccessTokenErrorResponse.java} (56%) diff --git a/changelog b/changelog index 4b6fc922d..cd7edebaa 100644 --- a/changelog +++ b/changelog @@ -1,5 +1,6 @@ [SNAPSHOT] - * Add Naver API + * Add Naver API (thanks to chooco) + * 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/ diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/NaverApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/NaverApi.java index 1f021fe03..514b17b96 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/NaverApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/NaverApi.java @@ -17,10 +17,12 @@ public static NaverApi instance() { return NaverApi.InstanceHolder.INSTANCE; } + @Override public String getAccessTokenEndpoint() { return "https://nid.naver.com/oauth2.0/token?grant_type=authorization_code"; } + @Override protected String getAuthorizationBaseUrl() { return "https://nid.naver.com/oauth2.0/authorize"; } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/exceptions/OAuthRequestException.java b/scribejava-core/src/main/java/com/github/scribejava/core/exceptions/OAuthRequestException.java deleted file mode 100644 index 409a51501..000000000 --- a/scribejava-core/src/main/java/com/github/scribejava/core/exceptions/OAuthRequestException.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.github.scribejava.core.exceptions; - -import com.github.scribejava.core.model.OAuth2ErrorResponse; - -public class OAuthRequestException extends OAuthException { - - private final OAuth2ErrorResponse error; - - public OAuthRequestException(String message, OAuth2ErrorResponse error) { - super(message); - this.error = error; - } - - public OAuth2ErrorResponse getError() { - return error; - } -} 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 465b31c04..feeed66a7 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 @@ -6,7 +6,7 @@ import java.util.regex.Pattern; import com.github.scribejava.core.exceptions.OAuthException; import com.github.scribejava.core.model.OAuth2AccessToken; -import com.github.scribejava.core.model.OAuth2ErrorResponse; +import com.github.scribejava.core.model.OAuth2AccessTokenErrorResponse; import com.github.scribejava.core.model.Response; import com.github.scribejava.core.utils.Preconditions; @@ -48,7 +48,9 @@ public OAuth2AccessToken extract(Response response) throws IOException { return createToken(body); } - // Related documentation: https://tools.ietf.org/html/rfc6749#section-5.2 + /** + * Related documentation: https://tools.ietf.org/html/rfc6749#section-5.2 + */ private static void generateError(String response) { final String errorInString = extractParameter(response, ERROR_REGEX, true); final String errorDescription = extractParameter(response, ERROR_DESCRIPTION_REGEX, false); @@ -60,8 +62,8 @@ private static void generateError(String response) { errorUri = null; } - throw new OAuth2ErrorResponse(OAuth2ErrorResponse.OAuthError.valueOf(errorInString), errorDescription, - errorUri, response); + throw new OAuth2AccessTokenErrorResponse(OAuth2AccessTokenErrorResponse.ErrorCode.valueOf(errorInString), + errorDescription, errorUri, response); } private OAuth2AccessToken createToken(String response) { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/TokenExtractor.java b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/TokenExtractor.java index 0e1a1cfa8..00c662d81 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/TokenExtractor.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/TokenExtractor.java @@ -15,8 +15,9 @@ public interface TokenExtractor { /** * Extracts the concrete type of token from the contents of an Http Response * - * @param response the contents of the response + * @param response the whole response * @return OAuth access token + * @throws java.io.IOException in case of troubles while getting body from the response */ T extract(Response response) throws IOException, OAuthException; } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth2ErrorResponse.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth2AccessTokenErrorResponse.java similarity index 56% rename from scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth2ErrorResponse.java rename to scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth2AccessTokenErrorResponse.java index d39ffa55b..eba31404e 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth2ErrorResponse.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth2AccessTokenErrorResponse.java @@ -7,34 +7,33 @@ /** * Representing "5.2. Error Response" */ -public class OAuth2ErrorResponse extends OAuthException { +public class OAuth2AccessTokenErrorResponse extends OAuthException { - public enum OAuthError { + private static final long serialVersionUID = 2309424849700276816L; + + public enum ErrorCode { invalid_request, invalid_client, invalid_grant, unauthorized_client, unsupported_grant_type, invalid_scope } - private final OAuthError error; + private final ErrorCode errorCode; private final String errorDescription; private final URI errorUri; private final String rawResponse; - public OAuth2ErrorResponse(OAuthError error, String errorDescription, URI errorUri, String rawResponse) { - super(generateMessage(error, errorDescription, errorUri, rawResponse)); - if (error == null) { - throw new IllegalArgumentException("error must not be null"); + public OAuth2AccessTokenErrorResponse(ErrorCode errorCode, String errorDescription, URI errorUri, + String rawResponse) { + super(rawResponse); + if (errorCode == null) { + throw new IllegalArgumentException("errorCode must not be null"); } - this.error = error; + this.errorCode = errorCode; this.errorDescription = errorDescription; this.errorUri = errorUri; this.rawResponse = rawResponse; } - private static String generateMessage(OAuthError error, String errorDescription, URI errorUri, String rawResponse) { - return rawResponse; - } - - public OAuthError getError() { - return error; + public ErrorCode getErrorCode() { + return errorCode; } public String getErrorDescription() { 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 a92c9ba1d..026885dcf 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 @@ -1,7 +1,7 @@ package com.github.scribejava.core.extractors; import com.github.scribejava.core.model.OAuth2AccessToken; -import com.github.scribejava.core.model.OAuth2ErrorResponse; +import com.github.scribejava.core.model.OAuth2AccessTokenErrorResponse; import com.github.scribejava.core.model.Response; import org.junit.Test; @@ -9,7 +9,7 @@ import java.util.Collections; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; public class OAuth2AccessTokenJsonExtractorTest { @@ -38,15 +38,13 @@ public void shouldThrowExceptionIfResponseIsError() throws IOException { "\"error_description\":\"unknown, invalid, or expired refresh token\"," + "\"error\":\"invalid_grant\"" + "}"; - boolean hadException = false; try { extractor.extract(error(body)); - } catch (OAuth2ErrorResponse oaer) { - hadException = true; - assertEquals(OAuth2ErrorResponse.OAuthError.invalid_grant, oaer.getError()); + fail(); + } catch (OAuth2AccessTokenErrorResponse oaer) { + assertEquals(OAuth2AccessTokenErrorResponse.ErrorCode.invalid_grant, oaer.getErrorCode()); assertEquals("unknown, invalid, or expired refresh token", oaer.getErrorDescription()); } - assertTrue(hadException); } private static Response ok(String body) { From 018398ae5b08c03a12f2e40319fbc9445da8cfca Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 8 Sep 2016 17:51:55 +0300 Subject: [PATCH 277/882] update AHC http client --- scribejava-httpclient-ahc/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 1161c406d..e8c45940f 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -23,7 +23,7 @@ org.asynchttpclient async-http-client - 2.0.12 + 2.0.14 From ef017161b5b3844ad433912529980314d3df594f Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 8 Sep 2016 17:58:10 +0300 Subject: [PATCH 278/882] prepare to release 3.2.0 --- README.md | 4 ++-- changelog | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 0e74d2d6b..81e365476 100644 --- a/README.md +++ b/README.md @@ -93,7 +93,7 @@ You can pull ScribeJava from the central maven repository, just add these to you com.github.scribejava scribejava-apis - 3.1.0 + 3.2.0 ``` @@ -102,7 +102,7 @@ And in case you need just core classes (that's it, without any external API (FB, com.github.scribejava scribejava-core - 3.1.0 + 3.2.0 ``` diff --git a/changelog b/changelog index cd7edebaa..2acf8c641 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,4 @@ -[SNAPSHOT] +[3.2.0] * Add Naver API (thanks to chooco) * handle OAuth2 error response for Issuing an Access Token (thanks to juherr) From 4cd60c183162cc7f96ffa12aaac0755469c21f62 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 8 Sep 2016 17:59:07 +0300 Subject: [PATCH 279/882] [maven-release-plugin] prepare release scribejava-3.2.0 --- pom.xml | 2 +- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index 226256246..ac936e8a9 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 3.1.1-SNAPSHOT + 3.2.0 ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 0fc7155a3..dc8968df6 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 3.1.1-SNAPSHOT + 3.2.0 ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index ceabc6b76..3faf98da7 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 3.1.1-SNAPSHOT + 3.2.0 ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index e8c45940f..c061a3fe9 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 3.1.1-SNAPSHOT + 3.2.0 ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index af7aa4794..38bbb6217 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 3.1.1-SNAPSHOT + 3.2.0 ../pom.xml From c9ac8639566a67502fcfca52f3b6aac3d1df96f7 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 8 Sep 2016 17:59:13 +0300 Subject: [PATCH 280/882] [maven-release-plugin] prepare for next development iteration --- pom.xml | 2 +- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index ac936e8a9..11e7535e2 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 3.2.0 + 3.2.1-SNAPSHOT ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index dc8968df6..8a95b9739 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 3.2.0 + 3.2.1-SNAPSHOT ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 3faf98da7..b8774fd58 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 3.2.0 + 3.2.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index c061a3fe9..6d76e6ebf 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 3.2.0 + 3.2.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index 38bbb6217..c0d6d44e3 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 3.2.0 + 3.2.1-SNAPSHOT ../pom.xml From aef1632ddf93479fb719f1ef0a4c3bbc7d642a5c Mon Sep 17 00:00:00 2001 From: Ray Vanderborght Date: Sat, 1 Oct 2016 15:59:03 -0700 Subject: [PATCH 281/882] Ensure consistent Content-Encoding header name in Response Support HttpURLConnection implementations such as the one google appengine uses, which normalizes header names to lower case in the implementation of getHeaderFields(). --- .../com/github/scribejava/core/model/Response.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/Response.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/Response.java index 869066788..f52eb77df 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/Response.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/Response.java @@ -5,7 +5,9 @@ import java.net.HttpURLConnection; import java.net.UnknownHostException; import java.util.HashMap; +import java.util.List; import java.util.Map; +import java.util.Map.Entry; import com.github.scribejava.core.exceptions.OAuthException; import com.github.scribejava.core.utils.StreamUtils; @@ -48,8 +50,13 @@ private String parseBodyContents() throws IOException { private Map parseHeaders(HttpURLConnection conn) { final Map headers = new HashMap<>(); - for (String key : conn.getHeaderFields().keySet()) { - headers.put(key, conn.getHeaderFields().get(key).get(0)); + for (final Entry> entry : conn.getHeaderFields().entrySet()) { + final String key = entry.getKey(); + if ("Content-Encoding".equalsIgnoreCase(key)) { + headers.put("Content-Encoding", entry.getValue().get(0)); + } else { + headers.put(key, entry.getValue().get(0)); + } } return headers; } From d5ce425921f2866e0b08ec23a4d9b146da639aae Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 6 Oct 2016 16:36:38 +0300 Subject: [PATCH 282/882] update maven deps, cleanup redundant 'final' --- pom.xml | 2 +- .../main/java/com/github/scribejava/core/model/Response.java | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 11e7535e2..cff41d24c 100644 --- a/pom.xml +++ b/pom.xml @@ -130,7 +130,7 @@ com.puppycrawl.tools checkstyle - 7.1 + 7.1.2 diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/Response.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/Response.java index f52eb77df..e57f39c44 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/Response.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/Response.java @@ -50,7 +50,7 @@ private String parseBodyContents() throws IOException { private Map parseHeaders(HttpURLConnection conn) { final Map headers = new HashMap<>(); - for (final Entry> entry : conn.getHeaderFields().entrySet()) { + for (Entry> entry : conn.getHeaderFields().entrySet()) { final String key = entry.getKey(); if ("Content-Encoding".equalsIgnoreCase(key)) { headers.put("Content-Encoding", entry.getValue().get(0)); diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 6d76e6ebf..ee1bc2b17 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -23,7 +23,7 @@ org.asynchttpclient async-http-client - 2.0.14 + 2.0.15 From d9c8a0f356494cf1b38c4f8fec27414379f1d8ef Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 12 Oct 2016 12:58:47 +0300 Subject: [PATCH 283/882] update Facebook v2.6 -> v2.8 --- changelog | 3 +++ .../main/java/com/github/scribejava/apis/FacebookApi.java | 6 +++--- .../scribejava/apis/examples/FacebookAsyncNingExample.java | 2 +- .../github/scribejava/apis/examples/FacebookExample.java | 2 +- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/changelog b/changelog index 2acf8c641..8220f8a2b 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,6 @@ +[SNAPSHOT] + * update Facebook v2.6 -> v2.8 + [3.2.0] * Add Naver API (thanks to chooco) * handle OAuth2 error response for Issuing an Access Token (thanks to juherr) 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 9bf5abfc0..1f00e931c 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 @@ -4,7 +4,7 @@ import com.github.scribejava.core.model.Verb; /** - * Facebook v2.6 API + * Facebook v2.8 API */ public class FacebookApi extends DefaultApi20 { @@ -27,7 +27,7 @@ public Verb getAccessTokenVerb() { @Override public String getAccessTokenEndpoint() { - return "https://graph.facebook.com/v2.6/oauth/access_token"; + return "https://graph.facebook.com/v2.8/oauth/access_token"; } @Override @@ -37,6 +37,6 @@ public String getRefreshTokenEndpoint() { @Override protected String getAuthorizationBaseUrl() { - return "https://www.facebook.com/v2.6/dialog/oauth"; + return "https://www.facebook.com/v2.8/dialog/oauth"; } } diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java index 9cddb3b85..ce0aab781 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java @@ -19,7 +19,7 @@ public final class FacebookAsyncNingExample { private static final String NETWORK_NAME = "Facebook"; - private static final String PROTECTED_RESOURCE_URL = "https://graph.facebook.com/v2.6/me"; + private static final String PROTECTED_RESOURCE_URL = "https://graph.facebook.com/v2.8/me"; private FacebookAsyncNingExample() { } diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java index 9da9c874b..d955c1f85 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java @@ -14,7 +14,7 @@ public final class FacebookExample { private static final String NETWORK_NAME = "Facebook"; - private static final String PROTECTED_RESOURCE_URL = "https://graph.facebook.com/v2.6/me"; + private static final String PROTECTED_RESOURCE_URL = "https://graph.facebook.com/v2.8/me"; private FacebookExample() { } From e6f305d3de95f9786f20fdd92a3bafec6e32d92f Mon Sep 17 00:00:00 2001 From: jpmeijers Date: Wed, 2 Nov 2016 12:35:39 +0100 Subject: [PATCH 284/882] Added API and tests for The Things Network. Both for v1-staging and v2-preview. You need to register your own client_id with TTN to use this library. --- .../apis/TheThingsNetworkV1StagingApi.java | 41 +++++++ .../apis/TheThingsNetworkV2PreviewApi.java | 41 +++++++ .../apis/examples/TTNV1Example.java | 105 ++++++++++++++++++ .../apis/examples/TTNV2Example.java | 101 +++++++++++++++++ 4 files changed, 288 insertions(+) create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/TheThingsNetworkV1StagingApi.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/TheThingsNetworkV2PreviewApi.java create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TTNV1Example.java create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TTNV2Example.java diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/TheThingsNetworkV1StagingApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/TheThingsNetworkV1StagingApi.java new file mode 100644 index 000000000..4b97b50c5 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/TheThingsNetworkV1StagingApi.java @@ -0,0 +1,41 @@ +package com.github.scribejava.apis; + +import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; +import com.github.scribejava.core.extractors.TokenExtractor; +import com.github.scribejava.core.model.OAuth2AccessToken; +import com.github.scribejava.core.model.Verb; + +public class TheThingsNetworkV1StagingApi extends DefaultApi20 { + + protected TheThingsNetworkV1StagingApi() { + } + + private static class InstanceHolder { + private static final TheThingsNetworkV1StagingApi INSTANCE = new TheThingsNetworkV1StagingApi(); + } + + public static TheThingsNetworkV1StagingApi instance() { + return InstanceHolder.INSTANCE; + } + + @Override + public Verb getAccessTokenVerb() { + return Verb.POST; + } + + @Override + public String getAccessTokenEndpoint() { + return "https://account.thethingsnetwork.org/users/token"; + } + + @Override + protected String getAuthorizationBaseUrl() { + return "https://account.thethingsnetwork.org/users/authorize"; + } + + @Override + public TokenExtractor getAccessTokenExtractor() { + return OAuth2AccessTokenJsonExtractor.instance(); + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/TheThingsNetworkV2PreviewApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/TheThingsNetworkV2PreviewApi.java new file mode 100644 index 000000000..c649e2298 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/TheThingsNetworkV2PreviewApi.java @@ -0,0 +1,41 @@ +package com.github.scribejava.apis; + +import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; +import com.github.scribejava.core.extractors.TokenExtractor; +import com.github.scribejava.core.model.OAuth2AccessToken; +import com.github.scribejava.core.model.Verb; + +public class TheThingsNetworkV2PreviewApi extends DefaultApi20 { + + protected TheThingsNetworkV2PreviewApi() { + } + + private static class InstanceHolder { + private static final TheThingsNetworkV2PreviewApi INSTANCE = new TheThingsNetworkV2PreviewApi(); + } + + public static TheThingsNetworkV2PreviewApi instance() { + return InstanceHolder.INSTANCE; + } + + @Override + public Verb getAccessTokenVerb() { + return Verb.POST; + } + + @Override + public String getAccessTokenEndpoint() { + return "https://preview.account.thethingsnetwork.org/users/token"; + } + + @Override + protected String getAuthorizationBaseUrl() { + return "https://preview.account.thethingsnetwork.org/users/authorize"; + } + + @Override + public TokenExtractor getAccessTokenExtractor() { + return OAuth2AccessTokenJsonExtractor.instance(); + } +} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TTNV1Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TTNV1Example.java new file mode 100644 index 000000000..d9652405c --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TTNV1Example.java @@ -0,0 +1,105 @@ +package com.github.scribejava.apis.examples; + +import com.github.scribejava.apis.TheThingsNetworkV1StagingApi; +import com.github.scribejava.apis.TheThingsNetworkV2PreviewApi; +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.net.URLDecoder; +import java.util.Random; +import java.util.Scanner; + +public final class TTNV1Example { + + private static final String NETWORK_NAME = "TTNv1staging"; + private static final String PROTECTED_RESOURCE_URL = "https://account.thethingsnetwork.org/applications"; + + private TTNV1Example() { + } + + public static void main(String... args) throws IOException { + // Replace these with your client id and secret + final String clientId = "your_client_id"; + final String clientSecret = "your_client_secret"; + final String secretState = "secret" + new Random().nextInt(999_999); + final String redirectURI = "https://your_redirect_uri"; + + final OAuth20Service service = new ServiceBuilder() + .apiKey(clientId) + .apiSecret(clientSecret) + .state(secretState) + .callback(redirectURI) + .build(TheThingsNetworkV1StagingApi.instance()); + final Scanner in = new Scanner(System.in, "UTF-8"); + + System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); + System.out.println(); + + // Obtain the Authorization URL + System.out.println("Fetching the Authorization URL..."); + final String authorizationUrl = service.getAuthorizationUrl(); + System.out.println("Got the Authorization URL!"); + System.out.println("Now go and authorize ScribeJava here:"); + System.out.println(authorizationUrl); + System.out.println("And paste the authorization code here"); + System.out.print(">>"); + + // TTN v1staging does not have URL safe keys, so we have to decode it + final String code = URLDecoder.decode(in.nextLine(), "UTF-8"); + System.out.println("Using code: "+code); + System.out.println(); + + 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("Oops, state value does not match!"); + System.out.println("Expected = " + secretState); + System.out.println("Got = " + value); + System.out.println(); + } + + // Trade the Request Token and Verifier for the Access Token + System.out.println("Trading the Request Token for an Access Token..."); + final OAuth2AccessToken accessToken = service.getAccessToken(code); + System.out.println("Got the Access Token!"); + System.out.println("(if your curious it looks like this: " + accessToken + + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println(); + + // Now let's go and ask for a protected resource! + System.out.println("Now we're going to access a protected resource..."); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service); + + // TTN should support both signing the request with a parameter, or with a header. + // 1. Token as a parameter + service.signRequest(accessToken, request); + // 2. Token in the header. + //request.addHeader("Authorization", "bearer "+accessToken.getAccessToken()); + // And we always expect JSON data. + request.addHeader("Accept", "application/json"); + final Response response = request.send(); + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getCode()); + + if(response.getCode()==401) + { + System.out.println("Not authorised: "+response.getBody()); + } + else { + System.out.println("You should see a JSON array of your registered applications:"); + System.out.println(response.getBody()); + + System.out.println(); + System.out.println("That's it man! Go and build something awesome with ScribeJava! :)"); + } + } +} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TTNV2Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TTNV2Example.java new file mode 100644 index 000000000..18979aa8b --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TTNV2Example.java @@ -0,0 +1,101 @@ +package com.github.scribejava.apis.examples; + +import com.github.scribejava.apis.TheThingsNetworkV2PreviewApi; +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.net.URLDecoder; +import java.util.Random; +import java.util.Scanner; + +public final class TTNV2Example { + + private static final String NETWORK_NAME = "TTNv2preview"; + private static final String PROTECTED_RESOURCE_URL = "https://preview.account.thethingsnetwork.org/api/v2/applications"; + + private TTNV2Example() { + } + + public static void main(String... args) throws IOException { + // Replace these with your client id and secret + final String clientId = "your_client_id"; + final String clientSecret = "your_client_secret"; + final String secretState = "secret" + new Random().nextInt(999_999); + final String redirectURI = "https://your_redirect_uri"; + + final OAuth20Service service = new ServiceBuilder() + .apiKey(clientId) + .apiSecret(clientSecret) + .state(secretState) + .callback(redirectURI) + .build(TheThingsNetworkV2PreviewApi.instance()); + final Scanner in = new Scanner(System.in, "UTF-8"); + + System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); + System.out.println(); + + // Obtain the Authorization URL + System.out.println("Fetching the Authorization URL..."); + final String authorizationUrl = service.getAuthorizationUrl(); + System.out.println("Got the Authorization URL!"); + System.out.println("Now go and authorize ScribeJava here:"); + System.out.println(authorizationUrl); + System.out.println("And paste the authorization code here"); + System.out.print(">>"); + final String code = in.nextLine(); + System.out.println(); + + System.out.println("And paste the state from server here. We have set 'secretState'='" + secretState + "'."); + System.out.print(">>"); + final String value = in.nextLine(); + if (secretState.equals(value)) { + System.out.println("State value does match!"); + } else { + System.out.println("Oops, state value does not match!"); + System.out.println("Expected = " + secretState); + System.out.println("Got = " + value); + System.out.println(); + } + + // Trade the Request Token and Verifier for the Access Token + System.out.println("Trading the Request Token for an Access Token..."); + final OAuth2AccessToken accessToken = service.getAccessToken(code); + System.out.println("Got the Access Token!"); + System.out.println("(if your curious it looks like this: " + accessToken + + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println(); + + // Now let's go and ask for a protected resource! + System.out.println("Now we're going to access a protected resource..."); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service); + + // TTN should support both signing the request with a parameter, or with a header. + // 1. Token as a parameter + service.signRequest(accessToken, request); + // 2. Token in the header. + //request.addHeader("Authorization", "bearer "+accessToken.getAccessToken()); + // And we always expect JSON data. + request.addHeader("Accept", "application/json"); + final Response response = request.send(); + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getCode()); + + if(response.getCode()==401) + { + System.out.println("Not authorised: "+response.getBody()); + } + else { + System.out.println("You should see a JSON array of your registered applications:"); + System.out.println(response.getBody()); + + System.out.println(); + System.out.println("That's it man! Go and build something awesome with ScribeJava! :)"); + } + } +} From 4eee5ffc1ab3f8523f21db3e10702414b458246a Mon Sep 17 00:00:00 2001 From: jpmeijers Date: Wed, 2 Nov 2016 14:46:05 +0100 Subject: [PATCH 285/882] Fix style errors from tests. --- .../github/scribejava/apis/examples/TTNV1Example.java | 7 ++----- .../github/scribejava/apis/examples/TTNV2Example.java | 10 ++++------ 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TTNV1Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TTNV1Example.java index d9652405c..155b9e999 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TTNV1Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TTNV1Example.java @@ -1,7 +1,6 @@ package com.github.scribejava.apis.examples; import com.github.scribejava.apis.TheThingsNetworkV1StagingApi; -import com.github.scribejava.apis.TheThingsNetworkV2PreviewApi; import com.github.scribejava.core.builder.ServiceBuilder; import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthRequest; @@ -90,11 +89,9 @@ public static void main(String... args) throws IOException { System.out.println(); System.out.println(response.getCode()); - if(response.getCode()==401) - { + if(response.getCode()==401) { System.out.println("Not authorised: "+response.getBody()); - } - else { + } else { System.out.println("You should see a JSON array of your registered applications:"); System.out.println(response.getBody()); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TTNV2Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TTNV2Example.java index 18979aa8b..d8c30ffbc 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TTNV2Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TTNV2Example.java @@ -9,14 +9,14 @@ import com.github.scribejava.core.oauth.OAuth20Service; import java.io.IOException; -import java.net.URLDecoder; import java.util.Random; import java.util.Scanner; public final class TTNV2Example { private static final String NETWORK_NAME = "TTNv2preview"; - private static final String PROTECTED_RESOURCE_URL = "https://preview.account.thethingsnetwork.org/api/v2/applications"; + private static final String PROTECTED_RESOURCE_URL = + "https://preview.account.thethingsnetwork.org/api/v2/applications"; private TTNV2Example() { } @@ -86,11 +86,9 @@ public static void main(String... args) throws IOException { System.out.println(); System.out.println(response.getCode()); - if(response.getCode()==401) - { + if(response.getCode()==401) { System.out.println("Not authorised: "+response.getBody()); - } - else { + } else { System.out.println("You should see a JSON array of your registered applications:"); System.out.println(response.getBody()); From 53ebea16ae7eefd96d7f4ebfadad5f1fa983ebfa Mon Sep 17 00:00:00 2001 From: jpmeijers Date: Wed, 2 Nov 2016 14:53:53 +0100 Subject: [PATCH 286/882] Remove trailing white space. --- .../java/com/github/scribejava/apis/examples/TTNV2Example.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TTNV2Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TTNV2Example.java index d8c30ffbc..290f90905 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TTNV2Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TTNV2Example.java @@ -15,7 +15,7 @@ public final class TTNV2Example { private static final String NETWORK_NAME = "TTNv2preview"; - private static final String PROTECTED_RESOURCE_URL = + private static final String PROTECTED_RESOURCE_URL = "https://preview.account.thethingsnetwork.org/api/v2/applications"; private TTNV2Example() { From 6bff3a43878bb43f3fb398405936bd6baf2eaace Mon Sep 17 00:00:00 2001 From: Steven McLaughlin Date: Wed, 2 Nov 2016 17:48:01 -0400 Subject: [PATCH 287/882] Added an Api for Box.com --- .../com/github/scribejava/apis/BoxApi20.java | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/BoxApi20.java diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/BoxApi20.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/BoxApi20.java new file mode 100644 index 000000000..b1bfb28b0 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/BoxApi20.java @@ -0,0 +1,33 @@ +package com.github.scribejava.apis; + +import com.github.scribejava.core.builder.api.DefaultApi20; + +/** + * Box.com Api + */ +public class BoxApi20 extends DefaultApi20 { + + + protected BoxApi20() { + + } + + private static class InstanceHolder { + private static final BoxApi20 INSTANCE = new BoxApi20(); + } + + public static BoxApi20 instance() { + return InstanceHolder.INSTANCE; + } + + @Override + public String getAccessTokenEndpoint() { + return "https://api.box.com/oauth2/token"; + } + + @Override + protected String getAuthorizationBaseUrl() { + return "https://account.box.com/api/oauth2/authorize"; + } + +} From edeecaa0aa74eb238cfc8a97ff3f5714089315bf Mon Sep 17 00:00:00 2001 From: MclaughlinSteve Date: Wed, 2 Nov 2016 22:24:15 -0400 Subject: [PATCH 288/882] Changed Whitespace to tabs Fixed whitespace errors, and added first draft of test. Will update test soon. --- .../com/github/scribejava/apis/BoxApi20.java | 29 +++-- .../apis/examples/Box20Example.java | 112 ++++++++++++++++++ 2 files changed, 126 insertions(+), 15 deletions(-) create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Box20Example.java diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/BoxApi20.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/BoxApi20.java index b1bfb28b0..4353b6fdf 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/BoxApi20.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/BoxApi20.java @@ -6,12 +6,11 @@ * Box.com Api */ public class BoxApi20 extends DefaultApi20 { - - - protected BoxApi20() { - - } - + + + protected BoxApi20() { + } + private static class InstanceHolder { private static final BoxApi20 INSTANCE = new BoxApi20(); } @@ -20,14 +19,14 @@ public static BoxApi20 instance() { return InstanceHolder.INSTANCE; } - @Override - public String getAccessTokenEndpoint() { - return "https://api.box.com/oauth2/token"; - } + @Override + public String getAccessTokenEndpoint() { + return "https://api.box.com/oauth2/token"; + } + + @Override + protected String getAuthorizationBaseUrl() { + return "https://account.box.com/api/oauth2/authorize"; + } - @Override - protected String getAuthorizationBaseUrl() { - return "https://account.box.com/api/oauth2/authorize"; - } - } diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Box20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Box20Example.java new file mode 100644 index 000000000..55a35fbda --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Box20Example.java @@ -0,0 +1,112 @@ +package com.github.scribejava.apis.examples; + +import java.util.Random; +import java.util.Scanner; +import com.github.scribejava.core.builder.ServiceBuilder; +import com.github.scribejava.apis.BoxApi20; +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; + +public final class Box20Example { + + private static final String NETWORK_NAME = "Box"; + private static final String PROTECTED_RESOURCE_URL = "https://www.googleapis.com/plus/v1/people/me"; + + private Box20Example() { + } + + public static void main(String... args) throws IOException { + //Replace these with your client id and secret + final String clientId ="your client id"; + final string clientSecret = "your client secret"; + final String secretState = "secret" + new Random().nextInt(999_999); + final OAuth20Service service = new ServiceBuilder() + .apiKey(clientId) + .apiSecret(clientSecret) + .scope("profile") // replace with desired scope + .state(secretState) + .callback("http://example.com/callback") + .build(BoxApi20.instance()); + final Scanner in = new Scanner(System.in, "UTF-8"); + + System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); + System.out.println(); + + // Obtain the Authorization URL + System.out.println("Fetching the Authorization URL..."); + //pass access_type=offline to get refresh token + //https://developers.google.com/identity/protocols/OAuth2WebServer#preparing-to-start-the-oauth-20-flow + final Map additionalParams = new HashMap<>(); + additionalParams.put("access_type", "offline"); + //force to reget refresh token (if usera are asked not the first time) + additionalParams.put("prompt", "consent"); + final String authorizationUrl = service.getAuthorizationUrl(additionalParams); + System.out.println("Got the Authorization URL!"); + System.out.println("Now go and authorize ScribeJava here:"); + System.out.println(authorizationUrl); + System.out.println("And paste the authorization code here"); + System.out.print(">>"); + final String code = in.nextLine(); + System.out.println(); + + System.out.println("And paste the state from server here. We have set 'secretState'='" + secretState + "'."); + System.out.print(">>"); + final String value = in.nextLine(); + if (secretState.equals(value)) { + System.out.println("State value does match!"); + } else { + System.out.println("Ooops, state value does not match!"); + System.out.println("Expected = " + secretState); + System.out.println("Got = " + value); + System.out.println(); + } + + // Trade the Request Token and Verfier for the Access Token + System.out.println("Trading the Request Token for an Access Token..."); + OAuth2AccessToken accessToken = service.getAccessToken(code); + System.out.println("Got the Access Token!"); + System.out.println("(if your curious it looks like this: " + accessToken + + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + + System.out.println("Refreshing the Access Token..."); + accessToken = service.refreshAccessToken(accessToken.getRefreshToken()); + System.out.println("Refreshed the Access Token!"); + System.out.println("(if your curious it looks like this: " + accessToken + + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println(); + + // Now let's go and ask for a protected resource! + System.out.println("Now we're going to access a protected resource..."); + while (true) { + System.out.println("Paste fieldnames to fetch (leave empty to get profile, 'exit' to stop example)"); + System.out.print(">>"); + final String query = in.nextLine(); + System.out.println(); + + final String requestUrl; + if ("exit".equals(query)) { + break; + } else if (query == null || query.isEmpty()) { + requestUrl = PROTECTED_RESOURCE_URL; + } else { + requestUrl = PROTECTED_RESOURCE_URL + "?fields=" + query; + } + + final OAuthRequest request = new OAuthRequest(Verb.GET, requestUrl, service); + service.signRequest(accessToken, request); + final Response response = request.send(); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + + System.out.println(); + } + } + +} \ No newline at end of file From 6e6c5502827bb2910002ff3f08fcbd4b60f27047 Mon Sep 17 00:00:00 2001 From: MclaughlinSteve Date: Wed, 2 Nov 2016 22:31:41 -0400 Subject: [PATCH 289/882] Whitespace fixes fixed some additional whitespace issues --- .../src/main/java/com/github/scribejava/apis/BoxApi20.java | 2 +- .../com/github/scribejava/apis/examples/Box20Example.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/BoxApi20.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/BoxApi20.java index 4353b6fdf..79d75180c 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/BoxApi20.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/BoxApi20.java @@ -8,7 +8,7 @@ public class BoxApi20 extends DefaultApi20 { - protected BoxApi20() { + protected BoxApi20() { } private static class InstanceHolder { diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Box20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Box20Example.java index 55a35fbda..9fd966ad8 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Box20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Box20Example.java @@ -23,7 +23,7 @@ private Box20Example() { public static void main(String... args) throws IOException { //Replace these with your client id and secret - final String clientId ="your client id"; + final String clientId = "your client id"; final string clientSecret = "your client secret"; final String secretState = "secret" + new Random().nextInt(999_999); final OAuth20Service service = new ServiceBuilder() @@ -109,4 +109,4 @@ public static void main(String... args) throws IOException { } } -} \ No newline at end of file +} From cee1ed39f39cb5fd403db3986d2412d6cab7da0c Mon Sep 17 00:00:00 2001 From: MclaughlinSteve Date: Wed, 2 Nov 2016 22:36:53 -0400 Subject: [PATCH 290/882] Fixed typo fixed typo (string -> String) --- .../java/com/github/scribejava/apis/examples/Box20Example.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Box20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Box20Example.java index 9fd966ad8..cc5adffd2 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Box20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Box20Example.java @@ -24,7 +24,7 @@ private Box20Example() { public static void main(String... args) throws IOException { //Replace these with your client id and secret final String clientId = "your client id"; - final string clientSecret = "your client secret"; + final String clientSecret = "your client secret"; final String secretState = "secret" + new Random().nextInt(999_999); final OAuth20Service service = new ServiceBuilder() .apiKey(clientId) From a47689cebdc97795d68b7380bbbcc2c5e772a63d Mon Sep 17 00:00:00 2001 From: MclaughlinSteve Date: Wed, 2 Nov 2016 23:26:54 -0400 Subject: [PATCH 291/882] Fixed test Updated test. Should be working now --- .../apis/examples/Box20Example.java | 44 +++---------------- 1 file changed, 5 insertions(+), 39 deletions(-) diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Box20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Box20Example.java index cc5adffd2..17997fd6e 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Box20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Box20Example.java @@ -16,7 +16,7 @@ public final class Box20Example { private static final String NETWORK_NAME = "Box"; - private static final String PROTECTED_RESOURCE_URL = "https://www.googleapis.com/plus/v1/people/me"; + private static final String PROTECTED_RESOURCE_URL = "https://app.box.com/files"; private Box20Example() { } @@ -25,13 +25,12 @@ public static void main(String... args) throws IOException { //Replace these with your client id and secret final String clientId = "your client id"; final String clientSecret = "your client secret"; - final String secretState = "secret" + new Random().nextInt(999_999); + final String secretState = "security_token" + new Random().nextInt(999_999); final OAuth20Service service = new ServiceBuilder() .apiKey(clientId) .apiSecret(clientSecret) - .scope("profile") // replace with desired scope .state(secretState) - .callback("http://example.com/callback") + .callback("https://example.com/callback") .build(BoxApi20.instance()); final Scanner in = new Scanner(System.in, "UTF-8"); @@ -41,7 +40,6 @@ public static void main(String... args) throws IOException { // Obtain the Authorization URL System.out.println("Fetching the Authorization URL..."); //pass access_type=offline to get refresh token - //https://developers.google.com/identity/protocols/OAuth2WebServer#preparing-to-start-the-oauth-20-flow final Map additionalParams = new HashMap<>(); additionalParams.put("access_type", "offline"); //force to reget refresh token (if usera are asked not the first time) @@ -71,42 +69,10 @@ public static void main(String... args) throws IOException { System.out.println("Trading the Request Token for an Access Token..."); OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken + System.out.println("(If you're curious, it looks like this: " + accessToken + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); - System.out.println("Refreshing the Access Token..."); - accessToken = service.refreshAccessToken(accessToken.getRefreshToken()); - System.out.println("Refreshed the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); - System.out.println(); - - // Now let's go and ask for a protected resource! - System.out.println("Now we're going to access a protected resource..."); - while (true) { - System.out.println("Paste fieldnames to fetch (leave empty to get profile, 'exit' to stop example)"); - System.out.print(">>"); - final String query = in.nextLine(); - System.out.println(); - - final String requestUrl; - if ("exit".equals(query)) { - break; - } else if (query == null || query.isEmpty()) { - requestUrl = PROTECTED_RESOURCE_URL; - } else { - requestUrl = PROTECTED_RESOURCE_URL + "?fields=" + query; - } - - final OAuthRequest request = new OAuthRequest(Verb.GET, requestUrl, service); - service.signRequest(accessToken, request); - final Response response = request.send(); - 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 6405e8b2b556dc9bd615b5095d8a1190e8e113d1 Mon Sep 17 00:00:00 2001 From: MclaughlinSteve Date: Wed, 2 Nov 2016 23:43:35 -0400 Subject: [PATCH 292/882] Updated test Made fixes to test --- .../scribejava/apis/examples/Box20Example.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Box20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Box20Example.java index 17997fd6e..f22aa6883 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Box20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Box20Example.java @@ -16,7 +16,7 @@ public final class Box20Example { private static final String NETWORK_NAME = "Box"; - private static final String PROTECTED_RESOURCE_URL = "https://app.box.com/files"; + private static final String PROTECTED_RESOURCE_URL = "https://app.box.com/profile"; private Box20Example() { } @@ -67,11 +67,23 @@ public static void main(String... args) throws IOException { // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - OAuth2AccessToken accessToken = service.getAccessToken(code); + final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); System.out.println("(If you're curious, it looks like this: " + accessToken + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println(); + + // 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); + service.signRequest(accessToken, request); + final Response response = request.send(); + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); } From 5ffd3abd64aa20892bc7cb646947cd8375bf35ae Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 8 Nov 2016 17:43:00 +0300 Subject: [PATCH 293/882] update dependencies --- pom.xml | 6 +++--- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index cff41d24c..71236d7af 100644 --- a/pom.xml +++ b/pom.xml @@ -84,7 +84,7 @@ com.google.code.gson gson - 2.7 + 2.8.0 test @@ -130,7 +130,7 @@ com.puppycrawl.tools checkstyle - 7.1.2 + 7.2 @@ -139,7 +139,7 @@ maven-compiler-plugin - 3.5.1 + 3.6.0 UTF-8 1.7 diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index ee1bc2b17..3c4e95698 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -23,7 +23,7 @@ org.asynchttpclient async-http-client - 2.0.15 + 2.0.21 diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index c0d6d44e3..5602512ca 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -23,7 +23,7 @@ com.ning async-http-client - 1.9.39 + 1.9.40 From 315cb1346ff20870761fc261a5931d2c53a4785b Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 8 Nov 2016 18:01:04 +0300 Subject: [PATCH 294/882] minor fixes and additionals for TheThingsNetwork --- README.md | 1 + changelog | 1 + .../apis/TheThingsNetworkV1StagingApi.java | 14 -------------- .../apis/TheThingsNetworkV2PreviewApi.java | 14 -------------- ....java => TheThingsNetworkV1StagingExample.java} | 4 ++-- ....java => TheThingsNetworkV2PreviewExample.java} | 4 ++-- 6 files changed, 6 insertions(+), 32 deletions(-) rename scribejava-apis/src/test/java/com/github/scribejava/apis/examples/{TTNV1Example.java => TheThingsNetworkV1StagingExample.java} (97%) rename scribejava-apis/src/test/java/com/github/scribejava/apis/examples/{TTNV2Example.java => TheThingsNetworkV2PreviewExample.java} (97%) diff --git a/README.md b/README.md index 81e365476..4dca5e9a8 100644 --- a/README.md +++ b/README.md @@ -59,6 +59,7 @@ You can use ning async http client 1.9.x or asynchttpclient 2.x out-of-box, just * Skyrock (http://skyrock.com/) * sohu 搜狐 (http://www.sohu.com/) * StackExchange (http://stackexchange.com/) +* The Things Network (v1-staging and v2-preview) (https://www.thethingsnetwork.org/) * Trello (https://trello.com/) * Tumblr (https://www.tumblr.com/) * TUT.BY (http://www.tut.by/) diff --git a/changelog b/changelog index 8220f8a2b..998deef3f 100644 --- a/changelog +++ b/changelog @@ -1,5 +1,6 @@ [SNAPSHOT] * update Facebook v2.6 -> v2.8 + * add The Things Network API (v1-staging and v2-preview) (thanks to https://github.com/jpmeijers) [3.2.0] * Add Naver API (thanks to chooco) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/TheThingsNetworkV1StagingApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/TheThingsNetworkV1StagingApi.java index 4b97b50c5..844d75758 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/TheThingsNetworkV1StagingApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/TheThingsNetworkV1StagingApi.java @@ -1,10 +1,6 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; -import com.github.scribejava.core.extractors.TokenExtractor; -import com.github.scribejava.core.model.OAuth2AccessToken; -import com.github.scribejava.core.model.Verb; public class TheThingsNetworkV1StagingApi extends DefaultApi20 { @@ -19,11 +15,6 @@ public static TheThingsNetworkV1StagingApi instance() { return InstanceHolder.INSTANCE; } - @Override - public Verb getAccessTokenVerb() { - return Verb.POST; - } - @Override public String getAccessTokenEndpoint() { return "https://account.thethingsnetwork.org/users/token"; @@ -33,9 +24,4 @@ public String getAccessTokenEndpoint() { protected String getAuthorizationBaseUrl() { return "https://account.thethingsnetwork.org/users/authorize"; } - - @Override - public TokenExtractor getAccessTokenExtractor() { - return OAuth2AccessTokenJsonExtractor.instance(); - } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/TheThingsNetworkV2PreviewApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/TheThingsNetworkV2PreviewApi.java index c649e2298..1ac5437a0 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/TheThingsNetworkV2PreviewApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/TheThingsNetworkV2PreviewApi.java @@ -1,10 +1,6 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; -import com.github.scribejava.core.extractors.TokenExtractor; -import com.github.scribejava.core.model.OAuth2AccessToken; -import com.github.scribejava.core.model.Verb; public class TheThingsNetworkV2PreviewApi extends DefaultApi20 { @@ -19,11 +15,6 @@ public static TheThingsNetworkV2PreviewApi instance() { return InstanceHolder.INSTANCE; } - @Override - public Verb getAccessTokenVerb() { - return Verb.POST; - } - @Override public String getAccessTokenEndpoint() { return "https://preview.account.thethingsnetwork.org/users/token"; @@ -33,9 +24,4 @@ public String getAccessTokenEndpoint() { protected String getAuthorizationBaseUrl() { return "https://preview.account.thethingsnetwork.org/users/authorize"; } - - @Override - public TokenExtractor getAccessTokenExtractor() { - return OAuth2AccessTokenJsonExtractor.instance(); - } } diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TTNV1Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV1StagingExample.java similarity index 97% rename from scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TTNV1Example.java rename to scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV1StagingExample.java index 155b9e999..0905fb441 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TTNV1Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV1StagingExample.java @@ -13,12 +13,12 @@ import java.util.Random; import java.util.Scanner; -public final class TTNV1Example { +public final class TheThingsNetworkV1StagingExample { private static final String NETWORK_NAME = "TTNv1staging"; private static final String PROTECTED_RESOURCE_URL = "https://account.thethingsnetwork.org/applications"; - private TTNV1Example() { + private TheThingsNetworkV1StagingExample() { } public static void main(String... args) throws IOException { diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TTNV2Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV2PreviewExample.java similarity index 97% rename from scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TTNV2Example.java rename to scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV2PreviewExample.java index 290f90905..ed7f2f6e7 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TTNV2Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV2PreviewExample.java @@ -12,13 +12,13 @@ import java.util.Random; import java.util.Scanner; -public final class TTNV2Example { +public final class TheThingsNetworkV2PreviewExample { private static final String NETWORK_NAME = "TTNv2preview"; private static final String PROTECTED_RESOURCE_URL = "https://preview.account.thethingsnetwork.org/api/v2/applications"; - private TTNV2Example() { + private TheThingsNetworkV2PreviewExample() { } public static void main(String... args) throws IOException { From 0533226b66093fcc71cf631c8f33b3c49683d206 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 8 Nov 2016 18:32:52 +0300 Subject: [PATCH 295/882] fix Box20Example API protected URL --- .../java/com/github/scribejava/apis/examples/Box20Example.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Box20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Box20Example.java index f22aa6883..731e0b217 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Box20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Box20Example.java @@ -16,7 +16,7 @@ public final class Box20Example { private static final String NETWORK_NAME = "Box"; - private static final String PROTECTED_RESOURCE_URL = "https://app.box.com/profile"; + private static final String PROTECTED_RESOURCE_URL = "https://api.box.com/2.0/users/me"; private Box20Example() { } From 6d4bf7d998513a9440ff2c5df508dfc0745c257a Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 8 Nov 2016 18:35:10 +0300 Subject: [PATCH 296/882] add Box API --- README.md | 1 + changelog | 1 + 2 files changed, 2 insertions(+) diff --git a/README.md b/README.md index 4dca5e9a8..619afd563 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,7 @@ You can use ning async http client 1.9.x or asynchttpclient 2.x out-of-box, just ### Supports all major 1.0a and 2.0 OAuth APIs out-of-the-box * AWeber (http://www.aweber.com/) +* Box (https://www.box.com/) * Digg (http://digg.com/) * Доктор на работе (http://www.doktornarabote.ru/) * Facebook (https://www.facebook.com/) diff --git a/changelog b/changelog index 998deef3f..4504d0cce 100644 --- a/changelog +++ b/changelog @@ -1,6 +1,7 @@ [SNAPSHOT] * 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) [3.2.0] * Add Naver API (thanks to chooco) From e9ec58f96917a7d742893f6e0fb07922ef2921b8 Mon Sep 17 00:00:00 2001 From: Vivin Paliath Date: Wed, 16 Nov 2016 16:02:32 -0700 Subject: [PATCH 297/882] issue #722 `OAuth20Service.refreshAccessToken` uses the correct URL by calling `api.getRefreshTokenEndpoint` instead of `api.getAccessTokenEndpoint`. --- .../java/com/github/scribejava/core/oauth/OAuth20Service.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java index a6ecc0019..550074c21 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 @@ -88,7 +88,7 @@ protected T createAccessTokenRequest(String code, T public final OAuth2AccessToken refreshAccessToken(String refreshToken) throws IOException { final OAuthRequest request = createRefreshTokenRequest(refreshToken, - new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint(), this)); + new OAuthRequest(api.getAccessTokenVerb(), api.getRefreshTokenEndpoint(), this)); return sendAccessTokenRequestSync(request); } From 2ec0701e6fff84c8ea9f0438aca956df12e2945d Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 17 Nov 2016 11:42:29 +0300 Subject: [PATCH 298/882] fix: OAuth20Service::refreshAccessToken should use RefreshTokenEndpoint, not AccessTokenEndpoint (thanks to https://github.com/vivin) --- changelog | 1 + 1 file changed, 1 insertion(+) diff --git a/changelog b/changelog index 4504d0cce..09542f689 100644 --- a/changelog +++ b/changelog @@ -2,6 +2,7 @@ * 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) [3.2.0] * Add Naver API (thanks to chooco) From 1736a9da5cc7a2c9a3eb8d6491e3425bf2d4bc60 Mon Sep 17 00:00:00 2001 From: Alexey Pomelov Date: Thu, 17 Nov 2016 15:19:20 +0200 Subject: [PATCH 299/882] Generify OAuthService with access token type --- .../com/github/scribejava/core/builder/ServiceBuilder.java | 2 +- .../com/github/scribejava/core/builder/api/BaseApi.java | 2 +- .../com/github/scribejava/core/model/AbstractRequest.java | 6 +++--- .../java/com/github/scribejava/core/model/OAuthRequest.java | 2 +- .../com/github/scribejava/core/model/OAuthRequestAsync.java | 4 ++-- .../com/github/scribejava/core/oauth/OAuth10aService.java | 3 ++- .../com/github/scribejava/core/oauth/OAuth20Service.java | 3 ++- .../java/com/github/scribejava/core/oauth/OAuthService.java | 6 +++++- .../scribejava/core/model/ForceTypeOfHttpRequestTest.java | 2 +- .../java/com/github/scribejava/core/model/RequestTest.java | 2 +- 10 files changed, 19 insertions(+), 13 deletions(-) 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 aa994d0a1..b45555f93 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 @@ -178,7 +178,7 @@ private OAuthConfig createConfig() { * @param api will build Service for this API * @return fully configured {@link S} */ - public S build(BaseApi api) { + public > S build(BaseApi api) { return api.createService(createConfig()); } } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/BaseApi.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/BaseApi.java index a42fe35fa..7f6fbdd4f 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/BaseApi.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/BaseApi.java @@ -3,7 +3,7 @@ import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.oauth.OAuthService; -public interface BaseApi { +public interface BaseApi> { T createService(OAuthConfig config); } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/AbstractRequest.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/AbstractRequest.java index 3c994c1d9..d163e2c6d 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/AbstractRequest.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/AbstractRequest.java @@ -25,7 +25,7 @@ public abstract class AbstractRequest { private final ParameterList bodyParams = new ParameterList(); private final Map headers = new HashMap<>(); private boolean followRedirects = true; - private final OAuthService service; + private final OAuthService service; private String payload; private String charset; @@ -41,7 +41,7 @@ public abstract class AbstractRequest { * @param url resource URL * @param service OAuthService */ - public AbstractRequest(Verb verb, String url, OAuthService service) { + public AbstractRequest(Verb verb, String url, OAuthService service) { this.verb = verb; this.url = url; this.service = service; @@ -285,7 +285,7 @@ public boolean isFollowRedirects() { return followRedirects; } - public OAuthService getService() { + public OAuthService getService() { return service; } } 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 fa7212a9e..b3986c5e8 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 @@ -12,7 +12,7 @@ public class OAuthRequest extends AbstractRequest { private HttpURLConnection connection; - public OAuthRequest(Verb verb, String url, OAuthService service) { + public OAuthRequest(Verb verb, String url, OAuthService service) { super(verb, url, service); } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequestAsync.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequestAsync.java index 1a92f0699..1de5f69b5 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequestAsync.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequestAsync.java @@ -8,7 +8,7 @@ public class OAuthRequestAsync extends AbstractRequest { - public OAuthRequestAsync(Verb verb, String url, OAuthService service) { + public OAuthRequestAsync(Verb verb, String url, OAuthService service) { super(verb, url, service); } @@ -17,7 +17,7 @@ public Future sendAsync(OAuthAsyncRequestCallback callback, ResponseCo if (ForceTypeOfHttpRequest.FORCE_SYNC_ONLY_HTTP_REQUESTS == forceTypeOfHttpRequest) { throw new OAuthException("Cannot use async operations, only sync"); } - final OAuthService service = getService(); + final OAuthService service = getService(); final OAuthConfig config = service.getConfig(); if (ForceTypeOfHttpRequest.PREFER_SYNC_ONLY_HTTP_REQUESTS == forceTypeOfHttpRequest) { config.log("Cannot use async operations, only sync"); 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 e1cc5bf5d..cbfa777f9 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 @@ -19,7 +19,7 @@ /** * OAuth 1.0a implementation of {@link OAuthService} */ -public class OAuth10aService extends OAuthService { +public class OAuth10aService extends OAuthService { private static final String VERSION = "1.0"; private final DefaultApi10a api; @@ -134,6 +134,7 @@ protected void prepareAccessTokenRequest(AbstractRequest request, OAuth1RequestT appendSignature(request); } + @Override public void signRequest(OAuth1AccessToken token, AbstractRequest request) { final OAuthConfig config = getConfig(); config.log("signing request: " + request.getCompleteUrl()); diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java index 550074c21..c59627844 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 @@ -16,7 +16,7 @@ import com.github.scribejava.core.model.Response; import java.util.Map; -public class OAuth20Service extends OAuthService { +public class OAuth20Service extends OAuthService { private static final String VERSION = "2.0"; private final DefaultApi20 api; @@ -169,6 +169,7 @@ public String getVersion() { return VERSION; } + @Override public void signRequest(OAuth2AccessToken accessToken, AbstractRequest request) { request.addQuerystringParameter(OAuthConstants.ACCESS_TOKEN, accessToken.getAccessToken()); } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java index 172ed26ff..40d0b707f 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java @@ -2,12 +2,14 @@ import com.github.scribejava.core.exceptions.OAuthException; import com.github.scribejava.core.httpclient.HttpClientProvider; +import com.github.scribejava.core.model.AbstractRequest; import com.github.scribejava.core.model.ForceTypeOfHttpRequest; import com.github.scribejava.core.model.HttpClient; import com.github.scribejava.core.model.OAuthAsyncRequestCallback; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthRequestAsync; import com.github.scribejava.core.model.ScribeJavaConfig; +import com.github.scribejava.core.model.Token; import com.github.scribejava.core.model.Verb; import java.io.IOException; @@ -20,7 +22,7 @@ * * A facade responsible for the retrieval of request and access tokens and for the signing of HTTP requests. */ -public abstract class OAuthService { +public abstract class OAuthService { private final OAuthConfig config; private final HttpClient httpClient; @@ -76,6 +78,8 @@ public OAuthConfig getConfig() { */ public abstract String getVersion(); + public abstract void signRequest(T token, AbstractRequest request); + public Future executeAsync(Map headers, Verb httpVerb, String completeUrl, String bodyContents, OAuthAsyncRequestCallback callback, OAuthRequestAsync.ResponseConverter converter) { diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/model/ForceTypeOfHttpRequestTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/model/ForceTypeOfHttpRequestTest.java index 9e60f3fb2..f6c6424b6 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/model/ForceTypeOfHttpRequestTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/model/ForceTypeOfHttpRequestTest.java @@ -20,7 +20,7 @@ public class ForceTypeOfHttpRequestTest { @Before public void setUp() { ScribeJavaConfig.setForceTypeOfHttpRequests(ForceTypeOfHttpRequest.NONE); - final OAuthService oAuthService = new OAuth20Service(null, new OAuthConfig("test", "test")); + final OAuthService oAuthService = new OAuth20Service(null, new OAuthConfig("test", "test")); request = new OAuthRequest(Verb.GET, "http://example.com?qsparam=value&other+param=value+with+spaces", oAuthService); requestAsync = new OAuthRequestAsync(Verb.GET, "http://example.com?qsparam=value&other+param=value+with+spaces", diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/model/RequestTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/model/RequestTest.java index 16b060000..cd2733926 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/model/RequestTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/model/RequestTest.java @@ -14,7 +14,7 @@ public class RequestTest { private OAuthRequest getRequest; private OAuthRequest postRequest; private ConnectionStub connection; - private OAuthService oAuthService; + private OAuthService oAuthService; @Before public void setUp() throws MalformedURLException { From 7ae74c391020e34b7b62ec763fd84dc49fc4f516 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 18 Nov 2016 17:08:13 +0300 Subject: [PATCH 300/882] move signRequest method to OAuthService (common for OAuth1 and OAuth2) (thanks to https://github.com/apomelov) --- changelog | 1 + 1 file changed, 1 insertion(+) diff --git a/changelog b/changelog index 09542f689..558f2742c 100644 --- a/changelog +++ b/changelog @@ -3,6 +3,7 @@ * 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) + * move signRequest method to OAuthService (common for OAuth1 and OAuth2) (thanks to https://github.com/apomelov) [3.2.0] * Add Naver API (thanks to chooco) From 1cfd31a909b52b0e6dbe31ac60a2bc5d1eb1c673 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 18 Nov 2016 17:12:54 +0300 Subject: [PATCH 301/882] update async-http-client --- scribejava-httpclient-ahc/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 3c4e95698..238c0fabd 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -23,7 +23,7 @@ org.asynchttpclient async-http-client - 2.0.21 + 2.0.24 From 4f59e5ee49ee131a0a1c2ed6ed1222beaa6cf105 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 18 Nov 2016 17:59:48 +0300 Subject: [PATCH 302/882] drop deprecated setConnectionKeepAlive method, add javadoc --- changelog | 1 + .../scribejava/core/model/AbstractRequest.java | 14 -------------- .../github/scribejava/core/oauth/OAuthService.java | 1 + 3 files changed, 2 insertions(+), 14 deletions(-) diff --git a/changelog b/changelog index 558f2742c..f83d1f745 100644 --- a/changelog +++ b/changelog @@ -4,6 +4,7 @@ * add Box (thanks to https://github.com/MclaughlinSteve) * 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 [3.2.0] * Add Naver API (thanks to chooco) diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/AbstractRequest.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/AbstractRequest.java index d163e2c6d..213ed4b34 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/AbstractRequest.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/AbstractRequest.java @@ -254,20 +254,6 @@ public void setCharset(String charsetName) { charset = charsetName; } - /** - * Sets whether the underlying Http Connection is persistent or not. - * - * @param connectionKeepAlive boolean - * - * @see http://download.oracle.com/javase/1.5.0/docs/guide/net/http-keepalive.html - * @deprecated does nothing - JVM default is left untouched. Set {@code http.keepAlive} system property to - * {@code false} for pre-deprecation behavior. - */ - @Deprecated - public void setConnectionKeepAlive(boolean connectionKeepAlive) { - } - /** * Sets whether the underlying Http Connection follows redirects or not. * diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java index 40d0b707f..dc52942be 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java @@ -21,6 +21,7 @@ * The main ScribeJava object. * * A facade responsible for the retrieval of request and access tokens and for the signing of HTTP requests. + * @param type of token used to sign the request */ public abstract class OAuthService { From feff31f16b46563ede25b8cb503bffcb3b6eb661 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 18 Nov 2016 18:01:57 +0300 Subject: [PATCH 303/882] prepare to release 3.3.0 --- README.md | 4 ++-- changelog | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 619afd563..5b185be1b 100644 --- a/README.md +++ b/README.md @@ -95,7 +95,7 @@ You can pull ScribeJava from the central maven repository, just add these to you com.github.scribejava scribejava-apis - 3.2.0 + 3.3.0 ``` @@ -104,7 +104,7 @@ And in case you need just core classes (that's it, without any external API (FB, com.github.scribejava scribejava-core - 3.2.0 + 3.3.0 ``` diff --git a/changelog b/changelog index f83d1f745..b07af8930 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,4 @@ -[SNAPSHOT] +[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) From d9cf3507ab26d3a13852b0f748861b47c0f789b3 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 18 Nov 2016 18:14:32 +0300 Subject: [PATCH 304/882] make releasing a bit easier --- pom.xml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pom.xml b/pom.xml index 71236d7af..992e6929d 100644 --- a/pom.xml +++ b/pom.xml @@ -134,6 +134,13 @@ + + maven-release-plugin + 2.5.3 + + true + + From f62ca3d64a98ff2f18d34ee789d1a2266e83f995 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 18 Nov 2016 18:15:31 +0300 Subject: [PATCH 305/882] [maven-release-plugin] prepare release scribejava-3.3.0 --- pom.xml | 5 +++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- 5 files changed, 7 insertions(+), 6 deletions(-) diff --git a/pom.xml b/pom.xml index 992e6929d..45e9d2ef3 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 3.2.1-SNAPSHOT + 3.3.0 ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -32,7 +32,8 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - + scribejava-3.3.0 + diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 8a95b9739..81e0765ae 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 3.2.1-SNAPSHOT + 3.3.0 ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index b8774fd58..f555e8038 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 3.2.1-SNAPSHOT + 3.3.0 ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 238c0fabd..db6a178e3 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 3.2.1-SNAPSHOT + 3.3.0 ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index 5602512ca..c9e6e54b3 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 3.2.1-SNAPSHOT + 3.3.0 ../pom.xml From d3042262335297b7af37f32ecebd7c4ad7649518 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 18 Nov 2016 18:16:10 +0300 Subject: [PATCH 306/882] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pom.xml b/pom.xml index 45e9d2ef3..e61816262 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 3.3.0 + 3.3.1-SNAPSHOT ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -32,7 +32,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - scribejava-3.3.0 + HEAD diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 81e0765ae..4b164db75 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 3.3.0 + 3.3.1-SNAPSHOT ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index f555e8038..8bffdd6fc 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 3.3.0 + 3.3.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index db6a178e3..0ccfc5f8d 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 3.3.0 + 3.3.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index c9e6e54b3..bd310a533 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 3.3.0 + 3.3.1-SNAPSHOT ../pom.xml From feca5d4ef938b076dc23d0dabbc15ef4a454171f Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 18 Nov 2016 18:23:00 +0300 Subject: [PATCH 307/882] Revert "[maven-release-plugin] prepare for next development iteration" This reverts commit d3042262335297b7af37f32ecebd7c4ad7649518. --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pom.xml b/pom.xml index e61816262..45e9d2ef3 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 3.3.1-SNAPSHOT + 3.3.0 ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -32,7 +32,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - HEAD + scribejava-3.3.0 diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 4b164db75..81e0765ae 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 3.3.1-SNAPSHOT + 3.3.0 ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 8bffdd6fc..f555e8038 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 3.3.1-SNAPSHOT + 3.3.0 ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 0ccfc5f8d..db6a178e3 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 3.3.1-SNAPSHOT + 3.3.0 ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index bd310a533..c9e6e54b3 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 3.3.1-SNAPSHOT + 3.3.0 ../pom.xml From 195e1eb1e2b38d933d8367a458a9473836f95093 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 18 Nov 2016 18:23:12 +0300 Subject: [PATCH 308/882] Revert "[maven-release-plugin] prepare release scribejava-3.3.0" This reverts commit f62ca3d64a98ff2f18d34ee789d1a2266e83f995. --- pom.xml | 5 ++--- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- 5 files changed, 6 insertions(+), 7 deletions(-) diff --git a/pom.xml b/pom.xml index 45e9d2ef3..992e6929d 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 3.3.0 + 3.2.1-SNAPSHOT ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -32,8 +32,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - scribejava-3.3.0 - + diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 81e0765ae..8a95b9739 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 3.3.0 + 3.2.1-SNAPSHOT ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index f555e8038..b8774fd58 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 3.3.0 + 3.2.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index db6a178e3..238c0fabd 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 3.3.0 + 3.2.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index c9e6e54b3..5602512ca 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 3.3.0 + 3.2.1-SNAPSHOT ../pom.xml From 0e85a499c0fe5b4de3f0f0057ac765b0431d8fdd Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 18 Nov 2016 18:24:37 +0300 Subject: [PATCH 309/882] [maven-release-plugin] prepare release scribejava-3.3.0 --- pom.xml | 5 +++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- 5 files changed, 7 insertions(+), 6 deletions(-) diff --git a/pom.xml b/pom.xml index 992e6929d..45e9d2ef3 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 3.2.1-SNAPSHOT + 3.3.0 ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -32,7 +32,8 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - + scribejava-3.3.0 + diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 8a95b9739..81e0765ae 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 3.2.1-SNAPSHOT + 3.3.0 ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index b8774fd58..f555e8038 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 3.2.1-SNAPSHOT + 3.3.0 ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 238c0fabd..db6a178e3 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 3.2.1-SNAPSHOT + 3.3.0 ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index 5602512ca..c9e6e54b3 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 3.2.1-SNAPSHOT + 3.3.0 ../pom.xml From ab828cf5b9590685226a373c4aff397aadf8437d Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 18 Nov 2016 18:24:43 +0300 Subject: [PATCH 310/882] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pom.xml b/pom.xml index 45e9d2ef3..e61816262 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 3.3.0 + 3.3.1-SNAPSHOT ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -32,7 +32,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - scribejava-3.3.0 + HEAD diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 81e0765ae..4b164db75 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 3.3.0 + 3.3.1-SNAPSHOT ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index f555e8038..8bffdd6fc 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 3.3.0 + 3.3.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index db6a178e3..0ccfc5f8d 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 3.3.0 + 3.3.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index c9e6e54b3..bd310a533 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 3.3.0 + 3.3.1-SNAPSHOT ../pom.xml From 40c480919262c3753623d0e284aa3a0a34d08b4e Mon Sep 17 00:00:00 2001 From: Arcao Date: Tue, 29 Nov 2016 00:18:21 +0100 Subject: [PATCH 311/882] Support for okhttp #689 --- pom.xml | 1 + scribejava-apis/pom.xml | 6 ++ .../examples/GitHubAsyncOkHttpExample.java | 87 +++++++++++++++ scribejava-httpclient-okhttp/pom.xml | 42 ++++++++ .../okhttp/OAuthAsyncCompletionHandler.java | 101 ++++++++++++++++++ .../httpclient/okhttp/OkHttpHttpClient.java | 69 ++++++++++++ .../okhttp/OkHttpHttpClientConfig.java | 17 +++ .../httpclient/okhttp/OkHttpProvider.java | 15 +++ ...ibejava.core.httpclient.HttpClientProvider | 1 + 9 files changed, 339 insertions(+) create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubAsyncOkHttpExample.java create mode 100644 scribejava-httpclient-okhttp/pom.xml create mode 100644 scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OAuthAsyncCompletionHandler.java create mode 100644 scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java create mode 100644 scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClientConfig.java create mode 100644 scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpProvider.java create mode 100644 scribejava-httpclient-okhttp/src/main/resources/META-INF/services/com.github.scribejava.core.httpclient.HttpClientProvider diff --git a/pom.xml b/pom.xml index e61816262..f6c4aa233 100644 --- a/pom.xml +++ b/pom.xml @@ -19,6 +19,7 @@ scribejava-apis scribejava-httpclient-ahc scribejava-httpclient-ning + scribejava-httpclient-okhttp diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 4b164db75..bc6f2dbd3 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -32,6 +32,12 @@ ${project.version} test + + com.github.scribejava + scribejava-httpclient-okhttp + ${project.version} + test + diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubAsyncOkHttpExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubAsyncOkHttpExample.java new file mode 100644 index 000000000..c0e4e6859 --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubAsyncOkHttpExample.java @@ -0,0 +1,87 @@ +package com.github.scribejava.apis.examples; + +import com.github.scribejava.apis.GitHubApi; +import com.github.scribejava.core.builder.ServiceBuilder; +import com.github.scribejava.core.model.OAuth2AccessToken; +import com.github.scribejava.core.model.OAuthRequestAsync; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.oauth.OAuth20Service; +import com.github.scribejava.httpclient.okhttp.OkHttpHttpClient; +import okhttp3.OkHttpClient; + +import java.io.IOException; +import java.util.Random; +import java.util.Scanner; +import java.util.concurrent.ExecutionException; + +public final class GitHubAsyncOkHttpExample { + + private static final String NETWORK_NAME = "GitHub"; + private static final String PROTECTED_RESOURCE_URL = "https://api.github.com/user"; + + private GitHubAsyncOkHttpExample() { + } + + public static void main(String... args) throws IOException, ExecutionException, InterruptedException { + // Replace these with your client id and secret + final String clientId = "your client id"; + final String clientSecret = "your client secret"; + final String secretState = "secret" + new Random().nextInt(999_999); + final OAuth20Service service = new ServiceBuilder() + .apiKey(clientId) + .apiSecret(clientSecret) + .state(secretState) + .callback("http://www.example.com/oauth_callback/") + .httpClient(new OkHttpHttpClient(new OkHttpClient())) + .build(GitHubApi.instance()); + final Scanner in = new Scanner(System.in, "UTF-8"); + + System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); + System.out.println(); + + // Obtain the Authorization URL + System.out.println("Fetching the Authorization URL..."); + final String authorizationUrl = service.getAuthorizationUrl(); + System.out.println("Got the Authorization URL!"); + System.out.println("Now go and authorize ScribeJava here:"); + System.out.println(authorizationUrl); + System.out.println("And paste the authorization code here"); + System.out.print(">>"); + final String code = in.nextLine(); + System.out.println(); + + System.out.println("And paste the state from server here. We have set 'secretState'='" + secretState + "'."); + System.out.print(">>"); + final String value = in.nextLine(); + if (secretState.equals(value)) { + System.out.println("State value does match!"); + } else { + System.out.println("Ooops, state value does not match!"); + System.out.println("Expected = " + secretState); + System.out.println("Got = " + value); + System.out.println(); + } + + // Trade the Request Token and Verfier for the Access Token + System.out.println("Trading the Request Token for an Access Token..."); + final OAuth2AccessToken accessToken = service.getAccessTokenAsync(code, null).get(); + System.out.println("Got the Access Token!"); + System.out.println("(if your curious it looks like this: " + accessToken + + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println(); + + // Now let's go and ask for a protected resource! + System.out.println("Now we're going to access a protected resource..."); + final OAuthRequestAsync request = new OAuthRequestAsync(Verb.GET, PROTECTED_RESOURCE_URL, service); + service.signRequest(accessToken, request); + final Response response = request.sendAsync(null).get(); + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + + System.out.println(); + System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); + } +} diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml new file mode 100644 index 000000000..4536b87de --- /dev/null +++ b/scribejava-httpclient-okhttp/pom.xml @@ -0,0 +1,42 @@ + + + 4.0.0 + + + com.github.scribejava + scribejava + 3.3.1-SNAPSHOT + ../pom.xml + + + com.github.scribejava + scribejava-httpclient-okhttp + ScribeJava OkHttp Client support + jar + + + + com.github.scribejava + scribejava-core + ${project.version} + + + com.squareup.okhttp3 + okhttp + 3.4.2 + + + + + + + org.apache.felix + maven-bundle-plugin + + + org.apache.maven.plugins + maven-jar-plugin + + + + diff --git a/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OAuthAsyncCompletionHandler.java b/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OAuthAsyncCompletionHandler.java new file mode 100644 index 000000000..bde6870e8 --- /dev/null +++ b/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OAuthAsyncCompletionHandler.java @@ -0,0 +1,101 @@ +package com.github.scribejava.httpclient.okhttp; + +import com.github.scribejava.core.model.OAuthAsyncRequestCallback; +import com.github.scribejava.core.model.OAuthRequestAsync; +import com.github.scribejava.core.model.Response; +import okhttp3.Call; +import okhttp3.Callback; +import okhttp3.Headers; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; + +class OAuthAsyncCompletionHandler implements Callback, Future { + + private final OAuthAsyncRequestCallback callback; + private final OAuthRequestAsync.ResponseConverter converter; + private final Call call; + private final CountDownLatch latch; + private T result; + + OAuthAsyncCompletionHandler(OAuthAsyncRequestCallback callback, + OAuthRequestAsync.ResponseConverter converter, Call call) { + this.callback = callback; + this.converter = converter; + this.call = call; + this.latch = new CountDownLatch(1); + + call.enqueue(this); + } + + @Override + public void onFailure(Call call, IOException e) { + try { + if (callback != null) { + callback.onThrowable(e); + } + } finally { + latch.countDown(); + } + } + + @Override + public void onResponse(Call call, okhttp3.Response okHttpResponse) throws IOException { + try { + final Headers headers = okHttpResponse.headers(); + final Map headersMap = new HashMap<>(); + + for (String name : headers.names()) { + headersMap.put(name, headers.get(name)); + } + + final Response response = new Response(okHttpResponse.code(), + okHttpResponse.message(), + headersMap, + okHttpResponse.body().string(), + null); // cannot return both body String and InputStream + + @SuppressWarnings("unchecked") + final T t = result = converter == null ? (T) response : converter.convert(response); + if (callback != null) { + callback.onCompleted(t); + } + } finally { + latch.countDown(); + } + } + + @Override + public boolean cancel(boolean mayInterruptIfRunning) { + call.cancel(); + return call.isCanceled(); + } + + @Override + public boolean isCancelled() { + return call.isCanceled(); + } + + @Override + public boolean isDone() { + return call.isExecuted(); + } + + @Override + public T get() throws InterruptedException, ExecutionException { + latch.await(); + return result; + } + + @Override + public T get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { + latch.await(timeout, unit); + return result; + } +} diff --git a/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java b/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java new file mode 100644 index 000000000..452d54f62 --- /dev/null +++ b/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java @@ -0,0 +1,69 @@ +package com.github.scribejava.httpclient.okhttp; + +import com.github.scribejava.core.model.AbstractRequest; +import com.github.scribejava.core.model.HttpClient; +import com.github.scribejava.core.model.OAuthAsyncRequestCallback; +import com.github.scribejava.core.model.OAuthConstants; +import com.github.scribejava.core.model.OAuthRequestAsync; +import com.github.scribejava.core.model.Verb; +import okhttp3.Call; +import okhttp3.MediaType; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.RequestBody; + +import java.io.IOException; +import java.util.Map; +import java.util.concurrent.Future; + +import static com.github.scribejava.core.model.AbstractRequest.DEFAULT_CONTENT_TYPE; + +public class OkHttpHttpClient implements HttpClient { + + private final OkHttpClient client; + + public OkHttpHttpClient(OkHttpHttpClientConfig config) { + client = config.getClient(); + } + + public OkHttpHttpClient(OkHttpClient client) { + this.client = client; + } + + @Override + public void close() throws IOException { + //client.close(); + } + + @Override + public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, + String bodyContents, OAuthAsyncRequestCallback callback, + OAuthRequestAsync.ResponseConverter converter) { + final Request.Builder requestBuilder = new Request.Builder(); + requestBuilder.url(completeUrl); + + switch (httpVerb) { + case GET: + requestBuilder.get(); + break; + case POST: + String contentType = headers.containsKey(AbstractRequest.CONTENT_TYPE) ? + headers.get(AbstractRequest.CONTENT_TYPE) : DEFAULT_CONTENT_TYPE; + + requestBuilder.post(RequestBody.create(MediaType.parse(contentType), bodyContents)); + break; + default: + throw new IllegalArgumentException("message build error: unknown verb type"); + } + + for (Map.Entry header : headers.entrySet()) { + requestBuilder.addHeader(header.getKey(), header.getValue()); + } + if (userAgent != null) { + requestBuilder.header(OAuthConstants.USER_AGENT_HEADER_NAME, userAgent); + } + + final Call call = client.newCall(requestBuilder.build()); + return new OAuthAsyncCompletionHandler<>(callback, converter, call); + } +} diff --git a/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClientConfig.java b/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClientConfig.java new file mode 100644 index 000000000..b5acae110 --- /dev/null +++ b/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClientConfig.java @@ -0,0 +1,17 @@ +package com.github.scribejava.httpclient.okhttp; + +import com.github.scribejava.core.model.HttpClient; +import okhttp3.OkHttpClient; + +public class OkHttpHttpClientConfig implements HttpClient.Config { + + private final OkHttpClient client; + + public OkHttpHttpClientConfig(OkHttpClient client) { + this.client = client; + } + + public OkHttpClient getClient() { + return client; + } +} diff --git a/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpProvider.java b/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpProvider.java new file mode 100644 index 000000000..3dbfcba5d --- /dev/null +++ b/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpProvider.java @@ -0,0 +1,15 @@ +package com.github.scribejava.httpclient.okhttp; + +import com.github.scribejava.core.httpclient.HttpClientProvider; +import com.github.scribejava.core.model.HttpClient; + +public class OkHttpProvider implements HttpClientProvider { + + @Override + public HttpClient createClient(HttpClient.Config config) { + if (config instanceof OkHttpHttpClientConfig) { + return new OkHttpHttpClient((OkHttpHttpClientConfig) config); + } + return null; + } +} diff --git a/scribejava-httpclient-okhttp/src/main/resources/META-INF/services/com.github.scribejava.core.httpclient.HttpClientProvider b/scribejava-httpclient-okhttp/src/main/resources/META-INF/services/com.github.scribejava.core.httpclient.HttpClientProvider new file mode 100644 index 000000000..46afa18ed --- /dev/null +++ b/scribejava-httpclient-okhttp/src/main/resources/META-INF/services/com.github.scribejava.core.httpclient.HttpClientProvider @@ -0,0 +1 @@ +com.github.scribejava.httpclient.okhttp.OkHttpProvider From e74c194bc46873ce13335bd5fa450c6d749bfedd Mon Sep 17 00:00:00 2001 From: Arcao Date: Tue, 29 Nov 2016 00:38:01 +0100 Subject: [PATCH 312/882] Fixed Checkstyle errors --- .../httpclient/okhttp/OAuthAsyncCompletionHandler.java | 3 ++- .../github/scribejava/httpclient/okhttp/OkHttpHttpClient.java | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OAuthAsyncCompletionHandler.java b/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OAuthAsyncCompletionHandler.java index bde6870e8..94836543b 100644 --- a/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OAuthAsyncCompletionHandler.java +++ b/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OAuthAsyncCompletionHandler.java @@ -62,7 +62,8 @@ public void onResponse(Call call, okhttp3.Response okHttpResponse) throws IOExce null); // cannot return both body String and InputStream @SuppressWarnings("unchecked") - final T t = result = converter == null ? (T) response : converter.convert(response); + final T t = converter == null ? (T) response : converter.convert(response); + result = t; if (callback != null) { callback.onCompleted(t); } diff --git a/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java b/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java index 452d54f62..30dfe8759 100644 --- a/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java +++ b/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java @@ -47,8 +47,8 @@ public Future executeAsync(String userAgent, Map headers, requestBuilder.get(); break; case POST: - String contentType = headers.containsKey(AbstractRequest.CONTENT_TYPE) ? - headers.get(AbstractRequest.CONTENT_TYPE) : DEFAULT_CONTENT_TYPE; + final String contentType = headers.containsKey(AbstractRequest.CONTENT_TYPE) ? + headers.get(AbstractRequest.CONTENT_TYPE) : DEFAULT_CONTENT_TYPE; requestBuilder.post(RequestBody.create(MediaType.parse(contentType), bodyContents)); break; From 3a8d4f6c68dbce35bf71d88aed9fc74431b703a4 Mon Sep 17 00:00:00 2001 From: Arcao Date: Tue, 29 Nov 2016 00:39:22 +0100 Subject: [PATCH 313/882] Minor change in pom artifact name --- scribejava-httpclient-okhttp/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 4536b87de..07d6a6df1 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -11,7 +11,7 @@ com.github.scribejava scribejava-httpclient-okhttp - ScribeJava OkHttp Client support + ScribeJava Async OkHttp Client support jar From 6f21f1563788b8d14569cb33981350a3f08bc7d5 Mon Sep 17 00:00:00 2001 From: Arcao Date: Tue, 29 Nov 2016 10:07:24 +0100 Subject: [PATCH 314/882] Support for more HTTP methods --- .../httpclient/okhttp/OkHttpHttpClient.java | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java b/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java index 30dfe8759..cad3f641a 100644 --- a/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java +++ b/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java @@ -11,6 +11,7 @@ import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; +import okhttp3.internal.http.HttpMethod; import java.io.IOException; import java.util.Map; @@ -42,20 +43,20 @@ public Future executeAsync(String userAgent, Map headers, final Request.Builder requestBuilder = new Request.Builder(); requestBuilder.url(completeUrl); - switch (httpVerb) { - case GET: - requestBuilder.get(); - break; - case POST: - final String contentType = headers.containsKey(AbstractRequest.CONTENT_TYPE) ? - headers.get(AbstractRequest.CONTENT_TYPE) : DEFAULT_CONTENT_TYPE; + final String method = httpVerb.name(); - requestBuilder.post(RequestBody.create(MediaType.parse(contentType), bodyContents)); - break; - default: - throw new IllegalArgumentException("message build error: unknown verb type"); + // prepare body + RequestBody body = null; + if (bodyContents != null && !bodyContents.isEmpty() && HttpMethod.permitsRequestBody(method)) { + final String contentType = headers.containsKey(AbstractRequest.CONTENT_TYPE) ? + headers.get(AbstractRequest.CONTENT_TYPE) : DEFAULT_CONTENT_TYPE; + body = RequestBody.create(MediaType.parse(contentType), bodyContents); } + // fill HTTP method and body + requestBuilder.method(method, body); + + // fill headers for (Map.Entry header : headers.entrySet()) { requestBuilder.addHeader(header.getKey(), header.getValue()); } @@ -63,6 +64,7 @@ public Future executeAsync(String userAgent, Map headers, requestBuilder.header(OAuthConstants.USER_AGENT_HEADER_NAME, userAgent); } + // create a new call final Call call = client.newCall(requestBuilder.build()); return new OAuthAsyncCompletionHandler<>(callback, converter, call); } From 9787c7df70ed1b248fec22639931db91253f580a Mon Sep 17 00:00:00 2001 From: Arcao Date: Tue, 29 Nov 2016 11:19:00 +0100 Subject: [PATCH 315/882] Added tests, fixed empty body error --- scribejava-httpclient-okhttp/pom.xml | 6 ++ .../httpclient/okhttp/OkHttpHttpClient.java | 2 +- .../okhttp/OkHttpHttpClientTest.java | 87 +++++++++++++++++++ 3 files changed, 94 insertions(+), 1 deletion(-) create mode 100644 scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClientTest.java diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 07d6a6df1..b1b0a7a3d 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -25,6 +25,12 @@ okhttp 3.4.2 + + com.squareup.okhttp3 + mockwebserver + 3.4.2 + test + diff --git a/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java b/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java index cad3f641a..57f90ca5f 100644 --- a/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java +++ b/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java @@ -47,7 +47,7 @@ public Future executeAsync(String userAgent, Map headers, // prepare body RequestBody body = null; - if (bodyContents != null && !bodyContents.isEmpty() && HttpMethod.permitsRequestBody(method)) { + if (bodyContents != null && HttpMethod.permitsRequestBody(method)) { final String contentType = headers.containsKey(AbstractRequest.CONTENT_TYPE) ? headers.get(AbstractRequest.CONTENT_TYPE) : DEFAULT_CONTENT_TYPE; body = RequestBody.create(MediaType.parse(contentType), bodyContents); diff --git a/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClientTest.java b/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClientTest.java new file mode 100644 index 000000000..c0d986eae --- /dev/null +++ b/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClientTest.java @@ -0,0 +1,87 @@ +package com.github.scribejava.httpclient.okhttp; + +import com.github.scribejava.core.model.*; +import com.github.scribejava.core.oauth.OAuth20Service; +import com.github.scribejava.core.oauth.OAuthService; +import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; +import okhttp3.mockwebserver.MockResponse; +import okhttp3.mockwebserver.MockWebServer; +import okhttp3.mockwebserver.RecordedRequest; +import org.junit.Before; +import org.junit.Test; + +import java.net.MalformedURLException; +import java.util.concurrent.TimeUnit; + +import static org.junit.Assert.assertEquals; + +public class OkHttpHttpClientTest { + private OAuthService oAuthService; + + @Before + public void setUp() throws MalformedURLException { + HttpClient client = new OkHttpHttpClient(new OkHttpClient()); + oAuthService = new OAuth20Service(null, + new OAuthConfig("test", "test", null, null, null, null, null, null, null, null, null, null, client)); + } + + + @Test + public void shouldSendGetRequest() throws Exception { + String expectedResponseBody = "response body"; + + MockWebServer server = new MockWebServer(); + server.enqueue(new MockResponse().setBody(expectedResponseBody)); + server.start(); + + HttpUrl baseUrl = server.url("/testUrl"); + + OAuthRequestAsync request = new OAuthRequestAsync(Verb.GET, baseUrl.toString(), oAuthService); + Response response = request.sendAsync(null).get(30, TimeUnit.SECONDS); + + assertEquals(expectedResponseBody, response.getBody()); + + RecordedRequest recordedRequest = server.takeRequest(); + assertEquals("GET", recordedRequest.getMethod()); + + server.shutdown(); + } + + @Test + public void shouldSendPostRequest() throws Exception { + String expectedResponseBody = "response body"; + String expectedRequestBody = "request body"; + + MockWebServer server = new MockWebServer(); + server.enqueue(new MockResponse().setBody(expectedResponseBody)); + server.enqueue(new MockResponse().setBody(expectedResponseBody)); + server.start(); + + HttpUrl baseUrl = server.url("/testUrl"); + + // request with body + OAuthRequestAsync request = new OAuthRequestAsync(Verb.POST, baseUrl.toString(), oAuthService); + request.addPayload(expectedRequestBody); + Response response = request.sendAsync(null).get(30, TimeUnit.SECONDS); + + assertEquals(expectedResponseBody, response.getBody()); + + RecordedRequest recordedRequest = server.takeRequest(); + assertEquals("POST", recordedRequest.getMethod()); + assertEquals(expectedRequestBody, recordedRequest.getBody().readUtf8()); + + + // request with empty body + request = new OAuthRequestAsync(Verb.POST, baseUrl.toString(), oAuthService); + response = request.sendAsync(null).get(30, TimeUnit.SECONDS); + + assertEquals(expectedResponseBody, response.getBody()); + + recordedRequest = server.takeRequest(); + assertEquals("POST", recordedRequest.getMethod()); + assertEquals("", recordedRequest.getBody().readUtf8()); + + server.shutdown(); + } +} From 9bc1ff892fb82029613c852cc0b42c925c2279f9 Mon Sep 17 00:00:00 2001 From: Arcao Date: Tue, 29 Nov 2016 12:09:20 +0100 Subject: [PATCH 316/882] Fixed not working Response.getStream method --- .../okhttp/OAuthAsyncCompletionHandler.java | 4 +-- .../okhttp/OkHttpHttpClientTest.java | 28 ++++++++++++++++++- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OAuthAsyncCompletionHandler.java b/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OAuthAsyncCompletionHandler.java index 94836543b..9ae280c88 100644 --- a/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OAuthAsyncCompletionHandler.java +++ b/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OAuthAsyncCompletionHandler.java @@ -58,8 +58,8 @@ public void onResponse(Call call, okhttp3.Response okHttpResponse) throws IOExce final Response response = new Response(okHttpResponse.code(), okHttpResponse.message(), headersMap, - okHttpResponse.body().string(), - null); // cannot return both body String and InputStream + null, // cannot return both body String and InputStream + okHttpResponse.body().byteStream()); @SuppressWarnings("unchecked") final T t = converter == null ? (T) response : converter.convert(response); diff --git a/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClientTest.java b/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClientTest.java index c0d986eae..527321f48 100644 --- a/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClientTest.java +++ b/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClientTest.java @@ -1,8 +1,13 @@ package com.github.scribejava.httpclient.okhttp; -import com.github.scribejava.core.model.*; +import com.github.scribejava.core.model.HttpClient; +import com.github.scribejava.core.model.OAuthConfig; +import com.github.scribejava.core.model.OAuthRequestAsync; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.oauth.OAuth20Service; import com.github.scribejava.core.oauth.OAuthService; +import com.github.scribejava.core.utils.StreamUtils; import okhttp3.HttpUrl; import okhttp3.OkHttpClient; import okhttp3.mockwebserver.MockResponse; @@ -84,4 +89,25 @@ public void shouldSendPostRequest() throws Exception { server.shutdown(); } + + @Test + public void shouldReadResponseStream() throws Exception { + String expectedResponseBody = "response body"; + + MockWebServer server = new MockWebServer(); + server.enqueue(new MockResponse().setBody(expectedResponseBody)); + server.start(); + + HttpUrl baseUrl = server.url("/testUrl"); + + OAuthRequestAsync request = new OAuthRequestAsync(Verb.GET, baseUrl.toString(), oAuthService); + Response response = request.sendAsync(null).get(30, TimeUnit.SECONDS); + + assertEquals(expectedResponseBody, StreamUtils.getStreamContents(response.getStream())); + + RecordedRequest recordedRequest = server.takeRequest(); + assertEquals("GET", recordedRequest.getMethod()); + + server.shutdown(); + } } From fa96ffb331ec258df4d839a0ae3367b39956590b Mon Sep 17 00:00:00 2001 From: Arcao Date: Tue, 29 Nov 2016 12:18:51 +0100 Subject: [PATCH 317/882] Fixed Checkstyle errors --- .../okhttp/OkHttpHttpClientTest.java | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClientTest.java b/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClientTest.java index 527321f48..b1968dcb3 100644 --- a/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClientTest.java +++ b/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClientTest.java @@ -26,7 +26,7 @@ public class OkHttpHttpClientTest { @Before public void setUp() throws MalformedURLException { - HttpClient client = new OkHttpHttpClient(new OkHttpClient()); + final HttpClient client = new OkHttpHttpClient(new OkHttpClient()); oAuthService = new OAuth20Service(null, new OAuthConfig("test", "test", null, null, null, null, null, null, null, null, null, null, client)); } @@ -34,20 +34,20 @@ public void setUp() throws MalformedURLException { @Test public void shouldSendGetRequest() throws Exception { - String expectedResponseBody = "response body"; + final String expectedResponseBody = "response body"; - MockWebServer server = new MockWebServer(); + final MockWebServer server = new MockWebServer(); server.enqueue(new MockResponse().setBody(expectedResponseBody)); server.start(); - HttpUrl baseUrl = server.url("/testUrl"); + final HttpUrl baseUrl = server.url("/testUrl"); - OAuthRequestAsync request = new OAuthRequestAsync(Verb.GET, baseUrl.toString(), oAuthService); - Response response = request.sendAsync(null).get(30, TimeUnit.SECONDS); + final OAuthRequestAsync request = new OAuthRequestAsync(Verb.GET, baseUrl.toString(), oAuthService); + final Response response = request.sendAsync(null).get(30, TimeUnit.SECONDS); assertEquals(expectedResponseBody, response.getBody()); - RecordedRequest recordedRequest = server.takeRequest(); + final RecordedRequest recordedRequest = server.takeRequest(); assertEquals("GET", recordedRequest.getMethod()); server.shutdown(); @@ -55,15 +55,15 @@ public void shouldSendGetRequest() throws Exception { @Test public void shouldSendPostRequest() throws Exception { - String expectedResponseBody = "response body"; - String expectedRequestBody = "request body"; + final String expectedResponseBody = "response body"; + final String expectedRequestBody = "request body"; - MockWebServer server = new MockWebServer(); + final MockWebServer server = new MockWebServer(); server.enqueue(new MockResponse().setBody(expectedResponseBody)); server.enqueue(new MockResponse().setBody(expectedResponseBody)); server.start(); - HttpUrl baseUrl = server.url("/testUrl"); + final HttpUrl baseUrl = server.url("/testUrl"); // request with body OAuthRequestAsync request = new OAuthRequestAsync(Verb.POST, baseUrl.toString(), oAuthService); @@ -92,20 +92,20 @@ public void shouldSendPostRequest() throws Exception { @Test public void shouldReadResponseStream() throws Exception { - String expectedResponseBody = "response body"; + final String expectedResponseBody = "response body"; - MockWebServer server = new MockWebServer(); + final MockWebServer server = new MockWebServer(); server.enqueue(new MockResponse().setBody(expectedResponseBody)); server.start(); - HttpUrl baseUrl = server.url("/testUrl"); + final HttpUrl baseUrl = server.url("/testUrl"); - OAuthRequestAsync request = new OAuthRequestAsync(Verb.GET, baseUrl.toString(), oAuthService); - Response response = request.sendAsync(null).get(30, TimeUnit.SECONDS); + final OAuthRequestAsync request = new OAuthRequestAsync(Verb.GET, baseUrl.toString(), oAuthService); + final Response response = request.sendAsync(null).get(30, TimeUnit.SECONDS); assertEquals(expectedResponseBody, StreamUtils.getStreamContents(response.getStream())); - RecordedRequest recordedRequest = server.takeRequest(); + final RecordedRequest recordedRequest = server.takeRequest(); assertEquals("GET", recordedRequest.getMethod()); server.shutdown(); From 36c33b6001fd34a0fedc3e4df901e352aa780949 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 7 Dec 2016 16:04:48 +0300 Subject: [PATCH 318/882] uncouple OAuthRequest and Service --- changelog | 4 ++ .../apis/examples/AWeberExample.java | 2 +- .../apis/examples/Box20Example.java | 2 +- .../scribejava/apis/examples/DiggExample.java | 2 +- .../examples/FacebookAsyncNingExample.java | 4 +- .../apis/examples/FacebookExample.java | 2 +- .../apis/examples/FlickrExample.java | 2 +- .../apis/examples/Foursquare2Example.java | 2 +- .../apis/examples/FoursquareExample.java | 2 +- .../apis/examples/FreelancerExample.java | 2 +- .../apis/examples/GeniusExample.java | 2 +- .../apis/examples/GitHubExample.java | 2 +- .../examples/Google20AsyncAHCExample.java | 4 +- .../apis/examples/Google20Example.java | 2 +- .../scribejava/apis/examples/HHExample.java | 2 +- .../apis/examples/ImgurExample.java | 2 +- .../apis/examples/Kaixin20Example.java | 2 +- .../apis/examples/LinkedIn20Example.java | 2 +- .../apis/examples/LinkedInExample.java | 2 +- .../examples/LinkedInExampleWithScopes.java | 2 +- .../scribejava/apis/examples/LiveExample.java | 2 +- .../apis/examples/MailruAsyncExample.java | 4 +- .../apis/examples/MailruExample.java | 2 +- .../apis/examples/MeetupExample.java | 2 +- .../apis/examples/MisfitExample.java | 2 +- .../apis/examples/NaverExample.java | 2 +- .../apis/examples/NeteaseWeiboExample.java | 2 +- .../apis/examples/OdnoklassnikiExample.java | 2 +- .../apis/examples/PinterestExample.java | 2 +- .../apis/examples/Px500Example.java | 2 +- .../apis/examples/RenrenExample.java | 2 +- .../apis/examples/SalesforceExample.java | 2 +- .../examples/SalesforceNingAsyncExample.java | 4 +- .../apis/examples/SinaWeibo2Example.java | 2 +- .../apis/examples/SinaWeiboExample.java | 2 +- .../apis/examples/SkyrockExample.java | 2 +- .../apis/examples/SohuWeiboExample.java | 2 +- .../apis/examples/StackExchangeExample.java | 2 +- .../TheThingsNetworkV1StagingExample.java | 2 +- .../TheThingsNetworkV2PreviewExample.java | 2 +- .../apis/examples/TrelloExample.java | 2 +- .../apis/examples/TumblrExample.java | 2 +- .../apis/examples/TutByExample.java | 2 +- .../apis/examples/TwitterExample.java | 2 +- .../apis/examples/ViadeoExample.java | 2 +- .../apis/examples/VkontakteExample.java | 2 +- .../VkontakteExternalHttpExample.java | 4 +- .../scribejava/apis/examples/XingExample.java | 2 +- .../apis/examples/YahooExample.java | 2 +- .../service/OdnoklassnikiServiceTest.java | 2 +- .../core/model/AbstractRequest.java | 23 ++++++- .../scribejava/core/model/OAuthRequest.java | 25 ++++++-- .../core/model/OAuthRequestAsync.java | 49 ++++++++++----- .../core/oauth/OAuth10aService.java | 13 ++-- .../scribejava/core/oauth/OAuth20Service.java | 14 ++--- .../scribejava/core/oauth/OAuthService.java | 61 ++++++++++++++++++- .../github/scribejava/core/ObjectMother.java | 14 ++--- .../extractors/BaseStringExtractorTest.java | 4 +- .../core/extractors/HeaderExtractorTest.java | 3 +- .../model/ForceTypeOfHttpRequestTest.java | 14 +++-- .../core/model/OAuthRequestTest.java | 4 +- .../scribejava/core/model/RequestTest.java | 14 ++--- 62 files changed, 229 insertions(+), 121 deletions(-) diff --git a/changelog b/changelog index b07af8930..01d43cbb0 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,7 @@ +[SNAPSHOT] + * uncouple OAuthRequest and Service. OAuthRequest shouldn't know anything about OAuthservice. + You don't need OAuthService to create OAuthRequest anymore. Async request should be sent via OAuthService method. + [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) diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AWeberExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AWeberExample.java index 19a5f5b1f..60bce4f71 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AWeberExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AWeberExample.java @@ -56,7 +56,7 @@ public static void main(String... args) throws IOException { // 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, ACCOUNT_RESOURCE_URL, service); + final OAuthRequest request = new OAuthRequest(Verb.GET, ACCOUNT_RESOURCE_URL, service.getConfig()); service.signRequest(accessToken, request); final Response response = request.send(); System.out.println("Got it! Lets see what we found..."); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Box20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Box20Example.java index 731e0b217..af58ab9cc 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Box20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Box20Example.java @@ -76,7 +76,7 @@ public static void main(String... args) throws IOException { // 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); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service.getConfig()); service.signRequest(accessToken, request); final Response response = request.send(); System.out.println("Got it! Lets see what we found..."); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiggExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiggExample.java index 0e81446bb..238d6c1dc 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiggExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiggExample.java @@ -59,7 +59,7 @@ public static void main(String... args) throws IOException { // 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.POST, PROTECTED_RESOURCE_URL, service); + final OAuthRequest request = new OAuthRequest(Verb.POST, PROTECTED_RESOURCE_URL, service.getConfig()); request.addBodyParameter("comment_id", "20100729223726:4fef610331ee46a3b5cbd740bf71313e"); service.signRequest(accessToken, request); final Response response = request.send(); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java index ce0aab781..23f1dcba1 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java @@ -84,9 +84,9 @@ public static void main(String... args) throws InterruptedException, ExecutionEx // Now let's go and ask for a protected resource! System.out.println("Now we're going to access a protected resource..."); - final OAuthRequestAsync request = new OAuthRequestAsync(Verb.GET, PROTECTED_RESOURCE_URL, service); + final OAuthRequestAsync request = new OAuthRequestAsync(Verb.GET, PROTECTED_RESOURCE_URL); service.signRequest(accessToken, request); - final Response response = request.sendAsync(null).get(); + final Response response = service.execute(request, null).get(); 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/FacebookExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java index d955c1f85..32ce7d103 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java @@ -69,7 +69,7 @@ public static void main(String... args) throws IOException { // 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); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service.getConfig()); service.signRequest(accessToken, request); final Response response = request.send(); System.out.println("Got it! Lets see what we found..."); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExample.java index b3fd7912a..47c0f8a4e 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExample.java @@ -55,7 +55,7 @@ public static void main(String... args) throws IOException { // 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); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service.getConfig()); request.addQuerystringParameter("method", "flickr.test.login"); service.signRequest(accessToken, request); final Response response = request.send(); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java index 44d471537..042e8671c 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java @@ -54,7 +54,7 @@ public static void main(String... args) throws IOException { // Now let's go and ask for a protected resource! System.out.println("Now we're going to access a protected resource..."); final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL + accessToken.getAccessToken(), - service); + service.getConfig()); service.signRequest(accessToken, request); final Response response = request.send(); System.out.println("Got it! Lets see what we found..."); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FoursquareExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FoursquareExample.java index 645985c75..b347ce154 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FoursquareExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FoursquareExample.java @@ -51,7 +51,7 @@ public static void main(String... args) throws IOException { // 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); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service.getConfig()); service.signRequest(accessToken, request); final Response response = request.send(); System.out.println("Got it! Lets see what we found..."); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java index a4c843ea4..35cbed3e8 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java @@ -59,7 +59,7 @@ public static void main(String... args) throws IOException { // 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); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service.getConfig()); service.signRequest(accessToken, request); request.addHeader("GData-Version", "3.0"); final Response response = request.send(); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GeniusExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GeniusExample.java index 04cf9f1d4..842b09ec6 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GeniusExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GeniusExample.java @@ -75,7 +75,7 @@ public static void main(String... args) throws IOException { // Now let's go and ask for a protected resource! System.out.println("Accessing a protected resource..."); - final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service.getConfig()); service.signRequest(accessToken, request); final Response response = request.send(); System.out.println("Got it! Viewing contents..."); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubExample.java index 88adcd597..444b86856 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubExample.java @@ -68,7 +68,7 @@ public static void main(String... args) throws IOException { // 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); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service.getConfig()); service.signRequest(accessToken, request); final Response response = request.send(); System.out.println("Got it! Lets see what we found..."); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java index 855cf6e50..b760feeda 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java @@ -113,9 +113,9 @@ public static void main(String... args) throws InterruptedException, ExecutionEx requestUrl = PROTECTED_RESOURCE_URL + "?fields=" + query; } - final OAuthRequestAsync request = new OAuthRequestAsync(Verb.GET, requestUrl, service); + final OAuthRequestAsync request = new OAuthRequestAsync(Verb.GET, requestUrl); service.signRequest(accessToken, request); - final Response response = request.sendAsync(null).get(); + final Response response = service.execute(request, null).get(); System.out.println(); System.out.println(response.getCode()); System.out.println(response.getBody()); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java index 530de206d..2c1c4a4fc 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java @@ -98,7 +98,7 @@ public static void main(String... args) throws IOException { requestUrl = PROTECTED_RESOURCE_URL + "?fields=" + query; } - final OAuthRequest request = new OAuthRequest(Verb.GET, requestUrl, service); + final OAuthRequest request = new OAuthRequest(Verb.GET, requestUrl, service.getConfig()); service.signRequest(accessToken, request); final Response response = request.send(); System.out.println(); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HHExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HHExample.java index 91bd52966..ab09915ee 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HHExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HHExample.java @@ -54,7 +54,7 @@ public static void main(String... args) throws IOException { System.out.println(); System.out.println("Now we're going to access a protected resource..."); - final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service.getConfig()); service.signRequest(accessToken, request); final Response response = request.send(); System.out.println("Got it! Lets see what we found..."); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ImgurExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ImgurExample.java index 484142322..62b6b5194 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ImgurExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ImgurExample.java @@ -53,7 +53,7 @@ public static void main(String... args) throws IOException { // 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); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service.getConfig()); service.signRequest(accessToken, request); final Response response = request.send(); System.out.println("Got it! Lets see what we found..."); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Kaixin20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Kaixin20Example.java index 50fa30139..8171127db 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Kaixin20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Kaixin20Example.java @@ -53,7 +53,7 @@ public static void main(String... args) throws IOException { // 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); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service.getConfig()); service.signRequest(accessToken, request); final Response response = request.send(); System.out.println("Got it! Lets see what we found..."); 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 95b2c5118..448a04d11 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 @@ -65,7 +65,7 @@ public static void main(String... args) throws IOException { } final OAuthRequest request = new OAuthRequest(Verb.GET, String.format(PROTECTED_RESOURCE_URL, query), - service); + service.getConfig()); request.addHeader("x-li-format", "json"); request.addHeader("Accept-Language", "ru-RU"); service.signRequest(accessToken, request); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java index 927d89524..6bc3cf513 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java @@ -52,7 +52,7 @@ public static void main(String... args) throws IOException { // 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); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service.getConfig()); service.signRequest(accessToken, request); final Response response = request.send(); System.out.println("Got it! Lets see what we found..."); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java index 0888cab5e..7dbf7bc19 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java @@ -56,7 +56,7 @@ public static void main(String... args) throws IOException { // 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); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service.getConfig()); service.signRequest(accessToken, request); final Response response = request.send(); System.out.println("Got it! Lets see what we found..."); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java index d449355b4..5a09bc133 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java @@ -55,7 +55,7 @@ public static void main(String... args) throws IOException { // Now let's go and ask for a protected resource! System.out.println("Now we're going to access a protected resource..."); final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL + accessToken.getAccessToken(), - service); + service.getConfig()); service.signRequest(accessToken, request); final Response response = request.send(); System.out.println("Got it! Lets see what we found..."); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java index 547a8bd57..ec1c8868b 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java @@ -67,9 +67,9 @@ public static void main(String... args) throws InterruptedException, ExecutionEx System.out.println(); System.out.println("Now we're going to access a protected resource..."); - final OAuthRequestAsync request = new OAuthRequestAsync(Verb.GET, PROTECTED_RESOURCE_URL, service); + final OAuthRequestAsync request = new OAuthRequestAsync(Verb.GET, PROTECTED_RESOURCE_URL); service.signRequest(accessToken, request); - final Response response = request.sendAsync(null).get(); + final Response response = service.execute(request, null).get(); System.out.println("Got it! Lets see what we found..."); System.out.println(); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java index 391adcd25..91b0eee7a 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java @@ -54,7 +54,7 @@ public static void main(String... args) throws IOException { System.out.println(); System.out.println("Now we're going to access a protected resource..."); - final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service.getConfig()); service.signRequest(accessToken, request); final Response response = request.send(); System.out.println("Got it! Lets see what we found..."); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java index 9b3efce58..e78ef808f 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java @@ -51,7 +51,7 @@ public static void main(String... args) throws IOException { // 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); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service.getConfig()); service.signRequest(accessToken, request); final Response response = request.send(); System.out.println("Got it! Lets see what we found..."); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MisfitExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MisfitExample.java index 451d55539..e2c98b7a5 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MisfitExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MisfitExample.java @@ -56,7 +56,7 @@ public static void main(String... args) throws IOException { // 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); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service.getConfig()); service.signRequest(accessToken, request); final Response response = request.send(); System.out.println("Got it! Lets see what we found..."); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NaverExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NaverExample.java index 98eab65df..1a3eff1bb 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NaverExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NaverExample.java @@ -70,7 +70,7 @@ public static void main(String... args) throws IOException { // 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); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service.getConfig()); service.signRequest(accessToken, request); final Response response = request.send(); System.out.println("Got it! Lets see what we found..."); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NeteaseWeiboExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NeteaseWeiboExample.java index e40715ae9..17217db97 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NeteaseWeiboExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NeteaseWeiboExample.java @@ -59,7 +59,7 @@ public static void main(String... args) throws IOException { // 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); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service.getConfig()); service.signRequest(accessToken, request); final Response response = request.send(); System.out.println("Got it! Lets see what we found..."); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java index 6180595d7..c7b096715 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java @@ -66,7 +66,7 @@ public static void main(String... args) throws IOException { // 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, String.format(PROTECTED_RESOURCE_URL, publicKey), - service); + service.getConfig()); service.signRequest(accessToken, request); final Response response = request.send(); System.out.println("Got it! Lets see what we found..."); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java index b49f1d451..47f9c75dc 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java @@ -55,7 +55,7 @@ public static void main(String... args) throws IOException { // Now let's go and ask for a protected resource! System.out.println("Now we're going to access a protected resource..."); final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL + accessToken.getAccessToken(), - service); + service.getConfig()); service.signRequest(accessToken, request); final Response response = request.send(); System.out.println("Got it! Lets see what we found..."); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Px500Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Px500Example.java index fa84b773e..76c3b29d9 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Px500Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Px500Example.java @@ -51,7 +51,7 @@ public static void main(String... args) throws IOException { // 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); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service.getConfig()); service.signRequest(accessToken, request); final Response response = request.send(); System.out.println("Got it! Lets see what we found..."); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java index 0a22eba37..2be75bef1 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java @@ -63,7 +63,7 @@ public static void main(String... args) throws IOException { // 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.POST, PROTECTED_RESOURCE_URL, service); + final OAuthRequest request = new OAuthRequest(Verb.POST, PROTECTED_RESOURCE_URL, service.getConfig()); final Map parameters = new HashMap<>(); parameters.put("method", "users.getInfo"); parameters.put("format", "json"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceExample.java index 71cc8b0f8..9f6b22aaf 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceExample.java @@ -84,7 +84,7 @@ public static void main(String... args) throws IOException, NoSuchAlgorithmExcep System.out.println(); System.out.println("Full URL: " + url); - final OAuthRequest request = new OAuthRequest(Verb.GET, url, service); + final OAuthRequest request = new OAuthRequest(Verb.GET, url, service.getConfig()); request.addHeader("Authorization", "Bearer " + accessToken.getAccessToken()); final Response response = request.send(); System.out.println(); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceNingAsyncExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceNingAsyncExample.java index 09f8e8dd0..1cec996d3 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceNingAsyncExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceNingAsyncExample.java @@ -95,9 +95,9 @@ public static void main(String... args) throws InterruptedException, ExecutionEx System.out.println(); System.out.println("Full URL: " + url); - final OAuthRequestAsync request = new OAuthRequestAsync(Verb.GET, url, service); + final OAuthRequestAsync request = new OAuthRequestAsync(Verb.GET, url); request.addHeader("Authorization", "Bearer " + accessToken.getAccessToken()); - final Response response = request.sendAsync(null).get(); + final Response response = service.execute(request, null).get(); System.out.println(); System.out.println(response.getCode()); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeibo2Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeibo2Example.java index 5a720717a..414c2e18c 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeibo2Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeibo2Example.java @@ -53,7 +53,7 @@ public static void main(String... args) throws IOException { // 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); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service.getConfig()); service.signRequest(accessToken, request); final Response response = request.send(); System.out.println("Got it! Lets see what we found..."); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeiboExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeiboExample.java index 3a2ea9249..140aa99ee 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeiboExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeiboExample.java @@ -59,7 +59,7 @@ public static void main(String... args) throws IOException { // 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); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service.getConfig()); service.signRequest(accessToken, request); final Response response = request.send(); System.out.println("Got it! Lets see what we found..."); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SkyrockExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SkyrockExample.java index a1c0fa6dc..5ab1dd56a 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SkyrockExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SkyrockExample.java @@ -51,7 +51,7 @@ public static void main(String... args) throws IOException { // 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); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service.getConfig()); service.signRequest(accessToken, request); final Response response = request.send(); System.out.println("Got it! Lets see what we found..."); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SohuWeiboExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SohuWeiboExample.java index 1333fb0bb..cd9f62453 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SohuWeiboExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SohuWeiboExample.java @@ -59,7 +59,7 @@ public static void main(String... args) throws IOException { // 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); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service.getConfig()); service.signRequest(accessToken, request); final Response response = request.send(); System.out.println("Got it! Lets see what we found..."); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/StackExchangeExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/StackExchangeExample.java index c4c1b2f46..6fe816df3 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/StackExchangeExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/StackExchangeExample.java @@ -74,7 +74,7 @@ public static void main(String... args) throws IOException { // 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 + "?site=" + site + "&key=" + key, service); + PROTECTED_RESOURCE_URL + "?site=" + site + "&key=" + key, service.getConfig()); service.signRequest(accessToken, request); final Response response = request.send(); System.out.println("Got it! Lets see what we found..."); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV1StagingExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV1StagingExample.java index 0905fb441..b0bc642f1 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV1StagingExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV1StagingExample.java @@ -75,7 +75,7 @@ public static void main(String... args) throws IOException { // 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); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service.getConfig()); // TTN should support both signing the request with a parameter, or with a header. // 1. Token as a parameter diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV2PreviewExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV2PreviewExample.java index ed7f2f6e7..2b6ce70e9 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV2PreviewExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV2PreviewExample.java @@ -72,7 +72,7 @@ public static void main(String... args) throws IOException { // 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); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service.getConfig()); // TTN should support both signing the request with a parameter, or with a header. // 1. Token as a parameter diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TrelloExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TrelloExample.java index 80094c46c..21350ea9f 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TrelloExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TrelloExample.java @@ -53,7 +53,7 @@ public static void main(String... args) throws IOException { // 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); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service.getConfig()); service.signRequest(accessToken, request); final Response response = request.send(); System.out.println("Got it! Lets see what we found..."); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TumblrExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TumblrExample.java index 9dde7b284..e94e1f31b 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TumblrExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TumblrExample.java @@ -53,7 +53,7 @@ public static void main(String... args) throws IOException { // 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); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service.getConfig()); service.signRequest(accessToken, request); final Response response = request.send(); System.out.println("Got it! Lets see what we found..."); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TutByExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TutByExample.java index 74b867939..82e57a344 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TutByExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TutByExample.java @@ -54,7 +54,7 @@ public static void main(String... args) throws IOException { // 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); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service.getConfig()); service.signRequest(accessToken, request); final Response response = request.send(); System.out.println("Got it! Lets see what we found..."); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TwitterExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TwitterExample.java index bae89f34a..41a7ea5d6 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TwitterExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TwitterExample.java @@ -51,7 +51,7 @@ public static void main(String... args) throws IOException { // 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); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service.getConfig()); service.signRequest(accessToken, request); final Response response = request.send(); System.out.println("Got it! Lets see what we found..."); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ViadeoExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ViadeoExample.java index c27cb7458..a89fef634 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ViadeoExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ViadeoExample.java @@ -53,7 +53,7 @@ public static void main(String... args) throws IOException { // 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); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service.getConfig()); service.signRequest(accessToken, request); final Response response = request.send(); System.out.println("Got it! Lets see what we found..."); 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 703e580fc..5ca4ae8de 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 @@ -54,7 +54,7 @@ public static void main(String... args) throws IOException { // 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); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service.getConfig()); service.signRequest(accessToken, request); final Response response = request.send(); System.out.println("Got it! Lets see what we found..."); 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 9221fae44..fe9618914 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 @@ -75,9 +75,9 @@ public static void main(String... args) throws IOException, InterruptedException // Now let's go and ask for a protected resource! System.out.println("Now we're going to access a protected resource..."); - final OAuthRequestAsync request = new OAuthRequestAsync(Verb.GET, PROTECTED_RESOURCE_URL, service); + final OAuthRequestAsync request = new OAuthRequestAsync(Verb.GET, PROTECTED_RESOURCE_URL); service.signRequest(accessToken, request); - final Response response = request.sendAsync(null).get(); + final Response response = service.execute(request, null).get(); 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/XingExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XingExample.java index 6133f80cb..93d57b963 100755 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XingExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XingExample.java @@ -51,7 +51,7 @@ public static void main(String... args) throws IOException { // 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); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service.getConfig()); service.signRequest(accessToken, request); final Response response = request.send(); System.out.println("Got it! Lets see what we found..."); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/YahooExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/YahooExample.java index 3779ed782..7127d28cd 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/YahooExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/YahooExample.java @@ -52,7 +52,7 @@ public static void main(String... args) throws IOException { // 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); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service.getConfig()); service.signRequest(accessToken, request); final Response response = request.send(); System.out.println("Got it! Lets see what we found..."); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/service/OdnoklassnikiServiceTest.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/service/OdnoklassnikiServiceTest.java index 3adbafd02..4e4e833cf 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/service/OdnoklassnikiServiceTest.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/service/OdnoklassnikiServiceTest.java @@ -27,7 +27,7 @@ public class OdnoklassnikiServiceTest { @Test public void testSigGeneration() { final OAuth2AccessToken accessToken = new OAuth2AccessToken("d3iwa.403gvrs194740652m1k4w2a503k3c"); - final OAuthRequest request = new OAuthRequest(Verb.GET, URL, service); + final OAuthRequest request = new OAuthRequest(Verb.GET, URL, service.getConfig()); service.signRequest(accessToken, request); assertEquals("96127f5ca29a8351399e94bbd284ab16", findParam(request.getQueryStringParams(), "sig")); } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/AbstractRequest.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/AbstractRequest.java index 213ed4b34..94d61095f 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/AbstractRequest.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/AbstractRequest.java @@ -25,7 +25,6 @@ public abstract class AbstractRequest { private final ParameterList bodyParams = new ParameterList(); private final Map headers = new HashMap<>(); private boolean followRedirects = true; - private final OAuthService service; private String payload; private String charset; @@ -40,11 +39,22 @@ public abstract class AbstractRequest { * @param verb Http verb/method * @param url resource URL * @param service OAuthService + * @deprecated use {@link #AbstractRequest(com.github.scribejava.core.model.Verb, java.lang.String)} */ + @Deprecated public AbstractRequest(Verb verb, String url, OAuthService service) { + this(verb, url); + } + + /** + * Default constructor. + * + * @param verb Http verb/method + * @param url resource URL + */ + public AbstractRequest(Verb verb, String url) { this.verb = verb; this.url = url; - this.service = service; } /** @@ -271,7 +281,14 @@ public boolean isFollowRedirects() { return followRedirects; } + /** + * always throws UnsupportedOperationException + * + * @return never + * @deprecated Request doesn't couple with Service anymore. It doesn't need it. Look for service somewhere else + */ + @Deprecated public OAuthService getService() { - return service; + throw new UnsupportedOperationException(); } } 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 b3986c5e8..cf723093d 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 @@ -12,13 +12,31 @@ public class OAuthRequest extends AbstractRequest { private HttpURLConnection connection; + private final OAuthConfig config; + + /** + * + * @param verb verb + * @param url url + * @param service service + * @deprecated use {@link #OAuthRequest(com.github.scribejava.core.model.Verb, java.lang.String, + * com.github.scribejava.core.model.OAuthConfig)} + */ + @Deprecated public OAuthRequest(Verb verb, String url, OAuthService service) { - super(verb, url, service); + this(verb, url, service.getConfig()); + } + + public OAuthRequest(Verb verb, String url, OAuthConfig config) { + super(verb, url); + this.config = config; } /** * Execute the request and return a {@link Response} * + * the same as {@link OAuthService#execute(com.github.scribejava.core.model.OAuthRequest)} + * * @return Http Response * * @throws RuntimeException if the connection cannot be created. @@ -30,7 +48,7 @@ public Response send() { throw new OAuthException("Cannot use sync operations, only async"); } if (ForceTypeOfHttpRequest.PREFER_ASYNC_ONLY_HTTP_REQUESTS == forceTypeOfHttpRequest) { - getService().getConfig().log("Cannot use sync operations, only async"); + config.log("Cannot use sync operations, only async"); } try { createConnection(); @@ -43,7 +61,6 @@ public Response send() { Response doSend() throws IOException { final Verb verb = getVerb(); connection.setRequestMethod(verb.name()); - final OAuthConfig config = getService().getConfig(); if (config.getConnectTimeout() != null) { connection.setConnectTimeout(config.getConnectTimeout()); } @@ -69,7 +86,7 @@ void addHeaders() { for (Map.Entry entry : getHeaders().entrySet()) { connection.setRequestProperty(entry.getKey(), entry.getValue()); } - final String userAgent = getService().getConfig().getUserAgent(); + final String userAgent = config.getUserAgent(); if (userAgent != null) { connection.setRequestProperty(OAuthConstants.USER_AGENT_HEADER_NAME, userAgent); } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequestAsync.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequestAsync.java index 1de5f69b5..930fe5b76 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequestAsync.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequestAsync.java @@ -1,32 +1,53 @@ package com.github.scribejava.core.model; -import com.github.scribejava.core.exceptions.OAuthException; import com.github.scribejava.core.oauth.OAuthService; - import java.io.IOException; import java.util.concurrent.Future; public class OAuthRequestAsync extends AbstractRequest { + /** + * @param verb verb + * @param url url + * @param service service + * @deprecated use {@link #OAuthRequestAsync(com.github.scribejava.core.model.Verb, java.lang.String) } + */ + @Deprecated public OAuthRequestAsync(Verb verb, String url, OAuthService service) { - super(verb, url, service); + this(verb, url); + } + + public OAuthRequestAsync(Verb verb, String url) { + super(verb, url); } + /** + * always throws UnsupportedOperationException + * + * @param T + * @param callback callback + * @param converter converter + * @return never + * @deprecated user {@link OAuthService#execute(com.github.scribejava.core.model.OAuthRequestAsync, + * com.github.scribejava.core.model.OAuthAsyncRequestCallback, + * com.github.scribejava.core.model.OAuthRequestAsync.ResponseConverter) } + */ + @Deprecated public Future sendAsync(OAuthAsyncRequestCallback callback, ResponseConverter converter) { - final ForceTypeOfHttpRequest forceTypeOfHttpRequest = ScribeJavaConfig.getForceTypeOfHttpRequests(); - if (ForceTypeOfHttpRequest.FORCE_SYNC_ONLY_HTTP_REQUESTS == forceTypeOfHttpRequest) { - throw new OAuthException("Cannot use async operations, only sync"); - } - final OAuthService service = getService(); - final OAuthConfig config = service.getConfig(); - if (ForceTypeOfHttpRequest.PREFER_SYNC_ONLY_HTTP_REQUESTS == forceTypeOfHttpRequest) { - config.log("Cannot use async operations, only sync"); - } - return service.executeAsync(getHeaders(), getVerb(), getCompleteUrl(), getBodyContents(), callback, converter); + throw new UnsupportedOperationException(); } + /** + * always throws UnsupportedOperationException + * + * @param callback callback + * @return never + * @deprecated user {@link OAuthService#execute(com.github.scribejava.core.model.OAuthRequestAsync, + * com.github.scribejava.core.model.OAuthAsyncRequestCallback) } + */ + @Deprecated public Future sendAsync(OAuthAsyncRequestCallback callback) { - return sendAsync(callback, null); + throw new UnsupportedOperationException(); } public interface ResponseConverter { 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 cbfa777f9..cf988c846 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 @@ -38,7 +38,7 @@ public OAuth10aService(DefaultApi10a api, OAuthConfig config) { public final OAuth1RequestToken getRequestToken() throws IOException { final OAuthConfig config = getConfig(); config.log("obtaining request token from " + api.getRequestTokenEndpoint()); - final OAuthRequest request = new OAuthRequest(api.getRequestTokenVerb(), api.getRequestTokenEndpoint(), this); + final OAuthRequest request = new OAuthRequest(api.getRequestTokenVerb(), api.getRequestTokenEndpoint(), config); prepareRequestTokenRequest(request); @@ -56,9 +56,9 @@ public final Future getRequestTokenAsync( final OAuthConfig config = getConfig(); config.log("async obtaining request token from " + api.getRequestTokenEndpoint()); final OAuthRequestAsync request - = new OAuthRequestAsync(api.getRequestTokenVerb(), api.getRequestTokenEndpoint(), this); + = new OAuthRequestAsync(api.getRequestTokenVerb(), api.getRequestTokenEndpoint()); prepareRequestTokenRequest(request); - return request.sendAsync(callback, new OAuthRequestAsync.ResponseConverter() { + return execute(request, callback, new OAuthRequestAsync.ResponseConverter() { @Override public OAuth1RequestToken convert(Response response) throws IOException { return getApi().getRequestTokenExtractor().extract(response); @@ -94,7 +94,7 @@ public final OAuth1AccessToken getAccessToken(OAuth1RequestToken requestToken, S throws IOException { final OAuthConfig config = getConfig(); config.log("obtaining access token from " + api.getAccessTokenEndpoint()); - final OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint(), this); + final OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint(), config); prepareAccessTokenRequest(request, requestToken, oauthVerifier); final Response response = request.send(); return api.getAccessTokenExtractor().extract(response); @@ -113,10 +113,9 @@ public final Future getAccessTokenAsync(OAuth1RequestToken re OAuthAsyncRequestCallback callback) { final OAuthConfig config = getConfig(); config.log("async obtaining access token from " + api.getAccessTokenEndpoint()); - final OAuthRequestAsync request - = new OAuthRequestAsync(api.getAccessTokenVerb(), api.getAccessTokenEndpoint(), this); + final OAuthRequestAsync request = new OAuthRequestAsync(api.getAccessTokenVerb(), api.getAccessTokenEndpoint()); prepareAccessTokenRequest(request, requestToken, oauthVerifier); - return request.sendAsync(callback, new OAuthRequestAsync.ResponseConverter() { + return execute(request, callback, new OAuthRequestAsync.ResponseConverter() { @Override public OAuth1AccessToken convert(Response response) throws IOException { return getApi().getAccessTokenExtractor().extract(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 c59627844..656f0816d 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 @@ -41,7 +41,7 @@ protected OAuth2AccessToken sendAccessTokenRequestSync(OAuthRequest request) thr protected Future sendAccessTokenRequestAsync(OAuthRequestAsync request, OAuthAsyncRequestCallback callback) { - return request.sendAsync(callback, new OAuthRequestAsync.ResponseConverter() { + return execute(request, callback, new OAuthRequestAsync.ResponseConverter() { @Override public OAuth2AccessToken convert(Response response) throws IOException { return getApi().getAccessTokenExtractor().extract(response); @@ -51,7 +51,7 @@ public OAuth2AccessToken convert(Response response) throws IOException { public final OAuth2AccessToken getAccessToken(String code) throws IOException { final OAuthRequest request = createAccessTokenRequest(code, - new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint(), this)); + new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint(), getConfig())); return sendAccessTokenRequestSync(request); } @@ -67,7 +67,7 @@ public final OAuth2AccessToken getAccessToken(String code) throws IOException { public final Future getAccessTokenAsync(String code, OAuthAsyncRequestCallback callback) { final OAuthRequestAsync request = createAccessTokenRequest(code, - new OAuthRequestAsync(api.getAccessTokenVerb(), api.getAccessTokenEndpoint(), this)); + new OAuthRequestAsync(api.getAccessTokenVerb(), api.getAccessTokenEndpoint())); return sendAccessTokenRequestAsync(request, callback); } @@ -88,7 +88,7 @@ protected T createAccessTokenRequest(String code, T public final OAuth2AccessToken refreshAccessToken(String refreshToken) throws IOException { final OAuthRequest request = createRefreshTokenRequest(refreshToken, - new OAuthRequest(api.getAccessTokenVerb(), api.getRefreshTokenEndpoint(), this)); + new OAuthRequest(api.getAccessTokenVerb(), api.getRefreshTokenEndpoint(), getConfig())); return sendAccessTokenRequestSync(request); } @@ -96,7 +96,7 @@ public final OAuth2AccessToken refreshAccessToken(String refreshToken) throws IO public final Future refreshAccessTokenAsync(String refreshToken, OAuthAsyncRequestCallback callback) { final OAuthRequestAsync request = createRefreshTokenRequest(refreshToken, - new OAuthRequestAsync(api.getAccessTokenVerb(), api.getRefreshTokenEndpoint(), this)); + new OAuthRequestAsync(api.getAccessTokenVerb(), api.getRefreshTokenEndpoint())); return sendAccessTokenRequestAsync(request, callback); } @@ -115,7 +115,7 @@ protected T createRefreshTokenRequest(String refresh public final OAuth2AccessToken getAccessTokenPasswordGrant(String uname, String password) throws IOException { final OAuthRequest request = createAccessTokenPasswordGrantRequest(uname, password, - new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint(), this)); + new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint(), getConfig())); return sendAccessTokenRequestSync(request); } @@ -131,7 +131,7 @@ public final OAuth2AccessToken getAccessTokenPasswordGrant(String uname, String public final Future getAccessTokenPasswordGrantAsync(String uname, String password, OAuthAsyncRequestCallback callback) { final OAuthRequestAsync request = createAccessTokenPasswordGrantRequest(uname, password, - new OAuthRequestAsync(api.getAccessTokenVerb(), api.getAccessTokenEndpoint(), this)); + new OAuthRequestAsync(api.getAccessTokenVerb(), api.getAccessTokenEndpoint())); return sendAccessTokenRequestAsync(request, callback); } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java index dc52942be..a98391630 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java @@ -7,7 +7,9 @@ import com.github.scribejava.core.model.HttpClient; import com.github.scribejava.core.model.OAuthAsyncRequestCallback; import com.github.scribejava.core.model.OAuthConfig; +import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.OAuthRequestAsync; +import com.github.scribejava.core.model.Response; import com.github.scribejava.core.model.ScribeJavaConfig; import com.github.scribejava.core.model.Token; import com.github.scribejava.core.model.Verb; @@ -81,10 +83,65 @@ public OAuthConfig getConfig() { public abstract void signRequest(T token, AbstractRequest request); + /** + * + * @param T + * @param headers headers + * @param httpVerb httpVerb + * @param completeUrl completeUrl + * @param bodyContents bodyContents + * @param callback callback + * @param converter converter + * @return Future + * @deprecated use {@link #execute(com.github.scribejava.core.model.OAuthRequestAsync, + * com.github.scribejava.core.model.OAuthAsyncRequestCallback, + * com.github.scribejava.core.model.OAuthRequestAsync.ResponseConverter)}
+ * or
{@link #execute(com.github.scribejava.core.model.OAuthRequestAsync, + * com.github.scribejava.core.model.OAuthAsyncRequestCallback)} + */ + @Deprecated public Future executeAsync(Map headers, Verb httpVerb, String completeUrl, String bodyContents, OAuthAsyncRequestCallback callback, OAuthRequestAsync.ResponseConverter converter) { - return httpClient.executeAsync(config.getUserAgent(), headers, httpVerb, - completeUrl, bodyContents, callback, converter); + + final ForceTypeOfHttpRequest forceTypeOfHttpRequest = ScribeJavaConfig.getForceTypeOfHttpRequests(); + if (ForceTypeOfHttpRequest.FORCE_SYNC_ONLY_HTTP_REQUESTS == forceTypeOfHttpRequest) { + throw new OAuthException("Cannot use async operations, only sync"); + } + if (ForceTypeOfHttpRequest.PREFER_SYNC_ONLY_HTTP_REQUESTS == forceTypeOfHttpRequest) { + config.log("Cannot use async operations, only sync"); + } + + return httpClient.executeAsync(config.getUserAgent(), headers, httpVerb, completeUrl, bodyContents, callback, + converter); + } + + public Future execute(OAuthRequestAsync request, OAuthAsyncRequestCallback callback, + OAuthRequestAsync.ResponseConverter converter) { + + final ForceTypeOfHttpRequest forceTypeOfHttpRequest = ScribeJavaConfig.getForceTypeOfHttpRequests(); + if (ForceTypeOfHttpRequest.FORCE_SYNC_ONLY_HTTP_REQUESTS == forceTypeOfHttpRequest) { + throw new OAuthException("Cannot use async operations, only sync"); + } + if (ForceTypeOfHttpRequest.PREFER_SYNC_ONLY_HTTP_REQUESTS == forceTypeOfHttpRequest) { + config.log("Cannot use async operations, only sync"); + } + + return httpClient.executeAsync(config.getUserAgent(), request.getHeaders(), request.getVerb(), + request.getCompleteUrl(), request.getBodyContents(), callback, converter); + } + + public Future execute(OAuthRequestAsync request, OAuthAsyncRequestCallback callback) { + return execute(request, callback, null); + } + + /** + * the same as {@link OAuthRequest#send()} + * + * @param request request + * @return Response + */ + public Response execute(OAuthRequest request) { + return request.send(); } } diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/ObjectMother.java b/scribejava-core/src/test/java/com/github/scribejava/core/ObjectMother.java index 30482b2c6..c8d9d0ed4 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/ObjectMother.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/ObjectMother.java @@ -4,13 +4,11 @@ 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 abstract class ObjectMother { public static OAuthRequest createSampleOAuthRequest() { - final OAuthRequest request = new OAuthRequest(Verb.GET, "http://example.com", - new OAuth20Service(null, new OAuthConfig("test", "test"))); + final OAuthRequest request = new OAuthRequest(Verb.GET, "http://example.com", new OAuthConfig("test", "test")); request.addOAuthParameter(OAuthConstants.TIMESTAMP, "123456"); request.addOAuthParameter(OAuthConstants.CONSUMER_KEY, "AS#$^*@&"); request.addOAuthParameter(OAuthConstants.CALLBACK, "http://example/callback"); @@ -20,7 +18,7 @@ public static OAuthRequest createSampleOAuthRequest() { public static OAuthRequest createSampleOAuthRequestPort80() { final OAuthRequest request = new OAuthRequest(Verb.GET, "http://example.com:80", - new OAuth20Service(null, new OAuthConfig("test", "test"))); + new OAuthConfig("test", "test")); request.addOAuthParameter(OAuthConstants.TIMESTAMP, "123456"); request.addOAuthParameter(OAuthConstants.CONSUMER_KEY, "AS#$^*@&"); request.addOAuthParameter(OAuthConstants.CALLBACK, "http://example/callback"); @@ -30,7 +28,7 @@ public static OAuthRequest createSampleOAuthRequestPort80() { public static OAuthRequest createSampleOAuthRequestPort80v2() { final OAuthRequest request = new OAuthRequest(Verb.GET, "http://example.com:80/test", - new OAuth20Service(null, new OAuthConfig("test", "test"))); + new OAuthConfig("test", "test")); request.addOAuthParameter(OAuthConstants.TIMESTAMP, "123456"); request.addOAuthParameter(OAuthConstants.CONSUMER_KEY, "AS#$^*@&"); request.addOAuthParameter(OAuthConstants.CALLBACK, "http://example/callback"); @@ -40,7 +38,7 @@ public static OAuthRequest createSampleOAuthRequestPort80v2() { public static OAuthRequest createSampleOAuthRequestPort8080() { final OAuthRequest request = new OAuthRequest(Verb.GET, "http://example.com:8080", - new OAuth20Service(null, new OAuthConfig("test", "test"))); + new OAuthConfig("test", "test")); request.addOAuthParameter(OAuthConstants.TIMESTAMP, "123456"); request.addOAuthParameter(OAuthConstants.CONSUMER_KEY, "AS#$^*@&"); request.addOAuthParameter(OAuthConstants.CALLBACK, "http://example/callback"); @@ -50,7 +48,7 @@ public static OAuthRequest createSampleOAuthRequestPort8080() { public static OAuthRequest createSampleOAuthRequestPort443() { final OAuthRequest request = new OAuthRequest(Verb.GET, "https://example.com:443", - new OAuth20Service(null, new OAuthConfig("test", "test"))); + new OAuthConfig("test", "test")); request.addOAuthParameter(OAuthConstants.TIMESTAMP, "123456"); request.addOAuthParameter(OAuthConstants.CONSUMER_KEY, "AS#$^*@&"); request.addOAuthParameter(OAuthConstants.CALLBACK, "http://example/callback"); @@ -60,7 +58,7 @@ public static OAuthRequest createSampleOAuthRequestPort443() { public static OAuthRequest createSampleOAuthRequestPort443v2() { final OAuthRequest request = new OAuthRequest(Verb.GET, "https://example.com:443/test", - new OAuth20Service(null, new OAuthConfig("test", "test"))); + new OAuthConfig("test", "test")); request.addOAuthParameter(OAuthConstants.TIMESTAMP, "123456"); request.addOAuthParameter(OAuthConstants.CONSUMER_KEY, "AS#$^*@&"); request.addOAuthParameter(OAuthConstants.CALLBACK, "http://example/callback"); 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 3eb4b7404..f207f299e 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 @@ -8,7 +8,6 @@ import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Verb; -import com.github.scribejava.core.oauth.OAuth20Service; public class BaseStringExtractorTest { @@ -92,8 +91,7 @@ public void shouldThrowExceptionIfRquestIsNull() { @Test(expected = OAuthParametersMissingException.class) public void shouldThrowExceptionIfRquestHasNoOAuthParameters() { - final OAuthRequest request = new OAuthRequest(Verb.GET, "http://example.com", - new OAuth20Service(null, new OAuthConfig("test", "test"))); + final OAuthRequest request = new OAuthRequest(Verb.GET, "http://example.com", new OAuthConfig("test", "test")); extractor.extract(request); } 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 356a1fbba..63f6d4752 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 @@ -8,7 +8,6 @@ import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Verb; -import com.github.scribejava.core.oauth.OAuth20Service; import com.github.scribejava.core.ObjectMother; public class HeaderExtractorTest { @@ -53,7 +52,7 @@ public void shouldExceptionIfRequestIsNull() { @Test(expected = OAuthParametersMissingException.class) public void shouldExceptionIfRequestHasNoOAuthParams() { final OAuthRequest emptyRequest = new OAuthRequest(Verb.GET, "http://example.com", - new OAuth20Service(null, new OAuthConfig("test", "test"))); + new OAuthConfig("test", "test")); extractor.extract(emptyRequest); } } diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/model/ForceTypeOfHttpRequestTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/model/ForceTypeOfHttpRequestTest.java index f6c6424b6..1de09ea92 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/model/ForceTypeOfHttpRequestTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/model/ForceTypeOfHttpRequestTest.java @@ -16,15 +16,17 @@ public class ForceTypeOfHttpRequestTest { private OAuthRequest request; private OAuthRequestAsync requestAsync; + private OAuthService oAuthService; @Before public void setUp() { ScribeJavaConfig.setForceTypeOfHttpRequests(ForceTypeOfHttpRequest.NONE); - final OAuthService oAuthService = new OAuth20Service(null, new OAuthConfig("test", "test")); - request = new OAuthRequest(Verb.GET, "http://example.com?qsparam=value&other+param=value+with+spaces", - oAuthService); - requestAsync = new OAuthRequestAsync(Verb.GET, "http://example.com?qsparam=value&other+param=value+with+spaces", - oAuthService); + final OAuthConfig config = new OAuthConfig("test", "test"); + + oAuthService = new OAuth20Service(null, config); + request = new OAuthRequest(Verb.GET, "http://example.com?qsparam=value&other+param=value+with+spaces", config); + requestAsync + = new OAuthRequestAsync(Verb.GET, "http://example.com?qsparam=value&other+param=value+with+spaces"); } @Test @@ -40,6 +42,6 @@ public void shouldNotSendAsyncWithForceParameter() throws ExecutionException, In expectedException.expect(OAuthException.class); expectedException.expectMessage("Cannot use async operations, only sync"); ScribeJavaConfig.setForceTypeOfHttpRequests(ForceTypeOfHttpRequest.FORCE_SYNC_ONLY_HTTP_REQUESTS); - requestAsync.sendAsync(null).get(); + oAuthService.execute(requestAsync, null).get(); } } 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 d1bae5bfa..1e632dab8 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 @@ -3,7 +3,6 @@ import static org.junit.Assert.assertEquals; import org.junit.Before; import org.junit.Test; -import com.github.scribejava.core.oauth.OAuth20Service; public class OAuthRequestTest { @@ -11,8 +10,7 @@ public class OAuthRequestTest { @Before public void setUp() { - request = new OAuthRequest(Verb.GET, "http://example.com", - new OAuth20Service(null, new OAuthConfig("test", "test"))); + request = new OAuthRequest(Verb.GET, "http://example.com", new OAuthConfig("test", "test")); } @Test diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/model/RequestTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/model/RequestTest.java index cd2733926..6a038307a 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/model/RequestTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/model/RequestTest.java @@ -5,8 +5,6 @@ import static org.junit.Assert.assertTrue; import org.junit.Before; import org.junit.Test; -import com.github.scribejava.core.oauth.OAuth20Service; -import com.github.scribejava.core.oauth.OAuthService; import java.net.MalformedURLException; public class RequestTest { @@ -14,18 +12,18 @@ public class RequestTest { private OAuthRequest getRequest; private OAuthRequest postRequest; private ConnectionStub connection; - private OAuthService oAuthService; + private OAuthConfig config; @Before public void setUp() throws MalformedURLException { connection = new ConnectionStub(); - oAuthService = new OAuth20Service(null, new OAuthConfig("test", "test")); - postRequest = new OAuthRequest(Verb.POST, "http://example.com", oAuthService); + config = new OAuthConfig("test", "test"); + postRequest = new OAuthRequest(Verb.POST, "http://example.com", config); postRequest.addBodyParameter("param", "value"); postRequest.addBodyParameter("param with spaces", "value with spaces"); postRequest.setConnection(connection); getRequest = new OAuthRequest(Verb.GET, "http://example.com?qsparam=value&other+param=value+with+spaces", - oAuthService); + config); getRequest.setConnection(connection); } @@ -68,7 +66,7 @@ public void shouldSetPayloadAndHeaders() { @Test public void shouldAllowAddingQuerystringParametersAfterCreation() { - final OAuthRequest request = new OAuthRequest(Verb.GET, "http://example.com?one=val", oAuthService); + final OAuthRequest request = new OAuthRequest(Verb.GET, "http://example.com?one=val", config); request.addQuerystringParameter("two", "other val"); request.addQuerystringParameter("more", "params"); assertEquals(3, request.getQueryStringParams().size()); @@ -76,7 +74,7 @@ public void shouldAllowAddingQuerystringParametersAfterCreation() { @Test public void shouldReturnTheCompleteUrl() { - final OAuthRequest request = new OAuthRequest(Verb.GET, "http://example.com?one=val", oAuthService); + final OAuthRequest request = new OAuthRequest(Verb.GET, "http://example.com?one=val", config); request.addQuerystringParameter("two", "other val"); request.addQuerystringParameter("more", "params"); assertEquals("http://example.com?one=val&two=other%20val&more=params", request.getCompleteUrl()); From b7d0c6dd510c23457fa8ad9da46a6748749aa032 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 7 Dec 2016 16:39:52 +0300 Subject: [PATCH 319/882] add support for byte[] and File (async only) payload in OAuth Requests (thanks to https://github.com/keijohyttinen) --- changelog | 1 + .../core/model/AbstractRequest.java | 98 +++++++++++++++---- .../scribejava/core/model/HttpClient.java | 13 ++- .../scribejava/core/model/OAuthRequest.java | 10 +- .../scribejava/core/oauth/OAuthService.java | 14 ++- .../scribejava/core/model/RequestTest.java | 11 ++- .../httpclient/ahc/AhcHttpClient.java | 77 ++++++++++++++- .../httpclient/ning/NingHttpClient.java | 80 ++++++++++++++- 8 files changed, 270 insertions(+), 34 deletions(-) diff --git a/changelog b/changelog index 01d43cbb0..061400944 100644 --- a/changelog +++ b/changelog @@ -1,6 +1,7 @@ [SNAPSHOT] * uncouple OAuthRequest and Service. OAuthRequest shouldn't know anything about OAuthservice. You don't need OAuthService to create OAuthRequest anymore. Async request should be sent via OAuthService method. + * add support for byte[] and File (async only) payload in OAuth Requests (thanks to https://github.com/keijohyttinen) [3.3.0] * update Facebook v2.6 -> v2.8 diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/AbstractRequest.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/AbstractRequest.java index 94d61095f..d31bdc658 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/AbstractRequest.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/AbstractRequest.java @@ -8,6 +8,7 @@ import java.util.Map; import com.github.scribejava.core.exceptions.OAuthException; import com.github.scribejava.core.oauth.OAuthService; +import java.io.File; /** * The representation of an OAuth HttpRequest. @@ -26,9 +27,12 @@ public abstract class AbstractRequest { private final Map headers = new HashMap<>(); private boolean followRedirects = true; - private String payload; private String charset; - private byte[] bytePayload; + + private String stringPayload; + private byte[] byteArrayPayload; + private File filePayload; + private final Map oauthParameters = new HashMap<>(); private String realm; @@ -142,13 +146,32 @@ protected boolean hasBodyContent() { } /** - * Add body payload. This method is used when the HTTP body is not a form-url-encoded string, but another thing. + * @param payload payload + * @deprecated use {@link #setPayload(java.lang.String) } + */ + @Deprecated + public void addPayload(String payload) { + setPayload(payload); + } + + /** + * @param payload payload + * @deprecated use {@link #setPayload(byte[]) } + */ + @Deprecated + public void addPayload(byte[] payload) { + setPayload(payload); + } + + /** + * Set body payload. This method is used when the HTTP body is not a form-url-encoded string, but another thing. * Like for example XML. Note: The contents are not part of the OAuth signature * * @param payload the body of the request */ - public void addPayload(String payload) { - this.payload = payload; + public void setPayload(String payload) { + resetPayload(); + stringPayload = payload; } /** @@ -156,8 +179,25 @@ public void addPayload(String payload) { * * @param payload byte[] */ - public void addPayload(byte[] payload) { - this.bytePayload = payload.clone(); + public void setPayload(byte[] payload) { + resetPayload(); + byteArrayPayload = payload.clone(); + } + + /** + * Overloaded version for File + * + * @param payload File + */ + public void setPayload(File payload) { + resetPayload(); + filePayload = payload; + } + + private void resetPayload() { + stringPayload = null; + byteArrayPayload = null; + filePayload = null; } /** @@ -212,25 +252,43 @@ public String getSanitizedUrl() { } /** - * Returns the body of the request + * @return value set in {@link #setPayload(java.lang.String)} + * @deprecated use {@link #getStringPayload()} or {@link #getByteArrayPayload()} + */ + @Deprecated + public String getBodyContents() { + return getStringPayload(); + } + + /** + * Returns the body of the request (set in {@link #setPayload(java.lang.String)}) * * @return form encoded string * * @throws OAuthException if the charset chosen is not supported */ - public String getBodyContents() { - try { - return new String(getByteBodyContents(), getCharset()); - } catch (UnsupportedEncodingException uee) { - throw new OAuthException("Unsupported Charset: " + charset, uee); - } + public String getStringPayload() { + return stringPayload; + } + + /** + * @return value set in {@link #setPayload(byte[])} + * @deprecated use {@link #getByteArrayPayload() } + */ + @Deprecated + public byte[] getByteBodyContents() { + return getByteArrayPayload(); } - byte[] getByteBodyContents() { - if (bytePayload != null) { - return bytePayload; + /** + * @return the body of the request (set in {@link #setPayload(byte[])} or in + * {@link #addBodyParameter(java.lang.String, java.lang.String)} ) + */ + public byte[] getByteArrayPayload() { + if (byteArrayPayload != null) { + return byteArrayPayload; } - final String body = (payload == null) ? bodyParams.asFormUrlEncodedString() : payload; + final String body = bodyParams.asFormUrlEncodedString(); try { return body.getBytes(getCharset()); } catch (UnsupportedEncodingException uee) { @@ -238,6 +296,10 @@ byte[] getByteBodyContents() { } } + public File getFilePayload() { + return filePayload; + } + @Override public String toString() { return String.format("@Request(%s %s)", getVerb(), getUrl()); diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/HttpClient.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/HttpClient.java index 3762f7083..339e2d7f4 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/HttpClient.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/HttpClient.java @@ -1,15 +1,24 @@ package com.github.scribejava.core.model; +import java.io.File; import java.io.IOException; import java.util.Map; import java.util.concurrent.Future; public interface HttpClient { + void close() throws IOException; Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, - String bodyContents, OAuthAsyncRequestCallback callback, - OAuthRequestAsync.ResponseConverter converter); + byte[] bodyContents, OAuthAsyncRequestCallback callback, + OAuthRequestAsync.ResponseConverter converter); + + Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, + String bodyContents, OAuthAsyncRequestCallback callback, + OAuthRequestAsync.ResponseConverter converter); + + Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, + File bodyContents, OAuthAsyncRequestCallback callback, OAuthRequestAsync.ResponseConverter converter); interface Config { } 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 cf723093d..c0f35408a 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequest.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequest.java @@ -7,6 +7,7 @@ import com.github.scribejava.core.exceptions.OAuthConnectionException; import com.github.scribejava.core.exceptions.OAuthException; import com.github.scribejava.core.oauth.OAuthService; +import java.io.File; public class OAuthRequest extends AbstractRequest { @@ -69,7 +70,14 @@ Response doSend() throws IOException { } addHeaders(); if (hasBodyContent()) { - addBody(getByteBodyContents()); + final File filePayload = getFilePayload(); + if (filePayload != null) { + throw new UnsupportedOperationException("Sync Requests do not support File payload for the moment"); + } else if (getStringPayload() != null) { + addBody(getStringPayload().getBytes(getCharset())); + } else { + addBody(getByteArrayPayload()); + } } return new Response(connection); } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java index a98391630..19d9af62d 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java @@ -13,6 +13,7 @@ import com.github.scribejava.core.model.ScribeJavaConfig; import com.github.scribejava.core.model.Token; import com.github.scribejava.core.model.Verb; +import java.io.File; import java.io.IOException; import java.util.Map; @@ -127,8 +128,17 @@ public Future execute(OAuthRequestAsync request, OAuthAsyncRequestCallbac config.log("Cannot use async operations, only sync"); } - return httpClient.executeAsync(config.getUserAgent(), request.getHeaders(), request.getVerb(), - request.getCompleteUrl(), request.getBodyContents(), callback, converter); + final File filePayload = request.getFilePayload(); + if (filePayload != null) { + return httpClient.executeAsync(config.getUserAgent(), request.getHeaders(), request.getVerb(), + request.getCompleteUrl(), filePayload, callback, converter); + } else if (request.getStringPayload() != null) { + return httpClient.executeAsync(config.getUserAgent(), request.getHeaders(), request.getVerb(), + request.getCompleteUrl(), request.getStringPayload(), callback, converter); + } else { + return httpClient.executeAsync(config.getUserAgent(), request.getHeaders(), request.getVerb(), + request.getCompleteUrl(), request.getByteArrayPayload(), callback, converter); + } } public Future execute(OAuthRequestAsync request, OAuthAsyncRequestCallback callback) { diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/model/RequestTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/model/RequestTest.java index 6a038307a..bd6cff86f 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/model/RequestTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/model/RequestTest.java @@ -51,16 +51,17 @@ public void shouldAddRequestHeaders() { @Test public void shouldSetBodyParamsAndAddContentLength() { - assertEquals("param=value¶m%20with%20spaces=value%20with%20spaces", postRequest.getBodyContents()); + assertEquals("param=value¶m%20with%20spaces=value%20with%20spaces", + new String(postRequest.getByteArrayPayload())); postRequest.send(); assertTrue(connection.getHeaders().containsKey("Content-Length")); } @Test public void shouldSetPayloadAndHeaders() { - postRequest.addPayload("PAYLOAD"); + postRequest.setPayload("PAYLOAD"); postRequest.send(); - assertEquals("PAYLOAD", postRequest.getBodyContents()); + assertEquals("PAYLOAD", postRequest.getStringPayload()); assertTrue(connection.getHeaders().containsKey("Content-Length")); } @@ -87,14 +88,14 @@ public void shouldHandleQueryStringSpaceEncodingProperly() { @Test public void shouldAutomaticallyAddContentTypeForPostRequestsWithBytePayload() { - postRequest.addPayload("PAYLOAD".getBytes()); + postRequest.setPayload("PAYLOAD".getBytes()); postRequest.send(); assertEquals(OAuthRequest.DEFAULT_CONTENT_TYPE, connection.getHeaders().get("Content-Type")); } @Test public void shouldAutomaticallyAddContentTypeForPostRequestsWithStringPayload() { - postRequest.addPayload("PAYLOAD"); + postRequest.setPayload("PAYLOAD"); postRequest.send(); assertEquals(OAuthRequest.DEFAULT_CONTENT_TYPE, connection.getHeaders().get("Content-Type")); } 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 14d88ea31..2729c475d 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 @@ -14,6 +14,7 @@ import java.util.concurrent.Future; import static com.github.scribejava.core.model.AbstractRequest.DEFAULT_CONTENT_TYPE; +import java.io.File; import org.asynchttpclient.BoundRequestBuilder; public class AhcHttpClient implements HttpClient { @@ -35,8 +36,31 @@ public void close() throws IOException { @Override public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, - String bodyContents, OAuthAsyncRequestCallback callback, - OAuthRequestAsync.ResponseConverter converter) { + byte[] bodyContents, OAuthAsyncRequestCallback callback, + OAuthRequestAsync.ResponseConverter converter) { + return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, new ByteArrayBodySetter(bodyContents), + callback, converter); + } + + @Override + public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, + String bodyContents, OAuthAsyncRequestCallback callback, + OAuthRequestAsync.ResponseConverter converter) { + return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, new StringBodySetter(bodyContents), callback, + converter); + } + + @Override + public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, + File bodyContents, OAuthAsyncRequestCallback callback, + OAuthRequestAsync.ResponseConverter converter) { + return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, new FileBodySetter(bodyContents), callback, + converter); + } + + private Future doExecuteAsync(String userAgent, Map headers, Verb httpVerb, + String completeUrl, BodySetter bodySetter, OAuthAsyncRequestCallback callback, + OAuthRequestAsync.ResponseConverter converter) { final BoundRequestBuilder boundRequestBuilder; switch (httpVerb) { case GET: @@ -47,7 +71,7 @@ public Future executeAsync(String userAgent, Map headers, if (!headers.containsKey(AbstractRequest.CONTENT_TYPE)) { requestBuilder = requestBuilder.addHeader(AbstractRequest.CONTENT_TYPE, DEFAULT_CONTENT_TYPE); } - boundRequestBuilder = requestBuilder.setBody(bodyContents); + boundRequestBuilder = bodySetter.setBody(requestBuilder); break; default: throw new IllegalArgumentException("message build error: unknown verb type"); @@ -64,4 +88,51 @@ public Future executeAsync(String userAgent, Map headers, .execute(new OAuthAsyncCompletionHandler<>( callback, converter)); } + + private interface BodySetter { + + BoundRequestBuilder setBody(BoundRequestBuilder requestBuilder); + } + + private static class ByteArrayBodySetter implements BodySetter { + + private final byte[] bodyContents; + + private ByteArrayBodySetter(byte[] bodyContents) { + this.bodyContents = bodyContents; + } + + @Override + public BoundRequestBuilder setBody(BoundRequestBuilder requestBuilder) { + return requestBuilder.setBody(bodyContents); + } + } + + private static class StringBodySetter implements BodySetter { + + private final String bodyContents; + + private StringBodySetter(String bodyContents) { + this.bodyContents = bodyContents; + } + + @Override + public BoundRequestBuilder setBody(BoundRequestBuilder requestBuilder) { + return requestBuilder.setBody(bodyContents); + } + } + + private static class FileBodySetter implements BodySetter { + + private final File bodyContents; + + private FileBodySetter(File bodyContents) { + this.bodyContents = bodyContents; + } + + @Override + public BoundRequestBuilder setBody(BoundRequestBuilder requestBuilder) { + return requestBuilder.setBody(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 9d4bccffd..5bf19fd53 100644 --- a/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/NingHttpClient.java +++ b/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/NingHttpClient.java @@ -12,6 +12,7 @@ import java.util.concurrent.Future; import static com.github.scribejava.core.model.AbstractRequest.DEFAULT_CONTENT_TYPE; +import java.io.File; public class NingHttpClient implements HttpClient { @@ -34,8 +35,34 @@ public void close() { @Override public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, - String bodyContents, OAuthAsyncRequestCallback callback, - OAuthRequestAsync.ResponseConverter converter) { + byte[] bodyContents, OAuthAsyncRequestCallback callback, + OAuthRequestAsync.ResponseConverter converter) { + + return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, new ByteArrayBodySetter(bodyContents), + callback, converter); + } + + @Override + public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, + String bodyContents, OAuthAsyncRequestCallback callback, + OAuthRequestAsync.ResponseConverter converter) { + + return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, new StringBodySetter(bodyContents), callback, + converter); + } + + @Override + public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, + File bodyContents, OAuthAsyncRequestCallback callback, + OAuthRequestAsync.ResponseConverter converter) { + + return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, new FileBodySetter(bodyContents), callback, + converter); + } + + private Future doExecuteAsync(String userAgent, Map headers, Verb httpVerb, + String completeUrl, BodySetter bodySetter, OAuthAsyncRequestCallback callback, + OAuthRequestAsync.ResponseConverter converter) { final AsyncHttpClient.BoundRequestBuilder boundRequestBuilder; switch (httpVerb) { case GET: @@ -46,7 +73,7 @@ public Future executeAsync(String userAgent, Map headers, if (!headers.containsKey(AbstractRequest.CONTENT_TYPE)) { requestBuilder = requestBuilder.addHeader(AbstractRequest.CONTENT_TYPE, DEFAULT_CONTENT_TYPE); } - boundRequestBuilder = requestBuilder.setBody(bodyContents); + boundRequestBuilder = bodySetter.setBody(requestBuilder); break; default: throw new IllegalArgumentException("message build error: unknown verb type"); @@ -63,4 +90,51 @@ public Future executeAsync(String userAgent, Map headers, .execute(new OAuthAsyncCompletionHandler<>( callback, converter)); } + + private interface BodySetter { + + AsyncHttpClient.BoundRequestBuilder setBody(AsyncHttpClient.BoundRequestBuilder requestBuilder); + } + + private static class ByteArrayBodySetter implements BodySetter { + + private final byte[] bodyContents; + + private ByteArrayBodySetter(byte[] bodyContents) { + this.bodyContents = bodyContents; + } + + @Override + public AsyncHttpClient.BoundRequestBuilder setBody(AsyncHttpClient.BoundRequestBuilder requestBuilder) { + return requestBuilder.setBody(bodyContents); + } + } + + private static class StringBodySetter implements BodySetter { + + private final String bodyContents; + + private StringBodySetter(String bodyContents) { + this.bodyContents = bodyContents; + } + + @Override + public AsyncHttpClient.BoundRequestBuilder setBody(AsyncHttpClient.BoundRequestBuilder requestBuilder) { + return requestBuilder.setBody(bodyContents); + } + } + + private static class FileBodySetter implements BodySetter { + + private final File bodyContents; + + private FileBodySetter(File bodyContents) { + this.bodyContents = bodyContents; + } + + @Override + public AsyncHttpClient.BoundRequestBuilder setBody(AsyncHttpClient.BoundRequestBuilder requestBuilder) { + return requestBuilder.setBody(bodyContents); + } + } } From 43ea452609f7fa857e61c5f35f955faff6efe760 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 7 Dec 2016 16:55:48 +0300 Subject: [PATCH 320/882] add support for HTTP verbs (thanks to https://github.com/keijohyttinen) --- changelog | 1 + .../httpclient/ahc/AhcHttpClient.java | 21 +++++++++++++------ .../httpclient/ning/NingHttpClient.java | 21 +++++++++++++------ 3 files changed, 31 insertions(+), 12 deletions(-) diff --git a/changelog b/changelog index 061400944..9d9cf23f4 100644 --- a/changelog +++ b/changelog @@ -2,6 +2,7 @@ * uncouple OAuthRequest and Service. OAuthRequest shouldn't know anything about OAuthservice. You don't need OAuthService to create OAuthRequest anymore. Async request should be sent via OAuthService method. * 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) [3.3.0] * update Facebook v2.6 -> v2.8 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 2729c475d..0eca9a6fa 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 @@ -61,22 +61,31 @@ public Future executeAsync(String userAgent, Map headers, private Future doExecuteAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, BodySetter bodySetter, OAuthAsyncRequestCallback callback, OAuthRequestAsync.ResponseConverter converter) { - final BoundRequestBuilder boundRequestBuilder; + BoundRequestBuilder boundRequestBuilder; switch (httpVerb) { case GET: boundRequestBuilder = client.prepareGet(completeUrl); break; case POST: - BoundRequestBuilder requestBuilder = client.preparePost(completeUrl); - if (!headers.containsKey(AbstractRequest.CONTENT_TYPE)) { - requestBuilder = requestBuilder.addHeader(AbstractRequest.CONTENT_TYPE, DEFAULT_CONTENT_TYPE); - } - boundRequestBuilder = bodySetter.setBody(requestBuilder); + boundRequestBuilder = client.preparePost(completeUrl); + break; + case PUT: + boundRequestBuilder = client.preparePut(completeUrl); + break; + case DELETE: + boundRequestBuilder = client.prepareDelete(completeUrl); break; default: throw new IllegalArgumentException("message build error: unknown verb type"); } + if (httpVerb == Verb.POST || httpVerb == Verb.PUT || httpVerb == Verb.DELETE) { + if (!headers.containsKey(AbstractRequest.CONTENT_TYPE)) { + boundRequestBuilder = boundRequestBuilder.addHeader(AbstractRequest.CONTENT_TYPE, DEFAULT_CONTENT_TYPE); + } + boundRequestBuilder = bodySetter.setBody(boundRequestBuilder); + } + for (Map.Entry header : headers.entrySet()) { boundRequestBuilder.addHeader(header.getKey(), header.getValue()); } 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 5bf19fd53..f75c645c1 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 @@ -63,22 +63,31 @@ public Future executeAsync(String userAgent, Map headers, private Future doExecuteAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, BodySetter bodySetter, OAuthAsyncRequestCallback callback, OAuthRequestAsync.ResponseConverter converter) { - final AsyncHttpClient.BoundRequestBuilder boundRequestBuilder; + AsyncHttpClient.BoundRequestBuilder boundRequestBuilder; switch (httpVerb) { case GET: boundRequestBuilder = client.prepareGet(completeUrl); break; case POST: - AsyncHttpClient.BoundRequestBuilder requestBuilder = client.preparePost(completeUrl); - if (!headers.containsKey(AbstractRequest.CONTENT_TYPE)) { - requestBuilder = requestBuilder.addHeader(AbstractRequest.CONTENT_TYPE, DEFAULT_CONTENT_TYPE); - } - boundRequestBuilder = bodySetter.setBody(requestBuilder); + boundRequestBuilder = client.preparePost(completeUrl); + break; + case PUT: + boundRequestBuilder = client.preparePut(completeUrl); + break; + case DELETE: + boundRequestBuilder = client.prepareDelete(completeUrl); break; default: throw new IllegalArgumentException("message build error: unknown verb type"); } + if (httpVerb == Verb.POST || httpVerb == Verb.PUT || httpVerb == Verb.DELETE) { + if (!headers.containsKey(AbstractRequest.CONTENT_TYPE)) { + boundRequestBuilder = boundRequestBuilder.addHeader(AbstractRequest.CONTENT_TYPE, DEFAULT_CONTENT_TYPE); + } + boundRequestBuilder = bodySetter.setBody(boundRequestBuilder); + } + for (Map.Entry header : headers.entrySet()) { boundRequestBuilder.addHeader(header.getKey(), header.getValue()); } From 5e560cc50fecc907ed1af729656a531b7fd0e149 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 8 Dec 2016 16:18:42 +0300 Subject: [PATCH 321/882] fixes and refactorings to OkHttp support --- README.md | 7 +- changelog | 1 + .../examples/GitHubAsyncOkHttpExample.java | 10 ++- .../VkontakteExternalHttpExample.java | 2 +- .../httpclient/ahc/AhcHttpClient.java | 80 ++++++------------ .../httpclient/ning/NingHttpClient.java | 84 +++++++------------ .../okhttp/OAuthAsyncCompletionHandler.java | 52 ++---------- .../httpclient/okhttp/OkHttpFuture.java | 59 +++++++++++++ .../httpclient/okhttp/OkHttpHttpClient.java | 78 +++++++++++++++-- .../okhttp/OkHttpHttpClientConfig.java | 10 +-- .../okhttp/OkHttpHttpClientTest.java | 21 +++-- 11 files changed, 222 insertions(+), 182 deletions(-) create mode 100644 scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpFuture.java diff --git a/README.md b/README.md index 5b185be1b..f2e576d29 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,12 @@ Hit ScribeJava as hard and with many threads as you like. ### Async and other HTTP clients -You can use ning async http client 1.9.x or asynchttpclient 2.x out-of-box, just add maven modules scribejava-httpclient-ning or scribejava-httpclient-ahc to your pom +ScribeJava support out-of-box several HTTP clients: + * ning async http client 1.9.x (maven module scribejava-httpclient-ning) + * asynchttpclient 2.x (maven module scribejava-httpclient-ahc) + * OkHttp (maven module scribejava-httpclient-okhttp) + + just add corresponding maven modules to your pom ### Supports all major 1.0a and 2.0 OAuth APIs out-of-the-box diff --git a/changelog b/changelog index 9d9cf23f4..1eff1321c 100644 --- a/changelog +++ b/changelog @@ -3,6 +3,7 @@ You don't need OAuthService to create OAuthRequest anymore. Async request should be sent via OAuthService method. * 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) [3.3.0] * update Facebook v2.6 -> v2.8 diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubAsyncOkHttpExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubAsyncOkHttpExample.java index c0e4e6859..f3153f66e 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubAsyncOkHttpExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubAsyncOkHttpExample.java @@ -7,7 +7,7 @@ import com.github.scribejava.core.model.Response; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.oauth.OAuth20Service; -import com.github.scribejava.httpclient.okhttp.OkHttpHttpClient; +import com.github.scribejava.httpclient.okhttp.OkHttpHttpClientConfig; import okhttp3.OkHttpClient; import java.io.IOException; @@ -28,12 +28,13 @@ public static void main(String... args) throws IOException, ExecutionException, final String clientId = "your client id"; final String clientSecret = "your client secret"; final String secretState = "secret" + new Random().nextInt(999_999); + final OkHttpClient.Builder okHttpBuilder = new OkHttpClient.Builder(); final OAuth20Service service = new ServiceBuilder() .apiKey(clientId) .apiSecret(clientSecret) .state(secretState) .callback("http://www.example.com/oauth_callback/") - .httpClient(new OkHttpHttpClient(new OkHttpClient())) + .httpClientConfig(new OkHttpHttpClientConfig(okHttpBuilder)) .build(GitHubApi.instance()); final Scanner in = new Scanner(System.in, "UTF-8"); @@ -73,9 +74,9 @@ public static void main(String... args) throws IOException, ExecutionException, // Now let's go and ask for a protected resource! System.out.println("Now we're going to access a protected resource..."); - final OAuthRequestAsync request = new OAuthRequestAsync(Verb.GET, PROTECTED_RESOURCE_URL, service); + final OAuthRequestAsync request = new OAuthRequestAsync(Verb.GET, PROTECTED_RESOURCE_URL); service.signRequest(accessToken, request); - final Response response = request.sendAsync(null).get(); + final Response response = service.execute(request, null).get(); System.out.println("Got it! Lets see what we found..."); System.out.println(); System.out.println(response.getCode()); @@ -83,5 +84,6 @@ public static void main(String... args) throws IOException, ExecutionException, System.out.println(); System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); + service.closeAsyncClient(); } } 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 fe9618914..065d1af4e 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 @@ -30,7 +30,7 @@ public static void main(String... args) throws IOException, InterruptedException final String clientSecret = "your client secret"; ScribeJavaConfig.setForceTypeOfHttpRequests(ForceTypeOfHttpRequest.FORCE_ASYNC_ONLY_HTTP_REQUESTS); - //create any http cleint externally + //create any http client externally final DefaultAsyncHttpClientConfig httpClientConfig = new DefaultAsyncHttpClientConfig.Builder() .setMaxConnections(5) .setRequestTimeout(10_000) 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 0eca9a6fa..60d5c92cd 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 @@ -38,15 +38,15 @@ public void close() throws IOException { public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, byte[] bodyContents, OAuthAsyncRequestCallback callback, OAuthRequestAsync.ResponseConverter converter) { - return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, new ByteArrayBodySetter(bodyContents), - callback, converter); + return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, BodySetter.BYTE_ARRAY, bodyContents, callback, + converter); } @Override public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, String bodyContents, OAuthAsyncRequestCallback callback, OAuthRequestAsync.ResponseConverter converter) { - return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, new StringBodySetter(bodyContents), callback, + return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, BodySetter.STRING, bodyContents, callback, converter); } @@ -54,12 +54,12 @@ public Future executeAsync(String userAgent, Map headers, public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, File bodyContents, OAuthAsyncRequestCallback callback, OAuthRequestAsync.ResponseConverter converter) { - return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, new FileBodySetter(bodyContents), callback, + return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, BodySetter.FILE, bodyContents, callback, converter); } private Future doExecuteAsync(String userAgent, Map headers, Verb httpVerb, - String completeUrl, BodySetter bodySetter, OAuthAsyncRequestCallback callback, + String completeUrl, BodySetter bodySetter, Object bodyContents, OAuthAsyncRequestCallback callback, OAuthRequestAsync.ResponseConverter converter) { BoundRequestBuilder boundRequestBuilder; switch (httpVerb) { @@ -83,7 +83,7 @@ private Future doExecuteAsync(String userAgent, Map heade if (!headers.containsKey(AbstractRequest.CONTENT_TYPE)) { boundRequestBuilder = boundRequestBuilder.addHeader(AbstractRequest.CONTENT_TYPE, DEFAULT_CONTENT_TYPE); } - boundRequestBuilder = bodySetter.setBody(boundRequestBuilder); + boundRequestBuilder = bodySetter.setBody(boundRequestBuilder, bodyContents); } for (Map.Entry header : headers.entrySet()) { @@ -93,55 +93,29 @@ private Future doExecuteAsync(String userAgent, Map heade boundRequestBuilder.setHeader(OAuthConstants.USER_AGENT_HEADER_NAME, userAgent); } - return boundRequestBuilder - .execute(new OAuthAsyncCompletionHandler<>( - callback, converter)); - } - - private interface BodySetter { - - BoundRequestBuilder setBody(BoundRequestBuilder requestBuilder); + return boundRequestBuilder.execute(new OAuthAsyncCompletionHandler<>(callback, converter)); } - private static class ByteArrayBodySetter implements BodySetter { - - private final byte[] bodyContents; - - private ByteArrayBodySetter(byte[] bodyContents) { - this.bodyContents = bodyContents; - } - - @Override - public BoundRequestBuilder setBody(BoundRequestBuilder requestBuilder) { - return requestBuilder.setBody(bodyContents); - } - } - - private static class StringBodySetter implements BodySetter { - - private final String bodyContents; - - private StringBodySetter(String bodyContents) { - this.bodyContents = bodyContents; - } - - @Override - public BoundRequestBuilder setBody(BoundRequestBuilder requestBuilder) { - return requestBuilder.setBody(bodyContents); - } - } - - private static class FileBodySetter implements BodySetter { - - private final File bodyContents; - - private FileBodySetter(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 BoundRequestBuilder setBody(BoundRequestBuilder requestBuilder) { - return 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 f75c645c1..26b6c41a4 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 @@ -38,8 +38,8 @@ public Future executeAsync(String userAgent, Map headers, byte[] bodyContents, OAuthAsyncRequestCallback callback, OAuthRequestAsync.ResponseConverter converter) { - return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, new ByteArrayBodySetter(bodyContents), - callback, converter); + return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, BodySetter.BYTE_ARRAY, bodyContents, callback, + converter); } @Override @@ -47,7 +47,7 @@ public Future executeAsync(String userAgent, Map headers, String bodyContents, OAuthAsyncRequestCallback callback, OAuthRequestAsync.ResponseConverter converter) { - return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, new StringBodySetter(bodyContents), callback, + return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, BodySetter.STRING, bodyContents, callback, converter); } @@ -56,12 +56,12 @@ public Future executeAsync(String userAgent, Map headers, File bodyContents, OAuthAsyncRequestCallback callback, OAuthRequestAsync.ResponseConverter converter) { - return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, new FileBodySetter(bodyContents), callback, + return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, BodySetter.FILE, bodyContents, callback, converter); } private Future doExecuteAsync(String userAgent, Map headers, Verb httpVerb, - String completeUrl, BodySetter bodySetter, OAuthAsyncRequestCallback callback, + String completeUrl, BodySetter bodySetter, Object bodyContents, OAuthAsyncRequestCallback callback, OAuthRequestAsync.ResponseConverter converter) { AsyncHttpClient.BoundRequestBuilder boundRequestBuilder; switch (httpVerb) { @@ -85,7 +85,7 @@ private Future doExecuteAsync(String userAgent, Map heade if (!headers.containsKey(AbstractRequest.CONTENT_TYPE)) { boundRequestBuilder = boundRequestBuilder.addHeader(AbstractRequest.CONTENT_TYPE, DEFAULT_CONTENT_TYPE); } - boundRequestBuilder = bodySetter.setBody(boundRequestBuilder); + boundRequestBuilder = bodySetter.setBody(boundRequestBuilder, bodyContents); } for (Map.Entry header : headers.entrySet()) { @@ -95,55 +95,33 @@ private Future doExecuteAsync(String userAgent, Map heade boundRequestBuilder.setHeader(OAuthConstants.USER_AGENT_HEADER_NAME, userAgent); } - return boundRequestBuilder - .execute(new OAuthAsyncCompletionHandler<>( - callback, converter)); - } - - private interface BodySetter { - - AsyncHttpClient.BoundRequestBuilder setBody(AsyncHttpClient.BoundRequestBuilder requestBuilder); + return boundRequestBuilder.execute(new OAuthAsyncCompletionHandler<>(callback, converter)); } - private static class ByteArrayBodySetter implements BodySetter { - - private final byte[] bodyContents; - - private ByteArrayBodySetter(byte[] bodyContents) { - this.bodyContents = bodyContents; - } - - @Override - public AsyncHttpClient.BoundRequestBuilder setBody(AsyncHttpClient.BoundRequestBuilder requestBuilder) { - return requestBuilder.setBody(bodyContents); - } - } - - private static class StringBodySetter implements BodySetter { - - private final String bodyContents; - - private StringBodySetter(String bodyContents) { - this.bodyContents = bodyContents; - } - - @Override - public AsyncHttpClient.BoundRequestBuilder setBody(AsyncHttpClient.BoundRequestBuilder requestBuilder) { - return requestBuilder.setBody(bodyContents); - } - } - - private static class FileBodySetter implements BodySetter { - - private final File bodyContents; - - private FileBodySetter(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 AsyncHttpClient.BoundRequestBuilder setBody(AsyncHttpClient.BoundRequestBuilder requestBuilder) { - return requestBuilder.setBody(bodyContents); - } + abstract AsyncHttpClient.BoundRequestBuilder setBody(AsyncHttpClient.BoundRequestBuilder requestBuilder, + Object bodyContents); } } diff --git a/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OAuthAsyncCompletionHandler.java b/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OAuthAsyncCompletionHandler.java index 9ae280c88..189781669 100644 --- a/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OAuthAsyncCompletionHandler.java +++ b/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OAuthAsyncCompletionHandler.java @@ -10,28 +10,18 @@ import java.io.IOException; import java.util.HashMap; import java.util.Map; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; -class OAuthAsyncCompletionHandler implements Callback, Future { +class OAuthAsyncCompletionHandler implements Callback { private final OAuthAsyncRequestCallback callback; private final OAuthRequestAsync.ResponseConverter converter; - private final Call call; - private final CountDownLatch latch; - private T result; + private final OkHttpFuture okHttpFuture; OAuthAsyncCompletionHandler(OAuthAsyncRequestCallback callback, - OAuthRequestAsync.ResponseConverter converter, Call call) { + OAuthRequestAsync.ResponseConverter converter, OkHttpFuture okHttpFuture) { this.callback = callback; this.converter = converter; - this.call = call; - this.latch = new CountDownLatch(1); - - call.enqueue(this); + this.okHttpFuture = okHttpFuture; } @Override @@ -41,7 +31,7 @@ public void onFailure(Call call, IOException e) { callback.onThrowable(e); } } finally { - latch.countDown(); + okHttpFuture.finish(); } } @@ -63,40 +53,12 @@ public void onResponse(Call call, okhttp3.Response okHttpResponse) throws IOExce @SuppressWarnings("unchecked") final T t = converter == null ? (T) response : converter.convert(response); - result = t; + okHttpFuture.setResult(t); if (callback != null) { callback.onCompleted(t); } } finally { - latch.countDown(); + okHttpFuture.finish(); } } - - @Override - public boolean cancel(boolean mayInterruptIfRunning) { - call.cancel(); - return call.isCanceled(); - } - - @Override - public boolean isCancelled() { - return call.isCanceled(); - } - - @Override - public boolean isDone() { - return call.isExecuted(); - } - - @Override - public T get() throws InterruptedException, ExecutionException { - latch.await(); - return result; - } - - @Override - public T get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { - latch.await(timeout, unit); - return result; - } } diff --git a/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpFuture.java b/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpFuture.java new file mode 100644 index 000000000..ebf459260 --- /dev/null +++ b/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpFuture.java @@ -0,0 +1,59 @@ +package com.github.scribejava.httpclient.okhttp; + +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; +import okhttp3.Call; + +public class OkHttpFuture implements Future { + + private final CountDownLatch latch = new CountDownLatch(1); + private final Call call; + private T result; + + public OkHttpFuture(Call call) { + this.call = call; + } + + @Override + public boolean cancel(boolean mayInterruptIfRunning) { + call.cancel(); + return call.isCanceled(); + } + + @Override + public boolean isCancelled() { + return call.isCanceled(); + } + + @Override + public boolean isDone() { + return call.isExecuted(); + } + + @Override + public T get() throws InterruptedException, ExecutionException { + latch.await(); + return result; + } + + @Override + public T get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { + if (latch.await(timeout, unit)) { + return result; + } else { + throw new TimeoutException(); + } + } + + void finish() { + latch.countDown(); + } + + void setResult(T result) { + this.result = result; + } + +} diff --git a/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java b/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java index 57f90ca5f..45beb8c41 100644 --- a/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java +++ b/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java @@ -18,13 +18,17 @@ import java.util.concurrent.Future; import static com.github.scribejava.core.model.AbstractRequest.DEFAULT_CONTENT_TYPE; +import java.io.File; +import okhttp3.Cache; public class OkHttpHttpClient implements HttpClient { + private static final MediaType DEFAULT_CONTENT_TYPE_MEDIA_TYPE = MediaType.parse(DEFAULT_CONTENT_TYPE); + private final OkHttpClient client; public OkHttpHttpClient(OkHttpHttpClientConfig config) { - client = config.getClient(); + client = config.getClientBuilder().build(); } public OkHttpHttpClient(OkHttpClient client) { @@ -33,24 +37,55 @@ public OkHttpHttpClient(OkHttpClient client) { @Override public void close() throws IOException { - //client.close(); + client.dispatcher().executorService().shutdown(); + client.connectionPool().evictAll(); + final Cache cache = client.cache(); + if (cache != null) { + cache.close(); + } + } + + @Override + public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, + byte[] bodyContents, OAuthAsyncRequestCallback callback, + OAuthRequestAsync.ResponseConverter converter) { + return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, BodyType.BYTE_ARRAY, bodyContents, callback, + converter); + } + + @Override + public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, + String bodyContents, OAuthAsyncRequestCallback callback, + OAuthRequestAsync.ResponseConverter converter) { + return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, BodyType.STRING, bodyContents, callback, + converter); } @Override public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, - String bodyContents, OAuthAsyncRequestCallback callback, - OAuthRequestAsync.ResponseConverter converter) { + File bodyContents, OAuthAsyncRequestCallback callback, + OAuthRequestAsync.ResponseConverter converter) { + return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, BodyType.FILE, bodyContents, callback, + converter); + } + + private Future doExecuteAsync(String userAgent, Map headers, Verb httpVerb, + String completeUrl, BodyType bodyType, Object bodyContents, OAuthAsyncRequestCallback callback, + OAuthRequestAsync.ResponseConverter converter) { final Request.Builder requestBuilder = new Request.Builder(); requestBuilder.url(completeUrl); final String method = httpVerb.name(); // prepare body - RequestBody body = null; + final RequestBody body; if (bodyContents != null && HttpMethod.permitsRequestBody(method)) { - final String contentType = headers.containsKey(AbstractRequest.CONTENT_TYPE) ? - headers.get(AbstractRequest.CONTENT_TYPE) : DEFAULT_CONTENT_TYPE; - body = RequestBody.create(MediaType.parse(contentType), bodyContents); + final MediaType mediaType = headers.containsKey(AbstractRequest.CONTENT_TYPE) + ? MediaType.parse(headers.get(AbstractRequest.CONTENT_TYPE)) : DEFAULT_CONTENT_TYPE_MEDIA_TYPE; + + body = bodyType.createBody(mediaType, bodyContents); + } else { + body = null; } // fill HTTP method and body @@ -66,6 +101,31 @@ public Future executeAsync(String userAgent, Map headers, // create a new call final Call call = client.newCall(requestBuilder.build()); - return new OAuthAsyncCompletionHandler<>(callback, converter, call); + final OkHttpFuture okHttpFuture = new OkHttpFuture<>(call); + call.enqueue(new OAuthAsyncCompletionHandler<>(callback, converter, okHttpFuture)); + return okHttpFuture; + } + + private enum BodyType { + BYTE_ARRAY { + @Override + RequestBody createBody(MediaType mediaType, Object bodyContents) { + return RequestBody.create(mediaType, (byte[]) bodyContents); + } + }, + STRING { + @Override + RequestBody createBody(MediaType mediaType, Object bodyContents) { + return RequestBody.create(mediaType, (String) bodyContents); + } + }, + FILE { + @Override + RequestBody createBody(MediaType mediaType, Object bodyContents) { + return RequestBody.create(mediaType, (File) bodyContents); + } + }; + + abstract RequestBody createBody(MediaType mediaType, Object bodyContents); } } diff --git a/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClientConfig.java b/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClientConfig.java index b5acae110..e536fd810 100644 --- a/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClientConfig.java +++ b/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClientConfig.java @@ -5,13 +5,13 @@ public class OkHttpHttpClientConfig implements HttpClient.Config { - private final OkHttpClient client; + private final OkHttpClient.Builder clientBuilder; - public OkHttpHttpClientConfig(OkHttpClient client) { - this.client = client; + public OkHttpHttpClientConfig(OkHttpClient.Builder clientBuilder) { + this.clientBuilder = clientBuilder; } - public OkHttpClient getClient() { - return client; + public OkHttpClient.Builder getClientBuilder() { + return clientBuilder; } } diff --git a/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClientTest.java b/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClientTest.java index b1968dcb3..97b8cbad6 100644 --- a/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClientTest.java +++ b/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClientTest.java @@ -16,7 +16,6 @@ import org.junit.Before; import org.junit.Test; -import java.net.MalformedURLException; import java.util.concurrent.TimeUnit; import static org.junit.Assert.assertEquals; @@ -25,7 +24,7 @@ public class OkHttpHttpClientTest { private OAuthService oAuthService; @Before - public void setUp() throws MalformedURLException { + public void setUp() { final HttpClient client = new OkHttpHttpClient(new OkHttpClient()); oAuthService = new OAuth20Service(null, new OAuthConfig("test", "test", null, null, null, null, null, null, null, null, null, null, client)); @@ -42,8 +41,8 @@ public void shouldSendGetRequest() throws Exception { final HttpUrl baseUrl = server.url("/testUrl"); - final OAuthRequestAsync request = new OAuthRequestAsync(Verb.GET, baseUrl.toString(), oAuthService); - final Response response = request.sendAsync(null).get(30, TimeUnit.SECONDS); + final OAuthRequestAsync request = new OAuthRequestAsync(Verb.GET, baseUrl.toString()); + final Response response = oAuthService.execute(request, null).get(30, TimeUnit.SECONDS); assertEquals(expectedResponseBody, response.getBody()); @@ -66,9 +65,9 @@ public void shouldSendPostRequest() throws Exception { final HttpUrl baseUrl = server.url("/testUrl"); // request with body - OAuthRequestAsync request = new OAuthRequestAsync(Verb.POST, baseUrl.toString(), oAuthService); - request.addPayload(expectedRequestBody); - Response response = request.sendAsync(null).get(30, TimeUnit.SECONDS); + OAuthRequestAsync request = new OAuthRequestAsync(Verb.POST, baseUrl.toString()); + request.setPayload(expectedRequestBody); + Response response = oAuthService.execute(request, null).get(30, TimeUnit.SECONDS); assertEquals(expectedResponseBody, response.getBody()); @@ -78,8 +77,8 @@ public void shouldSendPostRequest() throws Exception { // request with empty body - request = new OAuthRequestAsync(Verb.POST, baseUrl.toString(), oAuthService); - response = request.sendAsync(null).get(30, TimeUnit.SECONDS); + request = new OAuthRequestAsync(Verb.POST, baseUrl.toString()); + response = oAuthService.execute(request, null).get(30, TimeUnit.SECONDS); assertEquals(expectedResponseBody, response.getBody()); @@ -100,8 +99,8 @@ public void shouldReadResponseStream() throws Exception { final HttpUrl baseUrl = server.url("/testUrl"); - final OAuthRequestAsync request = new OAuthRequestAsync(Verb.GET, baseUrl.toString(), oAuthService); - final Response response = request.sendAsync(null).get(30, TimeUnit.SECONDS); + final OAuthRequestAsync request = new OAuthRequestAsync(Verb.GET, baseUrl.toString()); + final Response response = oAuthService.execute(request, null).get(30, TimeUnit.SECONDS); assertEquals(expectedResponseBody, StreamUtils.getStreamContents(response.getStream())); From 65761bb1bcefd1299f47c8572501ced3cb3e2c02 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 8 Dec 2016 18:00:10 +0300 Subject: [PATCH 322/882] add default HTTP client configs (to use like 'new ServiceBuilder().httpClientConfig(OkHttpHttpClientConfig.defaultConfig())') --- changelog | 1 + .../examples/GitHubAsyncOkHttpExample.java | 4 +- .../examples/Google20AsyncAHCExample.java | 4 +- .../core/builder/ServiceBuilder.java | 19 +++++++-- .../core/httpclient/HttpClient.java | 26 ++++++++++++ .../core/httpclient/HttpClientConfig.java | 6 +++ .../core/httpclient/HttpClientProvider.java | 4 +- .../scribejava/core/model/HttpClient.java | 11 +++++ .../scribejava/core/model/OAuthConfig.java | 41 ++++++++++++++++--- .../scribejava/core/oauth/OAuthService.java | 7 ++-- .../httpclient/ahc/AhcHttpClient.java | 6 ++- .../httpclient/ahc/AhcHttpClientConfig.java | 13 +++++- .../httpclient/ahc/AhcProvider.java | 5 ++- .../httpclient/ning/NingHttpClient.java | 14 +++++-- .../httpclient/ning/NingHttpClientConfig.java | 13 +++++- .../httpclient/ning/NingProvider.java | 5 ++- .../httpclient/okhttp/OkHttpHttpClient.java | 5 ++- .../okhttp/OkHttpHttpClientConfig.java | 13 +++++- .../httpclient/okhttp/OkHttpProvider.java | 5 ++- .../okhttp/OkHttpHttpClientTest.java | 2 +- 20 files changed, 165 insertions(+), 39 deletions(-) create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/httpclient/HttpClient.java create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/httpclient/HttpClientConfig.java diff --git a/changelog b/changelog index 1eff1321c..189e1555b 100644 --- a/changelog +++ b/changelog @@ -4,6 +4,7 @@ * 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())') [3.3.0] * update Facebook v2.6 -> v2.8 diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubAsyncOkHttpExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubAsyncOkHttpExample.java index f3153f66e..fc8d5ec44 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubAsyncOkHttpExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubAsyncOkHttpExample.java @@ -8,7 +8,6 @@ import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.oauth.OAuth20Service; import com.github.scribejava.httpclient.okhttp.OkHttpHttpClientConfig; -import okhttp3.OkHttpClient; import java.io.IOException; import java.util.Random; @@ -28,13 +27,12 @@ public static void main(String... args) throws IOException, ExecutionException, final String clientId = "your client id"; final String clientSecret = "your client secret"; final String secretState = "secret" + new Random().nextInt(999_999); - final OkHttpClient.Builder okHttpBuilder = new OkHttpClient.Builder(); final OAuth20Service service = new ServiceBuilder() .apiKey(clientId) .apiSecret(clientSecret) .state(secretState) .callback("http://www.example.com/oauth_callback/") - .httpClientConfig(new OkHttpHttpClientConfig(okHttpBuilder)) + .httpClientConfig(OkHttpHttpClientConfig.defaultConfig()) .build(GitHubApi.instance()); final Scanner in = new Scanner(System.in, "UTF-8"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java index b760feeda..735b04911 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java @@ -6,7 +6,7 @@ import com.github.scribejava.httpclient.ahc.AhcHttpClientConfig; import com.github.scribejava.core.builder.ServiceBuilder; import com.github.scribejava.core.model.ForceTypeOfHttpRequest; -import com.github.scribejava.core.model.HttpClient; +import com.github.scribejava.core.httpclient.HttpClientConfig; import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthRequestAsync; import com.github.scribejava.core.model.Response; @@ -33,7 +33,7 @@ public static void main(String... args) throws InterruptedException, ExecutionEx final String clientSecret = "your client secret"; final String secretState = "secret" + new Random().nextInt(999_999); ScribeJavaConfig.setForceTypeOfHttpRequests(ForceTypeOfHttpRequest.FORCE_ASYNC_ONLY_HTTP_REQUESTS); - final HttpClient.Config clientConfig = new AhcHttpClientConfig(new DefaultAsyncHttpClientConfig.Builder() + final HttpClientConfig clientConfig = new AhcHttpClientConfig(new DefaultAsyncHttpClientConfig.Builder() .setMaxConnections(5) .setRequestTimeout(10_000) .setPooledConnectionIdleTimeout(1_000) 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 b45555f93..e34f3316f 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilder.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilder.java @@ -1,7 +1,8 @@ package com.github.scribejava.core.builder; import com.github.scribejava.core.builder.api.BaseApi; -import com.github.scribejava.core.model.HttpClient; +import com.github.scribejava.core.httpclient.HttpClient; +import com.github.scribejava.core.httpclient.HttpClientConfig; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.SignatureType; @@ -30,7 +31,7 @@ public class ServiceBuilder { private Integer readTimeout; //not-default httpclient only - private HttpClient.Config httpClientConfig; + private HttpClientConfig httpClientConfig; private HttpClient httpClient; public ServiceBuilder() { @@ -134,7 +135,19 @@ public ServiceBuilder readTimeout(Integer readTimeout) { return this; } - public ServiceBuilder httpClientConfig(HttpClient.Config httpClientConfig) { + /** + * throws UnsupportedOperationException + * + * @param httpClientConfig httpClientConfig + * @return never + * @deprecated use {@link #httpClientConfig(com.github.scribejava.core.httpclient.HttpClientConfig)} + */ + @Deprecated + public ServiceBuilder httpClientConfig(com.github.scribejava.core.model.HttpClient.Config httpClientConfig) { + throw new UnsupportedOperationException("deprecated, use another method, see javadocs"); + } + + public ServiceBuilder httpClientConfig(HttpClientConfig httpClientConfig) { Preconditions.checkNotNull(httpClientConfig, "httpClientConfig can't be null"); this.httpClientConfig = httpClientConfig; return this; diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/HttpClient.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/HttpClient.java new file mode 100644 index 000000000..fba0ef215 --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/HttpClient.java @@ -0,0 +1,26 @@ +package com.github.scribejava.core.httpclient; + +import com.github.scribejava.core.model.OAuthAsyncRequestCallback; +import com.github.scribejava.core.model.OAuthRequestAsync; +import com.github.scribejava.core.model.Verb; +import java.io.File; +import java.io.IOException; +import java.util.Map; +import java.util.concurrent.Future; + +public interface HttpClient { + + void close() throws IOException; + + Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, + byte[] bodyContents, OAuthAsyncRequestCallback callback, + OAuthRequestAsync.ResponseConverter converter); + + Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, + String bodyContents, OAuthAsyncRequestCallback callback, + OAuthRequestAsync.ResponseConverter converter); + + Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, + File bodyContents, OAuthAsyncRequestCallback callback, OAuthRequestAsync.ResponseConverter converter); + +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/HttpClientConfig.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/HttpClientConfig.java new file mode 100644 index 000000000..3c28d6249 --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/HttpClientConfig.java @@ -0,0 +1,6 @@ +package com.github.scribejava.core.httpclient; + +public interface HttpClientConfig { + + HttpClientConfig createDefaultConfig(); +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/HttpClientProvider.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/HttpClientProvider.java index d7667ee20..5b69156d2 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/HttpClientProvider.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/HttpClientProvider.java @@ -1,8 +1,6 @@ package com.github.scribejava.core.httpclient; -import com.github.scribejava.core.model.HttpClient; - public interface HttpClientProvider { - HttpClient createClient(HttpClient.Config httpClientConfig); + HttpClient createClient(HttpClientConfig httpClientConfig); } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/HttpClient.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/HttpClient.java index 339e2d7f4..7d0d45078 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/HttpClient.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/HttpClient.java @@ -5,6 +5,11 @@ import java.util.Map; import java.util.concurrent.Future; +/** + * + * @deprecated use {@link com.github.scribejava.core.httpclient.HttpClient} + */ +@Deprecated public interface HttpClient { void close() throws IOException; @@ -20,6 +25,12 @@ Future executeAsync(String userAgent, Map headers, Verb h Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, File bodyContents, OAuthAsyncRequestCallback callback, OAuthRequestAsync.ResponseConverter converter); + /** + * + * @deprecated use {@link com.github.scribejava.core.httpclient.HttpClientConfig} + */ + @Deprecated interface Config { + } } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConfig.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConfig.java index 0a6e44894..37be3f2a0 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConfig.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConfig.java @@ -1,5 +1,6 @@ package com.github.scribejava.core.model; +import com.github.scribejava.core.httpclient.HttpClientConfig; import java.io.IOException; import java.io.OutputStream; @@ -23,16 +24,46 @@ public class OAuthConfig { private final Integer readTimeout; //async version only - private HttpClient.Config httpClientConfig; - private HttpClient httpClient; + private HttpClientConfig httpClientConfig; + private com.github.scribejava.core.httpclient.HttpClient httpClient; public OAuthConfig(String key, String secret) { - this(key, secret, null, null, null, null, null, null, null, null, null, null, null); + this(key, secret, null, null, null, null, null, null, null, null, null, (HttpClientConfig) null, null); } + /** + * throws UnsupportedOperationException + * + * @param apiKey apiKey + * @param apiSecret apiSecret + * @param callback callback + * @param signatureType signatureType + * @param scope scope + * @param debugStream debugStream + * @param state state + * @param responseType responseType + * @param userAgent userAgent + * @param connectTimeout connectTimeout + * @param readTimeout readTimeout + * @param httpClientConfig httpClientConfig + * @param httpClient httpClient + * @deprecated use + * {@link #OAuthConfig(java.lang.String, java.lang.String, java.lang.String, + * com.github.scribejava.core.model.SignatureType, java.lang.String, java.io.OutputStream, java.lang.String, + * java.lang.String, java.lang.String, java.lang.Integer, java.lang.Integer, + * com.github.scribejava.core.httpclient.HttpClientConfig, com.github.scribejava.core.httpclient.HttpClient)} + */ + @Deprecated public OAuthConfig(String apiKey, String apiSecret, String callback, SignatureType signatureType, String scope, OutputStream debugStream, String state, String responseType, String userAgent, Integer connectTimeout, Integer readTimeout, HttpClient.Config httpClientConfig, HttpClient httpClient) { + throw new UnsupportedOperationException("deprecated, use another method, see javadocs"); + } + + public OAuthConfig(String apiKey, String apiSecret, String callback, SignatureType signatureType, String scope, + OutputStream debugStream, String state, String responseType, String userAgent, Integer connectTimeout, + Integer readTimeout, HttpClientConfig httpClientConfig, + com.github.scribejava.core.httpclient.HttpClient httpClient) { this.apiKey = apiKey; this.apiSecret = apiSecret; this.callback = callback; @@ -99,11 +130,11 @@ public Integer getReadTimeout() { return readTimeout; } - public HttpClient.Config getHttpClientConfig() { + public HttpClientConfig getHttpClientConfig() { return httpClientConfig; } - public HttpClient getHttpClient() { + public com.github.scribejava.core.httpclient.HttpClient getHttpClient() { return httpClient; } } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java index 19d9af62d..3ea22dade 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java @@ -4,7 +4,8 @@ import com.github.scribejava.core.httpclient.HttpClientProvider; import com.github.scribejava.core.model.AbstractRequest; import com.github.scribejava.core.model.ForceTypeOfHttpRequest; -import com.github.scribejava.core.model.HttpClient; +import com.github.scribejava.core.httpclient.HttpClient; +import com.github.scribejava.core.httpclient.HttpClientConfig; import com.github.scribejava.core.model.OAuthAsyncRequestCallback; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthRequest; @@ -34,7 +35,7 @@ public abstract class OAuthService { public OAuthService(OAuthConfig config) { this.config = config; final ForceTypeOfHttpRequest forceTypeOfHttpRequest = ScribeJavaConfig.getForceTypeOfHttpRequests(); - final HttpClient.Config httpClientConfig = config.getHttpClientConfig(); + final HttpClientConfig httpClientConfig = config.getHttpClientConfig(); final HttpClient externalHttpClient = config.getHttpClient(); if (httpClientConfig == null && externalHttpClient == null) { @@ -57,7 +58,7 @@ public OAuthService(OAuthConfig config) { } } - private static HttpClient getClient(HttpClient.Config config) { + private static HttpClient getClient(HttpClientConfig config) { for (HttpClientProvider provider : ServiceLoader.load(HttpClientProvider.class)) { final HttpClient client = provider.createClient(config); if (client != null) { 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 60d5c92cd..4426946c8 100644 --- a/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/AhcHttpClient.java +++ b/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/AhcHttpClient.java @@ -1,7 +1,7 @@ package com.github.scribejava.httpclient.ahc; import com.github.scribejava.core.model.AbstractRequest; -import com.github.scribejava.core.model.HttpClient; +import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.model.OAuthAsyncRequestCallback; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.OAuthRequestAsync; @@ -15,6 +15,7 @@ import static com.github.scribejava.core.model.AbstractRequest.DEFAULT_CONTENT_TYPE; import java.io.File; +import org.asynchttpclient.AsyncHttpClientConfig; import org.asynchttpclient.BoundRequestBuilder; public class AhcHttpClient implements HttpClient { @@ -22,7 +23,8 @@ public class AhcHttpClient implements HttpClient { private final AsyncHttpClient client; public AhcHttpClient(AhcHttpClientConfig ahcConfig) { - client = new DefaultAsyncHttpClient(ahcConfig.getClientConfig()); + final AsyncHttpClientConfig clientConfig = ahcConfig.getClientConfig(); + client = clientConfig == null ? new DefaultAsyncHttpClient() : new DefaultAsyncHttpClient(clientConfig); } public AhcHttpClient(DefaultAsyncHttpClient ahcClient) { diff --git a/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/AhcHttpClientConfig.java b/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/AhcHttpClientConfig.java index bc6820281..67fc92bdf 100644 --- a/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/AhcHttpClientConfig.java +++ b/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/AhcHttpClientConfig.java @@ -1,9 +1,9 @@ package com.github.scribejava.httpclient.ahc; -import com.github.scribejava.core.model.HttpClient; +import com.github.scribejava.core.httpclient.HttpClientConfig; import org.asynchttpclient.AsyncHttpClientConfig; -public class AhcHttpClientConfig implements HttpClient.Config { +public class AhcHttpClientConfig implements HttpClientConfig { private final AsyncHttpClientConfig clientConfig; @@ -14,4 +14,13 @@ public AhcHttpClientConfig(AsyncHttpClientConfig clientConfig) { public AsyncHttpClientConfig getClientConfig() { return clientConfig; } + + @Override + public HttpClientConfig createDefaultConfig() { + return defaultConfig(); + } + + public static HttpClientConfig defaultConfig() { + return new AhcHttpClientConfig(null); + } } diff --git a/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/AhcProvider.java b/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/AhcProvider.java index 835ba5f03..97c21dc86 100644 --- a/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/AhcProvider.java +++ b/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/AhcProvider.java @@ -1,12 +1,13 @@ package com.github.scribejava.httpclient.ahc; import com.github.scribejava.core.httpclient.HttpClientProvider; -import com.github.scribejava.core.model.HttpClient; +import com.github.scribejava.core.httpclient.HttpClient; +import com.github.scribejava.core.httpclient.HttpClientConfig; public class AhcProvider implements HttpClientProvider { @Override - public HttpClient createClient(HttpClient.Config config) { + public HttpClient createClient(HttpClientConfig config) { if (config instanceof AhcHttpClientConfig) { return new AhcHttpClient((AhcHttpClientConfig) config); } 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 26b6c41a4..b2fced5e5 100644 --- a/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/NingHttpClient.java +++ b/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/NingHttpClient.java @@ -1,7 +1,7 @@ package com.github.scribejava.httpclient.ning; import com.github.scribejava.core.model.AbstractRequest; -import com.github.scribejava.core.model.HttpClient; +import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.model.OAuthAsyncRequestCallback; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.OAuthRequestAsync; @@ -12,6 +12,7 @@ import java.util.concurrent.Future; import static com.github.scribejava.core.model.AbstractRequest.DEFAULT_CONTENT_TYPE; +import com.ning.http.client.AsyncHttpClientConfig; import java.io.File; public class NingHttpClient implements HttpClient { @@ -20,8 +21,15 @@ public class NingHttpClient implements HttpClient { public NingHttpClient(NingHttpClientConfig ningConfig) { final String ningAsyncHttpProviderClassName = ningConfig.getNingAsyncHttpProviderClassName(); - client = ningAsyncHttpProviderClassName == null ? new AsyncHttpClient(ningConfig.getConfig()) - : new AsyncHttpClient(ningAsyncHttpProviderClassName, ningConfig.getConfig()); + AsyncHttpClientConfig config = ningConfig.getConfig(); + if (ningAsyncHttpProviderClassName == null) { + client = config == null ? new AsyncHttpClient() : new AsyncHttpClient(config); + } else { + if (config == null) { + config = new AsyncHttpClientConfig.Builder().build(); + } + client = new AsyncHttpClient(ningAsyncHttpProviderClassName, config); + } } public NingHttpClient(AsyncHttpClient client) { diff --git a/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/NingHttpClientConfig.java b/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/NingHttpClientConfig.java index f25d91e54..1dc5aad2a 100644 --- a/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/NingHttpClientConfig.java +++ b/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/NingHttpClientConfig.java @@ -1,9 +1,9 @@ package com.github.scribejava.httpclient.ning; -import com.github.scribejava.core.model.HttpClient; +import com.github.scribejava.core.httpclient.HttpClientConfig; import com.ning.http.client.AsyncHttpClientConfig; -public class NingHttpClientConfig implements HttpClient.Config { +public class NingHttpClientConfig implements HttpClientConfig { private final AsyncHttpClientConfig config; private String ningAsyncHttpProviderClassName; @@ -23,4 +23,13 @@ public void setNingAsyncHttpProviderClassName(String ningAsyncHttpProviderClassN public AsyncHttpClientConfig getConfig() { return config; } + + @Override + public HttpClientConfig createDefaultConfig() { + return defaultConfig(); + } + + public static HttpClientConfig defaultConfig() { + return new NingHttpClientConfig(null); + } } diff --git a/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/NingProvider.java b/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/NingProvider.java index bfd4bce96..2db967249 100644 --- a/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/NingProvider.java +++ b/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/NingProvider.java @@ -1,12 +1,13 @@ package com.github.scribejava.httpclient.ning; import com.github.scribejava.core.httpclient.HttpClientProvider; -import com.github.scribejava.core.model.HttpClient; +import com.github.scribejava.core.httpclient.HttpClient; +import com.github.scribejava.core.httpclient.HttpClientConfig; public class NingProvider implements HttpClientProvider { @Override - public HttpClient createClient(HttpClient.Config httpClientConfig) { + public HttpClient createClient(HttpClientConfig httpClientConfig) { if (httpClientConfig instanceof NingHttpClientConfig) { return new NingHttpClient((NingHttpClientConfig) httpClientConfig); } diff --git a/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java b/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java index 45beb8c41..e41011991 100644 --- a/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java +++ b/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java @@ -1,7 +1,7 @@ package com.github.scribejava.httpclient.okhttp; import com.github.scribejava.core.model.AbstractRequest; -import com.github.scribejava.core.model.HttpClient; +import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.model.OAuthAsyncRequestCallback; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.OAuthRequestAsync; @@ -28,7 +28,8 @@ public class OkHttpHttpClient implements HttpClient { private final OkHttpClient client; public OkHttpHttpClient(OkHttpHttpClientConfig config) { - client = config.getClientBuilder().build(); + final OkHttpClient.Builder clientBuilder = config.getClientBuilder(); + client = clientBuilder == null ? new OkHttpClient() : clientBuilder.build(); } public OkHttpHttpClient(OkHttpClient client) { diff --git a/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClientConfig.java b/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClientConfig.java index e536fd810..62737fe31 100644 --- a/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClientConfig.java +++ b/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClientConfig.java @@ -1,9 +1,9 @@ package com.github.scribejava.httpclient.okhttp; -import com.github.scribejava.core.model.HttpClient; +import com.github.scribejava.core.httpclient.HttpClientConfig; import okhttp3.OkHttpClient; -public class OkHttpHttpClientConfig implements HttpClient.Config { +public class OkHttpHttpClientConfig implements HttpClientConfig { private final OkHttpClient.Builder clientBuilder; @@ -14,4 +14,13 @@ public OkHttpHttpClientConfig(OkHttpClient.Builder clientBuilder) { public OkHttpClient.Builder getClientBuilder() { return clientBuilder; } + + @Override + public HttpClientConfig createDefaultConfig() { + return defaultConfig(); + } + + public static HttpClientConfig defaultConfig() { + return new OkHttpHttpClientConfig(null); + } } diff --git a/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpProvider.java b/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpProvider.java index 3dbfcba5d..4d27f5f0c 100644 --- a/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpProvider.java +++ b/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpProvider.java @@ -1,12 +1,13 @@ package com.github.scribejava.httpclient.okhttp; import com.github.scribejava.core.httpclient.HttpClientProvider; -import com.github.scribejava.core.model.HttpClient; +import com.github.scribejava.core.httpclient.HttpClient; +import com.github.scribejava.core.httpclient.HttpClientConfig; public class OkHttpProvider implements HttpClientProvider { @Override - public HttpClient createClient(HttpClient.Config config) { + public HttpClient createClient(HttpClientConfig config) { if (config instanceof OkHttpHttpClientConfig) { return new OkHttpHttpClient((OkHttpHttpClientConfig) config); } diff --git a/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClientTest.java b/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClientTest.java index 97b8cbad6..917fe1ce8 100644 --- a/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClientTest.java +++ b/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClientTest.java @@ -1,6 +1,6 @@ package com.github.scribejava.httpclient.okhttp; -import com.github.scribejava.core.model.HttpClient; +import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthRequestAsync; import com.github.scribejava.core.model.Response; From d59818211179ba4b04fa129ae13f5e47d87ce8bf Mon Sep 17 00:00:00 2001 From: Gabriel Titerlea Date: Tue, 6 Dec 2016 15:57:02 +0200 Subject: [PATCH 323/882] Using interface instead of impl in AhcHttpClient. --- .../com/github/scribejava/httpclient/ahc/AhcHttpClient.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 4426946c8..74d3ac730 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 @@ -27,7 +27,7 @@ public AhcHttpClient(AhcHttpClientConfig ahcConfig) { client = clientConfig == null ? new DefaultAsyncHttpClient() : new DefaultAsyncHttpClient(clientConfig); } - public AhcHttpClient(DefaultAsyncHttpClient ahcClient) { + public AhcHttpClient(AsyncHttpClient ahcClient) { client = ahcClient; } From cab69546950fdfd48ff41bd33722214a7fd09849 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 8 Dec 2016 18:05:52 +0300 Subject: [PATCH 324/882] update changelog --- changelog | 1 + 1 file changed, 1 insertion(+) diff --git a/changelog b/changelog index 189e1555b..4d0136640 100644 --- a/changelog +++ b/changelog @@ -5,6 +5,7 @@ * 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())') + * you can use your own impl of AsyncHttpClient [3.3.0] * update Facebook v2.6 -> v2.8 From 18aa97b5ed6b21794748585424908c178594c7b6 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 8 Dec 2016 18:29:48 +0300 Subject: [PATCH 325/882] update checkstyle and OkHttp --- pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index f6c4aa233..5aae303c7 100644 --- a/pom.xml +++ b/pom.xml @@ -132,7 +132,7 @@ com.puppycrawl.tools checkstyle - 7.2 + 7.3 diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index b1b0a7a3d..3d2f016da 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -23,12 +23,12 @@ com.squareup.okhttp3 okhttp - 3.4.2 + 3.5.0 com.squareup.okhttp3 mockwebserver - 3.4.2 + 3.5.0 test From 5a64f30a76cfb675d895728aa9ffdc18644a043e Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 8 Dec 2016 19:15:12 +0300 Subject: [PATCH 326/882] prepare to release 3.4.0 --- README.md | 4 ++-- changelog | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index f2e576d29..93b7a9c2d 100644 --- a/README.md +++ b/README.md @@ -100,7 +100,7 @@ You can pull ScribeJava from the central maven repository, just add these to you com.github.scribejava scribejava-apis - 3.3.0 + 3.4.0 ``` @@ -109,7 +109,7 @@ And in case you need just core classes (that's it, without any external API (FB, com.github.scribejava scribejava-core - 3.3.0 + 3.4.0 ``` diff --git a/changelog b/changelog index 4d0136640..4b6baf4fd 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,4 @@ -[SNAPSHOT] +[3.4.0] * uncouple OAuthRequest and Service. OAuthRequest shouldn't know anything about OAuthservice. You don't need OAuthService to create OAuthRequest anymore. Async request should be sent via OAuthService method. * add support for byte[] and File (async only) payload in OAuth Requests (thanks to https://github.com/keijohyttinen) From c47e787ddab4c2fb88ab2bb6028b02a5d79148fc Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 8 Dec 2016 19:16:23 +0300 Subject: [PATCH 327/882] [maven-release-plugin] prepare release scribejava-3.4.0 --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/pom.xml b/pom.xml index 5aae303c7..5de98acda 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 3.3.1-SNAPSHOT + 3.4.0 ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -33,7 +33,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - HEAD + scribejava-3.4.0 diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index bc6f2dbd3..f23d9794e 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 3.3.1-SNAPSHOT + 3.4.0 ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 8bffdd6fc..667affac6 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 3.3.1-SNAPSHOT + 3.4.0 ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 0ccfc5f8d..bf22b97f0 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 3.3.1-SNAPSHOT + 3.4.0 ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index bd310a533..70ed01963 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 3.3.1-SNAPSHOT + 3.4.0 ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 3d2f016da..0323ddf88 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 3.3.1-SNAPSHOT + 3.4.0 ../pom.xml From 13d67a7fd0c48b6fd64eb3047b5530f8f7d411e9 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 8 Dec 2016 19:16:29 +0300 Subject: [PATCH 328/882] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/pom.xml b/pom.xml index 5de98acda..dc3506a62 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 3.4.0 + 3.4.1-SNAPSHOT ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -33,7 +33,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - scribejava-3.4.0 + HEAD diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index f23d9794e..cb5c6e443 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 3.4.0 + 3.4.1-SNAPSHOT ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 667affac6..470d5a534 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 3.4.0 + 3.4.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index bf22b97f0..08551999b 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 3.4.0 + 3.4.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index 70ed01963..7d7d6d3e3 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 3.4.0 + 3.4.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 0323ddf88..86365bfff 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 3.4.0 + 3.4.1-SNAPSHOT ../pom.xml From 83930b3e245d1d4d4e79729bc6d6b50f35433329 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 13 Dec 2016 12:23:45 +0300 Subject: [PATCH 329/882] drop deprecated methods --- .../core/builder/ServiceBuilder.java | 12 ---- .../core/model/AbstractRequest.java | 61 ------------------- .../scribejava/core/model/HttpClient.java | 36 ----------- .../scribejava/core/model/OAuthConfig.java | 31 +--------- .../scribejava/core/model/OAuthRequest.java | 13 ---- .../core/model/OAuthRequestAsync.java | 42 ------------- .../scribejava/core/oauth/OAuthService.java | 35 ----------- 7 files changed, 1 insertion(+), 229 deletions(-) delete mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/model/HttpClient.java 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 e34f3316f..dd1cc1989 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 @@ -135,18 +135,6 @@ public ServiceBuilder readTimeout(Integer readTimeout) { return this; } - /** - * throws UnsupportedOperationException - * - * @param httpClientConfig httpClientConfig - * @return never - * @deprecated use {@link #httpClientConfig(com.github.scribejava.core.httpclient.HttpClientConfig)} - */ - @Deprecated - public ServiceBuilder httpClientConfig(com.github.scribejava.core.model.HttpClient.Config httpClientConfig) { - throw new UnsupportedOperationException("deprecated, use another method, see javadocs"); - } - public ServiceBuilder httpClientConfig(HttpClientConfig httpClientConfig) { Preconditions.checkNotNull(httpClientConfig, "httpClientConfig can't be null"); this.httpClientConfig = httpClientConfig; diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/AbstractRequest.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/AbstractRequest.java index d31bdc658..3a5499c03 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/AbstractRequest.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/AbstractRequest.java @@ -7,7 +7,6 @@ import java.util.HashMap; import java.util.Map; import com.github.scribejava.core.exceptions.OAuthException; -import com.github.scribejava.core.oauth.OAuthService; import java.io.File; /** @@ -37,19 +36,6 @@ public abstract class AbstractRequest { private String realm; - /** - * Default constructor. - * - * @param verb Http verb/method - * @param url resource URL - * @param service OAuthService - * @deprecated use {@link #AbstractRequest(com.github.scribejava.core.model.Verb, java.lang.String)} - */ - @Deprecated - public AbstractRequest(Verb verb, String url, OAuthService service) { - this(verb, url); - } - /** * Default constructor. * @@ -145,24 +131,6 @@ protected boolean hasBodyContent() { return verb == Verb.PUT || verb == Verb.POST; } - /** - * @param payload payload - * @deprecated use {@link #setPayload(java.lang.String) } - */ - @Deprecated - public void addPayload(String payload) { - setPayload(payload); - } - - /** - * @param payload payload - * @deprecated use {@link #setPayload(byte[]) } - */ - @Deprecated - public void addPayload(byte[] payload) { - setPayload(payload); - } - /** * Set body payload. This method is used when the HTTP body is not a form-url-encoded string, but another thing. * Like for example XML. Note: The contents are not part of the OAuth signature @@ -251,15 +219,6 @@ public String getSanitizedUrl() { } } - /** - * @return value set in {@link #setPayload(java.lang.String)} - * @deprecated use {@link #getStringPayload()} or {@link #getByteArrayPayload()} - */ - @Deprecated - public String getBodyContents() { - return getStringPayload(); - } - /** * Returns the body of the request (set in {@link #setPayload(java.lang.String)}) * @@ -271,15 +230,6 @@ public String getStringPayload() { return stringPayload; } - /** - * @return value set in {@link #setPayload(byte[])} - * @deprecated use {@link #getByteArrayPayload() } - */ - @Deprecated - public byte[] getByteBodyContents() { - return getByteArrayPayload(); - } - /** * @return the body of the request (set in {@link #setPayload(byte[])} or in * {@link #addBodyParameter(java.lang.String, java.lang.String)} ) @@ -342,15 +292,4 @@ public void setFollowRedirects(boolean followRedirects) { public boolean isFollowRedirects() { return followRedirects; } - - /** - * always throws UnsupportedOperationException - * - * @return never - * @deprecated Request doesn't couple with Service anymore. It doesn't need it. Look for service somewhere else - */ - @Deprecated - public OAuthService getService() { - throw new UnsupportedOperationException(); - } } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/HttpClient.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/HttpClient.java deleted file mode 100644 index 7d0d45078..000000000 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/HttpClient.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.github.scribejava.core.model; - -import java.io.File; -import java.io.IOException; -import java.util.Map; -import java.util.concurrent.Future; - -/** - * - * @deprecated use {@link com.github.scribejava.core.httpclient.HttpClient} - */ -@Deprecated -public interface HttpClient { - - void close() throws IOException; - - Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, - byte[] bodyContents, OAuthAsyncRequestCallback callback, - OAuthRequestAsync.ResponseConverter converter); - - Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, - String bodyContents, OAuthAsyncRequestCallback callback, - OAuthRequestAsync.ResponseConverter converter); - - Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, - File bodyContents, OAuthAsyncRequestCallback callback, OAuthRequestAsync.ResponseConverter converter); - - /** - * - * @deprecated use {@link com.github.scribejava.core.httpclient.HttpClientConfig} - */ - @Deprecated - interface Config { - - } -} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConfig.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConfig.java index 37be3f2a0..b54c79180 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConfig.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConfig.java @@ -28,36 +28,7 @@ public class OAuthConfig { private com.github.scribejava.core.httpclient.HttpClient httpClient; public OAuthConfig(String key, String secret) { - this(key, secret, null, null, null, null, null, null, null, null, null, (HttpClientConfig) null, null); - } - - /** - * throws UnsupportedOperationException - * - * @param apiKey apiKey - * @param apiSecret apiSecret - * @param callback callback - * @param signatureType signatureType - * @param scope scope - * @param debugStream debugStream - * @param state state - * @param responseType responseType - * @param userAgent userAgent - * @param connectTimeout connectTimeout - * @param readTimeout readTimeout - * @param httpClientConfig httpClientConfig - * @param httpClient httpClient - * @deprecated use - * {@link #OAuthConfig(java.lang.String, java.lang.String, java.lang.String, - * com.github.scribejava.core.model.SignatureType, java.lang.String, java.io.OutputStream, java.lang.String, - * java.lang.String, java.lang.String, java.lang.Integer, java.lang.Integer, - * com.github.scribejava.core.httpclient.HttpClientConfig, com.github.scribejava.core.httpclient.HttpClient)} - */ - @Deprecated - public OAuthConfig(String apiKey, String apiSecret, String callback, SignatureType signatureType, String scope, - OutputStream debugStream, String state, String responseType, String userAgent, Integer connectTimeout, - Integer readTimeout, HttpClient.Config httpClientConfig, HttpClient httpClient) { - throw new UnsupportedOperationException("deprecated, use another method, see javadocs"); + this(key, secret, null, null, null, null, null, null, null, null, null, null, null); } public OAuthConfig(String apiKey, String apiSecret, String callback, SignatureType signatureType, String scope, 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 c0f35408a..d82153b3c 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 @@ -15,19 +15,6 @@ public class OAuthRequest extends AbstractRequest { private final OAuthConfig config; - /** - * - * @param verb verb - * @param url url - * @param service service - * @deprecated use {@link #OAuthRequest(com.github.scribejava.core.model.Verb, java.lang.String, - * com.github.scribejava.core.model.OAuthConfig)} - */ - @Deprecated - public OAuthRequest(Verb verb, String url, OAuthService service) { - this(verb, url, service.getConfig()); - } - public OAuthRequest(Verb verb, String url, OAuthConfig config) { super(verb, url); this.config = config; diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequestAsync.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequestAsync.java index 930fe5b76..f6bd48003 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequestAsync.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequestAsync.java @@ -1,55 +1,13 @@ package com.github.scribejava.core.model; -import com.github.scribejava.core.oauth.OAuthService; import java.io.IOException; -import java.util.concurrent.Future; public class OAuthRequestAsync extends AbstractRequest { - /** - * @param verb verb - * @param url url - * @param service service - * @deprecated use {@link #OAuthRequestAsync(com.github.scribejava.core.model.Verb, java.lang.String) } - */ - @Deprecated - public OAuthRequestAsync(Verb verb, String url, OAuthService service) { - this(verb, url); - } - public OAuthRequestAsync(Verb verb, String url) { super(verb, url); } - /** - * always throws UnsupportedOperationException - * - * @param T - * @param callback callback - * @param converter converter - * @return never - * @deprecated user {@link OAuthService#execute(com.github.scribejava.core.model.OAuthRequestAsync, - * com.github.scribejava.core.model.OAuthAsyncRequestCallback, - * com.github.scribejava.core.model.OAuthRequestAsync.ResponseConverter) } - */ - @Deprecated - public Future sendAsync(OAuthAsyncRequestCallback callback, ResponseConverter converter) { - throw new UnsupportedOperationException(); - } - - /** - * always throws UnsupportedOperationException - * - * @param callback callback - * @return never - * @deprecated user {@link OAuthService#execute(com.github.scribejava.core.model.OAuthRequestAsync, - * com.github.scribejava.core.model.OAuthAsyncRequestCallback) } - */ - @Deprecated - public Future sendAsync(OAuthAsyncRequestCallback callback) { - throw new UnsupportedOperationException(); - } - public interface ResponseConverter { T convert(Response response) throws IOException; diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java index 3ea22dade..82d46d549 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java @@ -13,11 +13,9 @@ import com.github.scribejava.core.model.Response; import com.github.scribejava.core.model.ScribeJavaConfig; import com.github.scribejava.core.model.Token; -import com.github.scribejava.core.model.Verb; import java.io.File; import java.io.IOException; -import java.util.Map; import java.util.ServiceLoader; import java.util.concurrent.Future; @@ -85,39 +83,6 @@ public OAuthConfig getConfig() { public abstract void signRequest(T token, AbstractRequest request); - /** - * - * @param T - * @param headers headers - * @param httpVerb httpVerb - * @param completeUrl completeUrl - * @param bodyContents bodyContents - * @param callback callback - * @param converter converter - * @return Future - * @deprecated use {@link #execute(com.github.scribejava.core.model.OAuthRequestAsync, - * com.github.scribejava.core.model.OAuthAsyncRequestCallback, - * com.github.scribejava.core.model.OAuthRequestAsync.ResponseConverter)}
- * or
{@link #execute(com.github.scribejava.core.model.OAuthRequestAsync, - * com.github.scribejava.core.model.OAuthAsyncRequestCallback)} - */ - @Deprecated - public Future executeAsync(Map headers, Verb httpVerb, String completeUrl, - String bodyContents, OAuthAsyncRequestCallback callback, - OAuthRequestAsync.ResponseConverter converter) { - - final ForceTypeOfHttpRequest forceTypeOfHttpRequest = ScribeJavaConfig.getForceTypeOfHttpRequests(); - if (ForceTypeOfHttpRequest.FORCE_SYNC_ONLY_HTTP_REQUESTS == forceTypeOfHttpRequest) { - throw new OAuthException("Cannot use async operations, only sync"); - } - if (ForceTypeOfHttpRequest.PREFER_SYNC_ONLY_HTTP_REQUESTS == forceTypeOfHttpRequest) { - config.log("Cannot use async operations, only sync"); - } - - return httpClient.executeAsync(config.getUserAgent(), headers, httpVerb, completeUrl, bodyContents, callback, - converter); - } - public Future execute(OAuthRequestAsync request, OAuthAsyncRequestCallback callback, OAuthRequestAsync.ResponseConverter converter) { From 1f9087c700df1a53f9e4367f2b28ce1ccb6a011f Mon Sep 17 00:00:00 2001 From: Eugeny Zibrov Date: Wed, 14 Dec 2016 17:28:48 +0300 Subject: [PATCH 330/882] Move doktornarabote.ru urls to https --- README.md | 2 +- .../java/com/github/scribejava/apis/DoktornaraboteApi.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 93b7a9c2d..310c3184c 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ ScribeJava support out-of-box several HTTP clients: * AWeber (http://www.aweber.com/) * Box (https://www.box.com/) * Digg (http://digg.com/) -* Доктор на работе (http://www.doktornarabote.ru/) +* Доктор на работе (https://www.doktornarabote.ru/) * Facebook (https://www.facebook.com/) * Flickr (https://www.flickr.com/) * Foursquare (https://foursquare.com/) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/DoktornaraboteApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/DoktornaraboteApi.java index 8965ea07f..9cb308be3 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/DoktornaraboteApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/DoktornaraboteApi.java @@ -20,12 +20,12 @@ public static DoktornaraboteApi instance() { @Override public String getAccessTokenEndpoint() { - return "http://auth.doktornarabote.ru/OAuth/Token"; + return "https://auth.doktornarabote.ru/OAuth/Token"; } @Override protected String getAuthorizationBaseUrl() { - return "http://auth.doktornarabote.ru/OAuth/Authorize"; + return "https://auth.doktornarabote.ru/OAuth/Authorize"; } @Override From 4722632641132eff869f33d285b20cb5c61f5c8e Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 14 Dec 2016 17:35:11 +0300 Subject: [PATCH 331/882] update changelog --- changelog | 4 ++++ pom.xml | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/changelog b/changelog index 4b6baf4fd..e79803e97 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,7 @@ +[SNAPSHOT] + * Drop deprecated methods + * Move doktornarabote.ru urls to https (thanks to https://github.com/ezibrov) + [3.4.0] * uncouple OAuthRequest and Service. OAuthRequest shouldn't know anything about OAuthservice. You don't need OAuthService to create OAuthRequest anymore. Async request should be sent via OAuthService method. diff --git a/pom.xml b/pom.xml index dc3506a62..045d8b5d7 100644 --- a/pom.xml +++ b/pom.xml @@ -172,7 +172,7 @@ org.apache.maven.plugins maven-resources-plugin - 3.0.1 + 3.0.2 UTF-8 From 5f960068c681db9ff8302dbf80e0bb002f88518f Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 14 Dec 2016 17:54:05 +0300 Subject: [PATCH 332/882] prepare 3.4.1 release --- README.md | 4 ++-- changelog | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 310c3184c..0c78e074d 100644 --- a/README.md +++ b/README.md @@ -100,7 +100,7 @@ You can pull ScribeJava from the central maven repository, just add these to you com.github.scribejava scribejava-apis - 3.4.0 + 3.4.1 ``` @@ -109,7 +109,7 @@ And in case you need just core classes (that's it, without any external API (FB, com.github.scribejava scribejava-core - 3.4.0 + 3.4.1 ``` diff --git a/changelog b/changelog index e79803e97..d829bbe9a 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,4 @@ -[SNAPSHOT] +[3.4.1] * Drop deprecated methods * Move doktornarabote.ru urls to https (thanks to https://github.com/ezibrov) From 731f72217b4cde9a6f01805596f095ecadebb6a9 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 14 Dec 2016 17:55:10 +0300 Subject: [PATCH 333/882] [maven-release-plugin] prepare release scribejava-3.4.1 --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/pom.xml b/pom.xml index 045d8b5d7..2cbd98768 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 3.4.1-SNAPSHOT + 3.4.1 ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -33,7 +33,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - HEAD + scribejava-3.4.1 diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index cb5c6e443..c71a40aa0 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 3.4.1-SNAPSHOT + 3.4.1 ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 470d5a534..f1f792f84 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 3.4.1-SNAPSHOT + 3.4.1 ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 08551999b..1e0add6fb 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 3.4.1-SNAPSHOT + 3.4.1 ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index 7d7d6d3e3..481938ae0 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 3.4.1-SNAPSHOT + 3.4.1 ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 86365bfff..a324fa458 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 3.4.1-SNAPSHOT + 3.4.1 ../pom.xml From 548da8fb7fa61094f312be3e1e38e07df23cde28 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 14 Dec 2016 17:55:17 +0300 Subject: [PATCH 334/882] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/pom.xml b/pom.xml index 2cbd98768..8277cd1b6 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 3.4.1 + 3.4.2-SNAPSHOT ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -33,7 +33,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - scribejava-3.4.1 + HEAD diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index c71a40aa0..1e0291007 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 3.4.1 + 3.4.2-SNAPSHOT ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index f1f792f84..186c868e0 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 3.4.1 + 3.4.2-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 1e0add6fb..190e489c4 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 3.4.1 + 3.4.2-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index 481938ae0..a8d55177e 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 3.4.1 + 3.4.2-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index a324fa458..cc1c52080 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 3.4.1 + 3.4.2-SNAPSHOT ../pom.xml From 840dbeba90608274f6069bd399f126a2a3b008a9 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 26 Dec 2016 15:56:00 +0300 Subject: [PATCH 335/882] deprecate ScribeJavaConfig and ForceTypeOfHttpRequest --- .../examples/FacebookAsyncNingExample.java | 3 -- .../examples/Google20AsyncAHCExample.java | 3 -- .../examples/SalesforceNingAsyncExample.java | 3 -- .../VkontakteExternalHttpExample.java | 3 -- .../core/model/ForceTypeOfHttpRequest.java | 5 ++ .../scribejava/core/model/OAuthRequest.java | 9 ---- .../core/model/ScribeJavaConfig.java | 5 ++ .../scribejava/core/oauth/OAuthService.java | 25 ---------- .../model/ForceTypeOfHttpRequestTest.java | 47 ------------------- 9 files changed, 10 insertions(+), 93 deletions(-) delete mode 100644 scribejava-core/src/test/java/com/github/scribejava/core/model/ForceTypeOfHttpRequestTest.java diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java index 23f1dcba1..a6e8b58f5 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java @@ -7,11 +7,9 @@ import java.util.concurrent.ExecutionException; import com.github.scribejava.apis.FacebookApi; import com.github.scribejava.core.builder.ServiceBuilder; -import com.github.scribejava.core.model.ForceTypeOfHttpRequest; import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthRequestAsync; import com.github.scribejava.core.model.Response; -import com.github.scribejava.core.model.ScribeJavaConfig; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.oauth.OAuth20Service; import java.io.IOException; @@ -29,7 +27,6 @@ public static void main(String... args) throws InterruptedException, ExecutionEx final String clientId = "your client id"; final String clientSecret = "your client secret"; final String secretState = "secret" + new Random().nextInt(999_999); - ScribeJavaConfig.setForceTypeOfHttpRequests(ForceTypeOfHttpRequest.FORCE_ASYNC_ONLY_HTTP_REQUESTS); final NingHttpClientConfig clientConfig = new NingHttpClientConfig(new AsyncHttpClientConfig.Builder() .setMaxConnections(5) .setRequestTimeout(10_000) diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java index 735b04911..4511aa64b 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java @@ -5,12 +5,10 @@ import com.github.scribejava.apis.GoogleApi20; import com.github.scribejava.httpclient.ahc.AhcHttpClientConfig; import com.github.scribejava.core.builder.ServiceBuilder; -import com.github.scribejava.core.model.ForceTypeOfHttpRequest; import com.github.scribejava.core.httpclient.HttpClientConfig; import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthRequestAsync; import com.github.scribejava.core.model.Response; -import com.github.scribejava.core.model.ScribeJavaConfig; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.oauth.OAuth20Service; import java.io.IOException; @@ -32,7 +30,6 @@ public static void main(String... args) throws InterruptedException, ExecutionEx final String clientId = "your client id"; final String clientSecret = "your client secret"; final String secretState = "secret" + new Random().nextInt(999_999); - ScribeJavaConfig.setForceTypeOfHttpRequests(ForceTypeOfHttpRequest.FORCE_ASYNC_ONLY_HTTP_REQUESTS); final HttpClientConfig clientConfig = new AhcHttpClientConfig(new DefaultAsyncHttpClientConfig.Builder() .setMaxConnections(5) .setRequestTimeout(10_000) diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceNingAsyncExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceNingAsyncExample.java index 1cec996d3..4167b535d 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceNingAsyncExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceNingAsyncExample.java @@ -11,10 +11,8 @@ import com.github.scribejava.apis.salesforce.SalesforceToken; import com.github.scribejava.httpclient.ning.NingHttpClientConfig; import com.github.scribejava.core.builder.ServiceBuilder; -import com.github.scribejava.core.model.ForceTypeOfHttpRequest; import com.github.scribejava.core.model.OAuthRequestAsync; import com.github.scribejava.core.model.Response; -import com.github.scribejava.core.model.ScribeJavaConfig; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.oauth.OAuth20Service; import com.ning.http.client.AsyncHttpClientConfig; @@ -35,7 +33,6 @@ public static void main(String... args) throws InterruptedException, ExecutionEx final String clientId = "your client id"; final String clientSecret = "your client secret"; - ScribeJavaConfig.setForceTypeOfHttpRequests(ForceTypeOfHttpRequest.FORCE_ASYNC_ONLY_HTTP_REQUESTS); final NingHttpClientConfig clientConfig = new NingHttpClientConfig(new AsyncHttpClientConfig.Builder() .setMaxConnections(5) .setRequestTimeout(10_000) 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 065d1af4e..ad16d5428 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 @@ -3,11 +3,9 @@ import java.util.Scanner; import com.github.scribejava.core.builder.ServiceBuilder; import com.github.scribejava.apis.VkontakteApi; -import com.github.scribejava.core.model.ForceTypeOfHttpRequest; import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthRequestAsync; import com.github.scribejava.core.model.Response; -import com.github.scribejava.core.model.ScribeJavaConfig; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.oauth.OAuth20Service; import com.github.scribejava.httpclient.ahc.AhcHttpClient; @@ -28,7 +26,6 @@ public static void main(String... args) throws IOException, InterruptedException // Replace these with your client id and secret final String clientId = "your client id"; final String clientSecret = "your client secret"; - ScribeJavaConfig.setForceTypeOfHttpRequests(ForceTypeOfHttpRequest.FORCE_ASYNC_ONLY_HTTP_REQUESTS); //create any http client externally final DefaultAsyncHttpClientConfig httpClientConfig = new DefaultAsyncHttpClientConfig.Builder() diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/ForceTypeOfHttpRequest.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/ForceTypeOfHttpRequest.java index b0387a535..c1ea3f3ce 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/ForceTypeOfHttpRequest.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/ForceTypeOfHttpRequest.java @@ -1,5 +1,10 @@ package com.github.scribejava.core.model; +/** + * + * @deprecated unused anymore. Have no sense and impaction + */ +@Deprecated public enum ForceTypeOfHttpRequest { NONE, 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 d82153b3c..fe0b802df 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 @@ -5,7 +5,6 @@ import java.net.URL; import java.util.Map; import com.github.scribejava.core.exceptions.OAuthConnectionException; -import com.github.scribejava.core.exceptions.OAuthException; import com.github.scribejava.core.oauth.OAuthService; import java.io.File; @@ -30,14 +29,6 @@ public OAuthRequest(Verb verb, String url, OAuthConfig config) { * @throws RuntimeException if the connection cannot be created. */ public Response send() { - final ForceTypeOfHttpRequest forceTypeOfHttpRequest = ScribeJavaConfig.getForceTypeOfHttpRequests(); - - if (ForceTypeOfHttpRequest.FORCE_ASYNC_ONLY_HTTP_REQUESTS == forceTypeOfHttpRequest) { - throw new OAuthException("Cannot use sync operations, only async"); - } - if (ForceTypeOfHttpRequest.PREFER_ASYNC_ONLY_HTTP_REQUESTS == forceTypeOfHttpRequest) { - config.log("Cannot use sync operations, only async"); - } try { createConnection(); return doSend(); diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/ScribeJavaConfig.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/ScribeJavaConfig.java index 171bbac1a..3ebb31827 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/ScribeJavaConfig.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/ScribeJavaConfig.java @@ -1,5 +1,10 @@ package com.github.scribejava.core.model; +/** + * + * @deprecated unused anymore. Have no sense and impaction + */ +@Deprecated public abstract class ScribeJavaConfig { private static ForceTypeOfHttpRequest forceTypeOfHttpRequests = ForceTypeOfHttpRequest.NONE; diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java index 82d46d549..68275db6d 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java @@ -1,9 +1,7 @@ package com.github.scribejava.core.oauth; -import com.github.scribejava.core.exceptions.OAuthException; import com.github.scribejava.core.httpclient.HttpClientProvider; import com.github.scribejava.core.model.AbstractRequest; -import com.github.scribejava.core.model.ForceTypeOfHttpRequest; import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.httpclient.HttpClientConfig; import com.github.scribejava.core.model.OAuthAsyncRequestCallback; @@ -11,7 +9,6 @@ import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.OAuthRequestAsync; import com.github.scribejava.core.model.Response; -import com.github.scribejava.core.model.ScribeJavaConfig; import com.github.scribejava.core.model.Token; import java.io.File; @@ -32,26 +29,12 @@ public abstract class OAuthService { public OAuthService(OAuthConfig config) { this.config = config; - final ForceTypeOfHttpRequest forceTypeOfHttpRequest = ScribeJavaConfig.getForceTypeOfHttpRequests(); final HttpClientConfig httpClientConfig = config.getHttpClientConfig(); final HttpClient externalHttpClient = config.getHttpClient(); if (httpClientConfig == null && externalHttpClient == null) { - if (ForceTypeOfHttpRequest.FORCE_ASYNC_ONLY_HTTP_REQUESTS == forceTypeOfHttpRequest) { - throw new OAuthException("Cannot use sync operations, only async"); - } - if (ForceTypeOfHttpRequest.PREFER_ASYNC_ONLY_HTTP_REQUESTS == forceTypeOfHttpRequest) { - config.log("Cannot use sync operations, only async"); - } httpClient = null; } else { - if (ForceTypeOfHttpRequest.FORCE_SYNC_ONLY_HTTP_REQUESTS == forceTypeOfHttpRequest) { - throw new OAuthException("Cannot use async operations, only sync"); - } - if (ForceTypeOfHttpRequest.PREFER_SYNC_ONLY_HTTP_REQUESTS == forceTypeOfHttpRequest) { - config.log("Cannot use async operations, only sync"); - } - httpClient = externalHttpClient == null ? getClient(httpClientConfig) : externalHttpClient; } } @@ -86,14 +69,6 @@ public OAuthConfig getConfig() { public Future execute(OAuthRequestAsync request, OAuthAsyncRequestCallback callback, OAuthRequestAsync.ResponseConverter converter) { - final ForceTypeOfHttpRequest forceTypeOfHttpRequest = ScribeJavaConfig.getForceTypeOfHttpRequests(); - if (ForceTypeOfHttpRequest.FORCE_SYNC_ONLY_HTTP_REQUESTS == forceTypeOfHttpRequest) { - throw new OAuthException("Cannot use async operations, only sync"); - } - if (ForceTypeOfHttpRequest.PREFER_SYNC_ONLY_HTTP_REQUESTS == forceTypeOfHttpRequest) { - config.log("Cannot use async operations, only sync"); - } - final File filePayload = request.getFilePayload(); if (filePayload != null) { return httpClient.executeAsync(config.getUserAgent(), request.getHeaders(), request.getVerb(), diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/model/ForceTypeOfHttpRequestTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/model/ForceTypeOfHttpRequestTest.java deleted file mode 100644 index 1de09ea92..000000000 --- a/scribejava-core/src/test/java/com/github/scribejava/core/model/ForceTypeOfHttpRequestTest.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.github.scribejava.core.model; - -import java.util.concurrent.ExecutionException; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import com.github.scribejava.core.exceptions.OAuthException; -import com.github.scribejava.core.oauth.OAuth20Service; -import com.github.scribejava.core.oauth.OAuthService; - -public class ForceTypeOfHttpRequestTest { - - @Rule - public ExpectedException expectedException = ExpectedException.none(); - - private OAuthRequest request; - private OAuthRequestAsync requestAsync; - private OAuthService oAuthService; - - @Before - public void setUp() { - ScribeJavaConfig.setForceTypeOfHttpRequests(ForceTypeOfHttpRequest.NONE); - final OAuthConfig config = new OAuthConfig("test", "test"); - - oAuthService = new OAuth20Service(null, config); - request = new OAuthRequest(Verb.GET, "http://example.com?qsparam=value&other+param=value+with+spaces", config); - requestAsync - = new OAuthRequestAsync(Verb.GET, "http://example.com?qsparam=value&other+param=value+with+spaces"); - } - - @Test - public void shouldNotSendSyncWithForceParameter() { - expectedException.expect(OAuthException.class); - expectedException.expectMessage("Cannot use sync operations, only async"); - ScribeJavaConfig.setForceTypeOfHttpRequests(ForceTypeOfHttpRequest.FORCE_ASYNC_ONLY_HTTP_REQUESTS); - request.send(); - } - - @Test - public void shouldNotSendAsyncWithForceParameter() throws ExecutionException, InterruptedException { - expectedException.expect(OAuthException.class); - expectedException.expectMessage("Cannot use async operations, only sync"); - ScribeJavaConfig.setForceTypeOfHttpRequests(ForceTypeOfHttpRequest.FORCE_SYNC_ONLY_HTTP_REQUESTS); - oAuthService.execute(requestAsync, null).get(); - } -} From 7450a60a2c48a92cf4b03bfa3f266f38d7a7d7b6 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 26 Dec 2016 17:53:16 +0300 Subject: [PATCH 336/882] make Response do not know abouth HttpUrlConnection (or any other HTTP stuff) --- .../scribejava/core/model/OAuthRequest.java | 28 +++++++- .../scribejava/core/model/Response.java | 56 ++++++++++++++-- .../OAuth1AccessTokenExtractorTest.java | 3 +- .../OAuth2AccessTokenExtractorTest.java | 3 +- .../OAuth2AccessTokenJsonExtractorTest.java | 6 +- .../scribejava/core/model/ConnectionStub.java | 15 +---- .../scribejava/core/model/ResponseTest.java | 67 ------------------- .../ahc/OAuthAsyncCompletionHandler.java | 2 +- .../ning/OAuthAsyncCompletionHandler.java | 2 +- .../okhttp/OAuthAsyncCompletionHandler.java | 7 +- 10 files changed, 87 insertions(+), 102 deletions(-) delete mode 100644 scribejava-core/src/test/java/com/github/scribejava/core/model/ResponseTest.java 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 fe0b802df..9cc901bd5 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 @@ -5,8 +5,12 @@ import java.net.URL; import java.util.Map; import com.github.scribejava.core.exceptions.OAuthConnectionException; +import com.github.scribejava.core.exceptions.OAuthException; import com.github.scribejava.core.oauth.OAuthService; import java.io.File; +import java.net.UnknownHostException; +import java.util.HashMap; +import java.util.List; public class OAuthRequest extends AbstractRequest { @@ -57,7 +61,29 @@ Response doSend() throws IOException { addBody(getByteArrayPayload()); } } - return new Response(connection); + + try { + connection.connect(); + final int responseCode = connection.getResponseCode(); + return new Response(responseCode, connection.getResponseMessage(), parseHeaders(connection), + responseCode >= 200 && responseCode < 400 ? connection.getInputStream() + : connection.getErrorStream()); + } catch (UnknownHostException e) { + throw new OAuthException("The IP address of a host could not be determined.", e); + } + } + + private static Map parseHeaders(HttpURLConnection conn) { + final Map headers = new HashMap<>(); + for (Map.Entry> entry : conn.getHeaderFields().entrySet()) { + final String key = entry.getKey(); + if ("Content-Encoding".equalsIgnoreCase(key)) { + headers.put("Content-Encoding", entry.getValue().get(0)); + } else { + headers.put(key, entry.getValue().get(0)); + } + } + return headers; } private void createConnection() throws IOException { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/Response.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/Response.java index e57f39c44..3b50923a7 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/Response.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/Response.java @@ -13,20 +13,54 @@ public class Response { - private int code; - private String message; + private final int code; + private final String message; + private final Map headers; private String body; private InputStream stream; - private Map headers; + /** + * + * @param code code + * @param message message + * @param headers headers + * @param body body + * @param stream stream + * @deprecated use either {@link #Response(int, java.lang.String, java.util.Map, java.io.InputStream) } + * or {@link #Response(int, java.lang.String, java.util.Map, java.lang.String) } + */ + @Deprecated public Response(int code, String message, Map headers, String body, InputStream stream) { this.code = code; + this.message = message; this.headers = headers; this.body = body; + this.stream = stream; + } + + private Response(int code, String message, Map headers) { + this.code = code; this.message = message; + this.headers = headers; + } + + public Response(int code, String message, Map headers, InputStream stream) { + this(code, message, headers); this.stream = stream; } + public Response(int code, String message, Map headers, String body) { + this(code, message, headers); + this.body = body; + } + + /** + * + * @param connection connection + * @throws IOException + * @deprecated use {@link #Response(int, java.lang.String, java.util.Map, java.lang.String, java.io.InputStream) } + */ + @Deprecated Response(HttpURLConnection connection) throws IOException { try { connection.connect(); @@ -40,14 +74,24 @@ public Response(int code, String message, Map headers, String bo } private String parseBodyContents() throws IOException { + if (stream == null) { + return null; + } if ("gzip".equals(getHeader("Content-Encoding"))) { - body = StreamUtils.getGzipStreamContents(getStream()); + body = StreamUtils.getGzipStreamContents(stream); } else { - body = StreamUtils.getStreamContents(getStream()); + body = StreamUtils.getStreamContents(stream); } return body; } + /** + * + * @param conn conn + * @return + * @deprecated use {@link OAuthRequest#parseHeaders(java.net.HttpURLConnection) } + */ + @Deprecated private Map parseHeaders(HttpURLConnection conn) { final Map headers = new HashMap<>(); for (Entry> entry : conn.getHeaderFields().entrySet()) { @@ -62,7 +106,7 @@ private Map parseHeaders(HttpURLConnection conn) { } public final boolean isSuccessful() { - return getCode() >= 200 && getCode() < 400; + return code >= 200 && code < 400; } public String getBody() throws IOException { 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 b810d25b3..36ac4cd2e 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 @@ -77,7 +77,6 @@ public void shouldThrowExceptionIfResponseIsEmptyString() throws IOException { } private static Response ok(String body) { - return new Response(200, /* message */ null, /* headers */ Collections.emptyMap(), - body, /* stream */ null); + return new Response(200, /* message */ null, /* headers */ Collections.emptyMap(), body); } } diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/extractors/OAuth2AccessTokenExtractorTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/extractors/OAuth2AccessTokenExtractorTest.java index eb88b583f..7f2cd4ddd 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 @@ -76,7 +76,6 @@ public void shouldThrowExceptionIfResponseIsEmptyString() throws IOException { } private static Response ok(String body) { - return new Response(200, /* message */ null, /* headers */ Collections.emptyMap(), - body, /* stream */ null); + return new Response(200, /* message */ null, /* headers */ Collections.emptyMap(), body); } } diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractorTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractorTest.java index 026885dcf..42f07e25f 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 @@ -48,12 +48,10 @@ public void shouldThrowExceptionIfResponseIsError() throws IOException { } private static Response ok(String body) { - return new Response(200, /* message */ null, /* headers */ Collections.emptyMap(), - body, /* stream */ null); + return new Response(200, /* message */ null, /* headers */ Collections.emptyMap(), body); } private static Response error(String body) { - return new Response(400, /* message */ null, /* headers */ Collections.emptyMap(), - body, /* stream */ null); + return new Response(400, /* message */ null, /* headers */ Collections.emptyMap(), body); } } diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/model/ConnectionStub.java b/scribejava-core/src/test/java/com/github/scribejava/core/model/ConnectionStub.java index b7465527d..0e9839d47 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/model/ConnectionStub.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/model/ConnectionStub.java @@ -8,7 +8,7 @@ import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; -import java.util.Arrays; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -16,8 +16,6 @@ public class ConnectionStub extends HttpURLConnection { private final Map headers = new HashMap<>(); - private final Map> responseHeaders = new HashMap<>(); - private int inputStreamCalled; public ConnectionStub() throws MalformedURLException { super(new URL("http://example.com")); @@ -44,14 +42,9 @@ public int getResponseCode() throws IOException { @Override public InputStream getInputStream() throws IOException { - inputStreamCalled++; return new ByteArrayInputStream("contents".getBytes()); } - public int getTimesCalledInpuStream() { - return inputStreamCalled; - } - @Override public OutputStream getOutputStream() throws IOException { final ByteArrayOutputStream baos = new ByteArrayOutputStream(); @@ -61,11 +54,7 @@ public OutputStream getOutputStream() throws IOException { @Override public Map> getHeaderFields() { - return responseHeaders; - } - - public void addResponseHeader(String key, String value) { - responseHeaders.put(key, Arrays.asList(value)); + return Collections.emptyMap(); } @Override diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/model/ResponseTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/model/ResponseTest.java deleted file mode 100644 index 1f7b0a4fe..000000000 --- a/scribejava-core/src/test/java/com/github/scribejava/core/model/ResponseTest.java +++ /dev/null @@ -1,67 +0,0 @@ -package com.github.scribejava.core.model; - -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.net.MalformedURLException; -import static org.junit.Assert.assertEquals; -import org.junit.Before; -import org.junit.Test; - -public class ResponseTest { - - private Response response; - private ConnectionStub connection; - - @Before - public void setUp() throws IOException { - connection = new ConnectionStub(); - connection.addResponseHeader("one", "one"); - connection.addResponseHeader("two", "two"); - response = new Response(connection); - } - - @Test - public void shouldPopulateResponseHeaders() { - assertEquals(2, response.getHeaders().size()); - assertEquals("one", response.getHeader("one")); - } - - @Test - public void shouldParseBodyContents() throws IOException { - assertEquals("contents", response.getBody()); - assertEquals(1, connection.getTimesCalledInpuStream()); - } - - @Test - public void shouldParseBodyContentsOnlyOnce() throws IOException { - assertEquals("contents", response.getBody()); - assertEquals("contents", response.getBody()); - assertEquals("contents", response.getBody()); - assertEquals(1, connection.getTimesCalledInpuStream()); - } - - @Test - public void shouldHandleAConnectionWithErrors() throws IOException { - final Response errResponse = new Response(new FaultyConnection()); - assertEquals(400, errResponse.getCode()); - assertEquals("errors", errResponse.getBody()); - } - - private static class FaultyConnection extends ConnectionStub { - - private FaultyConnection() throws MalformedURLException { - super(); - } - - @Override - public InputStream getErrorStream() { - return new ByteArrayInputStream("errors".getBytes()); - } - - @Override - public int getResponseCode() throws IOException { - return 400; - } - } -} diff --git a/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/OAuthAsyncCompletionHandler.java b/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/OAuthAsyncCompletionHandler.java index b19e3c3a7..003821b2f 100644 --- a/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/OAuthAsyncCompletionHandler.java +++ b/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/OAuthAsyncCompletionHandler.java @@ -28,7 +28,7 @@ public T onCompleted(org.asynchttpclient.Response ahcResponse) throws IOExceptio headersMap.put(header.getKey(), header.getValue()); } final Response response = new Response(ahcResponse.getStatusCode(), ahcResponse.getStatusText(), headersMap, - ahcResponse.getResponseBody(), ahcResponse.getResponseBodyAsStream()); + ahcResponse.getResponseBodyAsStream()); @SuppressWarnings("unchecked") final T t = converter == null ? (T) response : converter.convert(response); diff --git a/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/OAuthAsyncCompletionHandler.java b/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/OAuthAsyncCompletionHandler.java index 2f176e6b0..1448b60c3 100644 --- a/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/OAuthAsyncCompletionHandler.java +++ b/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/OAuthAsyncCompletionHandler.java @@ -33,7 +33,7 @@ public T onCompleted(com.ning.http.client.Response ningResponse) throws IOExcept headersMap.put(header.getKey(), value.toString()); } final Response response = new Response(ningResponse.getStatusCode(), ningResponse.getStatusText(), headersMap, - ningResponse.getResponseBody(), ningResponse.getResponseBodyAsStream()); + ningResponse.getResponseBodyAsStream()); @SuppressWarnings("unchecked") final T t = converter == null ? (T) response : converter.convert(response); diff --git a/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OAuthAsyncCompletionHandler.java b/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OAuthAsyncCompletionHandler.java index 189781669..28dda16a2 100644 --- a/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OAuthAsyncCompletionHandler.java +++ b/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OAuthAsyncCompletionHandler.java @@ -45,11 +45,8 @@ public void onResponse(Call call, okhttp3.Response okHttpResponse) throws IOExce headersMap.put(name, headers.get(name)); } - final Response response = new Response(okHttpResponse.code(), - okHttpResponse.message(), - headersMap, - null, // cannot return both body String and InputStream - okHttpResponse.body().byteStream()); + final Response response = new Response(okHttpResponse.code(), okHttpResponse.message(), headersMap, + okHttpResponse.body().byteStream()); @SuppressWarnings("unchecked") final T t = converter == null ? (T) response : converter.convert(response); From a1cb90a9688c6d36ef81ec9c4ea53b9e7db90dff Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 26 Dec 2016 18:18:59 +0300 Subject: [PATCH 337/882] prepare to move HTTP communications logic from OAuthRequest to separate package --- .../scribejava/core/model/OAuthRequest.java | 46 ++++-------- .../scribejava/core/model/ConnectionStub.java | 73 ------------------- .../scribejava/core/model/RequestTest.java | 59 +-------------- 3 files changed, 18 insertions(+), 160 deletions(-) delete mode 100644 scribejava-core/src/test/java/com/github/scribejava/core/model/ConnectionStub.java 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 9cc901bd5..a7ee73b7b 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,20 +2,18 @@ import java.io.IOException; import java.net.HttpURLConnection; -import java.net.URL; import java.util.Map; import com.github.scribejava.core.exceptions.OAuthConnectionException; import com.github.scribejava.core.exceptions.OAuthException; import com.github.scribejava.core.oauth.OAuthService; import java.io.File; +import java.net.URL; import java.net.UnknownHostException; import java.util.HashMap; import java.util.List; public class OAuthRequest extends AbstractRequest { - private HttpURLConnection connection; - private final OAuthConfig config; public OAuthRequest(Verb verb, String url, OAuthConfig config) { @@ -34,31 +32,32 @@ public OAuthRequest(Verb verb, String url, OAuthConfig config) { */ public Response send() { try { - createConnection(); - return doSend(); + return doSend(config, isFollowRedirects(), getHeaders(), getVerb(), getCompleteUrl(), this); } catch (IOException | RuntimeException e) { throw new OAuthConnectionException(getCompleteUrl(), e); } } - Response doSend() throws IOException { - final Verb verb = getVerb(); - connection.setRequestMethod(verb.name()); + private static Response doSend(OAuthConfig config, boolean followRedirects, Map headers, + Verb httpVerb, String completeUrl, OAuthRequest request) throws IOException { + final HttpURLConnection connection = (HttpURLConnection) new URL(completeUrl).openConnection(); + connection.setInstanceFollowRedirects(followRedirects); + connection.setRequestMethod(httpVerb.name()); if (config.getConnectTimeout() != null) { connection.setConnectTimeout(config.getConnectTimeout()); } if (config.getReadTimeout() != null) { connection.setReadTimeout(config.getReadTimeout()); } - addHeaders(); - if (hasBodyContent()) { - final File filePayload = getFilePayload(); + addHeaders(connection, headers, config.getUserAgent()); + if (httpVerb == Verb.POST || httpVerb == Verb.PUT || httpVerb == Verb.DELETE) { + final File filePayload = request.getFilePayload(); if (filePayload != null) { throw new UnsupportedOperationException("Sync Requests do not support File payload for the moment"); - } else if (getStringPayload() != null) { - addBody(getStringPayload().getBytes(getCharset())); + } else if (request.getStringPayload() != null) { + addBody(connection, request.getStringPayload().getBytes(request.getCharset())); } else { - addBody(getByteArrayPayload()); + addBody(connection, request.getByteArrayPayload()); } } @@ -86,25 +85,16 @@ private static Map parseHeaders(HttpURLConnection conn) { return headers; } - private void createConnection() throws IOException { - final String completeUrl = getCompleteUrl(); - if (connection == null) { - connection = (HttpURLConnection) new URL(completeUrl).openConnection(); - connection.setInstanceFollowRedirects(isFollowRedirects()); - } - } - - void addHeaders() { - for (Map.Entry entry : getHeaders().entrySet()) { + private static void addHeaders(HttpURLConnection connection, Map headers, String userAgent) { + for (Map.Entry entry : headers.entrySet()) { connection.setRequestProperty(entry.getKey(), entry.getValue()); } - final String userAgent = config.getUserAgent(); if (userAgent != null) { connection.setRequestProperty(OAuthConstants.USER_AGENT_HEADER_NAME, userAgent); } } - void addBody(byte[] content) throws IOException { + private static void addBody(HttpURLConnection connection, byte[] content) throws IOException { connection.setRequestProperty(CONTENT_LENGTH, String.valueOf(content.length)); if (connection.getRequestProperty(CONTENT_TYPE) == null) { @@ -113,8 +103,4 @@ void addBody(byte[] content) throws IOException { connection.setDoOutput(true); connection.getOutputStream().write(content); } - - void setConnection(HttpURLConnection connection) { - this.connection = connection; - } } diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/model/ConnectionStub.java b/scribejava-core/src/test/java/com/github/scribejava/core/model/ConnectionStub.java deleted file mode 100644 index 0e9839d47..000000000 --- a/scribejava-core/src/test/java/com/github/scribejava/core/model/ConnectionStub.java +++ /dev/null @@ -1,73 +0,0 @@ -package com.github.scribejava.core.model; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.net.HttpURLConnection; -import java.net.MalformedURLException; -import java.net.URL; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -public class ConnectionStub extends HttpURLConnection { - - private final Map headers = new HashMap<>(); - - public ConnectionStub() throws MalformedURLException { - super(new URL("http://example.com")); - } - - @Override - public void setRequestProperty(String key, String value) { - headers.put(key, value); - } - - @Override - public String getRequestProperty(String s) { - return headers.get(s); - } - - public Map getHeaders() { - return headers; - } - - @Override - public int getResponseCode() throws IOException { - return 200; - } - - @Override - public InputStream getInputStream() throws IOException { - return new ByteArrayInputStream("contents".getBytes()); - } - - @Override - public OutputStream getOutputStream() throws IOException { - final ByteArrayOutputStream baos = new ByteArrayOutputStream(); - baos.write("contents".getBytes()); - return baos; - } - - @Override - public Map> getHeaderFields() { - return Collections.emptyMap(); - } - - @Override - public void connect() { - } - - @Override - public void disconnect() { - } - - @Override - public boolean usingProxy() { - return false; - } - -} diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/model/RequestTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/model/RequestTest.java index bd6cff86f..bdce597ef 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/model/RequestTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/model/RequestTest.java @@ -1,7 +1,6 @@ package com.github.scribejava.core.model; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import org.junit.Before; import org.junit.Test; @@ -11,26 +10,18 @@ public class RequestTest { private OAuthRequest getRequest; private OAuthRequest postRequest; - private ConnectionStub connection; private OAuthConfig config; @Before public void setUp() throws MalformedURLException { - connection = new ConnectionStub(); config = new OAuthConfig("test", "test"); + postRequest = new OAuthRequest(Verb.POST, "http://example.com", config); postRequest.addBodyParameter("param", "value"); postRequest.addBodyParameter("param with spaces", "value with spaces"); - postRequest.setConnection(connection); + getRequest = new OAuthRequest(Verb.GET, "http://example.com?qsparam=value&other+param=value+with+spaces", config); - getRequest.setConnection(connection); - } - - @Test - public void shouldSetRequestVerb() { - getRequest.send(); - assertEquals("GET", connection.getRequestMethod()); } @Test @@ -40,29 +31,16 @@ public void shouldGetQueryStringParameters() { assertTrue(getRequest.getQueryStringParams().contains(new Parameter("qsparam", "value"))); } - @Test - public void shouldAddRequestHeaders() { - getRequest.addHeader("Header", "1"); - getRequest.addHeader("Header2", "2"); - getRequest.send(); - assertEquals(2, getRequest.getHeaders().size()); - assertEquals(2, connection.getHeaders().size()); - } - @Test public void shouldSetBodyParamsAndAddContentLength() { assertEquals("param=value¶m%20with%20spaces=value%20with%20spaces", new String(postRequest.getByteArrayPayload())); - postRequest.send(); - assertTrue(connection.getHeaders().containsKey("Content-Length")); } @Test public void shouldSetPayloadAndHeaders() { postRequest.setPayload("PAYLOAD"); - postRequest.send(); assertEquals("PAYLOAD", postRequest.getStringPayload()); - assertTrue(connection.getHeaders().containsKey("Content-Length")); } @Test @@ -85,37 +63,4 @@ public void shouldReturnTheCompleteUrl() { public void shouldHandleQueryStringSpaceEncodingProperly() { assertTrue(getRequest.getQueryStringParams().contains(new Parameter("other param", "value with spaces"))); } - - @Test - public void shouldAutomaticallyAddContentTypeForPostRequestsWithBytePayload() { - postRequest.setPayload("PAYLOAD".getBytes()); - postRequest.send(); - assertEquals(OAuthRequest.DEFAULT_CONTENT_TYPE, connection.getHeaders().get("Content-Type")); - } - - @Test - public void shouldAutomaticallyAddContentTypeForPostRequestsWithStringPayload() { - postRequest.setPayload("PAYLOAD"); - postRequest.send(); - assertEquals(OAuthRequest.DEFAULT_CONTENT_TYPE, connection.getHeaders().get("Content-Type")); - } - - @Test - public void shouldAutomaticallyAddContentTypeForPostRequestsWithBodyParameters() { - postRequest.send(); - assertEquals(OAuthRequest.DEFAULT_CONTENT_TYPE, connection.getHeaders().get("Content-Type")); - } - - @Test - public void shouldBeAbleToOverrideItsContentType() { - postRequest.addHeader("Content-Type", "my-content-type"); - postRequest.send(); - assertEquals("my-content-type", connection.getHeaders().get("Content-Type")); - } - - @Test - public void shouldNotAddContentTypeForGetRequests() { - getRequest.send(); - assertFalse(connection.getHeaders().containsKey("Content-Type")); - } } From c09bfced136222cd04ef618fbec2d7819ae509bc Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 26 Dec 2016 19:15:36 +0300 Subject: [PATCH 338/882] add possibility to execute requests in sync manner for OkHttp, AHC and Ning (and any other) --- .../AbstractAsyncOnlyHttpClient.java | 33 ++++++++++++ .../core/httpclient/HttpClient.java | 10 ++++ .../scribejava/core/oauth/OAuthService.java | 19 ++++++- .../httpclient/ahc/AhcHttpClient.java | 4 +- .../httpclient/ning/NingHttpClient.java | 4 +- .../okhttp/OAuthAsyncCompletionHandler.java | 12 +---- .../httpclient/okhttp/OkHttpHttpClient.java | 54 +++++++++++++++++-- 7 files changed, 115 insertions(+), 21 deletions(-) create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/httpclient/AbstractAsyncOnlyHttpClient.java 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 new file mode 100644 index 000000000..7b59a81f5 --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/AbstractAsyncOnlyHttpClient.java @@ -0,0 +1,33 @@ +package com.github.scribejava.core.httpclient; + +import com.github.scribejava.core.model.OAuthRequestAsync; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.Verb; +import java.io.File; +import java.io.IOException; +import java.util.Map; +import java.util.concurrent.ExecutionException; + +public abstract class AbstractAsyncOnlyHttpClient implements HttpClient { + + @Override + public Response execute(String userAgent, Map headers, Verb httpVerb, String completeUrl, + byte[] bodyContents) throws InterruptedException, ExecutionException, IOException { + return executeAsync(userAgent, headers, httpVerb, completeUrl, bodyContents, null, + (OAuthRequestAsync.ResponseConverter) null).get(); + } + + @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, + (OAuthRequestAsync.ResponseConverter) null).get(); + } + + @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, + (OAuthRequestAsync.ResponseConverter) null).get(); + } +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/HttpClient.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/HttpClient.java index fba0ef215..9377226f9 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/HttpClient.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/HttpClient.java @@ -2,10 +2,12 @@ import com.github.scribejava.core.model.OAuthAsyncRequestCallback; import com.github.scribejava.core.model.OAuthRequestAsync; +import com.github.scribejava.core.model.Response; import com.github.scribejava.core.model.Verb; import java.io.File; import java.io.IOException; import java.util.Map; +import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; public interface HttpClient { @@ -23,4 +25,12 @@ Future executeAsync(String userAgent, Map headers, Verb h Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, File bodyContents, OAuthAsyncRequestCallback callback, OAuthRequestAsync.ResponseConverter converter); + Response execute(String userAgent, Map headers, Verb httpVerb, String completeUrl, + byte[] bodyContents) throws InterruptedException, ExecutionException, IOException; + + Response execute(String userAgent, Map headers, Verb httpVerb, String completeUrl, + String bodyContents) throws InterruptedException, ExecutionException, IOException; + + Response execute(String userAgent, Map headers, Verb httpVerb, String completeUrl, + File bodyContents) throws InterruptedException, ExecutionException, IOException; } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java index 68275db6d..3eb6b4890 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java @@ -14,6 +14,7 @@ import java.io.IOException; import java.util.ServiceLoader; +import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; /** @@ -66,8 +67,8 @@ public OAuthConfig getConfig() { public abstract void signRequest(T token, AbstractRequest request); - public Future execute(OAuthRequestAsync request, OAuthAsyncRequestCallback callback, - OAuthRequestAsync.ResponseConverter converter) { + public Future execute(OAuthRequestAsync request, OAuthAsyncRequestCallback callback, + OAuthRequestAsync.ResponseConverter converter) { final File filePayload = request.getFilePayload(); if (filePayload != null) { @@ -86,6 +87,20 @@ public Future execute(OAuthRequestAsync request, OAuthAsyncRequestCall return execute(request, callback, null); } + public Response execute(OAuthRequestAsync request) throws InterruptedException, ExecutionException, IOException { + final File filePayload = request.getFilePayload(); + if (filePayload != null) { + return httpClient.execute(config.getUserAgent(), request.getHeaders(), request.getVerb(), + request.getCompleteUrl(), filePayload); + } else if (request.getStringPayload() != null) { + return httpClient.execute(config.getUserAgent(), request.getHeaders(), request.getVerb(), + request.getCompleteUrl(), request.getStringPayload()); + } else { + return httpClient.execute(config.getUserAgent(), request.getHeaders(), request.getVerb(), + request.getCompleteUrl(), request.getByteArrayPayload()); + } + } + /** * the same as {@link OAuthRequest#send()} * 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 74d3ac730..e8742e2fc 100644 --- a/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/AhcHttpClient.java +++ b/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/AhcHttpClient.java @@ -1,7 +1,7 @@ package com.github.scribejava.httpclient.ahc; +import com.github.scribejava.core.httpclient.AbstractAsyncOnlyHttpClient; import com.github.scribejava.core.model.AbstractRequest; -import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.model.OAuthAsyncRequestCallback; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.OAuthRequestAsync; @@ -18,7 +18,7 @@ import org.asynchttpclient.AsyncHttpClientConfig; import org.asynchttpclient.BoundRequestBuilder; -public class AhcHttpClient implements HttpClient { +public class AhcHttpClient extends AbstractAsyncOnlyHttpClient { private final AsyncHttpClient client; 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 b2fced5e5..c2b27e3eb 100644 --- a/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/NingHttpClient.java +++ b/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/NingHttpClient.java @@ -1,7 +1,7 @@ package com.github.scribejava.httpclient.ning; +import com.github.scribejava.core.httpclient.AbstractAsyncOnlyHttpClient; import com.github.scribejava.core.model.AbstractRequest; -import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.model.OAuthAsyncRequestCallback; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.OAuthRequestAsync; @@ -15,7 +15,7 @@ import com.ning.http.client.AsyncHttpClientConfig; import java.io.File; -public class NingHttpClient implements HttpClient { +public class NingHttpClient extends AbstractAsyncOnlyHttpClient { private final AsyncHttpClient client; diff --git a/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OAuthAsyncCompletionHandler.java b/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OAuthAsyncCompletionHandler.java index 28dda16a2..8481b163f 100644 --- a/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OAuthAsyncCompletionHandler.java +++ b/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OAuthAsyncCompletionHandler.java @@ -5,11 +5,8 @@ import com.github.scribejava.core.model.Response; import okhttp3.Call; import okhttp3.Callback; -import okhttp3.Headers; import java.io.IOException; -import java.util.HashMap; -import java.util.Map; class OAuthAsyncCompletionHandler implements Callback { @@ -38,15 +35,8 @@ public void onFailure(Call call, IOException e) { @Override public void onResponse(Call call, okhttp3.Response okHttpResponse) throws IOException { try { - final Headers headers = okHttpResponse.headers(); - final Map headersMap = new HashMap<>(); - for (String name : headers.names()) { - headersMap.put(name, headers.get(name)); - } - - final Response response = new Response(okHttpResponse.code(), okHttpResponse.message(), headersMap, - okHttpResponse.body().byteStream()); + final Response response = OkHttpHttpClient.convertResponse(okHttpResponse); @SuppressWarnings("unchecked") final T t = converter == null ? (T) response : converter.convert(response); diff --git a/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java b/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java index e41011991..ff8f0c80f 100644 --- a/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java +++ b/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java @@ -18,8 +18,12 @@ import java.util.concurrent.Future; import static com.github.scribejava.core.model.AbstractRequest.DEFAULT_CONTENT_TYPE; +import com.github.scribejava.core.model.Response; import java.io.File; +import java.util.HashMap; +import java.util.concurrent.ExecutionException; import okhttp3.Cache; +import okhttp3.Headers; public class OkHttpHttpClient implements HttpClient { @@ -73,6 +77,38 @@ public Future executeAsync(String userAgent, Map headers, private Future doExecuteAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, BodyType bodyType, Object bodyContents, OAuthAsyncRequestCallback callback, OAuthRequestAsync.ResponseConverter converter) { + final Call call = createCall(userAgent, headers, httpVerb, completeUrl, bodyType, bodyContents); + final OkHttpFuture okHttpFuture = new OkHttpFuture<>(call); + call.enqueue(new OAuthAsyncCompletionHandler<>(callback, converter, okHttpFuture)); + return okHttpFuture; + } + + @Override + public Response execute(String userAgent, Map headers, Verb httpVerb, String completeUrl, + byte[] bodyContents) throws InterruptedException, ExecutionException, IOException { + return doExecute(userAgent, headers, httpVerb, completeUrl, BodyType.BYTE_ARRAY, bodyContents); + } + + @Override + public Response execute(String userAgent, Map headers, Verb httpVerb, String completeUrl, + String bodyContents) throws InterruptedException, ExecutionException, IOException { + return doExecute(userAgent, headers, httpVerb, completeUrl, BodyType.STRING, bodyContents); + } + + @Override + public Response execute(String userAgent, Map headers, Verb httpVerb, String completeUrl, + File bodyContents) throws InterruptedException, ExecutionException, IOException { + return doExecute(userAgent, headers, httpVerb, completeUrl, BodyType.FILE, bodyContents); + } + + private Response doExecute(String userAgent, Map headers, Verb httpVerb, String completeUrl, + BodyType bodyType, Object bodyContents) throws IOException { + final Call call = createCall(userAgent, headers, httpVerb, completeUrl, bodyType, bodyContents); + return convertResponse(call.execute()); + } + + private Call createCall(String userAgent, Map headers, Verb httpVerb, String completeUrl, + BodyType bodyType, Object bodyContents) { final Request.Builder requestBuilder = new Request.Builder(); requestBuilder.url(completeUrl); @@ -101,10 +137,7 @@ private Future doExecuteAsync(String userAgent, Map heade } // create a new call - final Call call = client.newCall(requestBuilder.build()); - final OkHttpFuture okHttpFuture = new OkHttpFuture<>(call); - call.enqueue(new OAuthAsyncCompletionHandler<>(callback, converter, okHttpFuture)); - return okHttpFuture; + return client.newCall(requestBuilder.build()); } private enum BodyType { @@ -129,4 +162,17 @@ RequestBody createBody(MediaType mediaType, Object bodyContents) { abstract RequestBody createBody(MediaType mediaType, Object bodyContents); } + + static Response convertResponse(okhttp3.Response okHttpResponse) { + final Headers headers = okHttpResponse.headers(); + final Map headersMap = new HashMap<>(); + + for (String name : headers.names()) { + headersMap.put(name, headers.get(name)); + } + + return new Response(okHttpResponse.code(), okHttpResponse.message(), headersMap, + okHttpResponse.body().byteStream()); + + } } From dae4fe61713eb75f21332c087a36de56d9727cab Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 9 Jan 2017 18:49:49 +0300 Subject: [PATCH 339/882] unify requests sending (async and sync variants). Allways use service::execute --- .../apis/examples/AWeberExample.java | 4 ++-- .../apis/examples/Box20Example.java | 4 ++-- .../scribejava/apis/examples/DiggExample.java | 4 ++-- .../apis/examples/FacebookExample.java | 4 ++-- .../apis/examples/FlickrExample.java | 4 ++-- .../apis/examples/Foursquare2Example.java | 5 ++-- .../apis/examples/FoursquareExample.java | 4 ++-- .../apis/examples/FreelancerExample.java | 4 ++-- .../apis/examples/GeniusExample.java | 4 ++-- .../apis/examples/GitHubExample.java | 4 ++-- .../apis/examples/Google20Example.java | 4 ++-- .../scribejava/apis/examples/HHExample.java | 4 ++-- .../apis/examples/ImgurExample.java | 4 ++-- .../apis/examples/Kaixin20Example.java | 4 ++-- .../apis/examples/LinkedIn20Example.java | 5 ++-- .../apis/examples/LinkedInExample.java | 4 ++-- .../examples/LinkedInExampleWithScopes.java | 4 ++-- .../scribejava/apis/examples/LiveExample.java | 5 ++-- .../apis/examples/MailruExample.java | 4 ++-- .../apis/examples/MeetupExample.java | 4 ++-- .../apis/examples/MisfitExample.java | 4 ++-- .../apis/examples/NaverExample.java | 4 ++-- .../apis/examples/NeteaseWeiboExample.java | 4 ++-- .../apis/examples/OdnoklassnikiExample.java | 5 ++-- .../apis/examples/PinterestExample.java | 5 ++-- .../apis/examples/Px500Example.java | 4 ++-- .../apis/examples/RenrenExample.java | 4 ++-- .../apis/examples/SalesforceExample.java | 4 ++-- .../apis/examples/SinaWeibo2Example.java | 4 ++-- .../apis/examples/SinaWeiboExample.java | 4 ++-- .../apis/examples/SkyrockExample.java | 4 ++-- .../apis/examples/SohuWeiboExample.java | 4 ++-- .../apis/examples/StackExchangeExample.java | 4 ++-- .../TheThingsNetworkV1StagingExample.java | 4 ++-- .../TheThingsNetworkV2PreviewExample.java | 4 ++-- .../apis/examples/TrelloExample.java | 4 ++-- .../apis/examples/TumblrExample.java | 4 ++-- .../apis/examples/TutByExample.java | 4 ++-- .../apis/examples/TwitterExample.java | 4 ++-- .../apis/examples/ViadeoExample.java | 4 ++-- .../apis/examples/VkontakteExample.java | 4 ++-- .../scribejava/apis/examples/XingExample.java | 4 ++-- .../apis/examples/YahooExample.java | 4 ++-- .../service/OdnoklassnikiServiceTest.java | 2 +- .../scribejava/core/model/OAuthRequest.java | 23 +++++++++---------- .../core/oauth/OAuth10aService.java | 11 ++++----- .../scribejava/core/oauth/OAuth20Service.java | 8 +++---- .../scribejava/core/oauth/OAuthService.java | 8 +------ .../github/scribejava/core/ObjectMother.java | 18 +++++---------- .../extractors/BaseStringExtractorTest.java | 3 +-- .../core/extractors/HeaderExtractorTest.java | 4 +--- .../core/model/OAuthRequestTest.java | 2 +- .../scribejava/core/model/RequestTest.java | 12 ++++------ 53 files changed, 121 insertions(+), 147 deletions(-) diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AWeberExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AWeberExample.java index 60bce4f71..324fcc013 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AWeberExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AWeberExample.java @@ -56,9 +56,9 @@ public static void main(String... args) throws IOException { // 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, ACCOUNT_RESOURCE_URL, service.getConfig()); + final OAuthRequest request = new OAuthRequest(Verb.GET, ACCOUNT_RESOURCE_URL); service.signRequest(accessToken, request); - final Response response = request.send(); + final Response response = service.execute(request); System.out.println("Got it! Lets see what we found..."); System.out.println(); System.out.println(response.getBody()); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Box20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Box20Example.java index af58ab9cc..c41e5f45e 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Box20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Box20Example.java @@ -76,9 +76,9 @@ public static void main(String... args) throws IOException { // 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.getConfig()); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); service.signRequest(accessToken, request); - final Response response = request.send(); + final 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/DiggExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiggExample.java index 238d6c1dc..61f6c1e75 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiggExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiggExample.java @@ -59,10 +59,10 @@ public static void main(String... args) throws IOException { // 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.POST, PROTECTED_RESOURCE_URL, service.getConfig()); + final OAuthRequest request = new OAuthRequest(Verb.POST, PROTECTED_RESOURCE_URL); request.addBodyParameter("comment_id", "20100729223726:4fef610331ee46a3b5cbd740bf71313e"); service.signRequest(accessToken, request); - final Response response = request.send(); + final 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/FacebookExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java index 32ce7d103..1aaa26ba5 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java @@ -69,9 +69,9 @@ public static void main(String... args) throws IOException { // 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.getConfig()); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); service.signRequest(accessToken, request); - final Response response = request.send(); + final 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/FlickrExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExample.java index 47c0f8a4e..c5055412b 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExample.java @@ -55,10 +55,10 @@ public static void main(String... args) throws IOException { // 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.getConfig()); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); request.addQuerystringParameter("method", "flickr.test.login"); service.signRequest(accessToken, request); - final Response response = request.send(); + final Response response = service.execute(request); System.out.println("Got it! Lets see what we found..."); System.out.println(); System.out.println(response.getBody()); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java index 042e8671c..1d371a51b 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java @@ -53,10 +53,9 @@ public static void main(String... args) throws IOException { // Now let's go and ask for a protected resource! System.out.println("Now we're going to access a protected resource..."); - final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL + accessToken.getAccessToken(), - service.getConfig()); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL + accessToken.getAccessToken()); service.signRequest(accessToken, request); - final Response response = request.send(); + final 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/FoursquareExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FoursquareExample.java index b347ce154..acfa08ce6 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FoursquareExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FoursquareExample.java @@ -51,9 +51,9 @@ public static void main(String... args) throws IOException { // 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.getConfig()); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); service.signRequest(accessToken, request); - final Response response = request.send(); + final Response response = service.execute(request); System.out.println("Got it! Lets see what we found..."); System.out.println(); System.out.println(response.getBody()); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java index 35cbed3e8..e1542dd0f 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java @@ -59,10 +59,10 @@ public static void main(String... args) throws IOException { // 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.getConfig()); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); service.signRequest(accessToken, request); request.addHeader("GData-Version", "3.0"); - final Response response = request.send(); + final 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/GeniusExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GeniusExample.java index 842b09ec6..f91fb5dc4 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GeniusExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GeniusExample.java @@ -75,9 +75,9 @@ public static void main(String... args) throws IOException { // Now let's go and ask for a protected resource! System.out.println("Accessing a protected resource..."); - final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service.getConfig()); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); service.signRequest(accessToken, request); - final Response response = request.send(); + final Response response = service.execute(request); System.out.println("Got it! Viewing contents..."); System.out.println(); System.out.println(response.getCode()); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubExample.java index 444b86856..bfd482f04 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubExample.java @@ -68,9 +68,9 @@ public static void main(String... args) throws IOException { // 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.getConfig()); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); service.signRequest(accessToken, request); - final Response response = request.send(); + final 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/Google20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java index 2c1c4a4fc..1fc8a6869 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java @@ -98,9 +98,9 @@ public static void main(String... args) throws IOException { requestUrl = PROTECTED_RESOURCE_URL + "?fields=" + query; } - final OAuthRequest request = new OAuthRequest(Verb.GET, requestUrl, service.getConfig()); + final OAuthRequest request = new OAuthRequest(Verb.GET, requestUrl); service.signRequest(accessToken, request); - final Response response = request.send(); + final Response response = service.execute(request); System.out.println(); System.out.println(response.getCode()); System.out.println(response.getBody()); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HHExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HHExample.java index ab09915ee..2a1d6d3f9 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HHExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HHExample.java @@ -54,9 +54,9 @@ public static void main(String... args) throws IOException { System.out.println(); System.out.println("Now we're going to access a protected resource..."); - final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service.getConfig()); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); service.signRequest(accessToken, request); - final Response response = request.send(); + final 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/ImgurExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ImgurExample.java index 62b6b5194..2eaa8db72 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ImgurExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ImgurExample.java @@ -53,9 +53,9 @@ public static void main(String... args) throws IOException { // 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.getConfig()); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); service.signRequest(accessToken, request); - final Response response = request.send(); + final 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/Kaixin20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Kaixin20Example.java index 8171127db..35591086e 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Kaixin20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Kaixin20Example.java @@ -53,9 +53,9 @@ public static void main(String... args) throws IOException { // 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.getConfig()); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); service.signRequest(accessToken, request); - final Response response = request.send(); + final 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/LinkedIn20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedIn20Example.java index 448a04d11..1dc096586 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 @@ -64,12 +64,11 @@ public static void main(String... args) throws IOException { break; } - final OAuthRequest request = new OAuthRequest(Verb.GET, String.format(PROTECTED_RESOURCE_URL, query), - service.getConfig()); + final OAuthRequest request = new OAuthRequest(Verb.GET, String.format(PROTECTED_RESOURCE_URL, query)); request.addHeader("x-li-format", "json"); request.addHeader("Accept-Language", "ru-RU"); service.signRequest(accessToken, request); - final Response response = request.send(); + final Response response = service.execute(request); System.out.println(); System.out.println(response.getCode()); System.out.println(response.getBody()); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java index 6bc3cf513..9c6a085ae 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java @@ -52,9 +52,9 @@ public static void main(String... args) throws IOException { // 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.getConfig()); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); service.signRequest(accessToken, request); - final Response response = request.send(); + final Response response = service.execute(request); System.out.println("Got it! Lets see what we found..."); System.out.println(); System.out.println(response.getBody()); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java index 7dbf7bc19..4bc2a3529 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java @@ -56,9 +56,9 @@ public static void main(String... args) throws IOException { // 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.getConfig()); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); service.signRequest(accessToken, request); - final Response response = request.send(); + final Response response = service.execute(request); System.out.println("Got it! Lets see what we found..."); System.out.println(); System.out.println(response.getBody()); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java index 5a09bc133..832382472 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java @@ -54,10 +54,9 @@ public static void main(String... args) throws IOException { // Now let's go and ask for a protected resource! System.out.println("Now we're going to access a protected resource..."); - final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL + accessToken.getAccessToken(), - service.getConfig()); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL + accessToken.getAccessToken()); service.signRequest(accessToken, request); - final Response response = request.send(); + final 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/MailruExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java index 91b0eee7a..9c633b9f4 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java @@ -54,9 +54,9 @@ public static void main(String... args) throws IOException { System.out.println(); System.out.println("Now we're going to access a protected resource..."); - final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service.getConfig()); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); service.signRequest(accessToken, request); - final Response response = request.send(); + final 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/MeetupExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java index e78ef808f..c488a1149 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java @@ -51,9 +51,9 @@ public static void main(String... args) throws IOException { // 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.getConfig()); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); service.signRequest(accessToken, request); - final Response response = request.send(); + final Response response = service.execute(request); System.out.println("Got it! Lets see what we found..."); System.out.println(); System.out.println(response.getBody()); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MisfitExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MisfitExample.java index e2c98b7a5..39037fde0 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MisfitExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MisfitExample.java @@ -56,9 +56,9 @@ public static void main(String... args) throws IOException { // 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.getConfig()); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); service.signRequest(accessToken, request); - final Response response = request.send(); + final 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/NaverExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NaverExample.java index 1a3eff1bb..962db655b 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NaverExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NaverExample.java @@ -70,9 +70,9 @@ public static void main(String... args) throws IOException { // 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.getConfig()); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); service.signRequest(accessToken, request); - final Response response = request.send(); + final 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/NeteaseWeiboExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NeteaseWeiboExample.java index 17217db97..27f2a6610 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NeteaseWeiboExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NeteaseWeiboExample.java @@ -59,9 +59,9 @@ public static void main(String... args) throws IOException { // 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.getConfig()); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); service.signRequest(accessToken, request); - final Response response = request.send(); + final 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/OdnoklassnikiExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java index c7b096715..a1c8e5bdb 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java @@ -65,10 +65,9 @@ public static void main(String... args) throws IOException { // 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, String.format(PROTECTED_RESOURCE_URL, publicKey), - service.getConfig()); + final OAuthRequest request = new OAuthRequest(Verb.GET, String.format(PROTECTED_RESOURCE_URL, publicKey)); service.signRequest(accessToken, request); - final Response response = request.send(); + final 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/PinterestExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java index 47f9c75dc..bb07b59cc 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java @@ -54,10 +54,9 @@ public static void main(String... args) throws IOException { // Now let's go and ask for a protected resource! System.out.println("Now we're going to access a protected resource..."); - final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL + accessToken.getAccessToken(), - service.getConfig()); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL + accessToken.getAccessToken()); service.signRequest(accessToken, request); - final Response response = request.send(); + final 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/Px500Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Px500Example.java index 76c3b29d9..c84acbaeb 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Px500Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Px500Example.java @@ -51,9 +51,9 @@ public static void main(String... args) throws IOException { // 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.getConfig()); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); service.signRequest(accessToken, request); - final Response response = request.send(); + final Response response = service.execute(request); System.out.println("Got it! Lets see what we found..."); System.out.println(); System.out.println(response.getBody()); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java index 2be75bef1..854eeb295 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java @@ -63,7 +63,7 @@ public static void main(String... args) throws IOException { // 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.POST, PROTECTED_RESOURCE_URL, service.getConfig()); + final OAuthRequest request = new OAuthRequest(Verb.POST, PROTECTED_RESOURCE_URL); final Map parameters = new HashMap<>(); parameters.put("method", "users.getInfo"); parameters.put("format", "json"); @@ -84,7 +84,7 @@ public static void main(String... args) throws IOException { System.out.println("Sig string: " + b.toString()); request.addQuerystringParameter("sig", md5(b.toString())); service.signRequest(accessToken, request); - final Response response = request.send(); + final 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/SalesforceExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceExample.java index 9f6b22aaf..d69181338 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceExample.java @@ -84,9 +84,9 @@ public static void main(String... args) throws IOException, NoSuchAlgorithmExcep System.out.println(); System.out.println("Full URL: " + url); - final OAuthRequest request = new OAuthRequest(Verb.GET, url, service.getConfig()); + final OAuthRequest request = new OAuthRequest(Verb.GET, url); request.addHeader("Authorization", "Bearer " + accessToken.getAccessToken()); - final Response response = request.send(); + final Response response = service.execute(request); System.out.println(); System.out.println(response.getCode()); System.out.println(response.getBody()); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeibo2Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeibo2Example.java index 414c2e18c..44b1ef2cf 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeibo2Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeibo2Example.java @@ -53,9 +53,9 @@ public static void main(String... args) throws IOException { // 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.getConfig()); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); service.signRequest(accessToken, request); - final Response response = request.send(); + final 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/SinaWeiboExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeiboExample.java index 140aa99ee..d09ff08e2 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeiboExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeiboExample.java @@ -59,9 +59,9 @@ public static void main(String... args) throws IOException { // 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.getConfig()); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); service.signRequest(accessToken, request); - final Response response = request.send(); + final 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/SkyrockExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SkyrockExample.java index 5ab1dd56a..d22a373e5 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SkyrockExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SkyrockExample.java @@ -51,9 +51,9 @@ public static void main(String... args) throws IOException { // 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.getConfig()); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); service.signRequest(accessToken, request); - final Response response = request.send(); + final 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/SohuWeiboExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SohuWeiboExample.java index cd9f62453..524268436 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SohuWeiboExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SohuWeiboExample.java @@ -59,9 +59,9 @@ public static void main(String... args) throws IOException { // 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.getConfig()); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); service.signRequest(accessToken, request); - final Response response = request.send(); + final 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/StackExchangeExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/StackExchangeExample.java index 6fe816df3..81e5bcf5a 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/StackExchangeExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/StackExchangeExample.java @@ -74,9 +74,9 @@ public static void main(String... args) throws IOException { // 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 + "?site=" + site + "&key=" + key, service.getConfig()); + PROTECTED_RESOURCE_URL + "?site=" + site + "&key=" + key); service.signRequest(accessToken, request); - final Response response = request.send(); + final 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/TheThingsNetworkV1StagingExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV1StagingExample.java index b0bc642f1..22fa12a73 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV1StagingExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV1StagingExample.java @@ -75,7 +75,7 @@ public static void main(String... args) throws IOException { // 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.getConfig()); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); // TTN should support both signing the request with a parameter, or with a header. // 1. Token as a parameter @@ -84,7 +84,7 @@ public static void main(String... args) throws IOException { //request.addHeader("Authorization", "bearer "+accessToken.getAccessToken()); // And we always expect JSON data. request.addHeader("Accept", "application/json"); - final Response response = request.send(); + final 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/TheThingsNetworkV2PreviewExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV2PreviewExample.java index 2b6ce70e9..1f6bb61bb 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV2PreviewExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV2PreviewExample.java @@ -72,7 +72,7 @@ public static void main(String... args) throws IOException { // 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.getConfig()); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); // TTN should support both signing the request with a parameter, or with a header. // 1. Token as a parameter @@ -81,7 +81,7 @@ public static void main(String... args) throws IOException { //request.addHeader("Authorization", "bearer "+accessToken.getAccessToken()); // And we always expect JSON data. request.addHeader("Accept", "application/json"); - final Response response = request.send(); + final 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/TrelloExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TrelloExample.java index 21350ea9f..b2371312f 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TrelloExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TrelloExample.java @@ -53,9 +53,9 @@ public static void main(String... args) throws IOException { // 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.getConfig()); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); service.signRequest(accessToken, request); - final Response response = request.send(); + final Response response = service.execute(request); System.out.println("Got it! Lets see what we found..."); System.out.println(); System.out.println(response.getBody()); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TumblrExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TumblrExample.java index e94e1f31b..efcc38cee 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TumblrExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TumblrExample.java @@ -53,9 +53,9 @@ public static void main(String... args) throws IOException { // 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.getConfig()); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); service.signRequest(accessToken, request); - final Response response = request.send(); + final Response response = service.execute(request); System.out.println("Got it! Lets see what we found..."); System.out.println(); System.out.println(response.getBody()); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TutByExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TutByExample.java index 82e57a344..012c2b88f 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TutByExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TutByExample.java @@ -54,9 +54,9 @@ public static void main(String... args) throws IOException { // 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.getConfig()); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); service.signRequest(accessToken, request); - final Response response = request.send(); + final 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/TwitterExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TwitterExample.java index 41a7ea5d6..b000f0c3f 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TwitterExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TwitterExample.java @@ -51,9 +51,9 @@ public static void main(String... args) throws IOException { // 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.getConfig()); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); service.signRequest(accessToken, request); - final Response response = request.send(); + final Response response = service.execute(request); System.out.println("Got it! Lets see what we found..."); System.out.println(); System.out.println(response.getBody()); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ViadeoExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ViadeoExample.java index a89fef634..a9e16905e 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ViadeoExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ViadeoExample.java @@ -53,9 +53,9 @@ public static void main(String... args) throws IOException { // 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.getConfig()); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); service.signRequest(accessToken, request); - final Response response = request.send(); + final 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/VkontakteExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExample.java index 5ca4ae8de..57bea7831 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 @@ -54,9 +54,9 @@ public static void main(String... args) throws IOException { // 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.getConfig()); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); service.signRequest(accessToken, request); - final Response response = request.send(); + final 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/XingExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XingExample.java index 93d57b963..4e6037b88 100755 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XingExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XingExample.java @@ -51,9 +51,9 @@ public static void main(String... args) throws IOException { // 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.getConfig()); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); service.signRequest(accessToken, request); - final Response response = request.send(); + final Response response = service.execute(request); System.out.println("Got it! Lets see what we found..."); System.out.println(); System.out.println(response.getBody()); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/YahooExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/YahooExample.java index 7127d28cd..3f4d52563 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/YahooExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/YahooExample.java @@ -52,9 +52,9 @@ public static void main(String... args) throws IOException { // 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.getConfig()); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); service.signRequest(accessToken, request); - final Response response = request.send(); + final 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/service/OdnoklassnikiServiceTest.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/service/OdnoklassnikiServiceTest.java index 4e4e833cf..af14b9744 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/service/OdnoklassnikiServiceTest.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/service/OdnoklassnikiServiceTest.java @@ -27,7 +27,7 @@ public class OdnoklassnikiServiceTest { @Test public void testSigGeneration() { final OAuth2AccessToken accessToken = new OAuth2AccessToken("d3iwa.403gvrs194740652m1k4w2a503k3c"); - final OAuthRequest request = new OAuthRequest(Verb.GET, URL, service.getConfig()); + final OAuthRequest request = new OAuthRequest(Verb.GET, URL); service.signRequest(accessToken, request); assertEquals("96127f5ca29a8351399e94bbd284ab16", findParam(request.getQueryStringParams(), "sig")); } 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 a7ee73b7b..b4feb382f 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 @@ -5,7 +5,6 @@ import java.util.Map; import com.github.scribejava.core.exceptions.OAuthConnectionException; import com.github.scribejava.core.exceptions.OAuthException; -import com.github.scribejava.core.oauth.OAuthService; import java.io.File; import java.net.URL; import java.net.UnknownHostException; @@ -14,23 +13,23 @@ public class OAuthRequest extends AbstractRequest { - private final OAuthConfig config; - - public OAuthRequest(Verb verb, String url, OAuthConfig config) { + public OAuthRequest(Verb verb, String url) { super(verb, url); - this.config = config; } /** - * Execute the request and return a {@link Response} - * - * the same as {@link OAuthService#execute(com.github.scribejava.core.model.OAuthRequest)} - * - * @return Http Response * - * @throws RuntimeException if the connection cannot be created. + * @param verb verb + * @param url url + * @param config unused + * @deprecated use {@link #OAuthRequest(com.github.scribejava.core.model.Verb, java.lang.String) } */ - public Response send() { + @Deprecated + public OAuthRequest(Verb verb, String url, OAuthConfig config) { + this(verb, url); + } + + public Response send(OAuthConfig config) { try { return doSend(config, isFollowRedirects(), getHeaders(), getVerb(), getCompleteUrl(), this); } catch (IOException | RuntimeException e) { 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 cf988c846..7c86ff342 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 @@ -38,12 +38,12 @@ public OAuth10aService(DefaultApi10a api, OAuthConfig config) { public final OAuth1RequestToken getRequestToken() throws IOException { final OAuthConfig config = getConfig(); config.log("obtaining request token from " + api.getRequestTokenEndpoint()); - final OAuthRequest request = new OAuthRequest(api.getRequestTokenVerb(), api.getRequestTokenEndpoint(), config); + final OAuthRequest request = new OAuthRequest(api.getRequestTokenVerb(), api.getRequestTokenEndpoint()); prepareRequestTokenRequest(request); config.log("sending request..."); - final Response response = request.send(); + final Response response = execute(request); final String body = response.getBody(); config.log("response status code: " + response.getCode()); @@ -92,11 +92,10 @@ private void addOAuthParams(AbstractRequest request, String tokenSecret) { public final OAuth1AccessToken getAccessToken(OAuth1RequestToken requestToken, String oauthVerifier) throws IOException { - final OAuthConfig config = getConfig(); - config.log("obtaining access token from " + api.getAccessTokenEndpoint()); - final OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint(), config); + getConfig().log("obtaining access token from " + api.getAccessTokenEndpoint()); + final OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint()); prepareAccessTokenRequest(request, requestToken, oauthVerifier); - final Response response = request.send(); + final Response response = execute(request); return api.getAccessTokenExtractor().extract(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 656f0816d..7c9d11ddf 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 @@ -34,7 +34,7 @@ public OAuth20Service(DefaultApi20 api, OAuthConfig config) { //sync version, protected to facilitate mocking protected OAuth2AccessToken sendAccessTokenRequestSync(OAuthRequest request) throws IOException { - return api.getAccessTokenExtractor().extract(request.send()); + return api.getAccessTokenExtractor().extract(execute(request)); } //async version, protected to facilitate mocking @@ -51,7 +51,7 @@ public OAuth2AccessToken convert(Response response) throws IOException { public final OAuth2AccessToken getAccessToken(String code) throws IOException { final OAuthRequest request = createAccessTokenRequest(code, - new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint(), getConfig())); + new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint())); return sendAccessTokenRequestSync(request); } @@ -88,7 +88,7 @@ protected T createAccessTokenRequest(String code, T public final OAuth2AccessToken refreshAccessToken(String refreshToken) throws IOException { final OAuthRequest request = createRefreshTokenRequest(refreshToken, - new OAuthRequest(api.getAccessTokenVerb(), api.getRefreshTokenEndpoint(), getConfig())); + new OAuthRequest(api.getAccessTokenVerb(), api.getRefreshTokenEndpoint())); return sendAccessTokenRequestSync(request); } @@ -115,7 +115,7 @@ protected T createRefreshTokenRequest(String refresh public final OAuth2AccessToken getAccessTokenPasswordGrant(String uname, String password) throws IOException { final OAuthRequest request = createAccessTokenPasswordGrantRequest(uname, password, - new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint(), getConfig())); + new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint())); return sendAccessTokenRequestSync(request); } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java index 3eb6b4890..1870115c8 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java @@ -101,13 +101,7 @@ public Response execute(OAuthRequestAsync request) throws InterruptedException, } } - /** - * the same as {@link OAuthRequest#send()} - * - * @param request request - * @return Response - */ public Response execute(OAuthRequest request) { - return request.send(); + return request.send(config); } } diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/ObjectMother.java b/scribejava-core/src/test/java/com/github/scribejava/core/ObjectMother.java index c8d9d0ed4..07e4081ec 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/ObjectMother.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/ObjectMother.java @@ -1,6 +1,5 @@ package com.github.scribejava.core; -import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Verb; @@ -8,7 +7,7 @@ public abstract class ObjectMother { public static OAuthRequest createSampleOAuthRequest() { - final OAuthRequest request = new OAuthRequest(Verb.GET, "http://example.com", new OAuthConfig("test", "test")); + final OAuthRequest request = new OAuthRequest(Verb.GET, "http://example.com"); request.addOAuthParameter(OAuthConstants.TIMESTAMP, "123456"); request.addOAuthParameter(OAuthConstants.CONSUMER_KEY, "AS#$^*@&"); request.addOAuthParameter(OAuthConstants.CALLBACK, "http://example/callback"); @@ -17,8 +16,7 @@ public static OAuthRequest createSampleOAuthRequest() { } public static OAuthRequest createSampleOAuthRequestPort80() { - final OAuthRequest request = new OAuthRequest(Verb.GET, "http://example.com:80", - new OAuthConfig("test", "test")); + final OAuthRequest request = new OAuthRequest(Verb.GET, "http://example.com:80"); request.addOAuthParameter(OAuthConstants.TIMESTAMP, "123456"); request.addOAuthParameter(OAuthConstants.CONSUMER_KEY, "AS#$^*@&"); request.addOAuthParameter(OAuthConstants.CALLBACK, "http://example/callback"); @@ -27,8 +25,7 @@ public static OAuthRequest createSampleOAuthRequestPort80() { } public static OAuthRequest createSampleOAuthRequestPort80v2() { - final OAuthRequest request = new OAuthRequest(Verb.GET, "http://example.com:80/test", - new OAuthConfig("test", "test")); + final OAuthRequest request = new OAuthRequest(Verb.GET, "http://example.com:80/test"); request.addOAuthParameter(OAuthConstants.TIMESTAMP, "123456"); request.addOAuthParameter(OAuthConstants.CONSUMER_KEY, "AS#$^*@&"); request.addOAuthParameter(OAuthConstants.CALLBACK, "http://example/callback"); @@ -37,8 +34,7 @@ public static OAuthRequest createSampleOAuthRequestPort80v2() { } public static OAuthRequest createSampleOAuthRequestPort8080() { - final OAuthRequest request = new OAuthRequest(Verb.GET, "http://example.com:8080", - new OAuthConfig("test", "test")); + final OAuthRequest request = new OAuthRequest(Verb.GET, "http://example.com:8080"); request.addOAuthParameter(OAuthConstants.TIMESTAMP, "123456"); request.addOAuthParameter(OAuthConstants.CONSUMER_KEY, "AS#$^*@&"); request.addOAuthParameter(OAuthConstants.CALLBACK, "http://example/callback"); @@ -47,8 +43,7 @@ public static OAuthRequest createSampleOAuthRequestPort8080() { } public static OAuthRequest createSampleOAuthRequestPort443() { - final OAuthRequest request = new OAuthRequest(Verb.GET, "https://example.com:443", - new OAuthConfig("test", "test")); + final OAuthRequest request = new OAuthRequest(Verb.GET, "https://example.com:443"); request.addOAuthParameter(OAuthConstants.TIMESTAMP, "123456"); request.addOAuthParameter(OAuthConstants.CONSUMER_KEY, "AS#$^*@&"); request.addOAuthParameter(OAuthConstants.CALLBACK, "http://example/callback"); @@ -57,8 +52,7 @@ public static OAuthRequest createSampleOAuthRequestPort443() { } public static OAuthRequest createSampleOAuthRequestPort443v2() { - final OAuthRequest request = new OAuthRequest(Verb.GET, "https://example.com:443/test", - new OAuthConfig("test", "test")); + final OAuthRequest request = new OAuthRequest(Verb.GET, "https://example.com:443/test"); request.addOAuthParameter(OAuthConstants.TIMESTAMP, "123456"); request.addOAuthParameter(OAuthConstants.CONSUMER_KEY, "AS#$^*@&"); request.addOAuthParameter(OAuthConstants.CALLBACK, "http://example/callback"); 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 f207f299e..bc833db08 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 @@ -5,7 +5,6 @@ import org.junit.Test; import com.github.scribejava.core.ObjectMother; import com.github.scribejava.core.exceptions.OAuthParametersMissingException; -import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Verb; @@ -91,7 +90,7 @@ public void shouldThrowExceptionIfRquestIsNull() { @Test(expected = OAuthParametersMissingException.class) public void shouldThrowExceptionIfRquestHasNoOAuthParameters() { - final OAuthRequest request = new OAuthRequest(Verb.GET, "http://example.com", new OAuthConfig("test", "test")); + final OAuthRequest request = new OAuthRequest(Verb.GET, "http://example.com"); extractor.extract(request); } 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 63f6d4752..c1658fc7e 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 @@ -5,7 +5,6 @@ import org.junit.Before; import org.junit.Test; import com.github.scribejava.core.exceptions.OAuthParametersMissingException; -import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.ObjectMother; @@ -51,8 +50,7 @@ public void shouldExceptionIfRequestIsNull() { @Test(expected = OAuthParametersMissingException.class) public void shouldExceptionIfRequestHasNoOAuthParams() { - final OAuthRequest emptyRequest = new OAuthRequest(Verb.GET, "http://example.com", - new OAuthConfig("test", "test")); + final OAuthRequest emptyRequest = new OAuthRequest(Verb.GET, "http://example.com"); extractor.extract(emptyRequest); } } 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 1e632dab8..0ea88985d 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 @@ -10,7 +10,7 @@ public class OAuthRequestTest { @Before public void setUp() { - request = new OAuthRequest(Verb.GET, "http://example.com", new OAuthConfig("test", "test")); + request = new OAuthRequest(Verb.GET, "http://example.com"); } @Test diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/model/RequestTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/model/RequestTest.java index bdce597ef..274ccca23 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/model/RequestTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/model/RequestTest.java @@ -10,18 +10,14 @@ public class RequestTest { private OAuthRequest getRequest; private OAuthRequest postRequest; - private OAuthConfig config; @Before public void setUp() throws MalformedURLException { - config = new OAuthConfig("test", "test"); - - postRequest = new OAuthRequest(Verb.POST, "http://example.com", config); + postRequest = new OAuthRequest(Verb.POST, "http://example.com"); postRequest.addBodyParameter("param", "value"); postRequest.addBodyParameter("param with spaces", "value with spaces"); - getRequest = new OAuthRequest(Verb.GET, "http://example.com?qsparam=value&other+param=value+with+spaces", - config); + getRequest = new OAuthRequest(Verb.GET, "http://example.com?qsparam=value&other+param=value+with+spaces"); } @Test @@ -45,7 +41,7 @@ public void shouldSetPayloadAndHeaders() { @Test public void shouldAllowAddingQuerystringParametersAfterCreation() { - final OAuthRequest request = new OAuthRequest(Verb.GET, "http://example.com?one=val", config); + final OAuthRequest request = new OAuthRequest(Verb.GET, "http://example.com?one=val"); request.addQuerystringParameter("two", "other val"); request.addQuerystringParameter("more", "params"); assertEquals(3, request.getQueryStringParams().size()); @@ -53,7 +49,7 @@ public void shouldAllowAddingQuerystringParametersAfterCreation() { @Test public void shouldReturnTheCompleteUrl() { - final OAuthRequest request = new OAuthRequest(Verb.GET, "http://example.com?one=val", config); + final OAuthRequest request = new OAuthRequest(Verb.GET, "http://example.com?one=val"); request.addQuerystringParameter("two", "other val"); request.addQuerystringParameter("more", "params"); assertEquals("http://example.com?one=val&two=other%20val&more=params", request.getCompleteUrl()); From 8dc788310ac737584e20fc003e5bf68ddbe7523d Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 9 Jan 2017 19:23:51 +0300 Subject: [PATCH 340/882] move JDK HTTP client specific config (connectTimeout and readTimeout) to separate class (JDKHttpClientConfig) --- .../core/builder/ServiceBuilder.java | 44 ++++++++++++++----- .../httpclient/jdk/JDKHttpClientConfig.java | 34 ++++++++++++++ .../scribejava/core/model/OAuthConfig.java | 42 +++++++++++------- .../scribejava/core/model/OAuthRequest.java | 20 +++++---- .../scribejava/core/oauth/OAuthService.java | 6 ++- .../httpclient/ahc/AhcHttpClientConfig.java | 4 +- .../httpclient/ning/NingHttpClientConfig.java | 4 +- .../okhttp/OkHttpHttpClientConfig.java | 4 +- .../okhttp/OkHttpHttpClientTest.java | 2 +- 9 files changed, 118 insertions(+), 42 deletions(-) create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClientConfig.java 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 dd1cc1989..ca7e5f05e 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilder.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilder.java @@ -3,6 +3,7 @@ import com.github.scribejava.core.builder.api.BaseApi; import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.httpclient.HttpClientConfig; +import com.github.scribejava.core.httpclient.jdk.JDKHttpClientConfig; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.SignatureType; @@ -26,11 +27,6 @@ public class ServiceBuilder { private String responseType = "code"; private String userAgent; - //sync version only - private Integer connectTimeout; - private Integer readTimeout; - - //not-default httpclient only private HttpClientConfig httpClientConfig; private HttpClient httpClient; @@ -123,15 +119,43 @@ public ServiceBuilder responseType(String responseType) { return this; } + /** + * + * @param connectTimeout connectTimeout + * @return ServiceBuilder to chain methods + * @deprecated use {@link com.github.scribejava.core.httpclient.jdk.JDKHttpClientConfig} and + *
{@link #httpClientConfig(com.github.scribejava.core.httpclient.HttpClientConfig) } + */ + @Deprecated public ServiceBuilder connectTimeout(Integer connectTimeout) { - Preconditions.checkNotNull(connectTimeout, "Connection timeout can't be null"); - this.connectTimeout = connectTimeout; + final JDKHttpClientConfig jdkHttpClientConfig; + if (httpClientConfig instanceof JDKHttpClientConfig) { + jdkHttpClientConfig = (JDKHttpClientConfig) httpClientConfig; + } else { + jdkHttpClientConfig = new JDKHttpClientConfig(); + httpClientConfig = jdkHttpClientConfig; + } + jdkHttpClientConfig.setConnectTimeout(connectTimeout); return this; } + /** + * + * @param readTimeout readTimeout + * @return ServiceBuilder to chain methods + * @deprecated use {@link com.github.scribejava.core.httpclient.jdk.JDKHttpClientConfig} and + *
{@link #httpClientConfig(com.github.scribejava.core.httpclient.HttpClientConfig) } + */ + @Deprecated public ServiceBuilder readTimeout(Integer readTimeout) { - Preconditions.checkNotNull(readTimeout, "Read timeout can't be null"); - this.readTimeout = readTimeout; + final JDKHttpClientConfig jdkHttpClientConfig; + if (httpClientConfig instanceof JDKHttpClientConfig) { + jdkHttpClientConfig = (JDKHttpClientConfig) httpClientConfig; + } else { + jdkHttpClientConfig = new JDKHttpClientConfig(); + httpClientConfig = jdkHttpClientConfig; + } + jdkHttpClientConfig.setReadTimeout(readTimeout); return this; } @@ -169,7 +193,7 @@ public void checkPreconditions() { private OAuthConfig createConfig() { checkPreconditions(); return new OAuthConfig(apiKey, apiSecret, callback, signatureType, scope, debugStream, state, responseType, - userAgent, connectTimeout, readTimeout, httpClientConfig, httpClient); + userAgent, httpClientConfig, httpClient); } /** diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClientConfig.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClientConfig.java new file mode 100644 index 000000000..471fb5c96 --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClientConfig.java @@ -0,0 +1,34 @@ +package com.github.scribejava.core.httpclient.jdk; + +import com.github.scribejava.core.httpclient.HttpClientConfig; + +public class JDKHttpClientConfig implements HttpClientConfig { + + private Integer connectTimeout; + private Integer readTimeout; + + @Override + public JDKHttpClientConfig createDefaultConfig() { + return defaultConfig(); + } + + public static JDKHttpClientConfig defaultConfig() { + return new JDKHttpClientConfig(); + } + + public Integer getConnectTimeout() { + return connectTimeout; + } + + public void setConnectTimeout(Integer connectTimeout) { + this.connectTimeout = connectTimeout; + } + + public Integer getReadTimeout() { + return readTimeout; + } + + public void setReadTimeout(Integer readTimeout) { + this.readTimeout = readTimeout; + } +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConfig.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConfig.java index b54c79180..65df39368 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConfig.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConfig.java @@ -1,6 +1,8 @@ package com.github.scribejava.core.model; +import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.httpclient.HttpClientConfig; +import com.github.scribejava.core.httpclient.jdk.JDKHttpClientConfig; import java.io.IOException; import java.io.OutputStream; @@ -19,22 +21,16 @@ public class OAuthConfig { private final String responseType; private final String userAgent; - //sync only version - private final Integer connectTimeout; - private final Integer readTimeout; - - //async version only private HttpClientConfig httpClientConfig; - private com.github.scribejava.core.httpclient.HttpClient httpClient; + private HttpClient httpClient; public OAuthConfig(String key, String secret) { - this(key, secret, null, null, null, null, null, null, null, null, null, null, null); + this(key, secret, null, null, null, null, null, null, null, null, null); } public OAuthConfig(String apiKey, String apiSecret, String callback, SignatureType signatureType, String scope, - OutputStream debugStream, String state, String responseType, String userAgent, Integer connectTimeout, - Integer readTimeout, HttpClientConfig httpClientConfig, - com.github.scribejava.core.httpclient.HttpClient httpClient) { + OutputStream debugStream, String state, String responseType, String userAgent, + HttpClientConfig httpClientConfig, HttpClient httpClient) { this.apiKey = apiKey; this.apiSecret = apiSecret; this.callback = callback; @@ -44,8 +40,6 @@ public OAuthConfig(String apiKey, String apiSecret, String callback, SignatureTy this.state = state; this.responseType = responseType; this.userAgent = userAgent; - this.connectTimeout = connectTimeout; - this.readTimeout = readTimeout; this.httpClientConfig = httpClientConfig; this.httpClient = httpClient; } @@ -93,19 +87,37 @@ public void log(String message) { } } + /** + * + * @return Connect Timeout + * @deprecated use {@link JDKHttpClientConfig} + */ + @Deprecated public Integer getConnectTimeout() { - return connectTimeout; + if (httpClientConfig instanceof JDKHttpClientConfig) { + return ((JDKHttpClientConfig) httpClientConfig).getConnectTimeout(); + } + return null; } + /** + * + * @return Read Timeout + * @deprecated use {@link JDKHttpClientConfig} + */ + @Deprecated public Integer getReadTimeout() { - return readTimeout; + if (httpClientConfig instanceof JDKHttpClientConfig) { + return ((JDKHttpClientConfig) httpClientConfig).getReadTimeout(); + } + return null; } public HttpClientConfig getHttpClientConfig() { return httpClientConfig; } - public com.github.scribejava.core.httpclient.HttpClient getHttpClient() { + public HttpClient getHttpClient() { return httpClient; } } 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 b4feb382f..bb8254f22 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 @@ -5,6 +5,7 @@ import java.util.Map; import com.github.scribejava.core.exceptions.OAuthConnectionException; import com.github.scribejava.core.exceptions.OAuthException; +import com.github.scribejava.core.httpclient.jdk.JDKHttpClientConfig; import java.io.File; import java.net.URL; import java.net.UnknownHostException; @@ -29,26 +30,27 @@ public OAuthRequest(Verb verb, String url, OAuthConfig config) { this(verb, url); } - public Response send(OAuthConfig config) { + public Response send(String userAgent, JDKHttpClientConfig httpClientConfig) { try { - return doSend(config, isFollowRedirects(), getHeaders(), getVerb(), getCompleteUrl(), this); + return doSend(userAgent, httpClientConfig, isFollowRedirects(), getHeaders(), getVerb(), getCompleteUrl(), + this); } catch (IOException | RuntimeException e) { throw new OAuthConnectionException(getCompleteUrl(), e); } } - private static Response doSend(OAuthConfig config, boolean followRedirects, Map headers, - Verb httpVerb, String completeUrl, OAuthRequest request) throws IOException { + private static Response doSend(String userAgent, JDKHttpClientConfig httpClientConfig, boolean followRedirects, + Map headers, Verb httpVerb, String completeUrl, OAuthRequest request) throws IOException { final HttpURLConnection connection = (HttpURLConnection) new URL(completeUrl).openConnection(); connection.setInstanceFollowRedirects(followRedirects); connection.setRequestMethod(httpVerb.name()); - if (config.getConnectTimeout() != null) { - connection.setConnectTimeout(config.getConnectTimeout()); + if (httpClientConfig.getConnectTimeout() != null) { + connection.setConnectTimeout(httpClientConfig.getConnectTimeout()); } - if (config.getReadTimeout() != null) { - connection.setReadTimeout(config.getReadTimeout()); + if (httpClientConfig.getReadTimeout() != null) { + connection.setReadTimeout(httpClientConfig.getReadTimeout()); } - addHeaders(connection, headers, config.getUserAgent()); + addHeaders(connection, headers, userAgent); if (httpVerb == Verb.POST || httpVerb == Verb.PUT || httpVerb == Verb.DELETE) { final File filePayload = request.getFilePayload(); if (filePayload != null) { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java index 1870115c8..8553aa4a1 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java @@ -4,6 +4,7 @@ import com.github.scribejava.core.model.AbstractRequest; import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.httpclient.HttpClientConfig; +import com.github.scribejava.core.httpclient.jdk.JDKHttpClientConfig; import com.github.scribejava.core.model.OAuthAsyncRequestCallback; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthRequest; @@ -102,6 +103,9 @@ public Response execute(OAuthRequestAsync request) throws InterruptedException, } public Response execute(OAuthRequest request) { - return request.send(config); + final HttpClientConfig httpClientConfig = config.getHttpClientConfig(); + return request.send(config.getUserAgent(), + httpClientConfig instanceof JDKHttpClientConfig ? (JDKHttpClientConfig) httpClientConfig + : JDKHttpClientConfig.defaultConfig()); } } diff --git a/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/AhcHttpClientConfig.java b/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/AhcHttpClientConfig.java index 67fc92bdf..490eaf2e6 100644 --- a/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/AhcHttpClientConfig.java +++ b/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/AhcHttpClientConfig.java @@ -16,11 +16,11 @@ public AsyncHttpClientConfig getClientConfig() { } @Override - public HttpClientConfig createDefaultConfig() { + public AhcHttpClientConfig createDefaultConfig() { return defaultConfig(); } - public static HttpClientConfig defaultConfig() { + public static AhcHttpClientConfig defaultConfig() { return new AhcHttpClientConfig(null); } } diff --git a/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/NingHttpClientConfig.java b/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/NingHttpClientConfig.java index 1dc5aad2a..9eb5d83c2 100644 --- a/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/NingHttpClientConfig.java +++ b/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/NingHttpClientConfig.java @@ -25,11 +25,11 @@ public AsyncHttpClientConfig getConfig() { } @Override - public HttpClientConfig createDefaultConfig() { + public NingHttpClientConfig createDefaultConfig() { return defaultConfig(); } - public static HttpClientConfig defaultConfig() { + public static NingHttpClientConfig defaultConfig() { return new NingHttpClientConfig(null); } } diff --git a/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClientConfig.java b/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClientConfig.java index 62737fe31..7759a0936 100644 --- a/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClientConfig.java +++ b/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClientConfig.java @@ -16,11 +16,11 @@ public OkHttpClient.Builder getClientBuilder() { } @Override - public HttpClientConfig createDefaultConfig() { + public OkHttpHttpClientConfig createDefaultConfig() { return defaultConfig(); } - public static HttpClientConfig defaultConfig() { + public static OkHttpHttpClientConfig defaultConfig() { return new OkHttpHttpClientConfig(null); } } diff --git a/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClientTest.java b/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClientTest.java index 917fe1ce8..9770f403a 100644 --- a/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClientTest.java +++ b/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClientTest.java @@ -27,7 +27,7 @@ public class OkHttpHttpClientTest { public void setUp() { final HttpClient client = new OkHttpHttpClient(new OkHttpClient()); oAuthService = new OAuth20Service(null, - new OAuthConfig("test", "test", null, null, null, null, null, null, null, null, null, null, client)); + new OAuthConfig("test", "test", null, null, null, null, null, null, null, null, client)); } From a75a695ff7c81e21c04c4e3a2e190d1e4b66b425 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 10 Jan 2017 12:11:48 +0300 Subject: [PATCH 341/882] move JDK HTTP client specific config (followRedirects) from OAuthRequest to JDKHttpClientConfig --- .../httpclient/jdk/JDKHttpClientConfig.java | 18 ++++++++++++++++++ .../scribejava/core/model/AbstractRequest.java | 18 ------------------ .../scribejava/core/model/OAuthRequest.java | 8 ++++---- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClientConfig.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClientConfig.java index 471fb5c96..cfb97b359 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClientConfig.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClientConfig.java @@ -6,6 +6,7 @@ public class JDKHttpClientConfig implements HttpClientConfig { private Integer connectTimeout; private Integer readTimeout; + private boolean followRedirects = true; @Override public JDKHttpClientConfig createDefaultConfig() { @@ -31,4 +32,21 @@ public Integer getReadTimeout() { public void setReadTimeout(Integer readTimeout) { this.readTimeout = readTimeout; } + + public boolean isFollowRedirects() { + return followRedirects; + } + + /** + * Sets whether the underlying Http Connection follows redirects or not. + * + * Defaults to true (follow redirects) + * + * @see http://docs.oracle.com/javase/6/docs/api/java/net/HttpURLConnection.html#setInstanceFollowRedirects(boolean) + * @param followRedirects boolean + */ + public void setFollowRedirects(boolean followRedirects) { + this.followRedirects = followRedirects; + } } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/AbstractRequest.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/AbstractRequest.java index 3a5499c03..9e48c4f52 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/AbstractRequest.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/AbstractRequest.java @@ -24,7 +24,6 @@ public abstract class AbstractRequest { private final ParameterList querystringParams = new ParameterList(); private final ParameterList bodyParams = new ParameterList(); private final Map headers = new HashMap<>(); - private boolean followRedirects = true; private String charset; @@ -275,21 +274,4 @@ public String getCharset() { public void setCharset(String charsetName) { charset = charsetName; } - - /** - * Sets whether the underlying Http Connection follows redirects or not. - * - * Defaults to true (follow redirects) - * - * @see http://docs.oracle.com/javase/6/docs/api/java/net/HttpURLConnection.html#setInstanceFollowRedirects(boolean) - * @param followRedirects boolean - */ - public void setFollowRedirects(boolean followRedirects) { - this.followRedirects = followRedirects; - } - - public boolean isFollowRedirects() { - return followRedirects; - } } 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 bb8254f22..e498d62fa 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 @@ -32,17 +32,17 @@ public OAuthRequest(Verb verb, String url, OAuthConfig config) { public Response send(String userAgent, JDKHttpClientConfig httpClientConfig) { try { - return doSend(userAgent, httpClientConfig, isFollowRedirects(), getHeaders(), getVerb(), getCompleteUrl(), + return doSend(userAgent, httpClientConfig, getHeaders(), getVerb(), getCompleteUrl(), this); } catch (IOException | RuntimeException e) { throw new OAuthConnectionException(getCompleteUrl(), e); } } - private static Response doSend(String userAgent, JDKHttpClientConfig httpClientConfig, boolean followRedirects, - Map headers, Verb httpVerb, String completeUrl, OAuthRequest request) throws IOException { + private static Response doSend(String userAgent, JDKHttpClientConfig httpClientConfig, Map headers, + Verb httpVerb, String completeUrl, OAuthRequest request) throws IOException { final HttpURLConnection connection = (HttpURLConnection) new URL(completeUrl).openConnection(); - connection.setInstanceFollowRedirects(followRedirects); + connection.setInstanceFollowRedirects(httpClientConfig.isFollowRedirects()); connection.setRequestMethod(httpVerb.name()); if (httpClientConfig.getConnectTimeout() != null) { connection.setConnectTimeout(httpClientConfig.getConnectTimeout()); From a69f9def256f09cf9758ef9773c28e3091af3567 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 11 Jan 2017 14:09:38 +0300 Subject: [PATCH 342/882] introduce JDKHttpClient (default). --- .../core/httpclient/HttpClient.java | 3 + .../core/httpclient/jdk/JDKHttpClient.java | 147 ++++++++++++++++++ .../core/httpclient/jdk/JDKHttpProvider.java | 16 ++ .../core/model/AbstractRequest.java | 3 - .../scribejava/core/model/OAuthRequest.java | 87 ----------- .../scribejava/core/oauth/OAuthService.java | 11 +- ...ibejava.core.httpclient.HttpClientProvider | 2 + .../httpclient/ahc/AhcHttpClient.java | 6 +- .../httpclient/ning/NingHttpClient.java | 6 +- .../httpclient/okhttp/OkHttpHttpClient.java | 6 +- 10 files changed, 180 insertions(+), 107 deletions(-) create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpProvider.java create mode 100644 scribejava-core/src/main/resources/META-INF/services/com.github.scribejava.core.httpclient.HttpClientProvider diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/HttpClient.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/HttpClient.java index 9377226f9..3d6d0433f 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/HttpClient.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/HttpClient.java @@ -11,6 +11,9 @@ import java.util.concurrent.Future; public interface HttpClient { + String DEFAULT_CONTENT_TYPE = "application/x-www-form-urlencoded"; + String CONTENT_TYPE = "Content-Type"; + String CONTENT_LENGTH = "Content-Length"; void close() throws IOException; diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java new file mode 100644 index 000000000..0a673f056 --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java @@ -0,0 +1,147 @@ +package com.github.scribejava.core.httpclient.jdk; + +import com.github.scribejava.core.exceptions.OAuthConnectionException; +import com.github.scribejava.core.exceptions.OAuthException; +import com.github.scribejava.core.httpclient.HttpClient; +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.OAuthRequestAsync; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.Verb; +import java.io.File; +import java.io.IOException; +import java.net.HttpURLConnection; +import java.net.URL; +import java.net.UnknownHostException; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Future; + +public class JDKHttpClient implements HttpClient { + + private final JDKHttpClientConfig config; + + public JDKHttpClient(JDKHttpClientConfig clientConfig) { + config = clientConfig; + } + + @Override + public void close() throws IOException { + } + + @Override + public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, + byte[] bodyContents, OAuthAsyncRequestCallback callback, + OAuthRequestAsync.ResponseConverter converter) { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, + String bodyContents, OAuthAsyncRequestCallback callback, + OAuthRequestAsync.ResponseConverter converter) { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, + File bodyContents, OAuthAsyncRequestCallback callback, + OAuthRequestAsync.ResponseConverter converter) { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public Response execute(String userAgent, Map headers, Verb httpVerb, String completeUrl, + byte[] bodyContents) throws InterruptedException, ExecutionException, IOException { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public Response execute(String userAgent, Map headers, Verb httpVerb, String completeUrl, + String bodyContents) throws InterruptedException, ExecutionException, IOException { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public Response execute(String userAgent, Map headers, Verb httpVerb, String completeUrl, + File bodyContents) throws InterruptedException, ExecutionException, IOException { + throw new UnsupportedOperationException("Not supported yet."); + } + + public Response send(String userAgent, OAuthRequest request) { + try { + return doSend(userAgent, request.getHeaders(), request.getVerb(), request.getCompleteUrl(), request); + } catch (IOException | RuntimeException e) { + throw new OAuthConnectionException(request.getCompleteUrl(), e); + } + } + + private Response doSend(String userAgent, Map headers, Verb httpVerb, String completeUrl, + OAuthRequest request) throws IOException { + final HttpURLConnection connection = (HttpURLConnection) new URL(completeUrl).openConnection(); + connection.setInstanceFollowRedirects(config.isFollowRedirects()); + connection.setRequestMethod(httpVerb.name()); + if (config.getConnectTimeout() != null) { + connection.setConnectTimeout(config.getConnectTimeout()); + } + if (config.getReadTimeout() != null) { + connection.setReadTimeout(config.getReadTimeout()); + } + addHeaders(connection, headers, userAgent); + if (httpVerb == Verb.POST || httpVerb == Verb.PUT || httpVerb == Verb.DELETE) { + final File filePayload = request.getFilePayload(); + if (filePayload != null) { + throw new UnsupportedOperationException("Sync Requests do not support File payload for the moment"); + } else if (request.getStringPayload() != null) { + addBody(connection, request.getStringPayload().getBytes(request.getCharset())); + } else { + addBody(connection, request.getByteArrayPayload()); + } + } + + try { + connection.connect(); + final int responseCode = connection.getResponseCode(); + return new Response(responseCode, connection.getResponseMessage(), parseHeaders(connection), + responseCode >= 200 && responseCode < 400 ? connection.getInputStream() + : connection.getErrorStream()); + } catch (UnknownHostException e) { + throw new OAuthException("The IP address of a host could not be determined.", e); + } + } + + private static Map parseHeaders(HttpURLConnection conn) { + final Map headers = new HashMap<>(); + for (Map.Entry> entry : conn.getHeaderFields().entrySet()) { + final String key = entry.getKey(); + if ("Content-Encoding".equalsIgnoreCase(key)) { + headers.put("Content-Encoding", entry.getValue().get(0)); + } else { + headers.put(key, entry.getValue().get(0)); + } + } + return headers; + } + + private static void addHeaders(HttpURLConnection connection, Map headers, String userAgent) { + for (Map.Entry entry : headers.entrySet()) { + connection.setRequestProperty(entry.getKey(), entry.getValue()); + } + if (userAgent != null) { + connection.setRequestProperty(OAuthConstants.USER_AGENT_HEADER_NAME, userAgent); + } + } + + private static void addBody(HttpURLConnection connection, byte[] content) throws IOException { + connection.setRequestProperty(CONTENT_LENGTH, String.valueOf(content.length)); + + if (connection.getRequestProperty(CONTENT_TYPE) == null) { + connection.setRequestProperty(CONTENT_TYPE, DEFAULT_CONTENT_TYPE); + } + connection.setDoOutput(true); + connection.getOutputStream().write(content); + } +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpProvider.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpProvider.java new file mode 100644 index 000000000..04472e78a --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpProvider.java @@ -0,0 +1,16 @@ +package com.github.scribejava.core.httpclient.jdk; + +import com.github.scribejava.core.httpclient.HttpClient; +import com.github.scribejava.core.httpclient.HttpClientConfig; +import com.github.scribejava.core.httpclient.HttpClientProvider; + +public class JDKHttpProvider implements HttpClientProvider { + + @Override + public HttpClient createClient(HttpClientConfig config) { + if (config instanceof JDKHttpClientConfig) { + return new JDKHttpClient((JDKHttpClientConfig) config); + } + return null; + } +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/AbstractRequest.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/AbstractRequest.java index 9e48c4f52..57ded183b 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/AbstractRequest.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/AbstractRequest.java @@ -14,9 +14,6 @@ */ public abstract class AbstractRequest { - public static final String DEFAULT_CONTENT_TYPE = "application/x-www-form-urlencoded"; - public static final String CONTENT_TYPE = "Content-Type"; - protected static final String CONTENT_LENGTH = "Content-Length"; private static final String OAUTH_PREFIX = "oauth_"; private final String url; 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 e498d62fa..b12c3683d 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequest.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequest.java @@ -1,17 +1,5 @@ package com.github.scribejava.core.model; -import java.io.IOException; -import java.net.HttpURLConnection; -import java.util.Map; -import com.github.scribejava.core.exceptions.OAuthConnectionException; -import com.github.scribejava.core.exceptions.OAuthException; -import com.github.scribejava.core.httpclient.jdk.JDKHttpClientConfig; -import java.io.File; -import java.net.URL; -import java.net.UnknownHostException; -import java.util.HashMap; -import java.util.List; - public class OAuthRequest extends AbstractRequest { public OAuthRequest(Verb verb, String url) { @@ -29,79 +17,4 @@ public OAuthRequest(Verb verb, String url) { public OAuthRequest(Verb verb, String url, OAuthConfig config) { this(verb, url); } - - public Response send(String userAgent, JDKHttpClientConfig httpClientConfig) { - try { - return doSend(userAgent, httpClientConfig, getHeaders(), getVerb(), getCompleteUrl(), - this); - } catch (IOException | RuntimeException e) { - throw new OAuthConnectionException(getCompleteUrl(), e); - } - } - - private static Response doSend(String userAgent, JDKHttpClientConfig httpClientConfig, Map headers, - Verb httpVerb, String completeUrl, OAuthRequest request) throws IOException { - final HttpURLConnection connection = (HttpURLConnection) new URL(completeUrl).openConnection(); - connection.setInstanceFollowRedirects(httpClientConfig.isFollowRedirects()); - connection.setRequestMethod(httpVerb.name()); - if (httpClientConfig.getConnectTimeout() != null) { - connection.setConnectTimeout(httpClientConfig.getConnectTimeout()); - } - if (httpClientConfig.getReadTimeout() != null) { - connection.setReadTimeout(httpClientConfig.getReadTimeout()); - } - addHeaders(connection, headers, userAgent); - if (httpVerb == Verb.POST || httpVerb == Verb.PUT || httpVerb == Verb.DELETE) { - final File filePayload = request.getFilePayload(); - if (filePayload != null) { - throw new UnsupportedOperationException("Sync Requests do not support File payload for the moment"); - } else if (request.getStringPayload() != null) { - addBody(connection, request.getStringPayload().getBytes(request.getCharset())); - } else { - addBody(connection, request.getByteArrayPayload()); - } - } - - try { - connection.connect(); - final int responseCode = connection.getResponseCode(); - return new Response(responseCode, connection.getResponseMessage(), parseHeaders(connection), - responseCode >= 200 && responseCode < 400 ? connection.getInputStream() - : connection.getErrorStream()); - } catch (UnknownHostException e) { - throw new OAuthException("The IP address of a host could not be determined.", e); - } - } - - private static Map parseHeaders(HttpURLConnection conn) { - final Map headers = new HashMap<>(); - for (Map.Entry> entry : conn.getHeaderFields().entrySet()) { - final String key = entry.getKey(); - if ("Content-Encoding".equalsIgnoreCase(key)) { - headers.put("Content-Encoding", entry.getValue().get(0)); - } else { - headers.put(key, entry.getValue().get(0)); - } - } - return headers; - } - - private static void addHeaders(HttpURLConnection connection, Map headers, String userAgent) { - for (Map.Entry entry : headers.entrySet()) { - connection.setRequestProperty(entry.getKey(), entry.getValue()); - } - if (userAgent != null) { - connection.setRequestProperty(OAuthConstants.USER_AGENT_HEADER_NAME, userAgent); - } - } - - private static void addBody(HttpURLConnection connection, byte[] content) throws IOException { - connection.setRequestProperty(CONTENT_LENGTH, String.valueOf(content.length)); - - if (connection.getRequestProperty(CONTENT_TYPE) == null) { - connection.setRequestProperty(CONTENT_TYPE, DEFAULT_CONTENT_TYPE); - } - connection.setDoOutput(true); - connection.getOutputStream().write(content); - } } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java index 8553aa4a1..ca00bc5f7 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java @@ -4,6 +4,7 @@ import com.github.scribejava.core.model.AbstractRequest; import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.httpclient.HttpClientConfig; +import com.github.scribejava.core.httpclient.jdk.JDKHttpClient; import com.github.scribejava.core.httpclient.jdk.JDKHttpClientConfig; import com.github.scribejava.core.model.OAuthAsyncRequestCallback; import com.github.scribejava.core.model.OAuthConfig; @@ -35,7 +36,7 @@ public OAuthService(OAuthConfig config) { final HttpClient externalHttpClient = config.getHttpClient(); if (httpClientConfig == null && externalHttpClient == null) { - httpClient = null; + httpClient = new JDKHttpClient(JDKHttpClientConfig.defaultConfig()); } else { httpClient = externalHttpClient == null ? getClient(httpClientConfig) : externalHttpClient; } @@ -103,9 +104,9 @@ public Response execute(OAuthRequestAsync request) throws InterruptedException, } public Response execute(OAuthRequest request) { - final HttpClientConfig httpClientConfig = config.getHttpClientConfig(); - return request.send(config.getUserAgent(), - httpClientConfig instanceof JDKHttpClientConfig ? (JDKHttpClientConfig) httpClientConfig - : JDKHttpClientConfig.defaultConfig()); + final JDKHttpClient jdkHttpClient = httpClient instanceof JDKHttpClient ? (JDKHttpClient) httpClient + : new JDKHttpClient(JDKHttpClientConfig.defaultConfig()); + + return jdkHttpClient.send(config.getUserAgent(), request); } } diff --git a/scribejava-core/src/main/resources/META-INF/services/com.github.scribejava.core.httpclient.HttpClientProvider b/scribejava-core/src/main/resources/META-INF/services/com.github.scribejava.core.httpclient.HttpClientProvider new file mode 100644 index 000000000..7df053c24 --- /dev/null +++ b/scribejava-core/src/main/resources/META-INF/services/com.github.scribejava.core.httpclient.HttpClientProvider @@ -0,0 +1,2 @@ +com.github.scribejava.core.httpclient.jdk.JDKHttpProvider + 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 e8742e2fc..f547779a1 100644 --- a/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/AhcHttpClient.java +++ b/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/AhcHttpClient.java @@ -1,7 +1,6 @@ package com.github.scribejava.httpclient.ahc; import com.github.scribejava.core.httpclient.AbstractAsyncOnlyHttpClient; -import com.github.scribejava.core.model.AbstractRequest; import com.github.scribejava.core.model.OAuthAsyncRequestCallback; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.OAuthRequestAsync; @@ -13,7 +12,6 @@ import java.util.Map; import java.util.concurrent.Future; -import static com.github.scribejava.core.model.AbstractRequest.DEFAULT_CONTENT_TYPE; import java.io.File; import org.asynchttpclient.AsyncHttpClientConfig; import org.asynchttpclient.BoundRequestBuilder; @@ -82,8 +80,8 @@ private Future doExecuteAsync(String userAgent, Map heade } if (httpVerb == Verb.POST || httpVerb == Verb.PUT || httpVerb == Verb.DELETE) { - if (!headers.containsKey(AbstractRequest.CONTENT_TYPE)) { - boundRequestBuilder = boundRequestBuilder.addHeader(AbstractRequest.CONTENT_TYPE, DEFAULT_CONTENT_TYPE); + if (!headers.containsKey(CONTENT_TYPE)) { + boundRequestBuilder = boundRequestBuilder.addHeader(CONTENT_TYPE, DEFAULT_CONTENT_TYPE); } boundRequestBuilder = bodySetter.setBody(boundRequestBuilder, 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 c2b27e3eb..6c4acde60 100644 --- a/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/NingHttpClient.java +++ b/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/NingHttpClient.java @@ -1,7 +1,6 @@ package com.github.scribejava.httpclient.ning; import com.github.scribejava.core.httpclient.AbstractAsyncOnlyHttpClient; -import com.github.scribejava.core.model.AbstractRequest; import com.github.scribejava.core.model.OAuthAsyncRequestCallback; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.OAuthRequestAsync; @@ -11,7 +10,6 @@ import java.util.Map; import java.util.concurrent.Future; -import static com.github.scribejava.core.model.AbstractRequest.DEFAULT_CONTENT_TYPE; import com.ning.http.client.AsyncHttpClientConfig; import java.io.File; @@ -90,8 +88,8 @@ private Future doExecuteAsync(String userAgent, Map heade } if (httpVerb == Verb.POST || httpVerb == Verb.PUT || httpVerb == Verb.DELETE) { - if (!headers.containsKey(AbstractRequest.CONTENT_TYPE)) { - boundRequestBuilder = boundRequestBuilder.addHeader(AbstractRequest.CONTENT_TYPE, DEFAULT_CONTENT_TYPE); + if (!headers.containsKey(CONTENT_TYPE)) { + boundRequestBuilder = boundRequestBuilder.addHeader(CONTENT_TYPE, DEFAULT_CONTENT_TYPE); } boundRequestBuilder = bodySetter.setBody(boundRequestBuilder, bodyContents); } diff --git a/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java b/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java index ff8f0c80f..80c0c4ddc 100644 --- a/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java +++ b/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java @@ -1,6 +1,5 @@ package com.github.scribejava.httpclient.okhttp; -import com.github.scribejava.core.model.AbstractRequest; import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.model.OAuthAsyncRequestCallback; import com.github.scribejava.core.model.OAuthConstants; @@ -17,7 +16,6 @@ import java.util.Map; import java.util.concurrent.Future; -import static com.github.scribejava.core.model.AbstractRequest.DEFAULT_CONTENT_TYPE; import com.github.scribejava.core.model.Response; import java.io.File; import java.util.HashMap; @@ -117,8 +115,8 @@ private Call createCall(String userAgent, Map headers, Verb http // prepare body final RequestBody body; if (bodyContents != null && HttpMethod.permitsRequestBody(method)) { - final MediaType mediaType = headers.containsKey(AbstractRequest.CONTENT_TYPE) - ? MediaType.parse(headers.get(AbstractRequest.CONTENT_TYPE)) : DEFAULT_CONTENT_TYPE_MEDIA_TYPE; + final MediaType mediaType = headers.containsKey(CONTENT_TYPE) ? MediaType.parse(headers.get(CONTENT_TYPE)) + : DEFAULT_CONTENT_TYPE_MEDIA_TYPE; body = bodyType.createBody(mediaType, bodyContents); } else { From 3c724082167ba8d334b5a5d7f5ccbe87d591cb32 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 11 Jan 2017 15:01:28 +0300 Subject: [PATCH 343/882] make JDKHttpClient implement sync execute methods from HttpClient --- .../apis/examples/AWeberExample.java | 3 +- .../apis/examples/Box20Example.java | 3 +- .../scribejava/apis/examples/DiggExample.java | 3 +- .../apis/examples/FacebookExample.java | 3 +- .../apis/examples/FlickrExample.java | 3 +- .../apis/examples/Foursquare2Example.java | 3 +- .../apis/examples/FoursquareExample.java | 3 +- .../apis/examples/FreelancerExample.java | 3 +- .../apis/examples/GeniusExample.java | 3 +- .../apis/examples/GitHubExample.java | 3 +- .../apis/examples/Google20Example.java | 3 +- .../scribejava/apis/examples/HHExample.java | 3 +- .../apis/examples/ImgurExample.java | 3 +- .../apis/examples/Kaixin20Example.java | 3 +- .../apis/examples/LinkedIn20Example.java | 3 +- .../apis/examples/LinkedInExample.java | 3 +- .../examples/LinkedInExampleWithScopes.java | 3 +- .../scribejava/apis/examples/LiveExample.java | 3 +- .../apis/examples/MailruExample.java | 3 +- .../apis/examples/MeetupExample.java | 3 +- .../apis/examples/MisfitExample.java | 3 +- .../apis/examples/NaverExample.java | 3 +- .../apis/examples/NeteaseWeiboExample.java | 3 +- .../apis/examples/OdnoklassnikiExample.java | 3 +- .../apis/examples/PinterestExample.java | 3 +- .../apis/examples/Px500Example.java | 3 +- .../apis/examples/RenrenExample.java | 3 +- .../apis/examples/SalesforceExample.java | 4 +- .../apis/examples/SinaWeibo2Example.java | 3 +- .../apis/examples/SinaWeiboExample.java | 3 +- .../apis/examples/SkyrockExample.java | 3 +- .../apis/examples/SohuWeiboExample.java | 3 +- .../apis/examples/StackExchangeExample.java | 3 +- .../TheThingsNetworkV1StagingExample.java | 3 +- .../TheThingsNetworkV2PreviewExample.java | 3 +- .../apis/examples/TrelloExample.java | 3 +- .../apis/examples/TumblrExample.java | 3 +- .../apis/examples/TutByExample.java | 3 +- .../apis/examples/TwitterExample.java | 3 +- .../apis/examples/ViadeoExample.java | 3 +- .../apis/examples/VkontakteExample.java | 3 +- .../scribejava/apis/examples/XingExample.java | 3 +- .../apis/examples/YahooExample.java | 3 +- .../exceptions/OAuthConnectionException.java | 11 ----- .../core/httpclient/jdk/JDKHttpClient.java | 46 +++++++++---------- .../core/model/AbstractRequest.java | 2 - .../core/oauth/OAuth10aService.java | 5 +- .../scribejava/core/oauth/OAuth20Service.java | 13 ++++-- .../scribejava/core/oauth/OAuthService.java | 14 +++++- .../core/oauth/OAuth20ServiceTest.java | 2 +- 50 files changed, 135 insertions(+), 88 deletions(-) delete mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/exceptions/OAuthConnectionException.java diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AWeberExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AWeberExample.java index 324fcc013..d79bd77b2 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AWeberExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AWeberExample.java @@ -10,6 +10,7 @@ import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.oauth.OAuth10aService; import java.io.IOException; +import java.util.concurrent.ExecutionException; public final class AWeberExample { @@ -22,7 +23,7 @@ public final class AWeberExample { private AWeberExample() { } - public static void main(String... args) throws IOException { + public static void main(String... args) throws IOException, InterruptedException, ExecutionException { final OAuth10aService service = new ServiceBuilder() .apiKey(CONSUMER_KEY) .apiSecret(CONSUMER_SECRET) diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Box20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Box20Example.java index c41e5f45e..e2f5d6f2c 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Box20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Box20Example.java @@ -12,6 +12,7 @@ import java.io.IOException; import java.util.HashMap; import java.util.Map; +import java.util.concurrent.ExecutionException; public final class Box20Example { @@ -21,7 +22,7 @@ public final class Box20Example { private Box20Example() { } - public static void main(String... args) throws IOException { + public static void main(String... args) throws IOException, InterruptedException, ExecutionException { //Replace these with your client id and secret final String clientId = "your client id"; final String clientSecret = "your client secret"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiggExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiggExample.java index 61f6c1e75..6afd1db07 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiggExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiggExample.java @@ -10,6 +10,7 @@ import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.oauth.OAuth10aService; import java.io.IOException; +import java.util.concurrent.ExecutionException; public final class DiggExample { @@ -19,7 +20,7 @@ public final class DiggExample { private DiggExample() { } - public static void main(String... args) throws IOException { + public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your own api key and secret final String apiKey = "myKey"; final String apiSecret = "mySecret"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java index 1aaa26ba5..54f56181a 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java @@ -10,6 +10,7 @@ import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.oauth.OAuth20Service; import java.io.IOException; +import java.util.concurrent.ExecutionException; public final class FacebookExample { @@ -19,7 +20,7 @@ public final class FacebookExample { private FacebookExample() { } - public static void main(String... args) throws IOException { + public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your client id and secret final String clientId = "your client id"; final String clientSecret = "your client secret"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExample.java index c5055412b..7165844bf 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExample.java @@ -10,6 +10,7 @@ import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.oauth.OAuth10aService; import java.io.IOException; +import java.util.concurrent.ExecutionException; public final class FlickrExample { @@ -18,7 +19,7 @@ public final class FlickrExample { private FlickrExample() { } - public static void main(String... args) throws IOException { + public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your own api key and secret final String apiKey = "your_app_id"; final String apiSecret = "your_api_secret"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java index 1d371a51b..1874e5deb 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java @@ -9,6 +9,7 @@ import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.oauth.OAuth20Service; import java.io.IOException; +import java.util.concurrent.ExecutionException; public final class Foursquare2Example { @@ -18,7 +19,7 @@ public final class Foursquare2Example { private Foursquare2Example() { } - public static void main(String... args) throws IOException { + public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your own api key and secret final String apiKey = "your client id"; final String apiSecret = "your client secret"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FoursquareExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FoursquareExample.java index acfa08ce6..59956cafd 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FoursquareExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FoursquareExample.java @@ -10,6 +10,7 @@ import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.oauth.OAuth10aService; import java.io.IOException; +import java.util.concurrent.ExecutionException; public final class FoursquareExample { @@ -18,7 +19,7 @@ public final class FoursquareExample { private FoursquareExample() { } - public static void main(String... args) throws IOException { + public static void main(String... args) throws IOException, InterruptedException, ExecutionException { final OAuth10aService service = new ServiceBuilder() .apiKey("your client id") .apiSecret("your client secret") diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java index e1542dd0f..3908ae116 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java @@ -11,6 +11,7 @@ import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.oauth.OAuth10aService; import java.io.IOException; +import java.util.concurrent.ExecutionException; public final class FreelancerExample { @@ -23,7 +24,7 @@ public final class FreelancerExample { private FreelancerExample() { } - public static void main(String... args) throws IOException { + public static void main(String... args) throws IOException, InterruptedException, ExecutionException { final OAuth10aService service = new ServiceBuilder() .signatureType(SignatureType.QueryString) .apiKey("your client id") diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GeniusExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GeniusExample.java index f91fb5dc4..59c2d872a 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GeniusExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GeniusExample.java @@ -10,6 +10,7 @@ import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.oauth.OAuth20Service; import java.io.IOException; +import java.util.concurrent.ExecutionException; public final class GeniusExample { @@ -19,7 +20,7 @@ public final class GeniusExample { private GeniusExample() { } - public static void main(String... args) throws IOException { + public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your client id and secret final String clientId = "your client id"; final String clientSecret = "your client secret"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubExample.java index bfd482f04..28d5bc5c4 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubExample.java @@ -10,6 +10,7 @@ import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.oauth.OAuth20Service; import java.io.IOException; +import java.util.concurrent.ExecutionException; public final class GitHubExample { @@ -19,7 +20,7 @@ public final class GitHubExample { private GitHubExample() { } - public static void main(String... args) throws IOException { + public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your client id and secret final String clientId = "your client id"; final String clientSecret = "your client secret"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java index 1fc8a6869..770703321 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java @@ -12,6 +12,7 @@ import java.io.IOException; import java.util.HashMap; import java.util.Map; +import java.util.concurrent.ExecutionException; public final class Google20Example { @@ -21,7 +22,7 @@ public final class Google20Example { private Google20Example() { } - public static void main(String... args) throws IOException { + public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your client id and secret final String clientId = "your client id"; final String clientSecret = "your client secret"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HHExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HHExample.java index 2a1d6d3f9..c19ba50c3 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HHExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HHExample.java @@ -11,6 +11,7 @@ import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.oauth.OAuth20Service; import java.io.IOException; +import java.util.concurrent.ExecutionException; public final class HHExample { @@ -20,7 +21,7 @@ public final class HHExample { private HHExample() { } - public static void main(String... args) throws IOException { + public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your own client id and secret final String clientId = "your client id"; final String clientSecret = "your client secret"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ImgurExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ImgurExample.java index 2eaa8db72..fd8c59c31 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ImgurExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ImgurExample.java @@ -10,6 +10,7 @@ import java.io.IOException; import java.util.Scanner; +import java.util.concurrent.ExecutionException; public final class ImgurExample { @@ -19,7 +20,7 @@ public final class ImgurExample { private ImgurExample() { } - public static void main(String... args) throws IOException { + public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your own api key and secret final String apiKey = "your client id"; final String apiSecret = "your client secret"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Kaixin20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Kaixin20Example.java index 35591086e..50a134c7d 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Kaixin20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Kaixin20Example.java @@ -9,6 +9,7 @@ import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.oauth.OAuth20Service; import java.io.IOException; +import java.util.concurrent.ExecutionException; public final class Kaixin20Example { @@ -18,7 +19,7 @@ public final class Kaixin20Example { private Kaixin20Example() { } - public static void main(String... args) throws IOException { + public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your own api key and secret final String apiKey = "your api key"; final String apiSecret = "your api secret"; 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 1dc096586..cf34a9ae0 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedIn20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedIn20Example.java @@ -9,6 +9,7 @@ import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.oauth.OAuth20Service; import java.io.IOException; +import java.util.concurrent.ExecutionException; public final class LinkedIn20Example { @@ -18,7 +19,7 @@ public final class LinkedIn20Example { private LinkedIn20Example() { } - public static void main(String... args) throws IOException { + public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your client id and secret final String clientId = "your client id"; final String clientSecret = "your client secret"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java index 9c6a085ae..6f9654e7f 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java @@ -10,6 +10,7 @@ import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.oauth.OAuth10aService; import java.io.IOException; +import java.util.concurrent.ExecutionException; public final class LinkedInExample { @@ -19,7 +20,7 @@ public final class LinkedInExample { private LinkedInExample() { } - public static void main(String... args) throws IOException { + public static void main(String... args) throws IOException, InterruptedException, ExecutionException { final OAuth10aService service = new ServiceBuilder() .apiKey("your client id") .apiSecret("your client secret") diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java index 4bc2a3529..3ab8bb006 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java @@ -10,6 +10,7 @@ import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.oauth.OAuth10aService; import java.io.IOException; +import java.util.concurrent.ExecutionException; public final class LinkedInExampleWithScopes { @@ -19,7 +20,7 @@ public final class LinkedInExampleWithScopes { private LinkedInExampleWithScopes() { } - public static void main(String... args) throws IOException { + public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your client id and secret final String clientId = "your client id"; final String clientSecret = "your client id"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java index 832382472..a93643eda 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java @@ -9,6 +9,7 @@ import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.oauth.OAuth20Service; import java.io.IOException; +import java.util.concurrent.ExecutionException; public final class LiveExample { @@ -18,7 +19,7 @@ public final class LiveExample { private LiveExample() { } - public static void main(String... args) throws IOException { + public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your own api key and secret final String apiKey = ""; final String apiSecret = ""; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java index 9c633b9f4..9fb743b05 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java @@ -9,6 +9,7 @@ import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.oauth.OAuth20Service; import java.io.IOException; +import java.util.concurrent.ExecutionException; public final class MailruExample { @@ -19,7 +20,7 @@ public final class MailruExample { private MailruExample() { } - public static void main(String... args) throws IOException { + public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your client id and secret final String clientId = "your client id"; final String clientSecret = "your client secret"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java index c488a1149..f7c41894a 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java @@ -10,6 +10,7 @@ import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.oauth.OAuth10aService; import java.io.IOException; +import java.util.concurrent.ExecutionException; public final class MeetupExample { @@ -18,7 +19,7 @@ public final class MeetupExample { private MeetupExample() { } - public static void main(String... args) throws IOException { + public static void main(String... args) throws IOException, InterruptedException, ExecutionException { final OAuth10aService service = new ServiceBuilder() .apiKey("your client id") .apiSecret("your client secret") diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MisfitExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MisfitExample.java index 39037fde0..1caa28eb1 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MisfitExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MisfitExample.java @@ -10,6 +10,7 @@ import java.io.IOException; import java.util.Scanner; +import java.util.concurrent.ExecutionException; public final class MisfitExample { @@ -20,7 +21,7 @@ public final class MisfitExample { private MisfitExample() { } - public static void main(String... args) throws IOException { + public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your own api key and secret final String apiKey = "your client id"; final String apiSecret = "your client secret"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NaverExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NaverExample.java index 962db655b..3a85e8845 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NaverExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NaverExample.java @@ -11,6 +11,7 @@ import java.io.IOException; import java.util.Random; import java.util.Scanner; +import java.util.concurrent.ExecutionException; public final class NaverExample { @@ -20,7 +21,7 @@ public final class NaverExample { private NaverExample() { } - public static void main(String... args) throws IOException { + public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your client id and secret final String clientId = "your client id"; final String clientSecret = "your client secret"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NeteaseWeiboExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NeteaseWeiboExample.java index 27f2a6610..cde99f609 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NeteaseWeiboExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NeteaseWeiboExample.java @@ -10,6 +10,7 @@ import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.oauth.OAuth10aService; import java.io.IOException; +import java.util.concurrent.ExecutionException; public final class NeteaseWeiboExample { @@ -19,7 +20,7 @@ public final class NeteaseWeiboExample { private NeteaseWeiboExample() { } - public static void main(String... args) throws IOException { + public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your own api key and secret final String apiKey = "your key"; final String apiSecret = "your secret"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java index a1c8e5bdb..c87fad63c 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java @@ -9,6 +9,7 @@ import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.oauth.OAuth20Service; import java.io.IOException; +import java.util.concurrent.ExecutionException; public final class OdnoklassnikiExample { @@ -19,7 +20,7 @@ public final class OdnoklassnikiExample { private OdnoklassnikiExample() { } - public static void main(String... args) throws IOException { + public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your client id and secret final String clientId = "your api client id"; final String publicKey = "your api public key"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java index bb07b59cc..16a8f6e65 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java @@ -10,6 +10,7 @@ import java.io.IOException; import java.util.Scanner; +import java.util.concurrent.ExecutionException; public final class PinterestExample { @@ -18,7 +19,7 @@ public final class PinterestExample { private PinterestExample() { } - public static void main(String... args) throws IOException { + public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your own api key and secret final String apiKey = "your_app_id"; final String apiSecret = "your_app_secret"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Px500Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Px500Example.java index c84acbaeb..2ab55085c 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Px500Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Px500Example.java @@ -10,6 +10,7 @@ import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.oauth.OAuth10aService; import java.io.IOException; +import java.util.concurrent.ExecutionException; public final class Px500Example { @@ -18,7 +19,7 @@ public final class Px500Example { private Px500Example() { } - public static void main(String... args) throws IOException { + public static void main(String... args) throws IOException, InterruptedException, ExecutionException { final OAuth10aService service = new ServiceBuilder() .apiKey("your-api-key") .apiSecret("your-api-secret") diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java index 854eeb295..021c9b0d4 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java @@ -18,6 +18,7 @@ import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.oauth.OAuth20Service; import java.io.IOException; +import java.util.concurrent.ExecutionException; public final class RenrenExample { @@ -27,7 +28,7 @@ public final class RenrenExample { private RenrenExample() { } - public static void main(String... args) throws IOException { + public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your own api key and secret final String apiKey = "your api key"; final String apiSecret = "your api secret"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceExample.java index d69181338..bfe562249 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceExample.java @@ -14,6 +14,7 @@ import com.github.scribejava.core.oauth.OAuth20Service; import java.security.KeyManagementException; import java.security.NoSuchAlgorithmException; +import java.util.concurrent.ExecutionException; public final class SalesforceExample { @@ -22,7 +23,8 @@ public final class SalesforceExample { private SalesforceExample() { } - public static void main(String... args) throws IOException, NoSuchAlgorithmException, KeyManagementException { + public static void main(String... args) throws IOException, NoSuchAlgorithmException, KeyManagementException, + InterruptedException, ExecutionException { // Replace these with your client id and secret final String clientId = "your client id"; final String clientSecret = "your client secret"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeibo2Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeibo2Example.java index 44b1ef2cf..d99a20b1c 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeibo2Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeibo2Example.java @@ -9,6 +9,7 @@ import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.oauth.OAuth20Service; import java.io.IOException; +import java.util.concurrent.ExecutionException; public final class SinaWeibo2Example { @@ -18,7 +19,7 @@ public final class SinaWeibo2Example { private SinaWeibo2Example() { } - public static void main(String... args) throws IOException { + public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your own api key and secret final String apiKey = "your_api_key"; final String apiSecret = "your_api_secret"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeiboExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeiboExample.java index d09ff08e2..18edbb49e 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeiboExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeiboExample.java @@ -10,6 +10,7 @@ import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.oauth.OAuth10aService; import java.io.IOException; +import java.util.concurrent.ExecutionException; public final class SinaWeiboExample { @@ -19,7 +20,7 @@ public final class SinaWeiboExample { private SinaWeiboExample() { } - public static void main(String... args) throws IOException { + public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your own api key and secret final String apiKey = "your key"; final String apiSecret = "your secret"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SkyrockExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SkyrockExample.java index d22a373e5..a9c957541 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SkyrockExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SkyrockExample.java @@ -10,6 +10,7 @@ import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.oauth.OAuth10aService; import java.io.IOException; +import java.util.concurrent.ExecutionException; public final class SkyrockExample { @@ -18,7 +19,7 @@ public final class SkyrockExample { private SkyrockExample() { } - public static void main(String... args) throws IOException { + public static void main(String... args) throws IOException, InterruptedException, ExecutionException { final OAuth10aService service = new ServiceBuilder() .apiKey("your-api-key") .apiSecret("your-api-secret") diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SohuWeiboExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SohuWeiboExample.java index 524268436..81202256d 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SohuWeiboExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SohuWeiboExample.java @@ -10,6 +10,7 @@ import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.oauth.OAuth10aService; import java.io.IOException; +import java.util.concurrent.ExecutionException; public final class SohuWeiboExample { @@ -19,7 +20,7 @@ public final class SohuWeiboExample { private SohuWeiboExample() { } - public static void main(String... args) throws IOException { + public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your own api key and secret final String apiKey = "your_key"; final String apiSecret = "your_secret"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/StackExchangeExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/StackExchangeExample.java index 81e5bcf5a..ed3eea0db 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/StackExchangeExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/StackExchangeExample.java @@ -11,6 +11,7 @@ import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.oauth.OAuth20Service; import java.io.IOException; +import java.util.concurrent.ExecutionException; public final class StackExchangeExample { @@ -20,7 +21,7 @@ public final class StackExchangeExample { private StackExchangeExample() { } - public static void main(String... args) throws IOException { + public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your client id, secret, application key and // optionally site name final String clientId = "your client id"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV1StagingExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV1StagingExample.java index 22fa12a73..50fbef28e 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV1StagingExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV1StagingExample.java @@ -12,6 +12,7 @@ import java.net.URLDecoder; import java.util.Random; import java.util.Scanner; +import java.util.concurrent.ExecutionException; public final class TheThingsNetworkV1StagingExample { @@ -21,7 +22,7 @@ public final class TheThingsNetworkV1StagingExample { private TheThingsNetworkV1StagingExample() { } - public static void main(String... args) throws IOException { + public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your client id and secret final String clientId = "your_client_id"; final String clientSecret = "your_client_secret"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV2PreviewExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV2PreviewExample.java index 1f6bb61bb..38bd2fb5f 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV2PreviewExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV2PreviewExample.java @@ -11,6 +11,7 @@ import java.io.IOException; import java.util.Random; import java.util.Scanner; +import java.util.concurrent.ExecutionException; public final class TheThingsNetworkV2PreviewExample { @@ -21,7 +22,7 @@ public final class TheThingsNetworkV2PreviewExample { private TheThingsNetworkV2PreviewExample() { } - public static void main(String... args) throws IOException { + public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your client id and secret final String clientId = "your_client_id"; final String clientSecret = "your_client_secret"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TrelloExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TrelloExample.java index b2371312f..e847d7b94 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TrelloExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TrelloExample.java @@ -10,6 +10,7 @@ import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.oauth.OAuth10aService; import java.io.IOException; +import java.util.concurrent.ExecutionException; public final class TrelloExample { @@ -20,7 +21,7 @@ public final class TrelloExample { private TrelloExample() { } - public static void main(String... args) throws IOException { + public static void main(String... args) throws IOException, InterruptedException, ExecutionException { final OAuth10aService service = new ServiceBuilder() .apiKey(API_KEY) .apiSecret(API_SECRET) diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TumblrExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TumblrExample.java index efcc38cee..edc12efa7 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TumblrExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TumblrExample.java @@ -10,6 +10,7 @@ import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.oauth.OAuth10aService; import java.io.IOException; +import java.util.concurrent.ExecutionException; public final class TumblrExample { @@ -18,7 +19,7 @@ public final class TumblrExample { private TumblrExample() { } - public static void main(String... args) throws IOException { + public static void main(String... args) throws IOException, InterruptedException, ExecutionException { final OAuth10aService service = new ServiceBuilder() .apiKey("MY_CONSUMER_KEY") .apiSecret("MY_CONSUMER_SECRET") diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TutByExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TutByExample.java index 012c2b88f..06e035abb 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TutByExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TutByExample.java @@ -11,6 +11,7 @@ import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.oauth.OAuth20Service; import java.io.IOException; +import java.util.concurrent.ExecutionException; public final class TutByExample { @@ -20,7 +21,7 @@ public final class TutByExample { private TutByExample() { } - public static void main(String... args) throws IOException { + public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your client id and secret final String clientId = "your client id"; final String clientSecret = "your client secret"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TwitterExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TwitterExample.java index b000f0c3f..6cd012bb7 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TwitterExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TwitterExample.java @@ -10,6 +10,7 @@ import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.oauth.OAuth10aService; import java.io.IOException; +import java.util.concurrent.ExecutionException; public final class TwitterExample { @@ -18,7 +19,7 @@ public final class TwitterExample { private TwitterExample() { } - public static void main(String... args) throws IOException { + public static void main(String... args) throws IOException, InterruptedException, ExecutionException { final OAuth10aService service = new ServiceBuilder() .apiKey("your client id") .apiSecret("your client secret") diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ViadeoExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ViadeoExample.java index a9e16905e..d0b5cfaeb 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ViadeoExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ViadeoExample.java @@ -9,6 +9,7 @@ import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.oauth.OAuth20Service; import java.io.IOException; +import java.util.concurrent.ExecutionException; public final class ViadeoExample { @@ -18,7 +19,7 @@ public final class ViadeoExample { private ViadeoExample() { } - public static void main(String... args) throws IOException { + public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your own api key and secret final String apiKey = "your_app_id"; final String apiSecret = "your_api_secret"; 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 57bea7831..fb806492d 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 @@ -9,6 +9,7 @@ import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.oauth.OAuth20Service; import java.io.IOException; +import java.util.concurrent.ExecutionException; public final class VkontakteExample { @@ -18,7 +19,7 @@ public final class VkontakteExample { private VkontakteExample() { } - public static void main(String... args) throws IOException { + public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your client id and secret final String clientId = "your client id"; final String clientSecret = "your client secret"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XingExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XingExample.java index 4e6037b88..3ec67e472 100755 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XingExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XingExample.java @@ -10,6 +10,7 @@ import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.oauth.OAuth10aService; import java.io.IOException; +import java.util.concurrent.ExecutionException; public final class XingExample { @@ -18,7 +19,7 @@ public final class XingExample { private XingExample() { } - public static void main(String... args) throws IOException { + public static void main(String... args) throws IOException, InterruptedException, ExecutionException { final OAuth10aService service = new ServiceBuilder() .apiKey("your client id") .apiSecret("your client secret") diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/YahooExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/YahooExample.java index 3f4d52563..aa6691cdb 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/YahooExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/YahooExample.java @@ -10,6 +10,7 @@ import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.oauth.OAuth10aService; import java.io.IOException; +import java.util.concurrent.ExecutionException; public final class YahooExample { @@ -19,7 +20,7 @@ public final class YahooExample { private YahooExample() { } - public static void main(String... args) throws IOException { + public static void main(String... args) throws IOException, InterruptedException, ExecutionException { final OAuth10aService service = new ServiceBuilder() .apiKey("your client id") .apiSecret("your client secret") diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/exceptions/OAuthConnectionException.java b/scribejava-core/src/main/java/com/github/scribejava/core/exceptions/OAuthConnectionException.java deleted file mode 100644 index 93feb8c42..000000000 --- a/scribejava-core/src/main/java/com/github/scribejava/core/exceptions/OAuthConnectionException.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.github.scribejava.core.exceptions; - -public class OAuthConnectionException extends OAuthException { - - private static final long serialVersionUID = 6901269342236961310L; - private static final String MSG = "There was a problem while creating a connection to the remote service: "; - - public OAuthConnectionException(String url, Exception e) { - super(MSG + url, e); - } -} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java index 0a673f056..00b795367 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java @@ -1,11 +1,9 @@ package com.github.scribejava.core.httpclient.jdk; -import com.github.scribejava.core.exceptions.OAuthConnectionException; import com.github.scribejava.core.exceptions.OAuthException; import com.github.scribejava.core.httpclient.HttpClient; 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.OAuthRequestAsync; import com.github.scribejava.core.model.Response; import com.github.scribejava.core.model.Verb; @@ -56,31 +54,23 @@ public Future executeAsync(String userAgent, Map headers, @Override public Response execute(String userAgent, Map headers, Verb httpVerb, String completeUrl, byte[] bodyContents) throws InterruptedException, ExecutionException, IOException { - throw new UnsupportedOperationException("Not supported yet."); + return doExecute(userAgent, headers, httpVerb, completeUrl, BodyType.BYTE_ARRAY, bodyContents); } @Override public Response execute(String userAgent, Map headers, Verb httpVerb, String completeUrl, String bodyContents) throws InterruptedException, ExecutionException, IOException { - throw new UnsupportedOperationException("Not supported yet."); + return doExecute(userAgent, headers, httpVerb, completeUrl, BodyType.STRING, bodyContents); } @Override public Response execute(String userAgent, Map headers, Verb httpVerb, String completeUrl, File bodyContents) throws InterruptedException, ExecutionException, IOException { - throw new UnsupportedOperationException("Not supported yet."); - } - - public Response send(String userAgent, OAuthRequest request) { - try { - return doSend(userAgent, request.getHeaders(), request.getVerb(), request.getCompleteUrl(), request); - } catch (IOException | RuntimeException e) { - throw new OAuthConnectionException(request.getCompleteUrl(), e); - } + throw new UnsupportedOperationException("JDKHttpClient do not support File payload for the moment"); } - private Response doSend(String userAgent, Map headers, Verb httpVerb, String completeUrl, - OAuthRequest request) throws IOException { + private Response doExecute(String userAgent, Map headers, Verb httpVerb, String completeUrl, + BodyType bodyType, Object bodyContents) throws IOException { final HttpURLConnection connection = (HttpURLConnection) new URL(completeUrl).openConnection(); connection.setInstanceFollowRedirects(config.isFollowRedirects()); connection.setRequestMethod(httpVerb.name()); @@ -92,14 +82,7 @@ private Response doSend(String userAgent, Map headers, Verb http } addHeaders(connection, headers, userAgent); if (httpVerb == Verb.POST || httpVerb == Verb.PUT || httpVerb == Verb.DELETE) { - final File filePayload = request.getFilePayload(); - if (filePayload != null) { - throw new UnsupportedOperationException("Sync Requests do not support File payload for the moment"); - } else if (request.getStringPayload() != null) { - addBody(connection, request.getStringPayload().getBytes(request.getCharset())); - } else { - addBody(connection, request.getByteArrayPayload()); - } + bodyType.setBody(connection, bodyContents); } try { @@ -113,6 +96,23 @@ private Response doSend(String userAgent, Map headers, Verb http } } + private enum BodyType { + BYTE_ARRAY { + @Override + void setBody(HttpURLConnection connection, Object bodyContents) throws IOException { + addBody(connection, (byte[]) bodyContents); + } + }, + STRING { + @Override + void setBody(HttpURLConnection connection, Object bodyContents) throws IOException { + addBody(connection, ((String) bodyContents).getBytes()); + } + }; + + abstract void setBody(HttpURLConnection connection, Object bodyContents) throws IOException; + } + private static Map parseHeaders(HttpURLConnection conn) { final Map headers = new HashMap<>(); for (Map.Entry> entry : conn.getHeaderFields().entrySet()) { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/AbstractRequest.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/AbstractRequest.java index 57ded183b..96550f4e9 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/AbstractRequest.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/AbstractRequest.java @@ -219,8 +219,6 @@ public String getSanitizedUrl() { * Returns the body of the request (set in {@link #setPayload(java.lang.String)}) * * @return form encoded string - * - * @throws OAuthException if the charset chosen is not supported */ public String getStringPayload() { return stringPayload; 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 7c86ff342..6bdb539ed 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 @@ -15,6 +15,7 @@ import com.github.scribejava.core.model.Response; import com.github.scribejava.core.services.Base64Encoder; import com.github.scribejava.core.utils.MapUtils; +import java.util.concurrent.ExecutionException; /** * OAuth 1.0a implementation of {@link OAuthService} @@ -35,7 +36,7 @@ public OAuth10aService(DefaultApi10a api, OAuthConfig config) { this.api = api; } - public final OAuth1RequestToken getRequestToken() throws IOException { + public final OAuth1RequestToken getRequestToken() throws IOException, InterruptedException, ExecutionException { final OAuthConfig config = getConfig(); config.log("obtaining request token from " + api.getRequestTokenEndpoint()); final OAuthRequest request = new OAuthRequest(api.getRequestTokenVerb(), api.getRequestTokenEndpoint()); @@ -91,7 +92,7 @@ private void addOAuthParams(AbstractRequest request, String tokenSecret) { } public final OAuth1AccessToken getAccessToken(OAuth1RequestToken requestToken, String oauthVerifier) - throws IOException { + throws IOException, InterruptedException, ExecutionException { getConfig().log("obtaining access token from " + api.getAccessTokenEndpoint()); final OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint()); prepareAccessTokenRequest(request, requestToken, oauthVerifier); diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java index 7c9d11ddf..d33c6fd07 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java @@ -15,6 +15,7 @@ import com.github.scribejava.core.model.OAuthRequestAsync; import com.github.scribejava.core.model.Response; import java.util.Map; +import java.util.concurrent.ExecutionException; public class OAuth20Service extends OAuthService { @@ -33,7 +34,8 @@ public OAuth20Service(DefaultApi20 api, OAuthConfig config) { } //sync version, protected to facilitate mocking - protected OAuth2AccessToken sendAccessTokenRequestSync(OAuthRequest request) throws IOException { + protected OAuth2AccessToken sendAccessTokenRequestSync(OAuthRequest request) + throws IOException, InterruptedException, ExecutionException { return api.getAccessTokenExtractor().extract(execute(request)); } @@ -49,7 +51,8 @@ public OAuth2AccessToken convert(Response response) throws IOException { }); } - public final OAuth2AccessToken getAccessToken(String code) throws IOException { + public final OAuth2AccessToken getAccessToken(String code) + throws IOException, InterruptedException, ExecutionException { final OAuthRequest request = createAccessTokenRequest(code, new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint())); @@ -86,7 +89,8 @@ protected T createAccessTokenRequest(String code, T return request; } - public final OAuth2AccessToken refreshAccessToken(String refreshToken) throws IOException { + public final OAuth2AccessToken refreshAccessToken(String refreshToken) + throws IOException, InterruptedException, ExecutionException { final OAuthRequest request = createRefreshTokenRequest(refreshToken, new OAuthRequest(api.getAccessTokenVerb(), api.getRefreshTokenEndpoint())); @@ -113,7 +117,8 @@ protected T createRefreshTokenRequest(String refresh return request; } - public final OAuth2AccessToken getAccessTokenPasswordGrant(String uname, String password) throws IOException { + public final OAuth2AccessToken getAccessTokenPasswordGrant(String uname, String password) + throws IOException, InterruptedException, ExecutionException { final OAuthRequest request = createAccessTokenPasswordGrantRequest(uname, password, new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint())); diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java index ca00bc5f7..251c2f9fe 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java @@ -103,10 +103,20 @@ public Response execute(OAuthRequestAsync request) throws InterruptedException, } } - public Response execute(OAuthRequest request) { + public Response execute(OAuthRequest request) throws InterruptedException, ExecutionException, IOException { final JDKHttpClient jdkHttpClient = httpClient instanceof JDKHttpClient ? (JDKHttpClient) httpClient : new JDKHttpClient(JDKHttpClientConfig.defaultConfig()); - return jdkHttpClient.send(config.getUserAgent(), request); + final File filePayload = request.getFilePayload(); + if (filePayload != null) { + return jdkHttpClient.execute(config.getUserAgent(), request.getHeaders(), request.getVerb(), + request.getCompleteUrl(), filePayload); + } else if (request.getStringPayload() != null) { + return jdkHttpClient.execute(config.getUserAgent(), request.getHeaders(), request.getVerb(), + request.getCompleteUrl(), request.getStringPayload()); + } else { + return jdkHttpClient.execute(config.getUserAgent(), request.getHeaders(), request.getVerb(), + request.getCompleteUrl(), request.getByteArrayPayload()); + } } } 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 050b0ae4d..3115fd832 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 @@ -19,7 +19,7 @@ public class OAuth20ServiceTest { @Test - public void shouldProduceCorrectRequestSync() throws IOException { + public void shouldProduceCorrectRequestSync() throws IOException, InterruptedException, ExecutionException { final OAuth20Service service = new ServiceBuilder() .apiKey("your_api_key") .apiSecret("your_api_secret") From c9bb1a1c4c9909b21ff1f08e9dfe49b5dbfbceb2 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 11 Jan 2017 15:45:02 +0300 Subject: [PATCH 344/882] implement async HTTPClient methods in JDKHttpClient (it's complete now) --- .../core/httpclient/jdk/JDKHttpClient.java | 20 +++++-- .../core/httpclient/jdk/JDKHttpFuture.java | 54 +++++++++++++++++++ 2 files changed, 71 insertions(+), 3 deletions(-) create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpFuture.java diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java index 00b795367..64350a764 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java @@ -34,21 +34,35 @@ public void close() throws IOException { public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, byte[] bodyContents, OAuthAsyncRequestCallback callback, OAuthRequestAsync.ResponseConverter converter) { - throw new UnsupportedOperationException("Not supported yet."); + try { + final T response = converter.convert(execute(userAgent, headers, httpVerb, completeUrl, bodyContents)); + callback.onCompleted(response); + return new JDKHttpFuture<>(response); + } catch (InterruptedException | ExecutionException | IOException e) { + callback.onThrowable(e); + return new JDKHttpFuture<>(e); + } } @Override public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, String bodyContents, OAuthAsyncRequestCallback callback, OAuthRequestAsync.ResponseConverter converter) { - throw new UnsupportedOperationException("Not supported yet."); + try { + final T response = converter.convert(execute(userAgent, headers, httpVerb, completeUrl, bodyContents)); + callback.onCompleted(response); + return new JDKHttpFuture<>(response); + } catch (InterruptedException | ExecutionException | IOException e) { + callback.onThrowable(e); + return new JDKHttpFuture<>(e); + } } @Override public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, File bodyContents, OAuthAsyncRequestCallback callback, OAuthRequestAsync.ResponseConverter converter) { - throw new UnsupportedOperationException("Not supported yet."); + throw new UnsupportedOperationException("JDKHttpClient do not support File payload for the moment"); } @Override 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 new file mode 100644 index 000000000..14d95ec80 --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpFuture.java @@ -0,0 +1,54 @@ +package com.github.scribejava.core.httpclient.jdk; + +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; + +public class JDKHttpFuture implements Future { + + private final Exception exception; + private final V response; + + public JDKHttpFuture(Exception exception) { + this(null, exception); + } + + public JDKHttpFuture(V response) { + this(response, null); + } + + private JDKHttpFuture(V response, Exception exception) { + this.response = response; + this.exception = exception; + } + + @Override + public boolean cancel(boolean mayInterruptIfRunning) { + return false; + } + + @Override + public boolean isCancelled() { + return false; + } + + @Override + public boolean isDone() { + return true; + } + + @Override + public V get() throws InterruptedException, ExecutionException { + if (exception != null) { + throw new ExecutionException(exception); + } + + return response; + } + + @Override + public V get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { + return get(); + } +} From bfa0109cb9f11ec5f80276906f215847e6cc87e1 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 11 Jan 2017 16:46:44 +0300 Subject: [PATCH 345/882] Remove OAuthRequestAsync, just OAuthRequest. Request should not know anything about sync vs async --- changelog | 3 + .../DoktornaraboteOAuthServiceImpl.java | 4 +- .../apis/service/GeniusOAuthServiceImpl.java | 4 +- .../apis/service/HHOAuthServiceImpl.java | 4 +- .../apis/service/ImgurOAuthServiceImpl.java | 8 +- .../apis/service/LinkedIn20ServiceImpl.java | 4 +- .../apis/service/MailruOAuthServiceImpl.java | 4 +- .../service/OdnoklassnikiServiceImpl.java | 4 +- .../apis/service/TutByOAuthServiceImpl.java | 4 +- .../examples/FacebookAsyncNingExample.java | 92 +++--- .../examples/GitHubAsyncOkHttpExample.java | 93 +++--- .../examples/Google20AsyncAHCExample.java | 133 ++++----- .../apis/examples/MailruAsyncExample.java | 69 +++-- .../examples/SalesforceNingAsyncExample.java | 95 +++--- .../VkontakteExternalHttpExample.java | 4 +- .../OAuthParametersMissingException.java | 4 +- .../core/extractors/BaseStringExtractor.java | 8 +- .../extractors/BaseStringExtractorImpl.java | 12 +- .../core/extractors/HeaderExtractor.java | 4 +- .../core/extractors/HeaderExtractorImpl.java | 6 +- .../AbstractAsyncOnlyHttpClient.java | 8 +- .../core/httpclient/HttpClient.java | 10 +- .../core/httpclient/jdk/JDKHttpClient.java | 19 +- .../core/model/AbstractRequest.java | 267 +---------------- .../scribejava/core/model/OAuthRequest.java | 273 +++++++++++++++++- .../core/model/OAuthRequestAsync.java | 24 +- .../core/oauth/OAuth10aService.java | 45 +-- .../scribejava/core/oauth/OAuth20Service.java | 57 ++-- .../scribejava/core/oauth/OAuthService.java | 42 ++- .../core/oauth/OAuth20ServiceUnit.java | 6 +- .../httpclient/ahc/AhcHttpClient.java | 13 +- .../ahc/OAuthAsyncCompletionHandler.java | 6 +- .../httpclient/ning/NingHttpClient.java | 13 +- .../ning/OAuthAsyncCompletionHandler.java | 6 +- .../okhttp/OAuthAsyncCompletionHandler.java | 8 +- .../httpclient/okhttp/OkHttpHttpClient.java | 13 +- .../okhttp/OkHttpHttpClientTest.java | 10 +- 37 files changed, 694 insertions(+), 685 deletions(-) diff --git a/changelog b/changelog index d829bbe9a..d3a832068 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,6 @@ +[SNAPSHOT] + * Remove OAuthRequestAsync, just OAuthRequest. Request should know about sync vs async + [3.4.1] * Drop deprecated methods * Move doktornarabote.ru urls to https (thanks to https://github.com/ezibrov) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/DoktornaraboteOAuthServiceImpl.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/DoktornaraboteOAuthServiceImpl.java index 837449436..80c6cde48 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/DoktornaraboteOAuthServiceImpl.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/DoktornaraboteOAuthServiceImpl.java @@ -1,9 +1,9 @@ package com.github.scribejava.apis.service; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.model.AbstractRequest; import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthConfig; +import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.oauth.OAuth20Service; public class DoktornaraboteOAuthServiceImpl extends OAuth20Service { @@ -13,7 +13,7 @@ public DoktornaraboteOAuthServiceImpl(DefaultApi20 api, OAuthConfig config) { } @Override - public void signRequest(OAuth2AccessToken accessToken, AbstractRequest request) { + public void signRequest(OAuth2AccessToken accessToken, OAuthRequest request) { request.addHeader("Authorization", "Bearer " + accessToken.getAccessToken()); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/GeniusOAuthServiceImpl.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/GeniusOAuthServiceImpl.java index 4c2aa992c..dd9c493cd 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/GeniusOAuthServiceImpl.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/GeniusOAuthServiceImpl.java @@ -1,9 +1,9 @@ package com.github.scribejava.apis.service; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.model.AbstractRequest; import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthConfig; +import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.oauth.OAuth20Service; public class GeniusOAuthServiceImpl extends OAuth20Service { @@ -13,7 +13,7 @@ public GeniusOAuthServiceImpl(DefaultApi20 api, OAuthConfig config) { } @Override - public void signRequest(OAuth2AccessToken accessToken, AbstractRequest request) { + public void signRequest(OAuth2AccessToken accessToken, OAuthRequest request) { request.addHeader("Authorization", "Bearer " + accessToken.getAccessToken()); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/HHOAuthServiceImpl.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/HHOAuthServiceImpl.java index 8d1799272..ba9dd809b 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/HHOAuthServiceImpl.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/HHOAuthServiceImpl.java @@ -1,9 +1,9 @@ package com.github.scribejava.apis.service; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.model.AbstractRequest; import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthConfig; +import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.oauth.OAuth20Service; public class HHOAuthServiceImpl extends OAuth20Service { @@ -13,7 +13,7 @@ public HHOAuthServiceImpl(DefaultApi20 api, OAuthConfig config) { } @Override - public void signRequest(OAuth2AccessToken accessToken, AbstractRequest request) { + public void signRequest(OAuth2AccessToken accessToken, OAuthRequest request) { request.addHeader("Authorization", "Bearer " + accessToken.getAccessToken()); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthServiceImpl.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthServiceImpl.java index ac80b1df6..c0f74aab6 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthServiceImpl.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthServiceImpl.java @@ -2,10 +2,10 @@ import com.github.scribejava.apis.ImgurApi; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.model.AbstractRequest; import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; +import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.oauth.OAuth20Service; public class ImgurOAuthServiceImpl extends OAuth20Service { @@ -15,7 +15,9 @@ public ImgurOAuthServiceImpl(DefaultApi20 api, OAuthConfig config) { } @Override - protected T createAccessTokenRequest(String oauthVerifier, T request) { + protected OAuthRequest createAccessTokenRequest(String oauthVerifier) { + final DefaultApi20 api = getApi(); + final OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint()); final OAuthConfig config = getConfig(); request.addBodyParameter(OAuthConstants.CLIENT_ID, config.getApiKey()); request.addBodyParameter(OAuthConstants.CLIENT_SECRET, config.getApiSecret()); @@ -31,7 +33,7 @@ protected T createAccessTokenRequest(String oauthVer } @Override - public void signRequest(OAuth2AccessToken accessToken, AbstractRequest request) { + public void signRequest(OAuth2AccessToken accessToken, OAuthRequest request) { request.addHeader("Authorization", accessToken == null ? "Client-ID " + getConfig().getApiKey() : "Bearer " + accessToken.getAccessToken()); diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/LinkedIn20ServiceImpl.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/LinkedIn20ServiceImpl.java index b0e6adf14..4e26c6635 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/LinkedIn20ServiceImpl.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/LinkedIn20ServiceImpl.java @@ -1,9 +1,9 @@ package com.github.scribejava.apis.service; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.model.AbstractRequest; import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthConfig; +import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.oauth.OAuth20Service; public class LinkedIn20ServiceImpl extends OAuth20Service { @@ -13,7 +13,7 @@ public LinkedIn20ServiceImpl(DefaultApi20 api, OAuthConfig config) { } @Override - public void signRequest(OAuth2AccessToken accessToken, AbstractRequest request) { + public void signRequest(OAuth2AccessToken accessToken, OAuthRequest request) { request.addQuerystringParameter("oauth2_access_token", accessToken.getAccessToken()); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthServiceImpl.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthServiceImpl.java index d436d8244..3330bb006 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthServiceImpl.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthServiceImpl.java @@ -7,9 +7,9 @@ import org.apache.commons.codec.CharEncoding; import static org.apache.commons.codec.digest.DigestUtils.md5Hex; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.model.AbstractRequest; import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthConfig; +import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.oauth.OAuth20Service; public class MailruOAuthServiceImpl extends OAuth20Service { @@ -19,7 +19,7 @@ public MailruOAuthServiceImpl(DefaultApi20 api, OAuthConfig config) { } @Override - public void signRequest(OAuth2AccessToken accessToken, AbstractRequest request) { + public void signRequest(OAuth2AccessToken accessToken, OAuthRequest request) { // sig = md5(params + secret_key) request.addQuerystringParameter("session_key", accessToken.getAccessToken()); request.addQuerystringParameter("app_id", getConfig().getApiKey()); diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiServiceImpl.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiServiceImpl.java index 2a6e01339..9de7f8fa2 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiServiceImpl.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiServiceImpl.java @@ -5,9 +5,9 @@ import org.apache.commons.codec.CharEncoding; import static org.apache.commons.codec.digest.DigestUtils.md5Hex; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.model.AbstractRequest; import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthConfig; +import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.oauth.OAuth20Service; import java.util.Arrays; @@ -18,7 +18,7 @@ public OdnoklassnikiServiceImpl(DefaultApi20 api, OAuthConfig config) { } @Override - public void signRequest(OAuth2AccessToken accessToken, AbstractRequest request) { + public void signRequest(OAuth2AccessToken accessToken, OAuthRequest request) { //sig = lower(md5( sorted_request_params_composed_string + md5(access_token + application_secret_key))) try { final String tokenDigest = md5Hex(accessToken.getAccessToken() + getConfig().getApiSecret()); diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/TutByOAuthServiceImpl.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/TutByOAuthServiceImpl.java index 21a61d13e..f1f14485f 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/TutByOAuthServiceImpl.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/TutByOAuthServiceImpl.java @@ -1,10 +1,10 @@ package com.github.scribejava.apis.service; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.model.AbstractRequest; import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; +import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.oauth.OAuth20Service; public class TutByOAuthServiceImpl extends OAuth20Service { @@ -14,7 +14,7 @@ public TutByOAuthServiceImpl(DefaultApi20 api, OAuthConfig config) { } @Override - public void signRequest(OAuth2AccessToken accessToken, AbstractRequest request) { + public void signRequest(OAuth2AccessToken accessToken, OAuthRequest request) { request.addQuerystringParameter(OAuthConstants.TOKEN, accessToken.getAccessToken()); } } diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java index a6e8b58f5..7bc944dd8 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java @@ -8,7 +8,7 @@ import com.github.scribejava.apis.FacebookApi; import com.github.scribejava.core.builder.ServiceBuilder; import com.github.scribejava.core.model.OAuth2AccessToken; -import com.github.scribejava.core.model.OAuthRequestAsync; +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; @@ -35,62 +35,62 @@ public static void main(String... args) throws InterruptedException, ExecutionEx .setReadTimeout(1_000) .build()); - final OAuth20Service service = new ServiceBuilder() + try (OAuth20Service service = new ServiceBuilder() .apiKey(clientId) .apiSecret(clientSecret) .state(secretState) .callback("http://www.example.com/oauth_callback/") .httpClientConfig(clientConfig) - .build(FacebookApi.instance()); + .build(FacebookApi.instance())) { + final Scanner in = new Scanner(System.in, "UTF-8"); - final Scanner in = new Scanner(System.in, "UTF-8"); + System.out.println("=== " + NETWORK_NAME + "'s Async OAuth Workflow ==="); + System.out.println(); - System.out.println("=== " + NETWORK_NAME + "'s Async OAuth Workflow ==="); - System.out.println(); + // Obtain the Authorization URL + System.out.println("Fetching the Authorization URL..."); + final String authorizationUrl = service.getAuthorizationUrl(); + System.out.println("Got the Authorization URL!"); + System.out.println("Now go and authorize ScribeJava here:"); + System.out.println(authorizationUrl); + System.out.println("And paste the authorization code here"); + System.out.print(">>"); + final String code = in.nextLine(); + System.out.println(); - // Obtain the Authorization URL - System.out.println("Fetching the Authorization URL..."); - final String authorizationUrl = service.getAuthorizationUrl(); - System.out.println("Got the Authorization URL!"); - System.out.println("Now go and authorize ScribeJava here:"); - System.out.println(authorizationUrl); - System.out.println("And paste the authorization code here"); - System.out.print(">>"); - final String code = in.nextLine(); - System.out.println(); + System.out.println("And paste the state from server here. We have set 'secretState'='" + + secretState + "'."); + System.out.print(">>"); + final String value = in.nextLine(); + if (secretState.equals(value)) { + System.out.println("State value does match!"); + } else { + System.out.println("Ooops, state value does not match!"); + System.out.println("Expected = " + secretState); + System.out.println("Got = " + value); + System.out.println(); + } - 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); + // Trade the Request Token and Verfier for the Access Token + System.out.println("Trading the Request Token for an Access Token..."); + final OAuth2AccessToken accessToken = service.getAccessTokenAsync(code, null).get(); + System.out.println("Got the Access Token!"); + System.out.println("(if your curious it looks like this: " + accessToken + + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); System.out.println(); - } - - // Trade the Request Token and Verfier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); - final OAuth2AccessToken accessToken = service.getAccessTokenAsync(code, null).get(); - System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); - System.out.println(); - // Now let's go and ask for a protected resource! - System.out.println("Now we're going to access a protected resource..."); - final OAuthRequestAsync request = new OAuthRequestAsync(Verb.GET, PROTECTED_RESOURCE_URL); - service.signRequest(accessToken, request); - final Response response = service.execute(request, null).get(); - System.out.println("Got it! Lets see what we found..."); - System.out.println(); - System.out.println(response.getCode()); - System.out.println(response.getBody()); + // Now let's go and ask for a protected resource! + System.out.println("Now we're going to access a protected resource..."); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); + service.signRequest(accessToken, request); + final Response response = service.execute(request, null).get(); + 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! :)"); - service.closeAsyncClient(); + System.out.println(); + System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); + } } } diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubAsyncOkHttpExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubAsyncOkHttpExample.java index fc8d5ec44..1cfb35d06 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubAsyncOkHttpExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubAsyncOkHttpExample.java @@ -3,7 +3,7 @@ import com.github.scribejava.apis.GitHubApi; import com.github.scribejava.core.builder.ServiceBuilder; import com.github.scribejava.core.model.OAuth2AccessToken; -import com.github.scribejava.core.model.OAuthRequestAsync; +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; @@ -27,61 +27,62 @@ public static void main(String... args) throws IOException, ExecutionException, final String clientId = "your client id"; final String clientSecret = "your client secret"; final String secretState = "secret" + new Random().nextInt(999_999); - final OAuth20Service service = new ServiceBuilder() + try (OAuth20Service service = new ServiceBuilder() .apiKey(clientId) .apiSecret(clientSecret) .state(secretState) .callback("http://www.example.com/oauth_callback/") .httpClientConfig(OkHttpHttpClientConfig.defaultConfig()) - .build(GitHubApi.instance()); - final Scanner in = new Scanner(System.in, "UTF-8"); + .build(GitHubApi.instance())) { + final Scanner in = new Scanner(System.in, "UTF-8"); - System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); - System.out.println(); - - // Obtain the Authorization URL - System.out.println("Fetching the Authorization URL..."); - final String authorizationUrl = service.getAuthorizationUrl(); - System.out.println("Got the Authorization URL!"); - System.out.println("Now go and authorize ScribeJava here:"); - System.out.println(authorizationUrl); - System.out.println("And paste the authorization code here"); - System.out.print(">>"); - final String code = in.nextLine(); - System.out.println(); + System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); + 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); + // Obtain the Authorization URL + System.out.println("Fetching the Authorization URL..."); + final String authorizationUrl = service.getAuthorizationUrl(); + System.out.println("Got the Authorization URL!"); + System.out.println("Now go and authorize ScribeJava here:"); + System.out.println(authorizationUrl); + System.out.println("And paste the authorization code here"); + System.out.print(">>"); + final String code = in.nextLine(); System.out.println(); - } - // Trade the Request Token and Verfier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); - final OAuth2AccessToken accessToken = service.getAccessTokenAsync(code, null).get(); - System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); - System.out.println(); + System.out.println("And paste the state from server here. We have set 'secretState'='" + + secretState + "'."); + System.out.print(">>"); + final String value = in.nextLine(); + if (secretState.equals(value)) { + System.out.println("State value does match!"); + } else { + System.out.println("Ooops, state value does not match!"); + System.out.println("Expected = " + secretState); + System.out.println("Got = " + value); + System.out.println(); + } + + // Trade the Request Token and Verfier for the Access Token + System.out.println("Trading the Request Token for an Access Token..."); + final OAuth2AccessToken accessToken = service.getAccessTokenAsync(code, null).get(); + System.out.println("Got the Access Token!"); + System.out.println("(if your curious it looks like this: " + accessToken + + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println(); - // Now let's go and ask for a protected resource! - System.out.println("Now we're going to access a protected resource..."); - final OAuthRequestAsync request = new OAuthRequestAsync(Verb.GET, PROTECTED_RESOURCE_URL); - service.signRequest(accessToken, request); - final Response response = service.execute(request, null).get(); - System.out.println("Got it! Lets see what we found..."); - System.out.println(); - System.out.println(response.getCode()); - System.out.println(response.getBody()); + // Now let's go and ask for a protected resource! + System.out.println("Now we're going to access a protected resource..."); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); + service.signRequest(accessToken, request); + final Response response = service.execute(request, null).get(); + 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! :)"); - service.closeAsyncClient(); + System.out.println(); + System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); + } } } diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java index 4511aa64b..baddacc9b 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java @@ -7,7 +7,7 @@ import com.github.scribejava.core.builder.ServiceBuilder; import com.github.scribejava.core.httpclient.HttpClientConfig; import com.github.scribejava.core.model.OAuth2AccessToken; -import com.github.scribejava.core.model.OAuthRequestAsync; +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; @@ -37,88 +37,89 @@ public static void main(String... args) throws InterruptedException, ExecutionEx .setReadTimeout(1_000) .build()); - final OAuth20Service service = new ServiceBuilder() + try (OAuth20Service service = new ServiceBuilder() .apiKey(clientId) .apiSecret(clientSecret) .scope("profile") // replace with desired scope .state(secretState) .callback("http://example.com/callback") .httpClientConfig(clientConfig) - .build(GoogleApi20.instance()); - final Scanner in = new Scanner(System.in, "UTF-8"); + .build(GoogleApi20.instance())) { + final Scanner in = new Scanner(System.in, "UTF-8"); - System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); - System.out.println(); - - // Obtain the Authorization URL - System.out.println("Fetching the Authorization URL..."); - //pass access_type=offline to get refresh token - //https://developers.google.com/identity/protocols/OAuth2WebServer#preparing-to-start-the-oauth-20-flow - final Map additionalParams = new HashMap<>(); - additionalParams.put("access_type", "offline"); - //force to reget refresh token (if usera are asked not the first time) - additionalParams.put("prompt", "consent"); - final String authorizationUrl = service.getAuthorizationUrl(additionalParams); - System.out.println("Got the Authorization URL!"); - System.out.println("Now go and authorize ScribeJava here:"); - System.out.println(authorizationUrl); - System.out.println("And paste the authorization code here"); - System.out.print(">>"); - final String code = in.nextLine(); - System.out.println(); - - System.out.println("And paste the state from server here. We have set 'secretState'='" + secretState + "'."); - System.out.print(">>"); - final String value = in.nextLine(); - if (secretState.equals(value)) { - System.out.println("State value does match!"); - } else { - System.out.println("Ooops, state value does not match!"); - System.out.println("Expected = " + secretState); - System.out.println("Got = " + value); + System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); System.out.println(); - } - // Trade the Request Token and Verfier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); - OAuth2AccessToken accessToken = service.getAccessTokenAsync(code, null).get(); - System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); - - System.out.println("Refreshing the Access Token..."); - accessToken = service.refreshAccessTokenAsync(accessToken.getRefreshToken(), null).get(); - System.out.println("Refreshed the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); - System.out.println(); - - // Now let's go and ask for a protected resource! - System.out.println("Now we're going to access a protected resource..."); - while (true) { - System.out.println("Paste fieldnames to fetch (leave empty to get profile, 'exit' to stop example)"); + // Obtain the Authorization URL + System.out.println("Fetching the Authorization URL..."); + //pass access_type=offline to get refresh token + //https://developers.google.com/identity/protocols/OAuth2WebServer#preparing-to-start-the-oauth-20-flow + final Map additionalParams = new HashMap<>(); + additionalParams.put("access_type", "offline"); + //force to reget refresh token (if usera are asked not the first time) + additionalParams.put("prompt", "consent"); + final String authorizationUrl = service.getAuthorizationUrl(additionalParams); + System.out.println("Got the Authorization URL!"); + System.out.println("Now go and authorize ScribeJava here:"); + System.out.println(authorizationUrl); + System.out.println("And paste the authorization code here"); System.out.print(">>"); - final String query = in.nextLine(); + final String code = in.nextLine(); System.out.println(); - final String requestUrl; - if ("exit".equals(query)) { - break; - } else if (query == null || query.isEmpty()) { - requestUrl = PROTECTED_RESOURCE_URL; + 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 { - requestUrl = PROTECTED_RESOURCE_URL + "?fields=" + query; + System.out.println("Ooops, state value does not match!"); + System.out.println("Expected = " + secretState); + System.out.println("Got = " + value); + System.out.println(); } - final OAuthRequestAsync request = new OAuthRequestAsync(Verb.GET, requestUrl); - service.signRequest(accessToken, request); - final Response response = service.execute(request, null).get(); - System.out.println(); - System.out.println(response.getCode()); - System.out.println(response.getBody()); + // Trade the Request Token and Verfier for the Access Token + System.out.println("Trading the Request Token for an Access Token..."); + OAuth2AccessToken accessToken = service.getAccessTokenAsync(code, null).get(); + System.out.println("Got the Access Token!"); + System.out.println("(if your curious it looks like this: " + accessToken + + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("Refreshing the Access Token..."); + accessToken = service.refreshAccessTokenAsync(accessToken.getRefreshToken(), null).get(); + System.out.println("Refreshed the Access Token!"); + System.out.println("(if your curious it looks like this: " + accessToken + + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); System.out.println(); + + // Now let's go and ask for a protected resource! + System.out.println("Now we're going to access a protected resource..."); + while (true) { + System.out.println("Paste fieldnames to fetch (leave empty to get profile, 'exit' to stop example)"); + System.out.print(">>"); + final String query = in.nextLine(); + System.out.println(); + + final String requestUrl; + if ("exit".equals(query)) { + break; + } else if (query == null || query.isEmpty()) { + requestUrl = PROTECTED_RESOURCE_URL; + } else { + requestUrl = PROTECTED_RESOURCE_URL + "?fields=" + query; + } + + final OAuthRequest request = new OAuthRequest(Verb.GET, requestUrl); + service.signRequest(accessToken, request); + final Response response = service.execute(request, null).get(); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + + System.out.println(); + } } - service.closeAsyncClient(); } } diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java index ec1c8868b..e4343d19b 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java @@ -7,7 +7,7 @@ import com.github.scribejava.apis.MailruApi; import com.github.scribejava.core.builder.ServiceBuilder; import com.github.scribejava.core.model.OAuth2AccessToken; -import com.github.scribejava.core.model.OAuthRequestAsync; +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; @@ -35,49 +35,48 @@ public static void main(String... args) throws InterruptedException, ExecutionEx .setReadTimeout(10_000) .build()); - final OAuth20Service service = new ServiceBuilder() + try (OAuth20Service service = new ServiceBuilder() .apiKey(clientId) .apiSecret(clientSecret) .callback("http://www.example.com/oauth_callback/") .httpClientConfig(clientConfig) - .build(MailruApi.instance()); + .build(MailruApi.instance())) { + final Scanner in = new Scanner(System.in, "UTF-8"); - final Scanner in = new Scanner(System.in, "UTF-8"); + System.out.println("=== " + NETWORK_NAME + "'s Async OAuth Workflow ==="); + System.out.println(); - System.out.println("=== " + NETWORK_NAME + "'s Async OAuth Workflow ==="); - System.out.println(); + // Obtain the Authorization URL + System.out.println("Fetching the Authorization URL..."); + final String authorizationUrl = service.getAuthorizationUrl(); + System.out.println("Got the Authorization URL!"); + System.out.println("Now go and authorize ScribeJava here:"); + System.out.println(authorizationUrl); + System.out.println("And paste the authorization code here"); + System.out.print(">>"); + final String code = in.nextLine(); + System.out.println(); - // Obtain the Authorization URL - System.out.println("Fetching the Authorization URL..."); - final String authorizationUrl = service.getAuthorizationUrl(); - System.out.println("Got the Authorization URL!"); - System.out.println("Now go and authorize ScribeJava here:"); - System.out.println(authorizationUrl); - System.out.println("And paste the authorization code here"); - System.out.print(">>"); - final String code = in.nextLine(); - System.out.println(); + // Trade the Request Token and Verfier for the Access Token + System.out.println("Trading the Request Token for an Access Token..."); + final OAuth2AccessToken accessToken = service.getAccessTokenAsync(code, null).get(); + System.out.println("Got the Access Token!"); + System.out.println("(if your curious it looks like this: " + accessToken + + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println(); - // Trade the Request Token and Verfier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); - final OAuth2AccessToken accessToken = service.getAccessTokenAsync(code, null).get(); - System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); - System.out.println(); + System.out.println("Now we're going to access a protected resource..."); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); + service.signRequest(accessToken, request); + final Response response = service.execute(request, null).get(); - System.out.println("Now we're going to access a protected resource..."); - final OAuthRequestAsync request = new OAuthRequestAsync(Verb.GET, PROTECTED_RESOURCE_URL); - service.signRequest(accessToken, request); - final Response response = service.execute(request, null).get(); + 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("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! :)"); - service.closeAsyncClient(); + System.out.println(); + System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); + } } } diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceNingAsyncExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceNingAsyncExample.java index 4167b535d..e57cd7f8d 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceNingAsyncExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceNingAsyncExample.java @@ -11,7 +11,7 @@ import com.github.scribejava.apis.salesforce.SalesforceToken; import com.github.scribejava.httpclient.ning.NingHttpClientConfig; import com.github.scribejava.core.builder.ServiceBuilder; -import com.github.scribejava.core.model.OAuthRequestAsync; +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; @@ -43,62 +43,51 @@ public static void main(String... args) throws InterruptedException, ExecutionEx //IT's important! Salesforce upper require TLS v1.1 or 1.2 SalesforceApi.initTLSv11orUpper(); - final OAuth20Service service = new ServiceBuilder() + try (OAuth20Service service = new ServiceBuilder() .apiKey(clientId) .apiSecret(clientSecret) .httpClientConfig(clientConfig) .callback("https://www.example.com/callback") - .build(SalesforceApi.instance()); - - System.out.println("=== " + NETWORK_NAME + "'s OAuth20 Workflow ==="); - System.out.println(); - - // Obtain the Authorization URL - System.out.println("Fetching the Authorization URL..."); - final String authorizationUrl = service.getAuthorizationUrl(); - System.out.println("Got the Authorization URL!"); - System.out.println("Now go and authorize ScribeJava here:"); - System.out.println(authorizationUrl); - System.out.println("And paste the authorization code here"); - System.out.print(">>"); - final String code; - try (Scanner in = new Scanner(System.in)) { - code = in.nextLine(); + .build(SalesforceApi.instance())) { + System.out.println("=== " + NETWORK_NAME + "'s OAuth20 Workflow ==="); + System.out.println(); + // Obtain the Authorization URL + System.out.println("Fetching the Authorization URL..."); + final String authorizationUrl = service.getAuthorizationUrl(); + System.out.println("Got the Authorization URL!"); + System.out.println("Now go and authorize ScribeJava here:"); + System.out.println(authorizationUrl); + System.out.println("And paste the authorization code here"); + System.out.print(">>"); + final String code; + try (Scanner in = new Scanner(System.in)) { + code = in.nextLine(); + } + System.out.println(); + final String codeEncoded = URLDecoder.decode(code, "UTF-8"); + // Trade the Request Token and Verifier for the Access Token + System.out.println("Trading the Request Token for an Access Token..."); + final SalesforceToken accessToken = (SalesforceToken) service.getAccessTokenAsync(codeEncoded, null).get(); + System.out.println("Got the Access Token!"); + System.out.println("(if your curious it looks like this: " + accessToken + + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println(); + System.out.println("Instance is: " + accessToken.getInstanceUrl()); + // Now let's go and ask for a protected resource! + System.out.println("Now we're reading accounts from the Salesforce org (maxing them to 10)."); + // Sample SOQL statement + final String queryEncoded = URLEncoder.encode("Select Id, Name from Account LIMIT 10", "UTF-8"); + // Building the query URI. We've parsed the instance URL from the + // accessToken request. + final String url = accessToken.getInstanceUrl() + "/services/data/v36.0/query?q=" + queryEncoded; + System.out.println(); + System.out.println("Full URL: " + url); + final OAuthRequest request = new OAuthRequest(Verb.GET, url); + request.addHeader("Authorization", "Bearer " + accessToken.getAccessToken()); + final Response response = service.execute(request, null).get(); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); } - System.out.println(); - - final String codeEncoded = URLDecoder.decode(code, "UTF-8"); - - // Trade the Request Token and Verifier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); - final SalesforceToken accessToken = (SalesforceToken) service.getAccessTokenAsync(codeEncoded, null).get(); - System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); - System.out.println(); - - System.out.println("Instance is: " + accessToken.getInstanceUrl()); - - // Now let's go and ask for a protected resource! - System.out.println("Now we're reading accounts from the Salesforce org (maxing them to 10)."); - - // Sample SOQL statement - final String queryEncoded = URLEncoder.encode("Select Id, Name from Account LIMIT 10", "UTF-8"); - - // Building the query URI. We've parsed the instance URL from the - // accessToken request. - final String url = accessToken.getInstanceUrl() + "/services/data/v36.0/query?q=" + queryEncoded; - - System.out.println(); - System.out.println("Full URL: " + url); - - final OAuthRequestAsync request = new OAuthRequestAsync(Verb.GET, url); - request.addHeader("Authorization", "Bearer " + accessToken.getAccessToken()); - final Response response = service.execute(request, null).get(); - - System.out.println(); - System.out.println(response.getCode()); - System.out.println(response.getBody()); - service.closeAsyncClient(); } } 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 ad16d5428..cfdbe6210 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 @@ -4,7 +4,7 @@ import com.github.scribejava.core.builder.ServiceBuilder; import com.github.scribejava.apis.VkontakteApi; import com.github.scribejava.core.model.OAuth2AccessToken; -import com.github.scribejava.core.model.OAuthRequestAsync; +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; @@ -72,7 +72,7 @@ public static void main(String... args) throws IOException, InterruptedException // Now let's go and ask for a protected resource! System.out.println("Now we're going to access a protected resource..."); - final OAuthRequestAsync request = new OAuthRequestAsync(Verb.GET, PROTECTED_RESOURCE_URL); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); service.signRequest(accessToken, request); final Response response = service.execute(request, null).get(); System.out.println("Got it! Lets see what we found..."); diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/exceptions/OAuthParametersMissingException.java b/scribejava-core/src/main/java/com/github/scribejava/core/exceptions/OAuthParametersMissingException.java index ddf77ab78..2d4a5dfc4 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/exceptions/OAuthParametersMissingException.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/exceptions/OAuthParametersMissingException.java @@ -1,6 +1,6 @@ package com.github.scribejava.core.exceptions; -import com.github.scribejava.core.model.AbstractRequest; +import com.github.scribejava.core.model.OAuthRequest; /** * Specialized exception that represents a missing OAuth parameter. @@ -16,7 +16,7 @@ public class OAuthParametersMissingException extends OAuthException { * * @param request OAuthRequest that caused the error */ - public OAuthParametersMissingException(AbstractRequest request) { + public OAuthParametersMissingException(OAuthRequest request) { super(String.format(MSG, request)); } } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/BaseStringExtractor.java b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/BaseStringExtractor.java index 113dc3515..21cb3431b 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/BaseStringExtractor.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/BaseStringExtractor.java @@ -1,19 +1,19 @@ package com.github.scribejava.core.extractors; -import com.github.scribejava.core.model.AbstractRequest; +import com.github.scribejava.core.model.OAuthRequest; /** - * Simple command object that extracts a base string from a {@link AbstractRequest} + * Simple command object that extracts a base string from a {@link OAuthRequest} */ public interface BaseStringExtractor { /** - * Extracts an url-encoded base string from the {@link AbstractRequest}. + * Extracts an url-encoded base string from the {@link OAuthRequest}. * * See the oauth spec for more info on this. * * @param request the OAuthRequest * @return the url-encoded base string */ - String extract(AbstractRequest request); + String extract(OAuthRequest request); } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/BaseStringExtractorImpl.java b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/BaseStringExtractorImpl.java index e2ba3b950..879dac9ae 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/BaseStringExtractorImpl.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/BaseStringExtractorImpl.java @@ -1,7 +1,7 @@ package com.github.scribejava.core.extractors; import com.github.scribejava.core.exceptions.OAuthParametersMissingException; -import com.github.scribejava.core.model.AbstractRequest; +import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.ParameterList; import com.github.scribejava.core.utils.OAuthEncoder; import com.github.scribejava.core.utils.Preconditions; @@ -17,7 +17,7 @@ public class BaseStringExtractorImpl implements BaseStringExtractor { * {@inheritDoc} */ @Override - public String extract(AbstractRequest request) { + public String extract(OAuthRequest request) { checkPreconditions(request); final String verb = OAuthEncoder.encode(getVerb(request)); final String url = OAuthEncoder.encode(getUrl(request)); @@ -25,15 +25,15 @@ public String extract(AbstractRequest request) { return String.format(AMPERSAND_SEPARATED_STRING, verb, url, params); } - protected String getVerb(AbstractRequest request) { + protected String getVerb(OAuthRequest request) { return request.getVerb().name(); } - protected String getUrl(AbstractRequest request) { + protected String getUrl(OAuthRequest request) { return request.getSanitizedUrl(); } - protected String getSortedAndEncodedParams(AbstractRequest request) { + protected String getSortedAndEncodedParams(OAuthRequest request) { final ParameterList params = new ParameterList(); params.addAll(request.getQueryStringParams()); params.addAll(request.getBodyParams()); @@ -41,7 +41,7 @@ protected String getSortedAndEncodedParams(AbstractRequest request) { return params.sort().asOauthBaseString(); } - protected void checkPreconditions(AbstractRequest request) { + protected void checkPreconditions(OAuthRequest request) { Preconditions.checkNotNull(request, "Cannot extract base string from a null object"); if (request.getOauthParameters() == null || request.getOauthParameters().size() <= 0) { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/HeaderExtractor.java b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/HeaderExtractor.java index d84390a91..e6e6156e4 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/HeaderExtractor.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/HeaderExtractor.java @@ -1,6 +1,6 @@ package com.github.scribejava.core.extractors; -import com.github.scribejava.core.model.AbstractRequest; +import com.github.scribejava.core.model.OAuthRequest; /** * Simple command object that generates an OAuth Authorization header to include in the request. @@ -13,5 +13,5 @@ public interface HeaderExtractor { * @param request the AbstractRequest to inspect and generate the header * @return the Http header value */ - String extract(AbstractRequest request); + String extract(OAuthRequest request); } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/HeaderExtractorImpl.java b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/HeaderExtractorImpl.java index a3c142a10..2a840521c 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/HeaderExtractorImpl.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/HeaderExtractorImpl.java @@ -3,7 +3,7 @@ import java.util.Map; import com.github.scribejava.core.exceptions.OAuthParametersMissingException; import com.github.scribejava.core.model.OAuthConstants; -import com.github.scribejava.core.model.AbstractRequest; +import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.utils.OAuthEncoder; import com.github.scribejava.core.utils.Preconditions; @@ -20,7 +20,7 @@ public class HeaderExtractorImpl implements HeaderExtractor { * {@inheritDoc} */ @Override - public String extract(AbstractRequest request) { + public String extract(OAuthRequest request) { checkPreconditions(request); final Map parameters = request.getOauthParameters(); final StringBuilder header = new StringBuilder(parameters.size() * ESTIMATED_PARAM_LENGTH); @@ -40,7 +40,7 @@ public String extract(AbstractRequest request) { return header.toString(); } - private void checkPreconditions(AbstractRequest request) { + private void checkPreconditions(OAuthRequest request) { Preconditions.checkNotNull(request, "Cannot extract a header from a null object"); if (request.getOauthParameters() == null || request.getOauthParameters().size() <= 0) { 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 7b59a81f5..091a95849 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.OAuthRequestAsync; +import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; import com.github.scribejava.core.model.Verb; import java.io.File; @@ -14,20 +14,20 @@ 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, - (OAuthRequestAsync.ResponseConverter) null).get(); + (OAuthRequest.ResponseConverter) null).get(); } @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, - (OAuthRequestAsync.ResponseConverter) null).get(); + (OAuthRequest.ResponseConverter) null).get(); } @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, - (OAuthRequestAsync.ResponseConverter) null).get(); + (OAuthRequest.ResponseConverter) null).get(); } } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/HttpClient.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/HttpClient.java index 3d6d0433f..5793faf5c 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/HttpClient.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/HttpClient.java @@ -1,7 +1,7 @@ package com.github.scribejava.core.httpclient; import com.github.scribejava.core.model.OAuthAsyncRequestCallback; -import com.github.scribejava.core.model.OAuthRequestAsync; +import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; import com.github.scribejava.core.model.Verb; import java.io.File; @@ -18,15 +18,13 @@ public interface HttpClient { void close() throws IOException; Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, - byte[] bodyContents, OAuthAsyncRequestCallback callback, - OAuthRequestAsync.ResponseConverter converter); + byte[] bodyContents, OAuthAsyncRequestCallback callback, OAuthRequest.ResponseConverter converter); Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, - String bodyContents, OAuthAsyncRequestCallback callback, - OAuthRequestAsync.ResponseConverter converter); + String bodyContents, OAuthAsyncRequestCallback callback, OAuthRequest.ResponseConverter converter); Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, - File bodyContents, OAuthAsyncRequestCallback callback, OAuthRequestAsync.ResponseConverter converter); + File bodyContents, OAuthAsyncRequestCallback callback, OAuthRequest.ResponseConverter converter); Response execute(String userAgent, Map headers, Verb httpVerb, String completeUrl, byte[] bodyContents) throws InterruptedException, ExecutionException, IOException; diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java index 64350a764..3e19a7d6d 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java @@ -4,7 +4,7 @@ import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.model.OAuthAsyncRequestCallback; import com.github.scribejava.core.model.OAuthConstants; -import com.github.scribejava.core.model.OAuthRequestAsync; +import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; import com.github.scribejava.core.model.Verb; import java.io.File; @@ -32,8 +32,7 @@ public void close() throws IOException { @Override public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, - byte[] bodyContents, OAuthAsyncRequestCallback callback, - OAuthRequestAsync.ResponseConverter converter) { + byte[] bodyContents, OAuthAsyncRequestCallback callback, OAuthRequest.ResponseConverter converter) { try { final T response = converter.convert(execute(userAgent, headers, httpVerb, completeUrl, bodyContents)); callback.onCompleted(response); @@ -46,22 +45,24 @@ public Future executeAsync(String userAgent, Map headers, @Override public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, - String bodyContents, OAuthAsyncRequestCallback callback, - OAuthRequestAsync.ResponseConverter converter) { + String bodyContents, OAuthAsyncRequestCallback callback, OAuthRequest.ResponseConverter converter) { try { final T response = converter.convert(execute(userAgent, headers, httpVerb, completeUrl, bodyContents)); - callback.onCompleted(response); + if (callback != null) { + callback.onCompleted(response); + } return new JDKHttpFuture<>(response); } catch (InterruptedException | ExecutionException | IOException e) { - callback.onThrowable(e); + if (callback != null) { + callback.onThrowable(e); + } return new JDKHttpFuture<>(e); } } @Override public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, - File bodyContents, OAuthAsyncRequestCallback callback, - OAuthRequestAsync.ResponseConverter converter) { + File bodyContents, OAuthAsyncRequestCallback callback, OAuthRequest.ResponseConverter converter) { throw new UnsupportedOperationException("JDKHttpClient do not support File payload for the moment"); } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/AbstractRequest.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/AbstractRequest.java index 96550f4e9..7cf52107d 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/AbstractRequest.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/AbstractRequest.java @@ -1,272 +1,9 @@ package com.github.scribejava.core.model; -import java.io.UnsupportedEncodingException; -import java.net.MalformedURLException; -import java.net.URL; -import java.nio.charset.Charset; -import java.util.HashMap; -import java.util.Map; -import com.github.scribejava.core.exceptions.OAuthException; -import java.io.File; - /** - * The representation of an OAuth HttpRequest. + * @deprecated use {@link OAuthRequest} */ +@Deprecated public abstract class AbstractRequest { - private static final String OAUTH_PREFIX = "oauth_"; - - private final String url; - private final Verb verb; - private final ParameterList querystringParams = new ParameterList(); - private final ParameterList bodyParams = new ParameterList(); - private final Map headers = new HashMap<>(); - - private String charset; - - private String stringPayload; - private byte[] byteArrayPayload; - private File filePayload; - - private final Map oauthParameters = new HashMap<>(); - - private String realm; - - /** - * Default constructor. - * - * @param verb Http verb/method - * @param url resource URL - */ - public AbstractRequest(Verb verb, String url) { - this.verb = verb; - this.url = url; - } - - /** - * Adds an OAuth parameter. - * - * @param key name of the parameter - * @param value value of the parameter - * @throws IllegalArgumentException if the parameter is not an OAuth parameter - */ - public void addOAuthParameter(String key, String value) { - oauthParameters.put(checkKey(key), value); - } - - private String checkKey(String key) { - if (key.startsWith(OAUTH_PREFIX) || key.equals(OAuthConstants.SCOPE) || key.equals(OAuthConstants.REALM)) { - return key; - } else { - throw new IllegalArgumentException( - String.format("OAuth parameters must either be '%s', '%s' or start with '%s'", OAuthConstants.SCOPE, - OAuthConstants.REALM, OAUTH_PREFIX)); - } - } - - public Map getOauthParameters() { - return oauthParameters; - } - - public void setRealm(String realm) { - this.realm = realm; - } - - public String getRealm() { - return realm; - } - - /** - * Returns the complete url (host + resource + encoded querystring parameters). - * - * @return the complete url. - */ - public String getCompleteUrl() { - return querystringParams.appendTo(url); - } - - /** - * Add an HTTP Header to the Request - * - * @param key the header name - * @param value the header value - */ - public void addHeader(String key, String value) { - this.headers.put(key, value); - } - - /** - * Add a body Parameter (for POST/ PUT Requests) - * - * @param key the parameter name - * @param value the parameter value - */ - public void addBodyParameter(String key, String value) { - this.bodyParams.add(key, value); - } - - /** - * Add a QueryString parameter - * - * @param key the parameter name - * @param value the parameter value - */ - public void addQuerystringParameter(String key, String value) { - this.querystringParams.add(key, value); - } - - public void addParameter(String key, String value) { - if (hasBodyContent()) { - bodyParams.add(key, value); - } else { - querystringParams.add(key, value); - } - } - - protected boolean hasBodyContent() { - return verb == Verb.PUT || verb == Verb.POST; - } - - /** - * Set body payload. This method is used when the HTTP body is not a form-url-encoded string, but another thing. - * Like for example XML. Note: The contents are not part of the OAuth signature - * - * @param payload the body of the request - */ - public void setPayload(String payload) { - resetPayload(); - stringPayload = payload; - } - - /** - * Overloaded version for byte arrays - * - * @param payload byte[] - */ - public void setPayload(byte[] payload) { - resetPayload(); - byteArrayPayload = payload.clone(); - } - - /** - * Overloaded version for File - * - * @param payload File - */ - public void setPayload(File payload) { - resetPayload(); - filePayload = payload; - } - - private void resetPayload() { - stringPayload = null; - byteArrayPayload = null; - filePayload = null; - } - - /** - * Get a {@link ParameterList} with the query string parameters. - * - * @return a {@link ParameterList} containing the query string parameters. - * @throws OAuthException if the request URL is not valid. - */ - public ParameterList getQueryStringParams() { - try { - final ParameterList result = new ParameterList(); - final String queryString = new URL(url).getQuery(); - result.addQuerystring(queryString); - result.addAll(querystringParams); - return result; - } catch (MalformedURLException mue) { - throw new OAuthException("Malformed URL", mue); - } - } - - /** - * Obtains a {@link ParameterList} of the body parameters. - * - * @return a {@link ParameterList}containing the body parameters. - */ - public ParameterList getBodyParams() { - return bodyParams; - } - - /** - * Obtains the URL of the HTTP Request. - * - * @return the original URL of the HTTP Request - */ - public String getUrl() { - return url; - } - - /** - * Returns the URL without the port and the query string part. - * - * @return the OAuth-sanitized URL - */ - public String getSanitizedUrl() { - if (url.startsWith("http://") && (url.endsWith(":80") || url.contains(":80/"))) { - return url.replaceAll("\\?.*", "").replaceAll(":80", ""); - } else if (url.startsWith("https://") && (url.endsWith(":443") || url.contains(":443/"))) { - return url.replaceAll("\\?.*", "").replaceAll(":443", ""); - } else { - return url.replaceAll("\\?.*", ""); - } - } - - /** - * Returns the body of the request (set in {@link #setPayload(java.lang.String)}) - * - * @return form encoded string - */ - public String getStringPayload() { - return stringPayload; - } - - /** - * @return the body of the request (set in {@link #setPayload(byte[])} or in - * {@link #addBodyParameter(java.lang.String, java.lang.String)} ) - */ - public byte[] getByteArrayPayload() { - if (byteArrayPayload != null) { - return byteArrayPayload; - } - final String body = bodyParams.asFormUrlEncodedString(); - try { - return body.getBytes(getCharset()); - } catch (UnsupportedEncodingException uee) { - throw new OAuthException("Unsupported Charset: " + getCharset(), uee); - } - } - - public File getFilePayload() { - return filePayload; - } - - @Override - public String toString() { - return String.format("@Request(%s %s)", getVerb(), getUrl()); - } - - public Verb getVerb() { - return verb; - } - - public Map getHeaders() { - return headers; - } - - public String getCharset() { - return charset == null ? Charset.defaultCharset().name() : charset; - } - - /** - * Set the charset of the body of the request - * - * @param charsetName name of the charset of the request - */ - public void setCharset(String charsetName) { - charset = charsetName; - } } 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 b12c3683d..ba99bf6b5 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequest.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequest.java @@ -1,9 +1,47 @@ package com.github.scribejava.core.model; +import com.github.scribejava.core.exceptions.OAuthException; +import java.io.File; +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.net.MalformedURLException; +import java.net.URL; +import java.nio.charset.Charset; +import java.util.HashMap; +import java.util.Map; + +/** + * The representation of an OAuth HttpRequest. + */ public class OAuthRequest extends AbstractRequest { + private static final String OAUTH_PREFIX = "oauth_"; + + private final String url; + private final Verb verb; + private final ParameterList querystringParams = new ParameterList(); + private final ParameterList bodyParams = new ParameterList(); + private final Map headers = new HashMap<>(); + + private String charset; + + private String stringPayload; + private byte[] byteArrayPayload; + private File filePayload; + + private final Map oauthParameters = new HashMap<>(); + + private String realm; + + /** + * Default constructor. + * + * @param verb Http verb/method + * @param url resource URL + */ public OAuthRequest(Verb verb, String url) { - super(verb, url); + this.verb = verb; + this.url = url; } /** @@ -17,4 +55,237 @@ public OAuthRequest(Verb verb, String url) { public OAuthRequest(Verb verb, String url, OAuthConfig config) { this(verb, url); } + + /** + * Adds an OAuth parameter. + * + * @param key name of the parameter + * @param value value of the parameter + * @throws IllegalArgumentException if the parameter is not an OAuth parameter + */ + public void addOAuthParameter(String key, String value) { + oauthParameters.put(checkKey(key), value); + } + + private String checkKey(String key) { + if (key.startsWith(OAUTH_PREFIX) || key.equals(OAuthConstants.SCOPE) || key.equals(OAuthConstants.REALM)) { + return key; + } else { + throw new IllegalArgumentException( + String.format("OAuth parameters must either be '%s', '%s' or start with '%s'", OAuthConstants.SCOPE, + OAuthConstants.REALM, OAUTH_PREFIX)); + } + } + + public Map getOauthParameters() { + return oauthParameters; + } + + public void setRealm(String realm) { + this.realm = realm; + } + + public String getRealm() { + return realm; + } + + /** + * Returns the complete url (host + resource + encoded querystring parameters). + * + * @return the complete url. + */ + public String getCompleteUrl() { + return querystringParams.appendTo(url); + } + + /** + * Add an HTTP Header to the Request + * + * @param key the header name + * @param value the header value + */ + public void addHeader(String key, String value) { + this.headers.put(key, value); + } + + /** + * Add a body Parameter (for POST/ PUT Requests) + * + * @param key the parameter name + * @param value the parameter value + */ + public void addBodyParameter(String key, String value) { + this.bodyParams.add(key, value); + } + + /** + * Add a QueryString parameter + * + * @param key the parameter name + * @param value the parameter value + */ + public void addQuerystringParameter(String key, String value) { + this.querystringParams.add(key, value); + } + + public void addParameter(String key, String value) { + if (hasBodyContent()) { + bodyParams.add(key, value); + } else { + querystringParams.add(key, value); + } + } + + protected boolean hasBodyContent() { + return verb == Verb.PUT || verb == Verb.POST; + } + + /** + * Set body payload. This method is used when the HTTP body is not a form-url-encoded string, but another thing. + * Like for example XML. Note: The contents are not part of the OAuth signature + * + * @param payload the body of the request + */ + public void setPayload(String payload) { + resetPayload(); + stringPayload = payload; + } + + /** + * Overloaded version for byte arrays + * + * @param payload byte[] + */ + public void setPayload(byte[] payload) { + resetPayload(); + byteArrayPayload = payload.clone(); + } + + /** + * Overloaded version for File + * + * @param payload File + */ + public void setPayload(File payload) { + resetPayload(); + filePayload = payload; + } + + private void resetPayload() { + stringPayload = null; + byteArrayPayload = null; + filePayload = null; + } + + /** + * Get a {@link ParameterList} with the query string parameters. + * + * @return a {@link ParameterList} containing the query string parameters. + * @throws OAuthException if the request URL is not valid. + */ + public ParameterList getQueryStringParams() { + try { + final ParameterList result = new ParameterList(); + final String queryString = new URL(url).getQuery(); + result.addQuerystring(queryString); + result.addAll(querystringParams); + return result; + } catch (MalformedURLException mue) { + throw new OAuthException("Malformed URL", mue); + } + } + + /** + * Obtains a {@link ParameterList} of the body parameters. + * + * @return a {@link ParameterList}containing the body parameters. + */ + public ParameterList getBodyParams() { + return bodyParams; + } + + /** + * Obtains the URL of the HTTP Request. + * + * @return the original URL of the HTTP Request + */ + public String getUrl() { + return url; + } + + /** + * Returns the URL without the port and the query string part. + * + * @return the OAuth-sanitized URL + */ + public String getSanitizedUrl() { + if (url.startsWith("http://") && (url.endsWith(":80") || url.contains(":80/"))) { + return url.replaceAll("\\?.*", "").replaceAll(":80", ""); + } else if (url.startsWith("https://") && (url.endsWith(":443") || url.contains(":443/"))) { + return url.replaceAll("\\?.*", "").replaceAll(":443", ""); + } else { + return url.replaceAll("\\?.*", ""); + } + } + + /** + * Returns the body of the request (set in {@link #setPayload(java.lang.String)}) + * + * @return form encoded string + */ + public String getStringPayload() { + return stringPayload; + } + + /** + * @return the body of the request (set in {@link #setPayload(byte[])} or in + * {@link #addBodyParameter(java.lang.String, java.lang.String)} ) + */ + public byte[] getByteArrayPayload() { + if (byteArrayPayload != null) { + return byteArrayPayload; + } + final String body = bodyParams.asFormUrlEncodedString(); + try { + return body.getBytes(getCharset()); + } catch (UnsupportedEncodingException uee) { + throw new OAuthException("Unsupported Charset: " + getCharset(), uee); + } + } + + public File getFilePayload() { + return filePayload; + } + + @Override + public String toString() { + return String.format("@Request(%s %s)", getVerb(), getUrl()); + } + + public Verb getVerb() { + return verb; + } + + public Map getHeaders() { + return headers; + } + + public String getCharset() { + return charset == null ? Charset.defaultCharset().name() : charset; + } + + /** + * Set the charset of the body of the request + * + * @param charsetName name of the charset of the request + */ + public void setCharset(String charsetName) { + charset = charsetName; + } + + public interface ResponseConverter { + + T convert(Response response) throws IOException; + } + } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequestAsync.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequestAsync.java index f6bd48003..dc8127c05 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequestAsync.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequestAsync.java @@ -1,15 +1,27 @@ package com.github.scribejava.core.model; -import java.io.IOException; - -public class OAuthRequestAsync extends AbstractRequest { +/** + * + * @deprecated use {@link OAuthRequest} + */ +@Deprecated +public class OAuthRequestAsync extends OAuthRequest { + /** + * + * @deprecated use {@link OAuthRequest#OAuthRequest(com.github.scribejava.core.model.Verb, java.lang.String) } + */ + @Deprecated public OAuthRequestAsync(Verb verb, String url) { super(verb, url); } - public interface ResponseConverter { - - T convert(Response response) throws IOException; + /** + * + * @param goal type + * @deprecated use {@link OAuthRequest.ResponseConverter} + */ + @Deprecated + public interface ResponseConverter extends OAuthRequest.ResponseConverter { } } 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 6bdb539ed..d9332d03b 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java @@ -4,14 +4,12 @@ import java.util.Map; import java.util.concurrent.Future; import com.github.scribejava.core.builder.api.DefaultApi10a; -import com.github.scribejava.core.model.AbstractRequest; import com.github.scribejava.core.model.OAuth1AccessToken; import com.github.scribejava.core.model.OAuth1RequestToken; import com.github.scribejava.core.model.OAuthAsyncRequestCallback; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.OAuthRequest; -import com.github.scribejava.core.model.OAuthRequestAsync; import com.github.scribejava.core.model.Response; import com.github.scribejava.core.services.Base64Encoder; import com.github.scribejava.core.utils.MapUtils; @@ -39,9 +37,7 @@ public OAuth10aService(DefaultApi10a api, OAuthConfig config) { public final OAuth1RequestToken getRequestToken() throws IOException, InterruptedException, ExecutionException { final OAuthConfig config = getConfig(); config.log("obtaining request token from " + api.getRequestTokenEndpoint()); - final OAuthRequest request = new OAuthRequest(api.getRequestTokenVerb(), api.getRequestTokenEndpoint()); - - prepareRequestTokenRequest(request); + final OAuthRequest request = prepareRequestTokenRequest(); config.log("sending request..."); final Response response = execute(request); @@ -52,14 +48,16 @@ public final OAuth1RequestToken getRequestToken() throws IOException, Interrupte return api.getRequestTokenExtractor().extract(response); } + public final Future getRequestTokenAsync() { + return getRequestTokenAsync(null); + } + public final Future getRequestTokenAsync( OAuthAsyncRequestCallback callback) { final OAuthConfig config = getConfig(); config.log("async obtaining request token from " + api.getRequestTokenEndpoint()); - final OAuthRequestAsync request - = new OAuthRequestAsync(api.getRequestTokenVerb(), api.getRequestTokenEndpoint()); - prepareRequestTokenRequest(request); - return execute(request, callback, new OAuthRequestAsync.ResponseConverter() { + final OAuthRequest request = prepareRequestTokenRequest(); + return execute(request, callback, new OAuthRequest.ResponseConverter() { @Override public OAuth1RequestToken convert(Response response) throws IOException { return getApi().getRequestTokenExtractor().extract(response); @@ -67,15 +65,17 @@ public OAuth1RequestToken convert(Response response) throws IOException { }); } - protected void prepareRequestTokenRequest(AbstractRequest request) { + protected OAuthRequest prepareRequestTokenRequest() { + final OAuthRequest request = new OAuthRequest(api.getRequestTokenVerb(), api.getRequestTokenEndpoint()); final OAuthConfig config = getConfig(); config.log("setting oauth_callback to " + config.getCallback()); request.addOAuthParameter(OAuthConstants.CALLBACK, config.getCallback()); addOAuthParams(request, ""); appendSignature(request); + return request; } - private void addOAuthParams(AbstractRequest request, String tokenSecret) { + private void addOAuthParams(OAuthRequest request, String tokenSecret) { final OAuthConfig config = getConfig(); request.addOAuthParameter(OAuthConstants.TIMESTAMP, api.getTimestampService().getTimestampInSeconds()); request.addOAuthParameter(OAuthConstants.NONCE, api.getTimestampService().getNonce()); @@ -94,12 +94,15 @@ private void addOAuthParams(AbstractRequest request, String tokenSecret) { public final OAuth1AccessToken getAccessToken(OAuth1RequestToken requestToken, String oauthVerifier) throws IOException, InterruptedException, ExecutionException { getConfig().log("obtaining access token from " + api.getAccessTokenEndpoint()); - final OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint()); - prepareAccessTokenRequest(request, requestToken, oauthVerifier); + final OAuthRequest request = prepareAccessTokenRequest(requestToken, oauthVerifier); final Response response = execute(request); return api.getAccessTokenExtractor().extract(response); } + public final Future getAccessTokenAsync(OAuth1RequestToken requestToken, String oauthVerifier) { + return getAccessTokenAsync(requestToken, oauthVerifier, null); + } + /** * Start the request to retrieve the access token. The optionally provided * callback will be called with the Token when it is available. @@ -113,9 +116,8 @@ public final Future getAccessTokenAsync(OAuth1RequestToken re OAuthAsyncRequestCallback callback) { final OAuthConfig config = getConfig(); config.log("async obtaining access token from " + api.getAccessTokenEndpoint()); - final OAuthRequestAsync request = new OAuthRequestAsync(api.getAccessTokenVerb(), api.getAccessTokenEndpoint()); - prepareAccessTokenRequest(request, requestToken, oauthVerifier); - return execute(request, callback, new OAuthRequestAsync.ResponseConverter() { + final OAuthRequest request = prepareAccessTokenRequest(requestToken, oauthVerifier); + return execute(request, callback, new OAuthRequest.ResponseConverter() { @Override public OAuth1AccessToken convert(Response response) throws IOException { return getApi().getAccessTokenExtractor().extract(response); @@ -123,18 +125,19 @@ public OAuth1AccessToken convert(Response response) throws IOException { }); } - protected void prepareAccessTokenRequest(AbstractRequest request, OAuth1RequestToken requestToken, - String oauthVerifier) { + protected OAuthRequest prepareAccessTokenRequest(OAuth1RequestToken requestToken, String oauthVerifier) { + final OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint()); final OAuthConfig config = getConfig(); request.addOAuthParameter(OAuthConstants.TOKEN, requestToken.getToken()); request.addOAuthParameter(OAuthConstants.VERIFIER, oauthVerifier); config.log("setting token to: " + requestToken + " and verifier to: " + oauthVerifier); addOAuthParams(request, requestToken.getTokenSecret()); appendSignature(request); + return request; } @Override - public void signRequest(OAuth1AccessToken token, AbstractRequest request) { + public void signRequest(OAuth1AccessToken token, OAuthRequest request) { final OAuthConfig config = getConfig(); config.log("signing request: " + request.getCompleteUrl()); @@ -162,7 +165,7 @@ public String getAuthorizationUrl(OAuth1RequestToken requestToken) { return api.getAuthorizationUrl(requestToken); } - private String getSignature(AbstractRequest request, String tokenSecret) { + private String getSignature(OAuthRequest request, String tokenSecret) { final OAuthConfig config = getConfig(); config.log("generating signature..."); config.log("using base64 encoder: " + Base64Encoder.type()); @@ -174,7 +177,7 @@ private String getSignature(AbstractRequest request, String tokenSecret) { return signature; } - private void appendSignature(AbstractRequest request) { + private void appendSignature(OAuthRequest request) { final OAuthConfig config = getConfig(); switch (config.getSignatureType()) { case Header: 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 d33c6fd07..c1ec7fc44 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 @@ -5,14 +5,12 @@ import java.nio.charset.Charset; import java.util.concurrent.Future; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.model.AbstractRequest; import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuth2Authorization; import com.github.scribejava.core.model.OAuthAsyncRequestCallback; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.OAuthRequest; -import com.github.scribejava.core.model.OAuthRequestAsync; import com.github.scribejava.core.model.Response; import java.util.Map; import java.util.concurrent.ExecutionException; @@ -33,17 +31,22 @@ public OAuth20Service(DefaultApi20 api, OAuthConfig config) { this.api = api; } - //sync version, protected to facilitate mocking + //protected to facilitate mocking protected OAuth2AccessToken sendAccessTokenRequestSync(OAuthRequest request) throws IOException, InterruptedException, ExecutionException { return api.getAccessTokenExtractor().extract(execute(request)); } - //async version, protected to facilitate mocking - protected Future sendAccessTokenRequestAsync(OAuthRequestAsync request, + //protected to facilitate mocking + protected Future sendAccessTokenRequestAsync(OAuthRequest request) { + return sendAccessTokenRequestAsync(request, null); + } + + //protected to facilitate mocking + protected Future sendAccessTokenRequestAsync(OAuthRequest request, OAuthAsyncRequestCallback callback) { - return execute(request, callback, new OAuthRequestAsync.ResponseConverter() { + return execute(request, callback, new OAuthRequest.ResponseConverter() { @Override public OAuth2AccessToken convert(Response response) throws IOException { return getApi().getAccessTokenExtractor().extract(response); @@ -53,12 +56,15 @@ public OAuth2AccessToken convert(Response response) throws IOException { public final OAuth2AccessToken getAccessToken(String code) throws IOException, InterruptedException, ExecutionException { - final OAuthRequest request = createAccessTokenRequest(code, - new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint())); + final OAuthRequest request = createAccessTokenRequest(code); return sendAccessTokenRequestSync(request); } + public final Future getAccessTokenAsync(String code) { + return getAccessTokenAsync(code, null); + } + /** * Start the request to retrieve the access token. The optionally provided callback will be called with the Token * when it is available. @@ -69,13 +75,13 @@ public final OAuth2AccessToken getAccessToken(String code) */ public final Future getAccessTokenAsync(String code, OAuthAsyncRequestCallback callback) { - final OAuthRequestAsync request = createAccessTokenRequest(code, - new OAuthRequestAsync(api.getAccessTokenVerb(), api.getAccessTokenEndpoint())); + final OAuthRequest request = createAccessTokenRequest(code); return sendAccessTokenRequestAsync(request, callback); } - protected T createAccessTokenRequest(String code, T request) { + protected OAuthRequest createAccessTokenRequest(String code) { + final OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint()); final OAuthConfig config = getConfig(); request.addParameter(OAuthConstants.CLIENT_ID, config.getApiKey()); request.addParameter(OAuthConstants.CLIENT_SECRET, config.getApiSecret()); @@ -91,24 +97,27 @@ protected T createAccessTokenRequest(String code, T public final OAuth2AccessToken refreshAccessToken(String refreshToken) throws IOException, InterruptedException, ExecutionException { - final OAuthRequest request = createRefreshTokenRequest(refreshToken, - new OAuthRequest(api.getAccessTokenVerb(), api.getRefreshTokenEndpoint())); + final OAuthRequest request = createRefreshTokenRequest(refreshToken); return sendAccessTokenRequestSync(request); } + public final Future refreshAccessTokenAsync(String refreshToken) { + return refreshAccessTokenAsync(refreshToken, null); + } + public final Future refreshAccessTokenAsync(String refreshToken, OAuthAsyncRequestCallback callback) { - final OAuthRequestAsync request = createRefreshTokenRequest(refreshToken, - new OAuthRequestAsync(api.getAccessTokenVerb(), api.getRefreshTokenEndpoint())); + final OAuthRequest request = createRefreshTokenRequest(refreshToken); return sendAccessTokenRequestAsync(request, callback); } - protected T createRefreshTokenRequest(String refreshToken, T request) { + protected OAuthRequest createRefreshTokenRequest(String refreshToken) { if (refreshToken == null || refreshToken.isEmpty()) { throw new IllegalArgumentException("The refreshToken cannot be null or empty"); } + final OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getRefreshTokenEndpoint()); final OAuthConfig config = getConfig(); request.addParameter(OAuthConstants.CLIENT_ID, config.getApiKey()); request.addParameter(OAuthConstants.CLIENT_SECRET, config.getApiSecret()); @@ -119,12 +128,15 @@ protected T createRefreshTokenRequest(String refresh public final OAuth2AccessToken getAccessTokenPasswordGrant(String uname, String password) throws IOException, InterruptedException, ExecutionException { - final OAuthRequest request = createAccessTokenPasswordGrantRequest(uname, password, - new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint())); + final OAuthRequest request = createAccessTokenPasswordGrantRequest(uname, password); return sendAccessTokenRequestSync(request); } + public final Future getAccessTokenPasswordGrantAsync(String uname, String password) { + return getAccessTokenPasswordGrantAsync(uname, password, null); + } + /** * Request Access Token Password Grant async version * @@ -135,14 +147,13 @@ public final OAuth2AccessToken getAccessTokenPasswordGrant(String uname, String */ public final Future getAccessTokenPasswordGrantAsync(String uname, String password, OAuthAsyncRequestCallback callback) { - final OAuthRequestAsync request = createAccessTokenPasswordGrantRequest(uname, password, - new OAuthRequestAsync(api.getAccessTokenVerb(), api.getAccessTokenEndpoint())); + final OAuthRequest request = createAccessTokenPasswordGrantRequest(uname, password); return sendAccessTokenRequestAsync(request, callback); } - protected T createAccessTokenPasswordGrantRequest(String username, String password, - T request) { + protected OAuthRequest createAccessTokenPasswordGrantRequest(String username, String password) { + final OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint()); final OAuthConfig config = getConfig(); request.addParameter(OAuthConstants.USERNAME, username); request.addParameter(OAuthConstants.PASSWORD, password); @@ -175,7 +186,7 @@ public String getVersion() { } @Override - public void signRequest(OAuth2AccessToken accessToken, AbstractRequest request) { + public void signRequest(OAuth2AccessToken accessToken, OAuthRequest request) { request.addQuerystringParameter(OAuthConstants.ACCESS_TOKEN, accessToken.getAccessToken()); } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java index 251c2f9fe..c17c3b7dc 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java @@ -1,7 +1,6 @@ package com.github.scribejava.core.oauth; import com.github.scribejava.core.httpclient.HttpClientProvider; -import com.github.scribejava.core.model.AbstractRequest; import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.httpclient.HttpClientConfig; import com.github.scribejava.core.httpclient.jdk.JDKHttpClient; @@ -9,7 +8,6 @@ import com.github.scribejava.core.model.OAuthAsyncRequestCallback; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthRequest; -import com.github.scribejava.core.model.OAuthRequestAsync; import com.github.scribejava.core.model.Response; import com.github.scribejava.core.model.Token; import java.io.File; @@ -25,7 +23,7 @@ * A facade responsible for the retrieval of request and access tokens and for the signing of HTTP requests. * @param type of token used to sign the request */ -public abstract class OAuthService { +public abstract class OAuthService implements AutoCloseable { private final OAuthConfig config; private final HttpClient httpClient; @@ -52,7 +50,18 @@ private static HttpClient getClient(HttpClientConfig config) { return null; } + /** + * + * @throws IOException IOException + * @deprecated use {@link #close() } + */ + @Deprecated public void closeAsyncClient() throws IOException { + close(); + } + + @Override + public void close() throws IOException { httpClient.close(); } @@ -67,10 +76,10 @@ public OAuthConfig getConfig() { */ public abstract String getVersion(); - public abstract void signRequest(T token, AbstractRequest request); + public abstract void signRequest(T token, OAuthRequest request); - public Future execute(OAuthRequestAsync request, OAuthAsyncRequestCallback callback, - OAuthRequestAsync.ResponseConverter converter) { + public Future execute(OAuthRequest request, OAuthAsyncRequestCallback callback, + OAuthRequest.ResponseConverter converter) { final File filePayload = request.getFilePayload(); if (filePayload != null) { @@ -85,11 +94,11 @@ public Future execute(OAuthRequestAsync request, OAuthAsyncRequestCallbac } } - public Future execute(OAuthRequestAsync request, OAuthAsyncRequestCallback callback) { + public Future execute(OAuthRequest request, OAuthAsyncRequestCallback callback) { return execute(request, callback, null); } - public Response execute(OAuthRequestAsync request) throws InterruptedException, ExecutionException, IOException { + public Response execute(OAuthRequest request) throws InterruptedException, ExecutionException, IOException { final File filePayload = request.getFilePayload(); if (filePayload != null) { return httpClient.execute(config.getUserAgent(), request.getHeaders(), request.getVerb(), @@ -102,21 +111,4 @@ public Response execute(OAuthRequestAsync request) throws InterruptedException, request.getCompleteUrl(), request.getByteArrayPayload()); } } - - public Response execute(OAuthRequest request) throws InterruptedException, ExecutionException, IOException { - final JDKHttpClient jdkHttpClient = httpClient instanceof JDKHttpClient ? (JDKHttpClient) httpClient - : new JDKHttpClient(JDKHttpClientConfig.defaultConfig()); - - final File filePayload = request.getFilePayload(); - if (filePayload != null) { - return jdkHttpClient.execute(config.getUserAgent(), request.getHeaders(), request.getVerb(), - request.getCompleteUrl(), filePayload); - } else if (request.getStringPayload() != null) { - return jdkHttpClient.execute(config.getUserAgent(), request.getHeaders(), request.getVerb(), - request.getCompleteUrl(), request.getStringPayload()); - } else { - return jdkHttpClient.execute(config.getUserAgent(), request.getHeaders(), request.getVerb(), - request.getCompleteUrl(), request.getByteArrayPayload()); - } - } } diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceUnit.java b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceUnit.java index 4d75c5ece..8a49c0ee1 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceUnit.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceUnit.java @@ -1,13 +1,11 @@ package com.github.scribejava.core.oauth; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.model.AbstractRequest; import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthAsyncRequestCallback; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.OAuthRequest; -import com.github.scribejava.core.model.OAuthRequestAsync; import com.github.scribejava.core.model.Parameter; import com.google.gson.Gson; @@ -30,7 +28,7 @@ protected OAuth2AccessToken sendAccessTokenRequestSync(OAuthRequest request) { return new OAuth2AccessToken(TOKEN, prepareRawResponse(request)); } - private String prepareRawResponse(T request) { + private String prepareRawResponse(OAuthRequest request) { final Gson json = new Gson(); final Map response = new HashMap<>(); response.put(OAuthConstants.ACCESS_TOKEN, TOKEN); @@ -48,7 +46,7 @@ private String prepareRawResponse(T request) { } @Override - protected Future sendAccessTokenRequestAsync(OAuthRequestAsync request, + protected Future sendAccessTokenRequestAsync(OAuthRequest request, OAuthAsyncRequestCallback callback) { final OAuth2AccessToken accessToken = new OAuth2AccessToken(TOKEN, prepareRawResponse(request)); 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 f547779a1..a4962b2b5 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 @@ -3,7 +3,7 @@ import com.github.scribejava.core.httpclient.AbstractAsyncOnlyHttpClient; import com.github.scribejava.core.model.OAuthAsyncRequestCallback; import com.github.scribejava.core.model.OAuthConstants; -import com.github.scribejava.core.model.OAuthRequestAsync; +import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Verb; import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.DefaultAsyncHttpClient; @@ -36,31 +36,28 @@ public void close() throws IOException { @Override public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, - byte[] bodyContents, OAuthAsyncRequestCallback callback, - OAuthRequestAsync.ResponseConverter converter) { + byte[] bodyContents, OAuthAsyncRequestCallback callback, OAuthRequest.ResponseConverter converter) { return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, BodySetter.BYTE_ARRAY, bodyContents, callback, converter); } @Override public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, - String bodyContents, OAuthAsyncRequestCallback callback, - OAuthRequestAsync.ResponseConverter converter) { + String bodyContents, OAuthAsyncRequestCallback callback, OAuthRequest.ResponseConverter converter) { 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, - OAuthRequestAsync.ResponseConverter converter) { + File bodyContents, OAuthAsyncRequestCallback callback, OAuthRequest.ResponseConverter converter) { return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, BodySetter.FILE, bodyContents, callback, converter); } private Future doExecuteAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, BodySetter bodySetter, Object bodyContents, OAuthAsyncRequestCallback callback, - OAuthRequestAsync.ResponseConverter converter) { + OAuthRequest.ResponseConverter converter) { BoundRequestBuilder boundRequestBuilder; switch (httpVerb) { case GET: diff --git a/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/OAuthAsyncCompletionHandler.java b/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/OAuthAsyncCompletionHandler.java index 003821b2f..856cbcf68 100644 --- a/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/OAuthAsyncCompletionHandler.java +++ b/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/OAuthAsyncCompletionHandler.java @@ -1,7 +1,7 @@ package com.github.scribejava.httpclient.ahc; import com.github.scribejava.core.model.OAuthAsyncRequestCallback; -import com.github.scribejava.core.model.OAuthRequestAsync; +import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; import io.netty.handler.codec.http.HttpHeaders; import java.io.IOException; @@ -12,10 +12,10 @@ public class OAuthAsyncCompletionHandler extends AsyncCompletionHandler { private final OAuthAsyncRequestCallback callback; - private final OAuthRequestAsync.ResponseConverter converter; + private final OAuthRequest.ResponseConverter converter; public OAuthAsyncCompletionHandler(OAuthAsyncRequestCallback callback, - OAuthRequestAsync.ResponseConverter converter) { + OAuthRequest.ResponseConverter converter) { this.callback = callback; this.converter = converter; } diff --git a/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/NingHttpClient.java b/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/NingHttpClient.java index 6c4acde60..a9fcb0a81 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 @@ -3,7 +3,7 @@ import com.github.scribejava.core.httpclient.AbstractAsyncOnlyHttpClient; import com.github.scribejava.core.model.OAuthAsyncRequestCallback; import com.github.scribejava.core.model.OAuthConstants; -import com.github.scribejava.core.model.OAuthRequestAsync; +import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Verb; import com.ning.http.client.AsyncHttpClient; @@ -41,8 +41,7 @@ public void close() { @Override public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, - byte[] bodyContents, OAuthAsyncRequestCallback callback, - OAuthRequestAsync.ResponseConverter converter) { + byte[] bodyContents, OAuthAsyncRequestCallback callback, OAuthRequest.ResponseConverter converter) { return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, BodySetter.BYTE_ARRAY, bodyContents, callback, converter); @@ -50,8 +49,7 @@ public Future executeAsync(String userAgent, Map headers, @Override public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, - String bodyContents, OAuthAsyncRequestCallback callback, - OAuthRequestAsync.ResponseConverter converter) { + String bodyContents, OAuthAsyncRequestCallback callback, OAuthRequest.ResponseConverter converter) { return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, BodySetter.STRING, bodyContents, callback, converter); @@ -59,8 +57,7 @@ public Future executeAsync(String userAgent, Map headers, @Override public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, - File bodyContents, OAuthAsyncRequestCallback callback, - OAuthRequestAsync.ResponseConverter converter) { + File bodyContents, OAuthAsyncRequestCallback callback, OAuthRequest.ResponseConverter converter) { return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, BodySetter.FILE, bodyContents, callback, converter); @@ -68,7 +65,7 @@ public Future executeAsync(String userAgent, Map headers, private Future doExecuteAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, BodySetter bodySetter, Object bodyContents, OAuthAsyncRequestCallback callback, - OAuthRequestAsync.ResponseConverter converter) { + OAuthRequest.ResponseConverter converter) { AsyncHttpClient.BoundRequestBuilder boundRequestBuilder; switch (httpVerb) { case GET: diff --git a/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/OAuthAsyncCompletionHandler.java b/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/OAuthAsyncCompletionHandler.java index 1448b60c3..5ce461b1b 100644 --- a/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/OAuthAsyncCompletionHandler.java +++ b/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/OAuthAsyncCompletionHandler.java @@ -1,7 +1,7 @@ package com.github.scribejava.httpclient.ning; import com.github.scribejava.core.model.OAuthAsyncRequestCallback; -import com.github.scribejava.core.model.OAuthRequestAsync; +import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; import com.ning.http.client.AsyncCompletionHandler; import com.ning.http.client.FluentCaseInsensitiveStringsMap; @@ -13,10 +13,10 @@ public class OAuthAsyncCompletionHandler extends AsyncCompletionHandler { private final OAuthAsyncRequestCallback callback; - private final OAuthRequestAsync.ResponseConverter converter; + private final OAuthRequest.ResponseConverter converter; public OAuthAsyncCompletionHandler(OAuthAsyncRequestCallback callback, - OAuthRequestAsync.ResponseConverter converter) { + OAuthRequest.ResponseConverter converter) { this.callback = callback; this.converter = converter; } diff --git a/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OAuthAsyncCompletionHandler.java b/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OAuthAsyncCompletionHandler.java index 8481b163f..af59abbb5 100644 --- a/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OAuthAsyncCompletionHandler.java +++ b/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OAuthAsyncCompletionHandler.java @@ -1,7 +1,7 @@ package com.github.scribejava.httpclient.okhttp; import com.github.scribejava.core.model.OAuthAsyncRequestCallback; -import com.github.scribejava.core.model.OAuthRequestAsync; +import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; import okhttp3.Call; import okhttp3.Callback; @@ -11,11 +11,11 @@ class OAuthAsyncCompletionHandler implements Callback { private final OAuthAsyncRequestCallback callback; - private final OAuthRequestAsync.ResponseConverter converter; + private final OAuthRequest.ResponseConverter converter; private final OkHttpFuture okHttpFuture; - OAuthAsyncCompletionHandler(OAuthAsyncRequestCallback callback, - OAuthRequestAsync.ResponseConverter converter, OkHttpFuture okHttpFuture) { + OAuthAsyncCompletionHandler(OAuthAsyncRequestCallback callback, OAuthRequest.ResponseConverter converter, + OkHttpFuture okHttpFuture) { this.callback = callback; this.converter = converter; this.okHttpFuture = okHttpFuture; diff --git a/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java b/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java index 80c0c4ddc..1199c87de 100644 --- a/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java +++ b/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java @@ -3,7 +3,7 @@ import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.model.OAuthAsyncRequestCallback; import com.github.scribejava.core.model.OAuthConstants; -import com.github.scribejava.core.model.OAuthRequestAsync; +import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Verb; import okhttp3.Call; import okhttp3.MediaType; @@ -50,31 +50,28 @@ public void close() throws IOException { @Override public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, - byte[] bodyContents, OAuthAsyncRequestCallback callback, - OAuthRequestAsync.ResponseConverter converter) { + byte[] bodyContents, OAuthAsyncRequestCallback callback, OAuthRequest.ResponseConverter converter) { return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, BodyType.BYTE_ARRAY, bodyContents, callback, converter); } @Override public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, - String bodyContents, OAuthAsyncRequestCallback callback, - OAuthRequestAsync.ResponseConverter converter) { + String bodyContents, OAuthAsyncRequestCallback callback, OAuthRequest.ResponseConverter converter) { return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, BodyType.STRING, bodyContents, callback, converter); } @Override public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, - File bodyContents, OAuthAsyncRequestCallback callback, - OAuthRequestAsync.ResponseConverter converter) { + File bodyContents, OAuthAsyncRequestCallback callback, OAuthRequest.ResponseConverter converter) { return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, BodyType.FILE, bodyContents, callback, converter); } private Future doExecuteAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, BodyType bodyType, Object bodyContents, OAuthAsyncRequestCallback callback, - OAuthRequestAsync.ResponseConverter converter) { + OAuthRequest.ResponseConverter converter) { final Call call = createCall(userAgent, headers, httpVerb, completeUrl, bodyType, bodyContents); final OkHttpFuture okHttpFuture = new OkHttpFuture<>(call); call.enqueue(new OAuthAsyncCompletionHandler<>(callback, converter, okHttpFuture)); diff --git a/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClientTest.java b/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClientTest.java index 9770f403a..92ef44423 100644 --- a/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClientTest.java +++ b/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClientTest.java @@ -2,7 +2,7 @@ import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.model.OAuthConfig; -import com.github.scribejava.core.model.OAuthRequestAsync; +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; @@ -41,7 +41,7 @@ public void shouldSendGetRequest() throws Exception { final HttpUrl baseUrl = server.url("/testUrl"); - final OAuthRequestAsync request = new OAuthRequestAsync(Verb.GET, baseUrl.toString()); + final OAuthRequest request = new OAuthRequest(Verb.GET, baseUrl.toString()); final Response response = oAuthService.execute(request, null).get(30, TimeUnit.SECONDS); assertEquals(expectedResponseBody, response.getBody()); @@ -65,7 +65,7 @@ public void shouldSendPostRequest() throws Exception { final HttpUrl baseUrl = server.url("/testUrl"); // request with body - OAuthRequestAsync request = new OAuthRequestAsync(Verb.POST, baseUrl.toString()); + OAuthRequest request = new OAuthRequest(Verb.POST, baseUrl.toString()); request.setPayload(expectedRequestBody); Response response = oAuthService.execute(request, null).get(30, TimeUnit.SECONDS); @@ -77,7 +77,7 @@ public void shouldSendPostRequest() throws Exception { // request with empty body - request = new OAuthRequestAsync(Verb.POST, baseUrl.toString()); + request = new OAuthRequest(Verb.POST, baseUrl.toString()); response = oAuthService.execute(request, null).get(30, TimeUnit.SECONDS); assertEquals(expectedResponseBody, response.getBody()); @@ -99,7 +99,7 @@ public void shouldReadResponseStream() throws Exception { final HttpUrl baseUrl = server.url("/testUrl"); - final OAuthRequestAsync request = new OAuthRequestAsync(Verb.GET, baseUrl.toString()); + final OAuthRequest request = new OAuthRequest(Verb.GET, baseUrl.toString()); final Response response = oAuthService.execute(request, null).get(30, TimeUnit.SECONDS); assertEquals(expectedResponseBody, StreamUtils.getStreamContents(response.getStream())); From a013e330b6c672aa45e33c88c0a7eefb746a3e16 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 11 Jan 2017 16:51:52 +0300 Subject: [PATCH 346/882] update checkstyle, fix some violations, update changelog --- changelog | 2 +- pom.xml | 2 +- .../apis/examples/TheThingsNetworkV1StagingExample.java | 2 +- .../apis/examples/TheThingsNetworkV2PreviewExample.java | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/changelog b/changelog index d3a832068..3806d5822 100644 --- a/changelog +++ b/changelog @@ -1,5 +1,5 @@ [SNAPSHOT] - * Remove OAuthRequestAsync, just OAuthRequest. Request should know about sync vs async + * Remove OAuthRequestAsync, just OAuthRequest. Request should know about sync vs async. Move default Http engine to JDKHttpClient. [3.4.1] * Drop deprecated methods diff --git a/pom.xml b/pom.xml index 8277cd1b6..94bd2f763 100644 --- a/pom.xml +++ b/pom.xml @@ -132,7 +132,7 @@ com.puppycrawl.tools checkstyle - 7.3 + 7.4
diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV1StagingExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV1StagingExample.java index 50fbef28e..44aee4c74 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV1StagingExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV1StagingExample.java @@ -90,7 +90,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println(); System.out.println(response.getCode()); - if(response.getCode()==401) { + if (response.getCode() == 401) { System.out.println("Not authorised: "+response.getBody()); } else { System.out.println("You should see a JSON array of your registered applications:"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV2PreviewExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV2PreviewExample.java index 38bd2fb5f..c1c3eb9a6 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV2PreviewExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV2PreviewExample.java @@ -87,7 +87,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println(); System.out.println(response.getCode()); - if(response.getCode()==401) { + if (response.getCode() == 401) { System.out.println("Not authorised: "+response.getBody()); } else { System.out.println("You should see a JSON array of your registered applications:"); From 78cb95ccb6c92499265298bf8d9cb6079ae36775 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 11 Jan 2017 17:38:44 +0300 Subject: [PATCH 347/882] introduce SignatureType for OAuth2.0 to implement Bearer signing for the requests --- changelog | 1 + .../com/github/scribejava/apis/BoxApi20.java | 5 ++++ .../scribejava/apis/DoktornaraboteApi.java | 8 ----- .../github/scribejava/apis/FacebookApi.java | 6 ++++ .../scribejava/apis/Foursquare2Api.java | 6 ++++ .../com/github/scribejava/apis/GeniusApi.java | 8 ----- .../com/github/scribejava/apis/GitHubApi.java | 6 ++++ .../github/scribejava/apis/GoogleApi20.java | 6 ++++ .../com/github/scribejava/apis/HHApi.java | 9 ------ .../github/scribejava/apis/KaixinApi20.java | 6 ++++ .../github/scribejava/apis/LinkedInApi20.java | 6 ++++ .../com/github/scribejava/apis/LiveApi.java | 6 ++++ .../com/github/scribejava/apis/MisfitApi.java | 6 ++++ .../com/github/scribejava/apis/NaverApi.java | 6 ++++ .../github/scribejava/apis/PinterestApi.java | 6 ++++ .../com/github/scribejava/apis/RenrenApi.java | 6 ++++ .../scribejava/apis/SinaWeiboApi20.java | 6 ++++ .../scribejava/apis/StackExchangeApi.java | 6 ++++ .../com/github/scribejava/apis/ViadeoApi.java | 6 ++++ .../github/scribejava/apis/VkontakteApi.java | 6 ++++ .../DoktornaraboteOAuthServiceImpl.java | 19 ------------ .../apis/service/GeniusOAuthServiceImpl.java | 19 ------------ .../apis/service/HHOAuthServiceImpl.java | 19 ------------ .../apis/examples/SalesforceExample.java | 1 - .../examples/SalesforceNingAsyncExample.java | 1 - .../TheThingsNetworkV1StagingExample.java | 5 ---- .../TheThingsNetworkV2PreviewExample.java | 5 ---- .../core/builder/api/DefaultApi20.java | 4 +++ .../core/builder/api/SignatureType.java | 30 +++++++++++++++++++ .../core/model/OAuthRequestAsync.java | 3 ++ .../scribejava/core/oauth/OAuth20Service.java | 2 +- .../scribejava/core/oauth/OAuth20ApiUnit.java | 6 ++++ 32 files changed, 140 insertions(+), 95 deletions(-) delete mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/service/DoktornaraboteOAuthServiceImpl.java delete mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/service/GeniusOAuthServiceImpl.java delete mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/service/HHOAuthServiceImpl.java create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/builder/api/SignatureType.java diff --git a/changelog b/changelog index 3806d5822..bd889038c 100644 --- a/changelog +++ b/changelog @@ -1,5 +1,6 @@ [SNAPSHOT] * 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 [3.4.1] * Drop deprecated methods diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/BoxApi20.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/BoxApi20.java index 79d75180c..c6613b62e 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/BoxApi20.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/BoxApi20.java @@ -1,6 +1,7 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.builder.api.SignatureType; /** * Box.com Api @@ -29,4 +30,8 @@ protected String getAuthorizationBaseUrl() { return "https://account.box.com/api/oauth2/authorize"; } + @Override + public SignatureType getSignatureType() { + return SignatureType.BEARER_URI_QUERY_PARAMETER; + } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/DoktornaraboteApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/DoktornaraboteApi.java index 9cb308be3..1fcac7108 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/DoktornaraboteApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/DoktornaraboteApi.java @@ -1,9 +1,6 @@ package com.github.scribejava.apis; -import com.github.scribejava.apis.service.DoktornaraboteOAuthServiceImpl; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.model.OAuthConfig; -import com.github.scribejava.core.oauth.OAuth20Service; public class DoktornaraboteApi extends DefaultApi20 { @@ -27,9 +24,4 @@ public String getAccessTokenEndpoint() { protected String getAuthorizationBaseUrl() { return "https://auth.doktornarabote.ru/OAuth/Authorize"; } - - @Override - public OAuth20Service createService(OAuthConfig config) { - return new DoktornaraboteOAuthServiceImpl(this, config); - } } 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 1f00e931c..c5320708d 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java @@ -1,6 +1,7 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.builder.api.SignatureType; import com.github.scribejava.core.model.Verb; /** @@ -39,4 +40,9 @@ public String getRefreshTokenEndpoint() { protected String getAuthorizationBaseUrl() { return "https://www.facebook.com/v2.8/dialog/oauth"; } + + @Override + public SignatureType getSignatureType() { + return SignatureType.BEARER_URI_QUERY_PARAMETER; + } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/Foursquare2Api.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/Foursquare2Api.java index cb574618d..71fb94768 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/Foursquare2Api.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/Foursquare2Api.java @@ -1,6 +1,7 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.builder.api.SignatureType; import com.github.scribejava.core.model.Verb; public class Foursquare2Api extends DefaultApi20 { @@ -30,4 +31,9 @@ public String getAccessTokenEndpoint() { protected String getAuthorizationBaseUrl() { return "https://foursquare.com/oauth2/authenticate"; } + + @Override + public SignatureType getSignatureType() { + return SignatureType.BEARER_URI_QUERY_PARAMETER; + } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/GeniusApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/GeniusApi.java index 14570697c..03eae859c 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/GeniusApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/GeniusApi.java @@ -1,9 +1,6 @@ package com.github.scribejava.apis; -import com.github.scribejava.apis.service.GeniusOAuthServiceImpl; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.model.OAuthConfig; -import com.github.scribejava.core.oauth.OAuth20Service; public class GeniusApi extends DefaultApi20 { @@ -28,9 +25,4 @@ public String getAccessTokenEndpoint() { protected String getAuthorizationBaseUrl() { return "https://api.genius.com/oauth/authorize"; } - - @Override - public OAuth20Service createService(OAuthConfig config) { - return new GeniusOAuthServiceImpl(this, config); - } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/GitHubApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/GitHubApi.java index ada35c1b3..7e10fefc3 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/GitHubApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/GitHubApi.java @@ -1,6 +1,7 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.builder.api.SignatureType; import com.github.scribejava.core.extractors.OAuth2AccessTokenExtractor; import com.github.scribejava.core.extractors.TokenExtractor; import com.github.scribejava.core.model.OAuth2AccessToken; @@ -38,4 +39,9 @@ protected String getAuthorizationBaseUrl() { public TokenExtractor getAccessTokenExtractor() { return OAuth2AccessTokenExtractor.instance(); } + + @Override + public SignatureType getSignatureType() { + return SignatureType.BEARER_URI_QUERY_PARAMETER; + } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/GoogleApi20.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/GoogleApi20.java index 157753f6d..a9394dfee 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/GoogleApi20.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/GoogleApi20.java @@ -2,6 +2,7 @@ import com.github.scribejava.apis.google.GoogleJsonTokenExtractor; import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.builder.api.SignatureType; import com.github.scribejava.core.extractors.TokenExtractor; import com.github.scribejava.core.model.OAuth2AccessToken; @@ -32,4 +33,9 @@ protected String getAuthorizationBaseUrl() { public TokenExtractor getAccessTokenExtractor() { return GoogleJsonTokenExtractor.instance(); } + + @Override + public SignatureType getSignatureType() { + return SignatureType.BEARER_URI_QUERY_PARAMETER; + } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/HHApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/HHApi.java index acb239fa5..2a8a8aa12 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/HHApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/HHApi.java @@ -1,10 +1,6 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.model.OAuthConfig; - -import com.github.scribejava.apis.service.HHOAuthServiceImpl; -import com.github.scribejava.core.oauth.OAuth20Service; public class HHApi extends DefaultApi20 { @@ -28,9 +24,4 @@ public String getAccessTokenEndpoint() { protected String getAuthorizationBaseUrl() { return "https://hh.ru/oauth/authorize"; } - - @Override - public OAuth20Service createService(OAuthConfig config) { - return new HHOAuthServiceImpl(this, config); - } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/KaixinApi20.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/KaixinApi20.java index cd8917fd5..fdf8f67af 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/KaixinApi20.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/KaixinApi20.java @@ -1,6 +1,7 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.builder.api.SignatureType; import com.github.scribejava.core.model.Verb; /** @@ -33,4 +34,9 @@ public String getAccessTokenEndpoint() { protected String getAuthorizationBaseUrl() { return "http://api.kaixin001.com/oauth2/authorize"; } + + @Override + public SignatureType getSignatureType() { + return SignatureType.BEARER_URI_QUERY_PARAMETER; + } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi20.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi20.java index 88dc30e7f..2ba6259f3 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi20.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi20.java @@ -2,6 +2,7 @@ import com.github.scribejava.apis.service.LinkedIn20ServiceImpl; import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.builder.api.SignatureType; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.oauth.OAuth20Service; @@ -32,4 +33,9 @@ protected String getAuthorizationBaseUrl() { public OAuth20Service createService(OAuthConfig config) { return new LinkedIn20ServiceImpl(this, config); } + + @Override + public SignatureType getSignatureType() { + return SignatureType.BEARER_URI_QUERY_PARAMETER; + } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/LiveApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/LiveApi.java index ee6c6ba12..da34cab8f 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/LiveApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/LiveApi.java @@ -1,6 +1,7 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.builder.api.SignatureType; import com.github.scribejava.core.model.Verb; public class LiveApi extends DefaultApi20 { @@ -30,4 +31,9 @@ public String getAccessTokenEndpoint() { protected String getAuthorizationBaseUrl() { return "https://oauth.live.com/authorize"; } + + @Override + public SignatureType getSignatureType() { + return SignatureType.BEARER_URI_QUERY_PARAMETER; + } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/MisfitApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/MisfitApi.java index f6d2fc706..54559e6da 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/MisfitApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/MisfitApi.java @@ -1,6 +1,7 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.builder.api.SignatureType; public class MisfitApi extends DefaultApi20 { @@ -25,4 +26,9 @@ public String getAccessTokenEndpoint() { protected String getAuthorizationBaseUrl() { return "https://api.misfitwearables.com/auth/dialog/authorize"; } + + @Override + public SignatureType getSignatureType() { + return SignatureType.BEARER_URI_QUERY_PARAMETER; + } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/NaverApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/NaverApi.java index 514b17b96..42056e7eb 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/NaverApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/NaverApi.java @@ -1,6 +1,7 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.builder.api.SignatureType; public class NaverApi extends DefaultApi20 { protected NaverApi() { @@ -26,4 +27,9 @@ public String getAccessTokenEndpoint() { protected String getAuthorizationBaseUrl() { return "https://nid.naver.com/oauth2.0/authorize"; } + + @Override + public SignatureType getSignatureType() { + return SignatureType.BEARER_URI_QUERY_PARAMETER; + } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/PinterestApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/PinterestApi.java index 0f44d7b12..2940f0a15 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/PinterestApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/PinterestApi.java @@ -1,6 +1,7 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.builder.api.SignatureType; public class PinterestApi extends DefaultApi20 { @@ -24,4 +25,9 @@ public String getAccessTokenEndpoint() { protected String getAuthorizationBaseUrl() { return "https://api.pinterest.com/oauth"; } + + @Override + public SignatureType getSignatureType() { + return SignatureType.BEARER_URI_QUERY_PARAMETER; + } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/RenrenApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/RenrenApi.java index da10760c3..08fde329e 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/RenrenApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/RenrenApi.java @@ -1,6 +1,7 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.builder.api.SignatureType; import com.github.scribejava.core.model.Verb; /** @@ -33,4 +34,9 @@ public String getAccessTokenEndpoint() { protected String getAuthorizationBaseUrl() { return "https://graph.renren.com/oauth/authorize"; } + + @Override + public SignatureType getSignatureType() { + return SignatureType.BEARER_URI_QUERY_PARAMETER; + } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/SinaWeiboApi20.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/SinaWeiboApi20.java index 1799806f1..64d3b4950 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/SinaWeiboApi20.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/SinaWeiboApi20.java @@ -1,6 +1,7 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.builder.api.SignatureType; /** * SinaWeibo OAuth 2.0 api. @@ -27,4 +28,9 @@ public String getAccessTokenEndpoint() { protected String getAuthorizationBaseUrl() { return "https://api.weibo.com/oauth2/authorize"; } + + @Override + public SignatureType getSignatureType() { + return SignatureType.BEARER_URI_QUERY_PARAMETER; + } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/StackExchangeApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/StackExchangeApi.java index c6dfcb101..b2f6f0db7 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/StackExchangeApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/StackExchangeApi.java @@ -1,6 +1,7 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.builder.api.SignatureType; import com.github.scribejava.core.extractors.OAuth2AccessTokenExtractor; import com.github.scribejava.core.extractors.TokenExtractor; import com.github.scribejava.core.model.OAuth2AccessToken; @@ -36,4 +37,9 @@ protected String getAuthorizationBaseUrl() { public TokenExtractor getAccessTokenExtractor() { return OAuth2AccessTokenExtractor.instance(); } + + @Override + public SignatureType getSignatureType() { + return SignatureType.BEARER_URI_QUERY_PARAMETER; + } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/ViadeoApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/ViadeoApi.java index e3143b5b4..bc1833563 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/ViadeoApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/ViadeoApi.java @@ -1,6 +1,7 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.builder.api.SignatureType; import com.github.scribejava.core.model.Verb; public class ViadeoApi extends DefaultApi20 { @@ -30,4 +31,9 @@ public String getAccessTokenEndpoint() { protected String getAuthorizationBaseUrl() { return "https://secure.viadeo.com/oauth-provider/authorize2"; } + + @Override + public SignatureType getSignatureType() { + return SignatureType.BEARER_URI_QUERY_PARAMETER; + } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/VkontakteApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/VkontakteApi.java index 7d440d275..87217c4b8 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/VkontakteApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/VkontakteApi.java @@ -1,6 +1,7 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.builder.api.SignatureType; import com.github.scribejava.core.model.Verb; public class VkontakteApi extends DefaultApi20 { @@ -30,4 +31,9 @@ public String getAccessTokenEndpoint() { protected String getAuthorizationBaseUrl() { return "https://oauth.vk.com/authorize"; } + + @Override + public SignatureType getSignatureType() { + return SignatureType.BEARER_URI_QUERY_PARAMETER; + } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/DoktornaraboteOAuthServiceImpl.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/DoktornaraboteOAuthServiceImpl.java deleted file mode 100644 index 80c6cde48..000000000 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/DoktornaraboteOAuthServiceImpl.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.github.scribejava.apis.service; - -import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.model.OAuth2AccessToken; -import com.github.scribejava.core.model.OAuthConfig; -import com.github.scribejava.core.model.OAuthRequest; -import com.github.scribejava.core.oauth.OAuth20Service; - -public class DoktornaraboteOAuthServiceImpl extends OAuth20Service { - - public DoktornaraboteOAuthServiceImpl(DefaultApi20 api, OAuthConfig config) { - super(api, config); - } - - @Override - public void signRequest(OAuth2AccessToken accessToken, OAuthRequest request) { - request.addHeader("Authorization", "Bearer " + accessToken.getAccessToken()); - } -} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/GeniusOAuthServiceImpl.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/GeniusOAuthServiceImpl.java deleted file mode 100644 index dd9c493cd..000000000 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/GeniusOAuthServiceImpl.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.github.scribejava.apis.service; - -import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.model.OAuth2AccessToken; -import com.github.scribejava.core.model.OAuthConfig; -import com.github.scribejava.core.model.OAuthRequest; -import com.github.scribejava.core.oauth.OAuth20Service; - -public class GeniusOAuthServiceImpl extends OAuth20Service { - - public GeniusOAuthServiceImpl(DefaultApi20 api, OAuthConfig config) { - super(api, config); - } - - @Override - public void signRequest(OAuth2AccessToken accessToken, OAuthRequest request) { - request.addHeader("Authorization", "Bearer " + accessToken.getAccessToken()); - } -} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/HHOAuthServiceImpl.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/HHOAuthServiceImpl.java deleted file mode 100644 index ba9dd809b..000000000 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/HHOAuthServiceImpl.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.github.scribejava.apis.service; - -import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.model.OAuth2AccessToken; -import com.github.scribejava.core.model.OAuthConfig; -import com.github.scribejava.core.model.OAuthRequest; -import com.github.scribejava.core.oauth.OAuth20Service; - -public class HHOAuthServiceImpl extends OAuth20Service { - - public HHOAuthServiceImpl(DefaultApi20 api, OAuthConfig config) { - super(api, config); - } - - @Override - public void signRequest(OAuth2AccessToken accessToken, OAuthRequest request) { - request.addHeader("Authorization", "Bearer " + accessToken.getAccessToken()); - } -} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceExample.java index bfe562249..e47fbaeea 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceExample.java @@ -87,7 +87,6 @@ public static void main(String... args) throws IOException, NoSuchAlgorithmExcep System.out.println("Full URL: " + url); final OAuthRequest request = new OAuthRequest(Verb.GET, url); - request.addHeader("Authorization", "Bearer " + accessToken.getAccessToken()); final Response response = service.execute(request); System.out.println(); System.out.println(response.getCode()); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceNingAsyncExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceNingAsyncExample.java index e57cd7f8d..080cebd50 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceNingAsyncExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceNingAsyncExample.java @@ -83,7 +83,6 @@ public static void main(String... args) throws InterruptedException, ExecutionEx System.out.println(); System.out.println("Full URL: " + url); final OAuthRequest request = new OAuthRequest(Verb.GET, url); - request.addHeader("Authorization", "Bearer " + accessToken.getAccessToken()); final Response response = service.execute(request, null).get(); System.out.println(); System.out.println(response.getCode()); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV1StagingExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV1StagingExample.java index 44aee4c74..e154dc634 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV1StagingExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV1StagingExample.java @@ -78,12 +78,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); - // TTN should support both signing the request with a parameter, or with a header. - // 1. Token as a parameter service.signRequest(accessToken, request); - // 2. Token in the header. - //request.addHeader("Authorization", "bearer "+accessToken.getAccessToken()); - // And we always expect JSON data. request.addHeader("Accept", "application/json"); final Response response = service.execute(request); System.out.println("Got it! Lets see what we found..."); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV2PreviewExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV2PreviewExample.java index c1c3eb9a6..4feb220c3 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV2PreviewExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV2PreviewExample.java @@ -75,12 +75,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); - // TTN should support both signing the request with a parameter, or with a header. - // 1. Token as a parameter service.signRequest(accessToken, request); - // 2. Token in the header. - //request.addHeader("Authorization", "bearer "+accessToken.getAccessToken()); - // And we always expect JSON data. request.addHeader("Accept", "application/json"); final Response response = service.execute(request); System.out.println("Got it! Lets see what we found..."); diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java index 480a7a34d..95c3022b6 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java @@ -90,4 +90,8 @@ public String getAuthorizationUrl(OAuthConfig config, Map additi public OAuth20Service createService(OAuthConfig config) { return new OAuth20Service(this, config); } + + public SignatureType getSignatureType() { + return SignatureType.BEARER_AUTHORIZATION_REQUEST_HEADER_FIELD; + } } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/SignatureType.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/SignatureType.java new file mode 100644 index 000000000..91ebf5b94 --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/SignatureType.java @@ -0,0 +1,30 @@ +package com.github.scribejava.core.builder.api; + +import com.github.scribejava.core.model.OAuth2AccessToken; +import com.github.scribejava.core.model.OAuthConstants; +import com.github.scribejava.core.model.OAuthRequest; + +public enum SignatureType { + /** + * https://tools.ietf.org/html/rfc6750#section-2.1 + */ + BEARER_AUTHORIZATION_REQUEST_HEADER_FIELD { + @Override + public void signRequest(OAuth2AccessToken accessToken, OAuthRequest request) { + request.addHeader("Authorization", "Bearer " + accessToken.getAccessToken()); + } + + }, + /** + * https://tools.ietf.org/html/rfc6750#section-2.3 + */ + BEARER_URI_QUERY_PARAMETER { + @Override + public void signRequest(OAuth2AccessToken accessToken, OAuthRequest request) { + request.addQuerystringParameter(OAuthConstants.ACCESS_TOKEN, accessToken.getAccessToken()); + } + + }; + + public abstract void signRequest(OAuth2AccessToken accessToken, OAuthRequest request); +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequestAsync.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequestAsync.java index dc8127c05..4717b1259 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequestAsync.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequestAsync.java @@ -8,6 +8,9 @@ public class OAuthRequestAsync extends OAuthRequest { /** + * + * @param verb verb + * @param url url * * @deprecated use {@link OAuthRequest#OAuthRequest(com.github.scribejava.core.model.Verb, java.lang.String) } */ 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 c1ec7fc44..94463003a 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 @@ -187,7 +187,7 @@ public String getVersion() { @Override public void signRequest(OAuth2AccessToken accessToken, OAuthRequest request) { - request.addQuerystringParameter(OAuthConstants.ACCESS_TOKEN, accessToken.getAccessToken()); + api.getSignatureType().signRequest(accessToken, request); } /** diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ApiUnit.java b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ApiUnit.java index 7b23203ac..55e04a461 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ApiUnit.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ApiUnit.java @@ -1,6 +1,7 @@ package com.github.scribejava.core.oauth; import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.builder.api.SignatureType; import com.github.scribejava.core.model.OAuthConfig; class OAuth20ApiUnit extends DefaultApi20 { @@ -19,4 +20,9 @@ protected String getAuthorizationBaseUrl() { public OAuth20Service createService(OAuthConfig config) { return new OAuth20ServiceUnit(this, config); } + + @Override + public SignatureType getSignatureType() { + return SignatureType.BEARER_URI_QUERY_PARAMETER; + } } From 3d4e1657b5aebb2ce77114c1e2b53e09354011fa Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 12 Jan 2017 16:43:12 +0300 Subject: [PATCH 348/882] fix after new signing enum in OAuth2.0 --- .../java/com/github/scribejava/apis/OdnoklassnikiApi.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java index 3144a77e0..85f3cb007 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java @@ -2,6 +2,7 @@ import com.github.scribejava.apis.service.OdnoklassnikiServiceImpl; import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.builder.api.SignatureType; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.oauth.OAuth20Service; @@ -32,4 +33,9 @@ protected String getAuthorizationBaseUrl() { public OAuth20Service createService(OAuthConfig config) { return new OdnoklassnikiServiceImpl(this, config); } + + @Override + public SignatureType getSignatureType() { + return SignatureType.BEARER_URI_QUERY_PARAMETER; + } } From a8f1e32851dd14e8f587b3c65fc3dc9207c90182 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 12 Jan 2017 16:56:57 +0300 Subject: [PATCH 349/882] switch Google, GitHub, Facebook OAuth2.0 oauth requests signing to more secured recommended variant (GET-param -> header Bearer) --- changelog | 1 + .../main/java/com/github/scribejava/apis/FacebookApi.java | 6 ------ .../src/main/java/com/github/scribejava/apis/GitHubApi.java | 6 ------ .../main/java/com/github/scribejava/apis/GoogleApi20.java | 6 ------ 4 files changed, 1 insertion(+), 18 deletions(-) diff --git a/changelog b/changelog index bd889038c..0fde371d4 100644 --- a/changelog +++ b/changelog @@ -1,6 +1,7 @@ [SNAPSHOT] * 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) [3.4.1] * Drop deprecated methods 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 c5320708d..1f00e931c 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java @@ -1,7 +1,6 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.builder.api.SignatureType; import com.github.scribejava.core.model.Verb; /** @@ -40,9 +39,4 @@ public String getRefreshTokenEndpoint() { protected String getAuthorizationBaseUrl() { return "https://www.facebook.com/v2.8/dialog/oauth"; } - - @Override - public SignatureType getSignatureType() { - return SignatureType.BEARER_URI_QUERY_PARAMETER; - } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/GitHubApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/GitHubApi.java index 7e10fefc3..ada35c1b3 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/GitHubApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/GitHubApi.java @@ -1,7 +1,6 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.builder.api.SignatureType; import com.github.scribejava.core.extractors.OAuth2AccessTokenExtractor; import com.github.scribejava.core.extractors.TokenExtractor; import com.github.scribejava.core.model.OAuth2AccessToken; @@ -39,9 +38,4 @@ protected String getAuthorizationBaseUrl() { public TokenExtractor getAccessTokenExtractor() { return OAuth2AccessTokenExtractor.instance(); } - - @Override - public SignatureType getSignatureType() { - return SignatureType.BEARER_URI_QUERY_PARAMETER; - } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/GoogleApi20.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/GoogleApi20.java index a9394dfee..157753f6d 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/GoogleApi20.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/GoogleApi20.java @@ -2,7 +2,6 @@ import com.github.scribejava.apis.google.GoogleJsonTokenExtractor; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.builder.api.SignatureType; import com.github.scribejava.core.extractors.TokenExtractor; import com.github.scribejava.core.model.OAuth2AccessToken; @@ -33,9 +32,4 @@ protected String getAuthorizationBaseUrl() { public TokenExtractor getAccessTokenExtractor() { return GoogleJsonTokenExtractor.instance(); } - - @Override - public SignatureType getSignatureType() { - return SignatureType.BEARER_URI_QUERY_PARAMETER; - } } From bdb25f30d708250fce50264d5782e5a4df5a407b Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 12 Jan 2017 17:08:04 +0300 Subject: [PATCH 350/882] fix OAuth20Service::extractAuthorization when redirectLocation contains '#' part --- .../com/github/scribejava/core/oauth/OAuth20Service.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java index 94463003a..89a74febd 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 @@ -215,7 +215,11 @@ public DefaultApi20 getApi() { public OAuth2Authorization extractAuthorization(String redirectLocation) { final OAuth2Authorization authorization = new OAuth2Authorization(); - for (String param : redirectLocation.substring(redirectLocation.indexOf('?') + 1).split("&")) { + 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) { switch (keyValue[0]) { From caf723056f41fc0561719f2b24856eb58515b13f Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 13 Jan 2017 14:09:26 +0300 Subject: [PATCH 351/882] introduce custom nonstandard Facebook AccessTokenErrorResponse --- changelog | 1 + .../github/scribejava/apis/FacebookApi.java | 8 ++ .../FacebookAccessTokenErrorResponse.java | 95 +++++++++++++++++++ .../FacebookAccessTokenJsonExtractor.java | 45 +++++++++ .../OAuth2AccessTokenJsonExtractor.java | 4 +- 5 files changed, 152 insertions(+), 1 deletion(-) create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookAccessTokenErrorResponse.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookAccessTokenJsonExtractor.java diff --git a/changelog b/changelog index 0fde371d4..24a3756d3 100644 --- a/changelog +++ b/changelog @@ -2,6 +2,7 @@ * 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) + * introduce custom nonstandard Facebook AccessTokenErrorResponse [3.4.1] * Drop deprecated methods 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 1f00e931c..f761aab03 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java @@ -1,6 +1,9 @@ package com.github.scribejava.apis; +import com.github.scribejava.apis.facebook.FacebookAccessTokenJsonExtractor; import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.extractors.TokenExtractor; +import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.Verb; /** @@ -39,4 +42,9 @@ public String getRefreshTokenEndpoint() { protected String getAuthorizationBaseUrl() { return "https://www.facebook.com/v2.8/dialog/oauth"; } + + @Override + public TokenExtractor getAccessTokenExtractor() { + return FacebookAccessTokenJsonExtractor.instance(); + } } 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 new file mode 100644 index 000000000..30c049a3f --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookAccessTokenErrorResponse.java @@ -0,0 +1,95 @@ +package com.github.scribejava.apis.facebook; + +import com.github.scribejava.core.exceptions.OAuthException; +import java.util.Objects; + +/** + * non standard Facebook replace for {@link com.github.scribejava.core.model.OAuth2AccessTokenErrorResponse} + * + * examples:
+ * + * '{"error":{"message":"This authorization code has been + * used.","type":"OAuthException","code":100,"fbtrace_id":"DtxvtGRaxbB"}}'
+ * + * '{"error":{"message":"Error validating application. Invalid application + * ID.","type":"OAuthException","code":101,"fbtrace_id":"CvDR+X4WWIx"}}' + */ +public class FacebookAccessTokenErrorResponse extends OAuthException { + + private static final long serialVersionUID = -1277129766099856895L; + + private final String type; + private final String code; + private final String fbtraceId; + private final String rawResponse; + + public FacebookAccessTokenErrorResponse(String message, String type, String code, String fbtraceId, + String rawResponse) { + super(message); + this.type = type; + this.code = code; + this.fbtraceId = fbtraceId; + this.rawResponse = rawResponse; + } + + public String getType() { + return type; + } + + public String getCode() { + return code; + } + + public String getFbtraceId() { + return fbtraceId; + } + + public String getRawResponse() { + return rawResponse; + } + + @Override + public int hashCode() { + int hash = 5; + hash = 83 * hash + Objects.hashCode(rawResponse); + hash = 83 * hash + Objects.hashCode(getMessage()); + hash = 83 * hash + Objects.hashCode(type); + hash = 83 * hash + Objects.hashCode(code); + hash = 83 * hash + Objects.hashCode(fbtraceId); + 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 FacebookAccessTokenErrorResponse other = (FacebookAccessTokenErrorResponse) obj; + if (!Objects.equals(rawResponse, other.getRawResponse())) { + return false; + } + if (!Objects.equals(getMessage(), other.getMessage())) { + return false; + } + if (!Objects.equals(type, other.getType())) { + return false; + } + if (!Objects.equals(code, other.getCode())) { + return false; + } + return Objects.equals(fbtraceId, other.getFbtraceId()); + } + + @Override + public String toString() { + return "FacebookAccessTokenErrorResponse{'type'='" + type + "', 'code'='" + code + + "', 'fbtraceId'='" + fbtraceId + "', 'rawResponse'='" + rawResponse + + "', 'message'='" + getMessage() + "'}"; + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookAccessTokenJsonExtractor.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookAccessTokenJsonExtractor.java new file mode 100644 index 000000000..b78f048ac --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookAccessTokenJsonExtractor.java @@ -0,0 +1,45 @@ +package com.github.scribejava.apis.facebook; + +import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; + +/** + * non standard Facebook Extractor + */ +public class FacebookAccessTokenJsonExtractor extends OAuth2AccessTokenJsonExtractor { + + private static final String MESSAGE_REGEX = "\"message\"\\s*:\\s*\"([^\"]*?)\""; + private static final String TYPE_REGEX = "\"type\"\\s*:\\s*\"([^\"]*?)\""; + private static final String CODE_REGEX = "\"code\"\\s*:\\s*\"?([^\",}]*?)[\",}]"; + private static final String FBTRACE_ID_REGEX = "\"fbtrace_id\"\\s*:\\s*\"([^\"]*?)\""; + + protected FacebookAccessTokenJsonExtractor() { + } + + private static class InstanceHolder { + + private static final FacebookAccessTokenJsonExtractor INSTANCE = new FacebookAccessTokenJsonExtractor(); + } + + public static FacebookAccessTokenJsonExtractor instance() { + return InstanceHolder.INSTANCE; + } + + /** + * non standard. examples:
+ * + * '{"error":{"message":"This authorization code has been + * used.","type":"OAuthException","code":100,"fbtrace_id":"DtxvtGRaxbB"}}'
+ * + * '{"error":{"message":"Error validating application. Invalid application + * ID.","type":"OAuthException","code":101,"fbtrace_id":"CvDR+X4WWIx"}}' + */ + @Override + protected void generateError(String response) { + extractParameter(response, MESSAGE_REGEX, false); + + throw new FacebookAccessTokenErrorResponse(extractParameter(response, MESSAGE_REGEX, false), + extractParameter(response, TYPE_REGEX, false), extractParameter(response, CODE_REGEX, false), + extractParameter(response, FBTRACE_ID_REGEX, false), 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 feeed66a7..71950a759 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 @@ -50,8 +50,10 @@ public OAuth2AccessToken extract(Response response) throws IOException { /** * Related documentation: https://tools.ietf.org/html/rfc6749#section-5.2 + * + * @param response response */ - private static void generateError(String response) { + protected void generateError(String response) { final String errorInString = extractParameter(response, ERROR_REGEX, true); final String errorDescription = extractParameter(response, ERROR_DESCRIPTION_REGEX, false); final String errorUriInString = extractParameter(response, ERROR_URI_REGEX, false); From b6cb1dcb24abda20da59bb40d21cd92f0d9c905b Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 13 Jan 2017 15:39:48 +0300 Subject: [PATCH 352/882] precompile regexp Patterns (microoptimizations) --- .../FacebookAccessTokenJsonExtractor.java | 18 ++++---- .../apis/google/GoogleJsonTokenExtractor.java | 5 ++- .../SalesforceJsonTokenExtractor.java | 5 ++- .../AbstractOAuth1TokenExtractor.java | 8 ++-- .../OAuth2AccessTokenExtractor.java | 28 ++++++------ .../OAuth2AccessTokenJsonExtractor.java | 40 +++++++++-------- .../scribejava/core/utils/Preconditions.java | 24 +++++++++- .../core/utils/PreconditionsTest.java | 45 ------------------- 8 files changed, 78 insertions(+), 95 deletions(-) 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 b78f048ac..5f6d71d44 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookAccessTokenJsonExtractor.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookAccessTokenJsonExtractor.java @@ -1,16 +1,17 @@ package com.github.scribejava.apis.facebook; import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; +import java.util.regex.Pattern; /** * non standard Facebook Extractor */ public class FacebookAccessTokenJsonExtractor extends OAuth2AccessTokenJsonExtractor { - private static final String MESSAGE_REGEX = "\"message\"\\s*:\\s*\"([^\"]*?)\""; - private static final String TYPE_REGEX = "\"type\"\\s*:\\s*\"([^\"]*?)\""; - private static final String CODE_REGEX = "\"code\"\\s*:\\s*\"?([^\",}]*?)[\",}]"; - private static final String FBTRACE_ID_REGEX = "\"fbtrace_id\"\\s*:\\s*\"([^\"]*?)\""; + private static final Pattern MESSAGE_REGEX_PATTERN = Pattern.compile("\"message\"\\s*:\\s*\"([^\"]*?)\""); + private static final Pattern TYPE_REGEX_PATTERN = Pattern.compile("\"type\"\\s*:\\s*\"([^\"]*?)\""); + private static final Pattern CODE_REGEX_PATTERN = Pattern.compile("\"code\"\\s*:\\s*\"?([^\",}]*?)[\",}]"); + private static final Pattern FBTRACE_ID_REGEX_PATTERN = Pattern.compile("\"fbtrace_id\"\\s*:\\s*\"([^\"]*?)\""); protected FacebookAccessTokenJsonExtractor() { } @@ -35,11 +36,12 @@ public static FacebookAccessTokenJsonExtractor instance() { */ @Override protected void generateError(String response) { - extractParameter(response, MESSAGE_REGEX, false); + extractParameter(response, MESSAGE_REGEX_PATTERN, false); - throw new FacebookAccessTokenErrorResponse(extractParameter(response, MESSAGE_REGEX, false), - extractParameter(response, TYPE_REGEX, false), extractParameter(response, CODE_REGEX, false), - extractParameter(response, FBTRACE_ID_REGEX, false), response); + throw new FacebookAccessTokenErrorResponse(extractParameter(response, MESSAGE_REGEX_PATTERN, false), + extractParameter(response, TYPE_REGEX_PATTERN, false), + extractParameter(response, CODE_REGEX_PATTERN, false), + extractParameter(response, FBTRACE_ID_REGEX_PATTERN, false), response); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/google/GoogleJsonTokenExtractor.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/google/GoogleJsonTokenExtractor.java index 8295ddc3f..722390ae0 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/google/GoogleJsonTokenExtractor.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/google/GoogleJsonTokenExtractor.java @@ -1,13 +1,14 @@ package com.github.scribejava.apis.google; import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; +import java.util.regex.Pattern; /** * additionally parses OpenID id_token */ public class GoogleJsonTokenExtractor extends OAuth2AccessTokenJsonExtractor { - private static final String ID_TOKEN_REGEX = "\"id_token\"\\s*:\\s*\"(\\S*?)\""; + private static final Pattern ID_TOKEN_REGEX_PATTERN = Pattern.compile("\"id_token\"\\s*:\\s*\"(\\S*?)\""); protected GoogleJsonTokenExtractor() { } @@ -25,6 +26,6 @@ public static GoogleJsonTokenExtractor instance() { protected GoogleToken createToken(String accessToken, String tokenType, Integer expiresIn, String refreshToken, String scope, String response) { return new GoogleToken(accessToken, tokenType, expiresIn, refreshToken, scope, - extractParameter(response, ID_TOKEN_REGEX, false), response); + extractParameter(response, ID_TOKEN_REGEX_PATTERN, false), response); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/salesforce/SalesforceJsonTokenExtractor.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/salesforce/SalesforceJsonTokenExtractor.java index 2f219163a..841276724 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/salesforce/SalesforceJsonTokenExtractor.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/salesforce/SalesforceJsonTokenExtractor.java @@ -1,6 +1,7 @@ package com.github.scribejava.apis.salesforce; import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; +import java.util.regex.Pattern; /** * This extractor parses in addition to the standard Extractor the instance_url @@ -8,7 +9,7 @@ */ public class SalesforceJsonTokenExtractor extends OAuth2AccessTokenJsonExtractor { - private static final String INSTANCE_URL_REGEX = "\"instance_url\"\\s*:\\s*\"(\\S*?)\""; + private static final Pattern INSTANCE_URL_REGEX_PATTERN = Pattern.compile("\"instance_url\"\\s*:\\s*\"(\\S*?)\""); protected SalesforceJsonTokenExtractor() { } @@ -26,6 +27,6 @@ public static SalesforceJsonTokenExtractor instance() { protected SalesforceToken createToken(String accessToken, String tokenType, Integer expiresIn, String refreshToken, String scope, String response) { return new SalesforceToken(accessToken, tokenType, expiresIn, refreshToken, scope, - extractParameter(response, INSTANCE_URL_REGEX, true), response); + extractParameter(response, INSTANCE_URL_REGEX_PATTERN, true), response); } } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/AbstractOAuth1TokenExtractor.java b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/AbstractOAuth1TokenExtractor.java index 36285c2c1..61578d01b 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/AbstractOAuth1TokenExtractor.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/AbstractOAuth1TokenExtractor.java @@ -18,8 +18,8 @@ */ public abstract class AbstractOAuth1TokenExtractor implements TokenExtractor { - private static final String OAUTH_TOKEN_REGEXP = "oauth_token=([^&]+)"; - private static final String OAUTH_TOKEN_SECRET_REGEXP = "oauth_token_secret=([^&]*)"; + private static final Pattern OAUTH_TOKEN_REGEXP_PATTERN = Pattern.compile("oauth_token=([^&]+)"); + private static final Pattern OAUTH_TOKEN_SECRET_REGEXP_PATTERN = Pattern.compile("oauth_token_secret=([^&]*)"); /** * {@inheritDoc} @@ -29,8 +29,8 @@ public T extract(Response response) throws IOException { final String body = response.getBody(); Preconditions.checkEmptyString(body, "Response body is incorrect. Can't extract a token from an empty string"); - final String token = extract(body, Pattern.compile(OAUTH_TOKEN_REGEXP)); - final String secret = extract(body, Pattern.compile(OAUTH_TOKEN_SECRET_REGEXP)); + final String token = extract(body, OAUTH_TOKEN_REGEXP_PATTERN); + final String secret = extract(body, OAUTH_TOKEN_SECRET_REGEXP_PATTERN); return createToken(token, secret, body); } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenExtractor.java b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenExtractor.java index 67de27299..8af44d3aa 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenExtractor.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenExtractor.java @@ -14,11 +14,11 @@ */ public class OAuth2AccessTokenExtractor implements TokenExtractor { - private static final String ACCESS_TOKEN_REGEX = "access_token=([^&]+)"; - private static final String TOKEN_TYPE_REGEX = "token_type=([^&]+)"; - private static final String EXPIRES_IN_REGEX = "expires_in=([^&]+)"; - private static final String REFRESH_TOKEN_REGEX = "refresh_token=([^&]+)"; - private static final String SCOPE_REGEX = "scope=([^&]+)"; + private static final Pattern ACCESS_TOKEN_REGEX_PATTERN = Pattern.compile("access_token=([^&]+)"); + private static final Pattern TOKEN_TYPE_REGEX_PATTERN = Pattern.compile("token_type=([^&]+)"); + private static final Pattern EXPIRES_IN_REGEX_PATTERN = Pattern.compile("expires_in=([^&]+)"); + private static final Pattern REFRESH_TOKEN_REGEX_PATTERN = Pattern.compile("refresh_token=([^&]+)"); + private static final Pattern SCOPE_REGEX_PATTERN = Pattern.compile("scope=([^&]+)"); protected OAuth2AccessTokenExtractor() { } @@ -41,27 +41,29 @@ public OAuth2AccessToken extract(Response response) throws IOException { Preconditions.checkEmptyString(body, "Response body is incorrect. Can't extract a token from an empty string"); - final String accessToken = extractParameter(body, ACCESS_TOKEN_REGEX, true); - final String tokenType = extractParameter(body, TOKEN_TYPE_REGEX, false); - final String expiresInString = extractParameter(body, EXPIRES_IN_REGEX, false); + final String accessToken = extractParameter(body, ACCESS_TOKEN_REGEX_PATTERN, true); + final String tokenType = extractParameter(body, TOKEN_TYPE_REGEX_PATTERN, false); + final String expiresInString = extractParameter(body, EXPIRES_IN_REGEX_PATTERN, false); Integer expiresIn; try { expiresIn = expiresInString == null ? null : Integer.valueOf(expiresInString); } catch (NumberFormatException nfe) { expiresIn = null; } - final String refreshToken = extractParameter(body, REFRESH_TOKEN_REGEX, false); - final String scope = extractParameter(body, SCOPE_REGEX, false); + final String refreshToken = extractParameter(body, REFRESH_TOKEN_REGEX_PATTERN, false); + final String scope = extractParameter(body, SCOPE_REGEX_PATTERN, false); return new OAuth2AccessToken(accessToken, tokenType, expiresIn, refreshToken, scope, body); } - private static String extractParameter(String response, String regex, boolean required) throws OAuthException { - final Matcher matcher = Pattern.compile(regex).matcher(response); + private static String extractParameter(String response, Pattern regexPattern, boolean required) + throws OAuthException { + + final Matcher matcher = regexPattern.matcher(response); if (matcher.find()) { return OAuthEncoder.decode(matcher.group(1)); } else if (required) { - throw new OAuthException("Response body is incorrect. Can't extract a '" + regex + throw new OAuthException("Response body is incorrect. Can't extract a '" + regexPattern.pattern() + "' from this: '" + response + "'", null); } else { return null; diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractor.java b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractor.java index 71950a759..0c24755b3 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 @@ -15,14 +15,15 @@ */ public class OAuth2AccessTokenJsonExtractor implements TokenExtractor { - private static final String ACCESS_TOKEN_REGEX = "\"access_token\"\\s*:\\s*\"(\\S*?)\""; - private static final String TOKEN_TYPE_REGEX = "\"token_type\"\\s*:\\s*\"(\\S*?)\""; - private static final String EXPIRES_IN_REGEX = "\"expires_in\"\\s*:\\s*\"?(\\d*?)\"?\\D"; - private static final String REFRESH_TOKEN_REGEX = "\"refresh_token\"\\s*:\\s*\"(\\S*?)\""; - private static final String SCOPE_REGEX = "\"scope\"\\s*:\\s*\"(\\S*?)\""; - private static final String ERROR_REGEX = "\"error\"\\s*:\\s*\"(\\S*?)\""; - private static final String ERROR_DESCRIPTION_REGEX = "\"error_description\"\\s*:\\s*\"([^\"]*?)\""; - private static final String ERROR_URI_REGEX = "\"error_uri\"\\s*:\\s*\"(\\S*?)\""; + private static final Pattern ACCESS_TOKEN_REGEX_PATTERN = Pattern.compile("\"access_token\"\\s*:\\s*\"(\\S*?)\""); + private static final Pattern TOKEN_TYPE_REGEX_PATTERN = Pattern.compile("\"token_type\"\\s*:\\s*\"(\\S*?)\""); + private static final Pattern EXPIRES_IN_REGEX_PATTERN = Pattern.compile("\"expires_in\"\\s*:\\s*\"?(\\d*?)\"?\\D"); + private static final Pattern REFRESH_TOKEN_REGEX_PATTERN = Pattern.compile("\"refresh_token\"\\s*:\\s*\"(\\S*?)\""); + private static final Pattern SCOPE_REGEX_PATTERN = Pattern.compile("\"scope\"\\s*:\\s*\"(\\S*?)\""); + private static final Pattern ERROR_REGEX_PATTERN = Pattern.compile("\"error\"\\s*:\\s*\"(\\S*?)\""); + private static final Pattern ERROR_DESCRIPTION_REGEX_PATTERN + = Pattern.compile("\"error_description\"\\s*:\\s*\"([^\"]*?)\""); + private static final Pattern ERROR_URI_REGEX_PATTERN = Pattern.compile("\"error_uri\"\\s*:\\s*\"(\\S*?)\""); protected OAuth2AccessTokenJsonExtractor() { } @@ -54,9 +55,9 @@ public OAuth2AccessToken extract(Response response) throws IOException { * @param response response */ protected void generateError(String response) { - final String errorInString = extractParameter(response, ERROR_REGEX, true); - final String errorDescription = extractParameter(response, ERROR_DESCRIPTION_REGEX, false); - final String errorUriInString = extractParameter(response, ERROR_URI_REGEX, false); + final String errorInString = extractParameter(response, ERROR_REGEX_PATTERN, true); + final String errorDescription = extractParameter(response, ERROR_DESCRIPTION_REGEX_PATTERN, false); + final String errorUriInString = extractParameter(response, ERROR_URI_REGEX_PATTERN, false); URI errorUri; try { errorUri = errorUriInString == null ? null : URI.create(errorUriInString); @@ -69,17 +70,17 @@ protected void generateError(String response) { } private OAuth2AccessToken createToken(String response) { - final String accessToken = extractParameter(response, ACCESS_TOKEN_REGEX, true); - final String tokenType = extractParameter(response, TOKEN_TYPE_REGEX, false); - final String expiresInString = extractParameter(response, EXPIRES_IN_REGEX, false); + final String accessToken = extractParameter(response, ACCESS_TOKEN_REGEX_PATTERN, true); + final String tokenType = extractParameter(response, TOKEN_TYPE_REGEX_PATTERN, false); + final String expiresInString = extractParameter(response, EXPIRES_IN_REGEX_PATTERN, false); Integer expiresIn; try { expiresIn = expiresInString == null ? null : Integer.valueOf(expiresInString); } catch (NumberFormatException nfe) { expiresIn = null; } - final String refreshToken = extractParameter(response, REFRESH_TOKEN_REGEX, false); - final String scope = extractParameter(response, SCOPE_REGEX, false); + final String refreshToken = extractParameter(response, REFRESH_TOKEN_REGEX_PATTERN, false); + final String scope = extractParameter(response, SCOPE_REGEX_PATTERN, false); return createToken(accessToken, tokenType, expiresIn, refreshToken, scope, response); } @@ -89,14 +90,15 @@ protected OAuth2AccessToken createToken(String accessToken, String tokenType, In return new OAuth2AccessToken(accessToken, tokenType, expiresIn, refreshToken, scope, response); } - protected static String extractParameter(String response, String regex, boolean required) throws OAuthException { - final Matcher matcher = Pattern.compile(regex).matcher(response); + protected static String extractParameter(String response, Pattern regexPattern, boolean required) + throws OAuthException { + final Matcher matcher = regexPattern.matcher(response); if (matcher.find()) { return matcher.group(1); } if (required) { - throw new OAuthException("Response body is incorrect. Can't extract a '" + regex + throw new OAuthException("Response body is incorrect. Can't extract a '" + regexPattern.pattern() + "' from this: '" + response + "'", null); } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/utils/Preconditions.java b/scribejava-core/src/main/java/com/github/scribejava/core/utils/Preconditions.java index 0858fc89d..6343eef3b 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/utils/Preconditions.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/utils/Preconditions.java @@ -35,15 +35,32 @@ public static void checkNotNull(Object object, String errorMsg) { * @throws IllegalArgumentException if the string is null or empty */ public static void checkEmptyString(String string, String errorMsg) { - check(string != null && !string.trim().isEmpty(), errorMsg); + check(hasText(string), errorMsg); } + public static boolean hasText(String str) { + if (str == null || str.isEmpty()) { + return false; + } + final int strLen = str.length(); + for (int i = 0; i < strLen; i++) { + if (!Character.isWhitespace(str.charAt(i))) { + return true; + } + } + return false; + } + + /** * Checks that a URL is valid * * @param url any string * @param errorMsg error message + * + * @deprecated will be just removed. not used in ScribeJava */ + @Deprecated public static void checkValidUrl(String url, String errorMsg) { checkEmptyString(url, errorMsg); check(isUrl(url), errorMsg); @@ -54,7 +71,10 @@ public static void checkValidUrl(String url, String errorMsg) { * * @param url any string * @param errorMsg error message + * + * @deprecated will be just removed. not used in ScribeJava */ + @Deprecated public static void checkValidOAuthCallback(String url, String errorMsg) { checkEmptyString(url, errorMsg); if (url.toLowerCase(Locale.getDefault()).compareToIgnoreCase(OAuthConstants.OUT_OF_BAND) != 0) { @@ -68,7 +88,7 @@ private static boolean isUrl(String url) { private static void check(boolean requirements, String error) { if (!requirements) { - throw new IllegalArgumentException(error == null || error.trim().length() <= 0 ? DEFAULT_MESSAGE : error); + throw new IllegalArgumentException(hasText(error) ? error : DEFAULT_MESSAGE); } } 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 76d64c5ba..ec6722c5a 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 @@ -25,49 +25,4 @@ public void shouldThrowExceptionForEmptyStrings() { public void shouldThrowExceptionForSpacesOnlyStrings() { Preconditions.checkEmptyString(" ", ERROR_MSG); } - - @Test(expected = IllegalArgumentException.class) - public void shouldThrowExceptionForInvalidUrls() { - Preconditions.checkValidUrl("this/is/not/a/valid/url", ERROR_MSG); - } - - @Test(expected = IllegalArgumentException.class) - public void shouldThrowExceptionForNullUrls() { - Preconditions.checkValidUrl(null, ERROR_MSG); - } - - @Test - public void shouldAllowValidUrls() { - Preconditions.checkValidUrl("http://www.example.com", ERROR_MSG); - } - - @Test - public void shouldAllowSSLUrls() { - Preconditions.checkValidUrl("https://www.example.com", ERROR_MSG); - } - - @Test - public void shouldAllowSpecialCharsInScheme() { - Preconditions.checkValidUrl("custom+9.3-1://www.example.com", ERROR_MSG); - } - - @Test - public void shouldAllowNonStandarProtocolsForAndroid() { - Preconditions.checkValidUrl("x-url-custom://www.example.com", ERROR_MSG); - } - - @Test(expected = IllegalArgumentException.class) - public void shouldNotAllowStrangeProtocolNames() { - Preconditions.checkValidUrl("$weird*://www.example.com", ERROR_MSG); - } - - @Test(expected = IllegalArgumentException.class) - public void shouldNotAllowUnderscoreInScheme() { - Preconditions.checkValidUrl("http_custom://www.example.com", ERROR_MSG); - } - - @Test - public void shouldAllowOutOfBandAsValidCallbackValue() { - Preconditions.checkValidOAuthCallback("oob", ERROR_MSG); - } } From 8aeb9d85e55ff0b263c892e01f9255c3a5d89e5e Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 13 Jan 2017 15:47:44 +0300 Subject: [PATCH 353/882] prepare 4.0.0 release --- README.md | 4 ++-- changelog | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 0c78e074d..156f924fb 100644 --- a/README.md +++ b/README.md @@ -100,7 +100,7 @@ You can pull ScribeJava from the central maven repository, just add these to you com.github.scribejava scribejava-apis - 3.4.1 + 4.0.0 ``` @@ -109,7 +109,7 @@ And in case you need just core classes (that's it, without any external API (FB, com.github.scribejava scribejava-core - 3.4.1 + 4.0.0 ``` diff --git a/changelog b/changelog index 24a3756d3..ee62bbf36 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,4 @@ -[SNAPSHOT] +[4.0.0] * 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) From c362f0c31bfb305bacb04564ea2d69bc152e0986 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 13 Jan 2017 15:48:50 +0300 Subject: [PATCH 354/882] [maven-release-plugin] prepare release scribejava-4.0.0 --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/pom.xml b/pom.xml index 94bd2f763..6fe3846c4 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 3.4.2-SNAPSHOT + 4.0.0 ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -33,7 +33,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - HEAD + scribejava-4.0.0 diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 1e0291007..2940b60e9 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 3.4.2-SNAPSHOT + 4.0.0 ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 186c868e0..6a3023c4f 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 3.4.2-SNAPSHOT + 4.0.0 ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 190e489c4..07c23c4d1 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 3.4.2-SNAPSHOT + 4.0.0 ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index a8d55177e..9db730f45 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 3.4.2-SNAPSHOT + 4.0.0 ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index cc1c52080..795e843fa 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 3.4.2-SNAPSHOT + 4.0.0 ../pom.xml From 1c9d5e3fe538a6aaa499212904ecae3ac4f2f045 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 13 Jan 2017 15:49:01 +0300 Subject: [PATCH 355/882] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/pom.xml b/pom.xml index 6fe3846c4..e3149970b 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 4.0.0 + 4.0.1-SNAPSHOT ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -33,7 +33,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - scribejava-4.0.0 + HEAD diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 2940b60e9..d317b3998 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 4.0.0 + 4.0.1-SNAPSHOT ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 6a3023c4f..00dee881e 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 4.0.0 + 4.0.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 07c23c4d1..3dde9e796 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 4.0.0 + 4.0.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index 9db730f45..6449b91cc 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 4.0.0 + 4.0.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 795e843fa..171ba7cd0 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 4.0.0 + 4.0.1-SNAPSHOT ../pom.xml From 9ee53d21b13a077856088079cb0b2e516ab5e579 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 13 Jan 2017 16:00:56 +0300 Subject: [PATCH 356/882] remove deprecated methods and class after release --- .../core/builder/ServiceBuilder.java | 41 ------------ .../core/model/AbstractRequest.java | 9 --- .../core/model/ForceTypeOfHttpRequest.java | 15 ----- .../scribejava/core/model/OAuthConfig.java | 27 -------- .../scribejava/core/model/OAuthRequest.java | 14 +--- .../core/model/OAuthRequestAsync.java | 30 --------- .../scribejava/core/model/Response.java | 64 ------------------- .../core/model/ScribeJavaConfig.java | 19 ------ .../scribejava/core/oauth/OAuthService.java | 10 --- .../scribejava/core/utils/Preconditions.java | 42 ------------ 10 files changed, 1 insertion(+), 270 deletions(-) delete mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/model/AbstractRequest.java delete mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/model/ForceTypeOfHttpRequest.java delete mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequestAsync.java delete mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/model/ScribeJavaConfig.java 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 ca7e5f05e..0651a0e9a 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilder.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilder.java @@ -3,7 +3,6 @@ import com.github.scribejava.core.builder.api.BaseApi; import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.httpclient.HttpClientConfig; -import com.github.scribejava.core.httpclient.jdk.JDKHttpClientConfig; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.SignatureType; @@ -119,46 +118,6 @@ public ServiceBuilder responseType(String responseType) { return this; } - /** - * - * @param connectTimeout connectTimeout - * @return ServiceBuilder to chain methods - * @deprecated use {@link com.github.scribejava.core.httpclient.jdk.JDKHttpClientConfig} and - *
{@link #httpClientConfig(com.github.scribejava.core.httpclient.HttpClientConfig) } - */ - @Deprecated - public ServiceBuilder connectTimeout(Integer connectTimeout) { - final JDKHttpClientConfig jdkHttpClientConfig; - if (httpClientConfig instanceof JDKHttpClientConfig) { - jdkHttpClientConfig = (JDKHttpClientConfig) httpClientConfig; - } else { - jdkHttpClientConfig = new JDKHttpClientConfig(); - httpClientConfig = jdkHttpClientConfig; - } - jdkHttpClientConfig.setConnectTimeout(connectTimeout); - return this; - } - - /** - * - * @param readTimeout readTimeout - * @return ServiceBuilder to chain methods - * @deprecated use {@link com.github.scribejava.core.httpclient.jdk.JDKHttpClientConfig} and - *
{@link #httpClientConfig(com.github.scribejava.core.httpclient.HttpClientConfig) } - */ - @Deprecated - public ServiceBuilder readTimeout(Integer readTimeout) { - final JDKHttpClientConfig jdkHttpClientConfig; - if (httpClientConfig instanceof JDKHttpClientConfig) { - jdkHttpClientConfig = (JDKHttpClientConfig) httpClientConfig; - } else { - jdkHttpClientConfig = new JDKHttpClientConfig(); - httpClientConfig = jdkHttpClientConfig; - } - jdkHttpClientConfig.setReadTimeout(readTimeout); - return this; - } - public ServiceBuilder httpClientConfig(HttpClientConfig httpClientConfig) { Preconditions.checkNotNull(httpClientConfig, "httpClientConfig can't be null"); this.httpClientConfig = httpClientConfig; diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/AbstractRequest.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/AbstractRequest.java deleted file mode 100644 index 7cf52107d..000000000 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/AbstractRequest.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.github.scribejava.core.model; - -/** - * @deprecated use {@link OAuthRequest} - */ -@Deprecated -public abstract class AbstractRequest { - -} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/ForceTypeOfHttpRequest.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/ForceTypeOfHttpRequest.java deleted file mode 100644 index c1ea3f3ce..000000000 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/ForceTypeOfHttpRequest.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.github.scribejava.core.model; - -/** - * - * @deprecated unused anymore. Have no sense and impaction - */ -@Deprecated -public enum ForceTypeOfHttpRequest { - - NONE, - FORCE_ASYNC_ONLY_HTTP_REQUESTS, - FORCE_SYNC_ONLY_HTTP_REQUESTS, - PREFER_ASYNC_ONLY_HTTP_REQUESTS, - PREFER_SYNC_ONLY_HTTP_REQUESTS -} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConfig.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConfig.java index 65df39368..e84ad6805 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConfig.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConfig.java @@ -2,7 +2,6 @@ import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.httpclient.HttpClientConfig; -import com.github.scribejava.core.httpclient.jdk.JDKHttpClientConfig; import java.io.IOException; import java.io.OutputStream; @@ -87,32 +86,6 @@ public void log(String message) { } } - /** - * - * @return Connect Timeout - * @deprecated use {@link JDKHttpClientConfig} - */ - @Deprecated - public Integer getConnectTimeout() { - if (httpClientConfig instanceof JDKHttpClientConfig) { - return ((JDKHttpClientConfig) httpClientConfig).getConnectTimeout(); - } - return null; - } - - /** - * - * @return Read Timeout - * @deprecated use {@link JDKHttpClientConfig} - */ - @Deprecated - public Integer getReadTimeout() { - if (httpClientConfig instanceof JDKHttpClientConfig) { - return ((JDKHttpClientConfig) httpClientConfig).getReadTimeout(); - } - return null; - } - public HttpClientConfig getHttpClientConfig() { return httpClientConfig; } 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 ba99bf6b5..102bc702a 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 @@ -13,7 +13,7 @@ /** * The representation of an OAuth HttpRequest. */ -public class OAuthRequest extends AbstractRequest { +public class OAuthRequest { private static final String OAUTH_PREFIX = "oauth_"; @@ -44,18 +44,6 @@ public OAuthRequest(Verb verb, String url) { this.url = url; } - /** - * - * @param verb verb - * @param url url - * @param config unused - * @deprecated use {@link #OAuthRequest(com.github.scribejava.core.model.Verb, java.lang.String) } - */ - @Deprecated - public OAuthRequest(Verb verb, String url, OAuthConfig config) { - this(verb, url); - } - /** * Adds an OAuth parameter. * diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequestAsync.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequestAsync.java deleted file mode 100644 index 4717b1259..000000000 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequestAsync.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.github.scribejava.core.model; - -/** - * - * @deprecated use {@link OAuthRequest} - */ -@Deprecated -public class OAuthRequestAsync extends OAuthRequest { - - /** - * - * @param verb verb - * @param url url - * - * @deprecated use {@link OAuthRequest#OAuthRequest(com.github.scribejava.core.model.Verb, java.lang.String) } - */ - @Deprecated - public OAuthRequestAsync(Verb verb, String url) { - super(verb, url); - } - - /** - * - * @param goal type - * @deprecated use {@link OAuthRequest.ResponseConverter} - */ - @Deprecated - public interface ResponseConverter extends OAuthRequest.ResponseConverter { - } -} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/Response.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/Response.java index 3b50923a7..8a4807677 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/Response.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/Response.java @@ -2,13 +2,7 @@ import java.io.IOException; import java.io.InputStream; -import java.net.HttpURLConnection; -import java.net.UnknownHostException; -import java.util.HashMap; -import java.util.List; import java.util.Map; -import java.util.Map.Entry; -import com.github.scribejava.core.exceptions.OAuthException; import com.github.scribejava.core.utils.StreamUtils; public class Response { @@ -19,25 +13,6 @@ public class Response { private String body; private InputStream stream; - /** - * - * @param code code - * @param message message - * @param headers headers - * @param body body - * @param stream stream - * @deprecated use either {@link #Response(int, java.lang.String, java.util.Map, java.io.InputStream) } - * or {@link #Response(int, java.lang.String, java.util.Map, java.lang.String) } - */ - @Deprecated - public Response(int code, String message, Map headers, String body, InputStream stream) { - this.code = code; - this.message = message; - this.headers = headers; - this.body = body; - this.stream = stream; - } - private Response(int code, String message, Map headers) { this.code = code; this.message = message; @@ -54,25 +29,6 @@ public Response(int code, String message, Map headers, String bo this.body = body; } - /** - * - * @param connection connection - * @throws IOException - * @deprecated use {@link #Response(int, java.lang.String, java.util.Map, java.lang.String, java.io.InputStream) } - */ - @Deprecated - Response(HttpURLConnection connection) throws IOException { - try { - connection.connect(); - code = connection.getResponseCode(); - message = connection.getResponseMessage(); - headers = parseHeaders(connection); - stream = isSuccessful() ? connection.getInputStream() : connection.getErrorStream(); - } catch (UnknownHostException e) { - throw new OAuthException("The IP address of a host could not be determined.", e); - } - } - private String parseBodyContents() throws IOException { if (stream == null) { return null; @@ -85,26 +41,6 @@ private String parseBodyContents() throws IOException { return body; } - /** - * - * @param conn conn - * @return - * @deprecated use {@link OAuthRequest#parseHeaders(java.net.HttpURLConnection) } - */ - @Deprecated - private Map parseHeaders(HttpURLConnection conn) { - final Map headers = new HashMap<>(); - for (Entry> entry : conn.getHeaderFields().entrySet()) { - final String key = entry.getKey(); - if ("Content-Encoding".equalsIgnoreCase(key)) { - headers.put("Content-Encoding", entry.getValue().get(0)); - } else { - headers.put(key, entry.getValue().get(0)); - } - } - return headers; - } - public final boolean isSuccessful() { return code >= 200 && code < 400; } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/ScribeJavaConfig.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/ScribeJavaConfig.java deleted file mode 100644 index 3ebb31827..000000000 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/ScribeJavaConfig.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.github.scribejava.core.model; - -/** - * - * @deprecated unused anymore. Have no sense and impaction - */ -@Deprecated -public abstract class ScribeJavaConfig { - - private static ForceTypeOfHttpRequest forceTypeOfHttpRequests = ForceTypeOfHttpRequest.NONE; - - public static ForceTypeOfHttpRequest getForceTypeOfHttpRequests() { - return forceTypeOfHttpRequests; - } - - public static void setForceTypeOfHttpRequests(ForceTypeOfHttpRequest forceTypeOfHttpRequests) { - ScribeJavaConfig.forceTypeOfHttpRequests = forceTypeOfHttpRequests; - } -} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java index c17c3b7dc..27fedec80 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java @@ -50,16 +50,6 @@ private static HttpClient getClient(HttpClientConfig config) { return null; } - /** - * - * @throws IOException IOException - * @deprecated use {@link #close() } - */ - @Deprecated - public void closeAsyncClient() throws IOException { - close(); - } - @Override public void close() throws IOException { httpClient.close(); diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/utils/Preconditions.java b/scribejava-core/src/main/java/com/github/scribejava/core/utils/Preconditions.java index 6343eef3b..19e1df083 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/utils/Preconditions.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/utils/Preconditions.java @@ -1,9 +1,5 @@ package com.github.scribejava.core.utils; -import java.util.Locale; -import java.util.regex.Pattern; -import com.github.scribejava.core.model.OAuthConstants; - /** * Utils for checking preconditions and invariants */ @@ -11,9 +7,6 @@ public abstract class Preconditions { private static final String DEFAULT_MESSAGE = "Received an invalid parameter"; - // scheme = alpha *( alpha | digit | "+" | "-" | "." ) - private static final String URL_REGEXP = "^[a-zA-Z][a-zA-Z0-9+.-]*://\\S+"; - /** * Checks that an object is not null. * @@ -51,41 +44,6 @@ public static boolean hasText(String str) { return false; } - - /** - * Checks that a URL is valid - * - * @param url any string - * @param errorMsg error message - * - * @deprecated will be just removed. not used in ScribeJava - */ - @Deprecated - public static void checkValidUrl(String url, String errorMsg) { - checkEmptyString(url, errorMsg); - check(isUrl(url), errorMsg); - } - - /** - * Checks that a URL is a valid OAuth callback - * - * @param url any string - * @param errorMsg error message - * - * @deprecated will be just removed. not used in ScribeJava - */ - @Deprecated - public static void checkValidOAuthCallback(String url, String errorMsg) { - checkEmptyString(url, errorMsg); - if (url.toLowerCase(Locale.getDefault()).compareToIgnoreCase(OAuthConstants.OUT_OF_BAND) != 0) { - check(isUrl(url), errorMsg); - } - } - - private static boolean isUrl(String url) { - return Pattern.compile(URL_REGEXP).matcher(url).matches(); - } - private static void check(boolean requirements, String error) { if (!requirements) { throw new IllegalArgumentException(hasText(error) ? error : DEFAULT_MESSAGE); From ad795568a083bc6cfe15ef8e531335159c1bcec8 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 13 Jan 2017 16:36:42 +0300 Subject: [PATCH 357/882] simplify async examples to reflect use of new OAuthService unified methods --- .../examples/FacebookAsyncNingExample.java | 4 +- .../examples/GitHubAsyncOkHttpExample.java | 4 +- .../examples/Google20AsyncAHCExample.java | 6 +-- .../apis/examples/MailruAsyncExample.java | 4 +- .../examples/SalesforceNingAsyncExample.java | 4 +- .../VkontakteExternalHttpExample.java | 4 +- .../scribejava/core/oauth/OAuth20Service.java | 54 +++++++++++++++---- .../scribejava/core/oauth/OAuthService.java | 12 +++-- 8 files changed, 65 insertions(+), 27 deletions(-) diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java index 7bc944dd8..bf916d083 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java @@ -73,7 +73,7 @@ public static void main(String... args) throws InterruptedException, ExecutionEx // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - final OAuth2AccessToken accessToken = service.getAccessTokenAsync(code, null).get(); + final OAuth2AccessToken accessToken = service.getAccessTokenAsync(code).get(); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); @@ -83,7 +83,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); - final Response response = service.execute(request, null).get(); + final 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/GitHubAsyncOkHttpExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubAsyncOkHttpExample.java index 1cfb35d06..ed8189390 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubAsyncOkHttpExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubAsyncOkHttpExample.java @@ -65,7 +65,7 @@ public static void main(String... args) throws IOException, ExecutionException, // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - final OAuth2AccessToken accessToken = service.getAccessTokenAsync(code, null).get(); + final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); @@ -75,7 +75,7 @@ public static void main(String... args) throws IOException, ExecutionException, System.out.println("Now we're going to access a protected resource..."); final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); service.signRequest(accessToken, request); - final Response response = service.execute(request, null).get(); + final 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/Google20AsyncAHCExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java index baddacc9b..970c5d534 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java @@ -82,13 +82,13 @@ public static void main(String... args) throws InterruptedException, ExecutionEx // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - OAuth2AccessToken accessToken = service.getAccessTokenAsync(code, null).get(); + OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); System.out.println("Refreshing the Access Token..."); - accessToken = service.refreshAccessTokenAsync(accessToken.getRefreshToken(), null).get(); + accessToken = service.refreshAccessToken(accessToken.getRefreshToken()); System.out.println("Refreshed the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); @@ -113,7 +113,7 @@ public static void main(String... args) throws InterruptedException, ExecutionEx final OAuthRequest request = new OAuthRequest(Verb.GET, requestUrl); service.signRequest(accessToken, request); - final Response response = service.execute(request, null).get(); + final Response response = service.execute(request); System.out.println(); System.out.println(response.getCode()); System.out.println(response.getBody()); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java index e4343d19b..38613c019 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java @@ -59,7 +59,7 @@ public static void main(String... args) throws InterruptedException, ExecutionEx // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - final OAuth2AccessToken accessToken = service.getAccessTokenAsync(code, null).get(); + final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); @@ -68,7 +68,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); - final Response response = service.execute(request, null).get(); + final Response response = service.execute(request); System.out.println("Got it! Lets see what we found..."); System.out.println(); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceNingAsyncExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceNingAsyncExample.java index 080cebd50..2cf040a45 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceNingAsyncExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceNingAsyncExample.java @@ -67,7 +67,7 @@ public static void main(String... args) throws InterruptedException, ExecutionEx final String codeEncoded = URLDecoder.decode(code, "UTF-8"); // Trade the Request Token and Verifier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - final SalesforceToken accessToken = (SalesforceToken) service.getAccessTokenAsync(codeEncoded, null).get(); + final SalesforceToken accessToken = (SalesforceToken) service.getAccessToken(codeEncoded); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); @@ -83,7 +83,7 @@ public static void main(String... args) throws InterruptedException, ExecutionEx System.out.println(); System.out.println("Full URL: " + url); final OAuthRequest request = new OAuthRequest(Verb.GET, url); - final Response response = service.execute(request, null).get(); + final Response response = service.execute(request); System.out.println(); System.out.println(response.getCode()); System.out.println(response.getBody()); 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 cfdbe6210..2cd858236 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 @@ -64,7 +64,7 @@ public static void main(String... args) throws IOException, InterruptedException // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - final OAuth2AccessToken accessToken = service.getAccessTokenAsync(code, null).get(); + final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); @@ -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); - final Response response = service.execute(request, null).get(); + final 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-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 89a74febd..fadf54800 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 @@ -54,6 +54,28 @@ public OAuth2AccessToken convert(Response response) throws IOException { }); } + public final Future getAccessTokenAsync(String code) { + return getAccessToken(code, null); + } + + /** + * Start the request to retrieve the access token. The optionally provided callback will be called with the Token + * when it is available. + * + * @param code code + * @param callback optional callback + * @return Future + * @deprecated user {@link #getAccessToken(java.lang.String, + * com.github.scribejava.core.model.OAuthAsyncRequestCallback) } + */ + @Deprecated + public final Future getAccessTokenAsync(String code, + OAuthAsyncRequestCallback callback) { + final OAuthRequest request = createAccessTokenRequest(code); + + return sendAccessTokenRequestAsync(request, callback); + } + public final OAuth2AccessToken getAccessToken(String code) throws IOException, InterruptedException, ExecutionException { final OAuthRequest request = createAccessTokenRequest(code); @@ -61,10 +83,6 @@ public final OAuth2AccessToken getAccessToken(String code) return sendAccessTokenRequestSync(request); } - public final Future getAccessTokenAsync(String code) { - return getAccessTokenAsync(code, null); - } - /** * Start the request to retrieve the access token. The optionally provided callback will be called with the Token * when it is available. @@ -73,7 +91,7 @@ public final Future getAccessTokenAsync(String code) { * @param callback optional callback * @return Future */ - public final Future getAccessTokenAsync(String code, + public final Future getAccessToken(String code, OAuthAsyncRequestCallback callback) { final OAuthRequest request = createAccessTokenRequest(code); @@ -95,6 +113,26 @@ protected OAuthRequest createAccessTokenRequest(String code) { return request; } + public final Future refreshAccessTokenAsync(String refreshToken) { + return refreshAccessToken(refreshToken, null); + } + + /** + * + * @param refreshToken refreshToken + * @param callback callback + * @return future + * @deprecated use {@link #refreshAccessToken(java.lang.String, + * com.github.scribejava.core.model.OAuthAsyncRequestCallback)} + */ + @Deprecated + public final Future refreshAccessTokenAsync(String refreshToken, + OAuthAsyncRequestCallback callback) { + final OAuthRequest request = createRefreshTokenRequest(refreshToken); + + return sendAccessTokenRequestAsync(request, callback); + } + public final OAuth2AccessToken refreshAccessToken(String refreshToken) throws IOException, InterruptedException, ExecutionException { final OAuthRequest request = createRefreshTokenRequest(refreshToken); @@ -102,11 +140,7 @@ public final OAuth2AccessToken refreshAccessToken(String refreshToken) return sendAccessTokenRequestSync(request); } - public final Future refreshAccessTokenAsync(String refreshToken) { - return refreshAccessTokenAsync(refreshToken, null); - } - - public final Future refreshAccessTokenAsync(String refreshToken, + public final Future refreshAccessToken(String refreshToken, OAuthAsyncRequestCallback callback) { final OAuthRequest request = createRefreshTokenRequest(refreshToken); diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java index 27fedec80..df58ce3ea 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java @@ -68,6 +68,14 @@ public OAuthConfig getConfig() { public abstract void signRequest(T token, OAuthRequest request); + public Future executeAsync(OAuthRequest request) { + return execute(request, null); + } + + public Future execute(OAuthRequest request, OAuthAsyncRequestCallback callback) { + return execute(request, callback, null); + } + public Future execute(OAuthRequest request, OAuthAsyncRequestCallback callback, OAuthRequest.ResponseConverter converter) { @@ -84,10 +92,6 @@ public Future execute(OAuthRequest request, OAuthAsyncRequestCallback } } - public Future execute(OAuthRequest request, OAuthAsyncRequestCallback callback) { - return execute(request, callback, null); - } - public Response execute(OAuthRequest request) throws InterruptedException, ExecutionException, IOException { final File filePayload = request.getFilePayload(); if (filePayload != null) { From bd9a43018147cd72e5d2d04ad76752c3b4065ae4 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 1 Feb 2017 13:09:21 +0300 Subject: [PATCH 358/882] add body for PATCH HTTP method --- changelog | 3 +++ pom.xml | 2 +- .../core/httpclient/jdk/JDKHttpClient.java | 2 +- .../github/scribejava/core/model/OAuthRequest.java | 6 +----- .../java/com/github/scribejava/core/model/Verb.java | 12 +++++++++++- scribejava-httpclient-ahc/pom.xml | 2 +- .../scribejava/httpclient/ahc/AhcHttpClient.java | 2 +- .../scribejava/httpclient/ning/NingHttpClient.java | 2 +- 8 files changed, 20 insertions(+), 11 deletions(-) diff --git a/changelog b/changelog index ee62bbf36..9cc7f8f12 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,6 @@ +[SNAPSHOT] + * add body for PATCH HTTP method + [4.0.0] * 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 diff --git a/pom.xml b/pom.xml index e3149970b..8be793348 100644 --- a/pom.xml +++ b/pom.xml @@ -148,7 +148,7 @@ maven-compiler-plugin - 3.6.0 + 3.6.1 UTF-8 1.7 diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java index 3e19a7d6d..205c842b9 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java @@ -96,7 +96,7 @@ private Response doExecute(String userAgent, Map headers, Verb h connection.setReadTimeout(config.getReadTimeout()); } addHeaders(connection, headers, userAgent); - if (httpVerb == Verb.POST || httpVerb == Verb.PUT || httpVerb == Verb.DELETE) { + if (httpVerb.isPermitBody()) { bodyType.setBody(connection, bodyContents); } 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 102bc702a..3f50440eb 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 @@ -117,17 +117,13 @@ public void addQuerystringParameter(String key, String value) { } public void addParameter(String key, String value) { - if (hasBodyContent()) { + if (verb.isPermitBody()) { bodyParams.add(key, value); } else { querystringParams.add(key, value); } } - protected boolean hasBodyContent() { - return verb == Verb.PUT || verb == Verb.POST; - } - /** * Set body payload. This method is used when the HTTP body is not a form-url-encoded string, but another thing. * Like for example XML. Note: The contents are not part of the OAuth signature diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/Verb.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/Verb.java index 6ca83a517..ddcebc6b2 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/Verb.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/Verb.java @@ -5,5 +5,15 @@ */ public enum Verb { - GET, POST, PUT, DELETE, HEAD, OPTIONS, TRACE, PATCH + GET(false), POST(true), PUT(true), DELETE(true), HEAD(false), OPTIONS(false), TRACE(false), PATCH(true); + + private final boolean permitBody; + + Verb(boolean permitBody) { + this.permitBody = permitBody; + } + + public boolean isPermitBody() { + return permitBody; + } } diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 3dde9e796..8c78da1cd 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -23,7 +23,7 @@ org.asynchttpclient async-http-client - 2.0.24 + 2.0.26 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 a4962b2b5..cdc894bb8 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 @@ -76,7 +76,7 @@ private Future doExecuteAsync(String userAgent, Map heade throw new IllegalArgumentException("message build error: unknown verb type"); } - if (httpVerb == Verb.POST || httpVerb == Verb.PUT || httpVerb == Verb.DELETE) { + if (httpVerb.isPermitBody()) { if (!headers.containsKey(CONTENT_TYPE)) { boundRequestBuilder = boundRequestBuilder.addHeader(CONTENT_TYPE, DEFAULT_CONTENT_TYPE); } 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 a9fcb0a81..bcc843e00 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 @@ -84,7 +84,7 @@ private Future doExecuteAsync(String userAgent, Map heade throw new IllegalArgumentException("message build error: unknown verb type"); } - if (httpVerb == Verb.POST || httpVerb == Verb.PUT || httpVerb == Verb.DELETE) { + if (httpVerb.isPermitBody()) { if (!headers.containsKey(CONTENT_TYPE)) { boundRequestBuilder = boundRequestBuilder.addHeader(CONTENT_TYPE, DEFAULT_CONTENT_TYPE); } From 4cd58302f9e252e0a3c355b1f842a527e9b6af3d Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 4 Apr 2017 16:09:11 +0300 Subject: [PATCH 359/882] move OAuth1 SignatureType to ServiceBuilder to API --- changelog | 1 + .../com/github/scribejava/apis/BoxApi20.java | 6 +-- .../scribejava/apis/Foursquare2Api.java | 6 +-- .../github/scribejava/apis/FreelancerApi.java | 6 +++ .../github/scribejava/apis/KaixinApi20.java | 6 +-- .../github/scribejava/apis/LinkedInApi20.java | 6 +-- .../com/github/scribejava/apis/LiveApi.java | 6 +-- .../com/github/scribejava/apis/MisfitApi.java | 6 +-- .../com/github/scribejava/apis/NaverApi.java | 6 +-- .../scribejava/apis/OdnoklassnikiApi.java | 6 +-- .../github/scribejava/apis/PinterestApi.java | 6 +-- .../com/github/scribejava/apis/RenrenApi.java | 6 +-- .../scribejava/apis/SinaWeiboApi20.java | 6 +-- .../scribejava/apis/StackExchangeApi.java | 6 +-- .../com/github/scribejava/apis/ViadeoApi.java | 6 +-- .../github/scribejava/apis/VkontakteApi.java | 6 +-- .../apis/examples/FreelancerExample.java | 2 - .../core/builder/ServiceBuilder.java | 24 ++++++--- .../core/builder/api/DefaultApi10a.java | 7 +++ .../core/builder/api/DefaultApi20.java | 4 +- .../core/builder/api/OAuth1SignatureType.java | 7 +++ .../core/builder/api/OAuth2SignatureType.java | 30 +++++++++++ .../core/builder/api/SignatureType.java | 4 ++ .../scribejava/core/model/OAuthConfig.java | 53 ++++++++++++++++--- .../scribejava/core/model/SignatureType.java | 4 ++ .../core/oauth/OAuth10aService.java | 8 ++- .../core/builder/ServiceBuilderTest.java | 10 ++-- .../scribejava/core/oauth/OAuth20ApiUnit.java | 6 +-- .../okhttp/OkHttpHttpClientTest.java | 2 +- 29 files changed, 183 insertions(+), 69 deletions(-) create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/builder/api/OAuth1SignatureType.java create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/builder/api/OAuth2SignatureType.java diff --git a/changelog b/changelog index 9cc7f8f12..359cd2c75 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,5 @@ [SNAPSHOT] + * move OAuth1 SignatureType to ServiceBuilder to API * add body for PATCH HTTP method [4.0.0] diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/BoxApi20.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/BoxApi20.java index c6613b62e..d21cc39be 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/BoxApi20.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/BoxApi20.java @@ -1,7 +1,7 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.builder.api.SignatureType; +import com.github.scribejava.core.builder.api.OAuth2SignatureType; /** * Box.com Api @@ -31,7 +31,7 @@ protected String getAuthorizationBaseUrl() { } @Override - public SignatureType getSignatureType() { - return SignatureType.BEARER_URI_QUERY_PARAMETER; + public OAuth2SignatureType getSignatureType() { + return OAuth2SignatureType.BEARER_URI_QUERY_PARAMETER; } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/Foursquare2Api.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/Foursquare2Api.java index 71fb94768..321554af2 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/Foursquare2Api.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/Foursquare2Api.java @@ -1,7 +1,7 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.builder.api.SignatureType; +import com.github.scribejava.core.builder.api.OAuth2SignatureType; import com.github.scribejava.core.model.Verb; public class Foursquare2Api extends DefaultApi20 { @@ -33,7 +33,7 @@ protected String getAuthorizationBaseUrl() { } @Override - public SignatureType getSignatureType() { - return SignatureType.BEARER_URI_QUERY_PARAMETER; + public OAuth2SignatureType getSignatureType() { + return OAuth2SignatureType.BEARER_URI_QUERY_PARAMETER; } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/FreelancerApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/FreelancerApi.java index 52fe4cc1f..65b64c04f 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/FreelancerApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/FreelancerApi.java @@ -1,6 +1,7 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi10a; +import com.github.scribejava.core.builder.api.OAuth1SignatureType; import com.github.scribejava.core.model.OAuth1RequestToken; import com.github.scribejava.core.model.Verb; @@ -19,6 +20,11 @@ public static FreelancerApi instance() { return InstanceHolder.INSTANCE; } + @Override + public OAuth1SignatureType getSignatureType() { + return OAuth1SignatureType.QueryString; + } + @Override public String getAccessTokenEndpoint() { return "http://api.freelancer.com/RequestAccessToken/requestAccessToken.xml?"; diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/KaixinApi20.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/KaixinApi20.java index fdf8f67af..927813535 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/KaixinApi20.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/KaixinApi20.java @@ -1,7 +1,7 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.builder.api.SignatureType; +import com.github.scribejava.core.builder.api.OAuth2SignatureType; import com.github.scribejava.core.model.Verb; /** @@ -36,7 +36,7 @@ protected String getAuthorizationBaseUrl() { } @Override - public SignatureType getSignatureType() { - return SignatureType.BEARER_URI_QUERY_PARAMETER; + public OAuth2SignatureType getSignatureType() { + return OAuth2SignatureType.BEARER_URI_QUERY_PARAMETER; } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi20.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi20.java index 2ba6259f3..8fa239c5d 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi20.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi20.java @@ -2,7 +2,7 @@ import com.github.scribejava.apis.service.LinkedIn20ServiceImpl; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.builder.api.SignatureType; +import com.github.scribejava.core.builder.api.OAuth2SignatureType; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.oauth.OAuth20Service; @@ -35,7 +35,7 @@ public OAuth20Service createService(OAuthConfig config) { } @Override - public SignatureType getSignatureType() { - return SignatureType.BEARER_URI_QUERY_PARAMETER; + public OAuth2SignatureType getSignatureType() { + return OAuth2SignatureType.BEARER_URI_QUERY_PARAMETER; } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/LiveApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/LiveApi.java index da34cab8f..ffaf3bcf6 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/LiveApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/LiveApi.java @@ -1,7 +1,7 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.builder.api.SignatureType; +import com.github.scribejava.core.builder.api.OAuth2SignatureType; import com.github.scribejava.core.model.Verb; public class LiveApi extends DefaultApi20 { @@ -33,7 +33,7 @@ protected String getAuthorizationBaseUrl() { } @Override - public SignatureType getSignatureType() { - return SignatureType.BEARER_URI_QUERY_PARAMETER; + public OAuth2SignatureType getSignatureType() { + return OAuth2SignatureType.BEARER_URI_QUERY_PARAMETER; } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/MisfitApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/MisfitApi.java index 54559e6da..c34d2cc15 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/MisfitApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/MisfitApi.java @@ -1,7 +1,7 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.builder.api.SignatureType; +import com.github.scribejava.core.builder.api.OAuth2SignatureType; public class MisfitApi extends DefaultApi20 { @@ -28,7 +28,7 @@ protected String getAuthorizationBaseUrl() { } @Override - public SignatureType getSignatureType() { - return SignatureType.BEARER_URI_QUERY_PARAMETER; + public OAuth2SignatureType getSignatureType() { + return OAuth2SignatureType.BEARER_URI_QUERY_PARAMETER; } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/NaverApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/NaverApi.java index 42056e7eb..a3028ae11 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/NaverApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/NaverApi.java @@ -1,7 +1,7 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.builder.api.SignatureType; +import com.github.scribejava.core.builder.api.OAuth2SignatureType; public class NaverApi extends DefaultApi20 { protected NaverApi() { @@ -29,7 +29,7 @@ protected String getAuthorizationBaseUrl() { } @Override - public SignatureType getSignatureType() { - return SignatureType.BEARER_URI_QUERY_PARAMETER; + public OAuth2SignatureType getSignatureType() { + return OAuth2SignatureType.BEARER_URI_QUERY_PARAMETER; } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java index 85f3cb007..f8e1a40ef 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java @@ -2,7 +2,7 @@ import com.github.scribejava.apis.service.OdnoklassnikiServiceImpl; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.builder.api.SignatureType; +import com.github.scribejava.core.builder.api.OAuth2SignatureType; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.oauth.OAuth20Service; @@ -35,7 +35,7 @@ public OAuth20Service createService(OAuthConfig config) { } @Override - public SignatureType getSignatureType() { - return SignatureType.BEARER_URI_QUERY_PARAMETER; + public OAuth2SignatureType getSignatureType() { + return OAuth2SignatureType.BEARER_URI_QUERY_PARAMETER; } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/PinterestApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/PinterestApi.java index 2940f0a15..d93404b5e 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/PinterestApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/PinterestApi.java @@ -1,7 +1,7 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.builder.api.SignatureType; +import com.github.scribejava.core.builder.api.OAuth2SignatureType; public class PinterestApi extends DefaultApi20 { @@ -27,7 +27,7 @@ protected String getAuthorizationBaseUrl() { } @Override - public SignatureType getSignatureType() { - return SignatureType.BEARER_URI_QUERY_PARAMETER; + public OAuth2SignatureType getSignatureType() { + return OAuth2SignatureType.BEARER_URI_QUERY_PARAMETER; } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/RenrenApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/RenrenApi.java index 08fde329e..cc475440e 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/RenrenApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/RenrenApi.java @@ -1,7 +1,7 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.builder.api.SignatureType; +import com.github.scribejava.core.builder.api.OAuth2SignatureType; import com.github.scribejava.core.model.Verb; /** @@ -36,7 +36,7 @@ protected String getAuthorizationBaseUrl() { } @Override - public SignatureType getSignatureType() { - return SignatureType.BEARER_URI_QUERY_PARAMETER; + public OAuth2SignatureType getSignatureType() { + return OAuth2SignatureType.BEARER_URI_QUERY_PARAMETER; } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/SinaWeiboApi20.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/SinaWeiboApi20.java index 64d3b4950..edd316f87 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/SinaWeiboApi20.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/SinaWeiboApi20.java @@ -1,7 +1,7 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.builder.api.SignatureType; +import com.github.scribejava.core.builder.api.OAuth2SignatureType; /** * SinaWeibo OAuth 2.0 api. @@ -30,7 +30,7 @@ protected String getAuthorizationBaseUrl() { } @Override - public SignatureType getSignatureType() { - return SignatureType.BEARER_URI_QUERY_PARAMETER; + public OAuth2SignatureType getSignatureType() { + return OAuth2SignatureType.BEARER_URI_QUERY_PARAMETER; } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/StackExchangeApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/StackExchangeApi.java index b2f6f0db7..554c97b33 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/StackExchangeApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/StackExchangeApi.java @@ -1,7 +1,7 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.builder.api.SignatureType; +import com.github.scribejava.core.builder.api.OAuth2SignatureType; import com.github.scribejava.core.extractors.OAuth2AccessTokenExtractor; import com.github.scribejava.core.extractors.TokenExtractor; import com.github.scribejava.core.model.OAuth2AccessToken; @@ -39,7 +39,7 @@ public TokenExtractor getAccessTokenExtractor() { } @Override - public SignatureType getSignatureType() { - return SignatureType.BEARER_URI_QUERY_PARAMETER; + public OAuth2SignatureType getSignatureType() { + return OAuth2SignatureType.BEARER_URI_QUERY_PARAMETER; } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/ViadeoApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/ViadeoApi.java index bc1833563..30c0ffcfe 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/ViadeoApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/ViadeoApi.java @@ -1,7 +1,7 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.builder.api.SignatureType; +import com.github.scribejava.core.builder.api.OAuth2SignatureType; import com.github.scribejava.core.model.Verb; public class ViadeoApi extends DefaultApi20 { @@ -33,7 +33,7 @@ protected String getAuthorizationBaseUrl() { } @Override - public SignatureType getSignatureType() { - return SignatureType.BEARER_URI_QUERY_PARAMETER; + public OAuth2SignatureType getSignatureType() { + return OAuth2SignatureType.BEARER_URI_QUERY_PARAMETER; } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/VkontakteApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/VkontakteApi.java index 87217c4b8..285cb2cde 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/VkontakteApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/VkontakteApi.java @@ -1,7 +1,7 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.builder.api.SignatureType; +import com.github.scribejava.core.builder.api.OAuth2SignatureType; import com.github.scribejava.core.model.Verb; public class VkontakteApi extends DefaultApi20 { @@ -33,7 +33,7 @@ protected String getAuthorizationBaseUrl() { } @Override - public SignatureType getSignatureType() { - return SignatureType.BEARER_URI_QUERY_PARAMETER; + public OAuth2SignatureType getSignatureType() { + return OAuth2SignatureType.BEARER_URI_QUERY_PARAMETER; } } diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java index 3908ae116..45986edf1 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java @@ -7,7 +7,6 @@ import com.github.scribejava.core.model.OAuth1RequestToken; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; -import com.github.scribejava.core.model.SignatureType; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.oauth.OAuth10aService; import java.io.IOException; @@ -26,7 +25,6 @@ private FreelancerExample() { public static void main(String... args) throws IOException, InterruptedException, ExecutionException { final OAuth10aService service = new ServiceBuilder() - .signatureType(SignatureType.QueryString) .apiKey("your client id") .apiSecret("your client secret") .scope(SCOPE) 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 0651a0e9a..b0a6067db 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 @@ -5,7 +5,7 @@ import com.github.scribejava.core.httpclient.HttpClientConfig; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; -import com.github.scribejava.core.model.SignatureType; +import com.github.scribejava.core.builder.api.OAuth1SignatureType; import com.github.scribejava.core.oauth.OAuthService; import com.github.scribejava.core.utils.Preconditions; @@ -21,7 +21,12 @@ public class ServiceBuilder { private String apiSecret; private String scope; private String state; - private SignatureType signatureType; + /** + * @deprecated override or change in Pull Request + * {@link com.github.scribejava.core.builder.api.DefaultApi10a#getSignatureType()} + */ + @Deprecated + private OAuth1SignatureType signatureType; private OutputStream debugStream; private String responseType = "code"; private String userAgent; @@ -31,7 +36,6 @@ public class ServiceBuilder { public ServiceBuilder() { callback = OAuthConstants.OUT_OF_BAND; - signatureType = SignatureType.Header; } /** @@ -95,13 +99,18 @@ public ServiceBuilder state(String state) { } /** - * Configures the signature type, choose between header, querystring, etc. Defaults to Header + * Configures the signature type, choose between header, querystring, etc. Defaults to null.
+ * 'null' means to use default for API + * {@link com.github.scribejava.core.builder.api.DefaultApi10a#getSignatureType()} * - * @param signatureType SignatureType + * @param signatureType OAuth1SignatureType * @return the {@link ServiceBuilder} instance for method chaining + * + * @deprecated override or change in Pull Request + * {@link com.github.scribejava.core.builder.api.DefaultApi10a#getSignatureType()} */ - public ServiceBuilder signatureType(SignatureType signatureType) { - Preconditions.checkNotNull(signatureType, "Signature type can't be null"); + @Deprecated + public ServiceBuilder signatureType(OAuth1SignatureType signatureType) { this.signatureType = signatureType; return this; } @@ -149,6 +158,7 @@ public void checkPreconditions() { Preconditions.checkEmptyString(apiKey, "You must provide an api key"); } + @SuppressWarnings("deprecation") private OAuthConfig createConfig() { checkPreconditions(); return new OAuthConfig(apiKey, apiSecret, callback, signatureType, scope, debugStream, state, responseType, diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi10a.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi10a.java index 3b4b148c6..b7167a86e 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi10a.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi10a.java @@ -77,6 +77,13 @@ public SignatureService getSignatureService() { return new HMACSha1SignatureService(); } + /** + * @return the signature type, choose between header, querystring, etc. Defaults to Header + */ + public OAuth1SignatureType getSignatureType() { + return OAuth1SignatureType.Header; + } + /** * Returns the timestamp service. * diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java index 95c3022b6..5a9e7ce44 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java @@ -91,7 +91,7 @@ public OAuth20Service createService(OAuthConfig config) { return new OAuth20Service(this, config); } - public SignatureType getSignatureType() { - return SignatureType.BEARER_AUTHORIZATION_REQUEST_HEADER_FIELD; + public OAuth2SignatureType getSignatureType() { + return OAuth2SignatureType.BEARER_AUTHORIZATION_REQUEST_HEADER_FIELD; } } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/OAuth1SignatureType.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/OAuth1SignatureType.java new file mode 100644 index 000000000..7660b5826 --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/OAuth1SignatureType.java @@ -0,0 +1,7 @@ +package com.github.scribejava.core.builder.api; + +public enum OAuth1SignatureType { + + Header, + QueryString +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/OAuth2SignatureType.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/OAuth2SignatureType.java new file mode 100644 index 000000000..a6825a757 --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/OAuth2SignatureType.java @@ -0,0 +1,30 @@ +package com.github.scribejava.core.builder.api; + +import com.github.scribejava.core.model.OAuth2AccessToken; +import com.github.scribejava.core.model.OAuthConstants; +import com.github.scribejava.core.model.OAuthRequest; + +public enum OAuth2SignatureType { + /** + * https://tools.ietf.org/html/rfc6750#section-2.1 + */ + BEARER_AUTHORIZATION_REQUEST_HEADER_FIELD { + @Override + public void signRequest(OAuth2AccessToken accessToken, OAuthRequest request) { + request.addHeader("Authorization", "Bearer " + accessToken.getAccessToken()); + } + + }, + /** + * https://tools.ietf.org/html/rfc6750#section-2.3 + */ + BEARER_URI_QUERY_PARAMETER { + @Override + public void signRequest(OAuth2AccessToken accessToken, OAuthRequest request) { + request.addQuerystringParameter(OAuthConstants.ACCESS_TOKEN, accessToken.getAccessToken()); + } + + }; + + public abstract void signRequest(OAuth2AccessToken accessToken, OAuthRequest request); +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/SignatureType.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/SignatureType.java index 91ebf5b94..3429b64b5 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/SignatureType.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/SignatureType.java @@ -4,6 +4,10 @@ import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.OAuthRequest; +/** + * @deprecated renamed to {@link OAuth2SignatureType} + */ +@Deprecated public enum SignatureType { /** * https://tools.ietf.org/html/rfc6750#section-2.1 diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConfig.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConfig.java index e84ad6805..929fc97cc 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConfig.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConfig.java @@ -1,5 +1,6 @@ package com.github.scribejava.core.model; +import com.github.scribejava.core.builder.api.OAuth1SignatureType; import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.httpclient.HttpClientConfig; import java.io.IOException; @@ -13,7 +14,12 @@ public class OAuthConfig { private final String apiKey; private final String apiSecret; private final String callback; - private final SignatureType signatureType; + /** + * @deprecated override or change in Pull Request + * {@link com.github.scribejava.core.builder.api.DefaultApi10a#getSignatureType()} + */ + @Deprecated + private OAuth1SignatureType signatureType; private final String scope; private final OutputStream debugStream; private final String state; @@ -24,16 +30,44 @@ public class OAuthConfig { private HttpClient httpClient; public OAuthConfig(String key, String secret) { - this(key, secret, null, null, null, null, null, null, null, null, null); + this(key, secret, null, null, null, null, null, null, null, null); } - public OAuthConfig(String apiKey, String apiSecret, String callback, SignatureType signatureType, String scope, - OutputStream debugStream, String state, String responseType, String userAgent, + /** + * @param apiKey apiKey + * @param apiSecret apiSecret + * @param callback callback + * @param signatureType signatureType + * @param scope scope + * @param debugStream debugStream + * @param state state + * @param responseType responseType + * @param userAgent userAgent + * @param httpClientConfig httpClientConfig + * @param httpClient httpClient + * + * @deprecated use {@link #OAuthConfig(java.lang.String, java.lang.String, java.lang.String, java.lang.String, + * java.io.OutputStream, java.lang.String, java.lang.String, java.lang.String, + * com.github.scribejava.core.httpclient.HttpClientConfig, com.github.scribejava.core.httpclient.HttpClient)} + *
+ * without OAuth1SignatureType param. to change OAuth1SignatureType override or change in Pull Request + *
{@link com.github.scribejava.core.builder.api.DefaultApi10a#getSignatureType()} + */ + @Deprecated + public OAuthConfig(String apiKey, String apiSecret, String callback, OAuth1SignatureType signatureType, + String scope, OutputStream debugStream, String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { + this(apiKey, apiSecret, callback, scope, debugStream, state, responseType, userAgent, httpClientConfig, + httpClient); + this.signatureType = signatureType; + } + + public OAuthConfig(String apiKey, String apiSecret, String callback, String scope, OutputStream debugStream, + String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, + HttpClient httpClient) { this.apiKey = apiKey; this.apiSecret = apiSecret; this.callback = callback; - this.signatureType = signatureType; this.scope = scope; this.debugStream = debugStream; this.state = state; @@ -55,7 +89,14 @@ public String getCallback() { return callback; } - public SignatureType getSignatureType() { + /** + * @return configured OAuth1SignatureType to override from API + * + * @deprecated override or change in Pull Request + * {@link com.github.scribejava.core.builder.api.DefaultApi10a#getSignatureType()} + */ + @Deprecated + public OAuth1SignatureType getSignatureType() { return signatureType; } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/SignatureType.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/SignatureType.java index 26ffe054e..5e6dd91a7 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/SignatureType.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/SignatureType.java @@ -1,5 +1,9 @@ package com.github.scribejava.core.model; +/** + * @deprecated renamed to {@link com.github.scribejava.core.builder.api.OAuth1SignatureType} + */ +@Deprecated public enum SignatureType { Header, 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 d9332d03b..8dab33476 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java @@ -4,6 +4,7 @@ import java.util.Map; import java.util.concurrent.Future; import com.github.scribejava.core.builder.api.DefaultApi10a; +import com.github.scribejava.core.builder.api.OAuth1SignatureType; import com.github.scribejava.core.model.OAuth1AccessToken; import com.github.scribejava.core.model.OAuth1RequestToken; import com.github.scribejava.core.model.OAuthAsyncRequestCallback; @@ -179,7 +180,10 @@ private String getSignature(OAuthRequest request, String tokenSecret) { private void appendSignature(OAuthRequest request) { final OAuthConfig config = getConfig(); - switch (config.getSignatureType()) { + @SuppressWarnings("deprecation") + final OAuth1SignatureType signatureType + = config.getSignatureType() == null ? api.getSignatureType() : config.getSignatureType(); + switch (signatureType) { case Header: config.log("using Http Header signature"); @@ -194,7 +198,7 @@ private void appendSignature(OAuthRequest request) { } break; default: - throw new IllegalStateException("Unknown new Signature Type '" + config.getSignatureType() + "'."); + throw new IllegalStateException("Unknown new Signature Type '" + signatureType + "'."); } } diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/builder/ServiceBuilderTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/builder/ServiceBuilderTest.java index 57f7d62e2..6654c15b4 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/builder/ServiceBuilderTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/builder/ServiceBuilderTest.java @@ -6,7 +6,7 @@ import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; -import com.github.scribejava.core.model.SignatureType; +import com.github.scribejava.core.builder.api.OAuth1SignatureType; import com.github.scribejava.core.oauth.OAuth20Service; public class ServiceBuilderTest { @@ -21,6 +21,7 @@ public void setUp() { } @Test + @SuppressWarnings("deprecation") public void shouldReturnConfigDefaultValues() { builder.apiKey("key").apiSecret("secret").build(api); @@ -28,7 +29,7 @@ public void shouldReturnConfigDefaultValues() { assertEquals(config.getApiKey(), "key"); assertEquals(config.getApiSecret(), "secret"); assertEquals(config.getCallback(), OAuthConstants.OUT_OF_BAND); - assertEquals(config.getSignatureType(), SignatureType.Header); + assertEquals(config.getSignatureType(), null); } @Test @@ -42,13 +43,14 @@ public void shouldAcceptValidCallbackUrl() { } @Test + @SuppressWarnings("deprecation") public void shouldAcceptASignatureType() { - builder.apiKey("key").apiSecret("secret").signatureType(SignatureType.QueryString).build(api); + builder.apiKey("key").apiSecret("secret").signatureType(OAuth1SignatureType.QueryString).build(api); final OAuthConfig config = api.getConfig(); assertEquals(config.getApiKey(), "key"); assertEquals(config.getApiSecret(), "secret"); - assertEquals(config.getSignatureType(), SignatureType.QueryString); + assertEquals(config.getSignatureType(), OAuth1SignatureType.QueryString); } @Test(expected = IllegalArgumentException.class) diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ApiUnit.java b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ApiUnit.java index 55e04a461..c6c05e05c 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ApiUnit.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ApiUnit.java @@ -1,7 +1,7 @@ package com.github.scribejava.core.oauth; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.builder.api.SignatureType; +import com.github.scribejava.core.builder.api.OAuth2SignatureType; import com.github.scribejava.core.model.OAuthConfig; class OAuth20ApiUnit extends DefaultApi20 { @@ -22,7 +22,7 @@ public OAuth20Service createService(OAuthConfig config) { } @Override - public SignatureType getSignatureType() { - return SignatureType.BEARER_URI_QUERY_PARAMETER; + public OAuth2SignatureType getSignatureType() { + return OAuth2SignatureType.BEARER_URI_QUERY_PARAMETER; } } diff --git a/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClientTest.java b/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClientTest.java index 92ef44423..496882cdd 100644 --- a/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClientTest.java +++ b/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClientTest.java @@ -27,7 +27,7 @@ public class OkHttpHttpClientTest { public void setUp() { final HttpClient client = new OkHttpHttpClient(new OkHttpClient()); oAuthService = new OAuth20Service(null, - new OAuthConfig("test", "test", null, null, null, null, null, null, null, null, client)); + new OAuthConfig("test", "test", null, null, null, null, null, null, null, client)); } From ac8ff60ed008e43202d826d7ba7f21a881825e44 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 4 Apr 2017 17:35:20 +0300 Subject: [PATCH 360/882] make client_secret optional in OAuth2 while requesting AccessToken (if set to null, it's not required by OAuth2 specs) --- changelog | 1 + .../com/github/scribejava/core/oauth/OAuth20Service.java | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/changelog b/changelog index 359cd2c75..0e4300df6 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,5 @@ [SNAPSHOT] + * make client_secret optional in OAuth2 while requesting AccessToken (if set to null, it's not required by OAuth2 specs) * move OAuth1 SignatureType to ServiceBuilder to API * add body for PATCH HTTP method 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 fadf54800..8174a8e51 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 @@ -102,7 +102,10 @@ protected OAuthRequest createAccessTokenRequest(String code) { final OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint()); final OAuthConfig config = getConfig(); request.addParameter(OAuthConstants.CLIENT_ID, config.getApiKey()); - request.addParameter(OAuthConstants.CLIENT_SECRET, config.getApiSecret()); + final String apiSecret = config.getApiSecret(); + if (apiSecret != null) { + request.addParameter(OAuthConstants.CLIENT_SECRET, apiSecret); + } request.addParameter(OAuthConstants.CODE, code); request.addParameter(OAuthConstants.REDIRECT_URI, config.getCallback()); final String scope = config.getScope(); From a2887ddc0d724c22a3071eb9c44c8c3db6505bb9 Mon Sep 17 00:00:00 2001 From: Vivin Paliath Date: Wed, 29 Mar 2017 10:50:01 -0700 Subject: [PATCH 361/882] issue #753 Makes `addOAuthParams` and `appendSignature` `protected`, so that they can be used from overridden `prepareRequestTokenRequest` methods in subclasses. This makes it possible to deal with the (rare) case where the request-token endpoint in an OAuth 1.0a service accepts additional-parameters; these are supported by request-token endpoints as per the specification. --- .../com/github/scribejava/core/oauth/OAuth10aService.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 d9332d03b..c1291646f 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 @@ -75,7 +75,7 @@ protected OAuthRequest prepareRequestTokenRequest() { return request; } - private void addOAuthParams(OAuthRequest request, String tokenSecret) { + protected void addOAuthParams(OAuthRequest request, String tokenSecret) { final OAuthConfig config = getConfig(); request.addOAuthParameter(OAuthConstants.TIMESTAMP, api.getTimestampService().getTimestampInSeconds()); request.addOAuthParameter(OAuthConstants.NONCE, api.getTimestampService().getNonce()); @@ -177,7 +177,7 @@ private String getSignature(OAuthRequest request, String tokenSecret) { return signature; } - private void appendSignature(OAuthRequest request) { + protected void appendSignature(OAuthRequest request) { final OAuthConfig config = getConfig(); switch (config.getSignatureType()) { case Header: From cad7e9a4ddc68e840e49721bbf1206e29c721c4d Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 10 Apr 2017 12:47:21 +0300 Subject: [PATCH 362/882] refactor example a bit --- .../apis/examples/SalesforceExample.java | 17 +++++++++++++---- .../examples/SalesforceNingAsyncExample.java | 17 +++++++++++++---- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceExample.java index e47fbaeea..925819a7b 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceExample.java @@ -8,6 +8,7 @@ import com.github.scribejava.apis.SalesforceApi; import com.github.scribejava.apis.salesforce.SalesforceToken; 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; @@ -66,13 +67,21 @@ public static void main(String... args) throws IOException, NoSuchAlgorithmExcep // Trade the Request Token and Verifier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - final SalesforceToken accessToken = (SalesforceToken) service.getAccessToken(codeEncoded); + + final OAuth2AccessToken accessToken = service.getAccessToken(codeEncoded); + final SalesforceToken salesforceAccessToken; + if (accessToken instanceof SalesforceToken) { + salesforceAccessToken = (SalesforceToken) accessToken; + } else { + throw new IllegalStateException("Salesforce API didn't return SalesforceToken."); + } System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken + ", 'rawResponse'='" + + System.out.println("(if your curious it looks like this: " + salesforceAccessToken + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); System.out.println(); - System.out.println("instance_url is: " + accessToken.getInstanceUrl()); + System.out.println("instance_url is: " + salesforceAccessToken.getInstanceUrl()); // Now let's go and ask for a protected resource! System.out.println("Now we're reading accounts from the Salesforce org (maxing them to 10)."); @@ -81,7 +90,7 @@ public static void main(String... args) throws IOException, NoSuchAlgorithmExcep final String queryEncoded = URLEncoder.encode("Select Id, Name from Account LIMIT 10", "UTF-8"); // Building the query URI. We've parsed the instance URL from the accessToken request. - final String url = accessToken.getInstanceUrl() + "/services/data/v36.0/query?q=" + queryEncoded; + final String url = salesforceAccessToken.getInstanceUrl() + "/services/data/v36.0/query?q=" + queryEncoded; System.out.println(); System.out.println("Full URL: " + url); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceNingAsyncExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceNingAsyncExample.java index 2cf040a45..36a060123 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceNingAsyncExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceNingAsyncExample.java @@ -11,6 +11,7 @@ import com.github.scribejava.apis.salesforce.SalesforceToken; import com.github.scribejava.httpclient.ning.NingHttpClientConfig; 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; @@ -67,19 +68,27 @@ public static void main(String... args) throws InterruptedException, ExecutionEx final String codeEncoded = URLDecoder.decode(code, "UTF-8"); // Trade the Request Token and Verifier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - final SalesforceToken accessToken = (SalesforceToken) service.getAccessToken(codeEncoded); + + final OAuth2AccessToken accessToken = service.getAccessToken(codeEncoded); + final SalesforceToken salesforceAccessToken; + if (accessToken instanceof SalesforceToken) { + salesforceAccessToken = (SalesforceToken) accessToken; + } else { + throw new IllegalStateException("Salesforce API didn't return SalesforceToken."); + } System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken + + System.out.println("(if your curious it looks like this: " + salesforceAccessToken + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); System.out.println(); - System.out.println("Instance is: " + accessToken.getInstanceUrl()); + System.out.println("Instance is: " + salesforceAccessToken.getInstanceUrl()); // Now let's go and ask for a protected resource! System.out.println("Now we're reading accounts from the Salesforce org (maxing them to 10)."); // Sample SOQL statement final String queryEncoded = URLEncoder.encode("Select Id, Name from Account LIMIT 10", "UTF-8"); // Building the query URI. We've parsed the instance URL from the // accessToken request. - final String url = accessToken.getInstanceUrl() + "/services/data/v36.0/query?q=" + queryEncoded; + final String url = salesforceAccessToken.getInstanceUrl() + "/services/data/v36.0/query?q=" + queryEncoded; System.out.println(); System.out.println("Full URL: " + url); final OAuthRequest request = new OAuthRequest(Verb.GET, url); From 04f42bbb97019171a8c4ce6f297680b7063dde7f Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 10 Apr 2017 13:38:01 +0300 Subject: [PATCH 363/882] update maven deps --- pom.xml | 4 ++-- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index 8be793348..ba06a1035 100644 --- a/pom.xml +++ b/pom.xml @@ -103,7 +103,7 @@ org.apache.felix maven-bundle-plugin - 3.2.0 + 3.3.0 bundle-manifest @@ -132,7 +132,7 @@ com.puppycrawl.tools checkstyle - 7.4 + 7.6.1 diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 8c78da1cd..d4ff34885 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -23,7 +23,7 @@ org.asynchttpclient async-http-client - 2.0.26 + 2.0.31 diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 171ba7cd0..8c2b45af1 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -23,12 +23,12 @@ com.squareup.okhttp3 okhttp - 3.5.0 + 3.6.0 com.squareup.okhttp3 mockwebserver - 3.5.0 + 3.6.0 test From 6548aaba76571278dcc1e7168d5bf28c80a3e16d Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 18 Apr 2017 11:26:05 +0300 Subject: [PATCH 364/882] add changelog entry --- changelog | 1 + 1 file changed, 1 insertion(+) diff --git a/changelog b/changelog index 0e4300df6..3fe88d590 100644 --- a/changelog +++ b/changelog @@ -2,6 +2,7 @@ * make client_secret optional in OAuth2 while requesting AccessToken (if set to null, it's not required by OAuth2 specs) * move OAuth1 SignatureType to 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) [4.0.0] * Remove OAuthRequestAsync, just OAuthRequest. Request should know about sync vs async. Move default Http engine to JDKHttpClient. From 3d10ecad0fe36887dbc298e749431d1f137ff51e Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 18 Apr 2017 11:47:26 +0300 Subject: [PATCH 365/882] fix typo in changelog --- changelog | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog b/changelog index 3fe88d590..8f626f359 100644 --- a/changelog +++ b/changelog @@ -1,6 +1,6 @@ [SNAPSHOT] * make client_secret optional in OAuth2 while requesting AccessToken (if set to null, it's not required by OAuth2 specs) - * move OAuth1 SignatureType to ServiceBuilder to API + * 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) From 32be73a4fb7479fcaf200eedbc83318133467882 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 18 Apr 2017 11:48:34 +0300 Subject: [PATCH 366/882] prepare 4.1.0 release --- README.md | 4 ++-- changelog | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 156f924fb..e1fdf095e 100644 --- a/README.md +++ b/README.md @@ -100,7 +100,7 @@ You can pull ScribeJava from the central maven repository, just add these to you com.github.scribejava scribejava-apis - 4.0.0 + 4.1.0 ``` @@ -109,7 +109,7 @@ And in case you need just core classes (that's it, without any external API (FB, com.github.scribejava scribejava-core - 4.0.0 + 4.1.0 ``` diff --git a/changelog b/changelog index 8f626f359..2a6598599 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,4 @@ -[SNAPSHOT] +[4.1.0] * 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 From 08afa0d96e7da433035eeab273cee095da297fb4 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 18 Apr 2017 11:50:05 +0300 Subject: [PATCH 367/882] [maven-release-plugin] prepare release scribejava-4.1.0 --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/pom.xml b/pom.xml index ba06a1035..7dc377c7e 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 4.0.1-SNAPSHOT + 4.1.0 ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -33,7 +33,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - HEAD + scribejava-4.1.0 diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index d317b3998..327ca9e68 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 4.0.1-SNAPSHOT + 4.1.0 ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 00dee881e..0817d3390 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 4.0.1-SNAPSHOT + 4.1.0 ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index d4ff34885..d1adebfe3 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 4.0.1-SNAPSHOT + 4.1.0 ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index 6449b91cc..5fe6be24d 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 4.0.1-SNAPSHOT + 4.1.0 ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 8c2b45af1..94d74190c 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 4.0.1-SNAPSHOT + 4.1.0 ../pom.xml From c09046936a6518a53612b6ca66d8ae1fcc1a72c2 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 18 Apr 2017 11:50:12 +0300 Subject: [PATCH 368/882] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/pom.xml b/pom.xml index 7dc377c7e..4b61d03ae 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 4.1.0 + 4.1.1-SNAPSHOT ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -33,7 +33,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - scribejava-4.1.0 + HEAD diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 327ca9e68..237f2586f 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 4.1.0 + 4.1.1-SNAPSHOT ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 0817d3390..4101caf4b 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 4.1.0 + 4.1.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index d1adebfe3..e3da50259 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 4.1.0 + 4.1.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index 5fe6be24d..1f8283d29 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 4.1.0 + 4.1.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 94d74190c..89cf81ef0 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 4.1.0 + 4.1.1-SNAPSHOT ../pom.xml From 2b0dce249d35ef35d2f9a84172aa609f39844690 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 19 Apr 2017 12:21:31 +0300 Subject: [PATCH 369/882] remove deprecated code --- changelog | 2 + .../core/builder/ServiceBuilder.java | 29 +----------- .../core/builder/api/SignatureType.java | 34 -------------- .../scribejava/core/model/OAuthConfig.java | 47 ------------------- .../scribejava/core/model/SignatureType.java | 11 ----- .../core/oauth/OAuth10aService.java | 4 +- .../scribejava/core/oauth/OAuth20Service.java | 34 -------------- .../core/builder/ServiceBuilderTest.java | 14 ------ 8 files changed, 5 insertions(+), 170 deletions(-) delete mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/builder/api/SignatureType.java delete mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/model/SignatureType.java diff --git a/changelog b/changelog index 2a6598599..0378202e7 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,5 @@ +[SNAPSHOT] + [4.1.0] * 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 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 b0a6067db..d44b784fd 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 @@ -5,7 +5,6 @@ import com.github.scribejava.core.httpclient.HttpClientConfig; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; -import com.github.scribejava.core.builder.api.OAuth1SignatureType; import com.github.scribejava.core.oauth.OAuthService; import com.github.scribejava.core.utils.Preconditions; @@ -21,12 +20,6 @@ public class ServiceBuilder { private String apiSecret; private String scope; private String state; - /** - * @deprecated override or change in Pull Request - * {@link com.github.scribejava.core.builder.api.DefaultApi10a#getSignatureType()} - */ - @Deprecated - private OAuth1SignatureType signatureType; private OutputStream debugStream; private String responseType = "code"; private String userAgent; @@ -98,23 +91,6 @@ public ServiceBuilder state(String state) { return this; } - /** - * Configures the signature type, choose between header, querystring, etc. Defaults to null.
- * 'null' means to use default for API - * {@link com.github.scribejava.core.builder.api.DefaultApi10a#getSignatureType()} - * - * @param signatureType OAuth1SignatureType - * @return the {@link ServiceBuilder} instance for method chaining - * - * @deprecated override or change in Pull Request - * {@link com.github.scribejava.core.builder.api.DefaultApi10a#getSignatureType()} - */ - @Deprecated - public ServiceBuilder signatureType(OAuth1SignatureType signatureType) { - this.signatureType = signatureType; - return this; - } - public ServiceBuilder debugStream(OutputStream debugStream) { Preconditions.checkNotNull(debugStream, "debug stream can't be null"); this.debugStream = debugStream; @@ -158,11 +134,10 @@ public void checkPreconditions() { Preconditions.checkEmptyString(apiKey, "You must provide an api key"); } - @SuppressWarnings("deprecation") private OAuthConfig createConfig() { checkPreconditions(); - return new OAuthConfig(apiKey, apiSecret, callback, signatureType, scope, debugStream, state, responseType, - userAgent, httpClientConfig, httpClient); + return new OAuthConfig(apiKey, apiSecret, callback, scope, debugStream, state, responseType, userAgent, + httpClientConfig, httpClient); } /** diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/SignatureType.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/SignatureType.java deleted file mode 100644 index 3429b64b5..000000000 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/SignatureType.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.github.scribejava.core.builder.api; - -import com.github.scribejava.core.model.OAuth2AccessToken; -import com.github.scribejava.core.model.OAuthConstants; -import com.github.scribejava.core.model.OAuthRequest; - -/** - * @deprecated renamed to {@link OAuth2SignatureType} - */ -@Deprecated -public enum SignatureType { - /** - * https://tools.ietf.org/html/rfc6750#section-2.1 - */ - BEARER_AUTHORIZATION_REQUEST_HEADER_FIELD { - @Override - public void signRequest(OAuth2AccessToken accessToken, OAuthRequest request) { - request.addHeader("Authorization", "Bearer " + accessToken.getAccessToken()); - } - - }, - /** - * https://tools.ietf.org/html/rfc6750#section-2.3 - */ - BEARER_URI_QUERY_PARAMETER { - @Override - public void signRequest(OAuth2AccessToken accessToken, OAuthRequest request) { - request.addQuerystringParameter(OAuthConstants.ACCESS_TOKEN, accessToken.getAccessToken()); - } - - }; - - public abstract void signRequest(OAuth2AccessToken accessToken, OAuthRequest request); -} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConfig.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConfig.java index 929fc97cc..244ca6731 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConfig.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConfig.java @@ -1,6 +1,5 @@ package com.github.scribejava.core.model; -import com.github.scribejava.core.builder.api.OAuth1SignatureType; import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.httpclient.HttpClientConfig; import java.io.IOException; @@ -14,12 +13,6 @@ public class OAuthConfig { private final String apiKey; private final String apiSecret; private final String callback; - /** - * @deprecated override or change in Pull Request - * {@link com.github.scribejava.core.builder.api.DefaultApi10a#getSignatureType()} - */ - @Deprecated - private OAuth1SignatureType signatureType; private final String scope; private final OutputStream debugStream; private final String state; @@ -33,35 +26,6 @@ public OAuthConfig(String key, String secret) { this(key, secret, null, null, null, null, null, null, null, null); } - /** - * @param apiKey apiKey - * @param apiSecret apiSecret - * @param callback callback - * @param signatureType signatureType - * @param scope scope - * @param debugStream debugStream - * @param state state - * @param responseType responseType - * @param userAgent userAgent - * @param httpClientConfig httpClientConfig - * @param httpClient httpClient - * - * @deprecated use {@link #OAuthConfig(java.lang.String, java.lang.String, java.lang.String, java.lang.String, - * java.io.OutputStream, java.lang.String, java.lang.String, java.lang.String, - * com.github.scribejava.core.httpclient.HttpClientConfig, com.github.scribejava.core.httpclient.HttpClient)} - *
- * without OAuth1SignatureType param. to change OAuth1SignatureType override or change in Pull Request - *
{@link com.github.scribejava.core.builder.api.DefaultApi10a#getSignatureType()} - */ - @Deprecated - public OAuthConfig(String apiKey, String apiSecret, String callback, OAuth1SignatureType signatureType, - String scope, OutputStream debugStream, String state, String responseType, String userAgent, - HttpClientConfig httpClientConfig, HttpClient httpClient) { - this(apiKey, apiSecret, callback, scope, debugStream, state, responseType, userAgent, httpClientConfig, - httpClient); - this.signatureType = signatureType; - } - public OAuthConfig(String apiKey, String apiSecret, String callback, String scope, OutputStream debugStream, String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { @@ -89,17 +53,6 @@ public String getCallback() { return callback; } - /** - * @return configured OAuth1SignatureType to override from API - * - * @deprecated override or change in Pull Request - * {@link com.github.scribejava.core.builder.api.DefaultApi10a#getSignatureType()} - */ - @Deprecated - public OAuth1SignatureType getSignatureType() { - return signatureType; - } - public String getScope() { return scope; } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/SignatureType.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/SignatureType.java deleted file mode 100644 index 5e6dd91a7..000000000 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/SignatureType.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.github.scribejava.core.model; - -/** - * @deprecated renamed to {@link com.github.scribejava.core.builder.api.OAuth1SignatureType} - */ -@Deprecated -public enum SignatureType { - - Header, - QueryString -} 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 455ed542d..ad9e6eda0 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 @@ -180,9 +180,7 @@ private String getSignature(OAuthRequest request, String tokenSecret) { protected void appendSignature(OAuthRequest request) { final OAuthConfig config = getConfig(); - @SuppressWarnings("deprecation") - final OAuth1SignatureType signatureType - = config.getSignatureType() == null ? api.getSignatureType() : config.getSignatureType(); + final OAuth1SignatureType signatureType = api.getSignatureType(); switch (signatureType) { case Header: config.log("using Http Header signature"); diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java index 8174a8e51..1f87a1704 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 @@ -58,24 +58,6 @@ public final Future getAccessTokenAsync(String code) { return getAccessToken(code, null); } - /** - * Start the request to retrieve the access token. The optionally provided callback will be called with the Token - * when it is available. - * - * @param code code - * @param callback optional callback - * @return Future - * @deprecated user {@link #getAccessToken(java.lang.String, - * com.github.scribejava.core.model.OAuthAsyncRequestCallback) } - */ - @Deprecated - public final Future getAccessTokenAsync(String code, - OAuthAsyncRequestCallback callback) { - final OAuthRequest request = createAccessTokenRequest(code); - - return sendAccessTokenRequestAsync(request, callback); - } - public final OAuth2AccessToken getAccessToken(String code) throws IOException, InterruptedException, ExecutionException { final OAuthRequest request = createAccessTokenRequest(code); @@ -120,22 +102,6 @@ public final Future refreshAccessTokenAsync(String refreshTok return refreshAccessToken(refreshToken, null); } - /** - * - * @param refreshToken refreshToken - * @param callback callback - * @return future - * @deprecated use {@link #refreshAccessToken(java.lang.String, - * com.github.scribejava.core.model.OAuthAsyncRequestCallback)} - */ - @Deprecated - public final Future refreshAccessTokenAsync(String refreshToken, - OAuthAsyncRequestCallback callback) { - final OAuthRequest request = createRefreshTokenRequest(refreshToken); - - return sendAccessTokenRequestAsync(request, callback); - } - public final OAuth2AccessToken refreshAccessToken(String refreshToken) throws IOException, InterruptedException, ExecutionException { final OAuthRequest request = createRefreshTokenRequest(refreshToken); diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/builder/ServiceBuilderTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/builder/ServiceBuilderTest.java index 6654c15b4..3aa88699a 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/builder/ServiceBuilderTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/builder/ServiceBuilderTest.java @@ -6,7 +6,6 @@ import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; -import com.github.scribejava.core.builder.api.OAuth1SignatureType; import com.github.scribejava.core.oauth.OAuth20Service; public class ServiceBuilderTest { @@ -21,7 +20,6 @@ public void setUp() { } @Test - @SuppressWarnings("deprecation") public void shouldReturnConfigDefaultValues() { builder.apiKey("key").apiSecret("secret").build(api); @@ -29,7 +27,6 @@ public void shouldReturnConfigDefaultValues() { assertEquals(config.getApiKey(), "key"); assertEquals(config.getApiSecret(), "secret"); assertEquals(config.getCallback(), OAuthConstants.OUT_OF_BAND); - assertEquals(config.getSignatureType(), null); } @Test @@ -42,17 +39,6 @@ public void shouldAcceptValidCallbackUrl() { assertEquals(config.getCallback(), "http://example.com"); } - @Test - @SuppressWarnings("deprecation") - public void shouldAcceptASignatureType() { - builder.apiKey("key").apiSecret("secret").signatureType(OAuth1SignatureType.QueryString).build(api); - - final OAuthConfig config = api.getConfig(); - assertEquals(config.getApiKey(), "key"); - assertEquals(config.getApiSecret(), "secret"); - assertEquals(config.getSignatureType(), OAuth1SignatureType.QueryString); - } - @Test(expected = IllegalArgumentException.class) public void shouldNotAcceptNullAsCallback() { builder.apiKey("key").apiSecret("secret").callback(null).build(api); From 97c03a04f3173bf9fe9eb09aeaa9b26d3d1a637a Mon Sep 17 00:00:00 2001 From: KungfuPancake Date: Sun, 23 Apr 2017 17:13:34 +0200 Subject: [PATCH 370/882] Only add secret key if set --- .../java/com/github/scribejava/core/oauth/OAuth20Service.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java index 1f87a1704..75ac7166b 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 @@ -123,7 +123,9 @@ protected OAuthRequest createRefreshTokenRequest(String refreshToken) { final OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getRefreshTokenEndpoint()); final OAuthConfig config = getConfig(); request.addParameter(OAuthConstants.CLIENT_ID, config.getApiKey()); - request.addParameter(OAuthConstants.CLIENT_SECRET, config.getApiSecret()); + if (config.getApiSecret() != null) { + request.addParameter(OAuthConstants.CLIENT_SECRET, config.getApiSecret()); + } request.addParameter(OAuthConstants.REFRESH_TOKEN, refreshToken); request.addParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.REFRESH_TOKEN); return request; From 4fcfe672ea3c5f1abc2fcf46b6c9ec6b5c63669e Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 24 Apr 2017 10:08:21 +0300 Subject: [PATCH 371/882] add javadoc for JDKHttpFuture --- .../github/scribejava/core/httpclient/jdk/JDKHttpFuture.java | 4 ++++ 1 file changed, 4 insertions(+) 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 14d95ec80..5de4dbc87 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 @@ -5,6 +5,10 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; +/** + * 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. + */ public class JDKHttpFuture implements Future { private final Exception exception; From 99359dfbbf06f6dd6dc66992f3d095ccdc7ce8d1 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 24 Apr 2017 10:13:17 +0300 Subject: [PATCH 372/882] add more javadoc for JDKHttpFuture --- .../github/scribejava/core/httpclient/jdk/JDKHttpFuture.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 5de4dbc87..1922d3aef 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpFuture.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpFuture.java @@ -7,7 +7,7 @@ /** * 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. + * That's it. Sync execution with Async methods. This class does NOT provide any async executions. */ public class JDKHttpFuture implements Future { From 4ebafd508cbab78810cc735d27dd75d82a069a48 Mon Sep 17 00:00:00 2001 From: Roger Hu Date: Mon, 24 Apr 2017 01:31:01 -0700 Subject: [PATCH 373/882] Allow perms to be specified in Flickr Api (read, write, or delete) --- .../com/github/scribejava/apis/FlickrApi.java | 33 ++++++++- .../apis/examples/FlickrExampleWithPerms.java | 72 +++++++++++++++++++ 2 files changed, 103 insertions(+), 2 deletions(-) create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExampleWithPerms.java diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/FlickrApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/FlickrApi.java index 0e1db4ea7..e3dcc1795 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/FlickrApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/FlickrApi.java @@ -10,7 +10,29 @@ */ public class FlickrApi extends DefaultApi10a { - protected FlickrApi() { + private static final String AUTHORIZE_URL = "https://www.flickr.com/services/oauth/authorize?oauth_token=%s"; + + public enum FLICKR_PERM { + READ, WRITE, DELETE + }; + + private String permString; /* read, write, or delete (delete includes read/write) */ + + public FlickrApi() { + permString = null; + } + + public FlickrApi(FLICKR_PERM perm) { + switch(perm) { + case READ: + this.permString = "read"; + break; + case WRITE: + this.permString = "write"; + break; + case DELETE: + this.permString = "delete"; + } } private static class InstanceHolder { @@ -21,6 +43,7 @@ public static FlickrApi instance() { return InstanceHolder.INSTANCE; } + /** * {@inheritDoc} */ @@ -34,7 +57,13 @@ public String getAccessTokenEndpoint() { */ @Override public String getAuthorizationUrl(OAuth1RequestToken requestToken) { - return "https://www.flickr.com/services/oauth/authorize?oauth_token=" + requestToken.getToken(); + String authUrl = String.format(AUTHORIZE_URL, requestToken.getToken()); + + if (permString != null) { + authUrl += "&perms=" + permString; + } + + return authUrl; } /** diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExampleWithPerms.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExampleWithPerms.java new file mode 100644 index 000000000..aba762e82 --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExampleWithPerms.java @@ -0,0 +1,72 @@ +package com.github.scribejava.apis.examples; + +import com.github.scribejava.apis.FlickrApi; +import com.github.scribejava.core.builder.ServiceBuilder; +import com.github.scribejava.core.model.OAuth1AccessToken; +import com.github.scribejava.core.model.OAuth1RequestToken; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.oauth.OAuth10aService; + +import java.io.IOException; +import java.util.Scanner; +import java.util.concurrent.ExecutionException; + +public final class FlickrExampleWithPerms { + + private static final String PROTECTED_RESOURCE_URL = "http://api.flickr.com/services/rest/"; + + private FlickrExampleWithPerms() { + } + + public static void main(String... args) throws IOException, InterruptedException, ExecutionException { + // Replace these with your own api key and secret + final String apiKey = "your_app_id"; + final String apiSecret = "your_api_secret"; + + final OAuth10aService service = new ServiceBuilder() + .apiKey(apiKey) + .apiSecret(apiSecret) + .build(new FlickrApi(FlickrApi.FLICKR_PERM.DELETE)); + final Scanner in = new Scanner(System.in); + + System.out.println("=== Flickr's OAuth Workflow ==="); + System.out.println(); + + // Obtain the Request Token + System.out.println("Fetching the Request Token..."); + final OAuth1RequestToken requestToken = service.getRequestToken(); + System.out.println("Got the Request Token!"); + System.out.println(); + + System.out.println("Now go and authorize ScribeJava here:"); + final String authorizationUrl = service.getAuthorizationUrl(requestToken); + System.out.println(authorizationUrl); + System.out.println("And paste the verifier here"); + System.out.print(">>"); + final String oauthVerifier = in.nextLine(); + System.out.println(); + + // Trade the Request Token and Verfier for the Access Token + System.out.println("Trading the Request Token for an Access Token..."); + final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); + System.out.println("Got the Access Token!"); + System.out.println("(if your curious it looks like this: " + accessToken + + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println(); + + // Now let's go and ask for a protected resource! + System.out.println("Now we're going to access a protected resource..."); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); + request.addQuerystringParameter("method", "flickr.test.login"); + service.signRequest(accessToken, request); + final Response response = service.execute(request); + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getBody()); + + System.out.println(); + System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); + } +} From a85af76a38cb083875f9dd30777c163d2b8c89f4 Mon Sep 17 00:00:00 2001 From: Nikolaj Viguro Date: Tue, 2 May 2017 20:14:59 +0300 Subject: [PATCH 374/882] In POST request body params does not calculated in signature --- .../service/OdnoklassnikiServiceImpl.java | 45 ++++++++++++------- 1 file changed, 28 insertions(+), 17 deletions(-) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiServiceImpl.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiServiceImpl.java index 9de7f8fa2..70f18c781 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiServiceImpl.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiServiceImpl.java @@ -1,15 +1,22 @@ package com.github.scribejava.apis.service; -import java.io.UnsupportedEncodingException; -import java.net.URLDecoder; -import org.apache.commons.codec.CharEncoding; -import static org.apache.commons.codec.digest.DigestUtils.md5Hex; import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Parameter; +import com.github.scribejava.core.model.ParameterList; import com.github.scribejava.core.oauth.OAuth20Service; -import java.util.Arrays; + +import org.apache.commons.codec.CharEncoding; + +import java.io.UnsupportedEncodingException; +import java.net.URLDecoder; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import static org.apache.commons.codec.digest.DigestUtils.md5Hex; public class OdnoklassnikiServiceImpl extends OAuth20Service { @@ -23,20 +30,24 @@ public void signRequest(OAuth2AccessToken accessToken, OAuthRequest request) { try { final String tokenDigest = md5Hex(accessToken.getAccessToken() + getConfig().getApiSecret()); - final String completeUrl = request.getCompleteUrl(); - final int queryIndex = completeUrl.indexOf('?'); - if (queryIndex != -1) { - final String[] params = completeUrl.substring(queryIndex + 1).split("&"); - Arrays.sort(params); - final StringBuilder builder = new StringBuilder(); - for (String param : params) { - builder.append(param); - } - - final String sigSource = URLDecoder.decode(builder.toString(), CharEncoding.UTF_8) + tokenDigest; - request.addQuerystringParameter("sig", md5Hex(sigSource).toLowerCase()); + ParameterList queryParams = request.getQueryStringParams(); + ParameterList bodyParams = request.getBodyParams(); + queryParams.addAll(bodyParams); + Collections.sort(queryParams.getParams()); + + List params = new ArrayList<>(); + for(Parameter param : queryParams.getParams()) { + params.add(param.getKey().concat("=").concat(param.getValue())); } + final StringBuilder builder = new StringBuilder(); + for (String param : params) { + builder.append(param); + } + + final String sigSource = URLDecoder.decode(builder.toString(), CharEncoding.UTF_8) + tokenDigest; + request.addQuerystringParameter("sig", md5Hex(sigSource).toLowerCase()); + super.signRequest(accessToken, request); } catch (UnsupportedEncodingException unex) { throw new IllegalStateException(unex); From c1d9a5464177ea7955cfc26529cfb49eb409504f Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 15 May 2017 14:43:51 +0300 Subject: [PATCH 375/882] omit the client_secret parameter if it is an empty string while refreshing token (thanks to https://github.com/KungfuPancake) --- changelog | 1 + .../com/github/scribejava/core/oauth/OAuth20Service.java | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/changelog b/changelog index 0378202e7..5f47b7951 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,5 @@ [SNAPSHOT] + * omit the client_secret parameter if it is an empty string while refreshing token (thanks to https://github.com/KungfuPancake) [4.1.0] * make client_secret optional in OAuth2 while requesting AccessToken (if set to null, it's not required by OAuth2 specs) 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 75ac7166b..4565a4165 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 @@ -123,8 +123,9 @@ protected OAuthRequest createRefreshTokenRequest(String refreshToken) { final OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getRefreshTokenEndpoint()); final OAuthConfig config = getConfig(); request.addParameter(OAuthConstants.CLIENT_ID, config.getApiKey()); - if (config.getApiSecret() != null) { - request.addParameter(OAuthConstants.CLIENT_SECRET, config.getApiSecret()); + final String apiSecret = config.getApiSecret(); + if (apiSecret != null) { + request.addParameter(OAuthConstants.CLIENT_SECRET, apiSecret); } request.addParameter(OAuthConstants.REFRESH_TOKEN, refreshToken); request.addParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.REFRESH_TOKEN); From 00b9d73052e538caaec40751ad9f8ffd5a34c623 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 15 May 2017 15:03:47 +0300 Subject: [PATCH 376/882] allow perms to be specified in Flickr Api (read, write, or delete) (thanks to https://github.com/rogerhu) --- changelog | 1 + .../com/github/scribejava/apis/FlickrApi.java | 22 +++--- .../apis/examples/FlickrExample.java | 10 +-- .../apis/examples/FlickrExampleWithPerms.java | 72 ------------------- 4 files changed, 15 insertions(+), 90 deletions(-) delete mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExampleWithPerms.java diff --git a/changelog b/changelog index 5f47b7951..3ba477b86 100644 --- a/changelog +++ b/changelog @@ -1,5 +1,6 @@ [SNAPSHOT] * 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) [4.1.0] * make client_secret optional in OAuth2 while requesting AccessToken (if set to null, it's not required by OAuth2 specs) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/FlickrApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/FlickrApi.java index e3dcc1795..b4a8b37b7 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/FlickrApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/FlickrApi.java @@ -12,27 +12,21 @@ public class FlickrApi extends DefaultApi10a { private static final String AUTHORIZE_URL = "https://www.flickr.com/services/oauth/authorize?oauth_token=%s"; - public enum FLICKR_PERM { + public enum FlickrPerm { READ, WRITE, DELETE }; - private String permString; /* read, write, or delete (delete includes read/write) */ + /** + * read, write, or delete (delete includes read/write) + */ + private final String permString; - public FlickrApi() { + protected FlickrApi() { permString = null; } - public FlickrApi(FLICKR_PERM perm) { - switch(perm) { - case READ: - this.permString = "read"; - break; - case WRITE: - this.permString = "write"; - break; - case DELETE: - this.permString = "delete"; - } + public FlickrApi(FlickrPerm perm) { + permString = perm.name().toLowerCase(); } private static class InstanceHolder { diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExample.java index 7165844bf..f7240f397 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExample.java @@ -1,15 +1,16 @@ package com.github.scribejava.apis.examples; -import java.util.Scanner; -import com.github.scribejava.core.builder.ServiceBuilder; import com.github.scribejava.apis.FlickrApi; +import com.github.scribejava.core.builder.ServiceBuilder; import com.github.scribejava.core.model.OAuth1AccessToken; import com.github.scribejava.core.model.OAuth1RequestToken; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.oauth.OAuth10aService; + import java.io.IOException; +import java.util.Scanner; import java.util.concurrent.ExecutionException; public final class FlickrExample { @@ -23,10 +24,11 @@ public static void main(String... args) throws IOException, InterruptedException // Replace these with your own api key and secret final String apiKey = "your_app_id"; final String apiSecret = "your_api_secret"; + final OAuth10aService service = new ServiceBuilder() .apiKey(apiKey) .apiSecret(apiSecret) - .build(FlickrApi.instance()); + .build(new FlickrApi(FlickrApi.FlickrPerm.DELETE)); final Scanner in = new Scanner(System.in); System.out.println("=== Flickr's OAuth Workflow ==="); @@ -40,7 +42,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Now go and authorize ScribeJava here:"); final String authorizationUrl = service.getAuthorizationUrl(requestToken); - System.out.println(authorizationUrl + "&perms=read"); + System.out.println(authorizationUrl); System.out.println("And paste the verifier here"); System.out.print(">>"); final String oauthVerifier = in.nextLine(); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExampleWithPerms.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExampleWithPerms.java deleted file mode 100644 index aba762e82..000000000 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExampleWithPerms.java +++ /dev/null @@ -1,72 +0,0 @@ -package com.github.scribejava.apis.examples; - -import com.github.scribejava.apis.FlickrApi; -import com.github.scribejava.core.builder.ServiceBuilder; -import com.github.scribejava.core.model.OAuth1AccessToken; -import com.github.scribejava.core.model.OAuth1RequestToken; -import com.github.scribejava.core.model.OAuthRequest; -import com.github.scribejava.core.model.Response; -import com.github.scribejava.core.model.Verb; -import com.github.scribejava.core.oauth.OAuth10aService; - -import java.io.IOException; -import java.util.Scanner; -import java.util.concurrent.ExecutionException; - -public final class FlickrExampleWithPerms { - - private static final String PROTECTED_RESOURCE_URL = "http://api.flickr.com/services/rest/"; - - private FlickrExampleWithPerms() { - } - - public static void main(String... args) throws IOException, InterruptedException, ExecutionException { - // Replace these with your own api key and secret - final String apiKey = "your_app_id"; - final String apiSecret = "your_api_secret"; - - final OAuth10aService service = new ServiceBuilder() - .apiKey(apiKey) - .apiSecret(apiSecret) - .build(new FlickrApi(FlickrApi.FLICKR_PERM.DELETE)); - final Scanner in = new Scanner(System.in); - - System.out.println("=== Flickr's OAuth Workflow ==="); - System.out.println(); - - // Obtain the Request Token - System.out.println("Fetching the Request Token..."); - final OAuth1RequestToken requestToken = service.getRequestToken(); - System.out.println("Got the Request Token!"); - System.out.println(); - - System.out.println("Now go and authorize ScribeJava here:"); - final String authorizationUrl = service.getAuthorizationUrl(requestToken); - System.out.println(authorizationUrl); - System.out.println("And paste the verifier here"); - System.out.print(">>"); - final String oauthVerifier = in.nextLine(); - System.out.println(); - - // Trade the Request Token and Verfier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); - final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); - System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); - System.out.println(); - - // Now let's go and ask for a protected resource! - System.out.println("Now we're going to access a protected resource..."); - final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); - request.addQuerystringParameter("method", "flickr.test.login"); - service.signRequest(accessToken, request); - final Response response = service.execute(request); - System.out.println("Got it! Lets see what we found..."); - System.out.println(); - System.out.println(response.getBody()); - - System.out.println(); - System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); - } -} From 04f69677cd00c1106ce63f52bcaeaf642a4ffc37 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 15 May 2017 15:10:15 +0300 Subject: [PATCH 377/882] use instance method for FlickrApi instead of constructor --- .../src/main/java/com/github/scribejava/apis/FlickrApi.java | 5 ++++- .../com/github/scribejava/apis/examples/FlickrExample.java | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/FlickrApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/FlickrApi.java index b4a8b37b7..f5ecca530 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/FlickrApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/FlickrApi.java @@ -25,7 +25,7 @@ protected FlickrApi() { permString = null; } - public FlickrApi(FlickrPerm perm) { + protected FlickrApi(FlickrPerm perm) { permString = perm.name().toLowerCase(); } @@ -37,6 +37,9 @@ public static FlickrApi instance() { return InstanceHolder.INSTANCE; } + public static FlickrApi instance(FlickrPerm perm) { + return perm == null ? instance() : new FlickrApi(perm); + } /** * {@inheritDoc} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExample.java index f7240f397..353431f46 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExample.java @@ -28,7 +28,7 @@ public static void main(String... args) throws IOException, InterruptedException final OAuth10aService service = new ServiceBuilder() .apiKey(apiKey) .apiSecret(apiSecret) - .build(new FlickrApi(FlickrApi.FlickrPerm.DELETE)); + .build(FlickrApi.instance(FlickrApi.FlickrPerm.DELETE)); final Scanner in = new Scanner(System.in); System.out.println("=== Flickr's OAuth Workflow ==="); From 6e3d2a2f00dcb46043c5b496ba02d4083384dbea Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 15 May 2017 15:19:35 +0300 Subject: [PATCH 378/882] improve LinkedInApi interface --- .../com/github/scribejava/apis/LinkedInApi.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi.java index 2d876ec5f..a9a4b5a99 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi.java @@ -10,11 +10,22 @@ public class LinkedInApi extends DefaultApi10a { private final String scopesAsString; + /** + * @deprecated use {@link #instance() } + */ + @Deprecated + //TODO: make protected in the next release public LinkedInApi() { scopesAsString = null; } + /** + * @deprecated use {@link #instance(java.lang.String...) } + */ + @Deprecated + //TODO: make protected in the next release public LinkedInApi(String... scopes) { + //TODO: deprecated check if (scopes == null || scopes.length == 0) { scopesAsString = null; } else { @@ -35,6 +46,10 @@ public static LinkedInApi instance() { return InstanceHolder.INSTANCE; } + public static LinkedInApi instance(String... scopes) { + return scopes == null || scopes.length == 0 ? instance() : new LinkedInApi(scopes); + } + @Override public String getAccessTokenEndpoint() { return "https://api.linkedin.com/uas/oauth/accessToken"; From 17e9220b72965a67726011e0f7255d9e2cb6cf4d Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 15 May 2017 17:29:45 +0300 Subject: [PATCH 379/882] do not open OutputStream for output while sending empty body in HTTP requests in the default JDK Http client --- .../scribejava/core/httpclient/jdk/JDKHttpClient.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java index 205c842b9..761f8be2a 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java @@ -151,12 +151,15 @@ private static void addHeaders(HttpURLConnection connection, Map } private static void addBody(HttpURLConnection connection, byte[] content) throws IOException { - connection.setRequestProperty(CONTENT_LENGTH, String.valueOf(content.length)); + final int contentLength = content.length; + connection.setRequestProperty(CONTENT_LENGTH, String.valueOf(contentLength)); if (connection.getRequestProperty(CONTENT_TYPE) == null) { connection.setRequestProperty(CONTENT_TYPE, DEFAULT_CONTENT_TYPE); } - connection.setDoOutput(true); - connection.getOutputStream().write(content); + if (contentLength > 0) { + connection.setDoOutput(true); + connection.getOutputStream().write(content); + } } } From 85e8e621dcb0d3e5457472e5a4c023fe6466c967 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 15 May 2017 17:50:13 +0300 Subject: [PATCH 380/882] OdnoklassnikiService should consider params in a body while signing the request (thanks to https://github.com/MrNeuronix) --- changelog | 1 + .../github/scribejava/apis/LinkedInApi.java | 1 + .../apis/service/OdnoklassnikiServiceImpl.java | 18 ++++++------------ 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/changelog b/changelog index 3ba477b86..e4253e62c 100644 --- a/changelog +++ b/changelog @@ -1,6 +1,7 @@ [SNAPSHOT] * 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) [4.1.0] * make client_secret optional in OAuth2 while requesting AccessToken (if set to null, it's not required by OAuth2 specs) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi.java index a9a4b5a99..fcefa5755 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi.java @@ -20,6 +20,7 @@ public LinkedInApi() { } /** + * @param scopes scopes * @deprecated use {@link #instance(java.lang.String...) } */ @Deprecated diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiServiceImpl.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiServiceImpl.java index 70f18c781..fa9ae2e56 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiServiceImpl.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiServiceImpl.java @@ -12,7 +12,6 @@ import java.io.UnsupportedEncodingException; import java.net.URLDecoder; -import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -30,19 +29,14 @@ public void signRequest(OAuth2AccessToken accessToken, OAuthRequest request) { try { final String tokenDigest = md5Hex(accessToken.getAccessToken() + getConfig().getApiSecret()); - ParameterList queryParams = request.getQueryStringParams(); - ParameterList bodyParams = request.getBodyParams(); - queryParams.addAll(bodyParams); - Collections.sort(queryParams.getParams()); - - List params = new ArrayList<>(); - for(Parameter param : queryParams.getParams()) { - params.add(param.getKey().concat("=").concat(param.getValue())); - } + final ParameterList queryParams = request.getQueryStringParams(); + queryParams.addAll(request.getBodyParams()); + final List allParams = queryParams.getParams(); + Collections.sort(allParams); final StringBuilder builder = new StringBuilder(); - for (String param : params) { - builder.append(param); + for (Parameter param : allParams) { + builder.append(param.getKey()).append('=').append(param.getValue()); } final String sigSource = URLDecoder.decode(builder.toString(), CharEncoding.UTF_8) + tokenDigest; From 9b0883436014a35d387b39989ec714f936c0f671 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 15 May 2017 18:20:46 +0300 Subject: [PATCH 381/882] update dependencies --- pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 4 ++-- .../github/scribejava/httpclient/okhttp/OkHttpHttpClient.java | 4 +++- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index 4b61d03ae..7a5758bf4 100644 --- a/pom.xml +++ b/pom.xml @@ -132,7 +132,7 @@ com.puppycrawl.tools checkstyle - 7.6.1 + 7.7
diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index e3da50259..a0bd4f8fb 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -23,7 +23,7 @@ org.asynchttpclient async-http-client - 2.0.31 + 2.0.32 diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 89cf81ef0..04d81c9d3 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -23,12 +23,12 @@ com.squareup.okhttp3 okhttp - 3.6.0 + 3.8.0 com.squareup.okhttp3 mockwebserver - 3.6.0 + 3.8.0 test diff --git a/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java b/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java index 1199c87de..66d2daee0 100644 --- a/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java +++ b/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java @@ -22,6 +22,7 @@ import java.util.concurrent.ExecutionException; import okhttp3.Cache; import okhttp3.Headers; +import okhttp3.ResponseBody; public class OkHttpHttpClient implements HttpClient { @@ -166,8 +167,9 @@ static Response convertResponse(okhttp3.Response okHttpResponse) { headersMap.put(name, headers.get(name)); } + final ResponseBody body = okHttpResponse.body(); return new Response(okHttpResponse.code(), okHttpResponse.message(), headersMap, - okHttpResponse.body().byteStream()); + body == null ? null : body.byteStream()); } } From 87bce806ac3aaf5ae8b9c865a671c2cc989ac36a Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 16 May 2017 11:29:33 +0300 Subject: [PATCH 382/882] prepare 4.1.1 release --- README.md | 4 ++-- changelog | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index e1fdf095e..808dc634e 100644 --- a/README.md +++ b/README.md @@ -100,7 +100,7 @@ You can pull ScribeJava from the central maven repository, just add these to you com.github.scribejava scribejava-apis - 4.1.0 + 4.1.1 ``` @@ -109,7 +109,7 @@ And in case you need just core classes (that's it, without any external API (FB, com.github.scribejava scribejava-core - 4.1.0 + 4.1.1 ``` diff --git a/changelog b/changelog index e4253e62c..55270bac7 100644 --- a/changelog +++ b/changelog @@ -1,7 +1,8 @@ -[SNAPSHOT] +[4.1.1] * 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) + * 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) From 2bbc8b065770461bd7aeae186ec93099bf0d4344 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 16 May 2017 11:30:48 +0300 Subject: [PATCH 383/882] [maven-release-plugin] prepare release scribejava-4.1.1 --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/pom.xml b/pom.xml index 7a5758bf4..9dbab96f4 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 4.1.1-SNAPSHOT + 4.1.1 ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -33,7 +33,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - HEAD + scribejava-4.1.1 diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 237f2586f..6d87b5a2f 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 4.1.1-SNAPSHOT + 4.1.1 ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 4101caf4b..59179571f 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 4.1.1-SNAPSHOT + 4.1.1 ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index a0bd4f8fb..565f3d3c0 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 4.1.1-SNAPSHOT + 4.1.1 ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index 1f8283d29..de40985f8 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 4.1.1-SNAPSHOT + 4.1.1 ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 04d81c9d3..5414b3fa1 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 4.1.1-SNAPSHOT + 4.1.1 ../pom.xml From 6c5b9b33e1ae25495ebf334d91e9ff1e46d330eb Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 16 May 2017 11:31:02 +0300 Subject: [PATCH 384/882] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/pom.xml b/pom.xml index 9dbab96f4..79f339291 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 4.1.1 + 4.1.2-SNAPSHOT ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -33,7 +33,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - scribejava-4.1.1 + HEAD diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 6d87b5a2f..b12ba4c48 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 4.1.1 + 4.1.2-SNAPSHOT ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 59179571f..f41d33f58 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 4.1.1 + 4.1.2-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 565f3d3c0..1a42399a4 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 4.1.1 + 4.1.2-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index de40985f8..462ca93db 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 4.1.1 + 4.1.2-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 5414b3fa1..0427e8d9a 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 4.1.1 + 4.1.2-SNAPSHOT ../pom.xml From 9640a74c12e300400ba1bf6e48e0d477b0a727c8 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 16 May 2017 11:59:26 +0300 Subject: [PATCH 385/882] drop deprecated methods --- .../github/scribejava/apis/LinkedInApi.java | 28 ++++--------------- 1 file changed, 6 insertions(+), 22 deletions(-) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi.java index fcefa5755..f30b44d17 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi.java @@ -10,32 +10,16 @@ public class LinkedInApi extends DefaultApi10a { private final String scopesAsString; - /** - * @deprecated use {@link #instance() } - */ - @Deprecated - //TODO: make protected in the next release - public LinkedInApi() { + protected LinkedInApi() { scopesAsString = null; } - /** - * @param scopes scopes - * @deprecated use {@link #instance(java.lang.String...) } - */ - @Deprecated - //TODO: make protected in the next release - public LinkedInApi(String... scopes) { - //TODO: deprecated check - if (scopes == null || scopes.length == 0) { - scopesAsString = null; - } else { - final StringBuilder builder = new StringBuilder(); - for (String scope : scopes) { - builder.append('+').append(scope); - } - scopesAsString = "?scope=" + builder.substring(1); + protected LinkedInApi(String... scopes) { + final StringBuilder builder = new StringBuilder(); + for (String scope : scopes) { + builder.append('+').append(scope); } + scopesAsString = "?scope=" + builder.substring(1); } private static class InstanceHolder { From f889a1d741000bc6072ea34aa143de9fc703540c Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 16 May 2017 12:04:24 +0300 Subject: [PATCH 386/882] fix LinkedIn Example --- .../scribejava/apis/examples/LinkedInExampleWithScopes.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java index 3ab8bb006..2b26f11ea 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java @@ -28,7 +28,7 @@ public static void main(String... args) throws IOException, InterruptedException final OAuth10aService service = new ServiceBuilder() .apiKey(clientId) .apiSecret(clientSecret) - .build(new LinkedInApi("foo", "bar", "baz")); + .build(LinkedInApi.instance("foo", "bar", "baz")); final Scanner in = new Scanner(System.in); System.out.println("=== LinkedIn's OAuth Workflow ==="); From 30824b340cc68c6b5670450e3c295a3a108a76ee Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 29 May 2017 17:21:51 +0300 Subject: [PATCH 387/882] LinkedIn use Header to sign OAuth2 requests --- changelog | 3 +++ .../github/scribejava/apis/LinkedInApi20.java | 14 -------------- .../apis/service/LinkedIn20ServiceImpl.java | 19 ------------------- 3 files changed, 3 insertions(+), 33 deletions(-) delete mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/service/LinkedIn20ServiceImpl.java diff --git a/changelog b/changelog index 55270bac7..b1bfaadb7 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,6 @@ +[SNAPSHOT] + * LinkedIn use Header to sign OAuth2 requests + [4.1.1] * 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) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi20.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi20.java index 8fa239c5d..0d22d705c 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi20.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi20.java @@ -1,10 +1,6 @@ package com.github.scribejava.apis; -import com.github.scribejava.apis.service.LinkedIn20ServiceImpl; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.builder.api.OAuth2SignatureType; -import com.github.scribejava.core.model.OAuthConfig; -import com.github.scribejava.core.oauth.OAuth20Service; public class LinkedInApi20 extends DefaultApi20 { @@ -28,14 +24,4 @@ public String getAccessTokenEndpoint() { protected String getAuthorizationBaseUrl() { return "https://www.linkedin.com/oauth/v2/authorization"; } - - @Override - public OAuth20Service createService(OAuthConfig config) { - return new LinkedIn20ServiceImpl(this, config); - } - - @Override - public OAuth2SignatureType getSignatureType() { - return OAuth2SignatureType.BEARER_URI_QUERY_PARAMETER; - } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/LinkedIn20ServiceImpl.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/LinkedIn20ServiceImpl.java deleted file mode 100644 index 4e26c6635..000000000 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/LinkedIn20ServiceImpl.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.github.scribejava.apis.service; - -import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.model.OAuth2AccessToken; -import com.github.scribejava.core.model.OAuthConfig; -import com.github.scribejava.core.model.OAuthRequest; -import com.github.scribejava.core.oauth.OAuth20Service; - -public class LinkedIn20ServiceImpl extends OAuth20Service { - - public LinkedIn20ServiceImpl(DefaultApi20 api, OAuthConfig config) { - super(api, config); - } - - @Override - public void signRequest(OAuth2AccessToken accessToken, OAuthRequest request) { - request.addQuerystringParameter("oauth2_access_token", accessToken.getAccessToken()); - } -} From d242f45cb1f1a90d0cbb7ee78a0379aecc014ed2 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 2 Jun 2017 15:58:36 +0300 Subject: [PATCH 388/882] upgrade ServiceBuilder to check apiKey preconditions compile-tim (not run-time) --- changelog | 1 + .../apis/examples/AWeberExample.java | 3 +- .../apis/examples/Box20Example.java | 3 +- .../scribejava/apis/examples/DiggExample.java | 3 +- .../examples/FacebookAsyncNingExample.java | 3 +- .../apis/examples/FacebookExample.java | 3 +- .../apis/examples/FlickrExample.java | 3 +- .../apis/examples/Foursquare2Example.java | 3 +- .../apis/examples/FoursquareExample.java | 3 +- .../apis/examples/FreelancerExample.java | 3 +- .../apis/examples/GeniusExample.java | 3 +- .../examples/GitHubAsyncOkHttpExample.java | 3 +- .../apis/examples/GitHubExample.java | 3 +- .../examples/Google20AsyncAHCExample.java | 3 +- .../apis/examples/Google20Example.java | 3 +- .../scribejava/apis/examples/HHExample.java | 3 +- .../apis/examples/ImgurExample.java | 3 +- .../apis/examples/Kaixin20Example.java | 3 +- .../apis/examples/LinkedIn20Example.java | 4 +-- .../apis/examples/LinkedInExample.java | 3 +- .../examples/LinkedInExampleWithScopes.java | 3 +- .../scribejava/apis/examples/LiveExample.java | 3 +- .../apis/examples/MailruAsyncExample.java | 3 +- .../apis/examples/MailruExample.java | 3 +- .../apis/examples/MeetupExample.java | 3 +- .../apis/examples/MisfitExample.java | 3 +- .../apis/examples/NaverExample.java | 3 +- .../apis/examples/NeteaseWeiboExample.java | 3 +- .../apis/examples/OdnoklassnikiExample.java | 3 +- .../apis/examples/PinterestExample.java | 3 +- .../apis/examples/Px500Example.java | 3 +- .../apis/examples/RenrenExample.java | 3 +- .../apis/examples/SalesforceExample.java | 3 +- .../examples/SalesforceNingAsyncExample.java | 3 +- .../apis/examples/SinaWeibo2Example.java | 3 +- .../apis/examples/SinaWeiboExample.java | 3 +- .../apis/examples/SkyrockExample.java | 3 +- .../apis/examples/SohuWeiboExample.java | 3 +- .../apis/examples/StackExchangeExample.java | 3 +- .../TheThingsNetworkV1StagingExample.java | 3 +- .../TheThingsNetworkV2PreviewExample.java | 3 +- .../apis/examples/TrelloExample.java | 3 +- .../apis/examples/TumblrExample.java | 3 +- .../apis/examples/TutByExample.java | 3 +- .../apis/examples/TwitterExample.java | 3 +- .../apis/examples/ViadeoExample.java | 3 +- .../apis/examples/VkontakteExample.java | 3 +- .../VkontakteExternalHttpExample.java | 3 +- .../scribejava/apis/examples/XingExample.java | 3 +- .../apis/examples/YahooExample.java | 3 +- .../service/OdnoklassnikiServiceTest.java | 3 +- .../core/builder/ServiceBuilder.java | 30 ++++++++++++------- .../core/builder/ServiceBuilderTest.java | 2 +- .../core/oauth/OAuth20ServiceTest.java | 9 ++---- 54 files changed, 76 insertions(+), 117 deletions(-) diff --git a/changelog b/changelog index b1bfaadb7..a66b68f9a 100644 --- a/changelog +++ b/changelog @@ -1,5 +1,6 @@ [SNAPSHOT] * LinkedIn use Header to sign OAuth2 requests + * upgrade ServiceBuilder to check apiKey preconditions compile-tim (not run-time) [4.1.1] * omit the client_secret parameter if it is an empty string while refreshing token (thanks to https://github.com/KungfuPancake) diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AWeberExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AWeberExample.java index d79bd77b2..d304dc6d4 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AWeberExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AWeberExample.java @@ -24,8 +24,7 @@ private AWeberExample() { } public static void main(String... args) throws IOException, InterruptedException, ExecutionException { - final OAuth10aService service = new ServiceBuilder() - .apiKey(CONSUMER_KEY) + final OAuth10aService service = new ServiceBuilder(CONSUMER_KEY) .apiSecret(CONSUMER_SECRET) .build(AWeberApi.instance()); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Box20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Box20Example.java index e2f5d6f2c..de8a1c1ed 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Box20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Box20Example.java @@ -27,8 +27,7 @@ public static void main(String... args) throws IOException, InterruptedException final String clientId = "your client id"; final String clientSecret = "your client secret"; final String secretState = "security_token" + new Random().nextInt(999_999); - final OAuth20Service service = new ServiceBuilder() - .apiKey(clientId) + final OAuth20Service service = new ServiceBuilder(clientId) .apiSecret(clientSecret) .state(secretState) .callback("https://example.com/callback") diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiggExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiggExample.java index 6afd1db07..aafbea10c 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiggExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiggExample.java @@ -24,8 +24,7 @@ public static void main(String... args) throws IOException, InterruptedException // Replace these with your own api key and secret final String apiKey = "myKey"; final String apiSecret = "mySecret"; - final OAuth10aService service = new ServiceBuilder() - .apiKey(apiKey) + final OAuth10aService service = new ServiceBuilder(apiKey) .apiSecret(apiSecret) .build(DiggApi.instance()); final Scanner in = new Scanner(System.in); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java index bf916d083..ae8879790 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java @@ -35,8 +35,7 @@ public static void main(String... args) throws InterruptedException, ExecutionEx .setReadTimeout(1_000) .build()); - try (OAuth20Service service = new ServiceBuilder() - .apiKey(clientId) + try (OAuth20Service service = new ServiceBuilder(clientId) .apiSecret(clientSecret) .state(secretState) .callback("http://www.example.com/oauth_callback/") diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java index 54f56181a..521020e29 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java @@ -25,8 +25,7 @@ public static void main(String... args) throws IOException, InterruptedException final String clientId = "your client id"; final String clientSecret = "your client secret"; final String secretState = "secret" + new Random().nextInt(999_999); - final OAuth20Service service = new ServiceBuilder() - .apiKey(clientId) + final OAuth20Service service = new ServiceBuilder(clientId) .apiSecret(clientSecret) .state(secretState) .callback("http://www.example.com/oauth_callback/") diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExample.java index 353431f46..e5809874f 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExample.java @@ -25,8 +25,7 @@ public static void main(String... args) throws IOException, InterruptedException final String apiKey = "your_app_id"; final String apiSecret = "your_api_secret"; - final OAuth10aService service = new ServiceBuilder() - .apiKey(apiKey) + final OAuth10aService service = new ServiceBuilder(apiKey) .apiSecret(apiSecret) .build(FlickrApi.instance(FlickrApi.FlickrPerm.DELETE)); final Scanner in = new Scanner(System.in); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java index 1874e5deb..33e6206ef 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java @@ -23,8 +23,7 @@ public static void main(String... args) throws IOException, InterruptedException // Replace these with your own api key and secret final String apiKey = "your client id"; final String apiSecret = "your client secret"; - final OAuth20Service service = new ServiceBuilder() - .apiKey(apiKey) + final OAuth20Service service = new ServiceBuilder(apiKey) .apiSecret(apiSecret) .callback("http://localhost:9000/") .build(Foursquare2Api.instance()); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FoursquareExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FoursquareExample.java index 59956cafd..afaaca188 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FoursquareExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FoursquareExample.java @@ -20,8 +20,7 @@ private FoursquareExample() { } public static void main(String... args) throws IOException, InterruptedException, ExecutionException { - final OAuth10aService service = new ServiceBuilder() - .apiKey("your client id") + final OAuth10aService service = new ServiceBuilder("your client id") .apiSecret("your client secret") .build(FoursquareApi.instance()); final Scanner in = new Scanner(System.in); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java index 45986edf1..a17f896de 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java @@ -24,8 +24,7 @@ private FreelancerExample() { } public static void main(String... args) throws IOException, InterruptedException, ExecutionException { - final OAuth10aService service = new ServiceBuilder() - .apiKey("your client id") + final OAuth10aService service = new ServiceBuilder("your client id") .apiSecret("your client secret") .scope(SCOPE) .build(FreelancerApi.Sandbox.instance()); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GeniusExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GeniusExample.java index 59c2d872a..af515b79c 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GeniusExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GeniusExample.java @@ -25,8 +25,7 @@ public static void main(String... args) throws IOException, InterruptedException final String clientId = "your client id"; final String clientSecret = "your client secret"; final String secretState = "100"; - final OAuth20Service service = new ServiceBuilder() - .apiKey(clientId) + final OAuth20Service service = new ServiceBuilder(clientId) .apiSecret(clientSecret) .scope("me") .state(secretState) diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubAsyncOkHttpExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubAsyncOkHttpExample.java index ed8189390..596a14a45 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubAsyncOkHttpExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubAsyncOkHttpExample.java @@ -27,8 +27,7 @@ public static void main(String... args) throws IOException, ExecutionException, final String clientId = "your client id"; final String clientSecret = "your client secret"; final String secretState = "secret" + new Random().nextInt(999_999); - try (OAuth20Service service = new ServiceBuilder() - .apiKey(clientId) + try (OAuth20Service service = new ServiceBuilder(clientId) .apiSecret(clientSecret) .state(secretState) .callback("http://www.example.com/oauth_callback/") diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubExample.java index 28d5bc5c4..8c3444d92 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubExample.java @@ -25,8 +25,7 @@ public static void main(String... args) throws IOException, InterruptedException final String clientId = "your client id"; final String clientSecret = "your client secret"; final String secretState = "secret" + new Random().nextInt(999_999); - final OAuth20Service service = new ServiceBuilder() - .apiKey(clientId) + final OAuth20Service service = new ServiceBuilder(clientId) .apiSecret(clientSecret) .state(secretState) .callback("http://www.example.com/oauth_callback/") diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java index 970c5d534..7ac82e7e9 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java @@ -37,8 +37,7 @@ public static void main(String... args) throws InterruptedException, ExecutionEx .setReadTimeout(1_000) .build()); - try (OAuth20Service service = new ServiceBuilder() - .apiKey(clientId) + try (OAuth20Service service = new ServiceBuilder(clientId) .apiSecret(clientSecret) .scope("profile") // replace with desired scope .state(secretState) diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java index 770703321..e9e2adf27 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java @@ -27,8 +27,7 @@ public static void main(String... args) throws IOException, InterruptedException final String clientId = "your client id"; final String clientSecret = "your client secret"; final String secretState = "secret" + new Random().nextInt(999_999); - final OAuth20Service service = new ServiceBuilder() - .apiKey(clientId) + final OAuth20Service service = new ServiceBuilder(clientId) .apiSecret(clientSecret) .scope("profile") // replace with desired scope .state(secretState) diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HHExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HHExample.java index c19ba50c3..e892eace3 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HHExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HHExample.java @@ -25,8 +25,7 @@ public static void main(String... args) throws IOException, InterruptedException // Replace these with your own client id and secret final String clientId = "your client id"; final String clientSecret = "your client secret"; - final OAuth20Service service = new ServiceBuilder() - .apiKey(clientId) + final OAuth20Service service = new ServiceBuilder(clientId) .apiSecret(clientSecret) .callback("http://your.site.com/callback") .build(HHApi.instance()); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ImgurExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ImgurExample.java index fd8c59c31..35f6d9a31 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ImgurExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ImgurExample.java @@ -24,8 +24,7 @@ public static void main(String... args) throws IOException, InterruptedException // Replace these with your own api key and secret final String apiKey = "your client id"; final String apiSecret = "your client secret"; - final OAuth20Service service = new ServiceBuilder() - .apiKey(apiKey) + final OAuth20Service service = new ServiceBuilder(apiKey) .apiSecret(apiSecret) .build(ImgurApi.instance()); final Scanner in = new Scanner(System.in); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Kaixin20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Kaixin20Example.java index 50a134c7d..6d61a613b 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Kaixin20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Kaixin20Example.java @@ -23,8 +23,7 @@ public static void main(String... args) throws IOException, InterruptedException // Replace these with your own api key and secret final String apiKey = "your api key"; final String apiSecret = "your api secret"; - final OAuth20Service service = new ServiceBuilder() - .apiKey(apiKey) + final OAuth20Service service = new ServiceBuilder(apiKey) .apiSecret(apiSecret) .callback("http://your.domain.com/handle") .build(KaixinApi20.instance()); 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 cf34a9ae0..8553c3498 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 @@ -23,8 +23,8 @@ public static void main(String... args) throws IOException, InterruptedException // Replace these with your client id and secret final String clientId = "your client id"; final String clientSecret = "your client secret"; - final OAuth20Service service = new ServiceBuilder() - .apiKey(clientId).apiSecret(clientSecret) + final OAuth20Service service = new ServiceBuilder(clientId) + .apiSecret(clientSecret) .scope("r_basicprofile r_emailaddress") // replace with desired scope .callback("http://example.com/callback") .state("some_params") diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java index 6f9654e7f..02ae520c1 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java @@ -21,8 +21,7 @@ private LinkedInExample() { } public static void main(String... args) throws IOException, InterruptedException, ExecutionException { - final OAuth10aService service = new ServiceBuilder() - .apiKey("your client id") + final OAuth10aService service = new ServiceBuilder("your client id") .apiSecret("your client secret") .build(LinkedInApi.instance()); final Scanner in = new Scanner(System.in); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java index 2b26f11ea..a8247f65c 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java @@ -25,8 +25,7 @@ public static void main(String... args) throws IOException, InterruptedException final String clientId = "your client id"; final String clientSecret = "your client id"; - final OAuth10aService service = new ServiceBuilder() - .apiKey(clientId) + final OAuth10aService service = new ServiceBuilder(clientId) .apiSecret(clientSecret) .build(LinkedInApi.instance("foo", "bar", "baz")); final Scanner in = new Scanner(System.in); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java index a93643eda..c693b0e73 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java @@ -23,8 +23,7 @@ public static void main(String... args) throws IOException, InterruptedException // Replace these with your own api key and secret final String apiKey = ""; final String apiSecret = ""; - final OAuth20Service service = new ServiceBuilder() - .apiKey(apiKey) + final OAuth20Service service = new ServiceBuilder(apiKey) .apiSecret(apiSecret) .scope("wl.basic") .callback("http://localhost:9000/") diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java index 38613c019..2c566e99b 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java @@ -35,8 +35,7 @@ public static void main(String... args) throws InterruptedException, ExecutionEx .setReadTimeout(10_000) .build()); - try (OAuth20Service service = new ServiceBuilder() - .apiKey(clientId) + try (OAuth20Service service = new ServiceBuilder(clientId) .apiSecret(clientSecret) .callback("http://www.example.com/oauth_callback/") .httpClientConfig(clientConfig) diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java index 9fb743b05..f6c620d0f 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java @@ -24,8 +24,7 @@ public static void main(String... args) throws IOException, InterruptedException // Replace these with your client id and secret final String clientId = "your client id"; final String clientSecret = "your client secret"; - final OAuth20Service service = new ServiceBuilder() - .apiKey(clientId) + final OAuth20Service service = new ServiceBuilder(clientId) .apiSecret(clientSecret) .callback("http://www.example.com/oauth_callback/") .build(MailruApi.instance()); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java index f7c41894a..c8d6ea911 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java @@ -20,8 +20,7 @@ private MeetupExample() { } public static void main(String... args) throws IOException, InterruptedException, ExecutionException { - final OAuth10aService service = new ServiceBuilder() - .apiKey("your client id") + final OAuth10aService service = new ServiceBuilder("your client id") .apiSecret("your client secret") .build(MeetupApi.instance()); final Scanner in = new Scanner(System.in); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MisfitExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MisfitExample.java index 1caa28eb1..ed6c1dd7f 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MisfitExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MisfitExample.java @@ -25,8 +25,7 @@ public static void main(String... args) throws IOException, InterruptedException // Replace these with your own api key and secret final String apiKey = "your client id"; final String apiSecret = "your client secret"; - final OAuth20Service service = new ServiceBuilder() - .apiKey(apiKey) + final OAuth20Service service = new ServiceBuilder(apiKey) .apiSecret(apiSecret) .callback("http://example.com/callback/") .scope("public,birthday,email,tracking,session,sleep") diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NaverExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NaverExample.java index 3a85e8845..5d2d5548e 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NaverExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NaverExample.java @@ -26,8 +26,7 @@ public static void main(String... args) throws IOException, InterruptedException final String clientId = "your client id"; final String clientSecret = "your client secret"; final String secretState = "secret" + new Random().nextInt(999_999); - final OAuth20Service service = new ServiceBuilder() - .apiKey(clientId) + final OAuth20Service service = new ServiceBuilder(clientId) .apiSecret(clientSecret) .state(secretState) .callback("http://www.example.com/oauth_callback/") diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NeteaseWeiboExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NeteaseWeiboExample.java index cde99f609..866c2167b 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NeteaseWeiboExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NeteaseWeiboExample.java @@ -24,8 +24,7 @@ public static void main(String... args) throws IOException, InterruptedException // Replace these with your own api key and secret final String apiKey = "your key"; final String apiSecret = "your secret"; - final OAuth10aService service = new ServiceBuilder() - .apiKey(apiKey) + final OAuth10aService service = new ServiceBuilder(apiKey) .apiSecret(apiSecret) .build(NeteaseWeibooApi.instance()); final Scanner in = new Scanner(System.in); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java index c87fad63c..8ea048fe8 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java @@ -26,8 +26,7 @@ public static void main(String... args) throws IOException, InterruptedException final String publicKey = "your api public key"; final String secretKey = "your api secret key"; - final OAuth20Service service = new ServiceBuilder() - .apiKey(clientId) + final OAuth20Service service = new ServiceBuilder(clientId) .apiSecret(secretKey) .callback("http://your.site.com/callback") .build(OdnoklassnikiApi.instance()); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java index 16a8f6e65..1fec439b4 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java @@ -23,8 +23,7 @@ public static void main(String... args) throws IOException, InterruptedException // Replace these with your own api key and secret final String apiKey = "your_app_id"; final String apiSecret = "your_app_secret"; - final OAuth20Service service = new ServiceBuilder() - .apiKey(apiKey) + final OAuth20Service service = new ServiceBuilder(apiKey) .apiSecret(apiSecret) .scope("read_public,write_public,read_relationships,write_relationships") .callback("https://localhost:9000/") // Add as valid callback in developer portal diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Px500Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Px500Example.java index 2ab55085c..820a0e821 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Px500Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Px500Example.java @@ -20,8 +20,7 @@ private Px500Example() { } public static void main(String... args) throws IOException, InterruptedException, ExecutionException { - final OAuth10aService service = new ServiceBuilder() - .apiKey("your-api-key") + final OAuth10aService service = new ServiceBuilder("your-api-key") .apiSecret("your-api-secret") .build(Px500Api.instance()); final Scanner in = new Scanner(System.in); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java index 021c9b0d4..1eea7e581 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java @@ -32,8 +32,7 @@ public static void main(String... args) throws IOException, InterruptedException // Replace these with your own api key and secret final String apiKey = "your api key"; final String apiSecret = "your api secret"; - final OAuth20Service service = new ServiceBuilder() - .apiKey(apiKey) + final OAuth20Service service = new ServiceBuilder(apiKey) .apiSecret(apiSecret) .scope("status_update publish_feed") .callback("http://your.doman.com/oauth/renren") diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceExample.java index 925819a7b..30f4aab85 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceExample.java @@ -39,8 +39,7 @@ public static void main(String... args) throws IOException, NoSuchAlgorithmExcep // When you plan to connect to a Sandbox environment you've to use SalesforceApi.sandbox() API instance // new ServiceBuilder.....build(SalesforceApi.sandbox()); - final OAuth20Service service = new ServiceBuilder() - .apiKey(clientId) + final OAuth20Service service = new ServiceBuilder(clientId) .apiSecret(clientSecret) .callback("https://www.example.com/callback") .build(SalesforceApi.instance()); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceNingAsyncExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceNingAsyncExample.java index 36a060123..d057df0d9 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceNingAsyncExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceNingAsyncExample.java @@ -44,8 +44,7 @@ public static void main(String... args) throws InterruptedException, ExecutionEx //IT's important! Salesforce upper require TLS v1.1 or 1.2 SalesforceApi.initTLSv11orUpper(); - try (OAuth20Service service = new ServiceBuilder() - .apiKey(clientId) + try (OAuth20Service service = new ServiceBuilder(clientId) .apiSecret(clientSecret) .httpClientConfig(clientConfig) .callback("https://www.example.com/callback") diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeibo2Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeibo2Example.java index d99a20b1c..a2bacaff4 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeibo2Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeibo2Example.java @@ -23,8 +23,7 @@ public static void main(String... args) throws IOException, InterruptedException // Replace these with your own api key and secret final String apiKey = "your_api_key"; final String apiSecret = "your_api_secret"; - final OAuth20Service service = new ServiceBuilder() - .apiKey(apiKey) + final OAuth20Service service = new ServiceBuilder(apiKey) .apiSecret(apiSecret) .callback("http://www.dajie.com/oauth/sina") .build(SinaWeiboApi20.instance()); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeiboExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeiboExample.java index 18edbb49e..289f4eb50 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeiboExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeiboExample.java @@ -24,8 +24,7 @@ public static void main(String... args) throws IOException, InterruptedException // Replace these with your own api key and secret final String apiKey = "your key"; final String apiSecret = "your secret"; - final OAuth10aService service = new ServiceBuilder() - .apiKey(apiKey) + final OAuth10aService service = new ServiceBuilder(apiKey) .apiSecret(apiSecret) .build(SinaWeiboApi.instance()); final Scanner in = new Scanner(System.in); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SkyrockExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SkyrockExample.java index a9c957541..fcb2f592a 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SkyrockExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SkyrockExample.java @@ -20,8 +20,7 @@ private SkyrockExample() { } public static void main(String... args) throws IOException, InterruptedException, ExecutionException { - final OAuth10aService service = new ServiceBuilder() - .apiKey("your-api-key") + final OAuth10aService service = new ServiceBuilder("your-api-key") .apiSecret("your-api-secret") .build(SkyrockApi.instance()); final Scanner in = new Scanner(System.in); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SohuWeiboExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SohuWeiboExample.java index 81202256d..0cb93b91a 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SohuWeiboExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SohuWeiboExample.java @@ -24,8 +24,7 @@ public static void main(String... args) throws IOException, InterruptedException // Replace these with your own api key and secret final String apiKey = "your_key"; final String apiSecret = "your_secret"; - final OAuth10aService service = new ServiceBuilder() - .apiKey(apiKey) + final OAuth10aService service = new ServiceBuilder(apiKey) .apiSecret(apiSecret) .build(SohuWeiboApi.instance()); final Scanner in = new Scanner(System.in); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/StackExchangeExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/StackExchangeExample.java index ed3eea0db..04858eab6 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/StackExchangeExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/StackExchangeExample.java @@ -30,8 +30,7 @@ public static void main(String... args) throws IOException, InterruptedException // Enter one of Stack Exchange site names the user has account with. final String site = "stackoverflow"; final String secretState = "secret" + new Random().nextInt(999_999); - final OAuth20Service service = new ServiceBuilder() - .apiKey(clientId) + final OAuth20Service service = new ServiceBuilder(clientId) .apiSecret(clientSecret) .state(secretState) .callback("http://www.example.com/oauth_callback/") diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV1StagingExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV1StagingExample.java index e154dc634..057f9b27c 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV1StagingExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV1StagingExample.java @@ -29,8 +29,7 @@ public static void main(String... args) throws IOException, InterruptedException final String secretState = "secret" + new Random().nextInt(999_999); final String redirectURI = "https://your_redirect_uri"; - final OAuth20Service service = new ServiceBuilder() - .apiKey(clientId) + final OAuth20Service service = new ServiceBuilder(clientId) .apiSecret(clientSecret) .state(secretState) .callback(redirectURI) diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV2PreviewExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV2PreviewExample.java index 4feb220c3..acb791c1c 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV2PreviewExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV2PreviewExample.java @@ -29,8 +29,7 @@ public static void main(String... args) throws IOException, InterruptedException final String secretState = "secret" + new Random().nextInt(999_999); final String redirectURI = "https://your_redirect_uri"; - final OAuth20Service service = new ServiceBuilder() - .apiKey(clientId) + final OAuth20Service service = new ServiceBuilder(clientId) .apiSecret(clientSecret) .state(secretState) .callback(redirectURI) diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TrelloExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TrelloExample.java index e847d7b94..dea9fc659 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TrelloExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TrelloExample.java @@ -22,8 +22,7 @@ private TrelloExample() { } public static void main(String... args) throws IOException, InterruptedException, ExecutionException { - final OAuth10aService service = new ServiceBuilder() - .apiKey(API_KEY) + final OAuth10aService service = new ServiceBuilder(API_KEY) .apiSecret(API_SECRET) .build(TrelloApi.instance()); final Scanner in = new Scanner(System.in); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TumblrExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TumblrExample.java index edc12efa7..ec21d3bfb 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TumblrExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TumblrExample.java @@ -20,8 +20,7 @@ private TumblrExample() { } public static void main(String... args) throws IOException, InterruptedException, ExecutionException { - final OAuth10aService service = new ServiceBuilder() - .apiKey("MY_CONSUMER_KEY") + final OAuth10aService service = new ServiceBuilder("MY_CONSUMER_KEY") .apiSecret("MY_CONSUMER_SECRET") // OOB forbidden. We need an url and the better is on the tumblr website ! .callback("http://www.tumblr.com/connect/login_success.html") diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TutByExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TutByExample.java index 06e035abb..daa5f0122 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TutByExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TutByExample.java @@ -25,8 +25,7 @@ public static void main(String... args) throws IOException, InterruptedException // Replace these with your client id and secret final String clientId = "your client id"; final String clientSecret = "your client secret"; - final OAuth20Service service = new ServiceBuilder() - .apiKey(clientId) + final OAuth20Service service = new ServiceBuilder(clientId) .apiSecret(clientSecret) .callback("http://www.example.com/oauth_callback/") .build(TutByApi.instance()); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TwitterExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TwitterExample.java index 6cd012bb7..620eb7820 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TwitterExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TwitterExample.java @@ -20,8 +20,7 @@ private TwitterExample() { } public static void main(String... args) throws IOException, InterruptedException, ExecutionException { - final OAuth10aService service = new ServiceBuilder() - .apiKey("your client id") + final OAuth10aService service = new ServiceBuilder("your client id") .apiSecret("your client secret") .build(TwitterApi.instance()); final Scanner in = new Scanner(System.in); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ViadeoExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ViadeoExample.java index d0b5cfaeb..09dcde65a 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ViadeoExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ViadeoExample.java @@ -23,8 +23,7 @@ public static void main(String... args) throws IOException, InterruptedException // Replace these with your own api key and secret final String apiKey = "your_app_id"; final String apiSecret = "your_api_secret"; - final OAuth20Service service = new ServiceBuilder() - .apiKey(apiKey) + final OAuth20Service service = new ServiceBuilder(apiKey) .apiSecret(apiSecret) .callback("http://www.example.com/oauth_callback/") .build(ViadeoApi.instance()); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExample.java index fb806492d..240f78e7c 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 @@ -23,8 +23,7 @@ public static void main(String... args) throws IOException, InterruptedException // Replace these with your client id and secret final String clientId = "your client id"; final String clientSecret = "your client secret"; - final OAuth20Service service = new ServiceBuilder() - .apiKey(clientId) + final OAuth20Service service = new ServiceBuilder(clientId) .apiSecret(clientSecret) .scope("wall,offline") // replace with desired scope .callback("http://your.site.com/callback") 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 2cd858236..d16b714d8 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 @@ -39,9 +39,8 @@ public static void main(String... args) throws IOException, InterruptedException //wrap it final AhcHttpClient wrappedAHCHttpClient = new AhcHttpClient(ahcHttpClient); - final OAuth20Service service = new ServiceBuilder() + final OAuth20Service service = new ServiceBuilder(clientId) .httpClient(wrappedAHCHttpClient) - .apiKey(clientId) .apiSecret(clientSecret) .scope("wall,offline") // replace with desired scope .callback("http://your.site.com/callback") diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XingExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XingExample.java index 3ec67e472..9929c6152 100755 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XingExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XingExample.java @@ -20,8 +20,7 @@ private XingExample() { } public static void main(String... args) throws IOException, InterruptedException, ExecutionException { - final OAuth10aService service = new ServiceBuilder() - .apiKey("your client id") + final OAuth10aService service = new ServiceBuilder("your client id") .apiSecret("your client secret") .build(XingApi.instance()); final Scanner in = new Scanner(System.in); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/YahooExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/YahooExample.java index aa6691cdb..581600a3b 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/YahooExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/YahooExample.java @@ -21,8 +21,7 @@ private YahooExample() { } public static void main(String... args) throws IOException, InterruptedException, ExecutionException { - final OAuth10aService service = new ServiceBuilder() - .apiKey("your client id") + final OAuth10aService service = new ServiceBuilder("your client id") .apiSecret("your client secret") .build(YahooApi.instance()); final Scanner in = new Scanner(System.in); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/service/OdnoklassnikiServiceTest.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/service/OdnoklassnikiServiceTest.java index af14b9744..0dded23fb 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/service/OdnoklassnikiServiceTest.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/service/OdnoklassnikiServiceTest.java @@ -17,8 +17,7 @@ public class OdnoklassnikiServiceTest { private static final String URL = "https://api.ok.ru/fb.do?method=friends.get&fields=uid%2C" + "first_name%2Clast_name%2Cpic_2&application_key=AAAAAAAAAAAAAAAA&format=json"; - private final OAuth20Service service = new ServiceBuilder() - .apiKey("0000000000") + private final OAuth20Service service = new ServiceBuilder("0000000000") .apiSecret("CCCCCCCCCCCCCCCCCCCCCCCC") .scope("VALUABLE_ACCESS") .callback("http://your.site.com/callback") 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 d44b784fd..6ae14b1c9 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 @@ -15,7 +15,7 @@ */ public class ServiceBuilder { - private String callback; + private String callback = OAuthConstants.OUT_OF_BAND; private String apiKey; private String apiSecret; private String scope; @@ -27,8 +27,16 @@ public class ServiceBuilder { private HttpClientConfig httpClientConfig; private HttpClient httpClient; + /** + * + * @deprecated use {@link #ServiceBuilder(java.lang.String) } + */ + @Deprecated public ServiceBuilder() { - callback = OAuthConstants.OUT_OF_BAND; + } + + public ServiceBuilder(String apiKey) { + apiKey(apiKey); } /** @@ -49,7 +57,7 @@ public ServiceBuilder callback(String callback) { * @param apiKey The api key for your application * @return the {@link ServiceBuilder} instance for method chaining */ - public ServiceBuilder apiKey(String apiKey) { + public final ServiceBuilder apiKey(String apiKey) { Preconditions.checkEmptyString(apiKey, "Invalid Api key"); this.apiKey = apiKey; return this; @@ -130,16 +138,16 @@ public ServiceBuilder debug() { return this; } + /** + * + * @deprecated apiKey will be required param for the ServiceBuilder constructor + * {@link #ServiceBuilder(java.lang.String) } + */ + @Deprecated public void checkPreconditions() { Preconditions.checkEmptyString(apiKey, "You must provide an api key"); } - private OAuthConfig createConfig() { - checkPreconditions(); - return new OAuthConfig(apiKey, apiSecret, callback, scope, debugStream, state, responseType, userAgent, - httpClientConfig, httpClient); - } - /** * Returns the fully configured {@link S} * @@ -148,6 +156,8 @@ private OAuthConfig createConfig() { * @return fully configured {@link S} */ public > S build(BaseApi api) { - return api.createService(createConfig()); + checkPreconditions(); + return api.createService(new OAuthConfig(apiKey, apiSecret, callback, scope, debugStream, state, responseType, + userAgent, httpClientConfig, httpClient)); } } diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/builder/ServiceBuilderTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/builder/ServiceBuilderTest.java index 3aa88699a..c7d4a4dac 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/builder/ServiceBuilderTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/builder/ServiceBuilderTest.java @@ -15,7 +15,7 @@ public class ServiceBuilderTest { @Before public void setUp() { - builder = new ServiceBuilder(); + builder = new ServiceBuilder("will override api_key by another later in test"); api = ApiMock.instance(); } diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceTest.java index 3115fd832..581fc5a63 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 @@ -20,8 +20,7 @@ public class OAuth20ServiceTest { @Test public void shouldProduceCorrectRequestSync() throws IOException, InterruptedException, ExecutionException { - final OAuth20Service service = new ServiceBuilder() - .apiKey("your_api_key") + final OAuth20Service service = new ServiceBuilder("your_api_key") .apiSecret("your_api_secret") .build(new OAuth20ApiUnit()); @@ -49,8 +48,7 @@ public void shouldProduceCorrectRequestSync() throws IOException, InterruptedExc @Test public void shouldProduceCorrectRequestAsync() throws ExecutionException, InterruptedException { - final OAuth20Service service = new ServiceBuilder() - .apiKey("your_api_key") + final OAuth20Service service = new ServiceBuilder("your_api_key") .apiSecret("your_api_secret") .build(new OAuth20ApiUnit()); @@ -78,8 +76,7 @@ public void shouldProduceCorrectRequestAsync() throws ExecutionException, Interr @Test public void testOAuthExtractAuthorization() { - final OAuth20Service service = new ServiceBuilder() - .apiKey("your_api_key") + final OAuth20Service service = new ServiceBuilder("your_api_key") .apiSecret("your_api_secret") .build(new OAuth20ApiUnit()); From 988cc9a600aa78810905aae0ef39b67f6ae9a1da Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 30 Jun 2017 12:34:03 +0300 Subject: [PATCH 389/882] fix Readme - remove deprecated usage of ServiceBuilder --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index 808dc634e..507421556 100644 --- a/README.md +++ b/README.md @@ -11,8 +11,7 @@ Who said OAuth/OAuth2 was difficult? Configuring ScribeJava is __so easy your grandma can do it__! check it out: ```java -OAuthService service = new ServiceBuilder() - .apiKey(YOUR_API_KEY) +OAuthService service = new ServiceBuilder(YOUR_API_KEY) .apiSecret(YOUR_API_SECRET) .build(LinkedInApi20.instance()); ``` From 3b3cbcc8090df83f02252ad816363a050700381b Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 5 Jul 2017 14:25:08 +0300 Subject: [PATCH 390/882] update Live API --- changelog | 1 + .../src/main/java/com/github/scribejava/apis/LiveApi.java | 8 +------- .../com/github/scribejava/apis/examples/LiveExample.java | 5 ++--- 3 files changed, 4 insertions(+), 10 deletions(-) diff --git a/changelog b/changelog index a66b68f9a..8b8f1c32e 100644 --- a/changelog +++ b/changelog @@ -1,6 +1,7 @@ [SNAPSHOT] * LinkedIn use Header to sign OAuth2 requests * upgrade ServiceBuilder to check apiKey preconditions compile-tim (not run-time) + * 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) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/LiveApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/LiveApi.java index ffaf3bcf6..83cd89780 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/LiveApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/LiveApi.java @@ -2,7 +2,6 @@ import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.builder.api.OAuth2SignatureType; -import com.github.scribejava.core.model.Verb; public class LiveApi extends DefaultApi20 { @@ -17,11 +16,6 @@ public static LiveApi instance() { return InstanceHolder.INSTANCE; } - @Override - public Verb getAccessTokenVerb() { - return Verb.GET; - } - @Override public String getAccessTokenEndpoint() { return "https://login.live.com/oauth20_token.srf"; @@ -29,7 +23,7 @@ public String getAccessTokenEndpoint() { @Override protected String getAuthorizationBaseUrl() { - return "https://oauth.live.com/authorize"; + return "https://login.live.com/oauth20_authorize.srf"; } @Override diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java index c693b0e73..09fabe03a 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java @@ -13,8 +13,7 @@ public final class LiveExample { - private static final String PROTECTED_RESOURCE_URL - = "https://api.foursquare.com/v2/users/self/friends?oauth_token="; + private static final String PROTECTED_RESOURCE_URL = "https://apis.live.net/v5.0/me"; private LiveExample() { } @@ -54,7 +53,7 @@ public static void main(String... args) throws IOException, InterruptedException // Now let's go and ask for a protected resource! System.out.println("Now we're going to access a protected resource..."); - final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL + accessToken.getAccessToken()); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); service.signRequest(accessToken, request); final Response response = service.execute(request); System.out.println("Got it! Lets see what we found..."); From 26f7c8d7fa9ff0b493d6f5eff0cdad90acf3f8fe Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 6 Jul 2017 12:07:57 +0300 Subject: [PATCH 391/882] fix typo in the changelog --- changelog | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog b/changelog index 8b8f1c32e..57a95c40e 100644 --- a/changelog +++ b/changelog @@ -1,6 +1,6 @@ [SNAPSHOT] * LinkedIn use Header to sign OAuth2 requests - * upgrade ServiceBuilder to check apiKey preconditions compile-tim (not run-time) + * upgrade ServiceBuilder to check apiKey preconditions compile-time (not run-time) * update Live API (thanks to https://github.com/typhoon17) [4.1.1] From 7817f679b8075f4ccee2da768811db734ea5bd70 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 6 Jul 2017 12:59:07 +0300 Subject: [PATCH 392/882] update maven deps + tiny refactor --- pom.xml | 4 ++-- .../main/java/com/github/scribejava/apis/FlickrApi.java | 9 ++------- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 4 ++-- 4 files changed, 7 insertions(+), 12 deletions(-) diff --git a/pom.xml b/pom.xml index 79f339291..e17d88e4f 100644 --- a/pom.xml +++ b/pom.xml @@ -86,7 +86,7 @@ com.google.code.gson gson - 2.8.0 + 2.8.1 test @@ -132,7 +132,7 @@ com.puppycrawl.tools checkstyle - 7.7 + 8.0 diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/FlickrApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/FlickrApi.java index f5ecca530..aafc6bbd8 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/FlickrApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/FlickrApi.java @@ -54,13 +54,8 @@ public String getAccessTokenEndpoint() { */ @Override public String getAuthorizationUrl(OAuth1RequestToken requestToken) { - String authUrl = String.format(AUTHORIZE_URL, requestToken.getToken()); - - if (permString != null) { - authUrl += "&perms=" + permString; - } - - return authUrl; + final String authUrl = String.format(AUTHORIZE_URL, requestToken.getToken()); + return permString == null ? authUrl : authUrl + "&perms=" + permString; } /** diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 1a42399a4..f97defbbf 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -23,7 +23,7 @@ org.asynchttpclient async-http-client - 2.0.32 + 2.0.33 diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 0427e8d9a..74f6efe12 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -23,12 +23,12 @@ com.squareup.okhttp3 okhttp - 3.8.0 + 3.8.1 com.squareup.okhttp3 mockwebserver - 3.8.0 + 3.8.1 test From dd5fdf4295c100c9c285b7a3ec2bc1bb75800f00 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 6 Jul 2017 13:46:25 +0300 Subject: [PATCH 393/882] prepare 4.1.2 release --- README.md | 4 ++-- changelog | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 507421556..a73907c92 100644 --- a/README.md +++ b/README.md @@ -99,7 +99,7 @@ You can pull ScribeJava from the central maven repository, just add these to you com.github.scribejava scribejava-apis - 4.1.1 + 4.1.2 ``` @@ -108,7 +108,7 @@ And in case you need just core classes (that's it, without any external API (FB, com.github.scribejava scribejava-core - 4.1.1 + 4.1.2 ``` diff --git a/changelog b/changelog index 57a95c40e..4bba4703d 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,4 @@ -[SNAPSHOT] +[4.1.2] * LinkedIn use Header to sign OAuth2 requests * upgrade ServiceBuilder to check apiKey preconditions compile-time (not run-time) * update Live API (thanks to https://github.com/typhoon17) From 0b545d685ac4e2a7b9992f8147c52e57c279edeb Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 6 Jul 2017 13:47:26 +0300 Subject: [PATCH 394/882] [maven-release-plugin] prepare release scribejava-4.1.2 --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/pom.xml b/pom.xml index e17d88e4f..bd1d5f548 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 4.1.2-SNAPSHOT + 4.1.2 ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -33,7 +33,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - HEAD + scribejava-4.1.2 diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index b12ba4c48..df8d7351b 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 4.1.2-SNAPSHOT + 4.1.2 ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index f41d33f58..2b2148ecc 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 4.1.2-SNAPSHOT + 4.1.2 ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index f97defbbf..eab69094c 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 4.1.2-SNAPSHOT + 4.1.2 ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index 462ca93db..de568c8ef 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 4.1.2-SNAPSHOT + 4.1.2 ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 74f6efe12..105b27b3b 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 4.1.2-SNAPSHOT + 4.1.2 ../pom.xml From c9eb4ab4a2e18e919584c5ccfb664f3d525fc6d3 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 6 Jul 2017 13:47:39 +0300 Subject: [PATCH 395/882] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/pom.xml b/pom.xml index bd1d5f548..15ee61cda 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 4.1.2 + 4.1.3-SNAPSHOT ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -33,7 +33,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - scribejava-4.1.2 + HEAD diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index df8d7351b..6993dd3e5 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 4.1.2 + 4.1.3-SNAPSHOT ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 2b2148ecc..c0721530c 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 4.1.2 + 4.1.3-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index eab69094c..a97c6a073 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 4.1.2 + 4.1.3-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index de568c8ef..1bd473637 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 4.1.2 + 4.1.3-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 105b27b3b..2e122949c 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 4.1.2 + 4.1.3-SNAPSHOT ../pom.xml From 98ec232371e521af119ed4d5489594163adbe3e3 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 12 Jul 2017 12:10:46 +0300 Subject: [PATCH 396/882] DELETE in JdkClient permits, but not requires payload --- changelog | 3 +++ .../core/httpclient/jdk/JDKHttpClient.java | 25 ++++++++++--------- .../github/scribejava/core/model/Verb.java | 17 +++++++++++-- 3 files changed, 31 insertions(+), 14 deletions(-) diff --git a/changelog b/changelog index 4bba4703d..503999697 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,6 @@ +[SNAPSHOT] + * DELETE in JdkClient permits, but not requires payload + [4.1.2] * LinkedIn use Header to sign OAuth2 requests * upgrade ServiceBuilder to check apiKey preconditions compile-time (not run-time) diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java index 761f8be2a..ca38aec48 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java @@ -97,7 +97,7 @@ private Response doExecute(String userAgent, Map headers, Verb h } addHeaders(connection, headers, userAgent); if (httpVerb.isPermitBody()) { - bodyType.setBody(connection, bodyContents); + bodyType.setBody(connection, bodyContents, httpVerb.isRequiresBody()); } try { @@ -114,18 +114,19 @@ private Response doExecute(String userAgent, Map headers, Verb h private enum BodyType { BYTE_ARRAY { @Override - void setBody(HttpURLConnection connection, Object bodyContents) throws IOException { - addBody(connection, (byte[]) bodyContents); + void setBody(HttpURLConnection connection, Object bodyContents, boolean requiresBody) throws IOException { + addBody(connection, (byte[]) bodyContents, requiresBody); } }, STRING { @Override - void setBody(HttpURLConnection connection, Object bodyContents) throws IOException { - addBody(connection, ((String) bodyContents).getBytes()); + void setBody(HttpURLConnection connection, Object bodyContents, boolean requiresBody) throws IOException { + addBody(connection, ((String) bodyContents).getBytes(), requiresBody); } }; - abstract void setBody(HttpURLConnection connection, Object bodyContents) throws IOException; + abstract void setBody(HttpURLConnection connection, Object bodyContents, boolean requiresBody) + throws IOException; } private static Map parseHeaders(HttpURLConnection conn) { @@ -150,14 +151,14 @@ private static void addHeaders(HttpURLConnection connection, Map } } - private static void addBody(HttpURLConnection connection, byte[] content) throws IOException { + private static void addBody(HttpURLConnection connection, byte[] content, boolean requiresBody) throws IOException { final int contentLength = content.length; - connection.setRequestProperty(CONTENT_LENGTH, String.valueOf(contentLength)); + if (requiresBody || contentLength > 0) { + connection.setRequestProperty(CONTENT_LENGTH, String.valueOf(contentLength)); - if (connection.getRequestProperty(CONTENT_TYPE) == null) { - connection.setRequestProperty(CONTENT_TYPE, DEFAULT_CONTENT_TYPE); - } - if (contentLength > 0) { + if (connection.getRequestProperty(CONTENT_TYPE) == null) { + connection.setRequestProperty(CONTENT_TYPE, DEFAULT_CONTENT_TYPE); + } connection.setDoOutput(true); connection.getOutputStream().write(content); } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/Verb.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/Verb.java index ddcebc6b2..8df5fd3f3 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/Verb.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/Verb.java @@ -5,14 +5,27 @@ */ public enum Verb { - GET(false), POST(true), PUT(true), DELETE(true), HEAD(false), OPTIONS(false), TRACE(false), PATCH(true); + GET(false), POST(true), PUT(true), DELETE(false, true), HEAD(false), OPTIONS(false), TRACE(false), PATCH(true); + private final boolean requiresBody; private final boolean permitBody; - Verb(boolean permitBody) { + Verb(boolean requiresBody) { + this(requiresBody, requiresBody); + } + + Verb(boolean requiresBody, boolean permitBody) { + if (requiresBody && !permitBody) { + throw new IllegalArgumentException(); + } + this.requiresBody = requiresBody; this.permitBody = permitBody; } + public boolean isRequiresBody() { + return requiresBody; + } + public boolean isPermitBody() { return permitBody; } From 412c5caf9701def8b2b3a60fd073b7588f2ee3c1 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 12 Jul 2017 12:19:10 +0300 Subject: [PATCH 397/882] drop deprecated methods --- .../core/builder/ServiceBuilder.java | 19 ------------------- 1 file changed, 19 deletions(-) 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 6ae14b1c9..a3ff17365 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 @@ -27,14 +27,6 @@ public class ServiceBuilder { private HttpClientConfig httpClientConfig; private HttpClient httpClient; - /** - * - * @deprecated use {@link #ServiceBuilder(java.lang.String) } - */ - @Deprecated - public ServiceBuilder() { - } - public ServiceBuilder(String apiKey) { apiKey(apiKey); } @@ -138,16 +130,6 @@ public ServiceBuilder debug() { return this; } - /** - * - * @deprecated apiKey will be required param for the ServiceBuilder constructor - * {@link #ServiceBuilder(java.lang.String) } - */ - @Deprecated - public void checkPreconditions() { - Preconditions.checkEmptyString(apiKey, "You must provide an api key"); - } - /** * Returns the fully configured {@link S} * @@ -156,7 +138,6 @@ public void checkPreconditions() { * @return fully configured {@link S} */ public > S build(BaseApi api) { - checkPreconditions(); return api.createService(new OAuthConfig(apiKey, apiSecret, callback, scope, debugStream, state, responseType, userAgent, httpClientConfig, httpClient)); } From 8203bcb982bb4c4ff0d45973060959475c63c59c Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 12 Jul 2017 12:39:14 +0300 Subject: [PATCH 398/882] add blame info to the last changelog's entry --- changelog | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog b/changelog index 503999697..39139caf9 100644 --- a/changelog +++ b/changelog @@ -1,5 +1,5 @@ [SNAPSHOT] - * DELETE in JdkClient permits, but not requires payload + * DELETE in JdkClient permits, but not requires payload (thanks to https://github.com/miguelD73) [4.1.2] * LinkedIn use Header to sign OAuth2 requests From f42812f4db9f49a98520c65de28fef50f380494d Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 13 Jul 2017 13:41:29 +0300 Subject: [PATCH 399/882] introduce generic OpenId OAuth2 Access Token instead of Google --- .../github/scribejava/apis/GoogleApi20.java | 4 +- .../apis/google/GoogleJsonTokenExtractor.java | 8 ++- .../scribejava/apis/google/GoogleToken.java | 67 +++--------------- .../apis/openid/OpenIdJsonTokenExtractor.java | 31 ++++++++ .../apis/openid/OpenIdOAuth2AccessToken.java | 70 +++++++++++++++++++ 5 files changed, 117 insertions(+), 63 deletions(-) create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/openid/OpenIdJsonTokenExtractor.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/openid/OpenIdOAuth2AccessToken.java diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/GoogleApi20.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/GoogleApi20.java index 157753f6d..1e4bd8c6f 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/GoogleApi20.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/GoogleApi20.java @@ -1,6 +1,6 @@ package com.github.scribejava.apis; -import com.github.scribejava.apis.google.GoogleJsonTokenExtractor; +import com.github.scribejava.apis.openid.OpenIdJsonTokenExtractor; import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.extractors.TokenExtractor; import com.github.scribejava.core.model.OAuth2AccessToken; @@ -30,6 +30,6 @@ protected String getAuthorizationBaseUrl() { @Override public TokenExtractor getAccessTokenExtractor() { - return GoogleJsonTokenExtractor.instance(); + return OpenIdJsonTokenExtractor.instance(); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/google/GoogleJsonTokenExtractor.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/google/GoogleJsonTokenExtractor.java index 722390ae0..a343e7f63 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/google/GoogleJsonTokenExtractor.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/google/GoogleJsonTokenExtractor.java @@ -1,12 +1,14 @@ package com.github.scribejava.apis.google; -import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; +import com.github.scribejava.apis.openid.OpenIdJsonTokenExtractor; import java.util.regex.Pattern; /** - * additionally parses OpenID id_token + * + * @deprecated use generic {@link OpenIdJsonTokenExtractor} */ -public class GoogleJsonTokenExtractor extends OAuth2AccessTokenJsonExtractor { +@Deprecated +public class GoogleJsonTokenExtractor extends OpenIdJsonTokenExtractor { private static final Pattern ID_TOKEN_REGEX_PATTERN = Pattern.compile("\"id_token\"\\s*:\\s*\"(\\S*?)\""); diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/google/GoogleToken.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/google/GoogleToken.java index 68ec31f82..aa76087b8 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/google/GoogleToken.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/google/GoogleToken.java @@ -1,70 +1,21 @@ package com.github.scribejava.apis.google; -import com.github.scribejava.core.model.OAuth2AccessToken; -import java.util.Objects; +import com.github.scribejava.apis.openid.OpenIdOAuth2AccessToken; -public class GoogleToken extends OAuth2AccessToken { +/** + * @deprecated use generic {@link OpenIdOAuth2AccessToken} + */ +@Deprecated +public class GoogleToken extends OpenIdOAuth2AccessToken { - private static final long serialVersionUID = 7845679917727899612L; - - /** - * Id_token is part of OpenID Connect specification. It can hold user information that you can directly extract - * without additional request to provider. - * - * See http://openid.net/specs/openid-connect-core-1_0.html#id_token-tokenExample and - * https://bitbucket.org/nimbusds/nimbus-jose-jwt/wiki/Home - * - * Here will be encoded and signed id token in JWT format or null, if not defined. - */ - private final String openIdToken; + private static final long serialVersionUID = -5959403983480821444L; public GoogleToken(String accessToken, String openIdToken, String rawResponse) { - this(accessToken, null, null, null, null, openIdToken, rawResponse); + super(accessToken, null, null, null, null, openIdToken, rawResponse); } public GoogleToken(String accessToken, String tokenType, Integer expiresIn, String refreshToken, String scope, String openIdToken, String rawResponse) { - super(accessToken, tokenType, expiresIn, refreshToken, scope, rawResponse); - this.openIdToken = openIdToken; - } - - public String getOpenIdToken() { - return openIdToken; - } - - @Override - public int hashCode() { - int hash = super.hashCode(); - hash = 37 * hash + Objects.hashCode(openIdToken); - 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(openIdToken, ((GoogleToken) obj).getOpenIdToken()); - } - - @Override - public String toString() { - return "GoogleToken{" - + "access_token=" + getAccessToken() - + ", token_type=" + getTokenType() - + ", expires_in=" + getExpiresIn() - + ", refresh_token=" + getRefreshToken() - + ", scope=" + getScope() - + ", open_id_token=" + openIdToken + '}'; + super(accessToken, tokenType, expiresIn, refreshToken, scope, openIdToken, rawResponse); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/openid/OpenIdJsonTokenExtractor.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/openid/OpenIdJsonTokenExtractor.java new file mode 100644 index 000000000..bec8b0613 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/openid/OpenIdJsonTokenExtractor.java @@ -0,0 +1,31 @@ +package com.github.scribejava.apis.openid; + +import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; +import java.util.regex.Pattern; + +/** + * additionally parses OpenID id_token + */ +public class OpenIdJsonTokenExtractor extends OAuth2AccessTokenJsonExtractor { + + private static final Pattern ID_TOKEN_REGEX_PATTERN = Pattern.compile("\"id_token\"\\s*:\\s*\"(\\S*?)\""); + + protected OpenIdJsonTokenExtractor() { + } + + private static class InstanceHolder { + + private static final OpenIdJsonTokenExtractor INSTANCE = new OpenIdJsonTokenExtractor(); + } + + public static OpenIdJsonTokenExtractor instance() { + return InstanceHolder.INSTANCE; + } + + @Override + protected OpenIdOAuth2AccessToken createToken(String accessToken, String tokenType, Integer expiresIn, + String refreshToken, String scope, String response) { + return new OpenIdOAuth2AccessToken(accessToken, tokenType, expiresIn, refreshToken, scope, + extractParameter(response, ID_TOKEN_REGEX_PATTERN, false), response); + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/openid/OpenIdOAuth2AccessToken.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/openid/OpenIdOAuth2AccessToken.java new file mode 100644 index 000000000..94550ef79 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/openid/OpenIdOAuth2AccessToken.java @@ -0,0 +1,70 @@ +package com.github.scribejava.apis.openid; + +import com.github.scribejava.core.model.OAuth2AccessToken; +import java.util.Objects; + +public class OpenIdOAuth2AccessToken extends OAuth2AccessToken { + + private static final long serialVersionUID = -4534058186528117610L; + + /** + * Id_token is part of OpenID Connect specification. It can hold user information that you can directly extract + * without additional request to provider. + * + * See http://openid.net/specs/openid-connect-core-1_0.html#id_token-tokenExample and + * https://bitbucket.org/nimbusds/nimbus-jose-jwt/wiki/Home + * + * Here will be encoded and signed id token in JWT format or null, if not defined. + */ + private final String openIdToken; + + public OpenIdOAuth2AccessToken(String accessToken, String openIdToken, String rawResponse) { + this(accessToken, null, null, null, null, openIdToken, rawResponse); + } + + public OpenIdOAuth2AccessToken(String accessToken, String tokenType, Integer expiresIn, String refreshToken, + String scope, String openIdToken, String rawResponse) { + super(accessToken, tokenType, expiresIn, refreshToken, scope, rawResponse); + this.openIdToken = openIdToken; + } + + public String getOpenIdToken() { + return openIdToken; + } + + @Override + public int hashCode() { + int hash = super.hashCode(); + hash = 37 * hash + Objects.hashCode(openIdToken); + 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(openIdToken, ((OpenIdOAuth2AccessToken) obj).getOpenIdToken()); + } + + @Override + public String toString() { + return "OpenIdOAuth2AccessToken{" + + "access_token=" + getAccessToken() + + ", token_type=" + getTokenType() + + ", expires_in=" + getExpiresIn() + + ", refresh_token=" + getRefreshToken() + + ", scope=" + getScope() + + ", open_id_token=" + openIdToken + '}'; + } +} From 6dbf10e638cc74b22f2ad8c997e97b94d738213b Mon Sep 17 00:00:00 2001 From: Revant Nandgaonkar Date: Tue, 11 Jul 2017 20:42:56 +0530 Subject: [PATCH 400/882] Added Frappe.io OAuth2 API --- .../com/github/scribejava/apis/FrappeApi.java | 45 ++++++++++++ .../apis/frappe/FrappeJsonTokenExtractor.java | 31 ++++++++ .../scribejava/apis/frappe/FrappeToken.java | 70 +++++++++++++++++++ .../apis/examples/Frappe20Example.java | 69 ++++++++++++++++++ 4 files changed, 215 insertions(+) create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/FrappeApi.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/frappe/FrappeJsonTokenExtractor.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/frappe/FrappeToken.java create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Frappe20Example.java diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/FrappeApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/FrappeApi.java new file mode 100644 index 000000000..b0151cb7f --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/FrappeApi.java @@ -0,0 +1,45 @@ +package com.github.scribejava.apis; + +import com.github.scribejava.apis.frappe.FrappeJsonTokenExtractor; +import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.extractors.TokenExtractor; +import com.github.scribejava.core.model.OAuth2AccessToken; + +public class FrappeApi extends DefaultApi20 { + + private String serverURL = "https://scribejava.mntechnique.com"; + + protected FrappeApi() { + } + + private static class InstanceHolder { + private static final FrappeApi INSTANCE = new FrappeApi(); + } + + public static FrappeApi instance() { + return InstanceHolder.INSTANCE; + } + + public String getServerURL() { + return this.serverURL; + } + + public void setServerURL(String serverURL) { + this.serverURL = serverURL; + } + + @Override + public String getAccessTokenEndpoint() { + return this.serverURL + "/api/method/frappe.integrations.oauth2.get_token"; + } + + @Override + protected String getAuthorizationBaseUrl() { + return this.serverURL + "/api/method/frappe.integrations.oauth2.authorize"; + } + + @Override + public TokenExtractor getAccessTokenExtractor() { + return FrappeJsonTokenExtractor.instance(); + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/frappe/FrappeJsonTokenExtractor.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/frappe/FrappeJsonTokenExtractor.java new file mode 100644 index 000000000..ddf7fe9c8 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/frappe/FrappeJsonTokenExtractor.java @@ -0,0 +1,31 @@ +package com.github.scribejava.apis.frappe; + +import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; +import java.util.regex.Pattern; + +/** + * additionally parses OpenID id_token + */ +public class FrappeJsonTokenExtractor extends OAuth2AccessTokenJsonExtractor { + + private static final Pattern ID_TOKEN_REGEX_PATTERN = Pattern.compile("\"id_token\"\\s*:\\s*\"(\\S*?)\""); + + protected FrappeJsonTokenExtractor() { + } + + private static class InstanceHolder { + + private static final FrappeJsonTokenExtractor INSTANCE = new FrappeJsonTokenExtractor(); + } + + public static FrappeJsonTokenExtractor instance() { + return InstanceHolder.INSTANCE; + } + + @Override + protected FrappeToken createToken(String accessToken, String tokenType, Integer expiresIn, + String refreshToken, String scope, String response) { + return new FrappeToken(accessToken, tokenType, expiresIn, refreshToken, scope, + extractParameter(response, ID_TOKEN_REGEX_PATTERN, false), response); + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/frappe/FrappeToken.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/frappe/FrappeToken.java new file mode 100644 index 000000000..cc2776d87 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/frappe/FrappeToken.java @@ -0,0 +1,70 @@ +package com.github.scribejava.apis.frappe; + +import com.github.scribejava.core.model.OAuth2AccessToken; +import java.util.Objects; + +public class FrappeToken extends OAuth2AccessToken { + + private static final long serialVersionUID = 7845679917727899612L; + + /** + * Id_token is part of OpenID Connect specification. It can hold user information that you can directly extract + * without additional request to provider. + * + * See http://openid.net/specs/openid-connect-core-1_0.html#id_token-tokenExample and + * https://bitbucket.org/nimbusds/nimbus-jose-jwt/wiki/Home + * + * Here will be encoded and signed id token in JWT format or null, if not defined. + */ + private final String openIdToken; + + public FrappeToken(String accessToken, String openIdToken, String rawResponse) { + this(accessToken, null, null, null, null, openIdToken, rawResponse); + } + + public FrappeToken(String accessToken, String tokenType, Integer expiresIn, String refreshToken, String scope, + String openIdToken, String rawResponse) { + super(accessToken, tokenType, expiresIn, refreshToken, scope, rawResponse); + this.openIdToken = openIdToken; + } + + public String getOpenIdToken() { + return openIdToken; + } + + @Override + public int hashCode() { + int hash = super.hashCode(); + hash = 37 * hash + Objects.hashCode(openIdToken); + 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(openIdToken, ((FrappeToken) obj).getOpenIdToken()); + } + + @Override + public String toString() { + return "FrappeToken{" + + "access_token=" + getAccessToken() + + ", token_type=" + getTokenType() + + ", expires_in=" + getExpiresIn() + + ", refresh_token=" + getRefreshToken() + + ", scope=" + getScope() + + ", open_id_token=" + openIdToken + '}'; + } +} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Frappe20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Frappe20Example.java new file mode 100644 index 000000000..25e0f4e79 --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Frappe20Example.java @@ -0,0 +1,69 @@ +package com.github.scribejava.apis.examples; + +import java.util.Scanner; +import com.github.scribejava.core.builder.ServiceBuilder; +import com.github.scribejava.apis.FrappeApi; +import com.github.scribejava.core.model.OAuth2AccessToken; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.oauth.OAuth20Service; +import java.io.IOException; +import java.util.concurrent.ExecutionException; + +public final class Frappe20Example { + + private static final String NETWORK_NAME = "Frappe"; + private static final String PROTECTED_RESOURCE_URL = "https://scribejava.mntechnique.com/" + + "api/method/frappe.integrations.oauth2.openid_profile"; + + private Frappe20Example() { + } + + public static void main(String... args) throws IOException, InterruptedException, ExecutionException { + //Replace these with your client id and secret + final String clientId = "37763ecdb0"; + final String clientSecret = "3e1d716ea7"; + final OAuth20Service service = new ServiceBuilder(clientId) + .apiSecret(clientSecret) + .scope("openid all") + .callback("https://example.com/callback") + .build(FrappeApi.instance()); + final Scanner in = new Scanner(System.in, "UTF-8"); + + System.out.println("=== " + NETWORK_NAME + "'s OAuth 2.0 Workflow ==="); + System.out.println(); + + // Obtain the Authorization URL + System.out.println("Fetching the Authorization URL..."); + final String authorizationUrl = service.getAuthorizationUrl(); + System.out.println("Got the Authorization URL!"); + System.out.println("Now go and authorize ScribeJava here:"); + System.out.println(authorizationUrl); + System.out.println("And paste the authorization code here"); + System.out.print(">>"); + final String code = in.nextLine(); + System.out.println(); + + // Trade the Authorization Code for the Access Token + System.out.println("Trading the Request Token for an Access Token..."); + final OAuth2AccessToken accessToken = service.getAccessToken(code); + System.out.println("Got the Access Token!"); + System.out.println("(If you're curious, it looks like this: " + accessToken + + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + + System.out.println(); + + // Now let's go and ask for a protected resource! + System.out.println("Now we're going to access a protected resource..."); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); + service.signRequest(accessToken, request); + final Response response = service.execute(request); + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + + System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); + } +} From 48d17c2f986af2e611c467d2f996c5d543fba859 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 13 Jul 2017 13:55:27 +0300 Subject: [PATCH 401/882] new API Frappe additions --- README.md | 1 + changelog | 1 + .../com/github/scribejava/apis/FrappeApi.java | 31 ++++---- .../apis/frappe/FrappeJsonTokenExtractor.java | 31 -------- .../scribejava/apis/frappe/FrappeToken.java | 70 ------------------- ...rappe20Example.java => FrappeExample.java} | 16 ++--- 6 files changed, 24 insertions(+), 126 deletions(-) delete mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/frappe/FrappeJsonTokenExtractor.java delete mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/frappe/FrappeToken.java rename scribejava-apis/src/test/java/com/github/scribejava/apis/examples/{Frappe20Example.java => FrappeExample.java} (86%) diff --git a/README.md b/README.md index a73907c92..087c0f430 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,7 @@ ScribeJava support out-of-box several HTTP clients: * Facebook (https://www.facebook.com/) * Flickr (https://www.flickr.com/) * Foursquare (https://foursquare.com/) +* Frappe (https://github.com/frappe/frappe) * Freelancer (https://www.freelancer.com/) * Genius (http://genius.com/) * GitHub (https://github.com/) diff --git a/changelog b/changelog index 39139caf9..01f18217c 100644 --- a/changelog +++ b/changelog @@ -1,5 +1,6 @@ [SNAPSHOT] * DELETE in JdkClient permits, but not requires payload (thanks to https://github.com/miguelD73) + * add new API - Frappe (https://github.com/frappe/frappe) (thanks to https://github.com/revant) [4.1.2] * LinkedIn use Header to sign OAuth2 requests diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/FrappeApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/FrappeApi.java index b0151cb7f..ec4cc61f4 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/FrappeApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/FrappeApi.java @@ -1,45 +1,42 @@ package com.github.scribejava.apis; -import com.github.scribejava.apis.frappe.FrappeJsonTokenExtractor; +import com.github.scribejava.apis.openid.OpenIdJsonTokenExtractor; import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.extractors.TokenExtractor; import com.github.scribejava.core.model.OAuth2AccessToken; public class FrappeApi extends DefaultApi20 { - private String serverURL = "https://scribejava.mntechnique.com"; + private final String serverURL; + private final String accessTokenEndpoint; + private final String authorizationBaseUrl; - protected FrappeApi() { - } - - private static class InstanceHolder { - private static final FrappeApi INSTANCE = new FrappeApi(); + protected FrappeApi(String serverURL) { + this.serverURL = serverURL; + this.accessTokenEndpoint = serverURL + "/api/method/frappe.integrations.oauth2.get_token"; + this.authorizationBaseUrl = serverURL + "/api/method/frappe.integrations.oauth2.authorize"; } - public static FrappeApi instance() { - return InstanceHolder.INSTANCE; + public static FrappeApi instance(String serverUrl) { + return new FrappeApi(serverUrl); } public String getServerURL() { - return this.serverURL; - } - - public void setServerURL(String serverURL) { - this.serverURL = serverURL; + return serverURL; } @Override public String getAccessTokenEndpoint() { - return this.serverURL + "/api/method/frappe.integrations.oauth2.get_token"; + return accessTokenEndpoint; } @Override protected String getAuthorizationBaseUrl() { - return this.serverURL + "/api/method/frappe.integrations.oauth2.authorize"; + return authorizationBaseUrl; } @Override public TokenExtractor getAccessTokenExtractor() { - return FrappeJsonTokenExtractor.instance(); + return OpenIdJsonTokenExtractor.instance(); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/frappe/FrappeJsonTokenExtractor.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/frappe/FrappeJsonTokenExtractor.java deleted file mode 100644 index ddf7fe9c8..000000000 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/frappe/FrappeJsonTokenExtractor.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.github.scribejava.apis.frappe; - -import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; -import java.util.regex.Pattern; - -/** - * additionally parses OpenID id_token - */ -public class FrappeJsonTokenExtractor extends OAuth2AccessTokenJsonExtractor { - - private static final Pattern ID_TOKEN_REGEX_PATTERN = Pattern.compile("\"id_token\"\\s*:\\s*\"(\\S*?)\""); - - protected FrappeJsonTokenExtractor() { - } - - private static class InstanceHolder { - - private static final FrappeJsonTokenExtractor INSTANCE = new FrappeJsonTokenExtractor(); - } - - public static FrappeJsonTokenExtractor instance() { - return InstanceHolder.INSTANCE; - } - - @Override - protected FrappeToken createToken(String accessToken, String tokenType, Integer expiresIn, - String refreshToken, String scope, String response) { - return new FrappeToken(accessToken, tokenType, expiresIn, refreshToken, scope, - extractParameter(response, ID_TOKEN_REGEX_PATTERN, false), response); - } -} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/frappe/FrappeToken.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/frappe/FrappeToken.java deleted file mode 100644 index cc2776d87..000000000 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/frappe/FrappeToken.java +++ /dev/null @@ -1,70 +0,0 @@ -package com.github.scribejava.apis.frappe; - -import com.github.scribejava.core.model.OAuth2AccessToken; -import java.util.Objects; - -public class FrappeToken extends OAuth2AccessToken { - - private static final long serialVersionUID = 7845679917727899612L; - - /** - * Id_token is part of OpenID Connect specification. It can hold user information that you can directly extract - * without additional request to provider. - * - * See http://openid.net/specs/openid-connect-core-1_0.html#id_token-tokenExample and - * https://bitbucket.org/nimbusds/nimbus-jose-jwt/wiki/Home - * - * Here will be encoded and signed id token in JWT format or null, if not defined. - */ - private final String openIdToken; - - public FrappeToken(String accessToken, String openIdToken, String rawResponse) { - this(accessToken, null, null, null, null, openIdToken, rawResponse); - } - - public FrappeToken(String accessToken, String tokenType, Integer expiresIn, String refreshToken, String scope, - String openIdToken, String rawResponse) { - super(accessToken, tokenType, expiresIn, refreshToken, scope, rawResponse); - this.openIdToken = openIdToken; - } - - public String getOpenIdToken() { - return openIdToken; - } - - @Override - public int hashCode() { - int hash = super.hashCode(); - hash = 37 * hash + Objects.hashCode(openIdToken); - 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(openIdToken, ((FrappeToken) obj).getOpenIdToken()); - } - - @Override - public String toString() { - return "FrappeToken{" - + "access_token=" + getAccessToken() - + ", token_type=" + getTokenType() - + ", expires_in=" + getExpiresIn() - + ", refresh_token=" + getRefreshToken() - + ", scope=" + getScope() - + ", open_id_token=" + openIdToken + '}'; - } -} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Frappe20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FrappeExample.java similarity index 86% rename from scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Frappe20Example.java rename to scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FrappeExample.java index 25e0f4e79..fe704ed7a 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Frappe20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FrappeExample.java @@ -11,24 +11,24 @@ import java.io.IOException; import java.util.concurrent.ExecutionException; -public final class Frappe20Example { +public final class FrappeExample { private static final String NETWORK_NAME = "Frappe"; - private static final String PROTECTED_RESOURCE_URL = "https://scribejava.mntechnique.com/" + - "api/method/frappe.integrations.oauth2.openid_profile"; + private static final String PROTECTED_RESOURCE_PATH = "/api/method/frappe.integrations.oauth2.openid_profile"; - private Frappe20Example() { + private FrappeExample() { } public static void main(String... args) throws IOException, InterruptedException, ExecutionException { //Replace these with your client id and secret - final String clientId = "37763ecdb0"; - final String clientSecret = "3e1d716ea7"; + final String clientId = "clientId"; + final String clientSecret = "clientSecret"; + final String clientDomain = "https://example.com"; final OAuth20Service service = new ServiceBuilder(clientId) .apiSecret(clientSecret) .scope("openid all") .callback("https://example.com/callback") - .build(FrappeApi.instance()); + .build(FrappeApi.instance(clientDomain)); final Scanner in = new Scanner(System.in, "UTF-8"); System.out.println("=== " + NETWORK_NAME + "'s OAuth 2.0 Workflow ==="); @@ -56,7 +56,7 @@ public static void main(String... args) throws IOException, InterruptedException // Now let's go and ask for a protected resource! System.out.println("Now we're going to access a protected resource..."); - final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); + final OAuthRequest request = new OAuthRequest(Verb.GET, clientDomain + PROTECTED_RESOURCE_PATH); service.signRequest(accessToken, request); final Response response = service.execute(request); System.out.println("Got it! Lets see what we found..."); From 6b516810b399f5fcbefabb68bcf5f4c582f3edd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Efe=20Kocaba=C5=9F?= Date: Tue, 25 Jul 2017 11:58:29 +0300 Subject: [PATCH 402/882] Added EtsyAPI --- README.md | 1 + .../com/github/scribejava/apis/EtsyApi.java | 52 +++++++++++++++ .../scribejava/apis/examples/EtsyExample.java | 66 +++++++++++++++++++ 3 files changed, 119 insertions(+) create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/EtsyApi.java create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/EtsyExample.java diff --git a/README.md b/README.md index 087c0f430..297e4dae5 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,7 @@ ScribeJava support out-of-box several HTTP clients: * Box (https://www.box.com/) * Digg (http://digg.com/) * Доктор на работе (https://www.doktornarabote.ru/) +* Etsy (https://www.etsy.com/) * Facebook (https://www.facebook.com/) * Flickr (https://www.flickr.com/) * Foursquare (https://foursquare.com/) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/EtsyApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/EtsyApi.java new file mode 100644 index 000000000..bd8a660ba --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/EtsyApi.java @@ -0,0 +1,52 @@ +package com.github.scribejava.apis; + +import com.github.scribejava.core.builder.api.DefaultApi10a; +import com.github.scribejava.core.model.OAuth1RequestToken; + +public class EtsyApi extends DefaultApi10a { + + private static final String AUTHORIZE_URL = "https://www.etsy.com/oauth/signin?oauth_token=%s"; + private static final String ACCESS_TOKEN_URL = "https://openapi.etsy.com/v2/oauth/access_token"; + private static final String REQUEST_TOKEN_URL = "https://openapi.etsy.com/v2/oauth/request_token"; + + private final String scopeAsString; + + private EtsyApi() { + scopeAsString = null; + } + + private EtsyApi(String... scopes) { + final StringBuilder builder = new StringBuilder(); + for (String scope : scopes) { + builder.append("%20").append(scope); + } + scopeAsString = "?scope=" + builder.substring(3); + } + + private static class InstanceHolder { + private static final EtsyApi INSTANCE = new EtsyApi(); + } + + public static EtsyApi instance() { + return InstanceHolder.INSTANCE; + } + + public static EtsyApi instance(String... scopes) { + return scopes == null || scopes.length == 0 ? instance() : new EtsyApi(scopes); + } + + @Override + public String getAccessTokenEndpoint() { + return ACCESS_TOKEN_URL; + } + + @Override + public String getRequestTokenEndpoint() { + return scopeAsString == null ? REQUEST_TOKEN_URL : REQUEST_TOKEN_URL + scopeAsString; + } + + @Override + public String getAuthorizationUrl(OAuth1RequestToken requestToken) { + return String.format(AUTHORIZE_URL, requestToken.getToken()); + } +} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/EtsyExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/EtsyExample.java new file mode 100644 index 000000000..115617f71 --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/EtsyExample.java @@ -0,0 +1,66 @@ +package com.github.scribejava.apis.examples; + +import com.github.scribejava.apis.EtsyApi; +import com.github.scribejava.core.builder.ServiceBuilder; +import com.github.scribejava.core.model.OAuth1AccessToken; +import com.github.scribejava.core.model.OAuth1RequestToken; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.oauth.OAuth10aService; + +import java.io.IOException; +import java.util.Scanner; +import java.util.concurrent.ExecutionException; + +public final class EtsyExample { + + private static final String PROTECTED_RESOURCE_URL = "https://openapi.etsy.com/v2/users/__SELF__"; + + private EtsyExample() { + } + + public static void main(String[] args) throws InterruptedException, ExecutionException, IOException { + // Replace with your api and secret key + final OAuth10aService service = new ServiceBuilder("your api key") + .apiSecret("your secret key") + .build(EtsyApi.instance()); + final Scanner in = new Scanner(System.in); + + System.out.println("=== Etsy's OAuth Workflow ==="); + System.out.println(); + + // Obtain the Request Token + System.out.println("Fetching the Request Token..."); + final OAuth1RequestToken requestToken = service.getRequestToken(); + System.out.println("Got the Request Token!"); + System.out.println(); + + System.out.println("Now go and authorize ScribeJava here:"); + System.out.println(service.getAuthorizationUrl(requestToken)); + System.out.println("And paste the verifier here"); + System.out.print(">>"); + final String oauthVerifier = in.nextLine(); + System.out.println(); + + // Trade the Request Token and Verifier for the Access Token + System.out.println("Trading the Request Token for an Access Token..."); + final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); + System.out.println("Got the Access Token!"); + System.out.println("(if your curious it looks like this: " + accessToken + + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println(); + + // Now let's go and ask for a protected resource! + System.out.println("Now we're going to access a protected resource..."); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); + service.signRequest(accessToken, request); + final Response response = service.execute(request); + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getBody()); + + System.out.println(); + System.out.println("That's it man! Go and build something awesome with ScribeJava! :)"); + } +} From 3dd5ef1236d4db7f38c0003208f1c335cc80b52f Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 25 Jul 2017 15:49:57 +0300 Subject: [PATCH 403/882] add new API - Etsy (https://www.etsy.com/) (thanks to https://github.com/efekocabas) --- changelog | 1 + 1 file changed, 1 insertion(+) diff --git a/changelog b/changelog index 01f18217c..2ec48024f 100644 --- a/changelog +++ b/changelog @@ -1,6 +1,7 @@ [SNAPSHOT] * DELETE in JdkClient permits, but not requires payload (thanks to https://github.com/miguelD73) * add new API - Frappe (https://github.com/frappe/frappe) (thanks to https://github.com/revant) + * add new API - Etsy (https://www.etsy.com/) (thanks to https://github.com/efekocabas) [4.1.2] * LinkedIn use Header to sign OAuth2 requests From 7ede38639987f0b4c727ae2e2be1da73dd4a21b8 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 25 Jul 2017 15:54:42 +0300 Subject: [PATCH 404/882] prepare 4.2.0 --- README.md | 4 ++-- changelog | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 297e4dae5..439c26ae3 100644 --- a/README.md +++ b/README.md @@ -101,7 +101,7 @@ You can pull ScribeJava from the central maven repository, just add these to you com.github.scribejava scribejava-apis - 4.1.2 + 4.2.0 ``` @@ -110,7 +110,7 @@ And in case you need just core classes (that's it, without any external API (FB, com.github.scribejava scribejava-core - 4.1.2 + 4.2.0 ``` diff --git a/changelog b/changelog index 2ec48024f..5b9f19d96 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,4 @@ -[SNAPSHOT] +[4.2.0] * DELETE in JdkClient permits, but not requires payload (thanks to https://github.com/miguelD73) * add new API - Frappe (https://github.com/frappe/frappe) (thanks to https://github.com/revant) * add new API - Etsy (https://www.etsy.com/) (thanks to https://github.com/efekocabas) From 73c8b425dd52d22f61d28ea80a6ced675f074df5 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 25 Jul 2017 15:55:45 +0300 Subject: [PATCH 405/882] [maven-release-plugin] prepare release scribejava-4.2.0 --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/pom.xml b/pom.xml index 15ee61cda..ab3f8dda0 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 4.1.3-SNAPSHOT + 4.2.0 ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -33,7 +33,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - HEAD + scribejava-4.2.0 diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 6993dd3e5..93cb6bac9 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 4.1.3-SNAPSHOT + 4.2.0 ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index c0721530c..82c1e2074 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 4.1.3-SNAPSHOT + 4.2.0 ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index a97c6a073..bea98dd2f 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 4.1.3-SNAPSHOT + 4.2.0 ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index 1bd473637..4bd0e96aa 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 4.1.3-SNAPSHOT + 4.2.0 ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 2e122949c..759a1e059 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 4.1.3-SNAPSHOT + 4.2.0 ../pom.xml From b2cdee90e327992654bab56ce609aba4b60af427 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 25 Jul 2017 15:56:02 +0300 Subject: [PATCH 406/882] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/pom.xml b/pom.xml index ab3f8dda0..139715de1 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 4.2.0 + 4.2.1-SNAPSHOT ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -33,7 +33,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - scribejava-4.2.0 + HEAD diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 93cb6bac9..583b8cdac 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 4.2.0 + 4.2.1-SNAPSHOT ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 82c1e2074..e2355021b 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 4.2.0 + 4.2.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index bea98dd2f..02eb03fe0 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 4.2.0 + 4.2.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index 4bd0e96aa..0142e94c0 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 4.2.0 + 4.2.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 759a1e059..12e034874 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 4.2.0 + 4.2.1-SNAPSHOT ../pom.xml From 868fb7c6c2ca1da0025160824f135720b4ad85b9 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 25 Jul 2017 16:08:11 +0300 Subject: [PATCH 407/882] clean deprecates --- .../apis/google/GoogleJsonTokenExtractor.java | 33 ------------------- .../scribejava/apis/google/GoogleToken.java | 21 ------------ 2 files changed, 54 deletions(-) delete mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/google/GoogleJsonTokenExtractor.java delete mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/google/GoogleToken.java diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/google/GoogleJsonTokenExtractor.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/google/GoogleJsonTokenExtractor.java deleted file mode 100644 index a343e7f63..000000000 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/google/GoogleJsonTokenExtractor.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.github.scribejava.apis.google; - -import com.github.scribejava.apis.openid.OpenIdJsonTokenExtractor; -import java.util.regex.Pattern; - -/** - * - * @deprecated use generic {@link OpenIdJsonTokenExtractor} - */ -@Deprecated -public class GoogleJsonTokenExtractor extends OpenIdJsonTokenExtractor { - - private static final Pattern ID_TOKEN_REGEX_PATTERN = Pattern.compile("\"id_token\"\\s*:\\s*\"(\\S*?)\""); - - protected GoogleJsonTokenExtractor() { - } - - private static class InstanceHolder { - - private static final GoogleJsonTokenExtractor INSTANCE = new GoogleJsonTokenExtractor(); - } - - public static GoogleJsonTokenExtractor instance() { - return InstanceHolder.INSTANCE; - } - - @Override - protected GoogleToken createToken(String accessToken, String tokenType, Integer expiresIn, - String refreshToken, String scope, String response) { - return new GoogleToken(accessToken, tokenType, expiresIn, refreshToken, scope, - extractParameter(response, ID_TOKEN_REGEX_PATTERN, false), response); - } -} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/google/GoogleToken.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/google/GoogleToken.java deleted file mode 100644 index aa76087b8..000000000 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/google/GoogleToken.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.github.scribejava.apis.google; - -import com.github.scribejava.apis.openid.OpenIdOAuth2AccessToken; - -/** - * @deprecated use generic {@link OpenIdOAuth2AccessToken} - */ -@Deprecated -public class GoogleToken extends OpenIdOAuth2AccessToken { - - private static final long serialVersionUID = -5959403983480821444L; - - public GoogleToken(String accessToken, String openIdToken, String rawResponse) { - super(accessToken, null, null, null, null, openIdToken, rawResponse); - } - - public GoogleToken(String accessToken, String tokenType, Integer expiresIn, String refreshToken, String scope, - String openIdToken, String rawResponse) { - super(accessToken, tokenType, expiresIn, refreshToken, scope, openIdToken, rawResponse); - } -} From 52d4dc06a57a28ceb7accd7ab50bfadb1be8fc41 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 26 Jul 2017 18:53:34 +0300 Subject: [PATCH 408/882] drop Java 7 backward compatibility support, become Java 8 only --- .travis.yml | 4 +-- changelog | 3 ++ checkstyle.xml | 1 - pom.xml | 28 ++-------------- .../apis/service/MailruOAuthServiceImpl.java | 12 +++---- .../service/OdnoklassnikiServiceImpl.java | 11 ++++--- .../apis/examples/RenrenExample.java | 32 +++++++++---------- .../core/extractors/HeaderExtractorImpl.java | 21 +++++------- .../core/httpclient/jdk/JDKHttpClient.java | 14 +++----- .../scribejava/core/model/ParameterList.java | 15 ++++----- .../core/oauth/OAuth10aService.java | 22 +++---------- .../scribejava/core/oauth/OAuth20Service.java | 8 +---- .../scribejava/core/utils/MapUtils.java | 25 --------------- .../core/oauth/OAuth20ServiceUnit.java | 5 +-- .../scribejava/core/utils/MapUtilsTest.java | 31 ------------------ .../ning/OAuthAsyncCompletionHandler.java | 17 +++------- .../httpclient/okhttp/OkHttpHttpClient.java | 15 ++++----- 17 files changed, 70 insertions(+), 194 deletions(-) delete mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/utils/MapUtils.java delete mode 100644 scribejava-core/src/test/java/com/github/scribejava/core/utils/MapUtilsTest.java diff --git a/.travis.yml b/.travis.yml index a79954ad5..80a91cb59 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,8 @@ +dist: trusty language: java script: mvn clean package jdk: - oraclejdk8 - - oraclejdk7 - - openjdk7 + - openjdk8 os: - linux diff --git a/changelog b/changelog index 5b9f19d96..84e7a582d 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,6 @@ +[SNAPSHOT] + * drop Java 7 backward compatibility support, become Java 8 only + [4.2.0] * DELETE in JdkClient permits, but not requires payload (thanks to https://github.com/miguelD73) * add new API - Frappe (https://github.com/frappe/frappe) (thanks to https://github.com/revant) diff --git a/checkstyle.xml b/checkstyle.xml index 9cba55776..2955d30b9 100644 --- a/checkstyle.xml +++ b/checkstyle.xml @@ -76,7 +76,6 @@ - diff --git a/pom.xml b/pom.xml index 139715de1..7b8520909 100644 --- a/pom.xml +++ b/pom.xml @@ -151,8 +151,8 @@ 3.6.1 UTF-8 - 1.7 - 1.7 + 1.8 + 1.8 true @@ -229,30 +229,6 @@
- - jdk-1.7 - - 1.7 - - - - - - org.apache.maven.plugins - maven-checkstyle-plugin - 2.17 - - - com.puppycrawl.tools - checkstyle - 6.19 - - - - - - - release-sign-artifacts diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthServiceImpl.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthServiceImpl.java index 3330bb006..86bcb79ab 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthServiceImpl.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthServiceImpl.java @@ -11,6 +11,7 @@ import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.oauth.OAuth20Service; +import java.util.stream.Collectors; public class MailruOAuthServiceImpl extends OAuth20Service { @@ -35,13 +36,10 @@ public void signRequest(OAuth2AccessToken accessToken, OAuthRequest request) { final String[] parts = param.split("="); map.put(parts[0], (parts.length == 1) ? "" : parts[1]); } - final StringBuilder urlNew = new StringBuilder(); - for (Map.Entry entry : map.entrySet()) { - urlNew.append(entry.getKey()); - urlNew.append('='); - urlNew.append(entry.getValue()); - } - final String sigSource = URLDecoder.decode(urlNew.toString(), CharEncoding.UTF_8) + clientSecret; + final String urlNew = map.entrySet().stream() + .map(entry -> entry.getKey() + '=' + entry.getValue()) + .collect(Collectors.joining()); + final String sigSource = URLDecoder.decode(urlNew, CharEncoding.UTF_8) + clientSecret; request.addQuerystringParameter("sig", md5Hex(sigSource)); } } catch (UnsupportedEncodingException e) { diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiServiceImpl.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiServiceImpl.java index fa9ae2e56..7e9017978 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiServiceImpl.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiServiceImpl.java @@ -14,6 +14,7 @@ import java.net.URLDecoder; import java.util.Collections; import java.util.List; +import java.util.stream.Collectors; import static org.apache.commons.codec.digest.DigestUtils.md5Hex; @@ -34,12 +35,12 @@ public void signRequest(OAuth2AccessToken accessToken, OAuthRequest request) { final List allParams = queryParams.getParams(); Collections.sort(allParams); - final StringBuilder builder = new StringBuilder(); - for (Parameter param : allParams) { - builder.append(param.getKey()).append('=').append(param.getValue()); - } - final String sigSource = URLDecoder.decode(builder.toString(), CharEncoding.UTF_8) + tokenDigest; + final String stringParams = allParams.stream() + .map(param -> param.getKey() + '=' + param.getValue()) + .collect(Collectors.joining()); + + final String sigSource = URLDecoder.decode(stringParams, CharEncoding.UTF_8) + tokenDigest; request.addQuerystringParameter("sig", md5Hex(sigSource).toLowerCase()); super.signRequest(accessToken, request); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java index 1eea7e581..eaeb35532 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java @@ -3,10 +3,7 @@ import java.nio.charset.Charset; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; -import java.util.ArrayList; -import java.util.Collections; import java.util.HashMap; -import java.util.List; import java.util.Map; import java.util.Scanner; import com.github.scribejava.core.builder.ServiceBuilder; @@ -19,6 +16,8 @@ import com.github.scribejava.core.oauth.OAuth20Service; import java.io.IOException; import java.util.concurrent.ExecutionException; +import java.util.stream.Collectors; +import java.util.stream.Stream; public final class RenrenExample { @@ -69,20 +68,19 @@ public static void main(String... args) throws IOException, InterruptedException parameters.put("format", "json"); parameters.put("v", "1.0"); - final List sigString = new ArrayList<>(parameters.size() + 1); - for (Map.Entry entry : parameters.entrySet()) { - request.addQuerystringParameter(entry.getKey(), entry.getValue()); - sigString.add(String.format("%s=%s", entry.getKey(), entry.getValue())); - } - sigString.add(String.format("%s=%s", OAuthConstants.ACCESS_TOKEN, accessToken.getAccessToken())); - Collections.sort(sigString); - final StringBuilder b = new StringBuilder(); - for (String param : sigString) { - b.append(param); - } - b.append(apiSecret); - System.out.println("Sig string: " + b.toString()); - request.addQuerystringParameter("sig", md5(b.toString())); + parameters.forEach((key, value) -> request.addQuerystringParameter(key, value)); + + final String sig = Stream.concat( + Stream.concat( + parameters.entrySet().stream() + .map(entry -> String.format("%s=%s", entry.getKey(), entry.getValue())), + Stream.of(String.format("%s=%s", OAuthConstants.ACCESS_TOKEN, accessToken.getAccessToken()))) + .sorted(), + Stream.of(apiSecret)) + .collect(Collectors.joining()); + + System.out.println("Sig string: " + sig); + request.addQuerystringParameter("sig", md5(sig)); service.signRequest(accessToken, request); final Response response = service.execute(request); System.out.println("Got it! Lets see what we found..."); diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/HeaderExtractorImpl.java b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/HeaderExtractorImpl.java index 2a840521c..a29ba9839 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/HeaderExtractorImpl.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/HeaderExtractorImpl.java @@ -6,13 +6,13 @@ import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.utils.OAuthEncoder; import com.github.scribejava.core.utils.Preconditions; +import java.util.stream.Collectors; /** * Default implementation of {@link HeaderExtractor}. Conforms to OAuth 1.0a */ public class HeaderExtractorImpl implements HeaderExtractor { - public static final int ESTIMATED_PARAM_LENGTH = 20; private static final String PARAM_SEPARATOR = ", "; private static final String PREAMBLE = "OAuth "; @@ -23,21 +23,16 @@ public class HeaderExtractorImpl implements HeaderExtractor { public String extract(OAuthRequest request) { checkPreconditions(request); final Map parameters = request.getOauthParameters(); - final StringBuilder header = new StringBuilder(parameters.size() * ESTIMATED_PARAM_LENGTH); - header.append(PREAMBLE); - for (Map.Entry entry : parameters.entrySet()) { - if (header.length() > PREAMBLE.length()) { - header.append(PARAM_SEPARATOR); - } - header.append(String.format("%s=\"%s\"", entry.getKey(), OAuthEncoder.encode(entry.getValue()))); - } - if (request.getRealm() != null && !request.getRealm().isEmpty()) { - header.append(PARAM_SEPARATOR); - header.append(String.format("%s=\"%s\"", OAuthConstants.REALM, request.getRealm())); + final String paramsString = parameters.entrySet().stream() + .map(entry -> String.format("%s=\"%s\"", entry.getKey(), OAuthEncoder.encode(entry.getValue()))) + .collect(Collectors.joining(PARAM_SEPARATOR, PREAMBLE, "")); + + if (request.getRealm() == null || request.getRealm().isEmpty()) { + return paramsString; } - return header.toString(); + return paramsString + PARAM_SEPARATOR + String.format("%s=\"%s\"", OAuthConstants.REALM, request.getRealm()); } private void checkPreconditions(OAuthRequest request) { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java index ca38aec48..8a6f3e516 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java @@ -13,7 +13,6 @@ import java.net.URL; import java.net.UnknownHostException; import java.util.HashMap; -import java.util.List; import java.util.Map; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; @@ -131,21 +130,18 @@ abstract void setBody(HttpURLConnection connection, Object bodyContents, boolean private static Map parseHeaders(HttpURLConnection conn) { final Map headers = new HashMap<>(); - for (Map.Entry> entry : conn.getHeaderFields().entrySet()) { - final String key = entry.getKey(); + conn.getHeaderFields().forEach((key, value) -> { if ("Content-Encoding".equalsIgnoreCase(key)) { - headers.put("Content-Encoding", entry.getValue().get(0)); + headers.put("Content-Encoding", value.get(0)); } else { - headers.put(key, entry.getValue().get(0)); + headers.put(key, value.get(0)); } - } + }); return headers; } private static void addHeaders(HttpURLConnection connection, Map headers, String userAgent) { - for (Map.Entry entry : headers.entrySet()) { - connection.setRequestProperty(entry.getKey(), entry.getValue()); - } + headers.forEach((key, value) -> connection.setRequestProperty(key, value)); if (userAgent != null) { connection.setRequestProperty(OAuthConstants.USER_AGENT_HEADER_NAME, userAgent); } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/ParameterList.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/ParameterList.java index 39d806652..0282eaca7 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/ParameterList.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/ParameterList.java @@ -6,6 +6,7 @@ import java.util.Map; import com.github.scribejava.core.utils.OAuthEncoder; import com.github.scribejava.core.utils.Preconditions; +import java.util.stream.Collectors; public class ParameterList { @@ -27,9 +28,9 @@ public ParameterList() { public ParameterList(Map map) { this(); if (map != null && !map.isEmpty()) { - for (Map.Entry entry : map.entrySet()) { - params.add(new Parameter(entry.getKey(), entry.getValue())); - } + map.entrySet().stream() + .map(entry -> new Parameter(entry.getKey(), entry.getValue())) + .forEach(params::add); } } @@ -58,11 +59,9 @@ public String asFormUrlEncodedString() { return EMPTY_STRING; } - final StringBuilder builder = new StringBuilder(); - for (Parameter p : params) { - builder.append(PARAM_SEPARATOR).append(p.asUrlEncodedPair()); - } - return builder.substring(1); + return params.stream() + .map(Parameter::asUrlEncodedPair) + .collect(Collectors.joining(PARAM_SEPARATOR)); } public void addAll(ParameterList other) { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java index ad9e6eda0..00be552cb 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java @@ -1,7 +1,6 @@ package com.github.scribejava.core.oauth; import java.io.IOException; -import java.util.Map; import java.util.concurrent.Future; import com.github.scribejava.core.builder.api.DefaultApi10a; import com.github.scribejava.core.builder.api.OAuth1SignatureType; @@ -13,7 +12,6 @@ import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; import com.github.scribejava.core.services.Base64Encoder; -import com.github.scribejava.core.utils.MapUtils; import java.util.concurrent.ExecutionException; /** @@ -58,12 +56,7 @@ public final Future getRequestTokenAsync( final OAuthConfig config = getConfig(); config.log("async obtaining request token from " + api.getRequestTokenEndpoint()); final OAuthRequest request = prepareRequestTokenRequest(); - return execute(request, callback, new OAuthRequest.ResponseConverter() { - @Override - public OAuth1RequestToken convert(Response response) throws IOException { - return getApi().getRequestTokenExtractor().extract(response); - } - }); + return execute(request, callback, response -> getApi().getRequestTokenExtractor().extract(response)); } protected OAuthRequest prepareRequestTokenRequest() { @@ -89,7 +82,7 @@ protected void addOAuthParams(OAuthRequest request, String tokenSecret) { } request.addOAuthParameter(OAuthConstants.SIGNATURE, getSignature(request, tokenSecret)); - config.log("appended additional OAuth parameters: " + MapUtils.toString(request.getOauthParameters())); + config.log("appended additional OAuth parameters: " + request.getOauthParameters()); } public final OAuth1AccessToken getAccessToken(OAuth1RequestToken requestToken, String oauthVerifier) @@ -118,12 +111,7 @@ public final Future getAccessTokenAsync(OAuth1RequestToken re final OAuthConfig config = getConfig(); config.log("async obtaining access token from " + api.getAccessTokenEndpoint()); final OAuthRequest request = prepareAccessTokenRequest(requestToken, oauthVerifier); - return execute(request, callback, new OAuthRequest.ResponseConverter() { - @Override - public OAuth1AccessToken convert(Response response) throws IOException { - return getApi().getAccessTokenExtractor().extract(response); - } - }); + return execute(request, callback, response -> getApi().getAccessTokenExtractor().extract(response)); } protected OAuthRequest prepareAccessTokenRequest(OAuth1RequestToken requestToken, String oauthVerifier) { @@ -191,9 +179,7 @@ protected void appendSignature(OAuthRequest request) { case QueryString: config.log("using Querystring signature"); - for (Map.Entry entry : request.getOauthParameters().entrySet()) { - request.addQuerystringParameter(entry.getKey(), entry.getValue()); - } + request.getOauthParameters().forEach((key, value) -> request.addQuerystringParameter(key, value)); break; default: throw new IllegalStateException("Unknown new Signature Type '" + signatureType + "'."); diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java index 4565a4165..803e6fa80 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java @@ -11,7 +11,6 @@ import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.OAuthRequest; -import com.github.scribejava.core.model.Response; import java.util.Map; import java.util.concurrent.ExecutionException; @@ -46,12 +45,7 @@ protected Future sendAccessTokenRequestAsync(OAuthRequest req protected Future sendAccessTokenRequestAsync(OAuthRequest request, OAuthAsyncRequestCallback callback) { - return execute(request, callback, new OAuthRequest.ResponseConverter() { - @Override - public OAuth2AccessToken convert(Response response) throws IOException { - return getApi().getAccessTokenExtractor().extract(response); - } - }); + return execute(request, callback, response -> getApi().getAccessTokenExtractor().extract(response)); } public final Future getAccessTokenAsync(String code) { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/utils/MapUtils.java b/scribejava-core/src/main/java/com/github/scribejava/core/utils/MapUtils.java deleted file mode 100644 index 9cb217cb9..000000000 --- a/scribejava-core/src/main/java/com/github/scribejava/core/utils/MapUtils.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.github.scribejava.core.utils; - -import java.util.Map; - -public abstract class MapUtils { - - public static String toString(Map map) { - if (map == null) { - return ""; - } - if (map.isEmpty()) { - return "{}"; - } - - final StringBuilder result = new StringBuilder(); - for (Map.Entry entry : map.entrySet()) { - result.append(", ") - .append(entry.getKey().toString()) - .append(" -> ") - .append(entry.getValue().toString()) - .append(' '); - } - return "{" + result.append('}').substring(1); - } -} diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceUnit.java b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceUnit.java index 8a49c0ee1..76bd0e8c6 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceUnit.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceUnit.java @@ -6,7 +6,6 @@ import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.OAuthRequest; -import com.github.scribejava.core.model.Parameter; import com.google.gson.Gson; import java.util.HashMap; @@ -38,9 +37,7 @@ private String prepareRawResponse(OAuthRequest request) { response.putAll(request.getHeaders()); response.putAll(request.getOauthParameters()); - for (Parameter p : request.getBodyParams().getParams()) { - response.put("query-" + p.getKey(), p.getValue()); - } + request.getBodyParams().getParams().forEach(p -> response.put("query-" + p.getKey(), p.getValue())); return json.toJson(response); } diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/utils/MapUtilsTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/utils/MapUtilsTest.java deleted file mode 100644 index 9ce36c76f..000000000 --- a/scribejava-core/src/test/java/com/github/scribejava/core/utils/MapUtilsTest.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.github.scribejava.core.utils; - -import java.util.LinkedHashMap; -import java.util.HashMap; -import java.util.Map; -import org.junit.Assert; -import org.junit.Test; - -public class MapUtilsTest { - - @Test - public void shouldPrettyPrintMap() { - final Map map = new LinkedHashMap<>(); - map.put(1, "one"); - map.put(2, "two"); - map.put(3, "three"); - map.put(4, "four"); - Assert.assertEquals("{ 1 -> one , 2 -> two , 3 -> three , 4 -> four }", MapUtils.toString(map)); - } - - @Test - public void shouldHandleEmptyMap() { - final Map map = new HashMap<>(); - Assert.assertEquals("{}", MapUtils.toString(map)); - } - - @Test - public void shouldHandleNullInputs() { - Assert.assertEquals("", MapUtils.toString(null)); - } -} diff --git a/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/OAuthAsyncCompletionHandler.java b/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/OAuthAsyncCompletionHandler.java index 5ce461b1b..c60388ac0 100644 --- a/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/OAuthAsyncCompletionHandler.java +++ b/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/OAuthAsyncCompletionHandler.java @@ -4,11 +4,9 @@ import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; import com.ning.http.client.AsyncCompletionHandler; -import com.ning.http.client.FluentCaseInsensitiveStringsMap; import java.io.IOException; -import java.util.HashMap; -import java.util.List; import java.util.Map; +import java.util.stream.Collectors; public class OAuthAsyncCompletionHandler extends AsyncCompletionHandler { @@ -23,15 +21,10 @@ public OAuthAsyncCompletionHandler(OAuthAsyncRequestCallback callback, @Override public T onCompleted(com.ning.http.client.Response ningResponse) throws IOException { - final FluentCaseInsensitiveStringsMap map = ningResponse.getHeaders(); - final Map headersMap = new HashMap<>(); - for (FluentCaseInsensitiveStringsMap.Entry> header : map) { - final StringBuilder value = new StringBuilder(); - for (String str : header.getValue()) { - value.append(str); - } - headersMap.put(header.getKey(), value.toString()); - } + final Map headersMap = ningResponse.getHeaders().entrySet().stream() + .collect(Collectors.toMap(header -> header.getKey(), + header -> header.getValue().stream().collect(Collectors.joining()))); + final Response response = new Response(ningResponse.getStatusCode(), ningResponse.getStatusText(), headersMap, ningResponse.getResponseBodyAsStream()); diff --git a/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java b/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java index 66d2daee0..8090ef845 100644 --- a/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java +++ b/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java @@ -18,8 +18,9 @@ import com.github.scribejava.core.model.Response; import java.io.File; -import java.util.HashMap; import java.util.concurrent.ExecutionException; +import java.util.function.Function; +import java.util.stream.Collectors; import okhttp3.Cache; import okhttp3.Headers; import okhttp3.ResponseBody; @@ -125,9 +126,8 @@ private Call createCall(String userAgent, Map headers, Verb http requestBuilder.method(method, body); // fill headers - for (Map.Entry header : headers.entrySet()) { - requestBuilder.addHeader(header.getKey(), header.getValue()); - } + headers.forEach((key, value) -> requestBuilder.addHeader(key, value)); + if (userAgent != null) { requestBuilder.header(OAuthConstants.USER_AGENT_HEADER_NAME, userAgent); } @@ -161,11 +161,8 @@ RequestBody createBody(MediaType mediaType, Object bodyContents) { static Response convertResponse(okhttp3.Response okHttpResponse) { final Headers headers = okHttpResponse.headers(); - final Map headersMap = new HashMap<>(); - - for (String name : headers.names()) { - headersMap.put(name, headers.get(name)); - } + final Map headersMap = headers.names().stream() + .collect(Collectors.toMap(Function.identity(), headers::get)); final ResponseBody body = okHttpResponse.body(); return new Response(okHttpResponse.code(), okHttpResponse.message(), headersMap, From bb23fed9e6b33a0c83905e0ca8a68ae4c1386b3e Mon Sep 17 00:00:00 2001 From: evstropovv Date: Sat, 26 Aug 2017 12:31:40 +0300 Subject: [PATCH 409/882] add ucoz api --- .../com/github/scribejava/apis/UcozApi.java | 40 +++++++++ .../AbstractOauth1UcozTokenExtractor.java | 41 ++++++++++ .../ucoz/OAuth1AccessUcozTokenExtractor.java | 23 ++++++ .../ucoz/OAuth1RequestUcozTokenExtractor.java | 23 ++++++ .../scribejava/apis/examples/UcozExample.java | 81 +++++++++++++++++++ 5 files changed, 208 insertions(+) create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/UcozApi.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/ucoz/AbstractOauth1UcozTokenExtractor.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/ucoz/OAuth1AccessUcozTokenExtractor.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/ucoz/OAuth1RequestUcozTokenExtractor.java create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/UcozExample.java diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/UcozApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/UcozApi.java new file mode 100644 index 000000000..d591149e5 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/UcozApi.java @@ -0,0 +1,40 @@ +package com.github.scribejava.apis; + +import com.github.scribejava.apis.ucoz.OAuth1AccessUcozTokenExtractor; +import com.github.scribejava.apis.ucoz.OAuth1RequestUcozTokenExtractor; +import com.github.scribejava.core.builder.api.DefaultApi10a; +import com.github.scribejava.core.extractors.TokenExtractor; +import com.github.scribejava.core.model.OAuth1AccessToken; +import com.github.scribejava.core.model.OAuth1RequestToken; + +public class UcozApi extends DefaultApi10a { + private static final String AUTHORIZE_URL = "http://uapi.ucoz.com/accounts/oauthauthorizetoken?oauth_token=%s"; + protected UcozApi() { + } + private static class InstanceHolder { + private static final UcozApi INSTANCE = new UcozApi(); + } + public static UcozApi instance() { + return InstanceHolder.INSTANCE; } + @Override + public String getAccessTokenEndpoint(){ + return "http://uapi.ucoz.com/accounts/oauthgetaccesstoken"; } + + @Override + public String getRequestTokenEndpoint() { + return "http://uapi.ucoz.com/accounts/oauthgetrequesttoken"; } + + @Override + public String getAuthorizationUrl(OAuth1RequestToken requestToken) { + return String.format(AUTHORIZE_URL, requestToken.getToken()); } + + @Override + public TokenExtractor getAccessTokenExtractor() { + return OAuth1AccessUcozTokenExtractor.instance(); + } + + @Override + public TokenExtractor getRequestTokenExtractor() { + return OAuth1RequestUcozTokenExtractor.instance(); + } +} \ No newline at end of file diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/ucoz/AbstractOauth1UcozTokenExtractor.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/ucoz/AbstractOauth1UcozTokenExtractor.java new file mode 100644 index 000000000..14a76dd75 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/ucoz/AbstractOauth1UcozTokenExtractor.java @@ -0,0 +1,41 @@ +package com.github.scribejava.apis.ucoz; + +import com.github.scribejava.core.exceptions.OAuthException; +import com.github.scribejava.core.extractors.TokenExtractor; +import com.github.scribejava.core.model.OAuth1Token; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.utils.OAuthEncoder; +import com.github.scribejava.core.utils.Preconditions; + +import java.io.IOException; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + + +public abstract class AbstractOauth1UcozTokenExtractor implements TokenExtractor { + + private Pattern OAUTH_TOKEN_PATTERN = Pattern.compile("\"oauth_token\"\\s*:\\s*\"(\\S*?)\""); + private Pattern OAUTH_TOKEN_SECRET_PATTERN = Pattern.compile("\"oauth_token_secret\"\\s*:\\s*\"(\\S*?)\""); + + @Override + public T extract(Response response) throws IOException { + final String body = response.getBody(); + Preconditions.checkEmptyString(body, + "Response body is incorrect. " + "Can't extract a token from an empty string"); + final String token = extract(body, OAUTH_TOKEN_PATTERN); + final String secret = extract(body, OAUTH_TOKEN_SECRET_PATTERN); + return createToken(token, secret, body); + } + + private String extract(String response, Pattern p) { + final Matcher matcher = p.matcher(response); + if (matcher.find() && matcher.groupCount() >= 1) { + return OAuthEncoder.decode(matcher.group(1)); + } else { + throw new OAuthException("Response body is incorrect. Can't extract token and secret from this: '" + + response + "'", null); + } + } + + protected abstract T createToken(String token, String secret, String response); +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/ucoz/OAuth1AccessUcozTokenExtractor.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/ucoz/OAuth1AccessUcozTokenExtractor.java new file mode 100644 index 000000000..bc155710e --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/ucoz/OAuth1AccessUcozTokenExtractor.java @@ -0,0 +1,23 @@ +package com.github.scribejava.apis.ucoz; + +import com.github.scribejava.core.model.OAuth1AccessToken; + +public class OAuth1AccessUcozTokenExtractor extends AbstractOauth1UcozTokenExtractor { + + protected OAuth1AccessUcozTokenExtractor() { + } + + @Override + protected OAuth1AccessToken createToken(String token, String secret, String response) { + return new OAuth1AccessToken(token, secret, response); + } + + private static class InstanceHolder { + + private static final OAuth1AccessUcozTokenExtractor INSTANCE = new OAuth1AccessUcozTokenExtractor(); + } + + public static OAuth1AccessUcozTokenExtractor instance() { + return OAuth1AccessUcozTokenExtractor.InstanceHolder.INSTANCE; + } +} \ No newline at end of file diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/ucoz/OAuth1RequestUcozTokenExtractor.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/ucoz/OAuth1RequestUcozTokenExtractor.java new file mode 100644 index 000000000..c615fb840 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/ucoz/OAuth1RequestUcozTokenExtractor.java @@ -0,0 +1,23 @@ +package com.github.scribejava.apis.ucoz; + +import com.github.scribejava.core.model.OAuth1RequestToken; + +public class OAuth1RequestUcozTokenExtractor extends AbstractOauth1UcozTokenExtractor { + + protected OAuth1RequestUcozTokenExtractor() { + } + + @Override + protected OAuth1RequestToken createToken(String token, String secret, String response) { + return new OAuth1RequestToken(token, secret, response); + } + + private static class InstanceHolder { + + private static final OAuth1RequestUcozTokenExtractor INSTANCE = new OAuth1RequestUcozTokenExtractor(); + } + + public static OAuth1RequestUcozTokenExtractor instance() { + return InstanceHolder.INSTANCE; + } +} \ No newline at end of file diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/UcozExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/UcozExample.java new file mode 100644 index 000000000..f2156dfc9 --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/UcozExample.java @@ -0,0 +1,81 @@ +package com.github.scribejava.apis.examples; + +import com.github.scribejava.apis.UcozApi; +import com.github.scribejava.core.builder.ServiceBuilder; +import com.github.scribejava.core.model.*; +import com.github.scribejava.core.oauth.OAuth10aService; + +import java.io.IOException; +import java.util.Scanner; +import java.util.concurrent.ExecutionException; + +public class UcozExample { + public static void main(String ...args){ + String PROTECTED_RESOURCE_URL ="http://artmurka.com/uapi/shop/request?page=categories"; + OAuth10aService service = new ServiceBuilder( "your_api_key") + .apiSecret("your_api_secret") + .debug() + .build(UcozApi.instance()); + Scanner in = new Scanner(System.in); + OAuth1RequestToken requestToken = null; + try { + requestToken = service.getRequestToken(); + } catch (IOException e) { + e.printStackTrace(); + } catch (InterruptedException e) { + e.printStackTrace(); + } catch (ExecutionException e) { + e.printStackTrace(); + } + System.out.println("Got the Request Token!"); + System.out.println(); + + System.out.println("Now go and authorize ScribeJava here:"); + System.out.println(service.getAuthorizationUrl(requestToken)); + System.out.println("And paste the verifier here"); + System.out.print(">>"); + final String oauthVerifier = in.nextLine(); + System.out.println(); + // Trade the Request Token and Verfier for the Access Token + System.out.println("Trading the Request Token for an Access Token..."); + OAuth1AccessToken accessToken = null; + try { + accessToken = service.getAccessToken(requestToken, oauthVerifier); + } catch (IOException e) { + e.printStackTrace(); + } catch (InterruptedException e) { + e.printStackTrace(); + } catch (ExecutionException e) { + e.printStackTrace(); + } + System.out.println("Got the Access Token!"); + System.out.println("(if your curious it looks like this: " + accessToken + + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println(); + + // Now let's go and ask for a protected resource! + System.out.println("Now we're going to access a protected resource..."); + OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); + service.signRequest(accessToken, request); + Response response = null; + try { + response = service.execute(request); + } catch (InterruptedException e) { + e.printStackTrace(); + } catch (ExecutionException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getCode()); + try { + System.out.println(response.getBody()); + } catch (IOException e) { + e.printStackTrace(); + } + System.out.println(); + System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); + } +} From 9ae56fd62d3230ea26d62615eb8bc85b6f498523 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 28 Aug 2017 12:52:18 +0300 Subject: [PATCH 410/882] format, rename, fix a bit --- README.md | 1 + changelog | 2 + .../com/github/scribejava/apis/UcozApi.java | 88 ++++++----- .../ucoz/OAuth1AccessUcozTokenExtractor.java | 23 --- .../ucoz/OAuth1RequestUcozTokenExtractor.java | 23 --- .../scribejava/apis/examples/UcozExample.java | 141 ++++++++---------- .../VkontakteExternalHttpExample.java | 2 +- .../apis/examples/YahooExample.java | 2 +- .../AbstractOAuth1JSONTokenExtractor.java | 81 +++++----- .../OAuth1AccessTokenJSONExtractor.java | 23 +++ .../OAuth1RequestTokenJSONExtractor.java | 23 +++ 11 files changed, 199 insertions(+), 210 deletions(-) delete mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/ucoz/OAuth1AccessUcozTokenExtractor.java delete mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/ucoz/OAuth1RequestUcozTokenExtractor.java rename scribejava-apis/src/main/java/com/github/scribejava/apis/ucoz/AbstractOauth1UcozTokenExtractor.java => scribejava-core/src/main/java/com/github/scribejava/core/extractors/AbstractOAuth1JSONTokenExtractor.java (66%) create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth1AccessTokenJSONExtractor.java create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth1RequestTokenJSONExtractor.java diff --git a/README.md b/README.md index 439c26ae3..567d5075b 100644 --- a/README.md +++ b/README.md @@ -71,6 +71,7 @@ ScribeJava support out-of-box several HTTP clients: * Tumblr (https://www.tumblr.com/) * TUT.BY (http://www.tut.by/) * Twitter (https://twitter.com/) +* uCoz (https://www.ucoz.com/) * Viadeo (http://viadeo.com/) * VK ВКонтакте (http://vk.com/) * XING (https://www.xing.com/) diff --git a/changelog b/changelog index 84e7a582d..4ef2ad99c 100644 --- a/changelog +++ b/changelog @@ -1,5 +1,7 @@ [SNAPSHOT] * drop Java 7 backward compatibility support, become Java 8 only + * add JSON token extractor for OAuth 1.0a (thanks to https://github.com/evstropovv) + * add new API - uCoz (https://www.ucoz.com/) (thanks to https://github.com/evstropovv) [4.2.0] * DELETE in JdkClient permits, but not requires payload (thanks to https://github.com/miguelD73) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/UcozApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/UcozApi.java index d591149e5..208eddc38 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/UcozApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/UcozApi.java @@ -1,40 +1,48 @@ -package com.github.scribejava.apis; - -import com.github.scribejava.apis.ucoz.OAuth1AccessUcozTokenExtractor; -import com.github.scribejava.apis.ucoz.OAuth1RequestUcozTokenExtractor; -import com.github.scribejava.core.builder.api.DefaultApi10a; -import com.github.scribejava.core.extractors.TokenExtractor; -import com.github.scribejava.core.model.OAuth1AccessToken; -import com.github.scribejava.core.model.OAuth1RequestToken; - -public class UcozApi extends DefaultApi10a { - private static final String AUTHORIZE_URL = "http://uapi.ucoz.com/accounts/oauthauthorizetoken?oauth_token=%s"; - protected UcozApi() { - } - private static class InstanceHolder { - private static final UcozApi INSTANCE = new UcozApi(); - } - public static UcozApi instance() { - return InstanceHolder.INSTANCE; } - @Override - public String getAccessTokenEndpoint(){ - return "http://uapi.ucoz.com/accounts/oauthgetaccesstoken"; } - - @Override - public String getRequestTokenEndpoint() { - return "http://uapi.ucoz.com/accounts/oauthgetrequesttoken"; } - - @Override - public String getAuthorizationUrl(OAuth1RequestToken requestToken) { - return String.format(AUTHORIZE_URL, requestToken.getToken()); } - - @Override - public TokenExtractor getAccessTokenExtractor() { - return OAuth1AccessUcozTokenExtractor.instance(); - } - - @Override - public TokenExtractor getRequestTokenExtractor() { - return OAuth1RequestUcozTokenExtractor.instance(); - } -} \ No newline at end of file +package com.github.scribejava.apis; + +import com.github.scribejava.core.extractors.OAuth1AccessTokenJSONExtractor; +import com.github.scribejava.core.extractors.OAuth1RequestTokenJSONExtractor; +import com.github.scribejava.core.builder.api.DefaultApi10a; +import com.github.scribejava.core.extractors.TokenExtractor; +import com.github.scribejava.core.model.OAuth1AccessToken; +import com.github.scribejava.core.model.OAuth1RequestToken; + +public class UcozApi extends DefaultApi10a { + private static final String AUTHORIZE_URL = "http://uapi.ucoz.com/accounts/oauthauthorizetoken?oauth_token=%s"; + + protected UcozApi() { + } + + private static class InstanceHolder { + private static final UcozApi INSTANCE = new UcozApi(); + } + + public static UcozApi instance() { + return InstanceHolder.INSTANCE; + } + + @Override + public String getAccessTokenEndpoint(){ + return "http://uapi.ucoz.com/accounts/oauthgetaccesstoken"; + } + + @Override + public String getRequestTokenEndpoint() { + return "http://uapi.ucoz.com/accounts/oauthgetrequesttoken"; + } + + @Override + public String getAuthorizationUrl(OAuth1RequestToken requestToken) { + return String.format(AUTHORIZE_URL, requestToken.getToken()); + } + + @Override + public TokenExtractor getAccessTokenExtractor() { + return OAuth1AccessTokenJSONExtractor.instance(); + } + + @Override + public TokenExtractor getRequestTokenExtractor() { + return OAuth1RequestTokenJSONExtractor.instance(); + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/ucoz/OAuth1AccessUcozTokenExtractor.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/ucoz/OAuth1AccessUcozTokenExtractor.java deleted file mode 100644 index bc155710e..000000000 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/ucoz/OAuth1AccessUcozTokenExtractor.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.github.scribejava.apis.ucoz; - -import com.github.scribejava.core.model.OAuth1AccessToken; - -public class OAuth1AccessUcozTokenExtractor extends AbstractOauth1UcozTokenExtractor { - - protected OAuth1AccessUcozTokenExtractor() { - } - - @Override - protected OAuth1AccessToken createToken(String token, String secret, String response) { - return new OAuth1AccessToken(token, secret, response); - } - - private static class InstanceHolder { - - private static final OAuth1AccessUcozTokenExtractor INSTANCE = new OAuth1AccessUcozTokenExtractor(); - } - - public static OAuth1AccessUcozTokenExtractor instance() { - return OAuth1AccessUcozTokenExtractor.InstanceHolder.INSTANCE; - } -} \ No newline at end of file diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/ucoz/OAuth1RequestUcozTokenExtractor.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/ucoz/OAuth1RequestUcozTokenExtractor.java deleted file mode 100644 index c615fb840..000000000 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/ucoz/OAuth1RequestUcozTokenExtractor.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.github.scribejava.apis.ucoz; - -import com.github.scribejava.core.model.OAuth1RequestToken; - -public class OAuth1RequestUcozTokenExtractor extends AbstractOauth1UcozTokenExtractor { - - protected OAuth1RequestUcozTokenExtractor() { - } - - @Override - protected OAuth1RequestToken createToken(String token, String secret, String response) { - return new OAuth1RequestToken(token, secret, response); - } - - private static class InstanceHolder { - - private static final OAuth1RequestUcozTokenExtractor INSTANCE = new OAuth1RequestUcozTokenExtractor(); - } - - public static OAuth1RequestUcozTokenExtractor instance() { - return InstanceHolder.INSTANCE; - } -} \ No newline at end of file diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/UcozExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/UcozExample.java index f2156dfc9..04dfaacf4 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/UcozExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/UcozExample.java @@ -1,81 +1,60 @@ -package com.github.scribejava.apis.examples; - -import com.github.scribejava.apis.UcozApi; -import com.github.scribejava.core.builder.ServiceBuilder; -import com.github.scribejava.core.model.*; -import com.github.scribejava.core.oauth.OAuth10aService; - -import java.io.IOException; -import java.util.Scanner; -import java.util.concurrent.ExecutionException; - -public class UcozExample { - public static void main(String ...args){ - String PROTECTED_RESOURCE_URL ="http://artmurka.com/uapi/shop/request?page=categories"; - OAuth10aService service = new ServiceBuilder( "your_api_key") - .apiSecret("your_api_secret") - .debug() - .build(UcozApi.instance()); - Scanner in = new Scanner(System.in); - OAuth1RequestToken requestToken = null; - try { - requestToken = service.getRequestToken(); - } catch (IOException e) { - e.printStackTrace(); - } catch (InterruptedException e) { - e.printStackTrace(); - } catch (ExecutionException e) { - e.printStackTrace(); - } - System.out.println("Got the Request Token!"); - System.out.println(); - - System.out.println("Now go and authorize ScribeJava here:"); - System.out.println(service.getAuthorizationUrl(requestToken)); - System.out.println("And paste the verifier here"); - System.out.print(">>"); - final String oauthVerifier = in.nextLine(); - System.out.println(); - // Trade the Request Token and Verfier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); - OAuth1AccessToken accessToken = null; - try { - accessToken = service.getAccessToken(requestToken, oauthVerifier); - } catch (IOException e) { - e.printStackTrace(); - } catch (InterruptedException e) { - e.printStackTrace(); - } catch (ExecutionException e) { - e.printStackTrace(); - } - System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); - System.out.println(); - - // Now let's go and ask for a protected resource! - System.out.println("Now we're going to access a protected resource..."); - OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); - service.signRequest(accessToken, request); - Response response = null; - try { - response = service.execute(request); - } catch (InterruptedException e) { - e.printStackTrace(); - } catch (ExecutionException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } - System.out.println("Got it! Lets see what we found..."); - System.out.println(); - System.out.println(response.getCode()); - try { - System.out.println(response.getBody()); - } catch (IOException e) { - e.printStackTrace(); - } - System.out.println(); - System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); - } -} +package com.github.scribejava.apis.examples; + +import com.github.scribejava.apis.UcozApi; +import com.github.scribejava.core.builder.ServiceBuilder; +import com.github.scribejava.core.model.OAuth1AccessToken; +import com.github.scribejava.core.model.OAuth1RequestToken; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.oauth.OAuth10aService; + +import java.io.IOException; +import java.util.Scanner; +import java.util.concurrent.ExecutionException; + +public class UcozExample { + + private static final String PROTECTED_RESOURCE_URL = "http://artmurka.com/uapi/shop/request?page=categories"; + + private UcozExample() { + } + + public static void main(String... args) throws IOException, InterruptedException, ExecutionException { + final OAuth10aService service = new ServiceBuilder("your_api_key") + .apiSecret("your_api_secret") + .debug() + .build(UcozApi.instance()); + final Scanner in = new Scanner(System.in); + final OAuth1RequestToken requestToken = service.getRequestToken(); + System.out.println("Got the Request Token!"); + System.out.println(); + + System.out.println("Now go and authorize ScribeJava here:"); + System.out.println(service.getAuthorizationUrl(requestToken)); + System.out.println("And paste the verifier here"); + System.out.print(">>"); + final String oauthVerifier = in.nextLine(); + System.out.println(); + // Trade the Request Token and Verfier for the Access Token + System.out.println("Trading the Request Token for an Access Token..."); + final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); + System.out.println("Got the Access Token!"); + System.out.println("(if your curious it looks like this: " + accessToken + + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println(); + + // Now let's go and ask for a protected resource! + System.out.println("Now we're going to access a protected resource..."); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); + service.signRequest(accessToken, request); + final Response response = service.execute(request); + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + + System.out.println(); + System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); + } +} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExternalHttpExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExternalHttpExample.java index d16b714d8..598d25c64 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExternalHttpExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExternalHttpExample.java @@ -14,7 +14,7 @@ import org.asynchttpclient.DefaultAsyncHttpClient; import org.asynchttpclient.DefaultAsyncHttpClientConfig; -public final class VkontakteExternalHttpExample { +public class VkontakteExternalHttpExample { private static final String NETWORK_NAME = "Vkontakte.ru"; private static final String PROTECTED_RESOURCE_URL = "https://api.vk.com/method/users.get"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/YahooExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/YahooExample.java index 581600a3b..3e8802fa8 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/YahooExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/YahooExample.java @@ -12,7 +12,7 @@ import java.io.IOException; import java.util.concurrent.ExecutionException; -public final class YahooExample { +public class YahooExample { private static final String PROTECTED_RESOURCE_URL = "http://social.yahooapis.com/v1/user/A6ROU63MXWDCW3Y5MGCYWVHDJI/profile/status?format=json"; diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/ucoz/AbstractOauth1UcozTokenExtractor.java b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/AbstractOAuth1JSONTokenExtractor.java similarity index 66% rename from scribejava-apis/src/main/java/com/github/scribejava/apis/ucoz/AbstractOauth1UcozTokenExtractor.java rename to scribejava-core/src/main/java/com/github/scribejava/core/extractors/AbstractOAuth1JSONTokenExtractor.java index 14a76dd75..16f684855 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/ucoz/AbstractOauth1UcozTokenExtractor.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/AbstractOAuth1JSONTokenExtractor.java @@ -1,41 +1,40 @@ -package com.github.scribejava.apis.ucoz; - -import com.github.scribejava.core.exceptions.OAuthException; -import com.github.scribejava.core.extractors.TokenExtractor; -import com.github.scribejava.core.model.OAuth1Token; -import com.github.scribejava.core.model.Response; -import com.github.scribejava.core.utils.OAuthEncoder; -import com.github.scribejava.core.utils.Preconditions; - -import java.io.IOException; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - - -public abstract class AbstractOauth1UcozTokenExtractor implements TokenExtractor { - - private Pattern OAUTH_TOKEN_PATTERN = Pattern.compile("\"oauth_token\"\\s*:\\s*\"(\\S*?)\""); - private Pattern OAUTH_TOKEN_SECRET_PATTERN = Pattern.compile("\"oauth_token_secret\"\\s*:\\s*\"(\\S*?)\""); - - @Override - public T extract(Response response) throws IOException { - final String body = response.getBody(); - Preconditions.checkEmptyString(body, - "Response body is incorrect. " + "Can't extract a token from an empty string"); - final String token = extract(body, OAUTH_TOKEN_PATTERN); - final String secret = extract(body, OAUTH_TOKEN_SECRET_PATTERN); - return createToken(token, secret, body); - } - - private String extract(String response, Pattern p) { - final Matcher matcher = p.matcher(response); - if (matcher.find() && matcher.groupCount() >= 1) { - return OAuthEncoder.decode(matcher.group(1)); - } else { - throw new OAuthException("Response body is incorrect. Can't extract token and secret from this: '" - + response + "'", null); - } - } - - protected abstract T createToken(String token, String secret, String response); -} +package com.github.scribejava.core.extractors; + +import com.github.scribejava.core.exceptions.OAuthException; +import com.github.scribejava.core.model.OAuth1Token; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.utils.OAuthEncoder; +import com.github.scribejava.core.utils.Preconditions; + +import java.io.IOException; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + + +public abstract class AbstractOAuth1JSONTokenExtractor implements TokenExtractor { + + private static final Pattern OAUTH_TOKEN_PATTERN = Pattern.compile("\"oauth_token\"\\s*:\\s*\"(\\S*?)\""); + private static final Pattern OAUTH_TOKEN_SECRET_PATTERN + = Pattern.compile("\"oauth_token_secret\"\\s*:\\s*\"(\\S*?)\""); + + @Override + public T extract(Response response) throws IOException { + final String body = response.getBody(); + Preconditions.checkEmptyString(body, "Response body is incorrect. Can't extract a token from an empty string"); + final String token = extract(body, OAUTH_TOKEN_PATTERN); + final String secret = extract(body, OAUTH_TOKEN_SECRET_PATTERN); + return createToken(token, secret, body); + } + + private String extract(String response, Pattern p) { + final Matcher matcher = p.matcher(response); + if (matcher.find() && matcher.groupCount() >= 1) { + return OAuthEncoder.decode(matcher.group(1)); + } else { + throw new OAuthException("Response body is incorrect. Can't extract token and secret from this: '" + + response + '\'', null); + } + } + + protected abstract T createToken(String token, String secret, String response); +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth1AccessTokenJSONExtractor.java b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth1AccessTokenJSONExtractor.java new file mode 100644 index 000000000..9267f80b4 --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth1AccessTokenJSONExtractor.java @@ -0,0 +1,23 @@ +package com.github.scribejava.core.extractors; + +import com.github.scribejava.core.model.OAuth1AccessToken; + +public class OAuth1AccessTokenJSONExtractor extends AbstractOAuth1JSONTokenExtractor { + + protected OAuth1AccessTokenJSONExtractor() { + } + + @Override + protected OAuth1AccessToken createToken(String token, String secret, String response) { + return new OAuth1AccessToken(token, secret, response); + } + + private static class InstanceHolder { + + private static final OAuth1AccessTokenJSONExtractor INSTANCE = new OAuth1AccessTokenJSONExtractor(); + } + + public static OAuth1AccessTokenJSONExtractor instance() { + return InstanceHolder.INSTANCE; + } +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth1RequestTokenJSONExtractor.java b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth1RequestTokenJSONExtractor.java new file mode 100644 index 000000000..875337a82 --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth1RequestTokenJSONExtractor.java @@ -0,0 +1,23 @@ +package com.github.scribejava.core.extractors; + +import com.github.scribejava.core.model.OAuth1RequestToken; + +public class OAuth1RequestTokenJSONExtractor extends AbstractOAuth1JSONTokenExtractor { + + protected OAuth1RequestTokenJSONExtractor() { + } + + @Override + protected OAuth1RequestToken createToken(String token, String secret, String response) { + return new OAuth1RequestToken(token, secret, response); + } + + private static class InstanceHolder { + + private static final OAuth1RequestTokenJSONExtractor INSTANCE = new OAuth1RequestTokenJSONExtractor(); + } + + public static OAuth1RequestTokenJSONExtractor instance() { + return InstanceHolder.INSTANCE; + } +} From 523769736fb350efd9c3db9a3a48cfe1785dd5ce Mon Sep 17 00:00:00 2001 From: Vivin Paliath Date: Thu, 31 Aug 2017 15:44:04 -0700 Subject: [PATCH 411/882] issue #793 Adds support for retrieving an access token using client-credentials grant. --- .../scribejava/core/model/OAuthConstants.java | 1 + .../scribejava/core/oauth/OAuth20Service.java | 67 +++++++++++++++---- 2 files changed, 55 insertions(+), 13 deletions(-) diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConstants.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConstants.java index 2cf8d236a..4f79cd355 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConstants.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConstants.java @@ -32,6 +32,7 @@ public interface OAuthConstants { String REFRESH_TOKEN = "refresh_token"; String GRANT_TYPE = "grant_type"; String AUTHORIZATION_CODE = "authorization_code"; + String CLIENT_CREDENTIALS = "client_credentials"; String STATE = "state"; String USERNAME = "username"; String PASSWORD = "password"; diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java index 803e6fa80..b6fd25882 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java @@ -92,37 +92,44 @@ protected OAuthRequest createAccessTokenRequest(String code) { return request; } - public final Future refreshAccessTokenAsync(String refreshToken) { - return refreshAccessToken(refreshToken, null); + public final Future getAccessTokenClientCredentialsGrantAsync() { + return getAccessTokenClientCredentialsGrant(null); } - public final OAuth2AccessToken refreshAccessToken(String refreshToken) + public final OAuth2AccessToken getAccessTokenClientCredentialsGrant() throws IOException, InterruptedException, ExecutionException { - final OAuthRequest request = createRefreshTokenRequest(refreshToken); + final OAuthRequest request = createAccessTokenClientCredentialsGrantRequest(); return sendAccessTokenRequestSync(request); } - public final Future refreshAccessToken(String refreshToken, + /** + * Start the request to retrieve the access token using client-credentials grant. The optionally provided callback + * will be called with the Token when it is available. + * + * @param callback optional callback + * @return Future + */ + public final Future getAccessTokenClientCredentialsGrant( OAuthAsyncRequestCallback callback) { - final OAuthRequest request = createRefreshTokenRequest(refreshToken); + final OAuthRequest request = createAccessTokenClientCredentialsGrantRequest(); return sendAccessTokenRequestAsync(request, callback); } - protected OAuthRequest createRefreshTokenRequest(String refreshToken) { - if (refreshToken == null || refreshToken.isEmpty()) { - throw new IllegalArgumentException("The refreshToken cannot be null or empty"); - } - final OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getRefreshTokenEndpoint()); + protected OAuthRequest createAccessTokenClientCredentialsGrantRequest() { + final OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint()); final OAuthConfig config = getConfig(); request.addParameter(OAuthConstants.CLIENT_ID, config.getApiKey()); final String apiSecret = config.getApiSecret(); if (apiSecret != null) { request.addParameter(OAuthConstants.CLIENT_SECRET, apiSecret); } - request.addParameter(OAuthConstants.REFRESH_TOKEN, refreshToken); - request.addParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.REFRESH_TOKEN); + final String scope = config.getScope(); + if (scope != null) { + request.addParameter(OAuthConstants.SCOPE, scope); + } + request.addParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.CLIENT_CREDENTIALS); return request; } @@ -177,6 +184,40 @@ protected OAuthRequest createAccessTokenPasswordGrantRequest(String username, St return request; } + public final Future refreshAccessTokenAsync(String refreshToken) { + return refreshAccessToken(refreshToken, null); + } + + public final OAuth2AccessToken refreshAccessToken(String refreshToken) + throws IOException, InterruptedException, ExecutionException { + final OAuthRequest request = createRefreshTokenRequest(refreshToken); + + return sendAccessTokenRequestSync(request); + } + + public final Future refreshAccessToken(String refreshToken, + OAuthAsyncRequestCallback callback) { + final OAuthRequest request = createRefreshTokenRequest(refreshToken); + + return sendAccessTokenRequestAsync(request, callback); + } + + protected OAuthRequest createRefreshTokenRequest(String refreshToken) { + if (refreshToken == null || refreshToken.isEmpty()) { + throw new IllegalArgumentException("The refreshToken cannot be null or empty"); + } + final OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getRefreshTokenEndpoint()); + final OAuthConfig config = getConfig(); + request.addParameter(OAuthConstants.CLIENT_ID, config.getApiKey()); + final String apiSecret = config.getApiSecret(); + if (apiSecret != null) { + request.addParameter(OAuthConstants.CLIENT_SECRET, apiSecret); + } + request.addParameter(OAuthConstants.REFRESH_TOKEN, refreshToken); + request.addParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.REFRESH_TOKEN); + return request; + } + /** * {@inheritDoc} */ From f296c750a0f11b4ec9c7dc1d355c5fc025ac325a Mon Sep 17 00:00:00 2001 From: Stephan Date: Sat, 30 Sep 2017 10:15:23 +1000 Subject: [PATCH 412/882] Apache http client integration --- pom.xml | 1 + scribejava-core/pom.xml | 16 ++ .../scribejava/core/AbstractClientTest.java | 178 ++++++++++++++++++ scribejava-httpclient-ahc/pom.xml | 13 ++ .../httpclient/ahc/AhcHttpClientTest.java | 12 ++ scribejava-httpclient-apache/pom.xml | 60 ++++++ .../httpclient/apache/ApacheHttpClient.java | 109 +++++++++++ .../apache/ApacheHttpClientConfig.java | 15 ++ .../httpclient/apache/ApacheHttpFuture.java | 44 +++++ .../httpclient/apache/ApacheProvider.java | 16 ++ .../apache/OAuthAsyncCompletionHandler.java | 95 ++++++++++ .../apache/ApacheHttpClientTest.java | 13 ++ .../OauthAsyncCompletionHandlerTest.java | 128 +++++++++++++ scribejava-httpclient-ning/pom.xml | 13 ++ .../httpclient/ning/NingHttpClientTest.java | 13 ++ scribejava-httpclient-okhttp/pom.xml | 7 + .../okhttp/OkHttpHttpClientTest.java | 109 +---------- 17 files changed, 738 insertions(+), 104 deletions(-) create mode 100644 scribejava-core/src/test/java/com/github/scribejava/core/AbstractClientTest.java create mode 100644 scribejava-httpclient-ahc/src/test/java/com/github/scribejava/httpclient/ahc/AhcHttpClientTest.java create mode 100644 scribejava-httpclient-apache/pom.xml create mode 100644 scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/ApacheHttpClient.java create mode 100644 scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/ApacheHttpClientConfig.java create mode 100644 scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/ApacheHttpFuture.java create mode 100644 scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/ApacheProvider.java create mode 100644 scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/OAuthAsyncCompletionHandler.java create mode 100644 scribejava-httpclient-apache/src/test/java/com/github/scribejava/httpclient/apache/ApacheHttpClientTest.java create mode 100644 scribejava-httpclient-apache/src/test/java/com/github/scribejava/httpclient/apache/OauthAsyncCompletionHandlerTest.java create mode 100644 scribejava-httpclient-ning/src/test/java/com/github/scribejava/httpclient/ning/NingHttpClientTest.java diff --git a/pom.xml b/pom.xml index 7b8520909..eaf094176 100644 --- a/pom.xml +++ b/pom.xml @@ -20,6 +20,7 @@ scribejava-httpclient-ahc scribejava-httpclient-ning scribejava-httpclient-okhttp + scribejava-httpclient-apache diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index e2355021b..460316e5d 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -14,6 +14,15 @@ ScribeJava Core jar + + + com.squareup.okhttp3 + mockwebserver + 3.8.1 + test + + + @@ -23,6 +32,13 @@ org.apache.maven.plugins maven-jar-plugin + + + + test-jar + + + diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/AbstractClientTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/AbstractClientTest.java new file mode 100644 index 000000000..0df7c6ad8 --- /dev/null +++ b/scribejava-core/src/test/java/com/github/scribejava/core/AbstractClientTest.java @@ -0,0 +1,178 @@ +package com.github.scribejava.core; + +import com.github.scribejava.core.httpclient.HttpClient; +import com.github.scribejava.core.model.OAuthAsyncRequestCallback; +import com.github.scribejava.core.model.OAuthConfig; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.oauth.OAuth20Service; +import com.github.scribejava.core.oauth.OAuthService; +import com.github.scribejava.core.utils.StreamUtils; +import okhttp3.HttpUrl; +import okhttp3.mockwebserver.MockResponse; +import okhttp3.mockwebserver.MockWebServer; +import okhttp3.mockwebserver.RecordedRequest; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import java.io.IOException; +import java.util.concurrent.TimeUnit; + +import static org.junit.Assert.assertEquals; + +public abstract class AbstractClientTest { + + class TestCallback implements OAuthAsyncRequestCallback { + + private Throwable throwable; + private T response; + + @Override + public void onCompleted(T response) { + this.response = response; + } + + @Override + public void onThrowable(Throwable throwable) { + this.throwable = throwable; + } + } + + private OAuthService oAuthService; + private HttpClient client; + + @Before + public void setUp() { + client = createNewClient(); + oAuthService = new OAuth20Service(null, + new OAuthConfig("test", "test", null, null, null, null, null, null, null, client)); + } + + @After + public void shutDown() throws IOException { + client.close(); + } + + protected abstract HttpClient createNewClient(); + + @Test + public void shouldSendGetRequest() throws Exception { + final String expectedResponseBody = "response body"; + + final MockWebServer server = new MockWebServer(); + server.enqueue(new MockResponse().setBody(expectedResponseBody)); + server.start(); + + final HttpUrl baseUrl = server.url("/testUrl"); + + final OAuthRequest request = new OAuthRequest(Verb.GET, baseUrl.toString()); + final Response response = oAuthService.execute(request, null).get(30, TimeUnit.SECONDS); + + assertEquals(expectedResponseBody, response.getBody()); + + final RecordedRequest recordedRequest = server.takeRequest(); + assertEquals("GET", recordedRequest.getMethod()); + + server.shutdown(); + } + + @Test + public void shouldSendPostRequest() throws Exception { + final String expectedResponseBody = "response body"; + final String expectedRequestBody = "request body"; + + final MockWebServer server = new MockWebServer(); + server.enqueue(new MockResponse().setBody(expectedResponseBody)); + server.enqueue(new MockResponse().setBody(expectedResponseBody)); + server.start(); + + final HttpUrl baseUrl = server.url("/testUrl"); + + // request with body + OAuthRequest request = new OAuthRequest(Verb.POST, baseUrl.toString()); + request.setPayload(expectedRequestBody); + Response response = oAuthService.execute(request, null).get(30, TimeUnit.SECONDS); + + assertEquals(expectedResponseBody, response.getBody()); + + RecordedRequest recordedRequest = server.takeRequest(); + assertEquals("POST", recordedRequest.getMethod()); + assertEquals(expectedRequestBody, recordedRequest.getBody().readUtf8()); + + + // request with empty body + request = new OAuthRequest(Verb.POST, baseUrl.toString()); + response = oAuthService.execute(request, null).get(30, TimeUnit.SECONDS); + + assertEquals(expectedResponseBody, response.getBody()); + + recordedRequest = server.takeRequest(); + assertEquals("POST", recordedRequest.getMethod()); + assertEquals("", recordedRequest.getBody().readUtf8()); + + server.shutdown(); + } + + @Test + public void shouldReadResponseStream() throws Exception { + final String expectedResponseBody = "response body"; + + final MockWebServer server = new MockWebServer(); + server.enqueue(new MockResponse().setBody(expectedResponseBody)); + server.start(); + + final HttpUrl baseUrl = server.url("/testUrl"); + + final OAuthRequest request = new OAuthRequest(Verb.GET, baseUrl.toString()); + final Response response = oAuthService.execute(request, null).get(30, TimeUnit.SECONDS); + + assertEquals(expectedResponseBody, StreamUtils.getStreamContents(response.getStream())); + + final RecordedRequest recordedRequest = server.takeRequest(); + assertEquals("GET", recordedRequest.getMethod()); + + server.shutdown(); + } + + @Test + public void shouldCallCallback() throws Exception { + final String expectedResponseBody = "response body"; + + final MockWebServer server = new MockWebServer(); + server.enqueue(new MockResponse().setBody(expectedResponseBody)); + server.start(); + + final HttpUrl baseUrl = server.url("/testUrl"); + + final OAuthRequest request = new OAuthRequest(Verb.GET, baseUrl.toString()); + + final TestCallback callback = new TestCallback<>(); + oAuthService.execute(request, callback).get(); + + assertEquals(expectedResponseBody, callback.response.getBody()); + + server.shutdown(); + } + + @Test + public void shouldPassErrors() throws Exception { + + final MockWebServer server = new MockWebServer(); + server.enqueue(new MockResponse().setResponseCode(500)); + server.start(); + + final HttpUrl baseUrl = server.url("/testUrl"); + + final OAuthRequest request = new OAuthRequest(Verb.GET, baseUrl.toString()); + + final TestCallback callback = new TestCallback<>(); + final Response response = oAuthService.execute(request, callback).get(); + + assertEquals(500, response.getCode()); + assertEquals(500, callback.response.getCode()); + + server.shutdown(); + } +} diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 02eb03fe0..b312e65e2 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -25,6 +25,19 @@ async-http-client 2.0.33 + + com.github.scribejava + scribejava-core + ${project.version} + test-jar + test + + + com.squareup.okhttp3 + mockwebserver + 3.8.1 + test + diff --git a/scribejava-httpclient-ahc/src/test/java/com/github/scribejava/httpclient/ahc/AhcHttpClientTest.java b/scribejava-httpclient-ahc/src/test/java/com/github/scribejava/httpclient/ahc/AhcHttpClientTest.java new file mode 100644 index 000000000..34d940205 --- /dev/null +++ b/scribejava-httpclient-ahc/src/test/java/com/github/scribejava/httpclient/ahc/AhcHttpClientTest.java @@ -0,0 +1,12 @@ +package com.github.scribejava.httpclient.ahc; + +import com.github.scribejava.core.AbstractClientTest; +import com.github.scribejava.core.httpclient.HttpClient; + +public class AhcHttpClientTest extends AbstractClientTest { + + @Override + protected HttpClient createNewClient() { + return new AhcHttpClient(AhcHttpClientConfig.defaultConfig()); + } +} diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml new file mode 100644 index 000000000..6ce5a545a --- /dev/null +++ b/scribejava-httpclient-apache/pom.xml @@ -0,0 +1,60 @@ + + + 4.0.0 + + + com.github.scribejava + scribejava + 4.2.1-SNAPSHOT + ../pom.xml + + + com.github.scribejava + scribejava-httpclient-apache + ScribeJava Apache Http Client support + jar + + + + com.github.scribejava + scribejava-core + ${project.version} + + + org.apache.httpcomponents + httpclient + 4.5.2 + + + org.apache.httpcomponents + httpasyncclient + 4.1.3 + + + com.github.scribejava + scribejava-core + ${project.version} + test-jar + test + + + com.squareup.okhttp3 + mockwebserver + 3.8.1 + test + + + + + + + org.apache.felix + maven-bundle-plugin + + + org.apache.maven.plugins + maven-jar-plugin + + + + diff --git a/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/ApacheHttpClient.java b/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/ApacheHttpClient.java new file mode 100644 index 000000000..db6c8e48f --- /dev/null +++ b/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/ApacheHttpClient.java @@ -0,0 +1,109 @@ +package com.github.scribejava.httpclient.apache; + +import com.github.scribejava.core.httpclient.AbstractAsyncOnlyHttpClient; +import com.github.scribejava.core.model.OAuthAsyncRequestCallback; +import com.github.scribejava.core.model.OAuthConstants; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Verb; +import org.apache.http.HttpEntity; +import org.apache.http.HttpResponse; +import org.apache.http.client.methods.RequestBuilder; +import org.apache.http.entity.ByteArrayEntity; +import org.apache.http.entity.FileEntity; +import org.apache.http.entity.StringEntity; +import org.apache.http.impl.nio.client.CloseableHttpAsyncClient; +import org.apache.http.impl.nio.client.HttpAsyncClients; + +import java.io.File; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.util.Map; +import java.util.concurrent.Future; + +public class ApacheHttpClient extends AbstractAsyncOnlyHttpClient { + + private final CloseableHttpAsyncClient client; + + public ApacheHttpClient() { + this(HttpAsyncClients.createDefault()); + } + + public ApacheHttpClient(CloseableHttpAsyncClient client) { + this.client = client; + this.client.start(); + } + + @Override + public void close() throws IOException { + client.close(); + } + + @Override + public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, + byte[] bodyContents, OAuthAsyncRequestCallback callback, OAuthRequest.ResponseConverter converter) { + final HttpEntity entity = bodyContents == null ? null : new ByteArrayEntity(bodyContents); + return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, entity, callback, converter); + } + + @Override + public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, + String bodyContents, OAuthAsyncRequestCallback callback, OAuthRequest.ResponseConverter converter) { + final HttpEntity entity = bodyContents == null ? null : new StringEntity(bodyContents, StandardCharsets.UTF_8); + return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, entity, callback, converter); + } + + @Override + public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, + File bodyContents, OAuthAsyncRequestCallback callback, OAuthRequest.ResponseConverter converter) { + final HttpEntity entity = bodyContents == null ? null : new FileEntity(bodyContents); + return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, entity, callback, converter); + } + + private Future doExecuteAsync(String userAgent, Map headers, Verb httpVerb, + String completeUrl, HttpEntity entity, OAuthAsyncRequestCallback callback, + OAuthRequest.ResponseConverter converter) { + final RequestBuilder builder = getRequestBuilder(httpVerb); + builder.setUri(completeUrl); + + if (httpVerb.isPermitBody()) { + if (!headers.containsKey(CONTENT_TYPE)) { + builder.addHeader(CONTENT_TYPE, DEFAULT_CONTENT_TYPE); + } + builder.setEntity(entity); + } + + for (Map.Entry header : headers.entrySet()) { + builder.addHeader(header.getKey(), header.getValue()); + } + + if (userAgent != null) { + builder.setHeader(OAuthConstants.USER_AGENT_HEADER_NAME, userAgent); + } + final OAuthAsyncCompletionHandler handler = new OAuthAsyncCompletionHandler<>(callback, converter); + final Future future = client.execute(builder.build(), handler); + return new ApacheHttpFuture<>(future, handler); + } + + private RequestBuilder getRequestBuilder(Verb httpVerb) { + switch (httpVerb) { + case GET: + return RequestBuilder.get(); + case PUT: + return RequestBuilder.put(); + case DELETE: + return RequestBuilder.delete(); + case HEAD: + return RequestBuilder.head(); + case POST: + return RequestBuilder.post(); + case PATCH: + return RequestBuilder.patch(); + case TRACE: + return RequestBuilder.trace(); + case OPTIONS: + return RequestBuilder.options(); + default: + throw new IllegalArgumentException("message build error: unknown verb type"); + } + } +} diff --git a/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/ApacheHttpClientConfig.java b/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/ApacheHttpClientConfig.java new file mode 100644 index 000000000..5ff523431 --- /dev/null +++ b/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/ApacheHttpClientConfig.java @@ -0,0 +1,15 @@ +package com.github.scribejava.httpclient.apache; + +import com.github.scribejava.core.httpclient.HttpClientConfig; + +public class ApacheHttpClientConfig implements HttpClientConfig { + + @Override + public HttpClientConfig createDefaultConfig() { + return defaultConfig(); + } + + public static ApacheHttpClientConfig defaultConfig() { + return new ApacheHttpClientConfig(); + } +} diff --git a/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/ApacheHttpFuture.java b/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/ApacheHttpFuture.java new file mode 100644 index 000000000..47c098383 --- /dev/null +++ b/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/ApacheHttpFuture.java @@ -0,0 +1,44 @@ +package com.github.scribejava.httpclient.apache; + +import org.apache.http.HttpResponse; + +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; + +public class ApacheHttpFuture implements Future { + + private final Future future; + private final OAuthAsyncCompletionHandler handler; + + public ApacheHttpFuture(Future future, OAuthAsyncCompletionHandler handler) { + this.future = future; + this.handler = handler; + } + + @Override + public boolean cancel(boolean mayInterruptIfRunning) { + return future.cancel(mayInterruptIfRunning); + } + + @Override + public boolean isCancelled() { + return future.isCancelled(); + } + + @Override + public boolean isDone() { + return future.isDone(); + } + + @Override + public T get() throws InterruptedException, ExecutionException { + return handler.getResult(); + } + + @Override + public T get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { + return handler.getResult(timeout, unit); + } +} diff --git a/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/ApacheProvider.java b/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/ApacheProvider.java new file mode 100644 index 000000000..ed8efcf68 --- /dev/null +++ b/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/ApacheProvider.java @@ -0,0 +1,16 @@ +package com.github.scribejava.httpclient.apache; + +import com.github.scribejava.core.httpclient.HttpClient; +import com.github.scribejava.core.httpclient.HttpClientConfig; +import com.github.scribejava.core.httpclient.HttpClientProvider; + +public class ApacheProvider implements HttpClientProvider { + + @Override + public HttpClient createClient(HttpClientConfig httpClientConfig) { + if (httpClientConfig instanceof ApacheHttpClientConfig) { + return new ApacheHttpClient(); + } + return null; + } +} diff --git a/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/OAuthAsyncCompletionHandler.java b/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/OAuthAsyncCompletionHandler.java new file mode 100644 index 000000000..e63f17179 --- /dev/null +++ b/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/OAuthAsyncCompletionHandler.java @@ -0,0 +1,95 @@ +package com.github.scribejava.httpclient.apache; + +import com.github.scribejava.core.model.OAuthAsyncRequestCallback; +import com.github.scribejava.core.model.OAuthRequest.ResponseConverter; +import com.github.scribejava.core.model.Response; +import org.apache.http.Header; +import org.apache.http.HttpResponse; +import org.apache.http.concurrent.FutureCallback; + +import java.io.IOException; +import java.util.Map; +import java.util.concurrent.CancellationException; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +public class OAuthAsyncCompletionHandler implements FutureCallback { + + private final ResponseConverter converter; + private final OAuthAsyncRequestCallback callback; + private final CountDownLatch latch; + private T result; + private Exception exception; + + public OAuthAsyncCompletionHandler(OAuthAsyncRequestCallback callback, ResponseConverter converter) { + this.converter = converter; + this.callback = callback; + this.latch = new CountDownLatch(1); + } + + @Override + public void completed(HttpResponse httpResponse) { + try { + final Map headersMap = Stream.of(httpResponse.getAllHeaders()) + .collect(Collectors.toMap(Header::getName, Header::getValue)); + final Response response = new Response(httpResponse.getStatusLine().getStatusCode(), + httpResponse.getStatusLine().getReasonPhrase(), headersMap, httpResponse.getEntity().getContent()); + @SuppressWarnings("unchecked") + final T t = converter == null ? (T) response : converter.convert(response); + result = t; + if (callback != null) { + callback.onCompleted(result); + } + } catch (IOException e) { + exception = e; + if (callback != null) { + callback.onThrowable(e); + } + } finally { + latch.countDown(); + } + } + + @Override + public void failed(Exception e) { + exception = e; + try { + if (callback != null) { + callback.onThrowable(e); + } + } finally { + latch.countDown(); + } + } + + @Override + public void cancelled() { + exception = new CancellationException(); + try { + if (callback != null) { + callback.onThrowable(exception); + } + } finally { + latch.countDown(); + } + } + + public T getResult() throws InterruptedException, ExecutionException { + latch.await(); + if (exception != null) { + throw new ExecutionException(exception); + } + return result; + } + + public T getResult(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException { + latch.await(timeout, unit); + if (exception != null) { + throw new ExecutionException(exception); + } + return result; + } +} diff --git a/scribejava-httpclient-apache/src/test/java/com/github/scribejava/httpclient/apache/ApacheHttpClientTest.java b/scribejava-httpclient-apache/src/test/java/com/github/scribejava/httpclient/apache/ApacheHttpClientTest.java new file mode 100644 index 000000000..03924d81e --- /dev/null +++ b/scribejava-httpclient-apache/src/test/java/com/github/scribejava/httpclient/apache/ApacheHttpClientTest.java @@ -0,0 +1,13 @@ +package com.github.scribejava.httpclient.apache; + +import com.github.scribejava.core.AbstractClientTest; +import com.github.scribejava.core.httpclient.HttpClient; + +public class ApacheHttpClientTest extends AbstractClientTest { + + @Override + protected HttpClient createNewClient() { + return new ApacheHttpClient(); + } + +} diff --git a/scribejava-httpclient-apache/src/test/java/com/github/scribejava/httpclient/apache/OauthAsyncCompletionHandlerTest.java b/scribejava-httpclient-apache/src/test/java/com/github/scribejava/httpclient/apache/OauthAsyncCompletionHandlerTest.java new file mode 100644 index 000000000..f0309a173 --- /dev/null +++ b/scribejava-httpclient-apache/src/test/java/com/github/scribejava/httpclient/apache/OauthAsyncCompletionHandlerTest.java @@ -0,0 +1,128 @@ +package com.github.scribejava.httpclient.apache; + +import com.github.scribejava.core.model.OAuthAsyncRequestCallback; +import org.apache.http.HttpResponse; +import org.apache.http.ProtocolVersion; +import org.apache.http.entity.BasicHttpEntity; +import org.apache.http.message.BasicHttpResponse; +import org.apache.http.message.BasicStatusLine; +import org.junit.Before; +import org.junit.Test; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.util.concurrent.CancellationException; +import java.util.concurrent.ExecutionException; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +public class OauthAsyncCompletionHandlerTest { + + private OAuthAsyncCompletionHandler handler; + private TestCallback callback; + + class TestCallback implements OAuthAsyncRequestCallback { + + private Throwable throwable; + private String response; + + @Override + public void onCompleted(String response) { + this.response = response; + } + + @Override + public void onThrowable(Throwable throwable) { + this.throwable = throwable; + } + } + + @Before + public void setUp() { + callback = new TestCallback(); + } + + @Test + public void shouldReleaseLatchOnSuccess() throws Exception { + handler = new OAuthAsyncCompletionHandler<>(callback, response -> "All good"); + final HttpResponse response = new BasicHttpResponse(new BasicStatusLine( + new ProtocolVersion("4", 1, 1), 200, "ok")); + final BasicHttpEntity entity = new BasicHttpEntity(); + entity.setContent(new ByteArrayInputStream(new byte[0])); + response.setEntity(entity); + handler.completed(response); + assertNotNull(callback.response); + assertNull(callback.throwable); + // verify latch is released + assertEquals("All good", handler.getResult()); + } + + @Test + public void shouldReleaseLatchOnIOException() throws Exception { + handler = new OAuthAsyncCompletionHandler<>(callback, response -> { + throw new IOException("Failed to convert"); + }); + final HttpResponse response = new BasicHttpResponse(new BasicStatusLine( + new ProtocolVersion("4", 1, 1), 200, "ok")); + final BasicHttpEntity entity = new BasicHttpEntity(); + entity.setContent(new ByteArrayInputStream(new byte[0])); + response.setEntity(entity); + handler.completed(response); + assertNull(callback.response); + assertNotNull(callback.throwable); + assertTrue(callback.throwable instanceof IOException); + // verify latch is released + try { + handler.getResult(); + fail(); + } catch (ExecutionException expected) { + // expected + } + } + + @Test + public void shouldReleaseLatchOnCancel() throws Exception { + handler = new OAuthAsyncCompletionHandler<>(callback, response -> "All good"); + final HttpResponse response = new BasicHttpResponse(new BasicStatusLine( + new ProtocolVersion("4", 1, 1), 200, "ok")); + final BasicHttpEntity entity = new BasicHttpEntity(); + entity.setContent(new ByteArrayInputStream(new byte[0])); + response.setEntity(entity); + handler.cancelled(); + assertNull(callback.response); + assertNotNull(callback.throwable); + assertTrue(callback.throwable instanceof CancellationException); + // verify latch is released + try { + handler.getResult(); + fail(); + } catch (ExecutionException expected) { + // expected + } + } + + @Test + public void shouldReleaseLatchOnFailure() throws Exception { + handler = new OAuthAsyncCompletionHandler<>(callback, response -> "All good"); + final HttpResponse response = new BasicHttpResponse(new BasicStatusLine( + new ProtocolVersion("4", 1, 1), 200, "ok")); + final BasicHttpEntity entity = new BasicHttpEntity(); + entity.setContent(new ByteArrayInputStream(new byte[0])); + response.setEntity(entity); + handler.failed(new RuntimeException()); + assertNull(callback.response); + assertNotNull(callback.throwable); + assertTrue(callback.throwable instanceof RuntimeException); + // verify latch is released + try { + handler.getResult(); + fail(); + } catch (ExecutionException expected) { + // expected + } + } +} diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index 0142e94c0..1d1673810 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -25,6 +25,19 @@ async-http-client 1.9.40 + + com.github.scribejava + scribejava-core + ${project.version} + test-jar + test + + + com.squareup.okhttp3 + mockwebserver + 3.8.1 + test + diff --git a/scribejava-httpclient-ning/src/test/java/com/github/scribejava/httpclient/ning/NingHttpClientTest.java b/scribejava-httpclient-ning/src/test/java/com/github/scribejava/httpclient/ning/NingHttpClientTest.java new file mode 100644 index 000000000..8155cebf7 --- /dev/null +++ b/scribejava-httpclient-ning/src/test/java/com/github/scribejava/httpclient/ning/NingHttpClientTest.java @@ -0,0 +1,13 @@ +package com.github.scribejava.httpclient.ning; + +import com.github.scribejava.core.AbstractClientTest; +import com.github.scribejava.core.httpclient.HttpClient; +import com.ning.http.client.AsyncHttpClient; + +public class NingHttpClientTest extends AbstractClientTest { + + @Override + protected HttpClient createNewClient() { + return new NingHttpClient(new AsyncHttpClient()); + } +} diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 12e034874..f581e55de 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -31,6 +31,13 @@ 3.8.1 test + + com.github.scribejava + scribejava-core + ${project.version} + test-jar + test + diff --git a/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClientTest.java b/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClientTest.java index 496882cdd..1bc31919b 100644 --- a/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClientTest.java +++ b/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClientTest.java @@ -1,112 +1,13 @@ package com.github.scribejava.httpclient.okhttp; +import com.github.scribejava.core.AbstractClientTest; import com.github.scribejava.core.httpclient.HttpClient; -import com.github.scribejava.core.model.OAuthConfig; -import com.github.scribejava.core.model.OAuthRequest; -import com.github.scribejava.core.model.Response; -import com.github.scribejava.core.model.Verb; -import com.github.scribejava.core.oauth.OAuth20Service; -import com.github.scribejava.core.oauth.OAuthService; -import com.github.scribejava.core.utils.StreamUtils; -import okhttp3.HttpUrl; import okhttp3.OkHttpClient; -import okhttp3.mockwebserver.MockResponse; -import okhttp3.mockwebserver.MockWebServer; -import okhttp3.mockwebserver.RecordedRequest; -import org.junit.Before; -import org.junit.Test; -import java.util.concurrent.TimeUnit; +public class OkHttpHttpClientTest extends AbstractClientTest { -import static org.junit.Assert.assertEquals; - -public class OkHttpHttpClientTest { - private OAuthService oAuthService; - - @Before - public void setUp() { - final HttpClient client = new OkHttpHttpClient(new OkHttpClient()); - oAuthService = new OAuth20Service(null, - new OAuthConfig("test", "test", null, null, null, null, null, null, null, client)); - } - - - @Test - public void shouldSendGetRequest() throws Exception { - final String expectedResponseBody = "response body"; - - final MockWebServer server = new MockWebServer(); - server.enqueue(new MockResponse().setBody(expectedResponseBody)); - server.start(); - - final HttpUrl baseUrl = server.url("/testUrl"); - - final OAuthRequest request = new OAuthRequest(Verb.GET, baseUrl.toString()); - final Response response = oAuthService.execute(request, null).get(30, TimeUnit.SECONDS); - - assertEquals(expectedResponseBody, response.getBody()); - - final RecordedRequest recordedRequest = server.takeRequest(); - assertEquals("GET", recordedRequest.getMethod()); - - server.shutdown(); - } - - @Test - public void shouldSendPostRequest() throws Exception { - final String expectedResponseBody = "response body"; - final String expectedRequestBody = "request body"; - - final MockWebServer server = new MockWebServer(); - server.enqueue(new MockResponse().setBody(expectedResponseBody)); - server.enqueue(new MockResponse().setBody(expectedResponseBody)); - server.start(); - - final HttpUrl baseUrl = server.url("/testUrl"); - - // request with body - OAuthRequest request = new OAuthRequest(Verb.POST, baseUrl.toString()); - request.setPayload(expectedRequestBody); - Response response = oAuthService.execute(request, null).get(30, TimeUnit.SECONDS); - - assertEquals(expectedResponseBody, response.getBody()); - - RecordedRequest recordedRequest = server.takeRequest(); - assertEquals("POST", recordedRequest.getMethod()); - assertEquals(expectedRequestBody, recordedRequest.getBody().readUtf8()); - - - // request with empty body - request = new OAuthRequest(Verb.POST, baseUrl.toString()); - response = oAuthService.execute(request, null).get(30, TimeUnit.SECONDS); - - assertEquals(expectedResponseBody, response.getBody()); - - recordedRequest = server.takeRequest(); - assertEquals("POST", recordedRequest.getMethod()); - assertEquals("", recordedRequest.getBody().readUtf8()); - - server.shutdown(); - } - - @Test - public void shouldReadResponseStream() throws Exception { - final String expectedResponseBody = "response body"; - - final MockWebServer server = new MockWebServer(); - server.enqueue(new MockResponse().setBody(expectedResponseBody)); - server.start(); - - final HttpUrl baseUrl = server.url("/testUrl"); - - final OAuthRequest request = new OAuthRequest(Verb.GET, baseUrl.toString()); - final Response response = oAuthService.execute(request, null).get(30, TimeUnit.SECONDS); - - assertEquals(expectedResponseBody, StreamUtils.getStreamContents(response.getStream())); - - final RecordedRequest recordedRequest = server.takeRequest(); - assertEquals("GET", recordedRequest.getMethod()); - - server.shutdown(); + @Override + protected HttpClient createNewClient() { + return new OkHttpHttpClient(new OkHttpClient()); } } From 5ee2173fbe4feeab5d5fd93d3b455e9f66771f21 Mon Sep 17 00:00:00 2001 From: Stephan Date: Sun, 1 Oct 2017 18:06:18 +1100 Subject: [PATCH 413/882] Added tests for JDKHttpClient, fixed bug --- .../core/httpclient/jdk/JDKHttpClient.java | 18 ++++++++++++------ .../core/httpclient/jdk/JDKHttpClientTest.java | 12 ++++++++++++ 2 files changed, 24 insertions(+), 6 deletions(-) create mode 100644 scribejava-core/src/test/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClientTest.java diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java index 8a6f3e516..d02dc5e8b 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java @@ -33,9 +33,13 @@ public void close() throws IOException { public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, byte[] bodyContents, OAuthAsyncRequestCallback callback, OAuthRequest.ResponseConverter converter) { try { - final T response = converter.convert(execute(userAgent, headers, httpVerb, completeUrl, bodyContents)); - callback.onCompleted(response); - return new JDKHttpFuture<>(response); + final Response response = execute(userAgent, headers, httpVerb, completeUrl, bodyContents); + @SuppressWarnings("unchecked") + final T t = converter == null ? (T) response : converter.convert(response); + if (callback != null) { + callback.onCompleted(t); + } + return new JDKHttpFuture<>(t); } catch (InterruptedException | ExecutionException | IOException e) { callback.onThrowable(e); return new JDKHttpFuture<>(e); @@ -46,11 +50,13 @@ public Future executeAsync(String userAgent, Map headers, public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, String bodyContents, OAuthAsyncRequestCallback callback, OAuthRequest.ResponseConverter converter) { try { - final T response = converter.convert(execute(userAgent, headers, httpVerb, completeUrl, bodyContents)); + final Response response = execute(userAgent, headers, httpVerb, completeUrl, bodyContents); + @SuppressWarnings("unchecked") + final T t = converter == null ? (T) response : converter.convert(response); if (callback != null) { - callback.onCompleted(response); + callback.onCompleted(t); } - return new JDKHttpFuture<>(response); + return new JDKHttpFuture<>(t); } catch (InterruptedException | ExecutionException | IOException e) { if (callback != null) { callback.onThrowable(e); diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClientTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClientTest.java new file mode 100644 index 000000000..09d34f0c3 --- /dev/null +++ b/scribejava-core/src/test/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClientTest.java @@ -0,0 +1,12 @@ +package com.github.scribejava.core.httpclient.jdk; + +import com.github.scribejava.core.AbstractClientTest; +import com.github.scribejava.core.httpclient.HttpClient; + +public class JDKHttpClientTest extends AbstractClientTest { + + @Override + protected HttpClient createNewClient() { + return new JDKHttpClient(JDKHttpClientConfig.defaultConfig()); + } +} From 8d62f0cace86975a95c382fbf3176cbbf3881748 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 3 Nov 2017 16:30:02 +0300 Subject: [PATCH 414/882] add PKCE (RFC 7636) support (Proof Key for Code Exchange by OAuth Public Clients) (thanks for suggesting to https://github.com/dieseldjango) --- changelog | 1 + .../examples/Google20WithPKCEExample.java | 115 ++++++++++++++++++ .../core/oauth/OAuth10aService.java | 2 - .../scribejava/core/oauth/OAuth20Service.java | 77 ++++++++++-- .../core/pkce/AuthorizationUrlWithPKCE.java | 21 ++++ .../com/github/scribejava/core/pkce/PKCE.java | 49 ++++++++ .../core/pkce/PKCECodeChallengeMethod.java | 27 ++++ .../scribejava/core/pkce/PKCEService.java | 54 ++++++++ .../core/services/Base64Encoder.java | 15 +-- .../core/services/CommonsEncoder.java | 4 + .../services/DatatypeConverterEncoder.java | 4 + .../services/HMACSha1SignatureService.java | 6 +- .../services/RSASha1SignatureService.java | 6 +- .../core/services/SignatureService.java | 3 + .../pkce/PKCECodeChallengeMethodTest.java | 26 ++++ 15 files changed, 379 insertions(+), 31 deletions(-) create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20WithPKCEExample.java create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/pkce/AuthorizationUrlWithPKCE.java create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/pkce/PKCE.java create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/pkce/PKCECodeChallengeMethod.java create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/pkce/PKCEService.java create mode 100644 scribejava-core/src/test/java/com/github/scribejava/core/pkce/PKCECodeChallengeMethodTest.java diff --git a/changelog b/changelog index 4ef2ad99c..076c80762 100644 --- a/changelog +++ b/changelog @@ -2,6 +2,7 @@ * drop Java 7 backward compatibility support, become Java 8 only * add JSON token extractor for OAuth 1.0a (thanks to https://github.com/evstropovv) * add new API - uCoz (https://www.ucoz.com/) (thanks to https://github.com/evstropovv) + * add PKCE (RFC 7636) support (Proof Key for Code Exchange by OAuth Public Clients) (thanks for suggesting to https://github.com/dieseldjango) [4.2.0] * DELETE in JdkClient permits, but not requires payload (thanks to https://github.com/miguelD73) diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20WithPKCEExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20WithPKCEExample.java new file mode 100644 index 000000000..91a108cb1 --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20WithPKCEExample.java @@ -0,0 +1,115 @@ +package com.github.scribejava.apis.examples; + +import java.util.Random; +import java.util.Scanner; +import com.github.scribejava.core.builder.ServiceBuilder; +import com.github.scribejava.apis.GoogleApi20; +import com.github.scribejava.core.model.OAuth2AccessToken; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.oauth.OAuth20Service; +import com.github.scribejava.core.pkce.AuthorizationUrlWithPKCE; +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.ExecutionException; + +public final class Google20WithPKCEExample { + + private static final String NETWORK_NAME = "G+"; + private static final String PROTECTED_RESOURCE_URL = "https://www.googleapis.com/plus/v1/people/me"; + + private Google20WithPKCEExample() { + } + + public static void main(String... args) throws IOException, InterruptedException, ExecutionException { + // Replace these with your client id and secret + final String clientId = "your client id"; + final String clientSecret = "your client secret"; + final String secretState = "secret" + new Random().nextInt(999_999); + final OAuth20Service service = new ServiceBuilder(clientId) + .apiSecret(clientSecret) + .scope("profile") // replace with desired scope + .state(secretState) + .callback("http://example.com/callback") + .build(GoogleApi20.instance()); + + final Scanner in = new Scanner(System.in, "UTF-8"); + + System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); + System.out.println(); + + // Obtain the Authorization URL + System.out.println("Fetching the Authorization URL..."); + //pass access_type=offline to get refresh token + //https://developers.google.com/identity/protocols/OAuth2WebServer#preparing-to-start-the-oauth-20-flow + final Map additionalParams = new HashMap<>(); + additionalParams.put("access_type", "offline"); + //force to reget refresh token (if usera are asked not the first time) + additionalParams.put("prompt", "consent"); + + final AuthorizationUrlWithPKCE authUrlWithPKCE = service.getAuthorizationUrlWithPKCE(additionalParams); + + System.out.println("Got the Authorization URL!"); + System.out.println("Now go and authorize ScribeJava here:"); + System.out.println(authUrlWithPKCE.getAuthorizationUrl()); + System.out.println("And paste the authorization code here"); + System.out.print(">>"); + final String code = in.nextLine(); + System.out.println(); + + System.out.println("And paste the state from server here. We have set 'secretState'='" + secretState + "'."); + System.out.print(">>"); + final String value = in.nextLine(); + if (secretState.equals(value)) { + System.out.println("State value does match!"); + } else { + System.out.println("Ooops, state value does not match!"); + System.out.println("Expected = " + secretState); + System.out.println("Got = " + value); + System.out.println(); + } + + // Trade the Request Token and Verfier for the Access Token + System.out.println("Trading the Request Token for an Access Token..."); + OAuth2AccessToken accessToken = service.getAccessToken(code, authUrlWithPKCE.getPkce().getCodeVerifier()); + System.out.println("Got the Access Token!"); + System.out.println("(if your curious it looks like this: " + accessToken + + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + + System.out.println("Refreshing the Access Token..."); + accessToken = service.refreshAccessToken(accessToken.getRefreshToken()); + System.out.println("Refreshed the Access Token!"); + System.out.println("(if your curious it looks like this: " + accessToken + + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println(); + + // Now let's go and ask for a protected resource! + System.out.println("Now we're going to access a protected resource..."); + while (true) { + System.out.println("Paste fieldnames to fetch (leave empty to get profile, 'exit' to stop example)"); + System.out.print(">>"); + final String query = in.nextLine(); + System.out.println(); + + final String requestUrl; + if ("exit".equals(query)) { + break; + } else if (query == null || query.isEmpty()) { + requestUrl = PROTECTED_RESOURCE_URL; + } else { + requestUrl = PROTECTED_RESOURCE_URL + "?fields=" + query; + } + + final OAuthRequest request = new OAuthRequest(Verb.GET, requestUrl); + service.signRequest(accessToken, request); + final Response response = service.execute(request); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + + System.out.println(); + } + } +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java index 00be552cb..1023def56 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java @@ -11,7 +11,6 @@ import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; -import com.github.scribejava.core.services.Base64Encoder; import java.util.concurrent.ExecutionException; /** @@ -157,7 +156,6 @@ public String getAuthorizationUrl(OAuth1RequestToken requestToken) { private String getSignature(OAuthRequest request, String tokenSecret) { final OAuthConfig config = getConfig(); config.log("generating signature..."); - config.log("using base64 encoder: " + Base64Encoder.type()); final String baseString = api.getBaseStringExtractor().extract(request); final String signature = api.getSignatureService().getSignature(baseString, config.getApiSecret(), tokenSecret); diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java index 803e6fa80..5caefdca9 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java @@ -1,6 +1,5 @@ package com.github.scribejava.core.oauth; -import com.github.scribejava.core.services.Base64Encoder; import java.io.IOException; import java.nio.charset.Charset; import java.util.concurrent.Future; @@ -11,12 +10,19 @@ import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.pkce.AuthorizationUrlWithPKCE; +import com.github.scribejava.core.pkce.PKCE; +import com.github.scribejava.core.pkce.PKCEService; +import java.util.Base64; +import java.util.HashMap; import java.util.Map; import java.util.concurrent.ExecutionException; public class OAuth20Service extends OAuthService { private static final String VERSION = "2.0"; + private static final Base64.Encoder BASE_64_ENCODER = Base64.getEncoder(); + private static final PKCEService PKCE_SERVICE = new PKCEService(); private final DefaultApi20 api; /** @@ -49,12 +55,21 @@ protected Future sendAccessTokenRequestAsync(OAuthRequest req } public final Future getAccessTokenAsync(String code) { - return getAccessToken(code, null); + return getAccessToken(code, null, null); + } + + public final Future getAccessTokenAsync(String code, String pkceCodeVerifier) { + return getAccessToken(code, null, pkceCodeVerifier); } public final OAuth2AccessToken getAccessToken(String code) throws IOException, InterruptedException, ExecutionException { - final OAuthRequest request = createAccessTokenRequest(code); + return getAccessToken(code, (String) null); + } + + public final OAuth2AccessToken getAccessToken(String code, String pkceCodeVerifier) + throws IOException, InterruptedException, ExecutionException { + final OAuthRequest request = createAccessTokenRequest(code, pkceCodeVerifier); return sendAccessTokenRequestSync(request); } @@ -65,15 +80,22 @@ public final OAuth2AccessToken getAccessToken(String code) * * @param code code * @param callback optional callback + * @param pkceCodeVerifier pkce Code Verifier * @return Future */ public final Future getAccessToken(String code, - OAuthAsyncRequestCallback callback) { - final OAuthRequest request = createAccessTokenRequest(code); + OAuthAsyncRequestCallback callback, String pkceCodeVerifier) { + final OAuthRequest request = createAccessTokenRequest(code, pkceCodeVerifier); return sendAccessTokenRequestAsync(request, callback); } + public final Future getAccessToken(String code, + OAuthAsyncRequestCallback callback) { + + return getAccessToken(code, callback, null); + } + protected OAuthRequest createAccessTokenRequest(String code) { final OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint()); final OAuthConfig config = getConfig(); @@ -92,6 +114,14 @@ protected OAuthRequest createAccessTokenRequest(String code) { return request; } + protected OAuthRequest createAccessTokenRequest(String code, String pkceCodeVerifier) { + final OAuthRequest request = createAccessTokenRequest(code); + if (pkceCodeVerifier != null) { + request.addParameter(PKCE.PKCE_CODE_VERIFIER_PARAM, pkceCodeVerifier); + } + return request; + } + public final Future refreshAccessTokenAsync(String refreshToken) { return refreshAccessToken(refreshToken, null); } @@ -168,10 +198,9 @@ protected OAuthRequest createAccessTokenPasswordGrantRequest(String username, St final String apiKey = config.getApiKey(); final String apiSecret = config.getApiSecret(); if (apiKey != null && apiSecret != null) { - request.addHeader(OAuthConstants.HEADER, - OAuthConstants.BASIC + ' ' - + Base64Encoder.getInstance() - .encode(String.format("%s:%s", apiKey, apiSecret).getBytes(Charset.forName("UTF-8")))); + request.addHeader(OAuthConstants.HEADER, OAuthConstants.BASIC + ' ' + + BASE_64_ENCODER.encodeToString( + String.format("%s:%s", apiKey, apiSecret).getBytes(Charset.forName("UTF-8")))); } return request; @@ -190,13 +219,22 @@ public void signRequest(OAuth2AccessToken accessToken, OAuthRequest request) { api.getSignatureType().signRequest(accessToken, request); } + public final AuthorizationUrlWithPKCE getAuthorizationUrlWithPKCE() { + return getAuthorizationUrlWithPKCE(null); + } + + public final AuthorizationUrlWithPKCE getAuthorizationUrlWithPKCE(Map additionalParams) { + final PKCE pkce = PKCE_SERVICE.generatePKCE(); + return new AuthorizationUrlWithPKCE(pkce, getAuthorizationUrl(additionalParams, pkce)); + } + /** * Returns the URL where you should redirect your users to authenticate your application. * * @return the URL where you should redirect your users */ public final String getAuthorizationUrl() { - return getAuthorizationUrl(null); + return getAuthorizationUrl(null, null); } /** @@ -205,8 +243,23 @@ public final String getAuthorizationUrl() { * @param additionalParams any additional GET params to add to the URL * @return the URL where you should redirect your users */ - public String getAuthorizationUrl(Map additionalParams) { - return api.getAuthorizationUrl(getConfig(), additionalParams); + public final String getAuthorizationUrl(Map additionalParams) { + return getAuthorizationUrl(additionalParams, null); + } + + public final String getAuthorizationUrl(PKCE pkce) { + return getAuthorizationUrl(null, pkce); + } + + public String getAuthorizationUrl(Map additionalParams, PKCE pkce) { + final Map params; + if (pkce == null) { + params = additionalParams; + } else { + params = additionalParams == null ? new HashMap<>() : new HashMap<>(additionalParams); + params.putAll(pkce.getAuthorizationUrlParams()); + } + return api.getAuthorizationUrl(getConfig(), params); } public DefaultApi20 getApi() { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/pkce/AuthorizationUrlWithPKCE.java b/scribejava-core/src/main/java/com/github/scribejava/core/pkce/AuthorizationUrlWithPKCE.java new file mode 100644 index 000000000..101f82f10 --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/pkce/AuthorizationUrlWithPKCE.java @@ -0,0 +1,21 @@ +package com.github.scribejava.core.pkce; + +public class AuthorizationUrlWithPKCE { + + private final PKCE pkce; + private final String authorizationUrl; + + public AuthorizationUrlWithPKCE(PKCE pkce, String authorizationUrl) { + this.pkce = pkce; + this.authorizationUrl = authorizationUrl; + } + + public PKCE getPkce() { + return pkce; + } + + public String getAuthorizationUrl() { + return authorizationUrl; + } + +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/pkce/PKCE.java b/scribejava-core/src/main/java/com/github/scribejava/core/pkce/PKCE.java new file mode 100644 index 000000000..c8d43d26e --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/pkce/PKCE.java @@ -0,0 +1,49 @@ +package com.github.scribejava.core.pkce; + +import java.util.HashMap; +import java.util.Map; + +/** + * Used to hold code_challenge, code_challenge_method and code_verifier for https://tools.ietf.org/html/rfc7636 + */ +public class PKCE { + + public static final String PKCE_CODE_CHALLENGE_METHOD_PARAM = "code_challenge_method"; + public static final String PKCE_CODE_CHALLENGE_PARAM = "code_challenge"; + public static final String PKCE_CODE_VERIFIER_PARAM = "code_verifier"; + + private String codeChallenge; + private PKCECodeChallengeMethod codeChallengeMethod = PKCECodeChallengeMethod.S256; + private String codeVerifier; + + public String getCodeChallenge() { + return codeChallenge; + } + + public void setCodeChallenge(String codeChallenge) { + this.codeChallenge = codeChallenge; + } + + public PKCECodeChallengeMethod getCodeChallengeMethod() { + return codeChallengeMethod; + } + + public void setCodeChallengeMethod(PKCECodeChallengeMethod codeChallengeMethod) { + this.codeChallengeMethod = codeChallengeMethod; + } + + public String getCodeVerifier() { + return codeVerifier; + } + + public void setCodeVerifier(String codeVerifier) { + this.codeVerifier = codeVerifier; + } + + public Map getAuthorizationUrlParams() { + final Map params = new HashMap<>(); + params.put(PKCE_CODE_CHALLENGE_PARAM, codeChallenge); + params.put(PKCE_CODE_CHALLENGE_METHOD_PARAM, codeChallengeMethod.name()); + return params; + } +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/pkce/PKCECodeChallengeMethod.java b/scribejava-core/src/main/java/com/github/scribejava/core/pkce/PKCECodeChallengeMethod.java new file mode 100644 index 000000000..e8e6cb6e2 --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/pkce/PKCECodeChallengeMethod.java @@ -0,0 +1,27 @@ +package com.github.scribejava.core.pkce; + +import java.nio.charset.StandardCharsets; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.util.Base64; + +public enum PKCECodeChallengeMethod { + S256 { + private final Base64.Encoder base64Encoder = Base64.getUrlEncoder().withoutPadding(); + + @Override + public String transform2CodeChallenge(String codeVerifier) throws NoSuchAlgorithmException { + return base64Encoder.encodeToString( + MessageDigest.getInstance("SHA-256").digest( + codeVerifier.getBytes(StandardCharsets.US_ASCII))); + } + }, + plain { + @Override + public String transform2CodeChallenge(String codeVerifier) { + return codeVerifier; + } + }; + + public abstract String transform2CodeChallenge(String codeVerifier) throws NoSuchAlgorithmException; +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/pkce/PKCEService.java b/scribejava-core/src/main/java/com/github/scribejava/core/pkce/PKCEService.java new file mode 100644 index 000000000..86cbb22af --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/pkce/PKCEService.java @@ -0,0 +1,54 @@ +package com.github.scribejava.core.pkce; + +import java.security.NoSuchAlgorithmException; +import java.security.SecureRandom; +import java.util.Base64; + +/** + * Used to implement Proof Key for Code Exchange by OAuth Public Clients https://tools.ietf.org/html/rfc7636 + * + */ +public class PKCEService { + + private static final SecureRandom RANDOM = new SecureRandom(); + private static final Base64.Encoder BASE_64_ENCODER = Base64.getUrlEncoder().withoutPadding(); + /** + * number of octets to randomly generate. + */ + private final int numberOFOctets; + + public PKCEService(int numberOFOctets) { + this.numberOFOctets = numberOFOctets; + } + + /** + * will create random generator with recommended params (32 octets) https://tools.ietf.org/html/rfc7636#section-4.1 + */ + public PKCEService() { + this(32); + } + + public PKCE generatePKCE() { + final byte[] bytes = new byte[numberOFOctets]; + RANDOM.nextBytes(bytes); + return generatePKCE(bytes); + } + + public PKCE generatePKCE(byte[] randomBytes) { + final String codeVerifier = BASE_64_ENCODER.encodeToString(randomBytes); + + final PKCE pkce = new PKCE(); + pkce.setCodeVerifier(codeVerifier); + try { + pkce.setCodeChallenge(pkce.getCodeChallengeMethod().transform2CodeChallenge(codeVerifier)); + } catch (NoSuchAlgorithmException nsaE) { + pkce.setCodeChallengeMethod(PKCECodeChallengeMethod.plain); + try { + pkce.setCodeChallenge(PKCECodeChallengeMethod.plain.transform2CodeChallenge(codeVerifier)); + } catch (NoSuchAlgorithmException unrealE) { + throw new IllegalStateException("It's just cannot be", unrealE); + } + } + return pkce; + } +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/services/Base64Encoder.java b/scribejava-core/src/main/java/com/github/scribejava/core/services/Base64Encoder.java index ab564941c..26285cda4 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/services/Base64Encoder.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/services/Base64Encoder.java @@ -1,16 +1,17 @@ package com.github.scribejava.core.services; +/** + * @deprecated use standard java8 java.util.Base64 + */ +@Deprecated public abstract class Base64Encoder { - private static Base64Encoder instance; + private static class InstanceHolder { + private static final Base64Encoder INSTANCE = createEncoderInstance(); + } public static Base64Encoder getInstance() { - synchronized (Base64Encoder.class) { - if (instance == null) { - instance = createEncoderInstance(); - } - } - return instance; + return InstanceHolder.INSTANCE; } private static Base64Encoder createEncoderInstance() { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/services/CommonsEncoder.java b/scribejava-core/src/main/java/com/github/scribejava/core/services/CommonsEncoder.java index 6e2afa24d..c982abfcd 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/services/CommonsEncoder.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/services/CommonsEncoder.java @@ -4,6 +4,10 @@ import org.apache.commons.codec.binary.Base64; import com.github.scribejava.core.exceptions.OAuthSignatureException; +/** + * @deprecated use standard java8 java.util.Base64 + */ +@Deprecated public class CommonsEncoder extends Base64Encoder { @Override diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/services/DatatypeConverterEncoder.java b/scribejava-core/src/main/java/com/github/scribejava/core/services/DatatypeConverterEncoder.java index eee87714f..cfc8c2ef2 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/services/DatatypeConverterEncoder.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/services/DatatypeConverterEncoder.java @@ -2,6 +2,10 @@ import javax.xml.bind.DatatypeConverter; +/** + * @deprecated use standard java8 java.util.Base64 + */ +@Deprecated public class DatatypeConverterEncoder extends Base64Encoder { @Override diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/services/HMACSha1SignatureService.java b/scribejava-core/src/main/java/com/github/scribejava/core/services/HMACSha1SignatureService.java index 824f488d7..3d942fbd0 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/services/HMACSha1SignatureService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/services/HMACSha1SignatureService.java @@ -40,11 +40,7 @@ private String doSign(String toSign, String keyString) throws UnsupportedEncodin final Mac mac = Mac.getInstance(HMAC_SHA1); mac.init(key); final byte[] bytes = mac.doFinal(toSign.getBytes(UTF8)); - return bytesToBase64String(bytes).replace(CARRIAGE_RETURN, EMPTY_STRING); - } - - private String bytesToBase64String(byte[] bytes) { - return Base64Encoder.getInstance().encode(bytes); + return BASE_64_ENCODER.encodeToString(bytes).replace(CARRIAGE_RETURN, EMPTY_STRING); } /** diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/services/RSASha1SignatureService.java b/scribejava-core/src/main/java/com/github/scribejava/core/services/RSASha1SignatureService.java index 78ecfa2a1..9cb460e7b 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/services/RSASha1SignatureService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/services/RSASha1SignatureService.java @@ -32,17 +32,13 @@ public String getSignature(String baseString, String apiSecret, String tokenSecr final Signature signature = Signature.getInstance(RSA_SHA1); signature.initSign(privateKey); signature.update(baseString.getBytes(UTF8)); - return bytesToBase64String(signature); + return BASE_64_ENCODER.encodeToString(signature.sign()); } catch (NoSuchAlgorithmException | InvalidKeyException | SignatureException | UnsupportedEncodingException | RuntimeException e) { throw new OAuthSignatureException(baseString, e); } } - private String bytesToBase64String(Signature signature) throws SignatureException { - return Base64Encoder.getInstance().encode(signature.sign()); - } - /** * {@inheritDoc} */ diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/services/SignatureService.java b/scribejava-core/src/main/java/com/github/scribejava/core/services/SignatureService.java index cf821d089..0b180d49f 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/services/SignatureService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/services/SignatureService.java @@ -1,9 +1,12 @@ package com.github.scribejava.core.services; +import java.util.Base64; + /** * Signs a base string, returning the OAuth signature */ public interface SignatureService { + Base64.Encoder BASE_64_ENCODER = Base64.getEncoder(); /** * Returns the signature diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/pkce/PKCECodeChallengeMethodTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/pkce/PKCECodeChallengeMethodTest.java new file mode 100644 index 000000000..1f580480a --- /dev/null +++ b/scribejava-core/src/test/java/com/github/scribejava/core/pkce/PKCECodeChallengeMethodTest.java @@ -0,0 +1,26 @@ +package com.github.scribejava.core.pkce; + +import org.junit.Test; +import static org.junit.Assert.assertEquals; + +/** + * test PKCE according to
+ * Appendix B. Example for the S256 code_challenge_method
+ * https://tools.ietf.org/html/rfc7636#appendix-B + */ +public class PKCECodeChallengeMethodTest { + + private static final byte[] RANDOM_BYTES = new byte[]{116, 24, (byte) 223, (byte) 180, (byte) 151, (byte) 153, + (byte) 224, 37, 79, (byte) 250, 96, 125, (byte) 216, (byte) 173, (byte) 187, (byte) 186, 22, (byte) 212, 37, 77, + 105, (byte) 214, (byte) 191, (byte) 240, 91, 88, 5, 88, 83, (byte) 132, (byte) 141, 121}; + + @Test + public void testGeneratingPKCE() { + final PKCE pkce = new PKCEService().generatePKCE(RANDOM_BYTES); + + assertEquals(PKCECodeChallengeMethod.S256, pkce.getCodeChallengeMethod()); + assertEquals("dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk", pkce.getCodeVerifier()); + assertEquals("E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM", pkce.getCodeChallenge()); + } + +} From a1368bbfc154eb32352367d4cdc155f10e6a6f77 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 3 Nov 2017 16:33:57 +0300 Subject: [PATCH 415/882] update deps --- pom.xml | 8 ++++---- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/pom.xml b/pom.xml index 7b8520909..864cc710d 100644 --- a/pom.xml +++ b/pom.xml @@ -86,13 +86,13 @@ com.google.code.gson gson - 2.8.1 + 2.8.2 test commons-codec commons-codec - 1.10 + 1.11 compile true @@ -132,7 +132,7 @@ com.puppycrawl.tools checkstyle - 8.0 + 8.3 @@ -148,7 +148,7 @@ maven-compiler-plugin - 3.6.1 + 3.7.0 UTF-8 1.8 diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 02eb03fe0..2bd07e247 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -23,7 +23,7 @@ org.asynchttpclient async-http-client - 2.0.33 + 2.0.37 diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 12e034874..dffe95c4d 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -23,12 +23,12 @@ com.squareup.okhttp3 okhttp - 3.8.1 + 3.9.0 com.squareup.okhttp3 mockwebserver - 3.8.1 + 3.9.0 test From 82f38333b9fd53291f32f29638ee473c578f9900 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 3 Nov 2017 18:50:59 +0300 Subject: [PATCH 416/882] switch to use HTTP Basic Authorization by default in requests with need of (2.3. Client Authentication) https://tools.ietf.org/html/rfc6749#section-2.3 Can be overrided in API class --- changelog | 2 + .../github/scribejava/apis/FacebookApi.java | 6 +++ .../com/github/scribejava/apis/HHApi.java | 6 +++ .../scribejava/apis/OdnoklassnikiApi.java | 6 +++ .../github/scribejava/apis/VkontakteApi.java | 6 +++ .../builder/api/ClientAuthenticationType.java | 43 +++++++++++++++++++ .../core/builder/api/DefaultApi20.java | 4 ++ .../scribejava/core/oauth/OAuth20Service.java | 28 +++--------- 8 files changed, 80 insertions(+), 21 deletions(-) create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/builder/api/ClientAuthenticationType.java diff --git a/changelog b/changelog index 076c80762..403427346 100644 --- a/changelog +++ b/changelog @@ -3,6 +3,8 @@ * add JSON token extractor for OAuth 1.0a (thanks to https://github.com/evstropovv) * add new API - uCoz (https://www.ucoz.com/) (thanks to https://github.com/evstropovv) * add PKCE (RFC 7636) support (Proof Key for Code Exchange by OAuth Public Clients) (thanks for suggesting to https://github.com/dieseldjango) + * switch to use HTTP Basic Authorization by default in requests with need of + (2.3. Client Authentication) https://tools.ietf.org/html/rfc6749#section-2.3 Can be overrided in API class [4.2.0] * DELETE in JdkClient permits, but not requires payload (thanks to https://github.com/miguelD73) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java index f761aab03..41333f4f0 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java @@ -1,6 +1,7 @@ package com.github.scribejava.apis; import com.github.scribejava.apis.facebook.FacebookAccessTokenJsonExtractor; +import com.github.scribejava.core.builder.api.ClientAuthenticationType; import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.extractors.TokenExtractor; import com.github.scribejava.core.model.OAuth2AccessToken; @@ -47,4 +48,9 @@ protected String getAuthorizationBaseUrl() { public TokenExtractor getAccessTokenExtractor() { return FacebookAccessTokenJsonExtractor.instance(); } + + @Override + public ClientAuthenticationType getClientAuthenticationType() { + return ClientAuthenticationType.REQUEST_BODY; + } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/HHApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/HHApi.java index 2a8a8aa12..f1f307155 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/HHApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/HHApi.java @@ -1,5 +1,6 @@ package com.github.scribejava.apis; +import com.github.scribejava.core.builder.api.ClientAuthenticationType; import com.github.scribejava.core.builder.api.DefaultApi20; public class HHApi extends DefaultApi20 { @@ -24,4 +25,9 @@ public String getAccessTokenEndpoint() { protected String getAuthorizationBaseUrl() { return "https://hh.ru/oauth/authorize"; } + + @Override + public ClientAuthenticationType getClientAuthenticationType() { + return ClientAuthenticationType.REQUEST_BODY; + } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java index f8e1a40ef..df4e2e755 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java @@ -1,6 +1,7 @@ package com.github.scribejava.apis; import com.github.scribejava.apis.service.OdnoklassnikiServiceImpl; +import com.github.scribejava.core.builder.api.ClientAuthenticationType; import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.builder.api.OAuth2SignatureType; import com.github.scribejava.core.model.OAuthConfig; @@ -38,4 +39,9 @@ public OAuth20Service createService(OAuthConfig config) { public OAuth2SignatureType getSignatureType() { return OAuth2SignatureType.BEARER_URI_QUERY_PARAMETER; } + + @Override + public ClientAuthenticationType getClientAuthenticationType() { + return ClientAuthenticationType.REQUEST_BODY; + } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/VkontakteApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/VkontakteApi.java index 285cb2cde..7472dba2e 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/VkontakteApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/VkontakteApi.java @@ -1,5 +1,6 @@ package com.github.scribejava.apis; +import com.github.scribejava.core.builder.api.ClientAuthenticationType; import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.builder.api.OAuth2SignatureType; import com.github.scribejava.core.model.Verb; @@ -36,4 +37,9 @@ protected String getAuthorizationBaseUrl() { public OAuth2SignatureType getSignatureType() { return OAuth2SignatureType.BEARER_URI_QUERY_PARAMETER; } + + @Override + public ClientAuthenticationType getClientAuthenticationType() { + return ClientAuthenticationType.REQUEST_BODY; + } } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/ClientAuthenticationType.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/ClientAuthenticationType.java new file mode 100644 index 000000000..7e2526b0e --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/ClientAuthenticationType.java @@ -0,0 +1,43 @@ +package com.github.scribejava.core.builder.api; + +import com.github.scribejava.core.model.OAuthConfig; +import com.github.scribejava.core.model.OAuthConstants; +import com.github.scribejava.core.model.OAuthRequest; +import java.nio.charset.Charset; +import java.util.Base64; + +/** + * Represents
+ * 2.3. Client Authentication
+ * https://tools.ietf.org/html/rfc6749#section-2.3
+ * in it's part 2.3.1. Client Password
+ * https://tools.ietf.org/html/rfc6749#section-2.3.1 + */ +public enum ClientAuthenticationType { + HTTP_BASIC_AUTHENTICATION_SCHEME { + private final Base64.Encoder base64Encoder = Base64.getEncoder(); + + @Override + public void addClientAuthentication(OAuthRequest request, OAuthConfig config) { + final String apiKey = config.getApiKey(); + final String apiSecret = config.getApiSecret(); + if (apiKey != null && apiSecret != null) { + request.addHeader(OAuthConstants.HEADER, OAuthConstants.BASIC + ' ' + + base64Encoder.encodeToString( + String.format("%s:%s", apiKey, apiSecret).getBytes(Charset.forName("UTF-8")))); + } + } + }, + REQUEST_BODY { + @Override + public void addClientAuthentication(OAuthRequest request, OAuthConfig config) { + request.addParameter(OAuthConstants.CLIENT_ID, config.getApiKey()); + final String apiSecret = config.getApiSecret(); + if (apiSecret != null) { + request.addParameter(OAuthConstants.CLIENT_SECRET, apiSecret); + } + } + }; + + public abstract void addClientAuthentication(OAuthRequest request, OAuthConfig config); +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java index 5a9e7ce44..90c65a162 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java @@ -94,4 +94,8 @@ public OAuth20Service createService(OAuthConfig config) { public OAuth2SignatureType getSignatureType() { return OAuth2SignatureType.BEARER_AUTHORIZATION_REQUEST_HEADER_FIELD; } + + public ClientAuthenticationType getClientAuthenticationType() { + return ClientAuthenticationType.HTTP_BASIC_AUTHENTICATION_SCHEME; + } } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java index 5caefdca9..be4804d54 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java @@ -1,7 +1,6 @@ package com.github.scribejava.core.oauth; import java.io.IOException; -import java.nio.charset.Charset; import java.util.concurrent.Future; import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.model.OAuth2AccessToken; @@ -13,7 +12,6 @@ import com.github.scribejava.core.pkce.AuthorizationUrlWithPKCE; import com.github.scribejava.core.pkce.PKCE; import com.github.scribejava.core.pkce.PKCEService; -import java.util.Base64; import java.util.HashMap; import java.util.Map; import java.util.concurrent.ExecutionException; @@ -21,7 +19,6 @@ public class OAuth20Service extends OAuthService { private static final String VERSION = "2.0"; - private static final Base64.Encoder BASE_64_ENCODER = Base64.getEncoder(); private static final PKCEService PKCE_SERVICE = new PKCEService(); private final DefaultApi20 api; @@ -99,11 +96,9 @@ public final Future getAccessToken(String code, protected OAuthRequest createAccessTokenRequest(String code) { final OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint()); final OAuthConfig config = getConfig(); - request.addParameter(OAuthConstants.CLIENT_ID, config.getApiKey()); - final String apiSecret = config.getApiSecret(); - if (apiSecret != null) { - request.addParameter(OAuthConstants.CLIENT_SECRET, apiSecret); - } + + api.getClientAuthenticationType().addClientAuthentication(request, config); + request.addParameter(OAuthConstants.CODE, code); request.addParameter(OAuthConstants.REDIRECT_URI, config.getCallback()); final String scope = config.getScope(); @@ -145,12 +140,9 @@ protected OAuthRequest createRefreshTokenRequest(String refreshToken) { throw new IllegalArgumentException("The refreshToken cannot be null or empty"); } final OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getRefreshTokenEndpoint()); - final OAuthConfig config = getConfig(); - request.addParameter(OAuthConstants.CLIENT_ID, config.getApiKey()); - final String apiSecret = config.getApiSecret(); - if (apiSecret != null) { - request.addParameter(OAuthConstants.CLIENT_SECRET, apiSecret); - } + + api.getClientAuthenticationType().addClientAuthentication(request, getConfig()); + request.addParameter(OAuthConstants.REFRESH_TOKEN, refreshToken); request.addParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.REFRESH_TOKEN); return request; @@ -195,13 +187,7 @@ protected OAuthRequest createAccessTokenPasswordGrantRequest(String username, St request.addParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.PASSWORD); - final String apiKey = config.getApiKey(); - final String apiSecret = config.getApiSecret(); - if (apiKey != null && apiSecret != null) { - request.addHeader(OAuthConstants.HEADER, OAuthConstants.BASIC + ' ' - + BASE_64_ENCODER.encodeToString( - String.format("%s:%s", apiKey, apiSecret).getBytes(Charset.forName("UTF-8")))); - } + api.getClientAuthenticationType().addClientAuthentication(request, config); return request; } From 68919e6331490da8a2fc6be1485d4c53ff4db894 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 3 Nov 2017 19:16:44 +0300 Subject: [PATCH 417/882] add support for client_credentials grant type (thanks to https://github.com/vivin) --- changelog | 1 + ...kontakteClientCredentialsGrantExample.java | 37 +++++++++++++++++++ .../scribejava/core/oauth/OAuth20Service.java | 8 ++-- 3 files changed, 41 insertions(+), 5 deletions(-) create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteClientCredentialsGrantExample.java diff --git a/changelog b/changelog index 403427346..7e381fea6 100644 --- a/changelog +++ b/changelog @@ -5,6 +5,7 @@ * add PKCE (RFC 7636) support (Proof Key for Code Exchange by OAuth Public Clients) (thanks for suggesting to https://github.com/dieseldjango) * switch to use HTTP Basic Authorization by default in requests with need of (2.3. Client Authentication) https://tools.ietf.org/html/rfc6749#section-2.3 Can be overrided in API class + * add support for client_credentials grant type (thanks to https://github.com/vivin) [4.2.0] * DELETE in JdkClient permits, but not requires payload (thanks to https://github.com/miguelD73) diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteClientCredentialsGrantExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteClientCredentialsGrantExample.java new file mode 100644 index 000000000..b91b115f3 --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteClientCredentialsGrantExample.java @@ -0,0 +1,37 @@ +package com.github.scribejava.apis.examples; + +import com.github.scribejava.core.builder.ServiceBuilder; +import com.github.scribejava.apis.VkontakteApi; +import com.github.scribejava.core.model.OAuth2AccessToken; +import com.github.scribejava.core.oauth.OAuth20Service; +import java.io.IOException; +import java.util.concurrent.ExecutionException; + +public final class VkontakteClientCredentialsGrantExample { + + private static final String NETWORK_NAME = "Vkontakte.ru"; + + private VkontakteClientCredentialsGrantExample() { + } + + public static void main(String... args) throws IOException, InterruptedException, ExecutionException { + // Replace these with your client id and secret + final String clientId = "your client id"; + final String clientSecret = "your client secret"; + final OAuth20Service service = new ServiceBuilder(clientId) + .apiSecret(clientSecret) + .scope("wall,offline") // replace with desired scope + .callback("http://your.site.com/callback") + .build(VkontakteApi.instance()); + + System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); + System.out.println(); + final OAuth2AccessToken accessToken = service.getAccessTokenClientCredentialsGrant(); + + System.out.println("Got the Access Token!"); + System.out.println(accessToken); + System.out.println(); + + System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); + } +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java index de76f3af5..a04eb8061 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java @@ -220,11 +220,9 @@ public final Future getAccessTokenClientCredentialsGrant( protected OAuthRequest createAccessTokenClientCredentialsGrantRequest() { final OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint()); final OAuthConfig config = getConfig(); - request.addParameter(OAuthConstants.CLIENT_ID, config.getApiKey()); - final String apiSecret = config.getApiSecret(); - if (apiSecret != null) { - request.addParameter(OAuthConstants.CLIENT_SECRET, apiSecret); - } + + api.getClientAuthenticationType().addClientAuthentication(request, config); + final String scope = config.getScope(); if (scope != null) { request.addParameter(OAuthConstants.SCOPE, scope); From f3cd5193346b60503c2103bf776d384be2dcfa43 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 14 Nov 2017 19:23:23 +0300 Subject: [PATCH 418/882] add support for RFC 7009 OAuth 2.0 Token Revocation (thanks to https://github.com/vivin) --- changelog | 1 + .../github/scribejava/apis/FacebookApi.java | 2 +- .../github/scribejava/apis/GoogleApi20.java | 5 + .../FacebookAccessTokenJsonExtractor.java | 2 +- .../apis/examples/Google20Example.java | 2 +- .../apis/examples/Google20RevokeExample.java | 104 ++++++++++++++++++ .../core/builder/api/DefaultApi20.java | 12 ++ .../OAuth2AccessTokenJsonExtractor.java | 7 +- .../model/OAuth2AccessTokenErrorResponse.java | 6 +- .../scribejava/core/oauth/OAuth20Service.java | 55 +++++++++ .../OAuth2RevokeTokenResponseConverter.java | 15 +++ .../src/main/java/revoke/TokenTypeHint.java | 12 ++ 12 files changed, 215 insertions(+), 8 deletions(-) create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20RevokeExample.java create mode 100644 scribejava-core/src/main/java/revoke/OAuth2RevokeTokenResponseConverter.java create mode 100644 scribejava-core/src/main/java/revoke/TokenTypeHint.java diff --git a/changelog b/changelog index 7e381fea6..c728e42dc 100644 --- a/changelog +++ b/changelog @@ -6,6 +6,7 @@ * switch to use HTTP Basic Authorization by default in requests with need of (2.3. Client Authentication) https://tools.ietf.org/html/rfc6749#section-2.3 Can be overrided in API class * add support for client_credentials grant type (thanks to https://github.com/vivin) + * add support for RFC 7009 OAuth 2.0 Token Revocation (thanks to https://github.com/vivin) [4.2.0] * DELETE in JdkClient permits, but not requires payload (thanks to https://github.com/miguelD73) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java index 41333f4f0..635a20e48 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java @@ -36,7 +36,7 @@ public String getAccessTokenEndpoint() { @Override public String getRefreshTokenEndpoint() { - throw new UnsupportedOperationException("Facebook doesn't support refershing tokens"); + throw new UnsupportedOperationException("Facebook doesn't support refreshing tokens"); } @Override diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/GoogleApi20.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/GoogleApi20.java index 1e4bd8c6f..b4ab24d39 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/GoogleApi20.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/GoogleApi20.java @@ -32,4 +32,9 @@ protected String getAuthorizationBaseUrl() { public TokenExtractor getAccessTokenExtractor() { return OpenIdJsonTokenExtractor.instance(); } + + @Override + public String getRevokeTokenEndpoint() { + return "https://accounts.google.com/o/oauth2/revoke"; + } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookAccessTokenJsonExtractor.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookAccessTokenJsonExtractor.java index 5f6d71d44..62326e099 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookAccessTokenJsonExtractor.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookAccessTokenJsonExtractor.java @@ -35,7 +35,7 @@ public static FacebookAccessTokenJsonExtractor instance() { * ID.","type":"OAuthException","code":101,"fbtrace_id":"CvDR+X4WWIx"}}' */ @Override - protected void generateError(String response) { + public void generateError(String response) { extractParameter(response, MESSAGE_REGEX_PATTERN, false); throw new FacebookAccessTokenErrorResponse(extractParameter(response, MESSAGE_REGEX_PATTERN, false), diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java index e9e2adf27..63507de18 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java @@ -14,7 +14,7 @@ import java.util.Map; import java.util.concurrent.ExecutionException; -public final class Google20Example { +public class Google20Example { private static final String NETWORK_NAME = "G+"; private static final String PROTECTED_RESOURCE_URL = "https://www.googleapis.com/plus/v1/people/me"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20RevokeExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20RevokeExample.java new file mode 100644 index 000000000..da2d7ea17 --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20RevokeExample.java @@ -0,0 +1,104 @@ +package com.github.scribejava.apis.examples; + +import java.util.Random; +import java.util.Scanner; +import com.github.scribejava.core.builder.ServiceBuilder; +import com.github.scribejava.apis.GoogleApi20; +import com.github.scribejava.core.model.OAuth2AccessToken; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.oauth.OAuth20Service; +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.ExecutionException; + +public class Google20RevokeExample { + + private static final String NETWORK_NAME = "G+"; + private static final String PROTECTED_RESOURCE_URL = "https://www.googleapis.com/plus/v1/people/me"; + + private Google20RevokeExample() { + } + + public static void main(String... args) throws IOException, InterruptedException, ExecutionException { + // Replace these with your client id and secret + final String clientId = "your client id"; + final String clientSecret = "your client secret"; + final String secretState = "secret" + new Random().nextInt(999_999); + final OAuth20Service service = new ServiceBuilder(clientId) + .apiSecret(clientSecret) + .scope("profile") // replace with desired scope + .state(secretState) + .callback("http://example.com/callback") + .build(GoogleApi20.instance()); + final Scanner in = new Scanner(System.in, "UTF-8"); + + System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); + System.out.println(); + + // Obtain the Authorization URL + System.out.println("Fetching the Authorization URL..."); + //pass access_type=offline to get refresh token + //https://developers.google.com/identity/protocols/OAuth2WebServer#preparing-to-start-the-oauth-20-flow + final Map additionalParams = new HashMap<>(); + additionalParams.put("access_type", "offline"); + //force to reget refresh token (if usera are asked not the first time) + additionalParams.put("prompt", "consent"); + final String authorizationUrl = service.getAuthorizationUrl(additionalParams); + System.out.println("Got the Authorization URL!"); + System.out.println("Now go and authorize ScribeJava here:"); + System.out.println(authorizationUrl); + System.out.println("And paste the authorization code here"); + System.out.print(">>"); + final String code = in.nextLine(); + System.out.println(); + + System.out.println("And paste the state from server here. We have set 'secretState'='" + secretState + "'."); + System.out.print(">>"); + final String value = in.nextLine(); + if (secretState.equals(value)) { + System.out.println("State value does match!"); + } else { + System.out.println("Ooops, state value does not match!"); + System.out.println("Expected = " + secretState); + System.out.println("Got = " + value); + System.out.println(); + } + + // Trade the Request Token and Verfier for the Access Token + System.out.println("Trading the Request Token for an Access Token..."); + final OAuth2AccessToken accessToken = service.getAccessToken(code); + System.out.println("Got the Access Token!"); + System.out.println("(if your curious it looks like this: " + accessToken + + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + + // Now let's go and ask for a protected resource! + System.out.println("Now we're going to access a protected resource..."); + OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); + service.signRequest(accessToken, request); + Response response = service.execute(request); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + System.out.println(); + + System.out.println("Revoking token..."); + service.revokeToken(accessToken.getAccessToken()); + System.out.println("done."); + System.out.println("After revoke we should fail requesting any data..."); + //Google Note: Following a successful revocation response, + //it might take some time before the revocation has full effect. + while (response.getCode() == 200) { + Thread.sleep(1000); + request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); + service.signRequest(accessToken, request); + response = service.execute(request); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + System.out.println(); + } + } +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java index 90c65a162..e0caa4637 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java @@ -54,6 +54,18 @@ public String getRefreshTokenEndpoint() { return getAccessTokenEndpoint(); } + /** + * As stated in RFC 7009 OAuth 2.0 Token Revocation + * + * @return endpoint, which allows clients to notify the authorization server that a previously obtained refresh or + * access token is no longer needed. + * @see RFC 7009 + */ + public String getRevokeTokenEndpoint() { + throw new UnsupportedOperationException( + "This API doesn't support revoking tokens or we have no info about this"); + } + protected abstract String getAuthorizationBaseUrl(); /** diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractor.java b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractor.java index 0c24755b3..49c6ec7d8 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractor.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractor.java @@ -40,11 +40,10 @@ public static OAuth2AccessTokenJsonExtractor instance() { @Override public OAuth2AccessToken extract(Response response) throws IOException { final String body = response.getBody(); - Preconditions.checkEmptyString(body, - "Response body is incorrect. Can't extract a token from an empty string"); + Preconditions.checkEmptyString(body, "Response body is incorrect. Can't extract a token from an empty string"); if (response.getCode() != 200) { - generateError(response.getBody()); + generateError(body); } return createToken(body); } @@ -54,7 +53,7 @@ public OAuth2AccessToken extract(Response response) throws IOException { * * @param response response */ - protected void generateError(String response) { + public void generateError(String response) { final String errorInString = extractParameter(response, ERROR_REGEX_PATTERN, true); final String errorDescription = extractParameter(response, ERROR_DESCRIPTION_REGEX_PATTERN, false); final String errorUriInString = extractParameter(response, ERROR_URI_REGEX_PATTERN, false); diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth2AccessTokenErrorResponse.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth2AccessTokenErrorResponse.java index eba31404e..6476799e0 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth2AccessTokenErrorResponse.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth2AccessTokenErrorResponse.java @@ -12,7 +12,11 @@ public class OAuth2AccessTokenErrorResponse extends OAuthException { private static final long serialVersionUID = 2309424849700276816L; public enum ErrorCode { - invalid_request, invalid_client, invalid_grant, unauthorized_client, unsupported_grant_type, invalid_scope + invalid_request, invalid_client, invalid_grant, unauthorized_client, unsupported_grant_type, invalid_scope, + /** + * @see RFC 7009, 2.2.1. Error Response + */ + unsupported_token_type } private final ErrorCode errorCode; diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java index a04eb8061..2c80b4bc5 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java @@ -3,18 +3,22 @@ import java.io.IOException; import java.util.concurrent.Future; import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuth2Authorization; import com.github.scribejava.core.model.OAuthAsyncRequestCallback; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.pkce.AuthorizationUrlWithPKCE; import com.github.scribejava.core.pkce.PKCE; import com.github.scribejava.core.pkce.PKCEService; import java.util.HashMap; import java.util.Map; import java.util.concurrent.ExecutionException; +import revoke.TokenTypeHint; public class OAuth20Service extends OAuthService { @@ -291,6 +295,57 @@ public DefaultApi20 getApi() { return api; } + protected OAuthRequest createRevokeTokenRequest(String tokenToRevoke, TokenTypeHint tokenTypeHint) { + final OAuthRequest request = new OAuthRequest(Verb.POST, api.getRevokeTokenEndpoint()); + + api.getClientAuthenticationType().addClientAuthentication(request, getConfig()); + + request.addParameter("token", tokenToRevoke); + if (tokenTypeHint != null) { + request.addParameter("token_type_hint", tokenTypeHint.toString()); + } + return request; + } + + public final Future revokeTokenAsync(String tokenToRevoke) { + return revokeTokenAsync(tokenToRevoke, null); + } + + public final Future revokeTokenAsync(String tokenToRevoke, TokenTypeHint tokenTypeHint) { + return revokeToken(tokenToRevoke, null, tokenTypeHint); + } + + public final void revokeToken(String tokenToRevoke) throws IOException, InterruptedException, ExecutionException { + revokeToken(tokenToRevoke, (TokenTypeHint) null); + } + + public final void revokeToken(String tokenToRevoke, TokenTypeHint tokenTypeHint) + throws IOException, InterruptedException, ExecutionException { + final OAuthRequest request = createRevokeTokenRequest(tokenToRevoke, tokenTypeHint); + + checkForErrorRevokeToken(execute(request)); + } + + public final Future revokeToken(String tokenToRevoke, OAuthAsyncRequestCallback callback) { + return revokeToken(tokenToRevoke, callback, null); + } + + public final Future revokeToken(String tokenToRevoke, OAuthAsyncRequestCallback callback, + TokenTypeHint tokenTypeHint) { + final OAuthRequest request = createRevokeTokenRequest(tokenToRevoke, tokenTypeHint); + + return execute(request, callback, response -> { + checkForErrorRevokeToken(response); + return null; + }); + } + + private void checkForErrorRevokeToken(Response response) throws IOException { + if (response.getCode() != 200) { + OAuth2AccessTokenJsonExtractor.instance().generateError(response.getBody()); + } + } + public OAuth2Authorization extractAuthorization(String redirectLocation) { final OAuth2Authorization authorization = new OAuth2Authorization(); int end = redirectLocation.indexOf('#'); diff --git a/scribejava-core/src/main/java/revoke/OAuth2RevokeTokenResponseConverter.java b/scribejava-core/src/main/java/revoke/OAuth2RevokeTokenResponseConverter.java new file mode 100644 index 000000000..a6c69609e --- /dev/null +++ b/scribejava-core/src/main/java/revoke/OAuth2RevokeTokenResponseConverter.java @@ -0,0 +1,15 @@ +package revoke; + +import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; +import com.github.scribejava.core.model.Response; +import java.io.IOException; + +public class OAuth2RevokeTokenResponseConverter { + + public Void convert(Response response) throws IOException { + if (response.getCode() != 200) { + OAuth2AccessTokenJsonExtractor.instance().generateError(response.getBody()); + } + return null; + } +} diff --git a/scribejava-core/src/main/java/revoke/TokenTypeHint.java b/scribejava-core/src/main/java/revoke/TokenTypeHint.java new file mode 100644 index 000000000..6855ee8b0 --- /dev/null +++ b/scribejava-core/src/main/java/revoke/TokenTypeHint.java @@ -0,0 +1,12 @@ +package revoke; + +/** + * + * as stated in RFC 7009
+ * 2.1. Revocation Request + * + * @see RFC 7009, 2.1. Revocation Request + */ +public enum TokenTypeHint { + access_token, refresh_token +} From 8d18844ca6a5720dcf435ff2bad032f12a400eff Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 14 Nov 2017 19:49:10 +0300 Subject: [PATCH 419/882] add OAuth2Service signRequest method accepting just String, not OAuth2 Access Token Object. Remove signRequest from abstract OAuthService. 2.0 and 1.0a will be a bit more different now. --- changelog | 2 ++ .../apis/service/ImgurOAuthServiceImpl.java | 6 ++---- .../apis/service/MailruOAuthServiceImpl.java | 5 ++--- .../service/OdnoklassnikiServiceImpl.java | 5 ++--- .../apis/service/TutByOAuthServiceImpl.java | 5 ++--- .../core/builder/ServiceBuilder.java | 2 +- .../scribejava/core/builder/api/BaseApi.java | 2 +- .../core/builder/api/OAuth2SignatureType.java | 21 ++++++++++++++----- .../core/oauth/OAuth10aService.java | 3 +-- .../scribejava/core/oauth/OAuth20Service.java | 9 +++++--- .../scribejava/core/oauth/OAuthService.java | 11 +--------- .../okhttp/OkHttpHttpClientTest.java | 2 +- 12 files changed, 37 insertions(+), 36 deletions(-) diff --git a/changelog b/changelog index c728e42dc..3b0e94297 100644 --- a/changelog +++ b/changelog @@ -7,6 +7,8 @@ (2.3. Client Authentication) https://tools.ietf.org/html/rfc6749#section-2.3 Can be overrided in API class * add support for client_credentials grant type (thanks to https://github.com/vivin) * add support for RFC 7009 OAuth 2.0 Token Revocation (thanks to https://github.com/vivin) + * add OAuth2Service signRequest method accepting just String, not OAuth2 Access Token Object. + Remove signRequest from abstract OAuthService. 2.0 and 1.0a will be a bit more different now. [4.2.0] * DELETE in JdkClient permits, but not requires payload (thanks to https://github.com/miguelD73) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthServiceImpl.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthServiceImpl.java index c0f74aab6..c77de1b70 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthServiceImpl.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthServiceImpl.java @@ -2,7 +2,6 @@ import com.github.scribejava.apis.ImgurApi; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.OAuthRequest; @@ -33,9 +32,8 @@ protected OAuthRequest createAccessTokenRequest(String oauthVerifier) { } @Override - public void signRequest(OAuth2AccessToken accessToken, OAuthRequest request) { + public void signRequest(String accessToken, OAuthRequest request) { request.addHeader("Authorization", - accessToken == null - ? "Client-ID " + getConfig().getApiKey() : "Bearer " + accessToken.getAccessToken()); + accessToken == null ? "Client-ID " + getConfig().getApiKey() : "Bearer " + accessToken); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthServiceImpl.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthServiceImpl.java index 86bcb79ab..2b6e3cc3e 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthServiceImpl.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthServiceImpl.java @@ -7,7 +7,6 @@ import org.apache.commons.codec.CharEncoding; import static org.apache.commons.codec.digest.DigestUtils.md5Hex; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.oauth.OAuth20Service; @@ -20,9 +19,9 @@ public MailruOAuthServiceImpl(DefaultApi20 api, OAuthConfig config) { } @Override - public void signRequest(OAuth2AccessToken accessToken, OAuthRequest request) { + public void signRequest(String accessToken, OAuthRequest request) { // sig = md5(params + secret_key) - request.addQuerystringParameter("session_key", accessToken.getAccessToken()); + request.addQuerystringParameter("session_key", accessToken); request.addQuerystringParameter("app_id", getConfig().getApiKey()); final String completeUrl = request.getCompleteUrl(); diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiServiceImpl.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiServiceImpl.java index 7e9017978..6d3850cc2 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiServiceImpl.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiServiceImpl.java @@ -1,7 +1,6 @@ package com.github.scribejava.apis.service; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Parameter; @@ -25,10 +24,10 @@ public OdnoklassnikiServiceImpl(DefaultApi20 api, OAuthConfig config) { } @Override - public void signRequest(OAuth2AccessToken accessToken, OAuthRequest request) { + public void signRequest(String accessToken, OAuthRequest request) { //sig = lower(md5( sorted_request_params_composed_string + md5(access_token + application_secret_key))) try { - final String tokenDigest = md5Hex(accessToken.getAccessToken() + getConfig().getApiSecret()); + final String tokenDigest = md5Hex(accessToken + getConfig().getApiSecret()); final ParameterList queryParams = request.getQueryStringParams(); queryParams.addAll(request.getBodyParams()); diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/TutByOAuthServiceImpl.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/TutByOAuthServiceImpl.java index f1f14485f..b199ac66a 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/TutByOAuthServiceImpl.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/TutByOAuthServiceImpl.java @@ -1,7 +1,6 @@ package com.github.scribejava.apis.service; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.OAuthRequest; @@ -14,7 +13,7 @@ public TutByOAuthServiceImpl(DefaultApi20 api, OAuthConfig config) { } @Override - public void signRequest(OAuth2AccessToken accessToken, OAuthRequest request) { - request.addQuerystringParameter(OAuthConstants.TOKEN, accessToken.getAccessToken()); + public void signRequest(String accessToken, OAuthRequest request) { + request.addQuerystringParameter(OAuthConstants.TOKEN, accessToken); } } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilder.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilder.java index a3ff17365..c003e7d18 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilder.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilder.java @@ -137,7 +137,7 @@ public ServiceBuilder debug() { * @param api will build Service for this API * @return fully configured {@link S} */ - public > S build(BaseApi api) { + public S build(BaseApi api) { return api.createService(new OAuthConfig(apiKey, apiSecret, callback, scope, debugStream, state, responseType, userAgent, httpClientConfig, httpClient)); } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/BaseApi.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/BaseApi.java index 7f6fbdd4f..a42fe35fa 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/BaseApi.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/BaseApi.java @@ -3,7 +3,7 @@ import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.oauth.OAuthService; -public interface BaseApi> { +public interface BaseApi { T createService(OAuthConfig config); } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/OAuth2SignatureType.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/OAuth2SignatureType.java index a6825a757..b2334be32 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/OAuth2SignatureType.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/OAuth2SignatureType.java @@ -10,8 +10,8 @@ public enum OAuth2SignatureType { */ BEARER_AUTHORIZATION_REQUEST_HEADER_FIELD { @Override - public void signRequest(OAuth2AccessToken accessToken, OAuthRequest request) { - request.addHeader("Authorization", "Bearer " + accessToken.getAccessToken()); + public void signRequest(String accessToken, OAuthRequest request) { + request.addHeader("Authorization", "Bearer " + accessToken); } }, @@ -20,11 +20,22 @@ public void signRequest(OAuth2AccessToken accessToken, OAuthRequest request) { */ BEARER_URI_QUERY_PARAMETER { @Override - public void signRequest(OAuth2AccessToken accessToken, OAuthRequest request) { - request.addQuerystringParameter(OAuthConstants.ACCESS_TOKEN, accessToken.getAccessToken()); + public void signRequest(String accessToken, OAuthRequest request) { + request.addQuerystringParameter(OAuthConstants.ACCESS_TOKEN, accessToken); } }; - public abstract void signRequest(OAuth2AccessToken accessToken, OAuthRequest request); + /** + * + * @param accessToken accessToken + * @param request request + * @deprecated use {@link #signRequest(java.lang.String, com.github.scribejava.core.model.OAuthRequest)} + */ + @Deprecated + public void signRequest(OAuth2AccessToken accessToken, OAuthRequest request) { + signRequest(accessToken == null ? null : accessToken.getAccessToken(), request); + } + + public abstract void signRequest(String accessToken, OAuthRequest request); } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java index 1023def56..a006c70b2 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java @@ -16,7 +16,7 @@ /** * OAuth 1.0a implementation of {@link OAuthService} */ -public class OAuth10aService extends OAuthService { +public class OAuth10aService extends OAuthService { private static final String VERSION = "1.0"; private final DefaultApi10a api; @@ -124,7 +124,6 @@ protected OAuthRequest prepareAccessTokenRequest(OAuth1RequestToken requestToken return request; } - @Override public void signRequest(OAuth1AccessToken token, OAuthRequest request) { final OAuthConfig config = getConfig(); config.log("signing request: " + request.getCompleteUrl()); diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java index 2c80b4bc5..b20f421b7 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java @@ -20,7 +20,7 @@ import java.util.concurrent.ExecutionException; import revoke.TokenTypeHint; -public class OAuth20Service extends OAuthService { +public class OAuth20Service extends OAuthService { private static final String VERSION = "2.0"; private static final PKCEService PKCE_SERVICE = new PKCEService(); @@ -243,11 +243,14 @@ public String getVersion() { return VERSION; } - @Override - public void signRequest(OAuth2AccessToken accessToken, OAuthRequest request) { + public void signRequest(String accessToken, OAuthRequest request) { api.getSignatureType().signRequest(accessToken, request); } + public final void signRequest(OAuth2AccessToken accessToken, OAuthRequest request) { + signRequest(accessToken == null ? null : accessToken.getAccessToken(), request); + } + public final AuthorizationUrlWithPKCE getAuthorizationUrlWithPKCE() { return getAuthorizationUrlWithPKCE(null); } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java index df58ce3ea..cf2ca6252 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java @@ -9,7 +9,6 @@ import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; -import com.github.scribejava.core.model.Token; import java.io.File; import java.io.IOException; @@ -17,13 +16,7 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; -/** - * The main ScribeJava object. - * - * A facade responsible for the retrieval of request and access tokens and for the signing of HTTP requests. - * @param type of token used to sign the request - */ -public abstract class OAuthService implements AutoCloseable { +public abstract class OAuthService implements AutoCloseable { private final OAuthConfig config; private final HttpClient httpClient; @@ -66,8 +59,6 @@ public OAuthConfig getConfig() { */ public abstract String getVersion(); - public abstract void signRequest(T token, OAuthRequest request); - public Future executeAsync(OAuthRequest request) { return execute(request, null); } diff --git a/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClientTest.java b/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClientTest.java index 496882cdd..469b6882a 100644 --- a/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClientTest.java +++ b/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClientTest.java @@ -21,7 +21,7 @@ import static org.junit.Assert.assertEquals; public class OkHttpHttpClientTest { - private OAuthService oAuthService; + private OAuthService oAuthService; @Before public void setUp() { From 76f626edd74f74c9ab4c5c32c2c504d963006cd7 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 15 Nov 2017 10:39:28 +0300 Subject: [PATCH 420/882] fix typo in package name --- .../java/com/github/scribejava/core/oauth/OAuth20Service.java | 2 +- .../core}/revoke/OAuth2RevokeTokenResponseConverter.java | 2 +- .../{ => com/github/scribejava/core}/revoke/TokenTypeHint.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) rename scribejava-core/src/main/java/{ => com/github/scribejava/core}/revoke/OAuth2RevokeTokenResponseConverter.java (91%) rename scribejava-core/src/main/java/{ => com/github/scribejava/core}/revoke/TokenTypeHint.java (84%) diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java index b20f421b7..9b9b22e41 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java @@ -18,7 +18,7 @@ import java.util.HashMap; import java.util.Map; import java.util.concurrent.ExecutionException; -import revoke.TokenTypeHint; +import com.github.scribejava.core.revoke.TokenTypeHint; public class OAuth20Service extends OAuthService { diff --git a/scribejava-core/src/main/java/revoke/OAuth2RevokeTokenResponseConverter.java b/scribejava-core/src/main/java/com/github/scribejava/core/revoke/OAuth2RevokeTokenResponseConverter.java similarity index 91% rename from scribejava-core/src/main/java/revoke/OAuth2RevokeTokenResponseConverter.java rename to scribejava-core/src/main/java/com/github/scribejava/core/revoke/OAuth2RevokeTokenResponseConverter.java index a6c69609e..b287d7868 100644 --- a/scribejava-core/src/main/java/revoke/OAuth2RevokeTokenResponseConverter.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/revoke/OAuth2RevokeTokenResponseConverter.java @@ -1,4 +1,4 @@ -package revoke; +package com.github.scribejava.core.revoke; import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; import com.github.scribejava.core.model.Response; diff --git a/scribejava-core/src/main/java/revoke/TokenTypeHint.java b/scribejava-core/src/main/java/com/github/scribejava/core/revoke/TokenTypeHint.java similarity index 84% rename from scribejava-core/src/main/java/revoke/TokenTypeHint.java rename to scribejava-core/src/main/java/com/github/scribejava/core/revoke/TokenTypeHint.java index 6855ee8b0..55a95057e 100644 --- a/scribejava-core/src/main/java/revoke/TokenTypeHint.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/revoke/TokenTypeHint.java @@ -1,4 +1,4 @@ -package revoke; +package com.github.scribejava.core.revoke; /** * From 73c29f539804fbed6e7e2587a87f97898439eeca Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 15 Nov 2017 10:55:51 +0300 Subject: [PATCH 421/882] drop toString method from *Tokens to prevent leak of sensible data (token ans secrets) (thanks to https://github.com/rcaa) --- changelog | 1 + .../apis/openid/OpenIdOAuth2AccessToken.java | 11 ----------- .../scribejava/apis/salesforce/SalesforceToken.java | 11 ----------- .../scribejava/apis/examples/AWeberExample.java | 3 +-- .../github/scribejava/apis/examples/Box20Example.java | 3 +-- .../github/scribejava/apis/examples/DiggExample.java | 3 +-- .../github/scribejava/apis/examples/EtsyExample.java | 3 +-- .../apis/examples/FacebookAsyncNingExample.java | 4 ++-- .../scribejava/apis/examples/FacebookExample.java | 3 +-- .../scribejava/apis/examples/FlickrExample.java | 3 +-- .../scribejava/apis/examples/Foursquare2Example.java | 3 +-- .../scribejava/apis/examples/FoursquareExample.java | 3 +-- .../scribejava/apis/examples/FrappeExample.java | 4 +--- .../scribejava/apis/examples/FreelancerExample.java | 5 ++--- .../apis/examples/GitHubAsyncOkHttpExample.java | 4 ++-- .../scribejava/apis/examples/GitHubExample.java | 3 +-- .../apis/examples/Google20AsyncAHCExample.java | 8 ++++---- .../scribejava/apis/examples/Google20Example.java | 6 ++---- .../apis/examples/Google20RevokeExample.java | 3 +-- .../apis/examples/Google20WithPKCEExample.java | 6 ++---- .../github/scribejava/apis/examples/HHExample.java | 3 +-- .../github/scribejava/apis/examples/ImgurExample.java | 3 +-- .../scribejava/apis/examples/Kaixin20Example.java | 3 +-- .../scribejava/apis/examples/LinkedIn20Example.java | 3 +-- .../scribejava/apis/examples/LinkedInExample.java | 3 +-- .../apis/examples/LinkedInExampleWithScopes.java | 3 +-- .../github/scribejava/apis/examples/LiveExample.java | 3 +-- .../scribejava/apis/examples/MailruAsyncExample.java | 4 ++-- .../scribejava/apis/examples/MailruExample.java | 3 +-- .../scribejava/apis/examples/MeetupExample.java | 3 +-- .../scribejava/apis/examples/MisfitExample.java | 3 +-- .../github/scribejava/apis/examples/NaverExample.java | 3 +-- .../scribejava/apis/examples/NeteaseWeiboExample.java | 3 +-- .../apis/examples/OdnoklassnikiExample.java | 6 ++---- .../scribejava/apis/examples/PinterestExample.java | 3 +-- .../github/scribejava/apis/examples/Px500Example.java | 3 +-- .../scribejava/apis/examples/RenrenExample.java | 3 +-- .../scribejava/apis/examples/SalesforceExample.java | 3 +-- .../apis/examples/SalesforceNingAsyncExample.java | 4 ++-- .../scribejava/apis/examples/SinaWeibo2Example.java | 3 +-- .../scribejava/apis/examples/SinaWeiboExample.java | 3 +-- .../scribejava/apis/examples/SkyrockExample.java | 3 +-- .../scribejava/apis/examples/SohuWeiboExample.java | 3 +-- .../apis/examples/StackExchangeExample.java | 3 +-- .../examples/TheThingsNetworkV1StagingExample.java | 3 +-- .../examples/TheThingsNetworkV2PreviewExample.java | 3 +-- .../scribejava/apis/examples/TrelloExample.java | 3 +-- .../scribejava/apis/examples/TumblrExample.java | 3 +-- .../github/scribejava/apis/examples/TutByExample.java | 3 +-- .../scribejava/apis/examples/TwitterExample.java | 3 +-- .../github/scribejava/apis/examples/UcozExample.java | 3 +-- .../scribejava/apis/examples/ViadeoExample.java | 3 +-- .../scribejava/apis/examples/VkontakteExample.java | 3 +-- .../apis/examples/VkontakteExternalHttpExample.java | 4 ++-- .../github/scribejava/apis/examples/XingExample.java | 3 +-- .../github/scribejava/apis/examples/YahooExample.java | 3 +-- .../scribejava/core/model/OAuth1AccessToken.java | 7 ------- .../scribejava/core/model/OAuth1RequestToken.java | 8 -------- .../scribejava/core/model/OAuth2AccessToken.java | 10 ---------- 59 files changed, 66 insertions(+), 163 deletions(-) diff --git a/changelog b/changelog index 3b0e94297..fda68b66e 100644 --- a/changelog +++ b/changelog @@ -9,6 +9,7 @@ * add support for RFC 7009 OAuth 2.0 Token Revocation (thanks to https://github.com/vivin) * add OAuth2Service signRequest method accepting just String, not OAuth2 Access Token Object. Remove signRequest from abstract OAuthService. 2.0 and 1.0a will be a bit more different now. + * drop toString method from *Tokens to prevent leak of sensible data (token ans secrets) (thanks to https://github.com/rcaa) [4.2.0] * DELETE in JdkClient permits, but not requires payload (thanks to https://github.com/miguelD73) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/openid/OpenIdOAuth2AccessToken.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/openid/OpenIdOAuth2AccessToken.java index 94550ef79..7e6588444 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/openid/OpenIdOAuth2AccessToken.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/openid/OpenIdOAuth2AccessToken.java @@ -56,15 +56,4 @@ public boolean equals(Object obj) { return Objects.equals(openIdToken, ((OpenIdOAuth2AccessToken) obj).getOpenIdToken()); } - - @Override - public String toString() { - return "OpenIdOAuth2AccessToken{" - + "access_token=" + getAccessToken() - + ", token_type=" + getTokenType() - + ", expires_in=" + getExpiresIn() - + ", refresh_token=" + getRefreshToken() - + ", scope=" + getScope() - + ", open_id_token=" + openIdToken + '}'; - } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/salesforce/SalesforceToken.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/salesforce/SalesforceToken.java index 14a0911cd..242cb7e31 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/salesforce/SalesforceToken.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/salesforce/SalesforceToken.java @@ -51,15 +51,4 @@ public boolean equals(Object obj) { } return Objects.equals(instanceUrl, ((SalesforceToken) obj).getInstanceUrl()); } - - @Override - public String toString() { - return "SalesforceToken{" - + "access_token=" + getAccessToken() - + ", token_type=" + getTokenType() - + ", expires_in=" + getExpiresIn() - + ", refresh_token=" + getRefreshToken() - + ", scope=" + getScope() - + ", instance_url=" + instanceUrl + '}'; - } } diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AWeberExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AWeberExample.java index d304dc6d4..f79dfa4ef 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AWeberExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AWeberExample.java @@ -50,8 +50,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Box20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Box20Example.java index de8a1c1ed..eaf26af17 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Box20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Box20Example.java @@ -69,8 +69,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); - System.out.println("(If you're curious, it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiggExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiggExample.java index aafbea10c..3985a7b83 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiggExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiggExample.java @@ -53,8 +53,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/EtsyExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/EtsyExample.java index 115617f71..a3bc12d40 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/EtsyExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/EtsyExample.java @@ -47,8 +47,7 @@ public static void main(String[] args) throws InterruptedException, ExecutionExc System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java index ae8879790..73062a43c 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java @@ -74,8 +74,8 @@ public static void main(String... args) throws InterruptedException, ExecutionEx System.out.println("Trading the Request Token for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessTokenAsync(code).get(); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java index 521020e29..c4c54897d 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java @@ -63,8 +63,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExample.java index e5809874f..81d47b10c 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExample.java @@ -51,8 +51,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java index 33e6206ef..0dd9d1a31 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java @@ -47,8 +47,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FoursquareExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FoursquareExample.java index afaaca188..9a30e6c10 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FoursquareExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FoursquareExample.java @@ -45,8 +45,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FrappeExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FrappeExample.java index fe704ed7a..16fe60528 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FrappeExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FrappeExample.java @@ -49,9 +49,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); - System.out.println("(If you're curious, it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); - + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java index a17f896de..696860bce 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java @@ -37,7 +37,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Fetching the Request Token..."); final OAuth1RequestToken requestToken = service.getRequestToken(); System.out.println("Got the Request Token!"); - System.out.println("(if your curious it looks like this: " + requestToken + " )"); + System.out.println("(if your curious the raw answer looks like this: " + requestToken.getRawResponse() + "')"); System.out.println(); System.out.println("Now go and authorize ScribeJava here:"); @@ -51,8 +51,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubAsyncOkHttpExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubAsyncOkHttpExample.java index 596a14a45..06e81e5dd 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubAsyncOkHttpExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubAsyncOkHttpExample.java @@ -66,8 +66,8 @@ public static void main(String... args) throws IOException, ExecutionException, System.out.println("Trading the Request Token for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubExample.java index 8c3444d92..392a0c494 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubExample.java @@ -62,8 +62,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java index 7ac82e7e9..c5e9dc5d0 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java @@ -83,14 +83,14 @@ public static void main(String... args) throws InterruptedException, ExecutionEx System.out.println("Trading the Request Token for an Access Token..."); OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + + "')"); System.out.println("Refreshing the Access Token..."); accessToken = service.refreshAccessToken(accessToken.getRefreshToken()); System.out.println("Refreshed the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java index 63507de18..02c8ff680 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java @@ -71,14 +71,12 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); System.out.println("Refreshing the Access Token..."); accessToken = service.refreshAccessToken(accessToken.getRefreshToken()); System.out.println("Refreshed the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20RevokeExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20RevokeExample.java index da2d7ea17..7e677731c 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20RevokeExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20RevokeExample.java @@ -71,8 +71,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); // Now let's go and ask for a protected resource! System.out.println("Now we're going to access a protected resource..."); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20WithPKCEExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20WithPKCEExample.java index 91a108cb1..5a5668147 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20WithPKCEExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20WithPKCEExample.java @@ -75,14 +75,12 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); OAuth2AccessToken accessToken = service.getAccessToken(code, authUrlWithPKCE.getPkce().getCodeVerifier()); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); System.out.println("Refreshing the Access Token..."); accessToken = service.refreshAccessToken(accessToken.getRefreshToken()); System.out.println("Refreshed the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HHExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HHExample.java index e892eace3..d273974d6 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HHExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HHExample.java @@ -49,8 +49,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); System.out.println("Now we're going to access a protected resource..."); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ImgurExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ImgurExample.java index 35f6d9a31..104b4cb61 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ImgurExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ImgurExample.java @@ -47,8 +47,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Kaixin20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Kaixin20Example.java index 6d61a613b..43d5fe583 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Kaixin20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Kaixin20Example.java @@ -47,8 +47,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedIn20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedIn20Example.java index 8553c3498..69a65ebc7 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedIn20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedIn20Example.java @@ -49,8 +49,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java index 02ae520c1..4d1c998fe 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java @@ -46,8 +46,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java index a8247f65c..f09d322d5 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java @@ -50,8 +50,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java index 09fabe03a..b6231a744 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java @@ -47,8 +47,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java index 2c566e99b..181ab1b82 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java @@ -60,8 +60,8 @@ public static void main(String... args) throws InterruptedException, ExecutionEx System.out.println("Trading the Request Token for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + + "')"); System.out.println(); System.out.println("Now we're going to access a protected resource..."); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java index f6c620d0f..8a02df6fd 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java @@ -49,8 +49,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); System.out.println("Now we're going to access a protected resource..."); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java index c8d6ea911..50d3a894b 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java @@ -45,8 +45,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MisfitExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MisfitExample.java index ed6c1dd7f..4c8cbddf1 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MisfitExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MisfitExample.java @@ -50,8 +50,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NaverExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NaverExample.java index 5d2d5548e..21ff0fa92 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NaverExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NaverExample.java @@ -64,8 +64,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NeteaseWeiboExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NeteaseWeiboExample.java index 866c2167b..63a7891c9 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NeteaseWeiboExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NeteaseWeiboExample.java @@ -53,8 +53,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java index 8ea048fe8..4ecd3779c 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java @@ -52,15 +52,13 @@ public static void main(String... args) throws IOException, InterruptedException OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); System.out.println("Refreshing the Access Token..."); accessToken = service.refreshAccessToken(accessToken.getRefreshToken()); System.out.println("Refreshed the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java index 1fec439b4..def416167 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java @@ -48,8 +48,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Px500Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Px500Example.java index 820a0e821..fbbad7874 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Px500Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Px500Example.java @@ -45,8 +45,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java index eaeb35532..621566f6e 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java @@ -56,8 +56,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceExample.java index 30f4aab85..d9c9ff819 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceExample.java @@ -76,8 +76,7 @@ public static void main(String... args) throws IOException, NoSuchAlgorithmExcep } System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + salesforceAccessToken + ", 'rawResponse'='" - + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); System.out.println("instance_url is: " + salesforceAccessToken.getInstanceUrl()); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceNingAsyncExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceNingAsyncExample.java index d057df0d9..9a55bd575 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceNingAsyncExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceNingAsyncExample.java @@ -77,8 +77,8 @@ public static void main(String... args) throws InterruptedException, ExecutionEx } System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + salesforceAccessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + + "')"); System.out.println(); System.out.println("Instance is: " + salesforceAccessToken.getInstanceUrl()); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeibo2Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeibo2Example.java index a2bacaff4..e314a82d7 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeibo2Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeibo2Example.java @@ -47,8 +47,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeiboExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeiboExample.java index 289f4eb50..324e02201 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeiboExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeiboExample.java @@ -53,8 +53,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SkyrockExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SkyrockExample.java index fcb2f592a..578ef88a3 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SkyrockExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SkyrockExample.java @@ -45,8 +45,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SohuWeiboExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SohuWeiboExample.java index 0cb93b91a..53d20aa9f 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SohuWeiboExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SohuWeiboExample.java @@ -53,8 +53,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/StackExchangeExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/StackExchangeExample.java index 04858eab6..e9af948d9 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/StackExchangeExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/StackExchangeExample.java @@ -67,8 +67,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV1StagingExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV1StagingExample.java index 057f9b27c..7264194a3 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV1StagingExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV1StagingExample.java @@ -69,8 +69,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV2PreviewExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV2PreviewExample.java index acb791c1c..943a2529a 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV2PreviewExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV2PreviewExample.java @@ -66,8 +66,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TrelloExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TrelloExample.java index dea9fc659..309d4a9b3 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TrelloExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TrelloExample.java @@ -47,8 +47,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TumblrExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TumblrExample.java index ec21d3bfb..1e6bdac15 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TumblrExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TumblrExample.java @@ -47,8 +47,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TutByExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TutByExample.java index daa5f0122..ef3f1c924 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TutByExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TutByExample.java @@ -48,8 +48,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TwitterExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TwitterExample.java index 620eb7820..235c0c2e6 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TwitterExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TwitterExample.java @@ -45,8 +45,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/UcozExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/UcozExample.java index 04dfaacf4..34a7a4b98 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/UcozExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/UcozExample.java @@ -40,8 +40,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ViadeoExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ViadeoExample.java index 09dcde65a..9605b1c49 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ViadeoExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ViadeoExample.java @@ -47,8 +47,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExample.java index 240f78e7c..9954116cc 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExample.java @@ -48,8 +48,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExternalHttpExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExternalHttpExample.java index 598d25c64..4a89fd4d4 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExternalHttpExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExternalHttpExample.java @@ -65,8 +65,8 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XingExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XingExample.java index 9929c6152..fce6c9aea 100755 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XingExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XingExample.java @@ -45,8 +45,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/YahooExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/YahooExample.java index 3e8802fa8..af3fa635a 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/YahooExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/YahooExample.java @@ -46,8 +46,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth1AccessToken.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth1AccessToken.java index e57a7db39..dd145e5c7 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth1AccessToken.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth1AccessToken.java @@ -62,11 +62,4 @@ public boolean equals(Object obj) { } return Objects.equals(getTokenSecret(), other.getTokenSecret()); } - - @Override - public String toString() { - return "OAuth1AccessToken{" - + "oauth_token=" + getToken() - + ", oauth_token_secret=" + getTokenSecret() + '}'; - } } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth1RequestToken.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth1RequestToken.java index 1c53d4932..b8b3d2be4 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth1RequestToken.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth1RequestToken.java @@ -83,12 +83,4 @@ public boolean equals(Object obj) { } return Objects.equals(getTokenSecret(), other.getTokenSecret()); } - - @Override - public String toString() { - return "OAuth1RequestToken{" - + "oauth_token=" + getToken() - + ", oauth_token_secret=" + getTokenSecret() - + ", oauth_callback_confirmed=" + oauthCallbackConfirmed + '}'; - } } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth2AccessToken.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth2AccessToken.java index b97e4e0a0..2b30f2031 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth2AccessToken.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth2AccessToken.java @@ -131,14 +131,4 @@ public boolean equals(Object obj) { } return Objects.equals(expiresIn, other.getExpiresIn()); } - - @Override - public String toString() { - return "OAuth2AccessToken{" - + "access_token=" + accessToken - + ", token_type=" + tokenType - + ", expires_in=" + expiresIn - + ", refresh_token=" + refreshToken - + ", scope=" + scope + '}'; - } } From 4003852cdd58260346dd749ee1417e656e182a5a Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 21 Nov 2017 13:26:01 +0300 Subject: [PATCH 422/882] add Apache HttpComponents HttpClient support in separate module (thanks to https://github.com/sschwieb) --- changelog | 1 + pom.xml | 6 ++ scribejava-apis/pom.xml | 6 ++ .../examples/FacebookAsyncApacheExample.java | 87 +++++++++++++++++++ scribejava-core/pom.xml | 9 -- .../core/httpclient/HttpClient.java | 5 +- .../core/httpclient/jdk/JDKHttpClient.java | 6 +- .../scribejava/core/oauth/OAuthService.java | 3 +- .../scribejava/core/AbstractClientTest.java | 42 +++++---- .../httpclient/jdk/JDKHttpClientTest.java | 2 +- scribejava-httpclient-ahc/pom.xml | 6 -- .../httpclient/ahc/AhcHttpClient.java | 53 ++++------- .../ahc/OAuthAsyncCompletionHandler.java | 7 +- .../httpclient/ahc/AhcHttpClientTest.java | 2 +- scribejava-httpclient-apache/pom.xml | 10 +-- .../httpclient/apache/ApacheHttpClient.java | 18 ++-- .../apache/ApacheHttpClientConfig.java | 13 ++- .../httpclient/apache/ApacheProvider.java | 2 +- .../apache/OAuthAsyncCompletionHandler.java | 25 ++++-- ...ibejava.core.httpclient.HttpClientProvider | 1 + .../OauthAsyncCompletionHandlerTest.java | 33 ++++--- scribejava-httpclient-ning/pom.xml | 6 -- .../httpclient/ning/NingHttpClient.java | 59 ++++--------- .../httpclient/ning/NingHttpClientTest.java | 3 +- scribejava-httpclient-okhttp/pom.xml | 6 -- .../httpclient/okhttp/OkHttpHttpClient.java | 4 + .../okhttp/OkHttpHttpClientTest.java | 3 +- 27 files changed, 240 insertions(+), 178 deletions(-) create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncApacheExample.java create mode 100644 scribejava-httpclient-apache/src/main/resources/META-INF/services/com.github.scribejava.core.httpclient.HttpClientProvider diff --git a/changelog b/changelog index fda68b66e..2c70fb103 100644 --- a/changelog +++ b/changelog @@ -10,6 +10,7 @@ * add OAuth2Service signRequest method accepting just String, not OAuth2 Access Token Object. Remove signRequest from abstract OAuthService. 2.0 and 1.0a will be a bit more different now. * drop toString method from *Tokens to prevent leak of sensible data (token ans secrets) (thanks to https://github.com/rcaa) + * add Apache HttpComponents HttpClient support in separate module (thanks to https://github.com/sschwieb) [4.2.0] * DELETE in JdkClient permits, but not requires payload (thanks to https://github.com/miguelD73) diff --git a/pom.xml b/pom.xml index 054ecafb4..3af42a45a 100644 --- a/pom.xml +++ b/pom.xml @@ -97,6 +97,12 @@ compile true + + com.squareup.okhttp3 + mockwebserver + 3.9.0 + test + diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 583b8cdac..2042df1c2 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -38,6 +38,12 @@ ${project.version} test + + com.github.scribejava + scribejava-httpclient-apache + ${project.version} + test + diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncApacheExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncApacheExample.java new file mode 100644 index 000000000..c15406779 --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncApacheExample.java @@ -0,0 +1,87 @@ +package com.github.scribejava.apis.examples; + +import java.util.Random; +import java.util.Scanner; +import java.util.concurrent.ExecutionException; +import com.github.scribejava.apis.FacebookApi; +import com.github.scribejava.core.builder.ServiceBuilder; +import com.github.scribejava.core.model.OAuth2AccessToken; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.oauth.OAuth20Service; +import com.github.scribejava.httpclient.apache.ApacheHttpClientConfig; +import java.io.IOException; + +public final class FacebookAsyncApacheExample { + + private static final String NETWORK_NAME = "Facebook"; + private static final String PROTECTED_RESOURCE_URL = "https://graph.facebook.com/v2.8/me"; + + private FacebookAsyncApacheExample() { + } + + public static void main(String... args) throws InterruptedException, ExecutionException, IOException { + // Replace these with your client id and secret + final String clientId = "your client id"; + final String clientSecret = "your client secret"; + final String secretState = "secret" + new Random().nextInt(999_999); + + try (OAuth20Service service = new ServiceBuilder(clientId) + .apiSecret(clientSecret) + .state(secretState) + .callback("http://www.example.com/oauth_callback/") + .httpClientConfig(ApacheHttpClientConfig.defaultConfig()) + .build(FacebookApi.instance())) { + final Scanner in = new Scanner(System.in, "UTF-8"); + + System.out.println("=== " + NETWORK_NAME + "'s Async OAuth Workflow ==="); + System.out.println(); + + // Obtain the Authorization URL + System.out.println("Fetching the Authorization URL..."); + final String authorizationUrl = service.getAuthorizationUrl(); + System.out.println("Got the Authorization URL!"); + System.out.println("Now go and authorize ScribeJava here:"); + System.out.println(authorizationUrl); + System.out.println("And paste the authorization code here"); + System.out.print(">>"); + final String code = in.nextLine(); + System.out.println(); + + System.out.println("And paste the state from server here. We have set 'secretState'='" + + secretState + "'."); + System.out.print(">>"); + final String value = in.nextLine(); + if (secretState.equals(value)) { + System.out.println("State value does match!"); + } else { + System.out.println("Ooops, state value does not match!"); + System.out.println("Expected = " + secretState); + System.out.println("Got = " + value); + System.out.println(); + } + + // Trade the Request Token and Verfier for the Access Token + System.out.println("Trading the Request Token for an Access Token..."); + final OAuth2AccessToken accessToken = service.getAccessTokenAsync(code).get(); + System.out.println("Got the Access Token!"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + + "')"); + System.out.println(); + + // Now let's go and ask for a protected resource! + System.out.println("Now we're going to access a protected resource..."); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); + service.signRequest(accessToken, request); + final Response response = service.execute(request); + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + + System.out.println(); + System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); + } + } +} diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 460316e5d..bfb71c2bf 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -14,15 +14,6 @@ ScribeJava Core jar - - - com.squareup.okhttp3 - mockwebserver - 3.8.1 - test - - - diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/HttpClient.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/HttpClient.java index 5793faf5c..a3bc0b5c5 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/HttpClient.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/HttpClient.java @@ -4,19 +4,18 @@ import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; import com.github.scribejava.core.model.Verb; +import java.io.Closeable; import java.io.File; import java.io.IOException; import java.util.Map; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; -public interface HttpClient { +public interface HttpClient extends Closeable { String DEFAULT_CONTENT_TYPE = "application/x-www-form-urlencoded"; String CONTENT_TYPE = "Content-Type"; String CONTENT_LENGTH = "Content-Length"; - void close() throws IOException; - Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, byte[] bodyContents, OAuthAsyncRequestCallback callback, OAuthRequest.ResponseConverter converter); diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java index d02dc5e8b..5e173eb7e 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java @@ -21,12 +21,16 @@ public class JDKHttpClient implements HttpClient { private final JDKHttpClientConfig config; + public JDKHttpClient() { + this(JDKHttpClientConfig.defaultConfig()); + } + public JDKHttpClient(JDKHttpClientConfig clientConfig) { config = clientConfig; } @Override - public void close() throws IOException { + public void close() { } @Override diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java index cf2ca6252..710f1bb68 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java @@ -9,6 +9,7 @@ import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; +import java.io.Closeable; import java.io.File; import java.io.IOException; @@ -16,7 +17,7 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; -public abstract class OAuthService implements AutoCloseable { +public abstract class OAuthService implements Closeable { private final OAuthConfig config; private final HttpClient httpClient; diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/AbstractClientTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/AbstractClientTest.java index 0df7c6ad8..56780f80c 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/AbstractClientTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/AbstractClientTest.java @@ -17,49 +17,48 @@ import org.junit.Before; import org.junit.Test; -import java.io.IOException; import java.util.concurrent.TimeUnit; import static org.junit.Assert.assertEquals; public abstract class AbstractClientTest { - class TestCallback implements OAuthAsyncRequestCallback { + private OAuthService oAuthService; - private Throwable throwable; - private T response; + private static class TestCallback implements OAuthAsyncRequestCallback { + + private Response response; @Override - public void onCompleted(T response) { + public void onCompleted(Response response) { this.response = response; } @Override public void onThrowable(Throwable throwable) { - this.throwable = throwable; } - } - private OAuthService oAuthService; - private HttpClient client; + public Response getResponse() { + return response; + } + } @Before public void setUp() { - client = createNewClient(); oAuthService = new OAuth20Service(null, - new OAuthConfig("test", "test", null, null, null, null, null, null, null, client)); + new OAuthConfig("test", "test", null, null, null, null, null, null, null, createNewClient())); } @After - public void shutDown() throws IOException { - client.close(); + public void shutDown() throws Exception { + oAuthService.close(); } protected abstract HttpClient createNewClient(); @Test public void shouldSendGetRequest() throws Exception { - final String expectedResponseBody = "response body"; + final String expectedResponseBody = "response body for test shouldSendGetRequest"; final MockWebServer server = new MockWebServer(); server.enqueue(new MockResponse().setBody(expectedResponseBody)); @@ -80,7 +79,7 @@ public void shouldSendGetRequest() throws Exception { @Test public void shouldSendPostRequest() throws Exception { - final String expectedResponseBody = "response body"; + final String expectedResponseBody = "response body for test shouldSendPostRequest"; final String expectedRequestBody = "request body"; final MockWebServer server = new MockWebServer(); @@ -101,7 +100,6 @@ public void shouldSendPostRequest() throws Exception { assertEquals("POST", recordedRequest.getMethod()); assertEquals(expectedRequestBody, recordedRequest.getBody().readUtf8()); - // request with empty body request = new OAuthRequest(Verb.POST, baseUrl.toString()); response = oAuthService.execute(request, null).get(30, TimeUnit.SECONDS); @@ -117,7 +115,7 @@ public void shouldSendPostRequest() throws Exception { @Test public void shouldReadResponseStream() throws Exception { - final String expectedResponseBody = "response body"; + final String expectedResponseBody = "response body for test shouldReadResponseStream"; final MockWebServer server = new MockWebServer(); server.enqueue(new MockResponse().setBody(expectedResponseBody)); @@ -138,7 +136,7 @@ public void shouldReadResponseStream() throws Exception { @Test public void shouldCallCallback() throws Exception { - final String expectedResponseBody = "response body"; + final String expectedResponseBody = "response body for test shouldCallCallback"; final MockWebServer server = new MockWebServer(); server.enqueue(new MockResponse().setBody(expectedResponseBody)); @@ -148,10 +146,10 @@ public void shouldCallCallback() throws Exception { final OAuthRequest request = new OAuthRequest(Verb.GET, baseUrl.toString()); - final TestCallback callback = new TestCallback<>(); + final TestCallback callback = new TestCallback(); oAuthService.execute(request, callback).get(); - assertEquals(expectedResponseBody, callback.response.getBody()); + assertEquals(expectedResponseBody, callback.getResponse().getBody()); server.shutdown(); } @@ -167,11 +165,11 @@ public void shouldPassErrors() throws Exception { final OAuthRequest request = new OAuthRequest(Verb.GET, baseUrl.toString()); - final TestCallback callback = new TestCallback<>(); + final TestCallback callback = new TestCallback(); final Response response = oAuthService.execute(request, callback).get(); assertEquals(500, response.getCode()); - assertEquals(500, callback.response.getCode()); + assertEquals(500, callback.getResponse().getCode()); server.shutdown(); } diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClientTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClientTest.java index 09d34f0c3..6ac1070fa 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClientTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClientTest.java @@ -7,6 +7,6 @@ public class JDKHttpClientTest extends AbstractClientTest { @Override protected HttpClient createNewClient() { - return new JDKHttpClient(JDKHttpClientConfig.defaultConfig()); + return new JDKHttpClient(); } } diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 652f24bc2..7cff01618 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -32,12 +32,6 @@ test-jar test - - com.squareup.okhttp3 - mockwebserver - 3.8.1 - test - diff --git a/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/AhcHttpClient.java b/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/AhcHttpClient.java index cdc894bb8..ce705c372 100644 --- a/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/AhcHttpClient.java +++ b/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/AhcHttpClient.java @@ -13,6 +13,7 @@ import java.util.concurrent.Future; import java.io.File; +import java.util.function.Consumer; import org.asynchttpclient.AsyncHttpClientConfig; import org.asynchttpclient.BoundRequestBuilder; @@ -20,6 +21,10 @@ public class AhcHttpClient extends AbstractAsyncOnlyHttpClient { private final AsyncHttpClient client; + public AhcHttpClient() { + this(AhcHttpClientConfig.defaultConfig()); + } + public AhcHttpClient(AhcHttpClientConfig ahcConfig) { final AsyncHttpClientConfig clientConfig = ahcConfig.getClientConfig(); client = clientConfig == null ? new DefaultAsyncHttpClient() : new DefaultAsyncHttpClient(clientConfig); @@ -37,28 +42,28 @@ public void close() throws IOException { @Override public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, byte[] bodyContents, OAuthAsyncRequestCallback callback, OAuthRequest.ResponseConverter converter) { - return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, BodySetter.BYTE_ARRAY, bodyContents, callback, - converter); + return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, + requestBuilder -> requestBuilder.setBody(bodyContents), callback, converter); } @Override public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, String bodyContents, OAuthAsyncRequestCallback callback, OAuthRequest.ResponseConverter converter) { - return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, BodySetter.STRING, bodyContents, callback, - converter); + return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, + requestBuilder -> requestBuilder.setBody(bodyContents), callback, converter); } @Override public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, File bodyContents, OAuthAsyncRequestCallback callback, OAuthRequest.ResponseConverter converter) { - return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, BodySetter.FILE, bodyContents, callback, - converter); + return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, + requestBuilder -> requestBuilder.setBody(bodyContents), callback, converter); } private Future doExecuteAsync(String userAgent, Map headers, Verb httpVerb, - String completeUrl, BodySetter bodySetter, Object bodyContents, OAuthAsyncRequestCallback callback, + String completeUrl, Consumer bodySetter, OAuthAsyncRequestCallback callback, OAuthRequest.ResponseConverter converter) { - BoundRequestBuilder boundRequestBuilder; + final BoundRequestBuilder boundRequestBuilder; switch (httpVerb) { case GET: boundRequestBuilder = client.prepareGet(completeUrl); @@ -78,41 +83,17 @@ private Future doExecuteAsync(String userAgent, Map heade if (httpVerb.isPermitBody()) { if (!headers.containsKey(CONTENT_TYPE)) { - boundRequestBuilder = boundRequestBuilder.addHeader(CONTENT_TYPE, DEFAULT_CONTENT_TYPE); + boundRequestBuilder.addHeader(CONTENT_TYPE, DEFAULT_CONTENT_TYPE); } - boundRequestBuilder = bodySetter.setBody(boundRequestBuilder, bodyContents); + bodySetter.accept(boundRequestBuilder); } - for (Map.Entry header : headers.entrySet()) { - boundRequestBuilder.addHeader(header.getKey(), header.getValue()); - } + headers.forEach((headerKey, headerValue) -> boundRequestBuilder.addHeader(headerKey, headerValue)); + if (userAgent != null) { boundRequestBuilder.setHeader(OAuthConstants.USER_AGENT_HEADER_NAME, userAgent); } return boundRequestBuilder.execute(new OAuthAsyncCompletionHandler<>(callback, converter)); } - - private enum BodySetter { - BYTE_ARRAY { - @Override - BoundRequestBuilder setBody(BoundRequestBuilder requestBuilder, Object bodyContents) { - return requestBuilder.setBody((byte[]) bodyContents); - } - }, - STRING { - @Override - BoundRequestBuilder setBody(BoundRequestBuilder requestBuilder, Object bodyContents) { - return requestBuilder.setBody((String) bodyContents); - } - }, - FILE { - @Override - BoundRequestBuilder setBody(BoundRequestBuilder requestBuilder, Object bodyContents) { - return requestBuilder.setBody((File) bodyContents); - } - }; - - abstract BoundRequestBuilder setBody(BoundRequestBuilder requestBuilder, Object bodyContents); - } } diff --git a/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/OAuthAsyncCompletionHandler.java b/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/OAuthAsyncCompletionHandler.java index 856cbcf68..444f52226 100644 --- a/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/OAuthAsyncCompletionHandler.java +++ b/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/OAuthAsyncCompletionHandler.java @@ -3,7 +3,6 @@ import com.github.scribejava.core.model.OAuthAsyncRequestCallback; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; -import io.netty.handler.codec.http.HttpHeaders; import java.io.IOException; import java.util.HashMap; import java.util.Map; @@ -22,11 +21,9 @@ public OAuthAsyncCompletionHandler(OAuthAsyncRequestCallback callback, @Override public T onCompleted(org.asynchttpclient.Response ahcResponse) throws IOException { - final HttpHeaders map = ahcResponse.getHeaders(); final Map headersMap = new HashMap<>(); - for (Map.Entry header : map) { - headersMap.put(header.getKey(), header.getValue()); - } + ahcResponse.getHeaders().forEach(header -> headersMap.put(header.getKey(), header.getValue())); + final Response response = new Response(ahcResponse.getStatusCode(), ahcResponse.getStatusText(), headersMap, ahcResponse.getResponseBodyAsStream()); diff --git a/scribejava-httpclient-ahc/src/test/java/com/github/scribejava/httpclient/ahc/AhcHttpClientTest.java b/scribejava-httpclient-ahc/src/test/java/com/github/scribejava/httpclient/ahc/AhcHttpClientTest.java index 34d940205..5de2d153e 100644 --- a/scribejava-httpclient-ahc/src/test/java/com/github/scribejava/httpclient/ahc/AhcHttpClientTest.java +++ b/scribejava-httpclient-ahc/src/test/java/com/github/scribejava/httpclient/ahc/AhcHttpClientTest.java @@ -7,6 +7,6 @@ public class AhcHttpClientTest extends AbstractClientTest { @Override protected HttpClient createNewClient() { - return new AhcHttpClient(AhcHttpClientConfig.defaultConfig()); + return new AhcHttpClient(); } } diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index 6ce5a545a..c004c990d 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -11,7 +11,7 @@ com.github.scribejava scribejava-httpclient-apache - ScribeJava Apache Http Client support + ScribeJava Apache HttpComponents HttpClient support jar @@ -23,7 +23,7 @@ org.apache.httpcomponents httpclient - 4.5.2 + 4.5.3 org.apache.httpcomponents @@ -37,12 +37,6 @@ test-jar test - - com.squareup.okhttp3 - mockwebserver - 3.8.1 - test - diff --git a/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/ApacheHttpClient.java b/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/ApacheHttpClient.java index db6c8e48f..e11eb3393 100644 --- a/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/ApacheHttpClient.java +++ b/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/ApacheHttpClient.java @@ -12,20 +12,28 @@ import org.apache.http.entity.FileEntity; import org.apache.http.entity.StringEntity; import org.apache.http.impl.nio.client.CloseableHttpAsyncClient; -import org.apache.http.impl.nio.client.HttpAsyncClients; import java.io.File; import java.io.IOException; import java.nio.charset.StandardCharsets; import java.util.Map; import java.util.concurrent.Future; +import org.apache.http.impl.nio.client.HttpAsyncClientBuilder; public class ApacheHttpClient extends AbstractAsyncOnlyHttpClient { private final CloseableHttpAsyncClient client; public ApacheHttpClient() { - this(HttpAsyncClients.createDefault()); + this(ApacheHttpClientConfig.defaultConfig()); + } + + public ApacheHttpClient(ApacheHttpClientConfig config) { + this(config.getHttpAsyncClientBuilder()); + } + + public ApacheHttpClient(HttpAsyncClientBuilder builder) { + this(builder.build()); } public ApacheHttpClient(CloseableHttpAsyncClient client) { @@ -72,9 +80,7 @@ private Future doExecuteAsync(String userAgent, Map heade builder.setEntity(entity); } - for (Map.Entry header : headers.entrySet()) { - builder.addHeader(header.getKey(), header.getValue()); - } + headers.forEach((headerKey, headerValue) -> builder.addHeader(headerKey, headerValue)); if (userAgent != null) { builder.setHeader(OAuthConstants.USER_AGENT_HEADER_NAME, userAgent); @@ -84,7 +90,7 @@ private Future doExecuteAsync(String userAgent, Map heade return new ApacheHttpFuture<>(future, handler); } - private RequestBuilder getRequestBuilder(Verb httpVerb) { + private static RequestBuilder getRequestBuilder(Verb httpVerb) { switch (httpVerb) { case GET: return RequestBuilder.get(); diff --git a/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/ApacheHttpClientConfig.java b/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/ApacheHttpClientConfig.java index 5ff523431..2a4f3a5b0 100644 --- a/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/ApacheHttpClientConfig.java +++ b/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/ApacheHttpClientConfig.java @@ -1,15 +1,26 @@ package com.github.scribejava.httpclient.apache; import com.github.scribejava.core.httpclient.HttpClientConfig; +import org.apache.http.impl.nio.client.HttpAsyncClientBuilder; public class ApacheHttpClientConfig implements HttpClientConfig { + private final HttpAsyncClientBuilder httpAsyncClientBuilder; + + public ApacheHttpClientConfig(HttpAsyncClientBuilder httpAsyncClientBuilder) { + this.httpAsyncClientBuilder = httpAsyncClientBuilder; + } + + public HttpAsyncClientBuilder getHttpAsyncClientBuilder() { + return httpAsyncClientBuilder; + } + @Override public HttpClientConfig createDefaultConfig() { return defaultConfig(); } public static ApacheHttpClientConfig defaultConfig() { - return new ApacheHttpClientConfig(); + return new ApacheHttpClientConfig(HttpAsyncClientBuilder.create()); } } diff --git a/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/ApacheProvider.java b/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/ApacheProvider.java index ed8efcf68..553972d1d 100644 --- a/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/ApacheProvider.java +++ b/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/ApacheProvider.java @@ -9,7 +9,7 @@ public class ApacheProvider implements HttpClientProvider { @Override public HttpClient createClient(HttpClientConfig httpClientConfig) { if (httpClientConfig instanceof ApacheHttpClientConfig) { - return new ApacheHttpClient(); + return new ApacheHttpClient((ApacheHttpClientConfig) httpClientConfig); } return null; } diff --git a/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/OAuthAsyncCompletionHandler.java b/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/OAuthAsyncCompletionHandler.java index e63f17179..eeef72e75 100644 --- a/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/OAuthAsyncCompletionHandler.java +++ b/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/OAuthAsyncCompletionHandler.java @@ -8,35 +8,41 @@ import org.apache.http.concurrent.FutureCallback; import java.io.IOException; +import java.util.Arrays; import java.util.Map; import java.util.concurrent.CancellationException; import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; import java.util.stream.Collectors; -import java.util.stream.Stream; +import org.apache.http.StatusLine; public class OAuthAsyncCompletionHandler implements FutureCallback { - private final ResponseConverter converter; private final OAuthAsyncRequestCallback callback; + private final ResponseConverter converter; private final CountDownLatch latch; private T result; private Exception exception; public OAuthAsyncCompletionHandler(OAuthAsyncRequestCallback callback, ResponseConverter converter) { - this.converter = converter; this.callback = callback; + this.converter = converter; this.latch = new CountDownLatch(1); } @Override public void completed(HttpResponse httpResponse) { try { - final Map headersMap = Stream.of(httpResponse.getAllHeaders()) + final Map headersMap = Arrays.stream(httpResponse.getAllHeaders()) .collect(Collectors.toMap(Header::getName, Header::getValue)); - final Response response = new Response(httpResponse.getStatusLine().getStatusCode(), - httpResponse.getStatusLine().getReasonPhrase(), headersMap, httpResponse.getEntity().getContent()); + + final StatusLine statusLine = httpResponse.getStatusLine(); + + final Response response = new Response(statusLine.getStatusCode(), statusLine.getReasonPhrase(), + headersMap, httpResponse.getEntity().getContent()); + @SuppressWarnings("unchecked") final T t = converter == null ? (T) response : converter.convert(response); result = t; @@ -85,8 +91,11 @@ public T getResult() throws InterruptedException, ExecutionException { return result; } - public T getResult(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException { - latch.await(timeout, unit); + public T getResult(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { + + if (!latch.await(timeout, unit)) { + throw new TimeoutException(); + } if (exception != null) { throw new ExecutionException(exception); } diff --git a/scribejava-httpclient-apache/src/main/resources/META-INF/services/com.github.scribejava.core.httpclient.HttpClientProvider b/scribejava-httpclient-apache/src/main/resources/META-INF/services/com.github.scribejava.core.httpclient.HttpClientProvider new file mode 100644 index 000000000..651910028 --- /dev/null +++ b/scribejava-httpclient-apache/src/main/resources/META-INF/services/com.github.scribejava.core.httpclient.HttpClientProvider @@ -0,0 +1 @@ +com.github.scribejava.httpclient.apache.ApacheProvider diff --git a/scribejava-httpclient-apache/src/test/java/com/github/scribejava/httpclient/apache/OauthAsyncCompletionHandlerTest.java b/scribejava-httpclient-apache/src/test/java/com/github/scribejava/httpclient/apache/OauthAsyncCompletionHandlerTest.java index f0309a173..89f3de1bc 100644 --- a/scribejava-httpclient-apache/src/test/java/com/github/scribejava/httpclient/apache/OauthAsyncCompletionHandlerTest.java +++ b/scribejava-httpclient-apache/src/test/java/com/github/scribejava/httpclient/apache/OauthAsyncCompletionHandlerTest.java @@ -25,7 +25,7 @@ public class OauthAsyncCompletionHandlerTest { private OAuthAsyncCompletionHandler handler; private TestCallback callback; - class TestCallback implements OAuthAsyncRequestCallback { + private static class TestCallback implements OAuthAsyncRequestCallback { private Throwable throwable; private String response; @@ -39,6 +39,15 @@ public void onCompleted(String response) { public void onThrowable(Throwable throwable) { this.throwable = throwable; } + + public Throwable getThrowable() { + return throwable; + } + + public String getResponse() { + return response; + } + } @Before @@ -55,8 +64,8 @@ public void shouldReleaseLatchOnSuccess() throws Exception { entity.setContent(new ByteArrayInputStream(new byte[0])); response.setEntity(entity); handler.completed(response); - assertNotNull(callback.response); - assertNull(callback.throwable); + assertNotNull(callback.getResponse()); + assertNull(callback.getThrowable()); // verify latch is released assertEquals("All good", handler.getResult()); } @@ -72,9 +81,9 @@ public void shouldReleaseLatchOnIOException() throws Exception { entity.setContent(new ByteArrayInputStream(new byte[0])); response.setEntity(entity); handler.completed(response); - assertNull(callback.response); - assertNotNull(callback.throwable); - assertTrue(callback.throwable instanceof IOException); + assertNull(callback.getResponse()); + assertNotNull(callback.getThrowable()); + assertTrue(callback.getThrowable() instanceof IOException); // verify latch is released try { handler.getResult(); @@ -93,9 +102,9 @@ public void shouldReleaseLatchOnCancel() throws Exception { entity.setContent(new ByteArrayInputStream(new byte[0])); response.setEntity(entity); handler.cancelled(); - assertNull(callback.response); - assertNotNull(callback.throwable); - assertTrue(callback.throwable instanceof CancellationException); + assertNull(callback.getResponse()); + assertNotNull(callback.getThrowable()); + assertTrue(callback.getThrowable() instanceof CancellationException); // verify latch is released try { handler.getResult(); @@ -114,9 +123,9 @@ public void shouldReleaseLatchOnFailure() throws Exception { entity.setContent(new ByteArrayInputStream(new byte[0])); response.setEntity(entity); handler.failed(new RuntimeException()); - assertNull(callback.response); - assertNotNull(callback.throwable); - assertTrue(callback.throwable instanceof RuntimeException); + assertNull(callback.getResponse()); + assertNotNull(callback.getThrowable()); + assertTrue(callback.getThrowable() instanceof RuntimeException); // verify latch is released try { handler.getResult(); diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index 1d1673810..04551b961 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -32,12 +32,6 @@ test-jar test - - com.squareup.okhttp3 - mockwebserver - 3.8.1 - test - diff --git a/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/NingHttpClient.java b/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/NingHttpClient.java index bcc843e00..32398b5aa 100644 --- a/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/NingHttpClient.java +++ b/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/NingHttpClient.java @@ -12,11 +12,16 @@ import com.ning.http.client.AsyncHttpClientConfig; import java.io.File; +import java.util.function.Consumer; public class NingHttpClient extends AbstractAsyncOnlyHttpClient { private final AsyncHttpClient client; + public NingHttpClient() { + this(NingHttpClientConfig.defaultConfig()); + } + public NingHttpClient(NingHttpClientConfig ningConfig) { final String ningAsyncHttpProviderClassName = ningConfig.getNingAsyncHttpProviderClassName(); AsyncHttpClientConfig config = ningConfig.getConfig(); @@ -43,30 +48,30 @@ public void close() { public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, byte[] bodyContents, OAuthAsyncRequestCallback callback, OAuthRequest.ResponseConverter converter) { - return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, BodySetter.BYTE_ARRAY, bodyContents, callback, - converter); + return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, + requestBuilder -> requestBuilder.setBody(bodyContents), callback, converter); } @Override public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, String bodyContents, OAuthAsyncRequestCallback callback, OAuthRequest.ResponseConverter converter) { - return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, BodySetter.STRING, bodyContents, callback, - converter); + return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, + requestBuilder -> requestBuilder.setBody(bodyContents), callback, converter); } @Override public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, File bodyContents, OAuthAsyncRequestCallback callback, OAuthRequest.ResponseConverter converter) { - return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, BodySetter.FILE, bodyContents, callback, - converter); + return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, + requestBuilder -> requestBuilder.setBody(bodyContents), callback, converter); } private Future doExecuteAsync(String userAgent, Map headers, Verb httpVerb, - String completeUrl, BodySetter bodySetter, Object bodyContents, OAuthAsyncRequestCallback callback, - OAuthRequest.ResponseConverter converter) { - AsyncHttpClient.BoundRequestBuilder boundRequestBuilder; + String completeUrl, Consumer bodySetter, + OAuthAsyncRequestCallback callback, OAuthRequest.ResponseConverter converter) { + final AsyncHttpClient.BoundRequestBuilder boundRequestBuilder; switch (httpVerb) { case GET: boundRequestBuilder = client.prepareGet(completeUrl); @@ -86,45 +91,17 @@ private Future doExecuteAsync(String userAgent, Map heade if (httpVerb.isPermitBody()) { if (!headers.containsKey(CONTENT_TYPE)) { - boundRequestBuilder = boundRequestBuilder.addHeader(CONTENT_TYPE, DEFAULT_CONTENT_TYPE); + boundRequestBuilder.addHeader(CONTENT_TYPE, DEFAULT_CONTENT_TYPE); } - boundRequestBuilder = bodySetter.setBody(boundRequestBuilder, bodyContents); + bodySetter.accept(boundRequestBuilder); } - for (Map.Entry header : headers.entrySet()) { - boundRequestBuilder.addHeader(header.getKey(), header.getValue()); - } + headers.forEach((headerKey, headerValue) -> boundRequestBuilder.addHeader(headerKey, headerValue)); + if (userAgent != null) { boundRequestBuilder.setHeader(OAuthConstants.USER_AGENT_HEADER_NAME, userAgent); } return boundRequestBuilder.execute(new OAuthAsyncCompletionHandler<>(callback, converter)); } - - private enum BodySetter { - BYTE_ARRAY { - @Override - AsyncHttpClient.BoundRequestBuilder setBody(AsyncHttpClient.BoundRequestBuilder requestBuilder, - Object bodyContents) { - return requestBuilder.setBody((byte[]) bodyContents); - } - }, - STRING { - @Override - AsyncHttpClient.BoundRequestBuilder setBody(AsyncHttpClient.BoundRequestBuilder requestBuilder, - Object bodyContents) { - return requestBuilder.setBody((String) bodyContents); - } - }, - FILE { - @Override - AsyncHttpClient.BoundRequestBuilder setBody(AsyncHttpClient.BoundRequestBuilder requestBuilder, - Object bodyContents) { - return requestBuilder.setBody((File) bodyContents); - } - }; - - abstract AsyncHttpClient.BoundRequestBuilder setBody(AsyncHttpClient.BoundRequestBuilder requestBuilder, - Object bodyContents); - } } diff --git a/scribejava-httpclient-ning/src/test/java/com/github/scribejava/httpclient/ning/NingHttpClientTest.java b/scribejava-httpclient-ning/src/test/java/com/github/scribejava/httpclient/ning/NingHttpClientTest.java index 8155cebf7..6ebf6456f 100644 --- a/scribejava-httpclient-ning/src/test/java/com/github/scribejava/httpclient/ning/NingHttpClientTest.java +++ b/scribejava-httpclient-ning/src/test/java/com/github/scribejava/httpclient/ning/NingHttpClientTest.java @@ -2,12 +2,11 @@ import com.github.scribejava.core.AbstractClientTest; import com.github.scribejava.core.httpclient.HttpClient; -import com.ning.http.client.AsyncHttpClient; public class NingHttpClientTest extends AbstractClientTest { @Override protected HttpClient createNewClient() { - return new NingHttpClient(new AsyncHttpClient()); + return new NingHttpClient(); } } diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 1d013f042..e63a88568 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -25,12 +25,6 @@ okhttp 3.9.0 - - com.squareup.okhttp3 - mockwebserver - 3.9.0 - test - com.github.scribejava scribejava-core diff --git a/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java b/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java index 8090ef845..f4638d3ab 100644 --- a/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java +++ b/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java @@ -31,6 +31,10 @@ public class OkHttpHttpClient implements HttpClient { private final OkHttpClient client; + public OkHttpHttpClient() { + this(OkHttpHttpClientConfig.defaultConfig()); + } + public OkHttpHttpClient(OkHttpHttpClientConfig config) { final OkHttpClient.Builder clientBuilder = config.getClientBuilder(); client = clientBuilder == null ? new OkHttpClient() : clientBuilder.build(); diff --git a/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClientTest.java b/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClientTest.java index 1bc31919b..80fdf2834 100644 --- a/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClientTest.java +++ b/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClientTest.java @@ -2,12 +2,11 @@ import com.github.scribejava.core.AbstractClientTest; import com.github.scribejava.core.httpclient.HttpClient; -import okhttp3.OkHttpClient; public class OkHttpHttpClientTest extends AbstractClientTest { @Override protected HttpClient createNewClient() { - return new OkHttpHttpClient(new OkHttpClient()); + return new OkHttpHttpClient(); } } From fd4f99ef56bbefcc75f0a028d14522a4711ebb11 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 22 Nov 2017 16:37:23 +0300 Subject: [PATCH 423/882] add support for appsecret_proof in Facebook --- changelog | 1 + .../github/scribejava/apis/FacebookApi.java | 7 +++ .../com/github/scribejava/apis/ImgurApi.java | 7 ++- .../com/github/scribejava/apis/MailruApi.java | 7 ++- .../scribejava/apis/OdnoklassnikiApi.java | 7 ++- .../com/github/scribejava/apis/TutByApi.java | 7 ++- .../apis/service/FacebookService.java | 40 +++++++++++++++ .../apis/service/ImgurOAuthService.java | 39 +++++++++++++++ .../apis/service/ImgurOAuthServiceImpl.java | 35 +++---------- .../apis/service/MailruOAuthService.java | 48 ++++++++++++++++++ .../apis/service/MailruOAuthServiceImpl.java | 44 +++------------- .../service/OdnoklassnikiOAuthService.java | 50 +++++++++++++++++++ .../service/OdnoklassnikiServiceImpl.java | 46 +++-------------- .../apis/service/TutByOAuthService.java | 19 +++++++ .../apis/service/TutByOAuthServiceImpl.java | 15 +++--- 15 files changed, 240 insertions(+), 132 deletions(-) create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/service/FacebookService.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthService.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthService.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiOAuthService.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/service/TutByOAuthService.java diff --git a/changelog b/changelog index 2c70fb103..c41771e81 100644 --- a/changelog +++ b/changelog @@ -11,6 +11,7 @@ Remove signRequest from abstract OAuthService. 2.0 and 1.0a will be a bit more different now. * drop toString method from *Tokens to prevent leak of sensible data (token ans secrets) (thanks to https://github.com/rcaa) * add Apache HttpComponents HttpClient support in separate module (thanks to https://github.com/sschwieb) + * add support for appsecret_proof in Facebook [4.2.0] * DELETE in JdkClient permits, but not requires payload (thanks to https://github.com/miguelD73) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java index 635a20e48..54f51cc25 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java @@ -1,10 +1,12 @@ package com.github.scribejava.apis; import com.github.scribejava.apis.facebook.FacebookAccessTokenJsonExtractor; +import com.github.scribejava.apis.service.FacebookService; import com.github.scribejava.core.builder.api.ClientAuthenticationType; import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.extractors.TokenExtractor; import com.github.scribejava.core.model.OAuth2AccessToken; +import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.Verb; /** @@ -53,4 +55,9 @@ public TokenExtractor getAccessTokenExtractor() { public ClientAuthenticationType getClientAuthenticationType() { return ClientAuthenticationType.REQUEST_BODY; } + + @Override + public FacebookService createService(OAuthConfig config) { + return new FacebookService(this, config); + } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java index 3b14473d1..477fb5e0f 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java @@ -1,11 +1,10 @@ package com.github.scribejava.apis; -import com.github.scribejava.apis.service.ImgurOAuthServiceImpl; +import com.github.scribejava.apis.service.ImgurOAuthService; import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.ParameterList; -import com.github.scribejava.core.oauth.OAuth20Service; import java.util.Map; public class ImgurApi extends DefaultApi20 { @@ -56,8 +55,8 @@ protected String getAuthorizationBaseUrl() { } @Override - public OAuth20Service createService(OAuthConfig config) { - return new ImgurOAuthServiceImpl(this, config); + public ImgurOAuthService createService(OAuthConfig config) { + return new ImgurOAuthService(this, config); } public static boolean isOob(OAuthConfig config) { diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java index a67e434c5..cf9ae9903 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java @@ -2,8 +2,7 @@ import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.model.OAuthConfig; -import com.github.scribejava.apis.service.MailruOAuthServiceImpl; -import com.github.scribejava.core.oauth.OAuth20Service; +import com.github.scribejava.apis.service.MailruOAuthService; public class MailruApi extends DefaultApi20 { @@ -29,7 +28,7 @@ protected String getAuthorizationBaseUrl() { } @Override - public OAuth20Service createService(OAuthConfig config) { - return new MailruOAuthServiceImpl(this, config); + public MailruOAuthService createService(OAuthConfig config) { + return new MailruOAuthService(this, config); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java index df4e2e755..4582d1ac9 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java @@ -1,11 +1,10 @@ package com.github.scribejava.apis; -import com.github.scribejava.apis.service.OdnoklassnikiServiceImpl; +import com.github.scribejava.apis.service.OdnoklassnikiOAuthService; import com.github.scribejava.core.builder.api.ClientAuthenticationType; import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.builder.api.OAuth2SignatureType; import com.github.scribejava.core.model.OAuthConfig; -import com.github.scribejava.core.oauth.OAuth20Service; public class OdnoklassnikiApi extends DefaultApi20 { @@ -31,8 +30,8 @@ protected String getAuthorizationBaseUrl() { } @Override - public OAuth20Service createService(OAuthConfig config) { - return new OdnoklassnikiServiceImpl(this, config); + public OdnoklassnikiOAuthService createService(OAuthConfig config) { + return new OdnoklassnikiOAuthService(this, config); } @Override diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/TutByApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/TutByApi.java index 6928ba70a..0e7359f08 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/TutByApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/TutByApi.java @@ -1,9 +1,8 @@ package com.github.scribejava.apis; +import com.github.scribejava.apis.service.TutByOAuthService; import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.model.OAuthConfig; -import com.github.scribejava.apis.service.TutByOAuthServiceImpl; -import com.github.scribejava.core.oauth.OAuth20Service; public class TutByApi extends DefaultApi20 { @@ -29,7 +28,7 @@ protected String getAuthorizationBaseUrl() { } @Override - public OAuth20Service createService(OAuthConfig config) { - return new TutByOAuthServiceImpl(this, config); + public TutByOAuthService createService(OAuthConfig config) { + return new TutByOAuthService(this, config); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/FacebookService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/FacebookService.java new file mode 100644 index 000000000..c506ce852 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/FacebookService.java @@ -0,0 +1,40 @@ +package com.github.scribejava.apis.service; + +import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.model.OAuthConfig; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.oauth.OAuth20Service; +import java.security.InvalidKeyException; +import java.security.NoSuchAlgorithmException; +import java.util.Formatter; +import javax.crypto.Mac; +import javax.crypto.spec.SecretKeySpec; + +public class FacebookService extends OAuth20Service { + + public FacebookService(DefaultApi20 api, OAuthConfig config) { + super(api, config); + } + + @Override + public void signRequest(String accessToken, OAuthRequest request) { + super.signRequest(accessToken, request); + + final Mac mac; + try { + mac = Mac.getInstance("HmacSHA256"); + final SecretKeySpec secretKey = new SecretKeySpec(getConfig().getApiSecret().getBytes(), "HmacSHA256"); + mac.init(secretKey); + + final Formatter appsecretProof = new Formatter(); + + for (byte b : mac.doFinal(accessToken.getBytes())) { + appsecretProof.format("%02x", b); + } + + request.addParameter("appsecret_proof", appsecretProof.toString()); + } catch (NoSuchAlgorithmException | InvalidKeyException e) { + throw new IllegalStateException("There is a problem while generating Facebook appsecret_proof.", e); + } + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthService.java new file mode 100644 index 000000000..89edf0198 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthService.java @@ -0,0 +1,39 @@ +package com.github.scribejava.apis.service; + +import com.github.scribejava.apis.ImgurApi; +import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.model.OAuthConfig; +import com.github.scribejava.core.model.OAuthConstants; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.oauth.OAuth20Service; + +public class ImgurOAuthService extends OAuth20Service { + + public ImgurOAuthService(DefaultApi20 api, OAuthConfig config) { + super(api, config); + } + + @Override + protected OAuthRequest createAccessTokenRequest(String oauthVerifier) { + final DefaultApi20 api = getApi(); + final OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint()); + final OAuthConfig config = getConfig(); + request.addBodyParameter(OAuthConstants.CLIENT_ID, config.getApiKey()); + request.addBodyParameter(OAuthConstants.CLIENT_SECRET, config.getApiSecret()); + + if (ImgurApi.isOob(config)) { + request.addBodyParameter(OAuthConstants.GRANT_TYPE, "pin"); + request.addBodyParameter("pin", oauthVerifier); + } else { + request.addBodyParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.AUTHORIZATION_CODE); + request.addBodyParameter(OAuthConstants.CODE, oauthVerifier); + } + return request; + } + + @Override + public void signRequest(String accessToken, OAuthRequest request) { + request.addHeader("Authorization", + accessToken == null ? "Client-ID " + getConfig().getApiKey() : "Bearer " + accessToken); + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthServiceImpl.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthServiceImpl.java index c77de1b70..b7ee9b1ad 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthServiceImpl.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthServiceImpl.java @@ -1,39 +1,16 @@ package com.github.scribejava.apis.service; -import com.github.scribejava.apis.ImgurApi; import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.model.OAuthConfig; -import com.github.scribejava.core.model.OAuthConstants; -import com.github.scribejava.core.model.OAuthRequest; -import com.github.scribejava.core.oauth.OAuth20Service; -public class ImgurOAuthServiceImpl extends OAuth20Service { +/** + * + * @deprecated renamed to {@link ImgurOAuthService} + */ +@Deprecated +public class ImgurOAuthServiceImpl extends ImgurOAuthService { public ImgurOAuthServiceImpl(DefaultApi20 api, OAuthConfig config) { super(api, config); } - - @Override - protected OAuthRequest createAccessTokenRequest(String oauthVerifier) { - final DefaultApi20 api = getApi(); - final OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint()); - final OAuthConfig config = getConfig(); - request.addBodyParameter(OAuthConstants.CLIENT_ID, config.getApiKey()); - request.addBodyParameter(OAuthConstants.CLIENT_SECRET, config.getApiSecret()); - - if (ImgurApi.isOob(config)) { - request.addBodyParameter(OAuthConstants.GRANT_TYPE, "pin"); - request.addBodyParameter("pin", oauthVerifier); - } else { - request.addBodyParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.AUTHORIZATION_CODE); - request.addBodyParameter(OAuthConstants.CODE, oauthVerifier); - } - return request; - } - - @Override - public void signRequest(String accessToken, OAuthRequest request) { - request.addHeader("Authorization", - accessToken == null ? "Client-ID " + getConfig().getApiKey() : "Bearer " + accessToken); - } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthService.java new file mode 100644 index 000000000..0e426f337 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthService.java @@ -0,0 +1,48 @@ +package com.github.scribejava.apis.service; + +import java.io.UnsupportedEncodingException; +import java.net.URLDecoder; +import java.util.Map; +import java.util.TreeMap; +import org.apache.commons.codec.CharEncoding; +import static org.apache.commons.codec.digest.DigestUtils.md5Hex; +import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.model.OAuthConfig; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.oauth.OAuth20Service; +import java.util.stream.Collectors; + +public class MailruOAuthService extends OAuth20Service { + + public MailruOAuthService(DefaultApi20 api, OAuthConfig config) { + super(api, config); + } + + @Override + public void signRequest(String accessToken, OAuthRequest request) { + // sig = md5(params + secret_key) + request.addQuerystringParameter("session_key", accessToken); + request.addQuerystringParameter("app_id", getConfig().getApiKey()); + final String completeUrl = request.getCompleteUrl(); + + try { + final String clientSecret = getConfig().getApiSecret(); + final int queryIndex = completeUrl.indexOf('?'); + if (queryIndex != -1) { + final String urlPart = completeUrl.substring(queryIndex + 1); + final Map map = new TreeMap<>(); + for (String param : urlPart.split("&")) { + final String[] parts = param.split("="); + map.put(parts[0], (parts.length == 1) ? "" : parts[1]); + } + final String urlNew = map.entrySet().stream() + .map(entry -> entry.getKey() + '=' + entry.getValue()) + .collect(Collectors.joining()); + final String sigSource = URLDecoder.decode(urlNew, CharEncoding.UTF_8) + clientSecret; + request.addQuerystringParameter("sig", md5Hex(sigSource)); + } + } catch (UnsupportedEncodingException e) { + throw new IllegalStateException(e); + } + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthServiceImpl.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthServiceImpl.java index 2b6e3cc3e..4301fd8fb 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthServiceImpl.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthServiceImpl.java @@ -1,48 +1,16 @@ package com.github.scribejava.apis.service; -import java.io.UnsupportedEncodingException; -import java.net.URLDecoder; -import java.util.Map; -import java.util.TreeMap; -import org.apache.commons.codec.CharEncoding; -import static org.apache.commons.codec.digest.DigestUtils.md5Hex; import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.model.OAuthConfig; -import com.github.scribejava.core.model.OAuthRequest; -import com.github.scribejava.core.oauth.OAuth20Service; -import java.util.stream.Collectors; -public class MailruOAuthServiceImpl extends OAuth20Service { +/** + * + * @deprecated renamed to {@link MailruOAuthService} + */ +@Deprecated +public class MailruOAuthServiceImpl extends MailruOAuthService { public MailruOAuthServiceImpl(DefaultApi20 api, OAuthConfig config) { super(api, config); } - - @Override - public void signRequest(String accessToken, OAuthRequest request) { - // sig = md5(params + secret_key) - request.addQuerystringParameter("session_key", accessToken); - request.addQuerystringParameter("app_id", getConfig().getApiKey()); - final String completeUrl = request.getCompleteUrl(); - - try { - final String clientSecret = getConfig().getApiSecret(); - final int queryIndex = completeUrl.indexOf('?'); - if (queryIndex != -1) { - final String urlPart = completeUrl.substring(queryIndex + 1); - final Map map = new TreeMap<>(); - for (String param : urlPart.split("&")) { - final String[] parts = param.split("="); - map.put(parts[0], (parts.length == 1) ? "" : parts[1]); - } - final String urlNew = map.entrySet().stream() - .map(entry -> entry.getKey() + '=' + entry.getValue()) - .collect(Collectors.joining()); - final String sigSource = URLDecoder.decode(urlNew, CharEncoding.UTF_8) + clientSecret; - request.addQuerystringParameter("sig", md5Hex(sigSource)); - } - } catch (UnsupportedEncodingException e) { - throw new IllegalStateException(e); - } - } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiOAuthService.java new file mode 100644 index 000000000..0bf117edd --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiOAuthService.java @@ -0,0 +1,50 @@ +package com.github.scribejava.apis.service; + +import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.model.OAuthConfig; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Parameter; +import com.github.scribejava.core.model.ParameterList; +import com.github.scribejava.core.oauth.OAuth20Service; + +import org.apache.commons.codec.CharEncoding; + +import java.io.UnsupportedEncodingException; +import java.net.URLDecoder; +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; + +import static org.apache.commons.codec.digest.DigestUtils.md5Hex; + +public class OdnoklassnikiOAuthService extends OAuth20Service { + + public OdnoklassnikiOAuthService(DefaultApi20 api, OAuthConfig config) { + super(api, config); + } + + @Override + public void signRequest(String accessToken, OAuthRequest request) { + //sig = lower(md5( sorted_request_params_composed_string + md5(access_token + application_secret_key))) + try { + final String tokenDigest = md5Hex(accessToken + getConfig().getApiSecret()); + + final ParameterList queryParams = request.getQueryStringParams(); + queryParams.addAll(request.getBodyParams()); + final List allParams = queryParams.getParams(); + + Collections.sort(allParams); + + final String stringParams = allParams.stream() + .map(param -> param.getKey() + '=' + param.getValue()) + .collect(Collectors.joining()); + + final String sigSource = URLDecoder.decode(stringParams, CharEncoding.UTF_8) + tokenDigest; + request.addQuerystringParameter("sig", md5Hex(sigSource).toLowerCase()); + + super.signRequest(accessToken, request); + } catch (UnsupportedEncodingException unex) { + throw new IllegalStateException(unex); + } + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiServiceImpl.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiServiceImpl.java index 6d3850cc2..6e001447e 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiServiceImpl.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiServiceImpl.java @@ -2,49 +2,15 @@ import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.model.OAuthConfig; -import com.github.scribejava.core.model.OAuthRequest; -import com.github.scribejava.core.model.Parameter; -import com.github.scribejava.core.model.ParameterList; -import com.github.scribejava.core.oauth.OAuth20Service; -import org.apache.commons.codec.CharEncoding; - -import java.io.UnsupportedEncodingException; -import java.net.URLDecoder; -import java.util.Collections; -import java.util.List; -import java.util.stream.Collectors; - -import static org.apache.commons.codec.digest.DigestUtils.md5Hex; - -public class OdnoklassnikiServiceImpl extends OAuth20Service { +/** + * + * @deprecated renamed to {@link OdnoklassnikiOAuthService} + */ +@Deprecated +public class OdnoklassnikiServiceImpl extends OdnoklassnikiOAuthService { public OdnoklassnikiServiceImpl(DefaultApi20 api, OAuthConfig config) { super(api, config); } - - @Override - public void signRequest(String accessToken, OAuthRequest request) { - //sig = lower(md5( sorted_request_params_composed_string + md5(access_token + application_secret_key))) - try { - final String tokenDigest = md5Hex(accessToken + getConfig().getApiSecret()); - - final ParameterList queryParams = request.getQueryStringParams(); - queryParams.addAll(request.getBodyParams()); - final List allParams = queryParams.getParams(); - - Collections.sort(allParams); - - final String stringParams = allParams.stream() - .map(param -> param.getKey() + '=' + param.getValue()) - .collect(Collectors.joining()); - - final String sigSource = URLDecoder.decode(stringParams, CharEncoding.UTF_8) + tokenDigest; - request.addQuerystringParameter("sig", md5Hex(sigSource).toLowerCase()); - - super.signRequest(accessToken, request); - } catch (UnsupportedEncodingException unex) { - throw new IllegalStateException(unex); - } - } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/TutByOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/TutByOAuthService.java new file mode 100644 index 000000000..ea9f8aa7b --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/TutByOAuthService.java @@ -0,0 +1,19 @@ +package com.github.scribejava.apis.service; + +import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.model.OAuthConfig; +import com.github.scribejava.core.model.OAuthConstants; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.oauth.OAuth20Service; + +public class TutByOAuthService extends OAuth20Service { + + public TutByOAuthService(DefaultApi20 api, OAuthConfig config) { + super(api, config); + } + + @Override + public void signRequest(String accessToken, OAuthRequest request) { + request.addQuerystringParameter(OAuthConstants.TOKEN, accessToken); + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/TutByOAuthServiceImpl.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/TutByOAuthServiceImpl.java index b199ac66a..64af14d84 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/TutByOAuthServiceImpl.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/TutByOAuthServiceImpl.java @@ -2,18 +2,15 @@ import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.model.OAuthConfig; -import com.github.scribejava.core.model.OAuthConstants; -import com.github.scribejava.core.model.OAuthRequest; -import com.github.scribejava.core.oauth.OAuth20Service; -public class TutByOAuthServiceImpl extends OAuth20Service { +/** + * + * @deprecated renamed to {@link TutByOAuthService} + */ +@Deprecated +public class TutByOAuthServiceImpl extends TutByOAuthService { public TutByOAuthServiceImpl(DefaultApi20 api, OAuthConfig config) { super(api, config); } - - @Override - public void signRequest(String accessToken, OAuthRequest request) { - request.addQuerystringParameter(OAuthConstants.TOKEN, accessToken); - } } From a4ce21509e9d61053849913f66a55a46b88ffbaa Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 22 Nov 2017 16:42:55 +0300 Subject: [PATCH 424/882] update Facebook v2.8 -> v2.11 --- changelog | 1 + .../main/java/com/github/scribejava/apis/FacebookApi.java | 6 +++--- .../apis/examples/FacebookAsyncApacheExample.java | 2 +- .../scribejava/apis/examples/FacebookAsyncNingExample.java | 2 +- .../github/scribejava/apis/examples/FacebookExample.java | 2 +- 5 files changed, 7 insertions(+), 6 deletions(-) diff --git a/changelog b/changelog index c41771e81..9ccba0fbc 100644 --- a/changelog +++ b/changelog @@ -12,6 +12,7 @@ * drop toString method from *Tokens to prevent leak of sensible data (token ans secrets) (thanks to https://github.com/rcaa) * add Apache HttpComponents HttpClient support in separate module (thanks to https://github.com/sschwieb) * add support for appsecret_proof in Facebook + * update Facebook v2.8 -> v2.11 [4.2.0] * DELETE in JdkClient permits, but not requires payload (thanks to https://github.com/miguelD73) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java index 54f51cc25..f67c36136 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java @@ -10,7 +10,7 @@ import com.github.scribejava.core.model.Verb; /** - * Facebook v2.8 API + * Facebook v2.11 API */ public class FacebookApi extends DefaultApi20 { @@ -33,7 +33,7 @@ public Verb getAccessTokenVerb() { @Override public String getAccessTokenEndpoint() { - return "https://graph.facebook.com/v2.8/oauth/access_token"; + return "https://graph.facebook.com/v2.11/oauth/access_token"; } @Override @@ -43,7 +43,7 @@ public String getRefreshTokenEndpoint() { @Override protected String getAuthorizationBaseUrl() { - return "https://www.facebook.com/v2.8/dialog/oauth"; + return "https://www.facebook.com/v2.11/dialog/oauth"; } @Override diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncApacheExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncApacheExample.java index c15406779..461576775 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncApacheExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncApacheExample.java @@ -16,7 +16,7 @@ public final class FacebookAsyncApacheExample { private static final String NETWORK_NAME = "Facebook"; - private static final String PROTECTED_RESOURCE_URL = "https://graph.facebook.com/v2.8/me"; + private static final String PROTECTED_RESOURCE_URL = "https://graph.facebook.com/v2.11/me"; private FacebookAsyncApacheExample() { } diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java index 73062a43c..292d1b9f2 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java @@ -17,7 +17,7 @@ public final class FacebookAsyncNingExample { private static final String NETWORK_NAME = "Facebook"; - private static final String PROTECTED_RESOURCE_URL = "https://graph.facebook.com/v2.8/me"; + private static final String PROTECTED_RESOURCE_URL = "https://graph.facebook.com/v2.11/me"; private FacebookAsyncNingExample() { } diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java index c4c54897d..c0721835d 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java @@ -15,7 +15,7 @@ public final class FacebookExample { private static final String NETWORK_NAME = "Facebook"; - private static final String PROTECTED_RESOURCE_URL = "https://graph.facebook.com/v2.8/me"; + private static final String PROTECTED_RESOURCE_URL = "https://graph.facebook.com/v2.11/me"; private FacebookExample() { } From dace89cb48934d553bce5087a55b56ccfb467003 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 22 Nov 2017 16:46:09 +0300 Subject: [PATCH 425/882] update some deps --- pom.xml | 4 ++-- scribejava-httpclient-okhttp/pom.xml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 3af42a45a..1b9cfb537 100644 --- a/pom.xml +++ b/pom.xml @@ -100,7 +100,7 @@ com.squareup.okhttp3 mockwebserver - 3.9.0 + 3.9.1 test @@ -139,7 +139,7 @@ com.puppycrawl.tools checkstyle - 8.3 + 8.4 diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index e63a88568..7c78aa158 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -23,7 +23,7 @@ com.squareup.okhttp3 okhttp - 3.9.0 + 3.9.1 com.github.scribejava From f7f19b137a6d2c30e95351df323f697a0875368e Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 22 Nov 2017 17:00:15 +0300 Subject: [PATCH 426/882] version of Facebook API can be configured while constructing OAuthService - use FacebookApi.customVersion("2.11") --- changelog | 2 +- .../com/github/scribejava/apis/FacebookApi.java | 17 ++++++++++++++--- .../apis/examples/Google20RevokeExample.java | 3 ++- .../VkontakteClientCredentialsGrantExample.java | 2 +- 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/changelog b/changelog index 9ccba0fbc..12ca3a11d 100644 --- a/changelog +++ b/changelog @@ -12,7 +12,7 @@ * drop toString method from *Tokens to prevent leak of sensible data (token ans secrets) (thanks to https://github.com/rcaa) * add Apache HttpComponents HttpClient support in separate module (thanks to https://github.com/sschwieb) * add support for appsecret_proof in Facebook - * update Facebook v2.8 -> v2.11 + * update Facebook v2.8 -> v2.11 (version can be configured while constructing OAuthService - use FacebookApi.customVersion("2.11")) [4.2.0] * DELETE in JdkClient permits, but not requires payload (thanks to https://github.com/miguelD73) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java index f67c36136..949304dfb 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java @@ -10,11 +10,18 @@ import com.github.scribejava.core.model.Verb; /** - * Facebook v2.11 API + * Facebook API */ public class FacebookApi extends DefaultApi20 { + private final String version; + protected FacebookApi() { + this("2.11"); + } + + protected FacebookApi(String version) { + this.version = version; } private static class InstanceHolder { @@ -26,6 +33,10 @@ public static FacebookApi instance() { return InstanceHolder.INSTANCE; } + public static FacebookApi customVersion(String version) { + return new FacebookApi(version); + } + @Override public Verb getAccessTokenVerb() { return Verb.GET; @@ -33,7 +44,7 @@ public Verb getAccessTokenVerb() { @Override public String getAccessTokenEndpoint() { - return "https://graph.facebook.com/v2.11/oauth/access_token"; + return "https://graph.facebook.com/v" + version + "/oauth/access_token"; } @Override @@ -43,7 +54,7 @@ public String getRefreshTokenEndpoint() { @Override protected String getAuthorizationBaseUrl() { - return "https://www.facebook.com/v2.11/dialog/oauth"; + return "https://www.facebook.com/v" + version + "/dialog/oauth"; } @Override diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20RevokeExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20RevokeExample.java index 7e677731c..89d36be2c 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20RevokeExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20RevokeExample.java @@ -86,7 +86,8 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Revoking token..."); service.revokeToken(accessToken.getAccessToken()); System.out.println("done."); - System.out.println("After revoke we should fail requesting any data..."); + System.out.println("After revoke we should fail requesting any data... Press enter to try"); + in.nextLine(); //Google Note: Following a successful revocation response, //it might take some time before the revocation has full effect. while (response.getCode() == 200) { diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteClientCredentialsGrantExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteClientCredentialsGrantExample.java index b91b115f3..0ffc2fc13 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteClientCredentialsGrantExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteClientCredentialsGrantExample.java @@ -29,7 +29,7 @@ public static void main(String... args) throws IOException, InterruptedException final OAuth2AccessToken accessToken = service.getAccessTokenClientCredentialsGrant(); System.out.println("Got the Access Token!"); - System.out.println(accessToken); + System.out.println(accessToken.getRawResponse()); System.out.println(); System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); From 6024845ce66bf60d37e917a863a4ae137aef4cfb Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 22 Nov 2017 17:06:59 +0300 Subject: [PATCH 427/882] prepare 5.0.0 --- README.md | 9 +++++---- changelog | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 567d5075b..a8ed20a7f 100644 --- a/README.md +++ b/README.md @@ -28,9 +28,10 @@ Hit ScribeJava as hard and with many threads as you like. ScribeJava support out-of-box several HTTP clients: * ning async http client 1.9.x (maven module scribejava-httpclient-ning) - * asynchttpclient 2.x (maven module scribejava-httpclient-ahc) + * Async Http Client asynchttpclient 2.x (maven module scribejava-httpclient-ahc) * OkHttp (maven module scribejava-httpclient-okhttp) - + * Apache HttpComponents HttpClient (maven module scribejava-httpclient-apache) + just add corresponding maven modules to your pom ### Supports all major 1.0a and 2.0 OAuth APIs out-of-the-box @@ -102,7 +103,7 @@ You can pull ScribeJava from the central maven repository, just add these to you com.github.scribejava scribejava-apis - 4.2.0 + 5.0.0 ``` @@ -111,7 +112,7 @@ And in case you need just core classes (that's it, without any external API (FB, com.github.scribejava scribejava-core - 4.2.0 + 5.0.0 ``` diff --git a/changelog b/changelog index 12ca3a11d..c1a691a34 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,4 @@ -[SNAPSHOT] +[5.0.0] * drop Java 7 backward compatibility support, become Java 8 only * add JSON token extractor for OAuth 1.0a (thanks to https://github.com/evstropovv) * add new API - uCoz (https://www.ucoz.com/) (thanks to https://github.com/evstropovv) From 69613265c6cf121b5c9687cd2966eb116674dd21 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 22 Nov 2017 17:08:11 +0300 Subject: [PATCH 428/882] [maven-release-plugin] prepare release scribejava-5.0.0 --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index 1b9cfb537..41b4cbce7 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 4.2.1-SNAPSHOT + 5.0.0 ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -34,7 +34,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - HEAD + scribejava-5.0.0 diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 2042df1c2..e4a8d7bdd 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 4.2.1-SNAPSHOT + 5.0.0 ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index bfb71c2bf..082932072 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 4.2.1-SNAPSHOT + 5.0.0 ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 7cff01618..a1b042a86 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 4.2.1-SNAPSHOT + 5.0.0 ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index c004c990d..b9708b4d5 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 4.2.1-SNAPSHOT + 5.0.0 ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index 04551b961..ca7a29ba9 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 4.2.1-SNAPSHOT + 5.0.0 ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 7c78aa158..25d9149ed 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 4.2.1-SNAPSHOT + 5.0.0 ../pom.xml From 4f2743793f408e285bcc42b1a5e03f789f0a7483 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 22 Nov 2017 17:08:18 +0300 Subject: [PATCH 429/882] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index 41b4cbce7..eb85fa190 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 5.0.0 + 5.0.1-SNAPSHOT ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -34,7 +34,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - scribejava-5.0.0 + HEAD diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index e4a8d7bdd..9a7b21a63 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.0.0 + 5.0.1-SNAPSHOT ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 082932072..3af1df7aa 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.0.0 + 5.0.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index a1b042a86..5a35925a3 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.0.0 + 5.0.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index b9708b4d5..95b48da1b 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.0.0 + 5.0.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index ca7a29ba9..bb88941ae 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.0.0 + 5.0.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 25d9149ed..c032e7667 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.0.0 + 5.0.1-SNAPSHOT ../pom.xml From 8d1527b5f2e6ad797ce9505cee04e2013b5bf67c Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 22 Nov 2017 17:42:46 +0300 Subject: [PATCH 430/882] drop optional dependency on Apache commons-codec --- changelog | 3 ++ pom.xml | 7 ---- .../apis/service/ImgurOAuthServiceImpl.java | 16 --------- .../apis/service/MailruOAuthService.java | 26 +++++++++++--- .../apis/service/MailruOAuthServiceImpl.java | 16 --------- .../service/OdnoklassnikiOAuthService.java | 30 +++++++++++----- .../service/OdnoklassnikiServiceImpl.java | 16 --------- .../apis/service/TutByOAuthServiceImpl.java | 16 --------- .../apis/examples/RenrenExample.java | 13 ++++--- .../core/builder/api/OAuth2SignatureType.java | 12 ------- .../core/pkce/PKCECodeChallengeMethod.java | 3 +- .../core/services/Base64Encoder.java | 32 ----------------- .../core/services/CommonsEncoder.java | 35 ------------------- .../services/DatatypeConverterEncoder.java | 20 ----------- .../core/oauth/OAuth20ServiceTest.java | 12 ++++--- 15 files changed, 60 insertions(+), 197 deletions(-) delete mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthServiceImpl.java delete mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthServiceImpl.java delete mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiServiceImpl.java delete mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/service/TutByOAuthServiceImpl.java delete mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/services/Base64Encoder.java delete mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/services/CommonsEncoder.java delete mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/services/DatatypeConverterEncoder.java diff --git a/changelog b/changelog index c1a691a34..a05a60c6e 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,6 @@ +[SNAPSHOT] + * drop optional dependency on Apache commons-codec + [5.0.0] * drop Java 7 backward compatibility support, become Java 8 only * add JSON token extractor for OAuth 1.0a (thanks to https://github.com/evstropovv) diff --git a/pom.xml b/pom.xml index eb85fa190..5fda43fc8 100644 --- a/pom.xml +++ b/pom.xml @@ -90,13 +90,6 @@ 2.8.2 test - - commons-codec - commons-codec - 1.11 - compile - true - com.squareup.okhttp3 mockwebserver diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthServiceImpl.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthServiceImpl.java deleted file mode 100644 index b7ee9b1ad..000000000 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthServiceImpl.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.github.scribejava.apis.service; - -import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.model.OAuthConfig; - -/** - * - * @deprecated renamed to {@link ImgurOAuthService} - */ -@Deprecated -public class ImgurOAuthServiceImpl extends ImgurOAuthService { - - public ImgurOAuthServiceImpl(DefaultApi20 api, OAuthConfig config) { - super(api, config); - } -} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthService.java index 0e426f337..625140ed9 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthService.java @@ -1,15 +1,17 @@ package com.github.scribejava.apis.service; -import java.io.UnsupportedEncodingException; import java.net.URLDecoder; import java.util.Map; import java.util.TreeMap; -import org.apache.commons.codec.CharEncoding; -import static org.apache.commons.codec.digest.DigestUtils.md5Hex; import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.oauth.OAuth20Service; +import java.io.UnsupportedEncodingException; +import java.nio.charset.Charset; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.util.Formatter; import java.util.stream.Collectors; public class MailruOAuthService extends OAuth20Service { @@ -38,11 +40,25 @@ public void signRequest(String accessToken, OAuthRequest request) { final String urlNew = map.entrySet().stream() .map(entry -> entry.getKey() + '=' + entry.getValue()) .collect(Collectors.joining()); - final String sigSource = URLDecoder.decode(urlNew, CharEncoding.UTF_8) + clientSecret; - request.addQuerystringParameter("sig", md5Hex(sigSource)); + final String sigSource = URLDecoder.decode(urlNew, "UTF-8") + clientSecret; + request.addQuerystringParameter("sig", md5(sigSource)); } } catch (UnsupportedEncodingException e) { throw new IllegalStateException(e); } } + + public static String md5(String orgString) { + try { + final MessageDigest md = MessageDigest.getInstance("MD5"); + final byte[] array = md.digest(orgString.getBytes(Charset.forName("UTF-8"))); + final Formatter builder = new Formatter(); + for (byte b : array) { + builder.format("%02x", b); + } + return builder.toString(); + } catch (NoSuchAlgorithmException e) { + throw new IllegalStateException("MD5 is unsupported?", e); + } + } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthServiceImpl.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthServiceImpl.java deleted file mode 100644 index 4301fd8fb..000000000 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthServiceImpl.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.github.scribejava.apis.service; - -import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.model.OAuthConfig; - -/** - * - * @deprecated renamed to {@link MailruOAuthService} - */ -@Deprecated -public class MailruOAuthServiceImpl extends MailruOAuthService { - - public MailruOAuthServiceImpl(DefaultApi20 api, OAuthConfig config) { - super(api, config); - } -} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiOAuthService.java index 0bf117edd..4b0ea020b 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiOAuthService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiOAuthService.java @@ -6,17 +6,17 @@ import com.github.scribejava.core.model.Parameter; import com.github.scribejava.core.model.ParameterList; import com.github.scribejava.core.oauth.OAuth20Service; - -import org.apache.commons.codec.CharEncoding; - import java.io.UnsupportedEncodingException; + import java.net.URLDecoder; +import java.nio.charset.Charset; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; import java.util.Collections; +import java.util.Formatter; import java.util.List; import java.util.stream.Collectors; -import static org.apache.commons.codec.digest.DigestUtils.md5Hex; - public class OdnoklassnikiOAuthService extends OAuth20Service { public OdnoklassnikiOAuthService(DefaultApi20 api, OAuthConfig config) { @@ -27,7 +27,7 @@ public OdnoklassnikiOAuthService(DefaultApi20 api, OAuthConfig config) { public void signRequest(String accessToken, OAuthRequest request) { //sig = lower(md5( sorted_request_params_composed_string + md5(access_token + application_secret_key))) try { - final String tokenDigest = md5Hex(accessToken + getConfig().getApiSecret()); + final String tokenDigest = md5(accessToken + getConfig().getApiSecret()); final ParameterList queryParams = request.getQueryStringParams(); queryParams.addAll(request.getBodyParams()); @@ -39,12 +39,26 @@ public void signRequest(String accessToken, OAuthRequest request) { .map(param -> param.getKey() + '=' + param.getValue()) .collect(Collectors.joining()); - final String sigSource = URLDecoder.decode(stringParams, CharEncoding.UTF_8) + tokenDigest; - request.addQuerystringParameter("sig", md5Hex(sigSource).toLowerCase()); + final String sigSource = URLDecoder.decode(stringParams, "UTF-8") + tokenDigest; + request.addQuerystringParameter("sig", md5(sigSource).toLowerCase()); super.signRequest(accessToken, request); } catch (UnsupportedEncodingException unex) { throw new IllegalStateException(unex); } } + + public static String md5(String orgString) { + try { + final MessageDigest md = MessageDigest.getInstance("MD5"); + final byte[] array = md.digest(orgString.getBytes(Charset.forName("UTF-8"))); + final Formatter builder = new Formatter(); + for (byte b : array) { + builder.format("%02x", b); + } + return builder.toString(); + } catch (NoSuchAlgorithmException e) { + throw new IllegalStateException("MD5 is unsupported?", e); + } + } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiServiceImpl.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiServiceImpl.java deleted file mode 100644 index 6e001447e..000000000 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiServiceImpl.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.github.scribejava.apis.service; - -import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.model.OAuthConfig; - -/** - * - * @deprecated renamed to {@link OdnoklassnikiOAuthService} - */ -@Deprecated -public class OdnoklassnikiServiceImpl extends OdnoklassnikiOAuthService { - - public OdnoklassnikiServiceImpl(DefaultApi20 api, OAuthConfig config) { - super(api, config); - } -} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/TutByOAuthServiceImpl.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/TutByOAuthServiceImpl.java deleted file mode 100644 index 64af14d84..000000000 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/TutByOAuthServiceImpl.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.github.scribejava.apis.service; - -import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.model.OAuthConfig; - -/** - * - * @deprecated renamed to {@link TutByOAuthService} - */ -@Deprecated -public class TutByOAuthServiceImpl extends TutByOAuthService { - - public TutByOAuthServiceImpl(DefaultApi20 api, OAuthConfig config) { - super(api, config); - } -} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java index 621566f6e..31f043d6e 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java @@ -15,6 +15,7 @@ import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.oauth.OAuth20Service; import java.io.IOException; +import java.util.Formatter; import java.util.concurrent.ExecutionException; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -96,15 +97,13 @@ public static String md5(String orgString) { try { final MessageDigest md = MessageDigest.getInstance("MD5"); final byte[] array = md.digest(orgString.getBytes(Charset.forName("UTF-8"))); - final StringBuffer sb = new StringBuffer(); - for (int i = 0; i < array.length; ++i) { - sb.append(Integer.toHexString((array[i] & 0xFF) | 0x100).substring(1, 3)); + final Formatter builder = new Formatter(); + for (byte b : array) { + builder.format("%02x", b); } - return sb.toString(); + return builder.toString(); } catch (NoSuchAlgorithmException e) { - e.printStackTrace(); + throw new IllegalStateException("MD5 is unsupported?", e); } - return null; } - } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/OAuth2SignatureType.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/OAuth2SignatureType.java index b2334be32..c42b54d98 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/OAuth2SignatureType.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/OAuth2SignatureType.java @@ -1,6 +1,5 @@ package com.github.scribejava.core.builder.api; -import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.OAuthRequest; @@ -26,16 +25,5 @@ public void signRequest(String accessToken, OAuthRequest request) { }; - /** - * - * @param accessToken accessToken - * @param request request - * @deprecated use {@link #signRequest(java.lang.String, com.github.scribejava.core.model.OAuthRequest)} - */ - @Deprecated - public void signRequest(OAuth2AccessToken accessToken, OAuthRequest request) { - signRequest(accessToken == null ? null : accessToken.getAccessToken(), request); - } - public abstract void signRequest(String accessToken, OAuthRequest request); } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/pkce/PKCECodeChallengeMethod.java b/scribejava-core/src/main/java/com/github/scribejava/core/pkce/PKCECodeChallengeMethod.java index e8e6cb6e2..69dbe17c6 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/pkce/PKCECodeChallengeMethod.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/pkce/PKCECodeChallengeMethod.java @@ -12,8 +12,7 @@ public enum PKCECodeChallengeMethod { @Override public String transform2CodeChallenge(String codeVerifier) throws NoSuchAlgorithmException { return base64Encoder.encodeToString( - MessageDigest.getInstance("SHA-256").digest( - codeVerifier.getBytes(StandardCharsets.US_ASCII))); + MessageDigest.getInstance("SHA-256").digest(codeVerifier.getBytes(StandardCharsets.US_ASCII))); } }, plain { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/services/Base64Encoder.java b/scribejava-core/src/main/java/com/github/scribejava/core/services/Base64Encoder.java deleted file mode 100644 index 26285cda4..000000000 --- a/scribejava-core/src/main/java/com/github/scribejava/core/services/Base64Encoder.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.github.scribejava.core.services; - -/** - * @deprecated use standard java8 java.util.Base64 - */ -@Deprecated -public abstract class Base64Encoder { - - private static class InstanceHolder { - private static final Base64Encoder INSTANCE = createEncoderInstance(); - } - - public static Base64Encoder getInstance() { - return InstanceHolder.INSTANCE; - } - - private static Base64Encoder createEncoderInstance() { - if (CommonsEncoder.isPresent()) { - return new CommonsEncoder(); - } else { - return new DatatypeConverterEncoder(); - } - } - - public static String type() { - return getInstance().getType(); - } - - public abstract String encode(byte[] bytes); - - public abstract String getType(); -} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/services/CommonsEncoder.java b/scribejava-core/src/main/java/com/github/scribejava/core/services/CommonsEncoder.java deleted file mode 100644 index c982abfcd..000000000 --- a/scribejava-core/src/main/java/com/github/scribejava/core/services/CommonsEncoder.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.github.scribejava.core.services; - -import java.io.UnsupportedEncodingException; -import org.apache.commons.codec.binary.Base64; -import com.github.scribejava.core.exceptions.OAuthSignatureException; - -/** - * @deprecated use standard java8 java.util.Base64 - */ -@Deprecated -public class CommonsEncoder extends Base64Encoder { - - @Override - public String encode(byte[] bytes) { - try { - return new String(Base64.encodeBase64(bytes), "UTF-8"); - } catch (UnsupportedEncodingException e) { - throw new OAuthSignatureException("Can't perform base64 encoding", e); - } - } - - @Override - public String getType() { - return "CommonsCodec"; - } - - public static boolean isPresent() { - try { - Class.forName("org.apache.commons.codec.binary.Base64"); - return true; - } catch (ClassNotFoundException e) { - return false; - } - } -} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/services/DatatypeConverterEncoder.java b/scribejava-core/src/main/java/com/github/scribejava/core/services/DatatypeConverterEncoder.java deleted file mode 100644 index cfc8c2ef2..000000000 --- a/scribejava-core/src/main/java/com/github/scribejava/core/services/DatatypeConverterEncoder.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.github.scribejava.core.services; - -import javax.xml.bind.DatatypeConverter; - -/** - * @deprecated use standard java8 java.util.Base64 - */ -@Deprecated -public class DatatypeConverterEncoder extends Base64Encoder { - - @Override - public String encode(byte[] bytes) { - return DatatypeConverter.printBase64Binary(bytes); - } - - @Override - public String getType() { - return "DatatypeConverter"; - } -} diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceTest.java index 581fc5a63..f62c49e86 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceTest.java @@ -4,7 +4,6 @@ import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuth2Authorization; import com.github.scribejava.core.model.OAuthConstants; -import com.github.scribejava.core.services.Base64Encoder; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; import java.io.IOException; @@ -13,11 +12,14 @@ import org.junit.Test; import java.nio.charset.Charset; +import java.util.Base64; import java.util.Map; import java.util.concurrent.ExecutionException; public class OAuth20ServiceTest { + private final Base64.Encoder base64Encoder = Base64.getEncoder(); + @Test public void shouldProduceCorrectRequestSync() throws IOException, InterruptedException, ExecutionException { final OAuth20Service service = new ServiceBuilder("your_api_key") @@ -35,8 +37,8 @@ public void shouldProduceCorrectRequestSync() throws IOException, InterruptedExc assertEquals(OAuth20ServiceUnit.STATE, map.get(OAuthConstants.STATE)); assertEquals(OAuth20ServiceUnit.EXPIRES, map.get("expires_in")); - final String authorize = Base64Encoder.getInstance() - .encode(String.format("%s:%s", service.getConfig().getApiKey(), service.getConfig().getApiSecret()) + final String authorize = base64Encoder.encodeToString( + String.format("%s:%s", service.getConfig().getApiKey(), service.getConfig().getApiSecret()) .getBytes(Charset.forName("UTF-8"))); assertEquals(OAuthConstants.BASIC + " " + authorize, map.get(OAuthConstants.HEADER)); @@ -63,8 +65,8 @@ public void shouldProduceCorrectRequestAsync() throws ExecutionException, Interr assertEquals(OAuth20ServiceUnit.STATE, map.get(OAuthConstants.STATE)); assertEquals(OAuth20ServiceUnit.EXPIRES, map.get("expires_in")); - final String authorize = Base64Encoder.getInstance() - .encode(String.format("%s:%s", service.getConfig().getApiKey(), service.getConfig().getApiSecret()) + final String authorize = base64Encoder.encodeToString( + String.format("%s:%s", service.getConfig().getApiKey(), service.getConfig().getApiSecret()) .getBytes(Charset.forName("UTF-8"))); assertEquals(OAuthConstants.BASIC + " " + authorize, map.get(OAuthConstants.HEADER)); From aa6098bffa9ae3a7876a5419f91c78c79acfcab2 Mon Sep 17 00:00:00 2001 From: Ruben Andreassen Date: Sun, 3 Dec 2017 20:08:32 +0100 Subject: [PATCH 431/882] Added DataportenApi --- .../github/scribejava/apis/DataportenApi.java | 41 ++++++++++ .../apis/examples/DataportenExample.java | 81 +++++++++++++++++++ 2 files changed, 122 insertions(+) create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/DataportenApi.java create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DataportenExample.java diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/DataportenApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/DataportenApi.java new file mode 100644 index 000000000..99acbd4df --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/DataportenApi.java @@ -0,0 +1,41 @@ +package com.github.scribejava.apis; + +import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; +import com.github.scribejava.core.extractors.TokenExtractor; +import com.github.scribejava.core.model.OAuth2AccessToken; +import com.github.scribejava.core.model.Verb; + +public class DataportenApi extends DefaultApi20 { + + protected DataportenApi() { + } + + private static class InstanceHolder { + private static final DataportenApi INSTANCE = new DataportenApi(); + } + + public static DataportenApi instance() { + return InstanceHolder.INSTANCE; + } + + @Override + public Verb getAccessTokenVerb() { + return Verb.POST; + } + + @Override + public String getAccessTokenEndpoint() { + return "https://auth.dataporten.no/oauth/token"; + } + + @Override + protected String getAuthorizationBaseUrl() { + return "https://auth.dataporten.no/oauth/authorization"; + } + + @Override + public TokenExtractor getAccessTokenExtractor() { + return OAuth2AccessTokenJsonExtractor.instance(); + } +} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DataportenExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DataportenExample.java new file mode 100644 index 000000000..00b75c26d --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DataportenExample.java @@ -0,0 +1,81 @@ +package com.github.scribejava.apis.examples; + +import java.util.Random; +import java.util.Scanner; +import com.github.scribejava.apis.DataportenApi; +import com.github.scribejava.core.builder.ServiceBuilder; +import com.github.scribejava.core.model.OAuth2AccessToken; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.oauth.OAuth20Service; +import java.io.IOException; +import java.util.concurrent.ExecutionException; + +public final class DataportenExample { + + private static final String NETWORK_NAME = "Dataporten"; + private static final String PROTECTED_RESOURCE_URL = "https://auth.dataporten.no/userinfo"; + + private DataportenExample() { + } + + public static void main(String... args) throws IOException, InterruptedException, ExecutionException { + // Replace these with your client id and secret + final String clientId = "your client id"; + final String clientSecret = "your client secret"; + final String secretState = "secret" + new Random().nextInt(999_999); + final OAuth20Service service = new ServiceBuilder(clientId) + .apiSecret(clientSecret) + .state(secretState) + .callback("http://www.example.com/oauth_callback/") + .build(DataportenApi.instance()); + final Scanner in = new Scanner(System.in, "UTF-8"); + + System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); + System.out.println(); + + // Obtain the Authorization URL + System.out.println("Fetching the Authorization URL..."); + final String authorizationUrl = service.getAuthorizationUrl(); + System.out.println("Got the Authorization URL!"); + System.out.println("Now go and authorize ScribeJava here:"); + System.out.println(authorizationUrl); + System.out.println("And paste the authorization code here"); + System.out.print(">>"); + final String code = in.nextLine(); + System.out.println(); + + System.out.println("And paste the state from server here. We have set 'secretState'='" + secretState + "'."); + System.out.print(">>"); + final String value = in.nextLine(); + if (secretState.equals(value)) { + System.out.println("State value does match!"); + } else { + System.out.println("Ooops, state value does not match!"); + System.out.println("Expected = " + secretState); + System.out.println("Got = " + value); + System.out.println(); + } + + // Trade the Request Token and Verfier for the Access Token + System.out.println("Trading the Request Token for an Access Token..."); + final OAuth2AccessToken accessToken = service.getAccessToken(code); + System.out.println("Got the Access Token!"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); + System.out.println(); + + // Now let's go and ask for a protected resource! + System.out.println("Now we're going to access a protected resource..."); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); + service.signRequest(accessToken, request); + final Response response = service.execute(request); + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + + System.out.println(); + System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); + } +} From dc5f6acfb55455148f5aca6b6ec99164c8413624 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 4 Dec 2017 13:51:14 +0300 Subject: [PATCH 432/882] add API - Dataporten (https://docs.dataporten.no/) (thanks to https://github.com/xibriz) --- README.md | 1 + changelog | 1 + .../com/github/scribejava/apis/DataportenApi.java | 14 -------------- 3 files changed, 2 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index a8ed20a7f..9ce7bba1a 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,7 @@ ScribeJava support out-of-box several HTTP clients: * AWeber (http://www.aweber.com/) * Box (https://www.box.com/) +* Dataporten (https://docs.dataporten.no/) * Digg (http://digg.com/) * Доктор на работе (https://www.doktornarabote.ru/) * Etsy (https://www.etsy.com/) diff --git a/changelog b/changelog index a05a60c6e..f26621947 100644 --- a/changelog +++ b/changelog @@ -1,5 +1,6 @@ [SNAPSHOT] * drop optional dependency on Apache commons-codec + * add API - Dataporten (https://docs.dataporten.no/) (thanks to https://github.com/xibriz) [5.0.0] * drop Java 7 backward compatibility support, become Java 8 only diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/DataportenApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/DataportenApi.java index 99acbd4df..5e7ad9ceb 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/DataportenApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/DataportenApi.java @@ -1,10 +1,6 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; -import com.github.scribejava.core.extractors.TokenExtractor; -import com.github.scribejava.core.model.OAuth2AccessToken; -import com.github.scribejava.core.model.Verb; public class DataportenApi extends DefaultApi20 { @@ -19,11 +15,6 @@ public static DataportenApi instance() { return InstanceHolder.INSTANCE; } - @Override - public Verb getAccessTokenVerb() { - return Verb.POST; - } - @Override public String getAccessTokenEndpoint() { return "https://auth.dataporten.no/oauth/token"; @@ -33,9 +24,4 @@ public String getAccessTokenEndpoint() { protected String getAuthorizationBaseUrl() { return "https://auth.dataporten.no/oauth/authorization"; } - - @Override - public TokenExtractor getAccessTokenExtractor() { - return OAuth2AccessTokenJsonExtractor.instance(); - } } From edc8222b2d2b3ab89b090e6730359a5d9ffeef31 Mon Sep 17 00:00:00 2001 From: Kaushal Mall Date: Mon, 4 Dec 2017 15:08:31 -0700 Subject: [PATCH 433/882] New files for Azure Active Directory OAuth Api + updates to OAuthConstants class. --- .../apis/AzureActiveDirectoryApi.java | 85 +++++++++++++++++++ .../service/AzureActiveDirectoryService.java | 47 ++++++++++ .../apis/examples/MicrosoftAzureExample.java | 67 +++++++++++++++ .../scribejava/core/model/OAuthConstants.java | 7 +- 4 files changed, 205 insertions(+), 1 deletion(-) create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/AzureActiveDirectoryApi.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/service/AzureActiveDirectoryService.java create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureExample.java diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/AzureActiveDirectoryApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/AzureActiveDirectoryApi.java new file mode 100644 index 000000000..b14de7380 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/AzureActiveDirectoryApi.java @@ -0,0 +1,85 @@ +package com.github.scribejava.apis; + +import com.github.scribejava.apis.service.AzureActiveDirectoryService; +import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; +import com.github.scribejava.core.extractors.TokenExtractor; +import com.github.scribejava.core.model.OAuth2AccessToken; +import com.github.scribejava.core.model.OAuthConfig; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.utils.OAuthEncoder; + +import java.util.Map; + +/** + * Microsoft Azure Active Directory Api + * + * Some helpful links + * https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-protocols-oauth-code + * https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-devquickstarts-webapp-java + * https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/signed-in-user-operations + * https://portal.azure.com + */ +public class AzureActiveDirectoryApi extends DefaultApi20 { + + private static final String MSFT_GRAPH_URL = "https://graph.windows.net"; + + private static final String AUTHORIZE_URL = "?client_id=%s&redirect_uri=%s&response_type=code&resource=" + + MSFT_GRAPH_URL; + private static final String SCOPED_AUTHORIZE_URL = AUTHORIZE_URL + "&scope=%s"; + + private static final String MSFT_LOGIN_URL = "https://login.microsoftonline.com"; + private static final String SLASH = "/"; + private static final String COMMON = "common"; + private static final String TOKEN_URI = "oauth2/token"; + private static final String AUTH_URI = "oauth2/authorize"; + + private static class InstanceHolder { + + private static final AzureActiveDirectoryApi INSTANCE = new AzureActiveDirectoryApi(); + } + + public static AzureActiveDirectoryApi instance() { + return AzureActiveDirectoryApi.InstanceHolder.INSTANCE; + } + + @Override + public String getAccessTokenEndpoint() { + return MSFT_LOGIN_URL + SLASH + COMMON + SLASH + TOKEN_URI; + } + + @Override + protected String getAuthorizationBaseUrl() { + return MSFT_LOGIN_URL + SLASH + COMMON + SLASH + AUTH_URI; + } + + @Override + public Verb getAccessTokenVerb() { + return Verb.POST; + } + + @Override + public AzureActiveDirectoryService createService(OAuthConfig config) { + return new AzureActiveDirectoryService(this, config); + } + + @Override + public TokenExtractor getAccessTokenExtractor() { + return OAuth2AccessTokenJsonExtractor.instance(); + } + + @Override + public String getAuthorizationUrl(OAuthConfig config, Map additionalParams) { + + String scope = config.getScope(); + + if ( scope == null ) { + return MSFT_LOGIN_URL + SLASH + COMMON + SLASH + AUTH_URI + String.format(SCOPED_AUTHORIZE_URL, config.getApiKey(), + OAuthEncoder.encode(config.getCallback()), OAuthEncoder.encode(config.getScope())); + } else { + return MSFT_LOGIN_URL + SLASH + COMMON + SLASH + AUTH_URI + + String.format(AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback())); + } + } + +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/AzureActiveDirectoryService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/AzureActiveDirectoryService.java new file mode 100644 index 000000000..fad1da6d2 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/AzureActiveDirectoryService.java @@ -0,0 +1,47 @@ +package com.github.scribejava.apis.service; + +import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.model.OAuthConfig; +import com.github.scribejava.core.model.OAuthConstants; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.oauth.OAuth20Service; + +public class AzureActiveDirectoryService extends OAuth20Service { + + private final DefaultApi20 api; + + public AzureActiveDirectoryService(DefaultApi20 api, OAuthConfig config) { + super(api, config); + this.api = api; + } + + @Override + public OAuthRequest createAccessTokenRequest(String code) { + final OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint()); + final OAuthConfig config = getConfig(); + + request.addHeader(OAuthConstants.CONTENT_TYPE, OAuthConstants.APPLICATION_X_WWW_FORM_URLENCODED); + + request.addBodyParameter(OAuthConstants.CLIENT_ID, config.getApiKey()); + final String apiSecret = config.getApiSecret(); + if (apiSecret != null) { + request.addBodyParameter(OAuthConstants.CLIENT_SECRET, apiSecret); + } + request.addBodyParameter(OAuthConstants.CODE, code); + request.addBodyParameter(OAuthConstants.REDIRECT_URI, config.getCallback()); + final String scope = config.getScope(); + if (scope != null) { + request.addBodyParameter(OAuthConstants.SCOPE, scope); + } + request.addBodyParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.AUTHORIZATION_CODE); + + return request; + } + + @Override + public void signRequest(String accessToken, OAuthRequest request) { + request.addHeader(OAuthConstants.AUTHORIZATION, OAuthConstants.BEARER + accessToken); + request.addHeader(OAuthConstants.ACCEPT, + OAuthConstants.APPLICATION_JSON_ODATA_MINIMALMETADATA_STREAMING_TRUE_CHARSET_UTF_8); + } +} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureExample.java new file mode 100644 index 000000000..fc5d97eaf --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureExample.java @@ -0,0 +1,67 @@ +package com.github.scribejava.apis.examples; + +import com.github.scribejava.apis.AzureActiveDirectoryApi; +import com.github.scribejava.core.builder.ServiceBuilder; +import com.github.scribejava.core.model.OAuth2AccessToken; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.oauth.OAuth20Service; + +import java.io.IOException; +import java.util.Scanner; +import java.util.concurrent.ExecutionException; + + + +public class MicrosoftAzureExample { + + private static final String NETWORK_NAME = "Microsoft Azure Active Directory"; + private static final String PROTECTED_RESOURCE_URL = "https://graph.windows.net/me?api-version=1.6"; + + public static void main(String... args) throws IOException, InterruptedException, ExecutionException { + // Replace these with your client id and secret + final String clientId = "client id here"; + final String clientSecret = "client secret here"; + final OAuth20Service service = new ServiceBuilder(clientId) + .apiSecret(clientSecret) + .scope( "openid" ) + .callback("http://www.example.com/oauth_callback/") + .build(AzureActiveDirectoryApi.instance()); + final Scanner in = new Scanner(System.in, "UTF-8"); + + System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); + System.out.println(); + + // Obtain the Authorization URL + System.out.println("Fetching the Authorization URL..."); + final String authorizationUrl = service.getAuthorizationUrl(); + System.out.println("Got the Authorization URL!"); + System.out.println("Now go and authorize ScribeJava here:"); + System.out.println(authorizationUrl); + System.out.println("And paste the authorization code here"); + System.out.print(">>"); + final String code = in.nextLine(); + System.out.println(); + + // Trade the Request Token and Verfier for the Access Token + System.out.println("Trading the Request Token for an Access Token..."); + final OAuth2AccessToken accessToken = service.getAccessToken(code); + System.out.println("Got the Access Token!"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); + System.out.println(); + + // Now let's go and ask for a protected resource! + System.out.println("Now we're going to access a protected resource..."); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); + service.signRequest(accessToken, request); + final Response response = service.execute(request); + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + + System.out.println(); + System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); + } +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConstants.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConstants.java index 4f79cd355..a86f467b5 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConstants.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConstants.java @@ -41,5 +41,10 @@ public interface OAuthConstants { //not OAuth specific String USER_AGENT_HEADER_NAME = "User-Agent"; - + String CONTENT_TYPE = "Content-Type"; + String APPLICATION_X_WWW_FORM_URLENCODED = "application/x-www-form-urlencoded"; + String AUTHORIZATION = "Authorization"; + String BEARER = "Bearer "; + String ACCEPT = "Accept"; + String APPLICATION_JSON_ODATA_MINIMALMETADATA_STREAMING_TRUE_CHARSET_UTF_8 = "application/json; odata=minimalmetadata; streaming=true; charset=utf-8"; } From 648e95d84bb39ff75907c1b2f2e74005cf275eca Mon Sep 17 00:00:00 2001 From: Kaushal Mall Date: Mon, 4 Dec 2017 16:10:42 -0700 Subject: [PATCH 434/882] updates for checkstyle failure. --- .../scribejava/apis/service/AzureActiveDirectoryService.java | 4 ++-- .../java/com/github/scribejava/core/model/OAuthConstants.java | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/AzureActiveDirectoryService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/AzureActiveDirectoryService.java index fad1da6d2..ccda746c7 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/AzureActiveDirectoryService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/AzureActiveDirectoryService.java @@ -9,6 +9,7 @@ public class AzureActiveDirectoryService extends OAuth20Service { private final DefaultApi20 api; + String ACCEPTED_FORMAT = "application/json; odata=minimalmetadata; streaming=true; charset=utf-8"; public AzureActiveDirectoryService(DefaultApi20 api, OAuthConfig config) { super(api, config); @@ -41,7 +42,6 @@ public OAuthRequest createAccessTokenRequest(String code) { @Override public void signRequest(String accessToken, OAuthRequest request) { request.addHeader(OAuthConstants.AUTHORIZATION, OAuthConstants.BEARER + accessToken); - request.addHeader(OAuthConstants.ACCEPT, - OAuthConstants.APPLICATION_JSON_ODATA_MINIMALMETADATA_STREAMING_TRUE_CHARSET_UTF_8); + request.addHeader(OAuthConstants.ACCEPT, ACCEPTED_FORMAT); } } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConstants.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConstants.java index a86f467b5..1d130fdc8 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConstants.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConstants.java @@ -46,5 +46,4 @@ public interface OAuthConstants { String AUTHORIZATION = "Authorization"; String BEARER = "Bearer "; String ACCEPT = "Accept"; - String APPLICATION_JSON_ODATA_MINIMALMETADATA_STREAMING_TRUE_CHARSET_UTF_8 = "application/json; odata=minimalmetadata; streaming=true; charset=utf-8"; } From 017086c642d3ceb9ca16b295fa9304fcf4841323 Mon Sep 17 00:00:00 2001 From: Kaushal Mall Date: Mon, 4 Dec 2017 16:37:44 -0700 Subject: [PATCH 435/882] more checkstyle changes --- .../github/scribejava/apis/AzureActiveDirectoryApi.java | 7 ++++--- .../apis/service/AzureActiveDirectoryService.java | 3 ++- .../scribejava/apis/examples/MicrosoftAzureExample.java | 6 +++++- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/AzureActiveDirectoryApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/AzureActiveDirectoryApi.java index b14de7380..41fe05f0d 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/AzureActiveDirectoryApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/AzureActiveDirectoryApi.java @@ -71,10 +71,11 @@ public TokenExtractor getAccessTokenExtractor() { @Override public String getAuthorizationUrl(OAuthConfig config, Map additionalParams) { - String scope = config.getScope(); + final String scope = config.getScope(); - if ( scope == null ) { - return MSFT_LOGIN_URL + SLASH + COMMON + SLASH + AUTH_URI + String.format(SCOPED_AUTHORIZE_URL, config.getApiKey(), + if (scope == null) { + return MSFT_LOGIN_URL + SLASH + COMMON + SLASH + AUTH_URI + + String.format(SCOPED_AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()), OAuthEncoder.encode(config.getScope())); } else { return MSFT_LOGIN_URL + SLASH + COMMON + SLASH + AUTH_URI diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/AzureActiveDirectoryService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/AzureActiveDirectoryService.java index ccda746c7..03e0d2ead 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/AzureActiveDirectoryService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/AzureActiveDirectoryService.java @@ -8,8 +8,9 @@ public class AzureActiveDirectoryService extends OAuth20Service { + private static final String ACCEPTED_FORMAT = "application/json; " + + "odata=minimalmetadata; streaming=true; charset=utf-8"; private final DefaultApi20 api; - String ACCEPTED_FORMAT = "application/json; odata=minimalmetadata; streaming=true; charset=utf-8"; public AzureActiveDirectoryService(DefaultApi20 api, OAuthConfig config) { super(api, config); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureExample.java index fc5d97eaf..9f82c9b81 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureExample.java @@ -19,13 +19,17 @@ public class MicrosoftAzureExample { private static final String NETWORK_NAME = "Microsoft Azure Active Directory"; private static final String PROTECTED_RESOURCE_URL = "https://graph.windows.net/me?api-version=1.6"; + private MicrosoftAzureExample(){ + + } + public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your client id and secret final String clientId = "client id here"; final String clientSecret = "client secret here"; final OAuth20Service service = new ServiceBuilder(clientId) .apiSecret(clientSecret) - .scope( "openid" ) + .scope("openid") .callback("http://www.example.com/oauth_callback/") .build(AzureActiveDirectoryApi.instance()); final Scanner in = new Scanner(System.in, "UTF-8"); From 6d339c85a8df034bb680a90d431eeffcae8afe3c Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 6 Dec 2017 13:03:17 +0300 Subject: [PATCH 436/882] add API - Microsoft Azure Active Directory (Azure AD) (thanks to https://github.com/kaushalmall) --- README.md | 1 + changelog | 1 + .../apis/AzureActiveDirectoryApi.java | 86 ------------------- .../MicrosoftAzureActiveDirectoryApi.java | 58 +++++++++++++ .../service/AzureActiveDirectoryService.java | 48 ----------- .../MicrosoftAzureActiveDirectoryService.java | 22 +++++ ...MicrosoftAzureActiveDirectoryExample.java} | 10 +-- .../scribejava/core/model/OAuthConstants.java | 5 -- 8 files changed, 86 insertions(+), 145 deletions(-) delete mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/AzureActiveDirectoryApi.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/MicrosoftAzureActiveDirectoryApi.java delete mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/service/AzureActiveDirectoryService.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/service/MicrosoftAzureActiveDirectoryService.java rename scribejava-apis/src/test/java/com/github/scribejava/apis/examples/{MicrosoftAzureExample.java => MicrosoftAzureActiveDirectoryExample.java} (92%) diff --git a/README.md b/README.md index 9ce7bba1a..2e953db75 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,7 @@ ScribeJava support out-of-box several HTTP clients: * Imgur (http://imgur.com/) * Kaixin 开心网 (http://www.kaixin001.com/) * LinkedIn (https://www.linkedin.com/) +* Microsoft Azure Active Directory (Azure AD) (http://azure.microsoft.com/) * Microsoft Live (https://login.live.com/) * Mail.Ru (https://mail.ru/) * Meetup (http://www.meetup.com/) diff --git a/changelog b/changelog index f26621947..fb5e1eaad 100644 --- a/changelog +++ b/changelog @@ -1,6 +1,7 @@ [SNAPSHOT] * drop optional dependency on Apache commons-codec * add API - Dataporten (https://docs.dataporten.no/) (thanks to https://github.com/xibriz) + * add API - Microsoft Azure Active Directory (Azure AD) (thanks to https://github.com/kaushalmall) [5.0.0] * drop Java 7 backward compatibility support, become Java 8 only diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/AzureActiveDirectoryApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/AzureActiveDirectoryApi.java deleted file mode 100644 index 41fe05f0d..000000000 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/AzureActiveDirectoryApi.java +++ /dev/null @@ -1,86 +0,0 @@ -package com.github.scribejava.apis; - -import com.github.scribejava.apis.service.AzureActiveDirectoryService; -import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; -import com.github.scribejava.core.extractors.TokenExtractor; -import com.github.scribejava.core.model.OAuth2AccessToken; -import com.github.scribejava.core.model.OAuthConfig; -import com.github.scribejava.core.model.Verb; -import com.github.scribejava.core.utils.OAuthEncoder; - -import java.util.Map; - -/** - * Microsoft Azure Active Directory Api - * - * Some helpful links - * https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-protocols-oauth-code - * https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-devquickstarts-webapp-java - * https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/signed-in-user-operations - * https://portal.azure.com - */ -public class AzureActiveDirectoryApi extends DefaultApi20 { - - private static final String MSFT_GRAPH_URL = "https://graph.windows.net"; - - private static final String AUTHORIZE_URL = "?client_id=%s&redirect_uri=%s&response_type=code&resource=" - + MSFT_GRAPH_URL; - private static final String SCOPED_AUTHORIZE_URL = AUTHORIZE_URL + "&scope=%s"; - - private static final String MSFT_LOGIN_URL = "https://login.microsoftonline.com"; - private static final String SLASH = "/"; - private static final String COMMON = "common"; - private static final String TOKEN_URI = "oauth2/token"; - private static final String AUTH_URI = "oauth2/authorize"; - - private static class InstanceHolder { - - private static final AzureActiveDirectoryApi INSTANCE = new AzureActiveDirectoryApi(); - } - - public static AzureActiveDirectoryApi instance() { - return AzureActiveDirectoryApi.InstanceHolder.INSTANCE; - } - - @Override - public String getAccessTokenEndpoint() { - return MSFT_LOGIN_URL + SLASH + COMMON + SLASH + TOKEN_URI; - } - - @Override - protected String getAuthorizationBaseUrl() { - return MSFT_LOGIN_URL + SLASH + COMMON + SLASH + AUTH_URI; - } - - @Override - public Verb getAccessTokenVerb() { - return Verb.POST; - } - - @Override - public AzureActiveDirectoryService createService(OAuthConfig config) { - return new AzureActiveDirectoryService(this, config); - } - - @Override - public TokenExtractor getAccessTokenExtractor() { - return OAuth2AccessTokenJsonExtractor.instance(); - } - - @Override - public String getAuthorizationUrl(OAuthConfig config, Map additionalParams) { - - final String scope = config.getScope(); - - if (scope == null) { - return MSFT_LOGIN_URL + SLASH + COMMON + SLASH + AUTH_URI - + String.format(SCOPED_AUTHORIZE_URL, config.getApiKey(), - OAuthEncoder.encode(config.getCallback()), OAuthEncoder.encode(config.getScope())); - } else { - return MSFT_LOGIN_URL + SLASH + COMMON + SLASH + AUTH_URI - + String.format(AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback())); - } - } - -} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/MicrosoftAzureActiveDirectoryApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/MicrosoftAzureActiveDirectoryApi.java new file mode 100644 index 000000000..44ea915e5 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/MicrosoftAzureActiveDirectoryApi.java @@ -0,0 +1,58 @@ +package com.github.scribejava.apis; + +import com.github.scribejava.apis.service.MicrosoftAzureActiveDirectoryService; +import com.github.scribejava.core.builder.api.ClientAuthenticationType; +import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.model.OAuthConfig; + +/** + * Microsoft Azure Active Directory Api + * + * @see + * Understand the OAuth 2.0 authorization code flow in Azure AD | Microsoft Docs + * @see + * Azure AD Java web app Getting Started | Microsoft Docs + * @see + * Azure AD Graph API Operations on the Signed-in User + * @see https://portal.azure.com + */ +public class MicrosoftAzureActiveDirectoryApi extends DefaultApi20 { + + private static final String MSFT_GRAPH_URL = "https://graph.windows.net"; + + private static final String MSFT_LOGIN_URL = "https://login.microsoftonline.com"; + private static final String SLASH = "/"; + private static final String COMMON = "common"; + private static final String TOKEN_URI = "oauth2/token"; + private static final String AUTH_URI = "oauth2/authorize?resource=" + MSFT_GRAPH_URL; + + private static class InstanceHolder { + + private static final MicrosoftAzureActiveDirectoryApi INSTANCE = new MicrosoftAzureActiveDirectoryApi(); + } + + public static MicrosoftAzureActiveDirectoryApi instance() { + return InstanceHolder.INSTANCE; + } + + @Override + public String getAccessTokenEndpoint() { + return MSFT_LOGIN_URL + SLASH + COMMON + SLASH + TOKEN_URI; + } + + @Override + protected String getAuthorizationBaseUrl() { + return MSFT_LOGIN_URL + SLASH + COMMON + SLASH + AUTH_URI; + } + + @Override + public MicrosoftAzureActiveDirectoryService createService(OAuthConfig config) { + return new MicrosoftAzureActiveDirectoryService(this, config); + } + + @Override + public ClientAuthenticationType getClientAuthenticationType() { + return ClientAuthenticationType.REQUEST_BODY; + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/AzureActiveDirectoryService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/AzureActiveDirectoryService.java deleted file mode 100644 index 03e0d2ead..000000000 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/AzureActiveDirectoryService.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.github.scribejava.apis.service; - -import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.model.OAuthConfig; -import com.github.scribejava.core.model.OAuthConstants; -import com.github.scribejava.core.model.OAuthRequest; -import com.github.scribejava.core.oauth.OAuth20Service; - -public class AzureActiveDirectoryService extends OAuth20Service { - - private static final String ACCEPTED_FORMAT = "application/json; " + - "odata=minimalmetadata; streaming=true; charset=utf-8"; - private final DefaultApi20 api; - - public AzureActiveDirectoryService(DefaultApi20 api, OAuthConfig config) { - super(api, config); - this.api = api; - } - - @Override - public OAuthRequest createAccessTokenRequest(String code) { - final OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint()); - final OAuthConfig config = getConfig(); - - request.addHeader(OAuthConstants.CONTENT_TYPE, OAuthConstants.APPLICATION_X_WWW_FORM_URLENCODED); - - request.addBodyParameter(OAuthConstants.CLIENT_ID, config.getApiKey()); - final String apiSecret = config.getApiSecret(); - if (apiSecret != null) { - request.addBodyParameter(OAuthConstants.CLIENT_SECRET, apiSecret); - } - request.addBodyParameter(OAuthConstants.CODE, code); - request.addBodyParameter(OAuthConstants.REDIRECT_URI, config.getCallback()); - final String scope = config.getScope(); - if (scope != null) { - request.addBodyParameter(OAuthConstants.SCOPE, scope); - } - request.addBodyParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.AUTHORIZATION_CODE); - - return request; - } - - @Override - public void signRequest(String accessToken, OAuthRequest request) { - request.addHeader(OAuthConstants.AUTHORIZATION, OAuthConstants.BEARER + accessToken); - request.addHeader(OAuthConstants.ACCEPT, ACCEPTED_FORMAT); - } -} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MicrosoftAzureActiveDirectoryService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MicrosoftAzureActiveDirectoryService.java new file mode 100644 index 000000000..703257eac --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MicrosoftAzureActiveDirectoryService.java @@ -0,0 +1,22 @@ +package com.github.scribejava.apis.service; + +import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.model.OAuthConfig; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.oauth.OAuth20Service; + +public class MicrosoftAzureActiveDirectoryService extends OAuth20Service { + + private static final String ACCEPTED_FORMAT + = "application/json; odata=minimalmetadata; streaming=true; charset=utf-8"; + + public MicrosoftAzureActiveDirectoryService(DefaultApi20 api, OAuthConfig config) { + super(api, config); + } + + @Override + public void signRequest(String accessToken, OAuthRequest request) { + super.signRequest(accessToken, request); + request.addHeader("Accept", ACCEPTED_FORMAT); + } +} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureActiveDirectoryExample.java similarity index 92% rename from scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureExample.java rename to scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureActiveDirectoryExample.java index 9f82c9b81..86c2fc4a6 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureActiveDirectoryExample.java @@ -1,6 +1,6 @@ package com.github.scribejava.apis.examples; -import com.github.scribejava.apis.AzureActiveDirectoryApi; +import com.github.scribejava.apis.MicrosoftAzureActiveDirectoryApi; import com.github.scribejava.core.builder.ServiceBuilder; import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthRequest; @@ -12,14 +12,12 @@ import java.util.Scanner; import java.util.concurrent.ExecutionException; - - -public class MicrosoftAzureExample { +public class MicrosoftAzureActiveDirectoryExample { private static final String NETWORK_NAME = "Microsoft Azure Active Directory"; private static final String PROTECTED_RESOURCE_URL = "https://graph.windows.net/me?api-version=1.6"; - private MicrosoftAzureExample(){ + private MicrosoftAzureActiveDirectoryExample() { } @@ -31,7 +29,7 @@ public static void main(String... args) throws IOException, InterruptedException .apiSecret(clientSecret) .scope("openid") .callback("http://www.example.com/oauth_callback/") - .build(AzureActiveDirectoryApi.instance()); + .build(MicrosoftAzureActiveDirectoryApi.instance()); final Scanner in = new Scanner(System.in, "UTF-8"); System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConstants.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConstants.java index 1d130fdc8..60bd33403 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConstants.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConstants.java @@ -41,9 +41,4 @@ public interface OAuthConstants { //not OAuth specific String USER_AGENT_HEADER_NAME = "User-Agent"; - String CONTENT_TYPE = "Content-Type"; - String APPLICATION_X_WWW_FORM_URLENCODED = "application/x-www-form-urlencoded"; - String AUTHORIZATION = "Authorization"; - String BEARER = "Bearer "; - String ACCEPT = "Accept"; } From dd5b08858466ce112a4aedf388db188c3a9d9492 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 10 Jan 2018 13:08:56 +0300 Subject: [PATCH 437/882] fix LinkedInApi20 (thanks to https://github.com/jhorowitz-firedrum) --- changelog | 1 + .../main/java/com/github/scribejava/apis/LinkedInApi20.java | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/changelog b/changelog index fb5e1eaad..35cf8287b 100644 --- a/changelog +++ b/changelog @@ -2,6 +2,7 @@ * drop optional dependency on Apache commons-codec * add API - Dataporten (https://docs.dataporten.no/) (thanks to https://github.com/xibriz) * add API - Microsoft Azure Active Directory (Azure AD) (thanks to https://github.com/kaushalmall) + * fix LinkedInApi20 (thanks to https://github.com/jhorowitz-firedrum) [5.0.0] * drop Java 7 backward compatibility support, become Java 8 only diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi20.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi20.java index 0d22d705c..97f78b354 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi20.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi20.java @@ -1,5 +1,6 @@ package com.github.scribejava.apis; +import com.github.scribejava.core.builder.api.ClientAuthenticationType; import com.github.scribejava.core.builder.api.DefaultApi20; public class LinkedInApi20 extends DefaultApi20 { @@ -24,4 +25,9 @@ public String getAccessTokenEndpoint() { protected String getAuthorizationBaseUrl() { return "https://www.linkedin.com/oauth/v2/authorization"; } + + @Override + public ClientAuthenticationType getClientAuthenticationType() { + return ClientAuthenticationType.REQUEST_BODY; + } } From 001686af4b358a48ebda9f0ec51b2c63883f5505 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 10 Jan 2018 13:13:29 +0300 Subject: [PATCH 438/882] update some dependencies --- pom.xml | 28 +++------------------------- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- 3 files changed, 5 insertions(+), 27 deletions(-) diff --git a/pom.xml b/pom.xml index 5fda43fc8..aa216cd8a 100644 --- a/pom.xml +++ b/pom.xml @@ -53,28 +53,6 @@ +7-909-677-11-16
- - chernatkin - Sergey Chernatkin - s.chernatkin@hh.ru - hh.ru - http://hh.ru - - all - - +3 - - - igaranina - Irina Garanina - i.garanina@hh.ru - hh.ru - http://hh.ru - - all - - +3 -
@@ -103,7 +81,7 @@ org.apache.felix maven-bundle-plugin - 3.3.0 + 3.5.0 bundle-manifest @@ -132,7 +110,7 @@ com.puppycrawl.tools checkstyle - 8.4 + 8.7 @@ -193,7 +171,7 @@ org.apache.maven.plugins maven-javadoc-plugin - 2.10.4 + 3.0.0 UTF-8 diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 5a35925a3..4b111458a 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -23,7 +23,7 @@ org.asynchttpclient async-http-client - 2.0.37 + 2.0.38 com.github.scribejava diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index 95b48da1b..84d9b4143 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -23,7 +23,7 @@ org.apache.httpcomponents httpclient - 4.5.3 + 4.5.4 org.apache.httpcomponents From a629df3e840d40f1dc7ac8acb721ca275558eb4e Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 10 Jan 2018 13:30:35 +0300 Subject: [PATCH 439/882] prepare 5.1.0 --- README.md | 4 ++-- changelog | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 2e953db75..c0a6ce197 100644 --- a/README.md +++ b/README.md @@ -105,7 +105,7 @@ You can pull ScribeJava from the central maven repository, just add these to you com.github.scribejava scribejava-apis - 5.0.0 + 5.1.0 ``` @@ -114,7 +114,7 @@ And in case you need just core classes (that's it, without any external API (FB, com.github.scribejava scribejava-core - 5.0.0 + 5.1.0 ``` diff --git a/changelog b/changelog index 35cf8287b..f42671a6f 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,4 @@ -[SNAPSHOT] +[5.1.0] * drop optional dependency on Apache commons-codec * add API - Dataporten (https://docs.dataporten.no/) (thanks to https://github.com/xibriz) * add API - Microsoft Azure Active Directory (Azure AD) (thanks to https://github.com/kaushalmall) From 57617806d8ce09df9cd832b565e41ff62ab21266 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 10 Jan 2018 13:31:28 +0300 Subject: [PATCH 440/882] [maven-release-plugin] prepare release scribejava-5.1.0 --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index aa216cd8a..abe672be6 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 5.0.1-SNAPSHOT + 5.1.0 ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -34,7 +34,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - HEAD + scribejava-5.1.0 diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 9a7b21a63..6739ad368 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.0.1-SNAPSHOT + 5.1.0 ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 3af1df7aa..07a7b191a 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.0.1-SNAPSHOT + 5.1.0 ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 4b111458a..617664b76 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.0.1-SNAPSHOT + 5.1.0 ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index 84d9b4143..961d429d3 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.0.1-SNAPSHOT + 5.1.0 ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index bb88941ae..1f1d3030c 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.0.1-SNAPSHOT + 5.1.0 ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index c032e7667..ab1685a74 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.0.1-SNAPSHOT + 5.1.0 ../pom.xml From 5d7f6865660ca33bc3cfdaf3bccbb26700c0fc2d Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 10 Jan 2018 13:31:38 +0300 Subject: [PATCH 441/882] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index abe672be6..cecfab589 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 5.1.0 + 5.1.1-SNAPSHOT ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -34,7 +34,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - scribejava-5.1.0 + HEAD diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 6739ad368..441f75844 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.1.0 + 5.1.1-SNAPSHOT ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 07a7b191a..325caa51e 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.1.0 + 5.1.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 617664b76..0294d6bfd 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.1.0 + 5.1.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index 961d429d3..7d7d35147 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.1.0 + 5.1.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index 1f1d3030c..7a247ffc6 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.1.0 + 5.1.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index ab1685a74..ab55c992f 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.1.0 + 5.1.1-SNAPSHOT ../pom.xml From 7b8aab5eaba99495518b69f36924e216fe1a037f Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 15 Jan 2018 15:03:49 +0300 Subject: [PATCH 442/882] allow 'null' as callback. It's an optional parameter. Remove "oob" as default (thanks to https://github.com/massongit) --- changelog | 3 +++ .../com/github/scribejava/core/builder/ServiceBuilder.java | 4 +--- .../com/github/scribejava/core/model/OAuthConstants.java | 1 - .../github/scribejava/core/builder/ServiceBuilderTest.java | 7 +++---- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/changelog b/changelog index f42671a6f..e39f3eee5 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,6 @@ +[SNAPSHOT] + * allow 'null' as callback. It's an optional parameter. Remove "oob" as default (thanks to https://github.com/massongit) + [5.1.0] * drop optional dependency on Apache commons-codec * add API - Dataporten (https://docs.dataporten.no/) (thanks to https://github.com/xibriz) diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilder.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilder.java index c003e7d18..d98e18ad7 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilder.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilder.java @@ -4,7 +4,6 @@ import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.httpclient.HttpClientConfig; import com.github.scribejava.core.model.OAuthConfig; -import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.oauth.OAuthService; import com.github.scribejava.core.utils.Preconditions; @@ -15,7 +14,7 @@ */ public class ServiceBuilder { - private String callback = OAuthConstants.OUT_OF_BAND; + private String callback; private String apiKey; private String apiSecret; private String scope; @@ -38,7 +37,6 @@ public ServiceBuilder(String apiKey) { * @return the {@link ServiceBuilder} instance for method chaining */ public ServiceBuilder callback(String callback) { - Preconditions.checkNotNull(callback, "Callback can't be null"); this.callback = callback; return this; } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConstants.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConstants.java index 60bd33403..93d936291 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConstants.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConstants.java @@ -17,7 +17,6 @@ public interface OAuthConstants { String PARAM_PREFIX = "oauth_"; String TOKEN = "oauth_token"; String TOKEN_SECRET = "oauth_token_secret"; - String OUT_OF_BAND = "oob"; String VERIFIER = "oauth_verifier"; String HEADER = "Authorization"; String SCOPE = "scope"; diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/builder/ServiceBuilderTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/builder/ServiceBuilderTest.java index c7d4a4dac..b2480af45 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/builder/ServiceBuilderTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/builder/ServiceBuilderTest.java @@ -5,7 +5,6 @@ import org.junit.Test; import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.model.OAuthConfig; -import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.oauth.OAuth20Service; public class ServiceBuilderTest { @@ -26,7 +25,7 @@ public void shouldReturnConfigDefaultValues() { final OAuthConfig config = api.getConfig(); assertEquals(config.getApiKey(), "key"); assertEquals(config.getApiSecret(), "secret"); - assertEquals(config.getCallback(), OAuthConstants.OUT_OF_BAND); + assertEquals(config.getCallback(), null); } @Test @@ -39,8 +38,8 @@ public void shouldAcceptValidCallbackUrl() { assertEquals(config.getCallback(), "http://example.com"); } - @Test(expected = IllegalArgumentException.class) - public void shouldNotAcceptNullAsCallback() { + @Test + public void shouldAcceptNullAsCallback() { builder.apiKey("key").apiSecret("secret").callback(null).build(api); } From bca97ef62c7a948eeb69be0c91dfa3e686f07eaa Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 24 Jan 2018 13:41:09 +0300 Subject: [PATCH 443/882] java7 compatible again! --- changelog | 1 + pom.xml | 7 +- .../apis/service/MailruOAuthService.java | 14 +- .../service/OdnoklassnikiOAuthService.java | 12 +- .../apis/examples/RenrenExample.java | 28 +- .../core/builder/ServiceBuilder.java | 4 +- .../builder/api/ClientAuthenticationType.java | 2 +- .../core/extractors/HeaderExtractorImpl.java | 24 +- .../core/httpclient/jdk/JDKHttpClient.java | 17 +- .../github/scribejava/core/java8/Base64.java | 977 ++++++++++++++++++ .../scribejava/core/java8/Consumer.java | 47 + .../scribejava/core/model/ParameterList.java | 15 +- .../core/oauth/OAuth10aService.java | 19 +- .../scribejava/core/oauth/OAuth20Service.java | 18 +- .../core/pkce/PKCECodeChallengeMethod.java | 2 +- .../scribejava/core/pkce/PKCEService.java | 2 +- .../core/services/SignatureService.java | 2 +- .../core/oauth/OAuth20ServiceTest.java | 2 +- .../core/oauth/OAuth20ServiceUnit.java | 5 +- .../httpclient/ahc/AhcHttpClient.java | 69 +- .../ahc/OAuthAsyncCompletionHandler.java | 4 +- .../httpclient/ahc/AhcHttpClientTest.java | 2 + .../httpclient/apache/ApacheHttpClient.java | 4 +- .../apache/OAuthAsyncCompletionHandler.java | 9 +- .../OauthAsyncCompletionHandlerTest.java | 31 +- .../httpclient/ning/NingHttpClient.java | 69 +- .../ning/OAuthAsyncCompletionHandler.java | 15 +- .../httpclient/okhttp/OkHttpHttpClient.java | 13 +- 28 files changed, 1311 insertions(+), 103 deletions(-) create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/java8/Base64.java create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/java8/Consumer.java diff --git a/changelog b/changelog index e39f3eee5..b62048c26 100644 --- a/changelog +++ b/changelog @@ -1,5 +1,6 @@ [SNAPSHOT] * allow 'null' as callback. It's an optional parameter. Remove "oob" as default (thanks to https://github.com/massongit) + * java7 compatible again! [5.1.0] * drop optional dependency on Apache commons-codec diff --git a/pom.xml b/pom.xml index cecfab589..e752fc7cb 100644 --- a/pom.xml +++ b/pom.xml @@ -110,7 +110,7 @@ com.puppycrawl.tools checkstyle - 8.7 + 6.19 @@ -129,8 +129,8 @@ 3.7.0 UTF-8 - 1.8 - 1.8 + 1.7 + 1.7 true @@ -192,6 +192,7 @@ validate validate + main/java/com/github/scribejava/core/java8/* ${basedir}/src checkstyle.xml UTF-8 diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthService.java index 625140ed9..f31503098 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthService.java @@ -12,7 +12,6 @@ import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.Formatter; -import java.util.stream.Collectors; public class MailruOAuthService extends OAuth20Service { @@ -37,10 +36,15 @@ public void signRequest(String accessToken, OAuthRequest request) { final String[] parts = param.split("="); map.put(parts[0], (parts.length == 1) ? "" : parts[1]); } - final String urlNew = map.entrySet().stream() - .map(entry -> entry.getKey() + '=' + entry.getValue()) - .collect(Collectors.joining()); - final String sigSource = URLDecoder.decode(urlNew, "UTF-8") + clientSecret; + + final StringBuilder urlNew = new StringBuilder(); + for (Map.Entry entry : map.entrySet()) { + urlNew.append(entry.getKey()); + urlNew.append('='); + urlNew.append(entry.getValue()); + } + + final String sigSource = URLDecoder.decode(urlNew.toString(), "UTF-8") + clientSecret; request.addQuerystringParameter("sig", md5(sigSource)); } } catch (UnsupportedEncodingException e) { diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiOAuthService.java index 4b0ea020b..517d097ab 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiOAuthService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiOAuthService.java @@ -15,7 +15,6 @@ import java.util.Collections; import java.util.Formatter; import java.util.List; -import java.util.stream.Collectors; public class OdnoklassnikiOAuthService extends OAuth20Service { @@ -35,11 +34,14 @@ public void signRequest(String accessToken, OAuthRequest request) { Collections.sort(allParams); - final String stringParams = allParams.stream() - .map(param -> param.getKey() + '=' + param.getValue()) - .collect(Collectors.joining()); + final StringBuilder stringParams = new StringBuilder(); + for (Parameter param : allParams) { + stringParams.append(param.getKey()) + .append('=') + .append(param.getValue()); + } - final String sigSource = URLDecoder.decode(stringParams, "UTF-8") + tokenDigest; + final String sigSource = URLDecoder.decode(stringParams.toString(), "UTF-8") + tokenDigest; request.addQuerystringParameter("sig", md5(sigSource).toLowerCase()); super.signRequest(accessToken, request); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java index 31f043d6e..9f31e0af3 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java @@ -15,10 +15,11 @@ import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.oauth.OAuth20Service; import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; import java.util.Formatter; +import java.util.List; import java.util.concurrent.ExecutionException; -import java.util.stream.Collectors; -import java.util.stream.Stream; public final class RenrenExample { @@ -68,17 +69,20 @@ public static void main(String... args) throws IOException, InterruptedException parameters.put("format", "json"); parameters.put("v", "1.0"); - parameters.forEach((key, value) -> request.addQuerystringParameter(key, value)); - - final String sig = Stream.concat( - Stream.concat( - parameters.entrySet().stream() - .map(entry -> String.format("%s=%s", entry.getKey(), entry.getValue())), - Stream.of(String.format("%s=%s", OAuthConstants.ACCESS_TOKEN, accessToken.getAccessToken()))) - .sorted(), - Stream.of(apiSecret)) - .collect(Collectors.joining()); + final List sigString = new ArrayList<>(parameters.size() + 1); + for (Map.Entry parameter : parameters.entrySet()) { + request.addQuerystringParameter(parameter.getKey(), parameter.getValue()); + sigString.add(String.format("%s=%s", parameter.getKey(), parameter.getValue())); + } + sigString.add(String.format("%s=%s", OAuthConstants.ACCESS_TOKEN, accessToken.getAccessToken())); + Collections.sort(sigString); + final StringBuilder sigBuilder = new StringBuilder(); + for (String param : sigString) { + sigBuilder.append(param); + } + sigBuilder.append(apiSecret); + final String sig = sigBuilder.toString(); System.out.println("Sig string: " + sig); request.addQuerystringParameter("sig", md5(sig)); service.signRequest(accessToken, request); diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilder.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilder.java index d98e18ad7..2ec6b1b22 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilder.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilder.java @@ -129,11 +129,11 @@ public ServiceBuilder debug() { } /** - * Returns the fully configured {@link S} + * Returns the fully configured {@link OAuthService} * * @param OAuthService implementation (OAuth1/OAuth2/any API specific) * @param api will build Service for this API - * @return fully configured {@link S} + * @return fully configured {@link OAuthService} */ public S build(BaseApi api) { return api.createService(new OAuthConfig(apiKey, apiSecret, callback, scope, debugStream, state, responseType, diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/ClientAuthenticationType.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/ClientAuthenticationType.java index 7e2526b0e..21c7f3793 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/ClientAuthenticationType.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/ClientAuthenticationType.java @@ -1,10 +1,10 @@ package com.github.scribejava.core.builder.api; +import com.github.scribejava.core.java8.Base64; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.OAuthRequest; import java.nio.charset.Charset; -import java.util.Base64; /** * Represents
diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/HeaderExtractorImpl.java b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/HeaderExtractorImpl.java index a29ba9839..5ffe0c023 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/HeaderExtractorImpl.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/HeaderExtractorImpl.java @@ -6,7 +6,6 @@ import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.utils.OAuthEncoder; import com.github.scribejava.core.utils.Preconditions; -import java.util.stream.Collectors; /** * Default implementation of {@link HeaderExtractor}. Conforms to OAuth 1.0a @@ -24,15 +23,26 @@ public String extract(OAuthRequest request) { checkPreconditions(request); final Map parameters = request.getOauthParameters(); - final String paramsString = parameters.entrySet().stream() - .map(entry -> String.format("%s=\"%s\"", entry.getKey(), OAuthEncoder.encode(entry.getValue()))) - .collect(Collectors.joining(PARAM_SEPARATOR, PREAMBLE, "")); + final StringBuilder header = new StringBuilder(PREAMBLE); - if (request.getRealm() == null || request.getRealm().isEmpty()) { - return paramsString; + for (Map.Entry parameter : parameters.entrySet()) { + if (header.length() > PREAMBLE.length()) { + header.append(PARAM_SEPARATOR); + } + header.append(parameter.getKey()) + .append("=\"") + .append(OAuthEncoder.encode(parameter.getValue())) + .append('"'); } - return paramsString + PARAM_SEPARATOR + String.format("%s=\"%s\"", OAuthConstants.REALM, request.getRealm()); + if (request.getRealm() != null && !request.getRealm().isEmpty()) { + header.append(PARAM_SEPARATOR) + .append(OAuthConstants.REALM) + .append("=\"") + .append(request.getRealm()) + .append('"'); + } + return header.toString(); } private void checkPreconditions(OAuthRequest request) { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java index 5e173eb7e..6e970bb07 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java @@ -13,6 +13,7 @@ import java.net.URL; import java.net.UnknownHostException; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; @@ -140,18 +141,24 @@ abstract void setBody(HttpURLConnection connection, Object bodyContents, boolean private static Map parseHeaders(HttpURLConnection conn) { final Map headers = new HashMap<>(); - conn.getHeaderFields().forEach((key, value) -> { + + for (Map.Entry> headerField : conn.getHeaderFields().entrySet()) { + final String key = headerField.getKey(); + final String value = headerField.getValue().get(0); if ("Content-Encoding".equalsIgnoreCase(key)) { - headers.put("Content-Encoding", value.get(0)); + headers.put("Content-Encoding", value); } else { - headers.put(key, value.get(0)); + headers.put(key, value); } - }); + } return headers; } private static void addHeaders(HttpURLConnection connection, Map headers, String userAgent) { - headers.forEach((key, value) -> connection.setRequestProperty(key, value)); + for (Map.Entry header : headers.entrySet()) { + connection.setRequestProperty(header.getKey(), header.getValue()); + } + if (userAgent != null) { connection.setRequestProperty(OAuthConstants.USER_AGENT_HEADER_NAME, userAgent); } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/java8/Base64.java b/scribejava-core/src/main/java/com/github/scribejava/core/java8/Base64.java new file mode 100644 index 000000000..7e599c6e5 --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/java8/Base64.java @@ -0,0 +1,977 @@ +/* + * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.github.scribejava.core.java8; + +import java.io.FilterOutputStream; +import java.io.InputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.nio.ByteBuffer; +import java.nio.charset.StandardCharsets; +import java.util.Arrays; +import java.util.Objects; + +/** + * This class consists exclusively of static methods for obtaining encoders and decoders for the Base64 encoding scheme. + * The implementation of this class supports the following types of Base64 as specified in + * RFC 4648 and + * RFC 2045. + * + *
    + *
  • Basic + *

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

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

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

  • + * + *
  • MIME + *

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

  • + *
+ * + *

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    + *
  1. Create an application at https://developer.yahoo.com/apps/create/
  2. + *
  3. Make sure the application has the API permission where your protected resource resides (Profiles, Fantasy Sports, etc)
  4. + *
  5. get Client ID and Client Secret after registering your app
  6. + *
+ */ +public class Yahoo20Example { + + // Update PROTECTED_RESOURCE_URL to a secure URL only you could reach = your profile, or private fantasy sports + private static final String PROTECTED_RESOURCE_URL + = "https://baseball.fantasysports.yahoo.com/b1/ ADD TEAM HERE!!!!"; + + private Yahoo20Example() { + } + + public static void main(String... args) throws IOException, InterruptedException, ExecutionException { + + // Add your personal information here + final String clientId = "ADD CLIENT ID HERE!!!!"; + final String clientSecret = "ADD SECRET HERE!!!!"; + + final OAuth20Service service = new ServiceBuilder(clientId) + .apiSecret(clientSecret) + .callback("oob") + .build(YahooApi20.instance()); + final Scanner in = new Scanner(System.in); + + System.out.println("=== Yahoo's OAuth Workflow ==="); + System.out.println(); + + // Obtain the Request Token + System.out.println("Fetching the Request Token..."); + System.out.println("Got the Request Token!"); + System.out.println(); + + System.out.println("Now go and authorize ScribeJava here:"); + System.out.println(service.getAuthorizationUrl()); + System.out.println("And paste the verifier here"); + System.out.print(">>"); + final String oauthVerifier = in.nextLine(); + System.out.println(); + + // Trade the Request Token and Verfier for the Access Token + System.out.println("Trading the Request Token for an Access Token..."); + final OAuth2AccessToken accessToken = service.getAccessToken(oauthVerifier); + System.out.println("Got the Access Token!"); + System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); + System.out.println(); + + // Now let's go and ask for a protected resource! + System.out.println("Now we're going to access a protected resource..."); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); + service.signRequest(accessToken, request); + final Response response = service.execute(request); + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + + System.out.println(); + System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); + + } +} From bb8deb19b708aa0c09aefe5d323fee11ca812d79 Mon Sep 17 00:00:00 2001 From: Bill Tarr Date: Mon, 19 Feb 2018 17:35:34 -0800 Subject: [PATCH 456/882] fix formatting issues identified by CI. --- .../apis/examples/Yahoo20Example.java | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Yahoo20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Yahoo20Example.java index 653061541..c385ddc44 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Yahoo20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Yahoo20Example.java @@ -2,7 +2,10 @@ import com.github.scribejava.apis.YahooApi20; import com.github.scribejava.core.builder.ServiceBuilder; -import com.github.scribejava.core.model.*; +import com.github.scribejava.core.model.OAuth2AccessToken; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.oauth.OAuth20Service; import java.io.IOException; @@ -12,14 +15,14 @@ /** * Flow as documented at https://developer.yahoo.com/oauth2/guide/flows_authcode *
    - *
  1. Create an application at https://developer.yahoo.com/apps/create/
  2. - *
  3. Make sure the application has the API permission where your protected resource resides (Profiles, Fantasy Sports, etc)
  4. - *
  5. get Client ID and Client Secret after registering your app
  6. + *
  7. Create an application at https://developer.yahoo.com/apps/create/
  8. + *
  9. Make sure application has permission to API resource (Profiles, Fantasy Sports, etc)
  10. + *
  11. get Client ID and Client Secret after registering your app
  12. *
*/ public class Yahoo20Example { - // Update PROTECTED_RESOURCE_URL to a secure URL only you could reach = your profile, or private fantasy sports + // Update PROTECTED_RESOURCE_URL to a secure URL only you could reach = your profile, or private fantasy sports private static final String PROTECTED_RESOURCE_URL = "https://baseball.fantasysports.yahoo.com/b1/ ADD TEAM HERE!!!!"; @@ -27,9 +30,8 @@ private Yahoo20Example() { } public static void main(String... args) throws IOException, InterruptedException, ExecutionException { - - // Add your personal information here - final String clientId = "ADD CLIENT ID HERE!!!!"; + // Add your personal information here + final String clientId = "ADD CLIENT ID HERE!!!!"; final String clientSecret = "ADD SECRET HERE!!!!"; final OAuth20Service service = new ServiceBuilder(clientId) @@ -74,4 +76,4 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); } -} +} \ No newline at end of file From dfe04a08dcc8b65ceef36f17f6a400d58336804e Mon Sep 17 00:00:00 2001 From: Bill Tarr Date: Mon, 19 Feb 2018 17:40:20 -0800 Subject: [PATCH 457/882] newline... --- .../com/github/scribejava/apis/examples/Yahoo20Example.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Yahoo20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Yahoo20Example.java index c385ddc44..cefd55cce 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Yahoo20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Yahoo20Example.java @@ -76,4 +76,4 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); } -} \ No newline at end of file +} From e7883ae01c7c7c1691260a5bd9db056854271e27 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 6 Mar 2018 13:42:19 +0300 Subject: [PATCH 458/882] add Yahoo2 API (thanks to https://github.com/javatestcase) --- changelog | 1 + .../main/java/com/github/scribejava/apis/YahooApi20.java | 9 --------- .../github/scribejava/apis/examples/Yahoo20Example.java | 3 +-- 3 files changed, 2 insertions(+), 11 deletions(-) diff --git a/changelog b/changelog index c3a70d1b4..801b51715 100644 --- a/changelog +++ b/changelog @@ -2,6 +2,7 @@ * fix Salesforce API (thanks to https://github.com/jhorowitz-firedrum) * remove 'final' from methods in OAuth[10a|20]Service to allow mocking it * fix Pinterest API (thanks to https://github.com/sschwieb) + * add Yahoo2 API (thanks to https://github.com/javatestcase) [5.2.0-java7again] * allow 'null' as callback. It's an optional parameter. Remove "oob" as default (thanks to https://github.com/massongit) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/YahooApi20.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/YahooApi20.java index 11c2f3745..bc50f6779 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/YahooApi20.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/YahooApi20.java @@ -1,9 +1,6 @@ package com.github.scribejava.apis; -import com.github.scribejava.apis.openid.OpenIdJsonTokenExtractor; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.extractors.TokenExtractor; -import com.github.scribejava.core.model.OAuth2AccessToken; public class YahooApi20 extends DefaultApi20 { @@ -27,10 +24,4 @@ public String getAccessTokenEndpoint() { protected String getAuthorizationBaseUrl() { return "https://api.login.yahoo.com/oauth2/request_auth"; } - - @Override - public TokenExtractor getAccessTokenExtractor() { - return OpenIdJsonTokenExtractor.instance(); - } - } diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Yahoo20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Yahoo20Example.java index cefd55cce..c2e003876 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Yahoo20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Yahoo20Example.java @@ -22,9 +22,8 @@ */ public class Yahoo20Example { - // Update PROTECTED_RESOURCE_URL to a secure URL only you could reach = your profile, or private fantasy sports private static final String PROTECTED_RESOURCE_URL - = "https://baseball.fantasysports.yahoo.com/b1/ ADD TEAM HERE!!!!"; + = "https://fantasysports.yahooapis.com/fantasy/v2/users;use_login=1/games/teams"; private Yahoo20Example() { } From ba7f6f900ac33b92294dd215326bb449c9594272 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 6 Mar 2018 14:25:33 +0300 Subject: [PATCH 459/882] fix Tumblr urls, convert to https (thanks to https://github.com/highthunder) --- changelog | 1 + .../java/com/github/scribejava/apis/AWeberApi.java | 7 +++---- .../java/com/github/scribejava/apis/DiggApi.java | 8 +++----- .../java/com/github/scribejava/apis/EtsyApi.java | 7 +++---- .../java/com/github/scribejava/apis/FlickrApi.java | 11 +++-------- .../com/github/scribejava/apis/FoursquareApi.java | 7 +++---- .../com/github/scribejava/apis/FreelancerApi.java | 11 +++++------ .../com/github/scribejava/apis/LinkedInApi.java | 7 +++---- .../java/com/github/scribejava/apis/MeetupApi.java | 7 +++---- .../github/scribejava/apis/NeteaseWeibooApi.java | 7 +++---- .../java/com/github/scribejava/apis/Px500Api.java | 7 +++---- .../com/github/scribejava/apis/SinaWeiboApi.java | 7 +++---- .../java/com/github/scribejava/apis/SkyrockApi.java | 7 +++---- .../com/github/scribejava/apis/SohuWeiboApi.java | 7 +++---- .../java/com/github/scribejava/apis/TrelloApi.java | 7 +++---- .../java/com/github/scribejava/apis/TumblrApi.java | 7 +++---- .../java/com/github/scribejava/apis/TwitterApi.java | 13 ++++++------- .../java/com/github/scribejava/apis/UcozApi.java | 6 +++--- .../java/com/github/scribejava/apis/XingApi.java | 7 +++---- .../java/com/github/scribejava/apis/YahooApi.java | 7 +++---- .../scribejava/core/builder/api/DefaultApi10a.java | 10 +++++++++- 21 files changed, 72 insertions(+), 86 deletions(-) diff --git a/changelog b/changelog index 801b51715..2bfabdf62 100644 --- a/changelog +++ b/changelog @@ -3,6 +3,7 @@ * remove 'final' from methods in OAuth[10a|20]Service to allow mocking it * fix Pinterest API (thanks to https://github.com/sschwieb) * add Yahoo2 API (thanks to https://github.com/javatestcase) + * fix Tumblr urls, convert to https (thanks to https://github.com/highthunder) [5.2.0-java7again] * allow 'null' as callback. It's an optional parameter. Remove "oob" as default (thanks to https://github.com/massongit) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/AWeberApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/AWeberApi.java index fe5d86691..84e5117df 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/AWeberApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/AWeberApi.java @@ -1,11 +1,10 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi10a; -import com.github.scribejava.core.model.OAuth1RequestToken; public class AWeberApi extends DefaultApi10a { - private static final String AUTHORIZE_URL = "https://auth.aweber.com/1.0/oauth/authorize?oauth_token=%s"; + private static final String AUTHORIZE_URL = "https://auth.aweber.com/1.0/oauth/authorize"; private static final String REQUEST_TOKEN_ENDPOINT = "https://auth.aweber.com/1.0/oauth/request_token"; private static final String ACCESS_TOKEN_ENDPOINT = "https://auth.aweber.com/1.0/oauth/access_token"; @@ -31,7 +30,7 @@ public String getRequestTokenEndpoint() { } @Override - public String getAuthorizationUrl(OAuth1RequestToken requestToken) { - return String.format(AUTHORIZE_URL, requestToken.getToken()); + public String getAuthorizationBaseUrl() { + return AUTHORIZE_URL; } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/DiggApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/DiggApi.java index 047537d8a..c7e8e1bd1 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/DiggApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/DiggApi.java @@ -1,11 +1,10 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi10a; -import com.github.scribejava.core.model.OAuth1RequestToken; public class DiggApi extends DefaultApi10a { - private static final String AUTHORIZATION_URL = "http://digg.com/oauth/authorize?oauth_token=%s"; + private static final String AUTHORIZATION_URL = "http://digg.com/oauth/authorize"; private static final String BASE_URL = "http://services.digg.com/oauth/"; protected DiggApi() { @@ -30,8 +29,7 @@ public String getAccessTokenEndpoint() { } @Override - public String getAuthorizationUrl(OAuth1RequestToken requestToken) { - return String.format(AUTHORIZATION_URL, requestToken.getToken()); + public String getAuthorizationBaseUrl() { + return AUTHORIZATION_URL; } - } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/EtsyApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/EtsyApi.java index bd8a660ba..289f83588 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/EtsyApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/EtsyApi.java @@ -1,11 +1,10 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi10a; -import com.github.scribejava.core.model.OAuth1RequestToken; public class EtsyApi extends DefaultApi10a { - private static final String AUTHORIZE_URL = "https://www.etsy.com/oauth/signin?oauth_token=%s"; + private static final String AUTHORIZE_URL = "https://www.etsy.com/oauth/signin"; private static final String ACCESS_TOKEN_URL = "https://openapi.etsy.com/v2/oauth/access_token"; private static final String REQUEST_TOKEN_URL = "https://openapi.etsy.com/v2/oauth/request_token"; @@ -46,7 +45,7 @@ public String getRequestTokenEndpoint() { } @Override - public String getAuthorizationUrl(OAuth1RequestToken requestToken) { - return String.format(AUTHORIZE_URL, requestToken.getToken()); + public String getAuthorizationBaseUrl() { + return AUTHORIZE_URL; } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/FlickrApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/FlickrApi.java index aafc6bbd8..33432f2bb 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/FlickrApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/FlickrApi.java @@ -1,7 +1,6 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi10a; -import com.github.scribejava.core.model.OAuth1RequestToken; /** * OAuth API for Flickr. @@ -10,7 +9,7 @@ */ public class FlickrApi extends DefaultApi10a { - private static final String AUTHORIZE_URL = "https://www.flickr.com/services/oauth/authorize?oauth_token=%s"; + private static final String AUTHORIZE_URL = "https://www.flickr.com/services/oauth/authorize"; public enum FlickrPerm { READ, WRITE, DELETE @@ -49,13 +48,9 @@ public String getAccessTokenEndpoint() { return "https://www.flickr.com/services/oauth/access_token"; } - /** - * {@inheritDoc} - */ @Override - public String getAuthorizationUrl(OAuth1RequestToken requestToken) { - final String authUrl = String.format(AUTHORIZE_URL, requestToken.getToken()); - return permString == null ? authUrl : authUrl + "&perms=" + permString; + public String getAuthorizationBaseUrl() { + return permString == null ? AUTHORIZE_URL : AUTHORIZE_URL + "?perms=" + permString; } /** diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/FoursquareApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/FoursquareApi.java index 69111d235..d10a184db 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/FoursquareApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/FoursquareApi.java @@ -1,11 +1,10 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi10a; -import com.github.scribejava.core.model.OAuth1RequestToken; public class FoursquareApi extends DefaultApi10a { - private static final String AUTHORIZATION_URL = "http://foursquare.com/oauth/authorize?oauth_token=%s"; + private static final String AUTHORIZATION_URL = "http://foursquare.com/oauth/authorize"; protected FoursquareApi() { } @@ -29,7 +28,7 @@ public String getRequestTokenEndpoint() { } @Override - public String getAuthorizationUrl(OAuth1RequestToken requestToken) { - return String.format(AUTHORIZATION_URL, requestToken.getToken()); + public String getAuthorizationBaseUrl() { + return AUTHORIZATION_URL; } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/FreelancerApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/FreelancerApi.java index 65b64c04f..b5c302ffc 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/FreelancerApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/FreelancerApi.java @@ -2,12 +2,11 @@ import com.github.scribejava.core.builder.api.DefaultApi10a; import com.github.scribejava.core.builder.api.OAuth1SignatureType; -import com.github.scribejava.core.model.OAuth1RequestToken; import com.github.scribejava.core.model.Verb; public class FreelancerApi extends DefaultApi10a { - private static final String AUTHORIZATION_URL = "http://www.freelancer.com/users/api-token/auth.php?oauth_token=%s"; + private static final String AUTHORIZATION_URL = "http://www.freelancer.com/users/api-token/auth.php"; protected FreelancerApi() { } @@ -46,8 +45,8 @@ public Verb getRequestTokenVerb() { } @Override - public String getAuthorizationUrl(OAuth1RequestToken requestToken) { - return String.format(AUTHORIZATION_URL, requestToken.getToken()); + public String getAuthorizationBaseUrl() { + return AUTHORIZATION_URL; } public static class Sandbox extends FreelancerApi { @@ -77,8 +76,8 @@ public String getAccessTokenEndpoint() { } @Override - public String getAuthorizationUrl(OAuth1RequestToken requestToken) { - return String.format(SANDBOX_AUTHORIZATION_URL + "?oauth_token=%s", requestToken.getToken()); + public String getAuthorizationBaseUrl() { + return SANDBOX_AUTHORIZATION_URL; } } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi.java index f30b44d17..62258bbec 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi.java @@ -1,11 +1,10 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi10a; -import com.github.scribejava.core.model.OAuth1RequestToken; public class LinkedInApi extends DefaultApi10a { - private static final String AUTHORIZE_URL = "https://api.linkedin.com/uas/oauth/authenticate?oauth_token=%s"; + private static final String AUTHORIZE_URL = "https://api.linkedin.com/uas/oauth/authenticate"; private static final String REQUEST_TOKEN_URL = "https://api.linkedin.com/uas/oauth/requestToken"; private final String scopesAsString; @@ -46,7 +45,7 @@ public String getRequestTokenEndpoint() { } @Override - public String getAuthorizationUrl(OAuth1RequestToken requestToken) { - return String.format(AUTHORIZE_URL, requestToken.getToken()); + public String getAuthorizationBaseUrl() { + return AUTHORIZE_URL; } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/MeetupApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/MeetupApi.java index b00db6159..b2acc5680 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/MeetupApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/MeetupApi.java @@ -1,14 +1,13 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi10a; -import com.github.scribejava.core.model.OAuth1RequestToken; /** * OAuth access to the Meetup.com API. For more information visit http://www.meetup.com/api */ public class MeetupApi extends DefaultApi10a { - private static final String AUTHORIZE_URL = "http://www.meetup.com/authenticate?oauth_token=%s"; + private static final String AUTHORIZE_URL = "http://www.meetup.com/authenticate"; protected MeetupApi() { } @@ -32,7 +31,7 @@ public String getAccessTokenEndpoint() { } @Override - public String getAuthorizationUrl(OAuth1RequestToken requestToken) { - return String.format(AUTHORIZE_URL, requestToken.getToken()); + public String getAuthorizationBaseUrl() { + return AUTHORIZE_URL; } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/NeteaseWeibooApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/NeteaseWeibooApi.java index 91edb38ca..2446b5f58 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/NeteaseWeibooApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/NeteaseWeibooApi.java @@ -1,14 +1,13 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi10a; -import com.github.scribejava.core.model.OAuth1RequestToken; import com.github.scribejava.core.model.OAuth1Token; public class NeteaseWeibooApi extends DefaultApi10a { private static final String REQUEST_TOKEN_URL = "http://api.t.163.com/oauth/request_token"; private static final String ACCESS_TOKEN_URL = "http://api.t.163.com/oauth/access_token"; - private static final String AUTHORIZE_URL = "http://api.t.163.com/oauth/authorize?oauth_token=%s"; + private static final String AUTHORIZE_URL = "http://api.t.163.com/oauth/authorize"; private static final String AUTHENTICATE_URL = "http://api.t.163.com/oauth/authenticate?oauth_token=%s"; protected NeteaseWeibooApi() { @@ -41,8 +40,8 @@ public String getAccessTokenEndpoint() { * @return url to redirect user to (to get code) */ @Override - public String getAuthorizationUrl(OAuth1RequestToken requestToken) { - return String.format(AUTHORIZE_URL, requestToken.getToken()); + public String getAuthorizationBaseUrl() { + return AUTHORIZE_URL; } /** diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/Px500Api.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/Px500Api.java index 2c4e6de3c..91e34a449 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/Px500Api.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/Px500Api.java @@ -1,11 +1,10 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi10a; -import com.github.scribejava.core.model.OAuth1RequestToken; public class Px500Api extends DefaultApi10a { - private static final String AUTHORIZATION_URL = "https://api.500px.com/v1/oauth/authorize?oauth_token=%s"; + private static final String AUTHORIZATION_URL = "https://api.500px.com/v1/oauth/authorize"; protected Px500Api() { } @@ -29,7 +28,7 @@ public String getRequestTokenEndpoint() { } @Override - public String getAuthorizationUrl(OAuth1RequestToken requestToken) { - return String.format(AUTHORIZATION_URL, requestToken.getToken()); + public String getAuthorizationBaseUrl() { + return AUTHORIZATION_URL; } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/SinaWeiboApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/SinaWeiboApi.java index b91108c18..9d69a9afc 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/SinaWeiboApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/SinaWeiboApi.java @@ -1,13 +1,12 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi10a; -import com.github.scribejava.core.model.OAuth1RequestToken; public class SinaWeiboApi extends DefaultApi10a { private static final String REQUEST_TOKEN_URL = "http://api.t.sina.com.cn/oauth/request_token"; private static final String ACCESS_TOKEN_URL = "http://api.t.sina.com.cn/oauth/access_token"; - private static final String AUTHORIZE_URL = "http://api.t.sina.com.cn/oauth/authorize?oauth_token=%s"; + private static final String AUTHORIZE_URL = "http://api.t.sina.com.cn/oauth/authorize"; protected SinaWeiboApi() { } @@ -31,7 +30,7 @@ public String getAccessTokenEndpoint() { } @Override - public String getAuthorizationUrl(OAuth1RequestToken requestToken) { - return String.format(AUTHORIZE_URL, requestToken.getToken()); + public String getAuthorizationBaseUrl() { + return AUTHORIZE_URL; } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/SkyrockApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/SkyrockApi.java index 02c0eb533..beb956a4a 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/SkyrockApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/SkyrockApi.java @@ -1,7 +1,6 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi10a; -import com.github.scribejava.core.model.OAuth1RequestToken; /** * OAuth API for Skyrock. @@ -12,7 +11,7 @@ public class SkyrockApi extends DefaultApi10a { private static final String API_ENDPOINT = "https://api.skyrock.com/v2"; private static final String REQUEST_TOKEN_RESOURCE = "/oauth/initiate"; - private static final String AUTHORIZE_URL = "/oauth/authorize?oauth_token=%s"; + private static final String AUTHORIZE_URL = "/oauth/authorize"; private static final String ACCESS_TOKEN_RESOURCE = "/oauth/token"; protected SkyrockApi() { @@ -37,7 +36,7 @@ public String getRequestTokenEndpoint() { } @Override - public String getAuthorizationUrl(OAuth1RequestToken requestToken) { - return String.format(API_ENDPOINT + AUTHORIZE_URL, requestToken.getToken()); + public String getAuthorizationBaseUrl() { + return API_ENDPOINT + AUTHORIZE_URL; } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/SohuWeiboApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/SohuWeiboApi.java index 6ef769c6a..a8447efd0 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/SohuWeiboApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/SohuWeiboApi.java @@ -1,13 +1,12 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi10a; -import com.github.scribejava.core.model.OAuth1RequestToken; public class SohuWeiboApi extends DefaultApi10a { private static final String REQUEST_TOKEN_URL = "http://api.t.sohu.com/oauth/request_token"; private static final String ACCESS_TOKEN_URL = "http://api.t.sohu.com/oauth/access_token"; - private static final String AUTHORIZE_URL = "http://api.t.sohu.com/oauth/authorize?oauth_token=%s"; + private static final String AUTHORIZE_URL = "http://api.t.sohu.com/oauth/authorize"; protected SohuWeiboApi() { } @@ -31,7 +30,7 @@ public String getAccessTokenEndpoint() { } @Override - public String getAuthorizationUrl(OAuth1RequestToken requestToken) { - return String.format(AUTHORIZE_URL, requestToken.getToken()); + public String getAuthorizationBaseUrl() { + return AUTHORIZE_URL; } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/TrelloApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/TrelloApi.java index 8fd95f7a2..438f57402 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/TrelloApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/TrelloApi.java @@ -1,11 +1,10 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi10a; -import com.github.scribejava.core.model.OAuth1RequestToken; public class TrelloApi extends DefaultApi10a { - private static final String AUTHORIZE_URL = "https://trello.com/1/OAuthAuthorizeToken?oauth_token=%s"; + private static final String AUTHORIZE_URL = "https://trello.com/1/OAuthAuthorizeToken"; protected TrelloApi() { } @@ -29,8 +28,8 @@ public String getRequestTokenEndpoint() { } @Override - public String getAuthorizationUrl(OAuth1RequestToken requestToken) { - return String.format(AUTHORIZE_URL, requestToken.getToken()); + public String getAuthorizationBaseUrl() { + return AUTHORIZE_URL; } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/TumblrApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/TumblrApi.java index 0d735ae27..111bf3342 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/TumblrApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/TumblrApi.java @@ -1,11 +1,10 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi10a; -import com.github.scribejava.core.model.OAuth1RequestToken; public class TumblrApi extends DefaultApi10a { - private static final String AUTHORIZE_URL = "https://www.tumblr.com/oauth/authorize?oauth_token=%s"; + private static final String AUTHORIZE_URL = "https://www.tumblr.com/oauth/authorize"; private static final String REQUEST_TOKEN_RESOURCE = "https://www.tumblr.com/oauth/request_token"; private static final String ACCESS_TOKEN_RESOURCE = "https://www.tumblr.com/oauth/access_token"; @@ -31,7 +30,7 @@ public String getRequestTokenEndpoint() { } @Override - public String getAuthorizationUrl(OAuth1RequestToken requestToken) { - return String.format(AUTHORIZE_URL, requestToken.getToken()); + public String getAuthorizationBaseUrl() { + return AUTHORIZE_URL; } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/TwitterApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/TwitterApi.java index 3d8a2aba7..d18c22b16 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/TwitterApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/TwitterApi.java @@ -1,11 +1,10 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi10a; -import com.github.scribejava.core.model.OAuth1RequestToken; public class TwitterApi extends DefaultApi10a { - private static final String AUTHORIZE_URL = "https://api.twitter.com/oauth/authorize?oauth_token=%s"; + private static final String AUTHORIZE_URL = "https://api.twitter.com/oauth/authorize"; private static final String REQUEST_TOKEN_RESOURCE = "api.twitter.com/oauth/request_token"; private static final String ACCESS_TOKEN_RESOURCE = "api.twitter.com/oauth/access_token"; @@ -31,8 +30,8 @@ public String getRequestTokenEndpoint() { } @Override - public String getAuthorizationUrl(OAuth1RequestToken requestToken) { - return String.format(AUTHORIZE_URL, requestToken.getToken()); + public String getAuthorizationBaseUrl() { + return AUTHORIZE_URL; } /** @@ -42,7 +41,7 @@ public String getAuthorizationUrl(OAuth1RequestToken requestToken) { */ public static class Authenticate extends TwitterApi { - private static final String AUTHENTICATE_URL = "https://api.twitter.com/oauth/authenticate?oauth_token=%s"; + private static final String AUTHENTICATE_URL = "https://api.twitter.com/oauth/authenticate"; private Authenticate() { } @@ -56,8 +55,8 @@ public static Authenticate instance() { } @Override - public String getAuthorizationUrl(OAuth1RequestToken requestToken) { - return String.format(AUTHENTICATE_URL, requestToken.getToken()); + public String getAuthorizationBaseUrl() { + return AUTHENTICATE_URL; } } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/UcozApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/UcozApi.java index 208eddc38..1a8992704 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/UcozApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/UcozApi.java @@ -8,7 +8,7 @@ import com.github.scribejava.core.model.OAuth1RequestToken; public class UcozApi extends DefaultApi10a { - private static final String AUTHORIZE_URL = "http://uapi.ucoz.com/accounts/oauthauthorizetoken?oauth_token=%s"; + private static final String AUTHORIZE_URL = "http://uapi.ucoz.com/accounts/oauthauthorizetoken"; protected UcozApi() { } @@ -32,8 +32,8 @@ public String getRequestTokenEndpoint() { } @Override - public String getAuthorizationUrl(OAuth1RequestToken requestToken) { - return String.format(AUTHORIZE_URL, requestToken.getToken()); + public String getAuthorizationBaseUrl() { + return AUTHORIZE_URL; } @Override diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/XingApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/XingApi.java index 5bef0670b..b83da3679 100755 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/XingApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/XingApi.java @@ -1,11 +1,10 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi10a; -import com.github.scribejava.core.model.OAuth1RequestToken; public class XingApi extends DefaultApi10a { - private static final String AUTHORIZE_URL = "https://api.xing.com/v1/authorize?oauth_token=%s"; + private static final String AUTHORIZE_URL = "https://api.xing.com/v1/authorize"; protected XingApi() { } @@ -29,8 +28,8 @@ public String getRequestTokenEndpoint() { } @Override - public String getAuthorizationUrl(OAuth1RequestToken requestToken) { - return String.format(AUTHORIZE_URL, requestToken.getToken()); + public String getAuthorizationBaseUrl() { + return AUTHORIZE_URL; } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/YahooApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/YahooApi.java index 18352fdb0..6f3be2038 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/YahooApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/YahooApi.java @@ -1,11 +1,10 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi10a; -import com.github.scribejava.core.model.OAuth1RequestToken; public class YahooApi extends DefaultApi10a { - private static final String AUTHORIZE_URL = "https://api.login.yahoo.com/oauth/v2/request_auth?oauth_token=%s"; + private static final String AUTHORIZE_URL = "https://api.login.yahoo.com/oauth/v2/request_auth"; protected YahooApi() { } @@ -29,7 +28,7 @@ public String getRequestTokenEndpoint() { } @Override - public String getAuthorizationUrl(OAuth1RequestToken requestToken) { - return String.format(AUTHORIZE_URL, requestToken.getToken()); + public String getAuthorizationBaseUrl() { + return AUTHORIZE_URL; } } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi10a.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi10a.java index b7167a86e..a9db2c031 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi10a.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi10a.java @@ -16,6 +16,8 @@ import com.github.scribejava.core.extractors.TokenExtractor; import com.github.scribejava.core.model.OAuth1AccessToken; import com.github.scribejava.core.model.OAuth1RequestToken; +import com.github.scribejava.core.model.OAuthConstants; +import com.github.scribejava.core.model.ParameterList; /** * Default implementation of the OAuth protocol, version 1.0a @@ -125,13 +127,19 @@ public Verb getRequestTokenVerb() { */ public abstract String getAccessTokenEndpoint(); + protected abstract String getAuthorizationBaseUrl(); + /** * Returns the URL where you should redirect your users to authenticate your application. * * @param requestToken the request token you need to authorize * @return the URL where you should redirect your users */ - public abstract String getAuthorizationUrl(OAuth1RequestToken requestToken); + public String getAuthorizationUrl(OAuth1RequestToken requestToken) { + final ParameterList parameters = new ParameterList(); + parameters.add(OAuthConstants.TOKEN, requestToken.getToken()); + return parameters.appendTo(getAuthorizationBaseUrl()); + } @Override public OAuth10aService createService(OAuthConfig config) { From 255a8e622a343b3b7401916af6cf92baa538bf16 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 7 Mar 2018 12:57:07 +0300 Subject: [PATCH 460/882] fix: allow spaces in scope param in OAuth2Accesstoken response --- changelog | 1 + .../OAuth2AccessTokenJsonExtractor.java | 2 +- .../OAuth2AccessTokenJsonExtractorTest.java | 29 +++++++++++++++++-- 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/changelog b/changelog index 2bfabdf62..ddf57c5fa 100644 --- a/changelog +++ b/changelog @@ -4,6 +4,7 @@ * fix Pinterest API (thanks to https://github.com/sschwieb) * add Yahoo2 API (thanks to https://github.com/javatestcase) * fix Tumblr urls, convert to https (thanks to https://github.com/highthunder) + * fix: allow spaces in scope param in OAuth2Accesstoken response [5.2.0-java7again] * allow 'null' as callback. It's an optional parameter. Remove "oob" as default (thanks to https://github.com/massongit) diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractor.java b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractor.java index 892b322be..e49831daf 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractor.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractor.java @@ -19,7 +19,7 @@ public class OAuth2AccessTokenJsonExtractor implements TokenExtractor Date: Wed, 7 Mar 2018 13:13:30 +0300 Subject: [PATCH 461/882] =?UTF-8?q?add=20required=20param=20version=20to?= =?UTF-8?q?=20VK=20=D0=92=D0=9A=D0=BE=D0=BD=D1=82=D0=B0=D0=BA=D1=82=D0=B5?= =?UTF-8?q?=20(http://vk.com/)=20urls?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- changelog | 1 + .../main/java/com/github/scribejava/apis/VkontakteApi.java | 4 +++- .../com/github/scribejava/apis/examples/VkontakteExample.java | 3 ++- .../apis/examples/VkontakteExternalHttpExample.java | 3 ++- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/changelog b/changelog index ddf57c5fa..6d764ca89 100644 --- a/changelog +++ b/changelog @@ -5,6 +5,7 @@ * add Yahoo2 API (thanks to https://github.com/javatestcase) * fix Tumblr urls, convert to https (thanks to https://github.com/highthunder) * fix: allow spaces in scope param in OAuth2Accesstoken response + * add required param version to VK ВКонтакте (http://vk.com/) urls [5.2.0-java7again] * allow 'null' as callback. It's an optional parameter. Remove "oob" as default (thanks to https://github.com/massongit) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/VkontakteApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/VkontakteApi.java index 7472dba2e..d5c6e48e8 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/VkontakteApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/VkontakteApi.java @@ -7,6 +7,8 @@ public class VkontakteApi extends DefaultApi20 { + public static final String VERSION = "5.73"; + protected VkontakteApi() { } @@ -30,7 +32,7 @@ public String getAccessTokenEndpoint() { @Override protected String getAuthorizationBaseUrl() { - return "https://oauth.vk.com/authorize"; + return "https://oauth.vk.com/authorize?v=" + VERSION; } @Override diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExample.java index b8f1fd2fc..e24261831 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExample.java @@ -14,7 +14,8 @@ public final class VkontakteExample { private static final String NETWORK_NAME = "Vkontakte.ru"; - private static final String PROTECTED_RESOURCE_URL = "https://api.vk.com/method/users.get"; + private static final String PROTECTED_RESOURCE_URL = "https://api.vk.com/method/users.get?v=" + + VkontakteApi.VERSION; private VkontakteExample() { } diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExternalHttpExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExternalHttpExample.java index 1be173c64..eb0958491 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExternalHttpExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExternalHttpExample.java @@ -17,7 +17,8 @@ public class VkontakteExternalHttpExample { private static final String NETWORK_NAME = "Vkontakte.ru"; - private static final String PROTECTED_RESOURCE_URL = "https://api.vk.com/method/users.get"; + private static final String PROTECTED_RESOURCE_URL = "https://api.vk.com/method/users.get?v=" + + VkontakteApi.VERSION; private VkontakteExternalHttpExample() { } From 48f5f159eb081ac0a8c5e45b0164414eed82fa17 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 7 Mar 2018 13:27:56 +0300 Subject: [PATCH 462/882] update deps --- pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index 9fec9cbbb..664d9efa1 100644 --- a/pom.xml +++ b/pom.xml @@ -71,7 +71,7 @@ com.squareup.okhttp3 mockwebserver - 3.9.1 + 3.10.0 test diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index c158ba42f..c8d9ff1d7 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -23,7 +23,7 @@ org.asynchttpclient async-http-client - 2.1.2 + 2.4.3 com.github.scribejava diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index 7fc9b7b62..285898fc2 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -23,7 +23,7 @@ org.apache.httpcomponents httpclient - 4.5.4 + 4.5.5 org.apache.httpcomponents diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 6c7d94c39..b627d31b6 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -23,7 +23,7 @@ com.squareup.okhttp3 okhttp - 3.9.1 + 3.10.0 com.github.scribejava From 78dffc5c98b3221abb60593109b1b82224862aff Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 7 Mar 2018 13:36:00 +0300 Subject: [PATCH 463/882] prepare release 5.3.0 --- README.md | 4 ++-- changelog | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 7359b47da..f56e24a64 100644 --- a/README.md +++ b/README.md @@ -109,7 +109,7 @@ You can pull ScribeJava from the central maven repository, just add these to you com.github.scribejava scribejava-apis - 5.2.0-java7again + 5.3.0 ``` @@ -118,7 +118,7 @@ And in case you need just core classes (that's it, without any external API (FB, com.github.scribejava scribejava-core - 5.2.0-java7again + 5.3.0 ``` diff --git a/changelog b/changelog index 6d764ca89..272b2b416 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,4 @@ -[SNAPSHOT] +[5.3.0] * fix Salesforce API (thanks to https://github.com/jhorowitz-firedrum) * remove 'final' from methods in OAuth[10a|20]Service to allow mocking it * fix Pinterest API (thanks to https://github.com/sschwieb) From 02b12a661af6c5ce5e0f4a289bd16ee8337293e3 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 7 Mar 2018 13:37:12 +0300 Subject: [PATCH 464/882] [maven-release-plugin] prepare release scribejava-5.3.0 --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index 664d9efa1..fedc439d1 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 5.2.1-SNAPSHOT + 5.3.0 ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -34,7 +34,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - HEAD + scribejava-5.3.0 diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index b2f8f67a5..8a1b38954 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.2.1-SNAPSHOT + 5.3.0 ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index b4bccf1c3..012f293f1 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.2.1-SNAPSHOT + 5.3.0 ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index c8d9ff1d7..16f664e81 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.2.1-SNAPSHOT + 5.3.0 ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index 285898fc2..fc1495b2a 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.2.1-SNAPSHOT + 5.3.0 ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index f688e597d..86236ef2a 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.2.1-SNAPSHOT + 5.3.0 ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index b627d31b6..1423f32e0 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.2.1-SNAPSHOT + 5.3.0 ../pom.xml From dc54b59032f1c53c4366b998695da8a1b253fe33 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 7 Mar 2018 13:37:22 +0300 Subject: [PATCH 465/882] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index fedc439d1..95d3f3d46 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 5.3.0 + 5.3.1-SNAPSHOT ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -34,7 +34,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - scribejava-5.3.0 + HEAD diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 8a1b38954..f6e826693 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.3.0 + 5.3.1-SNAPSHOT ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 012f293f1..d9ddaeb76 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.3.0 + 5.3.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 16f664e81..49ac5ad69 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.3.0 + 5.3.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index fc1495b2a..0bd9b04ec 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.3.0 + 5.3.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index 86236ef2a..7b5e1b0e4 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.3.0 + 5.3.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 1423f32e0..674113b2f 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.3.0 + 5.3.1-SNAPSHOT ../pom.xml From 7228206ba015454f29f3574ad1c6078ffdc3a889 Mon Sep 17 00:00:00 2001 From: Sriram Date: Fri, 9 Mar 2018 11:35:14 -0800 Subject: [PATCH 466/882] Added Automatic OAuth2 API Signed-off-by: Sriram --- README.md | 1 + .../github/scribejava/apis/AutomaticAPI.java | 58 +++++++++++++ .../apis/examples/AutomaticExample.java | 83 +++++++++++++++++++ 3 files changed, 142 insertions(+) create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/AutomaticAPI.java create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AutomaticExample.java diff --git a/README.md b/README.md index f56e24a64..e321a9547 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,7 @@ ScribeJava support out-of-box several HTTP clients: ### Supports all major 1.0a and 2.0 OAuth APIs out-of-the-box +* Automatic (http://www.automatic.com/) * AWeber (http://www.aweber.com/) * Box (https://www.box.com/) * Dataporten (https://docs.dataporten.no/) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/AutomaticAPI.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/AutomaticAPI.java new file mode 100644 index 000000000..66f8b391a --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/AutomaticAPI.java @@ -0,0 +1,58 @@ +package com.github.scribejava.apis; + +import com.github.scribejava.core.builder.api.ClientAuthenticationType; +import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.extractors.OAuth2AccessTokenExtractor; +import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; +import com.github.scribejava.core.extractors.TokenExtractor; +import com.github.scribejava.core.model.OAuth2AccessToken; +import com.github.scribejava.core.model.Verb; + +public class AutomaticAPI extends DefaultApi20 { + + private static final String AUTHORIZE_URL = "https://accounts.automatic.com/oauth/authorize"; + private static final String REFRESH_TOKEN_ENDPOINT = "https://accounts.automatic.com/oauth/refresh_token"; + private static final String ACCESS_TOKEN_ENDPOINT = "https://accounts.automatic.com/oauth/access_token"; + + protected AutomaticAPI() { + } + + private static class InstanceHolder { + private static final AutomaticAPI INSTANCE = new AutomaticAPI(); + } + + public static AutomaticAPI instance() { + return InstanceHolder.INSTANCE; + } + + @Override + public Verb getAccessTokenVerb() { + return Verb.POST; + } + + @Override + public String getAccessTokenEndpoint() { + return ACCESS_TOKEN_ENDPOINT; + } + + @Override + public String getRefreshTokenEndpoint() { + return REFRESH_TOKEN_ENDPOINT; + } + + @Override + protected String getAuthorizationBaseUrl() { + return AUTHORIZE_URL; + } + + @Override + public TokenExtractor getAccessTokenExtractor() { + return OAuth2AccessTokenJsonExtractor.instance(); + } + + @Override + public ClientAuthenticationType getClientAuthenticationType() { + return ClientAuthenticationType.REQUEST_BODY; + } + +} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AutomaticExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AutomaticExample.java new file mode 100644 index 000000000..e1cb6b809 --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AutomaticExample.java @@ -0,0 +1,83 @@ +package com.github.scribejava.apis.examples; + +import com.github.scribejava.apis.AutomaticAPI; +import com.github.scribejava.core.builder.ServiceBuilder; +import com.github.scribejava.core.model.OAuth2AccessToken; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.oauth.OAuth20Service; + +import java.io.IOException; +import java.util.Random; +import java.util.Scanner; +import java.util.concurrent.ExecutionException; + +public final class AutomaticExample { + + private static final String NETWORK_NAME = "Automatic"; + private static final String PROTECTED_RESOURCE_URL = "https://api.automatic.com/user/me/"; + + private AutomaticExample() { + } + + public static void main(String... args) throws IOException, InterruptedException, ExecutionException { + // Replace these with your client id and secret + final String clientId = "your client id"; + final String clientSecret = "your client secret"; + final String secretState = "secret" + new Random().nextInt(999_999); + final OAuth20Service service = new ServiceBuilder(clientId) + .apiSecret(clientSecret) + .state(secretState) + .callback("http://www.example.com/oauth_callback/") + .scope("scope:user:profile").debug() + .build(AutomaticAPI.instance()); + final Scanner in = new Scanner(System.in, "UTF-8"); + + System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); + System.out.println(); + + // Obtain the Authorization URL + System.out.println("Fetching the Authorization URL..."); + final String authorizationUrl = service.getAuthorizationUrl(); + System.out.println("Got the Authorization URL!"); + System.out.println("Now go and authorize ScribeJava here:"); + System.out.println(authorizationUrl); + System.out.println("And paste the authorization code here"); + System.out.print(">>"); + final String code = in.nextLine(); + System.out.println(); + + System.out.println("And paste the state from server here. We have set 'secretState'='" + secretState + "'."); + System.out.print(">>"); + final String value = in.nextLine(); + if (secretState.equals(value)) { + System.out.println("State value does match!"); + } else { + System.out.println("Ooops, state value does not match!"); + System.out.println("Expected = " + secretState); + System.out.println("Got = " + value); + System.out.println(); + } + + // Trade the Authorization Code for the Access Token + System.out.println("Trading the Authorization Code for an Access Token..."); + final OAuth2AccessToken accessToken = service.getAccessToken(code); + System.out.println("Got the Access Token!"); + System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); + System.out.println(); + + // Now let's go and ask for a protected resource! + System.out.println("Now we're going to access a protected resource..."); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); + service.signRequest(accessToken, request); + final Response response = service.execute(request); + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + + System.out.println(); + System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); + } +} From b4fb7f816ef849edc6c75431f65d3aac6de5ef4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tellef=20M=C3=B8llerup=20=C3=85mdal?= Date: Wed, 7 Mar 2018 14:01:20 +0100 Subject: [PATCH 467/882] Fixed missing support for scope for refresh_token grant. https://tools.ietf.org/html/rfc6749#section-6 --- .../com/github/scribejava/core/oauth/OAuth20Service.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java index 0aed00b0b..2d78ec555 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java @@ -148,8 +148,14 @@ protected OAuthRequest createRefreshTokenRequest(String refreshToken) { throw new IllegalArgumentException("The refreshToken cannot be null or empty"); } final OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getRefreshTokenEndpoint()); + final OAuthConfig config = getConfig(); - api.getClientAuthenticationType().addClientAuthentication(request, getConfig()); + api.getClientAuthenticationType().addClientAuthentication(request, config); + + final String scope = config.getScope(); + if (scope != null) { + request.addParameter(OAuthConstants.SCOPE, scope); + } request.addParameter(OAuthConstants.REFRESH_TOKEN, refreshToken); request.addParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.REFRESH_TOKEN); From 787668d196220bbc951bbb6eeacd7f263b37bc11 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 22 Mar 2018 10:51:47 +0300 Subject: [PATCH 468/882] fix missing support for scope for refresh_token grant_type [thanks to https://github.com/tlxtellef] --- changelog | 3 +++ 1 file changed, 3 insertions(+) diff --git a/changelog b/changelog index 272b2b416..8db2521eb 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,6 @@ +[SNAPSHOT] + * fix missing support for scope for refresh_token grant_type [thanks to https://github.com/tlxtellef] + [5.3.0] * fix Salesforce API (thanks to https://github.com/jhorowitz-firedrum) * remove 'final' from methods in OAuth[10a|20]Service to allow mocking it From 71f8539df1b5bfb758151d1ebc1d15def12afc0f Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 22 Mar 2018 12:21:30 +0300 Subject: [PATCH 469/882] add email field to VKOAuth2AccessToken (thanks to https://github.com/grouzen) --- changelog | 3 +- .../github/scribejava/apis/VkontakteApi.java | 9 ++++ .../apis/vk/VKJsonTokenExtractor.java | 31 ++++++++++++ .../apis/vk/VKOAuth2AccessToken.java | 50 +++++++++++++++++++ .../apis/examples/VkontakteExample.java | 7 ++- .../core/model/OAuth2AccessToken.java | 1 - 6 files changed, 98 insertions(+), 3 deletions(-) create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/vk/VKJsonTokenExtractor.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/vk/VKOAuth2AccessToken.java diff --git a/changelog b/changelog index 8db2521eb..1251ce824 100644 --- a/changelog +++ b/changelog @@ -1,5 +1,6 @@ [SNAPSHOT] - * fix missing support for scope for refresh_token grant_type [thanks to https://github.com/tlxtellef] + * fix missing support for scope for refresh_token grant_type (thanks to https://github.com/tlxtellef) + * add email field to VKOAuth2AccessToken (thanks to https://github.com/grouzen) [5.3.0] * fix Salesforce API (thanks to https://github.com/jhorowitz-firedrum) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/VkontakteApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/VkontakteApi.java index d5c6e48e8..1654ff34a 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/VkontakteApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/VkontakteApi.java @@ -1,8 +1,11 @@ package com.github.scribejava.apis; +import com.github.scribejava.apis.vk.VKJsonTokenExtractor; import com.github.scribejava.core.builder.api.ClientAuthenticationType; import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.builder.api.OAuth2SignatureType; +import com.github.scribejava.core.extractors.TokenExtractor; +import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.Verb; public class VkontakteApi extends DefaultApi20 { @@ -13,6 +16,7 @@ protected VkontakteApi() { } private static class InstanceHolder { + private static final VkontakteApi INSTANCE = new VkontakteApi(); } @@ -44,4 +48,9 @@ public OAuth2SignatureType getSignatureType() { public ClientAuthenticationType getClientAuthenticationType() { return ClientAuthenticationType.REQUEST_BODY; } + + @Override + public TokenExtractor getAccessTokenExtractor() { + return VKJsonTokenExtractor.instance(); + } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/vk/VKJsonTokenExtractor.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/vk/VKJsonTokenExtractor.java new file mode 100644 index 000000000..4e658b061 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/vk/VKJsonTokenExtractor.java @@ -0,0 +1,31 @@ +package com.github.scribejava.apis.vk; + +import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; +import java.util.regex.Pattern; + +/** + * additionally parses email + */ +public class VKJsonTokenExtractor extends OAuth2AccessTokenJsonExtractor { + + private static final Pattern EMAIL_REGEX_PATTERN = Pattern.compile("\"email\"\\s*:\\s*\"(\\S*?)\""); + + protected VKJsonTokenExtractor() { + } + + private static class InstanceHolder { + + private static final VKJsonTokenExtractor INSTANCE = new VKJsonTokenExtractor(); + } + + public static VKJsonTokenExtractor instance() { + return InstanceHolder.INSTANCE; + } + + @Override + protected VKOAuth2AccessToken createToken(String accessToken, String tokenType, Integer expiresIn, + String refreshToken, String scope, String response) { + return new VKOAuth2AccessToken(accessToken, tokenType, expiresIn, refreshToken, scope, + extractParameter(response, EMAIL_REGEX_PATTERN, false), response); + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/vk/VKOAuth2AccessToken.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/vk/VKOAuth2AccessToken.java new file mode 100644 index 000000000..a8e75992b --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/vk/VKOAuth2AccessToken.java @@ -0,0 +1,50 @@ +package com.github.scribejava.apis.vk; + +import com.github.scribejava.core.model.OAuth2AccessToken; +import java.util.Objects; + +public class VKOAuth2AccessToken extends OAuth2AccessToken { + + private static final long serialVersionUID = -3539517142527580499L; + + private final String email; + + public VKOAuth2AccessToken(String accessToken, String email, String rawResponse) { + this(accessToken, null, null, null, null, email, rawResponse); + } + + public VKOAuth2AccessToken(String accessToken, String tokenType, Integer expiresIn, String refreshToken, + String scope, String email, String rawResponse) { + super(accessToken, tokenType, expiresIn, refreshToken, scope, rawResponse); + this.email = email; + } + + public String getEmail() { + return email; + } + + @Override + public int hashCode() { + int hash = super.hashCode(); + hash = 37 * hash + Objects.hashCode(email); + return hash; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + if (!super.equals(obj)) { + return false; + } + + return Objects.equals(email, ((VKOAuth2AccessToken) obj).getEmail()); + } +} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExample.java index e24261831..5c18980b2 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExample.java @@ -3,6 +3,7 @@ import java.util.Scanner; import com.github.scribejava.core.builder.ServiceBuilder; import com.github.scribejava.apis.VkontakteApi; +import com.github.scribejava.apis.vk.VKOAuth2AccessToken; import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; @@ -26,7 +27,7 @@ public static void main(String... args) throws IOException, InterruptedException final String clientSecret = "your client secret"; final OAuth20Service service = new ServiceBuilder(clientId) .apiSecret(clientSecret) - .scope("wall,offline") // replace with desired scope + .scope("wall,offline,email") // replace with desired scope .callback("http://your.site.com/callback") .build(VkontakteApi.instance()); final Scanner in = new Scanner(System.in); @@ -50,6 +51,10 @@ public static void main(String... args) throws IOException, InterruptedException final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); + if (accessToken instanceof VKOAuth2AccessToken) { + System.out.println("it's a VKOAuth2AccessToken, it has email field = '" + + ((VKOAuth2AccessToken) accessToken).getEmail() + "'."); + } System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth2AccessToken.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth2AccessToken.java index 2b30f2031..37b951f13 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth2AccessToken.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth2AccessToken.java @@ -73,7 +73,6 @@ public OAuth2AccessToken(String accessToken, String tokenType, Integer expiresIn this.scope = scope; } - public String getAccessToken() { return accessToken; } From f399f7152feafbd723299248f42fc3e7830d749b Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 26 Mar 2018 12:44:10 +0300 Subject: [PATCH 470/882] add RFC urls to javadocs --- .../scribejava/core/extractors/BaseStringExtractorImpl.java | 4 ++++ .../scribejava/core/services/HMACSha1SignatureService.java | 1 + .../com/github/scribejava/core/services/SignatureService.java | 1 + 3 files changed, 6 insertions(+) diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/BaseStringExtractorImpl.java b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/BaseStringExtractorImpl.java index 879dac9ae..acda30254 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/BaseStringExtractorImpl.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/BaseStringExtractorImpl.java @@ -8,6 +8,7 @@ /** * Default implementation of {@link BaseStringExtractor}. Conforms to OAuth 1.0a + * https://tools.ietf.org/html/rfc5849#section-3.4.1.1 */ public class BaseStringExtractorImpl implements BaseStringExtractor { @@ -29,6 +30,9 @@ protected String getVerb(OAuthRequest request) { return request.getVerb().name(); } + /** + * https://tools.ietf.org/html/rfc5849#section-3.4.1.2 + */ protected String getUrl(OAuthRequest request) { return request.getSanitizedUrl(); } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/services/HMACSha1SignatureService.java b/scribejava-core/src/main/java/com/github/scribejava/core/services/HMACSha1SignatureService.java index 3d942fbd0..82d1135be 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/services/HMACSha1SignatureService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/services/HMACSha1SignatureService.java @@ -11,6 +11,7 @@ /** * HMAC-SHA1 implementation of {@link SignatureService} + * https://tools.ietf.org/html/rfc5849#section-3.4.2 */ public class HMACSha1SignatureService implements SignatureService { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/services/SignatureService.java b/scribejava-core/src/main/java/com/github/scribejava/core/services/SignatureService.java index 2248643c5..8cd4f2372 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/services/SignatureService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/services/SignatureService.java @@ -4,6 +4,7 @@ /** * Signs a base string, returning the OAuth signature + * https://tools.ietf.org/html/rfc5849#section-3.4 */ public interface SignatureService { Base64.Encoder BASE_64_ENCODER = Base64.getEncoder(); From 09364b69afa30e059ceb2276384cb97e465e42c4 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 4 Apr 2018 14:32:38 +0300 Subject: [PATCH 471/882] add new API - Automatic (https://www.automatic.com/) (thanks to https://github.com/ramsrib) --- README.md | 2 +- changelog | 1 + .../com/github/scribejava/apis/AutomaticAPI.java | 16 +--------------- 3 files changed, 3 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index e321a9547..939ff5343 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ ScribeJava support out-of-box several HTTP clients: ### Supports all major 1.0a and 2.0 OAuth APIs out-of-the-box -* Automatic (http://www.automatic.com/) +* Automatic (https://www.automatic.com/) * AWeber (http://www.aweber.com/) * Box (https://www.box.com/) * Dataporten (https://docs.dataporten.no/) diff --git a/changelog b/changelog index 1251ce824..f117ca857 100644 --- a/changelog +++ b/changelog @@ -1,6 +1,7 @@ [SNAPSHOT] * fix missing support for scope for refresh_token grant_type (thanks to https://github.com/tlxtellef) * add email field to VKOAuth2AccessToken (thanks to https://github.com/grouzen) + * add new API - Automatic (https://www.automatic.com/) (thanks to https://github.com/ramsrib) [5.3.0] * fix Salesforce API (thanks to https://github.com/jhorowitz-firedrum) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/AutomaticAPI.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/AutomaticAPI.java index 66f8b391a..479fc5d59 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/AutomaticAPI.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/AutomaticAPI.java @@ -2,11 +2,6 @@ import com.github.scribejava.core.builder.api.ClientAuthenticationType; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.extractors.OAuth2AccessTokenExtractor; -import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; -import com.github.scribejava.core.extractors.TokenExtractor; -import com.github.scribejava.core.model.OAuth2AccessToken; -import com.github.scribejava.core.model.Verb; public class AutomaticAPI extends DefaultApi20 { @@ -18,6 +13,7 @@ protected AutomaticAPI() { } private static class InstanceHolder { + private static final AutomaticAPI INSTANCE = new AutomaticAPI(); } @@ -25,11 +21,6 @@ public static AutomaticAPI instance() { return InstanceHolder.INSTANCE; } - @Override - public Verb getAccessTokenVerb() { - return Verb.POST; - } - @Override public String getAccessTokenEndpoint() { return ACCESS_TOKEN_ENDPOINT; @@ -45,11 +36,6 @@ protected String getAuthorizationBaseUrl() { return AUTHORIZE_URL; } - @Override - public TokenExtractor getAccessTokenExtractor() { - return OAuth2AccessTokenJsonExtractor.instance(); - } - @Override public ClientAuthenticationType getClientAuthenticationType() { return ClientAuthenticationType.REQUEST_BODY; From 4e6d8c5c90c4eaf358cc327109fba331767ce7e8 Mon Sep 17 00:00:00 2001 From: Justin Lawler Date: Tue, 10 Apr 2018 16:58:32 +0100 Subject: [PATCH 472/882] adding fitbit API --- README.md | 1 + .../github/scribejava/apis/FitbitApi20.java | 43 +++++++++ .../apis/service/Fitbit20ServiceImpl.java | 91 +++++++++++++++++++ .../apis/examples/FitbitApi20Example.java | 79 ++++++++++++++++ 4 files changed, 214 insertions(+) create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/FitbitApi20.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/service/Fitbit20ServiceImpl.java create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FitbitApi20Example.java diff --git a/README.md b/README.md index 939ff5343..07f185d5d 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,7 @@ ScribeJava support out-of-box several HTTP clients: * Доктор на работе (https://www.doktornarabote.ru/) * Etsy (https://www.etsy.com/) * Facebook (https://www.facebook.com/) +* Fitbit (https://www.fitbit.com/) * Flickr (https://www.flickr.com/) * Foursquare (https://foursquare.com/) * Frappe (https://github.com/frappe/frappe) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/FitbitApi20.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/FitbitApi20.java new file mode 100644 index 000000000..7d4fa85b2 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/FitbitApi20.java @@ -0,0 +1,43 @@ +package com.github.scribejava.apis; + +import com.github.scribejava.apis.service.Fitbit20ServiceImpl; +import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.model.OAuthConfig; +import com.github.scribejava.core.oauth.OAuth20Service; + + +/** + * Fitbit's OAuth2 client's implementation + * source: https://dev.fitbit.com/docs/oauth2/ + * + * Note - this is an updated version of this library for Scribe v5.3.0. Original code here: + * - https://github.com/alexthered/fitbitAPI20-scribe-java + */ +public class FitbitApi20 extends DefaultApi20 { + + protected FitbitApi20() { + } + + private static class InstanceHolder { + private static final FitbitApi20 INSTANCE = new FitbitApi20(); + } + + public static FitbitApi20 instance() { + return InstanceHolder.INSTANCE; + } + + @Override + public String getAccessTokenEndpoint() { + return "https://api.fitbit.com/oauth2/token"; + } + + @Override + protected String getAuthorizationBaseUrl() { + return "https://www.fitbit.com/oauth2/authorize"; + } + + @Override + public OAuth20Service createService(OAuthConfig config) { + return new Fitbit20ServiceImpl(this, config); + } +} \ No newline at end of file diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/Fitbit20ServiceImpl.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/Fitbit20ServiceImpl.java new file mode 100644 index 000000000..7884d846d --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/Fitbit20ServiceImpl.java @@ -0,0 +1,91 @@ +package com.github.scribejava.apis.service; + +import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.java8.Base64; +import com.github.scribejava.core.model.OAuthConfig; +import com.github.scribejava.core.model.OAuthConstants; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.oauth.OAuth20Service; + +import java.nio.charset.Charset; + +/** + * Created by hd on 10/09/16. + * + * Note - this is an updated version of this library for Scribe v5.3.0. Original code here: + * - https://github.com/alexthered/fitbitAPI20-scribe-java + */ +public class Fitbit20ServiceImpl extends OAuth20Service { + + public Fitbit20ServiceImpl(DefaultApi20 api, OAuthConfig config) { + super(api, config); + } + + /** + * ref: https://dev.fitbit.com/docs/oauth2/#access-token-request + * @param code + * @param request + * @param + * @return + */ + @Override + protected OAuthRequest createAccessTokenRequest(String code) + { + final DefaultApi20 api = getApi(); + final OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint()); + final OAuthConfig config = getConfig(); + request.addParameter(OAuthConstants.CLIENT_ID, config.getApiKey()); + request.addParameter(OAuthConstants.CLIENT_SECRET, config.getApiSecret()); + request.addParameter(OAuthConstants.CODE, code); + request.addParameter(OAuthConstants.REDIRECT_URI, config.getCallback()); + String scope = config.getScope(); + if (scope != null) { + request.addParameter(OAuthConstants.SCOPE, scope); + } + + //this is non-OAuth2 standard, but Fitbit requires it + request.addHeader("Authorization", "Basic " + getKeyBytesForFitbitAuth()); + + request.addParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.AUTHORIZATION_CODE); + return request; + } + + /** + * ref: https://dev.fitbit.com/docs/oauth2/#refreshing-tokens + * @param refreshToken + * @param request + * @param + * @return + */ + @Override + protected OAuthRequest createRefreshTokenRequest(String refreshToken) + { + if (refreshToken != null && !refreshToken.isEmpty()) { + final DefaultApi20 api = getApi(); + final OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint()); + final OAuthConfig config = this.getConfig(); + request.addParameter(OAuthConstants.CLIENT_ID, config.getApiKey()); + request.addParameter(OAuthConstants.CLIENT_SECRET, config.getApiSecret()); + request.addParameter(OAuthConstants.REFRESH_TOKEN, refreshToken); + request.addParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.REFRESH_TOKEN); + + //this is non-OAuth2 standard, but Fitbit requires it + request.addHeader("Authorization", "Basic " + getKeyBytesForFitbitAuth()); + + return request; + } else { + throw new IllegalArgumentException("The refreshToken cannot be null or empty"); + } + } + + /** + */ + private String getKeyBytesForFitbitAuth() + { + final OAuthConfig config = getConfig(); + String keyAndSecret = String.format("%s:%s", new Object[] {config.getApiKey(), config.getApiSecret()}); + byte[] keyBytes = Base64.getEncoder().encode(keyAndSecret.getBytes(Charset.forName("UTF-8"))); + + return new String(keyBytes); + } +} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FitbitApi20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FitbitApi20Example.java new file mode 100644 index 000000000..760dc165e --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FitbitApi20Example.java @@ -0,0 +1,79 @@ +package com.github.scribejava.apis.examples; +import java.util.Scanner; + +import com.github.scribejava.apis.FitbitApi20; +import com.github.scribejava.core.builder.ServiceBuilder; +import com.github.scribejava.core.model.OAuth2AccessToken; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.oauth.OAuth20Service; + +/** + * Created by hd on 10/09/16. + */ +public class FitbitApi20Example { + + private static final String NETWORK_NAME = "Fitbit"; + + // Replace with user ID to test API against + private static final String USER_ID = "your user id"; + private static final String PROTECTED_RESOURCE_URL = "https://api.fitbit.com/1/user/" + USER_ID + "/profile.json"; + + + private FitbitApi20Example() { + } + + public static void main(String... args) throws Exception { + + // Replace these with your client id and secret fron your app + final String clientId = "your client id"; + final String clientSecret = "your client secret"; + final OAuth20Service service = new ServiceBuilder(clientId) + .apiSecret(clientSecret) + .scope("activity profile") // replace with desired scope + .callback("http://www.example.com/oauth_callback/") //your callback URL to store and handle the authorization code sent by Fitbit + .state("some_params") + .build(FitbitApi20.instance()); + final Scanner in = new Scanner(System.in); + + System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); + System.out.println(); + + // Obtain the Authorization URL + System.out.println("Fetching the Authorization URL..."); + final String authorizationUrl = service.getAuthorizationUrl(); + System.out.println("Got the Authorization URL!"); + System.out.println("Now go and authorize ScribeJava here:"); + System.out.println(authorizationUrl); + System.out.println("And paste the authorization code here"); + System.out.print(">>"); + final String code = in.nextLine(); + System.out.println(); + + // Trade the Request Token and Verfier for the Access Token + System.out.println("Trading the Request Token for an Access Token..."); + final OAuth2AccessToken accessToken = service.getAccessToken(code); + System.out.println("Got the Access Token!"); + System.out.println("(if your curious it looks like this: " + accessToken + + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println(); + + // Now let's go and ask for a protected resource! + // This will get the profile for this user + System.out.println("Now we're going to access a protected resource..."); + + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); + request.addHeader("x-li-format", "json"); + + //add header for authentication (why make it so complicated, Fitbit?) + request.addHeader("Authorization", "Bearer " + accessToken.getAccessToken()); + + final Response response = service.execute(request); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + + System.out.println(); + } +} From 875db910f593276cacf50aa8d38f650bdffbbfb8 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 11 Apr 2018 14:56:20 +0300 Subject: [PATCH 473/882] add new API - Fitbit (https://www.fitbit.com/) (thanks to https://github.com/JustinLawler and https://github.com/alexthered) --- changelog | 1 + .../github/scribejava/apis/FitbitApi20.java | 13 +-- .../apis/fitbit/FitBitJsonTokenExtractor.java | 28 ++++++ .../apis/fitbit/FitBitOAuth2AccessToken.java | 50 ++++++++++ .../apis/service/Fitbit20ServiceImpl.java | 91 ------------------- .../apis/examples/FitbitApi20Example.java | 35 +++---- 6 files changed, 102 insertions(+), 116 deletions(-) create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractor.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/fitbit/FitBitOAuth2AccessToken.java delete mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/service/Fitbit20ServiceImpl.java diff --git a/changelog b/changelog index f117ca857..09db0ac72 100644 --- a/changelog +++ b/changelog @@ -2,6 +2,7 @@ * fix missing support for scope for refresh_token grant_type (thanks to https://github.com/tlxtellef) * add email field to VKOAuth2AccessToken (thanks to https://github.com/grouzen) * add new API - Automatic (https://www.automatic.com/) (thanks to https://github.com/ramsrib) + * add new API - Fitbit (https://www.fitbit.com/) (thanks to https://github.com/JustinLawler and https://github.com/alexthered) [5.3.0] * fix Salesforce API (thanks to https://github.com/jhorowitz-firedrum) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/FitbitApi20.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/FitbitApi20.java index 7d4fa85b2..f6e163978 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/FitbitApi20.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/FitbitApi20.java @@ -1,17 +1,12 @@ package com.github.scribejava.apis; -import com.github.scribejava.apis.service.Fitbit20ServiceImpl; +import com.github.scribejava.apis.fitbit.FitBitJsonTokenExtractor; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.model.OAuthConfig; -import com.github.scribejava.core.oauth.OAuth20Service; /** * Fitbit's OAuth2 client's implementation * source: https://dev.fitbit.com/docs/oauth2/ - * - * Note - this is an updated version of this library for Scribe v5.3.0. Original code here: - * - https://github.com/alexthered/fitbitAPI20-scribe-java */ public class FitbitApi20 extends DefaultApi20 { @@ -37,7 +32,7 @@ protected String getAuthorizationBaseUrl() { } @Override - public OAuth20Service createService(OAuthConfig config) { - return new Fitbit20ServiceImpl(this, config); + public FitBitJsonTokenExtractor getAccessTokenExtractor() { + return FitBitJsonTokenExtractor.instance(); } -} \ No newline at end of file +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractor.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractor.java new file mode 100644 index 000000000..affed2f6d --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractor.java @@ -0,0 +1,28 @@ +package com.github.scribejava.apis.fitbit; + +import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; +import java.util.regex.Pattern; + +public class FitBitJsonTokenExtractor extends OAuth2AccessTokenJsonExtractor { + + private static final Pattern USER_ID_REGEX_PATTERN = Pattern.compile("\"user_id\"\\s*:\\s*\"(\\S*?)\""); + + protected FitBitJsonTokenExtractor() { + } + + private static class InstanceHolder { + + private static final FitBitJsonTokenExtractor INSTANCE = new FitBitJsonTokenExtractor(); + } + + public static FitBitJsonTokenExtractor instance() { + return InstanceHolder.INSTANCE; + } + + @Override + protected FitBitOAuth2AccessToken createToken(String accessToken, String tokenType, Integer expiresIn, + String refreshToken, String scope, String response) { + return new FitBitOAuth2AccessToken(accessToken, tokenType, expiresIn, refreshToken, scope, + extractParameter(response, USER_ID_REGEX_PATTERN, false), response); + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/fitbit/FitBitOAuth2AccessToken.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/fitbit/FitBitOAuth2AccessToken.java new file mode 100644 index 000000000..018128bde --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/fitbit/FitBitOAuth2AccessToken.java @@ -0,0 +1,50 @@ +package com.github.scribejava.apis.fitbit; + +import com.github.scribejava.core.model.OAuth2AccessToken; +import java.util.Objects; + +public class FitBitOAuth2AccessToken extends OAuth2AccessToken { + + private static final long serialVersionUID = -6374486860742407411L; + + private final String userId; + + public FitBitOAuth2AccessToken(String accessToken, String openIdToken, String rawResponse) { + this(accessToken, null, null, null, null, openIdToken, rawResponse); + } + + public FitBitOAuth2AccessToken(String accessToken, String tokenType, Integer expiresIn, String refreshToken, + String scope, String userId, String rawResponse) { + super(accessToken, tokenType, expiresIn, refreshToken, scope, rawResponse); + this.userId = userId; + } + + public String getUserId() { + return userId; + } + + @Override + public int hashCode() { + int hash = super.hashCode(); + hash = 37 * hash + Objects.hashCode(userId); + return hash; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + if (!super.equals(obj)) { + return false; + } + + return Objects.equals(userId, ((FitBitOAuth2AccessToken) obj).getUserId()); + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/Fitbit20ServiceImpl.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/Fitbit20ServiceImpl.java deleted file mode 100644 index 7884d846d..000000000 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/Fitbit20ServiceImpl.java +++ /dev/null @@ -1,91 +0,0 @@ -package com.github.scribejava.apis.service; - -import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.java8.Base64; -import com.github.scribejava.core.model.OAuthConfig; -import com.github.scribejava.core.model.OAuthConstants; -import com.github.scribejava.core.model.OAuthRequest; -import com.github.scribejava.core.oauth.OAuth20Service; - -import java.nio.charset.Charset; - -/** - * Created by hd on 10/09/16. - * - * Note - this is an updated version of this library for Scribe v5.3.0. Original code here: - * - https://github.com/alexthered/fitbitAPI20-scribe-java - */ -public class Fitbit20ServiceImpl extends OAuth20Service { - - public Fitbit20ServiceImpl(DefaultApi20 api, OAuthConfig config) { - super(api, config); - } - - /** - * ref: https://dev.fitbit.com/docs/oauth2/#access-token-request - * @param code - * @param request - * @param - * @return - */ - @Override - protected OAuthRequest createAccessTokenRequest(String code) - { - final DefaultApi20 api = getApi(); - final OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint()); - final OAuthConfig config = getConfig(); - request.addParameter(OAuthConstants.CLIENT_ID, config.getApiKey()); - request.addParameter(OAuthConstants.CLIENT_SECRET, config.getApiSecret()); - request.addParameter(OAuthConstants.CODE, code); - request.addParameter(OAuthConstants.REDIRECT_URI, config.getCallback()); - String scope = config.getScope(); - if (scope != null) { - request.addParameter(OAuthConstants.SCOPE, scope); - } - - //this is non-OAuth2 standard, but Fitbit requires it - request.addHeader("Authorization", "Basic " + getKeyBytesForFitbitAuth()); - - request.addParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.AUTHORIZATION_CODE); - return request; - } - - /** - * ref: https://dev.fitbit.com/docs/oauth2/#refreshing-tokens - * @param refreshToken - * @param request - * @param - * @return - */ - @Override - protected OAuthRequest createRefreshTokenRequest(String refreshToken) - { - if (refreshToken != null && !refreshToken.isEmpty()) { - final DefaultApi20 api = getApi(); - final OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint()); - final OAuthConfig config = this.getConfig(); - request.addParameter(OAuthConstants.CLIENT_ID, config.getApiKey()); - request.addParameter(OAuthConstants.CLIENT_SECRET, config.getApiSecret()); - request.addParameter(OAuthConstants.REFRESH_TOKEN, refreshToken); - request.addParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.REFRESH_TOKEN); - - //this is non-OAuth2 standard, but Fitbit requires it - request.addHeader("Authorization", "Basic " + getKeyBytesForFitbitAuth()); - - return request; - } else { - throw new IllegalArgumentException("The refreshToken cannot be null or empty"); - } - } - - /** - */ - private String getKeyBytesForFitbitAuth() - { - final OAuthConfig config = getConfig(); - String keyAndSecret = String.format("%s:%s", new Object[] {config.getApiKey(), config.getApiSecret()}); - byte[] keyBytes = Base64.getEncoder().encode(keyAndSecret.getBytes(Charset.forName("UTF-8"))); - - return new String(keyBytes); - } -} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FitbitApi20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FitbitApi20Example.java index 760dc165e..72750de6b 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FitbitApi20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FitbitApi20Example.java @@ -1,7 +1,9 @@ package com.github.scribejava.apis.examples; + import java.util.Scanner; import com.github.scribejava.apis.FitbitApi20; +import com.github.scribejava.apis.fitbit.FitBitOAuth2AccessToken; import com.github.scribejava.core.builder.ServiceBuilder; import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthRequest; @@ -9,30 +11,25 @@ import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.oauth.OAuth20Service; -/** - * Created by hd on 10/09/16. - */ public class FitbitApi20Example { private static final String NETWORK_NAME = "Fitbit"; - - // Replace with user ID to test API against - private static final String USER_ID = "your user id"; - private static final String PROTECTED_RESOURCE_URL = "https://api.fitbit.com/1/user/" + USER_ID + "/profile.json"; - + private static final String PROTECTED_RESOURCE_URL = "https://api.fitbit.com/1/user/%s/profile.json"; + private FitbitApi20Example() { } public static void main(String... args) throws Exception { - + // Replace these with your client id and secret fron your app final String clientId = "your client id"; final String clientSecret = "your client secret"; final OAuth20Service service = new ServiceBuilder(clientId) .apiSecret(clientSecret) .scope("activity profile") // replace with desired scope - .callback("http://www.example.com/oauth_callback/") //your callback URL to store and handle the authorization code sent by Fitbit + //your callback URL to store and handle the authorization code sent by Fitbit + .callback("http://www.example.com/oauth_callback/") .state("some_params") .build(FitbitApi20.instance()); final Scanner in = new Scanner(System.in); @@ -53,21 +50,27 @@ public static void main(String... args) throws Exception { // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - final OAuth2AccessToken accessToken = service.getAccessToken(code); + final OAuth2AccessToken oauth2AccessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious it looks like this: " + oauth2AccessToken + + ", 'rawResponse'='" + oauth2AccessToken.getRawResponse() + "')"); System.out.println(); + if (!(oauth2AccessToken instanceof FitBitOAuth2AccessToken)) { + System.out.println("oauth2AccessToken is not instance of FitBitOAuth2AccessToken. Strange enough. exit."); + System.exit(0); + } + + final FitBitOAuth2AccessToken accessToken = (FitBitOAuth2AccessToken) oauth2AccessToken; // Now let's go and ask for a protected resource! // This will get the profile for this user System.out.println("Now we're going to access a protected resource..."); - final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); + final OAuthRequest request = new OAuthRequest(Verb.GET, + String.format(PROTECTED_RESOURCE_URL, accessToken.getUserId())); request.addHeader("x-li-format", "json"); - //add header for authentication (why make it so complicated, Fitbit?) - request.addHeader("Authorization", "Bearer " + accessToken.getAccessToken()); + service.signRequest(accessToken, request); final Response response = service.execute(request); System.out.println(); From aec994745985ef4b8e2fa2db7f2f20f3d5349186 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 18 Apr 2018 13:43:55 +0300 Subject: [PATCH 474/882] deprecate OAuthConfig --- changelog | 1 + .../github/scribejava/apis/FacebookApi.java | 21 ++++- .../com/github/scribejava/apis/ImgurApi.java | 35 +++++-- .../com/github/scribejava/apis/MailruApi.java | 21 ++++- .../MicrosoftAzureActiveDirectoryApi.java | 21 ++++- .../scribejava/apis/OdnoklassnikiApi.java | 21 ++++- .../com/github/scribejava/apis/TutByApi.java | 21 ++++- .../apis/service/FacebookService.java | 23 ++++- .../apis/service/ImgurOAuthService.java | 31 +++++-- .../apis/service/MailruOAuthService.java | 26 +++++- .../MicrosoftAzureActiveDirectoryService.java | 21 ++++- .../service/OdnoklassnikiOAuthService.java | 23 ++++- .../apis/service/TutByOAuthService.java | 21 ++++- .../apis/examples/Yahoo20Example.java | 3 +- .../core/builder/ServiceBuilder.java | 8 +- .../scribejava/core/builder/api/BaseApi.java | 13 +++ .../builder/api/ClientAuthenticationType.java | 20 ++-- .../core/builder/api/DefaultApi10a.java | 21 ++++- .../core/builder/api/DefaultApi20.java | 41 +++++++-- .../scribejava/core/model/OAuthConfig.java | 13 ++- .../scribejava/core/model/OAuthConstants.java | 3 + .../core/oauth/OAuth10aService.java | 88 +++++++++++------- .../scribejava/core/oauth/OAuth20Service.java | 59 ++++++++---- .../scribejava/core/oauth/OAuthService.java | 92 ++++++++++++++----- .../scribejava/core/AbstractClientTest.java | 5 +- .../core/builder/ServiceBuilderTest.java | 84 ----------------- .../scribejava/core/oauth/OAuth20ApiUnit.java | 21 ++++- .../core/oauth/OAuth20ServiceTest.java | 6 +- .../core/oauth/OAuth20ServiceUnit.java | 11 ++- 29 files changed, 552 insertions(+), 222 deletions(-) delete mode 100644 scribejava-core/src/test/java/com/github/scribejava/core/builder/ServiceBuilderTest.java diff --git a/changelog b/changelog index 09db0ac72..21b5817a4 100644 --- a/changelog +++ b/changelog @@ -3,6 +3,7 @@ * add email field to VKOAuth2AccessToken (thanks to https://github.com/grouzen) * add new API - Automatic (https://www.automatic.com/) (thanks to https://github.com/ramsrib) * add new API - Fitbit (https://www.fitbit.com/) (thanks to https://github.com/JustinLawler and https://github.com/alexthered) + * deprecate OAuthConfig [5.3.0] * fix Salesforce API (thanks to https://github.com/jhorowitz-firedrum) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java index 949304dfb..a2114760b 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java @@ -5,9 +5,12 @@ import com.github.scribejava.core.builder.api.ClientAuthenticationType; import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.extractors.TokenExtractor; +import com.github.scribejava.core.httpclient.HttpClient; +import com.github.scribejava.core.httpclient.HttpClientConfig; import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.Verb; +import java.io.OutputStream; /** * Facebook API @@ -67,8 +70,24 @@ public ClientAuthenticationType getClientAuthenticationType() { return ClientAuthenticationType.REQUEST_BODY; } + @Override + public FacebookService createService(String apiKey, String apiSecret, String callback, String scope, + OutputStream debugStream, String state, String responseType, String userAgent, + HttpClientConfig httpClientConfig, HttpClient httpClient) { + return new FacebookService(this, apiKey, apiSecret, callback, scope, debugStream, state, responseType, + userAgent, httpClientConfig, httpClient); + } + + /** + * @deprecated use {@link #createService(java.lang.String, java.lang.String, java.lang.String, java.lang.String, + * java.io.OutputStream, java.lang.String, java.lang.String, java.lang.String, + * com.github.scribejava.core.httpclient.HttpClientConfig, com.github.scribejava.core.httpclient.HttpClient)} + */ + @Deprecated @Override public FacebookService createService(OAuthConfig config) { - return new FacebookService(this, config); + return createService(config.getApiKey(), config.getApiSecret(), config.getCallback(), config.getScope(), + config.getDebugStream(), config.getState(), config.getResponseType(), config.getUserAgent(), + config.getHttpClientConfig(), config.getHttpClient()); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java index 477fb5e0f..720b62fd2 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java @@ -2,9 +2,12 @@ import com.github.scribejava.apis.service.ImgurOAuthService; import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.httpclient.HttpClient; +import com.github.scribejava.core.httpclient.HttpClientConfig; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.ParameterList; +import java.io.OutputStream; import java.util.Map; public class ImgurApi extends DefaultApi20 { @@ -26,22 +29,20 @@ public String getAccessTokenEndpoint() { } @Override - public String getAuthorizationUrl(OAuthConfig config, Map additionalParams) { + public String getAuthorizationUrl(String responseType, String apiKey, String callback, String scope, String state, + Map additionalParams) { final ParameterList parameters = new ParameterList(additionalParams); - parameters.add(OAuthConstants.RESPONSE_TYPE, isOob(config) ? "pin" : "code"); - parameters.add(OAuthConstants.CLIENT_ID, config.getApiKey()); + parameters.add(OAuthConstants.RESPONSE_TYPE, isOob(callback) ? "pin" : "code"); + parameters.add(OAuthConstants.CLIENT_ID, apiKey); - final String callback = config.getCallback(); if (callback != null) { parameters.add(OAuthConstants.REDIRECT_URI, callback); } - final String scope = config.getScope(); if (scope != null) { parameters.add(OAuthConstants.SCOPE, scope); } - final String state = config.getState(); if (state != null) { parameters.add(OAuthConstants.STATE, state); } @@ -54,12 +55,28 @@ protected String getAuthorizationBaseUrl() { throw new UnsupportedOperationException("use getAuthorizationUrl instead"); } + @Override + public ImgurOAuthService createService(String apiKey, String apiSecret, String callback, String scope, + OutputStream debugStream, String state, String responseType, String userAgent, + HttpClientConfig httpClientConfig, HttpClient httpClient) { + return new ImgurOAuthService(this, apiKey, apiSecret, callback, scope, debugStream, state, responseType, + userAgent, httpClientConfig, httpClient); + } + + /** + * @deprecated use {@link #createService(java.lang.String, java.lang.String, java.lang.String, java.lang.String, + * java.io.OutputStream, java.lang.String, java.lang.String, java.lang.String, + * com.github.scribejava.core.httpclient.HttpClientConfig, com.github.scribejava.core.httpclient.HttpClient)} + */ + @Deprecated @Override public ImgurOAuthService createService(OAuthConfig config) { - return new ImgurOAuthService(this, config); + return createService(config.getApiKey(), config.getApiSecret(), config.getCallback(), config.getScope(), + config.getDebugStream(), config.getState(), config.getResponseType(), config.getUserAgent(), + config.getHttpClientConfig(), config.getHttpClient()); } - public static boolean isOob(OAuthConfig config) { - return "oob".equals(config.getCallback()); + public static boolean isOob(String callback) { + return OAuthConstants.OOB.equals(callback); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java index cf9ae9903..318ab2bf2 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java @@ -3,6 +3,9 @@ import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.apis.service.MailruOAuthService; +import com.github.scribejava.core.httpclient.HttpClient; +import com.github.scribejava.core.httpclient.HttpClientConfig; +import java.io.OutputStream; public class MailruApi extends DefaultApi20 { @@ -27,8 +30,24 @@ protected String getAuthorizationBaseUrl() { return "https://connect.mail.ru/oauth/authorize"; } + @Override + public MailruOAuthService createService(String apiKey, String apiSecret, String callback, String scope, + OutputStream debugStream, String state, String responseType, String userAgent, + HttpClientConfig httpClientConfig, HttpClient httpClient) { + return new MailruOAuthService(this, apiKey, apiSecret, callback, scope, debugStream, state, responseType, + userAgent, httpClientConfig, httpClient); + } + + /** + * @deprecated use {@link #createService(java.lang.String, java.lang.String, java.lang.String, java.lang.String, + * java.io.OutputStream, java.lang.String, java.lang.String, java.lang.String, + * com.github.scribejava.core.httpclient.HttpClientConfig, com.github.scribejava.core.httpclient.HttpClient)} + */ + @Deprecated @Override public MailruOAuthService createService(OAuthConfig config) { - return new MailruOAuthService(this, config); + return createService(config.getApiKey(), config.getApiSecret(), config.getCallback(), config.getScope(), + config.getDebugStream(), config.getState(), config.getResponseType(), config.getUserAgent(), + config.getHttpClientConfig(), config.getHttpClient()); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/MicrosoftAzureActiveDirectoryApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/MicrosoftAzureActiveDirectoryApi.java index 44ea915e5..c2059d55b 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/MicrosoftAzureActiveDirectoryApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/MicrosoftAzureActiveDirectoryApi.java @@ -3,7 +3,10 @@ import com.github.scribejava.apis.service.MicrosoftAzureActiveDirectoryService; import com.github.scribejava.core.builder.api.ClientAuthenticationType; import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.httpclient.HttpClient; +import com.github.scribejava.core.httpclient.HttpClientConfig; import com.github.scribejava.core.model.OAuthConfig; +import java.io.OutputStream; /** * Microsoft Azure Active Directory Api @@ -46,9 +49,25 @@ protected String getAuthorizationBaseUrl() { return MSFT_LOGIN_URL + SLASH + COMMON + SLASH + AUTH_URI; } + @Override + public MicrosoftAzureActiveDirectoryService createService(String apiKey, String apiSecret, String callback, + String scope, OutputStream debugStream, String state, String responseType, String userAgent, + HttpClientConfig httpClientConfig, HttpClient httpClient) { + return new MicrosoftAzureActiveDirectoryService(this, apiKey, apiSecret, callback, scope, debugStream, state, + responseType, userAgent, httpClientConfig, httpClient); + } + + /** + * @deprecated use {@link #createService(java.lang.String, java.lang.String, java.lang.String, java.lang.String, + * java.io.OutputStream, java.lang.String, java.lang.String, java.lang.String, + * com.github.scribejava.core.httpclient.HttpClientConfig, com.github.scribejava.core.httpclient.HttpClient)} + */ + @Deprecated @Override public MicrosoftAzureActiveDirectoryService createService(OAuthConfig config) { - return new MicrosoftAzureActiveDirectoryService(this, config); + return createService(config.getApiKey(), config.getApiSecret(), config.getCallback(), config.getScope(), + config.getDebugStream(), config.getState(), config.getResponseType(), config.getUserAgent(), + config.getHttpClientConfig(), config.getHttpClient()); } @Override diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java index 4582d1ac9..a65f9b692 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java @@ -4,7 +4,10 @@ import com.github.scribejava.core.builder.api.ClientAuthenticationType; import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.builder.api.OAuth2SignatureType; +import com.github.scribejava.core.httpclient.HttpClient; +import com.github.scribejava.core.httpclient.HttpClientConfig; import com.github.scribejava.core.model.OAuthConfig; +import java.io.OutputStream; public class OdnoklassnikiApi extends DefaultApi20 { @@ -29,9 +32,25 @@ protected String getAuthorizationBaseUrl() { return "https://connect.ok.ru/oauth/authorize"; } + @Override + public OdnoklassnikiOAuthService createService(String apiKey, String apiSecret, String callback, String scope, + OutputStream debugStream, String state, String responseType, String userAgent, + HttpClientConfig httpClientConfig, HttpClient httpClient) { + return new OdnoklassnikiOAuthService(this, apiKey, apiSecret, callback, scope, debugStream, state, responseType, + userAgent, httpClientConfig, httpClient); + } + + /** + * @deprecated use {@link #createService(java.lang.String, java.lang.String, java.lang.String, java.lang.String, + * java.io.OutputStream, java.lang.String, java.lang.String, java.lang.String, + * com.github.scribejava.core.httpclient.HttpClientConfig, com.github.scribejava.core.httpclient.HttpClient)} + */ + @Deprecated @Override public OdnoklassnikiOAuthService createService(OAuthConfig config) { - return new OdnoklassnikiOAuthService(this, config); + return createService(config.getApiKey(), config.getApiSecret(), config.getCallback(), config.getScope(), + config.getDebugStream(), config.getState(), config.getResponseType(), config.getUserAgent(), + config.getHttpClientConfig(), config.getHttpClient()); } @Override diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/TutByApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/TutByApi.java index 0e7359f08..a6b864fb7 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/TutByApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/TutByApi.java @@ -2,7 +2,10 @@ import com.github.scribejava.apis.service.TutByOAuthService; import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.httpclient.HttpClient; +import com.github.scribejava.core.httpclient.HttpClientConfig; import com.github.scribejava.core.model.OAuthConfig; +import java.io.OutputStream; public class TutByApi extends DefaultApi20 { @@ -27,8 +30,24 @@ protected String getAuthorizationBaseUrl() { return "http://profile.tut.by/auth"; } + @Override + public TutByOAuthService createService(String apiKey, String apiSecret, String callback, String scope, + OutputStream debugStream, String state, String responseType, String userAgent, + HttpClientConfig httpClientConfig, HttpClient httpClient) { + return new TutByOAuthService(this, apiKey, apiSecret, callback, scope, debugStream, state, responseType, + userAgent, httpClientConfig, httpClient); + } + + /** + * @deprecated use {@link #createService(java.lang.String, java.lang.String, java.lang.String, java.lang.String, + * java.io.OutputStream, java.lang.String, java.lang.String, java.lang.String, + * com.github.scribejava.core.httpclient.HttpClientConfig, com.github.scribejava.core.httpclient.HttpClient)} + */ + @Deprecated @Override public TutByOAuthService createService(OAuthConfig config) { - return new TutByOAuthService(this, config); + return createService(config.getApiKey(), config.getApiSecret(), config.getCallback(), config.getScope(), + config.getDebugStream(), config.getState(), config.getResponseType(), config.getUserAgent(), + config.getHttpClientConfig(), config.getHttpClient()); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/FacebookService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/FacebookService.java index c506ce852..925d20f15 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/FacebookService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/FacebookService.java @@ -1,9 +1,12 @@ package com.github.scribejava.apis.service; import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.httpclient.HttpClient; +import com.github.scribejava.core.httpclient.HttpClientConfig; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.oauth.OAuth20Service; +import java.io.OutputStream; import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; import java.util.Formatter; @@ -12,8 +15,24 @@ public class FacebookService extends OAuth20Service { + /** + * @deprecated use {@link #FacebookService(com.github.scribejava.core.builder.api.DefaultApi20, java.lang.String, + * java.lang.String, java.lang.String, java.lang.String, java.io.OutputStream, java.lang.String, java.lang.String, + * java.lang.String, com.github.scribejava.core.httpclient.HttpClientConfig, + * com.github.scribejava.core.httpclient.HttpClient)} + */ + @Deprecated public FacebookService(DefaultApi20 api, OAuthConfig config) { - super(api, config); + this(api, config.getApiKey(), config.getApiSecret(), config.getCallback(), config.getScope(), + config.getDebugStream(), config.getState(), config.getResponseType(), config.getUserAgent(), + config.getHttpClientConfig(), config.getHttpClient()); + } + + public FacebookService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, + OutputStream debugStream, String state, String responseType, String userAgent, + HttpClientConfig httpClientConfig, HttpClient httpClient) { + super(api, apiKey, apiSecret, callback, scope, debugStream, state, responseType, userAgent, httpClientConfig, + httpClient); } @Override @@ -23,7 +42,7 @@ public void signRequest(String accessToken, OAuthRequest request) { final Mac mac; try { mac = Mac.getInstance("HmacSHA256"); - final SecretKeySpec secretKey = new SecretKeySpec(getConfig().getApiSecret().getBytes(), "HmacSHA256"); + final SecretKeySpec secretKey = new SecretKeySpec(getApiSecret().getBytes(), "HmacSHA256"); mac.init(secretKey); final Formatter appsecretProof = new Formatter(); diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthService.java index 89edf0198..980deb102 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthService.java @@ -2,26 +2,44 @@ import com.github.scribejava.apis.ImgurApi; import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.httpclient.HttpClient; +import com.github.scribejava.core.httpclient.HttpClientConfig; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.oauth.OAuth20Service; +import java.io.OutputStream; public class ImgurOAuthService extends OAuth20Service { + /** + * @deprecated use {@link #ImgurOAuthService(com.github.scribejava.core.builder.api.DefaultApi20, java.lang.String, + * java.lang.String, java.lang.String, java.lang.String, java.io.OutputStream, java.lang.String, java.lang.String, + * java.lang.String, com.github.scribejava.core.httpclient.HttpClientConfig, + * com.github.scribejava.core.httpclient.HttpClient)} + */ + @Deprecated public ImgurOAuthService(DefaultApi20 api, OAuthConfig config) { - super(api, config); + this(api, config.getApiKey(), config.getApiSecret(), config.getCallback(), config.getScope(), + config.getDebugStream(), config.getState(), config.getResponseType(), config.getUserAgent(), + config.getHttpClientConfig(), config.getHttpClient()); + } + + public ImgurOAuthService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, + OutputStream debugStream, String state, String responseType, String userAgent, + HttpClientConfig httpClientConfig, HttpClient httpClient) { + super(api, apiKey, apiSecret, callback, scope, debugStream, state, responseType, userAgent, httpClientConfig, + httpClient); } @Override protected OAuthRequest createAccessTokenRequest(String oauthVerifier) { final DefaultApi20 api = getApi(); final OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint()); - final OAuthConfig config = getConfig(); - request.addBodyParameter(OAuthConstants.CLIENT_ID, config.getApiKey()); - request.addBodyParameter(OAuthConstants.CLIENT_SECRET, config.getApiSecret()); + request.addBodyParameter(OAuthConstants.CLIENT_ID, getApiKey()); + request.addBodyParameter(OAuthConstants.CLIENT_SECRET, getApiSecret()); - if (ImgurApi.isOob(config)) { + if (ImgurApi.isOob(getCallback())) { request.addBodyParameter(OAuthConstants.GRANT_TYPE, "pin"); request.addBodyParameter("pin", oauthVerifier); } else { @@ -33,7 +51,6 @@ protected OAuthRequest createAccessTokenRequest(String oauthVerifier) { @Override public void signRequest(String accessToken, OAuthRequest request) { - request.addHeader("Authorization", - accessToken == null ? "Client-ID " + getConfig().getApiKey() : "Bearer " + accessToken); + request.addHeader("Authorization", accessToken == null ? "Client-ID " + getApiKey() : "Bearer " + accessToken); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthService.java index f31503098..70a96d211 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthService.java @@ -4,9 +4,12 @@ import java.util.Map; import java.util.TreeMap; import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.httpclient.HttpClient; +import com.github.scribejava.core.httpclient.HttpClientConfig; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.oauth.OAuth20Service; +import java.io.OutputStream; import java.io.UnsupportedEncodingException; import java.nio.charset.Charset; import java.security.MessageDigest; @@ -15,19 +18,36 @@ public class MailruOAuthService extends OAuth20Service { + /** + * @deprecated use {@link #MailruOAuthService(com.github.scribejava.core.builder.api.DefaultApi20, java.lang.String, + * java.lang.String, java.lang.String, java.lang.String, java.io.OutputStream, java.lang.String, java.lang.String, + * java.lang.String, com.github.scribejava.core.httpclient.HttpClientConfig, + * com.github.scribejava.core.httpclient.HttpClient)} + */ + @Deprecated public MailruOAuthService(DefaultApi20 api, OAuthConfig config) { - super(api, config); + this(api, config.getApiKey(), config.getApiSecret(), config.getCallback(), config.getScope(), + config.getDebugStream(), config.getState(), config.getResponseType(), config.getUserAgent(), + config.getHttpClientConfig(), config.getHttpClient()); } + public MailruOAuthService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, + OutputStream debugStream, String state, String responseType, String userAgent, + HttpClientConfig httpClientConfig, HttpClient httpClient) { + super(api, apiKey, apiSecret, callback, scope, debugStream, state, responseType, userAgent, httpClientConfig, + httpClient); + } + + @Override public void signRequest(String accessToken, OAuthRequest request) { // sig = md5(params + secret_key) request.addQuerystringParameter("session_key", accessToken); - request.addQuerystringParameter("app_id", getConfig().getApiKey()); + request.addQuerystringParameter("app_id", getApiKey()); final String completeUrl = request.getCompleteUrl(); try { - final String clientSecret = getConfig().getApiSecret(); + final String clientSecret = getApiSecret(); final int queryIndex = completeUrl.indexOf('?'); if (queryIndex != -1) { final String urlPart = completeUrl.substring(queryIndex + 1); diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MicrosoftAzureActiveDirectoryService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MicrosoftAzureActiveDirectoryService.java index 703257eac..afe2ad065 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MicrosoftAzureActiveDirectoryService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MicrosoftAzureActiveDirectoryService.java @@ -1,17 +1,36 @@ package com.github.scribejava.apis.service; import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.httpclient.HttpClient; +import com.github.scribejava.core.httpclient.HttpClientConfig; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.oauth.OAuth20Service; +import java.io.OutputStream; public class MicrosoftAzureActiveDirectoryService extends OAuth20Service { private static final String ACCEPTED_FORMAT = "application/json; odata=minimalmetadata; streaming=true; charset=utf-8"; + /** + * @deprecated use {@link #MicrosoftAzureActiveDirectoryService(com.github.scribejava.core.builder.api.DefaultApi20, + * java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.io.OutputStream, java.lang.String, + * java.lang.String, java.lang.String, com.github.scribejava.core.httpclient.HttpClientConfig, + * com.github.scribejava.core.httpclient.HttpClient)} + */ + @Deprecated public MicrosoftAzureActiveDirectoryService(DefaultApi20 api, OAuthConfig config) { - super(api, config); + this(api, config.getApiKey(), config.getApiSecret(), config.getCallback(), config.getScope(), + config.getDebugStream(), config.getState(), config.getResponseType(), config.getUserAgent(), + config.getHttpClientConfig(), config.getHttpClient()); + } + + public MicrosoftAzureActiveDirectoryService(DefaultApi20 api, String apiKey, String apiSecret, String callback, + String scope, OutputStream debugStream, String state, String responseType, String userAgent, + HttpClientConfig httpClientConfig, HttpClient httpClient) { + super(api, apiKey, apiSecret, callback, scope, debugStream, state, responseType, userAgent, httpClientConfig, + httpClient); } @Override diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiOAuthService.java index 517d097ab..82618313f 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiOAuthService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiOAuthService.java @@ -1,11 +1,14 @@ package com.github.scribejava.apis.service; import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.httpclient.HttpClient; +import com.github.scribejava.core.httpclient.HttpClientConfig; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Parameter; import com.github.scribejava.core.model.ParameterList; import com.github.scribejava.core.oauth.OAuth20Service; +import java.io.OutputStream; import java.io.UnsupportedEncodingException; import java.net.URLDecoder; @@ -18,15 +21,31 @@ public class OdnoklassnikiOAuthService extends OAuth20Service { + /** + * @deprecated use {@link #OdnoklassnikiOAuthService(com.github.scribejava.core.builder.api.DefaultApi20, + * java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.io.OutputStream, java.lang.String, + * java.lang.String, java.lang.String, com.github.scribejava.core.httpclient.HttpClientConfig, + * com.github.scribejava.core.httpclient.HttpClient)} + */ + @Deprecated public OdnoklassnikiOAuthService(DefaultApi20 api, OAuthConfig config) { - super(api, config); + this(api, config.getApiKey(), config.getApiSecret(), config.getCallback(), config.getScope(), + config.getDebugStream(), config.getState(), config.getResponseType(), config.getUserAgent(), + config.getHttpClientConfig(), config.getHttpClient()); + } + + public OdnoklassnikiOAuthService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, + OutputStream debugStream, String state, String responseType, String userAgent, + HttpClientConfig httpClientConfig, HttpClient httpClient) { + super(api, apiKey, apiSecret, callback, scope, debugStream, state, responseType, userAgent, httpClientConfig, + httpClient); } @Override public void signRequest(String accessToken, OAuthRequest request) { //sig = lower(md5( sorted_request_params_composed_string + md5(access_token + application_secret_key))) try { - final String tokenDigest = md5(accessToken + getConfig().getApiSecret()); + final String tokenDigest = md5(accessToken + getApiSecret()); final ParameterList queryParams = request.getQueryStringParams(); queryParams.addAll(request.getBodyParams()); diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/TutByOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/TutByOAuthService.java index ea9f8aa7b..c2d191e35 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/TutByOAuthService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/TutByOAuthService.java @@ -1,15 +1,34 @@ package com.github.scribejava.apis.service; import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.httpclient.HttpClient; +import com.github.scribejava.core.httpclient.HttpClientConfig; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.oauth.OAuth20Service; +import java.io.OutputStream; public class TutByOAuthService extends OAuth20Service { + /** + * @deprecated use {@link #TutByOAuthService(com.github.scribejava.core.builder.api.DefaultApi20, java.lang.String, + * java.lang.String, java.lang.String, java.lang.String, java.io.OutputStream, java.lang.String, java.lang.String, + * java.lang.String, com.github.scribejava.core.httpclient.HttpClientConfig, + * com.github.scribejava.core.httpclient.HttpClient)} + */ + @Deprecated public TutByOAuthService(DefaultApi20 api, OAuthConfig config) { - super(api, config); + this(api, config.getApiKey(), config.getApiSecret(), config.getCallback(), config.getScope(), + config.getDebugStream(), config.getState(), config.getResponseType(), config.getUserAgent(), + config.getHttpClientConfig(), config.getHttpClient()); + } + + public TutByOAuthService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, + OutputStream debugStream, String state, String responseType, String userAgent, + HttpClientConfig httpClientConfig, HttpClient httpClient) { + super(api, apiKey, apiSecret, callback, scope, debugStream, state, responseType, userAgent, httpClientConfig, + httpClient); } @Override diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Yahoo20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Yahoo20Example.java index c2e003876..8102b4ea3 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Yahoo20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Yahoo20Example.java @@ -3,6 +3,7 @@ import com.github.scribejava.apis.YahooApi20; import com.github.scribejava.core.builder.ServiceBuilder; import com.github.scribejava.core.model.OAuth2AccessToken; +import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; import com.github.scribejava.core.model.Verb; @@ -35,7 +36,7 @@ public static void main(String... args) throws IOException, InterruptedException final OAuth20Service service = new ServiceBuilder(clientId) .apiSecret(clientSecret) - .callback("oob") + .callback(OAuthConstants.OOB) .build(YahooApi20.instance()); final Scanner in = new Scanner(System.in); diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilder.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilder.java index 2ec6b1b22..8c70c4319 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilder.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilder.java @@ -3,7 +3,6 @@ import com.github.scribejava.core.builder.api.BaseApi; import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.httpclient.HttpClientConfig; -import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.oauth.OAuthService; import com.github.scribejava.core.utils.Preconditions; @@ -33,7 +32,8 @@ public ServiceBuilder(String apiKey) { /** * Adds an OAuth callback url * - * @param callback callback url. Must be a valid url or 'oob' for out of band OAuth + * @param callback callback url. Must be a valid url or 'oob' + * ({@link com.github.scribejava.core.model.OAuthConstants#OOB} for out of band OAuth * @return the {@link ServiceBuilder} instance for method chaining */ public ServiceBuilder callback(String callback) { @@ -136,7 +136,7 @@ public ServiceBuilder debug() { * @return fully configured {@link OAuthService} */ public S build(BaseApi api) { - return api.createService(new OAuthConfig(apiKey, apiSecret, callback, scope, debugStream, state, responseType, - userAgent, httpClientConfig, httpClient)); + return api.createService(apiKey, apiSecret, callback, scope, debugStream, state, responseType, userAgent, + httpClientConfig, httpClient); } } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/BaseApi.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/BaseApi.java index a42fe35fa..bac1cd7b7 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/BaseApi.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/BaseApi.java @@ -1,9 +1,22 @@ package com.github.scribejava.core.builder.api; +import com.github.scribejava.core.httpclient.HttpClient; +import com.github.scribejava.core.httpclient.HttpClientConfig; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.oauth.OAuthService; +import java.io.OutputStream; public interface BaseApi { + /** + * @deprecated use {@link #createService(java.lang.String, java.lang.String, java.lang.String, java.lang.String, + * java.io.OutputStream, java.lang.String, java.lang.String, java.lang.String, + * com.github.scribejava.core.httpclient.HttpClientConfig, com.github.scribejava.core.httpclient.HttpClient)} + */ + @Deprecated T createService(OAuthConfig config); + + T createService(String apiKey, String apiSecret, String callback, String scope, OutputStream debugStream, + String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, + HttpClient httpClient); } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/ClientAuthenticationType.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/ClientAuthenticationType.java index 21c7f3793..e466e2159 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/ClientAuthenticationType.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/ClientAuthenticationType.java @@ -18,9 +18,7 @@ public enum ClientAuthenticationType { private final Base64.Encoder base64Encoder = Base64.getEncoder(); @Override - public void addClientAuthentication(OAuthRequest request, OAuthConfig config) { - final String apiKey = config.getApiKey(); - final String apiSecret = config.getApiSecret(); + public void addClientAuthentication(OAuthRequest request, String apiKey, String apiSecret) { if (apiKey != null && apiSecret != null) { request.addHeader(OAuthConstants.HEADER, OAuthConstants.BASIC + ' ' + base64Encoder.encodeToString( @@ -30,14 +28,22 @@ public void addClientAuthentication(OAuthRequest request, OAuthConfig config) { }, REQUEST_BODY { @Override - public void addClientAuthentication(OAuthRequest request, OAuthConfig config) { - request.addParameter(OAuthConstants.CLIENT_ID, config.getApiKey()); - final String apiSecret = config.getApiSecret(); + public void addClientAuthentication(OAuthRequest request, String apiKey, String apiSecret) { + request.addParameter(OAuthConstants.CLIENT_ID, apiKey); if (apiSecret != null) { request.addParameter(OAuthConstants.CLIENT_SECRET, apiSecret); } } }; - public abstract void addClientAuthentication(OAuthRequest request, OAuthConfig config); + public abstract void addClientAuthentication(OAuthRequest request, String apiKey, String apiSecret); + + /** + * @deprecated use {@link #addClientAuthentication(com.github.scribejava.core.model.OAuthRequest, java.lang.String, + * java.lang.String)} + */ + @Deprecated + public void addClientAuthentication(OAuthRequest request, OAuthConfig config) { + addClientAuthentication(request, config.getApiKey(), config.getApiSecret()); + } } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi10a.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi10a.java index a9db2c031..aabb00028 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi10a.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi10a.java @@ -14,10 +14,13 @@ import com.github.scribejava.core.services.TimestampService; import com.github.scribejava.core.services.TimestampServiceImpl; import com.github.scribejava.core.extractors.TokenExtractor; +import com.github.scribejava.core.httpclient.HttpClient; +import com.github.scribejava.core.httpclient.HttpClientConfig; import com.github.scribejava.core.model.OAuth1AccessToken; import com.github.scribejava.core.model.OAuth1RequestToken; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.ParameterList; +import java.io.OutputStream; /** * Default implementation of the OAuth protocol, version 1.0a @@ -141,9 +144,25 @@ public String getAuthorizationUrl(OAuth1RequestToken requestToken) { return parameters.appendTo(getAuthorizationBaseUrl()); } + /** + * @deprecated use {@link #createService(java.lang.String, java.lang.String, java.lang.String, java.lang.String, + * java.io.OutputStream, java.lang.String, java.lang.String, java.lang.String, + * com.github.scribejava.core.httpclient.HttpClientConfig, com.github.scribejava.core.httpclient.HttpClient)} + */ + @Deprecated @Override public OAuth10aService createService(OAuthConfig config) { - return new OAuth10aService(this, config); + return createService(config.getApiKey(), config.getApiSecret(), config.getCallback(), config.getScope(), + config.getDebugStream(), config.getState(), config.getResponseType(), config.getUserAgent(), + config.getHttpClientConfig(), config.getHttpClient()); + } + + @Override + public OAuth10aService createService(String apiKey, String apiSecret, String callback, String scope, + OutputStream debugStream, String state, String responseType, String userAgent, + HttpClientConfig httpClientConfig, HttpClient httpClient) { + return new OAuth10aService(this, apiKey, apiSecret, callback, scope, debugStream, state, responseType, + userAgent, httpClientConfig, httpClient); } /** diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java index e0caa4637..0b916bce6 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java @@ -2,12 +2,15 @@ import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; import com.github.scribejava.core.extractors.TokenExtractor; +import com.github.scribejava.core.httpclient.HttpClient; +import com.github.scribejava.core.httpclient.HttpClientConfig; import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.ParameterList; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.oauth.OAuth20Service; +import java.io.OutputStream; import java.util.Map; /** @@ -68,6 +71,16 @@ public String getRevokeTokenEndpoint() { protected abstract String getAuthorizationBaseUrl(); + /** + * @deprecated use {@link #getAuthorizationUrl(java.lang.String, java.lang.String, java.lang.String, + * java.lang.String, java.lang.String, java.util.Map)} + */ + @Deprecated + public String getAuthorizationUrl(OAuthConfig config, Map additionalParams) { + return getAuthorizationUrl(config.getResponseType(), config.getApiKey(), config.getCallback(), + config.getScope(), config.getState(), additionalParams); + } + /** * Returns the URL where you should redirect your users to authenticate your application. * @@ -75,22 +88,20 @@ public String getRevokeTokenEndpoint() { * @param additionalParams any additional GET params to add to the URL * @return the URL where you should redirect your users */ - public String getAuthorizationUrl(OAuthConfig config, Map additionalParams) { + public String getAuthorizationUrl(String responseType, String apiKey, String callback, String scope, String state, + Map additionalParams) { final ParameterList parameters = new ParameterList(additionalParams); - parameters.add(OAuthConstants.RESPONSE_TYPE, config.getResponseType()); - parameters.add(OAuthConstants.CLIENT_ID, config.getApiKey()); + parameters.add(OAuthConstants.RESPONSE_TYPE, responseType); + parameters.add(OAuthConstants.CLIENT_ID, apiKey); - final String callback = config.getCallback(); if (callback != null) { parameters.add(OAuthConstants.REDIRECT_URI, callback); } - final String scope = config.getScope(); if (scope != null) { parameters.add(OAuthConstants.SCOPE, scope); } - final String state = config.getState(); if (state != null) { parameters.add(OAuthConstants.STATE, state); } @@ -98,9 +109,25 @@ public String getAuthorizationUrl(OAuthConfig config, Map additi return parameters.appendTo(getAuthorizationBaseUrl()); } + /** + * @deprecated use {@link #createService(java.lang.String, java.lang.String, java.lang.String, java.lang.String, + * java.io.OutputStream, java.lang.String, java.lang.String, java.lang.String, + * com.github.scribejava.core.httpclient.HttpClientConfig, com.github.scribejava.core.httpclient.HttpClient)} + */ + @Deprecated @Override public OAuth20Service createService(OAuthConfig config) { - return new OAuth20Service(this, config); + return createService(config.getApiKey(), config.getApiSecret(), config.getCallback(), config.getScope(), + config.getDebugStream(), config.getState(), config.getResponseType(), config.getUserAgent(), + config.getHttpClientConfig(), config.getHttpClient()); + } + + @Override + public OAuth20Service createService(String apiKey, String apiSecret, String callback, String scope, + OutputStream debugStream, String state, String responseType, String userAgent, + HttpClientConfig httpClientConfig, HttpClient httpClient) { + return new OAuth20Service(this, apiKey, apiSecret, callback, scope, debugStream, state, responseType, userAgent, + httpClientConfig, httpClient); } public OAuth2SignatureType getSignatureType() { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConfig.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConfig.java index 244ca6731..a31593879 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConfig.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConfig.java @@ -7,7 +7,11 @@ /** * Parameter object that groups OAuth config values + * + * @deprecated use service.getXXX() instead of service.getConfigXXX() and service.method(...) instead of + * service.method(config) */ +@Deprecated public class OAuthConfig { private final String apiKey; @@ -18,9 +22,8 @@ public class OAuthConfig { private final String state; private final String responseType; private final String userAgent; - - private HttpClientConfig httpClientConfig; - private HttpClient httpClient; + private final HttpClientConfig httpClientConfig; + private final HttpClient httpClient; public OAuthConfig(String key, String secret) { this(key, secret, null, null, null, null, null, null, null, null); @@ -87,4 +90,8 @@ public HttpClientConfig getHttpClientConfig() { public HttpClient getHttpClient() { return httpClient; } + + public OutputStream getDebugStream() { + return debugStream; + } } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConstants.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConstants.java index 93d936291..1a38cb36b 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConstants.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConstants.java @@ -22,6 +22,9 @@ public interface OAuthConstants { String SCOPE = "scope"; String BASIC = "Basic"; + // OAuth 1.0 + String OOB = "oob"; + // OAuth 2.0 String ACCESS_TOKEN = "access_token"; String CLIENT_ID = "client_id"; diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java index 09b744b2d..5d77af8a3 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java @@ -4,6 +4,8 @@ import java.util.concurrent.Future; import com.github.scribejava.core.builder.api.DefaultApi10a; import com.github.scribejava.core.builder.api.OAuth1SignatureType; +import com.github.scribejava.core.httpclient.HttpClient; +import com.github.scribejava.core.httpclient.HttpClientConfig; import com.github.scribejava.core.model.OAuth1AccessToken; import com.github.scribejava.core.model.OAuth1RequestToken; import com.github.scribejava.core.model.OAuthAsyncRequestCallback; @@ -11,6 +13,7 @@ import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; +import java.io.OutputStream; import java.util.Map; import java.util.concurrent.ExecutionException; @@ -20,30 +23,41 @@ public class OAuth10aService extends OAuthService { private static final String VERSION = "1.0"; + private final OutputStream debugStream; private final DefaultApi10a api; /** - * Default constructor - * - * @param api OAuth1.0a api information - * @param config OAuth 1.0a configuration param object + * @deprecated use {@link #OAuth10aService(com.github.scribejava.core.builder.api.DefaultApi10a, java.lang.String, + * java.lang.String, java.lang.String, java.lang.String, java.io.OutputStream, java.lang.String, java.lang.String, + * java.lang.String, com.github.scribejava.core.httpclient.HttpClientConfig, + * com.github.scribejava.core.httpclient.HttpClient)} */ + @Deprecated public OAuth10aService(DefaultApi10a api, OAuthConfig config) { - super(config); + this(api, config.getApiKey(), config.getApiSecret(), config.getCallback(), config.getScope(), + config.getDebugStream(), config.getState(), config.getResponseType(), config.getUserAgent(), + config.getHttpClientConfig(), config.getHttpClient()); + } + + public OAuth10aService(DefaultApi10a api, String apiKey, String apiSecret, String callback, String scope, + OutputStream debugStream, String state, String responseType, String userAgent, + HttpClientConfig httpClientConfig, HttpClient httpClient) { + super(apiKey, apiSecret, callback, scope, debugStream, state, responseType, userAgent, httpClientConfig, + httpClient); + this.debugStream = debugStream; this.api = api; } public OAuth1RequestToken getRequestToken() throws IOException, InterruptedException, ExecutionException { - final OAuthConfig config = getConfig(); - config.log("obtaining request token from " + api.getRequestTokenEndpoint()); + log("obtaining request token from " + api.getRequestTokenEndpoint()); final OAuthRequest request = prepareRequestTokenRequest(); - config.log("sending request..."); + log("sending request..."); final Response response = execute(request); final String body = response.getBody(); - config.log("response status code: " + response.getCode()); - config.log("response body: " + body); + log("response status code: " + response.getCode()); + log("response body: " + body); return api.getRequestTokenExtractor().extract(response); } @@ -52,8 +66,7 @@ public Future getRequestTokenAsync() { } public Future getRequestTokenAsync(OAuthAsyncRequestCallback callback) { - final OAuthConfig config = getConfig(); - config.log("async obtaining request token from " + api.getRequestTokenEndpoint()); + log("async obtaining request token from " + api.getRequestTokenEndpoint()); final OAuthRequest request = prepareRequestTokenRequest(); return execute(request, callback, new OAuthRequest.ResponseConverter() { @Override @@ -65,33 +78,32 @@ public OAuth1RequestToken convert(Response response) throws IOException { protected OAuthRequest prepareRequestTokenRequest() { final OAuthRequest request = new OAuthRequest(api.getRequestTokenVerb(), api.getRequestTokenEndpoint()); - final OAuthConfig config = getConfig(); - config.log("setting oauth_callback to " + config.getCallback()); - request.addOAuthParameter(OAuthConstants.CALLBACK, config.getCallback()); + final String callback = getCallback(); + log("setting oauth_callback to " + callback); + request.addOAuthParameter(OAuthConstants.CALLBACK, callback); addOAuthParams(request, ""); appendSignature(request); return request; } protected void addOAuthParams(OAuthRequest request, String tokenSecret) { - final OAuthConfig config = getConfig(); request.addOAuthParameter(OAuthConstants.TIMESTAMP, api.getTimestampService().getTimestampInSeconds()); request.addOAuthParameter(OAuthConstants.NONCE, api.getTimestampService().getNonce()); - request.addOAuthParameter(OAuthConstants.CONSUMER_KEY, config.getApiKey()); + request.addOAuthParameter(OAuthConstants.CONSUMER_KEY, getApiKey()); request.addOAuthParameter(OAuthConstants.SIGN_METHOD, api.getSignatureService().getSignatureMethod()); request.addOAuthParameter(OAuthConstants.VERSION, getVersion()); - final String scope = config.getScope(); + final String scope = getScope(); if (scope != null) { request.addOAuthParameter(OAuthConstants.SCOPE, scope); } request.addOAuthParameter(OAuthConstants.SIGNATURE, getSignature(request, tokenSecret)); - config.log("appended additional OAuth parameters: " + request.getOauthParameters()); + log("appended additional OAuth parameters: " + request.getOauthParameters()); } public OAuth1AccessToken getAccessToken(OAuth1RequestToken requestToken, String oauthVerifier) throws IOException, InterruptedException, ExecutionException { - getConfig().log("obtaining access token from " + api.getAccessTokenEndpoint()); + log("obtaining access token from " + api.getAccessTokenEndpoint()); final OAuthRequest request = prepareAccessTokenRequest(requestToken, oauthVerifier); final Response response = execute(request); return api.getAccessTokenExtractor().extract(response); @@ -112,8 +124,7 @@ public Future getAccessTokenAsync(OAuth1RequestToken requestT */ public Future getAccessTokenAsync(OAuth1RequestToken requestToken, String oauthVerifier, OAuthAsyncRequestCallback callback) { - final OAuthConfig config = getConfig(); - config.log("async obtaining access token from " + api.getAccessTokenEndpoint()); + log("async obtaining access token from " + api.getAccessTokenEndpoint()); final OAuthRequest request = prepareAccessTokenRequest(requestToken, oauthVerifier); return execute(request, callback, new OAuthRequest.ResponseConverter() { @Override @@ -125,23 +136,21 @@ public OAuth1AccessToken convert(Response response) throws IOException { protected OAuthRequest prepareAccessTokenRequest(OAuth1RequestToken requestToken, String oauthVerifier) { final OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint()); - final OAuthConfig config = getConfig(); request.addOAuthParameter(OAuthConstants.TOKEN, requestToken.getToken()); request.addOAuthParameter(OAuthConstants.VERIFIER, oauthVerifier); - config.log("setting token to: " + requestToken + " and verifier to: " + oauthVerifier); + log("setting token to: " + requestToken + " and verifier to: " + oauthVerifier); addOAuthParams(request, requestToken.getTokenSecret()); appendSignature(request); return request; } public void signRequest(OAuth1AccessToken token, OAuthRequest request) { - final OAuthConfig config = getConfig(); - config.log("signing request: " + request.getCompleteUrl()); + log("signing request: " + request.getCompleteUrl()); if (!token.isEmpty() || api.isEmptyOAuthTokenParamIsRequired()) { request.addOAuthParameter(OAuthConstants.TOKEN, token.getToken()); } - config.log("setting token to: " + token); + log("setting token to: " + token); addOAuthParams(request, token.getTokenSecret()); appendSignature(request); } @@ -163,28 +172,26 @@ public String getAuthorizationUrl(OAuth1RequestToken requestToken) { } private String getSignature(OAuthRequest request, String tokenSecret) { - final OAuthConfig config = getConfig(); - config.log("generating signature..."); + log("generating signature..."); final String baseString = api.getBaseStringExtractor().extract(request); - final String signature = api.getSignatureService().getSignature(baseString, config.getApiSecret(), tokenSecret); + final String signature = api.getSignatureService().getSignature(baseString, getApiSecret(), tokenSecret); - config.log("base string is: " + baseString); - config.log("signature is: " + signature); + log("base string is: " + baseString); + log("signature is: " + signature); return signature; } protected void appendSignature(OAuthRequest request) { - final OAuthConfig config = getConfig(); final OAuth1SignatureType signatureType = api.getSignatureType(); switch (signatureType) { case Header: - config.log("using Http Header signature"); + log("using Http Header signature"); final String oauthHeader = api.getHeaderExtractor().extract(request); request.addHeader(OAuthConstants.HEADER, oauthHeader); break; case QueryString: - config.log("using Querystring signature"); + log("using Querystring signature"); for (Map.Entry oauthParameter : request.getOauthParameters().entrySet()) { request.addQuerystringParameter(oauthParameter.getKey(), oauthParameter.getValue()); @@ -198,4 +205,15 @@ protected void appendSignature(OAuthRequest request) { public DefaultApi10a getApi() { return api; } + + public void log(String message) { + if (debugStream != null) { + message += '\n'; + try { + debugStream.write(message.getBytes("UTF8")); + } catch (IOException | RuntimeException e) { + throw new RuntimeException("there were problems while writting to the debug stream", e); + } + } + } } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java index 2d78ec555..1e38793f9 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java @@ -4,6 +4,8 @@ import java.util.concurrent.Future; import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; +import com.github.scribejava.core.httpclient.HttpClient; +import com.github.scribejava.core.httpclient.HttpClientConfig; import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuth2Authorization; import com.github.scribejava.core.model.OAuthAsyncRequestCallback; @@ -19,21 +21,38 @@ import java.util.Map; import java.util.concurrent.ExecutionException; import com.github.scribejava.core.revoke.TokenTypeHint; +import java.io.OutputStream; public class OAuth20Service extends OAuthService { private static final String VERSION = "2.0"; private static final PKCEService PKCE_SERVICE = new PKCEService(); private final DefaultApi20 api; + private final String responseType; + private final String state; /** - * Default constructor - * * @param api OAuth2.0 api information * @param config OAuth 2.0 configuration param object + * @deprecated use {@link #OAuth20Service(com.github.scribejava.core.builder.api.DefaultApi20, java.lang.String, + * java.lang.String, java.lang.String, java.lang.String, java.io.OutputStream, java.lang.String, java.lang.String, + * java.lang.String, com.github.scribejava.core.httpclient.HttpClientConfig, + * com.github.scribejava.core.httpclient.HttpClient)} */ + @Deprecated public OAuth20Service(DefaultApi20 api, OAuthConfig config) { - super(config); + this(api, config.getApiKey(), config.getApiSecret(), config.getCallback(), config.getScope(), + config.getDebugStream(), config.getState(), config.getResponseType(), config.getUserAgent(), + config.getHttpClientConfig(), config.getHttpClient()); + } + + public OAuth20Service(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, + OutputStream debugStream, String state, String responseType, String userAgent, + HttpClientConfig httpClientConfig, HttpClient httpClient) { + super(apiKey, apiSecret, callback, scope, debugStream, state, responseType, userAgent, httpClientConfig, + httpClient); + this.responseType = responseType; + this.state = state; this.api = api; } @@ -103,13 +122,12 @@ public Future getAccessToken(String code, protected OAuthRequest createAccessTokenRequest(String code) { final OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint()); - final OAuthConfig config = getConfig(); - api.getClientAuthenticationType().addClientAuthentication(request, config); + api.getClientAuthenticationType().addClientAuthentication(request, getApiKey(), getApiSecret()); request.addParameter(OAuthConstants.CODE, code); - request.addParameter(OAuthConstants.REDIRECT_URI, config.getCallback()); - final String scope = config.getScope(); + request.addParameter(OAuthConstants.REDIRECT_URI, getCallback()); + final String scope = getScope(); if (scope != null) { request.addParameter(OAuthConstants.SCOPE, scope); } @@ -148,11 +166,10 @@ protected OAuthRequest createRefreshTokenRequest(String refreshToken) { throw new IllegalArgumentException("The refreshToken cannot be null or empty"); } final OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getRefreshTokenEndpoint()); - final OAuthConfig config = getConfig(); - api.getClientAuthenticationType().addClientAuthentication(request, config); + api.getClientAuthenticationType().addClientAuthentication(request, getApiKey(), getApiSecret()); - final String scope = config.getScope(); + final String scope = getScope(); if (scope != null) { request.addParameter(OAuthConstants.SCOPE, scope); } @@ -190,18 +207,17 @@ public Future getAccessTokenPasswordGrantAsync(String uname, protected OAuthRequest createAccessTokenPasswordGrantRequest(String username, String password) { final OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint()); - final OAuthConfig config = getConfig(); request.addParameter(OAuthConstants.USERNAME, username); request.addParameter(OAuthConstants.PASSWORD, password); - final String scope = config.getScope(); + final String scope = getScope(); if (scope != null) { request.addParameter(OAuthConstants.SCOPE, scope); } request.addParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.PASSWORD); - api.getClientAuthenticationType().addClientAuthentication(request, config); + api.getClientAuthenticationType().addClientAuthentication(request, getApiKey(), getApiSecret()); return request; } @@ -233,11 +249,10 @@ public Future getAccessTokenClientCredentialsGrant( protected OAuthRequest createAccessTokenClientCredentialsGrantRequest() { final OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint()); - final OAuthConfig config = getConfig(); - api.getClientAuthenticationType().addClientAuthentication(request, config); + api.getClientAuthenticationType().addClientAuthentication(request, getApiKey(), getApiSecret()); - final String scope = config.getScope(); + final String scope = getScope(); if (scope != null) { request.addParameter(OAuthConstants.SCOPE, scope); } @@ -301,7 +316,7 @@ public String getAuthorizationUrl(Map additionalParams, PKCE pkc params = additionalParams == null ? new HashMap() : new HashMap<>(additionalParams); params.putAll(pkce.getAuthorizationUrlParams()); } - return api.getAuthorizationUrl(getConfig(), params); + return api.getAuthorizationUrl(getResponseType(), getApiKey(), getCallback(), getScope(), getState(), params); } public DefaultApi20 getApi() { @@ -311,7 +326,7 @@ public DefaultApi20 getApi() { protected OAuthRequest createRevokeTokenRequest(String tokenToRevoke, TokenTypeHint tokenTypeHint) { final OAuthRequest request = new OAuthRequest(Verb.POST, api.getRevokeTokenEndpoint()); - api.getClientAuthenticationType().addClientAuthentication(request, getConfig()); + api.getClientAuthenticationType().addClientAuthentication(request, getApiKey(), getApiSecret()); request.addParameter("token", tokenToRevoke); if (tokenTypeHint != null) { @@ -384,4 +399,12 @@ public OAuth2Authorization extractAuthorization(String redirectLocation) { } return authorization; } + + public String getResponseType() { + return responseType; + } + + public String getState() { + return state; + } } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java index 710f1bb68..1f53f37a0 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java @@ -13,25 +13,55 @@ import java.io.File; import java.io.IOException; +import java.io.OutputStream; import java.util.ServiceLoader; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; public abstract class OAuthService implements Closeable { - private final OAuthConfig config; + private final String apiKey; + private final String apiSecret; + private final String callback; + private final String scope; + private final String userAgent; private final HttpClient httpClient; - public OAuthService(OAuthConfig config) { - this.config = config; - final HttpClientConfig httpClientConfig = config.getHttpClientConfig(); - final HttpClient externalHttpClient = config.getHttpClient(); + /** + * + * @deprecated use all members directly from this class + */ + @Deprecated + private final OAuthConfig oAuthConfig; + + public OAuthService(String apiKey, String apiSecret, String callback, String scope, OutputStream debugStream, + String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, + HttpClient httpClient) { + this.apiKey = apiKey; + this.apiSecret = apiSecret; + this.callback = callback; + this.scope = scope; + this.userAgent = userAgent; - if (httpClientConfig == null && externalHttpClient == null) { - httpClient = new JDKHttpClient(JDKHttpClientConfig.defaultConfig()); + if (httpClientConfig == null && httpClient == null) { + this.httpClient = new JDKHttpClient(JDKHttpClientConfig.defaultConfig()); } else { - httpClient = externalHttpClient == null ? getClient(httpClientConfig) : externalHttpClient; + this.httpClient = httpClient == null ? getClient(httpClientConfig) : httpClient; } + oAuthConfig = new OAuthConfig(apiKey, apiSecret, callback, scope, debugStream, state, responseType, userAgent, + httpClientConfig, httpClient); + } + + /** + * @deprecated use {@link #OAuthService(java.lang.String, java.lang.String, java.lang.String, java.lang.String, + * java.io.OutputStream, java.lang.String, java.lang.String, java.lang.String, + * com.github.scribejava.core.httpclient.HttpClientConfig, com.github.scribejava.core.httpclient.HttpClient)} + */ + @Deprecated + public OAuthService(OAuthConfig config) { + this(config.getApiKey(), config.getApiSecret(), config.getCallback(), config.getScope(), + config.getDebugStream(), config.getState(), config.getResponseType(), config.getUserAgent(), + config.getHttpClientConfig(), config.getHttpClient()); } private static HttpClient getClient(HttpClientConfig config) { @@ -49,8 +79,28 @@ public void close() throws IOException { httpClient.close(); } + /** + * @deprecated use direct getXXX() instead of getConfig().getXXX() + */ + @Deprecated public OAuthConfig getConfig() { - return config; + return oAuthConfig; + } + + public String getApiKey() { + return apiKey; + } + + public String getApiSecret() { + return apiSecret; + } + + public String getCallback() { + return callback; + } + + public String getScope() { + return scope; } /** @@ -73,28 +123,28 @@ public Future execute(OAuthRequest request, OAuthAsyncRequestCallback final File filePayload = request.getFilePayload(); if (filePayload != null) { - return httpClient.executeAsync(config.getUserAgent(), request.getHeaders(), request.getVerb(), - request.getCompleteUrl(), filePayload, callback, converter); + return httpClient.executeAsync(userAgent, request.getHeaders(), request.getVerb(), request.getCompleteUrl(), + filePayload, callback, converter); } else if (request.getStringPayload() != null) { - return httpClient.executeAsync(config.getUserAgent(), request.getHeaders(), request.getVerb(), - request.getCompleteUrl(), request.getStringPayload(), callback, converter); + return httpClient.executeAsync(userAgent, request.getHeaders(), request.getVerb(), request.getCompleteUrl(), + request.getStringPayload(), callback, converter); } else { - return httpClient.executeAsync(config.getUserAgent(), request.getHeaders(), request.getVerb(), - request.getCompleteUrl(), request.getByteArrayPayload(), callback, converter); + return httpClient.executeAsync(userAgent, request.getHeaders(), request.getVerb(), request.getCompleteUrl(), + request.getByteArrayPayload(), callback, converter); } } public Response execute(OAuthRequest request) throws InterruptedException, ExecutionException, IOException { final File filePayload = request.getFilePayload(); if (filePayload != null) { - return httpClient.execute(config.getUserAgent(), request.getHeaders(), request.getVerb(), - request.getCompleteUrl(), filePayload); + return httpClient.execute(userAgent, request.getHeaders(), request.getVerb(), request.getCompleteUrl(), + filePayload); } else if (request.getStringPayload() != null) { - return httpClient.execute(config.getUserAgent(), request.getHeaders(), request.getVerb(), - request.getCompleteUrl(), request.getStringPayload()); + return httpClient.execute(userAgent, request.getHeaders(), request.getVerb(), request.getCompleteUrl(), + request.getStringPayload()); } else { - return httpClient.execute(config.getUserAgent(), request.getHeaders(), request.getVerb(), - request.getCompleteUrl(), request.getByteArrayPayload()); + return httpClient.execute(userAgent, request.getHeaders(), request.getVerb(), request.getCompleteUrl(), + request.getByteArrayPayload()); } } } diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/AbstractClientTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/AbstractClientTest.java index 56780f80c..089071494 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/AbstractClientTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/AbstractClientTest.java @@ -2,7 +2,6 @@ import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.model.OAuthAsyncRequestCallback; -import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; import com.github.scribejava.core.model.Verb; @@ -45,8 +44,8 @@ public Response getResponse() { @Before public void setUp() { - oAuthService = new OAuth20Service(null, - new OAuthConfig("test", "test", null, null, null, null, null, null, null, createNewClient())); + oAuthService = new OAuth20Service(null, "test", "test", null, null, null, null, null, null, null, + createNewClient()); } @After diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/builder/ServiceBuilderTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/builder/ServiceBuilderTest.java deleted file mode 100644 index b2480af45..000000000 --- a/scribejava-core/src/test/java/com/github/scribejava/core/builder/ServiceBuilderTest.java +++ /dev/null @@ -1,84 +0,0 @@ -package com.github.scribejava.core.builder; - -import static org.junit.Assert.assertEquals; -import org.junit.Before; -import org.junit.Test; -import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.model.OAuthConfig; -import com.github.scribejava.core.oauth.OAuth20Service; - -public class ServiceBuilderTest { - - private ServiceBuilder builder; - private ApiMock api; - - @Before - public void setUp() { - builder = new ServiceBuilder("will override api_key by another later in test"); - api = ApiMock.instance(); - } - - @Test - public void shouldReturnConfigDefaultValues() { - builder.apiKey("key").apiSecret("secret").build(api); - - final OAuthConfig config = api.getConfig(); - assertEquals(config.getApiKey(), "key"); - assertEquals(config.getApiSecret(), "secret"); - assertEquals(config.getCallback(), null); - } - - @Test - public void shouldAcceptValidCallbackUrl() { - builder.apiKey("key").apiSecret("secret").callback("http://example.com").build(api); - - final OAuthConfig config = api.getConfig(); - assertEquals(config.getApiKey(), "key"); - assertEquals(config.getApiSecret(), "secret"); - assertEquals(config.getCallback(), "http://example.com"); - } - - @Test - public void shouldAcceptNullAsCallback() { - builder.apiKey("key").apiSecret("secret").callback(null).build(api); - } - - @Test - public void shouldAcceptAnScope() { - builder.apiKey("key").apiSecret("secret").scope("rss-api").build(api); - - final OAuthConfig config = api.getConfig(); - assertEquals(config.getApiKey(), "key"); - assertEquals(config.getApiSecret(), "secret"); - assertEquals(config.getScope(), "rss-api"); - } - - private static class ApiMock extends DefaultApi20 { - - private OAuthConfig config; - - private static ApiMock instance() { - return new ApiMock(); - } - - private OAuthConfig getConfig() { - return config; - } - - @Override - public OAuth20Service createService(OAuthConfig config) { - this.config = config; - return null; - } - - @Override - public String getAccessTokenEndpoint() { - throw new UnsupportedOperationException("Not supported yet."); - } - - @Override - protected String getAuthorizationBaseUrl() { - throw new UnsupportedOperationException("Not supported yet."); - } - } -} diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ApiUnit.java b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ApiUnit.java index c6c05e05c..5518d9b22 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ApiUnit.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ApiUnit.java @@ -2,7 +2,10 @@ import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.builder.api.OAuth2SignatureType; +import com.github.scribejava.core.httpclient.HttpClient; +import com.github.scribejava.core.httpclient.HttpClientConfig; import com.github.scribejava.core.model.OAuthConfig; +import java.io.OutputStream; class OAuth20ApiUnit extends DefaultApi20 { @@ -16,9 +19,25 @@ protected String getAuthorizationBaseUrl() { return "http://localhost:8080/authorize"; } + @Override + public OAuth20ServiceUnit createService(String apiKey, String apiSecret, String callback, String scope, + OutputStream debugStream, String state, String responseType, String userAgent, + HttpClientConfig httpClientConfig, HttpClient httpClient) { + return new OAuth20ServiceUnit(this, apiKey, apiSecret, callback, scope, debugStream, state, responseType, + userAgent, httpClientConfig, httpClient); + } + + /** + * @deprecated use {@link #createService(java.lang.String, java.lang.String, java.lang.String, java.lang.String, + * java.io.OutputStream, java.lang.String, java.lang.String, java.lang.String, + * com.github.scribejava.core.httpclient.HttpClientConfig, com.github.scribejava.core.httpclient.HttpClient)} + */ + @Deprecated @Override public OAuth20Service createService(OAuthConfig config) { - return new OAuth20ServiceUnit(this, config); + return createService(config.getApiKey(), config.getApiSecret(), config.getCallback(), config.getScope(), + config.getDebugStream(), config.getState(), config.getResponseType(), config.getUserAgent(), + config.getHttpClientConfig(), config.getHttpClient()); } @Override diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceTest.java index b7a0febd0..c74e0ea57 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceTest.java @@ -38,8 +38,7 @@ public void shouldProduceCorrectRequestSync() throws IOException, InterruptedExc assertEquals(OAuth20ServiceUnit.EXPIRES, map.get("expires_in")); final String authorize = base64Encoder.encodeToString( - String.format("%s:%s", service.getConfig().getApiKey(), service.getConfig().getApiSecret()) - .getBytes(Charset.forName("UTF-8"))); + String.format("%s:%s", service.getApiKey(), service.getApiSecret()).getBytes(Charset.forName("UTF-8"))); assertEquals(OAuthConstants.BASIC + " " + authorize, map.get(OAuthConstants.HEADER)); @@ -66,8 +65,7 @@ public void shouldProduceCorrectRequestAsync() throws ExecutionException, Interr assertEquals(OAuth20ServiceUnit.EXPIRES, map.get("expires_in")); final String authorize = base64Encoder.encodeToString( - String.format("%s:%s", service.getConfig().getApiKey(), service.getConfig().getApiSecret()) - .getBytes(Charset.forName("UTF-8"))); + String.format("%s:%s", service.getApiKey(), service.getApiSecret()).getBytes(Charset.forName("UTF-8"))); assertEquals(OAuthConstants.BASIC + " " + authorize, map.get(OAuthConstants.HEADER)); diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceUnit.java b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceUnit.java index 7a7db4555..4b81912ae 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceUnit.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceUnit.java @@ -1,13 +1,15 @@ package com.github.scribejava.core.oauth; import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.httpclient.HttpClient; +import com.github.scribejava.core.httpclient.HttpClientConfig; import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthAsyncRequestCallback; -import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Parameter; import com.google.gson.Gson; +import java.io.OutputStream; import java.util.HashMap; import java.util.Map; @@ -19,8 +21,11 @@ class OAuth20ServiceUnit extends OAuth20Service { static final String STATE = "123"; static final String EXPIRES = "3600"; - OAuth20ServiceUnit(DefaultApi20 api, OAuthConfig config) { - super(api, config); + OAuth20ServiceUnit(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, + OutputStream debugStream, String state, String responseType, String userAgent, + HttpClientConfig httpClientConfig, HttpClient httpClient) { + super(api, apiKey, apiSecret, callback, scope, debugStream, state, responseType, userAgent, httpClientConfig, + httpClient); } @Override From 03dd1eafd8bc9bb3861e0195f93d72b93ab272c8 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 18 Apr 2018 13:55:23 +0300 Subject: [PATCH 475/882] OAuth1.0: send "oob" instead of null callback while requesting RequestToken (thanks to https://github.com/Rafaelsk) --- changelog | 1 + .../com/github/scribejava/core/oauth/OAuth10aService.java | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/changelog b/changelog index 21b5817a4..c5f2ef4ba 100644 --- a/changelog +++ b/changelog @@ -4,6 +4,7 @@ * add new API - Automatic (https://www.automatic.com/) (thanks to https://github.com/ramsrib) * add new API - Fitbit (https://www.fitbit.com/) (thanks to https://github.com/JustinLawler and https://github.com/alexthered) * deprecate OAuthConfig + * OAuth1.0: send "oob" instead of null callback while requesting RequestToken (thanks to https://github.com/Rafaelsk) [5.3.0] * fix Salesforce API (thanks to https://github.com/jhorowitz-firedrum) diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java index 5d77af8a3..c016e5e51 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java @@ -78,7 +78,10 @@ public OAuth1RequestToken convert(Response response) throws IOException { protected OAuthRequest prepareRequestTokenRequest() { final OAuthRequest request = new OAuthRequest(api.getRequestTokenVerb(), api.getRequestTokenEndpoint()); - final String callback = getCallback(); + String callback = getCallback(); + if (callback == null) { + callback = OAuthConstants.OOB; + } log("setting oauth_callback to " + callback); request.addOAuthParameter(OAuthConstants.CALLBACK, callback); addOAuthParams(request, ""); From 22bf184b5ae690603dbb027333a41904398d3e8f Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 18 Apr 2018 14:11:05 +0300 Subject: [PATCH 476/882] small fixes, update deps --- pom.xml | 2 +- .../com/github/scribejava/core/builder/api/DefaultApi20.java | 1 - .../java/com/github/scribejava/core/model/OAuthConstants.java | 4 ++++ scribejava-httpclient-ahc/pom.xml | 2 +- 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 95d3f3d46..2cd298645 100644 --- a/pom.xml +++ b/pom.xml @@ -95,7 +95,7 @@ org.apache.maven.plugins maven-jar-plugin - 3.0.2 + 3.1.0 ${project.build.outputDirectory}/META-INF/MANIFEST.MF diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java index 0b916bce6..799e92f31 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java @@ -84,7 +84,6 @@ public String getAuthorizationUrl(OAuthConfig config, Map additi /** * Returns the URL where you should redirect your users to authenticate your application. * - * @param config OAuth 2.0 configuration param object * @param additionalParams any additional GET params to add to the URL * @return the URL where you should redirect your users */ diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConstants.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConstants.java index 1a38cb36b..268e5f435 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConstants.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConstants.java @@ -23,6 +23,10 @@ public interface OAuthConstants { String BASIC = "Basic"; // OAuth 1.0 + /** + * to indicate an out-of-band configuration + * @see The OAuth 1.0 Protocol + */ String OOB = "oob"; // OAuth 2.0 diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 49ac5ad69..aa7b5ac51 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -23,7 +23,7 @@ org.asynchttpclient async-http-client - 2.4.3 + 2.4.5 com.github.scribejava From 23e4ed3083d5f2e6fb1a8deb8716ec6eb78f0419 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 18 Apr 2018 14:23:00 +0300 Subject: [PATCH 477/882] prepare release 5.4.0 --- README.md | 4 ++-- changelog | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 07f185d5d..7227ce97d 100644 --- a/README.md +++ b/README.md @@ -111,7 +111,7 @@ You can pull ScribeJava from the central maven repository, just add these to you com.github.scribejava scribejava-apis - 5.3.0 + 5.4.0 ``` @@ -120,7 +120,7 @@ And in case you need just core classes (that's it, without any external API (FB, com.github.scribejava scribejava-core - 5.3.0 + 5.4.0 ``` diff --git a/changelog b/changelog index c5f2ef4ba..cc865a4ed 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,4 @@ -[SNAPSHOT] +[5.4.0] * fix missing support for scope for refresh_token grant_type (thanks to https://github.com/tlxtellef) * add email field to VKOAuth2AccessToken (thanks to https://github.com/grouzen) * add new API - Automatic (https://www.automatic.com/) (thanks to https://github.com/ramsrib) From da982dd5409304e8ba4e6906e97955a6bdb8ba12 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 18 Apr 2018 14:24:27 +0300 Subject: [PATCH 478/882] [maven-release-plugin] prepare release scribejava-5.4.0 --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index 2cd298645..866c4c536 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 5.3.1-SNAPSHOT + 5.4.0 ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -34,7 +34,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - HEAD + scribejava-5.4.0 diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index f6e826693..91f3bacc2 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.3.1-SNAPSHOT + 5.4.0 ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index d9ddaeb76..f9b5b7a9d 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.3.1-SNAPSHOT + 5.4.0 ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index aa7b5ac51..df457ec85 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.3.1-SNAPSHOT + 5.4.0 ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index 0bd9b04ec..6ef02c328 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.3.1-SNAPSHOT + 5.4.0 ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index 7b5e1b0e4..fedcb5065 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.3.1-SNAPSHOT + 5.4.0 ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 674113b2f..2e726b426 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.3.1-SNAPSHOT + 5.4.0 ../pom.xml From 4b46ba4043fa6c09af2a3e70b2828cf13deca29c Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 18 Apr 2018 14:24:42 +0300 Subject: [PATCH 479/882] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index 866c4c536..e2b89b530 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 5.4.0 + 5.4.1-SNAPSHOT ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -34,7 +34,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - scribejava-5.4.0 + HEAD diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 91f3bacc2..da6150e43 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.4.0 + 5.4.1-SNAPSHOT ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index f9b5b7a9d..60e6da8cf 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.4.0 + 5.4.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index df457ec85..418fbccfa 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.4.0 + 5.4.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index 6ef02c328..2a3eedc01 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.4.0 + 5.4.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index fedcb5065..0b13d47a1 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.4.0 + 5.4.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 2e726b426..e135a6e93 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.4.0 + 5.4.1-SNAPSHOT ../pom.xml From 47c073250bb3227fd666be0f523e4c6d08c86f8a Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 18 Apr 2018 14:55:19 +0300 Subject: [PATCH 480/882] drop OAuthConfig, remove deprecate usaged --- .../github/scribejava/apis/FacebookApi.java | 18 +--- .../com/github/scribejava/apis/ImgurApi.java | 18 +--- .../com/github/scribejava/apis/MailruApi.java | 18 +--- .../MicrosoftAzureActiveDirectoryApi.java | 18 +--- .../scribejava/apis/OdnoklassnikiApi.java | 18 +--- .../com/github/scribejava/apis/TutByApi.java | 18 +--- .../apis/service/FacebookService.java | 21 ++-- .../apis/service/ImgurOAuthService.java | 21 ++-- .../apis/service/MailruOAuthService.java | 21 ++-- .../MicrosoftAzureActiveDirectoryService.java | 20 ++-- .../service/OdnoklassnikiOAuthService.java | 20 ++-- .../apis/service/TutByOAuthService.java | 21 ++-- .../scribejava/core/builder/api/BaseApi.java | 9 -- .../builder/api/ClientAuthenticationType.java | 10 -- .../core/builder/api/DefaultApi10a.java | 18 +--- .../core/builder/api/DefaultApi20.java | 26 +---- .../scribejava/core/model/OAuthConfig.java | 97 ------------------- .../core/oauth/OAuth10aService.java | 20 ++-- .../scribejava/core/oauth/OAuth20Service.java | 23 ++--- .../scribejava/core/oauth/OAuthService.java | 35 ++----- .../scribejava/core/AbstractClientTest.java | 2 +- .../scribejava/core/oauth/OAuth20ApiUnit.java | 18 +--- .../core/oauth/OAuth20ServiceUnit.java | 9 +- 23 files changed, 100 insertions(+), 399 deletions(-) delete mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConfig.java diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java index a2114760b..463a44d6c 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java @@ -8,7 +8,6 @@ import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.httpclient.HttpClientConfig; import com.github.scribejava.core.model.OAuth2AccessToken; -import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.Verb; import java.io.OutputStream; @@ -74,20 +73,7 @@ public ClientAuthenticationType getClientAuthenticationType() { public FacebookService createService(String apiKey, String apiSecret, String callback, String scope, OutputStream debugStream, String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - return new FacebookService(this, apiKey, apiSecret, callback, scope, debugStream, state, responseType, - userAgent, httpClientConfig, httpClient); - } - - /** - * @deprecated use {@link #createService(java.lang.String, java.lang.String, java.lang.String, java.lang.String, - * java.io.OutputStream, java.lang.String, java.lang.String, java.lang.String, - * com.github.scribejava.core.httpclient.HttpClientConfig, com.github.scribejava.core.httpclient.HttpClient)} - */ - @Deprecated - @Override - public FacebookService createService(OAuthConfig config) { - return createService(config.getApiKey(), config.getApiSecret(), config.getCallback(), config.getScope(), - config.getDebugStream(), config.getState(), config.getResponseType(), config.getUserAgent(), - config.getHttpClientConfig(), config.getHttpClient()); + return new FacebookService(this, apiKey, apiSecret, callback, scope, state, responseType, userAgent, + httpClientConfig, httpClient); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java index 720b62fd2..b8c802647 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java @@ -4,7 +4,6 @@ import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.httpclient.HttpClientConfig; -import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.ParameterList; import java.io.OutputStream; @@ -59,21 +58,8 @@ protected String getAuthorizationBaseUrl() { public ImgurOAuthService createService(String apiKey, String apiSecret, String callback, String scope, OutputStream debugStream, String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - return new ImgurOAuthService(this, apiKey, apiSecret, callback, scope, debugStream, state, responseType, - userAgent, httpClientConfig, httpClient); - } - - /** - * @deprecated use {@link #createService(java.lang.String, java.lang.String, java.lang.String, java.lang.String, - * java.io.OutputStream, java.lang.String, java.lang.String, java.lang.String, - * com.github.scribejava.core.httpclient.HttpClientConfig, com.github.scribejava.core.httpclient.HttpClient)} - */ - @Deprecated - @Override - public ImgurOAuthService createService(OAuthConfig config) { - return createService(config.getApiKey(), config.getApiSecret(), config.getCallback(), config.getScope(), - config.getDebugStream(), config.getState(), config.getResponseType(), config.getUserAgent(), - config.getHttpClientConfig(), config.getHttpClient()); + return new ImgurOAuthService(this, apiKey, apiSecret, callback, scope, state, responseType, userAgent, + httpClientConfig, httpClient); } public static boolean isOob(String callback) { diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java index 318ab2bf2..05ae5cb8a 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java @@ -1,7 +1,6 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.apis.service.MailruOAuthService; import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.httpclient.HttpClientConfig; @@ -34,20 +33,7 @@ protected String getAuthorizationBaseUrl() { public MailruOAuthService createService(String apiKey, String apiSecret, String callback, String scope, OutputStream debugStream, String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - return new MailruOAuthService(this, apiKey, apiSecret, callback, scope, debugStream, state, responseType, - userAgent, httpClientConfig, httpClient); - } - - /** - * @deprecated use {@link #createService(java.lang.String, java.lang.String, java.lang.String, java.lang.String, - * java.io.OutputStream, java.lang.String, java.lang.String, java.lang.String, - * com.github.scribejava.core.httpclient.HttpClientConfig, com.github.scribejava.core.httpclient.HttpClient)} - */ - @Deprecated - @Override - public MailruOAuthService createService(OAuthConfig config) { - return createService(config.getApiKey(), config.getApiSecret(), config.getCallback(), config.getScope(), - config.getDebugStream(), config.getState(), config.getResponseType(), config.getUserAgent(), - config.getHttpClientConfig(), config.getHttpClient()); + return new MailruOAuthService(this, apiKey, apiSecret, callback, scope, state, responseType, userAgent, + httpClientConfig, httpClient); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/MicrosoftAzureActiveDirectoryApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/MicrosoftAzureActiveDirectoryApi.java index c2059d55b..223a88b1c 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/MicrosoftAzureActiveDirectoryApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/MicrosoftAzureActiveDirectoryApi.java @@ -5,7 +5,6 @@ import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.httpclient.HttpClientConfig; -import com.github.scribejava.core.model.OAuthConfig; import java.io.OutputStream; /** @@ -53,21 +52,8 @@ protected String getAuthorizationBaseUrl() { public MicrosoftAzureActiveDirectoryService createService(String apiKey, String apiSecret, String callback, String scope, OutputStream debugStream, String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - return new MicrosoftAzureActiveDirectoryService(this, apiKey, apiSecret, callback, scope, debugStream, state, - responseType, userAgent, httpClientConfig, httpClient); - } - - /** - * @deprecated use {@link #createService(java.lang.String, java.lang.String, java.lang.String, java.lang.String, - * java.io.OutputStream, java.lang.String, java.lang.String, java.lang.String, - * com.github.scribejava.core.httpclient.HttpClientConfig, com.github.scribejava.core.httpclient.HttpClient)} - */ - @Deprecated - @Override - public MicrosoftAzureActiveDirectoryService createService(OAuthConfig config) { - return createService(config.getApiKey(), config.getApiSecret(), config.getCallback(), config.getScope(), - config.getDebugStream(), config.getState(), config.getResponseType(), config.getUserAgent(), - config.getHttpClientConfig(), config.getHttpClient()); + return new MicrosoftAzureActiveDirectoryService(this, apiKey, apiSecret, callback, scope, state, responseType, + userAgent, httpClientConfig, httpClient); } @Override diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java index a65f9b692..c21983fa3 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java @@ -6,7 +6,6 @@ import com.github.scribejava.core.builder.api.OAuth2SignatureType; import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.httpclient.HttpClientConfig; -import com.github.scribejava.core.model.OAuthConfig; import java.io.OutputStream; public class OdnoklassnikiApi extends DefaultApi20 { @@ -36,21 +35,8 @@ protected String getAuthorizationBaseUrl() { public OdnoklassnikiOAuthService createService(String apiKey, String apiSecret, String callback, String scope, OutputStream debugStream, String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - return new OdnoklassnikiOAuthService(this, apiKey, apiSecret, callback, scope, debugStream, state, responseType, - userAgent, httpClientConfig, httpClient); - } - - /** - * @deprecated use {@link #createService(java.lang.String, java.lang.String, java.lang.String, java.lang.String, - * java.io.OutputStream, java.lang.String, java.lang.String, java.lang.String, - * com.github.scribejava.core.httpclient.HttpClientConfig, com.github.scribejava.core.httpclient.HttpClient)} - */ - @Deprecated - @Override - public OdnoklassnikiOAuthService createService(OAuthConfig config) { - return createService(config.getApiKey(), config.getApiSecret(), config.getCallback(), config.getScope(), - config.getDebugStream(), config.getState(), config.getResponseType(), config.getUserAgent(), - config.getHttpClientConfig(), config.getHttpClient()); + return new OdnoklassnikiOAuthService(this, apiKey, apiSecret, callback, scope, state, responseType, userAgent, + httpClientConfig, httpClient); } @Override diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/TutByApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/TutByApi.java index a6b864fb7..377bc9046 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/TutByApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/TutByApi.java @@ -4,7 +4,6 @@ import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.httpclient.HttpClientConfig; -import com.github.scribejava.core.model.OAuthConfig; import java.io.OutputStream; public class TutByApi extends DefaultApi20 { @@ -34,20 +33,7 @@ protected String getAuthorizationBaseUrl() { public TutByOAuthService createService(String apiKey, String apiSecret, String callback, String scope, OutputStream debugStream, String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - return new TutByOAuthService(this, apiKey, apiSecret, callback, scope, debugStream, state, responseType, - userAgent, httpClientConfig, httpClient); - } - - /** - * @deprecated use {@link #createService(java.lang.String, java.lang.String, java.lang.String, java.lang.String, - * java.io.OutputStream, java.lang.String, java.lang.String, java.lang.String, - * com.github.scribejava.core.httpclient.HttpClientConfig, com.github.scribejava.core.httpclient.HttpClient)} - */ - @Deprecated - @Override - public TutByOAuthService createService(OAuthConfig config) { - return createService(config.getApiKey(), config.getApiSecret(), config.getCallback(), config.getScope(), - config.getDebugStream(), config.getState(), config.getResponseType(), config.getUserAgent(), - config.getHttpClientConfig(), config.getHttpClient()); + return new TutByOAuthService(this, apiKey, apiSecret, callback, scope, state, responseType, userAgent, + httpClientConfig, httpClient); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/FacebookService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/FacebookService.java index 925d20f15..565514efe 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/FacebookService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/FacebookService.java @@ -3,7 +3,6 @@ import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.httpclient.HttpClientConfig; -import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.oauth.OAuth20Service; import java.io.OutputStream; @@ -17,22 +16,20 @@ public class FacebookService extends OAuth20Service { /** * @deprecated use {@link #FacebookService(com.github.scribejava.core.builder.api.DefaultApi20, java.lang.String, - * java.lang.String, java.lang.String, java.lang.String, java.io.OutputStream, java.lang.String, java.lang.String, - * java.lang.String, com.github.scribejava.core.httpclient.HttpClientConfig, - * com.github.scribejava.core.httpclient.HttpClient)} + * java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, + * com.github.scribejava.core.httpclient.HttpClientConfig, com.github.scribejava.core.httpclient.HttpClient)} */ @Deprecated - public FacebookService(DefaultApi20 api, OAuthConfig config) { - this(api, config.getApiKey(), config.getApiSecret(), config.getCallback(), config.getScope(), - config.getDebugStream(), config.getState(), config.getResponseType(), config.getUserAgent(), - config.getHttpClientConfig(), config.getHttpClient()); - } - public FacebookService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, OutputStream debugStream, String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - super(api, apiKey, apiSecret, callback, scope, debugStream, state, responseType, userAgent, httpClientConfig, - httpClient); + this(api, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); + } + + public FacebookService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, + String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, + HttpClient httpClient) { + super(api, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); } @Override diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthService.java index 980deb102..c5bfb43f6 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthService.java @@ -4,7 +4,6 @@ import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.httpclient.HttpClientConfig; -import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.oauth.OAuth20Service; @@ -14,22 +13,20 @@ public class ImgurOAuthService extends OAuth20Service { /** * @deprecated use {@link #ImgurOAuthService(com.github.scribejava.core.builder.api.DefaultApi20, java.lang.String, - * java.lang.String, java.lang.String, java.lang.String, java.io.OutputStream, java.lang.String, java.lang.String, - * java.lang.String, com.github.scribejava.core.httpclient.HttpClientConfig, - * com.github.scribejava.core.httpclient.HttpClient)} + * java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, + * com.github.scribejava.core.httpclient.HttpClientConfig, com.github.scribejava.core.httpclient.HttpClient)} */ @Deprecated - public ImgurOAuthService(DefaultApi20 api, OAuthConfig config) { - this(api, config.getApiKey(), config.getApiSecret(), config.getCallback(), config.getScope(), - config.getDebugStream(), config.getState(), config.getResponseType(), config.getUserAgent(), - config.getHttpClientConfig(), config.getHttpClient()); - } - public ImgurOAuthService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, OutputStream debugStream, String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - super(api, apiKey, apiSecret, callback, scope, debugStream, state, responseType, userAgent, httpClientConfig, - httpClient); + this(api, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); + } + + public ImgurOAuthService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, + String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, + HttpClient httpClient) { + super(api, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); } @Override diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthService.java index 70a96d211..aadfc58b5 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthService.java @@ -6,7 +6,6 @@ import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.httpclient.HttpClientConfig; -import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.oauth.OAuth20Service; import java.io.OutputStream; @@ -20,22 +19,20 @@ public class MailruOAuthService extends OAuth20Service { /** * @deprecated use {@link #MailruOAuthService(com.github.scribejava.core.builder.api.DefaultApi20, java.lang.String, - * java.lang.String, java.lang.String, java.lang.String, java.io.OutputStream, java.lang.String, java.lang.String, - * java.lang.String, com.github.scribejava.core.httpclient.HttpClientConfig, - * com.github.scribejava.core.httpclient.HttpClient)} + * java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, + * com.github.scribejava.core.httpclient.HttpClientConfig, com.github.scribejava.core.httpclient.HttpClient)} */ @Deprecated - public MailruOAuthService(DefaultApi20 api, OAuthConfig config) { - this(api, config.getApiKey(), config.getApiSecret(), config.getCallback(), config.getScope(), - config.getDebugStream(), config.getState(), config.getResponseType(), config.getUserAgent(), - config.getHttpClientConfig(), config.getHttpClient()); - } - public MailruOAuthService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, OutputStream debugStream, String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - super(api, apiKey, apiSecret, callback, scope, debugStream, state, responseType, userAgent, httpClientConfig, - httpClient); + this(api, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); + } + + public MailruOAuthService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, + String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, + HttpClient httpClient) { + super(api, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MicrosoftAzureActiveDirectoryService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MicrosoftAzureActiveDirectoryService.java index afe2ad065..59fc2f00b 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MicrosoftAzureActiveDirectoryService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MicrosoftAzureActiveDirectoryService.java @@ -3,7 +3,6 @@ import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.httpclient.HttpClientConfig; -import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.oauth.OAuth20Service; import java.io.OutputStream; @@ -15,22 +14,21 @@ public class MicrosoftAzureActiveDirectoryService extends OAuth20Service { /** * @deprecated use {@link #MicrosoftAzureActiveDirectoryService(com.github.scribejava.core.builder.api.DefaultApi20, - * java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.io.OutputStream, java.lang.String, - * java.lang.String, java.lang.String, com.github.scribejava.core.httpclient.HttpClientConfig, + * java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, + * java.lang.String, com.github.scribejava.core.httpclient.HttpClientConfig, * com.github.scribejava.core.httpclient.HttpClient)} */ @Deprecated - public MicrosoftAzureActiveDirectoryService(DefaultApi20 api, OAuthConfig config) { - this(api, config.getApiKey(), config.getApiSecret(), config.getCallback(), config.getScope(), - config.getDebugStream(), config.getState(), config.getResponseType(), config.getUserAgent(), - config.getHttpClientConfig(), config.getHttpClient()); - } - public MicrosoftAzureActiveDirectoryService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, OutputStream debugStream, String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - super(api, apiKey, apiSecret, callback, scope, debugStream, state, responseType, userAgent, httpClientConfig, - httpClient); + this(api, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); + } + + public MicrosoftAzureActiveDirectoryService(DefaultApi20 api, String apiKey, String apiSecret, String callback, + String scope, String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, + HttpClient httpClient) { + super(api, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); } @Override diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiOAuthService.java index 82618313f..b2aa5cbda 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiOAuthService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiOAuthService.java @@ -3,7 +3,6 @@ import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.httpclient.HttpClientConfig; -import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Parameter; import com.github.scribejava.core.model.ParameterList; @@ -23,22 +22,21 @@ public class OdnoklassnikiOAuthService extends OAuth20Service { /** * @deprecated use {@link #OdnoklassnikiOAuthService(com.github.scribejava.core.builder.api.DefaultApi20, - * java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.io.OutputStream, java.lang.String, - * java.lang.String, java.lang.String, com.github.scribejava.core.httpclient.HttpClientConfig, + * java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, + * java.lang.String, com.github.scribejava.core.httpclient.HttpClientConfig, * com.github.scribejava.core.httpclient.HttpClient)} */ @Deprecated - public OdnoklassnikiOAuthService(DefaultApi20 api, OAuthConfig config) { - this(api, config.getApiKey(), config.getApiSecret(), config.getCallback(), config.getScope(), - config.getDebugStream(), config.getState(), config.getResponseType(), config.getUserAgent(), - config.getHttpClientConfig(), config.getHttpClient()); - } - public OdnoklassnikiOAuthService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, OutputStream debugStream, String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - super(api, apiKey, apiSecret, callback, scope, debugStream, state, responseType, userAgent, httpClientConfig, - httpClient); + this(api, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); + } + + public OdnoklassnikiOAuthService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, + String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, + HttpClient httpClient) { + super(api, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); } @Override diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/TutByOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/TutByOAuthService.java index c2d191e35..17e64e7b5 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/TutByOAuthService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/TutByOAuthService.java @@ -3,7 +3,6 @@ import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.httpclient.HttpClientConfig; -import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.oauth.OAuth20Service; @@ -13,22 +12,20 @@ public class TutByOAuthService extends OAuth20Service { /** * @deprecated use {@link #TutByOAuthService(com.github.scribejava.core.builder.api.DefaultApi20, java.lang.String, - * java.lang.String, java.lang.String, java.lang.String, java.io.OutputStream, java.lang.String, java.lang.String, - * java.lang.String, com.github.scribejava.core.httpclient.HttpClientConfig, - * com.github.scribejava.core.httpclient.HttpClient)} + * java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, + * com.github.scribejava.core.httpclient.HttpClientConfig, com.github.scribejava.core.httpclient.HttpClient)} */ @Deprecated - public TutByOAuthService(DefaultApi20 api, OAuthConfig config) { - this(api, config.getApiKey(), config.getApiSecret(), config.getCallback(), config.getScope(), - config.getDebugStream(), config.getState(), config.getResponseType(), config.getUserAgent(), - config.getHttpClientConfig(), config.getHttpClient()); - } - public TutByOAuthService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, OutputStream debugStream, String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - super(api, apiKey, apiSecret, callback, scope, debugStream, state, responseType, userAgent, httpClientConfig, - httpClient); + this(api, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); + } + + public TutByOAuthService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, + String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, + HttpClient httpClient) { + super(api, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); } @Override diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/BaseApi.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/BaseApi.java index bac1cd7b7..bce6192dc 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/BaseApi.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/BaseApi.java @@ -2,20 +2,11 @@ import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.httpclient.HttpClientConfig; -import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.oauth.OAuthService; import java.io.OutputStream; public interface BaseApi { - /** - * @deprecated use {@link #createService(java.lang.String, java.lang.String, java.lang.String, java.lang.String, - * java.io.OutputStream, java.lang.String, java.lang.String, java.lang.String, - * com.github.scribejava.core.httpclient.HttpClientConfig, com.github.scribejava.core.httpclient.HttpClient)} - */ - @Deprecated - T createService(OAuthConfig config); - T createService(String apiKey, String apiSecret, String callback, String scope, OutputStream debugStream, String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient); diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/ClientAuthenticationType.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/ClientAuthenticationType.java index e466e2159..77212ce95 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/ClientAuthenticationType.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/ClientAuthenticationType.java @@ -1,7 +1,6 @@ package com.github.scribejava.core.builder.api; import com.github.scribejava.core.java8.Base64; -import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.OAuthRequest; import java.nio.charset.Charset; @@ -37,13 +36,4 @@ public void addClientAuthentication(OAuthRequest request, String apiKey, String }; public abstract void addClientAuthentication(OAuthRequest request, String apiKey, String apiSecret); - - /** - * @deprecated use {@link #addClientAuthentication(com.github.scribejava.core.model.OAuthRequest, java.lang.String, - * java.lang.String)} - */ - @Deprecated - public void addClientAuthentication(OAuthRequest request, OAuthConfig config) { - addClientAuthentication(request, config.getApiKey(), config.getApiSecret()); - } } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi10a.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi10a.java index aabb00028..67bbd181e 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi10a.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi10a.java @@ -6,7 +6,6 @@ import com.github.scribejava.core.extractors.HeaderExtractorImpl; import com.github.scribejava.core.extractors.OAuth1AccessTokenExtractor; import com.github.scribejava.core.extractors.OAuth1RequestTokenExtractor; -import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.oauth.OAuth10aService; import com.github.scribejava.core.services.HMACSha1SignatureService; @@ -144,25 +143,12 @@ public String getAuthorizationUrl(OAuth1RequestToken requestToken) { return parameters.appendTo(getAuthorizationBaseUrl()); } - /** - * @deprecated use {@link #createService(java.lang.String, java.lang.String, java.lang.String, java.lang.String, - * java.io.OutputStream, java.lang.String, java.lang.String, java.lang.String, - * com.github.scribejava.core.httpclient.HttpClientConfig, com.github.scribejava.core.httpclient.HttpClient)} - */ - @Deprecated - @Override - public OAuth10aService createService(OAuthConfig config) { - return createService(config.getApiKey(), config.getApiSecret(), config.getCallback(), config.getScope(), - config.getDebugStream(), config.getState(), config.getResponseType(), config.getUserAgent(), - config.getHttpClientConfig(), config.getHttpClient()); - } - @Override public OAuth10aService createService(String apiKey, String apiSecret, String callback, String scope, OutputStream debugStream, String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - return new OAuth10aService(this, apiKey, apiSecret, callback, scope, debugStream, state, responseType, - userAgent, httpClientConfig, httpClient); + return new OAuth10aService(this, apiKey, apiSecret, callback, scope, debugStream, userAgent, httpClientConfig, + httpClient); } /** diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java index 799e92f31..5555faac3 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java @@ -5,7 +5,6 @@ import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.httpclient.HttpClientConfig; import com.github.scribejava.core.model.OAuth2AccessToken; -import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.ParameterList; import com.github.scribejava.core.model.Verb; @@ -71,16 +70,6 @@ public String getRevokeTokenEndpoint() { protected abstract String getAuthorizationBaseUrl(); - /** - * @deprecated use {@link #getAuthorizationUrl(java.lang.String, java.lang.String, java.lang.String, - * java.lang.String, java.lang.String, java.util.Map)} - */ - @Deprecated - public String getAuthorizationUrl(OAuthConfig config, Map additionalParams) { - return getAuthorizationUrl(config.getResponseType(), config.getApiKey(), config.getCallback(), - config.getScope(), config.getState(), additionalParams); - } - /** * Returns the URL where you should redirect your users to authenticate your application. * @@ -108,24 +97,11 @@ public String getAuthorizationUrl(String responseType, String apiKey, String cal return parameters.appendTo(getAuthorizationBaseUrl()); } - /** - * @deprecated use {@link #createService(java.lang.String, java.lang.String, java.lang.String, java.lang.String, - * java.io.OutputStream, java.lang.String, java.lang.String, java.lang.String, - * com.github.scribejava.core.httpclient.HttpClientConfig, com.github.scribejava.core.httpclient.HttpClient)} - */ - @Deprecated - @Override - public OAuth20Service createService(OAuthConfig config) { - return createService(config.getApiKey(), config.getApiSecret(), config.getCallback(), config.getScope(), - config.getDebugStream(), config.getState(), config.getResponseType(), config.getUserAgent(), - config.getHttpClientConfig(), config.getHttpClient()); - } - @Override public OAuth20Service createService(String apiKey, String apiSecret, String callback, String scope, OutputStream debugStream, String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - return new OAuth20Service(this, apiKey, apiSecret, callback, scope, debugStream, state, responseType, userAgent, + return new OAuth20Service(this, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConfig.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConfig.java deleted file mode 100644 index a31593879..000000000 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConfig.java +++ /dev/null @@ -1,97 +0,0 @@ -package com.github.scribejava.core.model; - -import com.github.scribejava.core.httpclient.HttpClient; -import com.github.scribejava.core.httpclient.HttpClientConfig; -import java.io.IOException; -import java.io.OutputStream; - -/** - * Parameter object that groups OAuth config values - * - * @deprecated use service.getXXX() instead of service.getConfigXXX() and service.method(...) instead of - * service.method(config) - */ -@Deprecated -public class OAuthConfig { - - private final String apiKey; - private final String apiSecret; - private final String callback; - private final String scope; - private final OutputStream debugStream; - private final String state; - private final String responseType; - private final String userAgent; - private final HttpClientConfig httpClientConfig; - private final HttpClient httpClient; - - public OAuthConfig(String key, String secret) { - this(key, secret, null, null, null, null, null, null, null, null); - } - - public OAuthConfig(String apiKey, String apiSecret, String callback, String scope, OutputStream debugStream, - String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, - HttpClient httpClient) { - this.apiKey = apiKey; - this.apiSecret = apiSecret; - this.callback = callback; - this.scope = scope; - this.debugStream = debugStream; - this.state = state; - this.responseType = responseType; - this.userAgent = userAgent; - this.httpClientConfig = httpClientConfig; - this.httpClient = httpClient; - } - - public String getApiKey() { - return apiKey; - } - - public String getApiSecret() { - return apiSecret; - } - - public String getCallback() { - return callback; - } - - public String getScope() { - return scope; - } - - public String getState() { - return state; - } - - public String getResponseType() { - return responseType; - } - - public String getUserAgent() { - return userAgent; - } - - public void log(String message) { - if (debugStream != null) { - message += '\n'; - try { - debugStream.write(message.getBytes("UTF8")); - } catch (IOException | RuntimeException e) { - throw new RuntimeException("there were problems while writting to the debug stream", e); - } - } - } - - public HttpClientConfig getHttpClientConfig() { - return httpClientConfig; - } - - public HttpClient getHttpClient() { - return httpClient; - } - - public OutputStream getDebugStream() { - return debugStream; - } -} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java index c016e5e51..bf708395e 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java @@ -9,7 +9,6 @@ import com.github.scribejava.core.model.OAuth1AccessToken; import com.github.scribejava.core.model.OAuth1RequestToken; import com.github.scribejava.core.model.OAuthAsyncRequestCallback; -import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; @@ -28,22 +27,19 @@ public class OAuth10aService extends OAuthService { /** * @deprecated use {@link #OAuth10aService(com.github.scribejava.core.builder.api.DefaultApi10a, java.lang.String, - * java.lang.String, java.lang.String, java.lang.String, java.io.OutputStream, java.lang.String, java.lang.String, - * java.lang.String, com.github.scribejava.core.httpclient.HttpClientConfig, - * com.github.scribejava.core.httpclient.HttpClient)} + * java.lang.String, java.lang.String, java.lang.String, java.io.OutputStream, java.lang.String, + * com.github.scribejava.core.httpclient.HttpClientConfig, com.github.scribejava.core.httpclient.HttpClient)} */ @Deprecated - public OAuth10aService(DefaultApi10a api, OAuthConfig config) { - this(api, config.getApiKey(), config.getApiSecret(), config.getCallback(), config.getScope(), - config.getDebugStream(), config.getState(), config.getResponseType(), config.getUserAgent(), - config.getHttpClientConfig(), config.getHttpClient()); - } - public OAuth10aService(DefaultApi10a api, String apiKey, String apiSecret, String callback, String scope, OutputStream debugStream, String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - super(apiKey, apiSecret, callback, scope, debugStream, state, responseType, userAgent, httpClientConfig, - httpClient); + this(api, apiKey, apiSecret, callback, scope, debugStream, userAgent, httpClientConfig, httpClient); + } + + public OAuth10aService(DefaultApi10a api, String apiKey, String apiSecret, String callback, String scope, + OutputStream debugStream, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { + super(apiKey, apiSecret, callback, scope, userAgent, httpClientConfig, httpClient); this.debugStream = debugStream; this.api = api; } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java index 1e38793f9..29df7e94e 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java @@ -9,7 +9,6 @@ import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuth2Authorization; import com.github.scribejava.core.model.OAuthAsyncRequestCallback; -import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; @@ -32,25 +31,21 @@ public class OAuth20Service extends OAuthService { private final String state; /** - * @param api OAuth2.0 api information - * @param config OAuth 2.0 configuration param object * @deprecated use {@link #OAuth20Service(com.github.scribejava.core.builder.api.DefaultApi20, java.lang.String, - * java.lang.String, java.lang.String, java.lang.String, java.io.OutputStream, java.lang.String, java.lang.String, - * java.lang.String, com.github.scribejava.core.httpclient.HttpClientConfig, - * com.github.scribejava.core.httpclient.HttpClient)} + * java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, + * com.github.scribejava.core.httpclient.HttpClientConfig, com.github.scribejava.core.httpclient.HttpClient)} */ @Deprecated - public OAuth20Service(DefaultApi20 api, OAuthConfig config) { - this(api, config.getApiKey(), config.getApiSecret(), config.getCallback(), config.getScope(), - config.getDebugStream(), config.getState(), config.getResponseType(), config.getUserAgent(), - config.getHttpClientConfig(), config.getHttpClient()); - } - public OAuth20Service(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, OutputStream debugStream, String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - super(apiKey, apiSecret, callback, scope, debugStream, state, responseType, userAgent, httpClientConfig, - httpClient); + this(api, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); + } + + public OAuth20Service(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, + String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, + HttpClient httpClient) { + super(apiKey, apiSecret, callback, scope, userAgent, httpClientConfig, httpClient); this.responseType = responseType; this.state = state; this.api = api; diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java index 1f53f37a0..60c2d39aa 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java @@ -6,7 +6,6 @@ import com.github.scribejava.core.httpclient.jdk.JDKHttpClient; import com.github.scribejava.core.httpclient.jdk.JDKHttpClientConfig; import com.github.scribejava.core.model.OAuthAsyncRequestCallback; -import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; import java.io.Closeable; @@ -27,16 +26,8 @@ public abstract class OAuthService implements Closeable { private final String userAgent; private final HttpClient httpClient; - /** - * - * @deprecated use all members directly from this class - */ - @Deprecated - private final OAuthConfig oAuthConfig; - - public OAuthService(String apiKey, String apiSecret, String callback, String scope, OutputStream debugStream, - String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, - HttpClient httpClient) { + public OAuthService(String apiKey, String apiSecret, String callback, String scope, String userAgent, + HttpClientConfig httpClientConfig, HttpClient httpClient) { this.apiKey = apiKey; this.apiSecret = apiSecret; this.callback = callback; @@ -48,20 +39,18 @@ public OAuthService(String apiKey, String apiSecret, String callback, String sco } else { this.httpClient = httpClient == null ? getClient(httpClientConfig) : httpClient; } - oAuthConfig = new OAuthConfig(apiKey, apiSecret, callback, scope, debugStream, state, responseType, userAgent, - httpClientConfig, httpClient); } /** * @deprecated use {@link #OAuthService(java.lang.String, java.lang.String, java.lang.String, java.lang.String, - * java.io.OutputStream, java.lang.String, java.lang.String, java.lang.String, - * com.github.scribejava.core.httpclient.HttpClientConfig, com.github.scribejava.core.httpclient.HttpClient)} + * java.lang.String, com.github.scribejava.core.httpclient.HttpClientConfig, + * com.github.scribejava.core.httpclient.HttpClient)} */ @Deprecated - public OAuthService(OAuthConfig config) { - this(config.getApiKey(), config.getApiSecret(), config.getCallback(), config.getScope(), - config.getDebugStream(), config.getState(), config.getResponseType(), config.getUserAgent(), - config.getHttpClientConfig(), config.getHttpClient()); + public OAuthService(String apiKey, String apiSecret, String callback, String scope, OutputStream debugStream, + String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, + HttpClient httpClient) { + this(apiKey, apiSecret, callback, scope, userAgent, httpClientConfig, httpClient); } private static HttpClient getClient(HttpClientConfig config) { @@ -79,14 +68,6 @@ public void close() throws IOException { httpClient.close(); } - /** - * @deprecated use direct getXXX() instead of getConfig().getXXX() - */ - @Deprecated - public OAuthConfig getConfig() { - return oAuthConfig; - } - public String getApiKey() { return apiKey; } diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/AbstractClientTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/AbstractClientTest.java index 089071494..58c4664de 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/AbstractClientTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/AbstractClientTest.java @@ -44,7 +44,7 @@ public Response getResponse() { @Before public void setUp() { - oAuthService = new OAuth20Service(null, "test", "test", null, null, null, null, null, null, null, + oAuthService = new OAuth20Service(null, "test", "test", null, null, null, null, null, null, createNewClient()); } diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ApiUnit.java b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ApiUnit.java index 5518d9b22..a3187957e 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ApiUnit.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ApiUnit.java @@ -4,7 +4,6 @@ import com.github.scribejava.core.builder.api.OAuth2SignatureType; import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.httpclient.HttpClientConfig; -import com.github.scribejava.core.model.OAuthConfig; import java.io.OutputStream; class OAuth20ApiUnit extends DefaultApi20 { @@ -23,21 +22,8 @@ protected String getAuthorizationBaseUrl() { public OAuth20ServiceUnit createService(String apiKey, String apiSecret, String callback, String scope, OutputStream debugStream, String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - return new OAuth20ServiceUnit(this, apiKey, apiSecret, callback, scope, debugStream, state, responseType, - userAgent, httpClientConfig, httpClient); - } - - /** - * @deprecated use {@link #createService(java.lang.String, java.lang.String, java.lang.String, java.lang.String, - * java.io.OutputStream, java.lang.String, java.lang.String, java.lang.String, - * com.github.scribejava.core.httpclient.HttpClientConfig, com.github.scribejava.core.httpclient.HttpClient)} - */ - @Deprecated - @Override - public OAuth20Service createService(OAuthConfig config) { - return createService(config.getApiKey(), config.getApiSecret(), config.getCallback(), config.getScope(), - config.getDebugStream(), config.getState(), config.getResponseType(), config.getUserAgent(), - config.getHttpClientConfig(), config.getHttpClient()); + return new OAuth20ServiceUnit(this, apiKey, apiSecret, callback, scope, state, responseType, userAgent, + httpClientConfig, httpClient); } @Override diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceUnit.java b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceUnit.java index 4b81912ae..a5cbf9763 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceUnit.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceUnit.java @@ -9,7 +9,6 @@ import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Parameter; import com.google.gson.Gson; -import java.io.OutputStream; import java.util.HashMap; import java.util.Map; @@ -21,11 +20,9 @@ class OAuth20ServiceUnit extends OAuth20Service { static final String STATE = "123"; static final String EXPIRES = "3600"; - OAuth20ServiceUnit(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, - OutputStream debugStream, String state, String responseType, String userAgent, - HttpClientConfig httpClientConfig, HttpClient httpClient) { - super(api, apiKey, apiSecret, callback, scope, debugStream, state, responseType, userAgent, httpClientConfig, - httpClient); + OAuth20ServiceUnit(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, String state, + String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { + super(api, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); } @Override From 16de05a34c1c9bf63bbb48f8f2ddfbf1de0422f7 Mon Sep 17 00:00:00 2001 From: eos1d3 Date: Sun, 29 Apr 2018 05:48:53 +0800 Subject: [PATCH 481/882] Add multipart form-data request to JDK Http Client Changes to be committed: modified: scribejava-core/src/main/java/com/github/scribejava/core/httpclient/AbstractAsyncOnlyHttpClient.java modified: scribejava-core/src/main/java/com/github/scribejava/core/httpclient/HttpClient.java modified: scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java modified: scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequest.java modified: scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java modified: scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java --- .../AbstractAsyncOnlyHttpClient.java | 6 + .../core/httpclient/HttpClient.java | 3 + .../core/httpclient/jdk/JDKHttpClient.java | 43 ++++++- .../scribejava/core/model/OAuthRequest.java | 110 +++++++++++++++++- .../scribejava/core/oauth/OAuthService.java | 6 +- .../httpclient/okhttp/OkHttpHttpClient.java | 11 +- 6 files changed, 171 insertions(+), 8 deletions(-) diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/AbstractAsyncOnlyHttpClient.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/AbstractAsyncOnlyHttpClient.java index 091a95849..b8d6dead9 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/AbstractAsyncOnlyHttpClient.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/AbstractAsyncOnlyHttpClient.java @@ -30,4 +30,10 @@ public Response execute(String userAgent, Map headers, Verb http return executeAsync(userAgent, headers, httpVerb, completeUrl, bodyContents, null, (OAuthRequest.ResponseConverter) null).get(); } + + @Override + public Response execute(String userAgent, Map headers, Verb httpVerb, String completeUrl, + OAuthRequest.MultipartPayloads multipartPayloads) throws InterruptedException, ExecutionException, IOException { + throw new UnsupportedOperationException("This HttpClient does not support Multipart payload for the moment"); + } } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/HttpClient.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/HttpClient.java index a3bc0b5c5..41c5df134 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/HttpClient.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/HttpClient.java @@ -27,6 +27,9 @@ Future executeAsync(String userAgent, Map headers, Verb h Response execute(String userAgent, Map headers, Verb httpVerb, String completeUrl, byte[] bodyContents) throws InterruptedException, ExecutionException, IOException; + + Response execute(String userAgent, Map headers, Verb httpVerb, String completeUrl, + OAuthRequest.MultipartPayloads multipartPayloads) throws InterruptedException, ExecutionException, IOException; Response execute(String userAgent, Map headers, Verb httpVerb, String completeUrl, String bodyContents) throws InterruptedException, ExecutionException, IOException; diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java index 6e970bb07..3b4245671 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java @@ -9,6 +9,7 @@ import com.github.scribejava.core.model.Verb; import java.io.File; import java.io.IOException; +import java.io.OutputStream; import java.net.HttpURLConnection; import java.net.URL; import java.net.UnknownHostException; @@ -73,7 +74,7 @@ public Future executeAsync(String userAgent, Map headers, @Override public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, File bodyContents, OAuthAsyncRequestCallback callback, OAuthRequest.ResponseConverter converter) { - throw new UnsupportedOperationException("JDKHttpClient do not support File payload for the moment"); + throw new UnsupportedOperationException("JDKHttpClient does not support File payload for the moment"); } @Override @@ -94,6 +95,12 @@ public Response execute(String userAgent, Map headers, Verb http throw new UnsupportedOperationException("JDKHttpClient do not support File payload for the moment"); } + @Override + public Response execute(String userAgent, Map headers, Verb httpVerb, String completeUrl, + OAuthRequest.MultipartPayloads multipartPayloads) throws InterruptedException, ExecutionException, IOException { + return doExecute(userAgent, headers, httpVerb, completeUrl, BodyType.MULTIPART, multipartPayloads); + } + private Response doExecute(String userAgent, Map headers, Verb httpVerb, String completeUrl, BodyType bodyType, Object bodyContents) throws IOException { final HttpURLConnection connection = (HttpURLConnection) new URL(completeUrl).openConnection(); @@ -128,6 +135,12 @@ void setBody(HttpURLConnection connection, Object bodyContents, boolean requires addBody(connection, (byte[]) bodyContents, requiresBody); } }, + MULTIPART { + @Override + void setBody(HttpURLConnection connection, Object bodyContents, boolean requiresBody) throws IOException { + addBody(connection, (OAuthRequest.MultipartPayloads) bodyContents, requiresBody); + } + }, STRING { @Override void setBody(HttpURLConnection connection, Object bodyContents, boolean requiresBody) throws IOException { @@ -137,6 +150,7 @@ void setBody(HttpURLConnection connection, Object bodyContents, boolean requires abstract void setBody(HttpURLConnection connection, Object bodyContents, boolean requiresBody) throws IOException; + } private static Map parseHeaders(HttpURLConnection conn) { @@ -164,11 +178,35 @@ private static void addHeaders(HttpURLConnection connection, Map } } + /* + * Multipart implementation supporting more than one payload + * + */ + private static void addBody(HttpURLConnection connection, OAuthRequest.MultipartPayloads multipartPayloads, boolean requiresBody) throws IOException { + int contentLength = multipartPayloads.getContentLength(); + System.out.println("length: " + contentLength); + if (requiresBody || contentLength > 0) { + connection.setRequestProperty(CONTENT_LENGTH, String.valueOf(contentLength)); + if (connection.getRequestProperty(CONTENT_TYPE) == null) { + connection.setRequestProperty(CONTENT_TYPE, DEFAULT_CONTENT_TYPE); + } + System.out.println("content-length: " + connection.getRequestProperty(CONTENT_TYPE)); + connection.setDoOutput(true); + OutputStream os = connection.getOutputStream(); + + int totalParts = multipartPayloads.getMultipartPayloadList().size(); + for (int i = 0; i < totalParts; i++) { + os.write(multipartPayloads.getStartBoundary(i)); + os.write(multipartPayloads.getMultipartPayloadList().get(i).getPayload(), 0, multipartPayloads.getMultipartPayloadList().get(i).getLength()); + os.write(multipartPayloads.getEndBoundary(i)); + } + } + } + private static void addBody(HttpURLConnection connection, byte[] content, boolean requiresBody) throws IOException { final int contentLength = content.length; if (requiresBody || contentLength > 0) { connection.setRequestProperty(CONTENT_LENGTH, String.valueOf(contentLength)); - if (connection.getRequestProperty(CONTENT_TYPE) == null) { connection.setRequestProperty(CONTENT_TYPE, DEFAULT_CONTENT_TYPE); } @@ -176,4 +214,5 @@ private static void addBody(HttpURLConnection connection, byte[] content, boolea connection.getOutputStream().write(content); } } + } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequest.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequest.java index 3f50440eb..39b3dd73f 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequest.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequest.java @@ -7,15 +7,79 @@ import java.net.MalformedURLException; import java.net.URL; import java.nio.charset.Charset; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; + /** * The representation of an OAuth HttpRequest. */ public class OAuthRequest { - - private static final String OAUTH_PREFIX = "oauth_"; + /* + * The class containing more than one payload of multipart/form-data request + */ + public class MultipartPayloads { + private String boundary; + private int contentLength; + private List multipartPayloadList; + + public MultipartPayloads(String boundary) { + this.boundary = boundary; + this.multipartPayloadList = new ArrayList<>(); + } + + public byte[] getStartBoundary(int index) { + MultipartPayload multipartPaayLoad = multipartPayloadList.get(index); + byte[] bytes = ("--" + boundary +"\r\n" + + "Content-Disposition: " + multipartPaayLoad.contentDisposition + "\r\n" + + (multipartPaayLoad == null ? "" : "Content-Type: " + multipartPaayLoad.contentType + "\r\n") + + "\r\n").getBytes(); + return bytes; + } + + public byte[] getEndBoundary(int index) { + return ("\r\n" + + "--" + boundary + "--\r\n").getBytes(); + } + + public int getContentLength() { + return contentLength; + } + + public void addContentLength(int length) { + this.contentLength += length; + } + + public List getMultipartPayloadList() { + return multipartPayloadList; + } + } + + public class MultipartPayload { + private String contentDisposition; + private String contentType; + private byte[] payload; + private int length; + + public MultipartPayload(String contentDisposition, String contentType, byte[] payload, int length) { + this.contentDisposition = contentDisposition; + this.contentType = contentType; + this.payload = payload; + this.length = length; + } + + public byte[] getPayload() { + return payload; + } + + public int getLength() { + return length; + } + } + + private static final String OAUTH_PREFIX = "oauth_"; private final String url; private final Verb verb; @@ -28,6 +92,7 @@ public class OAuthRequest { private String stringPayload; private byte[] byteArrayPayload; private File filePayload; + private MultipartPayloads multipartPayloads; private final Map oauthParameters = new HashMap<>(); @@ -123,7 +188,43 @@ public void addParameter(String key, String value) { querystringParams.add(key, value); } } + + /* + * Set boundary of multipart request + * + * @param boundary can be any string + */ + public void setMultipartBoundary(String boundary) { + multipartPayloads = new MultipartPayloads(boundary); + } + + + /* + * Add one multipart form-data payload to the request & increase the current Content-Length + * + * @param contentDisposition value of Content-Disposition header + * @param contentType value of Content-Type header + * @param payload data array containing the data to send + * @param length the max no of bytes to send + * + * Remarks: + * 57 and 37 are the length of constant portions of contentDisposition and/or contentType headers + * refer getStartBoundary and getEndBoundary for the constant + * + * Must be called after setMultipartBoundary method + */ + public void addMultipartPayload(String contentDisposition, String contentType, byte[] payload, int length) { + int contentLenght; + if (contentType == null) + contentLenght = 37 + multipartPayloads.boundary.length() * 2 + contentDisposition.length() + payload.length; + else + contentLenght = 53 + multipartPayloads.boundary.length() * 2 + contentDisposition.length() + + contentType.length() + payload.length; + multipartPayloads.addContentLength(contentLenght); + + multipartPayloads.getMultipartPayloadList().add(new MultipartPayload(contentDisposition, contentType, payload, length)); + } + /** * Set body payload. This method is used when the HTTP body is not a form-url-encoded string, but another thing. * Like for example XML. Note: The contents are not part of the OAuth signature @@ -159,6 +260,7 @@ private void resetPayload() { stringPayload = null; byteArrayPayload = null; filePayload = null; + multipartPayloads = null; } /** @@ -237,6 +339,10 @@ public byte[] getByteArrayPayload() { } } + public MultipartPayloads getMultipartPayloads() { + return multipartPayloads; + } + public File getFilePayload() { return filePayload; } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java index 60c2d39aa..8b92e51dc 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java @@ -123,7 +123,11 @@ public Response execute(OAuthRequest request) throws InterruptedException, Execu } else if (request.getStringPayload() != null) { return httpClient.execute(userAgent, request.getHeaders(), request.getVerb(), request.getCompleteUrl(), request.getStringPayload()); - } else { + } else if (request.getMultipartPayloads() != null) { + return httpClient.execute(userAgent, request.getHeaders(), request.getVerb(), request.getCompleteUrl(), + request.getMultipartPayloads()); + } + else { return httpClient.execute(userAgent, request.getHeaders(), request.getVerb(), request.getCompleteUrl(), request.getByteArrayPayload()); } diff --git a/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java b/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java index 123c943ba..2582eab17 100644 --- a/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java +++ b/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java @@ -4,6 +4,7 @@ import com.github.scribejava.core.model.OAuthAsyncRequestCallback; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.OAuthRequest.MultipartPayloads; import com.github.scribejava.core.model.Verb; import okhttp3.Call; import okhttp3.MediaType; @@ -11,11 +12,9 @@ import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.internal.http.HttpMethod; - import java.io.IOException; import java.util.Map; import java.util.concurrent.Future; - import com.github.scribejava.core.model.Response; import java.io.File; import java.util.HashMap; @@ -101,6 +100,12 @@ public Response execute(String userAgent, Map headers, Verb http return doExecute(userAgent, headers, httpVerb, completeUrl, BodyType.FILE, bodyContents); } + @Override + public Response execute(String userAgent, Map headers, Verb httpVerb, String completeUrl, + MultipartPayloads multipartPayloads) throws InterruptedException, ExecutionException, IOException { + throw new UnsupportedOperationException("OKHttpClient does not support Multipart payload for the moment"); + } + private Response doExecute(String userAgent, Map headers, Verb httpVerb, String completeUrl, BodyType bodyType, Object bodyContents) throws IOException { final Call call = createCall(userAgent, headers, httpVerb, completeUrl, bodyType, bodyContents); @@ -174,6 +179,6 @@ static Response convertResponse(okhttp3.Response okHttpResponse) { final ResponseBody body = okHttpResponse.body(); return new Response(okHttpResponse.code(), okHttpResponse.message(), headersMap, body == null ? null : body.byteStream()); - } + } From a8b06d1d81e68dbd6cfbeaa43f605f7ae253ce92 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 18 May 2018 18:32:47 +0300 Subject: [PATCH 482/882] small changes --- .../com/github/scribejava/apis/examples/AWeberExample.java | 2 +- .../com/github/scribejava/apis/examples/AutomaticExample.java | 2 +- .../com/github/scribejava/apis/examples/Box20Example.java | 2 +- .../github/scribejava/apis/examples/DataportenExample.java | 2 +- .../java/com/github/scribejava/apis/examples/DiggExample.java | 2 +- .../java/com/github/scribejava/apis/examples/EtsyExample.java | 2 +- .../scribejava/apis/examples/FacebookAsyncApacheExample.java | 2 +- .../scribejava/apis/examples/FacebookAsyncNingExample.java | 2 +- .../com/github/scribejava/apis/examples/FacebookExample.java | 2 +- .../com/github/scribejava/apis/examples/FlickrExample.java | 2 +- .../github/scribejava/apis/examples/Foursquare2Example.java | 2 +- .../github/scribejava/apis/examples/FoursquareExample.java | 2 +- .../com/github/scribejava/apis/examples/FrappeExample.java | 2 +- .../github/scribejava/apis/examples/FreelancerExample.java | 2 +- .../com/github/scribejava/apis/examples/GeniusExample.java | 2 +- .../scribejava/apis/examples/GitHubAsyncOkHttpExample.java | 2 +- .../com/github/scribejava/apis/examples/GitHubExample.java | 2 +- .../scribejava/apis/examples/Google20AsyncAHCExample.java | 2 +- .../scribejava/apis/examples/Google20WithPKCEExample.java | 2 +- .../java/com/github/scribejava/apis/examples/HHExample.java | 2 +- .../com/github/scribejava/apis/examples/ImgurExample.java | 2 +- .../com/github/scribejava/apis/examples/Kaixin20Example.java | 2 +- .../github/scribejava/apis/examples/LinkedIn20Example.java | 2 +- .../com/github/scribejava/apis/examples/LinkedInExample.java | 2 +- .../scribejava/apis/examples/LinkedInExampleWithScopes.java | 2 +- .../java/com/github/scribejava/apis/examples/LiveExample.java | 2 +- .../github/scribejava/apis/examples/MailruAsyncExample.java | 2 +- .../com/github/scribejava/apis/examples/MailruExample.java | 2 +- .../com/github/scribejava/apis/examples/MeetupExample.java | 2 +- .../com/github/scribejava/apis/examples/MisfitExample.java | 2 +- .../com/github/scribejava/apis/examples/NaverExample.java | 2 +- .../github/scribejava/apis/examples/NeteaseWeiboExample.java | 2 +- .../github/scribejava/apis/examples/OdnoklassnikiExample.java | 2 +- .../com/github/scribejava/apis/examples/PinterestExample.java | 2 +- .../com/github/scribejava/apis/examples/Px500Example.java | 2 +- .../com/github/scribejava/apis/examples/RenrenExample.java | 2 +- .../github/scribejava/apis/examples/SalesforceExample.java | 2 +- .../scribejava/apis/examples/SalesforceNingAsyncExample.java | 2 +- .../github/scribejava/apis/examples/SinaWeibo2Example.java | 2 +- .../com/github/scribejava/apis/examples/SinaWeiboExample.java | 2 +- .../com/github/scribejava/apis/examples/SkyrockExample.java | 2 +- .../com/github/scribejava/apis/examples/SohuWeiboExample.java | 2 +- .../github/scribejava/apis/examples/StackExchangeExample.java | 2 +- .../apis/examples/TheThingsNetworkV1StagingExample.java | 2 +- .../apis/examples/TheThingsNetworkV2PreviewExample.java | 2 +- .../com/github/scribejava/apis/examples/TrelloExample.java | 2 +- .../com/github/scribejava/apis/examples/TumblrExample.java | 2 +- .../com/github/scribejava/apis/examples/TutByExample.java | 2 +- .../com/github/scribejava/apis/examples/TwitterExample.java | 2 +- .../com/github/scribejava/apis/examples/ViadeoExample.java | 2 +- .../apis/examples/VkontakteClientCredentialsGrantExample.java | 2 +- .../com/github/scribejava/apis/examples/VkontakteExample.java | 2 +- .../java/com/github/scribejava/apis/examples/XingExample.java | 2 +- .../main/java/com/github/scribejava/core/model/Response.java | 4 ++-- 54 files changed, 55 insertions(+), 55 deletions(-) diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AWeberExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AWeberExample.java index ed7c20b96..6a35e469b 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AWeberExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AWeberExample.java @@ -12,7 +12,7 @@ import java.io.IOException; import java.util.concurrent.ExecutionException; -public final class AWeberExample { +public class AWeberExample { //To get your consumer key/secret, and view API docs, see https://labs.aweber.com/docs private static final String ACCOUNT_RESOURCE_URL = "https://api.aweber.com/1.0/accounts/"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AutomaticExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AutomaticExample.java index e1cb6b809..665a5552f 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AutomaticExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AutomaticExample.java @@ -13,7 +13,7 @@ import java.util.Scanner; import java.util.concurrent.ExecutionException; -public final class AutomaticExample { +public class AutomaticExample { private static final String NETWORK_NAME = "Automatic"; private static final String PROTECTED_RESOURCE_URL = "https://api.automatic.com/user/me/"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Box20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Box20Example.java index 062753217..7f82c9222 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Box20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Box20Example.java @@ -14,7 +14,7 @@ import java.util.Map; import java.util.concurrent.ExecutionException; -public final class Box20Example { +public class Box20Example { private static final String NETWORK_NAME = "Box"; private static final String PROTECTED_RESOURCE_URL = "https://api.box.com/2.0/users/me"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DataportenExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DataportenExample.java index f11b4e72c..fc0f4d3e2 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DataportenExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DataportenExample.java @@ -12,7 +12,7 @@ import java.io.IOException; import java.util.concurrent.ExecutionException; -public final class DataportenExample { +public class DataportenExample { private static final String NETWORK_NAME = "Dataporten"; private static final String PROTECTED_RESOURCE_URL = "https://auth.dataporten.no/userinfo"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiggExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiggExample.java index a27dd895c..a1f11b196 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiggExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiggExample.java @@ -12,7 +12,7 @@ import java.io.IOException; import java.util.concurrent.ExecutionException; -public final class DiggExample { +public class DiggExample { private static final String NETWORK_NAME = "Digg"; private static final String PROTECTED_RESOURCE_URL = "http://services.digg.com/2.0/comment.digg"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/EtsyExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/EtsyExample.java index 21800310d..d26adb59a 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/EtsyExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/EtsyExample.java @@ -13,7 +13,7 @@ import java.util.Scanner; import java.util.concurrent.ExecutionException; -public final class EtsyExample { +public class EtsyExample { private static final String PROTECTED_RESOURCE_URL = "https://openapi.etsy.com/v2/users/__SELF__"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncApacheExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncApacheExample.java index e5773f934..bf7c6f2ee 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncApacheExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncApacheExample.java @@ -13,7 +13,7 @@ import com.github.scribejava.httpclient.apache.ApacheHttpClientConfig; import java.io.IOException; -public final class FacebookAsyncApacheExample { +public class FacebookAsyncApacheExample { private static final String NETWORK_NAME = "Facebook"; private static final String PROTECTED_RESOURCE_URL = "https://graph.facebook.com/v2.11/me"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java index d5ea5438c..81d1dd53a 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java @@ -14,7 +14,7 @@ import com.github.scribejava.core.oauth.OAuth20Service; import java.io.IOException; -public final class FacebookAsyncNingExample { +public class FacebookAsyncNingExample { private static final String NETWORK_NAME = "Facebook"; private static final String PROTECTED_RESOURCE_URL = "https://graph.facebook.com/v2.11/me"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java index f7a156ddc..7a0ba726a 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java @@ -12,7 +12,7 @@ import java.io.IOException; import java.util.concurrent.ExecutionException; -public final class FacebookExample { +public class FacebookExample { private static final String NETWORK_NAME = "Facebook"; private static final String PROTECTED_RESOURCE_URL = "https://graph.facebook.com/v2.11/me"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExample.java index 25f858565..66ddf3fd2 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExample.java @@ -13,7 +13,7 @@ import java.util.Scanner; import java.util.concurrent.ExecutionException; -public final class FlickrExample { +public class FlickrExample { private static final String PROTECTED_RESOURCE_URL = "http://api.flickr.com/services/rest/"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java index ad78fe6ae..aae4fe7f8 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java @@ -11,7 +11,7 @@ import java.io.IOException; import java.util.concurrent.ExecutionException; -public final class Foursquare2Example { +public class Foursquare2Example { private static final String PROTECTED_RESOURCE_URL = "https://api.foursquare.com/v2/users/self/friends?oauth_token="; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FoursquareExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FoursquareExample.java index 2eaf4fcae..d9ec56652 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FoursquareExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FoursquareExample.java @@ -12,7 +12,7 @@ import java.io.IOException; import java.util.concurrent.ExecutionException; -public final class FoursquareExample { +public class FoursquareExample { private static final String PROTECTED_RESOURCE_URL = "http://api.foursquare.com/v1/user"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FrappeExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FrappeExample.java index b23792184..ce9012b1c 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FrappeExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FrappeExample.java @@ -11,7 +11,7 @@ import java.io.IOException; import java.util.concurrent.ExecutionException; -public final class FrappeExample { +public class FrappeExample { private static final String NETWORK_NAME = "Frappe"; private static final String PROTECTED_RESOURCE_PATH = "/api/method/frappe.integrations.oauth2.openid_profile"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java index d8a9afa3f..80640d989 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java @@ -12,7 +12,7 @@ import java.io.IOException; import java.util.concurrent.ExecutionException; -public final class FreelancerExample { +public class FreelancerExample { private static final String NETWORK_NAME = "Freelancer"; private static final String AUTHORIZE_URL diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GeniusExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GeniusExample.java index af515b79c..8f269657e 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GeniusExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GeniusExample.java @@ -12,7 +12,7 @@ import java.io.IOException; import java.util.concurrent.ExecutionException; -public final class GeniusExample { +public class GeniusExample { private static final String NETWORK_NAME = "Genius"; private static final String PROTECTED_RESOURCE_URL = "https://api.genius.com/songs/378195"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubAsyncOkHttpExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubAsyncOkHttpExample.java index 57d618db5..bc05042bf 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubAsyncOkHttpExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubAsyncOkHttpExample.java @@ -14,7 +14,7 @@ import java.util.Scanner; import java.util.concurrent.ExecutionException; -public final class GitHubAsyncOkHttpExample { +public class GitHubAsyncOkHttpExample { private static final String NETWORK_NAME = "GitHub"; private static final String PROTECTED_RESOURCE_URL = "https://api.github.com/user"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubExample.java index 3227f8fc9..6d60957a3 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubExample.java @@ -12,7 +12,7 @@ import java.io.IOException; import java.util.concurrent.ExecutionException; -public final class GitHubExample { +public class GitHubExample { private static final String NETWORK_NAME = "GitHub"; private static final String PROTECTED_RESOURCE_URL = "https://api.github.com/user"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java index 54bb06696..d815edce3 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java @@ -17,7 +17,7 @@ import java.util.concurrent.ExecutionException; import org.asynchttpclient.DefaultAsyncHttpClientConfig; -public final class Google20AsyncAHCExample { +public class Google20AsyncAHCExample { private static final String NETWORK_NAME = "G+ Async"; private static final String PROTECTED_RESOURCE_URL = "https://www.googleapis.com/plus/v1/people/me"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20WithPKCEExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20WithPKCEExample.java index eb4594e98..54a359291 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20WithPKCEExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20WithPKCEExample.java @@ -15,7 +15,7 @@ import java.util.Map; import java.util.concurrent.ExecutionException; -public final class Google20WithPKCEExample { +public class Google20WithPKCEExample { private static final String NETWORK_NAME = "G+"; private static final String PROTECTED_RESOURCE_URL = "https://www.googleapis.com/plus/v1/people/me"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HHExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HHExample.java index 9f2c4e560..0c1d24b9b 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HHExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HHExample.java @@ -13,7 +13,7 @@ import java.io.IOException; import java.util.concurrent.ExecutionException; -public final class HHExample { +public class HHExample { private static final String NETWORK_NAME = "hh.ru"; private static final String PROTECTED_RESOURCE_URL = "https://api.hh.ru/me"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ImgurExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ImgurExample.java index fcce7ec81..ddc67c107 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ImgurExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ImgurExample.java @@ -12,7 +12,7 @@ import java.util.Scanner; import java.util.concurrent.ExecutionException; -public final class ImgurExample { +public class ImgurExample { private static final String NETWORK_NAME = "Imgur"; private static final String PROTECTED_RESOURCE_URL = "https://api.imgur.com/3/account/me"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Kaixin20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Kaixin20Example.java index de1e491cd..dad494e49 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Kaixin20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Kaixin20Example.java @@ -11,7 +11,7 @@ import java.io.IOException; import java.util.concurrent.ExecutionException; -public final class Kaixin20Example { +public class Kaixin20Example { private static final String NETWORK_NAME = "Kaixin"; private static final String PROTECTED_RESOURCE_URL = "https://api.kaixin001.com/users/me.json"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedIn20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedIn20Example.java index 9ff9fe0cd..d76acb856 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedIn20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedIn20Example.java @@ -11,7 +11,7 @@ import java.io.IOException; import java.util.concurrent.ExecutionException; -public final class LinkedIn20Example { +public class LinkedIn20Example { private static final String NETWORK_NAME = "LinkedIn"; private static final String PROTECTED_RESOURCE_URL = "https://api.linkedin.com/v1/people/~:(%s)"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java index 7270b6a11..48f9fdcb5 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java @@ -12,7 +12,7 @@ import java.io.IOException; import java.util.concurrent.ExecutionException; -public final class LinkedInExample { +public class LinkedInExample { private static final String PROTECTED_RESOURCE_URL = "http://api.linkedin.com/v1/people/~/connections:(id,last-name)"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java index e94a687a0..f90f91ce0 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java @@ -12,7 +12,7 @@ import java.io.IOException; import java.util.concurrent.ExecutionException; -public final class LinkedInExampleWithScopes { +public class LinkedInExampleWithScopes { private static final String PROTECTED_RESOURCE_URL = "http://api.linkedin.com/v1/people/~/connections:(id,last-name)"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java index 1dc9c26df..119c5aca1 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java @@ -11,7 +11,7 @@ import java.io.IOException; import java.util.concurrent.ExecutionException; -public final class LiveExample { +public class LiveExample { private static final String PROTECTED_RESOURCE_URL = "https://apis.live.net/v5.0/me"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java index 9814bcfbe..95673747d 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java @@ -13,7 +13,7 @@ import com.github.scribejava.core.oauth.OAuth20Service; import java.io.IOException; -public final class MailruAsyncExample { +public class MailruAsyncExample { private static final String NETWORK_NAME = "Mail.ru"; private static final String PROTECTED_RESOURCE_URL diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java index 01ff29cd9..372bedd1a 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java @@ -11,7 +11,7 @@ import java.io.IOException; import java.util.concurrent.ExecutionException; -public final class MailruExample { +public class MailruExample { private static final String NETWORK_NAME = "Mail.ru"; private static final String PROTECTED_RESOURCE_URL diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java index dc182ae05..ff97a734a 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java @@ -12,7 +12,7 @@ import java.io.IOException; import java.util.concurrent.ExecutionException; -public final class MeetupExample { +public class MeetupExample { private static final String PROTECTED_RESOURCE_URL = "http://api.meetup.com/2/member/self"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MisfitExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MisfitExample.java index 057099500..60d5a903c 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MisfitExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MisfitExample.java @@ -12,7 +12,7 @@ import java.util.Scanner; import java.util.concurrent.ExecutionException; -public final class MisfitExample { +public class MisfitExample { private static final String NETWORK_NAME = "Misfit"; private static final String PROTECTED_RESOURCE_URL diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NaverExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NaverExample.java index 33e647f5c..bf359c547 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NaverExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NaverExample.java @@ -13,7 +13,7 @@ import java.util.Scanner; import java.util.concurrent.ExecutionException; -public final class NaverExample { +public class NaverExample { private static final String NETWORK_NAME = "Naver"; private static final String PROTECTED_RESOURCE_URL = "https://openapi.naver.com/v1/nid/me"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NeteaseWeiboExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NeteaseWeiboExample.java index 324b8709c..e56a05a0c 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NeteaseWeiboExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NeteaseWeiboExample.java @@ -12,7 +12,7 @@ import java.io.IOException; import java.util.concurrent.ExecutionException; -public final class NeteaseWeiboExample { +public class NeteaseWeiboExample { private static final String NETWORK_NAME = "NetEase(163.com) Weibo"; private static final String PROTECTED_RESOURCE_URL = "http://api.t.163.com/account/verify_credentials.json"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java index ee7b46549..4ff6a4933 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java @@ -11,7 +11,7 @@ import java.io.IOException; import java.util.concurrent.ExecutionException; -public final class OdnoklassnikiExample { +public class OdnoklassnikiExample { private static final String NETWORK_NAME = "Odnoklassniki.ru"; private static final String PROTECTED_RESOURCE_URL diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java index 6d25b80a2..03b3a428a 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java @@ -12,7 +12,7 @@ import java.util.Scanner; import java.util.concurrent.ExecutionException; -public final class PinterestExample { +public class PinterestExample { private static final String PROTECTED_RESOURCE_URL = "https://api.pinterest.com/v1/me/"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Px500Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Px500Example.java index 35fba3e8d..962faaa3d 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Px500Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Px500Example.java @@ -12,7 +12,7 @@ import java.io.IOException; import java.util.concurrent.ExecutionException; -public final class Px500Example { +public class Px500Example { private static final String PROTECTED_RESOURCE_URL = "https://api.500px.com/v1/"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java index 1f0ff3908..4d9b3bd76 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java @@ -21,7 +21,7 @@ import java.util.List; import java.util.concurrent.ExecutionException; -public final class RenrenExample { +public class RenrenExample { private static final String NETWORK_NAME = "Renren"; private static final String PROTECTED_RESOURCE_URL = "http://api.renren.com/restserver.do"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceExample.java index 39cbbc2fe..7d4aa6b10 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceExample.java @@ -17,7 +17,7 @@ import java.security.NoSuchAlgorithmException; import java.util.concurrent.ExecutionException; -public final class SalesforceExample { +public class SalesforceExample { private static final String NETWORK_NAME = "Salesforce"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceNingAsyncExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceNingAsyncExample.java index 19e530de1..f5a524026 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceNingAsyncExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceNingAsyncExample.java @@ -20,7 +20,7 @@ import java.security.KeyManagementException; import java.security.NoSuchAlgorithmException; -public final class SalesforceNingAsyncExample { +public class SalesforceNingAsyncExample { private static final String NETWORK_NAME = "Salesforce"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeibo2Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeibo2Example.java index 9233e1b32..d4ff865de 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeibo2Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeibo2Example.java @@ -11,7 +11,7 @@ import java.io.IOException; import java.util.concurrent.ExecutionException; -public final class SinaWeibo2Example { +public class SinaWeibo2Example { private static final String NETWORK_NAME = "SinaWeibo"; private static final String PROTECTED_RESOURCE_URL = "https://api.weibo.com/2/account/get_uid.json"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeiboExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeiboExample.java index e8622952c..618e8c881 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeiboExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeiboExample.java @@ -12,7 +12,7 @@ import java.io.IOException; import java.util.concurrent.ExecutionException; -public final class SinaWeiboExample { +public class SinaWeiboExample { private static final String NETWORK_NAME = "SinaWeibo"; private static final String PROTECTED_RESOURCE_URL = "http://api.t.sina.com.cn/account/verify_credentials.json"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SkyrockExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SkyrockExample.java index 07c010961..5751538ef 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SkyrockExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SkyrockExample.java @@ -12,7 +12,7 @@ import java.io.IOException; import java.util.concurrent.ExecutionException; -public final class SkyrockExample { +public class SkyrockExample { private static final String PROTECTED_RESOURCE_URL = "https://api.skyrock.com/v2/user/get.json"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SohuWeiboExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SohuWeiboExample.java index 2ae6d3ffd..690efa9a8 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SohuWeiboExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SohuWeiboExample.java @@ -12,7 +12,7 @@ import java.io.IOException; import java.util.concurrent.ExecutionException; -public final class SohuWeiboExample { +public class SohuWeiboExample { private static final String NETWORK_NAME = "SohuWeibo"; private static final String PROTECTED_RESOURCE_URL = "http://api.t.sohu.com/account/verify_credentials.json"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/StackExchangeExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/StackExchangeExample.java index b9e699b5b..39350cd14 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/StackExchangeExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/StackExchangeExample.java @@ -13,7 +13,7 @@ import java.io.IOException; import java.util.concurrent.ExecutionException; -public final class StackExchangeExample { +public class StackExchangeExample { private static final String NETWORK_NAME = "Stack Exchange"; private static final String PROTECTED_RESOURCE_URL = "https://api.stackexchange.com/2.2/me"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV1StagingExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV1StagingExample.java index 08279d535..427b83f2c 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV1StagingExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV1StagingExample.java @@ -14,7 +14,7 @@ import java.util.Scanner; import java.util.concurrent.ExecutionException; -public final class TheThingsNetworkV1StagingExample { +public class TheThingsNetworkV1StagingExample { private static final String NETWORK_NAME = "TTNv1staging"; private static final String PROTECTED_RESOURCE_URL = "https://account.thethingsnetwork.org/applications"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV2PreviewExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV2PreviewExample.java index 08c7eb888..19cc96331 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV2PreviewExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV2PreviewExample.java @@ -13,7 +13,7 @@ import java.util.Scanner; import java.util.concurrent.ExecutionException; -public final class TheThingsNetworkV2PreviewExample { +public class TheThingsNetworkV2PreviewExample { private static final String NETWORK_NAME = "TTNv2preview"; private static final String PROTECTED_RESOURCE_URL = diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TrelloExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TrelloExample.java index 62281a62f..a73826a34 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TrelloExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TrelloExample.java @@ -12,7 +12,7 @@ import java.io.IOException; import java.util.concurrent.ExecutionException; -public final class TrelloExample { +public class TrelloExample { private static final String API_KEY = "your_api_key"; private static final String API_SECRET = "your_api_secret"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TumblrExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TumblrExample.java index f202a4540..6d16ef54f 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TumblrExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TumblrExample.java @@ -12,7 +12,7 @@ import java.io.IOException; import java.util.concurrent.ExecutionException; -public final class TumblrExample { +public class TumblrExample { private static final String PROTECTED_RESOURCE_URL = "http://api.tumblr.com/v2/user/info"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TutByExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TutByExample.java index 5ce2d2e2c..70f05e5b2 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TutByExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TutByExample.java @@ -13,7 +13,7 @@ import java.io.IOException; import java.util.concurrent.ExecutionException; -public final class TutByExample { +public class TutByExample { private static final String NETWORK_NAME = "Tut.by"; private static final String PROTECTED_RESOURCE_URL = "http://profile.tut.by/getInfo"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TwitterExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TwitterExample.java index 24af2acc8..20b95531d 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TwitterExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TwitterExample.java @@ -12,7 +12,7 @@ import java.io.IOException; import java.util.concurrent.ExecutionException; -public final class TwitterExample { +public class TwitterExample { private static final String PROTECTED_RESOURCE_URL = "https://api.twitter.com/1.1/account/verify_credentials.json"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ViadeoExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ViadeoExample.java index 6e59af8db..134faf3cc 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ViadeoExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ViadeoExample.java @@ -11,7 +11,7 @@ import java.io.IOException; import java.util.concurrent.ExecutionException; -public final class ViadeoExample { +public class ViadeoExample { private static final String NETWORK_NAME = "Viadeo"; private static final String PROTECTED_RESOURCE_URL = "https://api.viadeo.com/me?user_detail=full"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteClientCredentialsGrantExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteClientCredentialsGrantExample.java index 0ffc2fc13..ed2fd0fba 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteClientCredentialsGrantExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteClientCredentialsGrantExample.java @@ -7,7 +7,7 @@ import java.io.IOException; import java.util.concurrent.ExecutionException; -public final class VkontakteClientCredentialsGrantExample { +public class VkontakteClientCredentialsGrantExample { private static final String NETWORK_NAME = "Vkontakte.ru"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExample.java index 5c18980b2..bbab9db62 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExample.java @@ -12,7 +12,7 @@ import java.io.IOException; import java.util.concurrent.ExecutionException; -public final class VkontakteExample { +public class VkontakteExample { private static final String NETWORK_NAME = "Vkontakte.ru"; private static final String PROTECTED_RESOURCE_URL = "https://api.vk.com/method/users.get?v=" diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XingExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XingExample.java index 09ee75878..5cfd1d89d 100755 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XingExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XingExample.java @@ -12,7 +12,7 @@ import java.io.IOException; import java.util.concurrent.ExecutionException; -public final class XingExample { +public class XingExample { private static final String PROTECTED_RESOURCE_URL = "https://api.xing.com/v1/users/me"; diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/Response.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/Response.java index 8a4807677..4a84c76ef 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/Response.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/Response.java @@ -41,7 +41,7 @@ private String parseBodyContents() throws IOException { return body; } - public final boolean isSuccessful() { + public boolean isSuccessful() { return code >= 200 && code < 400; } @@ -64,7 +64,7 @@ public InputStream getStream() { * * @return the status code */ - public final int getCode() { + public int getCode() { return code; } From 0084b13bdd5c396a6210a4536d75cd0c1bbd1d95 Mon Sep 17 00:00:00 2001 From: Dan Manastireanu Date: Wed, 16 May 2018 17:14:37 +0300 Subject: [PATCH 483/882] Fix Fitbit token error extraction --- .../apis/fitbit/FitBitJsonTokenExtractor.java | 23 ++++++- .../fitbit/FitBitJsonTokenExtractorTest.java | 62 +++++++++++++++++++ 2 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractorTest.java diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractor.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractor.java index affed2f6d..9cc8f1167 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractor.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractor.java @@ -1,12 +1,16 @@ package com.github.scribejava.apis.fitbit; import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; +import com.github.scribejava.core.model.OAuth2AccessTokenErrorResponse; + +import java.net.URI; import java.util.regex.Pattern; public class FitBitJsonTokenExtractor extends OAuth2AccessTokenJsonExtractor { private static final Pattern USER_ID_REGEX_PATTERN = Pattern.compile("\"user_id\"\\s*:\\s*\"(\\S*?)\""); - + private static final Pattern ERROR_REGEX_PATTERN = Pattern.compile("\"errorType\"\\s*:\\s*\"(\\S*?)\""); + private static final Pattern ERROR_DESCRIPTION_REGEX_PATTERN = Pattern.compile("\"message\"\\s*:\\s*\"([^\"]*?)\""); protected FitBitJsonTokenExtractor() { } @@ -25,4 +29,21 @@ protected FitBitOAuth2AccessToken createToken(String accessToken, String tokenTy return new FitBitOAuth2AccessToken(accessToken, tokenType, expiresIn, refreshToken, scope, extractParameter(response, USER_ID_REGEX_PATTERN, false), response); } + + @Override + public void generateError(String response) { + final String errorInString = extractParameter(response, ERROR_REGEX_PATTERN, true); + final String errorDescription = extractParameter(response, ERROR_DESCRIPTION_REGEX_PATTERN, false); + final URI errorUri = URI.create("https://dev.fitbit.com/build/reference/web-api/oauth2/"); + + OAuth2AccessTokenErrorResponse.ErrorCode errorCode; + try { + errorCode = OAuth2AccessTokenErrorResponse.ErrorCode.valueOf(errorInString); + } catch (IllegalArgumentException iaE) { + //non oauth standard error code + errorCode = null; + } + + throw new OAuth2AccessTokenErrorResponse(errorCode, errorDescription, errorUri, response); + } } diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractorTest.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractorTest.java new file mode 100644 index 000000000..49b94d46e --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractorTest.java @@ -0,0 +1,62 @@ +package com.github.scribejava.apis.fitbit; + +import com.github.scribejava.core.model.OAuth2AccessTokenErrorResponse; +import com.github.scribejava.core.model.OAuth2AccessTokenErrorResponse.ErrorCode; + +import org.hamcrest.FeatureMatcher; +import org.hamcrest.Matcher; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; + +import static org.hamcrest.CoreMatchers.equalTo; + +public class FitBitJsonTokenExtractorTest { + + private static final String ERROR_DESCRIPTION = "Authorization code invalid: " + + "cbb1c11b23209011e89be71201fa6381464dc0af " + + "Visit https://dev.fitbit.com/docs/oauth2 for more information " + + "on the Fitbit Web API authorization process."; + private static final String ERROR_JSON = "{\"errors\":[{\"errorType\":\"invalid_grant\",\"message\":\"" + + ERROR_DESCRIPTION + "\"}],\"success\":false}"; + + @Rule + public ExpectedException thrown = ExpectedException.none(); + + @Test + public void testErrorExtraction() { + + final FitBitJsonTokenExtractor extractor = new FitBitJsonTokenExtractor(); + + thrown.expect(OAuth2AccessTokenErrorResponse.class); + thrown.expect(errorCode(ErrorCode.invalid_grant)); + thrown.expect(errorDescription(ERROR_DESCRIPTION)); + + extractor.generateError(ERROR_JSON); + + } + + private Matcher errorCode(ErrorCode expected) { + return new FeatureMatcher( + equalTo(expected), + "a response with errorCode", + "errorCode") { + @Override + protected ErrorCode featureValueOf(OAuth2AccessTokenErrorResponse actual) { + return actual.getErrorCode(); + } + }; + } + + private Matcher errorDescription(String expected) { + return new FeatureMatcher( + equalTo(expected), + "a response with errorDescription", + "errorDescription") { + @Override + protected String featureValueOf(OAuth2AccessTokenErrorResponse actual) { + return actual.getErrorDescription(); + } + }; + } +} From e719d25d40d3ddf3fbc64a3c241261eabb04bd9b Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 18 May 2018 18:58:20 +0300 Subject: [PATCH 484/882] fix error parsing for Fitbit (thanks to https://github.com/danmana) --- changelog | 3 ++ .../apis/fitbit/FitBitJsonTokenExtractor.java | 7 +-- .../apis/examples/FitbitApi20Example.java | 2 +- .../fitbit/FitBitJsonTokenExtractorTest.java | 46 +++++++++---------- 4 files changed, 30 insertions(+), 28 deletions(-) diff --git a/changelog b/changelog index cc865a4ed..b68d3d070 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,6 @@ +[SNAPSHOT] + * fix error parsing for Fitbit (thanks to https://github.com/danmana) + [5.4.0] * fix missing support for scope for refresh_token grant_type (thanks to https://github.com/tlxtellef) * add email field to VKOAuth2AccessToken (thanks to https://github.com/grouzen) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractor.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractor.java index 9cc8f1167..fad86fc53 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractor.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractor.java @@ -3,7 +3,6 @@ import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; import com.github.scribejava.core.model.OAuth2AccessTokenErrorResponse; -import java.net.URI; import java.util.regex.Pattern; public class FitBitJsonTokenExtractor extends OAuth2AccessTokenJsonExtractor { @@ -30,11 +29,13 @@ protected FitBitOAuth2AccessToken createToken(String accessToken, String tokenTy extractParameter(response, USER_ID_REGEX_PATTERN, false), response); } + /** + * Related documentation: https://dev.fitbit.com/build/reference/web-api/oauth2/ + */ @Override public void generateError(String response) { final String errorInString = extractParameter(response, ERROR_REGEX_PATTERN, true); final String errorDescription = extractParameter(response, ERROR_DESCRIPTION_REGEX_PATTERN, false); - final URI errorUri = URI.create("https://dev.fitbit.com/build/reference/web-api/oauth2/"); OAuth2AccessTokenErrorResponse.ErrorCode errorCode; try { @@ -44,6 +45,6 @@ public void generateError(String response) { errorCode = null; } - throw new OAuth2AccessTokenErrorResponse(errorCode, errorDescription, errorUri, response); + throw new OAuth2AccessTokenErrorResponse(errorCode, errorDescription, null, response); } } diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FitbitApi20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FitbitApi20Example.java index 72750de6b..9c17e9054 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FitbitApi20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FitbitApi20Example.java @@ -58,7 +58,7 @@ public static void main(String... args) throws Exception { if (!(oauth2AccessToken instanceof FitBitOAuth2AccessToken)) { System.out.println("oauth2AccessToken is not instance of FitBitOAuth2AccessToken. Strange enough. exit."); - System.exit(0); + return; } final FitBitOAuth2AccessToken accessToken = (FitBitOAuth2AccessToken) oauth2AccessToken; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractorTest.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractorTest.java index 49b94d46e..a0f5b53a3 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractorTest.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractorTest.java @@ -4,7 +4,6 @@ import com.github.scribejava.core.model.OAuth2AccessTokenErrorResponse.ErrorCode; import org.hamcrest.FeatureMatcher; -import org.hamcrest.Matcher; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; @@ -29,34 +28,33 @@ public void testErrorExtraction() { final FitBitJsonTokenExtractor extractor = new FitBitJsonTokenExtractor(); thrown.expect(OAuth2AccessTokenErrorResponse.class); - thrown.expect(errorCode(ErrorCode.invalid_grant)); - thrown.expect(errorDescription(ERROR_DESCRIPTION)); + thrown.expect(new ErrorCodeFeatureMatcher(ErrorCode.invalid_grant)); + thrown.expect(new ErrorDescriptionFeatureMatcher(ERROR_DESCRIPTION)); extractor.generateError(ERROR_JSON); - } - private Matcher errorCode(ErrorCode expected) { - return new FeatureMatcher( - equalTo(expected), - "a response with errorCode", - "errorCode") { - @Override - protected ErrorCode featureValueOf(OAuth2AccessTokenErrorResponse actual) { - return actual.getErrorCode(); - } - }; + private static class ErrorCodeFeatureMatcher extends FeatureMatcher { + + private ErrorCodeFeatureMatcher(ErrorCode expected) { + super(equalTo(expected), "a response with errorCode", "errorCode"); + } + + @Override + protected ErrorCode featureValueOf(OAuth2AccessTokenErrorResponse actual) { + return actual.getErrorCode(); + } } - private Matcher errorDescription(String expected) { - return new FeatureMatcher( - equalTo(expected), - "a response with errorDescription", - "errorDescription") { - @Override - protected String featureValueOf(OAuth2AccessTokenErrorResponse actual) { - return actual.getErrorDescription(); - } - }; + private static class ErrorDescriptionFeatureMatcher extends FeatureMatcher { + + private ErrorDescriptionFeatureMatcher(String expected) { + super(equalTo(expected), "a response with errorDescription", "errorDescription"); + } + + @Override + protected String featureValueOf(OAuth2AccessTokenErrorResponse actual) { + return actual.getErrorDescription(); + } } } From ae143539daa079cac123e8c69a2fdc237fa77e14 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 18 May 2018 19:40:29 +0300 Subject: [PATCH 485/882] optimize debug log performance impact on prod in OAuth1 and fix NoClassDefFoundError on Android device with SDK 18 and lower (thanks to https://github.com/arcao) --- changelog | 2 + .../core/oauth/OAuth10aService.java | 37 +++++++++---------- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/changelog b/changelog index b68d3d070..3599d3d18 100644 --- a/changelog +++ b/changelog @@ -1,5 +1,7 @@ [SNAPSHOT] * fix error parsing for Fitbit (thanks to https://github.com/danmana) + * optimize debug log performance impact on prod in OAuth1 and fix + NoClassDefFoundError on Android device with SDK 18 and lower (thanks to https://github.com/arcao) [5.4.0] * fix missing support for scope for refresh_token grant_type (thanks to https://github.com/tlxtellef) diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java index bf708395e..3986f45d5 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java @@ -45,15 +45,15 @@ public OAuth10aService(DefaultApi10a api, String apiKey, String apiSecret, Strin } public OAuth1RequestToken getRequestToken() throws IOException, InterruptedException, ExecutionException { - log("obtaining request token from " + api.getRequestTokenEndpoint()); + log("obtaining request token from %s", api.getRequestTokenEndpoint()); final OAuthRequest request = prepareRequestTokenRequest(); log("sending request..."); final Response response = execute(request); final String body = response.getBody(); - log("response status code: " + response.getCode()); - log("response body: " + body); + log("response status code: %s", response.getCode()); + log("response body: %s", body); return api.getRequestTokenExtractor().extract(response); } @@ -62,7 +62,7 @@ public Future getRequestTokenAsync() { } public Future getRequestTokenAsync(OAuthAsyncRequestCallback callback) { - log("async obtaining request token from " + api.getRequestTokenEndpoint()); + log("async obtaining request token from %s", api.getRequestTokenEndpoint()); final OAuthRequest request = prepareRequestTokenRequest(); return execute(request, callback, new OAuthRequest.ResponseConverter() { @Override @@ -78,7 +78,7 @@ protected OAuthRequest prepareRequestTokenRequest() { if (callback == null) { callback = OAuthConstants.OOB; } - log("setting oauth_callback to " + callback); + log("setting oauth_callback to %s", callback); request.addOAuthParameter(OAuthConstants.CALLBACK, callback); addOAuthParams(request, ""); appendSignature(request); @@ -97,12 +97,12 @@ protected void addOAuthParams(OAuthRequest request, String tokenSecret) { } request.addOAuthParameter(OAuthConstants.SIGNATURE, getSignature(request, tokenSecret)); - log("appended additional OAuth parameters: " + request.getOauthParameters()); + log("appended additional OAuth parameters: %s", request.getOauthParameters()); } public OAuth1AccessToken getAccessToken(OAuth1RequestToken requestToken, String oauthVerifier) throws IOException, InterruptedException, ExecutionException { - log("obtaining access token from " + api.getAccessTokenEndpoint()); + log("obtaining access token from %s", api.getAccessTokenEndpoint()); final OAuthRequest request = prepareAccessTokenRequest(requestToken, oauthVerifier); final Response response = execute(request); return api.getAccessTokenExtractor().extract(response); @@ -113,8 +113,8 @@ public Future getAccessTokenAsync(OAuth1RequestToken requestT } /** - * Start the request to retrieve the access token. The optionally provided - * callback will be called with the Token when it is available. + * Start the request to retrieve the access token. The optionally provided callback will be called with the Token + * when it is available. * * @param requestToken request token (obtained previously or null) * @param oauthVerifier oauth_verifier @@ -123,7 +123,7 @@ public Future getAccessTokenAsync(OAuth1RequestToken requestT */ public Future getAccessTokenAsync(OAuth1RequestToken requestToken, String oauthVerifier, OAuthAsyncRequestCallback callback) { - log("async obtaining access token from " + api.getAccessTokenEndpoint()); + log("async obtaining access token from %s", api.getAccessTokenEndpoint()); final OAuthRequest request = prepareAccessTokenRequest(requestToken, oauthVerifier); return execute(request, callback, new OAuthRequest.ResponseConverter() { @Override @@ -137,19 +137,19 @@ protected OAuthRequest prepareAccessTokenRequest(OAuth1RequestToken requestToken final OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint()); request.addOAuthParameter(OAuthConstants.TOKEN, requestToken.getToken()); request.addOAuthParameter(OAuthConstants.VERIFIER, oauthVerifier); - log("setting token to: " + requestToken + " and verifier to: " + oauthVerifier); + log("setting token to: %s and verifier to: %s", requestToken, oauthVerifier); addOAuthParams(request, requestToken.getTokenSecret()); appendSignature(request); return request; } public void signRequest(OAuth1AccessToken token, OAuthRequest request) { - log("signing request: " + request.getCompleteUrl()); + log("signing request: %s", request.getCompleteUrl()); if (!token.isEmpty() || api.isEmptyOAuthTokenParamIsRequired()) { request.addOAuthParameter(OAuthConstants.TOKEN, token.getToken()); } - log("setting token to: " + token); + log("setting token to: %s", token); addOAuthParams(request, token.getTokenSecret()); appendSignature(request); } @@ -160,8 +160,7 @@ public String getVersion() { } /** - * Returns the URL where you should redirect your users to authenticate your - * application. + * Returns the URL where you should redirect your users to authenticate your application. * * @param requestToken the request token you need to authorize * @return the URL where you should redirect your users @@ -175,8 +174,8 @@ private String getSignature(OAuthRequest request, String tokenSecret) { final String baseString = api.getBaseStringExtractor().extract(request); final String signature = api.getSignatureService().getSignature(baseString, getApiSecret(), tokenSecret); - log("base string is: " + baseString); - log("signature is: " + signature); + log("base string is: %s", baseString); + log("signature is: %s", signature); return signature; } @@ -205,9 +204,9 @@ public DefaultApi10a getApi() { return api; } - public void log(String message) { + public void log(String messagePattern, Object... params) { if (debugStream != null) { - message += '\n'; + final String message = String.format(messagePattern, params) + '\n'; try { debugStream.write(message.getBytes("UTF8")); } catch (IOException | RuntimeException e) { From 60d37feead4a652c59f1a8a9bb2499cbf3c98881 Mon Sep 17 00:00:00 2001 From: Lucas Werkmeister Date: Thu, 17 May 2018 23:01:50 +0200 Subject: [PATCH 486/882] Add MediaWiki API MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This API can be used for any MediaWiki installation that has the OAuth extension [1] installed. Two default instances are provided for convenience: one for wikis hosted by the Wikimedia Foundation (including Wikipedia), which is the one most users will be interested in, and one for the Wikimedia Foundation’s Beta Cluster, which is more appropriate for testing purposes. The example is copied and slightly adapted from AWeberExample.java. [1]: https://www.mediawiki.org/wiki/Extension:OAuth --- README.md | 1 + .../github/scribejava/apis/MediaWikiApi.java | 70 +++++++++++++++++++ .../apis/examples/MediaWikiExample.java | 70 +++++++++++++++++++ 3 files changed, 141 insertions(+) create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/MediaWikiApi.java create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MediaWikiExample.java diff --git a/README.md b/README.md index 7227ce97d..554c8e1fc 100644 --- a/README.md +++ b/README.md @@ -63,6 +63,7 @@ ScribeJava support out-of-box several HTTP clients: * Microsoft Azure Active Directory (Azure AD) (http://azure.microsoft.com/) * Microsoft Live (https://login.live.com/) * Mail.Ru (https://mail.ru/) +* MediaWiki (https://www.mediawiki.org/) * Meetup (http://www.meetup.com/) * NAVER (http://www.naver.com/) * NetEase (http://www.163.com/) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/MediaWikiApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/MediaWikiApi.java new file mode 100644 index 000000000..de86d4407 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/MediaWikiApi.java @@ -0,0 +1,70 @@ +package com.github.scribejava.apis; + +import com.github.scribejava.core.builder.api.DefaultApi10a; + +public class MediaWikiApi extends DefaultApi10a { + + private static final MediaWikiApi WIKIMEDIA_INSTANCE = new MediaWikiApi( + "https://meta.wikimedia.org/w/index.php", + "https://meta.wikimedia.org/wiki/" + ); + + private static final MediaWikiApi WIKIMEDIA_BETA_INSTANCE = new MediaWikiApi( + "https://meta.wikimedia.beta.wmflabs.org/w/index.php", + "https://meta.wikimedia.beta.wmflabs.org/wiki/" + ); + + private final String indexUrl; + private final String niceUrlBase; + + /** + * @param indexUrl The URL to the index.php of the wiki. + * Due to a MediaWiki bug, + * some requests must currently use the non-nice URL. + * @param niceUrlBase The base of nice URLs for the wiki, including the trailing slash. + * Due to another MediaWiki bug, + * some requests must currently use the nice URL. + */ + public MediaWikiApi(final String indexUrl, final String niceUrlBase) { + this.indexUrl = indexUrl; + this.niceUrlBase = niceUrlBase; + } + + /** + * The instance for wikis hosted by the Wikimedia Foundation. + * Consumers are requested on + * + * Special:OAuthConsumerRegistration/propose + * . + */ + public static MediaWikiApi wikimediaInstance() { + return WIKIMEDIA_INSTANCE; + } + + /** + * The instance for wikis in the Wikimedia Foundation’s Beta Cluster. + * Consumers are requested on + * + * Special:OAuthConsumerRegistration/propose + * . + */ + public static MediaWikiApi wikimediaBetaInstance() { + return WIKIMEDIA_BETA_INSTANCE; + } + + @Override + public String getRequestTokenEndpoint() { + return indexUrl + "?title=Special:OAuth/initiate"; + } + + @Override + public String getAuthorizationBaseUrl() { + return niceUrlBase + "Special:OAuth/authorize"; + } + + @Override + public String getAccessTokenEndpoint() { + return indexUrl + "?title=Special:OAuth/token"; + } + +} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MediaWikiExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MediaWikiExample.java new file mode 100644 index 000000000..6d1ca6e17 --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MediaWikiExample.java @@ -0,0 +1,70 @@ +package com.github.scribejava.apis.examples; + +import java.util.Scanner; +import com.github.scribejava.core.builder.ServiceBuilder; +import com.github.scribejava.apis.MediaWikiApi; +import com.github.scribejava.core.model.OAuth1AccessToken; +import com.github.scribejava.core.model.OAuth1RequestToken; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.oauth.OAuth10aService; +import java.io.IOException; +import java.util.concurrent.ExecutionException; + +public final class MediaWikiExample { + + // To get your consumer key/secret, see https://meta.wikimedia.org/wiki/Special:OAuthConsumerRegistration/propose + private static final String CONSUMER_KEY = ""; + private static final String CONSUMER_SECRET = ""; + + private static final String API_USERINFO_URL = + "https://meta.wikimedia.org/w/api.php?action=query&format=json&meta=userinfo"; + + private MediaWikiExample() { + } + + public static void main(String... args) throws IOException, InterruptedException, ExecutionException { + final OAuth10aService service = new ServiceBuilder(CONSUMER_KEY) + .apiSecret(CONSUMER_SECRET) + .build(MediaWikiApi.wikimediaInstance()); + + final Scanner in = new Scanner(System.in); + + System.out.println("=== MediaWiki's OAuth Workflow ==="); + System.out.println(); + + // Obtain the Request Token + System.out.println("Fetching the Request Token..."); + final OAuth1RequestToken requestToken = service.getRequestToken(); + System.out.println("Got the Request Token!"); + System.out.println(); + + System.out.println("Now go and authorize ScribeJava here:"); + System.out.println(service.getAuthorizationUrl(requestToken)); + System.out.println("And paste the verifier here"); + System.out.print(">>"); + final String oauthVerifier = in.nextLine(); + System.out.println(); + + // Trade the Request Token and Verfier for the Access Token + System.out.println("Trading the Request Token for an Access Token..."); + final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); + System.out.println("Got the Access Token!"); + System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); + System.out.println(); + + // Now let's go and ask for a protected resource! + System.out.println("Now we're going to access a protected resource..."); + final OAuthRequest request = new OAuthRequest(Verb.GET, API_USERINFO_URL); + service.signRequest(accessToken, request); + final Response response = service.execute(request); + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getBody()); + + System.out.println(); + System.out.println("Thats it man! Go and build something awesome with MediaWiki and ScribeJava! :)"); + } + +} From 68c014982490f6a08dc27569fb7dbe3a914b87b9 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 23 May 2018 12:07:27 +0300 Subject: [PATCH 487/882] add new API - MediaWiki (https://www.mediawiki.org/) (thanks to https://github.com/lucaswerkmeister) --- changelog | 1 + .../github/scribejava/apis/MediaWikiApi.java | 49 ++++++++++--------- .../apis/examples/MediaWikiExample.java | 8 +-- 3 files changed, 31 insertions(+), 27 deletions(-) diff --git a/changelog b/changelog index 3599d3d18..6b3c5a577 100644 --- a/changelog +++ b/changelog @@ -2,6 +2,7 @@ * fix error parsing for Fitbit (thanks to https://github.com/danmana) * optimize debug log performance impact on prod in OAuth1 and fix NoClassDefFoundError on Android device with SDK 18 and lower (thanks to https://github.com/arcao) + * add new API - MediaWiki (https://www.mediawiki.org/) (thanks to https://github.com/lucaswerkmeister) [5.4.0] * fix missing support for scope for refresh_token grant_type (thanks to https://github.com/tlxtellef) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/MediaWikiApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/MediaWikiApi.java index de86d4407..8426d1924 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/MediaWikiApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/MediaWikiApi.java @@ -4,52 +4,55 @@ public class MediaWikiApi extends DefaultApi10a { - private static final MediaWikiApi WIKIMEDIA_INSTANCE = new MediaWikiApi( - "https://meta.wikimedia.org/w/index.php", - "https://meta.wikimedia.org/wiki/" - ); + private static class InstanceHolder { - private static final MediaWikiApi WIKIMEDIA_BETA_INSTANCE = new MediaWikiApi( - "https://meta.wikimedia.beta.wmflabs.org/w/index.php", - "https://meta.wikimedia.beta.wmflabs.org/wiki/" - ); + private static final MediaWikiApi INSTANCE = new MediaWikiApi( + "https://meta.wikimedia.org/w/index.php", + "https://meta.wikimedia.org/wiki/" + ); + } + + private static class BetaInstanceHolder { + + private static final MediaWikiApi BETA_INSTANCE = new MediaWikiApi( + "https://meta.wikimedia.beta.wmflabs.org/w/index.php", + "https://meta.wikimedia.beta.wmflabs.org/wiki/" + ); + } private final String indexUrl; private final String niceUrlBase; /** - * @param indexUrl The URL to the index.php of the wiki. - * Due to a MediaWiki bug, - * some requests must currently use the non-nice URL. - * @param niceUrlBase The base of nice URLs for the wiki, including the trailing slash. - * Due to another MediaWiki bug, - * some requests must currently use the nice URL. + * @param indexUrl The URL to the index.php of the wiki. Due to a + * MediaWiki bug, some requests must currently use the non-nice URL. + * @param niceUrlBase The base of nice URLs for the wiki, including the trailing slash. Due to + * another MediaWiki bug, some requests must currently use + * the nice URL. */ - public MediaWikiApi(final String indexUrl, final String niceUrlBase) { + public MediaWikiApi(String indexUrl, String niceUrlBase) { this.indexUrl = indexUrl; this.niceUrlBase = niceUrlBase; } /** - * The instance for wikis hosted by the Wikimedia Foundation. - * Consumers are requested on + * The instance for wikis hosted by the Wikimedia Foundation. Consumers are requested on * * Special:OAuthConsumerRegistration/propose * . */ - public static MediaWikiApi wikimediaInstance() { - return WIKIMEDIA_INSTANCE; + public static MediaWikiApi instance() { + return InstanceHolder.INSTANCE; } /** - * The instance for wikis in the Wikimedia Foundation’s Beta Cluster. - * Consumers are requested on + * The instance for wikis in the Wikimedia Foundation’s Beta Cluster. Consumers are requested on * * Special:OAuthConsumerRegistration/propose * . */ - public static MediaWikiApi wikimediaBetaInstance() { - return WIKIMEDIA_BETA_INSTANCE; + public static MediaWikiApi instanceBeta() { + return BetaInstanceHolder.BETA_INSTANCE; } @Override diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MediaWikiExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MediaWikiExample.java index 6d1ca6e17..6ec9e5b67 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MediaWikiExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MediaWikiExample.java @@ -12,14 +12,14 @@ import java.io.IOException; import java.util.concurrent.ExecutionException; -public final class MediaWikiExample { +public class MediaWikiExample { // To get your consumer key/secret, see https://meta.wikimedia.org/wiki/Special:OAuthConsumerRegistration/propose private static final String CONSUMER_KEY = ""; private static final String CONSUMER_SECRET = ""; - private static final String API_USERINFO_URL = - "https://meta.wikimedia.org/w/api.php?action=query&format=json&meta=userinfo"; + private static final String API_USERINFO_URL + = "https://meta.wikimedia.org/w/api.php?action=query&format=json&meta=userinfo"; private MediaWikiExample() { } @@ -27,7 +27,7 @@ private MediaWikiExample() { public static void main(String... args) throws IOException, InterruptedException, ExecutionException { final OAuth10aService service = new ServiceBuilder(CONSUMER_KEY) .apiSecret(CONSUMER_SECRET) - .build(MediaWikiApi.wikimediaInstance()); + .build(MediaWikiApi.instance()); final Scanner in = new Scanner(System.in); From 57f0e8f8f1c73fcb12b0a6b5eaa7d709287758da Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 23 May 2018 12:30:07 +0300 Subject: [PATCH 488/882] update deps --- pom.xml | 4 ++-- scribejava-httpclient-ahc/pom.xml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index e2b89b530..09fe4dfd5 100644 --- a/pom.xml +++ b/pom.xml @@ -65,7 +65,7 @@ com.google.code.gson gson - 2.8.2 + 2.8.5 test @@ -150,7 +150,7 @@ org.apache.maven.plugins maven-resources-plugin - 3.0.2 + 3.1.0 UTF-8 diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 418fbccfa..0519a9851 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -23,7 +23,7 @@ org.asynchttpclient async-http-client - 2.4.5 + 2.4.7 com.github.scribejava From b30c11ff8497d983e84d1dd78f365b6b9c2ae83f Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 23 May 2018 13:22:07 +0300 Subject: [PATCH 489/882] prepare 5.5.0 release --- README.md | 4 ++-- changelog | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 554c8e1fc..9b9cf3b58 100644 --- a/README.md +++ b/README.md @@ -112,7 +112,7 @@ You can pull ScribeJava from the central maven repository, just add these to you com.github.scribejava scribejava-apis - 5.4.0 + 5.5.0 ``` @@ -121,7 +121,7 @@ And in case you need just core classes (that's it, without any external API (FB, com.github.scribejava scribejava-core - 5.4.0 + 5.5.0 ``` diff --git a/changelog b/changelog index 6b3c5a577..56317a30f 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,4 @@ -[SNAPSHOT] +[5.5.0] * fix error parsing for Fitbit (thanks to https://github.com/danmana) * optimize debug log performance impact on prod in OAuth1 and fix NoClassDefFoundError on Android device with SDK 18 and lower (thanks to https://github.com/arcao) From 963c00878b2f049564bdf99ad6c76fbe53f66d8f Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 23 May 2018 13:23:10 +0300 Subject: [PATCH 490/882] [maven-release-plugin] prepare release scribejava-5.5.0 --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index 09fe4dfd5..cd2b792cb 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 5.4.1-SNAPSHOT + 5.5.0 ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -34,7 +34,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - HEAD + scribejava-5.5.0 diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index da6150e43..55aade30f 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.4.1-SNAPSHOT + 5.5.0 ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 60e6da8cf..7b4d8e21c 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.4.1-SNAPSHOT + 5.5.0 ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 0519a9851..0a715e2a6 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.4.1-SNAPSHOT + 5.5.0 ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index 2a3eedc01..d86c6cfd3 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.4.1-SNAPSHOT + 5.5.0 ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index 0b13d47a1..069afde05 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.4.1-SNAPSHOT + 5.5.0 ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index e135a6e93..ef9606be7 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.4.1-SNAPSHOT + 5.5.0 ../pom.xml From 72723ba99050eeca15a54fa8c8cf7294cc2bc66f Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 23 May 2018 13:23:18 +0300 Subject: [PATCH 491/882] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index cd2b792cb..bc7d1d445 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 5.5.0 + 5.5.1-SNAPSHOT ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -34,7 +34,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - scribejava-5.5.0 + HEAD diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 55aade30f..e92f60e67 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.5.0 + 5.5.1-SNAPSHOT ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 7b4d8e21c..96ea8ad56 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.5.0 + 5.5.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 0a715e2a6..5b8d1116f 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.5.0 + 5.5.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index d86c6cfd3..bd4c1bab4 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.5.0 + 5.5.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index 069afde05..fcd3e33aa 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.5.0 + 5.5.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index ef9606be7..bc10774b8 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.5.0 + 5.5.1-SNAPSHOT ../pom.xml From 7a635daf2131e00fc72a5a400806ac8af1e6f203 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 23 May 2018 13:53:35 +0300 Subject: [PATCH 492/882] drop deprecated methods and constructors --- .../scribejava/apis/service/FacebookService.java | 13 ------------- .../scribejava/apis/service/ImgurOAuthService.java | 13 ------------- .../apis/service/MailruOAuthService.java | 13 ------------- .../MicrosoftAzureActiveDirectoryService.java | 14 -------------- .../apis/service/OdnoklassnikiOAuthService.java | 14 -------------- .../scribejava/apis/service/TutByOAuthService.java | 13 ------------- .../scribejava/core/oauth/OAuth10aService.java | 12 ------------ .../scribejava/core/oauth/OAuth20Service.java | 13 ------------- .../github/scribejava/core/oauth/OAuthService.java | 13 ------------- 9 files changed, 118 deletions(-) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/FacebookService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/FacebookService.java index 565514efe..51e282310 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/FacebookService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/FacebookService.java @@ -5,7 +5,6 @@ import com.github.scribejava.core.httpclient.HttpClientConfig; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.oauth.OAuth20Service; -import java.io.OutputStream; import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; import java.util.Formatter; @@ -14,18 +13,6 @@ public class FacebookService extends OAuth20Service { - /** - * @deprecated use {@link #FacebookService(com.github.scribejava.core.builder.api.DefaultApi20, java.lang.String, - * java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, - * com.github.scribejava.core.httpclient.HttpClientConfig, com.github.scribejava.core.httpclient.HttpClient)} - */ - @Deprecated - public FacebookService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, - OutputStream debugStream, String state, String responseType, String userAgent, - HttpClientConfig httpClientConfig, HttpClient httpClient) { - this(api, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); - } - public FacebookService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthService.java index c5bfb43f6..e1b146846 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthService.java @@ -7,22 +7,9 @@ import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.oauth.OAuth20Service; -import java.io.OutputStream; public class ImgurOAuthService extends OAuth20Service { - /** - * @deprecated use {@link #ImgurOAuthService(com.github.scribejava.core.builder.api.DefaultApi20, java.lang.String, - * java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, - * com.github.scribejava.core.httpclient.HttpClientConfig, com.github.scribejava.core.httpclient.HttpClient)} - */ - @Deprecated - public ImgurOAuthService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, - OutputStream debugStream, String state, String responseType, String userAgent, - HttpClientConfig httpClientConfig, HttpClient httpClient) { - this(api, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); - } - public ImgurOAuthService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthService.java index aadfc58b5..f40727f53 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthService.java @@ -8,7 +8,6 @@ import com.github.scribejava.core.httpclient.HttpClientConfig; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.oauth.OAuth20Service; -import java.io.OutputStream; import java.io.UnsupportedEncodingException; import java.nio.charset.Charset; import java.security.MessageDigest; @@ -17,18 +16,6 @@ public class MailruOAuthService extends OAuth20Service { - /** - * @deprecated use {@link #MailruOAuthService(com.github.scribejava.core.builder.api.DefaultApi20, java.lang.String, - * java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, - * com.github.scribejava.core.httpclient.HttpClientConfig, com.github.scribejava.core.httpclient.HttpClient)} - */ - @Deprecated - public MailruOAuthService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, - OutputStream debugStream, String state, String responseType, String userAgent, - HttpClientConfig httpClientConfig, HttpClient httpClient) { - this(api, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); - } - public MailruOAuthService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MicrosoftAzureActiveDirectoryService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MicrosoftAzureActiveDirectoryService.java index 59fc2f00b..bab20d3b7 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MicrosoftAzureActiveDirectoryService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MicrosoftAzureActiveDirectoryService.java @@ -5,26 +5,12 @@ import com.github.scribejava.core.httpclient.HttpClientConfig; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.oauth.OAuth20Service; -import java.io.OutputStream; public class MicrosoftAzureActiveDirectoryService extends OAuth20Service { private static final String ACCEPTED_FORMAT = "application/json; odata=minimalmetadata; streaming=true; charset=utf-8"; - /** - * @deprecated use {@link #MicrosoftAzureActiveDirectoryService(com.github.scribejava.core.builder.api.DefaultApi20, - * java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, - * java.lang.String, com.github.scribejava.core.httpclient.HttpClientConfig, - * com.github.scribejava.core.httpclient.HttpClient)} - */ - @Deprecated - public MicrosoftAzureActiveDirectoryService(DefaultApi20 api, String apiKey, String apiSecret, String callback, - String scope, OutputStream debugStream, String state, String responseType, String userAgent, - HttpClientConfig httpClientConfig, HttpClient httpClient) { - this(api, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); - } - public MicrosoftAzureActiveDirectoryService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiOAuthService.java index b2aa5cbda..34bd0fe89 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiOAuthService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiOAuthService.java @@ -7,7 +7,6 @@ import com.github.scribejava.core.model.Parameter; import com.github.scribejava.core.model.ParameterList; import com.github.scribejava.core.oauth.OAuth20Service; -import java.io.OutputStream; import java.io.UnsupportedEncodingException; import java.net.URLDecoder; @@ -20,19 +19,6 @@ public class OdnoklassnikiOAuthService extends OAuth20Service { - /** - * @deprecated use {@link #OdnoklassnikiOAuthService(com.github.scribejava.core.builder.api.DefaultApi20, - * java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, - * java.lang.String, com.github.scribejava.core.httpclient.HttpClientConfig, - * com.github.scribejava.core.httpclient.HttpClient)} - */ - @Deprecated - public OdnoklassnikiOAuthService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, - OutputStream debugStream, String state, String responseType, String userAgent, - HttpClientConfig httpClientConfig, HttpClient httpClient) { - this(api, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); - } - public OdnoklassnikiOAuthService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/TutByOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/TutByOAuthService.java index 17e64e7b5..82ded6c92 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/TutByOAuthService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/TutByOAuthService.java @@ -6,22 +6,9 @@ import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.oauth.OAuth20Service; -import java.io.OutputStream; public class TutByOAuthService extends OAuth20Service { - /** - * @deprecated use {@link #TutByOAuthService(com.github.scribejava.core.builder.api.DefaultApi20, java.lang.String, - * java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, - * com.github.scribejava.core.httpclient.HttpClientConfig, com.github.scribejava.core.httpclient.HttpClient)} - */ - @Deprecated - public TutByOAuthService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, - OutputStream debugStream, String state, String responseType, String userAgent, - HttpClientConfig httpClientConfig, HttpClient httpClient) { - this(api, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); - } - public TutByOAuthService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java index 3986f45d5..b168a9f2c 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java @@ -25,18 +25,6 @@ public class OAuth10aService extends OAuthService { private final OutputStream debugStream; private final DefaultApi10a api; - /** - * @deprecated use {@link #OAuth10aService(com.github.scribejava.core.builder.api.DefaultApi10a, java.lang.String, - * java.lang.String, java.lang.String, java.lang.String, java.io.OutputStream, java.lang.String, - * com.github.scribejava.core.httpclient.HttpClientConfig, com.github.scribejava.core.httpclient.HttpClient)} - */ - @Deprecated - public OAuth10aService(DefaultApi10a api, String apiKey, String apiSecret, String callback, String scope, - OutputStream debugStream, String state, String responseType, String userAgent, - HttpClientConfig httpClientConfig, HttpClient httpClient) { - this(api, apiKey, apiSecret, callback, scope, debugStream, userAgent, httpClientConfig, httpClient); - } - public OAuth10aService(DefaultApi10a api, String apiKey, String apiSecret, String callback, String scope, OutputStream debugStream, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { super(apiKey, apiSecret, callback, scope, userAgent, httpClientConfig, httpClient); diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java index 29df7e94e..80a46dbe1 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java @@ -20,7 +20,6 @@ import java.util.Map; import java.util.concurrent.ExecutionException; import com.github.scribejava.core.revoke.TokenTypeHint; -import java.io.OutputStream; public class OAuth20Service extends OAuthService { @@ -30,18 +29,6 @@ public class OAuth20Service extends OAuthService { private final String responseType; private final String state; - /** - * @deprecated use {@link #OAuth20Service(com.github.scribejava.core.builder.api.DefaultApi20, java.lang.String, - * java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, - * com.github.scribejava.core.httpclient.HttpClientConfig, com.github.scribejava.core.httpclient.HttpClient)} - */ - @Deprecated - public OAuth20Service(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, - OutputStream debugStream, String state, String responseType, String userAgent, - HttpClientConfig httpClientConfig, HttpClient httpClient) { - this(api, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); - } - public OAuth20Service(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java index 60c2d39aa..4b5ddb87c 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java @@ -12,7 +12,6 @@ import java.io.File; import java.io.IOException; -import java.io.OutputStream; import java.util.ServiceLoader; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; @@ -41,18 +40,6 @@ public OAuthService(String apiKey, String apiSecret, String callback, String sco } } - /** - * @deprecated use {@link #OAuthService(java.lang.String, java.lang.String, java.lang.String, java.lang.String, - * java.lang.String, com.github.scribejava.core.httpclient.HttpClientConfig, - * com.github.scribejava.core.httpclient.HttpClient)} - */ - @Deprecated - public OAuthService(String apiKey, String apiSecret, String callback, String scope, OutputStream debugStream, - String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, - HttpClient httpClient) { - this(apiKey, apiSecret, callback, scope, userAgent, httpClientConfig, httpClient); - } - private static HttpClient getClient(HttpClientConfig config) { for (HttpClientProvider provider : ServiceLoader.load(HttpClientProvider.class)) { final HttpClient client = provider.createClient(config); From 6787f8c50a776b4a39b1da9014021e1a84d6f93e Mon Sep 17 00:00:00 2001 From: zhangzhenli Date: Tue, 26 Jun 2018 16:12:35 +0800 Subject: [PATCH 493/882] =?UTF-8?q?Modify=20the=20enum=20as=20an=20abstrac?= =?UTF-8?q?t=20type,=20allowing=20custom=20implementations=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../builder/api/ClientAuthenticationType.java | 50 +++++++++++-------- 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/ClientAuthenticationType.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/ClientAuthenticationType.java index 77212ce95..2faa81d46 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/ClientAuthenticationType.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/ClientAuthenticationType.java @@ -12,28 +12,36 @@ * in it's part 2.3.1. Client Password
* https://tools.ietf.org/html/rfc6749#section-2.3.1 */ -public enum ClientAuthenticationType { - HTTP_BASIC_AUTHENTICATION_SCHEME { - private final Base64.Encoder base64Encoder = Base64.getEncoder(); +public abstract class ClientAuthenticationType { - @Override - public void addClientAuthentication(OAuthRequest request, String apiKey, String apiSecret) { - if (apiKey != null && apiSecret != null) { - request.addHeader(OAuthConstants.HEADER, OAuthConstants.BASIC + ' ' - + base64Encoder.encodeToString( + public static final ClientAuthenticationType HTTP_BASIC_AUTHENTICATION_SCHEME = + new ClientAuthenticationType() { + private final Base64.Encoder base64Encoder = Base64.getEncoder(); + + @Override + public void addClientAuthentication(OAuthRequest request, String apiKey, + String apiSecret) { + if (apiKey != null && apiSecret != null) { + request.addHeader(OAuthConstants.HEADER, OAuthConstants.BASIC + ' ' + + base64Encoder.encodeToString( String.format("%s:%s", apiKey, apiSecret).getBytes(Charset.forName("UTF-8")))); - } - } - }, - REQUEST_BODY { - @Override - public void addClientAuthentication(OAuthRequest request, String apiKey, String apiSecret) { - request.addParameter(OAuthConstants.CLIENT_ID, apiKey); - if (apiSecret != null) { - request.addParameter(OAuthConstants.CLIENT_SECRET, apiSecret); - } - } - }; + } + } + }; + + public static final ClientAuthenticationType REQUEST_BODY = + new ClientAuthenticationType() { + + @Override + public void addClientAuthentication(OAuthRequest request, String apiKey, + String apiSecret) { + request.addParameter(OAuthConstants.CLIENT_ID, apiKey); + if (apiSecret != null) { + request.addParameter(OAuthConstants.CLIENT_SECRET, apiSecret); + } + } + }; - public abstract void addClientAuthentication(OAuthRequest request, String apiKey, String apiSecret); + public abstract void addClientAuthentication(OAuthRequest request, String apiKey, + String apiSecret); } From 3e765687be1425f647bbd66a51a4b43a128cb970 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 26 Jul 2018 22:17:53 +0300 Subject: [PATCH 494/882] add Multipart functionality to JDK Http Client (thanks to https://github.com/eos1d3) --- changelog | 3 + .../AbstractAsyncOnlyHttpClient.java | 17 ++- .../core/httpclient/BodyPartPayload.java | 27 ++++ .../core/httpclient/HttpClient.java | 9 +- .../core/httpclient/MultipartPayload.java | 54 +++++++ .../core/httpclient/jdk/JDKHttpClient.java | 125 ++++++++------- .../scribejava/core/model/OAuthRequest.java | 144 +++++------------- .../scribejava/core/oauth/OAuthService.java | 7 +- .../httpclient/ahc/AhcHttpClient.java | 9 ++ .../httpclient/apache/ApacheHttpClient.java | 9 ++ .../httpclient/ning/NingHttpClient.java | 9 ++ .../httpclient/okhttp/OkHttpHttpClient.java | 29 +++- 12 files changed, 262 insertions(+), 180 deletions(-) create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/httpclient/BodyPartPayload.java create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/httpclient/MultipartPayload.java diff --git a/changelog b/changelog index 56317a30f..0397fd622 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,6 @@ +[SNAPSHOT] + * add Multipart functionality to JDK Http Client (thanks to https://github.com/eos1d3) + [5.5.0] * fix error parsing for Fitbit (thanks to https://github.com/danmana) * optimize debug log performance impact on prod in OAuth1 and fix diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/AbstractAsyncOnlyHttpClient.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/AbstractAsyncOnlyHttpClient.java index b8d6dead9..6f75ee6c1 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/AbstractAsyncOnlyHttpClient.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/AbstractAsyncOnlyHttpClient.java @@ -13,6 +13,15 @@ public abstract class AbstractAsyncOnlyHttpClient implements HttpClient { @Override public Response execute(String userAgent, Map headers, Verb httpVerb, String completeUrl, byte[] bodyContents) throws InterruptedException, ExecutionException, IOException { + + return executeAsync(userAgent, headers, httpVerb, completeUrl, bodyContents, null, + (OAuthRequest.ResponseConverter) null).get(); + } + + @Override + public Response execute(String userAgent, Map headers, Verb httpVerb, String completeUrl, + MultipartPayload bodyContents) throws InterruptedException, ExecutionException, IOException { + return executeAsync(userAgent, headers, httpVerb, completeUrl, bodyContents, null, (OAuthRequest.ResponseConverter) null).get(); } @@ -20,6 +29,7 @@ public Response execute(String userAgent, Map headers, Verb http @Override public Response execute(String userAgent, Map headers, Verb httpVerb, String completeUrl, String bodyContents) throws InterruptedException, ExecutionException, IOException { + return executeAsync(userAgent, headers, httpVerb, completeUrl, bodyContents, null, (OAuthRequest.ResponseConverter) null).get(); } @@ -27,13 +37,8 @@ public Response execute(String userAgent, Map headers, Verb http @Override public Response execute(String userAgent, Map headers, Verb httpVerb, String completeUrl, File bodyContents) throws InterruptedException, ExecutionException, IOException { + return executeAsync(userAgent, headers, httpVerb, completeUrl, bodyContents, null, (OAuthRequest.ResponseConverter) null).get(); } - - @Override - public Response execute(String userAgent, Map headers, Verb httpVerb, String completeUrl, - OAuthRequest.MultipartPayloads multipartPayloads) throws InterruptedException, ExecutionException, IOException { - throw new UnsupportedOperationException("This HttpClient does not support Multipart payload for the moment"); - } } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/BodyPartPayload.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/BodyPartPayload.java new file mode 100644 index 000000000..3e8c6d47e --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/BodyPartPayload.java @@ -0,0 +1,27 @@ +package com.github.scribejava.core.httpclient; + +public class BodyPartPayload { + + private final String contentDisposition; + private final String contentType; + private final byte[] payload; + + public BodyPartPayload(String contentDisposition, String contentType, byte[] payload) { + this.contentDisposition = contentDisposition; + this.contentType = contentType; + this.payload = payload; + } + + public String getContentDisposition() { + return contentDisposition; + } + + public String getContentType() { + return contentType; + } + + public byte[] getPayload() { + return payload; + } + +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/HttpClient.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/HttpClient.java index 41c5df134..40f9663f5 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/HttpClient.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/HttpClient.java @@ -12,6 +12,7 @@ import java.util.concurrent.Future; public interface HttpClient extends Closeable { + String DEFAULT_CONTENT_TYPE = "application/x-www-form-urlencoded"; String CONTENT_TYPE = "Content-Type"; String CONTENT_LENGTH = "Content-Length"; @@ -19,6 +20,10 @@ public interface HttpClient extends Closeable { Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, byte[] bodyContents, OAuthAsyncRequestCallback callback, OAuthRequest.ResponseConverter converter); + Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, + MultipartPayload bodyContents, OAuthAsyncRequestCallback callback, + OAuthRequest.ResponseConverter converter); + Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, String bodyContents, OAuthAsyncRequestCallback callback, OAuthRequest.ResponseConverter converter); @@ -27,9 +32,9 @@ Future executeAsync(String userAgent, Map headers, Verb h Response execute(String userAgent, Map headers, Verb httpVerb, String completeUrl, byte[] bodyContents) throws InterruptedException, ExecutionException, IOException; - + Response execute(String userAgent, Map headers, Verb httpVerb, String completeUrl, - OAuthRequest.MultipartPayloads multipartPayloads) throws InterruptedException, ExecutionException, IOException; + MultipartPayload bodyContents) throws InterruptedException, ExecutionException, IOException; Response execute(String userAgent, Map headers, Verb httpVerb, String completeUrl, String bodyContents) throws InterruptedException, ExecutionException, IOException; diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/MultipartPayload.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/MultipartPayload.java new file mode 100644 index 000000000..a1dbb5e7e --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/MultipartPayload.java @@ -0,0 +1,54 @@ +package com.github.scribejava.core.httpclient; + +import java.util.ArrayList; +import java.util.List; + +/** + * The class containing more than one payload of multipart/form-data request + */ +public class MultipartPayload { + + private final String boundary; + private final List bodyParts = new ArrayList<>(); + + public MultipartPayload(String boundary) { + this.boundary = boundary; + } + + public byte[] getStartBoundary(BodyPartPayload bodyPart) { + return ("--" + boundary + "\r\n" + + "Content-Disposition: " + bodyPart.getContentDisposition() + "\r\n" + + (bodyPart.getContentType() == null ? "" : "Content-Type: " + bodyPart.getContentType() + "\r\n") + + "\r\n").getBytes(); + } + + public byte[] getEndBoundary() { + return ("\r\n--" + boundary + "--\r\n").getBytes(); + } + + public int getContentLength() { + int contentLength = 0; + for (BodyPartPayload bodyPart : bodyParts) { + contentLength += bodyPart.getPayload().length + + bodyPart.getContentDisposition().length(); + if (bodyPart.getContentType() != null) { + contentLength += 16 //length of constant portions of contentType header + + bodyPart.getContentType().length(); + } + } + + contentLength += (37 //length of constant portions of contentDisposition header, + //see getStartBoundary and getEndBoundary methods + + boundary.length() * 2 //twice. start and end parts + ) * bodyParts.size(); //for every part + return contentLength; + } + + public List getBodyParts() { + return bodyParts; + } + + public void addMultipartPayload(String contentDisposition, String contentType, byte[] payload) { + bodyParts.add(new BodyPartPayload(contentDisposition, contentType, payload)); + } +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java index 3b4245671..cc810ded5 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java @@ -1,7 +1,9 @@ package com.github.scribejava.core.httpclient.jdk; import com.github.scribejava.core.exceptions.OAuthException; +import com.github.scribejava.core.httpclient.BodyPartPayload; import com.github.scribejava.core.httpclient.HttpClient; +import com.github.scribejava.core.httpclient.MultipartPayload; import com.github.scribejava.core.model.OAuthAsyncRequestCallback; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.OAuthRequest; @@ -38,32 +40,46 @@ public void close() { @Override public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, byte[] bodyContents, OAuthAsyncRequestCallback callback, OAuthRequest.ResponseConverter converter) { - try { - final Response response = execute(userAgent, headers, httpVerb, completeUrl, bodyContents); - @SuppressWarnings("unchecked") - final T t = converter == null ? (T) response : converter.convert(response); - if (callback != null) { - callback.onCompleted(t); - } - return new JDKHttpFuture<>(t); - } catch (InterruptedException | ExecutionException | IOException e) { - callback.onThrowable(e); - return new JDKHttpFuture<>(e); - } + + return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, BodyType.BYTE_ARRAY, bodyContents, callback, + converter); + } + + @Override + public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, + MultipartPayload bodyContents, OAuthAsyncRequestCallback callback, + OAuthRequest.ResponseConverter converter) { + + return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, BodyType.MULTIPART, bodyContents, callback, + converter); } @Override public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, String bodyContents, OAuthAsyncRequestCallback callback, OAuthRequest.ResponseConverter converter) { + + return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, BodyType.STRING, bodyContents, callback, + converter); + } + + @Override + public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, + File bodyContents, OAuthAsyncRequestCallback callback, OAuthRequest.ResponseConverter converter) { + throw new UnsupportedOperationException("JDKHttpClient does not support File payload for the moment"); + } + + private Future doExecuteAsync(String userAgent, Map headers, Verb httpVerb, + String completeUrl, BodyType bodyType, Object bodyContents, OAuthAsyncRequestCallback callback, + OAuthRequest.ResponseConverter converter) { try { - final Response response = execute(userAgent, headers, httpVerb, completeUrl, bodyContents); + final Response response = doExecute(userAgent, headers, httpVerb, completeUrl, bodyType, bodyContents); @SuppressWarnings("unchecked") final T t = converter == null ? (T) response : converter.convert(response); if (callback != null) { callback.onCompleted(t); } return new JDKHttpFuture<>(t); - } catch (InterruptedException | ExecutionException | IOException e) { + } catch (IOException e) { if (callback != null) { callback.onThrowable(e); } @@ -72,15 +88,15 @@ public Future executeAsync(String userAgent, Map headers, } @Override - public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, - File bodyContents, OAuthAsyncRequestCallback callback, OAuthRequest.ResponseConverter converter) { - throw new UnsupportedOperationException("JDKHttpClient does not support File payload for the moment"); + public Response execute(String userAgent, Map headers, Verb httpVerb, String completeUrl, + byte[] bodyContents) throws InterruptedException, ExecutionException, IOException { + return doExecute(userAgent, headers, httpVerb, completeUrl, BodyType.BYTE_ARRAY, bodyContents); } @Override public Response execute(String userAgent, Map headers, Verb httpVerb, String completeUrl, - byte[] bodyContents) throws InterruptedException, ExecutionException, IOException { - return doExecute(userAgent, headers, httpVerb, completeUrl, BodyType.BYTE_ARRAY, bodyContents); + MultipartPayload multipartPayloads) throws InterruptedException, ExecutionException, IOException { + return doExecute(userAgent, headers, httpVerb, completeUrl, BodyType.MULTIPART, multipartPayloads); } @Override @@ -92,15 +108,9 @@ public Response execute(String userAgent, Map headers, Verb http @Override public Response execute(String userAgent, Map headers, Verb httpVerb, String completeUrl, File bodyContents) throws InterruptedException, ExecutionException, IOException { - throw new UnsupportedOperationException("JDKHttpClient do not support File payload for the moment"); + throw new UnsupportedOperationException("JDKHttpClient does not support File payload for the moment"); } - @Override - public Response execute(String userAgent, Map headers, Verb httpVerb, String completeUrl, - OAuthRequest.MultipartPayloads multipartPayloads) throws InterruptedException, ExecutionException, IOException { - return doExecute(userAgent, headers, httpVerb, completeUrl, BodyType.MULTIPART, multipartPayloads); - } - private Response doExecute(String userAgent, Map headers, Verb httpVerb, String completeUrl, BodyType bodyType, Object bodyContents) throws IOException { final HttpURLConnection connection = (HttpURLConnection) new URL(completeUrl).openConnection(); @@ -136,9 +146,9 @@ void setBody(HttpURLConnection connection, Object bodyContents, boolean requires } }, MULTIPART { - @Override + @Override void setBody(HttpURLConnection connection, Object bodyContents, boolean requiresBody) throws IOException { - addBody(connection, (OAuthRequest.MultipartPayloads) bodyContents, requiresBody); + addBody(connection, (MultipartPayload) bodyContents, requiresBody); } }, STRING { @@ -150,7 +160,6 @@ void setBody(HttpURLConnection connection, Object bodyContents, boolean requires abstract void setBody(HttpURLConnection connection, Object bodyContents, boolean requiresBody) throws IOException; - } private static Map parseHeaders(HttpURLConnection conn) { @@ -178,41 +187,41 @@ private static void addHeaders(HttpURLConnection connection, Map } } - /* - * Multipart implementation supporting more than one payload - * + /** + * Multipart implementation supporting more than one payload */ - private static void addBody(HttpURLConnection connection, OAuthRequest.MultipartPayloads multipartPayloads, boolean requiresBody) throws IOException { - int contentLength = multipartPayloads.getContentLength(); - System.out.println("length: " + contentLength); + private static void addBody(HttpURLConnection connection, MultipartPayload multipartPayload, boolean requiresBody) + throws IOException { + + final int contentLength = multipartPayload.getContentLength(); if (requiresBody || contentLength > 0) { - connection.setRequestProperty(CONTENT_LENGTH, String.valueOf(contentLength)); - if (connection.getRequestProperty(CONTENT_TYPE) == null) { - connection.setRequestProperty(CONTENT_TYPE, DEFAULT_CONTENT_TYPE); + final OutputStream os = prepareConnectionForBodyAndGetOutputStream(connection, contentLength); + + for (BodyPartPayload bodyPart : multipartPayload.getBodyParts()) { + os.write(multipartPayload.getStartBoundary(bodyPart)); + os.write(bodyPart.getPayload()); + os.write(multipartPayload.getEndBoundary()); } - System.out.println("content-length: " + connection.getRequestProperty(CONTENT_TYPE)); - connection.setDoOutput(true); - OutputStream os = connection.getOutputStream(); - - int totalParts = multipartPayloads.getMultipartPayloadList().size(); - for (int i = 0; i < totalParts; i++) { - os.write(multipartPayloads.getStartBoundary(i)); - os.write(multipartPayloads.getMultipartPayloadList().get(i).getPayload(), 0, multipartPayloads.getMultipartPayloadList().get(i).getLength()); - os.write(multipartPayloads.getEndBoundary(i)); - } - } - } - + } + } + private static void addBody(HttpURLConnection connection, byte[] content, boolean requiresBody) throws IOException { final int contentLength = content.length; if (requiresBody || contentLength > 0) { - connection.setRequestProperty(CONTENT_LENGTH, String.valueOf(contentLength)); - if (connection.getRequestProperty(CONTENT_TYPE) == null) { - connection.setRequestProperty(CONTENT_TYPE, DEFAULT_CONTENT_TYPE); - } - connection.setDoOutput(true); - connection.getOutputStream().write(content); + prepareConnectionForBodyAndGetOutputStream(connection, contentLength).write(content); } } - + + private static OutputStream prepareConnectionForBodyAndGetOutputStream(HttpURLConnection connection, + int contentLength) throws IOException { + + connection.setRequestProperty(CONTENT_LENGTH, String.valueOf(contentLength)); + if (connection.getRequestProperty(CONTENT_TYPE) == null) { + connection.setRequestProperty(CONTENT_TYPE, DEFAULT_CONTENT_TYPE); + + } + connection.setDoOutput(true); + return connection.getOutputStream(); + } + } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequest.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequest.java index 39b3dd73f..a33ac7d72 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequest.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequest.java @@ -1,85 +1,22 @@ package com.github.scribejava.core.model; import com.github.scribejava.core.exceptions.OAuthException; +import com.github.scribejava.core.httpclient.MultipartPayload; import java.io.File; import java.io.IOException; import java.io.UnsupportedEncodingException; import java.net.MalformedURLException; import java.net.URL; import java.nio.charset.Charset; -import java.util.ArrayList; import java.util.HashMap; -import java.util.List; import java.util.Map; - /** * The representation of an OAuth HttpRequest. */ public class OAuthRequest { - /* - * The class containing more than one payload of multipart/form-data request - */ - public class MultipartPayloads { - private String boundary; - private int contentLength; - private List multipartPayloadList; - - public MultipartPayloads(String boundary) { - this.boundary = boundary; - this.multipartPayloadList = new ArrayList<>(); - } - - public byte[] getStartBoundary(int index) { - MultipartPayload multipartPaayLoad = multipartPayloadList.get(index); - byte[] bytes = ("--" + boundary +"\r\n" - + "Content-Disposition: " + multipartPaayLoad.contentDisposition + "\r\n" - + (multipartPaayLoad == null ? "" : "Content-Type: " + multipartPaayLoad.contentType + "\r\n") - + "\r\n").getBytes(); - return bytes; - } - - public byte[] getEndBoundary(int index) { - return ("\r\n" - + "--" + boundary + "--\r\n").getBytes(); - } - - public int getContentLength() { - return contentLength; - } - - public void addContentLength(int length) { - this.contentLength += length; - } - - public List getMultipartPayloadList() { - return multipartPayloadList; - } - } - - public class MultipartPayload { - private String contentDisposition; - private String contentType; - private byte[] payload; - private int length; - - public MultipartPayload(String contentDisposition, String contentType, byte[] payload, int length) { - this.contentDisposition = contentDisposition; - this.contentType = contentType; - this.payload = payload; - this.length = length; - } - - public byte[] getPayload() { - return payload; - } - - public int getLength() { - return length; - } - } - - private static final String OAUTH_PREFIX = "oauth_"; + + private static final String OAUTH_PREFIX = "oauth_"; private final String url; private final Verb verb; @@ -92,7 +29,7 @@ public int getLength() { private String stringPayload; private byte[] byteArrayPayload; private File filePayload; - private MultipartPayloads multipartPayloads; + private MultipartPayload multipartPayload; private final Map oauthParameters = new HashMap<>(); @@ -188,43 +125,44 @@ public void addParameter(String key, String value) { querystringParams.add(key, value); } } - - /* + /** * Set boundary of multipart request - * + * * @param boundary can be any string */ - public void setMultipartBoundary(String boundary) { - multipartPayloads = new MultipartPayloads(boundary); - } - - - /* - * Add one multipart form-data payload to the request & increase the current Content-Length - * - * @param contentDisposition value of Content-Disposition header - * @param contentType value of Content-Type header - * @param payload data array containing the data to send - * @param length the max no of bytes to send - * - * Remarks: - * 57 and 37 are the length of constant portions of contentDisposition and/or contentType headers - * refer getStartBoundary and getEndBoundary for the constant - * - * Must be called after setMultipartBoundary method - */ - public void addMultipartPayload(String contentDisposition, String contentType, byte[] payload, int length) { - int contentLenght; - if (contentType == null) - contentLenght = 37 + multipartPayloads.boundary.length() * 2 + contentDisposition.length() + payload.length; - else - contentLenght = 53 + multipartPayloads.boundary.length() * 2 + contentDisposition.length() + + contentType.length() + payload.length; - multipartPayloads.addContentLength(contentLenght); - - multipartPayloads.getMultipartPayloadList().add(new MultipartPayload(contentDisposition, contentType, payload, length)); - } - + public void initMultipartBoundary(String boundary) { + multipartPayload = new MultipartPayload(boundary == null + ? Long.toString(System.currentTimeMillis()) + : boundary); + } + + /** + * init boundary of multipart request with default boundary + */ + public void initMultipartBoundary() { + initMultipartBoundary(null); + } + + /** + * you can invoke {@link #initMultipartBoundary(java.lang.String) } to set custom boundary + */ + public void addMultipartPayload(String contentDisposition, String contentType, byte[] payload) { + if (multipartPayload == null) { + initMultipartBoundary(); + } + multipartPayload.addMultipartPayload(contentDisposition, contentType, payload); + } + + public void setMultipartPayload(String contentDisposition, String contentType, byte[] payload) { + setMultipartPayload(null, contentDisposition, contentType, payload); + } + + public void setMultipartPayload(String boundary, String contentDisposition, String contentType, byte[] payload) { + initMultipartBoundary(boundary); + multipartPayload.addMultipartPayload(contentDisposition, contentType, payload); + } + /** * Set body payload. This method is used when the HTTP body is not a form-url-encoded string, but another thing. * Like for example XML. Note: The contents are not part of the OAuth signature @@ -260,7 +198,7 @@ private void resetPayload() { stringPayload = null; byteArrayPayload = null; filePayload = null; - multipartPayloads = null; + multipartPayload = null; } /** @@ -339,8 +277,8 @@ public byte[] getByteArrayPayload() { } } - public MultipartPayloads getMultipartPayloads() { - return multipartPayloads; + public MultipartPayload getMultipartPayloads() { + return multipartPayload; } public File getFilePayload() { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java index 3afd9855e..9f331a4ba 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java @@ -111,10 +111,9 @@ public Response execute(OAuthRequest request) throws InterruptedException, Execu return httpClient.execute(userAgent, request.getHeaders(), request.getVerb(), request.getCompleteUrl(), request.getStringPayload()); } else if (request.getMultipartPayloads() != null) { - return httpClient.execute(userAgent, request.getHeaders(), request.getVerb(), request.getCompleteUrl(), - request.getMultipartPayloads()); - } - else { + return httpClient.execute(userAgent, request.getHeaders(), request.getVerb(), request.getCompleteUrl(), + request.getMultipartPayloads()); + } else { return httpClient.execute(userAgent, request.getHeaders(), request.getVerb(), request.getCompleteUrl(), request.getByteArrayPayload()); } diff --git a/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/AhcHttpClient.java b/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/AhcHttpClient.java index 623e5d49d..ebe551571 100644 --- a/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/AhcHttpClient.java +++ b/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/AhcHttpClient.java @@ -1,6 +1,7 @@ package com.github.scribejava.httpclient.ahc; import com.github.scribejava.core.httpclient.AbstractAsyncOnlyHttpClient; +import com.github.scribejava.core.httpclient.MultipartPayload; import com.github.scribejava.core.java8.Consumer; import com.github.scribejava.core.model.OAuthAsyncRequestCallback; import com.github.scribejava.core.model.OAuthConstants; @@ -47,6 +48,14 @@ public Future executeAsync(String userAgent, Map headers, converter); } + @Override + public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, + MultipartPayload bodyContents, OAuthAsyncRequestCallback callback, + OAuthRequest.ResponseConverter converter) { + + throw new UnsupportedOperationException("AhcHttpClient does not support MultipartPayload yet."); + } + @Override public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, final String bodyContents, OAuthAsyncRequestCallback callback, diff --git a/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/ApacheHttpClient.java b/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/ApacheHttpClient.java index 9075ff1ef..dc5a3607b 100644 --- a/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/ApacheHttpClient.java +++ b/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/ApacheHttpClient.java @@ -1,6 +1,7 @@ package com.github.scribejava.httpclient.apache; import com.github.scribejava.core.httpclient.AbstractAsyncOnlyHttpClient; +import com.github.scribejava.core.httpclient.MultipartPayload; import com.github.scribejava.core.model.OAuthAsyncRequestCallback; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.OAuthRequest; @@ -53,6 +54,14 @@ public Future executeAsync(String userAgent, Map headers, return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, entity, callback, converter); } + @Override + public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, + MultipartPayload bodyContents, OAuthAsyncRequestCallback callback, + OAuthRequest.ResponseConverter converter) { + + throw new UnsupportedOperationException("ApacheHttpClient does not support MultipartPayload yet."); + } + @Override public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, String bodyContents, OAuthAsyncRequestCallback callback, OAuthRequest.ResponseConverter converter) { diff --git a/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/NingHttpClient.java b/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/NingHttpClient.java index 90fc92fec..4463ea9e1 100644 --- a/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/NingHttpClient.java +++ b/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/NingHttpClient.java @@ -1,6 +1,7 @@ package com.github.scribejava.httpclient.ning; import com.github.scribejava.core.httpclient.AbstractAsyncOnlyHttpClient; +import com.github.scribejava.core.httpclient.MultipartPayload; import com.github.scribejava.core.java8.Consumer; import com.github.scribejava.core.model.OAuthAsyncRequestCallback; import com.github.scribejava.core.model.OAuthConstants; @@ -53,6 +54,14 @@ public Future executeAsync(String userAgent, Map headers, converter); } + @Override + public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, + MultipartPayload bodyContents, OAuthAsyncRequestCallback callback, + OAuthRequest.ResponseConverter converter) { + + throw new UnsupportedOperationException("NingHttpClient does not support MultipartPayload yet."); + } + @Override public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, final String bodyContents, OAuthAsyncRequestCallback callback, diff --git a/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java b/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java index 2582eab17..8436f11ed 100644 --- a/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java +++ b/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java @@ -1,10 +1,10 @@ package com.github.scribejava.httpclient.okhttp; import com.github.scribejava.core.httpclient.HttpClient; +import com.github.scribejava.core.httpclient.MultipartPayload; import com.github.scribejava.core.model.OAuthAsyncRequestCallback; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.OAuthRequest; -import com.github.scribejava.core.model.OAuthRequest.MultipartPayloads; import com.github.scribejava.core.model.Verb; import okhttp3.Call; import okhttp3.MediaType; @@ -55,13 +55,23 @@ public void close() throws IOException { @Override public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, byte[] bodyContents, OAuthAsyncRequestCallback callback, OAuthRequest.ResponseConverter converter) { + return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, BodyType.BYTE_ARRAY, bodyContents, callback, converter); } + @Override + public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, + MultipartPayload bodyContents, OAuthAsyncRequestCallback callback, + OAuthRequest.ResponseConverter converter) { + + throw new UnsupportedOperationException("OKHttpClient does not support Multipart payload for the moment"); + } + @Override public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, String bodyContents, OAuthAsyncRequestCallback callback, OAuthRequest.ResponseConverter converter) { + return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, BodyType.STRING, bodyContents, callback, converter); } @@ -69,6 +79,7 @@ public Future executeAsync(String userAgent, Map headers, @Override public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, File bodyContents, OAuthAsyncRequestCallback callback, OAuthRequest.ResponseConverter converter) { + return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, BodyType.FILE, bodyContents, callback, converter); } @@ -85,27 +96,31 @@ private Future doExecuteAsync(String userAgent, Map heade @Override public Response execute(String userAgent, Map headers, Verb httpVerb, String completeUrl, byte[] bodyContents) throws InterruptedException, ExecutionException, IOException { + return doExecute(userAgent, headers, httpVerb, completeUrl, BodyType.BYTE_ARRAY, bodyContents); } + @Override + public Response execute(String userAgent, Map headers, Verb httpVerb, String completeUrl, + MultipartPayload bodyContents) throws InterruptedException, ExecutionException, IOException { + + throw new UnsupportedOperationException("OKHttpClient does not support Multipart payload for the moment"); + } + @Override public Response execute(String userAgent, Map headers, Verb httpVerb, String completeUrl, String bodyContents) throws InterruptedException, ExecutionException, IOException { + return doExecute(userAgent, headers, httpVerb, completeUrl, BodyType.STRING, bodyContents); } @Override public Response execute(String userAgent, Map headers, Verb httpVerb, String completeUrl, File bodyContents) throws InterruptedException, ExecutionException, IOException { + return doExecute(userAgent, headers, httpVerb, completeUrl, BodyType.FILE, bodyContents); } - @Override - public Response execute(String userAgent, Map headers, Verb httpVerb, String completeUrl, - MultipartPayloads multipartPayloads) throws InterruptedException, ExecutionException, IOException { - throw new UnsupportedOperationException("OKHttpClient does not support Multipart payload for the moment"); - } - private Response doExecute(String userAgent, Map headers, Verb httpVerb, String completeUrl, BodyType bodyType, Object bodyContents) throws IOException { final Call call = createCall(userAgent, headers, httpVerb, completeUrl, bodyType, bodyContents); From f96b6768cd2fcdb1f242e8de62e6737d4d0c4b02 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 26 Jul 2018 22:23:16 +0300 Subject: [PATCH 495/882] update maven deps --- pom.xml | 6 +++--- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pom.xml b/pom.xml index bc7d1d445..7f8d17a8f 100644 --- a/pom.xml +++ b/pom.xml @@ -71,7 +71,7 @@ com.squareup.okhttp3 mockwebserver - 3.10.0 + 3.11.0 test @@ -81,7 +81,7 @@ org.apache.felix maven-bundle-plugin - 3.5.0 + 3.5.1 bundle-manifest @@ -171,7 +171,7 @@ org.apache.maven.plugins maven-javadoc-plugin - 3.0.0 + 3.0.1 UTF-8 diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 5b8d1116f..eacdd6208 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -23,7 +23,7 @@ org.asynchttpclient async-http-client - 2.4.7 + 2.5.2 com.github.scribejava diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index bd4c1bab4..e8815c53e 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -23,7 +23,7 @@ org.apache.httpcomponents httpclient - 4.5.5 + 4.5.6 org.apache.httpcomponents diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index bc10774b8..554be1054 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -23,7 +23,7 @@ com.squareup.okhttp3 okhttp - 3.10.0 + 3.11.0 com.github.scribejava From f4b9b8edf487f5bb59070c1a62702f6605a62e52 Mon Sep 17 00:00:00 2001 From: Jochen Klein Date: Fri, 27 Jul 2018 17:35:52 +0200 Subject: [PATCH 496/882] Implement response code check for OAuth2AccessTokenExtractor --- .../core/extractors/OAuth2AccessTokenExtractor.java | 4 ++++ .../extractors/OAuth2AccessTokenExtractorTest.java | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenExtractor.java b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenExtractor.java index 8af44d3aa..22c1b90f0 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenExtractor.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenExtractor.java @@ -3,6 +3,7 @@ import java.io.IOException; import java.util.regex.Matcher; import java.util.regex.Pattern; + import com.github.scribejava.core.exceptions.OAuthException; import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.Response; @@ -37,6 +38,9 @@ public static OAuth2AccessTokenExtractor instance() { */ @Override public OAuth2AccessToken extract(Response response) throws IOException { + if (response.getCode() != 200) { + throw new OAuthException("Response code not 200 but " + response.getCode()); + } final String body = response.getBody(); Preconditions.checkEmptyString(body, "Response body is incorrect. Can't extract a token from an empty string"); diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/extractors/OAuth2AccessTokenExtractorTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/extractors/OAuth2AccessTokenExtractorTest.java index 7f2cd4ddd..b123d90aa 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/extractors/OAuth2AccessTokenExtractorTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/extractors/OAuth2AccessTokenExtractorTest.java @@ -58,6 +58,12 @@ public void shouldExtractTokenFromResponseWithManyParameters() throws IOExceptio assertEquals("foo1234", extracted.getAccessToken()); } + @Test(expected = OAuthException.class) + public void shouldThrowExceptionIfErrorResponse() throws IOException { + final String response = ""; + this.extractor.extract(error(response)); + } + @Test(expected = OAuthException.class) public void shouldThrowExceptionIfTokenIsAbsent() throws IOException { final String response = "&expires=5108"; @@ -78,4 +84,8 @@ public void shouldThrowExceptionIfResponseIsEmptyString() throws IOException { private static Response ok(String body) { return new Response(200, /* message */ null, /* headers */ Collections.emptyMap(), body); } + + private static Response error(final String body) { + return new Response(400, /* message */ null, /* headers */ Collections.emptyMap(), body); + } } From e46a55cca0bf2a4aee5488c32388d160ff65ff1d Mon Sep 17 00:00:00 2001 From: Jochen Klein Date: Fri, 27 Jul 2018 17:36:10 +0200 Subject: [PATCH 497/882] deliver OAuth exceptions from OAuthAsyncCompletionHandler - jdk http client --- .../scribejava/core/httpclient/jdk/JDKHttpClient.java | 2 +- .../scribejava/core/httpclient/jdk/JDKHttpFuture.java | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java index cc810ded5..164a0520f 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java @@ -79,7 +79,7 @@ private Future doExecuteAsync(String userAgent, Map heade callback.onCompleted(t); } return new JDKHttpFuture<>(t); - } catch (IOException e) { + } catch (Throwable e) { if (callback != null) { callback.onThrowable(e); } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpFuture.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpFuture.java index 1922d3aef..307c552c6 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpFuture.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpFuture.java @@ -11,10 +11,10 @@ */ public class JDKHttpFuture implements Future { - private final Exception exception; + private final Throwable exception; private final V response; - public JDKHttpFuture(Exception exception) { + public JDKHttpFuture(Throwable exception) { this(null, exception); } @@ -22,7 +22,7 @@ public JDKHttpFuture(V response) { this(response, null); } - private JDKHttpFuture(V response, Exception exception) { + private JDKHttpFuture(V response, Throwable exception) { this.response = response; this.exception = exception; } From 3a9ad1227c57c2cb26861ba9864a39155da27e55 Mon Sep 17 00:00:00 2001 From: Jochen Klein Date: Fri, 27 Jul 2018 17:36:24 +0200 Subject: [PATCH 498/882] deliver OAuth exceptions from OAuthAsyncCompletionHandler - apache httpclient --- .../apache/OAuthAsyncCompletionHandler.java | 25 ++++--- .../OauthAsyncCompletionHandlerTest.java | 75 +++++++++++++------ 2 files changed, 67 insertions(+), 33 deletions(-) diff --git a/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/OAuthAsyncCompletionHandler.java b/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/OAuthAsyncCompletionHandler.java index 02fc7616f..b49dd8513 100644 --- a/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/OAuthAsyncCompletionHandler.java +++ b/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/OAuthAsyncCompletionHandler.java @@ -1,13 +1,5 @@ package com.github.scribejava.httpclient.apache; -import com.github.scribejava.core.model.OAuthAsyncRequestCallback; -import com.github.scribejava.core.model.OAuthRequest.ResponseConverter; -import com.github.scribejava.core.model.Response; -import org.apache.http.Header; -import org.apache.http.HttpResponse; -import org.apache.http.concurrent.FutureCallback; - -import java.io.IOException; import java.util.HashMap; import java.util.Map; import java.util.concurrent.CancellationException; @@ -15,7 +7,15 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; + +import org.apache.http.Header; +import org.apache.http.HttpResponse; import org.apache.http.StatusLine; +import org.apache.http.concurrent.FutureCallback; + +import com.github.scribejava.core.model.OAuthAsyncRequestCallback; +import com.github.scribejava.core.model.OAuthRequest.ResponseConverter; +import com.github.scribejava.core.model.Response; public class OAuthAsyncCompletionHandler implements FutureCallback { @@ -23,7 +23,7 @@ public class OAuthAsyncCompletionHandler implements FutureCallback converter; private final CountDownLatch latch; private T result; - private Exception exception; + private Throwable exception; public OAuthAsyncCompletionHandler(OAuthAsyncRequestCallback callback, ResponseConverter converter) { this.callback = callback; @@ -41,8 +41,9 @@ public void completed(HttpResponse httpResponse) { final StatusLine statusLine = httpResponse.getStatusLine(); - final Response response = new Response(statusLine.getStatusCode(), statusLine.getReasonPhrase(), - headersMap, httpResponse.getEntity().getContent()); + final Response response = + new Response(statusLine.getStatusCode(), statusLine.getReasonPhrase(), headersMap, + httpResponse.getEntity().getContent()); @SuppressWarnings("unchecked") final T t = converter == null ? (T) response : converter.convert(response); @@ -50,7 +51,7 @@ public void completed(HttpResponse httpResponse) { if (callback != null) { callback.onCompleted(result); } - } catch (IOException e) { + } catch (Throwable e) { exception = e; if (callback != null) { callback.onThrowable(e); diff --git a/scribejava-httpclient-apache/src/test/java/com/github/scribejava/httpclient/apache/OauthAsyncCompletionHandlerTest.java b/scribejava-httpclient-apache/src/test/java/com/github/scribejava/httpclient/apache/OauthAsyncCompletionHandlerTest.java index 3b0065c06..12c4588f3 100644 --- a/scribejava-httpclient-apache/src/test/java/com/github/scribejava/httpclient/apache/OauthAsyncCompletionHandlerTest.java +++ b/scribejava-httpclient-apache/src/test/java/com/github/scribejava/httpclient/apache/OauthAsyncCompletionHandlerTest.java @@ -1,8 +1,16 @@ package com.github.scribejava.httpclient.apache; -import com.github.scribejava.core.model.OAuthAsyncRequestCallback; -import com.github.scribejava.core.model.OAuthRequest; -import com.github.scribejava.core.model.Response; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.util.concurrent.CancellationException; +import java.util.concurrent.ExecutionException; + import org.apache.http.HttpResponse; import org.apache.http.ProtocolVersion; import org.apache.http.entity.BasicHttpEntity; @@ -11,21 +19,17 @@ import org.junit.Before; import org.junit.Test; -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.util.concurrent.CancellationException; -import java.util.concurrent.ExecutionException; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import com.github.scribejava.core.exceptions.OAuthException; +import com.github.scribejava.core.model.OAuthAsyncRequestCallback; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Response; public class OauthAsyncCompletionHandlerTest { private static final AllGoodResponseConverter ALL_GOOD_RESPONSE_CONVERTER = new AllGoodResponseConverter(); private static final ExceptionResponseConverter EXCEPTION_RESPONSE_CONVERTER = new ExceptionResponseConverter(); + private static final OAuthExceptionResponseConverter OAUTH_EXCEPTION_RESPONSE_CONVERTER = + new OAuthExceptionResponseConverter(); private OAuthAsyncCompletionHandler handler; private TestCallback callback; @@ -63,8 +67,8 @@ public void setUp() { @Test public void shouldReleaseLatchOnSuccess() throws Exception { handler = new OAuthAsyncCompletionHandler<>(callback, ALL_GOOD_RESPONSE_CONVERTER); - final HttpResponse response = new BasicHttpResponse(new BasicStatusLine( - new ProtocolVersion("4", 1, 1), 200, "ok")); + final HttpResponse response = + new BasicHttpResponse(new BasicStatusLine(new ProtocolVersion("4", 1, 1), 200, "ok")); final BasicHttpEntity entity = new BasicHttpEntity(); entity.setContent(new ByteArrayInputStream(new byte[0])); response.setEntity(entity); @@ -78,8 +82,8 @@ public void shouldReleaseLatchOnSuccess() throws Exception { @Test public void shouldReleaseLatchOnIOException() throws Exception { handler = new OAuthAsyncCompletionHandler<>(callback, EXCEPTION_RESPONSE_CONVERTER); - final HttpResponse response = new BasicHttpResponse(new BasicStatusLine( - new ProtocolVersion("4", 1, 1), 200, "ok")); + final HttpResponse response = + new BasicHttpResponse(new BasicStatusLine(new ProtocolVersion("4", 1, 1), 200, "ok")); final BasicHttpEntity entity = new BasicHttpEntity(); entity.setContent(new ByteArrayInputStream(new byte[0])); response.setEntity(entity); @@ -96,11 +100,32 @@ public void shouldReleaseLatchOnIOException() throws Exception { } } + @Test + public void shouldReportOAuthException() throws Exception { + handler = new OAuthAsyncCompletionHandler<>(callback, OAUTH_EXCEPTION_RESPONSE_CONVERTER); + final HttpResponse response = + new BasicHttpResponse(new BasicStatusLine(new ProtocolVersion("4", 1, 1), 200, "ok")); + final BasicHttpEntity entity = new BasicHttpEntity(); + entity.setContent(new ByteArrayInputStream(new byte[0])); + response.setEntity(entity); + handler.completed(response); + assertNull(callback.getResponse()); + assertNotNull(callback.getThrowable()); + assertTrue(callback.getThrowable() instanceof OAuthException); + // verify latch is released + try { + handler.getResult(); + fail(); + } catch (ExecutionException expected) { + // expected + } + } + @Test public void shouldReleaseLatchOnCancel() throws Exception { handler = new OAuthAsyncCompletionHandler<>(callback, ALL_GOOD_RESPONSE_CONVERTER); - final HttpResponse response = new BasicHttpResponse(new BasicStatusLine( - new ProtocolVersion("4", 1, 1), 200, "ok")); + final HttpResponse response = + new BasicHttpResponse(new BasicStatusLine(new ProtocolVersion("4", 1, 1), 200, "ok")); final BasicHttpEntity entity = new BasicHttpEntity(); entity.setContent(new ByteArrayInputStream(new byte[0])); response.setEntity(entity); @@ -120,8 +145,8 @@ public void shouldReleaseLatchOnCancel() throws Exception { @Test public void shouldReleaseLatchOnFailure() throws Exception { handler = new OAuthAsyncCompletionHandler<>(callback, ALL_GOOD_RESPONSE_CONVERTER); - final HttpResponse response = new BasicHttpResponse(new BasicStatusLine( - new ProtocolVersion("4", 1, 1), 200, "ok")); + final HttpResponse response = + new BasicHttpResponse(new BasicStatusLine(new ProtocolVersion("4", 1, 1), 200, "ok")); final BasicHttpEntity entity = new BasicHttpEntity(); entity.setContent(new ByteArrayInputStream(new byte[0])); response.setEntity(entity); @@ -153,4 +178,12 @@ public String convert(Response response) throws IOException { throw new IOException("Failed to convert"); } } + + private static class OAuthExceptionResponseConverter implements OAuthRequest.ResponseConverter { + + @Override + public String convert(Response response) throws IOException { + throw new OAuthException("bad oauth"); + } + } } From d7597b46f1384c7308ac28429d9a955ddeb71649 Mon Sep 17 00:00:00 2001 From: Jochen Klein Date: Fri, 27 Jul 2018 17:36:49 +0200 Subject: [PATCH 499/882] deliver OAuth exceptions from OAuthAsyncCompletionHandler - ning http client --- .../ning/OAuthAsyncCompletionHandler.java | 17 ++- .../httpclient/ning/MockResponse.java | 132 ++++++++++++++++++ .../ning/OauthAsyncCompletionHandlerTest.java | 98 +++++++++++++ 3 files changed, 241 insertions(+), 6 deletions(-) create mode 100644 scribejava-httpclient-ning/src/test/java/com/github/scribejava/httpclient/ning/MockResponse.java create mode 100644 scribejava-httpclient-ning/src/test/java/com/github/scribejava/httpclient/ning/OauthAsyncCompletionHandlerTest.java diff --git a/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/OAuthAsyncCompletionHandler.java b/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/OAuthAsyncCompletionHandler.java index c0aa14ecd..f4122c1e9 100644 --- a/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/OAuthAsyncCompletionHandler.java +++ b/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/OAuthAsyncCompletionHandler.java @@ -35,12 +35,17 @@ public T onCompleted(com.ning.http.client.Response ningResponse) throws IOExcept final Response response = new Response(ningResponse.getStatusCode(), ningResponse.getStatusText(), headersMap, ningResponse.getResponseBodyAsStream()); - @SuppressWarnings("unchecked") - final T t = converter == null ? (T) response : converter.convert(response); - if (callback != null) { - callback.onCompleted(t); + try { + @SuppressWarnings("unchecked") + final T t = converter == null ? (T) response : converter.convert(response); + if (callback != null) { + callback.onCompleted(t); + } + return t; + } catch (Throwable t) { + onThrowable(t); + return null; } - return t; } @Override @@ -49,4 +54,4 @@ public void onThrowable(Throwable t) { callback.onThrowable(t); } } -}; +} diff --git a/scribejava-httpclient-ning/src/test/java/com/github/scribejava/httpclient/ning/MockResponse.java b/scribejava-httpclient-ning/src/test/java/com/github/scribejava/httpclient/ning/MockResponse.java new file mode 100644 index 000000000..c432d9ed2 --- /dev/null +++ b/scribejava-httpclient-ning/src/test/java/com/github/scribejava/httpclient/ning/MockResponse.java @@ -0,0 +1,132 @@ +package com.github.scribejava.httpclient.ning; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.nio.ByteBuffer; +import java.util.List; + +import com.ning.http.client.FluentCaseInsensitiveStringsMap; +import com.ning.http.client.Response; +import com.ning.http.client.cookie.Cookie; +import com.ning.http.client.uri.Uri; + +/** + * + */ +public class MockResponse implements Response { + + private final int statusCode; + private final String statusText; + private final FluentCaseInsensitiveStringsMap headers; + private final byte[] body; + + /** + * @param statusCode + * @param statusText + * @param body + */ + public MockResponse(int statusCode, String statusText, FluentCaseInsensitiveStringsMap headers, + byte[] body) { + super(); + this.statusCode = statusCode; + this.statusText = statusText; + this.headers = headers; + this.body = body; + } + + @Override + public int getStatusCode() { + return statusCode; + } + + @Override + public String getStatusText() { + return statusText; + } + + @Override + public byte[] getResponseBodyAsBytes() throws IOException { + return body; + } + + @Override + public ByteBuffer getResponseBodyAsByteBuffer() throws IOException { + throw new UnsupportedOperationException(); + } + + @Override + public InputStream getResponseBodyAsStream() throws IOException { + return new ByteArrayInputStream(getResponseBodyAsBytes()); + } + + @Override + public String getResponseBodyExcerpt(final int maxLength, final String charset) throws IOException { + throw new UnsupportedOperationException(); + } + + @Override + public String getResponseBodyExcerpt(final int maxLength) throws IOException { + throw new UnsupportedOperationException(); + } + + @Override + public String getResponseBody(final String charset) throws IOException { + throw new UnsupportedOperationException(); + } + + @Override + public String getResponseBody() throws IOException { + throw new UnsupportedOperationException(); + } + + @Override + public Uri getUri() { + throw new UnsupportedOperationException(); + } + + @Override + public String getContentType() { + throw new UnsupportedOperationException(); + } + + @Override + public String getHeader(final String name) { + return headers.getFirstValue(name); + } + + @Override + public List getHeaders(final String name) { + return headers.get(name); + } + + @Override + public FluentCaseInsensitiveStringsMap getHeaders() { + return headers; + } + + @Override + public boolean isRedirected() { + throw new UnsupportedOperationException(); + } + + @Override + public List getCookies() { + throw new UnsupportedOperationException(); + } + + @Override + public boolean hasResponseStatus() { + return true; + } + + @Override + public boolean hasResponseHeaders() { + return !this.headers.isEmpty(); + } + + @Override + public boolean hasResponseBody() { + return body != null && body.length > 0; + } +} diff --git a/scribejava-httpclient-ning/src/test/java/com/github/scribejava/httpclient/ning/OauthAsyncCompletionHandlerTest.java b/scribejava-httpclient-ning/src/test/java/com/github/scribejava/httpclient/ning/OauthAsyncCompletionHandlerTest.java new file mode 100644 index 000000000..efc516d68 --- /dev/null +++ b/scribejava-httpclient-ning/src/test/java/com/github/scribejava/httpclient/ning/OauthAsyncCompletionHandlerTest.java @@ -0,0 +1,98 @@ +package com.github.scribejava.httpclient.ning; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import java.io.IOException; + +import org.junit.Before; +import org.junit.Test; + +import com.github.scribejava.core.exceptions.OAuthException; +import com.github.scribejava.core.model.OAuthAsyncRequestCallback; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Response; +import com.ning.http.client.FluentCaseInsensitiveStringsMap; + +public class OauthAsyncCompletionHandlerTest { + + private static final AllGoodResponseConverter ALL_GOOD_RESPONSE_CONVERTER = new AllGoodResponseConverter(); + private static final OAuthExceptionResponseConverter OAUTH_EXCEPTION_RESPONSE_CONVERTER = + new OAuthExceptionResponseConverter(); + + private OAuthAsyncCompletionHandler handler; + private TestCallback callback; + + private static class TestCallback implements OAuthAsyncRequestCallback { + + private Throwable throwable; + private String response; + + @Override + public void onCompleted(String response) { + this.response = response; + } + + @Override + public void onThrowable(Throwable throwable) { + this.throwable = throwable; + } + + public Throwable getThrowable() { + return throwable; + } + + public String getResponse() { + return response; + } + + } + + @Before + public void setUp() { + callback = new TestCallback(); + } + + @Test + public void shouldReleaseLatchOnSuccess() throws Exception { + handler = new OAuthAsyncCompletionHandler<>(callback, ALL_GOOD_RESPONSE_CONVERTER); + + final com.ning.http.client.Response response = + new MockResponse(200, "ok", new FluentCaseInsensitiveStringsMap(), new byte[0]); + handler.onCompleted(response); + assertNotNull(callback.getResponse()); + assertNull(callback.getThrowable()); + // verify latch is released + assertEquals("All good", callback.getResponse()); + } + + @Test + public void shouldReportOAuthException() throws Exception { + handler = new OAuthAsyncCompletionHandler<>(callback, OAUTH_EXCEPTION_RESPONSE_CONVERTER); + + final com.ning.http.client.Response response = + new MockResponse(200, "ok", new FluentCaseInsensitiveStringsMap(), new byte[0]); + handler.onCompleted(response); + assertNull(callback.getResponse()); + assertNotNull(callback.getThrowable()); + assertTrue(callback.getThrowable() instanceof OAuthException); + } + + private static class AllGoodResponseConverter implements OAuthRequest.ResponseConverter { + + @Override + public String convert(Response response) throws IOException { + return "All good"; + } + } + + private static class OAuthExceptionResponseConverter implements OAuthRequest.ResponseConverter { + + @Override + public String convert(Response response) throws IOException { + throw new OAuthException("bad oauth"); + } + } +} From b1afe2ffc3648908f5114b933243ec3b478aa1f9 Mon Sep 17 00:00:00 2001 From: Jochen Klein Date: Fri, 27 Jul 2018 17:37:02 +0200 Subject: [PATCH 500/882] deliver OAuth exceptions from OAuthAsyncCompletionHandler - ok http client --- .../okhttp/OAuthAsyncCompletionHandler.java | 19 +- .../httpclient/okhttp/OkHttpFuture.java | 15 +- .../httpclient/okhttp/MockCall.java | 66 ++++++ .../OauthAsyncCompletionHandlerTest.java | 189 ++++++++++++++++++ 4 files changed, 281 insertions(+), 8 deletions(-) create mode 100644 scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/MockCall.java create mode 100644 scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/OauthAsyncCompletionHandlerTest.java diff --git a/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OAuthAsyncCompletionHandler.java b/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OAuthAsyncCompletionHandler.java index af59abbb5..bd613138a 100644 --- a/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OAuthAsyncCompletionHandler.java +++ b/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OAuthAsyncCompletionHandler.java @@ -24,6 +24,7 @@ class OAuthAsyncCompletionHandler implements Callback { @Override public void onFailure(Call call, IOException e) { try { + this.okHttpFuture.setError(e); if (callback != null) { callback.onThrowable(e); } @@ -37,12 +38,18 @@ public void onResponse(Call call, okhttp3.Response okHttpResponse) throws IOExce try { final Response response = OkHttpHttpClient.convertResponse(okHttpResponse); - - @SuppressWarnings("unchecked") - final T t = converter == null ? (T) response : converter.convert(response); - okHttpFuture.setResult(t); - if (callback != null) { - callback.onCompleted(t); + try { + @SuppressWarnings("unchecked") + final T t = converter == null ? (T) response : converter.convert(response); + okHttpFuture.setResult(t); + if (callback != null) { + callback.onCompleted(t); + } + } catch (Throwable t) { + okHttpFuture.setError(t); + if (callback != null) { + callback.onThrowable(t); + } } } finally { okHttpFuture.finish(); diff --git a/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpFuture.java b/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpFuture.java index ebf459260..a75617dd4 100644 --- a/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpFuture.java +++ b/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpFuture.java @@ -5,6 +5,7 @@ import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; + import okhttp3.Call; public class OkHttpFuture implements Future { @@ -12,6 +13,7 @@ public class OkHttpFuture implements Future { private final CountDownLatch latch = new CountDownLatch(1); private final Call call; private T result; + private Throwable t; public OkHttpFuture(Call call) { this.call = call; @@ -33,19 +35,28 @@ public boolean isDone() { return call.isExecuted(); } + public void setError(Throwable t) { + this.t = t; + } + @Override public T get() throws InterruptedException, ExecutionException { latch.await(); + if (t != null) { + throw new ExecutionException(t); + } return result; } @Override public T get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { if (latch.await(timeout, unit)) { + if (t != null) { + throw new ExecutionException(t); + } return result; - } else { - throw new TimeoutException(); } + throw new TimeoutException(); } void finish() { diff --git a/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/MockCall.java b/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/MockCall.java new file mode 100644 index 000000000..9b4b1d447 --- /dev/null +++ b/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/MockCall.java @@ -0,0 +1,66 @@ +package com.github.scribejava.httpclient.okhttp; + +import java.io.IOException; +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.Method; +import java.lang.reflect.Proxy; +import java.util.ArrayList; +import java.util.Collection; + +import okhttp3.Call; +import okhttp3.Callback; + +/** + * the only reason, this is a dynamic proxy is, that checkstyle forbids implementing clone()! + */ +public class MockCall implements InvocationHandler { + + private final Collection callbacks; + private boolean canceled; + + public MockCall() { + this(new ArrayList()); + } + + private MockCall(Collection callbacks) { + this.callbacks = new ArrayList<>(callbacks); + } + + public void enqueue(Callback responseCallback) { + callbacks.add(responseCallback); + } + + public void cancel(Call proxy) { + canceled = true; + for (Callback callback : callbacks) { + callback.onFailure(proxy, new IOException("Canceled")); + } + } + + public boolean isCanceled() { + return canceled; + } + + @Override + public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { + switch (method.getName()) { + case "enqueue": + enqueue((Callback) args[0]); + return null; + case "cancel": + cancel((Call) proxy); + return null; + case "isCanceled": + return isCanceled(); + default: + throw new UnsupportedOperationException(method.toString()); + } + } + + /** + * @return + */ + public static Call create() { + return (Call) Proxy.newProxyInstance(Call.class.getClassLoader(), new Class[] { Call.class }, new MockCall()); + } +} diff --git a/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/OauthAsyncCompletionHandlerTest.java b/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/OauthAsyncCompletionHandlerTest.java new file mode 100644 index 000000000..5181487ff --- /dev/null +++ b/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/OauthAsyncCompletionHandlerTest.java @@ -0,0 +1,189 @@ +package com.github.scribejava.httpclient.okhttp; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.io.IOException; +import java.util.concurrent.ExecutionException; + +import org.junit.Before; +import org.junit.Test; + +import com.github.scribejava.core.exceptions.OAuthException; +import com.github.scribejava.core.model.OAuthAsyncRequestCallback; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Response; + +import okhttp3.Call; +import okhttp3.MediaType; +import okhttp3.Protocol; +import okhttp3.Request; +import okhttp3.ResponseBody; + +public class OauthAsyncCompletionHandlerTest { + + private static final AllGoodResponseConverter ALL_GOOD_RESPONSE_CONVERTER = new AllGoodResponseConverter(); + private static final ExceptionResponseConverter EXCEPTION_RESPONSE_CONVERTER = new ExceptionResponseConverter(); + private static final OAuthExceptionResponseConverter OAUTH_EXCEPTION_RESPONSE_CONVERTER = + new OAuthExceptionResponseConverter(); + + private OAuthAsyncCompletionHandler handler; + private Call call; + private OkHttpFuture future; + private TestCallback callback; + + private static class TestCallback implements OAuthAsyncRequestCallback { + + private Throwable throwable; + private String response; + + @Override + public void onCompleted(String response) { + this.response = response; + } + + @Override + public void onThrowable(Throwable throwable) { + this.throwable = throwable; + } + + public Throwable getThrowable() { + return throwable; + } + + public String getResponse() { + return response; + } + + } + + @Before + public void setUp() { + callback = new TestCallback(); + call = MockCall.create(); + future = new OkHttpFuture<>(call); + } + + @Test + public void shouldReleaseLatchOnSuccess() throws Exception { + handler = new OAuthAsyncCompletionHandler<>(callback, ALL_GOOD_RESPONSE_CONVERTER, future); + call.enqueue(handler); + + final okhttp3.Request request = new Request.Builder().url("http://localhost/").build(); + final okhttp3.Response response = + new okhttp3.Response.Builder().request(request).protocol(Protocol.HTTP_1_1).code(200).message("ok") + .body(ResponseBody.create(MediaType.get("text/plain"), new byte[0])).build(); + handler.onResponse(call, response); + assertNotNull(callback.getResponse()); + assertNull(callback.getThrowable()); + // verify latch is released + assertEquals("All good", future.get()); + } + + @Test + public void shouldReleaseLatchOnIOException() throws Exception { + handler = new OAuthAsyncCompletionHandler<>(callback, EXCEPTION_RESPONSE_CONVERTER, future); + call.enqueue(handler); + + final okhttp3.Request request = new Request.Builder().url("http://localhost/").build(); + final okhttp3.Response response = + new okhttp3.Response.Builder().request(request).protocol(Protocol.HTTP_1_1).code(200).message("ok") + .body(ResponseBody.create(MediaType.get("text/plain"), new byte[0])).build(); + handler.onResponse(call, response); + assertNull(callback.getResponse()); + assertNotNull(callback.getThrowable()); + assertTrue(callback.getThrowable() instanceof IOException); + // verify latch is released + try { + future.get(); + fail(); + } catch (ExecutionException expected) { + // expected + } + } + + @Test + public void shouldReportOAuthException() throws Exception { + handler = new OAuthAsyncCompletionHandler<>(callback, OAUTH_EXCEPTION_RESPONSE_CONVERTER, future); + call.enqueue(handler); + + final okhttp3.Request request = new Request.Builder().url("http://localhost/").build(); + final okhttp3.Response response = + new okhttp3.Response.Builder().request(request).protocol(Protocol.HTTP_1_1).code(200).message("ok") + .body(ResponseBody.create(MediaType.get("text/plain"), new byte[0])).build(); + handler.onResponse(call, response); + assertNull(callback.getResponse()); + assertNotNull(callback.getThrowable()); + assertTrue(callback.getThrowable() instanceof OAuthException); + // verify latch is released + try { + future.get(); + fail(); + } catch (ExecutionException expected) { + // expected + } + } + + @Test + public void shouldReleaseLatchOnCancel() throws Exception { + handler = new OAuthAsyncCompletionHandler<>(callback, ALL_GOOD_RESPONSE_CONVERTER, future); + call.enqueue(handler); + + future.cancel(true); + assertNull(callback.getResponse()); + assertNotNull(callback.getThrowable()); + assertTrue(callback.getThrowable() instanceof IOException); + // verify latch is released + try { + future.get(); + fail(); + } catch (ExecutionException expected) { + // expected + } + } + + @Test + public void shouldReleaseLatchOnFailure() throws Exception { + handler = new OAuthAsyncCompletionHandler<>(callback, ALL_GOOD_RESPONSE_CONVERTER, future); + call.enqueue(handler); + + handler.onFailure(call, new IOException()); + assertNull(callback.getResponse()); + assertNotNull(callback.getThrowable()); + assertTrue(callback.getThrowable() instanceof IOException); + // verify latch is released + try { + future.get(); + fail(); + } catch (ExecutionException expected) { + // expected + } + } + + private static class AllGoodResponseConverter implements OAuthRequest.ResponseConverter { + + @Override + public String convert(Response response) throws IOException { + return "All good"; + } + } + + private static class ExceptionResponseConverter implements OAuthRequest.ResponseConverter { + + @Override + public String convert(Response response) throws IOException { + throw new IOException("Failed to convert"); + } + } + + private static class OAuthExceptionResponseConverter implements OAuthRequest.ResponseConverter { + + @Override + public String convert(Response response) throws IOException { + throw new OAuthException("bad oauth"); + } + } +} From 55fbe2f6f3d8e2df50953956de51644812d31ce7 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 3 Aug 2018 17:03:28 +0300 Subject: [PATCH 501/882] switch OAuth2 ClientAuthenticationType from enum to interface to be extensible according to https://tools.ietf.org/html/rfc6749#section-2.3.2 (thanks to https://github.com/zawn) --- changelog | 2 + .../github/scribejava/apis/AutomaticAPI.java | 8 +-- .../github/scribejava/apis/FacebookApi.java | 7 ++- .../com/github/scribejava/apis/HHApi.java | 7 ++- .../github/scribejava/apis/LinkedInApi20.java | 7 ++- .../MicrosoftAzureActiveDirectoryApi.java | 7 ++- .../scribejava/apis/OdnoklassnikiApi.java | 7 ++- .../github/scribejava/apis/PinterestApi.java | 7 ++- .../github/scribejava/apis/SalesforceApi.java | 7 ++- .../github/scribejava/apis/VkontakteApi.java | 7 ++- .../builder/api/ClientAuthenticationType.java | 60 +++++++++---------- .../core/builder/api/DefaultApi20.java | 18 ++++++ .../scribejava/core/oauth/OAuth20Service.java | 10 ++-- .../ClientAuthentication.java | 17 ++++++ .../HttpBasicAuthenticationScheme.java | 40 +++++++++++++ .../RequestBodyAuthenticationScheme.java | 34 +++++++++++ 16 files changed, 179 insertions(+), 66 deletions(-) create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/oauth2/clientauthentication/ClientAuthentication.java create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/oauth2/clientauthentication/HttpBasicAuthenticationScheme.java create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/oauth2/clientauthentication/RequestBodyAuthenticationScheme.java diff --git a/changelog b/changelog index 0397fd622..c1a5c41f1 100644 --- a/changelog +++ b/changelog @@ -1,5 +1,7 @@ [SNAPSHOT] * add Multipart functionality to JDK Http Client (thanks to https://github.com/eos1d3) + * switch OAuth2 ClientAuthenticationType from enum to interface to be extensible according to + https://tools.ietf.org/html/rfc6749#section-2.3.2 (thanks to https://github.com/zawn) [5.5.0] * fix error parsing for Fitbit (thanks to https://github.com/danmana) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/AutomaticAPI.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/AutomaticAPI.java index 479fc5d59..58c82e040 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/AutomaticAPI.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/AutomaticAPI.java @@ -1,7 +1,8 @@ package com.github.scribejava.apis; -import com.github.scribejava.core.builder.api.ClientAuthenticationType; import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.oauth2.clientauthentication.ClientAuthentication; +import com.github.scribejava.core.oauth2.clientauthentication.RequestBodyAuthenticationScheme; public class AutomaticAPI extends DefaultApi20 { @@ -37,8 +38,7 @@ protected String getAuthorizationBaseUrl() { } @Override - public ClientAuthenticationType getClientAuthenticationType() { - return ClientAuthenticationType.REQUEST_BODY; + public ClientAuthentication getClientAuthentication() { + return RequestBodyAuthenticationScheme.instance(); } - } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java index 463a44d6c..fb0668eb1 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java @@ -2,13 +2,14 @@ import com.github.scribejava.apis.facebook.FacebookAccessTokenJsonExtractor; import com.github.scribejava.apis.service.FacebookService; -import com.github.scribejava.core.builder.api.ClientAuthenticationType; import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.extractors.TokenExtractor; import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.httpclient.HttpClientConfig; import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.oauth2.clientauthentication.ClientAuthentication; +import com.github.scribejava.core.oauth2.clientauthentication.RequestBodyAuthenticationScheme; import java.io.OutputStream; /** @@ -65,8 +66,8 @@ public TokenExtractor getAccessTokenExtractor() { } @Override - public ClientAuthenticationType getClientAuthenticationType() { - return ClientAuthenticationType.REQUEST_BODY; + public ClientAuthentication getClientAuthentication() { + return RequestBodyAuthenticationScheme.instance(); } @Override diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/HHApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/HHApi.java index f1f307155..bd1224fe6 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/HHApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/HHApi.java @@ -1,7 +1,8 @@ package com.github.scribejava.apis; -import com.github.scribejava.core.builder.api.ClientAuthenticationType; import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.oauth2.clientauthentication.ClientAuthentication; +import com.github.scribejava.core.oauth2.clientauthentication.RequestBodyAuthenticationScheme; public class HHApi extends DefaultApi20 { @@ -27,7 +28,7 @@ protected String getAuthorizationBaseUrl() { } @Override - public ClientAuthenticationType getClientAuthenticationType() { - return ClientAuthenticationType.REQUEST_BODY; + public ClientAuthentication getClientAuthentication() { + return RequestBodyAuthenticationScheme.instance(); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi20.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi20.java index 97f78b354..36d4ab702 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi20.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi20.java @@ -1,7 +1,8 @@ package com.github.scribejava.apis; -import com.github.scribejava.core.builder.api.ClientAuthenticationType; import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.oauth2.clientauthentication.ClientAuthentication; +import com.github.scribejava.core.oauth2.clientauthentication.RequestBodyAuthenticationScheme; public class LinkedInApi20 extends DefaultApi20 { @@ -27,7 +28,7 @@ protected String getAuthorizationBaseUrl() { } @Override - public ClientAuthenticationType getClientAuthenticationType() { - return ClientAuthenticationType.REQUEST_BODY; + public ClientAuthentication getClientAuthentication() { + return RequestBodyAuthenticationScheme.instance(); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/MicrosoftAzureActiveDirectoryApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/MicrosoftAzureActiveDirectoryApi.java index 223a88b1c..2c793ae14 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/MicrosoftAzureActiveDirectoryApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/MicrosoftAzureActiveDirectoryApi.java @@ -1,10 +1,11 @@ package com.github.scribejava.apis; import com.github.scribejava.apis.service.MicrosoftAzureActiveDirectoryService; -import com.github.scribejava.core.builder.api.ClientAuthenticationType; import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.httpclient.HttpClientConfig; +import com.github.scribejava.core.oauth2.clientauthentication.ClientAuthentication; +import com.github.scribejava.core.oauth2.clientauthentication.RequestBodyAuthenticationScheme; import java.io.OutputStream; /** @@ -57,7 +58,7 @@ public MicrosoftAzureActiveDirectoryService createService(String apiKey, String } @Override - public ClientAuthenticationType getClientAuthenticationType() { - return ClientAuthenticationType.REQUEST_BODY; + public ClientAuthentication getClientAuthentication() { + return RequestBodyAuthenticationScheme.instance(); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java index c21983fa3..e7db8838d 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java @@ -1,11 +1,12 @@ package com.github.scribejava.apis; import com.github.scribejava.apis.service.OdnoklassnikiOAuthService; -import com.github.scribejava.core.builder.api.ClientAuthenticationType; import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.builder.api.OAuth2SignatureType; import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.httpclient.HttpClientConfig; +import com.github.scribejava.core.oauth2.clientauthentication.ClientAuthentication; +import com.github.scribejava.core.oauth2.clientauthentication.RequestBodyAuthenticationScheme; import java.io.OutputStream; public class OdnoklassnikiApi extends DefaultApi20 { @@ -45,7 +46,7 @@ public OAuth2SignatureType getSignatureType() { } @Override - public ClientAuthenticationType getClientAuthenticationType() { - return ClientAuthenticationType.REQUEST_BODY; + public ClientAuthentication getClientAuthentication() { + return RequestBodyAuthenticationScheme.instance(); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/PinterestApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/PinterestApi.java index f915aa605..70ef1caff 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/PinterestApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/PinterestApi.java @@ -1,7 +1,8 @@ package com.github.scribejava.apis; -import com.github.scribejava.core.builder.api.ClientAuthenticationType; import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.oauth2.clientauthentication.ClientAuthentication; +import com.github.scribejava.core.oauth2.clientauthentication.RequestBodyAuthenticationScheme; public class PinterestApi extends DefaultApi20 { @@ -27,7 +28,7 @@ protected String getAuthorizationBaseUrl() { } @Override - public ClientAuthenticationType getClientAuthenticationType() { - return ClientAuthenticationType.REQUEST_BODY; + public ClientAuthentication getClientAuthentication() { + return RequestBodyAuthenticationScheme.instance(); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/SalesforceApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/SalesforceApi.java index 0b1c3c11f..afd2eae5f 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/SalesforceApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/SalesforceApi.java @@ -3,11 +3,12 @@ import javax.net.ssl.SSLContext; import com.github.scribejava.apis.salesforce.SalesforceJsonTokenExtractor; -import com.github.scribejava.core.builder.api.ClientAuthenticationType; import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.extractors.TokenExtractor; import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.oauth2.clientauthentication.ClientAuthentication; +import com.github.scribejava.core.oauth2.clientauthentication.RequestBodyAuthenticationScheme; import java.io.IOException; import java.security.KeyManagementException; import java.security.NoSuchAlgorithmException; @@ -132,7 +133,7 @@ public static void initTLSv11orUpper() throws NoSuchAlgorithmException, KeyManag } @Override - public ClientAuthenticationType getClientAuthenticationType() { - return ClientAuthenticationType.REQUEST_BODY; + public ClientAuthentication getClientAuthentication() { + return RequestBodyAuthenticationScheme.instance(); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/VkontakteApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/VkontakteApi.java index 1654ff34a..ff11d902c 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/VkontakteApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/VkontakteApi.java @@ -1,12 +1,13 @@ package com.github.scribejava.apis; import com.github.scribejava.apis.vk.VKJsonTokenExtractor; -import com.github.scribejava.core.builder.api.ClientAuthenticationType; import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.builder.api.OAuth2SignatureType; import com.github.scribejava.core.extractors.TokenExtractor; import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.oauth2.clientauthentication.ClientAuthentication; +import com.github.scribejava.core.oauth2.clientauthentication.RequestBodyAuthenticationScheme; public class VkontakteApi extends DefaultApi20 { @@ -45,8 +46,8 @@ public OAuth2SignatureType getSignatureType() { } @Override - public ClientAuthenticationType getClientAuthenticationType() { - return ClientAuthenticationType.REQUEST_BODY; + public ClientAuthentication getClientAuthentication() { + return RequestBodyAuthenticationScheme.instance(); } @Override diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/ClientAuthenticationType.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/ClientAuthenticationType.java index 2faa81d46..097ba1081 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/ClientAuthenticationType.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/ClientAuthenticationType.java @@ -1,9 +1,8 @@ package com.github.scribejava.core.builder.api; -import com.github.scribejava.core.java8.Base64; -import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.OAuthRequest; -import java.nio.charset.Charset; +import com.github.scribejava.core.oauth2.clientauthentication.HttpBasicAuthenticationScheme; +import com.github.scribejava.core.oauth2.clientauthentication.RequestBodyAuthenticationScheme; /** * Represents
@@ -11,37 +10,32 @@ * https://tools.ietf.org/html/rfc6749#section-2.3
* in it's part 2.3.1. Client Password
* https://tools.ietf.org/html/rfc6749#section-2.3.1 + * + * @deprecated use {@link com.github.scribejava.core.oauth2.clientauthentication.ClientAuthentication} */ -public abstract class ClientAuthenticationType { +@Deprecated +public enum ClientAuthenticationType { + /** + * @deprecated use {@link com.github.scribejava.core.oauth2.clientauthentication.HttpBasicAuthenticationScheme} + */ + @Deprecated + HTTP_BASIC_AUTHENTICATION_SCHEME { - public static final ClientAuthenticationType HTTP_BASIC_AUTHENTICATION_SCHEME = - new ClientAuthenticationType() { - private final Base64.Encoder base64Encoder = Base64.getEncoder(); + @Override + public void addClientAuthentication(OAuthRequest request, String apiKey, String apiSecret) { + HttpBasicAuthenticationScheme.instance().addClientAuthentication(request, apiKey, apiSecret); + } + }, + /** + * @deprecated use {@link com.github.scribejava.core.oauth2.clientauthentication.RequestBodyAuthenticationScheme} + */ + @Deprecated + REQUEST_BODY { + @Override + public void addClientAuthentication(OAuthRequest request, String apiKey, String apiSecret) { + RequestBodyAuthenticationScheme.instance().addClientAuthentication(request, apiKey, apiSecret); + } + }; - @Override - public void addClientAuthentication(OAuthRequest request, String apiKey, - String apiSecret) { - if (apiKey != null && apiSecret != null) { - request.addHeader(OAuthConstants.HEADER, OAuthConstants.BASIC + ' ' - + base64Encoder.encodeToString( - String.format("%s:%s", apiKey, apiSecret).getBytes(Charset.forName("UTF-8")))); - } - } - }; - - public static final ClientAuthenticationType REQUEST_BODY = - new ClientAuthenticationType() { - - @Override - public void addClientAuthentication(OAuthRequest request, String apiKey, - String apiSecret) { - request.addParameter(OAuthConstants.CLIENT_ID, apiKey); - if (apiSecret != null) { - request.addParameter(OAuthConstants.CLIENT_SECRET, apiSecret); - } - } - }; - - public abstract void addClientAuthentication(OAuthRequest request, String apiKey, - String apiSecret); + public abstract void addClientAuthentication(OAuthRequest request, String apiKey, String apiSecret); } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java index 5555faac3..b429142a6 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java @@ -9,6 +9,9 @@ import com.github.scribejava.core.model.ParameterList; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.oauth.OAuth20Service; +import com.github.scribejava.core.oauth2.clientauthentication.ClientAuthentication; +import com.github.scribejava.core.oauth2.clientauthentication.HttpBasicAuthenticationScheme; +import com.github.scribejava.core.oauth2.clientauthentication.RequestBodyAuthenticationScheme; import java.io.OutputStream; import java.util.Map; @@ -109,6 +112,21 @@ public OAuth2SignatureType getSignatureType() { return OAuth2SignatureType.BEARER_AUTHORIZATION_REQUEST_HEADER_FIELD; } + public ClientAuthentication getClientAuthentication() { + switch (getClientAuthenticationType()) { + case HTTP_BASIC_AUTHENTICATION_SCHEME: + return HttpBasicAuthenticationScheme.instance(); + case REQUEST_BODY: + return RequestBodyAuthenticationScheme.instance(); + default: + throw new IllegalStateException("there was no such Client Authentication Type"); + } + } + + /** + * @deprecated use {@link #getClientAuthentication() } + */ + @Deprecated public ClientAuthenticationType getClientAuthenticationType() { return ClientAuthenticationType.HTTP_BASIC_AUTHENTICATION_SCHEME; } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java index 80a46dbe1..5b10849af 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java @@ -105,7 +105,7 @@ public Future getAccessToken(String code, protected OAuthRequest createAccessTokenRequest(String code) { final OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint()); - api.getClientAuthenticationType().addClientAuthentication(request, getApiKey(), getApiSecret()); + api.getClientAuthentication().addClientAuthentication(request, getApiKey(), getApiSecret()); request.addParameter(OAuthConstants.CODE, code); request.addParameter(OAuthConstants.REDIRECT_URI, getCallback()); @@ -149,7 +149,7 @@ protected OAuthRequest createRefreshTokenRequest(String refreshToken) { } final OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getRefreshTokenEndpoint()); - api.getClientAuthenticationType().addClientAuthentication(request, getApiKey(), getApiSecret()); + api.getClientAuthentication().addClientAuthentication(request, getApiKey(), getApiSecret()); final String scope = getScope(); if (scope != null) { @@ -199,7 +199,7 @@ protected OAuthRequest createAccessTokenPasswordGrantRequest(String username, St request.addParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.PASSWORD); - api.getClientAuthenticationType().addClientAuthentication(request, getApiKey(), getApiSecret()); + api.getClientAuthentication().addClientAuthentication(request, getApiKey(), getApiSecret()); return request; } @@ -232,7 +232,7 @@ public Future getAccessTokenClientCredentialsGrant( protected OAuthRequest createAccessTokenClientCredentialsGrantRequest() { final OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint()); - api.getClientAuthenticationType().addClientAuthentication(request, getApiKey(), getApiSecret()); + api.getClientAuthentication().addClientAuthentication(request, getApiKey(), getApiSecret()); final String scope = getScope(); if (scope != null) { @@ -308,7 +308,7 @@ public DefaultApi20 getApi() { protected OAuthRequest createRevokeTokenRequest(String tokenToRevoke, TokenTypeHint tokenTypeHint) { final OAuthRequest request = new OAuthRequest(Verb.POST, api.getRevokeTokenEndpoint()); - api.getClientAuthenticationType().addClientAuthentication(request, getApiKey(), getApiSecret()); + api.getClientAuthentication().addClientAuthentication(request, getApiKey(), getApiSecret()); request.addParameter("token", tokenToRevoke); if (tokenTypeHint != null) { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth2/clientauthentication/ClientAuthentication.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth2/clientauthentication/ClientAuthentication.java new file mode 100644 index 000000000..54fdb5de6 --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth2/clientauthentication/ClientAuthentication.java @@ -0,0 +1,17 @@ +package com.github.scribejava.core.oauth2.clientauthentication; + +import com.github.scribejava.core.model.OAuthRequest; + +/** + * Represents
+ * 2.3. Client Authentication
+ * https://tools.ietf.org/html/rfc6749#section-2.3 + *
+ * just implement this interface to implement "2.3.2. Other Authentication Methods"
+ * https://tools.ietf.org/html/rfc6749#section-2.3.2 + * + */ +public interface ClientAuthentication { + + void addClientAuthentication(OAuthRequest request, String apiKey, String apiSecret); +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth2/clientauthentication/HttpBasicAuthenticationScheme.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth2/clientauthentication/HttpBasicAuthenticationScheme.java new file mode 100644 index 000000000..509869d51 --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth2/clientauthentication/HttpBasicAuthenticationScheme.java @@ -0,0 +1,40 @@ +package com.github.scribejava.core.oauth2.clientauthentication; + +import com.github.scribejava.core.java8.Base64; +import com.github.scribejava.core.model.OAuthConstants; +import com.github.scribejava.core.model.OAuthRequest; +import java.nio.charset.Charset; + +/** + * 2.3. Client Authentication
+ * 2.3.1. Client Password
+ * https://tools.ietf.org/html/rfc6749#section-2.3.1 + *
+ * НTTP Basic authentication scheme + */ +public class HttpBasicAuthenticationScheme implements ClientAuthentication { + + private final Base64.Encoder base64Encoder = Base64.getEncoder(); + + protected HttpBasicAuthenticationScheme() { + } + + private static class InstanceHolder { + + private static final HttpBasicAuthenticationScheme INSTANCE = new HttpBasicAuthenticationScheme(); + } + + public static HttpBasicAuthenticationScheme instance() { + return InstanceHolder.INSTANCE; + } + + @Override + public void addClientAuthentication(OAuthRequest request, String apiKey, String apiSecret) { + if (apiKey != null && apiSecret != null) { + request.addHeader(OAuthConstants.HEADER, OAuthConstants.BASIC + ' ' + + base64Encoder.encodeToString( + String.format("%s:%s", apiKey, apiSecret).getBytes(Charset.forName("UTF-8")))); + } + } + +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth2/clientauthentication/RequestBodyAuthenticationScheme.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth2/clientauthentication/RequestBodyAuthenticationScheme.java new file mode 100644 index 000000000..5e91affa7 --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth2/clientauthentication/RequestBodyAuthenticationScheme.java @@ -0,0 +1,34 @@ +package com.github.scribejava.core.oauth2.clientauthentication; + +import com.github.scribejava.core.model.OAuthConstants; +import com.github.scribejava.core.model.OAuthRequest; + +/** + * 2.3. Client Authentication
+ * 2.3.1. Client Password
+ * https://tools.ietf.org/html/rfc6749#section-2.3.1 + *
+ * request-body authentication scheme + */ +public class RequestBodyAuthenticationScheme implements ClientAuthentication { + + protected RequestBodyAuthenticationScheme() { + } + + private static class InstanceHolder { + + private static final RequestBodyAuthenticationScheme INSTANCE = new RequestBodyAuthenticationScheme(); + } + + public static RequestBodyAuthenticationScheme instance() { + return InstanceHolder.INSTANCE; + } + + @Override + public void addClientAuthentication(OAuthRequest request, String apiKey, String apiSecret) { + request.addParameter(OAuthConstants.CLIENT_ID, apiKey); + if (apiSecret != null) { + request.addParameter(OAuthConstants.CLIENT_SECRET, apiSecret); + } + } +} From 7608d4312ee2cb1c0aab11a5c9bc520671559eaf Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 3 Aug 2018 17:06:31 +0300 Subject: [PATCH 502/882] update httpasyncclient --- scribejava-httpclient-apache/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index e8815c53e..0043155d0 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -28,7 +28,7 @@ org.apache.httpcomponents httpasyncclient - 4.1.3 + 4.1.4 com.github.scribejava From b867f072a2818ffba37095cd83b964e4b7488eda Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 13 Aug 2018 18:36:53 +0300 Subject: [PATCH 503/882] =?UTF-8?q?remove=20support=20for=20obsolete=20Net?= =?UTF-8?q?Ease=20(http://www.163.com/)=20and=20sohu=20=E6=90=9C=E7=8B=90?= =?UTF-8?q?=20(http://www.sohu.com/)=20(thanks=20to=20https://github.com/z?= =?UTF-8?q?awn)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 - changelog | 1 + .../scribejava/apis/NeteaseWeibooApi.java | 60 ---------------- .../github/scribejava/apis/SohuWeiboApi.java | 36 ---------- .../apis/examples/NeteaseWeiboExample.java | 72 ------------------- .../apis/examples/SohuWeiboExample.java | 72 ------------------- 6 files changed, 1 insertion(+), 242 deletions(-) delete mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/NeteaseWeibooApi.java delete mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/SohuWeiboApi.java delete mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NeteaseWeiboExample.java delete mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SohuWeiboExample.java diff --git a/README.md b/README.md index 9b9cf3b58..29d1833dd 100644 --- a/README.md +++ b/README.md @@ -66,7 +66,6 @@ ScribeJava support out-of-box several HTTP clients: * MediaWiki (https://www.mediawiki.org/) * Meetup (http://www.meetup.com/) * NAVER (http://www.naver.com/) -* NetEase (http://www.163.com/) * Odnoklassniki Одноклассники (http://ok.ru/) * Pinterest (https://www.pinterest.com/) * 500px (https://500px.com/) @@ -74,7 +73,6 @@ ScribeJava support out-of-box several HTTP clients: * Salesforce (https://www.salesforce.com/) * Sina (http://www.sina.com.cn/ http://weibo.com/login.php) * Skyrock (http://skyrock.com/) -* sohu 搜狐 (http://www.sohu.com/) * StackExchange (http://stackexchange.com/) * The Things Network (v1-staging and v2-preview) (https://www.thethingsnetwork.org/) * Trello (https://trello.com/) diff --git a/changelog b/changelog index c1a5c41f1..b711f672e 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,5 @@ [SNAPSHOT] + * remove support for obsolete NetEase (http://www.163.com/) and sohu 搜狐 (http://www.sohu.com/) (thanks to https://github.com/zawn) * add Multipart functionality to JDK Http Client (thanks to https://github.com/eos1d3) * switch OAuth2 ClientAuthenticationType from enum to interface to be extensible according to https://tools.ietf.org/html/rfc6749#section-2.3.2 (thanks to https://github.com/zawn) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/NeteaseWeibooApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/NeteaseWeibooApi.java deleted file mode 100644 index 2446b5f58..000000000 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/NeteaseWeibooApi.java +++ /dev/null @@ -1,60 +0,0 @@ -package com.github.scribejava.apis; - -import com.github.scribejava.core.builder.api.DefaultApi10a; -import com.github.scribejava.core.model.OAuth1Token; - -public class NeteaseWeibooApi extends DefaultApi10a { - - private static final String REQUEST_TOKEN_URL = "http://api.t.163.com/oauth/request_token"; - private static final String ACCESS_TOKEN_URL = "http://api.t.163.com/oauth/access_token"; - private static final String AUTHORIZE_URL = "http://api.t.163.com/oauth/authorize"; - private static final String AUTHENTICATE_URL = "http://api.t.163.com/oauth/authenticate?oauth_token=%s"; - - protected NeteaseWeibooApi() { - } - - private static class InstanceHolder { - private static final NeteaseWeibooApi INSTANCE = new NeteaseWeibooApi(); - } - - public static NeteaseWeibooApi instance() { - return InstanceHolder.INSTANCE; - } - - @Override - public String getRequestTokenEndpoint() { - return REQUEST_TOKEN_URL; - } - - @Override - public String getAccessTokenEndpoint() { - return ACCESS_TOKEN_URL; - } - - /** - * this method will ignore your callback if you're creating a desktop client please choose this url else your can - * call getAuthenticateUrl - * - * via - * http://open.t.163.com/wiki/index.php?title=%E8%AF%B7%E6%B1%82%E7%94%A8%E6%88%B7%E6%8E%88%E6%9D%83Token(oauth/authorize) - * @return url to redirect user to (to get code) - */ - @Override - public String getAuthorizationBaseUrl() { - return AUTHORIZE_URL; - } - - /** - * this method is for web client with callback url if you're creating a desktop client please call - * getAuthorizationUrl - * - * via - * http://open.t.163.com/wiki/index.php?title=%E8%AF%B7%E6%B1%82%E7%94%A8%E6%88%B7%E6%8E%88%E6%9D%83Token(oauth/authenticate) - * - * @param requestToken Token - * @return String - */ - public String getAuthenticateUrl(OAuth1Token requestToken) { - return String.format(AUTHENTICATE_URL, requestToken.getToken()); - } -} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/SohuWeiboApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/SohuWeiboApi.java deleted file mode 100644 index a8447efd0..000000000 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/SohuWeiboApi.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.github.scribejava.apis; - -import com.github.scribejava.core.builder.api.DefaultApi10a; - -public class SohuWeiboApi extends DefaultApi10a { - - private static final String REQUEST_TOKEN_URL = "http://api.t.sohu.com/oauth/request_token"; - private static final String ACCESS_TOKEN_URL = "http://api.t.sohu.com/oauth/access_token"; - private static final String AUTHORIZE_URL = "http://api.t.sohu.com/oauth/authorize"; - - protected SohuWeiboApi() { - } - - private static class InstanceHolder { - private static final SohuWeiboApi INSTANCE = new SohuWeiboApi(); - } - - public static SohuWeiboApi instance() { - return InstanceHolder.INSTANCE; - } - - @Override - public String getRequestTokenEndpoint() { - return REQUEST_TOKEN_URL; - } - - @Override - public String getAccessTokenEndpoint() { - return ACCESS_TOKEN_URL; - } - - @Override - public String getAuthorizationBaseUrl() { - return AUTHORIZE_URL; - } -} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NeteaseWeiboExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NeteaseWeiboExample.java deleted file mode 100644 index e56a05a0c..000000000 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NeteaseWeiboExample.java +++ /dev/null @@ -1,72 +0,0 @@ -package com.github.scribejava.apis.examples; - -import java.util.Scanner; -import com.github.scribejava.core.builder.ServiceBuilder; -import com.github.scribejava.apis.NeteaseWeibooApi; -import com.github.scribejava.core.model.OAuth1AccessToken; -import com.github.scribejava.core.model.OAuth1RequestToken; -import com.github.scribejava.core.model.OAuthRequest; -import com.github.scribejava.core.model.Response; -import com.github.scribejava.core.model.Verb; -import com.github.scribejava.core.oauth.OAuth10aService; -import java.io.IOException; -import java.util.concurrent.ExecutionException; - -public class NeteaseWeiboExample { - - private static final String NETWORK_NAME = "NetEase(163.com) Weibo"; - private static final String PROTECTED_RESOURCE_URL = "http://api.t.163.com/account/verify_credentials.json"; - - private NeteaseWeiboExample() { - } - - public static void main(String... args) throws IOException, InterruptedException, ExecutionException { - // Replace these with your own api key and secret - final String apiKey = "your key"; - final String apiSecret = "your secret"; - final OAuth10aService service = new ServiceBuilder(apiKey) - .apiSecret(apiSecret) - .build(NeteaseWeibooApi.instance()); - final Scanner in = new Scanner(System.in); - - System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); - System.out.println(); - - // Grab a request token. - System.out.println("Fetching request token."); - final OAuth1RequestToken requestToken = service.getRequestToken(); - System.out.println("Got it ... "); - System.out.println(requestToken.getToken()); - - // Obtain the Authorization URL - System.out.println("Fetching the Authorization URL..."); - final String authorizationUrl = service.getAuthorizationUrl(requestToken); - System.out.println("Got the Authorization URL!"); - System.out.println("Now go and authorize ScribeJava here:"); - System.out.println(authorizationUrl); - System.out.println("And paste the authorization code here"); - System.out.print(">>"); - final String oauthVerifier = in.nextLine(); - System.out.println(); - - // Trade the Request Token and Verfier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); - final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); - System.out.println("Got the Access Token!"); - System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); - System.out.println(); - - // Now let's go and ask for a protected resource! - System.out.println("Now we're going to access a protected resource..."); - final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); - service.signRequest(accessToken, request); - final Response response = service.execute(request); - System.out.println("Got it! Lets see what we found..."); - System.out.println(); - System.out.println(response.getCode()); - System.out.println(response.getBody()); - - System.out.println(); - System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); - } -} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SohuWeiboExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SohuWeiboExample.java deleted file mode 100644 index 690efa9a8..000000000 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SohuWeiboExample.java +++ /dev/null @@ -1,72 +0,0 @@ -package com.github.scribejava.apis.examples; - -import java.util.Scanner; -import com.github.scribejava.core.builder.ServiceBuilder; -import com.github.scribejava.apis.SohuWeiboApi; -import com.github.scribejava.core.model.OAuth1AccessToken; -import com.github.scribejava.core.model.OAuth1RequestToken; -import com.github.scribejava.core.model.OAuthRequest; -import com.github.scribejava.core.model.Response; -import com.github.scribejava.core.model.Verb; -import com.github.scribejava.core.oauth.OAuth10aService; -import java.io.IOException; -import java.util.concurrent.ExecutionException; - -public class SohuWeiboExample { - - private static final String NETWORK_NAME = "SohuWeibo"; - private static final String PROTECTED_RESOURCE_URL = "http://api.t.sohu.com/account/verify_credentials.json"; - - private SohuWeiboExample() { - } - - public static void main(String... args) throws IOException, InterruptedException, ExecutionException { - // Replace these with your own api key and secret - final String apiKey = "your_key"; - final String apiSecret = "your_secret"; - final OAuth10aService service = new ServiceBuilder(apiKey) - .apiSecret(apiSecret) - .build(SohuWeiboApi.instance()); - final Scanner in = new Scanner(System.in); - - System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); - System.out.println(); - - // Grab a request token. - System.out.println("Fetching request token."); - final OAuth1RequestToken requestToken = service.getRequestToken(); - System.out.println("Got it ... "); - System.out.println(requestToken.getToken()); - - // Obtain the Authorization URL - System.out.println("Fetching the Authorization URL..."); - final String authorizationUrl = service.getAuthorizationUrl(requestToken); - System.out.println("Got the Authorization URL!"); - System.out.println("Now go and authorize ScribeJava here:"); - System.out.println(authorizationUrl); - System.out.println("And paste the authorization code here"); - System.out.print(">>"); - final String oauthVerifier = in.nextLine(); - System.out.println(); - - // Trade the Request Token and Verfier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); - final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); - System.out.println("Got the Access Token!"); - System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); - System.out.println(); - - // Now let's go and ask for a protected resource! - System.out.println("Now we're going to access a protected resource..."); - final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); - service.signRequest(accessToken, request); - final Response response = service.execute(request); - System.out.println("Got it! Lets see what we found..."); - System.out.println(); - System.out.println(response.getCode()); - System.out.println(response.getBody()); - - System.out.println(); - System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); - } -} From a88c391ab620dfd820489f1d030ca22d8d1a1b31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20B=C3=B6hmer?= Date: Wed, 22 Aug 2018 18:09:12 +0200 Subject: [PATCH 504/882] Added OAuth2 API and example for HiOrg-Server --- .../scribejava/apis/HiOrgServerApi20.java | 52 +++++++++++ .../apis/examples/HiOrgServerExample.java | 93 +++++++++++++++++++ 2 files changed, 145 insertions(+) create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/HiOrgServerApi20.java create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HiOrgServerExample.java diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/HiOrgServerApi20.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/HiOrgServerApi20.java new file mode 100644 index 000000000..e78d093c9 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/HiOrgServerApi20.java @@ -0,0 +1,52 @@ +package com.github.scribejava.apis; + +import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.oauth2.clientauthentication.ClientAuthentication; +import com.github.scribejava.core.oauth2.clientauthentication.RequestBodyAuthenticationScheme; + +/** + * OAuth2 API for HiOrg-Server + * + * @see https://wiki.hiorg-server.de/admin/oauth2 + */ +public class HiOrgServerApi20 extends DefaultApi20 { + + private final String version; + + protected HiOrgServerApi20() { + this("v1"); + } + + protected HiOrgServerApi20(String version) { + this.version = version; + } + + private static class InstanceHolder { + + private static final HiOrgServerApi20 INSTANCE = new HiOrgServerApi20(); + } + + public static HiOrgServerApi20 instance() { + return InstanceHolder.INSTANCE; + } + + public static HiOrgServerApi20 customVersion(String version) { + return new HiOrgServerApi20(version); + } + + @Override + public String getAccessTokenEndpoint() { + return "https://www.hiorg-server.de/api/oauth2/" + version + "/token.php"; + } + + @Override + protected String getAuthorizationBaseUrl() { + return "https://www.hiorg-server.de/api/oauth2/" + version + "/authorize.php"; + } + + @Override + public ClientAuthentication getClientAuthentication() { + return RequestBodyAuthenticationScheme.instance(); + } + +} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HiOrgServerExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HiOrgServerExample.java new file mode 100644 index 000000000..6055af753 --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HiOrgServerExample.java @@ -0,0 +1,93 @@ +package com.github.scribejava.apis.examples; + +import com.github.scribejava.apis.HiOrgServerApi20; +import com.github.scribejava.core.builder.ServiceBuilder; +import com.github.scribejava.core.model.OAuth2AccessToken; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.oauth.OAuth20Service; +import java.io.IOException; +import java.util.Random; +import java.util.Scanner; +import java.util.concurrent.ExecutionException; + +public class HiOrgServerExample { + + private static final String NETWORK_NAME = "HiOrgServer"; + private static final String PROTECTED_RESOURCE_URL = "https://www.hiorg-server.de/api/oauth2/v1/user.php"; + private static final String CLIENT_ID = "your client id"; + private static final String CLIENT_SECRET = "your client secret"; + private static final String CALLBACK_URL = "http://www.example.com/oauth_callback/"; + + private HiOrgServerExample() { + } + + public static void main(String... args) throws IOException, InterruptedException, ExecutionException { + // Replace these with your client id and secret + final String clientId = CLIENT_ID; + final String clientSecret = CLIENT_SECRET; + final String secretState = "secret" + new Random().nextInt(999_999); + final OAuth20Service service = new ServiceBuilder(clientId) + .apiSecret(clientSecret) + .scope("basic eigenedaten") + .state(secretState) + .callback(CALLBACK_URL) + .build(HiOrgServerApi20.instance()); + + final Scanner in = new Scanner(System.in, "UTF-8"); + + System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); + System.out.println(); + + // Obtain the Authorization URL + System.out.println("Fetching the Authorization URL..."); + final String authorizationUrl = service.getAuthorizationUrl(); + System.out.println("Got the Authorization URL!"); + System.out.println("Now go and authorize ScribeJava here:"); + System.out.println(authorizationUrl); + System.out.println("And paste the authorization code here"); + System.out.print(">>"); + final String code = in.nextLine(); + System.out.println(); + + System.out.println("And paste the state from server here. We have set 'secretState'='" + secretState + "'."); + System.out.print(">>"); + final String value = in.nextLine(); + if (secretState.equals(value)) { + System.out.println("State value does match!"); + } else { + System.out.println("Ooops, state value does not match!"); + System.out.println("Expected = " + secretState); + System.out.println("Got = " + value); + System.out.println(); + } + + // Trade the Request Token and Verfier for the Access Token + System.out.println("Trading the Request Token for an Access Token..."); + OAuth2AccessToken accessToken = service.getAccessToken(code); + System.out.println("Got the Access Token!"); + System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); + System.out.println(); + + System.out.println("Refreshing the Access Token..."); + accessToken = service.refreshAccessToken(accessToken.getRefreshToken()); + System.out.println("Refreshed the Access Token!"); + System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); + System.out.println(); + + // Now let's go and ask for a protected resource! + System.out.println("Now we're going to access a protected resource..."); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); + service.signRequest(accessToken, request); + final Response response = service.execute(request); + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + + System.out.println(); + System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); + } + +} From 434fc4cc41a41c41af8c33870b19118a470ac3f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20B=C3=B6hmer?= Date: Wed, 22 Aug 2018 19:01:36 +0200 Subject: [PATCH 505/882] Corrected javadoc --- .../main/java/com/github/scribejava/apis/HiOrgServerApi20.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/HiOrgServerApi20.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/HiOrgServerApi20.java index e78d093c9..0733381cf 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/HiOrgServerApi20.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/HiOrgServerApi20.java @@ -7,7 +7,7 @@ /** * OAuth2 API for HiOrg-Server * - * @see https://wiki.hiorg-server.de/admin/oauth2 + * @see HiOrg-Server OAuth API documentation */ public class HiOrgServerApi20 extends DefaultApi20 { From e8ba32375e9c60c6a03006e3172ac9e6e791d70f Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 28 Aug 2018 16:52:27 +0300 Subject: [PATCH 506/882] * add RuntimeException processing in async http clients (delivered to onError callbacks) + check 200 status code from response in OAuth2AccessTokenExtractor (thanks to https://github.com/jochen314) --- changelog | 2 + checkstyle.xml | 1 - .../OAuth2AccessTokenExtractor.java | 2 +- .../core/httpclient/jdk/JDKHttpClient.java | 2 +- .../core/httpclient/jdk/JDKHttpFuture.java | 6 +- .../OAuth2AccessTokenExtractorTest.java | 4 +- .../ahc/OAuthAsyncCompletionHandler.java | 33 +++++----- .../apache/OAuthAsyncCompletionHandler.java | 10 ++-- ...a => OAuthAsyncCompletionHandlerTest.java} | 26 ++++---- .../ning/OAuthAsyncCompletionHandler.java | 28 ++++----- .../httpclient/ning/MockResponse.java | 12 +--- ...a => OAuthAsyncCompletionHandlerTest.java} | 14 ++--- .../okhttp/OAuthAsyncCompletionHandler.java | 14 ++--- .../httpclient/okhttp/OkHttpFuture.java | 14 ++--- .../httpclient/okhttp/MockCall.java | 60 ++++++++----------- ...a => OAuthAsyncCompletionHandlerTest.java} | 38 ++++++++---- 16 files changed, 131 insertions(+), 135 deletions(-) rename scribejava-httpclient-apache/src/test/java/com/github/scribejava/httpclient/apache/{OauthAsyncCompletionHandlerTest.java => OAuthAsyncCompletionHandlerTest.java} (88%) rename scribejava-httpclient-ning/src/test/java/com/github/scribejava/httpclient/ning/{OauthAsyncCompletionHandlerTest.java => OAuthAsyncCompletionHandlerTest.java} (86%) rename scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/{OauthAsyncCompletionHandlerTest.java => OAuthAsyncCompletionHandlerTest.java} (83%) diff --git a/changelog b/changelog index b711f672e..9b63227d1 100644 --- a/changelog +++ b/changelog @@ -3,6 +3,8 @@ * add Multipart functionality to JDK Http Client (thanks to https://github.com/eos1d3) * switch OAuth2 ClientAuthenticationType from enum to interface to be extensible according to https://tools.ietf.org/html/rfc6749#section-2.3.2 (thanks to https://github.com/zawn) + * add RuntimeException processing in async http clients (delivered to onError callbacks) (thanks to https://github.com/jochen314) + * check 200 status code from response in OAuth2AccessTokenExtractor (thanks to https://github.com/jochen314) [5.5.0] * fix error parsing for Fitbit (thanks to https://github.com/danmana) diff --git a/checkstyle.xml b/checkstyle.xml index 2955d30b9..f3befc8a5 100644 --- a/checkstyle.xml +++ b/checkstyle.xml @@ -45,7 +45,6 @@ - diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenExtractor.java b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenExtractor.java index 22c1b90f0..855a03c43 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenExtractor.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenExtractor.java @@ -39,7 +39,7 @@ public static OAuth2AccessTokenExtractor instance() { @Override public OAuth2AccessToken extract(Response response) throws IOException { if (response.getCode() != 200) { - throw new OAuthException("Response code not 200 but " + response.getCode()); + throw new OAuthException("Response code is not 200 but '" + response.getCode() + '\''); } final String body = response.getBody(); Preconditions.checkEmptyString(body, diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java index 164a0520f..7e87dba0b 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java @@ -79,7 +79,7 @@ private Future doExecuteAsync(String userAgent, Map heade callback.onCompleted(t); } return new JDKHttpFuture<>(t); - } catch (Throwable e) { + } catch (IOException | RuntimeException e) { if (callback != null) { callback.onThrowable(e); } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpFuture.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpFuture.java index 307c552c6..1922d3aef 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpFuture.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpFuture.java @@ -11,10 +11,10 @@ */ public class JDKHttpFuture implements Future { - private final Throwable exception; + private final Exception exception; private final V response; - public JDKHttpFuture(Throwable exception) { + public JDKHttpFuture(Exception exception) { this(null, exception); } @@ -22,7 +22,7 @@ public JDKHttpFuture(V response) { this(response, null); } - private JDKHttpFuture(V response, Throwable exception) { + private JDKHttpFuture(V response, Exception exception) { this.response = response; this.exception = exception; } diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/extractors/OAuth2AccessTokenExtractorTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/extractors/OAuth2AccessTokenExtractorTest.java index b123d90aa..a79a87615 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/extractors/OAuth2AccessTokenExtractorTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/extractors/OAuth2AccessTokenExtractorTest.java @@ -61,7 +61,7 @@ public void shouldExtractTokenFromResponseWithManyParameters() throws IOExceptio @Test(expected = OAuthException.class) public void shouldThrowExceptionIfErrorResponse() throws IOException { final String response = ""; - this.extractor.extract(error(response)); + extractor.extract(error(response)); } @Test(expected = OAuthException.class) @@ -85,7 +85,7 @@ private static Response ok(String body) { return new Response(200, /* message */ null, /* headers */ Collections.emptyMap(), body); } - private static Response error(final String body) { + private static Response error(String body) { return new Response(400, /* message */ null, /* headers */ Collections.emptyMap(), body); } } diff --git a/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/OAuthAsyncCompletionHandler.java b/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/OAuthAsyncCompletionHandler.java index 100406fda..08706c195 100644 --- a/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/OAuthAsyncCompletionHandler.java +++ b/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/OAuthAsyncCompletionHandler.java @@ -20,21 +20,26 @@ public OAuthAsyncCompletionHandler(OAuthAsyncRequestCallback callback, } @Override - public T onCompleted(org.asynchttpclient.Response ahcResponse) throws IOException { - final Map headersMap = new HashMap<>(); - for (Map.Entry header : ahcResponse.getHeaders()) { - headersMap.put(header.getKey(), header.getValue()); + public T onCompleted(org.asynchttpclient.Response ahcResponse) { + try { + final Map headersMap = new HashMap<>(); + for (Map.Entry header : ahcResponse.getHeaders()) { + headersMap.put(header.getKey(), header.getValue()); + } + + final Response response = new Response(ahcResponse.getStatusCode(), ahcResponse.getStatusText(), headersMap, + ahcResponse.getResponseBodyAsStream()); + + @SuppressWarnings("unchecked") + final T t = converter == null ? (T) response : converter.convert(response); + if (callback != null) { + callback.onCompleted(t); + } + return t; + } catch (IOException | RuntimeException e) { + onThrowable(e); + return null; } - - final Response response = new Response(ahcResponse.getStatusCode(), ahcResponse.getStatusText(), headersMap, - ahcResponse.getResponseBodyAsStream()); - - @SuppressWarnings("unchecked") - final T t = converter == null ? (T) response : converter.convert(response); - if (callback != null) { - callback.onCompleted(t); - } - return t; } @Override diff --git a/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/OAuthAsyncCompletionHandler.java b/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/OAuthAsyncCompletionHandler.java index b49dd8513..65b92a178 100644 --- a/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/OAuthAsyncCompletionHandler.java +++ b/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/OAuthAsyncCompletionHandler.java @@ -16,6 +16,7 @@ import com.github.scribejava.core.model.OAuthAsyncRequestCallback; import com.github.scribejava.core.model.OAuthRequest.ResponseConverter; import com.github.scribejava.core.model.Response; +import java.io.IOException; public class OAuthAsyncCompletionHandler implements FutureCallback { @@ -23,7 +24,7 @@ public class OAuthAsyncCompletionHandler implements FutureCallback converter; private final CountDownLatch latch; private T result; - private Throwable exception; + private Exception exception; public OAuthAsyncCompletionHandler(OAuthAsyncRequestCallback callback, ResponseConverter converter) { this.callback = callback; @@ -41,9 +42,8 @@ public void completed(HttpResponse httpResponse) { final StatusLine statusLine = httpResponse.getStatusLine(); - final Response response = - new Response(statusLine.getStatusCode(), statusLine.getReasonPhrase(), headersMap, - httpResponse.getEntity().getContent()); + final Response response = new Response(statusLine.getStatusCode(), statusLine.getReasonPhrase(), headersMap, + httpResponse.getEntity().getContent()); @SuppressWarnings("unchecked") final T t = converter == null ? (T) response : converter.convert(response); @@ -51,7 +51,7 @@ public void completed(HttpResponse httpResponse) { if (callback != null) { callback.onCompleted(result); } - } catch (Throwable e) { + } catch (IOException | RuntimeException e) { exception = e; if (callback != null) { callback.onThrowable(e); diff --git a/scribejava-httpclient-apache/src/test/java/com/github/scribejava/httpclient/apache/OauthAsyncCompletionHandlerTest.java b/scribejava-httpclient-apache/src/test/java/com/github/scribejava/httpclient/apache/OAuthAsyncCompletionHandlerTest.java similarity index 88% rename from scribejava-httpclient-apache/src/test/java/com/github/scribejava/httpclient/apache/OauthAsyncCompletionHandlerTest.java rename to scribejava-httpclient-apache/src/test/java/com/github/scribejava/httpclient/apache/OAuthAsyncCompletionHandlerTest.java index 12c4588f3..c43fbed9e 100644 --- a/scribejava-httpclient-apache/src/test/java/com/github/scribejava/httpclient/apache/OauthAsyncCompletionHandlerTest.java +++ b/scribejava-httpclient-apache/src/test/java/com/github/scribejava/httpclient/apache/OAuthAsyncCompletionHandlerTest.java @@ -24,12 +24,12 @@ import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; -public class OauthAsyncCompletionHandlerTest { +public class OAuthAsyncCompletionHandlerTest { private static final AllGoodResponseConverter ALL_GOOD_RESPONSE_CONVERTER = new AllGoodResponseConverter(); private static final ExceptionResponseConverter EXCEPTION_RESPONSE_CONVERTER = new ExceptionResponseConverter(); - private static final OAuthExceptionResponseConverter OAUTH_EXCEPTION_RESPONSE_CONVERTER = - new OAuthExceptionResponseConverter(); + private static final OAuthExceptionResponseConverter OAUTH_EXCEPTION_RESPONSE_CONVERTER + = new OAuthExceptionResponseConverter(); private OAuthAsyncCompletionHandler handler; private TestCallback callback; @@ -67,8 +67,8 @@ public void setUp() { @Test public void shouldReleaseLatchOnSuccess() throws Exception { handler = new OAuthAsyncCompletionHandler<>(callback, ALL_GOOD_RESPONSE_CONVERTER); - final HttpResponse response = - new BasicHttpResponse(new BasicStatusLine(new ProtocolVersion("4", 1, 1), 200, "ok")); + final HttpResponse response + = new BasicHttpResponse(new BasicStatusLine(new ProtocolVersion("4", 1, 1), 200, "ok")); final BasicHttpEntity entity = new BasicHttpEntity(); entity.setContent(new ByteArrayInputStream(new byte[0])); response.setEntity(entity); @@ -82,8 +82,8 @@ public void shouldReleaseLatchOnSuccess() throws Exception { @Test public void shouldReleaseLatchOnIOException() throws Exception { handler = new OAuthAsyncCompletionHandler<>(callback, EXCEPTION_RESPONSE_CONVERTER); - final HttpResponse response = - new BasicHttpResponse(new BasicStatusLine(new ProtocolVersion("4", 1, 1), 200, "ok")); + final HttpResponse response + = new BasicHttpResponse(new BasicStatusLine(new ProtocolVersion("4", 1, 1), 200, "ok")); final BasicHttpEntity entity = new BasicHttpEntity(); entity.setContent(new ByteArrayInputStream(new byte[0])); response.setEntity(entity); @@ -103,8 +103,8 @@ public void shouldReleaseLatchOnIOException() throws Exception { @Test public void shouldReportOAuthException() throws Exception { handler = new OAuthAsyncCompletionHandler<>(callback, OAUTH_EXCEPTION_RESPONSE_CONVERTER); - final HttpResponse response = - new BasicHttpResponse(new BasicStatusLine(new ProtocolVersion("4", 1, 1), 200, "ok")); + final HttpResponse response + = new BasicHttpResponse(new BasicStatusLine(new ProtocolVersion("4", 1, 1), 200, "ok")); final BasicHttpEntity entity = new BasicHttpEntity(); entity.setContent(new ByteArrayInputStream(new byte[0])); response.setEntity(entity); @@ -124,8 +124,8 @@ public void shouldReportOAuthException() throws Exception { @Test public void shouldReleaseLatchOnCancel() throws Exception { handler = new OAuthAsyncCompletionHandler<>(callback, ALL_GOOD_RESPONSE_CONVERTER); - final HttpResponse response = - new BasicHttpResponse(new BasicStatusLine(new ProtocolVersion("4", 1, 1), 200, "ok")); + final HttpResponse response + = new BasicHttpResponse(new BasicStatusLine(new ProtocolVersion("4", 1, 1), 200, "ok")); final BasicHttpEntity entity = new BasicHttpEntity(); entity.setContent(new ByteArrayInputStream(new byte[0])); response.setEntity(entity); @@ -145,8 +145,8 @@ public void shouldReleaseLatchOnCancel() throws Exception { @Test public void shouldReleaseLatchOnFailure() throws Exception { handler = new OAuthAsyncCompletionHandler<>(callback, ALL_GOOD_RESPONSE_CONVERTER); - final HttpResponse response = - new BasicHttpResponse(new BasicStatusLine(new ProtocolVersion("4", 1, 1), 200, "ok")); + final HttpResponse response + = new BasicHttpResponse(new BasicStatusLine(new ProtocolVersion("4", 1, 1), 200, "ok")); final BasicHttpEntity entity = new BasicHttpEntity(); entity.setContent(new ByteArrayInputStream(new byte[0])); response.setEntity(entity); diff --git a/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/OAuthAsyncCompletionHandler.java b/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/OAuthAsyncCompletionHandler.java index f4122c1e9..cd8a25ce1 100644 --- a/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/OAuthAsyncCompletionHandler.java +++ b/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/OAuthAsyncCompletionHandler.java @@ -21,29 +21,29 @@ public OAuthAsyncCompletionHandler(OAuthAsyncRequestCallback callback, } @Override - public T onCompleted(com.ning.http.client.Response ningResponse) throws IOException { - final Map headersMap = new HashMap<>(); - - for (Map.Entry> header : ningResponse.getHeaders().entrySet()) { - final StringBuilder value = new StringBuilder(); - for (String str : header.getValue()) { - value.append(str); + public T onCompleted(com.ning.http.client.Response ningResponse) { + try { + final Map headersMap = new HashMap<>(); + + for (Map.Entry> header : ningResponse.getHeaders().entrySet()) { + final StringBuilder value = new StringBuilder(); + for (String str : header.getValue()) { + value.append(str); + } + headersMap.put(header.getKey(), value.toString()); } - headersMap.put(header.getKey(), value.toString()); - } - final Response response = new Response(ningResponse.getStatusCode(), ningResponse.getStatusText(), headersMap, - ningResponse.getResponseBodyAsStream()); + final Response response = new Response(ningResponse.getStatusCode(), ningResponse.getStatusText(), + headersMap, ningResponse.getResponseBodyAsStream()); - try { @SuppressWarnings("unchecked") final T t = converter == null ? (T) response : converter.convert(response); if (callback != null) { callback.onCompleted(t); } return t; - } catch (Throwable t) { - onThrowable(t); + } catch (IOException | RuntimeException e) { + onThrowable(e); return null; } } diff --git a/scribejava-httpclient-ning/src/test/java/com/github/scribejava/httpclient/ning/MockResponse.java b/scribejava-httpclient-ning/src/test/java/com/github/scribejava/httpclient/ning/MockResponse.java index c432d9ed2..af75bf871 100644 --- a/scribejava-httpclient-ning/src/test/java/com/github/scribejava/httpclient/ning/MockResponse.java +++ b/scribejava-httpclient-ning/src/test/java/com/github/scribejava/httpclient/ning/MockResponse.java @@ -11,9 +11,6 @@ import com.ning.http.client.cookie.Cookie; import com.ning.http.client.uri.Uri; -/** - * - */ public class MockResponse implements Response { private final int statusCode; @@ -21,14 +18,7 @@ public class MockResponse implements Response { private final FluentCaseInsensitiveStringsMap headers; private final byte[] body; - /** - * @param statusCode - * @param statusText - * @param body - */ - public MockResponse(int statusCode, String statusText, FluentCaseInsensitiveStringsMap headers, - byte[] body) { - super(); + public MockResponse(int statusCode, String statusText, FluentCaseInsensitiveStringsMap headers, byte[] body) { this.statusCode = statusCode; this.statusText = statusText; this.headers = headers; diff --git a/scribejava-httpclient-ning/src/test/java/com/github/scribejava/httpclient/ning/OauthAsyncCompletionHandlerTest.java b/scribejava-httpclient-ning/src/test/java/com/github/scribejava/httpclient/ning/OAuthAsyncCompletionHandlerTest.java similarity index 86% rename from scribejava-httpclient-ning/src/test/java/com/github/scribejava/httpclient/ning/OauthAsyncCompletionHandlerTest.java rename to scribejava-httpclient-ning/src/test/java/com/github/scribejava/httpclient/ning/OAuthAsyncCompletionHandlerTest.java index efc516d68..c235061e9 100644 --- a/scribejava-httpclient-ning/src/test/java/com/github/scribejava/httpclient/ning/OauthAsyncCompletionHandlerTest.java +++ b/scribejava-httpclient-ning/src/test/java/com/github/scribejava/httpclient/ning/OAuthAsyncCompletionHandlerTest.java @@ -16,11 +16,11 @@ import com.github.scribejava.core.model.Response; import com.ning.http.client.FluentCaseInsensitiveStringsMap; -public class OauthAsyncCompletionHandlerTest { +public class OAuthAsyncCompletionHandlerTest { private static final AllGoodResponseConverter ALL_GOOD_RESPONSE_CONVERTER = new AllGoodResponseConverter(); - private static final OAuthExceptionResponseConverter OAUTH_EXCEPTION_RESPONSE_CONVERTER = - new OAuthExceptionResponseConverter(); + private static final OAuthExceptionResponseConverter OAUTH_EXCEPTION_RESPONSE_CONVERTER + = new OAuthExceptionResponseConverter(); private OAuthAsyncCompletionHandler handler; private TestCallback callback; @@ -59,8 +59,8 @@ public void setUp() { public void shouldReleaseLatchOnSuccess() throws Exception { handler = new OAuthAsyncCompletionHandler<>(callback, ALL_GOOD_RESPONSE_CONVERTER); - final com.ning.http.client.Response response = - new MockResponse(200, "ok", new FluentCaseInsensitiveStringsMap(), new byte[0]); + final com.ning.http.client.Response response + = new MockResponse(200, "ok", new FluentCaseInsensitiveStringsMap(), new byte[0]); handler.onCompleted(response); assertNotNull(callback.getResponse()); assertNull(callback.getThrowable()); @@ -72,8 +72,8 @@ public void shouldReleaseLatchOnSuccess() throws Exception { public void shouldReportOAuthException() throws Exception { handler = new OAuthAsyncCompletionHandler<>(callback, OAUTH_EXCEPTION_RESPONSE_CONVERTER); - final com.ning.http.client.Response response = - new MockResponse(200, "ok", new FluentCaseInsensitiveStringsMap(), new byte[0]); + final com.ning.http.client.Response response + = new MockResponse(200, "ok", new FluentCaseInsensitiveStringsMap(), new byte[0]); handler.onCompleted(response); assertNull(callback.getResponse()); assertNotNull(callback.getThrowable()); diff --git a/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OAuthAsyncCompletionHandler.java b/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OAuthAsyncCompletionHandler.java index bd613138a..8345fa9d1 100644 --- a/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OAuthAsyncCompletionHandler.java +++ b/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OAuthAsyncCompletionHandler.java @@ -22,11 +22,11 @@ class OAuthAsyncCompletionHandler implements Callback { } @Override - public void onFailure(Call call, IOException e) { + public void onFailure(Call call, IOException exception) { try { - this.okHttpFuture.setError(e); + okHttpFuture.setException(exception); if (callback != null) { - callback.onThrowable(e); + callback.onThrowable(exception); } } finally { okHttpFuture.finish(); @@ -34,7 +34,7 @@ public void onFailure(Call call, IOException e) { } @Override - public void onResponse(Call call, okhttp3.Response okHttpResponse) throws IOException { + public void onResponse(Call call, okhttp3.Response okHttpResponse) { try { final Response response = OkHttpHttpClient.convertResponse(okHttpResponse); @@ -45,10 +45,10 @@ public void onResponse(Call call, okhttp3.Response okHttpResponse) throws IOExce if (callback != null) { callback.onCompleted(t); } - } catch (Throwable t) { - okHttpFuture.setError(t); + } catch (IOException | RuntimeException e) { + okHttpFuture.setException(e); if (callback != null) { - callback.onThrowable(t); + callback.onThrowable(e); } } } finally { diff --git a/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpFuture.java b/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpFuture.java index a75617dd4..417b03e0a 100644 --- a/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpFuture.java +++ b/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpFuture.java @@ -13,7 +13,7 @@ public class OkHttpFuture implements Future { private final CountDownLatch latch = new CountDownLatch(1); private final Call call; private T result; - private Throwable t; + private Exception exception; public OkHttpFuture(Call call) { this.call = call; @@ -35,15 +35,15 @@ public boolean isDone() { return call.isExecuted(); } - public void setError(Throwable t) { - this.t = t; + public void setException(Exception exception) { + this.exception = exception; } @Override public T get() throws InterruptedException, ExecutionException { latch.await(); - if (t != null) { - throw new ExecutionException(t); + if (exception != null) { + throw new ExecutionException(exception); } return result; } @@ -51,8 +51,8 @@ public T get() throws InterruptedException, ExecutionException { @Override public T get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { if (latch.await(timeout, unit)) { - if (t != null) { - throw new ExecutionException(t); + if (exception != null) { + throw new ExecutionException(exception); } return result; } diff --git a/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/MockCall.java b/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/MockCall.java index 9b4b1d447..967d96c4a 100644 --- a/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/MockCall.java +++ b/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/MockCall.java @@ -1,66 +1,54 @@ package com.github.scribejava.httpclient.okhttp; import java.io.IOException; -import java.lang.reflect.InvocationHandler; -import java.lang.reflect.Method; -import java.lang.reflect.Proxy; import java.util.ArrayList; import java.util.Collection; import okhttp3.Call; import okhttp3.Callback; +import okhttp3.Request; +import okhttp3.Response; -/** - * the only reason, this is a dynamic proxy is, that checkstyle forbids implementing clone()! - */ -public class MockCall implements InvocationHandler { +public class MockCall implements Call { - private final Collection callbacks; + private final Collection callbacks = new ArrayList<>(); private boolean canceled; - public MockCall() { - this(new ArrayList()); - } - - private MockCall(Collection callbacks) { - this.callbacks = new ArrayList<>(callbacks); - } - + @Override public void enqueue(Callback responseCallback) { callbacks.add(responseCallback); } - public void cancel(Call proxy) { + @Override + public void cancel() { canceled = true; for (Callback callback : callbacks) { - callback.onFailure(proxy, new IOException("Canceled")); + callback.onFailure(this, new IOException("Canceled")); } } + @Override public boolean isCanceled() { return canceled; } @Override - public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { - switch (method.getName()) { - case "enqueue": - enqueue((Callback) args[0]); - return null; - case "cancel": - cancel((Call) proxy); - return null; - case "isCanceled": - return isCanceled(); - default: - throw new UnsupportedOperationException(method.toString()); - } + public Request request() { + throw new UnsupportedOperationException("Not supported yet."); } - /** - * @return - */ - public static Call create() { - return (Call) Proxy.newProxyInstance(Call.class.getClassLoader(), new Class[] { Call.class }, new MockCall()); + @Override + public Response execute() throws IOException { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public boolean isExecuted() { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public Call clone() { + throw new UnsupportedOperationException("Not supported yet."); } } diff --git a/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/OauthAsyncCompletionHandlerTest.java b/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/OAuthAsyncCompletionHandlerTest.java similarity index 83% rename from scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/OauthAsyncCompletionHandlerTest.java rename to scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/OAuthAsyncCompletionHandlerTest.java index 5181487ff..863d2eee3 100644 --- a/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/OauthAsyncCompletionHandlerTest.java +++ b/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/OAuthAsyncCompletionHandlerTest.java @@ -23,12 +23,12 @@ import okhttp3.Request; import okhttp3.ResponseBody; -public class OauthAsyncCompletionHandlerTest { +public class OAuthAsyncCompletionHandlerTest { private static final AllGoodResponseConverter ALL_GOOD_RESPONSE_CONVERTER = new AllGoodResponseConverter(); private static final ExceptionResponseConverter EXCEPTION_RESPONSE_CONVERTER = new ExceptionResponseConverter(); - private static final OAuthExceptionResponseConverter OAUTH_EXCEPTION_RESPONSE_CONVERTER = - new OAuthExceptionResponseConverter(); + private static final OAuthExceptionResponseConverter OAUTH_EXCEPTION_RESPONSE_CONVERTER + = new OAuthExceptionResponseConverter(); private OAuthAsyncCompletionHandler handler; private Call call; @@ -63,7 +63,7 @@ public String getResponse() { @Before public void setUp() { callback = new TestCallback(); - call = MockCall.create(); + call = new MockCall(); future = new OkHttpFuture<>(call); } @@ -73,9 +73,13 @@ public void shouldReleaseLatchOnSuccess() throws Exception { call.enqueue(handler); final okhttp3.Request request = new Request.Builder().url("http://localhost/").build(); - final okhttp3.Response response = - new okhttp3.Response.Builder().request(request).protocol(Protocol.HTTP_1_1).code(200).message("ok") - .body(ResponseBody.create(MediaType.get("text/plain"), new byte[0])).build(); + final okhttp3.Response response = new okhttp3.Response.Builder() + .request(request) + .protocol(Protocol.HTTP_1_1) + .code(200) + .message("ok") + .body(ResponseBody.create(MediaType.get("text/plain"), new byte[0])) + .build(); handler.onResponse(call, response); assertNotNull(callback.getResponse()); assertNull(callback.getThrowable()); @@ -89,9 +93,13 @@ public void shouldReleaseLatchOnIOException() throws Exception { call.enqueue(handler); final okhttp3.Request request = new Request.Builder().url("http://localhost/").build(); - final okhttp3.Response response = - new okhttp3.Response.Builder().request(request).protocol(Protocol.HTTP_1_1).code(200).message("ok") - .body(ResponseBody.create(MediaType.get("text/plain"), new byte[0])).build(); + final okhttp3.Response response = new okhttp3.Response.Builder() + .request(request) + .protocol(Protocol.HTTP_1_1) + .code(200) + .message("ok") + .body(ResponseBody.create(MediaType.get("text/plain"), new byte[0])) + .build(); handler.onResponse(call, response); assertNull(callback.getResponse()); assertNotNull(callback.getThrowable()); @@ -111,9 +119,13 @@ public void shouldReportOAuthException() throws Exception { call.enqueue(handler); final okhttp3.Request request = new Request.Builder().url("http://localhost/").build(); - final okhttp3.Response response = - new okhttp3.Response.Builder().request(request).protocol(Protocol.HTTP_1_1).code(200).message("ok") - .body(ResponseBody.create(MediaType.get("text/plain"), new byte[0])).build(); + final okhttp3.Response response = new okhttp3.Response.Builder() + .request(request) + .protocol(Protocol.HTTP_1_1) + .code(200) + .message("ok") + .body(ResponseBody.create(MediaType.get("text/plain"), new byte[0])) + .build(); handler.onResponse(call, response); assertNull(callback.getResponse()); assertNotNull(callback.getThrowable()); From c308760b84c5efef6ec8c0ab599dafaf8940da0d Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 28 Aug 2018 17:25:38 +0300 Subject: [PATCH 507/882] update maven compiler plugin --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 7f8d17a8f..7fd7e0dd9 100644 --- a/pom.xml +++ b/pom.xml @@ -126,7 +126,7 @@ maven-compiler-plugin - 3.7.0 + 3.8.0 UTF-8 1.7 From 3be2efcc4308fee45c8ba642b6af35fcc6a0e175 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 6 Sep 2018 13:12:42 +0300 Subject: [PATCH 508/882] fix case sensitive Http Headers comparison and sending Content-Type header along with content-type (thanks to https://github.com/marnix) --- changelog | 1 + .../core/httpclient/MultipartPayload.java | 3 ++- .../scribejava/core/model/OAuthRequest.java | 9 +++++---- .../core/model/OAuthRequestTest.java | 19 +++++++++++++++++++ 4 files changed, 27 insertions(+), 5 deletions(-) diff --git a/changelog b/changelog index 9b63227d1..aaddba45e 100644 --- a/changelog +++ b/changelog @@ -5,6 +5,7 @@ https://tools.ietf.org/html/rfc6749#section-2.3.2 (thanks to https://github.com/zawn) * add RuntimeException processing in async http clients (delivered to onError callbacks) (thanks to https://github.com/jochen314) * check 200 status code from response in OAuth2AccessTokenExtractor (thanks to https://github.com/jochen314) + * fix case sensitive Http Headers comparison and sending Content-Type header along with content-type (thanks to https://github.com/marnix) [5.5.0] * fix error parsing for Fitbit (thanks to https://github.com/danmana) diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/MultipartPayload.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/MultipartPayload.java index a1dbb5e7e..71d67f508 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/MultipartPayload.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/MultipartPayload.java @@ -18,7 +18,8 @@ public MultipartPayload(String boundary) { public byte[] getStartBoundary(BodyPartPayload bodyPart) { return ("--" + boundary + "\r\n" + "Content-Disposition: " + bodyPart.getContentDisposition() + "\r\n" - + (bodyPart.getContentType() == null ? "" : "Content-Type: " + bodyPart.getContentType() + "\r\n") + + (bodyPart.getContentType() == null + ? "" : HttpClient.CONTENT_TYPE + ": " + bodyPart.getContentType() + "\r\n") + "\r\n").getBytes(); } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequest.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequest.java index a33ac7d72..d132da1dc 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequest.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequest.java @@ -10,6 +10,7 @@ import java.nio.charset.Charset; import java.util.HashMap; import java.util.Map; +import java.util.TreeMap; /** * The representation of an OAuth HttpRequest. @@ -22,7 +23,7 @@ public class OAuthRequest { private final Verb verb; private final ParameterList querystringParams = new ParameterList(); private final ParameterList bodyParams = new ParameterList(); - private final Map headers = new HashMap<>(); + private final Map headers = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); private String charset; @@ -95,7 +96,7 @@ public String getCompleteUrl() { * @param value the header value */ public void addHeader(String key, String value) { - this.headers.put(key, value); + headers.put(key, value); } /** @@ -105,7 +106,7 @@ public void addHeader(String key, String value) { * @param value the parameter value */ public void addBodyParameter(String key, String value) { - this.bodyParams.add(key, value); + bodyParams.add(key, value); } /** @@ -115,7 +116,7 @@ public void addBodyParameter(String key, String value) { * @param value the parameter value */ public void addQuerystringParameter(String key, String value) { - this.querystringParams.add(key, value); + querystringParams.add(key, value); } public void addParameter(String key, String value) { diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/model/OAuthRequestTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/model/OAuthRequestTest.java index 0ea88985d..03688ce16 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/model/OAuthRequestTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/model/OAuthRequestTest.java @@ -1,6 +1,7 @@ package com.github.scribejava.core.model; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import org.junit.Before; import org.junit.Test; @@ -28,4 +29,22 @@ public void shouldAddOAuthParamters() { public void shouldThrowExceptionIfParameterIsNotOAuth() { request.addOAuthParameter("otherParam", "value"); } + + @Test + public void shouldNotSentHeaderTwice() { + assertTrue(request.getHeaders().isEmpty()); + request.addHeader("HEADER-NAME", "first"); + request.addHeader("header-name", "middle"); + request.addHeader("Header-Name", "last"); + + assertEquals(1, request.getHeaders().size()); + + assertTrue(request.getHeaders().containsKey("HEADER-NAME")); + assertTrue(request.getHeaders().containsKey("header-name")); + assertTrue(request.getHeaders().containsKey("Header-Name")); + + assertEquals("last", request.getHeaders().get("HEADER-NAME")); + assertEquals("last", request.getHeaders().get("header-name")); + assertEquals("last", request.getHeaders().get("Header-Name")); + } } From f00afdb763c883890227a26cfb7455a4013ff661 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 6 Sep 2018 13:18:16 +0300 Subject: [PATCH 509/882] update async-http-client --- scribejava-httpclient-ahc/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index eacdd6208..7ed0dbe69 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -23,7 +23,7 @@ org.asynchttpclient async-http-client - 2.5.2 + 2.5.3 com.github.scribejava From 3bf1ce4fd9117d41f312c3009c149288c6f07b99 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 10 Sep 2018 13:07:21 +0300 Subject: [PATCH 510/882] update info in pom --- pom.xml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index 7fd7e0dd9..25acee28b 100644 --- a/pom.xml +++ b/pom.xml @@ -41,15 +41,12 @@ kullfar Stas Gromov - s.gromov@hh.ru - hh.ru - http://hh.ru + kullfar@gmail.com all +3 - kullfar@gmail.com +7-909-677-11-16 From 1547b3e644960fcb11ff61be468fe5c0b06ff570 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 10 Sep 2018 13:07:58 +0300 Subject: [PATCH 511/882] Seems, it was illegal to add copyright here --- LICENSE.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/LICENSE.txt b/LICENSE.txt index 8cde51fa9..6085098bc 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,6 +1,5 @@ The MIT License -Copyright (c) 2013 hh.ru Copyright (c) 2010 Pablo Fernandez Permission is hereby granted, free of charge, to any person obtaining a copy @@ -19,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. \ No newline at end of file +THE SOFTWARE. From fb22d4158ec528a585abc4a2ad46179950ea7e41 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 11 Sep 2018 09:55:34 +0300 Subject: [PATCH 512/882] add HiOrg-Server (https://www.hiorg-server.de/) API (thanks to https://github.com/MartinBoehmer) --- README.md | 1 + changelog | 1 + .../java/com/github/scribejava/apis/HiOrgServerApi20.java | 8 -------- 3 files changed, 2 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 29d1833dd..af82ae54f 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,7 @@ ScribeJava support out-of-box several HTTP clients: * GitHub (https://github.com/) * Google (https://www.google.com/) * HeadHunter ХэдХантер (https://hh.ru/) +* HiOrg-Server (https://www.hiorg-server.de/) * Imgur (http://imgur.com/) * Kaixin 开心网 (http://www.kaixin001.com/) * LinkedIn (https://www.linkedin.com/) diff --git a/changelog b/changelog index aaddba45e..4df2d5ccc 100644 --- a/changelog +++ b/changelog @@ -6,6 +6,7 @@ * add RuntimeException processing in async http clients (delivered to onError callbacks) (thanks to https://github.com/jochen314) * check 200 status code from response in OAuth2AccessTokenExtractor (thanks to https://github.com/jochen314) * fix case sensitive Http Headers comparison and sending Content-Type header along with content-type (thanks to https://github.com/marnix) + * add HiOrg-Server (https://www.hiorg-server.de/) API (thanks to https://github.com/MartinBoehmer) [5.5.0] * fix error parsing for Fitbit (thanks to https://github.com/danmana) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/HiOrgServerApi20.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/HiOrgServerApi20.java index 0733381cf..a69673a25 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/HiOrgServerApi20.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/HiOrgServerApi20.java @@ -1,8 +1,6 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.oauth2.clientauthentication.ClientAuthentication; -import com.github.scribejava.core.oauth2.clientauthentication.RequestBodyAuthenticationScheme; /** * OAuth2 API for HiOrg-Server @@ -43,10 +41,4 @@ public String getAccessTokenEndpoint() { protected String getAuthorizationBaseUrl() { return "https://www.hiorg-server.de/api/oauth2/" + version + "/authorize.php"; } - - @Override - public ClientAuthentication getClientAuthentication() { - return RequestBodyAuthenticationScheme.instance(); - } - } From f54525dd0b5c7329c55b5f50f73807627e7fa8fd Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 11 Sep 2018 10:36:53 +0300 Subject: [PATCH 513/882] prepare 5.6.0 release --- README.md | 4 ++-- changelog | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index af82ae54f..25b0ce33e 100644 --- a/README.md +++ b/README.md @@ -111,7 +111,7 @@ You can pull ScribeJava from the central maven repository, just add these to you com.github.scribejava scribejava-apis - 5.5.0 + 5.6.0 ``` @@ -120,7 +120,7 @@ And in case you need just core classes (that's it, without any external API (FB, com.github.scribejava scribejava-core - 5.5.0 + 5.6.0 ``` diff --git a/changelog b/changelog index 4df2d5ccc..d7e6441ee 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,4 @@ -[SNAPSHOT] +[5.6.0] * remove support for obsolete NetEase (http://www.163.com/) and sohu 搜狐 (http://www.sohu.com/) (thanks to https://github.com/zawn) * add Multipart functionality to JDK Http Client (thanks to https://github.com/eos1d3) * switch OAuth2 ClientAuthenticationType from enum to interface to be extensible according to From 92068d25e6904ab443ce90264cd7cea8d731b06d Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 11 Sep 2018 10:38:49 +0300 Subject: [PATCH 514/882] [maven-release-plugin] prepare release scribejava-5.6.0 --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index 25acee28b..609b4375a 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 5.5.1-SNAPSHOT + 5.6.0 ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -34,7 +34,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - HEAD + scribejava-5.6.0 diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index e92f60e67..e8193e7f8 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.5.1-SNAPSHOT + 5.6.0 ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 96ea8ad56..9f2e9ad18 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.5.1-SNAPSHOT + 5.6.0 ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 7ed0dbe69..7312bb98c 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.5.1-SNAPSHOT + 5.6.0 ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index 0043155d0..1429b4840 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.5.1-SNAPSHOT + 5.6.0 ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index fcd3e33aa..fdecfd145 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.5.1-SNAPSHOT + 5.6.0 ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 554be1054..991f26dda 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.5.1-SNAPSHOT + 5.6.0 ../pom.xml From 0df58e1ad282c1d54c048f75cea23013e87f9d6e Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 11 Sep 2018 10:40:01 +0300 Subject: [PATCH 515/882] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index 609b4375a..30c158970 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 5.6.0 + 5.6.1-SNAPSHOT ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -34,7 +34,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - scribejava-5.6.0 + HEAD diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index e8193e7f8..3cc2f5f5a 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.6.0 + 5.6.1-SNAPSHOT ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 9f2e9ad18..b07f9627b 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.6.0 + 5.6.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 7312bb98c..ec7ab0a77 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.6.0 + 5.6.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index 1429b4840..f49a10a12 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.6.0 + 5.6.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index fdecfd145..dffa0f860 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.6.0 + 5.6.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 991f26dda..3d249abe7 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.6.0 + 5.6.1-SNAPSHOT ../pom.xml From 218dc162cdce822e2983bde186400f7496719aac Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 11 Sep 2018 12:21:22 +0300 Subject: [PATCH 516/882] remove deprecated ClientAuthenticationType --- .../builder/api/ClientAuthenticationType.java | 41 ------------------- .../core/builder/api/DefaultApi20.java | 18 +------- 2 files changed, 1 insertion(+), 58 deletions(-) delete mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/builder/api/ClientAuthenticationType.java diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/ClientAuthenticationType.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/ClientAuthenticationType.java deleted file mode 100644 index 097ba1081..000000000 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/ClientAuthenticationType.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.github.scribejava.core.builder.api; - -import com.github.scribejava.core.model.OAuthRequest; -import com.github.scribejava.core.oauth2.clientauthentication.HttpBasicAuthenticationScheme; -import com.github.scribejava.core.oauth2.clientauthentication.RequestBodyAuthenticationScheme; - -/** - * Represents
- * 2.3. Client Authentication
- * https://tools.ietf.org/html/rfc6749#section-2.3
- * in it's part 2.3.1. Client Password
- * https://tools.ietf.org/html/rfc6749#section-2.3.1 - * - * @deprecated use {@link com.github.scribejava.core.oauth2.clientauthentication.ClientAuthentication} - */ -@Deprecated -public enum ClientAuthenticationType { - /** - * @deprecated use {@link com.github.scribejava.core.oauth2.clientauthentication.HttpBasicAuthenticationScheme} - */ - @Deprecated - HTTP_BASIC_AUTHENTICATION_SCHEME { - - @Override - public void addClientAuthentication(OAuthRequest request, String apiKey, String apiSecret) { - HttpBasicAuthenticationScheme.instance().addClientAuthentication(request, apiKey, apiSecret); - } - }, - /** - * @deprecated use {@link com.github.scribejava.core.oauth2.clientauthentication.RequestBodyAuthenticationScheme} - */ - @Deprecated - REQUEST_BODY { - @Override - public void addClientAuthentication(OAuthRequest request, String apiKey, String apiSecret) { - RequestBodyAuthenticationScheme.instance().addClientAuthentication(request, apiKey, apiSecret); - } - }; - - public abstract void addClientAuthentication(OAuthRequest request, String apiKey, String apiSecret); -} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java index b429142a6..e10a57aeb 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java @@ -11,7 +11,6 @@ import com.github.scribejava.core.oauth.OAuth20Service; import com.github.scribejava.core.oauth2.clientauthentication.ClientAuthentication; import com.github.scribejava.core.oauth2.clientauthentication.HttpBasicAuthenticationScheme; -import com.github.scribejava.core.oauth2.clientauthentication.RequestBodyAuthenticationScheme; import java.io.OutputStream; import java.util.Map; @@ -113,21 +112,6 @@ public OAuth2SignatureType getSignatureType() { } public ClientAuthentication getClientAuthentication() { - switch (getClientAuthenticationType()) { - case HTTP_BASIC_AUTHENTICATION_SCHEME: - return HttpBasicAuthenticationScheme.instance(); - case REQUEST_BODY: - return RequestBodyAuthenticationScheme.instance(); - default: - throw new IllegalStateException("there was no such Client Authentication Type"); - } - } - - /** - * @deprecated use {@link #getClientAuthentication() } - */ - @Deprecated - public ClientAuthenticationType getClientAuthenticationType() { - return ClientAuthenticationType.HTTP_BASIC_AUTHENTICATION_SCHEME; + return HttpBasicAuthenticationScheme.instance(); } } From 32604f1f336e1f9621984df05ba640d789459751 Mon Sep 17 00:00:00 2001 From: Marvin Bredal Lillehaug Date: Fri, 14 Sep 2018 12:10:54 +0200 Subject: [PATCH 517/882] Issue #870 Avoid 'Cannot encode null object' when omitting callback url --- .../com/github/scribejava/core/oauth/OAuth20Service.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java index 5b10849af..addd023a7 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java @@ -108,7 +108,10 @@ protected OAuthRequest createAccessTokenRequest(String code) { api.getClientAuthentication().addClientAuthentication(request, getApiKey(), getApiSecret()); request.addParameter(OAuthConstants.CODE, code); - request.addParameter(OAuthConstants.REDIRECT_URI, getCallback()); + String callback = getCallback(); + if (callback != null) { + request.addParameter(OAuthConstants.REDIRECT_URI, callback); + } final String scope = getScope(); if (scope != null) { request.addParameter(OAuthConstants.SCOPE, scope); From 701d8d8d13c108cb02e9f7bf73dcdf8120a0c3fd Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 14 Sep 2018 14:12:48 +0300 Subject: [PATCH 518/882] make redirect_uri optional while Access Token requesting on OAuth 2.0 (thanks to https://github.com/computerlove) --- changelog | 3 +++ .../java/com/github/scribejava/core/oauth/OAuth20Service.java | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/changelog b/changelog index d7e6441ee..ed410e999 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,6 @@ +[SNAPSHOT] + * make redirect_uri optional while Access Token requesting on OAuth 2.0 (thanks to https://github.com/computerlove) + [5.6.0] * remove support for obsolete NetEase (http://www.163.com/) and sohu 搜狐 (http://www.sohu.com/) (thanks to https://github.com/zawn) * add Multipart functionality to JDK Http Client (thanks to https://github.com/eos1d3) diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java index addd023a7..d02b3f17b 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java @@ -108,7 +108,7 @@ protected OAuthRequest createAccessTokenRequest(String code) { api.getClientAuthentication().addClientAuthentication(request, getApiKey(), getApiSecret()); request.addParameter(OAuthConstants.CODE, code); - String callback = getCallback(); + final String callback = getCallback(); if (callback != null) { request.addParameter(OAuthConstants.REDIRECT_URI, callback); } From f974ca0714ea5c3f99e4f816867f456f8b23d316 Mon Sep 17 00:00:00 2001 From: Jokuni Date: Sun, 23 Sep 2018 01:47:54 +0200 Subject: [PATCH 519/882] Add support for Discord based on https://github.com/scribejava/scribejava/pull/735 --- README.md | 1 + .../github/scribejava/apis/DiscordApi.java | 47 ++++++++++ .../apis/service/DiscordService.java | 23 +++++ .../apis/examples/DiscordExample.java | 91 +++++++++++++++++++ 4 files changed, 162 insertions(+) create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/DiscordApi.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/service/DiscordService.java create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiscordExample.java diff --git a/README.md b/README.md index 25b0ce33e..86501a17b 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,7 @@ ScribeJava support out-of-box several HTTP clients: * Box (https://www.box.com/) * Dataporten (https://docs.dataporten.no/) * Digg (http://digg.com/) +* Discord (https://discordapp.com/) * Доктор на работе (https://www.doktornarabote.ru/) * Etsy (https://www.etsy.com/) * Facebook (https://www.facebook.com/) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/DiscordApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/DiscordApi.java new file mode 100644 index 000000000..96a3c31bf --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/DiscordApi.java @@ -0,0 +1,47 @@ +package com.github.scribejava.apis; + +import com.github.scribejava.apis.service.DiscordService; +import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.httpclient.HttpClient; +import com.github.scribejava.core.httpclient.HttpClientConfig; +import com.github.scribejava.core.oauth.OAuth20Service; + +import java.io.OutputStream; + +public class DiscordApi extends DefaultApi20 { + + private DiscordApi() { + } + + private static class InstanceHolder { + private static final DiscordApi INSTANCE = new DiscordApi(); + } + + public static DiscordApi instance() { + return DiscordApi.InstanceHolder.INSTANCE; + } + + @Override + protected String getAuthorizationBaseUrl() { + return "https://discordapp.com/api/oauth2/authorize"; + } + + @Override + public String getRevokeTokenEndpoint() { + return "https://discordapp.com/api/oauth2/token/revoke"; + } + + @Override + public String getAccessTokenEndpoint() { + return "https://discordapp.com/api/oauth2/token"; + } + + @Override + public OAuth20Service createService(String apiKey, String apiSecret, String callback, + String scope, OutputStream debugStream, String state, + String responseType, String userAgent, + HttpClientConfig httpClientConfig, HttpClient httpClient) { + return new DiscordService(this, apiKey, apiSecret, callback, scope, state, responseType, + userAgent, httpClientConfig, httpClient); + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/DiscordService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/DiscordService.java new file mode 100644 index 000000000..c97c10d7d --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/DiscordService.java @@ -0,0 +1,23 @@ +package com.github.scribejava.apis.service; + +import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.httpclient.HttpClient; +import com.github.scribejava.core.httpclient.HttpClientConfig; +import com.github.scribejava.core.model.OAuth2AccessToken; +import com.github.scribejava.core.model.OAuthConstants; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.oauth.OAuth20Service; + +public class DiscordService extends OAuth20Service { + public DiscordService(DefaultApi20 api, String apiKey, String apiSecret, String callback, + String scope, String state, String responseType, String userAgent, + HttpClientConfig httpClientConfig, HttpClient httpClient) { + super(api, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); + } + + @Override + public void signRequest(OAuth2AccessToken accessToken, OAuthRequest request) { + request.addHeader(OAuthConstants.HEADER, accessToken.getTokenType() + ' ' + accessToken.getAccessToken()); + } + +} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiscordExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiscordExample.java new file mode 100644 index 000000000..cad56cd73 --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiscordExample.java @@ -0,0 +1,91 @@ +package com.github.scribejava.apis.examples; + +import com.github.scribejava.apis.DiscordApi; +import com.github.scribejava.core.builder.ServiceBuilder; +import com.github.scribejava.core.model.OAuth2AccessToken; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.oauth.OAuth20Service; + +import java.io.IOException; +import java.util.Random; +import java.util.Scanner; +import java.util.concurrent.ExecutionException; + +public final class DiscordExample { + + private static final String NETWORK_NAME = "Discord"; + private static final String PROTECTED_RESOURCE_URL = "https://discordapp.com/api/users/@me"; + + private DiscordExample() { + } + + public static void main(String... args) throws IOException, ExecutionException, InterruptedException { + // Replace these with your client id and secret + final String clientId = "client id"; + final String clientSecret = "client secret"; + final String secretState = "secret" + new Random().nextInt(999_999); + final OAuth20Service service = new ServiceBuilder(clientId) + .apiSecret(clientSecret) + .scope("identify") // replace with desired scope + .state(secretState) + .callback("http://example.com/callback") + .userAgent("ScribeJava") + .build(DiscordApi.instance()); + final Scanner in = new Scanner(System.in, "UTF-8"); + + System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); + System.out.println(); + + // Obtain the Authorization URL + System.out.println("Fetching the Authorization URL..."); + final String authorizationUrl = service.getAuthorizationUrl(); + System.out.println("Got the Authorization URL!"); + System.out.println("Now go and authorize ScribeJava here:"); + System.out.println(authorizationUrl); + System.out.println("And paste the authorization code here"); + System.out.print(">>"); + final String code = in.nextLine(); + System.out.println(); + + System.out.println("And paste the state from server here. We have set 'secretState'='" + secretState + "'."); + System.out.print(">>"); + final String value = in.nextLine(); + if (secretState.equals(value)) { + System.out.println("State value does match!"); + } else { + System.out.println("Ooops, state value does not match!"); + System.out.println("Expected = " + secretState); + System.out.println("Got = " + value); + System.out.println(); + } + + // Trade the Request Token and Verfier for the Access Token + System.out.println("Trading the Request Token for an Access Token..."); + OAuth2AccessToken accessToken = service.getAccessToken(code); + System.out.println("Got the Access Token!"); + System.out.println("(if your curious it looks like this: " + accessToken + + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + + System.out.println("Refreshing the Access Token..."); + accessToken = service.refreshAccessToken(accessToken.getRefreshToken()); + System.out.println("Refreshed the Access Token!"); + System.out.println("(if your curious it looks like this: " + accessToken + + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println(); + + // Now let's go and ask for a protected resource! + System.out.println("Now we're going to access a protected resource..."); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); + service.signRequest(accessToken, request); + final Response response = service.execute(request); + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + + System.out.println(); + System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); + } +} From f69dbb249e56b560aecc4fb789e4421c4a2bd56c Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 25 Sep 2018 18:16:23 +0300 Subject: [PATCH 520/882] remove travis integration --- .travis.yml | 7 ------- README.md | 1 - 2 files changed, 8 deletions(-) delete mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 1420112b3..000000000 --- a/.travis.yml +++ /dev/null @@ -1,7 +0,0 @@ -dist: trusty -language: java -script: mvn clean package -jdk: - - openjdk7 -os: - - linux diff --git a/README.md b/README.md index 25b0ce33e..2ab83e798 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,5 @@ # Welcome to the home of ScribeJava, the simple OAuth client Java lib! -[![Build Status](https://travis-ci.org/scribejava/scribejava.svg?branch=master)](https://travis-ci.org/scribejava/scribejava) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.github.scribejava/scribejava/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.github.scribejava/scribejava) From c4254c3aa5b15b249cd2eddfd2ff965899ed548a Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 27 Sep 2018 14:17:33 +0300 Subject: [PATCH 521/882] switch to java 9+ (from java 7 only) for compilation. Runtime is still java 7+. Complement README with links and RFC descriptions. --- README.md | 19 +++++-- changelog | 4 +- pom.xml | 54 ++++++++++--------- .../github/scribejava/apis/MediaWikiApi.java | 6 ++- .../core/builder/api/DefaultApi20.java | 5 ++ .../extractors/BaseStringExtractorImpl.java | 2 + .../github/scribejava/core/java8/Base64.java | 38 +++++++------ .../scribejava/core/model/OAuthRequest.java | 3 ++ .../services/RSASha1SignatureServiceTest.java | 7 +-- .../httpclient/ahc/AhcHttpClientTest.java | 2 - 10 files changed, 87 insertions(+), 53 deletions(-) diff --git a/README.md b/README.md index 2ab83e798..6ab369f0f 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,7 @@ OAuthService service = new ServiceBuilder(YOUR_API_KEY) That **single line** (added newlines for readability) is the only thing you need to configure ScribeJava with LinkedIn's OAuth API for example. Working runnable examples are [here](https://github.com/scribejava/scribejava/tree/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples) +Common usage: [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java) ### Threadsafe @@ -26,17 +27,27 @@ Hit ScribeJava as hard and with many threads as you like. ### Java 7 compatible That's it. You can use it in old environments and in android apps. +note: To compile from sources you will need Java 9 or newer ### Async and other HTTP clients ScribeJava support out-of-box several HTTP clients: - * ning async http client 1.9.x (maven module scribejava-httpclient-ning) - * Async Http Client asynchttpclient 2.x (maven module scribejava-httpclient-ahc) - * OkHttp (maven module scribejava-httpclient-okhttp) - * Apache HttpComponents HttpClient (maven module scribejava-httpclient-apache) + * ning async http client 1.9.x (maven module scribejava-httpclient-ning) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java) + * Async Http Client asynchttpclient 2.x (maven module scribejava-httpclient-ahc) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java) + * OkHttp (maven module scribejava-httpclient-okhttp) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubAsyncOkHttpExample.java) + * Apache HttpComponents HttpClient (maven module scribejava-httpclient-apache) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncApacheExample.java) + * any externally created HTTP client [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExternalHttpExample.java) just add corresponding maven modules to your pom +### Supports many flows and additional features + + * RFC 6749 The OAuth 2.0 Authorization Framework, Authorization Code Authorization Grant [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java) + * RFC 6749 The OAuth 2.0 Authorization Framework, Client Credentials Authorization Grant [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteClientCredentialsGrantExample.java) + * RFC 6749 The OAuth 2.0 Authorization Framework, Resource Owner Password Credentials Authorization Grant + * RFC 7636 Proof Key for Code Exchange by OAuth Public Clients (PKCE) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20WithPKCEExample.java) + * RFC 7009 OAuth 2.0 Token Revocation [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20RevokeExample.java) + ### Supports all major 1.0a and 2.0 OAuth APIs out-of-the-box * Automatic (https://www.automatic.com/) diff --git a/changelog b/changelog index ed410e999..e2df12e69 100644 --- a/changelog +++ b/changelog @@ -1,5 +1,6 @@ [SNAPSHOT] * make redirect_uri optional while Access Token requesting on OAuth 2.0 (thanks to https://github.com/computerlove) + * switch to java 9+ (from java 7 only) for compilation. Runtime is still java 7+. Complement README with links and RFC descriptions. [5.6.0] * remove support for obsolete NetEase (http://www.163.com/) and sohu 搜狐 (http://www.sohu.com/) (thanks to https://github.com/zawn) @@ -205,8 +206,7 @@ [2.0] * merge back SubScribe fork to the ScribeJava - + for previous changes see v1-changelog - changelog for 1.x version v2pre-changelog - changelog for SubScribe fork - diff --git a/pom.xml b/pom.xml index 30c158970..85d155e54 100644 --- a/pom.xml +++ b/pom.xml @@ -34,8 +34,8 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - HEAD - + HEAD + @@ -78,7 +78,7 @@ org.apache.felix maven-bundle-plugin - 3.5.1 + 4.0.0 bundle-manifest @@ -107,17 +107,38 @@ com.puppycrawl.tools checkstyle - 6.19 + 8.12 + org.apache.maven.plugins maven-release-plugin 2.5.3 true + + org.apache.maven.plugins + maven-surefire-plugin + 2.22.0 + + + org.apache.maven.plugins + maven-clean-plugin + 3.1.0 + + + org.apache.maven.plugins + maven-enforcer-plugin + 1.4.1 + + + org.apache.maven.plugins + maven-install-plugin + 2.5.2 +
@@ -126,8 +147,7 @@ 3.8.0 UTF-8 - 1.7 - 1.7 + 7 true
@@ -170,7 +190,9 @@ maven-javadoc-plugin 3.0.1 + ${java.home}/bin/javadoc UTF-8 + -html5 @@ -203,26 +225,6 @@
- - org.apache.maven.plugins - maven-enforcer-plugin - 1.4.1 - - - enforce-java - - enforce - - - - - (,1.8) - - - - - -
diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/MediaWikiApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/MediaWikiApi.java index 8426d1924..d3c078f9b 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/MediaWikiApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/MediaWikiApi.java @@ -36,10 +36,12 @@ public MediaWikiApi(String indexUrl, String niceUrlBase) { } /** - * The instance for wikis hosted by the Wikimedia Foundation. Consumers are requested on + * The instance for wikis hosted by the Wikimedia Foundation.Consumers are requested on * * Special:OAuthConsumerRegistration/propose * . + * + * @return instance */ public static MediaWikiApi instance() { return InstanceHolder.INSTANCE; @@ -50,6 +52,8 @@ public static MediaWikiApi instance() { * * Special:OAuthConsumerRegistration/propose * . + * + * @return instanceBeta */ public static MediaWikiApi instanceBeta() { return BetaInstanceHolder.BETA_INSTANCE; diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java index e10a57aeb..6eec12bb6 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java @@ -75,7 +75,12 @@ public String getRevokeTokenEndpoint() { /** * Returns the URL where you should redirect your users to authenticate your application. * + * @param responseType responseType + * @param apiKey apiKey * @param additionalParams any additional GET params to add to the URL + * @param callback callback + * @param state state + * @param scope scope * @return the URL where you should redirect your users */ public String getAuthorizationUrl(String responseType, String apiKey, String callback, String scope, String state, diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/BaseStringExtractorImpl.java b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/BaseStringExtractorImpl.java index acda30254..3547fbcac 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/BaseStringExtractorImpl.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/BaseStringExtractorImpl.java @@ -32,6 +32,8 @@ protected String getVerb(OAuthRequest request) { /** * https://tools.ietf.org/html/rfc5849#section-3.4.1.2 + * @param request request + * @return url */ protected String getUrl(OAuthRequest request) { return request.getSanitizedUrl(); diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/java8/Base64.java b/scribejava-core/src/main/java/com/github/scribejava/core/java8/Base64.java index 7e599c6e5..6da66f9de 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/java8/Base64.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/java8/Base64.java @@ -40,19 +40,19 @@ * RFC 2045. * *
    - *
  • Basic + *
  • Basic *

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

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

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

  • * - *
  • MIME + *
  • MIME *

    * Uses the "The Base64 Alphabet" as specified in Table 1 of RFC 2045 for encoding and decoding operation. The encoded * output must be represented in lines of no more than 76 characters each and uses a carriage return {@code '\r'} @@ -629,7 +629,8 @@ private int outLength(byte[] src, int sp, int sl) { len -= (sl - sp + 1); break; } - if ((b = base64[b]) == -1) { + b = base64[b]; + if (b == -1) { n++; } } @@ -655,7 +656,8 @@ private int decode0(byte[] src, int sp, int sl, byte[] dst) { int shiftto = 18; // pos of first byte of 4-byte atom while (sp < sl) { int b = src[sp++] & 0xff; - if ((b = base64[b]) < 0) { + b = base64[b]; + if (b < 0) { if (b == -2) { // padding byte '=' // = shiftto==18 unnecessary padding // x= shiftto==12 a dangling single x @@ -689,15 +691,20 @@ private int decode0(byte[] src, int sp, int sl, byte[] dst) { } } // reached end of byte array or hit padding '=' characters. - if (shiftto == 6) { - dst[dp++] = (byte) (bits >> 16); - } else if (shiftto == 0) { - dst[dp++] = (byte) (bits >> 16); - dst[dp++] = (byte) (bits >> 8); - } else if (shiftto == 12) { - // dangling single "x", incorrectly encoded. - throw new IllegalArgumentException( - "Last unit does not have enough valid bits"); + switch (shiftto) { + case 6: + dst[dp++] = (byte) (bits >> 16); + break; + case 0: + dst[dp++] = (byte) (bits >> 16); + dst[dp++] = (byte) (bits >> 8); + break; + case 12: + // dangling single "x", incorrectly encoded. + throw new IllegalArgumentException( + "Last unit does not have enough valid bits"); + default: + break; } // anything left is invalid, if is not MIME. // if MIME, ignore all non-base64 character @@ -929,7 +936,8 @@ public int read(byte[] b, int off, int len) throws IOException { eof = true; break; } - if ((v = base64[v]) == -1) { + v = base64[v]; + if (v == -1) { if (isMIME) // skip if for rfc2045 { continue; diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequest.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequest.java index d132da1dc..87ace27bc 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequest.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequest.java @@ -147,6 +147,9 @@ public void initMultipartBoundary() { /** * you can invoke {@link #initMultipartBoundary(java.lang.String) } to set custom boundary + * @param contentDisposition contentDisposition + * @param contentType contentType + * @param payload payload */ public void addMultipartPayload(String contentDisposition, String contentType, byte[] payload) { if (multipartPayload == null) { diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/services/RSASha1SignatureServiceTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/services/RSASha1SignatureServiceTest.java index 261bc2bb4..adf93c68f 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/services/RSASha1SignatureServiceTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/services/RSASha1SignatureServiceTest.java @@ -1,11 +1,11 @@ package com.github.scribejava.core.services; +import com.github.scribejava.core.java8.Base64; import java.security.KeyFactory; import java.security.NoSuchAlgorithmException; import java.security.PrivateKey; import java.security.spec.InvalidKeySpecException; import java.security.spec.PKCS8EncodedKeySpec; -import javax.xml.bind.DatatypeConverter; import static org.junit.Assert.assertEquals; import org.junit.Test; @@ -48,11 +48,12 @@ private static PrivateKey getPrivateKey() { + "I/AfAkEA0Y9vr0tombsUB8cZv0v5OYoBZvCTbMANtzfb4AOHpiKqqbohDOevLQ7/\n" + "SpvgVCmVaDz2PptcRAyEBZ5MCssneQJAB2pmvaDH7Ambfod5bztLfOhLCtY5EkXJ\n" + "n6rZcDbRaHorRhdG7m3VtDKOUKZ2DF7glkQGV33phKukErVPUzlHBwJAScD9TqaG\n" - + "wJ3juUsVtujV23SnH43iMggXT7m82STpPGam1hPfmqu2Z0niePFo927ogQ7H1EMJ\n" + "UHgqXmuvk2X/Ww=="; + + "wJ3juUsVtujV23SnH43iMggXT7m82STpPGam1hPfmqu2Z0niePFo927ogQ7H1EMJ\n" + + "UHgqXmuvk2X/Ww=="; try { final KeyFactory fac = KeyFactory.getInstance("RSA"); - final PKCS8EncodedKeySpec privKeySpec = new PKCS8EncodedKeySpec(DatatypeConverter.parseBase64Binary(str)); + final PKCS8EncodedKeySpec privKeySpec = new PKCS8EncodedKeySpec(Base64.getMimeDecoder().decode(str)); return fac.generatePrivate(privKeySpec); } catch (NoSuchAlgorithmException | InvalidKeySpecException e) { throw new RuntimeException(e); diff --git a/scribejava-httpclient-ahc/src/test/java/com/github/scribejava/httpclient/ahc/AhcHttpClientTest.java b/scribejava-httpclient-ahc/src/test/java/com/github/scribejava/httpclient/ahc/AhcHttpClientTest.java index 1ee1ebaa1..5de2d153e 100644 --- a/scribejava-httpclient-ahc/src/test/java/com/github/scribejava/httpclient/ahc/AhcHttpClientTest.java +++ b/scribejava-httpclient-ahc/src/test/java/com/github/scribejava/httpclient/ahc/AhcHttpClientTest.java @@ -2,9 +2,7 @@ import com.github.scribejava.core.AbstractClientTest; import com.github.scribejava.core.httpclient.HttpClient; -import org.junit.Ignore; -@Ignore(value = "we are java7 and AHC is java8") public class AhcHttpClientTest extends AbstractClientTest { @Override From d82112bb4d41c39265c3447c4d51ad97dff5ed2f Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 8 Oct 2018 11:54:50 +0300 Subject: [PATCH 522/882] switch OAuth2 Bearer Token Usage from enum OAuth2SignatureType to interface BearerSignature to be extensible --- README.md | 1 + changelog | 3 +- .../com/github/scribejava/apis/BoxApi20.java | 7 +++-- .../scribejava/apis/Foursquare2Api.java | 7 +++-- .../github/scribejava/apis/KaixinApi20.java | 7 +++-- .../com/github/scribejava/apis/LiveApi.java | 7 +++-- .../com/github/scribejava/apis/MisfitApi.java | 7 +++-- .../com/github/scribejava/apis/NaverApi.java | 7 +++-- .../scribejava/apis/OdnoklassnikiApi.java | 7 +++-- .../com/github/scribejava/apis/RenrenApi.java | 7 +++-- .../scribejava/apis/SinaWeiboApi20.java | 7 +++-- .../scribejava/apis/StackExchangeApi.java | 7 +++-- .../com/github/scribejava/apis/ViadeoApi.java | 7 +++-- .../github/scribejava/apis/VkontakteApi.java | 7 +++-- .../core/builder/api/DefaultApi20.java | 18 ++++++++++++ .../core/builder/api/OAuth2SignatureType.java | 19 +++++++++---- .../scribejava/core/oauth/OAuth20Service.java | 2 +- .../bearersignature/BearerSignature.java | 12 ++++++++ ...natureAuthorizationRequestHeaderField.java | 28 +++++++++++++++++++ .../BearerSignatureURIQueryParameter.java | 27 ++++++++++++++++++ .../scribejava/core/oauth/OAuth20ApiUnit.java | 7 +++-- 21 files changed, 154 insertions(+), 47 deletions(-) create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/oauth2/bearersignature/BearerSignature.java create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/oauth2/bearersignature/BearerSignatureAuthorizationRequestHeaderField.java create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/oauth2/bearersignature/BearerSignatureURIQueryParameter.java diff --git a/README.md b/README.md index 6ab369f0f..4e82b188e 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,7 @@ ScribeJava support out-of-box several HTTP clients: * RFC 6749 The OAuth 2.0 Authorization Framework, Authorization Code Authorization Grant [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java) * RFC 6749 The OAuth 2.0 Authorization Framework, Client Credentials Authorization Grant [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteClientCredentialsGrantExample.java) * RFC 6749 The OAuth 2.0 Authorization Framework, Resource Owner Password Credentials Authorization Grant + * RFC 6750 The OAuth 2.0 Authorization Framework: Bearer Token Usage * RFC 7636 Proof Key for Code Exchange by OAuth Public Clients (PKCE) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20WithPKCEExample.java) * RFC 7009 OAuth 2.0 Token Revocation [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20RevokeExample.java) diff --git a/changelog b/changelog index e2df12e69..869884876 100644 --- a/changelog +++ b/changelog @@ -1,11 +1,12 @@ [SNAPSHOT] * make redirect_uri optional while Access Token requesting on OAuth 2.0 (thanks to https://github.com/computerlove) * switch to java 9+ (from java 7 only) for compilation. Runtime is still java 7+. Complement README with links and RFC descriptions. + * switch OAuth2 Bearer Token Usage from enum OAuth2SignatureType to interface BearerSignature to be extensible [5.6.0] * remove support for obsolete NetEase (http://www.163.com/) and sohu 搜狐 (http://www.sohu.com/) (thanks to https://github.com/zawn) * add Multipart functionality to JDK Http Client (thanks to https://github.com/eos1d3) - * switch OAuth2 ClientAuthenticationType from enum to interface to be extensible according to + * switch OAuth2 ClientAuthenticationType from enum to interface ClientAuthentication to be extensible according to https://tools.ietf.org/html/rfc6749#section-2.3.2 (thanks to https://github.com/zawn) * add RuntimeException processing in async http clients (delivered to onError callbacks) (thanks to https://github.com/jochen314) * check 200 status code from response in OAuth2AccessTokenExtractor (thanks to https://github.com/jochen314) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/BoxApi20.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/BoxApi20.java index d21cc39be..91a4b7c16 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/BoxApi20.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/BoxApi20.java @@ -1,7 +1,8 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.builder.api.OAuth2SignatureType; +import com.github.scribejava.core.oauth2.bearersignature.BearerSignature; +import com.github.scribejava.core.oauth2.bearersignature.BearerSignatureURIQueryParameter; /** * Box.com Api @@ -31,7 +32,7 @@ protected String getAuthorizationBaseUrl() { } @Override - public OAuth2SignatureType getSignatureType() { - return OAuth2SignatureType.BEARER_URI_QUERY_PARAMETER; + public BearerSignature getBearerSignature() { + return BearerSignatureURIQueryParameter.instance(); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/Foursquare2Api.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/Foursquare2Api.java index 321554af2..a90547f3a 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/Foursquare2Api.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/Foursquare2Api.java @@ -1,8 +1,9 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.builder.api.OAuth2SignatureType; import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.oauth2.bearersignature.BearerSignature; +import com.github.scribejava.core.oauth2.bearersignature.BearerSignatureURIQueryParameter; public class Foursquare2Api extends DefaultApi20 { @@ -33,7 +34,7 @@ protected String getAuthorizationBaseUrl() { } @Override - public OAuth2SignatureType getSignatureType() { - return OAuth2SignatureType.BEARER_URI_QUERY_PARAMETER; + public BearerSignature getBearerSignature() { + return BearerSignatureURIQueryParameter.instance(); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/KaixinApi20.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/KaixinApi20.java index 927813535..b94e8e1a3 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/KaixinApi20.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/KaixinApi20.java @@ -1,8 +1,9 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.builder.api.OAuth2SignatureType; import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.oauth2.bearersignature.BearerSignature; +import com.github.scribejava.core.oauth2.bearersignature.BearerSignatureURIQueryParameter; /** * Kaixin(http://www.kaixin001.com/) open platform api based on OAuth 2.0. @@ -36,7 +37,7 @@ protected String getAuthorizationBaseUrl() { } @Override - public OAuth2SignatureType getSignatureType() { - return OAuth2SignatureType.BEARER_URI_QUERY_PARAMETER; + public BearerSignature getBearerSignature() { + return BearerSignatureURIQueryParameter.instance(); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/LiveApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/LiveApi.java index 83cd89780..7a0a64ea5 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/LiveApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/LiveApi.java @@ -1,7 +1,8 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.builder.api.OAuth2SignatureType; +import com.github.scribejava.core.oauth2.bearersignature.BearerSignature; +import com.github.scribejava.core.oauth2.bearersignature.BearerSignatureURIQueryParameter; public class LiveApi extends DefaultApi20 { @@ -27,7 +28,7 @@ protected String getAuthorizationBaseUrl() { } @Override - public OAuth2SignatureType getSignatureType() { - return OAuth2SignatureType.BEARER_URI_QUERY_PARAMETER; + public BearerSignature getBearerSignature() { + return BearerSignatureURIQueryParameter.instance(); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/MisfitApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/MisfitApi.java index c34d2cc15..051de70c1 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/MisfitApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/MisfitApi.java @@ -1,7 +1,8 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.builder.api.OAuth2SignatureType; +import com.github.scribejava.core.oauth2.bearersignature.BearerSignature; +import com.github.scribejava.core.oauth2.bearersignature.BearerSignatureURIQueryParameter; public class MisfitApi extends DefaultApi20 { @@ -28,7 +29,7 @@ protected String getAuthorizationBaseUrl() { } @Override - public OAuth2SignatureType getSignatureType() { - return OAuth2SignatureType.BEARER_URI_QUERY_PARAMETER; + public BearerSignature getBearerSignature() { + return BearerSignatureURIQueryParameter.instance(); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/NaverApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/NaverApi.java index a3028ae11..3ff3a9b0a 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/NaverApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/NaverApi.java @@ -1,7 +1,8 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.builder.api.OAuth2SignatureType; +import com.github.scribejava.core.oauth2.bearersignature.BearerSignature; +import com.github.scribejava.core.oauth2.bearersignature.BearerSignatureURIQueryParameter; public class NaverApi extends DefaultApi20 { protected NaverApi() { @@ -29,7 +30,7 @@ protected String getAuthorizationBaseUrl() { } @Override - public OAuth2SignatureType getSignatureType() { - return OAuth2SignatureType.BEARER_URI_QUERY_PARAMETER; + public BearerSignature getBearerSignature() { + return BearerSignatureURIQueryParameter.instance(); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java index e7db8838d..f82b585b6 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java @@ -2,9 +2,10 @@ import com.github.scribejava.apis.service.OdnoklassnikiOAuthService; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.builder.api.OAuth2SignatureType; import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.httpclient.HttpClientConfig; +import com.github.scribejava.core.oauth2.bearersignature.BearerSignature; +import com.github.scribejava.core.oauth2.bearersignature.BearerSignatureURIQueryParameter; import com.github.scribejava.core.oauth2.clientauthentication.ClientAuthentication; import com.github.scribejava.core.oauth2.clientauthentication.RequestBodyAuthenticationScheme; import java.io.OutputStream; @@ -41,8 +42,8 @@ public OdnoklassnikiOAuthService createService(String apiKey, String apiSecret, } @Override - public OAuth2SignatureType getSignatureType() { - return OAuth2SignatureType.BEARER_URI_QUERY_PARAMETER; + public BearerSignature getBearerSignature() { + return BearerSignatureURIQueryParameter.instance(); } @Override diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/RenrenApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/RenrenApi.java index cc475440e..d4ade9fad 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/RenrenApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/RenrenApi.java @@ -1,8 +1,9 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.builder.api.OAuth2SignatureType; import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.oauth2.bearersignature.BearerSignature; +import com.github.scribejava.core.oauth2.bearersignature.BearerSignatureURIQueryParameter; /** * Renren(http://www.renren.com/) OAuth 2.0 based api. @@ -36,7 +37,7 @@ protected String getAuthorizationBaseUrl() { } @Override - public OAuth2SignatureType getSignatureType() { - return OAuth2SignatureType.BEARER_URI_QUERY_PARAMETER; + public BearerSignature getBearerSignature() { + return BearerSignatureURIQueryParameter.instance(); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/SinaWeiboApi20.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/SinaWeiboApi20.java index edd316f87..19aa9f356 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/SinaWeiboApi20.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/SinaWeiboApi20.java @@ -1,7 +1,8 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.builder.api.OAuth2SignatureType; +import com.github.scribejava.core.oauth2.bearersignature.BearerSignature; +import com.github.scribejava.core.oauth2.bearersignature.BearerSignatureURIQueryParameter; /** * SinaWeibo OAuth 2.0 api. @@ -30,7 +31,7 @@ protected String getAuthorizationBaseUrl() { } @Override - public OAuth2SignatureType getSignatureType() { - return OAuth2SignatureType.BEARER_URI_QUERY_PARAMETER; + public BearerSignature getBearerSignature() { + return BearerSignatureURIQueryParameter.instance(); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/StackExchangeApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/StackExchangeApi.java index 554c97b33..3ba195460 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/StackExchangeApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/StackExchangeApi.java @@ -1,10 +1,11 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.builder.api.OAuth2SignatureType; import com.github.scribejava.core.extractors.OAuth2AccessTokenExtractor; import com.github.scribejava.core.extractors.TokenExtractor; import com.github.scribejava.core.model.OAuth2AccessToken; +import com.github.scribejava.core.oauth2.bearersignature.BearerSignature; +import com.github.scribejava.core.oauth2.bearersignature.BearerSignatureURIQueryParameter; /** * Stack Exchange authentication via OAuth 2.0 (stackoverflow.com, @@ -39,7 +40,7 @@ public TokenExtractor getAccessTokenExtractor() { } @Override - public OAuth2SignatureType getSignatureType() { - return OAuth2SignatureType.BEARER_URI_QUERY_PARAMETER; + public BearerSignature getBearerSignature() { + return BearerSignatureURIQueryParameter.instance(); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/ViadeoApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/ViadeoApi.java index 30c0ffcfe..fb70de258 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/ViadeoApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/ViadeoApi.java @@ -1,8 +1,9 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.builder.api.OAuth2SignatureType; import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.oauth2.bearersignature.BearerSignature; +import com.github.scribejava.core.oauth2.bearersignature.BearerSignatureURIQueryParameter; public class ViadeoApi extends DefaultApi20 { @@ -33,7 +34,7 @@ protected String getAuthorizationBaseUrl() { } @Override - public OAuth2SignatureType getSignatureType() { - return OAuth2SignatureType.BEARER_URI_QUERY_PARAMETER; + public BearerSignature getBearerSignature() { + return BearerSignatureURIQueryParameter.instance(); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/VkontakteApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/VkontakteApi.java index ff11d902c..1662891c3 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/VkontakteApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/VkontakteApi.java @@ -2,10 +2,11 @@ import com.github.scribejava.apis.vk.VKJsonTokenExtractor; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.builder.api.OAuth2SignatureType; import com.github.scribejava.core.extractors.TokenExtractor; import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.oauth2.bearersignature.BearerSignature; +import com.github.scribejava.core.oauth2.bearersignature.BearerSignatureURIQueryParameter; import com.github.scribejava.core.oauth2.clientauthentication.ClientAuthentication; import com.github.scribejava.core.oauth2.clientauthentication.RequestBodyAuthenticationScheme; @@ -41,8 +42,8 @@ protected String getAuthorizationBaseUrl() { } @Override - public OAuth2SignatureType getSignatureType() { - return OAuth2SignatureType.BEARER_URI_QUERY_PARAMETER; + public BearerSignature getBearerSignature() { + return BearerSignatureURIQueryParameter.instance(); } @Override diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java index 6eec12bb6..84d7ab91c 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java @@ -9,6 +9,9 @@ import com.github.scribejava.core.model.ParameterList; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.oauth.OAuth20Service; +import com.github.scribejava.core.oauth2.bearersignature.BearerSignature; +import com.github.scribejava.core.oauth2.bearersignature.BearerSignatureAuthorizationRequestHeaderField; +import com.github.scribejava.core.oauth2.bearersignature.BearerSignatureURIQueryParameter; import com.github.scribejava.core.oauth2.clientauthentication.ClientAuthentication; import com.github.scribejava.core.oauth2.clientauthentication.HttpBasicAuthenticationScheme; import java.io.OutputStream; @@ -112,10 +115,25 @@ public OAuth20Service createService(String apiKey, String apiSecret, String call httpClientConfig, httpClient); } + /** + * @deprecated use {@link #getBearerSignature() } + */ + @Deprecated public OAuth2SignatureType getSignatureType() { return OAuth2SignatureType.BEARER_AUTHORIZATION_REQUEST_HEADER_FIELD; } + public BearerSignature getBearerSignature() { + switch (getSignatureType()) { + case BEARER_AUTHORIZATION_REQUEST_HEADER_FIELD: + return BearerSignatureAuthorizationRequestHeaderField.instance(); + case BEARER_URI_QUERY_PARAMETER: + return BearerSignatureURIQueryParameter.instance(); + default: + throw new IllegalStateException("unknown OAuth2SignatureType"); + } + } + public ClientAuthentication getClientAuthentication() { return HttpBasicAuthenticationScheme.instance(); } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/OAuth2SignatureType.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/OAuth2SignatureType.java index c42b54d98..baf246381 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/OAuth2SignatureType.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/OAuth2SignatureType.java @@ -1,28 +1,35 @@ package com.github.scribejava.core.builder.api; -import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.oauth2.bearersignature.BearerSignatureAuthorizationRequestHeaderField; +import com.github.scribejava.core.oauth2.bearersignature.BearerSignatureURIQueryParameter; +/** + * @deprecated use {@link com.github.scribejava.core.oauth2.bearersignature.BearerSignature} + */ +@Deprecated public enum OAuth2SignatureType { /** - * https://tools.ietf.org/html/rfc6750#section-2.1 + * @deprecated use + * {@link com.github.scribejava.core.oauth2.bearersignature.BearerSignatureAuthorizationRequestHeaderField} */ + @Deprecated BEARER_AUTHORIZATION_REQUEST_HEADER_FIELD { @Override public void signRequest(String accessToken, OAuthRequest request) { - request.addHeader("Authorization", "Bearer " + accessToken); + BearerSignatureAuthorizationRequestHeaderField.instance().signRequest(accessToken, request); } }, /** - * https://tools.ietf.org/html/rfc6750#section-2.3 + * @deprecated use {@link com.github.scribejava.core.oauth2.bearersignature.BearerSignatureURIQueryParameter} */ + @Deprecated BEARER_URI_QUERY_PARAMETER { @Override public void signRequest(String accessToken, OAuthRequest request) { - request.addQuerystringParameter(OAuthConstants.ACCESS_TOKEN, accessToken); + BearerSignatureURIQueryParameter.instance().signRequest(accessToken, request); } - }; public abstract void signRequest(String accessToken, OAuthRequest request); diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java index d02b3f17b..f7564ff1d 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java @@ -254,7 +254,7 @@ public String getVersion() { } public void signRequest(String accessToken, OAuthRequest request) { - api.getSignatureType().signRequest(accessToken, request); + api.getBearerSignature().signRequest(accessToken, request); } public void signRequest(OAuth2AccessToken accessToken, OAuthRequest request) { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth2/bearersignature/BearerSignature.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth2/bearersignature/BearerSignature.java new file mode 100644 index 000000000..61739e93e --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth2/bearersignature/BearerSignature.java @@ -0,0 +1,12 @@ +package com.github.scribejava.core.oauth2.bearersignature; + +import com.github.scribejava.core.model.OAuthRequest; + +/** + * Represents
    + * 2. Authenticated Requests
    + * https://tools.ietf.org/html/rfc6750#section-2 + */ +public interface BearerSignature { + void signRequest(String accessToken, OAuthRequest request); +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth2/bearersignature/BearerSignatureAuthorizationRequestHeaderField.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth2/bearersignature/BearerSignatureAuthorizationRequestHeaderField.java new file mode 100644 index 000000000..72ab0cbd2 --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth2/bearersignature/BearerSignatureAuthorizationRequestHeaderField.java @@ -0,0 +1,28 @@ +package com.github.scribejava.core.oauth2.bearersignature; + +import com.github.scribejava.core.model.OAuthRequest; + +/** + * 2.1. Authorization Request Header Field
    + * https://tools.ietf.org/html/rfc6750#section-2.1 + */ +public class BearerSignatureAuthorizationRequestHeaderField implements BearerSignature { + + protected BearerSignatureAuthorizationRequestHeaderField() { + } + + private static class InstanceHolder { + + private static final BearerSignatureAuthorizationRequestHeaderField INSTANCE + = new BearerSignatureAuthorizationRequestHeaderField(); + } + + public static BearerSignatureAuthorizationRequestHeaderField instance() { + return InstanceHolder.INSTANCE; + } + + @Override + public void signRequest(String accessToken, OAuthRequest request) { + request.addHeader("Authorization", "Bearer " + accessToken); + } +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth2/bearersignature/BearerSignatureURIQueryParameter.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth2/bearersignature/BearerSignatureURIQueryParameter.java new file mode 100644 index 000000000..72cc64b43 --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth2/bearersignature/BearerSignatureURIQueryParameter.java @@ -0,0 +1,27 @@ +package com.github.scribejava.core.oauth2.bearersignature; + +import com.github.scribejava.core.model.OAuthConstants; +import com.github.scribejava.core.model.OAuthRequest; + +/** + * 2.3. URI Query Parameter
    + * https://tools.ietf.org/html/rfc6750#section-2.3 + */ +public class BearerSignatureURIQueryParameter implements BearerSignature { + protected BearerSignatureURIQueryParameter() { + } + + private static class InstanceHolder { + + private static final BearerSignatureURIQueryParameter INSTANCE = new BearerSignatureURIQueryParameter(); + } + + public static BearerSignatureURIQueryParameter instance() { + return InstanceHolder.INSTANCE; + } + + @Override + public void signRequest(String accessToken, OAuthRequest request) { + request.addQuerystringParameter(OAuthConstants.ACCESS_TOKEN, accessToken); + } +} diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ApiUnit.java b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ApiUnit.java index a3187957e..8d7777f86 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ApiUnit.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ApiUnit.java @@ -1,9 +1,10 @@ package com.github.scribejava.core.oauth; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.builder.api.OAuth2SignatureType; import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.httpclient.HttpClientConfig; +import com.github.scribejava.core.oauth2.bearersignature.BearerSignature; +import com.github.scribejava.core.oauth2.bearersignature.BearerSignatureURIQueryParameter; import java.io.OutputStream; class OAuth20ApiUnit extends DefaultApi20 { @@ -27,7 +28,7 @@ public OAuth20ServiceUnit createService(String apiKey, String apiSecret, String } @Override - public OAuth2SignatureType getSignatureType() { - return OAuth2SignatureType.BEARER_URI_QUERY_PARAMETER; + public BearerSignature getBearerSignature() { + return BearerSignatureURIQueryParameter.instance(); } } From 82fbbcc69f11f779771cbee97689a69ab023aa53 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 8 Oct 2018 12:40:40 +0300 Subject: [PATCH 523/882] move Bearer Token Usage logic from MicrosoftAzureActiveDirectoryService and TutByOAuthService to their BearerSignature implementations --- .../MicrosoftAzureActiveDirectoryApi.java | 11 ++++++++ .../com/github/scribejava/apis/TutByApi.java | 11 ++++++++ ...ftAzureActiveDirectoryBearerSignature.java | 28 +++++++++++++++++++ .../MicrosoftAzureActiveDirectoryService.java | 14 +++++++--- .../apis/service/TutByOAuthService.java | 12 ++++++-- .../apis/tutby/TutByBearerSignature.java | 25 +++++++++++++++++ 6 files changed, 95 insertions(+), 6 deletions(-) create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/microsoftazureactivedirectory/MicrosoftAzureActiveDirectoryBearerSignature.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/tutby/TutByBearerSignature.java diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/MicrosoftAzureActiveDirectoryApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/MicrosoftAzureActiveDirectoryApi.java index 2c793ae14..2bbbe2ac5 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/MicrosoftAzureActiveDirectoryApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/MicrosoftAzureActiveDirectoryApi.java @@ -1,9 +1,11 @@ package com.github.scribejava.apis; +import com.github.scribejava.apis.microsoftazureactivedirectory.MicrosoftAzureActiveDirectoryBearerSignature; import com.github.scribejava.apis.service.MicrosoftAzureActiveDirectoryService; import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.httpclient.HttpClientConfig; +import com.github.scribejava.core.oauth2.bearersignature.BearerSignature; import com.github.scribejava.core.oauth2.clientauthentication.ClientAuthentication; import com.github.scribejava.core.oauth2.clientauthentication.RequestBodyAuthenticationScheme; import java.io.OutputStream; @@ -49,6 +51,10 @@ protected String getAuthorizationBaseUrl() { return MSFT_LOGIN_URL + SLASH + COMMON + SLASH + AUTH_URI; } + /** + * @deprecated moved to {@link #getBearerSignature() } + */ + @Deprecated @Override public MicrosoftAzureActiveDirectoryService createService(String apiKey, String apiSecret, String callback, String scope, OutputStream debugStream, String state, String responseType, String userAgent, @@ -61,4 +67,9 @@ public MicrosoftAzureActiveDirectoryService createService(String apiKey, String public ClientAuthentication getClientAuthentication() { return RequestBodyAuthenticationScheme.instance(); } + + @Override + public BearerSignature getBearerSignature() { + return MicrosoftAzureActiveDirectoryBearerSignature.instance(); + } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/TutByApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/TutByApi.java index 377bc9046..94905a010 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/TutByApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/TutByApi.java @@ -1,9 +1,11 @@ package com.github.scribejava.apis; import com.github.scribejava.apis.service.TutByOAuthService; +import com.github.scribejava.apis.tutby.TutByBearerSignature; import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.httpclient.HttpClientConfig; +import com.github.scribejava.core.oauth2.bearersignature.BearerSignature; import java.io.OutputStream; public class TutByApi extends DefaultApi20 { @@ -29,6 +31,10 @@ protected String getAuthorizationBaseUrl() { return "http://profile.tut.by/auth"; } + /** + * @deprecated moved to {@link #getBearerSignature() } + */ + @Deprecated @Override public TutByOAuthService createService(String apiKey, String apiSecret, String callback, String scope, OutputStream debugStream, String state, String responseType, String userAgent, @@ -36,4 +42,9 @@ public TutByOAuthService createService(String apiKey, String apiSecret, String c return new TutByOAuthService(this, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); } + + @Override + public BearerSignature getBearerSignature() { + return TutByBearerSignature.instance(); + } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/microsoftazureactivedirectory/MicrosoftAzureActiveDirectoryBearerSignature.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/microsoftazureactivedirectory/MicrosoftAzureActiveDirectoryBearerSignature.java new file mode 100644 index 000000000..dddf62d50 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/microsoftazureactivedirectory/MicrosoftAzureActiveDirectoryBearerSignature.java @@ -0,0 +1,28 @@ +package com.github.scribejava.apis.microsoftazureactivedirectory; + +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.oauth2.bearersignature.BearerSignatureAuthorizationRequestHeaderField; + +public class MicrosoftAzureActiveDirectoryBearerSignature extends BearerSignatureAuthorizationRequestHeaderField { + private static final String ACCEPTED_FORMAT + = "application/json; odata=minimalmetadata; streaming=true; charset=utf-8"; + + protected MicrosoftAzureActiveDirectoryBearerSignature() { + } + + private static class InstanceHolder { + + private static final MicrosoftAzureActiveDirectoryBearerSignature INSTANCE + = new MicrosoftAzureActiveDirectoryBearerSignature(); + } + + public static MicrosoftAzureActiveDirectoryBearerSignature instance() { + return InstanceHolder.INSTANCE; + } + + @Override + public void signRequest(String accessToken, OAuthRequest request) { + super.signRequest(accessToken, request); + request.addHeader("Accept", ACCEPTED_FORMAT); + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MicrosoftAzureActiveDirectoryService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MicrosoftAzureActiveDirectoryService.java index bab20d3b7..e2ff45c3b 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MicrosoftAzureActiveDirectoryService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MicrosoftAzureActiveDirectoryService.java @@ -6,20 +6,26 @@ import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.oauth.OAuth20Service; +/** + * @deprecated doesn't do anything useful, all MicrosoftAzureActiveDirectory specific logic was moved to + * {@link com.github.scribejava.apis.microsoftazureactivedirectory.MicrosoftAzureActiveDirectoryBearerSignature} + */ +@Deprecated public class MicrosoftAzureActiveDirectoryService extends OAuth20Service { - private static final String ACCEPTED_FORMAT - = "application/json; odata=minimalmetadata; streaming=true; charset=utf-8"; - public MicrosoftAzureActiveDirectoryService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { super(api, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); } + /** + * @deprecated moved to + * {@link com.github.scribejava.apis.microsoftazureactivedirectory.MicrosoftAzureActiveDirectoryBearerSignature} + */ + @Deprecated @Override public void signRequest(String accessToken, OAuthRequest request) { super.signRequest(accessToken, request); - request.addHeader("Accept", ACCEPTED_FORMAT); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/TutByOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/TutByOAuthService.java index 82ded6c92..1b92ca8da 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/TutByOAuthService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/TutByOAuthService.java @@ -3,10 +3,14 @@ import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.httpclient.HttpClientConfig; -import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.oauth.OAuth20Service; +/** + * @deprecated doesn't do anything useful, all TutBy specific logic was moved to + * {@link com.github.scribejava.apis.tutby.TutByBearerSignature} + */ +@Deprecated public class TutByOAuthService extends OAuth20Service { public TutByOAuthService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, @@ -15,8 +19,12 @@ public TutByOAuthService(DefaultApi20 api, String apiKey, String apiSecret, Stri super(api, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); } + /** + * @deprecated moved to {@link com.github.scribejava.apis.tutby.TutByBearerSignature} + */ + @Deprecated @Override public void signRequest(String accessToken, OAuthRequest request) { - request.addQuerystringParameter(OAuthConstants.TOKEN, accessToken); + super.signRequest(accessToken, request); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/tutby/TutByBearerSignature.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/tutby/TutByBearerSignature.java new file mode 100644 index 000000000..0c7609073 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/tutby/TutByBearerSignature.java @@ -0,0 +1,25 @@ +package com.github.scribejava.apis.tutby; + +import com.github.scribejava.core.model.OAuthConstants; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.oauth2.bearersignature.BearerSignature; + +public class TutByBearerSignature implements BearerSignature { + + protected TutByBearerSignature() { + } + + private static class InstanceHolder { + + private static final TutByBearerSignature INSTANCE = new TutByBearerSignature(); + } + + public static TutByBearerSignature instance() { + return InstanceHolder.INSTANCE; + } + + @Override + public void signRequest(String accessToken, OAuthRequest request) { + request.addQuerystringParameter(OAuthConstants.TOKEN, accessToken); + } +} From 73fc48f5b134c79f0027b14e197d2399e8611ee3 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 8 Oct 2018 13:09:45 +0300 Subject: [PATCH 524/882] move all classes from com.github.scribejava.apis.services to their APIs packages --- .../github/scribejava/apis/FacebookApi.java | 2 +- .../com/github/scribejava/apis/ImgurApi.java | 2 +- .../com/github/scribejava/apis/MailruApi.java | 2 +- .../scribejava/apis/OdnoklassnikiApi.java | 2 +- .../apis/facebook/FacebookService.java | 43 +++++++++++ .../apis/imgur/ImgurOAuthService.java | 40 +++++++++++ .../apis/mailru/MailruOAuthService.java | 72 +++++++++++++++++++ .../OdnoklassnikiOAuthService.java | 69 ++++++++++++++++++ .../apis/service/FacebookService.java | 35 ++------- .../apis/service/ImgurOAuthService.java | 32 ++------- .../apis/service/MailruOAuthService.java | 64 ++--------------- .../service/OdnoklassnikiOAuthService.java | 60 ++-------------- 12 files changed, 248 insertions(+), 175 deletions(-) create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookService.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/imgur/ImgurOAuthService.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/mailru/MailruOAuthService.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/odnoklassniki/OdnoklassnikiOAuthService.java diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java index fb0668eb1..6418d8964 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java @@ -1,7 +1,7 @@ package com.github.scribejava.apis; import com.github.scribejava.apis.facebook.FacebookAccessTokenJsonExtractor; -import com.github.scribejava.apis.service.FacebookService; +import com.github.scribejava.apis.facebook.FacebookService; import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.extractors.TokenExtractor; import com.github.scribejava.core.httpclient.HttpClient; diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java index b8c802647..f04736880 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java @@ -1,6 +1,6 @@ package com.github.scribejava.apis; -import com.github.scribejava.apis.service.ImgurOAuthService; +import com.github.scribejava.apis.imgur.ImgurOAuthService; import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.httpclient.HttpClientConfig; diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java index 05ae5cb8a..3835fff49 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java @@ -1,7 +1,7 @@ package com.github.scribejava.apis; +import com.github.scribejava.apis.mailru.MailruOAuthService; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.apis.service.MailruOAuthService; import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.httpclient.HttpClientConfig; import java.io.OutputStream; diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java index f82b585b6..f0d873b71 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java @@ -1,6 +1,6 @@ package com.github.scribejava.apis; -import com.github.scribejava.apis.service.OdnoklassnikiOAuthService; +import com.github.scribejava.apis.odnoklassniki.OdnoklassnikiOAuthService; import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.httpclient.HttpClientConfig; diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookService.java new file mode 100644 index 000000000..6aa4419e1 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookService.java @@ -0,0 +1,43 @@ +package com.github.scribejava.apis.facebook; + +import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.httpclient.HttpClient; +import com.github.scribejava.core.httpclient.HttpClientConfig; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.oauth.OAuth20Service; +import java.security.InvalidKeyException; +import java.security.NoSuchAlgorithmException; +import java.util.Formatter; +import javax.crypto.Mac; +import javax.crypto.spec.SecretKeySpec; + +public class FacebookService extends OAuth20Service { + + public FacebookService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, + String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, + HttpClient httpClient) { + super(api, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); + } + + @Override + public void signRequest(String accessToken, OAuthRequest request) { + super.signRequest(accessToken, request); + + final Mac mac; + try { + mac = Mac.getInstance("HmacSHA256"); + final SecretKeySpec secretKey = new SecretKeySpec(getApiSecret().getBytes(), "HmacSHA256"); + mac.init(secretKey); + + final Formatter appsecretProof = new Formatter(); + + for (byte b : mac.doFinal(accessToken.getBytes())) { + appsecretProof.format("%02x", b); + } + + request.addParameter("appsecret_proof", appsecretProof.toString()); + } catch (NoSuchAlgorithmException | InvalidKeyException e) { + throw new IllegalStateException("There is a problem while generating Facebook appsecret_proof.", e); + } + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/imgur/ImgurOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/imgur/ImgurOAuthService.java new file mode 100644 index 000000000..f37dfab95 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/imgur/ImgurOAuthService.java @@ -0,0 +1,40 @@ +package com.github.scribejava.apis.imgur; + +import com.github.scribejava.apis.ImgurApi; +import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.httpclient.HttpClient; +import com.github.scribejava.core.httpclient.HttpClientConfig; +import com.github.scribejava.core.model.OAuthConstants; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.oauth.OAuth20Service; + +public class ImgurOAuthService extends OAuth20Service { + + public ImgurOAuthService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, + String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, + HttpClient httpClient) { + super(api, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); + } + + @Override + protected OAuthRequest createAccessTokenRequest(String oauthVerifier) { + final DefaultApi20 api = getApi(); + final OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint()); + request.addBodyParameter(OAuthConstants.CLIENT_ID, getApiKey()); + request.addBodyParameter(OAuthConstants.CLIENT_SECRET, getApiSecret()); + + if (ImgurApi.isOob(getCallback())) { + request.addBodyParameter(OAuthConstants.GRANT_TYPE, "pin"); + request.addBodyParameter("pin", oauthVerifier); + } else { + request.addBodyParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.AUTHORIZATION_CODE); + request.addBodyParameter(OAuthConstants.CODE, oauthVerifier); + } + return request; + } + + @Override + public void signRequest(String accessToken, OAuthRequest request) { + request.addHeader("Authorization", accessToken == null ? "Client-ID " + getApiKey() : "Bearer " + accessToken); + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/mailru/MailruOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/mailru/MailruOAuthService.java new file mode 100644 index 000000000..f17a922a1 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/mailru/MailruOAuthService.java @@ -0,0 +1,72 @@ +package com.github.scribejava.apis.mailru; + +import java.net.URLDecoder; +import java.util.Map; +import java.util.TreeMap; +import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.httpclient.HttpClient; +import com.github.scribejava.core.httpclient.HttpClientConfig; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.oauth.OAuth20Service; +import java.io.UnsupportedEncodingException; +import java.nio.charset.Charset; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.util.Formatter; + +public class MailruOAuthService extends OAuth20Service { + + public MailruOAuthService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, + String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, + HttpClient httpClient) { + super(api, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); + } + + + @Override + public void signRequest(String accessToken, OAuthRequest request) { + // sig = md5(params + secret_key) + request.addQuerystringParameter("session_key", accessToken); + request.addQuerystringParameter("app_id", getApiKey()); + final String completeUrl = request.getCompleteUrl(); + + try { + final String clientSecret = getApiSecret(); + final int queryIndex = completeUrl.indexOf('?'); + if (queryIndex != -1) { + final String urlPart = completeUrl.substring(queryIndex + 1); + final Map map = new TreeMap<>(); + for (String param : urlPart.split("&")) { + final String[] parts = param.split("="); + map.put(parts[0], (parts.length == 1) ? "" : parts[1]); + } + + final StringBuilder urlNew = new StringBuilder(); + for (Map.Entry entry : map.entrySet()) { + urlNew.append(entry.getKey()); + urlNew.append('='); + urlNew.append(entry.getValue()); + } + + final String sigSource = URLDecoder.decode(urlNew.toString(), "UTF-8") + clientSecret; + request.addQuerystringParameter("sig", md5(sigSource)); + } + } catch (UnsupportedEncodingException e) { + throw new IllegalStateException(e); + } + } + + public static String md5(String orgString) { + try { + final MessageDigest md = MessageDigest.getInstance("MD5"); + final byte[] array = md.digest(orgString.getBytes(Charset.forName("UTF-8"))); + final Formatter builder = new Formatter(); + for (byte b : array) { + builder.format("%02x", b); + } + return builder.toString(); + } catch (NoSuchAlgorithmException e) { + throw new IllegalStateException("MD5 is unsupported?", e); + } + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/odnoklassniki/OdnoklassnikiOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/odnoklassniki/OdnoklassnikiOAuthService.java new file mode 100644 index 000000000..16a9f10a5 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/odnoklassniki/OdnoklassnikiOAuthService.java @@ -0,0 +1,69 @@ +package com.github.scribejava.apis.odnoklassniki; + +import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.httpclient.HttpClient; +import com.github.scribejava.core.httpclient.HttpClientConfig; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Parameter; +import com.github.scribejava.core.model.ParameterList; +import com.github.scribejava.core.oauth.OAuth20Service; +import java.io.UnsupportedEncodingException; + +import java.net.URLDecoder; +import java.nio.charset.Charset; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.util.Collections; +import java.util.Formatter; +import java.util.List; + +public class OdnoklassnikiOAuthService extends OAuth20Service { + + public OdnoklassnikiOAuthService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, + String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, + HttpClient httpClient) { + super(api, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); + } + + @Override + public void signRequest(String accessToken, OAuthRequest request) { + //sig = lower(md5( sorted_request_params_composed_string + md5(access_token + application_secret_key))) + try { + final String tokenDigest = md5(accessToken + getApiSecret()); + + final ParameterList queryParams = request.getQueryStringParams(); + queryParams.addAll(request.getBodyParams()); + final List allParams = queryParams.getParams(); + + Collections.sort(allParams); + + final StringBuilder stringParams = new StringBuilder(); + for (Parameter param : allParams) { + stringParams.append(param.getKey()) + .append('=') + .append(param.getValue()); + } + + final String sigSource = URLDecoder.decode(stringParams.toString(), "UTF-8") + tokenDigest; + request.addQuerystringParameter("sig", md5(sigSource).toLowerCase()); + + super.signRequest(accessToken, request); + } catch (UnsupportedEncodingException unex) { + throw new IllegalStateException(unex); + } + } + + public static String md5(String orgString) { + try { + final MessageDigest md = MessageDigest.getInstance("MD5"); + final byte[] array = md.digest(orgString.getBytes(Charset.forName("UTF-8"))); + final Formatter builder = new Formatter(); + for (byte b : array) { + builder.format("%02x", b); + } + return builder.toString(); + } catch (NoSuchAlgorithmException e) { + throw new IllegalStateException("MD5 is unsupported?", e); + } + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/FacebookService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/FacebookService.java index 51e282310..ca14eb8c4 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/FacebookService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/FacebookService.java @@ -3,41 +3,16 @@ import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.httpclient.HttpClientConfig; -import com.github.scribejava.core.model.OAuthRequest; -import com.github.scribejava.core.oauth.OAuth20Service; -import java.security.InvalidKeyException; -import java.security.NoSuchAlgorithmException; -import java.util.Formatter; -import javax.crypto.Mac; -import javax.crypto.spec.SecretKeySpec; -public class FacebookService extends OAuth20Service { +/** + * @deprecated moved to {@link com.github.scribejava.apis.facebook.FacebookService} + */ +@Deprecated +public class FacebookService extends com.github.scribejava.apis.facebook.FacebookService { public FacebookService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { super(api, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); } - - @Override - public void signRequest(String accessToken, OAuthRequest request) { - super.signRequest(accessToken, request); - - final Mac mac; - try { - mac = Mac.getInstance("HmacSHA256"); - final SecretKeySpec secretKey = new SecretKeySpec(getApiSecret().getBytes(), "HmacSHA256"); - mac.init(secretKey); - - final Formatter appsecretProof = new Formatter(); - - for (byte b : mac.doFinal(accessToken.getBytes())) { - appsecretProof.format("%02x", b); - } - - request.addParameter("appsecret_proof", appsecretProof.toString()); - } catch (NoSuchAlgorithmException | InvalidKeyException e) { - throw new IllegalStateException("There is a problem while generating Facebook appsecret_proof.", e); - } - } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthService.java index e1b146846..fb51337da 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthService.java @@ -1,40 +1,18 @@ package com.github.scribejava.apis.service; -import com.github.scribejava.apis.ImgurApi; import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.httpclient.HttpClientConfig; -import com.github.scribejava.core.model.OAuthConstants; -import com.github.scribejava.core.model.OAuthRequest; -import com.github.scribejava.core.oauth.OAuth20Service; -public class ImgurOAuthService extends OAuth20Service { +/** + * @deprecated moved to {@link com.github.scribejava.apis.imgur.ImgurOAuthService} + */ +@Deprecated +public class ImgurOAuthService extends com.github.scribejava.apis.imgur.ImgurOAuthService { public ImgurOAuthService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { super(api, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); } - - @Override - protected OAuthRequest createAccessTokenRequest(String oauthVerifier) { - final DefaultApi20 api = getApi(); - final OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint()); - request.addBodyParameter(OAuthConstants.CLIENT_ID, getApiKey()); - request.addBodyParameter(OAuthConstants.CLIENT_SECRET, getApiSecret()); - - if (ImgurApi.isOob(getCallback())) { - request.addBodyParameter(OAuthConstants.GRANT_TYPE, "pin"); - request.addBodyParameter("pin", oauthVerifier); - } else { - request.addBodyParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.AUTHORIZATION_CODE); - request.addBodyParameter(OAuthConstants.CODE, oauthVerifier); - } - return request; - } - - @Override - public void signRequest(String accessToken, OAuthRequest request) { - request.addHeader("Authorization", accessToken == null ? "Client-ID " + getApiKey() : "Bearer " + accessToken); - } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthService.java index f40727f53..c1593dd45 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthService.java @@ -1,72 +1,18 @@ package com.github.scribejava.apis.service; -import java.net.URLDecoder; -import java.util.Map; -import java.util.TreeMap; import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.httpclient.HttpClientConfig; -import com.github.scribejava.core.model.OAuthRequest; -import com.github.scribejava.core.oauth.OAuth20Service; -import java.io.UnsupportedEncodingException; -import java.nio.charset.Charset; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; -import java.util.Formatter; -public class MailruOAuthService extends OAuth20Service { +/** + * @deprecated moved to {@link com.github.scribejava.apis.mailru.MailruOAuthService} + */ +@Deprecated +public class MailruOAuthService extends com.github.scribejava.apis.mailru.MailruOAuthService { public MailruOAuthService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { super(api, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); } - - - @Override - public void signRequest(String accessToken, OAuthRequest request) { - // sig = md5(params + secret_key) - request.addQuerystringParameter("session_key", accessToken); - request.addQuerystringParameter("app_id", getApiKey()); - final String completeUrl = request.getCompleteUrl(); - - try { - final String clientSecret = getApiSecret(); - final int queryIndex = completeUrl.indexOf('?'); - if (queryIndex != -1) { - final String urlPart = completeUrl.substring(queryIndex + 1); - final Map map = new TreeMap<>(); - for (String param : urlPart.split("&")) { - final String[] parts = param.split("="); - map.put(parts[0], (parts.length == 1) ? "" : parts[1]); - } - - final StringBuilder urlNew = new StringBuilder(); - for (Map.Entry entry : map.entrySet()) { - urlNew.append(entry.getKey()); - urlNew.append('='); - urlNew.append(entry.getValue()); - } - - final String sigSource = URLDecoder.decode(urlNew.toString(), "UTF-8") + clientSecret; - request.addQuerystringParameter("sig", md5(sigSource)); - } - } catch (UnsupportedEncodingException e) { - throw new IllegalStateException(e); - } - } - - public static String md5(String orgString) { - try { - final MessageDigest md = MessageDigest.getInstance("MD5"); - final byte[] array = md.digest(orgString.getBytes(Charset.forName("UTF-8"))); - final Formatter builder = new Formatter(); - for (byte b : array) { - builder.format("%02x", b); - } - return builder.toString(); - } catch (NoSuchAlgorithmException e) { - throw new IllegalStateException("MD5 is unsupported?", e); - } - } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiOAuthService.java index 34bd0fe89..46a34102f 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiOAuthService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiOAuthService.java @@ -3,21 +3,12 @@ import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.httpclient.HttpClientConfig; -import com.github.scribejava.core.model.OAuthRequest; -import com.github.scribejava.core.model.Parameter; -import com.github.scribejava.core.model.ParameterList; -import com.github.scribejava.core.oauth.OAuth20Service; -import java.io.UnsupportedEncodingException; -import java.net.URLDecoder; -import java.nio.charset.Charset; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; -import java.util.Collections; -import java.util.Formatter; -import java.util.List; - -public class OdnoklassnikiOAuthService extends OAuth20Service { +/** + * @deprecated moved to {@link com.github.scribejava.apis.odnoklassniki.OdnoklassnikiOAuthService} + */ +@Deprecated +public class OdnoklassnikiOAuthService extends com.github.scribejava.apis.odnoklassniki.OdnoklassnikiOAuthService { public OdnoklassnikiOAuthService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, @@ -25,45 +16,4 @@ public OdnoklassnikiOAuthService(DefaultApi20 api, String apiKey, String apiSecr super(api, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); } - @Override - public void signRequest(String accessToken, OAuthRequest request) { - //sig = lower(md5( sorted_request_params_composed_string + md5(access_token + application_secret_key))) - try { - final String tokenDigest = md5(accessToken + getApiSecret()); - - final ParameterList queryParams = request.getQueryStringParams(); - queryParams.addAll(request.getBodyParams()); - final List allParams = queryParams.getParams(); - - Collections.sort(allParams); - - final StringBuilder stringParams = new StringBuilder(); - for (Parameter param : allParams) { - stringParams.append(param.getKey()) - .append('=') - .append(param.getValue()); - } - - final String sigSource = URLDecoder.decode(stringParams.toString(), "UTF-8") + tokenDigest; - request.addQuerystringParameter("sig", md5(sigSource).toLowerCase()); - - super.signRequest(accessToken, request); - } catch (UnsupportedEncodingException unex) { - throw new IllegalStateException(unex); - } - } - - public static String md5(String orgString) { - try { - final MessageDigest md = MessageDigest.getInstance("MD5"); - final byte[] array = md.digest(orgString.getBytes(Charset.forName("UTF-8"))); - final Formatter builder = new Formatter(); - for (byte b : array) { - builder.format("%02x", b); - } - return builder.toString(); - } catch (NoSuchAlgorithmException e) { - throw new IllegalStateException("MD5 is unsupported?", e); - } - } } From 8269f2ac9b3455899fcf8dd0a987c34538ca76ba Mon Sep 17 00:00:00 2001 From: M-F-K Date: Mon, 16 Jul 2018 16:19:47 +0200 Subject: [PATCH 525/882] Add support for the Wunderlist API --- .../scribejava/apis/WunderlistAPI20.java | 43 +++++++++++ .../apis/examples/Wunderlist20Example.java | 76 +++++++++++++++++++ 2 files changed, 119 insertions(+) create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/WunderlistAPI20.java create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Wunderlist20Example.java diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/WunderlistAPI20.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/WunderlistAPI20.java new file mode 100644 index 000000000..b7e82456a --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/WunderlistAPI20.java @@ -0,0 +1,43 @@ +package com.github.scribejava.apis; + +import com.github.scribejava.core.builder.api.ClientAuthenticationType; +import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.builder.api.OAuth2SignatureType; + +/** + * Wunderlist.com Api + */ +public class WunderlistAPI20 extends DefaultApi20 { + + + protected WunderlistAPI20() { + } + + private static class InstanceHolder { + private static final WunderlistAPI20 INSTANCE = new WunderlistAPI20(); + } + + public static WunderlistAPI20 instance() { + return InstanceHolder.INSTANCE; + } + + @Override + public String getAccessTokenEndpoint() { + return "https://www.wunderlist.com/oauth/access_token"; + } + + @Override + protected String getAuthorizationBaseUrl() { + return "https://www.wunderlist.com/oauth/authorize"; + } + + @Override + public OAuth2SignatureType getSignatureType() { + return OAuth2SignatureType.BEARER_URI_QUERY_PARAMETER; + } + + @Override + public ClientAuthenticationType getClientAuthenticationType() { + return ClientAuthenticationType.REQUEST_BODY; + } +} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Wunderlist20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Wunderlist20Example.java new file mode 100644 index 000000000..3528f3e9d --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Wunderlist20Example.java @@ -0,0 +1,76 @@ +package com.github.scribejava.apis.examples; + +import java.io.IOException; +import java.util.Random; +import java.util.Scanner; +import java.util.concurrent.ExecutionException; + +import com.github.scribejava.apis.WunderlistAPI20; +import com.github.scribejava.core.builder.ServiceBuilder; +import com.github.scribejava.core.model.OAuth2AccessToken; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.oauth.OAuth20Service; + +public class Wunderlist20Example { + + private static final String NETWORK_NAME = "Wunderlist"; + private static final String PROTECTED_RESOURCE_URL = "https://a.wunderlist.com/api/v1/user"; + + private Wunderlist20Example() { + } + + public static void main(String... args) throws IOException, InterruptedException, ExecutionException { + // Replace these with your own values + final String apiKey = "your_api_key"; + final String apiSecret = "your_api_secret"; + final String callbackUrl = "http://example.com/callback"; + final String secretState = "security_token" + new Random().nextInt(999_999); + + final OAuth20Service service = new ServiceBuilder(apiKey) + .apiSecret(apiSecret) + .callback(callbackUrl) + .state(secretState) + .debug() + .build(WunderlistAPI20.instance()); + final Scanner in = new Scanner(System.in, "UTF-8"); + + System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); + System.out.println(); + + + // Obtain the Authorization URL + System.out.println("Fetching the Authorization URL..."); + final String authorizationUrl = service.getAuthorizationUrl(); + System.out.println("Got the Authorization URL!"); + System.out.println("Now go and authorize ScribeJava here:"); + System.out.println(authorizationUrl); + System.out.println("And paste the authorization code here"); + System.out.print(">>"); + final String code = in.nextLine(); + in.close(); + System.out.println(); + + // Trade the Request Token and Verifier for the Access Token + System.out.println("Trading the Request Token for an Access Token..."); + final OAuth2AccessToken accessToken = service.getAccessToken(code); + System.out.println("Got the Access Token!"); + System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); + System.out.println(); + + // Now let's go and ask for a protected resource! + System.out.println("Now we're going to access a protected resource..."); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); + request.addHeader("X-Client-ID", apiKey); + service.signRequest(accessToken, request); + final Response response = service.execute(request); + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + + System.out.println(); + System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); + } +} From f571674dfd9f882583f7be0889b0942135bb13a2 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 8 Oct 2018 13:34:11 +0300 Subject: [PATCH 526/882] add new API Wunderlist (https://www.wunderlist.com/) (thanks to https://github.com/M-F-K) --- README.md | 3 +- changelog | 1 + .../github/scribejava/apis/WunderlistAPI.java | 58 +++++++++++++++++++ .../scribejava/apis/WunderlistAPI20.java | 43 -------------- .../apis/service/WunderlistOAuthService.java | 22 +++++++ ...t20Example.java => WunderlistExample.java} | 46 +++++++-------- 6 files changed, 105 insertions(+), 68 deletions(-) create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/WunderlistAPI.java delete mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/WunderlistAPI20.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/service/WunderlistOAuthService.java rename scribejava-apis/src/test/java/com/github/scribejava/apis/examples/{Wunderlist20Example.java => WunderlistExample.java} (68%) diff --git a/README.md b/README.md index 4e82b188e..b2ca047e7 100644 --- a/README.md +++ b/README.md @@ -74,6 +74,7 @@ ScribeJava support out-of-box several HTTP clients: * LinkedIn (https://www.linkedin.com/) * Microsoft Azure Active Directory (Azure AD) (http://azure.microsoft.com/) * Microsoft Live (https://login.live.com/) +* Misfit (http://misfit.com/) * Mail.Ru (https://mail.ru/) * MediaWiki (https://www.mediawiki.org/) * Meetup (http://www.meetup.com/) @@ -94,9 +95,9 @@ ScribeJava support out-of-box several HTTP clients: * uCoz (https://www.ucoz.com/) * Viadeo (http://viadeo.com/) * VK ВКонтакте (http://vk.com/) +* Wunderlist (https://www.wunderlist.com/) * XING (https://www.xing.com/) * Yahoo (https://www.yahoo.com/) -* Misfit (http://misfit.com/) * check the [examples folder](https://github.com/scribejava/scribejava/tree/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples) ### Small and modular diff --git a/changelog b/changelog index 869884876..5019675e9 100644 --- a/changelog +++ b/changelog @@ -2,6 +2,7 @@ * make redirect_uri optional while Access Token requesting on OAuth 2.0 (thanks to https://github.com/computerlove) * switch to java 9+ (from java 7 only) for compilation. Runtime is still java 7+. Complement README with links and RFC descriptions. * switch OAuth2 Bearer Token Usage from enum OAuth2SignatureType to interface BearerSignature to be extensible + * add new API Wunderlist (https://www.wunderlist.com/) (thanks to https://github.com/M-F-K) [5.6.0] * remove support for obsolete NetEase (http://www.163.com/) and sohu 搜狐 (http://www.sohu.com/) (thanks to https://github.com/zawn) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/WunderlistAPI.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/WunderlistAPI.java new file mode 100644 index 000000000..989725155 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/WunderlistAPI.java @@ -0,0 +1,58 @@ +package com.github.scribejava.apis; + +import com.github.scribejava.apis.service.WunderlistOAuthService; +import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.httpclient.HttpClient; +import com.github.scribejava.core.httpclient.HttpClientConfig; +import com.github.scribejava.core.oauth.OAuth20Service; +import com.github.scribejava.core.oauth2.bearersignature.BearerSignature; +import com.github.scribejava.core.oauth2.bearersignature.BearerSignatureURIQueryParameter; +import com.github.scribejava.core.oauth2.clientauthentication.ClientAuthentication; +import com.github.scribejava.core.oauth2.clientauthentication.RequestBodyAuthenticationScheme; +import java.io.OutputStream; + +/** + * Wunderlist.com Api + */ +public class WunderlistAPI extends DefaultApi20 { + + protected WunderlistAPI() { + } + + private static class InstanceHolder { + + private static final WunderlistAPI INSTANCE = new WunderlistAPI(); + } + + public static WunderlistAPI instance() { + return InstanceHolder.INSTANCE; + } + + @Override + public String getAccessTokenEndpoint() { + return "https://www.wunderlist.com/oauth/access_token"; + } + + @Override + protected String getAuthorizationBaseUrl() { + return "https://www.wunderlist.com/oauth/authorize"; + } + + @Override + public BearerSignature getBearerSignature() { + return BearerSignatureURIQueryParameter.instance(); + } + + @Override + public ClientAuthentication getClientAuthentication() { + return RequestBodyAuthenticationScheme.instance(); + } + + @Override + public OAuth20Service createService(String apiKey, String apiSecret, String callback, String scope, + OutputStream debugStream, String state, String responseType, String userAgent, + HttpClientConfig httpClientConfig, HttpClient httpClient) { + return new WunderlistOAuthService(this, apiKey, apiSecret, callback, scope, state, responseType, userAgent, + httpClientConfig, httpClient); + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/WunderlistAPI20.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/WunderlistAPI20.java deleted file mode 100644 index b7e82456a..000000000 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/WunderlistAPI20.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.github.scribejava.apis; - -import com.github.scribejava.core.builder.api.ClientAuthenticationType; -import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.builder.api.OAuth2SignatureType; - -/** - * Wunderlist.com Api - */ -public class WunderlistAPI20 extends DefaultApi20 { - - - protected WunderlistAPI20() { - } - - private static class InstanceHolder { - private static final WunderlistAPI20 INSTANCE = new WunderlistAPI20(); - } - - public static WunderlistAPI20 instance() { - return InstanceHolder.INSTANCE; - } - - @Override - public String getAccessTokenEndpoint() { - return "https://www.wunderlist.com/oauth/access_token"; - } - - @Override - protected String getAuthorizationBaseUrl() { - return "https://www.wunderlist.com/oauth/authorize"; - } - - @Override - public OAuth2SignatureType getSignatureType() { - return OAuth2SignatureType.BEARER_URI_QUERY_PARAMETER; - } - - @Override - public ClientAuthenticationType getClientAuthenticationType() { - return ClientAuthenticationType.REQUEST_BODY; - } -} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/WunderlistOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/WunderlistOAuthService.java new file mode 100644 index 000000000..1374a9e61 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/WunderlistOAuthService.java @@ -0,0 +1,22 @@ +package com.github.scribejava.apis.service; + +import com.github.scribejava.apis.WunderlistAPI; +import com.github.scribejava.core.httpclient.HttpClient; +import com.github.scribejava.core.httpclient.HttpClientConfig; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.oauth.OAuth20Service; + +public class WunderlistOAuthService extends OAuth20Service { + + public WunderlistOAuthService(WunderlistAPI api, String apiKey, String apiSecret, String callback, String scope, + String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, + HttpClient httpClient) { + super(api, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); + } + + @Override + public void signRequest(String accessToken, OAuthRequest request) { + super.signRequest(accessToken, request); + request.addHeader("X-Client-ID", getApiKey()); + } +} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Wunderlist20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/WunderlistExample.java similarity index 68% rename from scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Wunderlist20Example.java rename to scribejava-apis/src/test/java/com/github/scribejava/apis/examples/WunderlistExample.java index 3528f3e9d..91bb5f523 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Wunderlist20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/WunderlistExample.java @@ -5,7 +5,7 @@ import java.util.Scanner; import java.util.concurrent.ExecutionException; -import com.github.scribejava.apis.WunderlistAPI20; +import com.github.scribejava.apis.WunderlistAPI; import com.github.scribejava.core.builder.ServiceBuilder; import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthRequest; @@ -13,43 +13,42 @@ import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.oauth.OAuth20Service; -public class Wunderlist20Example { +public class WunderlistExample { private static final String NETWORK_NAME = "Wunderlist"; private static final String PROTECTED_RESOURCE_URL = "https://a.wunderlist.com/api/v1/user"; - private Wunderlist20Example() { + private WunderlistExample() { } public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your own values - final String apiKey = "your_api_key"; - final String apiSecret = "your_api_secret"; + final String apiKey = "apiKey"; + final String apiSecret = "apiSecret"; final String callbackUrl = "http://example.com/callback"; - final String secretState = "security_token" + new Random().nextInt(999_999); - + final String secretState = "security_token" + new Random().nextInt(999_999); + final OAuth20Service service = new ServiceBuilder(apiKey) .apiSecret(apiSecret) .callback(callbackUrl) .state(secretState) .debug() - .build(WunderlistAPI20.instance()); - final Scanner in = new Scanner(System.in, "UTF-8"); - - System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); - System.out.println(); - + .build(WunderlistAPI.instance()); - // Obtain the Authorization URL - System.out.println("Fetching the Authorization URL..."); - final String authorizationUrl = service.getAuthorizationUrl(); - System.out.println("Got the Authorization URL!"); - System.out.println("Now go and authorize ScribeJava here:"); - System.out.println(authorizationUrl); - System.out.println("And paste the authorization code here"); - System.out.print(">>"); - final String code = in.nextLine(); - in.close(); + final String code; + try (Scanner in = new Scanner(System.in, "UTF-8")) { + System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); + System.out.println(); + // Obtain the Authorization URL + System.out.println("Fetching the Authorization URL..."); + final String authorizationUrl = service.getAuthorizationUrl(); + System.out.println("Got the Authorization URL!"); + System.out.println("Now go and authorize ScribeJava here:"); + System.out.println(authorizationUrl); + System.out.println("And paste the authorization code here"); + System.out.print(">>"); + code = in.nextLine(); + } System.out.println(); // Trade the Request Token and Verifier for the Access Token @@ -62,7 +61,6 @@ public static void main(String... args) throws IOException, InterruptedException // Now let's go and ask for a protected resource! System.out.println("Now we're going to access a protected resource..."); final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); - request.addHeader("X-Client-ID", apiKey); service.signRequest(accessToken, request); final Response response = service.execute(request); System.out.println("Got it! Lets see what we found..."); From bdd1741370c056f7322669f438b7eb12b9e2318b Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 8 Oct 2018 13:48:26 +0300 Subject: [PATCH 527/882] move all classes from com.github.scribejava.apis.services to their APIs packages - 2 --- .../src/main/java/com/github/scribejava/apis/WunderlistAPI.java | 2 +- .../apis/{service => wunderlist}/WunderlistOAuthService.java | 2 +- .../{service => odnoklassniki}/OdnoklassnikiServiceTest.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) rename scribejava-apis/src/main/java/com/github/scribejava/apis/{service => wunderlist}/WunderlistOAuthService.java (95%) rename scribejava-apis/src/test/java/com/github/scribejava/apis/{service => odnoklassniki}/OdnoklassnikiServiceTest.java (97%) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/WunderlistAPI.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/WunderlistAPI.java index 989725155..e8eb92111 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/WunderlistAPI.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/WunderlistAPI.java @@ -1,6 +1,6 @@ package com.github.scribejava.apis; -import com.github.scribejava.apis.service.WunderlistOAuthService; +import com.github.scribejava.apis.wunderlist.WunderlistOAuthService; import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.httpclient.HttpClientConfig; diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/WunderlistOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/wunderlist/WunderlistOAuthService.java similarity index 95% rename from scribejava-apis/src/main/java/com/github/scribejava/apis/service/WunderlistOAuthService.java rename to scribejava-apis/src/main/java/com/github/scribejava/apis/wunderlist/WunderlistOAuthService.java index 1374a9e61..e5a5b07a7 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/WunderlistOAuthService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/wunderlist/WunderlistOAuthService.java @@ -1,4 +1,4 @@ -package com.github.scribejava.apis.service; +package com.github.scribejava.apis.wunderlist; import com.github.scribejava.apis.WunderlistAPI; import com.github.scribejava.core.httpclient.HttpClient; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/service/OdnoklassnikiServiceTest.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/odnoklassniki/OdnoklassnikiServiceTest.java similarity index 97% rename from scribejava-apis/src/test/java/com/github/scribejava/apis/service/OdnoklassnikiServiceTest.java rename to scribejava-apis/src/test/java/com/github/scribejava/apis/odnoklassniki/OdnoklassnikiServiceTest.java index 0dded23fb..f1e108f49 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/service/OdnoklassnikiServiceTest.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/odnoklassniki/OdnoklassnikiServiceTest.java @@ -1,4 +1,4 @@ -package com.github.scribejava.apis.service; +package com.github.scribejava.apis.odnoklassniki; import com.github.scribejava.apis.OdnoklassnikiApi; import com.github.scribejava.core.builder.ServiceBuilder; From a5b7b1e6f59e85944b8afbb5a9179c8047a25178 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 8 Oct 2018 14:06:24 +0300 Subject: [PATCH 528/882] update dependencies --- pom.xml | 2 +- .../com/github/scribejava/core/builder/api/DefaultApi20.java | 1 + scribejava-httpclient-ahc/pom.xml | 4 ++-- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 85d155e54..574a9913c 100644 --- a/pom.xml +++ b/pom.xml @@ -107,7 +107,7 @@ com.puppycrawl.tools checkstyle - 8.12 + 8.13 diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java index 84d7ab91c..75cdd40ba 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java @@ -116,6 +116,7 @@ public OAuth20Service createService(String apiKey, String apiSecret, String call } /** + * @return OAuth2SignatureType * @deprecated use {@link #getBearerSignature() } */ @Deprecated diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index ec7ab0a77..4828697c4 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -8,7 +8,7 @@ 5.6.1-SNAPSHOT ../pom.xml - + com.github.scribejava scribejava-httpclient-ahc ScribeJava Async Http Http Client support @@ -23,7 +23,7 @@ org.asynchttpclient async-http-client - 2.5.3 + 2.5.4 com.github.scribejava From dcfc1d1b9ca0a905e5bcee3ff69addb72afc96cf Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 8 Oct 2018 14:19:25 +0300 Subject: [PATCH 529/882] prepare release v6.0.0 --- README.md | 4 ++-- changelog | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index b2ca047e7..2cc181033 100644 --- a/README.md +++ b/README.md @@ -123,7 +123,7 @@ You can pull ScribeJava from the central maven repository, just add these to you com.github.scribejava scribejava-apis - 5.6.0 + 6.0.0 ``` @@ -132,7 +132,7 @@ And in case you need just core classes (that's it, without any external API (FB, com.github.scribejava scribejava-core - 5.6.0 + 6.0.0 ``` diff --git a/changelog b/changelog index 5019675e9..81c5e188d 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,4 @@ -[SNAPSHOT] +[6.0.0] * make redirect_uri optional while Access Token requesting on OAuth 2.0 (thanks to https://github.com/computerlove) * switch to java 9+ (from java 7 only) for compilation. Runtime is still java 7+. Complement README with links and RFC descriptions. * switch OAuth2 Bearer Token Usage from enum OAuth2SignatureType to interface BearerSignature to be extensible From 785e8f68c2e2126705451a5ed3026310e4a2fb31 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 8 Oct 2018 14:21:42 +0300 Subject: [PATCH 530/882] [maven-release-plugin] prepare release scribejava-6.0.0 --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index 574a9913c..42a99b4c5 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 5.6.1-SNAPSHOT + 6.0.0 ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -34,7 +34,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - HEAD + scribejava-6.0.0 diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 3cc2f5f5a..88d931471 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.6.1-SNAPSHOT + 6.0.0 ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index b07f9627b..4f866dc84 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.6.1-SNAPSHOT + 6.0.0 ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 4828697c4..db7d34d1f 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.6.1-SNAPSHOT + 6.0.0 ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index f49a10a12..10c48bf42 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.6.1-SNAPSHOT + 6.0.0 ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index dffa0f860..ba1f6a2bb 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.6.1-SNAPSHOT + 6.0.0 ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 3d249abe7..640477e11 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.6.1-SNAPSHOT + 6.0.0 ../pom.xml From 4f14bdbf5e9148e077eb85ef2398f2c39005e650 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 8 Oct 2018 14:21:49 +0300 Subject: [PATCH 531/882] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index 42a99b4c5..85f930caf 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 6.0.0 + 6.0.1-SNAPSHOT ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -34,7 +34,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - scribejava-6.0.0 + HEAD diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 88d931471..c96f2850c 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.0.0 + 6.0.1-SNAPSHOT ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 4f866dc84..5924eab0d 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.0.0 + 6.0.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index db7d34d1f..a8826d0d1 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.0.0 + 6.0.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index 10c48bf42..41694af95 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.0.0 + 6.0.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index ba1f6a2bb..7226faaea 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.0.0 + 6.0.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 640477e11..b93300259 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.0.0 + 6.0.1-SNAPSHOT ../pom.xml From 73c2ef4a3984336dfa3474a52e6e390170bc3fdc Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 8 Oct 2018 14:47:45 +0300 Subject: [PATCH 532/882] remove deprecated code --- .../MicrosoftAzureActiveDirectoryApi.java | 16 --------- .../com/github/scribejava/apis/TutByApi.java | 16 --------- .../apis/service/FacebookService.java | 18 ---------- .../apis/service/ImgurOAuthService.java | 18 ---------- .../apis/service/MailruOAuthService.java | 18 ---------- .../MicrosoftAzureActiveDirectoryService.java | 31 ---------------- .../service/OdnoklassnikiOAuthService.java | 19 ---------- .../apis/service/TutByOAuthService.java | 30 ---------------- .../core/builder/api/DefaultApi20.java | 19 +--------- .../core/builder/api/OAuth2SignatureType.java | 36 ------------------- 10 files changed, 1 insertion(+), 220 deletions(-) delete mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/service/FacebookService.java delete mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthService.java delete mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthService.java delete mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/service/MicrosoftAzureActiveDirectoryService.java delete mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiOAuthService.java delete mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/service/TutByOAuthService.java delete mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/builder/api/OAuth2SignatureType.java diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/MicrosoftAzureActiveDirectoryApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/MicrosoftAzureActiveDirectoryApi.java index 2bbbe2ac5..6817cc686 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/MicrosoftAzureActiveDirectoryApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/MicrosoftAzureActiveDirectoryApi.java @@ -1,14 +1,10 @@ package com.github.scribejava.apis; import com.github.scribejava.apis.microsoftazureactivedirectory.MicrosoftAzureActiveDirectoryBearerSignature; -import com.github.scribejava.apis.service.MicrosoftAzureActiveDirectoryService; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.httpclient.HttpClient; -import com.github.scribejava.core.httpclient.HttpClientConfig; import com.github.scribejava.core.oauth2.bearersignature.BearerSignature; import com.github.scribejava.core.oauth2.clientauthentication.ClientAuthentication; import com.github.scribejava.core.oauth2.clientauthentication.RequestBodyAuthenticationScheme; -import java.io.OutputStream; /** * Microsoft Azure Active Directory Api @@ -51,18 +47,6 @@ protected String getAuthorizationBaseUrl() { return MSFT_LOGIN_URL + SLASH + COMMON + SLASH + AUTH_URI; } - /** - * @deprecated moved to {@link #getBearerSignature() } - */ - @Deprecated - @Override - public MicrosoftAzureActiveDirectoryService createService(String apiKey, String apiSecret, String callback, - String scope, OutputStream debugStream, String state, String responseType, String userAgent, - HttpClientConfig httpClientConfig, HttpClient httpClient) { - return new MicrosoftAzureActiveDirectoryService(this, apiKey, apiSecret, callback, scope, state, responseType, - userAgent, httpClientConfig, httpClient); - } - @Override public ClientAuthentication getClientAuthentication() { return RequestBodyAuthenticationScheme.instance(); diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/TutByApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/TutByApi.java index 94905a010..41f71b307 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/TutByApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/TutByApi.java @@ -1,12 +1,8 @@ package com.github.scribejava.apis; -import com.github.scribejava.apis.service.TutByOAuthService; import com.github.scribejava.apis.tutby.TutByBearerSignature; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.httpclient.HttpClient; -import com.github.scribejava.core.httpclient.HttpClientConfig; import com.github.scribejava.core.oauth2.bearersignature.BearerSignature; -import java.io.OutputStream; public class TutByApi extends DefaultApi20 { @@ -31,18 +27,6 @@ protected String getAuthorizationBaseUrl() { return "http://profile.tut.by/auth"; } - /** - * @deprecated moved to {@link #getBearerSignature() } - */ - @Deprecated - @Override - public TutByOAuthService createService(String apiKey, String apiSecret, String callback, String scope, - OutputStream debugStream, String state, String responseType, String userAgent, - HttpClientConfig httpClientConfig, HttpClient httpClient) { - return new TutByOAuthService(this, apiKey, apiSecret, callback, scope, state, responseType, userAgent, - httpClientConfig, httpClient); - } - @Override public BearerSignature getBearerSignature() { return TutByBearerSignature.instance(); diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/FacebookService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/FacebookService.java deleted file mode 100644 index ca14eb8c4..000000000 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/FacebookService.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.github.scribejava.apis.service; - -import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.httpclient.HttpClient; -import com.github.scribejava.core.httpclient.HttpClientConfig; - -/** - * @deprecated moved to {@link com.github.scribejava.apis.facebook.FacebookService} - */ -@Deprecated -public class FacebookService extends com.github.scribejava.apis.facebook.FacebookService { - - public FacebookService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, - String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, - HttpClient httpClient) { - super(api, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); - } -} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthService.java deleted file mode 100644 index fb51337da..000000000 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthService.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.github.scribejava.apis.service; - -import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.httpclient.HttpClient; -import com.github.scribejava.core.httpclient.HttpClientConfig; - -/** - * @deprecated moved to {@link com.github.scribejava.apis.imgur.ImgurOAuthService} - */ -@Deprecated -public class ImgurOAuthService extends com.github.scribejava.apis.imgur.ImgurOAuthService { - - public ImgurOAuthService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, - String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, - HttpClient httpClient) { - super(api, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); - } -} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthService.java deleted file mode 100644 index c1593dd45..000000000 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthService.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.github.scribejava.apis.service; - -import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.httpclient.HttpClient; -import com.github.scribejava.core.httpclient.HttpClientConfig; - -/** - * @deprecated moved to {@link com.github.scribejava.apis.mailru.MailruOAuthService} - */ -@Deprecated -public class MailruOAuthService extends com.github.scribejava.apis.mailru.MailruOAuthService { - - public MailruOAuthService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, - String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, - HttpClient httpClient) { - super(api, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); - } -} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MicrosoftAzureActiveDirectoryService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MicrosoftAzureActiveDirectoryService.java deleted file mode 100644 index e2ff45c3b..000000000 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MicrosoftAzureActiveDirectoryService.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.github.scribejava.apis.service; - -import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.httpclient.HttpClient; -import com.github.scribejava.core.httpclient.HttpClientConfig; -import com.github.scribejava.core.model.OAuthRequest; -import com.github.scribejava.core.oauth.OAuth20Service; - -/** - * @deprecated doesn't do anything useful, all MicrosoftAzureActiveDirectory specific logic was moved to - * {@link com.github.scribejava.apis.microsoftazureactivedirectory.MicrosoftAzureActiveDirectoryBearerSignature} - */ -@Deprecated -public class MicrosoftAzureActiveDirectoryService extends OAuth20Service { - - public MicrosoftAzureActiveDirectoryService(DefaultApi20 api, String apiKey, String apiSecret, String callback, - String scope, String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, - HttpClient httpClient) { - super(api, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); - } - - /** - * @deprecated moved to - * {@link com.github.scribejava.apis.microsoftazureactivedirectory.MicrosoftAzureActiveDirectoryBearerSignature} - */ - @Deprecated - @Override - public void signRequest(String accessToken, OAuthRequest request) { - super.signRequest(accessToken, request); - } -} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiOAuthService.java deleted file mode 100644 index 46a34102f..000000000 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiOAuthService.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.github.scribejava.apis.service; - -import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.httpclient.HttpClient; -import com.github.scribejava.core.httpclient.HttpClientConfig; - -/** - * @deprecated moved to {@link com.github.scribejava.apis.odnoklassniki.OdnoklassnikiOAuthService} - */ -@Deprecated -public class OdnoklassnikiOAuthService extends com.github.scribejava.apis.odnoklassniki.OdnoklassnikiOAuthService { - - public OdnoklassnikiOAuthService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, - String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, - HttpClient httpClient) { - super(api, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); - } - -} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/TutByOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/TutByOAuthService.java deleted file mode 100644 index 1b92ca8da..000000000 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/TutByOAuthService.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.github.scribejava.apis.service; - -import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.httpclient.HttpClient; -import com.github.scribejava.core.httpclient.HttpClientConfig; -import com.github.scribejava.core.model.OAuthRequest; -import com.github.scribejava.core.oauth.OAuth20Service; - -/** - * @deprecated doesn't do anything useful, all TutBy specific logic was moved to - * {@link com.github.scribejava.apis.tutby.TutByBearerSignature} - */ -@Deprecated -public class TutByOAuthService extends OAuth20Service { - - public TutByOAuthService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, - String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, - HttpClient httpClient) { - super(api, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); - } - - /** - * @deprecated moved to {@link com.github.scribejava.apis.tutby.TutByBearerSignature} - */ - @Deprecated - @Override - public void signRequest(String accessToken, OAuthRequest request) { - super.signRequest(accessToken, request); - } -} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java index 75cdd40ba..d12f4844c 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java @@ -11,7 +11,6 @@ import com.github.scribejava.core.oauth.OAuth20Service; import com.github.scribejava.core.oauth2.bearersignature.BearerSignature; import com.github.scribejava.core.oauth2.bearersignature.BearerSignatureAuthorizationRequestHeaderField; -import com.github.scribejava.core.oauth2.bearersignature.BearerSignatureURIQueryParameter; import com.github.scribejava.core.oauth2.clientauthentication.ClientAuthentication; import com.github.scribejava.core.oauth2.clientauthentication.HttpBasicAuthenticationScheme; import java.io.OutputStream; @@ -115,24 +114,8 @@ public OAuth20Service createService(String apiKey, String apiSecret, String call httpClientConfig, httpClient); } - /** - * @return OAuth2SignatureType - * @deprecated use {@link #getBearerSignature() } - */ - @Deprecated - public OAuth2SignatureType getSignatureType() { - return OAuth2SignatureType.BEARER_AUTHORIZATION_REQUEST_HEADER_FIELD; - } - public BearerSignature getBearerSignature() { - switch (getSignatureType()) { - case BEARER_AUTHORIZATION_REQUEST_HEADER_FIELD: - return BearerSignatureAuthorizationRequestHeaderField.instance(); - case BEARER_URI_QUERY_PARAMETER: - return BearerSignatureURIQueryParameter.instance(); - default: - throw new IllegalStateException("unknown OAuth2SignatureType"); - } + return BearerSignatureAuthorizationRequestHeaderField.instance(); } public ClientAuthentication getClientAuthentication() { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/OAuth2SignatureType.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/OAuth2SignatureType.java deleted file mode 100644 index baf246381..000000000 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/OAuth2SignatureType.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.github.scribejava.core.builder.api; - -import com.github.scribejava.core.model.OAuthRequest; -import com.github.scribejava.core.oauth2.bearersignature.BearerSignatureAuthorizationRequestHeaderField; -import com.github.scribejava.core.oauth2.bearersignature.BearerSignatureURIQueryParameter; - -/** - * @deprecated use {@link com.github.scribejava.core.oauth2.bearersignature.BearerSignature} - */ -@Deprecated -public enum OAuth2SignatureType { - /** - * @deprecated use - * {@link com.github.scribejava.core.oauth2.bearersignature.BearerSignatureAuthorizationRequestHeaderField} - */ - @Deprecated - BEARER_AUTHORIZATION_REQUEST_HEADER_FIELD { - @Override - public void signRequest(String accessToken, OAuthRequest request) { - BearerSignatureAuthorizationRequestHeaderField.instance().signRequest(accessToken, request); - } - - }, - /** - * @deprecated use {@link com.github.scribejava.core.oauth2.bearersignature.BearerSignatureURIQueryParameter} - */ - @Deprecated - BEARER_URI_QUERY_PARAMETER { - @Override - public void signRequest(String accessToken, OAuthRequest request) { - BearerSignatureURIQueryParameter.instance().signRequest(accessToken, request); - } - }; - - public abstract void signRequest(String accessToken, OAuthRequest request); -} From d44ac101a52c461bc29f4ffcdb9258c1408fe1dc Mon Sep 17 00:00:00 2001 From: JureZe Date: Fri, 12 Oct 2018 14:28:32 +0200 Subject: [PATCH 533/882] Keycloak api and keyclak example --- .../github/scribejava/apis/KeyloackApi.java | 57 ++++++++++++++ .../apis/examples/KeyloackExample.java | 75 +++++++++++++++++++ 2 files changed, 132 insertions(+) create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/KeyloackApi.java create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/KeyloackExample.java diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/KeyloackApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/KeyloackApi.java new file mode 100644 index 000000000..d138505d5 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/KeyloackApi.java @@ -0,0 +1,57 @@ +package com.github.scribejava.apis; + +import com.github.scribejava.apis.openid.OpenIdJsonTokenExtractor; +import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.builder.api.OAuth2SignatureType; +import com.github.scribejava.core.extractors.TokenExtractor; +import com.github.scribejava.core.model.OAuth2AccessToken; + +public class KeyloackApi extends DefaultApi20 { + + private String baseUrl = "http://localhost:8080"; + private String realm = "master"; + + public void setBaseUrl(String baseUrl) { + this.baseUrl = baseUrl + (baseUrl.endsWith("/")? "" : "/"); + } + + public void setRealm(String realm) { + this.realm = realm; + } + + protected KeyloackApi() { + } + + private static class InstanceHolder { + private static final KeyloackApi INSTANCE = new KeyloackApi(); + } + + public static KeyloackApi instance() { + return KeyloackApi.InstanceHolder.INSTANCE; + } + + @Override + public String getAccessTokenEndpoint() { + return baseUrl + "auth/realms/" + realm + "/protocol/openid-connect/token"; + } + + @Override + protected String getAuthorizationBaseUrl() { + return baseUrl + "auth/realms/" + realm + "/protocol/openid-connect/auth"; + } + + @Override + public OAuth2SignatureType getSignatureType() { + return OAuth2SignatureType.BEARER_AUTHORIZATION_REQUEST_HEADER_FIELD; + } + + @Override + public TokenExtractor getAccessTokenExtractor() { + return OpenIdJsonTokenExtractor.instance(); + } + + @Override + public String getRevokeTokenEndpoint() { + throw new RuntimeException("Not implemented yet"); + } +} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/KeyloackExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/KeyloackExample.java new file mode 100644 index 000000000..9d977008f --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/KeyloackExample.java @@ -0,0 +1,75 @@ +package com.github.scribejava.apis.examples; + +import com.github.scribejava.apis.KeyloackApi; +import com.github.scribejava.core.builder.ServiceBuilder; +import com.github.scribejava.core.model.OAuth2AccessToken; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.oauth.OAuth20Service; + +import java.io.IOException; +import java.util.Scanner; +import java.util.concurrent.ExecutionException; + +public final class KeyloackExample { + + private static final String BASE_URL = "https://sicas.setcce.si"; + + private static final String REALM = "TEST_SP"; + + private static final String PROTECTED_RESOURCE_URL = BASE_URL + "/auth/realms/" + REALM + "/protocol/openid-connect/userinfo"; + + private KeyloackExample() { + } + + public static void main(String... args) throws IOException, InterruptedException, ExecutionException { + // Replace these with your own api key and secret + final String apiKey = "TEST_SP"; + final String apiSecret = "c9e04342-23e2-433a-a644-5af2a6c5d015"; + final KeyloackApi keyloackApi = KeyloackApi.instance(); + keyloackApi.setBaseUrl(BASE_URL); + keyloackApi.setRealm(REALM); + final OAuth20Service service = new ServiceBuilder(apiKey) + .apiSecret(apiSecret) + .scope("openid") + .callback("http://najdi.si") + .build(keyloackApi); + final Scanner in = new Scanner(System.in); + + System.out.println("=== Keyloack's OAuth Workflow ==="); + System.out.println(); + + // Obtain the Authorization URL + System.out.println("Fetching the Authorization URL..."); + final String authorizationUrl = service.getAuthorizationUrl(); + System.out.println("Got the Authorization URL!"); + System.out.println("Now go and authorize ScribeJava here:"); + System.out.println(authorizationUrl); + System.out.println("And paste the authorization code here"); + System.out.print(">>"); + final String code = in.nextLine(); + System.out.println(); + + // Trade the Request Token and Verfier for the Access Token + System.out.println("Trading the Request Token for an Access Token..."); + final OAuth2AccessToken accessToken = service.getAccessToken(code); + System.out.println("Got the Access Token!"); + System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); + System.out.println(); + + // Now let's go and ask for a protected resource! + System.out.println("Now we're going to access a protected resource..."); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); + service.signRequest(accessToken, request); + final Response response = service.execute(request); + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + + System.out.println(); + System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); + + } +} From bd527f6af5f88a9f62202cc74056e0b62ddde692 Mon Sep 17 00:00:00 2001 From: JureZe Date: Mon, 15 Oct 2018 12:13:27 +0200 Subject: [PATCH 534/882] Renamed api classes --- .../apis/{KeyloackApi.java => KeycloakApi.java} | 16 +++++----------- ...KeyloackExample.java => KeycloakExample.java} | 10 +++++----- 2 files changed, 10 insertions(+), 16 deletions(-) rename scribejava-apis/src/main/java/com/github/scribejava/apis/{KeyloackApi.java => KeycloakApi.java} (72%) rename scribejava-apis/src/test/java/com/github/scribejava/apis/examples/{KeyloackExample.java => KeycloakExample.java} (92%) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/KeyloackApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/KeycloakApi.java similarity index 72% rename from scribejava-apis/src/main/java/com/github/scribejava/apis/KeyloackApi.java rename to scribejava-apis/src/main/java/com/github/scribejava/apis/KeycloakApi.java index d138505d5..ca16dcbfe 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/KeyloackApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/KeycloakApi.java @@ -2,11 +2,10 @@ import com.github.scribejava.apis.openid.OpenIdJsonTokenExtractor; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.builder.api.OAuth2SignatureType; import com.github.scribejava.core.extractors.TokenExtractor; import com.github.scribejava.core.model.OAuth2AccessToken; -public class KeyloackApi extends DefaultApi20 { +public class KeycloakApi extends DefaultApi20 { private String baseUrl = "http://localhost:8080"; private String realm = "master"; @@ -19,15 +18,15 @@ public void setRealm(String realm) { this.realm = realm; } - protected KeyloackApi() { + protected KeycloakApi() { } private static class InstanceHolder { - private static final KeyloackApi INSTANCE = new KeyloackApi(); + private static final KeycloakApi INSTANCE = new KeycloakApi(); } - public static KeyloackApi instance() { - return KeyloackApi.InstanceHolder.INSTANCE; + public static KeycloakApi instance() { + return KeycloakApi.InstanceHolder.INSTANCE; } @Override @@ -40,11 +39,6 @@ protected String getAuthorizationBaseUrl() { return baseUrl + "auth/realms/" + realm + "/protocol/openid-connect/auth"; } - @Override - public OAuth2SignatureType getSignatureType() { - return OAuth2SignatureType.BEARER_AUTHORIZATION_REQUEST_HEADER_FIELD; - } - @Override public TokenExtractor getAccessTokenExtractor() { return OpenIdJsonTokenExtractor.instance(); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/KeyloackExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/KeycloakExample.java similarity index 92% rename from scribejava-apis/src/test/java/com/github/scribejava/apis/examples/KeyloackExample.java rename to scribejava-apis/src/test/java/com/github/scribejava/apis/examples/KeycloakExample.java index 9d977008f..de3202431 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/KeyloackExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/KeycloakExample.java @@ -1,6 +1,6 @@ package com.github.scribejava.apis.examples; -import com.github.scribejava.apis.KeyloackApi; +import com.github.scribejava.apis.KeycloakApi; import com.github.scribejava.core.builder.ServiceBuilder; import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthRequest; @@ -12,7 +12,7 @@ import java.util.Scanner; import java.util.concurrent.ExecutionException; -public final class KeyloackExample { +public final class KeycloakExample { private static final String BASE_URL = "https://sicas.setcce.si"; @@ -20,14 +20,14 @@ public final class KeyloackExample { private static final String PROTECTED_RESOURCE_URL = BASE_URL + "/auth/realms/" + REALM + "/protocol/openid-connect/userinfo"; - private KeyloackExample() { + private KeycloakExample() { } public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your own api key and secret final String apiKey = "TEST_SP"; - final String apiSecret = "c9e04342-23e2-433a-a644-5af2a6c5d015"; - final KeyloackApi keyloackApi = KeyloackApi.instance(); + final String apiSecret = "a8fe62c9-c3a1-4545-81ca-fda5df1c032b"; + final KeycloakApi keyloackApi = KeycloakApi.instance(); keyloackApi.setBaseUrl(BASE_URL); keyloackApi.setRealm(REALM); final OAuth20Service service = new ServiceBuilder(apiKey) From d5fa6563056f93cc523d2cf9c4f25cb7c06e0268 Mon Sep 17 00:00:00 2001 From: JureZe Date: Mon, 15 Oct 2018 13:58:08 +0200 Subject: [PATCH 535/882] immutable API classes - as suggested by kullfar --- .../github/scribejava/apis/KeycloakApi.java | 37 ++++++++++++------- .../apis/examples/KeycloakExample.java | 5 +-- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/KeycloakApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/KeycloakApi.java index ca16dcbfe..1e24c482f 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/KeycloakApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/KeycloakApi.java @@ -5,38 +5,47 @@ import com.github.scribejava.core.extractors.TokenExtractor; import com.github.scribejava.core.model.OAuth2AccessToken; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; + public class KeycloakApi extends DefaultApi20 { - private String baseUrl = "http://localhost:8080"; - private String realm = "master"; + private final String baseUrlWithRealm; - public void setBaseUrl(String baseUrl) { - this.baseUrl = baseUrl + (baseUrl.endsWith("/")? "" : "/"); - } + private static final ConcurrentMap INSTANCES = new ConcurrentHashMap<>(); - public void setRealm(String realm) { - this.realm = realm; + protected KeycloakApi(String baseUrlWithRealm) { + this.baseUrlWithRealm = baseUrlWithRealm; } - protected KeycloakApi() { + public static KeycloakApi instance() { + return instance("http://localhost:8080/", "master"); } - private static class InstanceHolder { - private static final KeycloakApi INSTANCE = new KeycloakApi(); + public static KeycloakApi instance(String baseUrl, String realm) { + final String defaultBaseUrlWithRealm = composeBaseUrlWithRealm(baseUrl, realm); + + //java8: switch to ConcurrentMap::computeIfAbsent + KeycloakApi api = INSTANCES.get(defaultBaseUrlWithRealm); + if (api == null) { + api = new KeycloakApi(defaultBaseUrlWithRealm); + INSTANCES.putIfAbsent(defaultBaseUrlWithRealm, api); + } + return api; } - public static KeycloakApi instance() { - return KeycloakApi.InstanceHolder.INSTANCE; + protected static String composeBaseUrlWithRealm(String baseUrl, String realm) { + return baseUrl + (baseUrl.endsWith("/") ? "" : "/") + "auth/realms/" + realm; } @Override public String getAccessTokenEndpoint() { - return baseUrl + "auth/realms/" + realm + "/protocol/openid-connect/token"; + return baseUrlWithRealm + "/protocol/openid-connect/token"; } @Override protected String getAuthorizationBaseUrl() { - return baseUrl + "auth/realms/" + realm + "/protocol/openid-connect/auth"; + return baseUrlWithRealm + "/protocol/openid-connect/auth"; } @Override diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/KeycloakExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/KeycloakExample.java index de3202431..65ca53825 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/KeycloakExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/KeycloakExample.java @@ -27,14 +27,11 @@ public static void main(String... args) throws IOException, InterruptedException // Replace these with your own api key and secret final String apiKey = "TEST_SP"; final String apiSecret = "a8fe62c9-c3a1-4545-81ca-fda5df1c032b"; - final KeycloakApi keyloackApi = KeycloakApi.instance(); - keyloackApi.setBaseUrl(BASE_URL); - keyloackApi.setRealm(REALM); final OAuth20Service service = new ServiceBuilder(apiKey) .apiSecret(apiSecret) .scope("openid") .callback("http://najdi.si") - .build(keyloackApi); + .build(KeycloakApi.instance(BASE_URL, REALM)); final Scanner in = new Scanner(System.in); System.out.println("=== Keyloack's OAuth Workflow ==="); From 70c4d35f39f8926c552c530fd5cbf851d3320a48 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 15 Oct 2018 15:43:47 +0300 Subject: [PATCH 536/882] add new API Keycloak (https://www.keycloak.org/) (thanks to https://github.com/JureZelic) --- README.md | 1 + changelog | 3 ++ .../github/scribejava/apis/KeycloakApi.java | 9 ++-- .../github/scribejava/apis/ExampleUtils.java | 52 +++++++++++++++++++ .../apis/examples/KeycloakExample.java | 26 +++++----- 5 files changed, 75 insertions(+), 16 deletions(-) create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/ExampleUtils.java diff --git a/README.md b/README.md index 2cc181033..f57ede33f 100644 --- a/README.md +++ b/README.md @@ -71,6 +71,7 @@ ScribeJava support out-of-box several HTTP clients: * HiOrg-Server (https://www.hiorg-server.de/) * Imgur (http://imgur.com/) * Kaixin 开心网 (http://www.kaixin001.com/) +* Keycloak (https://www.keycloak.org/) * LinkedIn (https://www.linkedin.com/) * Microsoft Azure Active Directory (Azure AD) (http://azure.microsoft.com/) * Microsoft Live (https://login.live.com/) diff --git a/changelog b/changelog index 81c5e188d..fe95b1173 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,6 @@ +[SNAPSHOT] + * add new API Keycloak (https://www.keycloak.org/) (thanks to https://github.com/JureZelic) + [6.0.0] * make redirect_uri optional while Access Token requesting on OAuth 2.0 (thanks to https://github.com/computerlove) * switch to java 9+ (from java 7 only) for compilation. Runtime is still java 7+. Complement README with links and RFC descriptions. diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/KeycloakApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/KeycloakApi.java index 1e24c482f..ed713b4d0 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/KeycloakApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/KeycloakApi.java @@ -10,10 +10,10 @@ public class KeycloakApi extends DefaultApi20 { - private final String baseUrlWithRealm; - private static final ConcurrentMap INSTANCES = new ConcurrentHashMap<>(); + private final String baseUrlWithRealm; + protected KeycloakApi(String baseUrlWithRealm) { this.baseUrlWithRealm = baseUrlWithRealm; } @@ -29,7 +29,10 @@ public static KeycloakApi instance(String baseUrl, String realm) { KeycloakApi api = INSTANCES.get(defaultBaseUrlWithRealm); if (api == null) { api = new KeycloakApi(defaultBaseUrlWithRealm); - INSTANCES.putIfAbsent(defaultBaseUrlWithRealm, api); + final KeycloakApi alreadyCreatedApi = INSTANCES.putIfAbsent(defaultBaseUrlWithRealm, api); + if (alreadyCreatedApi != null) { + return alreadyCreatedApi; + } } return api; } diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/ExampleUtils.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/ExampleUtils.java new file mode 100644 index 000000000..195729b3c --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/ExampleUtils.java @@ -0,0 +1,52 @@ +package com.github.scribejava.apis; + +import java.security.KeyManagementException; +import java.security.NoSuchAlgorithmException; +import java.security.cert.X509Certificate; +import javax.net.ssl.HostnameVerifier; +import javax.net.ssl.HttpsURLConnection; +import javax.net.ssl.SSLContext; +import javax.net.ssl.SSLSession; +import javax.net.ssl.TrustManager; +import javax.net.ssl.X509TrustManager; + +public class ExampleUtils { + + private ExampleUtils() { + } + + public static void turnOfSSl() { + try { + final TrustManager[] trustAllCerts = new TrustManager[]{new X509TrustManager() { + @Override + public java.security.cert.X509Certificate[] getAcceptedIssuers() { + return null; + } + + @Override + public void checkClientTrusted(X509Certificate[] certs, String authType) { + } + + @Override + public void checkServerTrusted(X509Certificate[] certs, String authType) { + } + } + }; + + final SSLContext sc = SSLContext.getInstance("SSL"); + sc.init(null, trustAllCerts, new java.security.SecureRandom()); + HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); + + final HostnameVerifier allHostsValid = new HostnameVerifier() { + @Override + public boolean verify(String hostname, SSLSession session) { + return true; + } + }; + + HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid); + } catch (NoSuchAlgorithmException | KeyManagementException e) { + throw new RuntimeException(e); + } + } +} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/KeycloakExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/KeycloakExample.java index 65ca53825..57fa12c4f 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/KeycloakExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/KeycloakExample.java @@ -12,26 +12,26 @@ import java.util.Scanner; import java.util.concurrent.ExecutionException; -public final class KeycloakExample { - - private static final String BASE_URL = "https://sicas.setcce.si"; - - private static final String REALM = "TEST_SP"; - - private static final String PROTECTED_RESOURCE_URL = BASE_URL + "/auth/realms/" + REALM + "/protocol/openid-connect/userinfo"; +public class KeycloakExample { private KeycloakExample() { } public static void main(String... args) throws IOException, InterruptedException, ExecutionException { - // Replace these with your own api key and secret - final String apiKey = "TEST_SP"; - final String apiSecret = "a8fe62c9-c3a1-4545-81ca-fda5df1c032b"; + // Replace these with your own api key, secret, callback, base url and realm + final String apiKey = "your_api_key"; + final String apiSecret = "your_api_secret"; + final String callback = "your_callback"; + final String baseUrl = "your_base_url"; + final String realm = "your_realm"; + + final String protectedResourceUrl = baseUrl + "/auth/realms/" + realm + "/protocol/openid-connect/userinfo"; + final OAuth20Service service = new ServiceBuilder(apiKey) .apiSecret(apiSecret) .scope("openid") - .callback("http://najdi.si") - .build(KeycloakApi.instance(BASE_URL, REALM)); + .callback(callback) + .build(KeycloakApi.instance(baseUrl, realm)); final Scanner in = new Scanner(System.in); System.out.println("=== Keyloack's OAuth Workflow ==="); @@ -57,7 +57,7 @@ public static void main(String... args) throws IOException, InterruptedException // Now let's go and ask for a protected resource! System.out.println("Now we're going to access a protected resource..."); - final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); + final OAuthRequest request = new OAuthRequest(Verb.GET, protectedResourceUrl); service.signRequest(accessToken, request); final Response response = service.execute(request); System.out.println("Got it! Lets see what we found..."); From dc3b98a66967a3416916a3e2e317822c22e7b572 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 15 Oct 2018 16:03:43 +0300 Subject: [PATCH 537/882] add links to the examples on README.md --- README.md | 94 +++++++++++++++++++++++++++---------------------------- 1 file changed, 47 insertions(+), 47 deletions(-) diff --git a/README.md b/README.md index f57ede33f..1903d478e 100644 --- a/README.md +++ b/README.md @@ -51,54 +51,54 @@ ScribeJava support out-of-box several HTTP clients: ### Supports all major 1.0a and 2.0 OAuth APIs out-of-the-box -* Automatic (https://www.automatic.com/) -* AWeber (http://www.aweber.com/) -* Box (https://www.box.com/) -* Dataporten (https://docs.dataporten.no/) -* Digg (http://digg.com/) +* Automatic (https://www.automatic.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AutomaticExample.java) +* AWeber (http://www.aweber.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AWeberExample.java) +* Box (https://www.box.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Box20Example.java) +* Dataporten (https://docs.dataporten.no/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DataportenExample.java) +* Digg (http://digg.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiggExample.java) * Доктор на работе (https://www.doktornarabote.ru/) -* Etsy (https://www.etsy.com/) -* Facebook (https://www.facebook.com/) -* Fitbit (https://www.fitbit.com/) -* Flickr (https://www.flickr.com/) -* Foursquare (https://foursquare.com/) -* Frappe (https://github.com/frappe/frappe) -* Freelancer (https://www.freelancer.com/) -* Genius (http://genius.com/) -* GitHub (https://github.com/) -* Google (https://www.google.com/) -* HeadHunter ХэдХантер (https://hh.ru/) -* HiOrg-Server (https://www.hiorg-server.de/) -* Imgur (http://imgur.com/) -* Kaixin 开心网 (http://www.kaixin001.com/) -* Keycloak (https://www.keycloak.org/) -* LinkedIn (https://www.linkedin.com/) -* Microsoft Azure Active Directory (Azure AD) (http://azure.microsoft.com/) -* Microsoft Live (https://login.live.com/) -* Misfit (http://misfit.com/) -* Mail.Ru (https://mail.ru/) -* MediaWiki (https://www.mediawiki.org/) -* Meetup (http://www.meetup.com/) -* NAVER (http://www.naver.com/) -* Odnoklassniki Одноклассники (http://ok.ru/) -* Pinterest (https://www.pinterest.com/) -* 500px (https://500px.com/) -* Renren (http://renren.com/) -* Salesforce (https://www.salesforce.com/) -* Sina (http://www.sina.com.cn/ http://weibo.com/login.php) -* Skyrock (http://skyrock.com/) -* StackExchange (http://stackexchange.com/) -* The Things Network (v1-staging and v2-preview) (https://www.thethingsnetwork.org/) -* Trello (https://trello.com/) -* Tumblr (https://www.tumblr.com/) -* TUT.BY (http://www.tut.by/) -* Twitter (https://twitter.com/) -* uCoz (https://www.ucoz.com/) -* Viadeo (http://viadeo.com/) -* VK ВКонтакте (http://vk.com/) -* Wunderlist (https://www.wunderlist.com/) -* XING (https://www.xing.com/) -* Yahoo (https://www.yahoo.com/) +* Etsy (https://www.etsy.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/EtsyExample.java) +* Facebook (https://www.facebook.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java) [example with Async Apache HTTP client](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncApacheExample.java) [example with Async Ning HTTP client](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java) +* Fitbit (https://www.fitbit.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FitbitApi20Example.java) +* Flickr (https://www.flickr.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExample.java) +* Foursquare (https://foursquare.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FoursquareExample.java) +* Frappe (https://github.com/frappe/frappe) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FrappeExample.java) +* Freelancer (https://www.freelancer.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java) +* Genius (http://genius.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GeniusExample.java) +* GitHub (https://github.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubExample.java) [example with OkHttp HTTP client](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubAsyncOkHttpExample.java) +* Google (https://www.google.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java) [example with Async Http Client](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java) [example Revoke](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20RevokeExample.java) [example with PKCEE](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20WithPKCEExample.java) +* HeadHunter ХэдХантер (https://hh.ru/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HHExample.java) +* HiOrg-Server (https://www.hiorg-server.de/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HiOrgServerExample.java) +* Imgur (http://imgur.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ImgurExample.java) +* Kaixin 开心网 (http://www.kaixin001.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Kaixin20Example.java) +* Keycloak (https://www.keycloak.org/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/KeycloakExample.java) +* LinkedIn (https://www.linkedin.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedIn20Example.java) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java) [example with custom scopes](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java) +* Mail.Ru (https://mail.ru/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java) [example with Async Ning HTTP Client](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java) +* MediaWiki (https://www.mediawiki.org/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MediaWikiExample.java) +* Meetup (http://www.meetup.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java) +* Microsoft Azure Active Directory (Azure AD) (http://azure.microsoft.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureActiveDirectoryExample.java) +* Microsoft Live (https://login.live.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java) +* Misfit (http://misfit.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MisfitExample.java) +* NAVER (http://www.naver.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NaverExample.java) +* Odnoklassniki Одноклассники (http://ok.ru/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java) +* Pinterest (https://www.pinterest.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java) +* 500px (https://500px.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Px500Example.java) +* Renren (http://renren.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java) +* Salesforce (https://www.salesforce.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceExample.java) [example with Async Ning HTTP Client](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceNingAsyncExample.java) +* Sina (http://www.sina.com.cn/ http://weibo.com/login.php) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeibo2Example.java) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeiboExample.java) +* Skyrock (http://skyrock.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SkyrockExample.java) +* StackExchange (http://stackexchange.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/StackExchangeExample.java) +* The Things Network (v1-staging and v2-preview) (https://www.thethingsnetwork.org/) [example v1](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV1StagingExample.java) [example v2 preview](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV2PreviewExample.java) +* Trello (https://trello.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TrelloExample.java) +* Tumblr (https://www.tumblr.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TumblrExample.java) +* TUT.BY (http://www.tut.by/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TutByExample.java) +* Twitter (https://twitter.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TwitterExample.java) +* uCoz (https://www.ucoz.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/UcozExample.java) +* Viadeo (http://viadeo.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ViadeoExample.java) +* VK ВКонтакте (http://vk.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExample.java) [example Client Credentials Grant](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteClientCredentialsGrantExample.java) [example with External HTTP Client](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExternalHttpExample.java) +* Wunderlist (https://www.wunderlist.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/WunderlistExample.java) +* XING (https://www.xing.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XingExample.java) +* Yahoo (https://www.yahoo.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Yahoo20Example.java) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/YahooExample.java) * check the [examples folder](https://github.com/scribejava/scribejava/tree/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples) ### Small and modular From debbbbd25472b16ef3532f0f29a0adbdb868e920 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 15 Oct 2018 16:06:26 +0300 Subject: [PATCH 538/882] format README.md --- README.md | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 1903d478e..fabbd06cc 100644 --- a/README.md +++ b/README.md @@ -58,22 +58,22 @@ ScribeJava support out-of-box several HTTP clients: * Digg (http://digg.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiggExample.java) * Доктор на работе (https://www.doktornarabote.ru/) * Etsy (https://www.etsy.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/EtsyExample.java) -* Facebook (https://www.facebook.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java) [example with Async Apache HTTP client](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncApacheExample.java) [example with Async Ning HTTP client](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java) +* Facebook (https://www.facebook.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java), [example with Async Apache HTTP client](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncApacheExample.java), [example with Async Ning HTTP client](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java) * Fitbit (https://www.fitbit.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FitbitApi20Example.java) * Flickr (https://www.flickr.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExample.java) -* Foursquare (https://foursquare.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FoursquareExample.java) +* Foursquare (https://foursquare.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java), [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FoursquareExample.java) * Frappe (https://github.com/frappe/frappe) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FrappeExample.java) * Freelancer (https://www.freelancer.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java) * Genius (http://genius.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GeniusExample.java) -* GitHub (https://github.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubExample.java) [example with OkHttp HTTP client](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubAsyncOkHttpExample.java) -* Google (https://www.google.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java) [example with Async Http Client](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java) [example Revoke](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20RevokeExample.java) [example with PKCEE](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20WithPKCEExample.java) +* GitHub (https://github.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubExample.java), [example with OkHttp HTTP client](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubAsyncOkHttpExample.java) +* Google (https://www.google.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java), [example with Async Http Client](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java), [example Revoke](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20RevokeExample.java), [example with PKCEE](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20WithPKCEExample.java) * HeadHunter ХэдХантер (https://hh.ru/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HHExample.java) * HiOrg-Server (https://www.hiorg-server.de/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HiOrgServerExample.java) * Imgur (http://imgur.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ImgurExample.java) * Kaixin 开心网 (http://www.kaixin001.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Kaixin20Example.java) * Keycloak (https://www.keycloak.org/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/KeycloakExample.java) -* LinkedIn (https://www.linkedin.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedIn20Example.java) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java) [example with custom scopes](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java) -* Mail.Ru (https://mail.ru/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java) [example with Async Ning HTTP Client](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java) +* LinkedIn (https://www.linkedin.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedIn20Example.java), [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java), [example with custom scopes](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java) +* Mail.Ru (https://mail.ru/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java), [example with Async Ning HTTP Client](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java) * MediaWiki (https://www.mediawiki.org/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MediaWikiExample.java) * Meetup (http://www.meetup.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java) * Microsoft Azure Active Directory (Azure AD) (http://azure.microsoft.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureActiveDirectoryExample.java) @@ -84,21 +84,21 @@ ScribeJava support out-of-box several HTTP clients: * Pinterest (https://www.pinterest.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java) * 500px (https://500px.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Px500Example.java) * Renren (http://renren.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java) -* Salesforce (https://www.salesforce.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceExample.java) [example with Async Ning HTTP Client](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceNingAsyncExample.java) -* Sina (http://www.sina.com.cn/ http://weibo.com/login.php) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeibo2Example.java) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeiboExample.java) +* Salesforce (https://www.salesforce.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceExample.java), [example with Async Ning HTTP Client](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceNingAsyncExample.java) +* Sina (http://www.sina.com.cn/ http://weibo.com/login.php) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeibo2Example.java), [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeiboExample.java) * Skyrock (http://skyrock.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SkyrockExample.java) * StackExchange (http://stackexchange.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/StackExchangeExample.java) -* The Things Network (v1-staging and v2-preview) (https://www.thethingsnetwork.org/) [example v1](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV1StagingExample.java) [example v2 preview](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV2PreviewExample.java) +* The Things Network (v1-staging and v2-preview) (https://www.thethingsnetwork.org/) [example v1](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV1StagingExample.java), [example v2 preview](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV2PreviewExample.java) * Trello (https://trello.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TrelloExample.java) * Tumblr (https://www.tumblr.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TumblrExample.java) * TUT.BY (http://www.tut.by/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TutByExample.java) * Twitter (https://twitter.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TwitterExample.java) * uCoz (https://www.ucoz.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/UcozExample.java) * Viadeo (http://viadeo.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ViadeoExample.java) -* VK ВКонтакте (http://vk.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExample.java) [example Client Credentials Grant](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteClientCredentialsGrantExample.java) [example with External HTTP Client](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExternalHttpExample.java) +* VK ВКонтакте (http://vk.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExample.java), [example Client Credentials Grant](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteClientCredentialsGrantExample.java), [example with External HTTP Client](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExternalHttpExample.java) * Wunderlist (https://www.wunderlist.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/WunderlistExample.java) * XING (https://www.xing.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XingExample.java) -* Yahoo (https://www.yahoo.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Yahoo20Example.java) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/YahooExample.java) +* Yahoo (https://www.yahoo.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Yahoo20Example.java), [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/YahooExample.java) * check the [examples folder](https://github.com/scribejava/scribejava/tree/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples) ### Small and modular From d854c786805aeaf04ff754f21a7578a743e3f444 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 6 Nov 2018 14:18:36 +0300 Subject: [PATCH 539/882] add new API Discord (https://discordapp.com/) (thanks to https://github.com/Jokuni) --- README.md | 2 +- changelog | 1 + .../github/scribejava/apis/DiscordApi.java | 15 ------------ .../apis/imgur/ImgurOAuthService.java | 3 ++- .../apis/service/DiscordService.java | 23 ------------------- .../apis/examples/DiscordExample.java | 2 +- ...natureAuthorizationRequestHeaderField.java | 3 ++- 7 files changed, 7 insertions(+), 42 deletions(-) delete mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/service/DiscordService.java diff --git a/README.md b/README.md index 00457c51e..150bd6e41 100644 --- a/README.md +++ b/README.md @@ -56,7 +56,7 @@ ScribeJava support out-of-box several HTTP clients: * Box (https://www.box.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Box20Example.java) * Dataporten (https://docs.dataporten.no/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DataportenExample.java) * Digg (http://digg.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiggExample.java) -* Discord (https://discordapp.com/) +* Discord (https://discordapp.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiscordExample.java) * Доктор на работе (https://www.doktornarabote.ru/) * Etsy (https://www.etsy.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/EtsyExample.java) * Facebook (https://www.facebook.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java), [example with Async Apache HTTP client](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncApacheExample.java), [example with Async Ning HTTP client](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java) diff --git a/changelog b/changelog index fe95b1173..ea0fe2eb2 100644 --- a/changelog +++ b/changelog @@ -1,5 +1,6 @@ [SNAPSHOT] * add new API Keycloak (https://www.keycloak.org/) (thanks to https://github.com/JureZelic) + * add new API Discord (https://discordapp.com/) (thanks to https://github.com/Jokuni) [6.0.0] * make redirect_uri optional while Access Token requesting on OAuth 2.0 (thanks to https://github.com/computerlove) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/DiscordApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/DiscordApi.java index 96a3c31bf..0583b6dc5 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/DiscordApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/DiscordApi.java @@ -1,12 +1,6 @@ package com.github.scribejava.apis; -import com.github.scribejava.apis.service.DiscordService; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.httpclient.HttpClient; -import com.github.scribejava.core.httpclient.HttpClientConfig; -import com.github.scribejava.core.oauth.OAuth20Service; - -import java.io.OutputStream; public class DiscordApi extends DefaultApi20 { @@ -35,13 +29,4 @@ public String getRevokeTokenEndpoint() { public String getAccessTokenEndpoint() { return "https://discordapp.com/api/oauth2/token"; } - - @Override - public OAuth20Service createService(String apiKey, String apiSecret, String callback, - String scope, OutputStream debugStream, String state, - String responseType, String userAgent, - HttpClientConfig httpClientConfig, HttpClient httpClient) { - return new DiscordService(this, apiKey, apiSecret, callback, scope, state, responseType, - userAgent, httpClientConfig, httpClient); - } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/imgur/ImgurOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/imgur/ImgurOAuthService.java index f37dfab95..b1c934a9a 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/imgur/ImgurOAuthService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/imgur/ImgurOAuthService.java @@ -35,6 +35,7 @@ protected OAuthRequest createAccessTokenRequest(String oauthVerifier) { @Override public void signRequest(String accessToken, OAuthRequest request) { - request.addHeader("Authorization", accessToken == null ? "Client-ID " + getApiKey() : "Bearer " + accessToken); + request.addHeader(OAuthConstants.HEADER, + accessToken == null ? "Client-ID " + getApiKey() : "Bearer " + accessToken); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/DiscordService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/DiscordService.java deleted file mode 100644 index c97c10d7d..000000000 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/DiscordService.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.github.scribejava.apis.service; - -import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.httpclient.HttpClient; -import com.github.scribejava.core.httpclient.HttpClientConfig; -import com.github.scribejava.core.model.OAuth2AccessToken; -import com.github.scribejava.core.model.OAuthConstants; -import com.github.scribejava.core.model.OAuthRequest; -import com.github.scribejava.core.oauth.OAuth20Service; - -public class DiscordService extends OAuth20Service { - public DiscordService(DefaultApi20 api, String apiKey, String apiSecret, String callback, - String scope, String state, String responseType, String userAgent, - HttpClientConfig httpClientConfig, HttpClient httpClient) { - super(api, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); - } - - @Override - public void signRequest(OAuth2AccessToken accessToken, OAuthRequest request) { - request.addHeader(OAuthConstants.HEADER, accessToken.getTokenType() + ' ' + accessToken.getAccessToken()); - } - -} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiscordExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiscordExample.java index cad56cd73..41c5be42b 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiscordExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiscordExample.java @@ -13,7 +13,7 @@ import java.util.Scanner; import java.util.concurrent.ExecutionException; -public final class DiscordExample { +public class DiscordExample { private static final String NETWORK_NAME = "Discord"; private static final String PROTECTED_RESOURCE_URL = "https://discordapp.com/api/users/@me"; diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth2/bearersignature/BearerSignatureAuthorizationRequestHeaderField.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth2/bearersignature/BearerSignatureAuthorizationRequestHeaderField.java index 72ab0cbd2..98196a708 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth2/bearersignature/BearerSignatureAuthorizationRequestHeaderField.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth2/bearersignature/BearerSignatureAuthorizationRequestHeaderField.java @@ -1,5 +1,6 @@ package com.github.scribejava.core.oauth2.bearersignature; +import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.OAuthRequest; /** @@ -23,6 +24,6 @@ public static BearerSignatureAuthorizationRequestHeaderField instance() { @Override public void signRequest(String accessToken, OAuthRequest request) { - request.addHeader("Authorization", "Bearer " + accessToken); + request.addHeader(OAuthConstants.HEADER, "Bearer " + accessToken); } } From 001f2f5afecbca89baa83606c6c0a71918180846 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 6 Nov 2018 14:33:07 +0300 Subject: [PATCH 540/882] update deps --- pom.xml | 6 +++--- scribejava-httpclient-ahc/pom.xml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index 85f930caf..2c9030940 100644 --- a/pom.xml +++ b/pom.xml @@ -78,7 +78,7 @@ org.apache.felix maven-bundle-plugin - 4.0.0 + 4.1.0 bundle-manifest @@ -107,7 +107,7 @@ com.puppycrawl.tools checkstyle - 8.13 + 8.14 @@ -122,7 +122,7 @@ org.apache.maven.plugins maven-surefire-plugin - 2.22.0 + 2.22.1 org.apache.maven.plugins diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index a8826d0d1..119aa998b 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -23,7 +23,7 @@ org.asynchttpclient async-http-client - 2.5.4 + 2.6.0 com.github.scribejava From 92c97d8d64562c9d49a4ade82b1c74b812469114 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 14 Nov 2018 17:28:27 +0300 Subject: [PATCH 541/882] prepare v6.1.0 --- README.md | 4 ++-- changelog | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 150bd6e41..2736a6a34 100644 --- a/README.md +++ b/README.md @@ -125,7 +125,7 @@ You can pull ScribeJava from the central maven repository, just add these to you com.github.scribejava scribejava-apis - 6.0.0 + 6.1.0 ``` @@ -134,7 +134,7 @@ And in case you need just core classes (that's it, without any external API (FB, com.github.scribejava scribejava-core - 6.0.0 + 6.1.0 ``` diff --git a/changelog b/changelog index ea0fe2eb2..7a2ba2cd3 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,4 @@ -[SNAPSHOT] +[6.1.0] * add new API Keycloak (https://www.keycloak.org/) (thanks to https://github.com/JureZelic) * add new API Discord (https://discordapp.com/) (thanks to https://github.com/Jokuni) From 944c350540944dd2aebce4d072e2a5656f8a45ca Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 14 Nov 2018 17:29:44 +0300 Subject: [PATCH 542/882] [maven-release-plugin] prepare release scribejava-6.1.0 --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index 2c9030940..5c79f48da 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 6.0.1-SNAPSHOT + 6.1.0 ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -34,7 +34,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - HEAD + scribejava-6.1.0 diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index c96f2850c..397e981c8 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.0.1-SNAPSHOT + 6.1.0 ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 5924eab0d..b0dc43311 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.0.1-SNAPSHOT + 6.1.0 ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 119aa998b..826709b08 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.0.1-SNAPSHOT + 6.1.0 ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index 41694af95..e772ec917 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.0.1-SNAPSHOT + 6.1.0 ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index 7226faaea..00f7b9272 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.0.1-SNAPSHOT + 6.1.0 ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index b93300259..0e511cb87 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.0.1-SNAPSHOT + 6.1.0 ../pom.xml From c6f060c4234658277bbaf8f9780fc2c30eba8ad7 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 14 Nov 2018 17:29:50 +0300 Subject: [PATCH 543/882] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index 5c79f48da..eb4a7e86a 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 6.1.0 + 6.1.1-SNAPSHOT ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -34,7 +34,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - scribejava-6.1.0 + HEAD diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 397e981c8..51ce2ae29 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.1.0 + 6.1.1-SNAPSHOT ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index b0dc43311..184a6f0b9 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.1.0 + 6.1.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 826709b08..19a4e8716 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.1.0 + 6.1.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index e772ec917..0e7e85cb0 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.1.0 + 6.1.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index 00f7b9272..550c0a3dc 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.1.0 + 6.1.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 0e511cb87..fdd3a0a14 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.1.0 + 6.1.1-SNAPSHOT ../pom.xml From 0a8ce3cb36a9b9cecca23eaee8266f309b5febc4 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 21 Nov 2018 17:52:47 +0300 Subject: [PATCH 544/882] add new API Microsoft Azure Active Directory (Azure AD) 2.0 (thanks to https://github.com/rzukow and https://github.com/dgrudenic) --- README.md | 1 + changelog | 3 + .../MicrosoftAzureActiveDirectory20Api.java | 28 ++++++++ .../MicrosoftAzureActiveDirectoryApi.java | 38 ++-------- .../BaseMicrosoftAzureActiveDirectoryApi.java | 69 +++++++++++++++++++ ...ftAzureActiveDirectoryBearerSignature.java | 20 ++++++ ...AzureActiveDirectory20BearerSignature.java | 18 +++++ ...ftAzureActiveDirectoryBearerSignature.java | 14 +--- ...icrosoftAzureActiveDirectory20Example.java | 62 +++++++++++++++++ 9 files changed, 208 insertions(+), 45 deletions(-) create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/MicrosoftAzureActiveDirectory20Api.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/microsoftazureactivedirectory/BaseMicrosoftAzureActiveDirectoryApi.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/microsoftazureactivedirectory/BaseMicrosoftAzureActiveDirectoryBearerSignature.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/microsoftazureactivedirectory/MicrosoftAzureActiveDirectory20BearerSignature.java create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureActiveDirectory20Example.java diff --git a/README.md b/README.md index 2736a6a34..8c5d54c29 100644 --- a/README.md +++ b/README.md @@ -78,6 +78,7 @@ ScribeJava support out-of-box several HTTP clients: * MediaWiki (https://www.mediawiki.org/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MediaWikiExample.java) * Meetup (http://www.meetup.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java) * Microsoft Azure Active Directory (Azure AD) (http://azure.microsoft.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureActiveDirectoryExample.java) +* Microsoft Azure Active Directory (Azure AD) 2.0 (http://azure.microsoft.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureActiveDirectory20Example.java) * Microsoft Live (https://login.live.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java) * Misfit (http://misfit.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MisfitExample.java) * NAVER (http://www.naver.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NaverExample.java) diff --git a/changelog b/changelog index 7a2ba2cd3..02fa06cfe 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,6 @@ +[SNAPSHOT] + * add new API Microsoft Azure Active Directory (Azure AD) 2.0 (thanks to https://github.com/rzukow and https://github.com/dgrudenic) + [6.1.0] * add new API Keycloak (https://www.keycloak.org/) (thanks to https://github.com/JureZelic) * add new API Discord (https://discordapp.com/) (thanks to https://github.com/Jokuni) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/MicrosoftAzureActiveDirectory20Api.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/MicrosoftAzureActiveDirectory20Api.java new file mode 100644 index 000000000..71b0a005e --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/MicrosoftAzureActiveDirectory20Api.java @@ -0,0 +1,28 @@ +package com.github.scribejava.apis; + +import com.github.scribejava.apis.microsoftazureactivedirectory.BaseMicrosoftAzureActiveDirectoryApi; + +/** + * Microsoft Azure Active Directory Api v 2.0 + * + * @see + * Understand the OAuth 2.0 authorization code flow in Azure AD | Microsoft Docs + * @see + * Microsoft Graph REST API v1.0 reference + * @see https://portal.azure.com + */ +public class MicrosoftAzureActiveDirectory20Api extends BaseMicrosoftAzureActiveDirectoryApi { + + protected MicrosoftAzureActiveDirectory20Api() { + super(MicrosoftAzureActiveDirectoryVersion.V_2_0); + } + + private static class InstanceHolder { + + private static final MicrosoftAzureActiveDirectory20Api INSTANCE = new MicrosoftAzureActiveDirectory20Api(); + } + + public static MicrosoftAzureActiveDirectory20Api instance() { + return InstanceHolder.INSTANCE; + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/MicrosoftAzureActiveDirectoryApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/MicrosoftAzureActiveDirectoryApi.java index 6817cc686..31250be3f 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/MicrosoftAzureActiveDirectoryApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/MicrosoftAzureActiveDirectoryApi.java @@ -1,10 +1,6 @@ package com.github.scribejava.apis; -import com.github.scribejava.apis.microsoftazureactivedirectory.MicrosoftAzureActiveDirectoryBearerSignature; -import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.oauth2.bearersignature.BearerSignature; -import com.github.scribejava.core.oauth2.clientauthentication.ClientAuthentication; -import com.github.scribejava.core.oauth2.clientauthentication.RequestBodyAuthenticationScheme; +import com.github.scribejava.apis.microsoftazureactivedirectory.BaseMicrosoftAzureActiveDirectoryApi; /** * Microsoft Azure Active Directory Api @@ -18,15 +14,11 @@ * Azure AD Graph API Operations on the Signed-in User * @see https://portal.azure.com */ -public class MicrosoftAzureActiveDirectoryApi extends DefaultApi20 { +public class MicrosoftAzureActiveDirectoryApi extends BaseMicrosoftAzureActiveDirectoryApi { - private static final String MSFT_GRAPH_URL = "https://graph.windows.net"; - - private static final String MSFT_LOGIN_URL = "https://login.microsoftonline.com"; - private static final String SLASH = "/"; - private static final String COMMON = "common"; - private static final String TOKEN_URI = "oauth2/token"; - private static final String AUTH_URI = "oauth2/authorize?resource=" + MSFT_GRAPH_URL; + protected MicrosoftAzureActiveDirectoryApi() { + super(MicrosoftAzureActiveDirectoryVersion.V_1_0); + } private static class InstanceHolder { @@ -36,24 +28,4 @@ private static class InstanceHolder { public static MicrosoftAzureActiveDirectoryApi instance() { return InstanceHolder.INSTANCE; } - - @Override - public String getAccessTokenEndpoint() { - return MSFT_LOGIN_URL + SLASH + COMMON + SLASH + TOKEN_URI; - } - - @Override - protected String getAuthorizationBaseUrl() { - return MSFT_LOGIN_URL + SLASH + COMMON + SLASH + AUTH_URI; - } - - @Override - public ClientAuthentication getClientAuthentication() { - return RequestBodyAuthenticationScheme.instance(); - } - - @Override - public BearerSignature getBearerSignature() { - return MicrosoftAzureActiveDirectoryBearerSignature.instance(); - } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/microsoftazureactivedirectory/BaseMicrosoftAzureActiveDirectoryApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/microsoftazureactivedirectory/BaseMicrosoftAzureActiveDirectoryApi.java new file mode 100644 index 000000000..bc813e398 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/microsoftazureactivedirectory/BaseMicrosoftAzureActiveDirectoryApi.java @@ -0,0 +1,69 @@ +package com.github.scribejava.apis.microsoftazureactivedirectory; + +import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.oauth2.bearersignature.BearerSignature; +import com.github.scribejava.core.oauth2.clientauthentication.ClientAuthentication; +import com.github.scribejava.core.oauth2.clientauthentication.RequestBodyAuthenticationScheme; + +public abstract class BaseMicrosoftAzureActiveDirectoryApi extends DefaultApi20 { + + private static final String MSFT_LOGIN_URL = "https://login.microsoftonline.com"; + private static final String SLASH = "/"; + private static final String COMMON = "common"; + private static final String TOKEN_URI = "oauth2/token"; + private final String resource; + private final BaseMicrosoftAzureActiveDirectoryBearerSignature bearerSignature; + + protected BaseMicrosoftAzureActiveDirectoryApi(String resource, + BaseMicrosoftAzureActiveDirectoryBearerSignature bearerSignature) { + this.resource = resource; + this.bearerSignature = bearerSignature; + } + + protected BaseMicrosoftAzureActiveDirectoryApi(MicrosoftAzureActiveDirectoryVersion version) { + this.resource = version.getResource(); + this.bearerSignature = version.getBearerSignature(); + } + + @Override + public String getAccessTokenEndpoint() { + return MSFT_LOGIN_URL + SLASH + COMMON + SLASH + TOKEN_URI; + } + + @Override + protected String getAuthorizationBaseUrl() { + return MSFT_LOGIN_URL + SLASH + COMMON + SLASH + "oauth2/authorize?resource=" + resource; + } + + @Override + public ClientAuthentication getClientAuthentication() { + return RequestBodyAuthenticationScheme.instance(); + } + + @Override + public BearerSignature getBearerSignature() { + return bearerSignature; + } + + protected enum MicrosoftAzureActiveDirectoryVersion { + V_1_0("https://graph.windows.net", MicrosoftAzureActiveDirectoryBearerSignature.instance()), + V_2_0("https://graph.microsoft.com", MicrosoftAzureActiveDirectory20BearerSignature.instance()); + + private final String resource; + private final BaseMicrosoftAzureActiveDirectoryBearerSignature bearerSignature; + + MicrosoftAzureActiveDirectoryVersion(String resource, + BaseMicrosoftAzureActiveDirectoryBearerSignature bearerSignature) { + this.resource = resource; + this.bearerSignature = bearerSignature; + } + + protected String getResource() { + return resource; + } + + protected BaseMicrosoftAzureActiveDirectoryBearerSignature getBearerSignature() { + return bearerSignature; + } + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/microsoftazureactivedirectory/BaseMicrosoftAzureActiveDirectoryBearerSignature.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/microsoftazureactivedirectory/BaseMicrosoftAzureActiveDirectoryBearerSignature.java new file mode 100644 index 000000000..ab85674af --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/microsoftazureactivedirectory/BaseMicrosoftAzureActiveDirectoryBearerSignature.java @@ -0,0 +1,20 @@ +package com.github.scribejava.apis.microsoftazureactivedirectory; + +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.oauth2.bearersignature.BearerSignatureAuthorizationRequestHeaderField; + +public abstract class BaseMicrosoftAzureActiveDirectoryBearerSignature + extends BearerSignatureAuthorizationRequestHeaderField { + + private final String acceptedFormat; + + protected BaseMicrosoftAzureActiveDirectoryBearerSignature(String acceptedFormat) { + this.acceptedFormat = acceptedFormat; + } + + @Override + public void signRequest(String accessToken, OAuthRequest request) { + super.signRequest(accessToken, request); + request.addHeader("Accept", acceptedFormat); + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/microsoftazureactivedirectory/MicrosoftAzureActiveDirectory20BearerSignature.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/microsoftazureactivedirectory/MicrosoftAzureActiveDirectory20BearerSignature.java new file mode 100644 index 000000000..c554beeff --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/microsoftazureactivedirectory/MicrosoftAzureActiveDirectory20BearerSignature.java @@ -0,0 +1,18 @@ +package com.github.scribejava.apis.microsoftazureactivedirectory; + +public class MicrosoftAzureActiveDirectory20BearerSignature extends BaseMicrosoftAzureActiveDirectoryBearerSignature { + + protected MicrosoftAzureActiveDirectory20BearerSignature() { + super("application/json"); + } + + private static class InstanceHolder { + + private static final MicrosoftAzureActiveDirectory20BearerSignature INSTANCE + = new MicrosoftAzureActiveDirectory20BearerSignature(); + } + + public static MicrosoftAzureActiveDirectory20BearerSignature instance() { + return InstanceHolder.INSTANCE; + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/microsoftazureactivedirectory/MicrosoftAzureActiveDirectoryBearerSignature.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/microsoftazureactivedirectory/MicrosoftAzureActiveDirectoryBearerSignature.java index dddf62d50..bfddd523a 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/microsoftazureactivedirectory/MicrosoftAzureActiveDirectoryBearerSignature.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/microsoftazureactivedirectory/MicrosoftAzureActiveDirectoryBearerSignature.java @@ -1,13 +1,9 @@ package com.github.scribejava.apis.microsoftazureactivedirectory; -import com.github.scribejava.core.model.OAuthRequest; -import com.github.scribejava.core.oauth2.bearersignature.BearerSignatureAuthorizationRequestHeaderField; - -public class MicrosoftAzureActiveDirectoryBearerSignature extends BearerSignatureAuthorizationRequestHeaderField { - private static final String ACCEPTED_FORMAT - = "application/json; odata=minimalmetadata; streaming=true; charset=utf-8"; +public class MicrosoftAzureActiveDirectoryBearerSignature extends BaseMicrosoftAzureActiveDirectoryBearerSignature { protected MicrosoftAzureActiveDirectoryBearerSignature() { + super("application/json; odata=minimalmetadata; streaming=true; charset=utf-8"); } private static class InstanceHolder { @@ -19,10 +15,4 @@ private static class InstanceHolder { public static MicrosoftAzureActiveDirectoryBearerSignature instance() { return InstanceHolder.INSTANCE; } - - @Override - public void signRequest(String accessToken, OAuthRequest request) { - super.signRequest(accessToken, request); - request.addHeader("Accept", ACCEPTED_FORMAT); - } } diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureActiveDirectory20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureActiveDirectory20Example.java new file mode 100644 index 000000000..c0bd6f88a --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureActiveDirectory20Example.java @@ -0,0 +1,62 @@ +package com.github.scribejava.apis.examples; + +import com.github.scribejava.apis.MicrosoftAzureActiveDirectory20Api; +import com.github.scribejava.core.builder.ServiceBuilder; +import com.github.scribejava.core.model.OAuth2AccessToken; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.oauth.OAuth20Service; +import java.io.IOException; +import java.util.Scanner; +import java.util.concurrent.ExecutionException; + +public class MicrosoftAzureActiveDirectory20Example { + + private static final String NETWORK_NAME = "Microsoft Azure Active Directory"; + private static final String PROTECTED_RESOURCE_URL = "https://graph.microsoft.com/v1.0/me"; + + private MicrosoftAzureActiveDirectory20Example() { + } + + public static void main(String... args) throws IOException, InterruptedException, ExecutionException { + // Replace these with your client id and secret + final String clientId = "client id here"; + final String clientSecret = "client secret here"; + final OAuth20Service service = new ServiceBuilder(clientId) + .apiSecret(clientSecret) + .scope("openid") + .callback("http://www.example.com/oauth_callback/") + .build(MicrosoftAzureActiveDirectory20Api.instance()); + final Scanner in = new Scanner(System.in, "UTF-8"); + System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); + System.out.println(); + // Obtain the Authorization URL + System.out.println("Fetching the Authorization URL..."); + final String authorizationUrl = service.getAuthorizationUrl(); + System.out.println("Got the Authorization URL!"); + System.out.println("Now go and authorize ScribeJava here:"); + System.out.println(authorizationUrl); + System.out.println("And paste the authorization code here"); + System.out.print(">>"); + final String code = in.nextLine(); + System.out.println(); + // Trade the Request Token and Verfier for the Access Token + System.out.println("Trading the Request Token for an Access Token..."); + final OAuth2AccessToken accessToken = service.getAccessToken(code); + System.out.println("Got the Access Token!"); + System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); + System.out.println(); + // Now let's go and ask for a protected resource! + System.out.println("Now we're going to access a protected resource..."); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); + service.signRequest(accessToken, request); + final Response response = service.execute(request); + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + System.out.println(); + System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); + } +} From 935bdf42204a5c97cfc919db53cad430da8ecb1b Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 11 Dec 2018 11:19:09 +0300 Subject: [PATCH 545/882] update OkHTTP --- pom.xml | 4 ++-- scribejava-httpclient-okhttp/pom.xml | 4 ++-- .../com/github/scribejava/httpclient/okhttp/MockCall.java | 6 ++++++ 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index eb4a7e86a..73ece612e 100644 --- a/pom.xml +++ b/pom.xml @@ -68,7 +68,7 @@ com.squareup.okhttp3 mockwebserver - 3.11.0 + 3.12.0 test @@ -107,7 +107,7 @@ com.puppycrawl.tools checkstyle - 8.14 + 8.15 diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index fdd3a0a14..e1eab50a3 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -8,7 +8,7 @@ 6.1.1-SNAPSHOT ../pom.xml - + com.github.scribejava scribejava-httpclient-okhttp ScribeJava Async OkHttp Client support @@ -23,7 +23,7 @@ com.squareup.okhttp3 okhttp - 3.11.0 + 3.12.0 com.github.scribejava diff --git a/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/MockCall.java b/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/MockCall.java index 967d96c4a..c6dabd4c2 100644 --- a/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/MockCall.java +++ b/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/MockCall.java @@ -8,6 +8,7 @@ import okhttp3.Callback; import okhttp3.Request; import okhttp3.Response; +import okio.Timeout; public class MockCall implements Call { @@ -51,4 +52,9 @@ public boolean isExecuted() { public Call clone() { throw new UnsupportedOperationException("Not supported yet."); } + + @Override + public Timeout timeout() { + throw new UnsupportedOperationException("Not supported yet."); + } } From 239ddc30cd301323aa38d29eae6116dfda828f2c Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 11 Dec 2018 11:39:37 +0300 Subject: [PATCH 546/882] prepare v6.2.0 --- README.md | 4 ++-- changelog | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 8c5d54c29..9d8162a93 100644 --- a/README.md +++ b/README.md @@ -126,7 +126,7 @@ You can pull ScribeJava from the central maven repository, just add these to you com.github.scribejava scribejava-apis - 6.1.0 + 6.2.0 ``` @@ -135,7 +135,7 @@ And in case you need just core classes (that's it, without any external API (FB, com.github.scribejava scribejava-core - 6.1.0 + 6.2.0 ``` diff --git a/changelog b/changelog index 02fa06cfe..96dfb8e84 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,4 @@ -[SNAPSHOT] +[6.2.0] * add new API Microsoft Azure Active Directory (Azure AD) 2.0 (thanks to https://github.com/rzukow and https://github.com/dgrudenic) [6.1.0] From a952ef04cf276a4b02eb1f572fe0bac0768e2315 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 11 Dec 2018 11:41:28 +0300 Subject: [PATCH 547/882] [maven-release-plugin] prepare release scribejava-6.2.0 --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index 73ece612e..eace26e6e 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 6.1.1-SNAPSHOT + 6.2.0 ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -34,7 +34,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - HEAD + scribejava-6.2.0 diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 51ce2ae29..07e05a009 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.1.1-SNAPSHOT + 6.2.0 ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 184a6f0b9..511bdf4ec 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.1.1-SNAPSHOT + 6.2.0 ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 19a4e8716..d492bf29c 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.1.1-SNAPSHOT + 6.2.0 ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index 0e7e85cb0..c3de9f1c0 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.1.1-SNAPSHOT + 6.2.0 ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index 550c0a3dc..f91dbf444 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.1.1-SNAPSHOT + 6.2.0 ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index e1eab50a3..1be3a8a04 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.1.1-SNAPSHOT + 6.2.0 ../pom.xml From b4f2cf8b676582f8ec2305e66a103ab69ae7d95d Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 11 Dec 2018 11:41:41 +0300 Subject: [PATCH 548/882] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index eace26e6e..09aaf9fa1 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 6.2.0 + 6.2.1-SNAPSHOT ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -34,7 +34,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - scribejava-6.2.0 + HEAD diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 07e05a009..39202c69b 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.2.0 + 6.2.1-SNAPSHOT ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 511bdf4ec..7da4f7cf5 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.2.0 + 6.2.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index d492bf29c..46e58e129 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.2.0 + 6.2.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index c3de9f1c0..5b6ffd268 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.2.0 + 6.2.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index f91dbf444..7b43aaf1b 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.2.0 + 6.2.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 1be3a8a04..701ba6109 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.2.0 + 6.2.1-SNAPSHOT ../pom.xml From eccb3a1ac684ad62c145f42e7b6db8b70af4bf24 Mon Sep 17 00:00:00 2001 From: Joe Stazak Date: Wed, 2 Jan 2019 14:15:51 -0500 Subject: [PATCH 549/882] Adding Asana OAuth 2.0 integration + example --- .../com/github/scribejava/apis/Asana20.java | 33 +++++++ .../apis/examples/AsanaExample.java | 87 +++++++++++++++++++ 2 files changed, 120 insertions(+) create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/Asana20.java create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AsanaExample.java diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/Asana20.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/Asana20.java new file mode 100644 index 000000000..b46151a35 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/Asana20.java @@ -0,0 +1,33 @@ +package com.github.scribejava.apis; + +import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.oauth2.clientauthentication.ClientAuthentication; +import com.github.scribejava.core.oauth2.clientauthentication.RequestBodyAuthenticationScheme; + +public class Asana20 extends DefaultApi20 { + protected Asana20() { + } + + private static class InstanceHolder { + private static final Asana20 INSTANCE = new Asana20(); + } + + public static Asana20 instance() { + return InstanceHolder.INSTANCE; + } + + @Override + public String getAccessTokenEndpoint() { + return "https://app.asana.com/-/oauth_token"; + } + + @Override + protected String getAuthorizationBaseUrl() { + return "https://app.asana.com/-/oauth_authorize"; + } + + @Override + public ClientAuthentication getClientAuthentication() { + return RequestBodyAuthenticationScheme.instance(); + } +} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AsanaExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AsanaExample.java new file mode 100644 index 000000000..5ae120df6 --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AsanaExample.java @@ -0,0 +1,87 @@ +package com.github.scribejava.apis.examples; + +import com.github.scribejava.apis.Asana20; +import com.github.scribejava.core.builder.ServiceBuilder; +import com.github.scribejava.core.model.OAuth2AccessToken; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.oauth.OAuth20Service; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; +import java.util.Random; +import java.util.Scanner; +import java.util.concurrent.ExecutionException; + +public class AsanaExample { + + private static final String PROTECTED_RESOURCE_URL = "https://app.asana.com/api/1.0/users/me"; + + private AsanaExample() { + + } + + public static void main(String... args) throws IOException, InterruptedException, ExecutionException { + final String apiKey = "your client id"; + final String apiSecret = "your client secret"; + final String secretState = "secret" + new Random().nextInt(999_999); + final OAuth20Service service = new ServiceBuilder(apiKey) + .apiSecret(apiSecret) + .callback("https://localhost/") + .build(Asana20.instance()); + final Scanner in = new Scanner(System.in); + + // Obtain Auth URL + System.out.println("Fetching the Authorication URL..."); + System.out.println("Got the Authorization URL!"); + final Map additionalParams = new HashMap<>(); + additionalParams.put("access_type", "offline"); + final String authorizationUrl = service.getAuthorizationUrl(additionalParams); + System.out.println("Now go and authorize ScribeJava here:"); + System.out.println(authorizationUrl); + System.out.println("And paste the authorization code here"); + System.out.print(">>"); + final String code = in.nextLine(); + System.out.println(); + + // Trade the Request Token and Verfier for the Access Token + System.out.println("Trading the Request Token for an Access Token..."); + OAuth2AccessToken accessToken = service.getAccessToken(code); + System.out.println("Got the Access Token!"); + System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); + System.out.println(); + + System.out.println("And paste the state from server here. We have set 'secretState'='" + secretState + "'."); + System.out.print(">>"); + final String value = in.nextLine(); + if (secretState.equals(value)) { + System.out.println("State value does match!"); + } else { + System.out.println("Ooops, state value does not match!"); + System.out.println("Expected = " + secretState); + System.out.println("Got = " + value); + System.out.println(); + } + + System.out.println("Refreshing the Access Token..."); + accessToken = service.refreshAccessToken(accessToken.getRefreshToken()); + System.out.println("Refreshed the Access Token!"); + System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); + System.out.println(); + + System.out.println("Now we're going to access a protected resource..."); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); + service.signRequest(accessToken, request); + final Response response = service.execute(request); + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + + System.out.println(); + System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); + } + +} From a44f6dcaa011104f77a9855a9feae8fddb10d5fb Mon Sep 17 00:00:00 2001 From: Joe Stazak Date: Wed, 2 Jan 2019 14:21:39 -0500 Subject: [PATCH 550/882] Updating authorization_url method in example --- .../com/github/scribejava/apis/examples/AsanaExample.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AsanaExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AsanaExample.java index 5ae120df6..9165fc1b8 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AsanaExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AsanaExample.java @@ -36,9 +36,7 @@ public static void main(String... args) throws IOException, InterruptedException // Obtain Auth URL System.out.println("Fetching the Authorication URL..."); System.out.println("Got the Authorization URL!"); - final Map additionalParams = new HashMap<>(); - additionalParams.put("access_type", "offline"); - final String authorizationUrl = service.getAuthorizationUrl(additionalParams); + final String authorizationUrl = service.getAuthorizationUrl(); System.out.println("Now go and authorize ScribeJava here:"); System.out.println(authorizationUrl); System.out.println("And paste the authorization code here"); From b29892c816453d12279d62421671820f0d3fcb80 Mon Sep 17 00:00:00 2001 From: Joe Stazak Date: Wed, 2 Jan 2019 14:24:42 -0500 Subject: [PATCH 551/882] Updating README --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 9d8162a93..314065569 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,7 @@ ScribeJava support out-of-box several HTTP clients: ### Supports all major 1.0a and 2.0 OAuth APIs out-of-the-box +* Asana (https://app.asana.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AsanaExample.java) * Automatic (https://www.automatic.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AutomaticExample.java) * AWeber (http://www.aweber.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AWeberExample.java) * Box (https://www.box.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Box20Example.java) From fac5e70bee6d2bcd7865feb90cef3aeea648b91f Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 17 Jan 2019 18:49:26 +0300 Subject: [PATCH 552/882] * fix Muplipart request model and implement it for a jdk HTTP client (thanks to https://github.com/NTPape) --- changelog | 3 + pom.xml | 6 +- .../AbstractAsyncOnlyHttpClient.java | 13 + .../core/httpclient/BodyPartPayload.java | 56 +++- .../core/httpclient/HttpClient.java | 40 +++ .../core/httpclient/MultipartPayload.java | 82 ++++-- .../core/httpclient/jdk/JDKHttpClient.java | 144 ++++++++-- .../httpclient/multipart/BodyPartPayload.java | 26 ++ .../multipart/ByteArrayBodyPartPayload.java | 26 ++ .../FileByteArrayBodyPartPayload.java | 52 ++++ .../multipart/MultipartPayload.java | 173 +++++++++++ .../scribejava/core/model/OAuthRequest.java | 179 +++++++++++- .../scribejava/core/oauth/OAuthService.java | 3 + .../httpclient/jdk/JDKHttpClientTest.java | 268 ++++++++++++++++++ .../multipart/MultipartPayloadTest.java | 121 ++++++++ .../httpclient/ahc/AhcHttpClient.java | 14 +- .../httpclient/apache/ApacheHttpClient.java | 14 +- .../httpclient/ning/NingHttpClient.java | 14 +- scribejava-httpclient-okhttp/pom.xml | 2 +- .../httpclient/okhttp/OkHttpHttpClient.java | 26 +- 20 files changed, 1203 insertions(+), 59 deletions(-) create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/BodyPartPayload.java create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/ByteArrayBodyPartPayload.java create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/FileByteArrayBodyPartPayload.java create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/MultipartPayload.java create mode 100644 scribejava-core/src/test/java/com/github/scribejava/core/httpclient/multipart/MultipartPayloadTest.java diff --git a/changelog b/changelog index 96dfb8e84..fa676453f 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,6 @@ +[SNAPSHOT] + * fix Muplipart request model and implement it for a jdk HTTP client (thanks to https://github.com/NTPape) + [6.2.0] * add new API Microsoft Azure Active Directory (Azure AD) 2.0 (thanks to https://github.com/rzukow and https://github.com/dgrudenic) diff --git a/pom.xml b/pom.xml index 09aaf9fa1..1fac89595 100644 --- a/pom.xml +++ b/pom.xml @@ -68,7 +68,7 @@ com.squareup.okhttp3 mockwebserver - 3.12.0 + 3.12.1 test @@ -92,7 +92,7 @@ org.apache.maven.plugins maven-jar-plugin - 3.1.0 + 3.1.1 ${project.build.outputDirectory}/META-INF/MANIFEST.MF @@ -107,7 +107,7 @@ com.puppycrawl.tools checkstyle - 8.15 + 8.16 diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/AbstractAsyncOnlyHttpClient.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/AbstractAsyncOnlyHttpClient.java index 6f75ee6c1..a54e51a58 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/AbstractAsyncOnlyHttpClient.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/AbstractAsyncOnlyHttpClient.java @@ -18,7 +18,11 @@ public Response execute(String userAgent, Map headers, Verb http (OAuthRequest.ResponseConverter) null).get(); } + /** + * @deprecated {@inheritDoc} + */ @Override + @Deprecated public Response execute(String userAgent, Map headers, Verb httpVerb, String completeUrl, MultipartPayload bodyContents) throws InterruptedException, ExecutionException, IOException { @@ -26,6 +30,15 @@ public Response execute(String userAgent, Map headers, Verb http (OAuthRequest.ResponseConverter) null).get(); } + @Override + public Response execute(String userAgent, Map headers, Verb httpVerb, String completeUrl, + com.github.scribejava.core.httpclient.multipart.MultipartPayload bodyContents) + throws InterruptedException, ExecutionException, IOException { + + return executeAsync(userAgent, headers, httpVerb, completeUrl, bodyContents, null, + (OAuthRequest.ResponseConverter) null).get(); + } + @Override public Response execute(String userAgent, Map headers, Verb httpVerb, String completeUrl, String bodyContents) throws InterruptedException, ExecutionException, IOException { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/BodyPartPayload.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/BodyPartPayload.java index 3e8c6d47e..2b349d666 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/BodyPartPayload.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/BodyPartPayload.java @@ -1,27 +1,69 @@ package com.github.scribejava.core.httpclient; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +/** + * @deprecated use {@link com.github.scribejava.core.httpclient.multipart.ByteArrayBodyPartPayload} + */ +@Deprecated public class BodyPartPayload { - private final String contentDisposition; - private final String contentType; + private final Map headers; private final byte[] payload; - public BodyPartPayload(String contentDisposition, String contentType, byte[] payload) { - this.contentDisposition = contentDisposition; - this.contentType = contentType; + public BodyPartPayload(Map headers, byte[] payload) { + this.headers = headers; this.payload = payload; } + public BodyPartPayload(String contentDisposition, String contentType, byte[] payload) { + this(createHeadersMap(contentDisposition, contentType), payload); + } + + public BodyPartPayload(String contentDisposition, byte[] payload) { + this(contentDisposition, null, payload); + } + + public Map getHeaders() { + return headers; + } + + /** + * @return return + * @deprecated use {@link #getHeaders() } and then get("Content-Disposition") + */ + @Deprecated public String getContentDisposition() { - return contentDisposition; + return headers.get("Content-Disposition"); } + /** + * @return return + * @deprecated use {@link #getHeaders() } and then get("Content-Type") + */ + @Deprecated public String getContentType() { - return contentType; + return headers.get(HttpClient.CONTENT_TYPE); } public byte[] getPayload() { return payload; } + private static Map createHeadersMap(String contentDisposition, String contentType) { + if (contentDisposition == null && contentType == null) { + return Collections.emptyMap(); + } + + final Map headers = new HashMap<>(); + if (contentDisposition != null) { + headers.put("Content-Disposition", contentDisposition); + } + if (contentType != null) { + headers.put(HttpClient.CONTENT_TYPE, contentType); + } + return headers; + } } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/HttpClient.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/HttpClient.java index 40f9663f5..4217ac717 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/HttpClient.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/HttpClient.java @@ -1,5 +1,6 @@ package com.github.scribejava.core.httpclient; +import com.github.scribejava.core.httpclient.multipart.MultipartPayload; import com.github.scribejava.core.model.OAuthAsyncRequestCallback; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; @@ -20,6 +21,27 @@ public interface HttpClient extends Closeable { Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, byte[] bodyContents, OAuthAsyncRequestCallback callback, OAuthRequest.ResponseConverter converter); + /** + * @param T + * @param userAgent userAgent + * @param headers headers + * @param httpVerb httpVerb + * @param completeUrl completeUrl + * @param bodyContents bodyContents + * @param callback callback + * @param converter converter + * @return return + * + * @deprecated use {@link #executeAsync(java.lang.String, java.util.Map, com.github.scribejava.core.model.Verb, + * java.lang.String, com.github.scribejava.core.httpclient.multipart.MultipartPayload, + * com.github.scribejava.core.model.OAuthAsyncRequestCallback, + * com.github.scribejava.core.model.OAuthRequest.ResponseConverter)} + */ + @Deprecated + Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, + com.github.scribejava.core.httpclient.MultipartPayload bodyContents, OAuthAsyncRequestCallback callback, + OAuthRequest.ResponseConverter converter); + Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, MultipartPayload bodyContents, OAuthAsyncRequestCallback callback, OAuthRequest.ResponseConverter converter); @@ -33,6 +55,24 @@ Future executeAsync(String userAgent, Map headers, Verb h Response execute(String userAgent, Map headers, Verb httpVerb, String completeUrl, byte[] bodyContents) throws InterruptedException, ExecutionException, IOException; + /** + * @param userAgent userAgent + * @param headers headers + * @param httpVerb httpVerb + * @param completeUrl completeUrl + * @param bodyContents bodyContents + * @return return + * @throws InterruptedException InterruptedException + * @throws ExecutionException ExecutionException + * @throws IOException IOException + * @deprecated use {@link #execute(java.lang.String, java.util.Map, com.github.scribejava.core.model.Verb, + * java.lang.String, com.github.scribejava.core.httpclient.multipart.MultipartPayload)} + */ + @Deprecated + Response execute(String userAgent, Map headers, Verb httpVerb, String completeUrl, + com.github.scribejava.core.httpclient.MultipartPayload bodyContents) + throws InterruptedException, ExecutionException, IOException; + Response execute(String userAgent, Map headers, Verb httpVerb, String completeUrl, MultipartPayload bodyContents) throws InterruptedException, ExecutionException, IOException; diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/MultipartPayload.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/MultipartPayload.java index 71d67f508..3d4016ea1 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/MultipartPayload.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/MultipartPayload.java @@ -1,47 +1,80 @@ package com.github.scribejava.core.httpclient; import java.util.ArrayList; +import java.util.Collections; import java.util.List; +import java.util.Map; /** * The class containing more than one payload of multipart/form-data request + * + * @deprecated use {@link com.github.scribejava.core.httpclient.multipart.MultipartPayload} */ +@Deprecated public class MultipartPayload { + private static final String DEFAULT_SUBTYPE = "form-data"; + private final String boundary; + private final Map headers; private final List bodyParts = new ArrayList<>(); public MultipartPayload(String boundary) { this.boundary = boundary; + headers = Collections.singletonMap(HttpClient.CONTENT_TYPE, + "multipart/" + DEFAULT_SUBTYPE + "; boundary=\"" + boundary + '"'); } + /** + * @param bodyPart bodyPart + * @return return + * @deprecated no replace for that. implement yourself. See code here + * {@link com.github.scribejava.core.httpclient.jdk.JDKHttpClient + * #getPayload(com.github.scribejava.core.httpclient.MultipartPayload)} + */ + @Deprecated public byte[] getStartBoundary(BodyPartPayload bodyPart) { - return ("--" + boundary + "\r\n" - + "Content-Disposition: " + bodyPart.getContentDisposition() + "\r\n" - + (bodyPart.getContentType() == null - ? "" : HttpClient.CONTENT_TYPE + ": " + bodyPart.getContentType() + "\r\n") - + "\r\n").getBytes(); + final StringBuilder startBoundary = new StringBuilder(); + startBoundary.append("\r\n--") + .append(boundary) + .append("\r\n"); + + for (Map.Entry header : bodyPart.getHeaders().entrySet()) { + startBoundary.append(header.getKey()) + .append(": ") + .append(header.getValue()) + .append("\r\n"); + } + return startBoundary.append("\r\n").toString().getBytes(); } + /** + * @return return + * @deprecated no replace for that. implement yourself. See code here + * {@link com.github.scribejava.core.httpclient.jdk.JDKHttpClient + * #getPayload(com.github.scribejava.core.httpclient.MultipartPayload)} + */ + @Deprecated public byte[] getEndBoundary() { return ("\r\n--" + boundary + "--\r\n").getBytes(); } + /** + * @return return + * @deprecated no replace for that. implement yourself. See code here + * {@link com.github.scribejava.core.httpclient.jdk.JDKHttpClient + * #getPayload(com.github.scribejava.core.httpclient.MultipartPayload)} + */ + @Deprecated public int getContentLength() { int contentLength = 0; + for (BodyPartPayload bodyPart : bodyParts) { - contentLength += bodyPart.getPayload().length - + bodyPart.getContentDisposition().length(); - if (bodyPart.getContentType() != null) { - contentLength += 16 //length of constant portions of contentType header - + bodyPart.getContentType().length(); - } + contentLength += getStartBoundary(bodyPart).length + bodyPart.getPayload().length; + } + if (!bodyParts.isEmpty()) { + contentLength += getEndBoundary().length; } - - contentLength += (37 //length of constant portions of contentDisposition header, - //see getStartBoundary and getEndBoundary methods - + boundary.length() * 2 //twice. start and end parts - ) * bodyParts.size(); //for every part return contentLength; } @@ -52,4 +85,21 @@ public List getBodyParts() { public void addMultipartPayload(String contentDisposition, String contentType, byte[] payload) { bodyParts.add(new BodyPartPayload(contentDisposition, contentType, payload)); } + + /** + * @return return + * @deprecated use {@link #getHeaders() } and then get("Content-Type") + */ + @Deprecated + public String getContentType() { + return headers.get(HttpClient.CONTENT_TYPE); + } + + public Map getHeaders() { + return headers; + } + + public String getBoundary() { + return boundary; + } } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java index 7e87dba0b..b13186603 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java @@ -1,14 +1,16 @@ package com.github.scribejava.core.httpclient.jdk; import com.github.scribejava.core.exceptions.OAuthException; -import com.github.scribejava.core.httpclient.BodyPartPayload; +import com.github.scribejava.core.httpclient.multipart.BodyPartPayload; import com.github.scribejava.core.httpclient.HttpClient; -import com.github.scribejava.core.httpclient.MultipartPayload; +import com.github.scribejava.core.httpclient.multipart.ByteArrayBodyPartPayload; +import com.github.scribejava.core.httpclient.multipart.MultipartPayload; import com.github.scribejava.core.model.OAuthAsyncRequestCallback; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; import com.github.scribejava.core.model.Verb; +import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; import java.io.OutputStream; @@ -45,6 +47,19 @@ public Future executeAsync(String userAgent, Map headers, converter); } + /** + * @deprecated {@inheritDoc} + */ + @Override + @Deprecated + public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, + com.github.scribejava.core.httpclient.MultipartPayload bodyContents, OAuthAsyncRequestCallback callback, + OAuthRequest.ResponseConverter converter) { + + return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, BodyType.OLD_MULTIPART, bodyContents, callback, + converter); + } + @Override public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, MultipartPayload bodyContents, OAuthAsyncRequestCallback callback, @@ -99,6 +114,17 @@ public Response execute(String userAgent, Map headers, Verb http return doExecute(userAgent, headers, httpVerb, completeUrl, BodyType.MULTIPART, multipartPayloads); } + /** + * @deprecated {@inheritDoc} + */ + @Override + @Deprecated + public Response execute(String userAgent, Map headers, Verb httpVerb, String completeUrl, + com.github.scribejava.core.httpclient.MultipartPayload multipartPayloads) + throws InterruptedException, ExecutionException, IOException { + return doExecute(userAgent, headers, httpVerb, completeUrl, BodyType.OLD_MULTIPART, multipartPayloads); + } + @Override public Response execute(String userAgent, Map headers, Verb httpVerb, String completeUrl, String bodyContents) throws InterruptedException, ExecutionException, IOException { @@ -145,6 +171,13 @@ void setBody(HttpURLConnection connection, Object bodyContents, boolean requires addBody(connection, (byte[]) bodyContents, requiresBody); } }, + OLD_MULTIPART { + @Override + void setBody(HttpURLConnection connection, Object bodyContents, boolean requiresBody) throws IOException { + addBody(connection, (com.github.scribejava.core.httpclient.MultipartPayload) bodyContents, + requiresBody); + } + }, MULTIPART { @Override void setBody(HttpURLConnection connection, Object bodyContents, boolean requiresBody) throws IOException { @@ -187,29 +220,109 @@ private static void addHeaders(HttpURLConnection connection, Map } } - /** - * Multipart implementation supporting more than one payload - */ + private static void addBody(HttpURLConnection connection, byte[] content, boolean requiresBody) throws IOException { + final int contentLength = content.length; + if (requiresBody || contentLength > 0) { + prepareConnectionForBodyAndGetOutputStream(connection, contentLength).write(content); + } + } + + private static void addBody(HttpURLConnection connection, + com.github.scribejava.core.httpclient.MultipartPayload multipartPayload, boolean requiresBody) + throws IOException { + + for (Map.Entry header : multipartPayload.getHeaders().entrySet()) { + connection.setRequestProperty(header.getKey(), header.getValue()); + } + + if (requiresBody) { + final ByteArrayOutputStream os = getPayload(multipartPayload); + + if (os.size() > 0) { + os.writeTo(prepareConnectionForBodyAndGetOutputStream(connection, os.size())); + } + } + } + private static void addBody(HttpURLConnection connection, MultipartPayload multipartPayload, boolean requiresBody) throws IOException { - final int contentLength = multipartPayload.getContentLength(); - if (requiresBody || contentLength > 0) { - final OutputStream os = prepareConnectionForBodyAndGetOutputStream(connection, contentLength); + for (Map.Entry header : multipartPayload.getHeaders().entrySet()) { + connection.setRequestProperty(header.getKey(), header.getValue()); + } - for (BodyPartPayload bodyPart : multipartPayload.getBodyParts()) { - os.write(multipartPayload.getStartBoundary(bodyPart)); + if (requiresBody) { + final ByteArrayOutputStream os = getPayload(multipartPayload); + + if (os.size() > 0) { + os.writeTo(prepareConnectionForBodyAndGetOutputStream(connection, os.size())); + } + } + } + + private static ByteArrayOutputStream getPayload( + com.github.scribejava.core.httpclient.MultipartPayload multipartPayload) throws IOException { + final ByteArrayOutputStream os = new ByteArrayOutputStream(); + final List bodyParts = multipartPayload.getBodyParts(); + if (!bodyParts.isEmpty()) { + final String boundary = multipartPayload.getBoundary(); + final byte[] startBoundary = ("\r\n--" + boundary + "\r\n").getBytes(); + + for (com.github.scribejava.core.httpclient.BodyPartPayload bodyPart : bodyParts) { + os.write(startBoundary); + + for (Map.Entry header : bodyPart.getHeaders().entrySet()) { + os.write((header.getKey() + ": " + header.getValue() + "\r\n").getBytes()); + } + os.write("\r\n".getBytes()); os.write(bodyPart.getPayload()); - os.write(multipartPayload.getEndBoundary()); } + + os.write(("\r\n--" + boundary + "--\r\n").getBytes()); } + return os; } - private static void addBody(HttpURLConnection connection, byte[] content, boolean requiresBody) throws IOException { - final int contentLength = content.length; - if (requiresBody || contentLength > 0) { - prepareConnectionForBodyAndGetOutputStream(connection, contentLength).write(content); + static ByteArrayOutputStream getPayload(MultipartPayload multipartPayload) throws IOException { + final ByteArrayOutputStream os = new ByteArrayOutputStream(); + + final String preamble = multipartPayload.getPreamble(); + if (preamble != null) { + os.write(preamble.getBytes()); } + final List bodyParts = multipartPayload.getBodyParts(); + if (!bodyParts.isEmpty()) { + final String boundary = multipartPayload.getBoundary(); + final byte[] startBoundary = ("\r\n--" + boundary + "\r\n").getBytes(); + + for (BodyPartPayload bodyPart : bodyParts) { + os.write(startBoundary); + + final Map bodyPartHeaders = bodyPart.getHeaders(); + if (bodyPartHeaders != null) { + for (Map.Entry header : bodyPartHeaders.entrySet()) { + os.write((header.getKey() + ": " + header.getValue() + "\r\n").getBytes()); + } + } + + if (bodyPart instanceof MultipartPayload) { + getPayload((MultipartPayload) bodyPart).writeTo(os); + } else if (bodyPart instanceof ByteArrayBodyPartPayload) { + os.write("\r\n".getBytes()); + os.write(((ByteArrayBodyPartPayload) bodyPart).getPayload()); + } else { + throw new AssertionError(bodyPart.getClass()); + } + } + + os.write(("\r\n--" + boundary + "--\r\n").getBytes()); + final String epilogue = multipartPayload.getEpilogue(); + if (epilogue != null) { + os.write((epilogue + "\r\n").getBytes()); + } + + } + return os; } private static OutputStream prepareConnectionForBodyAndGetOutputStream(HttpURLConnection connection, @@ -218,7 +331,6 @@ private static OutputStream prepareConnectionForBodyAndGetOutputStream(HttpURLCo connection.setRequestProperty(CONTENT_LENGTH, String.valueOf(contentLength)); if (connection.getRequestProperty(CONTENT_TYPE) == null) { connection.setRequestProperty(CONTENT_TYPE, DEFAULT_CONTENT_TYPE); - } connection.setDoOutput(true); return connection.getOutputStream(); diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/BodyPartPayload.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/BodyPartPayload.java new file mode 100644 index 000000000..ee426176b --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/BodyPartPayload.java @@ -0,0 +1,26 @@ +package com.github.scribejava.core.httpclient.multipart; + +import com.github.scribejava.core.httpclient.HttpClient; +import java.util.Collections; +import java.util.Map; + +public abstract class BodyPartPayload { + + private final Map headers; + + public BodyPartPayload() { + this((Map) null); + } + + public BodyPartPayload(String contentType) { + this(contentType == null ? null : Collections.singletonMap(HttpClient.CONTENT_TYPE, contentType)); + } + + public BodyPartPayload(Map headers) { + this.headers = headers; + } + + public Map getHeaders() { + return headers; + } +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/ByteArrayBodyPartPayload.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/ByteArrayBodyPartPayload.java new file mode 100644 index 000000000..7fd0d6d98 --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/ByteArrayBodyPartPayload.java @@ -0,0 +1,26 @@ +package com.github.scribejava.core.httpclient.multipart; + +import java.util.Map; + +public class ByteArrayBodyPartPayload extends BodyPartPayload { + + private final byte[] payload; + + public ByteArrayBodyPartPayload(byte[] payload) { + this.payload = payload; + } + + public ByteArrayBodyPartPayload(byte[] payload, String contentType) { + super(contentType); + this.payload = payload; + } + + public ByteArrayBodyPartPayload(byte[] payload, Map headers) { + super(headers); + this.payload = payload; + } + + public byte[] getPayload() { + return payload; + } +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/FileByteArrayBodyPartPayload.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/FileByteArrayBodyPartPayload.java new file mode 100644 index 000000000..524977819 --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/FileByteArrayBodyPartPayload.java @@ -0,0 +1,52 @@ +package com.github.scribejava.core.httpclient.multipart; + +import com.github.scribejava.core.httpclient.HttpClient; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +public class FileByteArrayBodyPartPayload extends ByteArrayBodyPartPayload { + + public FileByteArrayBodyPartPayload(byte[] payload) { + this(payload, null); + } + + public FileByteArrayBodyPartPayload(byte[] payload, String name) { + this(payload, name, null); + } + + public FileByteArrayBodyPartPayload(byte[] payload, String name, String filename) { + this(null, payload, name, filename); + } + + public FileByteArrayBodyPartPayload(String contentType, byte[] payload) { + this(contentType, payload, null); + } + + public FileByteArrayBodyPartPayload(String contentType, byte[] payload, String name) { + this(contentType, payload, name, null); + } + + public FileByteArrayBodyPartPayload(String contentType, byte[] payload, String name, String filename) { + super(payload, composeHeaders(contentType, name, filename)); + } + + private static Map composeHeaders(String contentType, String name, String filename) { + + String contentDispositionHeader = "form-data"; + if (name != null) { + contentDispositionHeader += "; name=\"" + name + '"'; + } + if (filename != null) { + contentDispositionHeader += "; filename=\"" + filename + '"'; + } + if (contentType == null) { + return Collections.singletonMap("Content-Disposition", contentDispositionHeader); + } else { + final Map headers = new HashMap<>(); + headers.put(HttpClient.CONTENT_TYPE, contentType); + headers.put("Content-Disposition", contentDispositionHeader); + return headers; + } + } +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/MultipartPayload.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/MultipartPayload.java new file mode 100644 index 000000000..5c9282272 --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/MultipartPayload.java @@ -0,0 +1,173 @@ +package com.github.scribejava.core.httpclient.multipart; + +import com.github.scribejava.core.httpclient.HttpClient; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class MultipartPayload extends BodyPartPayload { + private static final String B_CHARS_NO_SPACE_PATTERN = "0-9a-zA-Z'()+_,-./:=?"; + private static final String B_CHARS_PATTERN = B_CHARS_NO_SPACE_PATTERN + " "; + private static final String BOUNDARY_PATTERN = '[' + B_CHARS_PATTERN + "]{0,69}[" + B_CHARS_NO_SPACE_PATTERN + ']'; + private static final Pattern BOUNDARY_REGEXP = Pattern.compile(BOUNDARY_PATTERN); + private static final Pattern BOUNDARY_FROM_HEADER_REGEXP + = Pattern.compile("; boundary=\"?(" + BOUNDARY_PATTERN + ")\"?"); + + private static final String DEFAULT_SUBTYPE = "form-data"; + + private final String boundary; + private String preamble; + private final List bodyParts = new ArrayList<>(); + private String epilogue; + + public MultipartPayload() { + this(null, generateDefaultBoundary(), null); + } + + public MultipartPayload(String boundary) { + this(null, boundary, null); + } + + public MultipartPayload(String subtype, String boundary) { + this(subtype, boundary, null); + } + + public MultipartPayload(Map headers) { + this(null, parseOrGenerateBoundary(headers), headers); + } + + public MultipartPayload(String boundary, Map headers) { + this(null, boundary, headers); + } + + public MultipartPayload(String subtype, String boundary, Map headers) { + super(composeHeaders(subtype, boundary, headers)); + this.boundary = boundary; + } + + private static Map composeHeaders(String subtype, String boundary, Map headersIn) + throws IllegalArgumentException { + checkBoundarySyntax(boundary); + final Map headersOut; + String contentTypeHeader = headersIn == null ? null : headersIn.get(HttpClient.CONTENT_TYPE); + if (contentTypeHeader == null) { + contentTypeHeader = "multipart/" + (subtype == null ? DEFAULT_SUBTYPE : subtype) + + "; boundary=\"" + boundary + '"'; + if (headersIn == null) { + headersOut = Collections.singletonMap(HttpClient.CONTENT_TYPE, contentTypeHeader); + } else { + headersOut = headersIn; + headersOut.put(HttpClient.CONTENT_TYPE, contentTypeHeader); + } + } else { + headersOut = headersIn; + final String parsedBoundary = parseBoundaryFromHeader(contentTypeHeader); + if (parsedBoundary == null) { + headersOut.put(HttpClient.CONTENT_TYPE, contentTypeHeader + "; boundary=\"" + boundary + '"'); + } else if (!parsedBoundary.equals(boundary)) { + throw new IllegalArgumentException( + "Different boundaries was passed in constructors. One as argument, second as header"); + } + } + return headersOut; + } + + static void checkBoundarySyntax(String boundary) { + if (boundary == null || !BOUNDARY_REGEXP.matcher(boundary).matches()) { + throw new IllegalArgumentException("{'boundary'='" + boundary + "'} has invaid syntax. Should be '" + + BOUNDARY_PATTERN + "'."); + } + } + + private static String parseOrGenerateBoundary(Map headers) { + final String parsedBoundary = parseBoundaryFromHeader(headers.get(HttpClient.CONTENT_TYPE)); + return parsedBoundary == null ? generateDefaultBoundary() : parsedBoundary; + } + + private static String generateDefaultBoundary() { + return "----ScribeJava----" + System.currentTimeMillis(); + } + + static String parseBoundaryFromHeader(String contentTypeHeader) { + if (contentTypeHeader == null) { + return null; + } + final Matcher matcher = BOUNDARY_FROM_HEADER_REGEXP.matcher(contentTypeHeader); + return matcher.find() ? matcher.group(1) : null; + } + + public void addFileBodyPart(byte[] fileContent) { + addBodyPart(new FileByteArrayBodyPartPayload(fileContent)); + } + + public void addFileBodyPart(byte[] fileContent, String name) { + addBodyPart(new FileByteArrayBodyPartPayload(fileContent, name)); + } + + public void addFileBodyPart(byte[] fileContent, String name, String filename) { + addBodyPart(new FileByteArrayBodyPartPayload(fileContent, name, filename)); + } + + public void addFileBodyPart(String contentType, byte[] fileContent) { + addBodyPart(new FileByteArrayBodyPartPayload(contentType, fileContent)); + } + + public void addFileBodyPart(String contentType, byte[] fileContent, String name) { + addBodyPart(new FileByteArrayBodyPartPayload(contentType, fileContent, name)); + } + + public void addFileBodyPart(String contentType, byte[] fileContent, String name, String filename) { + addBodyPart(new FileByteArrayBodyPartPayload(contentType, fileContent, name, filename)); + } + + public void addBodyPart(BodyPartPayload bodyPartPayload) { + bodyParts.add(bodyPartPayload); + } + + public void addBodyPart(MultipartPayload multipartPayload) { + if (multipartPayload.getBoundary().equals(boundary)) { + throw new IllegalArgumentException("{'boundary'}={'" + boundary + + "'} is the same for parent MultipartPayload and child"); + } + bodyParts.add(multipartPayload); + } + + public void addBodyPart(byte[] bodyPartPayload) { + addBodyPart(new ByteArrayBodyPartPayload(bodyPartPayload)); + } + + public void addBodyPart(byte[] bodyPartPayload, String contentType) { + addBodyPart(new ByteArrayBodyPartPayload(bodyPartPayload, contentType)); + } + + public void addBodyPart(byte[] bodyPartPayload, Map headers) { + addBodyPart(new ByteArrayBodyPartPayload(bodyPartPayload, headers)); + } + + public List getBodyParts() { + return bodyParts; + } + + public String getBoundary() { + return boundary; + } + + public String getPreamble() { + return preamble; + } + + public void setPreamble(String preamble) { + this.preamble = preamble; + } + + public String getEpilogue() { + return epilogue; + } + + public void setEpilogue(String epilogue) { + this.epilogue = epilogue; + } +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequest.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequest.java index 87ace27bc..606577fbb 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequest.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequest.java @@ -1,7 +1,8 @@ package com.github.scribejava.core.model; import com.github.scribejava.core.exceptions.OAuthException; -import com.github.scribejava.core.httpclient.MultipartPayload; +import com.github.scribejava.core.httpclient.multipart.FileByteArrayBodyPartPayload; +import com.github.scribejava.core.httpclient.multipart.MultipartPayload; import java.io.File; import java.io.IOException; import java.io.UnsupportedEncodingException; @@ -30,6 +31,7 @@ public class OAuthRequest { private String stringPayload; private byte[] byteArrayPayload; private File filePayload; + private com.github.scribejava.core.httpclient.MultipartPayload oldMultipartPayload; private MultipartPayload multipartPayload; private final Map oauthParameters = new HashMap<>(); @@ -128,43 +130,190 @@ public void addParameter(String key, String value) { } /** - * Set boundary of multipart request - * - * @param boundary can be any string + * @param boundary boundary + * @deprecated create {@link #initMultipartPayload(java.lang.String) } */ + @Deprecated public void initMultipartBoundary(String boundary) { - multipartPayload = new MultipartPayload(boundary == null + oldMultipartPayload = new com.github.scribejava.core.httpclient.MultipartPayload(boundary == null ? Long.toString(System.currentTimeMillis()) : boundary); } /** - * init boundary of multipart request with default boundary + * @deprecated use {@link #initMultipartPayload()} */ + @Deprecated public void initMultipartBoundary() { initMultipartBoundary(null); } /** - * you can invoke {@link #initMultipartBoundary(java.lang.String) } to set custom boundary * @param contentDisposition contentDisposition * @param contentType contentType * @param payload payload + * @deprecated use {@link #addFileByteArrayBodyPartPayloadInMultipartPayload(java.lang.String, byte[], + * java.lang.String, java.lang.String)} */ + @Deprecated public void addMultipartPayload(String contentDisposition, String contentType, byte[] payload) { - if (multipartPayload == null) { + if (oldMultipartPayload == null) { initMultipartBoundary(); } - multipartPayload.addMultipartPayload(contentDisposition, contentType, payload); + oldMultipartPayload.addMultipartPayload(contentDisposition, contentType, payload); } + public MultipartPayload getMultipartPayload() { + return multipartPayload; + } + + /** + * @param contentDisposition contentDisposition + * @param contentType contentType + * @param payload payload + * @deprecated use {@link #setFileByteArrayBodyPartPayloadInMultipartPayload(java.lang.String, byte[], + * java.lang.String, java.lang.String)} + */ + @Deprecated public void setMultipartPayload(String contentDisposition, String contentType, byte[] payload) { setMultipartPayload(null, contentDisposition, contentType, payload); } + /** + * @param boundary boundary + * @param contentDisposition contentDisposition + * @param contentType contentType + * @param payload payload + * @deprecated use {@link #initMultipartPayload(java.lang.String) } + * and then {@link #setFileByteArrayBodyPartPayloadInMultipartPayload(java.lang.String, byte[], java.lang.String, + * java.lang.String)} + */ + @Deprecated public void setMultipartPayload(String boundary, String contentDisposition, String contentType, byte[] payload) { initMultipartBoundary(boundary); - multipartPayload.addMultipartPayload(contentDisposition, contentType, payload); + oldMultipartPayload.addMultipartPayload(contentDisposition, contentType, payload); + } + + public void setMultipartPayload(MultipartPayload multipartPayload) { + this.multipartPayload = multipartPayload; + } + + public void initMultipartPayload() { + this.multipartPayload = new MultipartPayload(); + } + + public void initMultipartPayload(String boundary) { + this.multipartPayload = new MultipartPayload(boundary); + } + + public void initMultipartPayload(String subtype, String boundary) { + this.multipartPayload = new MultipartPayload(subtype, boundary); + } + + public void initMultipartPayload(Map headers) { + this.multipartPayload = new MultipartPayload(headers); + } + + public void initMultipartPayload(String boundary, Map headers) { + this.multipartPayload = new MultipartPayload(boundary, headers); + } + + public void initMultipartPayload(String subtype, String boundary, Map headers) { + this.multipartPayload = new MultipartPayload(subtype, boundary, headers); + } + + public void setByteArrayBodyPartPayloadInMultipartPayload(byte[] bodyPartPayload) { + initMultipartPayload(); + addByteArrayBodyPartPayloadInMultipartPayload(bodyPartPayload); + } + + public void setByteArrayBodyPartPayloadInMultipartPayload(byte[] bodyPartPayload, String contentType) { + initMultipartPayload(); + addByteArrayBodyPartPayloadInMultipartPayload(bodyPartPayload, contentType); + } + + public void setByteArrayBodyPartPayloadInMultipartPayload(byte[] bodyPartPayload, Map headers) { + initMultipartPayload(); + addByteArrayBodyPartPayloadInMultipartPayload(bodyPartPayload, headers); + } + + public void addByteArrayBodyPartPayloadInMultipartPayload(byte[] bodyPartPayload) { + multipartPayload.addBodyPart(bodyPartPayload); + } + + public void addByteArrayBodyPartPayloadInMultipartPayload(byte[] bodyPartPayload, String contentType) { + multipartPayload.addBodyPart(bodyPartPayload, contentType); + } + + public void addByteArrayBodyPartPayloadInMultipartPayload(byte[] bodyPartPayload, Map headers) { + multipartPayload.addBodyPart(bodyPartPayload, headers); + } + + public void setFileByteArrayBodyPartPayloadInMultipartPayload(byte[] fileContent) { + initMultipartPayload(); + addFileByteArrayBodyPartPayloadInMultipartPayload(fileContent); + } + + public void setFileByteArrayBodyPartPayloadInMultipartPayload(String contentType, byte[] fileContent) { + initMultipartPayload(); + addFileByteArrayBodyPartPayloadInMultipartPayload(contentType, fileContent); + } + + public void setFileByteArrayBodyPartPayloadInMultipartPayload(byte[] fileContent, String name) { + initMultipartPayload(); + addFileByteArrayBodyPartPayloadInMultipartPayload(fileContent, name); + } + + public void setFileByteArrayBodyPartPayloadInMultipartPayload(String contentType, byte[] fileContent, String name) { + initMultipartPayload(); + addFileByteArrayBodyPartPayloadInMultipartPayload(contentType, fileContent, name); + } + + public void setFileByteArrayBodyPartPayloadInMultipartPayload(byte[] fileContent, String name, String filename) { + initMultipartPayload(); + addFileByteArrayBodyPartPayloadInMultipartPayload(fileContent, name, filename); + } + + public void setFileByteArrayBodyPartPayloadInMultipartPayload(String contentType, byte[] fileContent, String name, + String filename) { + initMultipartPayload(); + addFileByteArrayBodyPartPayloadInMultipartPayload(contentType, fileContent, name, filename); + } + + public void setFileByteArrayBodyPartPayloadInMultipartPayload( + FileByteArrayBodyPartPayload fileByteArrayBodyPartPayload) { + initMultipartPayload(); + addFileByteArrayBodyPartPayloadInMultipartPayload(fileByteArrayBodyPartPayload); + } + + public void addFileByteArrayBodyPartPayloadInMultipartPayload(byte[] fileContent) { + multipartPayload.addFileBodyPart(fileContent); + } + + public void addFileByteArrayBodyPartPayloadInMultipartPayload(String contentType, byte[] fileContent) { + multipartPayload.addFileBodyPart(contentType, fileContent); + } + + public void addFileByteArrayBodyPartPayloadInMultipartPayload(byte[] fileContent, String name) { + multipartPayload.addFileBodyPart(fileContent, name); + } + + public void addFileByteArrayBodyPartPayloadInMultipartPayload(String contentType, byte[] fileContent, String name) { + multipartPayload.addFileBodyPart(contentType, fileContent, name); + } + + public void addFileByteArrayBodyPartPayloadInMultipartPayload(byte[] fileContent, String name, String filename) { + multipartPayload.addFileBodyPart(fileContent, name, filename); + } + + public void addFileByteArrayBodyPartPayloadInMultipartPayload(String contentType, byte[] fileContent, String name, + String filename) { + multipartPayload.addFileBodyPart(contentType, fileContent, name, filename); + } + + public void addFileByteArrayBodyPartPayloadInMultipartPayload( + FileByteArrayBodyPartPayload fileByteArrayBodyPartPayload) { + multipartPayload.addBodyPart(fileByteArrayBodyPartPayload); } /** @@ -202,6 +351,7 @@ private void resetPayload() { stringPayload = null; byteArrayPayload = null; filePayload = null; + oldMultipartPayload = null; multipartPayload = null; } @@ -281,8 +431,13 @@ public byte[] getByteArrayPayload() { } } - public MultipartPayload getMultipartPayloads() { - return multipartPayload; + /** + * @return return + * @deprecated use {@link #getMultipartPayload() } + */ + @Deprecated + public com.github.scribejava.core.httpclient.MultipartPayload getMultipartPayloads() { + return oldMultipartPayload; } public File getFilePayload() { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java index 9f331a4ba..94aaa4c38 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java @@ -110,6 +110,9 @@ public Response execute(OAuthRequest request) throws InterruptedException, Execu } else if (request.getStringPayload() != null) { return httpClient.execute(userAgent, request.getHeaders(), request.getVerb(), request.getCompleteUrl(), request.getStringPayload()); + } else if (request.getMultipartPayload() != null) { + return httpClient.execute(userAgent, request.getHeaders(), request.getVerb(), request.getCompleteUrl(), + request.getMultipartPayload()); } else if (request.getMultipartPayloads() != null) { return httpClient.execute(userAgent, request.getHeaders(), request.getVerb(), request.getCompleteUrl(), request.getMultipartPayloads()); diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClientTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClientTest.java index 6ac1070fa..79a4a23f0 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClientTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClientTest.java @@ -2,6 +2,15 @@ import com.github.scribejava.core.AbstractClientTest; import com.github.scribejava.core.httpclient.HttpClient; +import com.github.scribejava.core.httpclient.multipart.ByteArrayBodyPartPayload; +import com.github.scribejava.core.httpclient.multipart.FileByteArrayBodyPartPayload; +import com.github.scribejava.core.httpclient.multipart.MultipartPayload; +import java.io.IOException; +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.Map; +import org.junit.Assert; +import org.junit.Test; public class JDKHttpClientTest extends AbstractClientTest { @@ -9,4 +18,263 @@ public class JDKHttpClientTest extends AbstractClientTest { protected HttpClient createNewClient() { return new JDKHttpClient(); } + + @Test + public void testEmptyMultipartPayload() throws IOException { + final MultipartPayload mP = new MultipartPayload(); + + final StringBuilder sb = new StringBuilder(); + for (Map.Entry header : mP.getHeaders().entrySet()) { + sb.append(header.getKey()) + .append(": ") + .append(header.getValue()) + .append("\r\n"); + } + + sb.append("\r\n").append(JDKHttpClient.getPayload(mP).toString()); + Assert.assertEquals("Content-Type: multipart/form-data; boundary=\"" + mP.getBoundary() + "\"\r\n\r\n", + sb.toString()); + } + + @Test + public void testSimpleMultipartPayload() throws IOException { + final Map headers = new LinkedHashMap<>(); + headers.put("X-Header", "X-Value"); + headers.put("Content-Disposition", "Content-Disposition-Value"); + final MultipartPayload mP = new MultipartPayload("mixed", "simple boundary", headers); + mP.setPreamble("This is the preamble. It is to be ignored, though it\n" + + "is a handy place for composition agents to include an\n" + + "explanatory note to non-MIME conformant readers."); + + mP.addBodyPart(("This is implicitly typed plain US-ASCII text.\n" + + "It does NOT end with a linebreak.").getBytes()); + + final ByteArrayBodyPartPayload bP = new ByteArrayBodyPartPayload( + ("This is explicitly typed plain US-ASCII text.\n" + + "It DOES end with a linebreak.\n").getBytes(), + Collections.singletonMap(HttpClient.CONTENT_TYPE, "text/plain; charset=us-ascii")); + mP.addBodyPart(bP); + + mP.setEpilogue("This is the epilogue. It is also to be ignored."); + + final StringBuilder sb = new StringBuilder(); + for (Map.Entry header : mP.getHeaders().entrySet()) { + sb.append(header.getKey()) + .append(": ") + .append(header.getValue()) + .append("\r\n"); + } + sb.append("\r\n").append(JDKHttpClient.getPayload(mP).toString()); + Assert.assertEquals("X-Header: X-Value\r\n" + + "Content-Disposition: Content-Disposition-Value\r\n" + + "Content-Type: multipart/mixed; boundary=\"simple boundary\"\r\n" + + "\r\n" + + "This is the preamble. It is to be ignored, though it\n" + + "is a handy place for composition agents to include an\n" + + "explanatory note to non-MIME conformant readers." + + "\r\n" + + "--simple boundary\r\n" + + "\r\n" + + "This is implicitly typed plain US-ASCII text.\n" + + "It does NOT end with a linebreak." + + "\r\n" + + "--simple boundary\r\n" + + "Content-Type: text/plain; charset=us-ascii\r\n" + + "\r\n" + + "This is explicitly typed plain US-ASCII text.\n" + + "It DOES end with a linebreak.\n" + + "\r\n" + + "--simple boundary--\r\n" + + "This is the epilogue. It is also to be ignored.\r\n", + sb.toString()); + } + + @Test + public void testCRLFMultipartPayload() throws IOException { + final MultipartPayload mP = new MultipartPayload("simple-boundary"); + mP.addBodyPart("It does NOT end with a linebreak.".getBytes()); + mP.addBodyPart("It does end with a \\r linebreak.\r".getBytes()); + mP.addBodyPart("It does end with a \\n linebreak.\n".getBytes()); + mP.addBodyPart("It does end with a \\r\\n linebreak.\r\n".getBytes()); + mP.addBodyPart("the last one".getBytes()); + + final StringBuilder sb = new StringBuilder(); + for (Map.Entry header : mP.getHeaders().entrySet()) { + sb.append(header.getKey()) + .append(": ") + .append(header.getValue()) + .append("\r\n"); + } + sb.append("\r\n").append(JDKHttpClient.getPayload(mP).toString()); + Assert.assertEquals("Content-Type: multipart/form-data; boundary=\"simple-boundary\"\r\n" + + "\r\n" + + "\r\n" + + "--simple-boundary\r\n" + + "\r\n" + + "It does NOT end with a linebreak." + + "\r\n" + + "--simple-boundary\r\n" + + "\r\n" + + "It does end with a \\r linebreak.\r" + + "\r\n" + + "--simple-boundary\r\n" + + "\r\n" + + "It does end with a \\n linebreak.\n" + + "\r\n" + + "--simple-boundary\r\n" + + "\r\n" + + "It does end with a \\r\\n linebreak.\r\n" + + "\r\n" + + "--simple-boundary\r\n" + + "\r\n" + + "the last one" + + "\r\n" + + "--simple-boundary--\r\n", + sb.toString()); + } + + @Test + public void testFileByteArrayBodyPartPayloadMultipartPayload() throws IOException { + final MultipartPayload mP = new MultipartPayload("testFileByteArrayBodyPartPayloadMultipartPayload boundary"); + mP.addBodyPart(new FileByteArrayBodyPartPayload("fileContent".getBytes(), "name", "filename.ext")); + + final StringBuilder sb = new StringBuilder(); + for (Map.Entry header : mP.getHeaders().entrySet()) { + sb.append(header.getKey()) + .append(": ") + .append(header.getValue()) + .append("\r\n"); + } + + sb.append("\r\n").append(JDKHttpClient.getPayload(mP).toString()); + Assert.assertEquals("Content-Type: multipart/form-data; " + + "boundary=\"testFileByteArrayBodyPartPayloadMultipartPayload boundary\"\r\n" + + "\r\n" + + "\r\n" + + "--testFileByteArrayBodyPartPayloadMultipartPayload boundary\r\n" + + "Content-Disposition: form-data; name=\"name\"; filename=\"filename.ext\"\r\n" + + "\r\n" + + "fileContent" + + "\r\n" + + "--testFileByteArrayBodyPartPayloadMultipartPayload boundary--\r\n", + sb.toString() + ); + } + + @Test + public void testComplexMultipartPayload() throws IOException { + final MultipartPayload mP = new MultipartPayload("mixed", "unique-boundary-1"); + + mP.setPreamble("This is the preamble area of a multipart message.\n" + + "Mail readers that understand multipart format\n" + + "should ignore this preamble.\n" + + "\n" + + "If you are reading this text, you might want to\n" + + "consider changing to a mail reader that understands\n" + + "how to properly display multipart messages.\n"); + + mP.addBodyPart("... Some text appears here ...".getBytes()); + + mP.addBodyPart(("This could have been part of the previous part, but\n" + + "illustrates explicit versus implicit typing of body\n" + + "parts.\n").getBytes(), "text/plain; charset=US-ASCII"); + + final MultipartPayload innerMP = new MultipartPayload("parallel", "unique-boundary-2"); + mP.addBodyPart(innerMP); + + final Map audioHeaders = new LinkedHashMap<>(); + audioHeaders.put("Content-Type", "audio/basic"); + audioHeaders.put("Content-Transfer-Encoding", "base64"); + innerMP.addBodyPart(("... base64-encoded 8000 Hz single-channel\n" + + " mu-law-format audio data goes here ...").getBytes(), audioHeaders); + + final Map imageHeaders = new LinkedHashMap<>(); + imageHeaders.put("Content-Type", "image/jpeg"); + imageHeaders.put("Content-Transfer-Encoding", "base64"); + innerMP.addBodyPart("... base64-encoded image data goes here ...".getBytes(), imageHeaders); + + mP.addBodyPart(("This is enriched.\n" + + "as defined in RFC 1896\n" + + "\n" + + "Isn't it\n" + + "cool?\n").getBytes(), "text/enriched"); + + mP.addBodyPart(("From: (mailbox in US-ASCII)\n" + + "To: (address in US-ASCII)\n" + + "Subject: (subject in US-ASCII)\n" + + "Content-Type: Text/plain; charset=ISO-8859-1\n" + + "Content-Transfer-Encoding: Quoted-printable\n" + + "\n" + + "... Additional text in ISO-8859-1 goes here ...\n").getBytes(), "message/rfc822"); + + final StringBuilder sb = new StringBuilder(); + for (Map.Entry header : mP.getHeaders().entrySet()) { + sb.append(header.getKey()) + .append(": ") + .append(header.getValue()) + .append("\r\n"); + } + sb.append("\r\n").append(JDKHttpClient.getPayload(mP).toString()); + Assert.assertEquals("Content-Type: multipart/mixed; boundary=\"unique-boundary-1\"\r\n" + + "\r\n" + + "This is the preamble area of a multipart message.\n" + + "Mail readers that understand multipart format\n" + + "should ignore this preamble.\n" + + "\n" + + "If you are reading this text, you might want to\n" + + "consider changing to a mail reader that understands\n" + + "how to properly display multipart messages.\n" + + "\r\n" + + "--unique-boundary-1\r\n" + + "\r\n" + + "... Some text appears here ..." + + "\r\n" + + "--unique-boundary-1\r\n" + + "Content-Type: text/plain; charset=US-ASCII\r\n" + + "\r\n" + + "This could have been part of the previous part, but\n" + + "illustrates explicit versus implicit typing of body\n" + + "parts.\n" + + "\r\n" + + "--unique-boundary-1\r\n" + + "Content-Type: multipart/parallel; boundary=\"unique-boundary-2\"\r\n" + + "\r\n" + + "--unique-boundary-2\r\n" + + "Content-Type: audio/basic\r\n" + + "Content-Transfer-Encoding: base64\r\n" + + "\r\n" + + "... base64-encoded 8000 Hz single-channel\n" + + " mu-law-format audio data goes here ..." + + "\r\n" + + "--unique-boundary-2\r\n" + + "Content-Type: image/jpeg\r\n" + + "Content-Transfer-Encoding: base64\r\n" + + "\r\n" + + "... base64-encoded image data goes here ..." + + "\r\n" + + "--unique-boundary-2--\r\n" + + "\r\n" + + "--unique-boundary-1\r\n" + + "Content-Type: text/enriched\r\n" + + "\r\n" + + "This is enriched.\n" + + "as defined in RFC 1896\n" + + "\n" + + "Isn't it\n" + + "cool?\n" + + "\r\n" + + "--unique-boundary-1\r\n" + + "Content-Type: message/rfc822\r\n" + + "\r\n" + + "From: (mailbox in US-ASCII)\n" + + "To: (address in US-ASCII)\n" + + "Subject: (subject in US-ASCII)\n" + + "Content-Type: Text/plain; charset=ISO-8859-1\n" + + "Content-Transfer-Encoding: Quoted-printable\n" + + "\n" + + "... Additional text in ISO-8859-1 goes here ...\n" + + "\r\n" + + "--unique-boundary-1--\r\n", + sb.toString()); + } } diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/httpclient/multipart/MultipartPayloadTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/httpclient/multipart/MultipartPayloadTest.java new file mode 100644 index 000000000..a7989a01e --- /dev/null +++ b/scribejava-core/src/test/java/com/github/scribejava/core/httpclient/multipart/MultipartPayloadTest.java @@ -0,0 +1,121 @@ +package com.github.scribejava.core.httpclient.multipart; + +import org.hamcrest.core.StringStartsWith; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; + +public class MultipartPayloadTest { + + @Rule + public ExpectedException thrown = ExpectedException.none(); + + @Test + public void testValidCheckBoundarySyntax() { + MultipartPayload.checkBoundarySyntax("0aA'()+_,-./:=?"); + MultipartPayload.checkBoundarySyntax("0aA'()+_,- ./:=?"); + MultipartPayload.checkBoundarySyntax(" 0aA'()+_,-./:=?"); + MultipartPayload.checkBoundarySyntax("1234567890123456789012345678901234567890123456789012345678901234567890"); + } + + @Test + public void testNonValidLastWhiteSpaceCheckBoundarySyntax() { + final String boundary = "0aA'()+_,-./:=? "; + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage( + StringStartsWith.startsWith("{'boundary'='" + boundary + "'} has invaid syntax. Should be '")); + MultipartPayload.checkBoundarySyntax(boundary); + } + + @Test + public void testNonValidEmptyCheckBoundarySyntax() { + final String boundary = ""; + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage( + StringStartsWith.startsWith("{'boundary'='" + boundary + "'} has invaid syntax. Should be '")); + MultipartPayload.checkBoundarySyntax(boundary); + } + + @Test + public void testNonValidIllegalSymbolCheckBoundarySyntax() { + final String boundary = "0aA'()+_;,-./:=? "; + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage( + StringStartsWith.startsWith("{'boundary'='" + boundary + "'} has invaid syntax. Should be '")); + MultipartPayload.checkBoundarySyntax(boundary); + } + + @Test + public void testNonValidTooLongCheckBoundarySyntax() { + final String boundary = "12345678901234567890123456789012345678901234567890123456789012345678901"; + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage( + StringStartsWith.startsWith("{'boundary'='" + boundary + "'} has invaid syntax. Should be '")); + MultipartPayload.checkBoundarySyntax(boundary); + } + + @Test + public void testNonValidNullCheckBoundarySyntax() { + final String boundary = null; + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage( + StringStartsWith.startsWith("{'boundary'='" + boundary + "'} has invaid syntax. Should be '")); + MultipartPayload.checkBoundarySyntax(boundary); + } + + @Test + public void testParseBoundaryFromHeader() { + assertNull(MultipartPayload.parseBoundaryFromHeader(null)); + + assertEquals("0aA'()+_,-./:=?", + MultipartPayload.parseBoundaryFromHeader("multipart/subtype; boundary=\"0aA'()+_,-./:=?\"")); + + assertEquals("0aA'()+_, -./:=?", + MultipartPayload.parseBoundaryFromHeader("multipart/subtype; boundary=\"0aA'()+_, -./:=?\"")); + + assertEquals("0aA'()+_, -./:=?", + MultipartPayload.parseBoundaryFromHeader("multipart/subtype; boundary=\"0aA'()+_, -./:=? \"")); + + assertEquals("0aA'()+_,-./:=?", + MultipartPayload.parseBoundaryFromHeader("multipart/subtype; boundary=0aA'()+_,-./:=?")); + + assertEquals("0aA'()+_, -./:=?", + MultipartPayload.parseBoundaryFromHeader("multipart/subtype; boundary=0aA'()+_, -./:=?")); + + assertEquals("0aA'()+_, -./:=?", + MultipartPayload.parseBoundaryFromHeader("multipart/subtype; boundary=0aA'()+_, -./:=? ")); + + assertEquals(" 0aA'()+_, -./:=?", + MultipartPayload.parseBoundaryFromHeader("multipart/subtype; boundary= 0aA'()+_, -./:=?")); + + assertNull(MultipartPayload.parseBoundaryFromHeader("multipart/subtype; boundar=0aA'()+_, -./:=? ")); + assertNull(MultipartPayload.parseBoundaryFromHeader("multipart/subtype; ")); + assertNull(MultipartPayload.parseBoundaryFromHeader("multipart/subtype;")); + assertNull(MultipartPayload.parseBoundaryFromHeader("multipart/subtype")); + assertNull(MultipartPayload.parseBoundaryFromHeader("multipart/subtype; boundary=")); + + assertEquals("0aA'()+_,", + MultipartPayload.parseBoundaryFromHeader("multipart/subtype; boundary=0aA'()+_,; -./:=? ")); + + assertEquals("0aA'()+_, -./:=?", + MultipartPayload.parseBoundaryFromHeader("multipart/subtype; boundary=\"0aA'()+_, -./:=?")); + + assertEquals("0aA'()+_, -./:=?", + MultipartPayload.parseBoundaryFromHeader("multipart/subtype; boundary=0aA'()+_, -./:=?\"")); + + assertEquals("1234567890123456789012345678901234567890123456789012345678901234567890", + MultipartPayload.parseBoundaryFromHeader("multipart/subtype; " + + "boundary=1234567890123456789012345678901234567890123456789012345678901234567890")); + + assertEquals("1234567890123456789012345678901234567890123456789012345678901234567890", + MultipartPayload.parseBoundaryFromHeader("multipart/subtype; " + + "boundary=12345678901234567890123456789012345678901234567890123456789012345678901")); + + assertNull(MultipartPayload.parseBoundaryFromHeader("multipart/subtype; boundary=")); + assertNull(MultipartPayload.parseBoundaryFromHeader("multipart/subtype; boundary=\"\"")); + assertNull(MultipartPayload.parseBoundaryFromHeader("multipart/subtype; boundary=;123")); + assertNull(MultipartPayload.parseBoundaryFromHeader("multipart/subtype; boundary=\"\"123")); + } +} diff --git a/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/AhcHttpClient.java b/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/AhcHttpClient.java index ebe551571..877d1e1f2 100644 --- a/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/AhcHttpClient.java +++ b/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/AhcHttpClient.java @@ -1,7 +1,7 @@ package com.github.scribejava.httpclient.ahc; import com.github.scribejava.core.httpclient.AbstractAsyncOnlyHttpClient; -import com.github.scribejava.core.httpclient.MultipartPayload; +import com.github.scribejava.core.httpclient.multipart.MultipartPayload; import com.github.scribejava.core.java8.Consumer; import com.github.scribejava.core.model.OAuthAsyncRequestCallback; import com.github.scribejava.core.model.OAuthConstants; @@ -48,6 +48,18 @@ public Future executeAsync(String userAgent, Map headers, converter); } + /** + * @deprecated {@inheritDoc} + */ + @Override + @Deprecated + public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, + com.github.scribejava.core.httpclient.MultipartPayload bodyContents, OAuthAsyncRequestCallback callback, + OAuthRequest.ResponseConverter converter) { + + throw new UnsupportedOperationException("AhcHttpClient does not support MultipartPayload yet."); + } + @Override public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, MultipartPayload bodyContents, OAuthAsyncRequestCallback callback, diff --git a/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/ApacheHttpClient.java b/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/ApacheHttpClient.java index dc5a3607b..168376604 100644 --- a/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/ApacheHttpClient.java +++ b/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/ApacheHttpClient.java @@ -1,7 +1,7 @@ package com.github.scribejava.httpclient.apache; import com.github.scribejava.core.httpclient.AbstractAsyncOnlyHttpClient; -import com.github.scribejava.core.httpclient.MultipartPayload; +import com.github.scribejava.core.httpclient.multipart.MultipartPayload; import com.github.scribejava.core.model.OAuthAsyncRequestCallback; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.OAuthRequest; @@ -54,6 +54,18 @@ public Future executeAsync(String userAgent, Map headers, return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, entity, callback, converter); } + /** + * @deprecated {@inheritDoc} + */ + @Override + @Deprecated + public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, + com.github.scribejava.core.httpclient.MultipartPayload bodyContents, OAuthAsyncRequestCallback callback, + OAuthRequest.ResponseConverter converter) { + + throw new UnsupportedOperationException("ApacheHttpClient does not support MultipartPayload yet."); + } + @Override public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, MultipartPayload bodyContents, OAuthAsyncRequestCallback callback, diff --git a/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/NingHttpClient.java b/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/NingHttpClient.java index 4463ea9e1..6b065a4db 100644 --- a/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/NingHttpClient.java +++ b/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/NingHttpClient.java @@ -1,7 +1,7 @@ package com.github.scribejava.httpclient.ning; import com.github.scribejava.core.httpclient.AbstractAsyncOnlyHttpClient; -import com.github.scribejava.core.httpclient.MultipartPayload; +import com.github.scribejava.core.httpclient.multipart.MultipartPayload; import com.github.scribejava.core.java8.Consumer; import com.github.scribejava.core.model.OAuthAsyncRequestCallback; import com.github.scribejava.core.model.OAuthConstants; @@ -54,6 +54,18 @@ public Future executeAsync(String userAgent, Map headers, converter); } + /** + * @deprecated {@inheritDoc} + */ + @Override + @Deprecated + public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, + com.github.scribejava.core.httpclient.MultipartPayload bodyContents, OAuthAsyncRequestCallback callback, + OAuthRequest.ResponseConverter converter) { + + throw new UnsupportedOperationException("NingHttpClient does not support MultipartPayload yet."); + } + @Override public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, MultipartPayload bodyContents, OAuthAsyncRequestCallback callback, diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 701ba6109..956c762da 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -23,7 +23,7 @@ com.squareup.okhttp3 okhttp - 3.12.0 + 3.12.1 com.github.scribejava diff --git a/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java b/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java index 8436f11ed..18ae14b13 100644 --- a/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java +++ b/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java @@ -1,7 +1,7 @@ package com.github.scribejava.httpclient.okhttp; import com.github.scribejava.core.httpclient.HttpClient; -import com.github.scribejava.core.httpclient.MultipartPayload; +import com.github.scribejava.core.httpclient.multipart.MultipartPayload; import com.github.scribejava.core.model.OAuthAsyncRequestCallback; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.OAuthRequest; @@ -60,6 +60,18 @@ public Future executeAsync(String userAgent, Map headers, converter); } + /** + * @deprecated {@inheritDoc} + */ + @Override + @Deprecated + public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, + com.github.scribejava.core.httpclient.MultipartPayload bodyContents, OAuthAsyncRequestCallback callback, + OAuthRequest.ResponseConverter converter) { + + throw new UnsupportedOperationException("OKHttpClient does not support Multipart payload for the moment"); + } + @Override public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, MultipartPayload bodyContents, OAuthAsyncRequestCallback callback, @@ -107,6 +119,18 @@ public Response execute(String userAgent, Map headers, Verb http throw new UnsupportedOperationException("OKHttpClient does not support Multipart payload for the moment"); } + /** + * @deprecated {@inheritDoc} + */ + @Override + @Deprecated + public Response execute(String userAgent, Map headers, Verb httpVerb, String completeUrl, + com.github.scribejava.core.httpclient.MultipartPayload bodyContents) + throws InterruptedException, ExecutionException, IOException { + + throw new UnsupportedOperationException("OKHttpClient does not support Multipart payload for the moment"); + } + @Override public Response execute(String userAgent, Map headers, Verb httpVerb, String completeUrl, String bodyContents) throws InterruptedException, ExecutionException, IOException { From 6ccc5f4bcad5b6c7dbbabee252025ba60fc2c23a Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 6 Feb 2019 15:19:30 +0300 Subject: [PATCH 553/882] update deps --- pom.xml | 4 ++-- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 4 ++-- scribejava-httpclient-okhttp/pom.xml | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pom.xml b/pom.xml index 1fac89595..c1d6db3fb 100644 --- a/pom.xml +++ b/pom.xml @@ -68,7 +68,7 @@ com.squareup.okhttp3 mockwebserver - 3.12.1 + 3.13.1 test @@ -107,7 +107,7 @@ com.puppycrawl.tools checkstyle - 8.16 + 8.17 diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 46e58e129..5b7c743f2 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -23,7 +23,7 @@ org.asynchttpclient async-http-client - 2.6.0 + 2.7.0 com.github.scribejava diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index 5b6ffd268..3c59ef366 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -8,7 +8,7 @@ 6.2.1-SNAPSHOT ../pom.xml - + com.github.scribejava scribejava-httpclient-apache ScribeJava Apache HttpComponents HttpClient support @@ -23,7 +23,7 @@ org.apache.httpcomponents httpclient - 4.5.6 + 4.5.7 org.apache.httpcomponents diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 956c762da..0c2ed23f1 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -23,7 +23,7 @@ com.squareup.okhttp3 okhttp - 3.12.1 + 3.13.1 com.github.scribejava From 584080faf09ecf801568e77285e8e821ac0a0179 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 6 Feb 2019 15:45:11 +0300 Subject: [PATCH 554/882] remove any Google+ mention (switch to clean Google OAuth2) (thanks to https://github.com/fvasco) --- changelog | 1 + .../scribejava/apis/examples/Google20AsyncAHCExample.java | 4 ++-- .../com/github/scribejava/apis/examples/Google20Example.java | 4 ++-- .../scribejava/apis/examples/Google20RevokeExample.java | 4 ++-- .../scribejava/apis/examples/Google20WithPKCEExample.java | 4 ++-- 5 files changed, 9 insertions(+), 8 deletions(-) diff --git a/changelog b/changelog index fa676453f..2f417fc56 100644 --- a/changelog +++ b/changelog @@ -1,5 +1,6 @@ [SNAPSHOT] * fix Muplipart request model and implement it for a jdk HTTP client (thanks to https://github.com/NTPape) + * remove any Google+ mention (switch to clean Google OAuth2) (thanks to https://github.com/fvasco) [6.2.0] * add new API Microsoft Azure Active Directory (Azure AD) 2.0 (thanks to https://github.com/rzukow and https://github.com/dgrudenic) diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java index d815edce3..d2d8260df 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java @@ -19,8 +19,8 @@ public class Google20AsyncAHCExample { - private static final String NETWORK_NAME = "G+ Async"; - private static final String PROTECTED_RESOURCE_URL = "https://www.googleapis.com/plus/v1/people/me"; + private static final String NETWORK_NAME = "Google Async"; + private static final String PROTECTED_RESOURCE_URL = "https://www.googleapis.com/oauth2/v3/userinfo"; private Google20AsyncAHCExample() { } diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java index 0cce9f250..8fe8a37d1 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java @@ -16,8 +16,8 @@ public class Google20Example { - private static final String NETWORK_NAME = "G+"; - private static final String PROTECTED_RESOURCE_URL = "https://www.googleapis.com/plus/v1/people/me"; + private static final String NETWORK_NAME = "Google"; + private static final String PROTECTED_RESOURCE_URL = "https://www.googleapis.com/oauth2/v3/userinfo"; private Google20Example() { } diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20RevokeExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20RevokeExample.java index f65b07c39..61f44501e 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20RevokeExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20RevokeExample.java @@ -16,8 +16,8 @@ public class Google20RevokeExample { - private static final String NETWORK_NAME = "G+"; - private static final String PROTECTED_RESOURCE_URL = "https://www.googleapis.com/plus/v1/people/me"; + private static final String NETWORK_NAME = "Google"; + private static final String PROTECTED_RESOURCE_URL = "https://www.googleapis.com/oauth2/v3/userinfo"; private Google20RevokeExample() { } diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20WithPKCEExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20WithPKCEExample.java index 54a359291..6c8b3a66a 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20WithPKCEExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20WithPKCEExample.java @@ -17,8 +17,8 @@ public class Google20WithPKCEExample { - private static final String NETWORK_NAME = "G+"; - private static final String PROTECTED_RESOURCE_URL = "https://www.googleapis.com/plus/v1/people/me"; + private static final String NETWORK_NAME = "Google"; + private static final String PROTECTED_RESOURCE_URL = "https://www.googleapis.com/oauth2/v3/userinfo"; private Google20WithPKCEExample() { } From 7042b4c9c078abeca668a27bc25c0d5c03795e64 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 6 Feb 2019 16:25:22 +0300 Subject: [PATCH 555/882] add links to RFCs in the Readme and info about refreshing token support --- README.md | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 9d8162a93..5d782bdf7 100644 --- a/README.md +++ b/README.md @@ -42,12 +42,13 @@ ScribeJava support out-of-box several HTTP clients: ### Supports many flows and additional features - * RFC 6749 The OAuth 2.0 Authorization Framework, Authorization Code Authorization Grant [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java) - * RFC 6749 The OAuth 2.0 Authorization Framework, Client Credentials Authorization Grant [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteClientCredentialsGrantExample.java) - * RFC 6749 The OAuth 2.0 Authorization Framework, Resource Owner Password Credentials Authorization Grant - * RFC 6750 The OAuth 2.0 Authorization Framework: Bearer Token Usage - * RFC 7636 Proof Key for Code Exchange by OAuth Public Clients (PKCE) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20WithPKCEExample.java) - * RFC 7009 OAuth 2.0 Token Revocation [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20RevokeExample.java) + * [RFC 6749](https://tools.ietf.org/html/rfc6749) The OAuth 2.0 Authorization Framework, [Authorization Code Authorization Grant](https://tools.ietf.org/html/rfc6749#section-4.1) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java) + * [RFC 6749](https://tools.ietf.org/html/rfc6749) The OAuth 2.0 Authorization Framework, [Client Credentials Authorization Grant](https://tools.ietf.org/html/rfc6749#section-4.4) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteClientCredentialsGrantExample.java) + * [RFC 6749](https://tools.ietf.org/html/rfc6749) The OAuth 2.0 Authorization Framework, [Resource Owner Password Credentials Authorization Grant](https://tools.ietf.org/html/rfc6749#section-4.3) + * [RFC 6749](https://tools.ietf.org/html/rfc6749) The OAuth 2.0 Authorization Framework, [Refreshing an Access Token](https://tools.ietf.org/html/rfc6749#section-6) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java#L77) + * [RFC 6750](https://tools.ietf.org/html/rfc6750) The OAuth 2.0 Authorization Framework: Bearer Token Usage + * [RFC 7636](https://tools.ietf.org/html/rfc7636) Proof Key for Code Exchange by OAuth Public Clients (PKCE) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20WithPKCEExample.java) + * [RFC 7009](https://tools.ietf.org/html/rfc7009) OAuth 2.0 Token Revocation [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20RevokeExample.java) ### Supports all major 1.0a and 2.0 OAuth APIs out-of-the-box From ea8e48d610b958759fb3f1866678a13d9e9745a0 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 6 Feb 2019 17:54:02 +0300 Subject: [PATCH 556/882] fix Microsoft Azure AD v1.0 and v2.0 (thanks to https://github.com/kenpusney and https://github.com/oscararias) --- changelog | 1 + .../MicrosoftAzureActiveDirectory20Api.java | 22 +++++++- .../MicrosoftAzureActiveDirectoryApi.java | 35 +++++++++++- .../BaseMicrosoftAzureActiveDirectoryApi.java | 54 +++++-------------- 4 files changed, 69 insertions(+), 43 deletions(-) diff --git a/changelog b/changelog index 2f417fc56..240862f7e 100644 --- a/changelog +++ b/changelog @@ -1,6 +1,7 @@ [SNAPSHOT] * fix Muplipart request model and implement it for a jdk HTTP client (thanks to https://github.com/NTPape) * remove any Google+ mention (switch to clean Google OAuth2) (thanks to https://github.com/fvasco) + * fix Microsoft Azure AD v1.0 and v2.0 (thanks to https://github.com/kenpusney and https://github.com/oscararias) [6.2.0] * add new API Microsoft Azure Active Directory (Azure AD) 2.0 (thanks to https://github.com/rzukow and https://github.com/dgrudenic) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/MicrosoftAzureActiveDirectory20Api.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/MicrosoftAzureActiveDirectory20Api.java index 71b0a005e..399cf54c9 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/MicrosoftAzureActiveDirectory20Api.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/MicrosoftAzureActiveDirectory20Api.java @@ -1,6 +1,8 @@ package com.github.scribejava.apis; import com.github.scribejava.apis.microsoftazureactivedirectory.BaseMicrosoftAzureActiveDirectoryApi; +import com.github.scribejava.apis.microsoftazureactivedirectory.MicrosoftAzureActiveDirectory20BearerSignature; +import com.github.scribejava.core.oauth2.bearersignature.BearerSignature; /** * Microsoft Azure Active Directory Api v 2.0 @@ -14,7 +16,11 @@ public class MicrosoftAzureActiveDirectory20Api extends BaseMicrosoftAzureActiveDirectoryApi { protected MicrosoftAzureActiveDirectory20Api() { - super(MicrosoftAzureActiveDirectoryVersion.V_2_0); + this(COMMON_TENANT); + } + + protected MicrosoftAzureActiveDirectory20Api(String tenant) { + super(tenant); } private static class InstanceHolder { @@ -25,4 +31,18 @@ private static class InstanceHolder { public static MicrosoftAzureActiveDirectory20Api instance() { return InstanceHolder.INSTANCE; } + + public static MicrosoftAzureActiveDirectory20Api custom(String tenant) { + return new MicrosoftAzureActiveDirectory20Api(tenant); + } + + @Override + public BearerSignature getBearerSignature() { + return MicrosoftAzureActiveDirectory20BearerSignature.instance(); + } + + @Override + protected String getEndpointVersionPath() { + return "/v2.0"; + } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/MicrosoftAzureActiveDirectoryApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/MicrosoftAzureActiveDirectoryApi.java index 31250be3f..9ab4aa291 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/MicrosoftAzureActiveDirectoryApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/MicrosoftAzureActiveDirectoryApi.java @@ -1,6 +1,8 @@ package com.github.scribejava.apis; import com.github.scribejava.apis.microsoftazureactivedirectory.BaseMicrosoftAzureActiveDirectoryApi; +import com.github.scribejava.apis.microsoftazureactivedirectory.MicrosoftAzureActiveDirectoryBearerSignature; +import com.github.scribejava.core.oauth2.bearersignature.BearerSignature; /** * Microsoft Azure Active Directory Api @@ -16,8 +18,15 @@ */ public class MicrosoftAzureActiveDirectoryApi extends BaseMicrosoftAzureActiveDirectoryApi { + private final String resource; + protected MicrosoftAzureActiveDirectoryApi() { - super(MicrosoftAzureActiveDirectoryVersion.V_1_0); + this(COMMON_TENANT, null); + } + + protected MicrosoftAzureActiveDirectoryApi(String tenant, String resource) { + super(tenant); + this.resource = resource; } private static class InstanceHolder { @@ -28,4 +37,28 @@ private static class InstanceHolder { public static MicrosoftAzureActiveDirectoryApi instance() { return InstanceHolder.INSTANCE; } + + public static MicrosoftAzureActiveDirectoryApi customTenant(String tenant) { + return new MicrosoftAzureActiveDirectoryApi(tenant, null); + } + + public static MicrosoftAzureActiveDirectoryApi customResource(String resource) { + return new MicrosoftAzureActiveDirectoryApi(COMMON_TENANT, resource); + } + + public static MicrosoftAzureActiveDirectoryApi custom(String tenant, String resource) { + return new MicrosoftAzureActiveDirectoryApi(tenant, resource); + } + + @Override + protected String getAuthorizationBaseUrl() { + final String authorizationBaseUrl = super.getAuthorizationBaseUrl(); + return resource == null || resource.isEmpty() ? authorizationBaseUrl + : authorizationBaseUrl + "?resource=" + resource; + } + + @Override + public BearerSignature getBearerSignature() { + return MicrosoftAzureActiveDirectoryBearerSignature.instance(); + } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/microsoftazureactivedirectory/BaseMicrosoftAzureActiveDirectoryApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/microsoftazureactivedirectory/BaseMicrosoftAzureActiveDirectoryApi.java index bc813e398..4eefb1d6f 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/microsoftazureactivedirectory/BaseMicrosoftAzureActiveDirectoryApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/microsoftazureactivedirectory/BaseMicrosoftAzureActiveDirectoryApi.java @@ -1,38 +1,33 @@ package com.github.scribejava.apis.microsoftazureactivedirectory; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.oauth2.bearersignature.BearerSignature; import com.github.scribejava.core.oauth2.clientauthentication.ClientAuthentication; import com.github.scribejava.core.oauth2.clientauthentication.RequestBodyAuthenticationScheme; public abstract class BaseMicrosoftAzureActiveDirectoryApi extends DefaultApi20 { - private static final String MSFT_LOGIN_URL = "https://login.microsoftonline.com"; - private static final String SLASH = "/"; - private static final String COMMON = "common"; - private static final String TOKEN_URI = "oauth2/token"; - private final String resource; - private final BaseMicrosoftAzureActiveDirectoryBearerSignature bearerSignature; + protected static final String COMMON_TENANT = "common"; - protected BaseMicrosoftAzureActiveDirectoryApi(String resource, - BaseMicrosoftAzureActiveDirectoryBearerSignature bearerSignature) { - this.resource = resource; - this.bearerSignature = bearerSignature; + private static final String MSFT_LOGIN_URL = "https://login.microsoftonline.com/"; + private static final String TOKEN_URI = "/oauth2/token"; + private final String tenant; + + protected BaseMicrosoftAzureActiveDirectoryApi() { + this(COMMON_TENANT); } - protected BaseMicrosoftAzureActiveDirectoryApi(MicrosoftAzureActiveDirectoryVersion version) { - this.resource = version.getResource(); - this.bearerSignature = version.getBearerSignature(); + protected BaseMicrosoftAzureActiveDirectoryApi(String tenant) { + this.tenant = tenant == null || tenant.isEmpty() ? COMMON_TENANT : tenant; } @Override public String getAccessTokenEndpoint() { - return MSFT_LOGIN_URL + SLASH + COMMON + SLASH + TOKEN_URI; + return MSFT_LOGIN_URL + tenant + TOKEN_URI; } @Override protected String getAuthorizationBaseUrl() { - return MSFT_LOGIN_URL + SLASH + COMMON + SLASH + "oauth2/authorize?resource=" + resource; + return MSFT_LOGIN_URL + tenant + getEndpointVersionPath() + "/oauth2/authorize"; } @Override @@ -40,30 +35,7 @@ public ClientAuthentication getClientAuthentication() { return RequestBodyAuthenticationScheme.instance(); } - @Override - public BearerSignature getBearerSignature() { - return bearerSignature; - } - - protected enum MicrosoftAzureActiveDirectoryVersion { - V_1_0("https://graph.windows.net", MicrosoftAzureActiveDirectoryBearerSignature.instance()), - V_2_0("https://graph.microsoft.com", MicrosoftAzureActiveDirectory20BearerSignature.instance()); - - private final String resource; - private final BaseMicrosoftAzureActiveDirectoryBearerSignature bearerSignature; - - MicrosoftAzureActiveDirectoryVersion(String resource, - BaseMicrosoftAzureActiveDirectoryBearerSignature bearerSignature) { - this.resource = resource; - this.bearerSignature = bearerSignature; - } - - protected String getResource() { - return resource; - } - - protected BaseMicrosoftAzureActiveDirectoryBearerSignature getBearerSignature() { - return bearerSignature; - } + protected String getEndpointVersionPath() { + return ""; } } From 1f024918d17e02331dc5a94ca5925a398834629d Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 7 Feb 2019 12:10:52 +0300 Subject: [PATCH 557/882] typo fix for MicrosoftAzureActiveDirectoryApi --- .../BaseMicrosoftAzureActiveDirectoryApi.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/microsoftazureactivedirectory/BaseMicrosoftAzureActiveDirectoryApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/microsoftazureactivedirectory/BaseMicrosoftAzureActiveDirectoryApi.java index 4eefb1d6f..5e4891164 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/microsoftazureactivedirectory/BaseMicrosoftAzureActiveDirectoryApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/microsoftazureactivedirectory/BaseMicrosoftAzureActiveDirectoryApi.java @@ -9,7 +9,7 @@ public abstract class BaseMicrosoftAzureActiveDirectoryApi extends DefaultApi20 protected static final String COMMON_TENANT = "common"; private static final String MSFT_LOGIN_URL = "https://login.microsoftonline.com/"; - private static final String TOKEN_URI = "/oauth2/token"; + private static final String OAUTH_2 = "/oauth2"; private final String tenant; protected BaseMicrosoftAzureActiveDirectoryApi() { @@ -22,12 +22,12 @@ protected BaseMicrosoftAzureActiveDirectoryApi(String tenant) { @Override public String getAccessTokenEndpoint() { - return MSFT_LOGIN_URL + tenant + TOKEN_URI; + return MSFT_LOGIN_URL + tenant + OAUTH_2 + getEndpointVersionPath() + "/token"; } @Override protected String getAuthorizationBaseUrl() { - return MSFT_LOGIN_URL + tenant + getEndpointVersionPath() + "/oauth2/authorize"; + return MSFT_LOGIN_URL + tenant + OAUTH_2 + getEndpointVersionPath() + "/authorize"; } @Override From e2ecdac1b68940513b2004209ee453256fde1279 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 7 Feb 2019 13:51:46 +0300 Subject: [PATCH 558/882] add new API Asana (https://asana.com/) (thanks to https://github.com/joestazak) --- README.md | 2 +- changelog | 1 + .../com/github/scribejava/apis/Asana20.java | 33 ------------------- .../github/scribejava/apis/Asana20Api.java | 27 +++++++++++++++ .../apis/examples/AsanaExample.java | 9 ++--- 5 files changed, 32 insertions(+), 40 deletions(-) delete mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/Asana20.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/Asana20Api.java diff --git a/README.md b/README.md index 5ee83f11c..d8c736e79 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ ScribeJava support out-of-box several HTTP clients: ### Supports all major 1.0a and 2.0 OAuth APIs out-of-the-box -* Asana (https://app.asana.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AsanaExample.java) +* Asana (https://asana.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AsanaExample.java) * Automatic (https://www.automatic.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AutomaticExample.java) * AWeber (http://www.aweber.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AWeberExample.java) * Box (https://www.box.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Box20Example.java) diff --git a/changelog b/changelog index 240862f7e..4918c596b 100644 --- a/changelog +++ b/changelog @@ -2,6 +2,7 @@ * fix Muplipart request model and implement it for a jdk HTTP client (thanks to https://github.com/NTPape) * remove any Google+ mention (switch to clean Google OAuth2) (thanks to https://github.com/fvasco) * fix Microsoft Azure AD v1.0 and v2.0 (thanks to https://github.com/kenpusney and https://github.com/oscararias) + * add new API Asana (https://asana.com/) (thanks to https://github.com/joestazak) [6.2.0] * add new API Microsoft Azure Active Directory (Azure AD) 2.0 (thanks to https://github.com/rzukow and https://github.com/dgrudenic) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/Asana20.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/Asana20.java deleted file mode 100644 index b46151a35..000000000 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/Asana20.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.github.scribejava.apis; - -import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.oauth2.clientauthentication.ClientAuthentication; -import com.github.scribejava.core.oauth2.clientauthentication.RequestBodyAuthenticationScheme; - -public class Asana20 extends DefaultApi20 { - protected Asana20() { - } - - private static class InstanceHolder { - private static final Asana20 INSTANCE = new Asana20(); - } - - public static Asana20 instance() { - return InstanceHolder.INSTANCE; - } - - @Override - public String getAccessTokenEndpoint() { - return "https://app.asana.com/-/oauth_token"; - } - - @Override - protected String getAuthorizationBaseUrl() { - return "https://app.asana.com/-/oauth_authorize"; - } - - @Override - public ClientAuthentication getClientAuthentication() { - return RequestBodyAuthenticationScheme.instance(); - } -} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/Asana20Api.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/Asana20Api.java new file mode 100644 index 000000000..5e769aab8 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/Asana20Api.java @@ -0,0 +1,27 @@ +package com.github.scribejava.apis; + +import com.github.scribejava.core.builder.api.DefaultApi20; + +public class Asana20Api extends DefaultApi20 { + + protected Asana20Api() { + } + + private static class InstanceHolder { + private static final Asana20Api INSTANCE = new Asana20Api(); + } + + public static Asana20Api instance() { + return InstanceHolder.INSTANCE; + } + + @Override + public String getAccessTokenEndpoint() { + return "https://app.asana.com/-/oauth_token"; + } + + @Override + protected String getAuthorizationBaseUrl() { + return "https://app.asana.com/-/oauth_authorize"; + } +} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AsanaExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AsanaExample.java index 9165fc1b8..3907bdc2b 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AsanaExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AsanaExample.java @@ -1,6 +1,6 @@ package com.github.scribejava.apis.examples; -import com.github.scribejava.apis.Asana20; +import com.github.scribejava.apis.Asana20Api; import com.github.scribejava.core.builder.ServiceBuilder; import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthRequest; @@ -9,8 +9,6 @@ import com.github.scribejava.core.oauth.OAuth20Service; import java.io.IOException; -import java.util.HashMap; -import java.util.Map; import java.util.Random; import java.util.Scanner; import java.util.concurrent.ExecutionException; @@ -20,7 +18,6 @@ public class AsanaExample { private static final String PROTECTED_RESOURCE_URL = "https://app.asana.com/api/1.0/users/me"; private AsanaExample() { - } public static void main(String... args) throws IOException, InterruptedException, ExecutionException { @@ -30,7 +27,8 @@ public static void main(String... args) throws IOException, InterruptedException final OAuth20Service service = new ServiceBuilder(apiKey) .apiSecret(apiSecret) .callback("https://localhost/") - .build(Asana20.instance()); + .state(secretState) + .build(Asana20Api.instance()); final Scanner in = new Scanner(System.in); // Obtain Auth URL @@ -81,5 +79,4 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println(); System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); } - } From 872af9aa4919900a94cf6e33774f2e081f15f89f Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 7 Feb 2019 15:49:52 +0300 Subject: [PATCH 559/882] fix MicrosoftAzureActiveDirectory20Example (add MS permission to OAuth2 scope) --- .../apis/examples/MicrosoftAzureActiveDirectory20Example.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureActiveDirectory20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureActiveDirectory20Example.java index c0bd6f88a..9a8ac4f1e 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureActiveDirectory20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureActiveDirectory20Example.java @@ -25,7 +25,7 @@ public static void main(String... args) throws IOException, InterruptedException final String clientSecret = "client secret here"; final OAuth20Service service = new ServiceBuilder(clientId) .apiSecret(clientSecret) - .scope("openid") + .scope("openid User.Read") .callback("http://www.example.com/oauth_callback/") .build(MicrosoftAzureActiveDirectory20Api.instance()); final Scanner in = new Scanner(System.in, "UTF-8"); From 784bb6e1e571482e5fc8854fc1cf1980408554cc Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 8 Feb 2019 14:04:33 +0300 Subject: [PATCH 560/882] state param should be used only for authorization url generation, for v2 only, for Authorization Code Grant only, and it should be set per request, not per created OAuthService --- README.md | 10 +-- changelog | 2 + .../github/scribejava/apis/FacebookApi.java | 23 ++++++ .../com/github/scribejava/apis/ImgurApi.java | 23 ++++++ .../com/github/scribejava/apis/MailruApi.java | 23 ++++++ .../scribejava/apis/OdnoklassnikiApi.java | 23 ++++++ .../github/scribejava/apis/WunderlistAPI.java | 23 ++++++ .../apis/facebook/FacebookService.java | 19 +++++ .../apis/imgur/ImgurOAuthService.java | 19 +++++ .../apis/mailru/MailruOAuthService.java | 19 +++++ .../OdnoklassnikiOAuthService.java | 19 +++++ .../wunderlist/WunderlistOAuthService.java | 19 +++++ .../apis/examples/AsanaExample.java | 3 +- .../apis/examples/AutomaticExample.java | 3 +- .../apis/examples/Box20Example.java | 3 +- .../apis/examples/DataportenExample.java | 3 +- .../apis/examples/DiscordExample.java | 3 +- .../examples/FacebookAsyncApacheExample.java | 3 +- .../examples/FacebookAsyncNingExample.java | 3 +- .../apis/examples/FacebookExample.java | 3 +- .../apis/examples/FitbitApi20Example.java | 3 +- .../apis/examples/GeniusExample.java | 3 +- .../examples/GitHubAsyncOkHttpExample.java | 3 +- .../apis/examples/GitHubExample.java | 3 +- .../examples/Google20AsyncAHCExample.java | 6 +- .../apis/examples/Google20Example.java | 3 +- .../apis/examples/Google20RevokeExample.java | 3 +- .../examples/Google20WithPKCEExample.java | 4 +- .../apis/examples/HiOrgServerExample.java | 3 +- .../apis/examples/LinkedIn20Example.java | 3 +- .../apis/examples/NaverExample.java | 3 +- .../apis/examples/StackExchangeExample.java | 3 +- .../TheThingsNetworkV1StagingExample.java | 3 +- .../TheThingsNetworkV2PreviewExample.java | 3 +- .../apis/examples/WunderlistExample.java | 3 +- .../core/builder/ServiceBuilder.java | 10 ++- .../scribejava/core/builder/api/BaseApi.java | 18 +++++ .../core/builder/api/DefaultApi10a.java | 25 +++++++ .../core/builder/api/DefaultApi20.java | 23 ++++++ .../scribejava/core/oauth/OAuth20Service.java | 73 +++++++++++++++++-- .../scribejava/core/AbstractClientTest.java | 3 +- .../scribejava/core/oauth/OAuth20ApiUnit.java | 6 +- .../core/oauth/OAuth20ServiceTest.java | 2 - .../core/oauth/OAuth20ServiceUnit.java | 4 +- 44 files changed, 388 insertions(+), 71 deletions(-) diff --git a/README.md b/README.md index d8c736e79..360a8411d 100644 --- a/README.md +++ b/README.md @@ -42,13 +42,13 @@ ScribeJava support out-of-box several HTTP clients: ### Supports many flows and additional features - * [RFC 6749](https://tools.ietf.org/html/rfc6749) The OAuth 2.0 Authorization Framework, [Authorization Code Authorization Grant](https://tools.ietf.org/html/rfc6749#section-4.1) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java) - * [RFC 6749](https://tools.ietf.org/html/rfc6749) The OAuth 2.0 Authorization Framework, [Client Credentials Authorization Grant](https://tools.ietf.org/html/rfc6749#section-4.4) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteClientCredentialsGrantExample.java) + * [RFC 6749](https://tools.ietf.org/html/rfc6749) The OAuth 2.0 Authorization Framework, [Authorization Code Authorization Grant](https://tools.ietf.org/html/rfc6749#section-4.1), [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java) * [RFC 6749](https://tools.ietf.org/html/rfc6749) The OAuth 2.0 Authorization Framework, [Resource Owner Password Credentials Authorization Grant](https://tools.ietf.org/html/rfc6749#section-4.3) - * [RFC 6749](https://tools.ietf.org/html/rfc6749) The OAuth 2.0 Authorization Framework, [Refreshing an Access Token](https://tools.ietf.org/html/rfc6749#section-6) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java#L77) + * [RFC 6749](https://tools.ietf.org/html/rfc6749) The OAuth 2.0 Authorization Framework, [Client Credentials Authorization Grant](https://tools.ietf.org/html/rfc6749#section-4.4), [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteClientCredentialsGrantExample.java) + * [RFC 6749](https://tools.ietf.org/html/rfc6749) The OAuth 2.0 Authorization Framework, [Refreshing an Access Token](https://tools.ietf.org/html/rfc6749#section-6), [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java#L77) * [RFC 6750](https://tools.ietf.org/html/rfc6750) The OAuth 2.0 Authorization Framework: Bearer Token Usage - * [RFC 7636](https://tools.ietf.org/html/rfc7636) Proof Key for Code Exchange by OAuth Public Clients (PKCE) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20WithPKCEExample.java) - * [RFC 7009](https://tools.ietf.org/html/rfc7009) OAuth 2.0 Token Revocation [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20RevokeExample.java) + * [RFC 7636](https://tools.ietf.org/html/rfc7636) Proof Key for Code Exchange by OAuth Public Clients (PKCE), [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20WithPKCEExample.java) + * [RFC 7009](https://tools.ietf.org/html/rfc7009) OAuth 2.0 Token Revocation, [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20RevokeExample.java) ### Supports all major 1.0a and 2.0 OAuth APIs out-of-the-box diff --git a/changelog b/changelog index 4918c596b..03ba4e7ad 100644 --- a/changelog +++ b/changelog @@ -3,6 +3,8 @@ * remove any Google+ mention (switch to clean Google OAuth2) (thanks to https://github.com/fvasco) * fix Microsoft Azure AD v1.0 and v2.0 (thanks to https://github.com/kenpusney and https://github.com/oscararias) * add new API Asana (https://asana.com/) (thanks to https://github.com/joestazak) + * state param should be used only for authorization url generation, for v2 only, for Authorization Code Grant only, + and it should be set per request, not per created OAuthService [6.2.0] * add new API Microsoft Azure Active Directory (Azure AD) 2.0 (thanks to https://github.com/rzukow and https://github.com/dgrudenic) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java index 6418d8964..da1acce63 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java @@ -70,6 +70,21 @@ public ClientAuthentication getClientAuthentication() { return RequestBodyAuthenticationScheme.instance(); } + /** + * @param apiKey apiKey + * @param apiSecret apiSecret + * @param callback callback + * @param scope scope + * @param debugStream debugStream + * @param state state + * @param responseType responseType + * @param userAgent userAgent + * @param httpClientConfig httpClientConfig + * @param httpClient httpClient + * @return return + * @deprecated use one of getAuthorizationUrl method in {@link com.github.scribejava.core.oauth.OAuth20Service} + */ + @Deprecated @Override public FacebookService createService(String apiKey, String apiSecret, String callback, String scope, OutputStream debugStream, String state, String responseType, String userAgent, @@ -77,4 +92,12 @@ public FacebookService createService(String apiKey, String apiSecret, String cal return new FacebookService(this, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); } + + @Override + public FacebookService createService(String apiKey, String apiSecret, String callback, String scope, + OutputStream debugStream, String responseType, String userAgent, HttpClientConfig httpClientConfig, + HttpClient httpClient) { + return createService(apiKey, apiSecret, callback, scope, debugStream, null, responseType, userAgent, + httpClientConfig, httpClient); + } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java index f04736880..59d7e3e8d 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java @@ -54,6 +54,21 @@ protected String getAuthorizationBaseUrl() { throw new UnsupportedOperationException("use getAuthorizationUrl instead"); } + /** + * @param apiKey apiKey + * @param apiSecret apiSecret + * @param callback callback + * @param scope scope + * @param debugStream debugStream + * @param state state + * @param responseType responseType + * @param userAgent userAgent + * @param httpClientConfig httpClientConfig + * @param httpClient httpClient + * @return return + * @deprecated use one of getAuthorizationUrl method in {@link com.github.scribejava.core.oauth.OAuth20Service} + */ + @Deprecated @Override public ImgurOAuthService createService(String apiKey, String apiSecret, String callback, String scope, OutputStream debugStream, String state, String responseType, String userAgent, @@ -62,6 +77,14 @@ public ImgurOAuthService createService(String apiKey, String apiSecret, String c httpClientConfig, httpClient); } + @Override + public ImgurOAuthService createService(String apiKey, String apiSecret, String callback, String scope, + OutputStream debugStream, String responseType, String userAgent, HttpClientConfig httpClientConfig, + HttpClient httpClient) { + return createService(apiKey, apiSecret, callback, scope, debugStream, null, responseType, userAgent, + httpClientConfig, httpClient); + } + public static boolean isOob(String callback) { return OAuthConstants.OOB.equals(callback); } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java index 3835fff49..83419dace 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java @@ -29,6 +29,21 @@ protected String getAuthorizationBaseUrl() { return "https://connect.mail.ru/oauth/authorize"; } + /** + * @param apiKey apiKey + * @param apiSecret apiSecret + * @param callback callback + * @param scope scope + * @param debugStream debugStream + * @param state state + * @param responseType responseType + * @param userAgent userAgent + * @param httpClientConfig httpClientConfig + * @param httpClient httpClient + * @return return + * @deprecated use one of getAuthorizationUrl method in {@link com.github.scribejava.core.oauth.OAuth20Service} + */ + @Deprecated @Override public MailruOAuthService createService(String apiKey, String apiSecret, String callback, String scope, OutputStream debugStream, String state, String responseType, String userAgent, @@ -36,4 +51,12 @@ public MailruOAuthService createService(String apiKey, String apiSecret, String return new MailruOAuthService(this, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); } + + @Override + public MailruOAuthService createService(String apiKey, String apiSecret, String callback, String scope, + OutputStream debugStream, String responseType, String userAgent, HttpClientConfig httpClientConfig, + HttpClient httpClient) { + return createService(apiKey, apiSecret, callback, scope, debugStream, null, responseType, userAgent, + httpClientConfig, httpClient); + } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java index f0d873b71..2e47b007c 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java @@ -33,6 +33,21 @@ protected String getAuthorizationBaseUrl() { return "https://connect.ok.ru/oauth/authorize"; } + /** + * @param apiKey apiKey + * @param apiSecret apiSecret + * @param callback callback + * @param scope scope + * @param debugStream debugStream + * @param state state + * @param responseType responseType + * @param userAgent userAgent + * @param httpClientConfig httpClientConfig + * @param httpClient httpClient + * @return return + * @deprecated use one of getAuthorizationUrl method in {@link com.github.scribejava.core.oauth.OAuth20Service} + */ + @Deprecated @Override public OdnoklassnikiOAuthService createService(String apiKey, String apiSecret, String callback, String scope, OutputStream debugStream, String state, String responseType, String userAgent, @@ -41,6 +56,14 @@ public OdnoklassnikiOAuthService createService(String apiKey, String apiSecret, httpClientConfig, httpClient); } + @Override + public OdnoklassnikiOAuthService createService(String apiKey, String apiSecret, String callback, String scope, + OutputStream debugStream, String responseType, String userAgent, HttpClientConfig httpClientConfig, + HttpClient httpClient) { + return createService(apiKey, apiSecret, callback, scope, debugStream, null, responseType, userAgent, + httpClientConfig, httpClient); + } + @Override public BearerSignature getBearerSignature() { return BearerSignatureURIQueryParameter.instance(); diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/WunderlistAPI.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/WunderlistAPI.java index e8eb92111..1c6b18e74 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/WunderlistAPI.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/WunderlistAPI.java @@ -48,6 +48,29 @@ public ClientAuthentication getClientAuthentication() { return RequestBodyAuthenticationScheme.instance(); } + @Override + public OAuth20Service createService(String apiKey, String apiSecret, String callback, String scope, + OutputStream debugStream, String responseType, String userAgent, HttpClientConfig httpClientConfig, + HttpClient httpClient) { + return createService(apiKey, apiSecret, callback, scope, debugStream, null, responseType, userAgent, + httpClientConfig, httpClient); + } + + /** + * @param apiKey apiKey + * @param apiSecret apiSecret + * @param callback callback + * @param scope scope + * @param debugStream debugStream + * @param state state + * @param responseType responseType + * @param userAgent userAgent + * @param httpClientConfig httpClientConfig + * @param httpClient httpClient + * @return return + * @deprecated use one of getAuthorizationUrl method in {@link com.github.scribejava.core.oauth.OAuth20Service} + */ + @Deprecated @Override public OAuth20Service createService(String apiKey, String apiSecret, String callback, String scope, OutputStream debugStream, String state, String responseType, String userAgent, diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookService.java index 6aa4419e1..97354456e 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookService.java @@ -13,12 +13,31 @@ public class FacebookService extends OAuth20Service { + /** + * @param api api + * @param apiKey apiKey + * @param apiSecret apiSecret + * @param callback callback + * @param scope scope + * @param state state + * @param responseType responseType + * @param userAgent userAgent + * @param httpClientConfig httpClientConfig + * @param httpClient httpClient + * @deprecated use one of getAuthorizationUrl method in {@link com.github.scribejava.core.oauth.OAuth20Service} + */ + @Deprecated public FacebookService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { super(api, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); } + public FacebookService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, + String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { + super(api, apiKey, apiSecret, callback, scope, responseType, userAgent, httpClientConfig, httpClient); + } + @Override public void signRequest(String accessToken, OAuthRequest request) { super.signRequest(accessToken, request); diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/imgur/ImgurOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/imgur/ImgurOAuthService.java index b1c934a9a..f05abfbbf 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/imgur/ImgurOAuthService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/imgur/ImgurOAuthService.java @@ -10,12 +10,31 @@ public class ImgurOAuthService extends OAuth20Service { + /** + * @param api api + * @param apiKey apiKey + * @param apiSecret apiSecret + * @param callback callback + * @param scope scope + * @param state state + * @param responseType responseType + * @param userAgent userAgent + * @param httpClientConfig httpClientConfig + * @param httpClient httpClient + * @deprecated use one of getAuthorizationUrl method in {@link com.github.scribejava.core.oauth.OAuth20Service} + */ + @Deprecated public ImgurOAuthService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { super(api, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); } + public ImgurOAuthService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, + String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { + super(api, apiKey, apiSecret, callback, scope, responseType, userAgent, httpClientConfig, httpClient); + } + @Override protected OAuthRequest createAccessTokenRequest(String oauthVerifier) { final DefaultApi20 api = getApi(); diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/mailru/MailruOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/mailru/MailruOAuthService.java index f17a922a1..99955bf64 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/mailru/MailruOAuthService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/mailru/MailruOAuthService.java @@ -16,12 +16,31 @@ public class MailruOAuthService extends OAuth20Service { + /** + * @param api api + * @param apiKey apiKey + * @param apiSecret apiSecret + * @param callback callback + * @param scope scope + * @param state state + * @param responseType responseType + * @param userAgent userAgent + * @param httpClientConfig httpClientConfig + * @param httpClient httpClient + * @deprecated use one of getAuthorizationUrl method in {@link com.github.scribejava.core.oauth.OAuth20Service} + */ + @Deprecated public MailruOAuthService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { super(api, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); } + public MailruOAuthService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, + String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { + super(api, apiKey, apiSecret, callback, scope, responseType, userAgent, httpClientConfig, httpClient); + } + @Override public void signRequest(String accessToken, OAuthRequest request) { diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/odnoklassniki/OdnoklassnikiOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/odnoklassniki/OdnoklassnikiOAuthService.java index 16a9f10a5..d0901f533 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/odnoklassniki/OdnoklassnikiOAuthService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/odnoklassniki/OdnoklassnikiOAuthService.java @@ -19,12 +19,31 @@ public class OdnoklassnikiOAuthService extends OAuth20Service { + /** + * @param api api + * @param apiKey apiKey + * @param apiSecret apiSecret + * @param callback callback + * @param scope scope + * @param state state + * @param responseType responseType + * @param userAgent userAgent + * @param httpClientConfig httpClientConfig + * @param httpClient httpClient + * @deprecated use one of getAuthorizationUrl method in {@link com.github.scribejava.core.oauth.OAuth20Service} + */ + @Deprecated public OdnoklassnikiOAuthService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { super(api, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); } + public OdnoklassnikiOAuthService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, + String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { + super(api, apiKey, apiSecret, callback, scope, responseType, userAgent, httpClientConfig, httpClient); + } + @Override public void signRequest(String accessToken, OAuthRequest request) { //sig = lower(md5( sorted_request_params_composed_string + md5(access_token + application_secret_key))) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/wunderlist/WunderlistOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/wunderlist/WunderlistOAuthService.java index e5a5b07a7..66766d7e2 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/wunderlist/WunderlistOAuthService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/wunderlist/WunderlistOAuthService.java @@ -8,12 +8,31 @@ public class WunderlistOAuthService extends OAuth20Service { + /** + * @param api api + * @param apiKey apiKey + * @param apiSecret apiSecret + * @param callback callback + * @param scope scope + * @param state state + * @param responseType responseType + * @param userAgent userAgent + * @param httpClientConfig httpClientConfig + * @param httpClient httpClient + * @deprecated use one of getAuthorizationUrl method in {@link com.github.scribejava.core.oauth.OAuth20Service} + */ + @Deprecated public WunderlistOAuthService(WunderlistAPI api, String apiKey, String apiSecret, String callback, String scope, String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { super(api, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); } + public WunderlistOAuthService(WunderlistAPI api, String apiKey, String apiSecret, String callback, String scope, + String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { + super(api, apiKey, apiSecret, callback, scope, responseType, userAgent, httpClientConfig, httpClient); + } + @Override public void signRequest(String accessToken, OAuthRequest request) { super.signRequest(accessToken, request); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AsanaExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AsanaExample.java index 3907bdc2b..c851a9e22 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AsanaExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AsanaExample.java @@ -27,14 +27,13 @@ public static void main(String... args) throws IOException, InterruptedException final OAuth20Service service = new ServiceBuilder(apiKey) .apiSecret(apiSecret) .callback("https://localhost/") - .state(secretState) .build(Asana20Api.instance()); final Scanner in = new Scanner(System.in); // Obtain Auth URL System.out.println("Fetching the Authorication URL..."); System.out.println("Got the Authorization URL!"); - final String authorizationUrl = service.getAuthorizationUrl(); + final String authorizationUrl = service.getAuthorizationUrl(secretState); System.out.println("Now go and authorize ScribeJava here:"); System.out.println(authorizationUrl); System.out.println("And paste the authorization code here"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AutomaticExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AutomaticExample.java index 665a5552f..ed7ccd7ec 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AutomaticExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AutomaticExample.java @@ -28,7 +28,6 @@ public static void main(String... args) throws IOException, InterruptedException final String secretState = "secret" + new Random().nextInt(999_999); final OAuth20Service service = new ServiceBuilder(clientId) .apiSecret(clientSecret) - .state(secretState) .callback("http://www.example.com/oauth_callback/") .scope("scope:user:profile").debug() .build(AutomaticAPI.instance()); @@ -39,7 +38,7 @@ public static void main(String... args) throws IOException, InterruptedException // Obtain the Authorization URL System.out.println("Fetching the Authorization URL..."); - final String authorizationUrl = service.getAuthorizationUrl(); + final String authorizationUrl = service.getAuthorizationUrl(secretState); System.out.println("Got the Authorization URL!"); System.out.println("Now go and authorize ScribeJava here:"); System.out.println(authorizationUrl); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Box20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Box20Example.java index 7f82c9222..4931f097b 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Box20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Box20Example.java @@ -29,7 +29,6 @@ public static void main(String... args) throws IOException, InterruptedException final String secretState = "security_token" + new Random().nextInt(999_999); final OAuth20Service service = new ServiceBuilder(clientId) .apiSecret(clientSecret) - .state(secretState) .callback("https://example.com/callback") .build(BoxApi20.instance()); final Scanner in = new Scanner(System.in, "UTF-8"); @@ -44,7 +43,7 @@ public static void main(String... args) throws IOException, InterruptedException additionalParams.put("access_type", "offline"); //force to reget refresh token (if usera are asked not the first time) additionalParams.put("prompt", "consent"); - final String authorizationUrl = service.getAuthorizationUrl(additionalParams); + final String authorizationUrl = service.getAuthorizationUrl(secretState, additionalParams); System.out.println("Got the Authorization URL!"); System.out.println("Now go and authorize ScribeJava here:"); System.out.println(authorizationUrl); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DataportenExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DataportenExample.java index fc0f4d3e2..c24a596fb 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DataportenExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DataportenExample.java @@ -27,7 +27,6 @@ public static void main(String... args) throws IOException, InterruptedException final String secretState = "secret" + new Random().nextInt(999_999); final OAuth20Service service = new ServiceBuilder(clientId) .apiSecret(clientSecret) - .state(secretState) .callback("http://www.example.com/oauth_callback/") .build(DataportenApi.instance()); final Scanner in = new Scanner(System.in, "UTF-8"); @@ -37,7 +36,7 @@ public static void main(String... args) throws IOException, InterruptedException // Obtain the Authorization URL System.out.println("Fetching the Authorization URL..."); - final String authorizationUrl = service.getAuthorizationUrl(); + final String authorizationUrl = service.getAuthorizationUrl(secretState); System.out.println("Got the Authorization URL!"); System.out.println("Now go and authorize ScribeJava here:"); System.out.println(authorizationUrl); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiscordExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiscordExample.java index 41c5be42b..70714a16c 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiscordExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiscordExample.java @@ -29,7 +29,6 @@ public static void main(String... args) throws IOException, ExecutionException, final OAuth20Service service = new ServiceBuilder(clientId) .apiSecret(clientSecret) .scope("identify") // replace with desired scope - .state(secretState) .callback("http://example.com/callback") .userAgent("ScribeJava") .build(DiscordApi.instance()); @@ -40,7 +39,7 @@ public static void main(String... args) throws IOException, ExecutionException, // Obtain the Authorization URL System.out.println("Fetching the Authorization URL..."); - final String authorizationUrl = service.getAuthorizationUrl(); + final String authorizationUrl = service.getAuthorizationUrl(secretState); System.out.println("Got the Authorization URL!"); System.out.println("Now go and authorize ScribeJava here:"); System.out.println(authorizationUrl); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncApacheExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncApacheExample.java index bf7c6f2ee..c98c00eba 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncApacheExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncApacheExample.java @@ -29,7 +29,6 @@ public static void main(String... args) throws InterruptedException, ExecutionEx try (OAuth20Service service = new ServiceBuilder(clientId) .apiSecret(clientSecret) - .state(secretState) .callback("http://www.example.com/oauth_callback/") .httpClientConfig(ApacheHttpClientConfig.defaultConfig()) .build(FacebookApi.instance())) { @@ -40,7 +39,7 @@ public static void main(String... args) throws InterruptedException, ExecutionEx // Obtain the Authorization URL System.out.println("Fetching the Authorization URL..."); - final String authorizationUrl = service.getAuthorizationUrl(); + final String authorizationUrl = service.getAuthorizationUrl(secretState); System.out.println("Got the Authorization URL!"); System.out.println("Now go and authorize ScribeJava here:"); System.out.println(authorizationUrl); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java index 81d1dd53a..1d7e38576 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java @@ -37,7 +37,6 @@ public static void main(String... args) throws InterruptedException, ExecutionEx try (OAuth20Service service = new ServiceBuilder(clientId) .apiSecret(clientSecret) - .state(secretState) .callback("http://www.example.com/oauth_callback/") .httpClientConfig(clientConfig) .build(FacebookApi.instance())) { @@ -48,7 +47,7 @@ public static void main(String... args) throws InterruptedException, ExecutionEx // Obtain the Authorization URL System.out.println("Fetching the Authorization URL..."); - final String authorizationUrl = service.getAuthorizationUrl(); + final String authorizationUrl = service.getAuthorizationUrl(secretState); System.out.println("Got the Authorization URL!"); System.out.println("Now go and authorize ScribeJava here:"); System.out.println(authorizationUrl); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java index 7a0ba726a..071a979a3 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java @@ -27,7 +27,6 @@ public static void main(String... args) throws IOException, InterruptedException final String secretState = "secret" + new Random().nextInt(999_999); final OAuth20Service service = new ServiceBuilder(clientId) .apiSecret(clientSecret) - .state(secretState) .callback("http://www.example.com/oauth_callback/") .build(FacebookApi.instance()); @@ -38,7 +37,7 @@ public static void main(String... args) throws IOException, InterruptedException // Obtain the Authorization URL System.out.println("Fetching the Authorization URL..."); - final String authorizationUrl = service.getAuthorizationUrl(); + final String authorizationUrl = service.getAuthorizationUrl(secretState); System.out.println("Got the Authorization URL!"); System.out.println("Now go and authorize ScribeJava here:"); System.out.println(authorizationUrl); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FitbitApi20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FitbitApi20Example.java index 9c17e9054..955c1289f 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FitbitApi20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FitbitApi20Example.java @@ -30,7 +30,6 @@ public static void main(String... args) throws Exception { .scope("activity profile") // replace with desired scope //your callback URL to store and handle the authorization code sent by Fitbit .callback("http://www.example.com/oauth_callback/") - .state("some_params") .build(FitbitApi20.instance()); final Scanner in = new Scanner(System.in); @@ -39,7 +38,7 @@ public static void main(String... args) throws Exception { // Obtain the Authorization URL System.out.println("Fetching the Authorization URL..."); - final String authorizationUrl = service.getAuthorizationUrl(); + final String authorizationUrl = service.getAuthorizationUrl("some_params"); System.out.println("Got the Authorization URL!"); System.out.println("Now go and authorize ScribeJava here:"); System.out.println(authorizationUrl); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GeniusExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GeniusExample.java index 8f269657e..d6726c2d1 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GeniusExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GeniusExample.java @@ -28,7 +28,6 @@ public static void main(String... args) throws IOException, InterruptedException final OAuth20Service service = new ServiceBuilder(clientId) .apiSecret(clientSecret) .scope("me") - .state(secretState) .callback("com.scribejavatest://callback") .userAgent("ScribeJava") .build(GeniusApi.instance()); @@ -38,7 +37,7 @@ public static void main(String... args) throws IOException, InterruptedException // Obtain the Authorization URL System.out.println("Fetching the Authorization URL..."); - final String authorizationUrl = service.getAuthorizationUrl(); + final String authorizationUrl = service.getAuthorizationUrl(secretState); System.out.println("Got the Authorization URL!"); System.out.println("Now go and authorize ScribeJava here:"); System.out.println(authorizationUrl); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubAsyncOkHttpExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubAsyncOkHttpExample.java index bc05042bf..eb4f5ee2e 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubAsyncOkHttpExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubAsyncOkHttpExample.java @@ -29,7 +29,6 @@ public static void main(String... args) throws IOException, ExecutionException, final String secretState = "secret" + new Random().nextInt(999_999); try (OAuth20Service service = new ServiceBuilder(clientId) .apiSecret(clientSecret) - .state(secretState) .callback("http://www.example.com/oauth_callback/") .httpClientConfig(OkHttpHttpClientConfig.defaultConfig()) .build(GitHubApi.instance())) { @@ -40,7 +39,7 @@ public static void main(String... args) throws IOException, ExecutionException, // Obtain the Authorization URL System.out.println("Fetching the Authorization URL..."); - final String authorizationUrl = service.getAuthorizationUrl(); + final String authorizationUrl = service.getAuthorizationUrl(secretState); System.out.println("Got the Authorization URL!"); System.out.println("Now go and authorize ScribeJava here:"); System.out.println(authorizationUrl); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubExample.java index 6d60957a3..d48d7abfd 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubExample.java @@ -27,7 +27,6 @@ public static void main(String... args) throws IOException, InterruptedException final String secretState = "secret" + new Random().nextInt(999_999); final OAuth20Service service = new ServiceBuilder(clientId) .apiSecret(clientSecret) - .state(secretState) .callback("http://www.example.com/oauth_callback/") .build(GitHubApi.instance()); final Scanner in = new Scanner(System.in, "UTF-8"); @@ -37,7 +36,7 @@ public static void main(String... args) throws IOException, InterruptedException // Obtain the Authorization URL System.out.println("Fetching the Authorization URL..."); - final String authorizationUrl = service.getAuthorizationUrl(); + final String authorizationUrl = service.getAuthorizationUrl(secretState); System.out.println("Got the Authorization URL!"); System.out.println("Now go and authorize ScribeJava here:"); System.out.println(authorizationUrl); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java index d2d8260df..4bf0522c5 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java @@ -40,9 +40,7 @@ public static void main(String... args) throws InterruptedException, ExecutionEx try (OAuth20Service service = new ServiceBuilder(clientId) .apiSecret(clientSecret) .scope("profile") // replace with desired scope - .state(secretState) - .callback("http://example.com/callback") - .httpClientConfig(clientConfig) + .callback("http://example.com/callback") .httpClientConfig(clientConfig) .build(GoogleApi20.instance())) { final Scanner in = new Scanner(System.in, "UTF-8"); @@ -57,7 +55,7 @@ public static void main(String... args) throws InterruptedException, ExecutionEx additionalParams.put("access_type", "offline"); //force to reget refresh token (if usera are asked not the first time) additionalParams.put("prompt", "consent"); - final String authorizationUrl = service.getAuthorizationUrl(additionalParams); + final String authorizationUrl = service.getAuthorizationUrl(secretState, additionalParams); System.out.println("Got the Authorization URL!"); System.out.println("Now go and authorize ScribeJava here:"); System.out.println(authorizationUrl); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java index 8fe8a37d1..de7e2e041 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java @@ -30,7 +30,6 @@ public static void main(String... args) throws IOException, InterruptedException final OAuth20Service service = new ServiceBuilder(clientId) .apiSecret(clientSecret) .scope("profile") // replace with desired scope - .state(secretState) .callback("http://example.com/callback") .build(GoogleApi20.instance()); final Scanner in = new Scanner(System.in, "UTF-8"); @@ -46,7 +45,7 @@ public static void main(String... args) throws IOException, InterruptedException additionalParams.put("access_type", "offline"); //force to reget refresh token (if usera are asked not the first time) additionalParams.put("prompt", "consent"); - final String authorizationUrl = service.getAuthorizationUrl(additionalParams); + final String authorizationUrl = service.getAuthorizationUrl(secretState, additionalParams); System.out.println("Got the Authorization URL!"); System.out.println("Now go and authorize ScribeJava here:"); System.out.println(authorizationUrl); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20RevokeExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20RevokeExample.java index 61f44501e..f44a972a2 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20RevokeExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20RevokeExample.java @@ -30,7 +30,6 @@ public static void main(String... args) throws IOException, InterruptedException final OAuth20Service service = new ServiceBuilder(clientId) .apiSecret(clientSecret) .scope("profile") // replace with desired scope - .state(secretState) .callback("http://example.com/callback") .build(GoogleApi20.instance()); final Scanner in = new Scanner(System.in, "UTF-8"); @@ -46,7 +45,7 @@ public static void main(String... args) throws IOException, InterruptedException additionalParams.put("access_type", "offline"); //force to reget refresh token (if usera are asked not the first time) additionalParams.put("prompt", "consent"); - final String authorizationUrl = service.getAuthorizationUrl(additionalParams); + final String authorizationUrl = service.getAuthorizationUrl(secretState, additionalParams); System.out.println("Got the Authorization URL!"); System.out.println("Now go and authorize ScribeJava here:"); System.out.println(authorizationUrl); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20WithPKCEExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20WithPKCEExample.java index 6c8b3a66a..377d52e6a 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20WithPKCEExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20WithPKCEExample.java @@ -31,7 +31,6 @@ public static void main(String... args) throws IOException, InterruptedException final OAuth20Service service = new ServiceBuilder(clientId) .apiSecret(clientSecret) .scope("profile") // replace with desired scope - .state(secretState) .callback("http://example.com/callback") .build(GoogleApi20.instance()); @@ -49,7 +48,8 @@ public static void main(String... args) throws IOException, InterruptedException //force to reget refresh token (if usera are asked not the first time) additionalParams.put("prompt", "consent"); - final AuthorizationUrlWithPKCE authUrlWithPKCE = service.getAuthorizationUrlWithPKCE(additionalParams); + final AuthorizationUrlWithPKCE authUrlWithPKCE + = service.getAuthorizationUrlWithPKCE(secretState, additionalParams); System.out.println("Got the Authorization URL!"); System.out.println("Now go and authorize ScribeJava here:"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HiOrgServerExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HiOrgServerExample.java index 6055af753..5ab81d8bc 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HiOrgServerExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HiOrgServerExample.java @@ -31,7 +31,6 @@ public static void main(String... args) throws IOException, InterruptedException final OAuth20Service service = new ServiceBuilder(clientId) .apiSecret(clientSecret) .scope("basic eigenedaten") - .state(secretState) .callback(CALLBACK_URL) .build(HiOrgServerApi20.instance()); @@ -42,7 +41,7 @@ public static void main(String... args) throws IOException, InterruptedException // Obtain the Authorization URL System.out.println("Fetching the Authorization URL..."); - final String authorizationUrl = service.getAuthorizationUrl(); + final String authorizationUrl = service.getAuthorizationUrl(secretState); System.out.println("Got the Authorization URL!"); System.out.println("Now go and authorize ScribeJava here:"); System.out.println(authorizationUrl); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedIn20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedIn20Example.java index d76acb856..825cf1ac2 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedIn20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedIn20Example.java @@ -27,7 +27,6 @@ public static void main(String... args) throws IOException, InterruptedException .apiSecret(clientSecret) .scope("r_basicprofile r_emailaddress") // replace with desired scope .callback("http://example.com/callback") - .state("some_params") .build(LinkedInApi20.instance()); final Scanner in = new Scanner(System.in); @@ -36,7 +35,7 @@ public static void main(String... args) throws IOException, InterruptedException // Obtain the Authorization URL System.out.println("Fetching the Authorization URL..."); - final String authorizationUrl = service.getAuthorizationUrl(); + final String authorizationUrl = service.getAuthorizationUrl("some_params"); System.out.println("Got the Authorization URL!"); System.out.println("Now go and authorize ScribeJava here:"); System.out.println(authorizationUrl); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NaverExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NaverExample.java index bf359c547..ec3e79db8 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NaverExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NaverExample.java @@ -28,7 +28,6 @@ public static void main(String... args) throws IOException, InterruptedException final String secretState = "secret" + new Random().nextInt(999_999); final OAuth20Service service = new ServiceBuilder(clientId) .apiSecret(clientSecret) - .state(secretState) .callback("http://www.example.com/oauth_callback/") .build(NaverApi.instance()); @@ -39,7 +38,7 @@ public static void main(String... args) throws IOException, InterruptedException // Obtain the Authorization URL System.out.println("Fetching the Authorization URL..."); - final String authorizationUrl = service.getAuthorizationUrl(); + final String authorizationUrl = service.getAuthorizationUrl(secretState); System.out.println("Got the Authorization URL!"); System.out.println("Now go and authorize ScribeJava here:"); System.out.println(authorizationUrl); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/StackExchangeExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/StackExchangeExample.java index 39350cd14..e179799e4 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/StackExchangeExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/StackExchangeExample.java @@ -32,7 +32,6 @@ public static void main(String... args) throws IOException, InterruptedException final String secretState = "secret" + new Random().nextInt(999_999); final OAuth20Service service = new ServiceBuilder(clientId) .apiSecret(clientSecret) - .state(secretState) .callback("http://www.example.com/oauth_callback/") .build(StackExchangeApi.instance()); final Scanner in = new Scanner(System.in, "UTF-8"); @@ -42,7 +41,7 @@ public static void main(String... args) throws IOException, InterruptedException // Obtain the Authorization URL System.out.println("Fetching the Authorization URL..."); - final String authorizationUrl = service.getAuthorizationUrl(); + final String authorizationUrl = service.getAuthorizationUrl(secretState); System.out.println("Got the Authorization URL!"); System.out.println("Now go and authorize ScribeJava here:"); System.out.println(authorizationUrl); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV1StagingExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV1StagingExample.java index 427b83f2c..6c88f7434 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV1StagingExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV1StagingExample.java @@ -31,7 +31,6 @@ public static void main(String... args) throws IOException, InterruptedException final OAuth20Service service = new ServiceBuilder(clientId) .apiSecret(clientSecret) - .state(secretState) .callback(redirectURI) .build(TheThingsNetworkV1StagingApi.instance()); final Scanner in = new Scanner(System.in, "UTF-8"); @@ -41,7 +40,7 @@ public static void main(String... args) throws IOException, InterruptedException // Obtain the Authorization URL System.out.println("Fetching the Authorization URL..."); - final String authorizationUrl = service.getAuthorizationUrl(); + final String authorizationUrl = service.getAuthorizationUrl(secretState); System.out.println("Got the Authorization URL!"); System.out.println("Now go and authorize ScribeJava here:"); System.out.println(authorizationUrl); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV2PreviewExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV2PreviewExample.java index 19cc96331..57aacac05 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV2PreviewExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV2PreviewExample.java @@ -31,7 +31,6 @@ public static void main(String... args) throws IOException, InterruptedException final OAuth20Service service = new ServiceBuilder(clientId) .apiSecret(clientSecret) - .state(secretState) .callback(redirectURI) .build(TheThingsNetworkV2PreviewApi.instance()); final Scanner in = new Scanner(System.in, "UTF-8"); @@ -41,7 +40,7 @@ public static void main(String... args) throws IOException, InterruptedException // Obtain the Authorization URL System.out.println("Fetching the Authorization URL..."); - final String authorizationUrl = service.getAuthorizationUrl(); + final String authorizationUrl = service.getAuthorizationUrl(secretState); System.out.println("Got the Authorization URL!"); System.out.println("Now go and authorize ScribeJava here:"); System.out.println(authorizationUrl); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/WunderlistExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/WunderlistExample.java index 91bb5f523..630df1c47 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/WunderlistExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/WunderlistExample.java @@ -31,7 +31,6 @@ public static void main(String... args) throws IOException, InterruptedException final OAuth20Service service = new ServiceBuilder(apiKey) .apiSecret(apiSecret) .callback(callbackUrl) - .state(secretState) .debug() .build(WunderlistAPI.instance()); @@ -41,7 +40,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println(); // Obtain the Authorization URL System.out.println("Fetching the Authorization URL..."); - final String authorizationUrl = service.getAuthorizationUrl(); + final String authorizationUrl = service.getAuthorizationUrl(secretState); System.out.println("Got the Authorization URL!"); System.out.println("Now go and authorize ScribeJava here:"); System.out.println(authorizationUrl); diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilder.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilder.java index 8c70c4319..afcb8a347 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilder.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilder.java @@ -3,6 +3,7 @@ import com.github.scribejava.core.builder.api.BaseApi; import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.httpclient.HttpClientConfig; +import com.github.scribejava.core.oauth.OAuth20Service; import com.github.scribejava.core.oauth.OAuthService; import com.github.scribejava.core.utils.Preconditions; @@ -78,11 +79,14 @@ public ServiceBuilder scope(String scope) { } /** + * /** * Configures the anti forgery session state. This is available in some APIs (like Google's). * * @param state The OAuth state * @return the {@link ServiceBuilder} instance for method chaining + * @deprecated use one of getAuthorizationUrl method in {@link com.github.scribejava.core.oauth.OAuth20Service} */ + @Deprecated public ServiceBuilder state(String state) { Preconditions.checkEmptyString(state, "Invalid OAuth state"); this.state = state; @@ -136,7 +140,11 @@ public ServiceBuilder debug() { * @return fully configured {@link OAuthService} */ public S build(BaseApi api) { - return api.createService(apiKey, apiSecret, callback, scope, debugStream, state, responseType, userAgent, + final S service = api.createService(apiKey, apiSecret, callback, scope, debugStream, responseType, userAgent, httpClientConfig, httpClient); + if (service instanceof OAuth20Service) { + ((OAuth20Service) service).setState(state); + } + return service; } } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/BaseApi.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/BaseApi.java index bce6192dc..2ba40e7e1 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/BaseApi.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/BaseApi.java @@ -7,7 +7,25 @@ public interface BaseApi { + /** + * @param apiKey apiKey + * @param apiSecret apiSecret + * @param callback callback + * @param scope scope + * @param debugStream debugStream + * @param state state + * @param responseType responseType + * @param userAgent userAgent + * @param httpClientConfig httpClientConfig + * @param httpClient httpClient + * @return return + * @deprecated use one of getAuthorizationUrl method in {@link com.github.scribejava.core.oauth.OAuth20Service} + */ + @Deprecated T createService(String apiKey, String apiSecret, String callback, String scope, OutputStream debugStream, String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient); + + T createService(String apiKey, String apiSecret, String callback, String scope, OutputStream debugStream, + String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient); } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi10a.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi10a.java index 67bbd181e..315ab9470 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi10a.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi10a.java @@ -143,6 +143,23 @@ public String getAuthorizationUrl(OAuth1RequestToken requestToken) { return parameters.appendTo(getAuthorizationBaseUrl()); } + /** + * @param apiKey apiKey + * @param apiSecret apiSecret + * @param callback callback + * @param scope scope + * @param debugStream debugStream + * @param state state + * @param responseType responseType + * @param userAgent userAgent + * @param httpClientConfig httpClientConfig + * @param httpClient httpClient + * @return return + * @deprecated use {@link #createService(java.lang.String, java.lang.String, java.lang.String, java.lang.String, + * java.io.OutputStream, java.lang.String, java.lang.String, com.github.scribejava.core.httpclient.HttpClientConfig, + * com.github.scribejava.core.httpclient.HttpClient)} + */ + @Deprecated @Override public OAuth10aService createService(String apiKey, String apiSecret, String callback, String scope, OutputStream debugStream, String state, String responseType, String userAgent, @@ -151,6 +168,14 @@ public OAuth10aService createService(String apiKey, String apiSecret, String cal httpClient); } + @Override + public OAuth10aService createService(String apiKey, String apiSecret, String callback, String scope, + OutputStream debugStream, String responseType, String userAgent, HttpClientConfig httpClientConfig, + HttpClient httpClient) { + return createService(apiKey, apiSecret, callback, scope, debugStream, null, responseType, userAgent, + httpClientConfig, httpClient); + } + /** * http://tools.ietf.org/html/rfc5849 says that "The client MAY omit the empty "oauth_token" protocol parameter from * the request", but not all oauth servers are good boys. diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java index d12f4844c..64d64cba1 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java @@ -106,6 +106,29 @@ public String getAuthorizationUrl(String responseType, String apiKey, String cal return parameters.appendTo(getAuthorizationBaseUrl()); } + @Override + public OAuth20Service createService(String apiKey, String apiSecret, String callback, String scope, + OutputStream debugStream, String responseType, String userAgent, HttpClientConfig httpClientConfig, + HttpClient httpClient) { + return createService(apiKey, apiSecret, callback, scope, debugStream, null, responseType, userAgent, + httpClientConfig, httpClient); + } + + /** + * @param apiKey apiKey + * @param apiSecret apiSecret + * @param callback callback + * @param scope scope + * @param debugStream debugStream + * @param state state + * @param responseType responseType + * @param userAgent userAgent + * @param httpClientConfig httpClientConfig + * @param httpClient httpClient + * @return return + * @deprecated use one of getAuthorizationUrl method in {@link com.github.scribejava.core.oauth.OAuth20Service} + */ + @Deprecated @Override public OAuth20Service createService(String apiKey, String apiSecret, String callback, String scope, OutputStream debugStream, String state, String responseType, String userAgent, diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java index f7564ff1d..d3fe22912 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java @@ -27,14 +27,33 @@ public class OAuth20Service extends OAuthService { private static final PKCEService PKCE_SERVICE = new PKCEService(); private final DefaultApi20 api; private final String responseType; - private final String state; + private String state; + /** + * @param api api + * @param apiKey apiKey + * @param apiSecret apiSecret + * @param callback callback + * @param scope scope + * @param state state + * @param responseType responseType + * @param userAgent userAgent + * @param httpClientConfig httpClientConfig + * @param httpClient httpClient + * @deprecated use one of getAuthorizationUrl method in {@link com.github.scribejava.core.oauth.OAuth20Service} + */ + @Deprecated public OAuth20Service(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { + this(api, apiKey, apiSecret, callback, scope, responseType, userAgent, httpClientConfig, httpClient); + this.state = state; + } + + public OAuth20Service(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, + String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { super(apiKey, apiSecret, callback, scope, userAgent, httpClientConfig, httpClient); this.responseType = responseType; - this.state = state; this.api = api; } @@ -262,12 +281,20 @@ public void signRequest(OAuth2AccessToken accessToken, OAuthRequest request) { } public AuthorizationUrlWithPKCE getAuthorizationUrlWithPKCE() { - return getAuthorizationUrlWithPKCE(null); + return getAuthorizationUrlWithPKCE(getState()); + } + + public AuthorizationUrlWithPKCE getAuthorizationUrlWithPKCE(String state) { + return getAuthorizationUrlWithPKCE(state, null); } public AuthorizationUrlWithPKCE getAuthorizationUrlWithPKCE(Map additionalParams) { + return getAuthorizationUrlWithPKCE(getState(), additionalParams); + } + + public AuthorizationUrlWithPKCE getAuthorizationUrlWithPKCE(String state, Map additionalParams) { final PKCE pkce = PKCE_SERVICE.generatePKCE(); - return new AuthorizationUrlWithPKCE(pkce, getAuthorizationUrl(additionalParams, pkce)); + return new AuthorizationUrlWithPKCE(pkce, getAuthorizationUrl(state, additionalParams, pkce)); } /** @@ -276,7 +303,11 @@ public AuthorizationUrlWithPKCE getAuthorizationUrlWithPKCE(Map * @return the URL where you should redirect your users */ public String getAuthorizationUrl() { - return getAuthorizationUrl(null, null); + return getAuthorizationUrl(getState()); + } + + public String getAuthorizationUrl(String state) { + return getAuthorizationUrl(state, null, null); } /** @@ -286,14 +317,26 @@ public String getAuthorizationUrl() { * @return the URL where you should redirect your users */ public String getAuthorizationUrl(Map additionalParams) { - return getAuthorizationUrl(additionalParams, null); + return getAuthorizationUrl(getState(), additionalParams); + } + + public String getAuthorizationUrl(String state, Map additionalParams) { + return getAuthorizationUrl(state, additionalParams, null); } public String getAuthorizationUrl(PKCE pkce) { - return getAuthorizationUrl(null, pkce); + return getAuthorizationUrl(getState(), pkce); + } + + public String getAuthorizationUrl(String state, PKCE pkce) { + return getAuthorizationUrl(state, null, pkce); } public String getAuthorizationUrl(Map additionalParams, PKCE pkce) { + return getAuthorizationUrl(getState(), additionalParams, pkce); + } + + public String getAuthorizationUrl(String state, Map additionalParams, PKCE pkce) { final Map params; if (pkce == null) { params = additionalParams; @@ -301,7 +344,7 @@ public String getAuthorizationUrl(Map additionalParams, PKCE pkc params = additionalParams == null ? new HashMap() : new HashMap<>(additionalParams); params.putAll(pkce.getAuthorizationUrlParams()); } - return api.getAuthorizationUrl(getResponseType(), getApiKey(), getCallback(), getScope(), getState(), params); + return api.getAuthorizationUrl(getResponseType(), getApiKey(), getCallback(), getScope(), state, params); } public DefaultApi20 getApi() { @@ -389,7 +432,21 @@ public String getResponseType() { return responseType; } + /** + * @return state + * @deprecated use one of getAuthorizationUrl method in {@link com.github.scribejava.core.oauth.OAuth20Service} + */ + @Deprecated public String getState() { return state; } + + /** + * @param state state + * @deprecated use one of getAuthorizationUrl method in {@link com.github.scribejava.core.oauth.OAuth20Service} + */ + @Deprecated + public void setState(String state) { + this.state = state; + } } diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/AbstractClientTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/AbstractClientTest.java index 58c4664de..ac4705974 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/AbstractClientTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/AbstractClientTest.java @@ -44,8 +44,7 @@ public Response getResponse() { @Before public void setUp() { - oAuthService = new OAuth20Service(null, "test", "test", null, null, null, null, null, null, - createNewClient()); + oAuthService = new OAuth20Service(null, "test", "test", null, null, null, null, null, createNewClient()); } @After diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ApiUnit.java b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ApiUnit.java index 8d7777f86..141be05d5 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ApiUnit.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ApiUnit.java @@ -21,9 +21,9 @@ protected String getAuthorizationBaseUrl() { @Override public OAuth20ServiceUnit createService(String apiKey, String apiSecret, String callback, String scope, - OutputStream debugStream, String state, String responseType, String userAgent, - HttpClientConfig httpClientConfig, HttpClient httpClient) { - return new OAuth20ServiceUnit(this, apiKey, apiSecret, callback, scope, state, responseType, userAgent, + OutputStream debugStream, String responseType, String userAgent, HttpClientConfig httpClientConfig, + HttpClient httpClient) { + return new OAuth20ServiceUnit(this, apiKey, apiSecret, callback, scope, responseType, userAgent, httpClientConfig, httpClient); } diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceTest.java index c74e0ea57..1f1983092 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceTest.java @@ -34,7 +34,6 @@ public void shouldProduceCorrectRequestSync() throws IOException, InterruptedExc final Map map = json.fromJson(token.getRawResponse(), new TypeTokenImpl().getType()); assertEquals(OAuth20ServiceUnit.TOKEN, map.get(OAuthConstants.ACCESS_TOKEN)); - assertEquals(OAuth20ServiceUnit.STATE, map.get(OAuthConstants.STATE)); assertEquals(OAuth20ServiceUnit.EXPIRES, map.get("expires_in")); final String authorize = base64Encoder.encodeToString( @@ -61,7 +60,6 @@ public void shouldProduceCorrectRequestAsync() throws ExecutionException, Interr final Map map = json.fromJson(token.getRawResponse(), new TypeTokenImpl().getType()); assertEquals(OAuth20ServiceUnit.TOKEN, map.get(OAuthConstants.ACCESS_TOKEN)); - assertEquals(OAuth20ServiceUnit.STATE, map.get(OAuthConstants.STATE)); assertEquals(OAuth20ServiceUnit.EXPIRES, map.get("expires_in")); final String authorize = base64Encoder.encodeToString( diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceUnit.java b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceUnit.java index a5cbf9763..0bcc766ad 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceUnit.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceUnit.java @@ -20,9 +20,9 @@ class OAuth20ServiceUnit extends OAuth20Service { static final String STATE = "123"; static final String EXPIRES = "3600"; - OAuth20ServiceUnit(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, String state, + OAuth20ServiceUnit(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - super(api, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); + super(api, apiKey, apiSecret, callback, scope, responseType, userAgent, httpClientConfig, httpClient); } @Override From 0508595e87f4b30e26e6a952213837a0749b0c99 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 8 Feb 2019 14:11:13 +0300 Subject: [PATCH 561/882] formatting typo --- .../scribejava/apis/examples/Google20AsyncAHCExample.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java index 4bf0522c5..3c20eb9bf 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java @@ -40,7 +40,8 @@ public static void main(String... args) throws InterruptedException, ExecutionEx try (OAuth20Service service = new ServiceBuilder(clientId) .apiSecret(clientSecret) .scope("profile") // replace with desired scope - .callback("http://example.com/callback") .httpClientConfig(clientConfig) + .callback("http://example.com/callback") + .httpClientConfig(clientConfig) .build(GoogleApi20.instance())) { final Scanner in = new Scanner(System.in, "UTF-8"); From 0d33279f3497f0e2e13abb5f2696e1b652a2c9e8 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 8 Feb 2019 14:24:22 +0300 Subject: [PATCH 562/882] prepare v6.3.0 --- README.md | 4 ++-- changelog | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 360a8411d..e0e5cc2dd 100644 --- a/README.md +++ b/README.md @@ -128,7 +128,7 @@ You can pull ScribeJava from the central maven repository, just add these to you com.github.scribejava scribejava-apis - 6.2.0 + 6.3.0 ``` @@ -137,7 +137,7 @@ And in case you need just core classes (that's it, without any external API (FB, com.github.scribejava scribejava-core - 6.2.0 + 6.3.0 ``` diff --git a/changelog b/changelog index 03ba4e7ad..89a311974 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,4 @@ -[SNAPSHOT] +[6.3.0] * fix Muplipart request model and implement it for a jdk HTTP client (thanks to https://github.com/NTPape) * remove any Google+ mention (switch to clean Google OAuth2) (thanks to https://github.com/fvasco) * fix Microsoft Azure AD v1.0 and v2.0 (thanks to https://github.com/kenpusney and https://github.com/oscararias) From ba0aa3d05c9041d3902aadd1bdfba4b31f6beac2 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 8 Feb 2019 14:26:08 +0300 Subject: [PATCH 563/882] [maven-release-plugin] prepare release scribejava-6.3.0 --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index c1d6db3fb..4daddcfe0 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 6.2.1-SNAPSHOT + 6.3.0 ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -34,7 +34,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - HEAD + scribejava-6.3.0 diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 39202c69b..90732e5af 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.2.1-SNAPSHOT + 6.3.0 ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 7da4f7cf5..854e714ea 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.2.1-SNAPSHOT + 6.3.0 ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 5b7c743f2..4c02aaa24 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.2.1-SNAPSHOT + 6.3.0 ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index 3c59ef366..33b8c2de1 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.2.1-SNAPSHOT + 6.3.0 ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index 7b43aaf1b..218c7757c 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.2.1-SNAPSHOT + 6.3.0 ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 0c2ed23f1..b2164ad3e 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.2.1-SNAPSHOT + 6.3.0 ../pom.xml From 8b5dca9f91bdd09a857ef1e8b00d6e33fef5cf40 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 8 Feb 2019 14:26:19 +0300 Subject: [PATCH 564/882] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index 4daddcfe0..b9c60a7cc 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 6.3.0 + 6.3.1-SNAPSHOT ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -34,7 +34,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - scribejava-6.3.0 + HEAD diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 90732e5af..81ac6e17b 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.3.0 + 6.3.1-SNAPSHOT ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 854e714ea..4252ba944 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.3.0 + 6.3.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 4c02aaa24..9c9f5c226 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.3.0 + 6.3.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index 33b8c2de1..a01b769d9 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.3.0 + 6.3.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index 218c7757c..33fb12bf8 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.3.0 + 6.3.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index b2164ad3e..bfc65c303 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.3.0 + 6.3.1-SNAPSHOT ../pom.xml From c270cefcfcd6105338c349fcd5429ce12996385b Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 8 Feb 2019 15:23:00 +0300 Subject: [PATCH 565/882] cleanup deprecated methods --- .../github/scribejava/apis/FacebookApi.java | 27 +---- .../com/github/scribejava/apis/ImgurApi.java | 25 +---- .../com/github/scribejava/apis/MailruApi.java | 25 +---- .../scribejava/apis/OdnoklassnikiApi.java | 25 +---- .../github/scribejava/apis/WunderlistAPI.java | 25 +---- .../apis/facebook/FacebookService.java | 20 ---- .../apis/imgur/ImgurOAuthService.java | 20 ---- .../apis/mailru/MailruOAuthService.java | 21 ---- .../OdnoklassnikiOAuthService.java | 20 ---- .../wunderlist/WunderlistOAuthService.java | 20 ---- .../core/builder/ServiceBuilder.java | 23 +--- .../scribejava/core/builder/api/BaseApi.java | 19 ---- .../core/builder/api/DefaultApi10a.java | 29 +---- .../core/builder/api/DefaultApi20.java | 27 +---- .../AbstractAsyncOnlyHttpClient.java | 12 -- .../core/httpclient/BodyPartPayload.java | 69 ------------ .../core/httpclient/HttpClient.java | 39 ------- .../core/httpclient/MultipartPayload.java | 105 ------------------ .../core/httpclient/jdk/JDKHttpClient.java | 71 ------------ .../scribejava/core/model/OAuthRequest.java | 72 ------------ .../scribejava/core/oauth/OAuth20Service.java | 52 +-------- .../scribejava/core/oauth/OAuthService.java | 3 - .../httpclient/ahc/AhcHttpClient.java | 12 -- .../httpclient/apache/ApacheHttpClient.java | 12 -- .../httpclient/ning/NingHttpClient.java | 12 -- .../httpclient/okhttp/OkHttpHttpClient.java | 24 ---- 26 files changed, 17 insertions(+), 792 deletions(-) delete mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/httpclient/BodyPartPayload.java delete mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/httpclient/MultipartPayload.java diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java index da1acce63..4b2df428e 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java @@ -70,34 +70,11 @@ public ClientAuthentication getClientAuthentication() { return RequestBodyAuthenticationScheme.instance(); } - /** - * @param apiKey apiKey - * @param apiSecret apiSecret - * @param callback callback - * @param scope scope - * @param debugStream debugStream - * @param state state - * @param responseType responseType - * @param userAgent userAgent - * @param httpClientConfig httpClientConfig - * @param httpClient httpClient - * @return return - * @deprecated use one of getAuthorizationUrl method in {@link com.github.scribejava.core.oauth.OAuth20Service} - */ - @Deprecated - @Override - public FacebookService createService(String apiKey, String apiSecret, String callback, String scope, - OutputStream debugStream, String state, String responseType, String userAgent, - HttpClientConfig httpClientConfig, HttpClient httpClient) { - return new FacebookService(this, apiKey, apiSecret, callback, scope, state, responseType, userAgent, - httpClientConfig, httpClient); - } - @Override public FacebookService createService(String apiKey, String apiSecret, String callback, String scope, OutputStream debugStream, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - return createService(apiKey, apiSecret, callback, scope, debugStream, null, responseType, userAgent, - httpClientConfig, httpClient); + return new FacebookService(this, apiKey, apiSecret, callback, scope, responseType, userAgent, httpClientConfig, + httpClient); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java index 59d7e3e8d..3e2eddb50 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java @@ -54,34 +54,11 @@ protected String getAuthorizationBaseUrl() { throw new UnsupportedOperationException("use getAuthorizationUrl instead"); } - /** - * @param apiKey apiKey - * @param apiSecret apiSecret - * @param callback callback - * @param scope scope - * @param debugStream debugStream - * @param state state - * @param responseType responseType - * @param userAgent userAgent - * @param httpClientConfig httpClientConfig - * @param httpClient httpClient - * @return return - * @deprecated use one of getAuthorizationUrl method in {@link com.github.scribejava.core.oauth.OAuth20Service} - */ - @Deprecated - @Override - public ImgurOAuthService createService(String apiKey, String apiSecret, String callback, String scope, - OutputStream debugStream, String state, String responseType, String userAgent, - HttpClientConfig httpClientConfig, HttpClient httpClient) { - return new ImgurOAuthService(this, apiKey, apiSecret, callback, scope, state, responseType, userAgent, - httpClientConfig, httpClient); - } - @Override public ImgurOAuthService createService(String apiKey, String apiSecret, String callback, String scope, OutputStream debugStream, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - return createService(apiKey, apiSecret, callback, scope, debugStream, null, responseType, userAgent, + return new ImgurOAuthService(this, apiKey, apiSecret, callback, scope, responseType, userAgent, httpClientConfig, httpClient); } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java index 83419dace..2235301ba 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java @@ -29,34 +29,11 @@ protected String getAuthorizationBaseUrl() { return "https://connect.mail.ru/oauth/authorize"; } - /** - * @param apiKey apiKey - * @param apiSecret apiSecret - * @param callback callback - * @param scope scope - * @param debugStream debugStream - * @param state state - * @param responseType responseType - * @param userAgent userAgent - * @param httpClientConfig httpClientConfig - * @param httpClient httpClient - * @return return - * @deprecated use one of getAuthorizationUrl method in {@link com.github.scribejava.core.oauth.OAuth20Service} - */ - @Deprecated - @Override - public MailruOAuthService createService(String apiKey, String apiSecret, String callback, String scope, - OutputStream debugStream, String state, String responseType, String userAgent, - HttpClientConfig httpClientConfig, HttpClient httpClient) { - return new MailruOAuthService(this, apiKey, apiSecret, callback, scope, state, responseType, userAgent, - httpClientConfig, httpClient); - } - @Override public MailruOAuthService createService(String apiKey, String apiSecret, String callback, String scope, OutputStream debugStream, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - return createService(apiKey, apiSecret, callback, scope, debugStream, null, responseType, userAgent, + return new MailruOAuthService(this, apiKey, apiSecret, callback, scope, responseType, userAgent, httpClientConfig, httpClient); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java index 2e47b007c..1d03bf1af 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java @@ -33,34 +33,11 @@ protected String getAuthorizationBaseUrl() { return "https://connect.ok.ru/oauth/authorize"; } - /** - * @param apiKey apiKey - * @param apiSecret apiSecret - * @param callback callback - * @param scope scope - * @param debugStream debugStream - * @param state state - * @param responseType responseType - * @param userAgent userAgent - * @param httpClientConfig httpClientConfig - * @param httpClient httpClient - * @return return - * @deprecated use one of getAuthorizationUrl method in {@link com.github.scribejava.core.oauth.OAuth20Service} - */ - @Deprecated - @Override - public OdnoklassnikiOAuthService createService(String apiKey, String apiSecret, String callback, String scope, - OutputStream debugStream, String state, String responseType, String userAgent, - HttpClientConfig httpClientConfig, HttpClient httpClient) { - return new OdnoklassnikiOAuthService(this, apiKey, apiSecret, callback, scope, state, responseType, userAgent, - httpClientConfig, httpClient); - } - @Override public OdnoklassnikiOAuthService createService(String apiKey, String apiSecret, String callback, String scope, OutputStream debugStream, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - return createService(apiKey, apiSecret, callback, scope, debugStream, null, responseType, userAgent, + return new OdnoklassnikiOAuthService(this, apiKey, apiSecret, callback, scope, responseType, userAgent, httpClientConfig, httpClient); } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/WunderlistAPI.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/WunderlistAPI.java index 1c6b18e74..6bdcfdf7c 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/WunderlistAPI.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/WunderlistAPI.java @@ -52,30 +52,7 @@ public ClientAuthentication getClientAuthentication() { public OAuth20Service createService(String apiKey, String apiSecret, String callback, String scope, OutputStream debugStream, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - return createService(apiKey, apiSecret, callback, scope, debugStream, null, responseType, userAgent, - httpClientConfig, httpClient); - } - - /** - * @param apiKey apiKey - * @param apiSecret apiSecret - * @param callback callback - * @param scope scope - * @param debugStream debugStream - * @param state state - * @param responseType responseType - * @param userAgent userAgent - * @param httpClientConfig httpClientConfig - * @param httpClient httpClient - * @return return - * @deprecated use one of getAuthorizationUrl method in {@link com.github.scribejava.core.oauth.OAuth20Service} - */ - @Deprecated - @Override - public OAuth20Service createService(String apiKey, String apiSecret, String callback, String scope, - OutputStream debugStream, String state, String responseType, String userAgent, - HttpClientConfig httpClientConfig, HttpClient httpClient) { - return new WunderlistOAuthService(this, apiKey, apiSecret, callback, scope, state, responseType, userAgent, + return new WunderlistOAuthService(this, apiKey, apiSecret, callback, scope, responseType, userAgent, httpClientConfig, httpClient); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookService.java index 97354456e..9ec9c0ceb 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookService.java @@ -13,26 +13,6 @@ public class FacebookService extends OAuth20Service { - /** - * @param api api - * @param apiKey apiKey - * @param apiSecret apiSecret - * @param callback callback - * @param scope scope - * @param state state - * @param responseType responseType - * @param userAgent userAgent - * @param httpClientConfig httpClientConfig - * @param httpClient httpClient - * @deprecated use one of getAuthorizationUrl method in {@link com.github.scribejava.core.oauth.OAuth20Service} - */ - @Deprecated - public FacebookService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, - String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, - HttpClient httpClient) { - super(api, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); - } - public FacebookService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { super(api, apiKey, apiSecret, callback, scope, responseType, userAgent, httpClientConfig, httpClient); diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/imgur/ImgurOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/imgur/ImgurOAuthService.java index f05abfbbf..4c8da3c82 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/imgur/ImgurOAuthService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/imgur/ImgurOAuthService.java @@ -10,26 +10,6 @@ public class ImgurOAuthService extends OAuth20Service { - /** - * @param api api - * @param apiKey apiKey - * @param apiSecret apiSecret - * @param callback callback - * @param scope scope - * @param state state - * @param responseType responseType - * @param userAgent userAgent - * @param httpClientConfig httpClientConfig - * @param httpClient httpClient - * @deprecated use one of getAuthorizationUrl method in {@link com.github.scribejava.core.oauth.OAuth20Service} - */ - @Deprecated - public ImgurOAuthService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, - String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, - HttpClient httpClient) { - super(api, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); - } - public ImgurOAuthService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { super(api, apiKey, apiSecret, callback, scope, responseType, userAgent, httpClientConfig, httpClient); diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/mailru/MailruOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/mailru/MailruOAuthService.java index 99955bf64..37fcab964 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/mailru/MailruOAuthService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/mailru/MailruOAuthService.java @@ -16,32 +16,11 @@ public class MailruOAuthService extends OAuth20Service { - /** - * @param api api - * @param apiKey apiKey - * @param apiSecret apiSecret - * @param callback callback - * @param scope scope - * @param state state - * @param responseType responseType - * @param userAgent userAgent - * @param httpClientConfig httpClientConfig - * @param httpClient httpClient - * @deprecated use one of getAuthorizationUrl method in {@link com.github.scribejava.core.oauth.OAuth20Service} - */ - @Deprecated - public MailruOAuthService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, - String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, - HttpClient httpClient) { - super(api, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); - } - public MailruOAuthService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { super(api, apiKey, apiSecret, callback, scope, responseType, userAgent, httpClientConfig, httpClient); } - @Override public void signRequest(String accessToken, OAuthRequest request) { // sig = md5(params + secret_key) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/odnoklassniki/OdnoklassnikiOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/odnoklassniki/OdnoklassnikiOAuthService.java index d0901f533..f8cb1e3f5 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/odnoklassniki/OdnoklassnikiOAuthService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/odnoklassniki/OdnoklassnikiOAuthService.java @@ -19,26 +19,6 @@ public class OdnoklassnikiOAuthService extends OAuth20Service { - /** - * @param api api - * @param apiKey apiKey - * @param apiSecret apiSecret - * @param callback callback - * @param scope scope - * @param state state - * @param responseType responseType - * @param userAgent userAgent - * @param httpClientConfig httpClientConfig - * @param httpClient httpClient - * @deprecated use one of getAuthorizationUrl method in {@link com.github.scribejava.core.oauth.OAuth20Service} - */ - @Deprecated - public OdnoklassnikiOAuthService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, - String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, - HttpClient httpClient) { - super(api, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); - } - public OdnoklassnikiOAuthService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { super(api, apiKey, apiSecret, callback, scope, responseType, userAgent, httpClientConfig, httpClient); diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/wunderlist/WunderlistOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/wunderlist/WunderlistOAuthService.java index 66766d7e2..b46a0870f 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/wunderlist/WunderlistOAuthService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/wunderlist/WunderlistOAuthService.java @@ -8,26 +8,6 @@ public class WunderlistOAuthService extends OAuth20Service { - /** - * @param api api - * @param apiKey apiKey - * @param apiSecret apiSecret - * @param callback callback - * @param scope scope - * @param state state - * @param responseType responseType - * @param userAgent userAgent - * @param httpClientConfig httpClientConfig - * @param httpClient httpClient - * @deprecated use one of getAuthorizationUrl method in {@link com.github.scribejava.core.oauth.OAuth20Service} - */ - @Deprecated - public WunderlistOAuthService(WunderlistAPI api, String apiKey, String apiSecret, String callback, String scope, - String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, - HttpClient httpClient) { - super(api, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); - } - public WunderlistOAuthService(WunderlistAPI api, String apiKey, String apiSecret, String callback, String scope, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { super(api, apiKey, apiSecret, callback, scope, responseType, userAgent, httpClientConfig, httpClient); diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilder.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilder.java index afcb8a347..254b46e5f 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilder.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilder.java @@ -3,7 +3,6 @@ import com.github.scribejava.core.builder.api.BaseApi; import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.httpclient.HttpClientConfig; -import com.github.scribejava.core.oauth.OAuth20Service; import com.github.scribejava.core.oauth.OAuthService; import com.github.scribejava.core.utils.Preconditions; @@ -18,7 +17,6 @@ public class ServiceBuilder { private String apiKey; private String apiSecret; private String scope; - private String state; private OutputStream debugStream; private String responseType = "code"; private String userAgent; @@ -78,21 +76,6 @@ public ServiceBuilder scope(String scope) { return this; } - /** - * /** - * Configures the anti forgery session state. This is available in some APIs (like Google's). - * - * @param state The OAuth state - * @return the {@link ServiceBuilder} instance for method chaining - * @deprecated use one of getAuthorizationUrl method in {@link com.github.scribejava.core.oauth.OAuth20Service} - */ - @Deprecated - public ServiceBuilder state(String state) { - Preconditions.checkEmptyString(state, "Invalid OAuth state"); - this.state = state; - return this; - } - public ServiceBuilder debugStream(OutputStream debugStream) { Preconditions.checkNotNull(debugStream, "debug stream can't be null"); this.debugStream = debugStream; @@ -140,11 +123,7 @@ public ServiceBuilder debug() { * @return fully configured {@link OAuthService} */ public S build(BaseApi api) { - final S service = api.createService(apiKey, apiSecret, callback, scope, debugStream, responseType, userAgent, + return api.createService(apiKey, apiSecret, callback, scope, debugStream, responseType, userAgent, httpClientConfig, httpClient); - if (service instanceof OAuth20Service) { - ((OAuth20Service) service).setState(state); - } - return service; } } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/BaseApi.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/BaseApi.java index 2ba40e7e1..0ce3377d6 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/BaseApi.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/BaseApi.java @@ -7,25 +7,6 @@ public interface BaseApi { - /** - * @param apiKey apiKey - * @param apiSecret apiSecret - * @param callback callback - * @param scope scope - * @param debugStream debugStream - * @param state state - * @param responseType responseType - * @param userAgent userAgent - * @param httpClientConfig httpClientConfig - * @param httpClient httpClient - * @return return - * @deprecated use one of getAuthorizationUrl method in {@link com.github.scribejava.core.oauth.OAuth20Service} - */ - @Deprecated - T createService(String apiKey, String apiSecret, String callback, String scope, OutputStream debugStream, - String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, - HttpClient httpClient); - T createService(String apiKey, String apiSecret, String callback, String scope, OutputStream debugStream, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient); } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi10a.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi10a.java index 315ab9470..7ef8b572d 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi10a.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi10a.java @@ -143,37 +143,12 @@ public String getAuthorizationUrl(OAuth1RequestToken requestToken) { return parameters.appendTo(getAuthorizationBaseUrl()); } - /** - * @param apiKey apiKey - * @param apiSecret apiSecret - * @param callback callback - * @param scope scope - * @param debugStream debugStream - * @param state state - * @param responseType responseType - * @param userAgent userAgent - * @param httpClientConfig httpClientConfig - * @param httpClient httpClient - * @return return - * @deprecated use {@link #createService(java.lang.String, java.lang.String, java.lang.String, java.lang.String, - * java.io.OutputStream, java.lang.String, java.lang.String, com.github.scribejava.core.httpclient.HttpClientConfig, - * com.github.scribejava.core.httpclient.HttpClient)} - */ - @Deprecated - @Override - public OAuth10aService createService(String apiKey, String apiSecret, String callback, String scope, - OutputStream debugStream, String state, String responseType, String userAgent, - HttpClientConfig httpClientConfig, HttpClient httpClient) { - return new OAuth10aService(this, apiKey, apiSecret, callback, scope, debugStream, userAgent, httpClientConfig, - httpClient); - } - @Override public OAuth10aService createService(String apiKey, String apiSecret, String callback, String scope, OutputStream debugStream, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - return createService(apiKey, apiSecret, callback, scope, debugStream, null, responseType, userAgent, - httpClientConfig, httpClient); + return new OAuth10aService(this, apiKey, apiSecret, callback, scope, debugStream, userAgent, httpClientConfig, + httpClient); } /** diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java index 64d64cba1..e998cde81 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java @@ -110,31 +110,8 @@ public String getAuthorizationUrl(String responseType, String apiKey, String cal public OAuth20Service createService(String apiKey, String apiSecret, String callback, String scope, OutputStream debugStream, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - return createService(apiKey, apiSecret, callback, scope, debugStream, null, responseType, userAgent, - httpClientConfig, httpClient); - } - - /** - * @param apiKey apiKey - * @param apiSecret apiSecret - * @param callback callback - * @param scope scope - * @param debugStream debugStream - * @param state state - * @param responseType responseType - * @param userAgent userAgent - * @param httpClientConfig httpClientConfig - * @param httpClient httpClient - * @return return - * @deprecated use one of getAuthorizationUrl method in {@link com.github.scribejava.core.oauth.OAuth20Service} - */ - @Deprecated - @Override - public OAuth20Service createService(String apiKey, String apiSecret, String callback, String scope, - OutputStream debugStream, String state, String responseType, String userAgent, - HttpClientConfig httpClientConfig, HttpClient httpClient) { - return new OAuth20Service(this, apiKey, apiSecret, callback, scope, state, responseType, userAgent, - httpClientConfig, httpClient); + return new OAuth20Service(this, apiKey, apiSecret, callback, scope, responseType, userAgent, httpClientConfig, + httpClient); } public BearerSignature getBearerSignature() { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/AbstractAsyncOnlyHttpClient.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/AbstractAsyncOnlyHttpClient.java index a54e51a58..48917eb60 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/AbstractAsyncOnlyHttpClient.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/AbstractAsyncOnlyHttpClient.java @@ -18,18 +18,6 @@ public Response execute(String userAgent, Map headers, Verb http (OAuthRequest.ResponseConverter) null).get(); } - /** - * @deprecated {@inheritDoc} - */ - @Override - @Deprecated - public Response execute(String userAgent, Map headers, Verb httpVerb, String completeUrl, - MultipartPayload bodyContents) throws InterruptedException, ExecutionException, IOException { - - return executeAsync(userAgent, headers, httpVerb, completeUrl, bodyContents, null, - (OAuthRequest.ResponseConverter) null).get(); - } - @Override public Response execute(String userAgent, Map headers, Verb httpVerb, String completeUrl, com.github.scribejava.core.httpclient.multipart.MultipartPayload bodyContents) diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/BodyPartPayload.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/BodyPartPayload.java deleted file mode 100644 index 2b349d666..000000000 --- a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/BodyPartPayload.java +++ /dev/null @@ -1,69 +0,0 @@ -package com.github.scribejava.core.httpclient; - -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - -/** - * @deprecated use {@link com.github.scribejava.core.httpclient.multipart.ByteArrayBodyPartPayload} - */ -@Deprecated -public class BodyPartPayload { - - private final Map headers; - private final byte[] payload; - - public BodyPartPayload(Map headers, byte[] payload) { - this.headers = headers; - this.payload = payload; - } - - public BodyPartPayload(String contentDisposition, String contentType, byte[] payload) { - this(createHeadersMap(contentDisposition, contentType), payload); - } - - public BodyPartPayload(String contentDisposition, byte[] payload) { - this(contentDisposition, null, payload); - } - - public Map getHeaders() { - return headers; - } - - /** - * @return return - * @deprecated use {@link #getHeaders() } and then get("Content-Disposition") - */ - @Deprecated - public String getContentDisposition() { - return headers.get("Content-Disposition"); - } - - /** - * @return return - * @deprecated use {@link #getHeaders() } and then get("Content-Type") - */ - @Deprecated - public String getContentType() { - return headers.get(HttpClient.CONTENT_TYPE); - } - - public byte[] getPayload() { - return payload; - } - - private static Map createHeadersMap(String contentDisposition, String contentType) { - if (contentDisposition == null && contentType == null) { - return Collections.emptyMap(); - } - - final Map headers = new HashMap<>(); - if (contentDisposition != null) { - headers.put("Content-Disposition", contentDisposition); - } - if (contentType != null) { - headers.put(HttpClient.CONTENT_TYPE, contentType); - } - return headers; - } -} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/HttpClient.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/HttpClient.java index 4217ac717..821c9b194 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/HttpClient.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/HttpClient.java @@ -21,27 +21,6 @@ public interface HttpClient extends Closeable { Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, byte[] bodyContents, OAuthAsyncRequestCallback callback, OAuthRequest.ResponseConverter converter); - /** - * @param T - * @param userAgent userAgent - * @param headers headers - * @param httpVerb httpVerb - * @param completeUrl completeUrl - * @param bodyContents bodyContents - * @param callback callback - * @param converter converter - * @return return - * - * @deprecated use {@link #executeAsync(java.lang.String, java.util.Map, com.github.scribejava.core.model.Verb, - * java.lang.String, com.github.scribejava.core.httpclient.multipart.MultipartPayload, - * com.github.scribejava.core.model.OAuthAsyncRequestCallback, - * com.github.scribejava.core.model.OAuthRequest.ResponseConverter)} - */ - @Deprecated - Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, - com.github.scribejava.core.httpclient.MultipartPayload bodyContents, OAuthAsyncRequestCallback callback, - OAuthRequest.ResponseConverter converter); - Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, MultipartPayload bodyContents, OAuthAsyncRequestCallback callback, OAuthRequest.ResponseConverter converter); @@ -55,24 +34,6 @@ Future executeAsync(String userAgent, Map headers, Verb h Response execute(String userAgent, Map headers, Verb httpVerb, String completeUrl, byte[] bodyContents) throws InterruptedException, ExecutionException, IOException; - /** - * @param userAgent userAgent - * @param headers headers - * @param httpVerb httpVerb - * @param completeUrl completeUrl - * @param bodyContents bodyContents - * @return return - * @throws InterruptedException InterruptedException - * @throws ExecutionException ExecutionException - * @throws IOException IOException - * @deprecated use {@link #execute(java.lang.String, java.util.Map, com.github.scribejava.core.model.Verb, - * java.lang.String, com.github.scribejava.core.httpclient.multipart.MultipartPayload)} - */ - @Deprecated - Response execute(String userAgent, Map headers, Verb httpVerb, String completeUrl, - com.github.scribejava.core.httpclient.MultipartPayload bodyContents) - throws InterruptedException, ExecutionException, IOException; - Response execute(String userAgent, Map headers, Verb httpVerb, String completeUrl, MultipartPayload bodyContents) throws InterruptedException, ExecutionException, IOException; diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/MultipartPayload.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/MultipartPayload.java deleted file mode 100644 index 3d4016ea1..000000000 --- a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/MultipartPayload.java +++ /dev/null @@ -1,105 +0,0 @@ -package com.github.scribejava.core.httpclient; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Map; - -/** - * The class containing more than one payload of multipart/form-data request - * - * @deprecated use {@link com.github.scribejava.core.httpclient.multipart.MultipartPayload} - */ -@Deprecated -public class MultipartPayload { - - private static final String DEFAULT_SUBTYPE = "form-data"; - - private final String boundary; - private final Map headers; - private final List bodyParts = new ArrayList<>(); - - public MultipartPayload(String boundary) { - this.boundary = boundary; - headers = Collections.singletonMap(HttpClient.CONTENT_TYPE, - "multipart/" + DEFAULT_SUBTYPE + "; boundary=\"" + boundary + '"'); - } - - /** - * @param bodyPart bodyPart - * @return return - * @deprecated no replace for that. implement yourself. See code here - * {@link com.github.scribejava.core.httpclient.jdk.JDKHttpClient - * #getPayload(com.github.scribejava.core.httpclient.MultipartPayload)} - */ - @Deprecated - public byte[] getStartBoundary(BodyPartPayload bodyPart) { - final StringBuilder startBoundary = new StringBuilder(); - startBoundary.append("\r\n--") - .append(boundary) - .append("\r\n"); - - for (Map.Entry header : bodyPart.getHeaders().entrySet()) { - startBoundary.append(header.getKey()) - .append(": ") - .append(header.getValue()) - .append("\r\n"); - } - return startBoundary.append("\r\n").toString().getBytes(); - } - - /** - * @return return - * @deprecated no replace for that. implement yourself. See code here - * {@link com.github.scribejava.core.httpclient.jdk.JDKHttpClient - * #getPayload(com.github.scribejava.core.httpclient.MultipartPayload)} - */ - @Deprecated - public byte[] getEndBoundary() { - return ("\r\n--" + boundary + "--\r\n").getBytes(); - } - - /** - * @return return - * @deprecated no replace for that. implement yourself. See code here - * {@link com.github.scribejava.core.httpclient.jdk.JDKHttpClient - * #getPayload(com.github.scribejava.core.httpclient.MultipartPayload)} - */ - @Deprecated - public int getContentLength() { - int contentLength = 0; - - for (BodyPartPayload bodyPart : bodyParts) { - contentLength += getStartBoundary(bodyPart).length + bodyPart.getPayload().length; - } - if (!bodyParts.isEmpty()) { - contentLength += getEndBoundary().length; - } - return contentLength; - } - - public List getBodyParts() { - return bodyParts; - } - - public void addMultipartPayload(String contentDisposition, String contentType, byte[] payload) { - bodyParts.add(new BodyPartPayload(contentDisposition, contentType, payload)); - } - - /** - * @return return - * @deprecated use {@link #getHeaders() } and then get("Content-Type") - */ - @Deprecated - public String getContentType() { - return headers.get(HttpClient.CONTENT_TYPE); - } - - public Map getHeaders() { - return headers; - } - - public String getBoundary() { - return boundary; - } -} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java index b13186603..ee459cf51 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java @@ -47,19 +47,6 @@ public Future executeAsync(String userAgent, Map headers, converter); } - /** - * @deprecated {@inheritDoc} - */ - @Override - @Deprecated - public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, - com.github.scribejava.core.httpclient.MultipartPayload bodyContents, OAuthAsyncRequestCallback callback, - OAuthRequest.ResponseConverter converter) { - - return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, BodyType.OLD_MULTIPART, bodyContents, callback, - converter); - } - @Override public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, MultipartPayload bodyContents, OAuthAsyncRequestCallback callback, @@ -114,17 +101,6 @@ public Response execute(String userAgent, Map headers, Verb http return doExecute(userAgent, headers, httpVerb, completeUrl, BodyType.MULTIPART, multipartPayloads); } - /** - * @deprecated {@inheritDoc} - */ - @Override - @Deprecated - public Response execute(String userAgent, Map headers, Verb httpVerb, String completeUrl, - com.github.scribejava.core.httpclient.MultipartPayload multipartPayloads) - throws InterruptedException, ExecutionException, IOException { - return doExecute(userAgent, headers, httpVerb, completeUrl, BodyType.OLD_MULTIPART, multipartPayloads); - } - @Override public Response execute(String userAgent, Map headers, Verb httpVerb, String completeUrl, String bodyContents) throws InterruptedException, ExecutionException, IOException { @@ -171,13 +147,6 @@ void setBody(HttpURLConnection connection, Object bodyContents, boolean requires addBody(connection, (byte[]) bodyContents, requiresBody); } }, - OLD_MULTIPART { - @Override - void setBody(HttpURLConnection connection, Object bodyContents, boolean requiresBody) throws IOException { - addBody(connection, (com.github.scribejava.core.httpclient.MultipartPayload) bodyContents, - requiresBody); - } - }, MULTIPART { @Override void setBody(HttpURLConnection connection, Object bodyContents, boolean requiresBody) throws IOException { @@ -227,23 +196,6 @@ private static void addBody(HttpURLConnection connection, byte[] content, boolea } } - private static void addBody(HttpURLConnection connection, - com.github.scribejava.core.httpclient.MultipartPayload multipartPayload, boolean requiresBody) - throws IOException { - - for (Map.Entry header : multipartPayload.getHeaders().entrySet()) { - connection.setRequestProperty(header.getKey(), header.getValue()); - } - - if (requiresBody) { - final ByteArrayOutputStream os = getPayload(multipartPayload); - - if (os.size() > 0) { - os.writeTo(prepareConnectionForBodyAndGetOutputStream(connection, os.size())); - } - } - } - private static void addBody(HttpURLConnection connection, MultipartPayload multipartPayload, boolean requiresBody) throws IOException { @@ -260,29 +212,6 @@ private static void addBody(HttpURLConnection connection, MultipartPayload multi } } - private static ByteArrayOutputStream getPayload( - com.github.scribejava.core.httpclient.MultipartPayload multipartPayload) throws IOException { - final ByteArrayOutputStream os = new ByteArrayOutputStream(); - final List bodyParts = multipartPayload.getBodyParts(); - if (!bodyParts.isEmpty()) { - final String boundary = multipartPayload.getBoundary(); - final byte[] startBoundary = ("\r\n--" + boundary + "\r\n").getBytes(); - - for (com.github.scribejava.core.httpclient.BodyPartPayload bodyPart : bodyParts) { - os.write(startBoundary); - - for (Map.Entry header : bodyPart.getHeaders().entrySet()) { - os.write((header.getKey() + ": " + header.getValue() + "\r\n").getBytes()); - } - os.write("\r\n".getBytes()); - os.write(bodyPart.getPayload()); - } - - os.write(("\r\n--" + boundary + "--\r\n").getBytes()); - } - return os; - } - static ByteArrayOutputStream getPayload(MultipartPayload multipartPayload) throws IOException { final ByteArrayOutputStream os = new ByteArrayOutputStream(); diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequest.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequest.java index 606577fbb..ca6a32bf0 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequest.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequest.java @@ -31,7 +31,6 @@ public class OAuthRequest { private String stringPayload; private byte[] byteArrayPayload; private File filePayload; - private com.github.scribejava.core.httpclient.MultipartPayload oldMultipartPayload; private MultipartPayload multipartPayload; private final Map oauthParameters = new HashMap<>(); @@ -129,71 +128,10 @@ public void addParameter(String key, String value) { } } - /** - * @param boundary boundary - * @deprecated create {@link #initMultipartPayload(java.lang.String) } - */ - @Deprecated - public void initMultipartBoundary(String boundary) { - oldMultipartPayload = new com.github.scribejava.core.httpclient.MultipartPayload(boundary == null - ? Long.toString(System.currentTimeMillis()) - : boundary); - } - - /** - * @deprecated use {@link #initMultipartPayload()} - */ - @Deprecated - public void initMultipartBoundary() { - initMultipartBoundary(null); - } - - /** - * @param contentDisposition contentDisposition - * @param contentType contentType - * @param payload payload - * @deprecated use {@link #addFileByteArrayBodyPartPayloadInMultipartPayload(java.lang.String, byte[], - * java.lang.String, java.lang.String)} - */ - @Deprecated - public void addMultipartPayload(String contentDisposition, String contentType, byte[] payload) { - if (oldMultipartPayload == null) { - initMultipartBoundary(); - } - oldMultipartPayload.addMultipartPayload(contentDisposition, contentType, payload); - } - public MultipartPayload getMultipartPayload() { return multipartPayload; } - /** - * @param contentDisposition contentDisposition - * @param contentType contentType - * @param payload payload - * @deprecated use {@link #setFileByteArrayBodyPartPayloadInMultipartPayload(java.lang.String, byte[], - * java.lang.String, java.lang.String)} - */ - @Deprecated - public void setMultipartPayload(String contentDisposition, String contentType, byte[] payload) { - setMultipartPayload(null, contentDisposition, contentType, payload); - } - - /** - * @param boundary boundary - * @param contentDisposition contentDisposition - * @param contentType contentType - * @param payload payload - * @deprecated use {@link #initMultipartPayload(java.lang.String) } - * and then {@link #setFileByteArrayBodyPartPayloadInMultipartPayload(java.lang.String, byte[], java.lang.String, - * java.lang.String)} - */ - @Deprecated - public void setMultipartPayload(String boundary, String contentDisposition, String contentType, byte[] payload) { - initMultipartBoundary(boundary); - oldMultipartPayload.addMultipartPayload(contentDisposition, contentType, payload); - } - public void setMultipartPayload(MultipartPayload multipartPayload) { this.multipartPayload = multipartPayload; } @@ -351,7 +289,6 @@ private void resetPayload() { stringPayload = null; byteArrayPayload = null; filePayload = null; - oldMultipartPayload = null; multipartPayload = null; } @@ -431,15 +368,6 @@ public byte[] getByteArrayPayload() { } } - /** - * @return return - * @deprecated use {@link #getMultipartPayload() } - */ - @Deprecated - public com.github.scribejava.core.httpclient.MultipartPayload getMultipartPayloads() { - return oldMultipartPayload; - } - public File getFilePayload() { return filePayload; } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java index d3fe22912..9c2a1aef3 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java @@ -27,28 +27,6 @@ public class OAuth20Service extends OAuthService { private static final PKCEService PKCE_SERVICE = new PKCEService(); private final DefaultApi20 api; private final String responseType; - private String state; - - /** - * @param api api - * @param apiKey apiKey - * @param apiSecret apiSecret - * @param callback callback - * @param scope scope - * @param state state - * @param responseType responseType - * @param userAgent userAgent - * @param httpClientConfig httpClientConfig - * @param httpClient httpClient - * @deprecated use one of getAuthorizationUrl method in {@link com.github.scribejava.core.oauth.OAuth20Service} - */ - @Deprecated - public OAuth20Service(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, - String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, - HttpClient httpClient) { - this(api, apiKey, apiSecret, callback, scope, responseType, userAgent, httpClientConfig, httpClient); - this.state = state; - } public OAuth20Service(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { @@ -281,7 +259,7 @@ public void signRequest(OAuth2AccessToken accessToken, OAuthRequest request) { } public AuthorizationUrlWithPKCE getAuthorizationUrlWithPKCE() { - return getAuthorizationUrlWithPKCE(getState()); + return getAuthorizationUrlWithPKCE(null, null); } public AuthorizationUrlWithPKCE getAuthorizationUrlWithPKCE(String state) { @@ -289,7 +267,7 @@ public AuthorizationUrlWithPKCE getAuthorizationUrlWithPKCE(String state) { } public AuthorizationUrlWithPKCE getAuthorizationUrlWithPKCE(Map additionalParams) { - return getAuthorizationUrlWithPKCE(getState(), additionalParams); + return getAuthorizationUrlWithPKCE(null, additionalParams); } public AuthorizationUrlWithPKCE getAuthorizationUrlWithPKCE(String state, Map additionalParams) { @@ -303,7 +281,7 @@ public AuthorizationUrlWithPKCE getAuthorizationUrlWithPKCE(String state, Map additionalParams) { - return getAuthorizationUrl(getState(), additionalParams); + return getAuthorizationUrl(null, additionalParams); } public String getAuthorizationUrl(String state, Map additionalParams) { @@ -325,7 +303,7 @@ public String getAuthorizationUrl(String state, Map additionalPa } public String getAuthorizationUrl(PKCE pkce) { - return getAuthorizationUrl(getState(), pkce); + return getAuthorizationUrl(null, null, pkce); } public String getAuthorizationUrl(String state, PKCE pkce) { @@ -333,7 +311,7 @@ public String getAuthorizationUrl(String state, PKCE pkce) { } public String getAuthorizationUrl(Map additionalParams, PKCE pkce) { - return getAuthorizationUrl(getState(), additionalParams, pkce); + return getAuthorizationUrl(null, additionalParams, pkce); } public String getAuthorizationUrl(String state, Map additionalParams, PKCE pkce) { @@ -431,22 +409,4 @@ public OAuth2Authorization extractAuthorization(String redirectLocation) { public String getResponseType() { return responseType; } - - /** - * @return state - * @deprecated use one of getAuthorizationUrl method in {@link com.github.scribejava.core.oauth.OAuth20Service} - */ - @Deprecated - public String getState() { - return state; - } - - /** - * @param state state - * @deprecated use one of getAuthorizationUrl method in {@link com.github.scribejava.core.oauth.OAuth20Service} - */ - @Deprecated - public void setState(String state) { - this.state = state; - } } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java index 94aaa4c38..cc9d7ad09 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java @@ -113,9 +113,6 @@ public Response execute(OAuthRequest request) throws InterruptedException, Execu } else if (request.getMultipartPayload() != null) { return httpClient.execute(userAgent, request.getHeaders(), request.getVerb(), request.getCompleteUrl(), request.getMultipartPayload()); - } else if (request.getMultipartPayloads() != null) { - return httpClient.execute(userAgent, request.getHeaders(), request.getVerb(), request.getCompleteUrl(), - request.getMultipartPayloads()); } else { return httpClient.execute(userAgent, request.getHeaders(), request.getVerb(), request.getCompleteUrl(), request.getByteArrayPayload()); diff --git a/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/AhcHttpClient.java b/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/AhcHttpClient.java index 877d1e1f2..882293a43 100644 --- a/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/AhcHttpClient.java +++ b/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/AhcHttpClient.java @@ -48,18 +48,6 @@ public Future executeAsync(String userAgent, Map headers, converter); } - /** - * @deprecated {@inheritDoc} - */ - @Override - @Deprecated - public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, - com.github.scribejava.core.httpclient.MultipartPayload bodyContents, OAuthAsyncRequestCallback callback, - OAuthRequest.ResponseConverter converter) { - - throw new UnsupportedOperationException("AhcHttpClient does not support MultipartPayload yet."); - } - @Override public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, MultipartPayload bodyContents, OAuthAsyncRequestCallback callback, diff --git a/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/ApacheHttpClient.java b/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/ApacheHttpClient.java index 168376604..8c204e67b 100644 --- a/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/ApacheHttpClient.java +++ b/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/ApacheHttpClient.java @@ -54,18 +54,6 @@ public Future executeAsync(String userAgent, Map headers, return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, entity, callback, converter); } - /** - * @deprecated {@inheritDoc} - */ - @Override - @Deprecated - public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, - com.github.scribejava.core.httpclient.MultipartPayload bodyContents, OAuthAsyncRequestCallback callback, - OAuthRequest.ResponseConverter converter) { - - throw new UnsupportedOperationException("ApacheHttpClient does not support MultipartPayload yet."); - } - @Override public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, MultipartPayload bodyContents, OAuthAsyncRequestCallback callback, diff --git a/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/NingHttpClient.java b/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/NingHttpClient.java index 6b065a4db..cc8c6fcda 100644 --- a/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/NingHttpClient.java +++ b/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/NingHttpClient.java @@ -54,18 +54,6 @@ public Future executeAsync(String userAgent, Map headers, converter); } - /** - * @deprecated {@inheritDoc} - */ - @Override - @Deprecated - public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, - com.github.scribejava.core.httpclient.MultipartPayload bodyContents, OAuthAsyncRequestCallback callback, - OAuthRequest.ResponseConverter converter) { - - throw new UnsupportedOperationException("NingHttpClient does not support MultipartPayload yet."); - } - @Override public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, MultipartPayload bodyContents, OAuthAsyncRequestCallback callback, diff --git a/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java b/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java index 18ae14b13..4f3e7e434 100644 --- a/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java +++ b/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java @@ -60,18 +60,6 @@ public Future executeAsync(String userAgent, Map headers, converter); } - /** - * @deprecated {@inheritDoc} - */ - @Override - @Deprecated - public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, - com.github.scribejava.core.httpclient.MultipartPayload bodyContents, OAuthAsyncRequestCallback callback, - OAuthRequest.ResponseConverter converter) { - - throw new UnsupportedOperationException("OKHttpClient does not support Multipart payload for the moment"); - } - @Override public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, MultipartPayload bodyContents, OAuthAsyncRequestCallback callback, @@ -119,18 +107,6 @@ public Response execute(String userAgent, Map headers, Verb http throw new UnsupportedOperationException("OKHttpClient does not support Multipart payload for the moment"); } - /** - * @deprecated {@inheritDoc} - */ - @Override - @Deprecated - public Response execute(String userAgent, Map headers, Verb httpVerb, String completeUrl, - com.github.scribejava.core.httpclient.MultipartPayload bodyContents) - throws InterruptedException, ExecutionException, IOException { - - throw new UnsupportedOperationException("OKHttpClient does not support Multipart payload for the moment"); - } - @Override public Response execute(String userAgent, Map headers, Verb httpVerb, String completeUrl, String bodyContents) throws InterruptedException, ExecutionException, IOException { From 111cb9dfe9a865741e57ac6e7c75f75bee28e0c4 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 18 Feb 2019 16:54:55 +0300 Subject: [PATCH 566/882] Create donate.md --- donate.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 donate.md diff --git a/donate.md b/donate.md new file mode 100644 index 000000000..634494bf1 --- /dev/null +++ b/donate.md @@ -0,0 +1 @@ +[![Donate with PayPal button](https://www.paypalobjects.com/en_US/RU/i/btn/btn_donateCC_LG.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=E3XAUM2ET2R3Y&source=url) From 9cadb25558fcca952e7efa40aa60009bcd5cc40f Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 18 Feb 2019 17:36:14 +0300 Subject: [PATCH 567/882] Update donate.md --- donate.md | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/donate.md b/donate.md index 634494bf1..ccc9d44c6 100644 --- a/donate.md +++ b/donate.md @@ -1 +1,13 @@ -[![Donate with PayPal button](https://www.paypalobjects.com/en_US/RU/i/btn/btn_donateCC_LG.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=E3XAUM2ET2R3Y&source=url) +You can now help ScribeJava not only by Pull Requests. + +You can use [https://paypal.me/kullfar](https://paypal.me/kullfar) directly + +or try donation button from PayPal: [![Donate with PayPal button](https://www.paypalobjects.com/en_US/RU/i/btn/btn_donateCC_LG.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=E3XAUM2ET2R3Y&source=url) + +Thanks in advance! + +ps.If you can't for any reason to use above methods, let me know, we will find the way out. + +Hall of fame "Donors" (in alphabetical order, if you don't want to be here, just put a note along with the donation): +1.Be the first one! +2.Your name can be here. From 414e1f531682eb3f572e946c42b520179652a962 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 18 Feb 2019 17:37:10 +0300 Subject: [PATCH 568/882] Update donate.md --- donate.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/donate.md b/donate.md index ccc9d44c6..55a937059 100644 --- a/donate.md +++ b/donate.md @@ -8,6 +8,6 @@ Thanks in advance! ps.If you can't for any reason to use above methods, let me know, we will find the way out. -Hall of fame "Donors" (in alphabetical order, if you don't want to be here, just put a note along with the donation): -1.Be the first one! +Hall of fame "Donors" (in alphabetical order, if you don't want to be here, just put a note along with the donation):
    +1.Be the first one!
    2.Your name can be here. From 76c6e157054da0aaf342c17cb996a8b2f97cdbde Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 18 Feb 2019 17:38:42 +0300 Subject: [PATCH 569/882] Update donate.md --- donate.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/donate.md b/donate.md index 55a937059..01974ea63 100644 --- a/donate.md +++ b/donate.md @@ -6,7 +6,7 @@ or try donation button from PayPal: [![Donate with PayPal button](https://www.pa Thanks in advance! -ps.If you can't for any reason to use above methods, let me know, we will find the way out. +ps.If you can't for any reason use above methods, let me know, we will find the way out. Hall of fame "Donors" (in alphabetical order, if you don't want to be here, just put a note along with the donation):
    1.Be the first one!
    From b5933c898939df9b984ada761fe51d5a94de0e9e Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 18 Feb 2019 17:42:37 +0300 Subject: [PATCH 570/882] Update README.md --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e0e5cc2dd..35cff6c1f 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Welcome to the home of ScribeJava, the simple OAuth client Java lib! -[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.github.scribejava/scribejava/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.github.scribejava/scribejava) +[![Donate](https://www.paypalobjects.com/en_US/RU/i/btn/btn_donateCC_LG.gif)](https://github.com/scribejava/scribejava/blob/master/donate.md) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.github.scribejava/scribejava/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.github.scribejava/scribejava) # Why use ScribeJava? @@ -141,6 +141,10 @@ And in case you need just core classes (that's it, without any external API (FB,
    ``` +## How can I help ScribeJava + +First of all, Pull Requests are welcome, Second option is [donations](https://github.com/scribejava/scribejava/blob/master/donate.md). + ## Getting started in less than 2 minutes Check the [Getting Started](https://github.com/scribejava/scribejava/wiki/getting-started) page and start rocking! Please Read the [FAQ](https://github.com/scribejava/scribejava/wiki/faq) before creating an issue :) From 086c700824cf662801290a46656421facc4c5941 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 18 Feb 2019 17:43:37 +0300 Subject: [PATCH 571/882] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 35cff6c1f..b7b8838de 100644 --- a/README.md +++ b/README.md @@ -143,7 +143,7 @@ And in case you need just core classes (that's it, without any external API (FB, ## How can I help ScribeJava -First of all, Pull Requests are welcome, Second option is [donations](https://github.com/scribejava/scribejava/blob/master/donate.md). +First of all, Pull Requests are welcome, the second option is [donations](https://github.com/scribejava/scribejava/blob/master/donate.md). ## Getting started in less than 2 minutes From bfd7bf6651561c9a01a660f6cf2f4cd36a024658 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 18 Feb 2019 18:00:42 +0300 Subject: [PATCH 572/882] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index b7b8838de..654d83dd8 100644 --- a/README.md +++ b/README.md @@ -149,6 +149,8 @@ First of all, Pull Requests are welcome, the second option is [donations](https: Check the [Getting Started](https://github.com/scribejava/scribejava/wiki/getting-started) page and start rocking! Please Read the [FAQ](https://github.com/scribejava/scribejava/wiki/faq) before creating an issue :) +Some useful info and answers you can find on the [wiki](https://github.com/scribejava/scribejava/wiki) + Also, remember to read the [fantastic tutorial](http://akoskm.github.io/2015/07/31/twitter-sign-in-for-web-apps.html) that [@akoskm](https://twitter.com/akoskm) wrote to easily integrate a server side app with an API (twitter in this case). ## Questions? From dc6290b466444fbb821ad35855fe8114c750f976 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 22 Feb 2019 12:50:39 +0300 Subject: [PATCH 573/882] Update donate.md --- donate.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/donate.md b/donate.md index 01974ea63..50f782838 100644 --- a/donate.md +++ b/donate.md @@ -9,5 +9,5 @@ Thanks in advance! ps.If you can't for any reason use above methods, let me know, we will find the way out. Hall of fame "Donors" (in alphabetical order, if you don't want to be here, just put a note along with the donation):
    -1.Be the first one!
    +1.Douglas Ross from USA
    2.Your name can be here. From bfc1cb4ccc950a200424930f6d92e7f68ba50b3c Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 25 Feb 2019 13:50:06 +0300 Subject: [PATCH 574/882] support TLS 1.3 in JDK 11 for Salesforce --- changelog | 3 ++ .../github/scribejava/apis/SalesforceApi.java | 35 +++++++------------ .../apis/examples/SalesforceExample.java | 2 +- .../examples/SalesforceNingAsyncExample.java | 2 +- 4 files changed, 18 insertions(+), 24 deletions(-) diff --git a/changelog b/changelog index 89a311974..0e81fe569 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,6 @@ +[SNAPSHOT] + * support TLS 1.3 in JDK 11 for Salesforce + [6.3.0] * fix Muplipart request model and implement it for a jdk HTTP client (thanks to https://github.com/NTPape) * remove any Google+ mention (switch to clean Google OAuth2) (thanks to https://github.com/fvasco) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/SalesforceApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/SalesforceApi.java index afd2eae5f..57cdd32ac 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/SalesforceApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/SalesforceApi.java @@ -12,6 +12,7 @@ import java.io.IOException; import java.security.KeyManagementException; import java.security.NoSuchAlgorithmException; +import java.util.Arrays; import javax.net.ssl.SSLSocket; /** @@ -84,7 +85,7 @@ public TokenExtractor getAccessTokenExtractor() { private static boolean isTLSv11orUpperEnabled(final SSLSocket socket) { for (String protocol : socket.getEnabledProtocols()) { - if ("TLSv1.2".equals(protocol) || "TLSv1.1".equals(protocol)) { + if (protocol.startsWith("TLSv1.")) { return true; } } @@ -97,7 +98,7 @@ private static boolean isTLSv11orUpperEnabled(final SSLSocket socket) { * Java 8 have TLS 1.2 enabled by default. java 7 - no, you should invoke this method or turn TLS>=1.1 somehow * else

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

    + * + * In case you're requesting always the same scope,
    + * you can just set it here and do not provide scope param nowhere more. + * + * @param defaultScope The OAuth scope, used as deafult + * @return the {@link ServiceBuilder} instance for method chaining + */ + ServiceBuilderOAuth20 defaultScope(String defaultScope); + + OAuth20Service build(DefaultApi20 api); +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/AccessTokenRequestParams.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/AccessTokenRequestParams.java new file mode 100644 index 000000000..787ead8a7 --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/AccessTokenRequestParams.java @@ -0,0 +1,37 @@ +package com.github.scribejava.core.oauth; + +public class AccessTokenRequestParams { + private final String code; + private String pkceCodeVerifier; + private String scope; + + public AccessTokenRequestParams(String code) { + this.code = code; + } + + public static AccessTokenRequestParams create(String code) { + return new AccessTokenRequestParams(code); + } + + public AccessTokenRequestParams pkceCodeVerifier(String pkceCodeVerifier) { + this.pkceCodeVerifier = pkceCodeVerifier; + return this; + } + + public AccessTokenRequestParams scope(String scope) { + this.scope = scope; + return this; + } + + public String getCode() { + return code; + } + + public String getPkceCodeVerifier() { + return pkceCodeVerifier; + } + + public String getScope() { + return scope; + } +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/AuthorizationUrlBuilder.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/AuthorizationUrlBuilder.java new file mode 100644 index 000000000..fd02f60dd --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/AuthorizationUrlBuilder.java @@ -0,0 +1,61 @@ +package com.github.scribejava.core.oauth; + +import com.github.scribejava.core.pkce.PKCE; +import com.github.scribejava.core.pkce.PKCEService; +import java.util.HashMap; +import java.util.Map; + +public class AuthorizationUrlBuilder { + + private final OAuth20Service oauth20Service; + + private String state; + private Map additionalParams; + private PKCE pkce; + private String scope; + + public AuthorizationUrlBuilder(OAuth20Service oauth20Service) { + this.oauth20Service = oauth20Service; + } + + public AuthorizationUrlBuilder state(String state) { + this.state = state; + return this; + } + + public AuthorizationUrlBuilder additionalParams(Map additionalParams) { + this.additionalParams = additionalParams; + return this; + } + + public AuthorizationUrlBuilder pkce(PKCE pkce) { + this.pkce = pkce; + return this; + } + + public AuthorizationUrlBuilder initPKCE() { + this.pkce = PKCEService.defaultInstance().generatePKCE(); + return this; + } + + public AuthorizationUrlBuilder scope(String scope) { + this.scope = scope; + return this; + } + + public PKCE getPkce() { + return pkce; + } + + public String build() { + final Map params; + if (pkce == null) { + params = additionalParams; + } else { + params = additionalParams == null ? new HashMap() : new HashMap<>(additionalParams); + params.putAll(pkce.getAuthorizationUrlParams()); + } + return oauth20Service.getApi().getAuthorizationUrl(oauth20Service.getResponseType(), oauth20Service.getApiKey(), + oauth20Service.getCallback(), scope == null ? oauth20Service.getDefaultScope() : scope, state, params); + } +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java index 2b85f7b47..2d571f9cc 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java @@ -15,8 +15,6 @@ import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.pkce.AuthorizationUrlWithPKCE; import com.github.scribejava.core.pkce.PKCE; -import com.github.scribejava.core.pkce.PKCEService; -import java.util.HashMap; import java.util.Map; import java.util.concurrent.ExecutionException; import com.github.scribejava.core.revoke.TokenTypeHint; @@ -63,14 +61,36 @@ public Future getAccessTokenAsync(String code) { return getAccessToken(code, null, null); } + /** + * @param code code + * @param pkceCodeVerifier pkceCodeVerifier + * @return future + * @deprecated use {@link #getAccessTokenAsync(com.github.scribejava.core.oauth.AccessTokenRequestParams) } + */ + @Deprecated public Future getAccessTokenAsync(String code, String pkceCodeVerifier) { return getAccessToken(code, null, pkceCodeVerifier); } + public Future getAccessTokenAsync(AccessTokenRequestParams params) { + return getAccessToken(params, null); + } + public OAuth2AccessToken getAccessToken(String code) throws IOException, InterruptedException, ExecutionException { return getAccessToken(code, (String) null); } + /** + * @param code code + * @param pkceCodeVerifier pkceCodeVerifier + * @return token + * @throws IOException IOException + * @throws InterruptedException InterruptedException + * @throws ExecutionException ExecutionException + * + * @deprecated use {@link #getAccessToken(com.github.scribejava.core.oauth.AccessTokenRequestParams) } + */ + @Deprecated public OAuth2AccessToken getAccessToken(String code, String pkceCodeVerifier) throws IOException, InterruptedException, ExecutionException { final OAuthRequest request = createAccessTokenRequest(code, pkceCodeVerifier); @@ -78,15 +98,34 @@ public OAuth2AccessToken getAccessToken(String code, String pkceCodeVerifier) return sendAccessTokenRequestSync(request); } + public OAuth2AccessToken getAccessToken(AccessTokenRequestParams params) + throws IOException, InterruptedException, ExecutionException { + return sendAccessTokenRequestSync(createAccessTokenRequest(params)); + } + /** * Start the request to retrieve the access token. The optionally provided callback will be called with the Token * when it is available. * - * @param code code + * @param params params * @param callback optional callback - * @param pkceCodeVerifier pkce Code Verifier * @return Future */ + public Future getAccessToken(AccessTokenRequestParams params, + OAuthAsyncRequestCallback callback) { + return sendAccessTokenRequestAsync(createAccessTokenRequest(params), callback); + } + + /** + * @param code code + * @param callback callback + * @param pkceCodeVerifier pkceCodeVerifier + * @return future + * + * @deprecated use {@link #getAccessToken(com.github.scribejava.core.oauth.AccessTokenRequestParams, + * com.github.scribejava.core.model.OAuthAsyncRequestCallback) } + */ + @Deprecated public Future getAccessToken(String code, OAuthAsyncRequestCallback callback, String pkceCodeVerifier) { final OAuthRequest request = createAccessTokenRequest(code, pkceCodeVerifier); @@ -100,25 +139,49 @@ public Future getAccessToken(String code, return getAccessToken(code, callback, null); } + /** + * @param code code + * @return request + * + * @deprecated use {@link #createAccessTokenRequest(com.github.scribejava.core.oauth.AccessTokenRequestParams)} + */ + @Deprecated protected OAuthRequest createAccessTokenRequest(String code) { + return createAccessTokenRequest(AccessTokenRequestParams.create(code)); + } + + /** + * + * @param code code + * @param pkceCodeVerifier pkceCodeVerifier + * @return request + * + * @deprecated use {@link #createAccessTokenRequest(com.github.scribejava.core.oauth.AccessTokenRequestParams)} + */ + @Deprecated + protected OAuthRequest createAccessTokenRequest(String code, String pkceCodeVerifier) { + return createAccessTokenRequest(AccessTokenRequestParams.create(code).pkceCodeVerifier(pkceCodeVerifier)); + } + + protected OAuthRequest createAccessTokenRequest(AccessTokenRequestParams params) { final OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint()); api.getClientAuthentication().addClientAuthentication(request, getApiKey(), getApiSecret()); - request.addParameter(OAuthConstants.CODE, code); + request.addParameter(OAuthConstants.CODE, params.getCode()); final String callback = getCallback(); if (callback != null) { request.addParameter(OAuthConstants.REDIRECT_URI, callback); } - if (defaultScope != null) { + final String scope = params.getScope(); + if (scope != null) { + request.addParameter(OAuthConstants.SCOPE, scope); + } else if (defaultScope != null) { request.addParameter(OAuthConstants.SCOPE, defaultScope); } request.addParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.AUTHORIZATION_CODE); - return request; - } - protected OAuthRequest createAccessTokenRequest(String code, String pkceCodeVerifier) { - final OAuthRequest request = createAccessTokenRequest(code); + final String pkceCodeVerifier = params.getPkceCodeVerifier(); if (pkceCodeVerifier != null) { request.addParameter(PKCE.PKCE_CODE_VERIFIER_PARAM, pkceCodeVerifier); } @@ -126,7 +189,11 @@ protected OAuthRequest createAccessTokenRequest(String code, String pkceCodeVeri } public Future refreshAccessTokenAsync(String refreshToken) { - return refreshAccessToken(refreshToken, null); + return refreshAccessToken(refreshToken, (OAuthAsyncRequestCallback) null); + } + + public Future refreshAccessTokenAsync(String refreshToken, String scope) { + return refreshAccessToken(refreshToken, scope, null); } public OAuth2AccessToken refreshAccessToken(String refreshToken) @@ -136,6 +203,13 @@ public OAuth2AccessToken refreshAccessToken(String refreshToken) return sendAccessTokenRequestSync(request); } + public OAuth2AccessToken refreshAccessToken(String refreshToken, String scope) + throws IOException, InterruptedException, ExecutionException { + final OAuthRequest request = createRefreshTokenRequest(refreshToken, scope); + + return sendAccessTokenRequestSync(request); + } + public Future refreshAccessToken(String refreshToken, OAuthAsyncRequestCallback callback) { final OAuthRequest request = createRefreshTokenRequest(refreshToken); @@ -143,7 +217,25 @@ public Future refreshAccessToken(String refreshToken, return sendAccessTokenRequestAsync(request, callback); } + public Future refreshAccessToken(String refreshToken, String scope, + OAuthAsyncRequestCallback callback) { + final OAuthRequest request = createRefreshTokenRequest(refreshToken, scope); + + return sendAccessTokenRequestAsync(request, callback); + } + + /** + * @param refreshToken refreshToken + * @return request + * + * @deprecated use {@link #createRefreshTokenRequest(java.lang.String, java.lang.String) } + */ + @Deprecated protected OAuthRequest createRefreshTokenRequest(String refreshToken) { + return createRefreshTokenRequest(refreshToken, null); + } + + protected OAuthRequest createRefreshTokenRequest(String refreshToken, String scope) { if (refreshToken == null || refreshToken.isEmpty()) { throw new IllegalArgumentException("The refreshToken cannot be null or empty"); } @@ -151,7 +243,9 @@ protected OAuthRequest createRefreshTokenRequest(String refreshToken) { api.getClientAuthentication().addClientAuthentication(request, getApiKey(), getApiSecret()); - if (defaultScope != null) { + if (scope != null) { + request.addParameter(OAuthConstants.SCOPE, scope); + } else if (defaultScope != null) { request.addParameter(OAuthConstants.SCOPE, defaultScope); } @@ -167,8 +261,19 @@ public OAuth2AccessToken getAccessTokenPasswordGrant(String uname, String passwo return sendAccessTokenRequestSync(request); } + public OAuth2AccessToken getAccessTokenPasswordGrant(String uname, String password, String scope) + throws IOException, InterruptedException, ExecutionException { + final OAuthRequest request = createAccessTokenPasswordGrantRequest(uname, password, scope); + + return sendAccessTokenRequestSync(request); + } + public Future getAccessTokenPasswordGrantAsync(String uname, String password) { - return getAccessTokenPasswordGrantAsync(uname, password, null); + return getAccessTokenPasswordGrantAsync(uname, password, (OAuthAsyncRequestCallback) null); + } + + public Future getAccessTokenPasswordGrantAsync(String uname, String password, String scope) { + return getAccessTokenPasswordGrantAsync(uname, password, scope, null); } /** @@ -186,12 +291,35 @@ public Future getAccessTokenPasswordGrantAsync(String uname, return sendAccessTokenRequestAsync(request, callback); } + public Future getAccessTokenPasswordGrantAsync(String uname, String password, String scope, + OAuthAsyncRequestCallback callback) { + final OAuthRequest request = createAccessTokenPasswordGrantRequest(uname, password, scope); + + return sendAccessTokenRequestAsync(request, callback); + } + + /** + * + * @param username username + * @param password password + * @return request + * + * @deprecated use {@link #createAccessTokenPasswordGrantRequest(java.lang.String, java.lang.String, + * java.lang.String) } + */ + @Deprecated protected OAuthRequest createAccessTokenPasswordGrantRequest(String username, String password) { + return createAccessTokenPasswordGrantRequest(username, password, null); + } + + protected OAuthRequest createAccessTokenPasswordGrantRequest(String username, String password, String scope) { final OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint()); request.addParameter(OAuthConstants.USERNAME, username); request.addParameter(OAuthConstants.PASSWORD, password); - if (defaultScope != null) { + if (scope != null) { + request.addParameter(OAuthConstants.SCOPE, scope); + } else if (defaultScope != null) { request.addParameter(OAuthConstants.SCOPE, defaultScope); } @@ -203,7 +331,11 @@ protected OAuthRequest createAccessTokenPasswordGrantRequest(String username, St } public Future getAccessTokenClientCredentialsGrantAsync() { - return getAccessTokenClientCredentialsGrant(null); + return getAccessTokenClientCredentialsGrant((OAuthAsyncRequestCallback) null); + } + + public Future getAccessTokenClientCredentialsGrantAsync(String scope) { + return getAccessTokenClientCredentialsGrant(scope, null); } public OAuth2AccessToken getAccessTokenClientCredentialsGrant() @@ -213,6 +345,13 @@ public OAuth2AccessToken getAccessTokenClientCredentialsGrant() return sendAccessTokenRequestSync(request); } + public OAuth2AccessToken getAccessTokenClientCredentialsGrant(String scope) + throws IOException, InterruptedException, ExecutionException { + final OAuthRequest request = createAccessTokenClientCredentialsGrantRequest(scope); + + return sendAccessTokenRequestSync(request); + } + /** * Start the request to retrieve the access token using client-credentials grant. The optionally provided callback * will be called with the Token when it is available. @@ -227,12 +366,31 @@ public Future getAccessTokenClientCredentialsGrant( return sendAccessTokenRequestAsync(request, callback); } + public Future getAccessTokenClientCredentialsGrant(String scope, + OAuthAsyncRequestCallback callback) { + final OAuthRequest request = createAccessTokenClientCredentialsGrantRequest(scope); + + return sendAccessTokenRequestAsync(request, callback); + } + + /** + * @return request + * + * @deprecated use {@link #createAccessTokenClientCredentialsGrantRequest(java.lang.String) } + */ + @Deprecated protected OAuthRequest createAccessTokenClientCredentialsGrantRequest() { + return createAccessTokenClientCredentialsGrantRequest(null); + } + + protected OAuthRequest createAccessTokenClientCredentialsGrantRequest(String scope) { final OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint()); api.getClientAuthentication().addClientAuthentication(request, getApiKey(), getApiSecret()); - if (defaultScope != null) { + if (scope != null) { + request.addParameter(OAuthConstants.SCOPE, scope); + } else if (defaultScope != null) { request.addParameter(OAuthConstants.SCOPE, defaultScope); } request.addParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.CLIENT_CREDENTIALS); @@ -255,21 +413,64 @@ public void signRequest(OAuth2AccessToken accessToken, OAuthRequest request) { signRequest(accessToken == null ? null : accessToken.getAccessToken(), request); } + /** + * @return AuthorizationUrlWithPKCE + * + * @deprecated use new builder pattern {@link AuthorizationUrlBuilder} + */ + @Deprecated public AuthorizationUrlWithPKCE getAuthorizationUrlWithPKCE() { - return getAuthorizationUrlWithPKCE(null, null); + final AuthorizationUrlBuilder authorizationUrlBuilder = createAuthorizationUrlBuilder() + .initPKCE(); + + return new AuthorizationUrlWithPKCE(authorizationUrlBuilder.getPkce(), authorizationUrlBuilder.build()); } + /** + * @param state state + * @return AuthorizationUrlWithPKCE + * + * @deprecated use new builder pattern {@link AuthorizationUrlBuilder} + */ + @Deprecated public AuthorizationUrlWithPKCE getAuthorizationUrlWithPKCE(String state) { - return getAuthorizationUrlWithPKCE(state, null); + final AuthorizationUrlBuilder authorizationUrlBuilder = createAuthorizationUrlBuilder() + .state(state) + .initPKCE(); + + return new AuthorizationUrlWithPKCE(authorizationUrlBuilder.getPkce(), authorizationUrlBuilder.build()); } + /** + * @param additionalParams additionalParams + * @return AuthorizationUrlWithPKCE + * + * @deprecated use new builder pattern {@link AuthorizationUrlBuilder} + */ + @Deprecated public AuthorizationUrlWithPKCE getAuthorizationUrlWithPKCE(Map additionalParams) { - return getAuthorizationUrlWithPKCE(null, additionalParams); + final AuthorizationUrlBuilder authorizationUrlBuilder = createAuthorizationUrlBuilder() + .additionalParams(additionalParams) + .initPKCE(); + + return new AuthorizationUrlWithPKCE(authorizationUrlBuilder.getPkce(), authorizationUrlBuilder.build()); } + /** + * @param state state + * @param additionalParams additionalParams + * @return AuthorizationUrlWithPKCE + * + * @deprecated use new builder pattern {@link AuthorizationUrlBuilder} + */ + @Deprecated public AuthorizationUrlWithPKCE getAuthorizationUrlWithPKCE(String state, Map additionalParams) { - final PKCE pkce = PKCEService.defaultInstance().generatePKCE(); - return new AuthorizationUrlWithPKCE(pkce, getAuthorizationUrl(state, additionalParams, pkce)); + final AuthorizationUrlBuilder authorizationUrlBuilder = createAuthorizationUrlBuilder() + .state(state) + .additionalParams(additionalParams) + .initPKCE(); + + return new AuthorizationUrlWithPKCE(authorizationUrlBuilder.getPkce(), authorizationUrlBuilder.build()); } /** @@ -278,11 +479,13 @@ public AuthorizationUrlWithPKCE getAuthorizationUrlWithPKCE(String state, Map additionalParams) { - return getAuthorizationUrl(null, additionalParams); + return createAuthorizationUrlBuilder() + .additionalParams(additionalParams) + .build(); } + /** + * + * @param state state + * @param additionalParams additionalParams + * @return url + * + * @deprecated use new builder pattern {@link AuthorizationUrlBuilder} + */ + @Deprecated public String getAuthorizationUrl(String state, Map additionalParams) { - return getAuthorizationUrl(state, additionalParams, null); + return createAuthorizationUrlBuilder() + .state(state) + .additionalParams(additionalParams) + .build(); } public String getAuthorizationUrl(PKCE pkce) { - return getAuthorizationUrl(null, null, pkce); + return createAuthorizationUrlBuilder() + .pkce(pkce) + .build(); } + /** + * @param state state + * @param pkce pkce + * @return url + * + * @deprecated use new builder pattern {@link AuthorizationUrlBuilder} + */ + @Deprecated public String getAuthorizationUrl(String state, PKCE pkce) { - return getAuthorizationUrl(state, null, pkce); + return createAuthorizationUrlBuilder() + .state(state) + .pkce(pkce) + .build(); } + /** + * @param additionalParams additionalParams + * @param pkce pkce + * @return url + * + * @deprecated use new builder pattern {@link AuthorizationUrlBuilder} + */ + @Deprecated public String getAuthorizationUrl(Map additionalParams, PKCE pkce) { - return getAuthorizationUrl(null, additionalParams, pkce); + return createAuthorizationUrlBuilder() + .additionalParams(additionalParams) + .pkce(pkce) + .build(); } + /** + * + * @param state state + * @param additionalParams additionalParams + * @param pkce pkce + * @return url + * + * @deprecated use new builder pattern {@link AuthorizationUrlBuilder} + */ + @Deprecated public String getAuthorizationUrl(String state, Map additionalParams, PKCE pkce) { - final Map params; - if (pkce == null) { - params = additionalParams; - } else { - params = additionalParams == null ? new HashMap() : new HashMap<>(additionalParams); - params.putAll(pkce.getAuthorizationUrlParams()); - } - return api.getAuthorizationUrl(getResponseType(), getApiKey(), getCallback(), defaultScope, state, params); + return createAuthorizationUrlBuilder() + .state(state) + .additionalParams(additionalParams) + .pkce(pkce) + .build(); + } + + public AuthorizationUrlBuilder createAuthorizationUrlBuilder() { + return new AuthorizationUrlBuilder(this); } public DefaultApi20 getApi() { @@ -406,4 +658,8 @@ public OAuth2Authorization extractAuthorization(String redirectLocation) { public String getResponseType() { return responseType; } + + public String getDefaultScope() { + return defaultScope; + } } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/pkce/AuthorizationUrlWithPKCE.java b/scribejava-core/src/main/java/com/github/scribejava/core/pkce/AuthorizationUrlWithPKCE.java index 101f82f10..3dc1f345c 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/pkce/AuthorizationUrlWithPKCE.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/pkce/AuthorizationUrlWithPKCE.java @@ -1,21 +1,52 @@ package com.github.scribejava.core.pkce; +import com.github.scribejava.core.oauth.AuthorizationUrlBuilder; + +/** + * @deprecated use new builder pattern {@link AuthorizationUrlBuilder} and it's methods
    + * {@link AuthorizationUrlBuilder#getPkce()} and {@link AuthorizationUrlBuilder#build()} + * + */ +@Deprecated public class AuthorizationUrlWithPKCE { private final PKCE pkce; private final String authorizationUrl; + /** + * + * @param pkce pkce + * @param authorizationUrl authorizationUrl + * + * @deprecated use new builder pattern {@link AuthorizationUrlBuilder} and it's methods
    + * {@link AuthorizationUrlBuilder#getPkce()} and {@link AuthorizationUrlBuilder#build()} + */ + @Deprecated public AuthorizationUrlWithPKCE(PKCE pkce, String authorizationUrl) { this.pkce = pkce; this.authorizationUrl = authorizationUrl; } + /** + * @return pkce + * + * @deprecated use new builder pattern {@link AuthorizationUrlBuilder} and it's method
    + * {@link AuthorizationUrlBuilder#getPkce()} + */ + @Deprecated public PKCE getPkce() { return pkce; } + /** + * + * @return url + * + * @deprecated use new builder pattern {@link AuthorizationUrlBuilder} and it's method
    + * {@link AuthorizationUrlBuilder#build()} + */ + @Deprecated public String getAuthorizationUrl() { return authorizationUrl; } - } diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceTest.java index 1f1983092..297c37894 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceTest.java @@ -52,7 +52,7 @@ public void shouldProduceCorrectRequestAsync() throws ExecutionException, Interr .apiSecret("your_api_secret") .build(new OAuth20ApiUnit()); - final OAuth2AccessToken token = service.getAccessTokenPasswordGrantAsync("user1", "password1", null).get(); + final OAuth2AccessToken token = service.getAccessTokenPasswordGrantAsync("user1", "password1").get(); final Gson json = new Gson(); assertNotNull(token); From c62fae68654c10f69c6e2adf0dbb948af522164d Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 22 Mar 2019 18:05:55 +0300 Subject: [PATCH 591/882] upgrade Facebook API from 2.11 to 3.2 --- changelog | 1 + .../src/main/java/com/github/scribejava/apis/FacebookApi.java | 2 +- .../scribejava/apis/examples/FacebookAsyncApacheExample.java | 2 +- .../scribejava/apis/examples/FacebookAsyncNingExample.java | 2 +- .../com/github/scribejava/apis/examples/FacebookExample.java | 2 +- 5 files changed, 5 insertions(+), 4 deletions(-) diff --git a/changelog b/changelog index ccce51b79..bcdc2babe 100644 --- a/changelog +++ b/changelog @@ -2,6 +2,7 @@ * separate OAuth1.0a and OAuth2.0 ServiceBuilders, introduce AuthorizationUrlBuilder (along with deprecation of AuthorizationUrlWithPKCE) add possibility to provide different scopes for each Access Token request + * upgrade Facebook API from v2.11 to v3.2 [6.4.1] * support TLS 1.3 in JDK 11 for Salesforce diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java index f41c801e1..a7d81e8b1 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java @@ -19,7 +19,7 @@ public class FacebookApi extends DefaultApi20 { private final String version; protected FacebookApi() { - this("2.11"); + this("3.2"); } protected FacebookApi(String version) { diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncApacheExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncApacheExample.java index c98c00eba..94e14e015 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncApacheExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncApacheExample.java @@ -16,7 +16,7 @@ public class FacebookAsyncApacheExample { private static final String NETWORK_NAME = "Facebook"; - private static final String PROTECTED_RESOURCE_URL = "https://graph.facebook.com/v2.11/me"; + private static final String PROTECTED_RESOURCE_URL = "https://graph.facebook.com/v3.2/me"; private FacebookAsyncApacheExample() { } diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java index 1d7e38576..fa42a2332 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java @@ -17,7 +17,7 @@ public class FacebookAsyncNingExample { private static final String NETWORK_NAME = "Facebook"; - private static final String PROTECTED_RESOURCE_URL = "https://graph.facebook.com/v2.11/me"; + private static final String PROTECTED_RESOURCE_URL = "https://graph.facebook.com/v3.2/me"; private FacebookAsyncNingExample() { } diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java index 071a979a3..139c01bf0 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java @@ -15,7 +15,7 @@ public class FacebookExample { private static final String NETWORK_NAME = "Facebook"; - private static final String PROTECTED_RESOURCE_URL = "https://graph.facebook.com/v2.11/me"; + private static final String PROTECTED_RESOURCE_URL = "https://graph.facebook.com/v3.2/me"; private FacebookExample() { } From b9ad89463744408ca451849bc4787400dce54c1b Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 22 Mar 2019 18:10:18 +0300 Subject: [PATCH 592/882] upgrade VkontakteApi from 5.73 to 5.92 --- changelog | 1 + .../src/main/java/com/github/scribejava/apis/VkontakteApi.java | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/changelog b/changelog index bcdc2babe..b730631ee 100644 --- a/changelog +++ b/changelog @@ -3,6 +3,7 @@ introduce AuthorizationUrlBuilder (along with deprecation of AuthorizationUrlWithPKCE) add possibility to provide different scopes for each Access Token request * upgrade Facebook API from v2.11 to v3.2 + * upgrade VkontakteApi from 5.73 to 5.92 [6.4.1] * support TLS 1.3 in JDK 11 for Salesforce diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/VkontakteApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/VkontakteApi.java index 1662891c3..dfc96275b 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/VkontakteApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/VkontakteApi.java @@ -12,7 +12,7 @@ public class VkontakteApi extends DefaultApi20 { - public static final String VERSION = "5.73"; + public static final String VERSION = "5.92"; protected VkontakteApi() { } From c84bf63693661b7e239e312c61abe94406d2d74c Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 22 Mar 2019 18:24:03 +0300 Subject: [PATCH 593/882] prepare v6.5.0 --- README.md | 4 ++-- changelog | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index b63986121..926d58931 100644 --- a/README.md +++ b/README.md @@ -128,7 +128,7 @@ You can pull ScribeJava from the central maven repository, just add these to you com.github.scribejava scribejava-apis - 6.4.1 + 6.5.0 ``` @@ -137,7 +137,7 @@ And in case you need just core classes (that's it, without any external API (FB, com.github.scribejava scribejava-core - 6.4.1 + 6.5.0 ``` diff --git a/changelog b/changelog index b730631ee..c1d509e7c 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,4 @@ -[SNAPSHOT] +[6.5.0] * separate OAuth1.0a and OAuth2.0 ServiceBuilders, introduce AuthorizationUrlBuilder (along with deprecation of AuthorizationUrlWithPKCE) add possibility to provide different scopes for each Access Token request From fbf94b3ea0aee9684329b40c1fff10ed8ccb498d Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 22 Mar 2019 18:25:15 +0300 Subject: [PATCH 594/882] [maven-release-plugin] prepare release scribejava-6.5.0 --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index bd17a9f31..f63433530 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 6.4.2-SNAPSHOT + 6.5.0 ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -34,7 +34,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - HEAD + scribejava-6.5.0 diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 4776cb3a5..93dcbb8b8 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.4.2-SNAPSHOT + 6.5.0 ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index eee982dbf..756890f9c 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.4.2-SNAPSHOT + 6.5.0 ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 54682f9c5..87ac1f88a 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.4.2-SNAPSHOT + 6.5.0 ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index 856fb8de7..43aa61499 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.4.2-SNAPSHOT + 6.5.0 ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index 6028cba24..de782bc53 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.4.2-SNAPSHOT + 6.5.0 ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 5640e147f..b0a0e3c38 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.4.2-SNAPSHOT + 6.5.0 ../pom.xml From ce72a8ab6350cb5160b44cbfe08ccae684a3c3fd Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 22 Mar 2019 18:25:21 +0300 Subject: [PATCH 595/882] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index f63433530..2d139ab8e 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 6.5.0 + 6.5.1-SNAPSHOT ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -34,7 +34,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - scribejava-6.5.0 + HEAD diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 93dcbb8b8..4c0903b8f 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.5.0 + 6.5.1-SNAPSHOT ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 756890f9c..caf694f86 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.5.0 + 6.5.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 87ac1f88a..87a926393 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.5.0 + 6.5.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index 43aa61499..d2271c72e 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.5.0 + 6.5.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index de782bc53..5d62b1bc3 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.5.0 + 6.5.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index b0a0e3c38..6e50aadb4 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.5.0 + 6.5.1-SNAPSHOT ../pom.xml From c3c19f2390a08f185c40f88fee6001bfc0e7bbe4 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 25 Mar 2019 10:59:07 +0300 Subject: [PATCH 596/882] cleanup deprecates methods --- changelog | 3 + .../core/builder/ServiceBuilder.java | 12 +- .../core/builder/ServiceBuilderCommon.java | 11 - .../core/builder/ServiceBuilderOAuth10a.java | 7 - .../core/builder/ServiceBuilderOAuth20.java | 7 - .../scribejava/core/oauth/OAuth20Service.java | 272 ++---------------- .../core/pkce/AuthorizationUrlWithPKCE.java | 52 ---- 7 files changed, 27 insertions(+), 337 deletions(-) delete mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/pkce/AuthorizationUrlWithPKCE.java diff --git a/changelog b/changelog index c1d509e7c..50be9ba26 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,6 @@ +[SNAPSHOT] + * cleanup deprecates methods + [6.5.0] * separate OAuth1.0a and OAuth2.0 ServiceBuilders, introduce AuthorizationUrlBuilder (along with deprecation of AuthorizationUrlWithPKCE) diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilder.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilder.java index fc767efb8..bbc68b571 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilder.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilder.java @@ -51,13 +51,7 @@ public ServiceBuilder apiSecret(String apiSecret) { return this; } - /** - * @deprecated use {@link ServiceBuilderOAuth20#defaultScope(java.lang.String)} or - * {@link ServiceBuilderOAuth10a#withScope(java.lang.String)} - */ - @Override - @Deprecated - public ServiceBuilder scope(String scope) { + private ServiceBuilder setScope(String scope) { Preconditions.checkEmptyString(scope, "Invalid OAuth scope"); this.scope = scope; return this; @@ -65,12 +59,12 @@ public ServiceBuilder scope(String scope) { @Override public ServiceBuilderOAuth20 defaultScope(String defaultScope) { - return scope(defaultScope); + return setScope(defaultScope); } @Override public ServiceBuilderOAuth10a withScope(String scope) { - return scope(scope); + return setScope(scope); } @Override diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilderCommon.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilderCommon.java index 3babd3d56..9cddb2947 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilderCommon.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilderCommon.java @@ -34,17 +34,6 @@ public interface ServiceBuilderCommon { */ ServiceBuilderCommon apiSecret(String apiSecret); - /** - * Configures the OAuth scope. This is only necessary in some APIs (like Google's). - * - * @param scope The OAuth scope - * @return the {@link ServiceBuilder} instance for method chaining - * @deprecated use {@link ServiceBuilderOAuth20#defaultScope(java.lang.String)} or - * {@link ServiceBuilderOAuth10a#withScope(java.lang.String)} - */ - @Deprecated - ServiceBuilderCommon scope(String scope); - ServiceBuilderCommon httpClientConfig(HttpClientConfig httpClientConfig); /** diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilderOAuth10a.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilderOAuth10a.java index d73b99af9..14323b809 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilderOAuth10a.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilderOAuth10a.java @@ -17,13 +17,6 @@ public interface ServiceBuilderOAuth10a extends ServiceBuilderCommon { @Override ServiceBuilderOAuth20 apiSecret(String apiSecret); - /** - * @deprecated use {@link #withScope(java.lang.String) } - */ - @Override - @Deprecated - ServiceBuilderOAuth20 scope(String scope); - @Override ServiceBuilderOAuth20 httpClientConfig(HttpClientConfig httpClientConfig); diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilderOAuth20.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilderOAuth20.java index b7cefc475..97347959b 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilderOAuth20.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilderOAuth20.java @@ -16,13 +16,6 @@ public interface ServiceBuilderOAuth20 extends ServiceBuilderCommon { @Override ServiceBuilderOAuth20 apiSecret(String apiSecret); - /** - * @deprecated use {@link #defaultScope(java.lang.String) } - */ - @Override - @Deprecated - ServiceBuilderOAuth20 scope(String scope); - @Override ServiceBuilderOAuth20 httpClientConfig(HttpClientConfig httpClientConfig); diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java index 2d571f9cc..13a3ed4ef 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java @@ -13,7 +13,6 @@ import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; import com.github.scribejava.core.model.Verb; -import com.github.scribejava.core.pkce.AuthorizationUrlWithPKCE; import com.github.scribejava.core.pkce.PKCE; import java.util.Map; import java.util.concurrent.ExecutionException; @@ -58,18 +57,7 @@ public OAuth2AccessToken convert(Response response) throws IOException { } public Future getAccessTokenAsync(String code) { - return getAccessToken(code, null, null); - } - - /** - * @param code code - * @param pkceCodeVerifier pkceCodeVerifier - * @return future - * @deprecated use {@link #getAccessTokenAsync(com.github.scribejava.core.oauth.AccessTokenRequestParams) } - */ - @Deprecated - public Future getAccessTokenAsync(String code, String pkceCodeVerifier) { - return getAccessToken(code, null, pkceCodeVerifier); + return getAccessToken(AccessTokenRequestParams.create(code), null); } public Future getAccessTokenAsync(AccessTokenRequestParams params) { @@ -77,25 +65,7 @@ public Future getAccessTokenAsync(AccessTokenRequestParams pa } public OAuth2AccessToken getAccessToken(String code) throws IOException, InterruptedException, ExecutionException { - return getAccessToken(code, (String) null); - } - - /** - * @param code code - * @param pkceCodeVerifier pkceCodeVerifier - * @return token - * @throws IOException IOException - * @throws InterruptedException InterruptedException - * @throws ExecutionException ExecutionException - * - * @deprecated use {@link #getAccessToken(com.github.scribejava.core.oauth.AccessTokenRequestParams) } - */ - @Deprecated - public OAuth2AccessToken getAccessToken(String code, String pkceCodeVerifier) - throws IOException, InterruptedException, ExecutionException { - final OAuthRequest request = createAccessTokenRequest(code, pkceCodeVerifier); - - return sendAccessTokenRequestSync(request); + return getAccessToken(AccessTokenRequestParams.create(code)); } public OAuth2AccessToken getAccessToken(AccessTokenRequestParams params) @@ -116,51 +86,9 @@ public Future getAccessToken(AccessTokenRequestParams params, return sendAccessTokenRequestAsync(createAccessTokenRequest(params), callback); } - /** - * @param code code - * @param callback callback - * @param pkceCodeVerifier pkceCodeVerifier - * @return future - * - * @deprecated use {@link #getAccessToken(com.github.scribejava.core.oauth.AccessTokenRequestParams, - * com.github.scribejava.core.model.OAuthAsyncRequestCallback) } - */ - @Deprecated - public Future getAccessToken(String code, OAuthAsyncRequestCallback callback, - String pkceCodeVerifier) { - final OAuthRequest request = createAccessTokenRequest(code, pkceCodeVerifier); - - return sendAccessTokenRequestAsync(request, callback); - } - public Future getAccessToken(String code, OAuthAsyncRequestCallback callback) { - - return getAccessToken(code, callback, null); - } - - /** - * @param code code - * @return request - * - * @deprecated use {@link #createAccessTokenRequest(com.github.scribejava.core.oauth.AccessTokenRequestParams)} - */ - @Deprecated - protected OAuthRequest createAccessTokenRequest(String code) { - return createAccessTokenRequest(AccessTokenRequestParams.create(code)); - } - - /** - * - * @param code code - * @param pkceCodeVerifier pkceCodeVerifier - * @return request - * - * @deprecated use {@link #createAccessTokenRequest(com.github.scribejava.core.oauth.AccessTokenRequestParams)} - */ - @Deprecated - protected OAuthRequest createAccessTokenRequest(String code, String pkceCodeVerifier) { - return createAccessTokenRequest(AccessTokenRequestParams.create(code).pkceCodeVerifier(pkceCodeVerifier)); + return getAccessToken(AccessTokenRequestParams.create(code), callback); } protected OAuthRequest createAccessTokenRequest(AccessTokenRequestParams params) { @@ -198,7 +126,7 @@ public Future refreshAccessTokenAsync(String refreshToken, St public OAuth2AccessToken refreshAccessToken(String refreshToken) throws IOException, InterruptedException, ExecutionException { - final OAuthRequest request = createRefreshTokenRequest(refreshToken); + final OAuthRequest request = createRefreshTokenRequest(refreshToken, null); return sendAccessTokenRequestSync(request); } @@ -212,7 +140,7 @@ public OAuth2AccessToken refreshAccessToken(String refreshToken, String scope) public Future refreshAccessToken(String refreshToken, OAuthAsyncRequestCallback callback) { - final OAuthRequest request = createRefreshTokenRequest(refreshToken); + final OAuthRequest request = createRefreshTokenRequest(refreshToken, null); return sendAccessTokenRequestAsync(request, callback); } @@ -224,17 +152,6 @@ public Future refreshAccessToken(String refreshToken, String return sendAccessTokenRequestAsync(request, callback); } - /** - * @param refreshToken refreshToken - * @return request - * - * @deprecated use {@link #createRefreshTokenRequest(java.lang.String, java.lang.String) } - */ - @Deprecated - protected OAuthRequest createRefreshTokenRequest(String refreshToken) { - return createRefreshTokenRequest(refreshToken, null); - } - protected OAuthRequest createRefreshTokenRequest(String refreshToken, String scope) { if (refreshToken == null || refreshToken.isEmpty()) { throw new IllegalArgumentException("The refreshToken cannot be null or empty"); @@ -254,64 +171,51 @@ protected OAuthRequest createRefreshTokenRequest(String refreshToken, String sco return request; } - public OAuth2AccessToken getAccessTokenPasswordGrant(String uname, String password) + public OAuth2AccessToken getAccessTokenPasswordGrant(String username, String password) throws IOException, InterruptedException, ExecutionException { - final OAuthRequest request = createAccessTokenPasswordGrantRequest(uname, password); + final OAuthRequest request = createAccessTokenPasswordGrantRequest(username, password, null); return sendAccessTokenRequestSync(request); } - public OAuth2AccessToken getAccessTokenPasswordGrant(String uname, String password, String scope) + public OAuth2AccessToken getAccessTokenPasswordGrant(String username, String password, String scope) throws IOException, InterruptedException, ExecutionException { - final OAuthRequest request = createAccessTokenPasswordGrantRequest(uname, password, scope); + final OAuthRequest request = createAccessTokenPasswordGrantRequest(username, password, scope); return sendAccessTokenRequestSync(request); } - public Future getAccessTokenPasswordGrantAsync(String uname, String password) { - return getAccessTokenPasswordGrantAsync(uname, password, (OAuthAsyncRequestCallback) null); + public Future getAccessTokenPasswordGrantAsync(String username, String password) { + return getAccessTokenPasswordGrantAsync(username, password, + (OAuthAsyncRequestCallback) null); } - public Future getAccessTokenPasswordGrantAsync(String uname, String password, String scope) { - return getAccessTokenPasswordGrantAsync(uname, password, scope, null); + public Future getAccessTokenPasswordGrantAsync(String username, String password, String scope) { + return getAccessTokenPasswordGrantAsync(username, password, scope, null); } /** * Request Access Token Password Grant async version * - * @param uname User name + * @param username User name * @param password User password * @param callback Optional callback * @return Future */ - public Future getAccessTokenPasswordGrantAsync(String uname, String password, + public Future getAccessTokenPasswordGrantAsync(String username, String password, OAuthAsyncRequestCallback callback) { - final OAuthRequest request = createAccessTokenPasswordGrantRequest(uname, password); + final OAuthRequest request = createAccessTokenPasswordGrantRequest(username, password, null); return sendAccessTokenRequestAsync(request, callback); } - public Future getAccessTokenPasswordGrantAsync(String uname, String password, String scope, + public Future getAccessTokenPasswordGrantAsync(String username, String password, String scope, OAuthAsyncRequestCallback callback) { - final OAuthRequest request = createAccessTokenPasswordGrantRequest(uname, password, scope); + final OAuthRequest request = createAccessTokenPasswordGrantRequest(username, password, scope); return sendAccessTokenRequestAsync(request, callback); } - /** - * - * @param username username - * @param password password - * @return request - * - * @deprecated use {@link #createAccessTokenPasswordGrantRequest(java.lang.String, java.lang.String, - * java.lang.String) } - */ - @Deprecated - protected OAuthRequest createAccessTokenPasswordGrantRequest(String username, String password) { - return createAccessTokenPasswordGrantRequest(username, password, null); - } - protected OAuthRequest createAccessTokenPasswordGrantRequest(String username, String password, String scope) { final OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint()); request.addParameter(OAuthConstants.USERNAME, username); @@ -340,7 +244,7 @@ public Future getAccessTokenClientCredentialsGrantAsync(Strin public OAuth2AccessToken getAccessTokenClientCredentialsGrant() throws IOException, InterruptedException, ExecutionException { - final OAuthRequest request = createAccessTokenClientCredentialsGrantRequest(); + final OAuthRequest request = createAccessTokenClientCredentialsGrantRequest(null); return sendAccessTokenRequestSync(request); } @@ -361,7 +265,7 @@ public OAuth2AccessToken getAccessTokenClientCredentialsGrant(String scope) */ public Future getAccessTokenClientCredentialsGrant( OAuthAsyncRequestCallback callback) { - final OAuthRequest request = createAccessTokenClientCredentialsGrantRequest(); + final OAuthRequest request = createAccessTokenClientCredentialsGrantRequest(null); return sendAccessTokenRequestAsync(request, callback); } @@ -373,16 +277,6 @@ public Future getAccessTokenClientCredentialsGrant(String sco return sendAccessTokenRequestAsync(request, callback); } - /** - * @return request - * - * @deprecated use {@link #createAccessTokenClientCredentialsGrantRequest(java.lang.String) } - */ - @Deprecated - protected OAuthRequest createAccessTokenClientCredentialsGrantRequest() { - return createAccessTokenClientCredentialsGrantRequest(null); - } - protected OAuthRequest createAccessTokenClientCredentialsGrantRequest(String scope) { final OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint()); @@ -413,66 +307,6 @@ public void signRequest(OAuth2AccessToken accessToken, OAuthRequest request) { signRequest(accessToken == null ? null : accessToken.getAccessToken(), request); } - /** - * @return AuthorizationUrlWithPKCE - * - * @deprecated use new builder pattern {@link AuthorizationUrlBuilder} - */ - @Deprecated - public AuthorizationUrlWithPKCE getAuthorizationUrlWithPKCE() { - final AuthorizationUrlBuilder authorizationUrlBuilder = createAuthorizationUrlBuilder() - .initPKCE(); - - return new AuthorizationUrlWithPKCE(authorizationUrlBuilder.getPkce(), authorizationUrlBuilder.build()); - } - - /** - * @param state state - * @return AuthorizationUrlWithPKCE - * - * @deprecated use new builder pattern {@link AuthorizationUrlBuilder} - */ - @Deprecated - public AuthorizationUrlWithPKCE getAuthorizationUrlWithPKCE(String state) { - final AuthorizationUrlBuilder authorizationUrlBuilder = createAuthorizationUrlBuilder() - .state(state) - .initPKCE(); - - return new AuthorizationUrlWithPKCE(authorizationUrlBuilder.getPkce(), authorizationUrlBuilder.build()); - } - - /** - * @param additionalParams additionalParams - * @return AuthorizationUrlWithPKCE - * - * @deprecated use new builder pattern {@link AuthorizationUrlBuilder} - */ - @Deprecated - public AuthorizationUrlWithPKCE getAuthorizationUrlWithPKCE(Map additionalParams) { - final AuthorizationUrlBuilder authorizationUrlBuilder = createAuthorizationUrlBuilder() - .additionalParams(additionalParams) - .initPKCE(); - - return new AuthorizationUrlWithPKCE(authorizationUrlBuilder.getPkce(), authorizationUrlBuilder.build()); - } - - /** - * @param state state - * @param additionalParams additionalParams - * @return AuthorizationUrlWithPKCE - * - * @deprecated use new builder pattern {@link AuthorizationUrlBuilder} - */ - @Deprecated - public AuthorizationUrlWithPKCE getAuthorizationUrlWithPKCE(String state, Map additionalParams) { - final AuthorizationUrlBuilder authorizationUrlBuilder = createAuthorizationUrlBuilder() - .state(state) - .additionalParams(additionalParams) - .initPKCE(); - - return new AuthorizationUrlWithPKCE(authorizationUrlBuilder.getPkce(), authorizationUrlBuilder.build()); - } - /** * Returns the URL where you should redirect your users to authenticate your application. * @@ -500,76 +334,12 @@ public String getAuthorizationUrl(Map additionalParams) { .build(); } - /** - * - * @param state state - * @param additionalParams additionalParams - * @return url - * - * @deprecated use new builder pattern {@link AuthorizationUrlBuilder} - */ - @Deprecated - public String getAuthorizationUrl(String state, Map additionalParams) { - return createAuthorizationUrlBuilder() - .state(state) - .additionalParams(additionalParams) - .build(); - } - public String getAuthorizationUrl(PKCE pkce) { return createAuthorizationUrlBuilder() .pkce(pkce) .build(); } - /** - * @param state state - * @param pkce pkce - * @return url - * - * @deprecated use new builder pattern {@link AuthorizationUrlBuilder} - */ - @Deprecated - public String getAuthorizationUrl(String state, PKCE pkce) { - return createAuthorizationUrlBuilder() - .state(state) - .pkce(pkce) - .build(); - } - - /** - * @param additionalParams additionalParams - * @param pkce pkce - * @return url - * - * @deprecated use new builder pattern {@link AuthorizationUrlBuilder} - */ - @Deprecated - public String getAuthorizationUrl(Map additionalParams, PKCE pkce) { - return createAuthorizationUrlBuilder() - .additionalParams(additionalParams) - .pkce(pkce) - .build(); - } - - /** - * - * @param state state - * @param additionalParams additionalParams - * @param pkce pkce - * @return url - * - * @deprecated use new builder pattern {@link AuthorizationUrlBuilder} - */ - @Deprecated - public String getAuthorizationUrl(String state, Map additionalParams, PKCE pkce) { - return createAuthorizationUrlBuilder() - .state(state) - .additionalParams(additionalParams) - .pkce(pkce) - .build(); - } - public AuthorizationUrlBuilder createAuthorizationUrlBuilder() { return new AuthorizationUrlBuilder(this); } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/pkce/AuthorizationUrlWithPKCE.java b/scribejava-core/src/main/java/com/github/scribejava/core/pkce/AuthorizationUrlWithPKCE.java deleted file mode 100644 index 3dc1f345c..000000000 --- a/scribejava-core/src/main/java/com/github/scribejava/core/pkce/AuthorizationUrlWithPKCE.java +++ /dev/null @@ -1,52 +0,0 @@ -package com.github.scribejava.core.pkce; - -import com.github.scribejava.core.oauth.AuthorizationUrlBuilder; - -/** - * @deprecated use new builder pattern {@link AuthorizationUrlBuilder} and it's methods
    - * {@link AuthorizationUrlBuilder#getPkce()} and {@link AuthorizationUrlBuilder#build()} - * - */ -@Deprecated -public class AuthorizationUrlWithPKCE { - - private final PKCE pkce; - private final String authorizationUrl; - - /** - * - * @param pkce pkce - * @param authorizationUrl authorizationUrl - * - * @deprecated use new builder pattern {@link AuthorizationUrlBuilder} and it's methods
    - * {@link AuthorizationUrlBuilder#getPkce()} and {@link AuthorizationUrlBuilder#build()} - */ - @Deprecated - public AuthorizationUrlWithPKCE(PKCE pkce, String authorizationUrl) { - this.pkce = pkce; - this.authorizationUrl = authorizationUrl; - } - - /** - * @return pkce - * - * @deprecated use new builder pattern {@link AuthorizationUrlBuilder} and it's method
    - * {@link AuthorizationUrlBuilder#getPkce()} - */ - @Deprecated - public PKCE getPkce() { - return pkce; - } - - /** - * - * @return url - * - * @deprecated use new builder pattern {@link AuthorizationUrlBuilder} and it's method
    - * {@link AuthorizationUrlBuilder#build()} - */ - @Deprecated - public String getAuthorizationUrl() { - return authorizationUrl; - } -} From dd388df2b67a3c5f07ea4a7e5e70ddc091b0c15e Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 25 Mar 2019 11:10:08 +0300 Subject: [PATCH 597/882] prepare v6.5.1 --- README.md | 4 ++-- changelog | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 926d58931..bbd290e7b 100644 --- a/README.md +++ b/README.md @@ -128,7 +128,7 @@ You can pull ScribeJava from the central maven repository, just add these to you com.github.scribejava scribejava-apis - 6.5.0 + 6.5.1 ``` @@ -137,7 +137,7 @@ And in case you need just core classes (that's it, without any external API (FB, com.github.scribejava scribejava-core - 6.5.0 + 6.5.1 ``` diff --git a/changelog b/changelog index 50be9ba26..c2f35d34b 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,4 @@ -[SNAPSHOT] +[6.5.1] * cleanup deprecates methods [6.5.0] From 3f4152e84884f521b409fb139ac0520e6c4e01b9 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 25 Mar 2019 11:11:27 +0300 Subject: [PATCH 598/882] [maven-release-plugin] prepare release scribejava-6.5.1 --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index 2d139ab8e..1d1637a3e 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 6.5.1-SNAPSHOT + 6.5.1 ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -34,7 +34,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - HEAD + scribejava-6.5.1 diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 4c0903b8f..3b44fbcde 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.5.1-SNAPSHOT + 6.5.1 ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index caf694f86..749182377 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.5.1-SNAPSHOT + 6.5.1 ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 87a926393..09ce718db 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.5.1-SNAPSHOT + 6.5.1 ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index d2271c72e..ad7f3c722 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.5.1-SNAPSHOT + 6.5.1 ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index 5d62b1bc3..17772e414 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.5.1-SNAPSHOT + 6.5.1 ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 6e50aadb4..3f02c3f28 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.5.1-SNAPSHOT + 6.5.1 ../pom.xml From ebf67e068906c5b3d78d93ce193811a5dd6df527 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 25 Mar 2019 11:13:17 +0300 Subject: [PATCH 599/882] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index 1d1637a3e..e6fa72440 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 6.5.1 + 6.5.2-SNAPSHOT ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -34,7 +34,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - scribejava-6.5.1 + HEAD diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 3b44fbcde..fbcbf7f41 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.5.1 + 6.5.2-SNAPSHOT ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 749182377..61cf7df26 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.5.1 + 6.5.2-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 09ce718db..f3de40bc2 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.5.1 + 6.5.2-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index ad7f3c722..02b290379 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.5.1 + 6.5.2-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index 17772e414..185088deb 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.5.1 + 6.5.2-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 3f02c3f28..d18c6f9e2 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.5.1 + 6.5.2-SNAPSHOT ../pom.xml From 7301f7abf9b846473eedfe59f07f098e4c342574 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 27 Mar 2019 15:02:29 +0300 Subject: [PATCH 600/882] introduce PMD check --- changelog | 3 ++ pmd.xml | 11 ++++ pom.xml | 51 ++++++++++++++++++- .../core/oauth/OAuth20ServiceTest.java | 4 +- 4 files changed, 66 insertions(+), 3 deletions(-) create mode 100644 pmd.xml diff --git a/changelog b/changelog index c2f35d34b..6e6bb1221 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,6 @@ +[SNAPSHOT] + * add PMD checks on compile + [6.5.1] * cleanup deprecates methods diff --git a/pmd.xml b/pmd.xml new file mode 100644 index 000000000..1a866a686 --- /dev/null +++ b/pmd.xml @@ -0,0 +1,11 @@ + + + + + This ruleset defines the PMD rules for project "ScribeJava". + + + diff --git a/pom.xml b/pom.xml index e6fa72440..506ba5237 100644 --- a/pom.xml +++ b/pom.xml @@ -147,7 +147,7 @@ 3.8.0 UTF-8 - 7 + ${java.release} true
    @@ -225,9 +225,58 @@ + + org.apache.maven.plugins + maven-pmd-plugin + 3.11.0 + + + net.sourceforge.pmd + pmd-core + ${pmdVersion} + + + net.sourceforge.pmd + pmd-java + ${pmdVersion} + + + net.sourceforge.pmd + pmd-javascript + ${pmdVersion} + + + net.sourceforge.pmd + pmd-jsp + ${pmdVersion} + + + + 1.${java.release} + false + + ../pmd.xml + + true + true + true + + + + + check + + + + + + 7 + 6.12.0 + + release-sign-artifacts diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceTest.java index 297c37894..b876d2d87 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceTest.java @@ -39,7 +39,7 @@ public void shouldProduceCorrectRequestSync() throws IOException, InterruptedExc final String authorize = base64Encoder.encodeToString( String.format("%s:%s", service.getApiKey(), service.getApiSecret()).getBytes(Charset.forName("UTF-8"))); - assertEquals(OAuthConstants.BASIC + " " + authorize, map.get(OAuthConstants.HEADER)); + assertEquals(OAuthConstants.BASIC + ' ' + authorize, map.get(OAuthConstants.HEADER)); assertEquals("user1", map.get("query-username")); assertEquals("password1", map.get("query-password")); @@ -65,7 +65,7 @@ public void shouldProduceCorrectRequestAsync() throws ExecutionException, Interr final String authorize = base64Encoder.encodeToString( String.format("%s:%s", service.getApiKey(), service.getApiSecret()).getBytes(Charset.forName("UTF-8"))); - assertEquals(OAuthConstants.BASIC + " " + authorize, map.get(OAuthConstants.HEADER)); + assertEquals(OAuthConstants.BASIC + ' ' + authorize, map.get(OAuthConstants.HEADER)); assertEquals("user1", map.get("query-username")); assertEquals("password1", map.get("query-password")); From 2afba057c55183d2c96a1a321766d5a81b6bece6 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 27 Mar 2019 15:54:53 +0300 Subject: [PATCH 601/882] introduce PMD/category/java/bestpractices.xml/AvoidPrintStackTrace rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 1a866a686..54150437d 100644 --- a/pmd.xml +++ b/pmd.xml @@ -8,4 +8,5 @@ This ruleset defines the PMD rules for project "ScribeJava". + From 8b27ee63075235d1e9f257bc357adf2afda2908d Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 27 Mar 2019 17:44:02 +0300 Subject: [PATCH 602/882] introduce PMD/category/java/bestpractices.xml/MissingOverride rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 54150437d..1a576a8ec 100644 --- a/pmd.xml +++ b/pmd.xml @@ -9,4 +9,5 @@ + From f70aaa3cff0d4337aef8bedbf744b042c9cd05aa Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 27 Mar 2019 17:54:31 +0300 Subject: [PATCH 603/882] introduce PMD/category/java/bestpractices.xml/OneDeclarationPerLine rule --- pmd.xml | 5 +++++ .../main/java/com/github/scribejava/core/java8/Base64.java | 7 +++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/pmd.xml b/pmd.xml index 1a576a8ec..aff50648c 100644 --- a/pmd.xml +++ b/pmd.xml @@ -10,4 +10,9 @@ + + + true + + diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/java8/Base64.java b/scribejava-core/src/main/java/com/github/scribejava/core/java8/Base64.java index 6da66f9de..59d1fdc2b 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/java8/Base64.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/java8/Base64.java @@ -566,7 +566,8 @@ public ByteBuffer decode(ByteBuffer buffer) { int pos0 = buffer.position(); try { byte[] src; - int sp, sl; + int sp; + int sl; if (buffer.hasArray()) { src = buffer.array(); sp = buffer.arrayOffset() + buffer.position(); @@ -725,7 +726,9 @@ private int decode0(byte[] src, int sp, int sl, byte[] dst) { private static class EncOutputStream extends FilterOutputStream { private int leftover; - private int b0, b1, b2; + private int b0; + private int b1; + private int b2; private boolean closed; private final char[] base64; // byte->base64 mapping From ba20e8483e50f43535a4fccc84af2b0be97157bf Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 27 Mar 2019 18:14:04 +0300 Subject: [PATCH 604/882] introduce PMD/category/java/bestpractices.xml/SwitchStmtsShouldHaveDefault rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index aff50648c..d483fa463 100644 --- a/pmd.xml +++ b/pmd.xml @@ -15,4 +15,5 @@ true + From a53f5392e03dcf6a3795505a6055bc2edfa17f59 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 27 Mar 2019 18:41:42 +0300 Subject: [PATCH 605/882] introduce PMD/category/java/bestpractices.xml/SystemPrintln rule --- pmd.xml | 1 + .../java/com/github/scribejava/apis/examples/AWeberExample.java | 1 + .../java/com/github/scribejava/apis/examples/AsanaExample.java | 1 + .../com/github/scribejava/apis/examples/AutomaticExample.java | 1 + .../java/com/github/scribejava/apis/examples/Box20Example.java | 1 + .../com/github/scribejava/apis/examples/DataportenExample.java | 1 + .../java/com/github/scribejava/apis/examples/DiggExample.java | 1 + .../com/github/scribejava/apis/examples/DiscordExample.java | 1 + .../java/com/github/scribejava/apis/examples/EtsyExample.java | 1 + .../scribejava/apis/examples/FacebookAsyncApacheExample.java | 1 + .../scribejava/apis/examples/FacebookAsyncNingExample.java | 1 + .../com/github/scribejava/apis/examples/FacebookExample.java | 1 + .../com/github/scribejava/apis/examples/FitbitApi20Example.java | 1 + .../java/com/github/scribejava/apis/examples/FlickrExample.java | 1 + .../com/github/scribejava/apis/examples/Foursquare2Example.java | 1 + .../com/github/scribejava/apis/examples/FoursquareExample.java | 1 + .../java/com/github/scribejava/apis/examples/FrappeExample.java | 1 + .../com/github/scribejava/apis/examples/FreelancerExample.java | 1 + .../java/com/github/scribejava/apis/examples/GeniusExample.java | 1 + .../scribejava/apis/examples/GitHubAsyncOkHttpExample.java | 1 + .../java/com/github/scribejava/apis/examples/GitHubExample.java | 1 + .../scribejava/apis/examples/Google20AsyncAHCExample.java | 1 + .../com/github/scribejava/apis/examples/Google20Example.java | 1 + .../github/scribejava/apis/examples/Google20RevokeExample.java | 1 + .../scribejava/apis/examples/Google20WithPKCEExample.java | 1 + .../java/com/github/scribejava/apis/examples/HHExample.java | 1 + .../com/github/scribejava/apis/examples/HiOrgServerExample.java | 1 + .../java/com/github/scribejava/apis/examples/ImgurExample.java | 1 + .../com/github/scribejava/apis/examples/Kaixin20Example.java | 1 + .../com/github/scribejava/apis/examples/KeycloakExample.java | 1 + .../com/github/scribejava/apis/examples/LinkedIn20Example.java | 1 + .../com/github/scribejava/apis/examples/LinkedInExample.java | 1 + .../scribejava/apis/examples/LinkedInExampleWithScopes.java | 1 + .../java/com/github/scribejava/apis/examples/LiveExample.java | 1 + .../com/github/scribejava/apis/examples/MailruAsyncExample.java | 1 + .../java/com/github/scribejava/apis/examples/MailruExample.java | 1 + .../com/github/scribejava/apis/examples/MediaWikiExample.java | 1 + .../java/com/github/scribejava/apis/examples/MeetupExample.java | 1 + .../apis/examples/MicrosoftAzureActiveDirectory20Example.java | 1 + .../apis/examples/MicrosoftAzureActiveDirectoryExample.java | 1 + .../java/com/github/scribejava/apis/examples/MisfitExample.java | 1 + .../java/com/github/scribejava/apis/examples/NaverExample.java | 1 + .../github/scribejava/apis/examples/OdnoklassnikiExample.java | 1 + .../com/github/scribejava/apis/examples/PinterestExample.java | 1 + .../java/com/github/scribejava/apis/examples/Px500Example.java | 1 + .../java/com/github/scribejava/apis/examples/RenrenExample.java | 1 + .../com/github/scribejava/apis/examples/SalesforceExample.java | 1 + .../scribejava/apis/examples/SalesforceNingAsyncExample.java | 2 +- .../com/github/scribejava/apis/examples/SinaWeibo2Example.java | 1 + .../com/github/scribejava/apis/examples/SinaWeiboExample.java | 1 + .../com/github/scribejava/apis/examples/SkyrockExample.java | 1 + .../github/scribejava/apis/examples/StackExchangeExample.java | 1 + .../apis/examples/TheThingsNetworkV1StagingExample.java | 1 + .../apis/examples/TheThingsNetworkV2PreviewExample.java | 1 + .../java/com/github/scribejava/apis/examples/TrelloExample.java | 1 + .../java/com/github/scribejava/apis/examples/TumblrExample.java | 1 + .../java/com/github/scribejava/apis/examples/TutByExample.java | 1 + .../com/github/scribejava/apis/examples/TwitterExample.java | 1 + .../java/com/github/scribejava/apis/examples/UcozExample.java | 1 + .../java/com/github/scribejava/apis/examples/ViadeoExample.java | 1 + .../apis/examples/VkontakteClientCredentialsGrantExample.java | 1 + .../com/github/scribejava/apis/examples/VkontakteExample.java | 1 + .../scribejava/apis/examples/VkontakteExternalHttpExample.java | 1 + .../com/github/scribejava/apis/examples/WunderlistExample.java | 1 + .../java/com/github/scribejava/apis/examples/XingExample.java | 1 + .../com/github/scribejava/apis/examples/Yahoo20Example.java | 1 + .../java/com/github/scribejava/apis/examples/YahooExample.java | 1 + 67 files changed, 67 insertions(+), 1 deletion(-) diff --git a/pmd.xml b/pmd.xml index d483fa463..fa2527ce9 100644 --- a/pmd.xml +++ b/pmd.xml @@ -16,4 +16,5 @@ + diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AWeberExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AWeberExample.java index 6a35e469b..e77555d7c 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AWeberExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AWeberExample.java @@ -23,6 +23,7 @@ public class AWeberExample { private AWeberExample() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { final OAuth10aService service = new ServiceBuilder(CONSUMER_KEY) .apiSecret(CONSUMER_SECRET) diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AsanaExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AsanaExample.java index c851a9e22..1c5bf684d 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AsanaExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AsanaExample.java @@ -20,6 +20,7 @@ public class AsanaExample { private AsanaExample() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { final String apiKey = "your client id"; final String apiSecret = "your client secret"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AutomaticExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AutomaticExample.java index b3375aadd..7174b0eb3 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AutomaticExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AutomaticExample.java @@ -21,6 +21,7 @@ public class AutomaticExample { private AutomaticExample() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your client id and secret final String clientId = "your client id"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Box20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Box20Example.java index 06d7d6c57..edbbd1663 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Box20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Box20Example.java @@ -22,6 +22,7 @@ public class Box20Example { private Box20Example() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { //Replace these with your client id and secret final String clientId = "your client id"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DataportenExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DataportenExample.java index c24a596fb..1878983eb 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DataportenExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DataportenExample.java @@ -20,6 +20,7 @@ public class DataportenExample { private DataportenExample() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your client id and secret final String clientId = "your client id"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiggExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiggExample.java index a1f11b196..3b1d0ad61 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiggExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiggExample.java @@ -20,6 +20,7 @@ public class DiggExample { private DiggExample() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your own api key and secret final String apiKey = "myKey"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiscordExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiscordExample.java index ec6784b14..b574034c7 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiscordExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiscordExample.java @@ -21,6 +21,7 @@ public class DiscordExample { private DiscordExample() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, ExecutionException, InterruptedException { // Replace these with your client id and secret final String clientId = "client id"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/EtsyExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/EtsyExample.java index d26adb59a..e39877ef6 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/EtsyExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/EtsyExample.java @@ -20,6 +20,7 @@ public class EtsyExample { private EtsyExample() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String[] args) throws InterruptedException, ExecutionException, IOException { // Replace with your api and secret key final OAuth10aService service = new ServiceBuilder("your api key") diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncApacheExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncApacheExample.java index 94e14e015..c2e55187e 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncApacheExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncApacheExample.java @@ -21,6 +21,7 @@ public class FacebookAsyncApacheExample { private FacebookAsyncApacheExample() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws InterruptedException, ExecutionException, IOException { // Replace these with your client id and secret final String clientId = "your client id"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java index fa42a2332..6c9b64436 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java @@ -22,6 +22,7 @@ public class FacebookAsyncNingExample { private FacebookAsyncNingExample() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws InterruptedException, ExecutionException, IOException { // Replace these with your client id and secret final String clientId = "your client id"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java index 139c01bf0..e4e7ca180 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java @@ -20,6 +20,7 @@ public class FacebookExample { private FacebookExample() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your client id and secret final String clientId = "your client id"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FitbitApi20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FitbitApi20Example.java index fcffc5f7e..0be7c1b6e 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FitbitApi20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FitbitApi20Example.java @@ -20,6 +20,7 @@ public class FitbitApi20Example { private FitbitApi20Example() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws Exception { // Replace these with your client id and secret fron your app diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExample.java index 66ddf3fd2..5c37b1248 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExample.java @@ -20,6 +20,7 @@ public class FlickrExample { private FlickrExample() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your own api key and secret final String apiKey = "your_app_id"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java index aae4fe7f8..3aa3ab38b 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java @@ -19,6 +19,7 @@ public class Foursquare2Example { private Foursquare2Example() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your own api key and secret final String apiKey = "your client id"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FoursquareExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FoursquareExample.java index d9ec56652..236d9b686 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FoursquareExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FoursquareExample.java @@ -19,6 +19,7 @@ public class FoursquareExample { private FoursquareExample() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { final OAuth10aService service = new ServiceBuilder("your client id") .apiSecret("your client secret") diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FrappeExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FrappeExample.java index ab1138411..64751a92d 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FrappeExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FrappeExample.java @@ -19,6 +19,7 @@ public class FrappeExample { private FrappeExample() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { //Replace these with your client id and secret final String clientId = "clientId"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java index 42089ae74..84cc45c2f 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java @@ -23,6 +23,7 @@ public class FreelancerExample { private FreelancerExample() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { final OAuth10aService service = new ServiceBuilder("your client id") .apiSecret("your client secret") diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GeniusExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GeniusExample.java index 538c4cf8d..71ebfc1f9 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GeniusExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GeniusExample.java @@ -20,6 +20,7 @@ public class GeniusExample { private GeniusExample() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your client id and secret final String clientId = "your client id"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubAsyncOkHttpExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubAsyncOkHttpExample.java index eb4f5ee2e..7559f9188 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubAsyncOkHttpExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubAsyncOkHttpExample.java @@ -22,6 +22,7 @@ public class GitHubAsyncOkHttpExample { private GitHubAsyncOkHttpExample() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, ExecutionException, InterruptedException { // Replace these with your client id and secret final String clientId = "your client id"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubExample.java index d48d7abfd..d9fa467be 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubExample.java @@ -20,6 +20,7 @@ public class GitHubExample { private GitHubExample() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your client id and secret final String clientId = "your client id"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java index 3365f06c7..6dc0dc624 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java @@ -25,6 +25,7 @@ public class Google20AsyncAHCExample { private Google20AsyncAHCExample() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws InterruptedException, ExecutionException, IOException { // Replace these with your client id and secret final String clientId = "your client id"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java index 079f5670e..4b141c42b 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java @@ -22,6 +22,7 @@ public class Google20Example { private Google20Example() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your client id and secret final String clientId = "your client id"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20RevokeExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20RevokeExample.java index d399aa22b..9f55b43d7 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20RevokeExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20RevokeExample.java @@ -22,6 +22,7 @@ public class Google20RevokeExample { private Google20RevokeExample() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your client id and secret final String clientId = "your client id"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20WithPKCEExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20WithPKCEExample.java index 4091215a7..b4d108430 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20WithPKCEExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20WithPKCEExample.java @@ -24,6 +24,7 @@ public class Google20WithPKCEExample { private Google20WithPKCEExample() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your client id and secret final String clientId = "your client id"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HHExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HHExample.java index 0c1d24b9b..ae7cafa2d 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HHExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HHExample.java @@ -21,6 +21,7 @@ public class HHExample { private HHExample() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your own client id and secret final String clientId = "your client id"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HiOrgServerExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HiOrgServerExample.java index 4eb43b695..22846f21d 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HiOrgServerExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HiOrgServerExample.java @@ -23,6 +23,7 @@ public class HiOrgServerExample { private HiOrgServerExample() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your client id and secret final String clientId = CLIENT_ID; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ImgurExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ImgurExample.java index ddc67c107..d804ed5d4 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ImgurExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ImgurExample.java @@ -20,6 +20,7 @@ public class ImgurExample { private ImgurExample() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your own api key and secret final String apiKey = "your client id"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Kaixin20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Kaixin20Example.java index dad494e49..e354722a6 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Kaixin20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Kaixin20Example.java @@ -19,6 +19,7 @@ public class Kaixin20Example { private Kaixin20Example() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your own api key and secret final String apiKey = "your api key"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/KeycloakExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/KeycloakExample.java index 18569f30d..80cf06473 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/KeycloakExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/KeycloakExample.java @@ -17,6 +17,7 @@ public class KeycloakExample { private KeycloakExample() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your own api key, secret, callback, base url and realm final String apiKey = "your_api_key"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedIn20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedIn20Example.java index 00ab0abbf..4fa1388de 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedIn20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedIn20Example.java @@ -19,6 +19,7 @@ public class LinkedIn20Example { private LinkedIn20Example() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your client id and secret final String clientId = "your client id"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java index 48f9fdcb5..ce7849b1d 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java @@ -20,6 +20,7 @@ public class LinkedInExample { private LinkedInExample() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { final OAuth10aService service = new ServiceBuilder("your client id") .apiSecret("your client secret") diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java index f90f91ce0..537c06104 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java @@ -20,6 +20,7 @@ public class LinkedInExampleWithScopes { private LinkedInExampleWithScopes() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your client id and secret final String clientId = "your client id"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java index 1bcd93cc9..fb6712b6a 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java @@ -18,6 +18,7 @@ public class LiveExample { private LiveExample() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your own api key and secret final String apiKey = ""; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java index 95673747d..6fcb28be8 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java @@ -22,6 +22,7 @@ public class MailruAsyncExample { private MailruAsyncExample() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws InterruptedException, ExecutionException, IOException { // Replace these with your client id and secret final String clientId = "your client id"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java index 372bedd1a..7c7ea8161 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java @@ -20,6 +20,7 @@ public class MailruExample { private MailruExample() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your client id and secret final String clientId = "your client id"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MediaWikiExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MediaWikiExample.java index 6ec9e5b67..e3a998ec8 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MediaWikiExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MediaWikiExample.java @@ -24,6 +24,7 @@ public class MediaWikiExample { private MediaWikiExample() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { final OAuth10aService service = new ServiceBuilder(CONSUMER_KEY) .apiSecret(CONSUMER_SECRET) diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java index ff97a734a..62b01866a 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java @@ -19,6 +19,7 @@ public class MeetupExample { private MeetupExample() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { final OAuth10aService service = new ServiceBuilder("your client id") .apiSecret("your client secret") diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureActiveDirectory20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureActiveDirectory20Example.java index bc42d4077..b06ae03db 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureActiveDirectory20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureActiveDirectory20Example.java @@ -19,6 +19,7 @@ public class MicrosoftAzureActiveDirectory20Example { private MicrosoftAzureActiveDirectory20Example() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your client id and secret final String clientId = "client id here"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureActiveDirectoryExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureActiveDirectoryExample.java index 2aa62b7b6..70dd25a94 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureActiveDirectoryExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureActiveDirectoryExample.java @@ -21,6 +21,7 @@ private MicrosoftAzureActiveDirectoryExample() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your client id and secret final String clientId = "client id here"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MisfitExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MisfitExample.java index e8a1437c0..309e34237 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MisfitExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MisfitExample.java @@ -21,6 +21,7 @@ public class MisfitExample { private MisfitExample() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your own api key and secret final String apiKey = "your client id"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NaverExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NaverExample.java index ec3e79db8..2879cb1f9 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NaverExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NaverExample.java @@ -21,6 +21,7 @@ public class NaverExample { private NaverExample() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your client id and secret final String clientId = "your client id"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java index 4ff6a4933..3deb43a30 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java @@ -20,6 +20,7 @@ public class OdnoklassnikiExample { private OdnoklassnikiExample() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your client id and secret final String clientId = "your api client id"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java index 54d058e68..c7fd39149 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java @@ -19,6 +19,7 @@ public class PinterestExample { private PinterestExample() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your own api key and secret final String apiKey = "your_app_id"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Px500Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Px500Example.java index 962faaa3d..d9b6622f6 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Px500Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Px500Example.java @@ -19,6 +19,7 @@ public class Px500Example { private Px500Example() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { final OAuth10aService service = new ServiceBuilder("your-api-key") .apiSecret("your-api-secret") diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java index a3cdf3d66..61bcd5c6d 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java @@ -29,6 +29,7 @@ public class RenrenExample { private RenrenExample() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your own api key and secret final String apiKey = "your api key"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceExample.java index b9c65a868..43d3d91b0 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceExample.java @@ -24,6 +24,7 @@ public class SalesforceExample { private SalesforceExample() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, NoSuchAlgorithmException, KeyManagementException, InterruptedException, ExecutionException { // Replace these with your client id and secret diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceNingAsyncExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceNingAsyncExample.java index 66470d597..10505a804 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceNingAsyncExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceNingAsyncExample.java @@ -27,7 +27,7 @@ public class SalesforceNingAsyncExample { private SalesforceNingAsyncExample() { } - @SuppressWarnings({"unchecked", "rawtypes"}) + @SuppressWarnings({"unchecked", "rawtypes", "PMD.SystemPrintln"}) public static void main(String... args) throws InterruptedException, ExecutionException, UnsupportedEncodingException, IOException, NoSuchAlgorithmException, KeyManagementException { // Replace these with your client id and secret diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeibo2Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeibo2Example.java index d4ff865de..a6565e7d6 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeibo2Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeibo2Example.java @@ -19,6 +19,7 @@ public class SinaWeibo2Example { private SinaWeibo2Example() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your own api key and secret final String apiKey = "your_api_key"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeiboExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeiboExample.java index 618e8c881..6a95f9472 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeiboExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeiboExample.java @@ -20,6 +20,7 @@ public class SinaWeiboExample { private SinaWeiboExample() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your own api key and secret final String apiKey = "your key"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SkyrockExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SkyrockExample.java index 5751538ef..dab1f94f8 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SkyrockExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SkyrockExample.java @@ -19,6 +19,7 @@ public class SkyrockExample { private SkyrockExample() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { final OAuth10aService service = new ServiceBuilder("your-api-key") .apiSecret("your-api-secret") diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/StackExchangeExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/StackExchangeExample.java index e179799e4..564dbc222 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/StackExchangeExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/StackExchangeExample.java @@ -21,6 +21,7 @@ public class StackExchangeExample { private StackExchangeExample() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your client id, secret, application key and // optionally site name diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV1StagingExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV1StagingExample.java index 6c88f7434..d1b8dcd09 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV1StagingExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV1StagingExample.java @@ -22,6 +22,7 @@ public class TheThingsNetworkV1StagingExample { private TheThingsNetworkV1StagingExample() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your client id and secret final String clientId = "your_client_id"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV2PreviewExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV2PreviewExample.java index 57aacac05..3c35b8be8 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV2PreviewExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV2PreviewExample.java @@ -22,6 +22,7 @@ public class TheThingsNetworkV2PreviewExample { private TheThingsNetworkV2PreviewExample() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your client id and secret final String clientId = "your_client_id"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TrelloExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TrelloExample.java index a73826a34..0909e9115 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TrelloExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TrelloExample.java @@ -21,6 +21,7 @@ public class TrelloExample { private TrelloExample() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { final OAuth10aService service = new ServiceBuilder(API_KEY) .apiSecret(API_SECRET) diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TumblrExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TumblrExample.java index 6d16ef54f..5ca71b373 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TumblrExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TumblrExample.java @@ -19,6 +19,7 @@ public class TumblrExample { private TumblrExample() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { final OAuth10aService service = new ServiceBuilder("MY_CONSUMER_KEY") .apiSecret("MY_CONSUMER_SECRET") diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TutByExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TutByExample.java index 70f05e5b2..393db2a65 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TutByExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TutByExample.java @@ -21,6 +21,7 @@ public class TutByExample { private TutByExample() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your client id and secret final String clientId = "your client id"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TwitterExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TwitterExample.java index 20b95531d..04d23911c 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TwitterExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TwitterExample.java @@ -19,6 +19,7 @@ public class TwitterExample { private TwitterExample() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { final OAuth10aService service = new ServiceBuilder("your client id") .apiSecret("your client secret") diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/UcozExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/UcozExample.java index dcf6e1fd5..899e2ed57 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/UcozExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/UcozExample.java @@ -20,6 +20,7 @@ public class UcozExample { private UcozExample() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { final OAuth10aService service = new ServiceBuilder("your_api_key") .apiSecret("your_api_secret") diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ViadeoExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ViadeoExample.java index 134faf3cc..c16bd9770 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ViadeoExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ViadeoExample.java @@ -19,6 +19,7 @@ public class ViadeoExample { private ViadeoExample() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your own api key and secret final String apiKey = "your_app_id"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteClientCredentialsGrantExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteClientCredentialsGrantExample.java index f9d4a4514..2b6e2d4f7 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteClientCredentialsGrantExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteClientCredentialsGrantExample.java @@ -14,6 +14,7 @@ public class VkontakteClientCredentialsGrantExample { private VkontakteClientCredentialsGrantExample() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your client id and secret final String clientId = "your client id"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExample.java index ca57c39f7..2c73d583d 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExample.java @@ -22,6 +22,7 @@ public class VkontakteExample { private VkontakteExample() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your client id and secret final String clientId = "your client id"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExternalHttpExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExternalHttpExample.java index abdf0b397..c918633c0 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExternalHttpExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExternalHttpExample.java @@ -23,6 +23,7 @@ public class VkontakteExternalHttpExample { private VkontakteExternalHttpExample() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your client id and secret final String clientId = "your client id"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/WunderlistExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/WunderlistExample.java index fd6fce936..5e9e9b52d 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/WunderlistExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/WunderlistExample.java @@ -21,6 +21,7 @@ public class WunderlistExample { private WunderlistExample() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your own values final String apiKey = "apiKey"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XingExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XingExample.java index 5cfd1d89d..c66ebb984 100755 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XingExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XingExample.java @@ -19,6 +19,7 @@ public class XingExample { private XingExample() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { final OAuth10aService service = new ServiceBuilder("your client id") .apiSecret("your client secret") diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Yahoo20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Yahoo20Example.java index 8102b4ea3..e151e8e5b 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Yahoo20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Yahoo20Example.java @@ -29,6 +29,7 @@ public class Yahoo20Example { private Yahoo20Example() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Add your personal information here final String clientId = "ADD CLIENT ID HERE!!!!"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/YahooExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/YahooExample.java index b75b8a447..455624cfd 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/YahooExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/YahooExample.java @@ -20,6 +20,7 @@ public class YahooExample { private YahooExample() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { final OAuth10aService service = new ServiceBuilder("your client id") .apiSecret("your client secret") From 163d5c7af0d4dbb0bfa77abc91524fc633df042f Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 27 Mar 2019 18:49:01 +0300 Subject: [PATCH 606/882] introduce PMD/category/java/bestpractices.xml/UnusedImports rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index fa2527ce9..8c86d5727 100644 --- a/pmd.xml +++ b/pmd.xml @@ -17,4 +17,5 @@ + From caf0bf5074f73b4c47ca9e2f8a4a4cfde65f0228 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 27 Mar 2019 19:00:47 +0300 Subject: [PATCH 607/882] introduce PMD/category/java/bestpractices.xml/UnusedLocalVariable rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 8c86d5727..ad141130a 100644 --- a/pmd.xml +++ b/pmd.xml @@ -18,4 +18,5 @@ + From a9abebf0359c2b961091f65478741b68ac19cca0 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 28 Mar 2019 16:29:08 +0300 Subject: [PATCH 608/882] introduce PMD/category/java/bestpractices.xml/UseAssertNullInsteadOfAssertTrue rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index ad141130a..576bc42d6 100644 --- a/pmd.xml +++ b/pmd.xml @@ -19,4 +19,5 @@ + From 6d15798f7ce5cfc70d7fb6d78131617d34827bb9 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 28 Mar 2019 16:46:15 +0300 Subject: [PATCH 609/882] introduce PMD/category/java/bestpractices.xml/UseAssertSameInsteadOfAssertTrue rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 576bc42d6..86b4a5e42 100644 --- a/pmd.xml +++ b/pmd.xml @@ -20,4 +20,5 @@ + From 2fc64208a351b3b7ca39b735a92b5c724374d644 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 28 Mar 2019 17:05:50 +0300 Subject: [PATCH 610/882] introduce PMD/category/java/bestpractices.xml/UseAssertTrueInsteadOfAssertEquals rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 86b4a5e42..66f5f55b1 100644 --- a/pmd.xml +++ b/pmd.xml @@ -21,4 +21,5 @@ + From 9b5013a696d1f536f52f53b204daaa50bd2ff62c Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 28 Mar 2019 17:17:57 +0300 Subject: [PATCH 611/882] introduce PMD/category/java/bestpractices.xml/UseCollectionIsEmpty rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 66f5f55b1..c4d0479fc 100644 --- a/pmd.xml +++ b/pmd.xml @@ -22,4 +22,5 @@ + From 04e6beea2095fd9ff0fd761ad2de4a130d428848 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 28 Mar 2019 17:25:34 +0300 Subject: [PATCH 612/882] introduce PMD/category/java/bestpractices.xml/UseTryWithResources rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index c4d0479fc..aa4bb843f 100644 --- a/pmd.xml +++ b/pmd.xml @@ -23,4 +23,5 @@ + From c722cb038d63f5132bfc07fcd682bf52ec33842c Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 28 Mar 2019 19:11:58 +0300 Subject: [PATCH 613/882] introduce PMD/category/java/codestyle.xml/AvoidDollarSigns rule --- pmd.xml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pmd.xml b/pmd.xml index aa4bb843f..b963acb63 100644 --- a/pmd.xml +++ b/pmd.xml @@ -24,4 +24,6 @@ + + From 8d81b4c8d35bab7c5c7894bde200c0f45a7e60ea Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 28 Mar 2019 19:15:27 +0300 Subject: [PATCH 614/882] introduce PMD/category/java/codestyle.xml/AvoidProtectedFieldInFinalClass rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index b963acb63..c7cca8510 100644 --- a/pmd.xml +++ b/pmd.xml @@ -26,4 +26,5 @@ + From 12f578f75a68958e5adccfdda684bbd2b8b744fd Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 28 Mar 2019 19:20:46 +0300 Subject: [PATCH 615/882] introduce PMD/category/java/codestyle.xml/AvoidProtectedMethodInFinalClassNotExtending rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index c7cca8510..84bc910d7 100644 --- a/pmd.xml +++ b/pmd.xml @@ -27,4 +27,5 @@ + From 946bf84251579afb7cd8e382fef0e582bdb70e48 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 28 Mar 2019 19:27:08 +0300 Subject: [PATCH 616/882] introduce PMD/category/java/codestyle.xml/BooleanGetMethodName rule --- pmd.xml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pmd.xml b/pmd.xml index 84bc910d7..85049489a 100644 --- a/pmd.xml +++ b/pmd.xml @@ -28,4 +28,9 @@ + + + true + + From bccbc594817a60ca1ae130f778d62de37d589004 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 29 Mar 2019 17:43:17 +0300 Subject: [PATCH 617/882] introduce PMD/category/java/codestyle.xml/ControlStatementBraces rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 85049489a..722aa43e0 100644 --- a/pmd.xml +++ b/pmd.xml @@ -33,4 +33,5 @@ true + From e843492791278761adb8a142ae4c2a44d5e485f3 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 29 Mar 2019 17:46:04 +0300 Subject: [PATCH 618/882] introduce PMD/category/java/codestyle.xml/DontImportJavaLang rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 722aa43e0..abfe6fbcb 100644 --- a/pmd.xml +++ b/pmd.xml @@ -34,4 +34,5 @@ + From 47a10e21189972ce2ebef5616423a86a6f336ddc Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 29 Mar 2019 17:47:50 +0300 Subject: [PATCH 619/882] introduce PMD/category/java/codestyle.xml/DuplicateImports rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index abfe6fbcb..ee423732a 100644 --- a/pmd.xml +++ b/pmd.xml @@ -35,4 +35,5 @@ + From ea5f7ea08945fac7a65e9b857e161fbe45144112 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 29 Mar 2019 17:53:36 +0300 Subject: [PATCH 620/882] introduce PMD/category/java/codestyle.xml/ExtendsObject rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index ee423732a..4f884821d 100644 --- a/pmd.xml +++ b/pmd.xml @@ -36,4 +36,5 @@ + From d67a7a69014b0c9bf8225914020741b7a0885ec0 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 29 Mar 2019 18:21:34 +0300 Subject: [PATCH 621/882] introduce PMD/category/java/codestyle.xml/FieldNamingConventions rule --- pmd.xml | 1 + .../github/scribejava/apis/FreelancerApi.java | 2 +- .../apis/fitbit/FitBitJsonTokenExtractor.java | 2 +- .../fitbit/FitBitJsonTokenExtractorTest.java | 2 +- .../core/builder/api/DefaultApi10a.java | 2 +- .../core/builder/api/OAuth1SignatureType.java | 4 ++-- .../OAuth2AccessTokenJsonExtractor.java | 2 +- .../model/OAuth2AccessTokenErrorResponse.java | 24 +++++++++++++++++-- .../core/oauth/OAuth10aService.java | 4 ++-- .../scribejava/core/oauth/OAuth20Service.java | 2 +- .../core/pkce/PKCECodeChallengeMethod.java | 2 +- .../scribejava/core/pkce/PKCEService.java | 4 ++-- .../scribejava/core/revoke/TokenTypeHint.java | 14 ++++++++++- .../OAuth2AccessTokenJsonExtractorTest.java | 2 +- 14 files changed, 50 insertions(+), 17 deletions(-) diff --git a/pmd.xml b/pmd.xml index 4f884821d..55885d489 100644 --- a/pmd.xml +++ b/pmd.xml @@ -37,4 +37,5 @@ + diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/FreelancerApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/FreelancerApi.java index b5c302ffc..33844d193 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/FreelancerApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/FreelancerApi.java @@ -21,7 +21,7 @@ public static FreelancerApi instance() { @Override public OAuth1SignatureType getSignatureType() { - return OAuth1SignatureType.QueryString; + return OAuth1SignatureType.QUERY_STRING; } @Override diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractor.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractor.java index fad86fc53..3679ee14a 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractor.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractor.java @@ -39,7 +39,7 @@ public void generateError(String response) { OAuth2AccessTokenErrorResponse.ErrorCode errorCode; try { - errorCode = OAuth2AccessTokenErrorResponse.ErrorCode.valueOf(errorInString); + errorCode = OAuth2AccessTokenErrorResponse.ErrorCode.parseFrom(errorInString); } catch (IllegalArgumentException iaE) { //non oauth standard error code errorCode = null; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractorTest.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractorTest.java index a0f5b53a3..448d5ff52 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractorTest.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractorTest.java @@ -28,7 +28,7 @@ public void testErrorExtraction() { final FitBitJsonTokenExtractor extractor = new FitBitJsonTokenExtractor(); thrown.expect(OAuth2AccessTokenErrorResponse.class); - thrown.expect(new ErrorCodeFeatureMatcher(ErrorCode.invalid_grant)); + thrown.expect(new ErrorCodeFeatureMatcher(ErrorCode.INVALID_GRANT)); thrown.expect(new ErrorDescriptionFeatureMatcher(ERROR_DESCRIPTION)); extractor.generateError(ERROR_JSON); diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi10a.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi10a.java index 6bd1c9392..2ea470110 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi10a.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi10a.java @@ -85,7 +85,7 @@ public SignatureService getSignatureService() { * @return the signature type, choose between header, querystring, etc. Defaults to Header */ public OAuth1SignatureType getSignatureType() { - return OAuth1SignatureType.Header; + return OAuth1SignatureType.HEADER; } /** diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/OAuth1SignatureType.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/OAuth1SignatureType.java index 7660b5826..7de68ff7b 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/OAuth1SignatureType.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/OAuth1SignatureType.java @@ -2,6 +2,6 @@ public enum OAuth1SignatureType { - Header, - QueryString + HEADER, + QUERY_STRING } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractor.java b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractor.java index e49831daf..a87e8ab82 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractor.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractor.java @@ -66,7 +66,7 @@ public void generateError(String response) { OAuth2AccessTokenErrorResponse.ErrorCode errorCode; try { - errorCode = OAuth2AccessTokenErrorResponse.ErrorCode.valueOf(errorInString); + errorCode = OAuth2AccessTokenErrorResponse.ErrorCode.parseFrom(errorInString); } catch (IllegalArgumentException iaE) { //non oauth standard error code errorCode = null; diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth2AccessTokenErrorResponse.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth2AccessTokenErrorResponse.java index 86ca38d88..57ada61de 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth2AccessTokenErrorResponse.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth2AccessTokenErrorResponse.java @@ -12,11 +12,31 @@ public class OAuth2AccessTokenErrorResponse extends OAuthException { private static final long serialVersionUID = 2309424849700276816L; public enum ErrorCode { - invalid_request, invalid_client, invalid_grant, unauthorized_client, unsupported_grant_type, invalid_scope, + INVALID_REQUEST("invalid_request"), + INVALID_CLIENT("invalid_client"), + INVALID_GRANT("invalid_grant"), + UNAUTHORIZED_CLIENT("unauthorized_client"), + UNSUPPORTED_GRANT_TYPE("unsupported_grant_type"), + INVALID_SCOPE("invalid_scope"), /** * @see RFC 7009, 2.2.1. Error Response */ - unsupported_token_type + UNSUPPORTED_TOKEN_TYPE("unsupported_token_type"); + + private final String errorCodeString; + + ErrorCode(String errorCodeString) { + this.errorCodeString = errorCodeString; + } + + public static ErrorCode parseFrom(String errorCodeString) { + for (ErrorCode errorCode : ErrorCode.values()) { + if (errorCode.errorCodeString.equals(errorCodeString)) { + return errorCode; + } + } + throw new IllegalArgumentException("there is no knowlege about '" + errorCodeString + "' ErrorCode"); + } } private final ErrorCode errorCode; diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java index a2dc08142..3e67bf1ad 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java @@ -171,13 +171,13 @@ private String getSignature(OAuthRequest request, String tokenSecret) { protected void appendSignature(OAuthRequest request) { final OAuth1SignatureType signatureType = api.getSignatureType(); switch (signatureType) { - case Header: + case HEADER: log("using Http Header signature"); final String oauthHeader = api.getHeaderExtractor().extract(request); request.addHeader(OAuthConstants.HEADER, oauthHeader); break; - case QueryString: + case QUERY_STRING: log("using Querystring signature"); for (Map.Entry oauthParameter : request.getOauthParameters().entrySet()) { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java index 13a3ed4ef..df4557ea0 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java @@ -355,7 +355,7 @@ protected OAuthRequest createRevokeTokenRequest(String tokenToRevoke, TokenTypeH request.addParameter("token", tokenToRevoke); if (tokenTypeHint != null) { - request.addParameter("token_type_hint", tokenTypeHint.toString()); + request.addParameter("token_type_hint", tokenTypeHint.getValue()); } return request; } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/pkce/PKCECodeChallengeMethod.java b/scribejava-core/src/main/java/com/github/scribejava/core/pkce/PKCECodeChallengeMethod.java index 29648859c..08bb60c5b 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/pkce/PKCECodeChallengeMethod.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/pkce/PKCECodeChallengeMethod.java @@ -15,7 +15,7 @@ public String transform2CodeChallenge(String codeVerifier) throws NoSuchAlgorith MessageDigest.getInstance("SHA-256").digest(codeVerifier.getBytes(StandardCharsets.US_ASCII))); } }, - plain { + PLAIN { @Override public String transform2CodeChallenge(String codeVerifier) { return codeVerifier; diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/pkce/PKCEService.java b/scribejava-core/src/main/java/com/github/scribejava/core/pkce/PKCEService.java index 8709174b8..eea3e7b94 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/pkce/PKCEService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/pkce/PKCEService.java @@ -51,9 +51,9 @@ public PKCE generatePKCE(byte[] randomBytes) { try { pkce.setCodeChallenge(pkce.getCodeChallengeMethod().transform2CodeChallenge(codeVerifier)); } catch (NoSuchAlgorithmException nsaE) { - pkce.setCodeChallengeMethod(PKCECodeChallengeMethod.plain); + pkce.setCodeChallengeMethod(PKCECodeChallengeMethod.PLAIN); try { - pkce.setCodeChallenge(PKCECodeChallengeMethod.plain.transform2CodeChallenge(codeVerifier)); + pkce.setCodeChallenge(PKCECodeChallengeMethod.PLAIN.transform2CodeChallenge(codeVerifier)); } catch (NoSuchAlgorithmException unrealE) { throw new IllegalStateException("It's just cannot be", unrealE); } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/revoke/TokenTypeHint.java b/scribejava-core/src/main/java/com/github/scribejava/core/revoke/TokenTypeHint.java index 55a95057e..450bd691b 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/revoke/TokenTypeHint.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/revoke/TokenTypeHint.java @@ -8,5 +8,17 @@ * @see RFC 7009, 2.1. Revocation Request */ public enum TokenTypeHint { - access_token, refresh_token + ACCESS_TOKEN("access_token"), + REFRESH_TOKEN("refresh_token"); + + private final String value; + + TokenTypeHint(String value) { + this.value = value; + } + + public String getValue() { + return value; + } + } diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractorTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractorTest.java index 3aa80cd30..5d00d89e0 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractorTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractorTest.java @@ -65,7 +65,7 @@ public void shouldThrowExceptionIfResponseIsError() throws IOException { extractor.extract(error(body)); fail(); } catch (OAuth2AccessTokenErrorResponse oaer) { - assertEquals(OAuth2AccessTokenErrorResponse.ErrorCode.invalid_grant, oaer.getErrorCode()); + assertEquals(OAuth2AccessTokenErrorResponse.ErrorCode.INVALID_GRANT, oaer.getErrorCode()); assertEquals("unknown, invalid, or expired refresh token", oaer.getErrorDescription()); } } From e4ec62a9860d2bcce48f2a175636cdc2a8a0c6d7 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 1 Apr 2019 13:38:45 +0300 Subject: [PATCH 622/882] add deprecation note for TokenTypeHint::toString method --- .../github/scribejava/core/revoke/TokenTypeHint.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/revoke/TokenTypeHint.java b/scribejava-core/src/main/java/com/github/scribejava/core/revoke/TokenTypeHint.java index 450bd691b..c041d3efc 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/revoke/TokenTypeHint.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/revoke/TokenTypeHint.java @@ -21,4 +21,15 @@ public String getValue() { return value; } + /** + * @return value + * @deprecated use {@link #getValue() } to get a lower-cased value as in reference (RFC7009), otherwise you can + * continue using this method. Note, that returned value will be UPPER-cased (not overrided toString method) in the + * next release. + */ + @Override + @Deprecated + public String toString() { + return value; + } } From 477587fa2d4e4ee6f3ed9d257d6e594526e4a4f6 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 1 Apr 2019 13:45:36 +0300 Subject: [PATCH 623/882] introduce PMD/category/java/codestyle.xml/ForLoopShouldBeWhileLoop rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 55885d489..1bacb8f9a 100644 --- a/pmd.xml +++ b/pmd.xml @@ -38,4 +38,5 @@ + From d36c4914a667613e8e798ef722bea648c0710090 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 1 Apr 2019 15:27:18 +0300 Subject: [PATCH 624/882] introduce PMD/category/java/codestyle.xml/FormalParameterNamingConventions rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 1bacb8f9a..475b5ed13 100644 --- a/pmd.xml +++ b/pmd.xml @@ -39,4 +39,5 @@ + From 55ed61e5db9cf2d917fa1fdbe0c380c9ad6e0e9b Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 1 Apr 2019 16:45:39 +0300 Subject: [PATCH 625/882] introduce PMD/category/java/codestyle.xml/IdenticalCatchBranches rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 475b5ed13..8ae744551 100644 --- a/pmd.xml +++ b/pmd.xml @@ -40,4 +40,5 @@ + From 3c5e14672d616cc0cb516e9df6b161730afa7830 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 1 Apr 2019 18:41:30 +0300 Subject: [PATCH 626/882] introduce PMD/category/java/codestyle.xml/LocalVariableNamingConventions rule --- pmd.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pmd.xml b/pmd.xml index 8ae744551..caa78ca37 100644 --- a/pmd.xml +++ b/pmd.xml @@ -28,7 +28,7 @@ - + true @@ -41,4 +41,5 @@ + From 8efe8cc585173797562a823948e902319475885f Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 1 Apr 2019 18:46:44 +0300 Subject: [PATCH 627/882] introduce PMD/category/java/codestyle.xml/MethodNamingConventions rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index caa78ca37..8a3424a06 100644 --- a/pmd.xml +++ b/pmd.xml @@ -42,4 +42,5 @@ + From ba3458aa825b81b1f34c8960031f785424e5ccea Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 1 Apr 2019 18:48:59 +0300 Subject: [PATCH 628/882] introduce PMD/category/java/codestyle.xml/NoPackage rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 8a3424a06..417a99b53 100644 --- a/pmd.xml +++ b/pmd.xml @@ -43,4 +43,5 @@ + From 3c6ab96ab21469accaf4d526b33fe9d8596ad3d2 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 1 Apr 2019 18:51:15 +0300 Subject: [PATCH 629/882] introduce PMD/category/java/codestyle.xml/PackageCase rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 417a99b53..ead5d39ea 100644 --- a/pmd.xml +++ b/pmd.xml @@ -44,4 +44,5 @@ + From a1a75d0b2fce6520c81ffb62b08acb7185d24cd3 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 2 Apr 2019 19:33:33 +0300 Subject: [PATCH 630/882] introduce PMD/category/java/codestyle.xml/UnnecessaryAnnotationValueElement rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index ead5d39ea..0738453c2 100644 --- a/pmd.xml +++ b/pmd.xml @@ -45,4 +45,5 @@ + From e7dd8e5d3d15d1b16efad3d077b7817b38b21447 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 2 Apr 2019 19:44:27 +0300 Subject: [PATCH 631/882] introduce PMD/category/java/codestyle.xml/UnnecessaryConstructor rule --- pmd.xml | 1 + .../src/main/java/com/github/scribejava/apis/NaverApi.java | 3 --- .../com/github/scribejava/core/oauth/OAuth20ServiceTest.java | 4 ---- 3 files changed, 1 insertion(+), 7 deletions(-) diff --git a/pmd.xml b/pmd.xml index 0738453c2..89c1cf62b 100644 --- a/pmd.xml +++ b/pmd.xml @@ -46,4 +46,5 @@ + diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/NaverApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/NaverApi.java index 3ff3a9b0a..f60871735 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/NaverApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/NaverApi.java @@ -10,9 +10,6 @@ protected NaverApi() { private static class InstanceHolder { private static final NaverApi INSTANCE = new NaverApi(); - - private InstanceHolder() { - } } public static NaverApi instance() { diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceTest.java index b876d2d87..3590e6b5d 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceTest.java @@ -121,9 +121,5 @@ public void testOAuthExtractAuthorization() { } private static class TypeTokenImpl extends TypeToken> { - - private TypeTokenImpl() { - } } - } From d27362811eb82b35a9da30e395d805fbd6b8f918 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 3 Apr 2019 14:03:36 +0300 Subject: [PATCH 632/882] introduce PMD/category/java/codestyle.xml/UnnecessaryFullyQualifiedName rule --- pmd.xml | 1 + .../test/java/com/github/scribejava/apis/ExampleUtils.java | 2 +- .../httpclient/okhttp/OAuthAsyncCompletionHandlerTest.java | 6 +++--- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/pmd.xml b/pmd.xml index 89c1cf62b..998e9941d 100644 --- a/pmd.xml +++ b/pmd.xml @@ -47,4 +47,5 @@ + diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/ExampleUtils.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/ExampleUtils.java index 195729b3c..f5917bcda 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/ExampleUtils.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/ExampleUtils.java @@ -19,7 +19,7 @@ public static void turnOfSSl() { try { final TrustManager[] trustAllCerts = new TrustManager[]{new X509TrustManager() { @Override - public java.security.cert.X509Certificate[] getAcceptedIssuers() { + public X509Certificate[] getAcceptedIssuers() { return null; } diff --git a/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/OAuthAsyncCompletionHandlerTest.java b/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/OAuthAsyncCompletionHandlerTest.java index 863d2eee3..645c45557 100644 --- a/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/OAuthAsyncCompletionHandlerTest.java +++ b/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/OAuthAsyncCompletionHandlerTest.java @@ -72,7 +72,7 @@ public void shouldReleaseLatchOnSuccess() throws Exception { handler = new OAuthAsyncCompletionHandler<>(callback, ALL_GOOD_RESPONSE_CONVERTER, future); call.enqueue(handler); - final okhttp3.Request request = new Request.Builder().url("http://localhost/").build(); + final Request request = new Request.Builder().url("http://localhost/").build(); final okhttp3.Response response = new okhttp3.Response.Builder() .request(request) .protocol(Protocol.HTTP_1_1) @@ -92,7 +92,7 @@ public void shouldReleaseLatchOnIOException() throws Exception { handler = new OAuthAsyncCompletionHandler<>(callback, EXCEPTION_RESPONSE_CONVERTER, future); call.enqueue(handler); - final okhttp3.Request request = new Request.Builder().url("http://localhost/").build(); + final Request request = new Request.Builder().url("http://localhost/").build(); final okhttp3.Response response = new okhttp3.Response.Builder() .request(request) .protocol(Protocol.HTTP_1_1) @@ -118,7 +118,7 @@ public void shouldReportOAuthException() throws Exception { handler = new OAuthAsyncCompletionHandler<>(callback, OAUTH_EXCEPTION_RESPONSE_CONVERTER, future); call.enqueue(handler); - final okhttp3.Request request = new Request.Builder().url("http://localhost/").build(); + final Request request = new Request.Builder().url("http://localhost/").build(); final okhttp3.Response response = new okhttp3.Response.Builder() .request(request) .protocol(Protocol.HTTP_1_1) From 3643fc2b52ef4ec7e95481cd6c03f728dc399e6c Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 3 Apr 2019 14:07:40 +0300 Subject: [PATCH 633/882] introduce PMD/category/java/codestyle.xml/UnnecessaryModifier rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 998e9941d..6abbac788 100644 --- a/pmd.xml +++ b/pmd.xml @@ -48,4 +48,5 @@ + From e49dcea29dc4913e7f2f72fc565ba408ce8a5e42 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 3 Apr 2019 14:23:42 +0300 Subject: [PATCH 634/882] introduce PMD/category/java/codestyle.xml/UnnecessaryReturn rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 6abbac788..e9b66c874 100644 --- a/pmd.xml +++ b/pmd.xml @@ -49,4 +49,5 @@ + From 91ce572f988c3b680a1c770e4e90c0bdd7f017ac Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 3 Apr 2019 14:30:05 +0300 Subject: [PATCH 635/882] introduce PMD/category/java/codestyle.xml/UselessParentheses rule --- pmd.xml | 1 + .../src/main/java/com/github/scribejava/core/java8/Base64.java | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/pmd.xml b/pmd.xml index e9b66c874..578935a1b 100644 --- a/pmd.xml +++ b/pmd.xml @@ -50,4 +50,5 @@ + diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/java8/Base64.java b/scribejava-core/src/main/java/com/github/scribejava/core/java8/Base64.java index 59d1fdc2b..9e855a617 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/java8/Base64.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/java8/Base64.java @@ -627,7 +627,7 @@ private int outLength(byte[] src, int sp, int sl) { while (sp < sl) { int b = src[sp++] & 0xff; if (b == '=') { - len -= (sl - sp + 1); + len -= sl - sp + 1; break; } b = base64[b]; From 91100833a34051edd2ac82cb8d1372db57ac9ac8 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 3 Apr 2019 14:36:38 +0300 Subject: [PATCH 636/882] introduce PMD/category/java/codestyle.xml/UselessQualifiedThis rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 578935a1b..3383e082a 100644 --- a/pmd.xml +++ b/pmd.xml @@ -51,4 +51,5 @@ + From fbf933db419711bc4d8f7c816d19e6fb08060430 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 3 Apr 2019 14:52:11 +0300 Subject: [PATCH 637/882] introduce PMD/category/java/design.xml/AbstractClassWithoutAnyMethod rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 3383e082a..5eff22b01 100644 --- a/pmd.xml +++ b/pmd.xml @@ -52,4 +52,5 @@ + From e41c220c67b1017b8e1cf989cb306cf7c6d0c6ca Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 3 Apr 2019 14:57:47 +0300 Subject: [PATCH 638/882] introduce PMD/category/java/design.xml/AvoidThrowingNewInstanceOfSameException rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 5eff22b01..47072ed72 100644 --- a/pmd.xml +++ b/pmd.xml @@ -53,4 +53,5 @@ + From 6ba97ec3960d2d81347b8003220916c37a31ed3f Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 3 Apr 2019 16:32:12 +0300 Subject: [PATCH 639/882] introduce PMD/category/java/design.xml/CollapsibleIfStatements rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 47072ed72..5765899f6 100644 --- a/pmd.xml +++ b/pmd.xml @@ -54,4 +54,5 @@ + From 0fc534b94c4d70603ad778fa425f6fa74be1a2a8 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 3 Apr 2019 16:36:51 +0300 Subject: [PATCH 640/882] introduce PMD/category/java/design.xml/DoNotExtendJavaLangError rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 5765899f6..9bc405aac 100644 --- a/pmd.xml +++ b/pmd.xml @@ -55,4 +55,5 @@ + From 8362b1773212b5d6229befe58f9dc7b1f0ca2bea Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 4 Apr 2019 12:41:20 +0300 Subject: [PATCH 641/882] introduce PMD/category/java/design.xml/LogicInversion rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 9bc405aac..533ab8cc6 100644 --- a/pmd.xml +++ b/pmd.xml @@ -56,4 +56,5 @@ + From 90cde591187623c68a97a0ccf6b8c0f92fd478c9 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 4 Apr 2019 13:35:36 +0300 Subject: [PATCH 642/882] introduce PMD/category/java/design.xml/SimplifiedTernary rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 533ab8cc6..6716713e4 100644 --- a/pmd.xml +++ b/pmd.xml @@ -57,4 +57,5 @@ + From 054dde3f21a23771f4fba3eddd7dc0be879f3aee Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 4 Apr 2019 13:53:39 +0300 Subject: [PATCH 643/882] introduce PMD/category/java/design.xml/SimplifyBooleanAssertion rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 6716713e4..fe37edaa5 100644 --- a/pmd.xml +++ b/pmd.xml @@ -58,4 +58,5 @@ + From da3a03e05b30e2c0a98ad049df003a3ea06022f1 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 4 Apr 2019 13:58:07 +0300 Subject: [PATCH 644/882] introduce PMD/category/java/design.xml/SimplifyBooleanExpressions rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index fe37edaa5..e159f2538 100644 --- a/pmd.xml +++ b/pmd.xml @@ -59,4 +59,5 @@ + From 5cfa2456de32be35fa6ac32c0166e535f00aa750 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 4 Apr 2019 14:16:47 +0300 Subject: [PATCH 645/882] introduce PMD/category/java/design.xml/SimplifyBooleanReturns rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index e159f2538..a0332f3d7 100644 --- a/pmd.xml +++ b/pmd.xml @@ -60,4 +60,5 @@ + From 88966d4a07832751f1a5e5634e67435ef773da2e Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 4 Apr 2019 14:31:24 +0300 Subject: [PATCH 646/882] introduce PMD/category/java/design.xml/SimplifyConditional rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index a0332f3d7..efd6ad411 100644 --- a/pmd.xml +++ b/pmd.xml @@ -61,4 +61,5 @@ + From 851051d6657e337e42647da9994ca5218ccecb84 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 4 Apr 2019 17:06:14 +0300 Subject: [PATCH 647/882] introduce PMD/category/java/design.xml/UseUtilityClass rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index efd6ad411..ce5c6a428 100644 --- a/pmd.xml +++ b/pmd.xml @@ -62,4 +62,5 @@ + From 8d5ef48496fa8d840b969403e011ecdcb6afb1d0 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 4 Apr 2019 17:20:31 +0300 Subject: [PATCH 648/882] introduce PMD/category/java/errorprone.xml/AvoidAssertAsIdentifier rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index ce5c6a428..f6c5a926c 100644 --- a/pmd.xml +++ b/pmd.xml @@ -63,4 +63,5 @@ + From 26a420b536518dfa73c32fafa31465efa9e5785d Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 4 Apr 2019 17:39:31 +0300 Subject: [PATCH 649/882] introduce PMD/category/java/errorprone.xml/AvoidBranchingStatementAsLastInLoop rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index f6c5a926c..caec51815 100644 --- a/pmd.xml +++ b/pmd.xml @@ -64,4 +64,5 @@ + From 5c0cccbf5d74619ef6078c73183365491e494eb8 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 4 Apr 2019 17:51:04 +0300 Subject: [PATCH 650/882] introduce PMD/category/java/errorprone.xml/AvoidCallingFinalize rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index caec51815..3351e91b7 100644 --- a/pmd.xml +++ b/pmd.xml @@ -65,4 +65,5 @@ + From 1a4d255f9d879380b5e93bb1a3c6f4a0effcedb2 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 4 Apr 2019 18:02:46 +0300 Subject: [PATCH 651/882] introduce PMD/category/java/errorprone.xml/AvoidEnumAsIdentifier rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 3351e91b7..1e3645a87 100644 --- a/pmd.xml +++ b/pmd.xml @@ -66,4 +66,5 @@ + From 6f3eb2bf9937662ce9ae73773028d745e5a5b884 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 4 Apr 2019 18:17:58 +0300 Subject: [PATCH 652/882] introduce PMD/category/java/errorprone.xml/AvoidLosingExceptionInformation rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 1e3645a87..20d8a6b11 100644 --- a/pmd.xml +++ b/pmd.xml @@ -67,4 +67,5 @@ + From f1ab512e23d45e77a9d3ef089a642e5dc7f832b4 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 4 Apr 2019 18:26:10 +0300 Subject: [PATCH 653/882] introduce PMD/category/java/errorprone.xml/AvoidMultipleUnaryOperators rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 20d8a6b11..6c459475b 100644 --- a/pmd.xml +++ b/pmd.xml @@ -68,4 +68,5 @@ + From 224248e1a8ab11f8c9c5cac390074b7ae7fad9f5 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 4 Apr 2019 18:30:02 +0300 Subject: [PATCH 654/882] introduce PMD/category/java/errorprone.xml/BrokenNullCheck rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 6c459475b..0bdcc86c2 100644 --- a/pmd.xml +++ b/pmd.xml @@ -69,4 +69,5 @@ + From 01a6e80661c5e85f779727f4d912976cf61e66c0 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 4 Apr 2019 18:33:10 +0300 Subject: [PATCH 655/882] introduce PMD/category/java/errorprone.xml/ClassCastExceptionWithToArray rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 0bdcc86c2..4fafa2891 100644 --- a/pmd.xml +++ b/pmd.xml @@ -70,4 +70,5 @@ + From 860e8d7a2df7bf2817bfa87bc97030c45783c721 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 4 Apr 2019 18:37:08 +0300 Subject: [PATCH 656/882] introduce PMD/category/java/errorprone.xml/CloneMethodMustBePublic rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 4fafa2891..eda022c06 100644 --- a/pmd.xml +++ b/pmd.xml @@ -71,4 +71,5 @@ + From 3cf82496224960f99b36c7574901e51254c46f59 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 4 Apr 2019 18:39:34 +0300 Subject: [PATCH 657/882] introduce PMD/category/java/errorprone.xml/CloneMethodMustImplementCloneable rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index eda022c06..08d9b6e35 100644 --- a/pmd.xml +++ b/pmd.xml @@ -72,4 +72,5 @@ + From 9137ca6a369c5311127569dd8af172243a03655b Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 4 Apr 2019 18:41:52 +0300 Subject: [PATCH 658/882] introduce PMD/category/java/errorprone.xml/CloneMethodReturnTypeMustMatchClassName rule --- pmd.xml | 1 + .../java/com/github/scribejava/httpclient/okhttp/MockCall.java | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/pmd.xml b/pmd.xml index 08d9b6e35..b2889b695 100644 --- a/pmd.xml +++ b/pmd.xml @@ -73,4 +73,5 @@ + diff --git a/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/MockCall.java b/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/MockCall.java index c6dabd4c2..7fa14a630 100644 --- a/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/MockCall.java +++ b/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/MockCall.java @@ -49,7 +49,7 @@ public boolean isExecuted() { } @Override - public Call clone() { + public MockCall clone() { throw new UnsupportedOperationException("Not supported yet."); } From a4ff03fee9599a95334af9fe65e54768444a4100 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 4 Apr 2019 19:31:49 +0300 Subject: [PATCH 659/882] introduce PMD/category/java/errorprone.xml/ConstructorCallsOverridableMethod rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index b2889b695..80ec8008b 100644 --- a/pmd.xml +++ b/pmd.xml @@ -74,4 +74,5 @@ + From c4898b990b7772699ea8fa449be4a7734f3d1df0 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 5 Apr 2019 11:40:22 +0300 Subject: [PATCH 660/882] introduce PMD/category/java/errorprone.xml/DoNotExtendJavaLangThrowable rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 80ec8008b..4707335a6 100644 --- a/pmd.xml +++ b/pmd.xml @@ -75,4 +75,5 @@ + From 6ee14a89d6d397d641f36fcc2f021af01f9c9cfc Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 5 Apr 2019 12:02:14 +0300 Subject: [PATCH 661/882] introduce PMD/category/java/errorprone.xml/DontImportSun rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 4707335a6..64b3f05c9 100644 --- a/pmd.xml +++ b/pmd.xml @@ -76,4 +76,5 @@ + From daebd4d3bdeced3288ac36220fe468cfd2048efd Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 5 Apr 2019 12:06:43 +0300 Subject: [PATCH 662/882] introduce PMD/category/java/errorprone.xml/EmptyFinalizer rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 64b3f05c9..cc0a36d89 100644 --- a/pmd.xml +++ b/pmd.xml @@ -77,4 +77,5 @@ + From 245682f32ee135dee76b0ec697d988cd087bd14e Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 5 Apr 2019 12:08:27 +0300 Subject: [PATCH 663/882] introduce PMD/category/java/errorprone.xml/EmptyFinallyBlock rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index cc0a36d89..42faf3351 100644 --- a/pmd.xml +++ b/pmd.xml @@ -78,4 +78,5 @@ + From 1b1846c3a6891ce45739d1514885848182983fc6 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 5 Apr 2019 12:12:02 +0300 Subject: [PATCH 664/882] introduce PMD/category/java/errorprone.xml/EmptyIfStmt rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 42faf3351..c3116e8dd 100644 --- a/pmd.xml +++ b/pmd.xml @@ -79,4 +79,5 @@ + From 667eef0748851e096d40b92c21fe5bc23f48b12e Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 5 Apr 2019 12:14:21 +0300 Subject: [PATCH 665/882] introduce PMD/category/java/errorprone.xml/EmptyInitializer rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index c3116e8dd..28df9569c 100644 --- a/pmd.xml +++ b/pmd.xml @@ -80,4 +80,5 @@ + From ac9eae5c0f5c7c4d95d6230ee373b5f804391c54 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 5 Apr 2019 12:17:54 +0300 Subject: [PATCH 666/882] introduce PMD/category/java/errorprone.xml/EmptyStatementBlock rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 28df9569c..e25acfb20 100644 --- a/pmd.xml +++ b/pmd.xml @@ -81,4 +81,5 @@ + From 6b22afbb936bf2ce1d32cc20499ab75118d2677e Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 5 Apr 2019 12:20:45 +0300 Subject: [PATCH 667/882] introduce PMD/category/java/errorprone.xml/EmptyStatementNotInLoop rule --- pmd.xml | 1 + .../scribejava/httpclient/ahc/OAuthAsyncCompletionHandler.java | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/pmd.xml b/pmd.xml index e25acfb20..58c576c70 100644 --- a/pmd.xml +++ b/pmd.xml @@ -82,4 +82,5 @@ + diff --git a/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/OAuthAsyncCompletionHandler.java b/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/OAuthAsyncCompletionHandler.java index 08706c195..0cb77af25 100644 --- a/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/OAuthAsyncCompletionHandler.java +++ b/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/OAuthAsyncCompletionHandler.java @@ -48,4 +48,4 @@ public void onThrowable(Throwable t) { callback.onThrowable(t); } } -}; +} From ec92064cb308e1ec65d0937f6955bea60fbd4be5 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 5 Apr 2019 12:23:14 +0300 Subject: [PATCH 668/882] introduce PMD/category/java/errorprone.xml/EmptySwitchStatements rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 58c576c70..12222308b 100644 --- a/pmd.xml +++ b/pmd.xml @@ -83,4 +83,5 @@ + From b98d84a25f064e598fceb991ba30690f8f78a000 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 5 Apr 2019 12:26:22 +0300 Subject: [PATCH 669/882] introduce PMD/category/java/errorprone.xml/EmptyTryBlock rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 12222308b..8e6d3ad5e 100644 --- a/pmd.xml +++ b/pmd.xml @@ -84,4 +84,5 @@ + From 09a5aba91e125d462ffcf2f45a251b51383863e8 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 5 Apr 2019 12:28:43 +0300 Subject: [PATCH 670/882] introduce PMD/category/java/errorprone.xml/EmptyWhileStmt rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 8e6d3ad5e..5fafcb9cb 100644 --- a/pmd.xml +++ b/pmd.xml @@ -85,4 +85,5 @@ + From 0c97686d526bf3abd70261b7db7601cc2babeeb1 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 5 Apr 2019 12:30:54 +0300 Subject: [PATCH 671/882] introduce PMD/category/java/errorprone.xml/EqualsNull rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 5fafcb9cb..89e65a84e 100644 --- a/pmd.xml +++ b/pmd.xml @@ -86,4 +86,5 @@ + From 0798550643dadfd291f1fb3ab6839d9480531fb8 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 5 Apr 2019 12:34:24 +0300 Subject: [PATCH 672/882] introduce PMD/category/java/errorprone.xml/FinalizeDoesNotCallSuperFinalize rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 89e65a84e..92abb1977 100644 --- a/pmd.xml +++ b/pmd.xml @@ -87,4 +87,5 @@ + From 9d69b65ee153dc28c6f0d867e88dccdf6ff819a6 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 5 Apr 2019 12:36:46 +0300 Subject: [PATCH 673/882] introduce PMD/category/java/errorprone.xml/FinalizeOnlyCallsSuperFinalize rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 92abb1977..088b01c19 100644 --- a/pmd.xml +++ b/pmd.xml @@ -88,4 +88,5 @@ + From 818aeed7a3a4e7ab5d24cc53ccd3da1c82c71a4d Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 5 Apr 2019 12:39:17 +0300 Subject: [PATCH 674/882] introduce PMD/category/java/errorprone.xml/FinalizeShouldBeProtected rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 088b01c19..5a05e2948 100644 --- a/pmd.xml +++ b/pmd.xml @@ -89,4 +89,5 @@ + From 7cba688df0e232222093b33b292199cc016d2bc5 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 5 Apr 2019 12:47:56 +0300 Subject: [PATCH 675/882] introduce PMD/category/java/errorprone.xml/IdempotentOperations rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 5a05e2948..56904bd31 100644 --- a/pmd.xml +++ b/pmd.xml @@ -90,4 +90,5 @@ + From bf163177d50232f994fa8d217a8875c2ec8aaa7f Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 5 Apr 2019 12:49:55 +0300 Subject: [PATCH 676/882] introduce PMD/category/java/errorprone.xml/ImportFromSamePackage rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 56904bd31..bc2c24a37 100644 --- a/pmd.xml +++ b/pmd.xml @@ -91,4 +91,5 @@ + From 15a2f53d4155c121c5ff72d2663f2698880c00ed Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 5 Apr 2019 12:56:37 +0300 Subject: [PATCH 677/882] introduce PMD/category/java/errorprone.xml/InstantiationToGetClass rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index bc2c24a37..7dfd56345 100644 --- a/pmd.xml +++ b/pmd.xml @@ -92,4 +92,5 @@ + From 7153f5ba292f140204a57365e6d376bc7f46f569 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 5 Apr 2019 13:45:50 +0300 Subject: [PATCH 678/882] introduce PMD/category/java/errorprone.xml/InvalidSlf4jMessageFormat rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 7dfd56345..ede4de616 100644 --- a/pmd.xml +++ b/pmd.xml @@ -93,4 +93,5 @@ + From 72ac67adadf1c6af7eb61493bdf5e2c54e238d6b Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 5 Apr 2019 13:58:57 +0300 Subject: [PATCH 679/882] introduce PMD/category/java/errorprone.xml/MissingStaticMethodInNonInstantiatableClass rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index ede4de616..20659404d 100644 --- a/pmd.xml +++ b/pmd.xml @@ -94,4 +94,5 @@ + From 0a88b7a2c18accde7256e6a44d1d9ecbddb15613 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 5 Apr 2019 14:08:27 +0300 Subject: [PATCH 680/882] introduce PMD/category/java/errorprone.xml/StringBufferInstantiationWithChar rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 20659404d..00e3455ce 100644 --- a/pmd.xml +++ b/pmd.xml @@ -95,4 +95,5 @@ + From fa2639c36c9ec669efdb223be35cf2765d5b9cec Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 5 Apr 2019 14:41:15 +0300 Subject: [PATCH 681/882] introduce PMD/category/java/errorprone.xml/UnconditionalIfStatement rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 00e3455ce..3682fb33f 100644 --- a/pmd.xml +++ b/pmd.xml @@ -96,4 +96,5 @@ + From 194c224f26da2a52499f601b065df6de147f994a Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 5 Apr 2019 14:48:24 +0300 Subject: [PATCH 682/882] introduce PMD/category/java/errorprone.xml/UnnecessaryBooleanAssertion rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 3682fb33f..6f1eba1f5 100644 --- a/pmd.xml +++ b/pmd.xml @@ -97,4 +97,5 @@ + From ef126c53c11abebcb09d88655def187136ad2f43 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 5 Apr 2019 15:00:05 +0300 Subject: [PATCH 683/882] introduce PMD/category/java/errorprone.xml/UnnecessaryConversionTemporary rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 6f1eba1f5..a1b0ce615 100644 --- a/pmd.xml +++ b/pmd.xml @@ -98,4 +98,5 @@ + From f30bf9fb9f7d10d3d71c1bc197cbb0b104e76675 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 5 Apr 2019 15:17:24 +0300 Subject: [PATCH 684/882] introduce PMD/category/java/errorprone.xml/UselessOperationOnImmutable rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index a1b0ce615..562364e08 100644 --- a/pmd.xml +++ b/pmd.xml @@ -99,4 +99,5 @@ + From 7263e338576326ecc76f24e557cd1719f650273d Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 5 Apr 2019 15:22:34 +0300 Subject: [PATCH 685/882] introduce PMD/category/java/multithreading.xml/DoubleCheckedLocking rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 562364e08..13c3a90cc 100644 --- a/pmd.xml +++ b/pmd.xml @@ -100,4 +100,5 @@ + From dc297ce6fe8665ec0ec409e1b9f93e2b12a3e07a Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 5 Apr 2019 15:55:08 +0300 Subject: [PATCH 686/882] introduce PMD/category/java/multithreading.xml/NonThreadSafeSingleton rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 13c3a90cc..d591af97e 100644 --- a/pmd.xml +++ b/pmd.xml @@ -101,4 +101,5 @@ + From 50cd8524992ed75473d0bde6853d497603360199 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 5 Apr 2019 16:10:39 +0300 Subject: [PATCH 687/882] introduce PMD/category/java/multithreading.xml/UnsynchronizedStaticFormatter rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index d591af97e..a9d8f109b 100644 --- a/pmd.xml +++ b/pmd.xml @@ -102,4 +102,5 @@ + From 39f02cc369d834df59b73b78f486d2c7ca20df41 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 5 Apr 2019 16:42:01 +0300 Subject: [PATCH 688/882] introduce PMD/category/java/performance.xml/AddEmptyString rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index a9d8f109b..ced4cd7b1 100644 --- a/pmd.xml +++ b/pmd.xml @@ -103,4 +103,5 @@ + From 128a12cff8ad5abb480a5235437e66d0ad9cef97 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 5 Apr 2019 16:53:32 +0300 Subject: [PATCH 689/882] introduce PMD/category/java/performance.xml/AppendCharacterWithChar rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index ced4cd7b1..3e81fab5c 100644 --- a/pmd.xml +++ b/pmd.xml @@ -104,4 +104,5 @@ + From ad666fec4796891fbdcd8344f68ec44a1a70b3f8 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 5 Apr 2019 16:56:04 +0300 Subject: [PATCH 690/882] introduce PMD/category/java/performance.xml/AvoidArrayLoops rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 3e81fab5c..bc3aa8b7f 100644 --- a/pmd.xml +++ b/pmd.xml @@ -105,4 +105,5 @@ + From 08f62983245d4352c652f3acdc8c1dad1d3c38d6 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 5 Apr 2019 18:04:14 +0300 Subject: [PATCH 691/882] introduce PMD/category/java/performance.xml/BigIntegerInstantiation rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index bc3aa8b7f..f135bc012 100644 --- a/pmd.xml +++ b/pmd.xml @@ -106,4 +106,5 @@ + From 07349a49f159a12c04521a8f99266fe66429c421 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 5 Apr 2019 18:06:07 +0300 Subject: [PATCH 692/882] introduce PMD/category/java/performance.xml/BooleanInstantiation rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index f135bc012..6690404cc 100644 --- a/pmd.xml +++ b/pmd.xml @@ -107,4 +107,5 @@ + From 929ad9eed358edcf81100ea89dcf0401b29b3c1b Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 5 Apr 2019 18:08:06 +0300 Subject: [PATCH 693/882] introduce PMD/category/java/performance.xml/ByteInstantiation rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 6690404cc..e2e7d16f1 100644 --- a/pmd.xml +++ b/pmd.xml @@ -108,4 +108,5 @@ + From 9ca8ba9ff5a2b04a5d2d7f6aa527c9b59cd881c5 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 5 Apr 2019 18:56:40 +0300 Subject: [PATCH 694/882] introduce PMD/category/java/performance.xml/ConsecutiveAppendsShouldReuse rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index e2e7d16f1..c0ec8d720 100644 --- a/pmd.xml +++ b/pmd.xml @@ -109,4 +109,5 @@ + From d0ecbc6bd7a6b3201f3743586083d3ae761c4ab4 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 5 Apr 2019 18:58:20 +0300 Subject: [PATCH 695/882] introduce PMD/category/java/performance.xml/ConsecutiveLiteralAppends rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index c0ec8d720..cd19493a7 100644 --- a/pmd.xml +++ b/pmd.xml @@ -110,4 +110,5 @@ + From f3f23f15e676d354e95dfc393528143717db04e3 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 5 Apr 2019 19:06:52 +0300 Subject: [PATCH 696/882] introduce PMD/category/java/performance.xml/InefficientEmptyStringCheck rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index cd19493a7..dcbeeb731 100644 --- a/pmd.xml +++ b/pmd.xml @@ -111,4 +111,5 @@ + From af2e0f08ca56eaa6ca9107690724d391af00a2d3 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 5 Apr 2019 19:12:36 +0300 Subject: [PATCH 697/882] introduce PMD/category/java/performance.xml/IntegerInstantiation rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index dcbeeb731..3dc600418 100644 --- a/pmd.xml +++ b/pmd.xml @@ -112,4 +112,5 @@ + From 3088146b0b95d2bc69556c28f42f875ec4a64576 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 5 Apr 2019 19:14:33 +0300 Subject: [PATCH 698/882] introduce PMD/category/java/performance.xml/LongInstantiation rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 3dc600418..a5fd3502a 100644 --- a/pmd.xml +++ b/pmd.xml @@ -113,4 +113,5 @@ + From 4768e4f1d5c263dfd6c85f8ef49157a5d7c86eb4 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 5 Apr 2019 19:26:41 +0300 Subject: [PATCH 699/882] introduce PMD/category/java/performance.xml/OptimizableToArrayCall rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index a5fd3502a..ec6496c4d 100644 --- a/pmd.xml +++ b/pmd.xml @@ -114,4 +114,5 @@ + From 5b64e222d4802c25200ccfc35df399ed1529720c Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 8 Apr 2019 12:51:49 +0300 Subject: [PATCH 700/882] introduce PMD/category/java/performance.xml/RedundantFieldInitializer rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index ec6496c4d..27897c6a1 100644 --- a/pmd.xml +++ b/pmd.xml @@ -115,4 +115,5 @@ + From 36546e8ff94e350a8248d37053fbf3665e97ebf6 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 8 Apr 2019 12:53:55 +0300 Subject: [PATCH 701/882] introduce PMD/category/java/performance.xml/ShortInstantiation rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 27897c6a1..8d8809ea4 100644 --- a/pmd.xml +++ b/pmd.xml @@ -116,4 +116,5 @@ + From 9cb0b10a6a898fd1364f848783a827276fff5e03 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 8 Apr 2019 12:57:56 +0300 Subject: [PATCH 702/882] introduce PMD/category/java/performance.xml/StringInstantiation rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 8d8809ea4..4691c3523 100644 --- a/pmd.xml +++ b/pmd.xml @@ -117,4 +117,5 @@ + From 9caf83aeb63a5cb8e01dc47a4bebcb82ea0ae093 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 8 Apr 2019 13:01:57 +0300 Subject: [PATCH 703/882] introduce PMD/category/java/performance.xml/StringToString rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 4691c3523..0903f6e17 100644 --- a/pmd.xml +++ b/pmd.xml @@ -118,4 +118,5 @@ + From 2751d798a25ed64d3dd2c71ed2457d1d2c9d5cd0 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 8 Apr 2019 13:08:27 +0300 Subject: [PATCH 704/882] introduce PMD/category/java/performance.xml/UnnecessaryWrapperObjectCreation rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 0903f6e17..71f32c4de 100644 --- a/pmd.xml +++ b/pmd.xml @@ -119,4 +119,5 @@ + From 9442d4fb8c70677db0464cc085e863783ea14121 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 8 Apr 2019 13:17:18 +0300 Subject: [PATCH 705/882] introduce PMD/category/java/performance.xml/UseIndexOfChar rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 71f32c4de..6eeafdc1c 100644 --- a/pmd.xml +++ b/pmd.xml @@ -120,4 +120,5 @@ + From 6ba30729fab56517f22c4c8b6175136ec54d7e46 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 8 Apr 2019 13:26:20 +0300 Subject: [PATCH 706/882] introduce PMD/category/java/performance.xml/UseStringBufferLength rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 6eeafdc1c..86b1c4d8f 100644 --- a/pmd.xml +++ b/pmd.xml @@ -121,4 +121,5 @@ + From a86cbeea005429add828e272e17911cd68758e8f Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 8 Apr 2019 13:52:47 +0300 Subject: [PATCH 707/882] introduce PMD/category/java/security.xml/HardCodedCryptoKey rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 86b1c4d8f..c7f438e23 100644 --- a/pmd.xml +++ b/pmd.xml @@ -122,4 +122,5 @@ + From 9c810fd4e2d84910a23c53e9548a9d1c34cb3593 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 8 Apr 2019 13:54:23 +0300 Subject: [PATCH 708/882] introduce PMD/category/java/security.xml/InsecureCryptoIv rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index c7f438e23..6c204f770 100644 --- a/pmd.xml +++ b/pmd.xml @@ -123,4 +123,5 @@ + From bc796e4c43d0323c151f7472fb079c22c7a09e58 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 11 Apr 2019 19:06:08 +0300 Subject: [PATCH 709/882] Update README.md add example for The OAuth 1.0 Protocol RFC 5849 --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index bbd290e7b..5ebf4674c 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,7 @@ ScribeJava support out-of-box several HTTP clients: * [RFC 6750](https://tools.ietf.org/html/rfc6750) The OAuth 2.0 Authorization Framework: Bearer Token Usage * [RFC 7636](https://tools.ietf.org/html/rfc7636) Proof Key for Code Exchange by OAuth Public Clients (PKCE), [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20WithPKCEExample.java) * [RFC 7009](https://tools.ietf.org/html/rfc7009) OAuth 2.0 Token Revocation, [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20RevokeExample.java) + * [RFC 5849](https://tools.ietf.org/html/rfc5849) The OAuth 1.0 Protocol, [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TwitterExample.java) ### Supports all major 1.0a and 2.0 OAuth APIs out-of-the-box From 030d76872fe371a84b5d05c6c3c33c34e8f611f1 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 11 Apr 2019 20:21:22 +0300 Subject: [PATCH 710/882] add all OAuth error codes from supported RFCs (incl. "invalid_token") (thanks to https://github.com/echorebel) --- changelog | 1 + .../apis/fitbit/FitBitJsonTokenExtractor.java | 5 +- .../fitbit/FitBitJsonTokenExtractorTest.java | 12 +-- .../OAuth2AccessTokenJsonExtractor.java | 5 +- .../model/OAuth2AccessTokenErrorResponse.java | 41 +++++++++ .../scribejava/core/oauth2/OAuth2Error.java | 90 +++++++++++++++++++ .../OAuth2AccessTokenJsonExtractorTest.java | 2 + 7 files changed, 146 insertions(+), 10 deletions(-) create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/oauth2/OAuth2Error.java diff --git a/changelog b/changelog index 6e6bb1221..6a5b00f49 100644 --- a/changelog +++ b/changelog @@ -1,5 +1,6 @@ [SNAPSHOT] * add PMD checks on compile + * add all OAuth error codes from supported RFCs (incl. "invalid_token") (thanks to https://github.com/echorebel) [6.5.1] * cleanup deprecates methods diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractor.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractor.java index 3679ee14a..1f9f4b5dc 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractor.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractor.java @@ -2,6 +2,7 @@ import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; import com.github.scribejava.core.model.OAuth2AccessTokenErrorResponse; +import com.github.scribejava.core.oauth2.OAuth2Error; import java.util.regex.Pattern; @@ -37,9 +38,9 @@ public void generateError(String response) { final String errorInString = extractParameter(response, ERROR_REGEX_PATTERN, true); final String errorDescription = extractParameter(response, ERROR_DESCRIPTION_REGEX_PATTERN, false); - OAuth2AccessTokenErrorResponse.ErrorCode errorCode; + OAuth2Error errorCode; try { - errorCode = OAuth2AccessTokenErrorResponse.ErrorCode.parseFrom(errorInString); + errorCode = OAuth2Error.parseFrom(errorInString); } catch (IllegalArgumentException iaE) { //non oauth standard error code errorCode = null; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractorTest.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractorTest.java index 448d5ff52..d7572816b 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractorTest.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractorTest.java @@ -1,7 +1,7 @@ package com.github.scribejava.apis.fitbit; import com.github.scribejava.core.model.OAuth2AccessTokenErrorResponse; -import com.github.scribejava.core.model.OAuth2AccessTokenErrorResponse.ErrorCode; +import com.github.scribejava.core.oauth2.OAuth2Error; import org.hamcrest.FeatureMatcher; import org.junit.Rule; @@ -28,21 +28,21 @@ public void testErrorExtraction() { final FitBitJsonTokenExtractor extractor = new FitBitJsonTokenExtractor(); thrown.expect(OAuth2AccessTokenErrorResponse.class); - thrown.expect(new ErrorCodeFeatureMatcher(ErrorCode.INVALID_GRANT)); + thrown.expect(new ErrorCodeFeatureMatcher(OAuth2Error.INVALID_GRANT)); thrown.expect(new ErrorDescriptionFeatureMatcher(ERROR_DESCRIPTION)); extractor.generateError(ERROR_JSON); } - private static class ErrorCodeFeatureMatcher extends FeatureMatcher { + private static class ErrorCodeFeatureMatcher extends FeatureMatcher { - private ErrorCodeFeatureMatcher(ErrorCode expected) { + private ErrorCodeFeatureMatcher(OAuth2Error expected) { super(equalTo(expected), "a response with errorCode", "errorCode"); } @Override - protected ErrorCode featureValueOf(OAuth2AccessTokenErrorResponse actual) { - return actual.getErrorCode(); + protected OAuth2Error featureValueOf(OAuth2AccessTokenErrorResponse actual) { + return actual.getError(); } } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractor.java b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractor.java index a87e8ab82..792ed613f 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractor.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractor.java @@ -8,6 +8,7 @@ import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuth2AccessTokenErrorResponse; import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.oauth2.OAuth2Error; import com.github.scribejava.core.utils.Preconditions; /** @@ -64,9 +65,9 @@ public void generateError(String response) { errorUri = null; } - OAuth2AccessTokenErrorResponse.ErrorCode errorCode; + OAuth2Error errorCode; try { - errorCode = OAuth2AccessTokenErrorResponse.ErrorCode.parseFrom(errorInString); + errorCode = OAuth2Error.parseFrom(errorInString); } catch (IllegalArgumentException iaE) { //non oauth standard error code errorCode = null; diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth2AccessTokenErrorResponse.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth2AccessTokenErrorResponse.java index 57ada61de..8d78f15c6 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth2AccessTokenErrorResponse.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth2AccessTokenErrorResponse.java @@ -1,6 +1,7 @@ package com.github.scribejava.core.model; import com.github.scribejava.core.exceptions.OAuthException; +import com.github.scribejava.core.oauth2.OAuth2Error; import java.net.URI; @@ -11,6 +12,10 @@ public class OAuth2AccessTokenErrorResponse extends OAuthException { private static final long serialVersionUID = 2309424849700276816L; + /** + * @deprecated use {@link com.github.scribejava.core.oauth2.OAuth2Error} + */ + @Deprecated public enum ErrorCode { INVALID_REQUEST("invalid_request"), INVALID_CLIENT("invalid_client"), @@ -40,19 +45,55 @@ public static ErrorCode parseFrom(String errorCodeString) { } private final ErrorCode errorCode; + private final OAuth2Error error; private final String errorDescription; private final URI errorUri; private final String rawResponse; + /** + * @param errorCode errorCode + * @param errorDescription errorDescription + * @param errorUri errorUri + * @param rawResponse rawResponse + * @deprecated use {@link #OAuth2AccessTokenErrorResponse(com.github.scribejava.core.oauth2.OAuth2Error, + * java.lang.String, java.net.URI, java.lang.String)} + */ + @Deprecated public OAuth2AccessTokenErrorResponse(ErrorCode errorCode, String errorDescription, URI errorUri, String rawResponse) { super(rawResponse); this.errorCode = errorCode; + this.error = OAuth2Error.parseFrom(errorCode.errorCodeString); this.errorDescription = errorDescription; this.errorUri = errorUri; this.rawResponse = rawResponse; } + public OAuth2AccessTokenErrorResponse(OAuth2Error error, String errorDescription, URI errorUri, + String rawResponse) { + super(rawResponse); + ErrorCode oldErrorCode; + try { + oldErrorCode = ErrorCode.parseFrom(error.getErrorString()); + } catch (IllegalArgumentException iaE) { + oldErrorCode = null; + } + this.errorCode = oldErrorCode; + this.error = error; + this.errorDescription = errorDescription; + this.errorUri = errorUri; + this.rawResponse = rawResponse; + } + + public OAuth2Error getError() { + return error; + } + + /** + * @return error code + * @deprecated use {@link #getError() } + */ + @Deprecated public ErrorCode getErrorCode() { return errorCode; } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth2/OAuth2Error.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth2/OAuth2Error.java new file mode 100644 index 000000000..b5a8d89e6 --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth2/OAuth2Error.java @@ -0,0 +1,90 @@ +package com.github.scribejava.core.oauth2; + +public enum OAuth2Error { + /** + * @see RFC 6749, 4.1.2.1 Error Response + * @see RFC 6749, 4.2.2.1 Error Response + * @see RFC 6749, 5.2 Error Response + * @see RFC 6750, 6.2. OAuth Extensions Error + * Registration + */ + INVALID_REQUEST("invalid_request"), + /** + * @see RFC 6749, 4.1.2.1 Error Response + * @see RFC 6749, 4.2.2.1 Error Response + * @see RFC 6749, 5.2 Error Response + */ + UNAUTHORIZED_CLIENT("unauthorized_client"), + /** + * @see RFC 6749, 4.1.2.1 Error Response + * @see RFC 6749, 4.2.2.1 Error Response + */ + ACCESS_DENIED("access_denied"), + /** + * @see RFC 6749, 4.1.2.1 Error Response + * @see RFC 6749, 4.2.2.1 Error Response + */ + UNSUPPORTED_RESPONSE_TYPE("unsupported_response_type"), + /** + * @see RFC 6749, 4.1.2.1 Error Response + * @see RFC 6749, 4.2.2.1 Error Response + * @see RFC 6749, 5.2 Error Response + */ + INVALID_SCOPE("invalid_scope"), + /** + * @see RFC 6749, 4.1.2.1 Error Response + * @see RFC 6749, 4.2.2.1 Error Response + */ + SERVER_ERROR("server_error"), + /** + * @see RFC 6749, 4.1.2.1 Error Response + * @see RFC 6749, 4.2.2.1 Error Response + */ + TEMPORARILY_UNAVAILABLE("temporarily_unavailable"), + /** + * @see RFC 6749, 5.2 Error Response + */ + INVALID_CLIENT("invalid_client"), + /** + * @see RFC 6749, 5.2 Error Response + */ + INVALID_GRANT("invalid_grant"), + /** + * @see RFC 6749, 5.2 Error Response + */ + UNSUPPORTED_GRANT_TYPE("unsupported_grant_type"), + /** + * @see RFC 6750, 6.2. OAuth Extensions Error + * Registration + */ + INVALID_TOKEN("invalid_token"), + /** + * @see RFC 6750, 6.2. OAuth Extensions Error + * Registration + */ + INSUFFICIENT_SCOPE("insufficient_scope"), + /** + * @see RFC 7009, 4.1. OAuth Extensions Error + * Registration + */ + UNSUPPORTED_TOKEN_TYPE("unsupported_token_type"); + + private final String errorString; + + OAuth2Error(String errorString) { + this.errorString = errorString; + } + + public static OAuth2Error parseFrom(String errorString) { + for (OAuth2Error error : OAuth2Error.values()) { + if (error.errorString.equals(errorString)) { + return error; + } + } + throw new IllegalArgumentException("there is no knowlege about '" + errorString + "' Error"); + } + + public String getErrorString() { + return errorString; + } +} diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractorTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractorTest.java index 5d00d89e0..0202c3c20 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractorTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractorTest.java @@ -3,6 +3,7 @@ import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuth2AccessTokenErrorResponse; import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.oauth2.OAuth2Error; import org.junit.Test; import java.io.IOException; @@ -66,6 +67,7 @@ public void shouldThrowExceptionIfResponseIsError() throws IOException { fail(); } catch (OAuth2AccessTokenErrorResponse oaer) { assertEquals(OAuth2AccessTokenErrorResponse.ErrorCode.INVALID_GRANT, oaer.getErrorCode()); + assertEquals(OAuth2Error.INVALID_GRANT, oaer.getError()); assertEquals("unknown, invalid, or expired refresh token", oaer.getErrorDescription()); } } From 4f84b315f17d4a4623ed78cf073b7dc8b2792865 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 20 May 2019 14:22:28 +0300 Subject: [PATCH 711/882] Update LinkedIn Example to API v2 (thanks to https://github.com/peternees) --- changelog | 1 + .../apis/examples/LinkedIn20Example.java | 51 ++++++++++--------- 2 files changed, 29 insertions(+), 23 deletions(-) diff --git a/changelog b/changelog index 6a5b00f49..806422173 100644 --- a/changelog +++ b/changelog @@ -1,6 +1,7 @@ [SNAPSHOT] * add PMD checks on compile * add all OAuth error codes from supported RFCs (incl. "invalid_token") (thanks to https://github.com/echorebel) + * Update LinkedIn Example to API v2 (thanks to https://github.com/peternees) [6.5.1] * cleanup deprecates methods diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedIn20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedIn20Example.java index 4fa1388de..e06dd2a3b 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedIn20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedIn20Example.java @@ -9,12 +9,15 @@ import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.oauth.OAuth20Service; import java.io.IOException; +import java.util.Random; import java.util.concurrent.ExecutionException; public class LinkedIn20Example { private static final String NETWORK_NAME = "LinkedIn"; - private static final String PROTECTED_RESOURCE_URL = "https://api.linkedin.com/v1/people/~:(%s)"; + private static final String PROTECTED_RESOURCE_URL = "https://api.linkedin.com/v2/me"; + private static final String PROTECTED_EMAIL_RESOURCE_URL + = "https://api.linkedin.com/v2/emailAddress?q=members&projection=(elements*(handle~))"; private LinkedIn20Example() { } @@ -26,7 +29,7 @@ public static void main(String... args) throws IOException, InterruptedException final String clientSecret = "your client secret"; final OAuth20Service service = new ServiceBuilder(clientId) .apiSecret(clientSecret) - .defaultScope("r_basicprofile r_emailaddress") // replace with desired scope + .defaultScope("r_liteprofile r_emailaddress") // replace with desired scope .callback("http://example.com/callback") .build(LinkedInApi20.instance()); final Scanner in = new Scanner(System.in); @@ -36,7 +39,8 @@ public static void main(String... args) throws IOException, InterruptedException // Obtain the Authorization URL System.out.println("Fetching the Authorization URL..."); - final String authorizationUrl = service.getAuthorizationUrl("some_params"); + final String secretState = "secret" + new Random().nextInt(999_999); + final String authorizationUrl = service.getAuthorizationUrl(secretState); System.out.println("Got the Authorization URL!"); System.out.println("Now go and authorize ScribeJava here:"); System.out.println(authorizationUrl); @@ -52,28 +56,29 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); - // Now let's go and ask for a protected resource! - System.out.println("Now we're going to access a protected resource..."); - while (true) { - System.out.println("Paste profile query for fetch (firstName, lastName, etc) or 'exit' to stop example"); - System.out.print(">>"); - final String query = in.nextLine(); - System.out.println(); + System.out.println("Now we're going to get the email of the current user..."); + final OAuthRequest emailRequest = new OAuthRequest(Verb.GET, PROTECTED_EMAIL_RESOURCE_URL); + emailRequest.addHeader("x-li-format", "json"); + emailRequest.addHeader("Accept-Language", "ru-RU"); + service.signRequest(accessToken, emailRequest); + final Response emailResponse = service.execute(emailRequest); + System.out.println(); + System.out.println(emailResponse.getCode()); + System.out.println(emailResponse.getBody()); - if ("exit".equals(query)) { - break; - } + System.out.println(); - final OAuthRequest request = new OAuthRequest(Verb.GET, String.format(PROTECTED_RESOURCE_URL, query)); - request.addHeader("x-li-format", "json"); - request.addHeader("Accept-Language", "ru-RU"); - service.signRequest(accessToken, request); - final Response response = service.execute(request); - System.out.println(); - System.out.println(response.getCode()); - System.out.println(response.getBody()); + System.out.println("Now we're going to access a protected profile resource..."); - System.out.println(); - } + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); + request.addHeader("x-li-format", "json"); + request.addHeader("Accept-Language", "ru-RU"); + service.signRequest(accessToken, request); + final Response response = service.execute(request); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + + System.out.println(); } } From 7d2ce91c04bd4ec8d3ce48de7dd6f53522d50db0 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 27 May 2019 18:17:28 +0300 Subject: [PATCH 712/882] switch to jackson dependency to parse json responses (thanks to https://github.com/galimru) --- changelog | 1 + pom.xml | 29 +++--- scribejava-apis/pom.xml | 2 +- .../FacebookAccessTokenJsonExtractor.java | 20 ++--- .../apis/fitbit/FitBitJsonTokenExtractor.java | 24 ++--- .../apis/openid/OpenIdJsonTokenExtractor.java | 8 +- .../SalesforceJsonTokenExtractor.java | 8 +- .../apis/vk/VKJsonTokenExtractor.java | 10 +-- .../fitbit/FitBitJsonTokenExtractorTest.java | 3 +- .../AbstractOAuth1JSONTokenExtractor.java | 35 ++++---- .../OAuth2AccessTokenJsonExtractor.java | 90 +++++++++++++------ .../OAuth2AccessTokenJsonExtractorTest.java | 6 ++ .../core/oauth/OAuth20ServiceTest.java | 19 ++-- .../core/oauth/OAuth20ServiceUnit.java | 11 ++- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 16 files changed, 153 insertions(+), 117 deletions(-) diff --git a/changelog b/changelog index 806422173..532b45e92 100644 --- a/changelog +++ b/changelog @@ -2,6 +2,7 @@ * add PMD checks on compile * add all OAuth error codes from supported RFCs (incl. "invalid_token") (thanks to https://github.com/echorebel) * Update LinkedIn Example to API v2 (thanks to https://github.com/peternees) + * switch to jackson dependency to parse json responses (thanks to https://github.com/galimru) [6.5.1] * cleanup deprecates methods diff --git a/pom.xml b/pom.xml index 506ba5237..7898059cb 100644 --- a/pom.xml +++ b/pom.xml @@ -53,22 +53,21 @@ + + com.fasterxml.jackson.core + jackson-databind + 2.9.9 + junit junit 4.12 test - - com.google.code.gson - gson - 2.8.5 - test - com.squareup.okhttp3 mockwebserver - 3.14.0 + 3.14.2 test @@ -78,7 +77,7 @@ org.apache.felix maven-bundle-plugin - 4.1.0 + 4.2.0 bundle-manifest @@ -92,7 +91,7 @@ org.apache.maven.plugins maven-jar-plugin - 3.1.1 + 3.1.2 ${project.build.outputDirectory}/META-INF/MANIFEST.MF @@ -107,7 +106,7 @@ com.puppycrawl.tools checkstyle - 8.18 + 8.20 @@ -122,7 +121,7 @@ org.apache.maven.plugins maven-surefire-plugin - 2.22.1 + 2.22.2 org.apache.maven.plugins @@ -144,7 +143,7 @@ maven-compiler-plugin - 3.8.0 + 3.8.1 UTF-8 ${java.release} @@ -175,7 +174,7 @@ org.apache.maven.plugins maven-source-plugin - 3.0.1 + 3.1.0 attach-sources @@ -228,7 +227,7 @@ org.apache.maven.plugins maven-pmd-plugin - 3.11.0 + 3.12.0 net.sourceforge.pmd @@ -274,7 +273,7 @@ 7 - 6.12.0 + 6.14.0 diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index fbcbf7f41..6f0e6e21d 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -8,7 +8,7 @@ 6.5.2-SNAPSHOT ../pom.xml - + com.github.scribejava scribejava-apis ScribeJava APIs diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookAccessTokenJsonExtractor.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookAccessTokenJsonExtractor.java index 62326e099..f7b783f6f 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookAccessTokenJsonExtractor.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookAccessTokenJsonExtractor.java @@ -1,18 +1,14 @@ package com.github.scribejava.apis.facebook; import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; -import java.util.regex.Pattern; +import java.io.IOException; +import java.util.Map; /** * non standard Facebook Extractor */ public class FacebookAccessTokenJsonExtractor extends OAuth2AccessTokenJsonExtractor { - private static final Pattern MESSAGE_REGEX_PATTERN = Pattern.compile("\"message\"\\s*:\\s*\"([^\"]*?)\""); - private static final Pattern TYPE_REGEX_PATTERN = Pattern.compile("\"type\"\\s*:\\s*\"([^\"]*?)\""); - private static final Pattern CODE_REGEX_PATTERN = Pattern.compile("\"code\"\\s*:\\s*\"?([^\",}]*?)[\",}]"); - private static final Pattern FBTRACE_ID_REGEX_PATTERN = Pattern.compile("\"fbtrace_id\"\\s*:\\s*\"([^\"]*?)\""); - protected FacebookAccessTokenJsonExtractor() { } @@ -35,13 +31,13 @@ public static FacebookAccessTokenJsonExtractor instance() { * ID.","type":"OAuthException","code":101,"fbtrace_id":"CvDR+X4WWIx"}}' */ @Override - public void generateError(String response) { - extractParameter(response, MESSAGE_REGEX_PATTERN, false); + public void generateError(String rawResponse) throws IOException { + @SuppressWarnings("unchecked") + final Map response = OAuth2AccessTokenJsonExtractor.OBJECT_MAPPER + .readValue(rawResponse, Map.class); - throw new FacebookAccessTokenErrorResponse(extractParameter(response, MESSAGE_REGEX_PATTERN, false), - extractParameter(response, TYPE_REGEX_PATTERN, false), - extractParameter(response, CODE_REGEX_PATTERN, false), - extractParameter(response, FBTRACE_ID_REGEX_PATTERN, false), response); + throw new FacebookAccessTokenErrorResponse(response.get("message"), response.get("type"), response.get("code"), + response.get("fbtrace_id"), rawResponse); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractor.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractor.java index 1f9f4b5dc..2923c3d42 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractor.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractor.java @@ -3,14 +3,12 @@ import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; import com.github.scribejava.core.model.OAuth2AccessTokenErrorResponse; import com.github.scribejava.core.oauth2.OAuth2Error; - -import java.util.regex.Pattern; +import java.io.IOException; +import java.util.List; +import java.util.Map; public class FitBitJsonTokenExtractor extends OAuth2AccessTokenJsonExtractor { - private static final Pattern USER_ID_REGEX_PATTERN = Pattern.compile("\"user_id\"\\s*:\\s*\"(\\S*?)\""); - private static final Pattern ERROR_REGEX_PATTERN = Pattern.compile("\"errorType\"\\s*:\\s*\"(\\S*?)\""); - private static final Pattern ERROR_DESCRIPTION_REGEX_PATTERN = Pattern.compile("\"message\"\\s*:\\s*\"([^\"]*?)\""); protected FitBitJsonTokenExtractor() { } @@ -25,27 +23,29 @@ public static FitBitJsonTokenExtractor instance() { @Override protected FitBitOAuth2AccessToken createToken(String accessToken, String tokenType, Integer expiresIn, - String refreshToken, String scope, String response) { + String refreshToken, String scope, Map response, String rawResponse) { return new FitBitOAuth2AccessToken(accessToken, tokenType, expiresIn, refreshToken, scope, - extractParameter(response, USER_ID_REGEX_PATTERN, false), response); + response.get("user_id"), rawResponse); } /** * Related documentation: https://dev.fitbit.com/build/reference/web-api/oauth2/ */ @Override - public void generateError(String response) { - final String errorInString = extractParameter(response, ERROR_REGEX_PATTERN, true); - final String errorDescription = extractParameter(response, ERROR_DESCRIPTION_REGEX_PATTERN, false); + public void generateError(String rawResponse) throws IOException { + @SuppressWarnings("unchecked") + final Map>> response = OAuth2AccessTokenJsonExtractor.OBJECT_MAPPER + .readValue(rawResponse, Map.class); + final Map errorResponse = response.get("errors").get(0); OAuth2Error errorCode; try { - errorCode = OAuth2Error.parseFrom(errorInString); + errorCode = OAuth2Error.parseFrom(extractRequiredParameter(errorResponse, "errorType", rawResponse)); } catch (IllegalArgumentException iaE) { //non oauth standard error code errorCode = null; } - throw new OAuth2AccessTokenErrorResponse(errorCode, errorDescription, null, response); + throw new OAuth2AccessTokenErrorResponse(errorCode, errorResponse.get("message"), null, rawResponse); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/openid/OpenIdJsonTokenExtractor.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/openid/OpenIdJsonTokenExtractor.java index bec8b0613..2a750dbcb 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/openid/OpenIdJsonTokenExtractor.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/openid/OpenIdJsonTokenExtractor.java @@ -1,15 +1,13 @@ package com.github.scribejava.apis.openid; import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; -import java.util.regex.Pattern; +import java.util.Map; /** * additionally parses OpenID id_token */ public class OpenIdJsonTokenExtractor extends OAuth2AccessTokenJsonExtractor { - private static final Pattern ID_TOKEN_REGEX_PATTERN = Pattern.compile("\"id_token\"\\s*:\\s*\"(\\S*?)\""); - protected OpenIdJsonTokenExtractor() { } @@ -24,8 +22,8 @@ public static OpenIdJsonTokenExtractor instance() { @Override protected OpenIdOAuth2AccessToken createToken(String accessToken, String tokenType, Integer expiresIn, - String refreshToken, String scope, String response) { + String refreshToken, String scope, Map response, String rawResponse) { return new OpenIdOAuth2AccessToken(accessToken, tokenType, expiresIn, refreshToken, scope, - extractParameter(response, ID_TOKEN_REGEX_PATTERN, false), response); + response.get("id_token"), rawResponse); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/salesforce/SalesforceJsonTokenExtractor.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/salesforce/SalesforceJsonTokenExtractor.java index 841276724..3876b587d 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/salesforce/SalesforceJsonTokenExtractor.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/salesforce/SalesforceJsonTokenExtractor.java @@ -1,7 +1,7 @@ package com.github.scribejava.apis.salesforce; import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; -import java.util.regex.Pattern; +import java.util.Map; /** * This extractor parses in addition to the standard Extractor the instance_url @@ -9,8 +9,6 @@ */ public class SalesforceJsonTokenExtractor extends OAuth2AccessTokenJsonExtractor { - private static final Pattern INSTANCE_URL_REGEX_PATTERN = Pattern.compile("\"instance_url\"\\s*:\\s*\"(\\S*?)\""); - protected SalesforceJsonTokenExtractor() { } @@ -25,8 +23,8 @@ public static SalesforceJsonTokenExtractor instance() { @Override protected SalesforceToken createToken(String accessToken, String tokenType, Integer expiresIn, - String refreshToken, String scope, String response) { + String refreshToken, String scope, Map response, String rawResponse) { return new SalesforceToken(accessToken, tokenType, expiresIn, refreshToken, scope, - extractParameter(response, INSTANCE_URL_REGEX_PATTERN, true), response); + extractRequiredParameter(response, "instance_url", rawResponse), rawResponse); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/vk/VKJsonTokenExtractor.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/vk/VKJsonTokenExtractor.java index 4e658b061..277904ec6 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/vk/VKJsonTokenExtractor.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/vk/VKJsonTokenExtractor.java @@ -1,15 +1,13 @@ package com.github.scribejava.apis.vk; import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; -import java.util.regex.Pattern; +import java.util.Map; /** * additionally parses email */ public class VKJsonTokenExtractor extends OAuth2AccessTokenJsonExtractor { - private static final Pattern EMAIL_REGEX_PATTERN = Pattern.compile("\"email\"\\s*:\\s*\"(\\S*?)\""); - protected VKJsonTokenExtractor() { } @@ -24,8 +22,8 @@ public static VKJsonTokenExtractor instance() { @Override protected VKOAuth2AccessToken createToken(String accessToken, String tokenType, Integer expiresIn, - String refreshToken, String scope, String response) { - return new VKOAuth2AccessToken(accessToken, tokenType, expiresIn, refreshToken, scope, - extractParameter(response, EMAIL_REGEX_PATTERN, false), response); + String refreshToken, String scope, Map response, String rawResponse) { + return new VKOAuth2AccessToken(accessToken, tokenType, expiresIn, refreshToken, scope, response.get("email"), + rawResponse); } } diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractorTest.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractorTest.java index d7572816b..e717dbd7b 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractorTest.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractorTest.java @@ -2,6 +2,7 @@ import com.github.scribejava.core.model.OAuth2AccessTokenErrorResponse; import com.github.scribejava.core.oauth2.OAuth2Error; +import java.io.IOException; import org.hamcrest.FeatureMatcher; import org.junit.Rule; @@ -23,7 +24,7 @@ public class FitBitJsonTokenExtractorTest { public ExpectedException thrown = ExpectedException.none(); @Test - public void testErrorExtraction() { + public void testErrorExtraction() throws IOException { final FitBitJsonTokenExtractor extractor = new FitBitJsonTokenExtractor(); diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/AbstractOAuth1JSONTokenExtractor.java b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/AbstractOAuth1JSONTokenExtractor.java index 16f684855..68c7fdac0 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/AbstractOAuth1JSONTokenExtractor.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/AbstractOAuth1JSONTokenExtractor.java @@ -1,39 +1,38 @@ package com.github.scribejava.core.extractors; +import com.fasterxml.jackson.databind.ObjectMapper; import com.github.scribejava.core.exceptions.OAuthException; import com.github.scribejava.core.model.OAuth1Token; +import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.Response; -import com.github.scribejava.core.utils.OAuthEncoder; import com.github.scribejava.core.utils.Preconditions; import java.io.IOException; -import java.util.regex.Matcher; -import java.util.regex.Pattern; +import java.util.Map; public abstract class AbstractOAuth1JSONTokenExtractor implements TokenExtractor { - private static final Pattern OAUTH_TOKEN_PATTERN = Pattern.compile("\"oauth_token\"\\s*:\\s*\"(\\S*?)\""); - private static final Pattern OAUTH_TOKEN_SECRET_PATTERN - = Pattern.compile("\"oauth_token_secret\"\\s*:\\s*\"(\\S*?)\""); + private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); @Override public T extract(Response response) throws IOException { - final String body = response.getBody(); - Preconditions.checkEmptyString(body, "Response body is incorrect. Can't extract a token from an empty string"); - final String token = extract(body, OAUTH_TOKEN_PATTERN); - final String secret = extract(body, OAUTH_TOKEN_SECRET_PATTERN); - return createToken(token, secret, body); - } + final String rawBody = response.getBody(); + Preconditions.checkEmptyString(rawBody, + "Response body is incorrect. Can't extract a token from an empty string"); + + @SuppressWarnings("unchecked") + final Map body = OBJECT_MAPPER.readValue(rawBody, Map.class); - private String extract(String response, Pattern p) { - final Matcher matcher = p.matcher(response); - if (matcher.find() && matcher.groupCount() >= 1) { - return OAuthEncoder.decode(matcher.group(1)); - } else { + final String token = body.get(OAuthConstants.TOKEN); + final String secret = body.get(OAuthConstants.TOKEN_SECRET); + + if (token == null || secret == null) { throw new OAuthException("Response body is incorrect. Can't extract token and secret from this: '" - + response + '\'', null); + + rawBody + '\'', null); } + + return createToken(token, secret, rawBody); } protected abstract T createToken(String token, String secret, String response); diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractor.java b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractor.java index 792ed613f..fc7be6e0f 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractor.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractor.java @@ -1,5 +1,6 @@ package com.github.scribejava.core.extractors; +import com.fasterxml.jackson.databind.ObjectMapper; import java.io.IOException; import java.net.URI; import java.util.regex.Matcher; @@ -7,24 +8,18 @@ import com.github.scribejava.core.exceptions.OAuthException; import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuth2AccessTokenErrorResponse; +import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.Response; import com.github.scribejava.core.oauth2.OAuth2Error; import com.github.scribejava.core.utils.Preconditions; +import java.util.Map; /** * JSON (default) implementation of {@link TokenExtractor} for OAuth 2.0 */ public class OAuth2AccessTokenJsonExtractor implements TokenExtractor { - private static final Pattern ACCESS_TOKEN_REGEX_PATTERN = Pattern.compile("\"access_token\"\\s*:\\s*\"(\\S*?)\""); - private static final Pattern TOKEN_TYPE_REGEX_PATTERN = Pattern.compile("\"token_type\"\\s*:\\s*\"(\\S*?)\""); - private static final Pattern EXPIRES_IN_REGEX_PATTERN = Pattern.compile("\"expires_in\"\\s*:\\s*\"?(\\d*?)\"?\\D"); - private static final Pattern REFRESH_TOKEN_REGEX_PATTERN = Pattern.compile("\"refresh_token\"\\s*:\\s*\"(\\S*?)\""); - private static final Pattern SCOPE_REGEX_PATTERN = Pattern.compile("\"scope\"\\s*:\\s*\"([^\"]*?)\""); - private static final Pattern ERROR_REGEX_PATTERN = Pattern.compile("\"error\"\\s*:\\s*\"(\\S*?)\""); - private static final Pattern ERROR_DESCRIPTION_REGEX_PATTERN - = Pattern.compile("\"error_description\"\\s*:\\s*\"([^\"]*?)\""); - private static final Pattern ERROR_URI_REGEX_PATTERN = Pattern.compile("\"error_uri\"\\s*:\\s*\"(\\S*?)\""); + protected static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); protected OAuth2AccessTokenJsonExtractor() { } @@ -52,12 +47,14 @@ public OAuth2AccessToken extract(Response response) throws IOException { /** * Related documentation: https://tools.ietf.org/html/rfc6749#section-5.2 * - * @param response response + * @param rawResponse response + * @throws IOException IOException */ - public void generateError(String response) { - final String errorInString = extractParameter(response, ERROR_REGEX_PATTERN, true); - final String errorDescription = extractParameter(response, ERROR_DESCRIPTION_REGEX_PATTERN, false); - final String errorUriInString = extractParameter(response, ERROR_URI_REGEX_PATTERN, false); + public void generateError(String rawResponse) throws IOException { + @SuppressWarnings("unchecked") + final Map response = OBJECT_MAPPER.readValue(rawResponse, Map.class); + + final String errorUriInString = response.get("error_uri"); URI errorUri; try { errorUri = errorUriInString == null ? null : URI.create(errorUriInString); @@ -67,36 +64,67 @@ public void generateError(String response) { OAuth2Error errorCode; try { - errorCode = OAuth2Error.parseFrom(errorInString); + errorCode = OAuth2Error.parseFrom(extractRequiredParameter(response, "error", rawResponse)); } catch (IllegalArgumentException iaE) { //non oauth standard error code errorCode = null; } - throw new OAuth2AccessTokenErrorResponse(errorCode, errorDescription, errorUri, response); + throw new OAuth2AccessTokenErrorResponse(errorCode, response.get("error_description"), errorUri, rawResponse); } - private OAuth2AccessToken createToken(String response) { - final String accessToken = extractParameter(response, ACCESS_TOKEN_REGEX_PATTERN, true); - final String tokenType = extractParameter(response, TOKEN_TYPE_REGEX_PATTERN, false); - final String expiresInString = extractParameter(response, EXPIRES_IN_REGEX_PATTERN, false); + private OAuth2AccessToken createToken(String rawResponse) throws IOException { + + @SuppressWarnings("unchecked") + final Map response = OBJECT_MAPPER.readValue(rawResponse, Map.class); + + final String expiresInString = response.get("expires_in"); Integer expiresIn; try { expiresIn = expiresInString == null ? null : Integer.valueOf(expiresInString); } catch (NumberFormatException nfe) { expiresIn = null; } - final String refreshToken = extractParameter(response, REFRESH_TOKEN_REGEX_PATTERN, false); - final String scope = extractParameter(response, SCOPE_REGEX_PATTERN, false); - return createToken(accessToken, tokenType, expiresIn, refreshToken, scope, response); + return createToken(extractRequiredParameter(response, OAuthConstants.ACCESS_TOKEN, rawResponse), + response.get("token_type"), expiresIn, response.get(OAuthConstants.REFRESH_TOKEN), + response.get(OAuthConstants.SCOPE), response, rawResponse); + } + + protected OAuth2AccessToken createToken(String accessToken, String tokenType, Integer expiresIn, + String refreshToken, String scope, Map response, String rawResponse) { + return createToken(accessToken, tokenType, expiresIn, refreshToken, scope, rawResponse); } + /** + * + * @param accessToken accessToken + * @param tokenType tokenType + * @param expiresIn expiresIn + * @param refreshToken refreshToken + * @param scope scope + * @param rawResponse rawResponse + * @return OAuth2AccessToken + * @deprecated use {@link #createToken(java.lang.String, java.lang.String, java.lang.Integer, java.lang.String, + * java.lang.String, java.util.Map, java.lang.String)} + */ + @Deprecated protected OAuth2AccessToken createToken(String accessToken, String tokenType, Integer expiresIn, - String refreshToken, String scope, String response) { - return new OAuth2AccessToken(accessToken, tokenType, expiresIn, refreshToken, scope, response); + String refreshToken, String scope, String rawResponse) { + return new OAuth2AccessToken(accessToken, tokenType, expiresIn, refreshToken, scope, rawResponse); } + /** + * + * @param response response + * @param regexPattern regexPattern + * @param required required + * @return parameter value + * @throws OAuthException OAuthException + * @deprecated use {@link #extractRequiredParameter(java.util.Map, java.lang.String, java.lang.String) } or + * {@link java.util.Map#get(java.lang.Object) } + */ + @Deprecated protected static String extractParameter(String response, Pattern regexPattern, boolean required) throws OAuthException { final Matcher matcher = regexPattern.matcher(response); @@ -111,4 +139,16 @@ protected static String extractParameter(String response, Pattern regexPattern, return null; } + + protected static String extractRequiredParameter(Map response, String parameterName, + String rawResponse) throws OAuthException { + final String value = response.get(parameterName); + + if (value == null) { + throw new OAuthException("Response body is incorrect. Can't extract a '" + parameterName + + "' from this: '" + rawResponse + "'", null); + } + + return value; + } } diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractorTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractorTest.java index 0202c3c20..9324b3e4f 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractorTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractorTest.java @@ -72,6 +72,12 @@ public void shouldThrowExceptionIfResponseIsError() throws IOException { } } + @Test + public void testEscapedJsonInResponse() throws IOException { + final OAuth2AccessToken token = extractor.extract(ok("{ \"access_token\":\"I0122HKLEM2\\/MV3ABKFTDT3T5X\"}")); + assertEquals("I0122HKLEM2/MV3ABKFTDT3T5X", token.getAccessToken()); + } + private static Response ok(String body) { return new Response(200, /* message */ null, /* headers */ Collections.emptyMap(), body); } diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceTest.java index 3590e6b5d..56e6361df 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceTest.java @@ -1,12 +1,11 @@ package com.github.scribejava.core.oauth; +import com.fasterxml.jackson.databind.ObjectMapper; import com.github.scribejava.core.builder.ServiceBuilder; import com.github.scribejava.core.java8.Base64; import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuth2Authorization; import com.github.scribejava.core.model.OAuthConstants; -import com.google.gson.Gson; -import com.google.gson.reflect.TypeToken; import java.io.IOException; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertEquals; @@ -18,6 +17,7 @@ public class OAuth20ServiceTest { + private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); private final Base64.Encoder base64Encoder = Base64.getEncoder(); @Test @@ -27,11 +27,10 @@ public void shouldProduceCorrectRequestSync() throws IOException, InterruptedExc .build(new OAuth20ApiUnit()); final OAuth2AccessToken token = service.getAccessTokenPasswordGrant("user1", "password1"); - final Gson json = new Gson(); - assertNotNull(token); - final Map map = json.fromJson(token.getRawResponse(), new TypeTokenImpl().getType()); + @SuppressWarnings("unchecked") + final Map map = OBJECT_MAPPER.readValue(token.getRawResponse(), Map.class); assertEquals(OAuth20ServiceUnit.TOKEN, map.get(OAuthConstants.ACCESS_TOKEN)); assertEquals(OAuth20ServiceUnit.EXPIRES, map.get("expires_in")); @@ -47,17 +46,17 @@ public void shouldProduceCorrectRequestSync() throws IOException, InterruptedExc } @Test - public void shouldProduceCorrectRequestAsync() throws ExecutionException, InterruptedException { + public void shouldProduceCorrectRequestAsync() throws ExecutionException, InterruptedException, IOException { final OAuth20Service service = new ServiceBuilder("your_api_key") .apiSecret("your_api_secret") .build(new OAuth20ApiUnit()); final OAuth2AccessToken token = service.getAccessTokenPasswordGrantAsync("user1", "password1").get(); - final Gson json = new Gson(); assertNotNull(token); - final Map map = json.fromJson(token.getRawResponse(), new TypeTokenImpl().getType()); + @SuppressWarnings("unchecked") + final Map map = OBJECT_MAPPER.readValue(token.getRawResponse(), Map.class); assertEquals(OAuth20ServiceUnit.TOKEN, map.get(OAuthConstants.ACCESS_TOKEN)); assertEquals(OAuth20ServiceUnit.EXPIRES, map.get("expires_in")); @@ -117,9 +116,5 @@ public void testOAuthExtractAuthorization() { authorization = service.extractAuthorization("https://cl.ex.com/cb"); assertEquals(null, authorization.getCode()); assertEquals(null, authorization.getState()); - - } - - private static class TypeTokenImpl extends TypeToken> { } } diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceUnit.java b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceUnit.java index fe68d3873..2811088dc 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceUnit.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceUnit.java @@ -1,5 +1,7 @@ package com.github.scribejava.core.oauth; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.httpclient.HttpClientConfig; @@ -8,7 +10,6 @@ import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Parameter; -import com.google.gson.Gson; import java.util.HashMap; import java.util.Map; @@ -19,6 +20,7 @@ class OAuth20ServiceUnit extends OAuth20Service { static final String TOKEN = "ae82980abab675c646a070686d5558ad"; static final String STATE = "123"; static final String EXPIRES = "3600"; + private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); OAuth20ServiceUnit(DefaultApi20 api, String apiKey, String apiSecret, String callback, String defaultScope, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { @@ -31,7 +33,6 @@ protected OAuth2AccessToken sendAccessTokenRequestSync(OAuthRequest request) { } private String prepareRawResponse(OAuthRequest request) { - final Gson json = new Gson(); final Map response = new HashMap<>(); response.put(OAuthConstants.ACCESS_TOKEN, TOKEN); response.put(OAuthConstants.STATE, STATE); @@ -44,7 +45,11 @@ private String prepareRawResponse(OAuthRequest request) { response.put("query-" + param.getKey(), param.getValue()); } - return json.toJson(response); + try { + return OBJECT_MAPPER.writeValueAsString(response); + } catch (JsonProcessingException ex) { + throw new IllegalStateException("smth wrong with Jackson?"); + } } @Override diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index 02b290379..93d57ee84 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -23,7 +23,7 @@ org.apache.httpcomponents httpclient - 4.5.7 + 4.5.8 org.apache.httpcomponents diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index d18c6f9e2..25ab4c0d9 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -23,7 +23,7 @@ com.squareup.okhttp3 okhttp - 3.14.0 + 3.14.2 com.github.scribejava From f7aaa7cd30f6b646ecba4380f7838394cdaf0c4c Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 28 May 2019 15:33:04 +0300 Subject: [PATCH 713/882] fixes after switching to jackson --- .../FacebookAccessTokenErrorResponse.java | 40 ++++++++++++--- .../FacebookAccessTokenJsonExtractor.java | 10 ++-- .../apis/fitbit/FitBitJsonTokenExtractor.java | 17 +++---- .../apis/openid/OpenIdJsonTokenExtractor.java | 6 +-- .../SalesforceJsonTokenExtractor.java | 6 +-- .../apis/vk/VKJsonTokenExtractor.java | 9 ++-- .../apis/examples/AsanaExample.java | 3 +- .../apis/examples/Box20Example.java | 5 +- .../apis/examples/DataportenExample.java | 3 +- .../apis/examples/DiscordExample.java | 3 +- .../examples/FacebookAsyncApacheExample.java | 3 +- .../examples/FacebookAsyncNingExample.java | 3 +- .../apis/examples/FacebookExample.java | 3 +- .../apis/examples/FitbitApi20Example.java | 3 +- .../apis/examples/Foursquare2Example.java | 3 +- .../examples/GitHubAsyncOkHttpExample.java | 3 +- .../apis/examples/GitHubExample.java | 3 +- .../examples/Google20AsyncAHCExample.java | 5 +- .../apis/examples/Google20Example.java | 5 +- .../apis/examples/Google20RevokeExample.java | 5 +- .../examples/Google20WithPKCEExample.java | 5 +- .../scribejava/apis/examples/HHExample.java | 3 +- .../apis/examples/HiOrgServerExample.java | 3 +- .../apis/examples/KeycloakExample.java | 3 +- .../apis/examples/LinkedIn20Example.java | 3 +- .../scribejava/apis/examples/LiveExample.java | 3 +- .../apis/examples/MailruAsyncExample.java | 3 +- .../apis/examples/MailruExample.java | 3 +- ...icrosoftAzureActiveDirectory20Example.java | 3 +- .../MicrosoftAzureActiveDirectoryExample.java | 3 +- .../apis/examples/NaverExample.java | 3 +- .../apis/examples/OdnoklassnikiExample.java | 4 +- .../apis/examples/PinterestExample.java | 3 +- .../apis/examples/RenrenExample.java | 3 +- .../apis/examples/StackExchangeExample.java | 3 +- .../apis/examples/TutByExample.java | 3 +- .../apis/examples/ViadeoExample.java | 3 +- .../apis/examples/VkontakteExample.java | 3 +- .../VkontakteExternalHttpExample.java | 3 +- .../apis/examples/Yahoo20Example.java | 3 +- .../FacebookAccessTokenJsonExtractorTest.java | 36 +++++++++++++ .../AbstractOAuth1JSONTokenExtractor.java | 11 ++-- .../OAuth2AccessTokenJsonExtractor.java | 51 +++++++++---------- .../scribejava/core/oauth/OAuth20Service.java | 22 +++++--- .../OAuth2AccessTokenJsonExtractorTest.java | 9 +++- .../core/oauth/OAuth20ServiceTest.java | 32 ++++++------ .../core/oauth/OAuth20ServiceUnit.java | 4 +- 47 files changed, 199 insertions(+), 167 deletions(-) create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/facebook/FacebookAccessTokenJsonExtractorTest.java diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookAccessTokenErrorResponse.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookAccessTokenErrorResponse.java index 30c049a3f..3fca57c85 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookAccessTokenErrorResponse.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookAccessTokenErrorResponse.java @@ -19,15 +19,34 @@ public class FacebookAccessTokenErrorResponse extends OAuthException { private static final long serialVersionUID = -1277129766099856895L; private final String type; - private final String code; + private final int codeInt; private final String fbtraceId; private final String rawResponse; + /** + * @param message message + * @param type type + * @param code code + * @param fbtraceId fbtraceId + * @param rawResponse rawResponse + * @deprecated use {@link #FacebookAccessTokenErrorResponse(java.lang.String, java.lang.String, int, + * java.lang.String, java.lang.String)} + */ + @Deprecated public FacebookAccessTokenErrorResponse(String message, String type, String code, String fbtraceId, String rawResponse) { super(message); this.type = type; - this.code = code; + this.codeInt = Integer.parseInt(code); + this.fbtraceId = fbtraceId; + this.rawResponse = rawResponse; + } + + public FacebookAccessTokenErrorResponse(String message, String type, int code, String fbtraceId, + String rawResponse) { + super(message); + this.type = type; + this.codeInt = code; this.fbtraceId = fbtraceId; this.rawResponse = rawResponse; } @@ -36,8 +55,17 @@ public String getType() { return type; } + /** + * @return code + * @deprecated use {@link #getCodeInt() } + */ + @Deprecated public String getCode() { - return code; + return Integer.toString(codeInt); + } + + public int getCodeInt() { + return codeInt; } public String getFbtraceId() { @@ -54,7 +82,7 @@ public int hashCode() { hash = 83 * hash + Objects.hashCode(rawResponse); hash = 83 * hash + Objects.hashCode(getMessage()); hash = 83 * hash + Objects.hashCode(type); - hash = 83 * hash + Objects.hashCode(code); + hash = 83 * hash + Objects.hashCode(codeInt); hash = 83 * hash + Objects.hashCode(fbtraceId); return hash; } @@ -80,7 +108,7 @@ public boolean equals(Object obj) { if (!Objects.equals(type, other.getType())) { return false; } - if (!Objects.equals(code, other.getCode())) { + if (codeInt != other.getCodeInt()) { return false; } return Objects.equals(fbtraceId, other.getFbtraceId()); @@ -88,7 +116,7 @@ public boolean equals(Object obj) { @Override public String toString() { - return "FacebookAccessTokenErrorResponse{'type'='" + type + "', 'code'='" + code + return "FacebookAccessTokenErrorResponse{'type'='" + type + "', 'codeInt'='" + codeInt + "', 'fbtraceId'='" + fbtraceId + "', 'rawResponse'='" + rawResponse + "', 'message'='" + getMessage() + "'}"; } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookAccessTokenJsonExtractor.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookAccessTokenJsonExtractor.java index f7b783f6f..7171c9fbd 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookAccessTokenJsonExtractor.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookAccessTokenJsonExtractor.java @@ -1,8 +1,8 @@ package com.github.scribejava.apis.facebook; +import com.fasterxml.jackson.databind.JsonNode; import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; import java.io.IOException; -import java.util.Map; /** * non standard Facebook Extractor @@ -32,12 +32,10 @@ public static FacebookAccessTokenJsonExtractor instance() { */ @Override public void generateError(String rawResponse) throws IOException { - @SuppressWarnings("unchecked") - final Map response = OAuth2AccessTokenJsonExtractor.OBJECT_MAPPER - .readValue(rawResponse, Map.class); + final JsonNode errorNode = OAuth2AccessTokenJsonExtractor.OBJECT_MAPPER.readTree(rawResponse).get("error"); - throw new FacebookAccessTokenErrorResponse(response.get("message"), response.get("type"), response.get("code"), - response.get("fbtrace_id"), rawResponse); + throw new FacebookAccessTokenErrorResponse(errorNode.get("message").asText(), errorNode.get("type").asText(), + errorNode.get("code").asInt(), errorNode.get("fbtrace_id").asText(), rawResponse); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractor.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractor.java index 2923c3d42..3ec56f5be 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractor.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractor.java @@ -1,11 +1,10 @@ package com.github.scribejava.apis.fitbit; +import com.fasterxml.jackson.databind.JsonNode; import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; import com.github.scribejava.core.model.OAuth2AccessTokenErrorResponse; import com.github.scribejava.core.oauth2.OAuth2Error; import java.io.IOException; -import java.util.List; -import java.util.Map; public class FitBitJsonTokenExtractor extends OAuth2AccessTokenJsonExtractor { @@ -23,9 +22,9 @@ public static FitBitJsonTokenExtractor instance() { @Override protected FitBitOAuth2AccessToken createToken(String accessToken, String tokenType, Integer expiresIn, - String refreshToken, String scope, Map response, String rawResponse) { + String refreshToken, String scope, JsonNode response, String rawResponse) { return new FitBitOAuth2AccessToken(accessToken, tokenType, expiresIn, refreshToken, scope, - response.get("user_id"), rawResponse); + response.get("user_id").asText(), rawResponse); } /** @@ -33,19 +32,17 @@ protected FitBitOAuth2AccessToken createToken(String accessToken, String tokenTy */ @Override public void generateError(String rawResponse) throws IOException { - @SuppressWarnings("unchecked") - final Map>> response = OAuth2AccessTokenJsonExtractor.OBJECT_MAPPER - .readValue(rawResponse, Map.class); + final JsonNode errorNode = OAuth2AccessTokenJsonExtractor.OBJECT_MAPPER.readTree(rawResponse) + .get("errors").get(0); - final Map errorResponse = response.get("errors").get(0); OAuth2Error errorCode; try { - errorCode = OAuth2Error.parseFrom(extractRequiredParameter(errorResponse, "errorType", rawResponse)); + errorCode = OAuth2Error.parseFrom(extractRequiredParameter(errorNode, "errorType", rawResponse).asText()); } catch (IllegalArgumentException iaE) { //non oauth standard error code errorCode = null; } - throw new OAuth2AccessTokenErrorResponse(errorCode, errorResponse.get("message"), null, rawResponse); + throw new OAuth2AccessTokenErrorResponse(errorCode, errorNode.get("message").asText(), null, rawResponse); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/openid/OpenIdJsonTokenExtractor.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/openid/OpenIdJsonTokenExtractor.java index 2a750dbcb..2b1be532c 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/openid/OpenIdJsonTokenExtractor.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/openid/OpenIdJsonTokenExtractor.java @@ -1,7 +1,7 @@ package com.github.scribejava.apis.openid; +import com.fasterxml.jackson.databind.JsonNode; import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; -import java.util.Map; /** * additionally parses OpenID id_token @@ -22,8 +22,8 @@ public static OpenIdJsonTokenExtractor instance() { @Override protected OpenIdOAuth2AccessToken createToken(String accessToken, String tokenType, Integer expiresIn, - String refreshToken, String scope, Map response, String rawResponse) { + String refreshToken, String scope, JsonNode response, String rawResponse) { return new OpenIdOAuth2AccessToken(accessToken, tokenType, expiresIn, refreshToken, scope, - response.get("id_token"), rawResponse); + response.get("id_token").asText(), rawResponse); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/salesforce/SalesforceJsonTokenExtractor.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/salesforce/SalesforceJsonTokenExtractor.java index 3876b587d..62a3294cf 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/salesforce/SalesforceJsonTokenExtractor.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/salesforce/SalesforceJsonTokenExtractor.java @@ -1,7 +1,7 @@ package com.github.scribejava.apis.salesforce; +import com.fasterxml.jackson.databind.JsonNode; import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; -import java.util.Map; /** * This extractor parses in addition to the standard Extractor the instance_url @@ -23,8 +23,8 @@ public static SalesforceJsonTokenExtractor instance() { @Override protected SalesforceToken createToken(String accessToken, String tokenType, Integer expiresIn, - String refreshToken, String scope, Map response, String rawResponse) { + String refreshToken, String scope, JsonNode response, String rawResponse) { return new SalesforceToken(accessToken, tokenType, expiresIn, refreshToken, scope, - extractRequiredParameter(response, "instance_url", rawResponse), rawResponse); + extractRequiredParameter(response, "instance_url", rawResponse).asText(), rawResponse); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/vk/VKJsonTokenExtractor.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/vk/VKJsonTokenExtractor.java index 277904ec6..a3d14aacf 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/vk/VKJsonTokenExtractor.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/vk/VKJsonTokenExtractor.java @@ -1,7 +1,7 @@ package com.github.scribejava.apis.vk; +import com.fasterxml.jackson.databind.JsonNode; import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; -import java.util.Map; /** * additionally parses email @@ -22,8 +22,9 @@ public static VKJsonTokenExtractor instance() { @Override protected VKOAuth2AccessToken createToken(String accessToken, String tokenType, Integer expiresIn, - String refreshToken, String scope, Map response, String rawResponse) { - return new VKOAuth2AccessToken(accessToken, tokenType, expiresIn, refreshToken, scope, response.get("email"), - rawResponse); + String refreshToken, String scope, JsonNode response, String rawResponse) { + final JsonNode email = response.get("email"); + return new VKOAuth2AccessToken(accessToken, tokenType, expiresIn, refreshToken, scope, + email == null ? null : email.asText(), rawResponse); } } diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AsanaExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AsanaExample.java index 1c5bf684d..4320fbe6e 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AsanaExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AsanaExample.java @@ -42,8 +42,7 @@ public static void main(String... args) throws IOException, InterruptedException final String code = in.nextLine(); System.out.println(); - // Trade the Request Token and Verfier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); + System.out.println("Trading the Authorization Code for an Access Token..."); OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Box20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Box20Example.java index edbbd1663..4dd9fad9f 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Box20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Box20Example.java @@ -42,7 +42,7 @@ public static void main(String... args) throws IOException, InterruptedException //pass access_type=offline to get refresh token final Map additionalParams = new HashMap<>(); additionalParams.put("access_type", "offline"); - //force to reget refresh token (if usera are asked not the first time) + //force to reget refresh token (if user are asked not the first time) additionalParams.put("prompt", "consent"); final String authorizationUrl = service.createAuthorizationUrlBuilder() .state(secretState) @@ -68,8 +68,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println(); } - // Trade the Request Token and Verfier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); + System.out.println("Trading the Authorization Code for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DataportenExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DataportenExample.java index 1878983eb..72dbba843 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DataportenExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DataportenExample.java @@ -58,8 +58,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println(); } - // Trade the Request Token and Verfier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); + System.out.println("Trading the Authorization Code for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiscordExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiscordExample.java index b574034c7..facca275b 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiscordExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiscordExample.java @@ -61,8 +61,7 @@ public static void main(String... args) throws IOException, ExecutionException, System.out.println(); } - // Trade the Request Token and Verfier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); + System.out.println("Trading the Authorization Code for an Access Token..."); OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncApacheExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncApacheExample.java index c2e55187e..337a11e40 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncApacheExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncApacheExample.java @@ -62,8 +62,7 @@ public static void main(String... args) throws InterruptedException, ExecutionEx System.out.println(); } - // Trade the Request Token and Verfier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); + System.out.println("Trading the Authorization Code for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessTokenAsync(code).get(); System.out.println("Got the Access Token!"); System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java index 6c9b64436..073df9ebe 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java @@ -70,8 +70,7 @@ public static void main(String... args) throws InterruptedException, ExecutionEx System.out.println(); } - // Trade the Request Token and Verfier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); + System.out.println("Trading the Authorization Code for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessTokenAsync(code).get(); System.out.println("Got the Access Token!"); System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java index e4e7ca180..cd9a7db9b 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java @@ -59,8 +59,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println(); } - // Trade the Request Token and Verfier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); + System.out.println("Trading the Authorization Code for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FitbitApi20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FitbitApi20Example.java index 0be7c1b6e..20ca7372b 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FitbitApi20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FitbitApi20Example.java @@ -48,8 +48,7 @@ public static void main(String... args) throws Exception { final String code = in.nextLine(); System.out.println(); - // Trade the Request Token and Verfier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); + System.out.println("Trading the Authorization Code for an Access Token..."); final OAuth2AccessToken oauth2AccessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + oauth2AccessToken diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java index 3aa3ab38b..69d9277f0 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java @@ -44,8 +44,7 @@ public static void main(String... args) throws IOException, InterruptedException final String code = in.nextLine(); System.out.println(); - // Trade the Request Token and Verfier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); + System.out.println("Trading the Authorization Code for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubAsyncOkHttpExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubAsyncOkHttpExample.java index 7559f9188..abecfd03b 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubAsyncOkHttpExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubAsyncOkHttpExample.java @@ -62,8 +62,7 @@ public static void main(String... args) throws IOException, ExecutionException, System.out.println(); } - // Trade the Request Token and Verfier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); + System.out.println("Trading the Authorization Code for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubExample.java index d9fa467be..59302a752 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubExample.java @@ -58,8 +58,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println(); } - // Trade the Request Token and Verfier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); + System.out.println("Trading the Authorization Code for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java index 6dc0dc624..f9214f05f 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java @@ -55,7 +55,7 @@ public static void main(String... args) throws InterruptedException, ExecutionEx //https://developers.google.com/identity/protocols/OAuth2WebServer#preparing-to-start-the-oauth-20-flow final Map additionalParams = new HashMap<>(); additionalParams.put("access_type", "offline"); - //force to reget refresh token (if usera are asked not the first time) + //force to reget refresh token (if user are asked not the first time) additionalParams.put("prompt", "consent"); final String authorizationUrl = service.createAuthorizationUrlBuilder() .state(secretState) @@ -82,8 +82,7 @@ public static void main(String... args) throws InterruptedException, ExecutionEx System.out.println(); } - // Trade the Request Token and Verfier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); + System.out.println("Trading the Authorization Code for an Access Token..."); OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java index 4b141c42b..4c23c3287 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java @@ -44,7 +44,7 @@ public static void main(String... args) throws IOException, InterruptedException //https://developers.google.com/identity/protocols/OAuth2WebServer#preparing-to-start-the-oauth-20-flow final Map additionalParams = new HashMap<>(); additionalParams.put("access_type", "offline"); - //force to reget refresh token (if usera are asked not the first time) + //force to reget refresh token (if user are asked not the first time) additionalParams.put("prompt", "consent"); final String authorizationUrl = service.createAuthorizationUrlBuilder() .state(secretState) @@ -70,8 +70,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println(); } - // Trade the Request Token and Verfier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); + System.out.println("Trading the Authorization Code for an Access Token..."); OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20RevokeExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20RevokeExample.java index 9f55b43d7..384183553 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20RevokeExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20RevokeExample.java @@ -44,7 +44,7 @@ public static void main(String... args) throws IOException, InterruptedException //https://developers.google.com/identity/protocols/OAuth2WebServer#preparing-to-start-the-oauth-20-flow final Map additionalParams = new HashMap<>(); additionalParams.put("access_type", "offline"); - //force to reget refresh token (if usera are asked not the first time) + //force to reget refresh token (if user are asked not the first time) additionalParams.put("prompt", "consent"); final String authorizationUrl = service.createAuthorizationUrlBuilder() .state(secretState) @@ -70,8 +70,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println(); } - // Trade the Request Token and Verfier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); + System.out.println("Trading the Authorization Code for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20WithPKCEExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20WithPKCEExample.java index b4d108430..5f9bb3e15 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20WithPKCEExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20WithPKCEExample.java @@ -47,7 +47,7 @@ public static void main(String... args) throws IOException, InterruptedException //https://developers.google.com/identity/protocols/OAuth2WebServer#preparing-to-start-the-oauth-20-flow final Map additionalParams = new HashMap<>(); additionalParams.put("access_type", "offline"); - //force to reget refresh token (if usera are asked not the first time) + //force to reget refresh token (if user are asked not the first time) additionalParams.put("prompt", "consent"); final AuthorizationUrlBuilder authorizationUrlBuilder = service.createAuthorizationUrlBuilder() @@ -75,8 +75,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println(); } - // Trade the Request Token and Verfier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); + System.out.println("Trading the Authorization Code for an Access Token..."); OAuth2AccessToken accessToken = service.getAccessToken(AccessTokenRequestParams.create(code) .pkceCodeVerifier(authorizationUrlBuilder.getPkce().getCodeVerifier())); System.out.println("Got the Access Token!"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HHExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HHExample.java index ae7cafa2d..3e9f7b892 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HHExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HHExample.java @@ -46,8 +46,7 @@ public static void main(String... args) throws IOException, InterruptedException final String code = in.nextLine(); System.out.println(); - // Trade the Request Token and Verfier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); + System.out.println("Trading the Authorization Code for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HiOrgServerExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HiOrgServerExample.java index 22846f21d..b2a764883 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HiOrgServerExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HiOrgServerExample.java @@ -63,8 +63,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println(); } - // Trade the Request Token and Verfier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); + System.out.println("Trading the Authorization Code for an Access Token..."); OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/KeycloakExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/KeycloakExample.java index 80cf06473..242ba46c6 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/KeycloakExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/KeycloakExample.java @@ -49,8 +49,7 @@ public static void main(String... args) throws IOException, InterruptedException final String code = in.nextLine(); System.out.println(); - // Trade the Request Token and Verfier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); + System.out.println("Trading the Authorization Code for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedIn20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedIn20Example.java index e06dd2a3b..b77a08c61 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedIn20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedIn20Example.java @@ -49,8 +49,7 @@ public static void main(String... args) throws IOException, InterruptedException final String code = in.nextLine(); System.out.println(); - // Trade the Request Token and Verfier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); + System.out.println("Trading the Authorization Code for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java index fb6712b6a..2e2109e28 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java @@ -44,8 +44,7 @@ public static void main(String... args) throws IOException, InterruptedException final String code = in.nextLine(); System.out.println(); - // Trade the Request Token and Verfier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); + System.out.println("Trading the Authorization Code for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java index 6fcb28be8..0dffbd4d3 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java @@ -57,8 +57,7 @@ public static void main(String... args) throws InterruptedException, ExecutionEx final String code = in.nextLine(); System.out.println(); - // Trade the Request Token and Verfier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); + System.out.println("Trading the Authorization Code for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java index 7c7ea8161..fe5df3e51 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java @@ -46,8 +46,7 @@ public static void main(String... args) throws IOException, InterruptedException final String code = in.nextLine(); System.out.println(); - // Trade the Request Token and Verfier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); + System.out.println("Trading the Authorization Code for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureActiveDirectory20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureActiveDirectory20Example.java index b06ae03db..9f9e0afce 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureActiveDirectory20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureActiveDirectory20Example.java @@ -42,8 +42,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.print(">>"); final String code = in.nextLine(); System.out.println(); - // Trade the Request Token and Verfier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); + System.out.println("Trading the Authorization Code for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureActiveDirectoryExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureActiveDirectoryExample.java index 70dd25a94..4d7e6c40e 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureActiveDirectoryExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureActiveDirectoryExample.java @@ -47,8 +47,7 @@ public static void main(String... args) throws IOException, InterruptedException final String code = in.nextLine(); System.out.println(); - // Trade the Request Token and Verfier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); + System.out.println("Trading the Authorization Code for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NaverExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NaverExample.java index 2879cb1f9..260dbec4f 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NaverExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NaverExample.java @@ -60,8 +60,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println(); } - // Trade the Request Token and Verfier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); + System.out.println("Trading the Authorization Code for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java index 3deb43a30..e97540a19 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java @@ -48,9 +48,7 @@ public static void main(String... args) throws IOException, InterruptedException final String code = in.nextLine(); System.out.println(); - // Trade the Request Token and Verfier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); - + System.out.println("Trading the Authorization Code for an Access Token..."); OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java index c7fd39149..e6d8922fa 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java @@ -45,8 +45,7 @@ public static void main(String... args) throws IOException, InterruptedException final String code = in.nextLine(); System.out.println(); - // Trade the Request Token and Verfier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); + System.out.println("Trading the Authorization Code for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java index 61bcd5c6d..1131b87fb 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java @@ -55,8 +55,7 @@ public static void main(String... args) throws IOException, InterruptedException final String code = in.nextLine(); System.out.println(); - // Trade the Request Token and Verfier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); + System.out.println("Trading the Authorization Code for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/StackExchangeExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/StackExchangeExample.java index 564dbc222..a35cda537 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/StackExchangeExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/StackExchangeExample.java @@ -63,8 +63,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println(); } - // Trade the Request Token and Verfier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); + System.out.println("Trading the Authorization Code for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TutByExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TutByExample.java index 393db2a65..475c7df58 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TutByExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TutByExample.java @@ -45,8 +45,7 @@ public static void main(String... args) throws IOException, InterruptedException final String code = in.nextLine(); System.out.println(); - // Trade the Request Token and Verfier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); + System.out.println("Trading the Authorization Code for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ViadeoExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ViadeoExample.java index c16bd9770..0efdcd448 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ViadeoExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ViadeoExample.java @@ -44,8 +44,7 @@ public static void main(String... args) throws IOException, InterruptedException final String code = in.nextLine(); System.out.println(); - // Trade the Request Token and Verfier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); + System.out.println("Trading the Authorization Code for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExample.java index 2c73d583d..26f7cde06 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExample.java @@ -51,8 +51,7 @@ public static void main(String... args) throws IOException, InterruptedException final String code = in.nextLine(); System.out.println(); - // Trade the Request Token and Verfier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); + System.out.println("Trading the Authorization Code for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(AccessTokenRequestParams.create(code) .scope(customScope)); System.out.println("Got the Access Token!"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExternalHttpExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExternalHttpExample.java index c918633c0..3171c8d8c 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExternalHttpExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExternalHttpExample.java @@ -63,8 +63,7 @@ public static void main(String... args) throws IOException, InterruptedException final String code = in.nextLine(); System.out.println(); - // Trade the Request Token and Verfier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); + System.out.println("Trading the Authorization Code for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Yahoo20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Yahoo20Example.java index e151e8e5b..1a5186286 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Yahoo20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Yahoo20Example.java @@ -56,8 +56,7 @@ public static void main(String... args) throws IOException, InterruptedException final String oauthVerifier = in.nextLine(); System.out.println(); - // Trade the Request Token and Verfier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); + System.out.println("Trading the Authorization Code for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(oauthVerifier); System.out.println("Got the Access Token!"); System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/facebook/FacebookAccessTokenJsonExtractorTest.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/facebook/FacebookAccessTokenJsonExtractorTest.java new file mode 100644 index 000000000..3fa402247 --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/facebook/FacebookAccessTokenJsonExtractorTest.java @@ -0,0 +1,36 @@ +package com.github.scribejava.apis.facebook; + +import com.github.scribejava.core.model.Response; +import java.io.IOException; +import java.util.Collections; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; +import org.junit.Test; + +public class FacebookAccessTokenJsonExtractorTest { + + private final FacebookAccessTokenJsonExtractor extractor = FacebookAccessTokenJsonExtractor.instance(); + + @Test + public void shouldThrowExceptionIfResponseIsError() throws IOException { + final String body = "{\"error\":" + + "{\"message\":\"This authorization code has been used.\"," + + "\"type\":\"OAuthException\"," + + "\"code\":100," + + "\"fbtrace_id\":\"DtxvtGRaxbB\"}}"; + try { + extractor.extract(error(body)); + fail(); + } catch (FacebookAccessTokenErrorResponse fateR) { + assertEquals("This authorization code has been used.", fateR.getMessage()); + assertEquals("OAuthException", fateR.getType()); + assertEquals(100, fateR.getCodeInt()); + assertEquals("DtxvtGRaxbB", fateR.getFbtraceId()); + assertEquals(body, fateR.getRawResponse()); + } + } + + private static Response error(String body) { + return new Response(400, /* message */ null, /* headers */ Collections.emptyMap(), body); + } +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/AbstractOAuth1JSONTokenExtractor.java b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/AbstractOAuth1JSONTokenExtractor.java index 68c7fdac0..5c42e812a 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/AbstractOAuth1JSONTokenExtractor.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/AbstractOAuth1JSONTokenExtractor.java @@ -1,5 +1,6 @@ package com.github.scribejava.core.extractors; +import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.github.scribejava.core.exceptions.OAuthException; import com.github.scribejava.core.model.OAuth1Token; @@ -8,7 +9,6 @@ import com.github.scribejava.core.utils.Preconditions; import java.io.IOException; -import java.util.Map; public abstract class AbstractOAuth1JSONTokenExtractor implements TokenExtractor { @@ -21,18 +21,17 @@ public T extract(Response response) throws IOException { Preconditions.checkEmptyString(rawBody, "Response body is incorrect. Can't extract a token from an empty string"); - @SuppressWarnings("unchecked") - final Map body = OBJECT_MAPPER.readValue(rawBody, Map.class); + final JsonNode body = OBJECT_MAPPER.readTree(rawBody); - final String token = body.get(OAuthConstants.TOKEN); - final String secret = body.get(OAuthConstants.TOKEN_SECRET); + final JsonNode token = body.get(OAuthConstants.TOKEN); + final JsonNode secret = body.get(OAuthConstants.TOKEN_SECRET); if (token == null || secret == null) { throw new OAuthException("Response body is incorrect. Can't extract token and secret from this: '" + rawBody + '\'', null); } - return createToken(token, secret, rawBody); + return createToken(token.asText(), secret.asText(), rawBody); } protected abstract T createToken(String token, String secret, String response); diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractor.java b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractor.java index fc7be6e0f..d626ca159 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractor.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractor.java @@ -1,5 +1,6 @@ package com.github.scribejava.core.extractors; +import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import java.io.IOException; import java.net.URI; @@ -12,7 +13,6 @@ import com.github.scribejava.core.model.Response; import com.github.scribejava.core.oauth2.OAuth2Error; import com.github.scribejava.core.utils.Preconditions; -import java.util.Map; /** * JSON (default) implementation of {@link TokenExtractor} for OAuth 2.0 @@ -51,48 +51,47 @@ public OAuth2AccessToken extract(Response response) throws IOException { * @throws IOException IOException */ public void generateError(String rawResponse) throws IOException { - @SuppressWarnings("unchecked") - final Map response = OBJECT_MAPPER.readValue(rawResponse, Map.class); + final JsonNode response = OBJECT_MAPPER.readTree(rawResponse); - final String errorUriInString = response.get("error_uri"); + final JsonNode errorUriInString = response.get("error_uri"); URI errorUri; try { - errorUri = errorUriInString == null ? null : URI.create(errorUriInString); + errorUri = errorUriInString == null ? null : URI.create(errorUriInString.asText()); } catch (IllegalArgumentException iae) { errorUri = null; } OAuth2Error errorCode; try { - errorCode = OAuth2Error.parseFrom(extractRequiredParameter(response, "error", rawResponse)); + errorCode = OAuth2Error.parseFrom(extractRequiredParameter(response, "error", rawResponse).asText()); } catch (IllegalArgumentException iaE) { //non oauth standard error code errorCode = null; } - throw new OAuth2AccessTokenErrorResponse(errorCode, response.get("error_description"), errorUri, rawResponse); + final JsonNode errorDescription = response.get("error_description"); + + throw new OAuth2AccessTokenErrorResponse(errorCode, errorDescription == null ? null : errorDescription.asText(), + errorUri, rawResponse); } private OAuth2AccessToken createToken(String rawResponse) throws IOException { - @SuppressWarnings("unchecked") - final Map response = OBJECT_MAPPER.readValue(rawResponse, Map.class); + final JsonNode response = OBJECT_MAPPER.readTree(rawResponse); - final String expiresInString = response.get("expires_in"); - Integer expiresIn; - try { - expiresIn = expiresInString == null ? null : Integer.valueOf(expiresInString); - } catch (NumberFormatException nfe) { - expiresIn = null; - } + final JsonNode expiresInNode = response.get("expires_in"); + final JsonNode refreshToken = response.get(OAuthConstants.REFRESH_TOKEN); + final JsonNode scope = response.get(OAuthConstants.SCOPE); + final JsonNode tokenType = response.get("token_type"); - return createToken(extractRequiredParameter(response, OAuthConstants.ACCESS_TOKEN, rawResponse), - response.get("token_type"), expiresIn, response.get(OAuthConstants.REFRESH_TOKEN), - response.get(OAuthConstants.SCOPE), response, rawResponse); + return createToken(extractRequiredParameter(response, OAuthConstants.ACCESS_TOKEN, rawResponse).asText(), + tokenType == null ? null : tokenType.asText(), expiresInNode == null ? null : expiresInNode.asInt(), + refreshToken == null ? null : refreshToken.asText(), scope == null ? null : scope.asText(), response, + rawResponse); } protected OAuth2AccessToken createToken(String accessToken, String tokenType, Integer expiresIn, - String refreshToken, String scope, Map response, String rawResponse) { + String refreshToken, String scope, JsonNode response, String rawResponse) { return createToken(accessToken, tokenType, expiresIn, refreshToken, scope, rawResponse); } @@ -106,7 +105,7 @@ protected OAuth2AccessToken createToken(String accessToken, String tokenType, In * @param rawResponse rawResponse * @return OAuth2AccessToken * @deprecated use {@link #createToken(java.lang.String, java.lang.String, java.lang.Integer, java.lang.String, - * java.lang.String, java.util.Map, java.lang.String)} + * java.lang.String, com.fasterxml.jackson.databind.JsonNode, java.lang.String)} */ @Deprecated protected OAuth2AccessToken createToken(String accessToken, String tokenType, Integer expiresIn, @@ -121,8 +120,8 @@ protected OAuth2AccessToken createToken(String accessToken, String tokenType, In * @param required required * @return parameter value * @throws OAuthException OAuthException - * @deprecated use {@link #extractRequiredParameter(java.util.Map, java.lang.String, java.lang.String) } or - * {@link java.util.Map#get(java.lang.Object) } + * @deprecated use {@link #extractRequiredParameter(com.fasterxml.jackson.databind.JsonNode, java.lang.String, + * java.lang.String)} */ @Deprecated protected static String extractParameter(String response, Pattern regexPattern, boolean required) @@ -140,9 +139,9 @@ protected static String extractParameter(String response, Pattern regexPattern, return null; } - protected static String extractRequiredParameter(Map response, String parameterName, - String rawResponse) throws OAuthException { - final String value = response.get(parameterName); + protected static JsonNode extractRequiredParameter(JsonNode errorNode, String parameterName, String rawResponse) + throws OAuthException { + final JsonNode value = errorNode.get(parameterName); if (value == null) { throw new OAuthException("Response body is incorrect. Can't extract a '" + parameterName diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java index df4557ea0..c80a6496d 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java @@ -17,6 +17,8 @@ import java.util.Map; import java.util.concurrent.ExecutionException; import com.github.scribejava.core.revoke.TokenTypeHint; +import java.io.UnsupportedEncodingException; +import java.net.URLDecoder; public class OAuth20Service extends OAuthService { @@ -411,14 +413,18 @@ public OAuth2Authorization extractAuthorization(String redirectLocation) { for (String param : redirectLocation.substring(redirectLocation.indexOf('?') + 1, end).split("&")) { final String[] keyValue = param.split("="); if (keyValue.length == 2) { - switch (keyValue[0]) { - case "code": - authorization.setCode(keyValue[1]); - break; - case "state": - authorization.setState(keyValue[1]); - break; - default: //just ignore any other param; + try { + switch (keyValue[0]) { + case "code": + authorization.setCode(URLDecoder.decode(keyValue[1], "UTF-8")); + break; + case "state": + authorization.setState(URLDecoder.decode(keyValue[1], "UTF-8")); + break; + default: //just ignore any other param; + } + } catch (UnsupportedEncodingException ueE) { + throw new IllegalStateException("jvm without UTF-8, really?", ueE); } } } diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractorTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractorTest.java index 9324b3e4f..7114115be 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractorTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractorTest.java @@ -19,7 +19,8 @@ public class OAuth2AccessTokenJsonExtractorTest { @Test public void shouldParseResponse() throws IOException { final OAuth2AccessToken token = extractor.extract( - ok("{ \"access_token\":\"I0122HHJKLEM21F3WLPYHDKGKZULAUO4SGMV3ABKFTDT3T3X\"}")); + ok("{ \"access_token\":\"I0122HHJKLEM21F3WLPYHDKGKZULAUO4SGMV3ABKFTDT3T3X\", " + + "\"token_type\":\"example\"}")); assertEquals("I0122HHJKLEM21F3WLPYHDKGKZULAUO4SGMV3ABKFTDT3T3X", token.getAccessToken()); } @@ -27,18 +28,21 @@ public void shouldParseResponse() throws IOException { public void shouldParseScopeFromResponse() throws IOException { OAuth2AccessToken token = extractor.extract( ok("{ \"access_token\":\"I0122HHJKLEM21F3WLPYHDKGKZULAUO4SGMV3ABKFTDT3T4X\", " + + "\"token_type\":\"example\"," + "\"scope\":\"s1\"}")); assertEquals("I0122HHJKLEM21F3WLPYHDKGKZULAUO4SGMV3ABKFTDT3T4X", token.getAccessToken()); assertEquals("s1", token.getScope()); token = extractor.extract( ok("{ \"access_token\":\"I0122HHJKLEM21F3WLPYHDKGKZULAUO4SGMV3ABKFTDT3T5X\", " + + "\"token_type\":\"example\"," + "\"scope\":\"s1 s2\"}")); assertEquals("I0122HHJKLEM21F3WLPYHDKGKZULAUO4SGMV3ABKFTDT3T5X", token.getAccessToken()); assertEquals("s1 s2", token.getScope()); token = extractor.extract( ok("{ \"access_token\":\"I0122HHJKLEM21F3WLPYHDKGKZULAUO4SGMV3ABKFTDT3T6X\", " + + "\"token_type\":\"example\"," + "\"scope\":\"s3 s4\", " + "\"refresh_token\":\"refresh_token1\"}")); assertEquals("I0122HHJKLEM21F3WLPYHDKGKZULAUO4SGMV3ABKFTDT3T6X", token.getAccessToken()); @@ -74,7 +78,8 @@ public void shouldThrowExceptionIfResponseIsError() throws IOException { @Test public void testEscapedJsonInResponse() throws IOException { - final OAuth2AccessToken token = extractor.extract(ok("{ \"access_token\":\"I0122HKLEM2\\/MV3ABKFTDT3T5X\"}")); + final OAuth2AccessToken token = extractor.extract(ok("{ \"access_token\":\"I0122HKLEM2\\/MV3ABKFTDT3T5X\"," + + "\"token_type\":\"example\"}")); assertEquals("I0122HKLEM2/MV3ABKFTDT3T5X", token.getAccessToken()); } diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceTest.java index 56e6361df..7dfe361f0 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceTest.java @@ -1,5 +1,6 @@ package com.github.scribejava.core.oauth; +import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.github.scribejava.core.builder.ServiceBuilder; import com.github.scribejava.core.java8.Base64; @@ -12,7 +13,6 @@ import org.junit.Test; import java.nio.charset.Charset; -import java.util.Map; import java.util.concurrent.ExecutionException; public class OAuth20ServiceTest { @@ -29,20 +29,19 @@ public void shouldProduceCorrectRequestSync() throws IOException, InterruptedExc final OAuth2AccessToken token = service.getAccessTokenPasswordGrant("user1", "password1"); assertNotNull(token); - @SuppressWarnings("unchecked") - final Map map = OBJECT_MAPPER.readValue(token.getRawResponse(), Map.class); + final JsonNode response = OBJECT_MAPPER.readTree(token.getRawResponse()); - assertEquals(OAuth20ServiceUnit.TOKEN, map.get(OAuthConstants.ACCESS_TOKEN)); - assertEquals(OAuth20ServiceUnit.EXPIRES, map.get("expires_in")); + assertEquals(OAuth20ServiceUnit.TOKEN, response.get(OAuthConstants.ACCESS_TOKEN).asText()); + assertEquals(OAuth20ServiceUnit.EXPIRES, response.get("expires_in").asInt()); final String authorize = base64Encoder.encodeToString( String.format("%s:%s", service.getApiKey(), service.getApiSecret()).getBytes(Charset.forName("UTF-8"))); - assertEquals(OAuthConstants.BASIC + ' ' + authorize, map.get(OAuthConstants.HEADER)); + assertEquals(OAuthConstants.BASIC + ' ' + authorize, response.get(OAuthConstants.HEADER).asText()); - assertEquals("user1", map.get("query-username")); - assertEquals("password1", map.get("query-password")); - assertEquals("password", map.get("query-grant_type")); + assertEquals("user1", response.get("query-username").asText()); + assertEquals("password1", response.get("query-password").asText()); + assertEquals("password", response.get("query-grant_type").asText()); } @Test @@ -55,20 +54,19 @@ public void shouldProduceCorrectRequestAsync() throws ExecutionException, Interr assertNotNull(token); - @SuppressWarnings("unchecked") - final Map map = OBJECT_MAPPER.readValue(token.getRawResponse(), Map.class); + final JsonNode response = OBJECT_MAPPER.readTree(token.getRawResponse()); - assertEquals(OAuth20ServiceUnit.TOKEN, map.get(OAuthConstants.ACCESS_TOKEN)); - assertEquals(OAuth20ServiceUnit.EXPIRES, map.get("expires_in")); + assertEquals(OAuth20ServiceUnit.TOKEN, response.get(OAuthConstants.ACCESS_TOKEN).asText()); + assertEquals(OAuth20ServiceUnit.EXPIRES, response.get("expires_in").asInt()); final String authorize = base64Encoder.encodeToString( String.format("%s:%s", service.getApiKey(), service.getApiSecret()).getBytes(Charset.forName("UTF-8"))); - assertEquals(OAuthConstants.BASIC + ' ' + authorize, map.get(OAuthConstants.HEADER)); + assertEquals(OAuthConstants.BASIC + ' ' + authorize, response.get(OAuthConstants.HEADER).asText()); - assertEquals("user1", map.get("query-username")); - assertEquals("password1", map.get("query-password")); - assertEquals("password", map.get("query-grant_type")); + assertEquals("user1", response.get("query-username").asText()); + assertEquals("password1", response.get("query-password").asText()); + assertEquals("password", response.get("query-grant_type").asText()); } @Test diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceUnit.java b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceUnit.java index 2811088dc..46cf9ee28 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceUnit.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceUnit.java @@ -19,7 +19,7 @@ class OAuth20ServiceUnit extends OAuth20Service { static final String TOKEN = "ae82980abab675c646a070686d5558ad"; static final String STATE = "123"; - static final String EXPIRES = "3600"; + static final int EXPIRES = 3600; private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); OAuth20ServiceUnit(DefaultApi20 api, String apiKey, String apiSecret, String callback, String defaultScope, @@ -33,7 +33,7 @@ protected OAuth2AccessToken sendAccessTokenRequestSync(OAuthRequest request) { } private String prepareRawResponse(OAuthRequest request) { - final Map response = new HashMap<>(); + final Map response = new HashMap<>(); response.put(OAuthConstants.ACCESS_TOKEN, TOKEN); response.put(OAuthConstants.STATE, STATE); response.put("expires_in", EXPIRES); From aefa8d6a809de0390f2bab981fe08dad00c6545a Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 28 May 2019 17:20:21 +0300 Subject: [PATCH 714/882] prepare v6.6.0 --- README.md | 4 ++-- changelog | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 5ebf4674c..393a0017b 100644 --- a/README.md +++ b/README.md @@ -129,7 +129,7 @@ You can pull ScribeJava from the central maven repository, just add these to you com.github.scribejava scribejava-apis - 6.5.1 + 6.6.0 ``` @@ -138,7 +138,7 @@ And in case you need just core classes (that's it, without any external API (FB, com.github.scribejava scribejava-core - 6.5.1 + 6.6.0 ``` diff --git a/changelog b/changelog index 532b45e92..d0659e450 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,4 @@ -[SNAPSHOT] +[6.6.0] * add PMD checks on compile * add all OAuth error codes from supported RFCs (incl. "invalid_token") (thanks to https://github.com/echorebel) * Update LinkedIn Example to API v2 (thanks to https://github.com/peternees) From 5f031fc989ed98bdc23e8c6ab3920db4abb6d131 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 28 May 2019 17:21:47 +0300 Subject: [PATCH 715/882] [maven-release-plugin] prepare release scribejava-6.6.0 --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index 7898059cb..5fb759ffb 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 6.5.2-SNAPSHOT + 6.6.0 ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -34,7 +34,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - HEAD + scribejava-6.6.0 diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 6f0e6e21d..d0e738d7f 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.5.2-SNAPSHOT + 6.6.0 ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 61cf7df26..3fe28bf80 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.5.2-SNAPSHOT + 6.6.0 ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index f3de40bc2..c927bd762 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.5.2-SNAPSHOT + 6.6.0 ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index 93d57ee84..627322daf 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.5.2-SNAPSHOT + 6.6.0 ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index 185088deb..e9da28657 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.5.2-SNAPSHOT + 6.6.0 ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 25ab4c0d9..eefca488a 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.5.2-SNAPSHOT + 6.6.0 ../pom.xml From ad059f67bea63fb1fa79f6de08ba953e9ec7cb85 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 28 May 2019 17:22:28 +0300 Subject: [PATCH 716/882] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index 5fb759ffb..9adb2c52a 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 6.6.0 + 6.6.1-SNAPSHOT ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -34,7 +34,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - scribejava-6.6.0 + HEAD diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index d0e738d7f..b2c0e128b 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.6.0 + 6.6.1-SNAPSHOT ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 3fe28bf80..c460ec225 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.6.0 + 6.6.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index c927bd762..dde3bc9f1 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.6.0 + 6.6.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index 627322daf..962a8339c 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.6.0 + 6.6.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index e9da28657..b094f19c6 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.6.0 + 6.6.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index eefca488a..efe512e3e 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.6.0 + 6.6.1-SNAPSHOT ../pom.xml From 5e2f639582e35dd3b242fa76a41186840d12ce73 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 28 May 2019 18:11:26 +0300 Subject: [PATCH 717/882] prepare 6.6.1 --- README.md | 4 ++-- changelog | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 393a0017b..764b5827e 100644 --- a/README.md +++ b/README.md @@ -129,7 +129,7 @@ You can pull ScribeJava from the central maven repository, just add these to you com.github.scribejava scribejava-apis - 6.6.0 + 6.6.1 ``` @@ -138,7 +138,7 @@ And in case you need just core classes (that's it, without any external API (FB, com.github.scribejava scribejava-core - 6.6.0 + 6.6.1 ``` diff --git a/changelog b/changelog index d0659e450..a5690d4f2 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,4 @@ -[6.6.0] +[6.6.1] * add PMD checks on compile * add all OAuth error codes from supported RFCs (incl. "invalid_token") (thanks to https://github.com/echorebel) * Update LinkedIn Example to API v2 (thanks to https://github.com/peternees) From f4894e2dd7222f52bf304d98ede71c752402dd21 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 28 May 2019 18:12:49 +0300 Subject: [PATCH 718/882] [maven-release-plugin] prepare release scribejava-6.6.1 --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index 9adb2c52a..60f615338 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 6.6.1-SNAPSHOT + 6.6.1 ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -34,7 +34,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - HEAD + scribejava-6.6.1 diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index b2c0e128b..6e81d8408 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.6.1-SNAPSHOT + 6.6.1 ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index c460ec225..3e009a6e8 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.6.1-SNAPSHOT + 6.6.1 ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index dde3bc9f1..8af0dc5c1 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.6.1-SNAPSHOT + 6.6.1 ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index 962a8339c..ded1494a5 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.6.1-SNAPSHOT + 6.6.1 ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index b094f19c6..63635622f 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.6.1-SNAPSHOT + 6.6.1 ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index efe512e3e..f5a779a4d 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.6.1-SNAPSHOT + 6.6.1 ../pom.xml From fe831d41846ed3db8af3a60bac7b7934422da49c Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 28 May 2019 18:12:55 +0300 Subject: [PATCH 719/882] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index 60f615338..c7e0f6573 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 6.6.1 + 6.6.2-SNAPSHOT ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -34,7 +34,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - scribejava-6.6.1 + HEAD diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 6e81d8408..e0f72e38b 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.6.1 + 6.6.2-SNAPSHOT ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 3e009a6e8..07f9b4ce0 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.6.1 + 6.6.2-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 8af0dc5c1..d1ed71ece 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.6.1 + 6.6.2-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index ded1494a5..c8bdfe85e 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.6.1 + 6.6.2-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index 63635622f..43d27b216 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.6.1 + 6.6.2-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index f5a779a4d..d511ff769 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.6.1 + 6.6.2-SNAPSHOT ../pom.xml From 86d8986113f8ab89f595f0238cdee0a509a3791e Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 28 May 2019 19:25:43 +0300 Subject: [PATCH 720/882] prepare v6.6.2 --- README.md | 4 ++-- changelog | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 764b5827e..e5031e7e8 100644 --- a/README.md +++ b/README.md @@ -129,7 +129,7 @@ You can pull ScribeJava from the central maven repository, just add these to you com.github.scribejava scribejava-apis - 6.6.1 + 6.6.2 ``` @@ -138,7 +138,7 @@ And in case you need just core classes (that's it, without any external API (FB, com.github.scribejava scribejava-core - 6.6.1 + 6.6.2 ``` diff --git a/changelog b/changelog index a5690d4f2..f8da95ca0 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,4 @@ -[6.6.1] +[6.6.2] * add PMD checks on compile * add all OAuth error codes from supported RFCs (incl. "invalid_token") (thanks to https://github.com/echorebel) * Update LinkedIn Example to API v2 (thanks to https://github.com/peternees) From 8e5ad0760c94c28e944fd034ad5a511de079c0e8 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 28 May 2019 19:27:23 +0300 Subject: [PATCH 721/882] [maven-release-plugin] prepare release scribejava-6.6.2 --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index c7e0f6573..15cecb02a 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 6.6.2-SNAPSHOT + 6.6.2 ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -34,7 +34,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - HEAD + scribejava-6.6.2 diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index e0f72e38b..b9308c7d4 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.6.2-SNAPSHOT + 6.6.2 ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 07f9b4ce0..372e52e50 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.6.2-SNAPSHOT + 6.6.2 ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index d1ed71ece..efcda092f 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.6.2-SNAPSHOT + 6.6.2 ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index c8bdfe85e..a322a0930 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.6.2-SNAPSHOT + 6.6.2 ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index 43d27b216..015df9cc6 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.6.2-SNAPSHOT + 6.6.2 ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index d511ff769..0d8719050 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.6.2-SNAPSHOT + 6.6.2 ../pom.xml From 6aaf652b79240e09103d238c1f0b23a02c89b81f Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 28 May 2019 19:27:29 +0300 Subject: [PATCH 722/882] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index 15cecb02a..f2cfc0943 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 6.6.2 + 6.6.3-SNAPSHOT ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -34,7 +34,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - scribejava-6.6.2 + HEAD diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index b9308c7d4..9d597784c 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.6.2 + 6.6.3-SNAPSHOT ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 372e52e50..1091ca710 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.6.2 + 6.6.3-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index efcda092f..5fc7c4c7b 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.6.2 + 6.6.3-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index a322a0930..3187a84b2 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.6.2 + 6.6.3-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index 015df9cc6..4b1df3e2b 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.6.2 + 6.6.3-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 0d8719050..82a8e7d64 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.6.2 + 6.6.3-SNAPSHOT ../pom.xml From 5abbcecd2c376214e5d3202133b5004144d728a4 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 29 May 2019 09:53:44 +0300 Subject: [PATCH 723/882] drop deprecated methods --- .../FacebookAccessTokenErrorResponse.java | 28 -------- .../OAuth2AccessTokenJsonExtractor.java | 46 ------------- .../model/OAuth2AccessTokenErrorResponse.java | 68 ------------------- .../scribejava/core/revoke/TokenTypeHint.java | 12 ---- .../OAuth2AccessTokenJsonExtractorTest.java | 1 - 5 files changed, 155 deletions(-) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookAccessTokenErrorResponse.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookAccessTokenErrorResponse.java index 3fca57c85..b792ad636 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookAccessTokenErrorResponse.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookAccessTokenErrorResponse.java @@ -23,25 +23,6 @@ public class FacebookAccessTokenErrorResponse extends OAuthException { private final String fbtraceId; private final String rawResponse; - /** - * @param message message - * @param type type - * @param code code - * @param fbtraceId fbtraceId - * @param rawResponse rawResponse - * @deprecated use {@link #FacebookAccessTokenErrorResponse(java.lang.String, java.lang.String, int, - * java.lang.String, java.lang.String)} - */ - @Deprecated - public FacebookAccessTokenErrorResponse(String message, String type, String code, String fbtraceId, - String rawResponse) { - super(message); - this.type = type; - this.codeInt = Integer.parseInt(code); - this.fbtraceId = fbtraceId; - this.rawResponse = rawResponse; - } - public FacebookAccessTokenErrorResponse(String message, String type, int code, String fbtraceId, String rawResponse) { super(message); @@ -55,15 +36,6 @@ public String getType() { return type; } - /** - * @return code - * @deprecated use {@link #getCodeInt() } - */ - @Deprecated - public String getCode() { - return Integer.toString(codeInt); - } - public int getCodeInt() { return codeInt; } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractor.java b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractor.java index d626ca159..b1b8c4536 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractor.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractor.java @@ -4,8 +4,6 @@ import com.fasterxml.jackson.databind.ObjectMapper; import java.io.IOException; import java.net.URI; -import java.util.regex.Matcher; -import java.util.regex.Pattern; import com.github.scribejava.core.exceptions.OAuthException; import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuth2AccessTokenErrorResponse; @@ -92,53 +90,9 @@ private OAuth2AccessToken createToken(String rawResponse) throws IOException { protected OAuth2AccessToken createToken(String accessToken, String tokenType, Integer expiresIn, String refreshToken, String scope, JsonNode response, String rawResponse) { - return createToken(accessToken, tokenType, expiresIn, refreshToken, scope, rawResponse); - } - - /** - * - * @param accessToken accessToken - * @param tokenType tokenType - * @param expiresIn expiresIn - * @param refreshToken refreshToken - * @param scope scope - * @param rawResponse rawResponse - * @return OAuth2AccessToken - * @deprecated use {@link #createToken(java.lang.String, java.lang.String, java.lang.Integer, java.lang.String, - * java.lang.String, com.fasterxml.jackson.databind.JsonNode, java.lang.String)} - */ - @Deprecated - protected OAuth2AccessToken createToken(String accessToken, String tokenType, Integer expiresIn, - String refreshToken, String scope, String rawResponse) { return new OAuth2AccessToken(accessToken, tokenType, expiresIn, refreshToken, scope, rawResponse); } - /** - * - * @param response response - * @param regexPattern regexPattern - * @param required required - * @return parameter value - * @throws OAuthException OAuthException - * @deprecated use {@link #extractRequiredParameter(com.fasterxml.jackson.databind.JsonNode, java.lang.String, - * java.lang.String)} - */ - @Deprecated - protected static String extractParameter(String response, Pattern regexPattern, boolean required) - throws OAuthException { - final Matcher matcher = regexPattern.matcher(response); - if (matcher.find()) { - return matcher.group(1); - } - - if (required) { - throw new OAuthException("Response body is incorrect. Can't extract a '" + regexPattern.pattern() - + "' from this: '" + response + "'", null); - } - - return null; - } - protected static JsonNode extractRequiredParameter(JsonNode errorNode, String parameterName, String rawResponse) throws OAuthException { final JsonNode value = errorNode.get(parameterName); diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth2AccessTokenErrorResponse.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth2AccessTokenErrorResponse.java index 8d78f15c6..f36572e0a 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth2AccessTokenErrorResponse.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth2AccessTokenErrorResponse.java @@ -12,73 +12,14 @@ public class OAuth2AccessTokenErrorResponse extends OAuthException { private static final long serialVersionUID = 2309424849700276816L; - /** - * @deprecated use {@link com.github.scribejava.core.oauth2.OAuth2Error} - */ - @Deprecated - public enum ErrorCode { - INVALID_REQUEST("invalid_request"), - INVALID_CLIENT("invalid_client"), - INVALID_GRANT("invalid_grant"), - UNAUTHORIZED_CLIENT("unauthorized_client"), - UNSUPPORTED_GRANT_TYPE("unsupported_grant_type"), - INVALID_SCOPE("invalid_scope"), - /** - * @see RFC 7009, 2.2.1. Error Response - */ - UNSUPPORTED_TOKEN_TYPE("unsupported_token_type"); - - private final String errorCodeString; - - ErrorCode(String errorCodeString) { - this.errorCodeString = errorCodeString; - } - - public static ErrorCode parseFrom(String errorCodeString) { - for (ErrorCode errorCode : ErrorCode.values()) { - if (errorCode.errorCodeString.equals(errorCodeString)) { - return errorCode; - } - } - throw new IllegalArgumentException("there is no knowlege about '" + errorCodeString + "' ErrorCode"); - } - } - - private final ErrorCode errorCode; private final OAuth2Error error; private final String errorDescription; private final URI errorUri; private final String rawResponse; - /** - * @param errorCode errorCode - * @param errorDescription errorDescription - * @param errorUri errorUri - * @param rawResponse rawResponse - * @deprecated use {@link #OAuth2AccessTokenErrorResponse(com.github.scribejava.core.oauth2.OAuth2Error, - * java.lang.String, java.net.URI, java.lang.String)} - */ - @Deprecated - public OAuth2AccessTokenErrorResponse(ErrorCode errorCode, String errorDescription, URI errorUri, - String rawResponse) { - super(rawResponse); - this.errorCode = errorCode; - this.error = OAuth2Error.parseFrom(errorCode.errorCodeString); - this.errorDescription = errorDescription; - this.errorUri = errorUri; - this.rawResponse = rawResponse; - } - public OAuth2AccessTokenErrorResponse(OAuth2Error error, String errorDescription, URI errorUri, String rawResponse) { super(rawResponse); - ErrorCode oldErrorCode; - try { - oldErrorCode = ErrorCode.parseFrom(error.getErrorString()); - } catch (IllegalArgumentException iaE) { - oldErrorCode = null; - } - this.errorCode = oldErrorCode; this.error = error; this.errorDescription = errorDescription; this.errorUri = errorUri; @@ -89,15 +30,6 @@ public OAuth2Error getError() { return error; } - /** - * @return error code - * @deprecated use {@link #getError() } - */ - @Deprecated - public ErrorCode getErrorCode() { - return errorCode; - } - public String getErrorDescription() { return errorDescription; } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/revoke/TokenTypeHint.java b/scribejava-core/src/main/java/com/github/scribejava/core/revoke/TokenTypeHint.java index c041d3efc..79de78d26 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/revoke/TokenTypeHint.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/revoke/TokenTypeHint.java @@ -20,16 +20,4 @@ public enum TokenTypeHint { public String getValue() { return value; } - - /** - * @return value - * @deprecated use {@link #getValue() } to get a lower-cased value as in reference (RFC7009), otherwise you can - * continue using this method. Note, that returned value will be UPPER-cased (not overrided toString method) in the - * next release. - */ - @Override - @Deprecated - public String toString() { - return value; - } } diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractorTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractorTest.java index 7114115be..dcc81929c 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractorTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractorTest.java @@ -70,7 +70,6 @@ public void shouldThrowExceptionIfResponseIsError() throws IOException { extractor.extract(error(body)); fail(); } catch (OAuth2AccessTokenErrorResponse oaer) { - assertEquals(OAuth2AccessTokenErrorResponse.ErrorCode.INVALID_GRANT, oaer.getErrorCode()); assertEquals(OAuth2Error.INVALID_GRANT, oaer.getError()); assertEquals("unknown, invalid, or expired refresh token", oaer.getErrorDescription()); } From dc8cfc3547884259e84a95a5d9fa8920501b3ce7 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 13 Jun 2019 12:27:47 +0300 Subject: [PATCH 724/882] fix NPE for OpenId providers --- changelog | 3 +++ pom.xml | 6 +++--- .../scribejava/apis/openid/OpenIdJsonTokenExtractor.java | 3 ++- scribejava-httpclient-ahc/pom.xml | 2 +- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/changelog b/changelog index f8da95ca0..aa15ea4ee 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,6 @@ +[SNAPSHOT] + * fix NPE for OpenId providers + [6.6.2] * add PMD checks on compile * add all OAuth error codes from supported RFCs (incl. "invalid_token") (thanks to https://github.com/echorebel) diff --git a/pom.xml b/pom.xml index f2cfc0943..7cea981bd 100644 --- a/pom.xml +++ b/pom.xml @@ -101,12 +101,12 @@ org.apache.maven.plugins maven-checkstyle-plugin - 3.0.0 + 3.1.0 com.puppycrawl.tools checkstyle - 8.20 + 8.21 @@ -273,7 +273,7 @@ 7 - 6.14.0 + 6.15.0 diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/openid/OpenIdJsonTokenExtractor.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/openid/OpenIdJsonTokenExtractor.java index 2b1be532c..1fc441a70 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/openid/OpenIdJsonTokenExtractor.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/openid/OpenIdJsonTokenExtractor.java @@ -23,7 +23,8 @@ public static OpenIdJsonTokenExtractor instance() { @Override protected OpenIdOAuth2AccessToken createToken(String accessToken, String tokenType, Integer expiresIn, String refreshToken, String scope, JsonNode response, String rawResponse) { + final JsonNode idToken = response.get("id_token"); return new OpenIdOAuth2AccessToken(accessToken, tokenType, expiresIn, refreshToken, scope, - response.get("id_token").asText(), rawResponse); + idToken == null ? null : idToken.asText(), rawResponse); } } diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 5fc7c4c7b..652c0eae1 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -23,7 +23,7 @@ org.asynchttpclient async-http-client - 2.8.1 + 2.10.0 com.github.scribejava From 0f901f5645876117b4b0d7e3ef6a05953c52ef42 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 13 Jun 2019 13:30:24 +0300 Subject: [PATCH 725/882] prepare v6.6.3 --- README.md | 4 ++-- changelog | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index e5031e7e8..a5cfc2014 100644 --- a/README.md +++ b/README.md @@ -129,7 +129,7 @@ You can pull ScribeJava from the central maven repository, just add these to you com.github.scribejava scribejava-apis - 6.6.2 + 6.6.3 ``` @@ -138,7 +138,7 @@ And in case you need just core classes (that's it, without any external API (FB, com.github.scribejava scribejava-core - 6.6.2 + 6.6.3 ``` diff --git a/changelog b/changelog index aa15ea4ee..ffcd2d9d9 100644 --- a/changelog +++ b/changelog @@ -1,6 +1,6 @@ -[SNAPSHOT] +[6.6.3] * fix NPE for OpenId providers - + [6.6.2] * add PMD checks on compile * add all OAuth error codes from supported RFCs (incl. "invalid_token") (thanks to https://github.com/echorebel) From 383aae83accb76997d746aa77c69278c74b0ee04 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 13 Jun 2019 13:31:54 +0300 Subject: [PATCH 726/882] [maven-release-plugin] prepare release scribejava-6.6.3 --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index 7cea981bd..c6e2e796d 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 6.6.3-SNAPSHOT + 6.6.3 ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -34,7 +34,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - HEAD + scribejava-6.6.3 diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 9d597784c..f95ad9815 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.6.3-SNAPSHOT + 6.6.3 ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 1091ca710..e54187d5f 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.6.3-SNAPSHOT + 6.6.3 ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 652c0eae1..afa16aaf2 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.6.3-SNAPSHOT + 6.6.3 ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index 3187a84b2..122d0e9b1 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.6.3-SNAPSHOT + 6.6.3 ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index 4b1df3e2b..9f947c8e9 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.6.3-SNAPSHOT + 6.6.3 ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 82a8e7d64..3f1b6a524 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.6.3-SNAPSHOT + 6.6.3 ../pom.xml From fce41f9f0a6ce175b8af35722c870843910ee155 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 13 Jun 2019 13:32:00 +0300 Subject: [PATCH 727/882] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index c6e2e796d..912e6bc49 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 6.6.3 + 6.6.4-SNAPSHOT ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -34,7 +34,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - scribejava-6.6.3 + HEAD diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index f95ad9815..3b4aae7d0 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.6.3 + 6.6.4-SNAPSHOT ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index e54187d5f..2f97a4b6b 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.6.3 + 6.6.4-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index afa16aaf2..586d72f06 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.6.3 + 6.6.4-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index 122d0e9b1..1b59210c0 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.6.3 + 6.6.4-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index 9f947c8e9..8f45e0314 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.6.3 + 6.6.4-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 3f1b6a524..15173147d 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.6.3 + 6.6.4-SNAPSHOT ../pom.xml From d717dca2243f8563c0b3100a8f9668d2bc180bdc Mon Sep 17 00:00:00 2001 From: Steve Martin De Souza <4013768+stevedes77@users.noreply.github.com> Date: Sun, 21 Jul 2019 14:34:43 +0900 Subject: [PATCH 728/882] Add OAuth2 API for Meetup.com --- README.md | 2 +- changelog | 3 + .../github/scribejava/apis/MeetupApi20.java | 34 ++++++++++ .../apis/examples/Meetup20Example.java | 66 +++++++++++++++++++ 4 files changed, 104 insertions(+), 1 deletion(-) create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/MeetupApi20.java create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Meetup20Example.java diff --git a/README.md b/README.md index a5cfc2014..3d4c6122e 100644 --- a/README.md +++ b/README.md @@ -79,7 +79,7 @@ ScribeJava support out-of-box several HTTP clients: * LinkedIn (https://www.linkedin.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedIn20Example.java), [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java), [example with custom scopes](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java) * Mail.Ru (https://mail.ru/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java), [example with Async Ning HTTP Client](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java) * MediaWiki (https://www.mediawiki.org/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MediaWikiExample.java) -* Meetup (http://www.meetup.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java) +* Meetup (http://www.meetup.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Meetup20Example.java), [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java) * Microsoft Azure Active Directory (Azure AD) (http://azure.microsoft.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureActiveDirectoryExample.java) * Microsoft Azure Active Directory (Azure AD) 2.0 (http://azure.microsoft.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureActiveDirectory20Example.java) * Microsoft Live (https://login.live.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java) diff --git a/changelog b/changelog index ffcd2d9d9..23d5ea51e 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,6 @@ +[SNAPSHOT] + * Add OAuth2 support for Meetup.com + [6.6.3] * fix NPE for OpenId providers diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/MeetupApi20.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/MeetupApi20.java new file mode 100644 index 000000000..ce09e931d --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/MeetupApi20.java @@ -0,0 +1,34 @@ +package com.github.scribejava.apis; + +import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.oauth2.clientauthentication.ClientAuthentication; +import com.github.scribejava.core.oauth2.clientauthentication.RequestBodyAuthenticationScheme; + +public class MeetupApi20 extends DefaultApi20 { + + protected MeetupApi20() { + } + + private static class InstanceHolder { + private static final MeetupApi20 INSTANCE = new MeetupApi20(); + } + + public static MeetupApi20 instance() { + return InstanceHolder.INSTANCE; + } + + @Override + public String getAccessTokenEndpoint() { + return "https://secure.meetup.com/oauth2/access"; + } + + @Override + protected String getAuthorizationBaseUrl() { + return "https://secure.meetup.com/oauth2/authorize"; + } + + @Override + public ClientAuthentication getClientAuthentication() { + return RequestBodyAuthenticationScheme.instance(); + } +} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Meetup20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Meetup20Example.java new file mode 100644 index 000000000..02d125d42 --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Meetup20Example.java @@ -0,0 +1,66 @@ +package com.github.scribejava.apis.examples; + +import com.github.scribejava.apis.MeetupApi20; +import com.github.scribejava.core.builder.ServiceBuilder; +import com.github.scribejava.core.model.*; +import com.github.scribejava.core.oauth.OAuth20Service; + +import java.io.IOException; +import java.util.Random; +import java.util.Scanner; +import java.util.concurrent.ExecutionException; + +public class Meetup20Example { + + private static final String NETWORK_NAME = "Meetup"; + private static final String PROTECTED_RESOURCE_URL = " https://api.meetup.com/self/groups"; + + private Meetup20Example() { + } + + @SuppressWarnings("PMD.SystemPrintln") + public static void main(String... args) throws IOException, InterruptedException, ExecutionException { + // Replace these with your Meetup consumer id and secret + final String consumerKey = "your consumer key"; + final String consumerSecret = "your consumer secret"; + final OAuth20Service service = new ServiceBuilder(consumerKey) + .apiSecret(consumerSecret) + .defaultScope("basic") // replace with desired scopes + .callback("http://example.com/callback") // replace with appropriate URI for your consumer, + // see https://www.meetup.com/meetup_api/auth/#redirect_uris + .build(MeetupApi20.instance()); + final Scanner in = new Scanner(System.in); + + System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); + System.out.println(); + + // Obtain the Authorization URL + System.out.println("Fetching the Authorization URL..."); + final String secretState = "secret" + new Random().nextInt(999_999); + final String authorizationUrl = service.getAuthorizationUrl(secretState); + System.out.println("Got the Authorization URL!"); + System.out.println("Now go and authorize ScribeJava here:"); + System.out.println(authorizationUrl); + System.out.println("And paste the authorization code here"); + System.out.print(">>"); + final String code = in.nextLine(); + System.out.println(); + + System.out.println("Trading the Authorization Code for an Access Token..."); + final OAuth2AccessToken accessToken = service.getAccessToken(code); + System.out.println("Got the Access Token!"); + System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); + System.out.println(); + + System.out.println("Now we're going to the user's groups...."); + + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); + service.signRequest(accessToken, request); + final Response response = service.execute(request); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + + System.out.println(); + } +} From 5d9939034fe7bce54ba6d40f5e8e6d5d98b0fe39 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 22 Jul 2019 15:33:30 +0300 Subject: [PATCH 729/882] Add OAuth2 support for Meetup.com (thanks to https://github.com/stevedes77) --- README.md | 2 +- changelog | 2 +- .../com/github/scribejava/apis/examples/Meetup20Example.java | 5 ++++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 3d4c6122e..067d0ba87 100644 --- a/README.md +++ b/README.md @@ -79,7 +79,7 @@ ScribeJava support out-of-box several HTTP clients: * LinkedIn (https://www.linkedin.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedIn20Example.java), [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java), [example with custom scopes](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java) * Mail.Ru (https://mail.ru/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java), [example with Async Ning HTTP Client](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java) * MediaWiki (https://www.mediawiki.org/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MediaWikiExample.java) -* Meetup (http://www.meetup.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Meetup20Example.java), [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java) +* Meetup (https://www.meetup.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Meetup20Example.java), [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java) * Microsoft Azure Active Directory (Azure AD) (http://azure.microsoft.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureActiveDirectoryExample.java) * Microsoft Azure Active Directory (Azure AD) 2.0 (http://azure.microsoft.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureActiveDirectory20Example.java) * Microsoft Live (https://login.live.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java) diff --git a/changelog b/changelog index 23d5ea51e..2097f8374 100644 --- a/changelog +++ b/changelog @@ -1,5 +1,5 @@ [SNAPSHOT] - * Add OAuth2 support for Meetup.com + * Add OAuth2 support for Meetup.com (thanks to https://github.com/stevedes77) [6.6.3] * fix NPE for OpenId providers diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Meetup20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Meetup20Example.java index 02d125d42..1c83722a0 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Meetup20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Meetup20Example.java @@ -2,7 +2,10 @@ import com.github.scribejava.apis.MeetupApi20; import com.github.scribejava.core.builder.ServiceBuilder; -import com.github.scribejava.core.model.*; +import com.github.scribejava.core.model.OAuth2AccessToken; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.oauth.OAuth20Service; import java.io.IOException; From c2023397cf81452d755a5401fe95b1d47dbde48a Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 22 Jul 2019 16:58:40 +0300 Subject: [PATCH 730/882] upgrade okhttp to 4.0.1 and security fix for jackson-databind 2.9.9.1 --- changelog | 1 + pom.xml | 10 +++++----- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- .../scribejava/httpclient/okhttp/OkHttpHttpClient.java | 6 +++--- .../okhttp/OAuthAsyncCompletionHandlerTest.java | 6 +++--- 7 files changed, 15 insertions(+), 14 deletions(-) diff --git a/changelog b/changelog index 2097f8374..10af8fe8c 100644 --- a/changelog +++ b/changelog @@ -1,5 +1,6 @@ [SNAPSHOT] * Add OAuth2 support for Meetup.com (thanks to https://github.com/stevedes77) + * upgrade okhttp to 4.0.1 and security fix for jackson-databind 2.9.9.1 [6.6.3] * fix NPE for OpenId providers diff --git a/pom.xml b/pom.xml index 912e6bc49..1c54a74d2 100644 --- a/pom.xml +++ b/pom.xml @@ -56,7 +56,7 @@ com.fasterxml.jackson.core jackson-databind - 2.9.9 + 2.9.9.1 junit @@ -67,7 +67,7 @@ com.squareup.okhttp3 mockwebserver - 3.14.2 + 4.0.1 test @@ -106,7 +106,7 @@ com.puppycrawl.tools checkstyle - 8.21 + 8.22 @@ -187,7 +187,7 @@ org.apache.maven.plugins maven-javadoc-plugin - 3.1.0 + 3.1.1 ${java.home}/bin/javadoc UTF-8 @@ -273,7 +273,7 @@ 7 - 6.15.0 + 6.16.0 diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 586d72f06..7913ad0ff 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -23,7 +23,7 @@ org.asynchttpclient async-http-client - 2.10.0 + 2.10.1 com.github.scribejava diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index 1b59210c0..d8cf139bf 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -23,7 +23,7 @@ org.apache.httpcomponents httpclient - 4.5.8 + 4.5.9 org.apache.httpcomponents diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 15173147d..22f16acec 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -23,7 +23,7 @@ com.squareup.okhttp3 okhttp - 3.14.2 + 4.0.1 com.github.scribejava diff --git a/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java b/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java index 4f3e7e434..67df4b089 100644 --- a/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java +++ b/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java @@ -165,19 +165,19 @@ private enum BodyType { BYTE_ARRAY { @Override RequestBody createBody(MediaType mediaType, Object bodyContents) { - return RequestBody.create(mediaType, (byte[]) bodyContents); + return RequestBody.create((byte[]) bodyContents, mediaType); } }, STRING { @Override RequestBody createBody(MediaType mediaType, Object bodyContents) { - return RequestBody.create(mediaType, (String) bodyContents); + return RequestBody.create((String) bodyContents, mediaType); } }, FILE { @Override RequestBody createBody(MediaType mediaType, Object bodyContents) { - return RequestBody.create(mediaType, (File) bodyContents); + return RequestBody.create((File) bodyContents, mediaType); } }; diff --git a/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/OAuthAsyncCompletionHandlerTest.java b/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/OAuthAsyncCompletionHandlerTest.java index 645c45557..93d3c01f1 100644 --- a/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/OAuthAsyncCompletionHandlerTest.java +++ b/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/OAuthAsyncCompletionHandlerTest.java @@ -78,7 +78,7 @@ public void shouldReleaseLatchOnSuccess() throws Exception { .protocol(Protocol.HTTP_1_1) .code(200) .message("ok") - .body(ResponseBody.create(MediaType.get("text/plain"), new byte[0])) + .body(ResponseBody.create(new byte[0], MediaType.get("text/plain"))) .build(); handler.onResponse(call, response); assertNotNull(callback.getResponse()); @@ -98,7 +98,7 @@ public void shouldReleaseLatchOnIOException() throws Exception { .protocol(Protocol.HTTP_1_1) .code(200) .message("ok") - .body(ResponseBody.create(MediaType.get("text/plain"), new byte[0])) + .body(ResponseBody.create(new byte[0], MediaType.get("text/plain"))) .build(); handler.onResponse(call, response); assertNull(callback.getResponse()); @@ -124,7 +124,7 @@ public void shouldReportOAuthException() throws Exception { .protocol(Protocol.HTTP_1_1) .code(200) .message("ok") - .body(ResponseBody.create(MediaType.get("text/plain"), new byte[0])) + .body(ResponseBody.create(new byte[0], MediaType.get("text/plain"))) .build(); handler.onResponse(call, response); assertNull(callback.getResponse()); From ee344bb146dc45df831da27ef93dc35ad62a7a58 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 22 Jul 2019 17:09:16 +0300 Subject: [PATCH 731/882] prepare v6.7.0 --- README.md | 4 ++-- changelog | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 067d0ba87..b1ef40366 100644 --- a/README.md +++ b/README.md @@ -129,7 +129,7 @@ You can pull ScribeJava from the central maven repository, just add these to you com.github.scribejava scribejava-apis - 6.6.3 + 6.7.0 ``` @@ -138,7 +138,7 @@ And in case you need just core classes (that's it, without any external API (FB, com.github.scribejava scribejava-core - 6.6.3 + 6.7.0 ``` diff --git a/changelog b/changelog index 10af8fe8c..17adb113e 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,4 @@ -[SNAPSHOT] +[6.7.0] * Add OAuth2 support for Meetup.com (thanks to https://github.com/stevedes77) * upgrade okhttp to 4.0.1 and security fix for jackson-databind 2.9.9.1 From 17df0f844077dbb0e3c88b2f6b2b1a50bf67646a Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 22 Jul 2019 17:10:51 +0300 Subject: [PATCH 732/882] [maven-release-plugin] prepare release scribejava-6.7.0 --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index 1c54a74d2..a5c60ce49 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 6.6.4-SNAPSHOT + 6.7.0 ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -34,7 +34,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - HEAD + scribejava-6.7.0 diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 3b4aae7d0..ed433de6a 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.6.4-SNAPSHOT + 6.7.0 ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 2f97a4b6b..778ccecc0 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.6.4-SNAPSHOT + 6.7.0 ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 7913ad0ff..ada37d03d 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.6.4-SNAPSHOT + 6.7.0 ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index d8cf139bf..d6a37e376 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.6.4-SNAPSHOT + 6.7.0 ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index 8f45e0314..85c71889d 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.6.4-SNAPSHOT + 6.7.0 ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 22f16acec..0b9e9510c 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.6.4-SNAPSHOT + 6.7.0 ../pom.xml From 387f95819adfe407e46cdb428be67f16112f4b28 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 22 Jul 2019 17:11:03 +0300 Subject: [PATCH 733/882] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index a5c60ce49..2e3434293 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 6.7.0 + 6.7.1-SNAPSHOT ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -34,7 +34,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - scribejava-6.7.0 + HEAD diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index ed433de6a..2fe76f005 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.7.0 + 6.7.1-SNAPSHOT ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 778ccecc0..3b8cfb6d0 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.7.0 + 6.7.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index ada37d03d..3eb2f9511 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.7.0 + 6.7.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index d6a37e376..38e123910 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.7.0 + 6.7.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index 85c71889d..b99eb1bca 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.7.0 + 6.7.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 0b9e9510c..838b87ac5 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.7.0 + 6.7.1-SNAPSHOT ../pom.xml From 6e85a3bc7335e5732c009429747c49561314b153 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 30 Jul 2019 15:14:08 +0300 Subject: [PATCH 734/882] always set Content-Length header in case of method defines a meaning for an enclosed payload body. --- .../core/httpclient/jdk/JDKHttpClient.java | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java index ee459cf51..9a9dbef4b 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java @@ -192,7 +192,10 @@ private static void addHeaders(HttpURLConnection connection, Map private static void addBody(HttpURLConnection connection, byte[] content, boolean requiresBody) throws IOException { final int contentLength = content.length; if (requiresBody || contentLength > 0) { - prepareConnectionForBodyAndGetOutputStream(connection, contentLength).write(content); + final OutputStream outputStream = prepareConnectionForBodyAndGetOutputStream(connection, contentLength); + if (contentLength > 0) { + outputStream.write(content); + } } } @@ -205,9 +208,10 @@ private static void addBody(HttpURLConnection connection, MultipartPayload multi if (requiresBody) { final ByteArrayOutputStream os = getPayload(multipartPayload); - - if (os.size() > 0) { - os.writeTo(prepareConnectionForBodyAndGetOutputStream(connection, os.size())); + final int contentLength = os.size(); + final OutputStream outputStream = prepareConnectionForBodyAndGetOutputStream(connection, contentLength); + if (contentLength > 0) { + os.writeTo(outputStream); } } } @@ -261,8 +265,11 @@ private static OutputStream prepareConnectionForBodyAndGetOutputStream(HttpURLCo if (connection.getRequestProperty(CONTENT_TYPE) == null) { connection.setRequestProperty(CONTENT_TYPE, DEFAULT_CONTENT_TYPE); } - connection.setDoOutput(true); - return connection.getOutputStream(); + if (contentLength > 0) { + connection.setDoOutput(true); + return connection.getOutputStream(); + } else { + return null; + } } - } From f6c5fc49146e9624aa9e57e0714991482a7fea74 Mon Sep 17 00:00:00 2001 From: Robert Barbey Date: Thu, 1 Aug 2019 00:04:28 +0200 Subject: [PATCH 735/882] Pulled up `debugStream` into `OAuthService` - this way both `OAuth10aService` and `OAuth20Service` can use it - adjusted constructors for various `*Api` and corresponding `*Service` implementations --- .../github/scribejava/apis/FacebookApi.java | 9 ++++++--- .../com/github/scribejava/apis/ImgurApi.java | 9 ++++++--- .../com/github/scribejava/apis/MailruApi.java | 9 ++++++--- .../scribejava/apis/OdnoklassnikiApi.java | 10 ++++++---- .../github/scribejava/apis/WunderlistAPI.java | 9 ++++++--- .../apis/facebook/FacebookService.java | 8 ++++++-- .../apis/imgur/ImgurOAuthService.java | 8 ++++++-- .../apis/mailru/MailruOAuthService.java | 8 ++++++-- .../OdnoklassnikiOAuthService.java | 9 ++++++--- .../wunderlist/WunderlistOAuthService.java | 9 ++++++--- .../core/builder/ServiceBuilder.java | 8 ++++---- .../core/builder/api/DefaultApi20.java | 7 +++++-- .../scribejava/core/oauth/OAuth10aService.java | 15 +-------------- .../scribejava/core/oauth/OAuth20Service.java | 6 ++++-- .../scribejava/core/oauth/OAuthService.java | 18 ++++++++++++++++-- .../scribejava/core/AbstractClientTest.java | 3 ++- .../scribejava/core/oauth/OAuth20ApiUnit.java | 9 ++++++--- .../core/oauth/OAuth20ServiceUnit.java | 7 +++++-- 18 files changed, 103 insertions(+), 58 deletions(-) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java index a7d81e8b1..9c3ee7a46 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java @@ -1,5 +1,7 @@ package com.github.scribejava.apis; +import java.io.OutputStream; + import com.github.scribejava.apis.facebook.FacebookAccessTokenJsonExtractor; import com.github.scribejava.apis.facebook.FacebookService; import com.github.scribejava.core.builder.api.DefaultApi20; @@ -71,8 +73,9 @@ public ClientAuthentication getClientAuthentication() { @Override public FacebookService createService(String apiKey, String apiSecret, String callback, String defaultScope, - String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - return new FacebookService(this, apiKey, apiSecret, callback, defaultScope, responseType, userAgent, - httpClientConfig, httpClient); + String responseType, OutputStream debugStream, String userAgent, HttpClientConfig httpClientConfig, + HttpClient httpClient) { + return new FacebookService(this, apiKey, apiSecret, callback, defaultScope, responseType, debugStream, + userAgent, httpClientConfig, httpClient); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java index 0a7aced8f..6c45b1d79 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java @@ -6,6 +6,8 @@ import com.github.scribejava.core.httpclient.HttpClientConfig; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.ParameterList; + +import java.io.OutputStream; import java.util.Map; public class ImgurApi extends DefaultApi20 { @@ -55,9 +57,10 @@ protected String getAuthorizationBaseUrl() { @Override public ImgurOAuthService createService(String apiKey, String apiSecret, String callback, String defaultScope, - String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - return new ImgurOAuthService(this, apiKey, apiSecret, callback, defaultScope, responseType, userAgent, - httpClientConfig, httpClient); + String responseType, OutputStream debugStream, String userAgent, HttpClientConfig httpClientConfig, + HttpClient httpClient) { + return new ImgurOAuthService(this, apiKey, apiSecret, callback, defaultScope, responseType, debugStream, + userAgent, httpClientConfig, httpClient); } public static boolean isOob(String callback) { diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java index c10dd0bab..dc1519f50 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java @@ -1,5 +1,7 @@ package com.github.scribejava.apis; +import java.io.OutputStream; + import com.github.scribejava.apis.mailru.MailruOAuthService; import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.httpclient.HttpClient; @@ -30,8 +32,9 @@ protected String getAuthorizationBaseUrl() { @Override public MailruOAuthService createService(String apiKey, String apiSecret, String callback, String defaultScope, - String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - return new MailruOAuthService(this, apiKey, apiSecret, callback, defaultScope, responseType, userAgent, - httpClientConfig, httpClient); + String responseType, OutputStream debugStream, String userAgent, HttpClientConfig httpClientConfig, + HttpClient httpClient) { + return new MailruOAuthService(this, apiKey, apiSecret, callback, defaultScope, responseType, debugStream, + userAgent, httpClientConfig, httpClient); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java index d1cdcedb0..d6bfe7690 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java @@ -1,5 +1,7 @@ package com.github.scribejava.apis; +import java.io.OutputStream; + import com.github.scribejava.apis.odnoklassniki.OdnoklassnikiOAuthService; import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.httpclient.HttpClient; @@ -34,10 +36,10 @@ protected String getAuthorizationBaseUrl() { @Override public OdnoklassnikiOAuthService createService(String apiKey, String apiSecret, String callback, - String defaultScope, String responseType, String userAgent, HttpClientConfig httpClientConfig, - HttpClient httpClient) { - return new OdnoklassnikiOAuthService(this, apiKey, apiSecret, callback, defaultScope, responseType, userAgent, - httpClientConfig, httpClient); + String defaultScope, String responseType, OutputStream debugStream, String userAgent, + HttpClientConfig httpClientConfig, HttpClient httpClient) { + return new OdnoklassnikiOAuthService(this, apiKey, apiSecret, callback, defaultScope, responseType, debugStream, + userAgent, httpClientConfig, httpClient); } @Override diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/WunderlistAPI.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/WunderlistAPI.java index 89f070fa4..7283c3ecf 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/WunderlistAPI.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/WunderlistAPI.java @@ -1,5 +1,7 @@ package com.github.scribejava.apis; +import java.io.OutputStream; + import com.github.scribejava.apis.wunderlist.WunderlistOAuthService; import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.httpclient.HttpClient; @@ -49,8 +51,9 @@ public ClientAuthentication getClientAuthentication() { @Override public OAuth20Service createService(String apiKey, String apiSecret, String callback, String defaultScope, - String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - return new WunderlistOAuthService(this, apiKey, apiSecret, callback, defaultScope, responseType, userAgent, - httpClientConfig, httpClient); + String responseType, OutputStream debugStream, String userAgent, HttpClientConfig httpClientConfig, + HttpClient httpClient) { + return new WunderlistOAuthService(this, apiKey, apiSecret, callback, defaultScope, responseType, debugStream, + userAgent, httpClientConfig, httpClient); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookService.java index 728d9349a..f1f79ad88 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookService.java @@ -5,6 +5,8 @@ import com.github.scribejava.core.httpclient.HttpClientConfig; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.oauth.OAuth20Service; + +import java.io.OutputStream; import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; import java.util.Formatter; @@ -14,8 +16,10 @@ public class FacebookService extends OAuth20Service { public FacebookService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String defaultScope, - String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - super(api, apiKey, apiSecret, callback, defaultScope, responseType, userAgent, httpClientConfig, httpClient); + String responseType, OutputStream debugStream, String userAgent, HttpClientConfig httpClientConfig, + HttpClient httpClient) { + super(api, apiKey, apiSecret, callback, defaultScope, responseType, debugStream, userAgent, httpClientConfig, + httpClient); } @Override diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/imgur/ImgurOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/imgur/ImgurOAuthService.java index a37d71cbf..589354891 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/imgur/ImgurOAuthService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/imgur/ImgurOAuthService.java @@ -1,5 +1,7 @@ package com.github.scribejava.apis.imgur; +import java.io.OutputStream; + import com.github.scribejava.apis.ImgurApi; import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.httpclient.HttpClient; @@ -13,8 +15,10 @@ public class ImgurOAuthService extends OAuth20Service { public ImgurOAuthService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String defaultScope, - String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - super(api, apiKey, apiSecret, callback, defaultScope, responseType, userAgent, httpClientConfig, httpClient); + String responseType, OutputStream debugStream, String userAgent, HttpClientConfig httpClientConfig, + HttpClient httpClient) { + super(api, apiKey, apiSecret, callback, defaultScope, responseType, debugStream, userAgent, httpClientConfig, + httpClient); } @Override diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/mailru/MailruOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/mailru/MailruOAuthService.java index b3f8c4770..ab8294139 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/mailru/MailruOAuthService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/mailru/MailruOAuthService.java @@ -8,6 +8,8 @@ import com.github.scribejava.core.httpclient.HttpClientConfig; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.oauth.OAuth20Service; + +import java.io.OutputStream; import java.io.UnsupportedEncodingException; import java.nio.charset.Charset; import java.security.MessageDigest; @@ -17,8 +19,10 @@ public class MailruOAuthService extends OAuth20Service { public MailruOAuthService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String defaultScope, - String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - super(api, apiKey, apiSecret, callback, defaultScope, responseType, userAgent, httpClientConfig, httpClient); + String responseType, OutputStream debugStream, String userAgent, HttpClientConfig httpClientConfig, + HttpClient httpClient) { + super(api, apiKey, apiSecret, callback, defaultScope, responseType, debugStream, userAgent, httpClientConfig, + httpClient); } @Override diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/odnoklassniki/OdnoklassnikiOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/odnoklassniki/OdnoklassnikiOAuthService.java index c168aafcc..a06b3f0c2 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/odnoklassniki/OdnoklassnikiOAuthService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/odnoklassniki/OdnoklassnikiOAuthService.java @@ -7,6 +7,8 @@ import com.github.scribejava.core.model.Parameter; import com.github.scribejava.core.model.ParameterList; import com.github.scribejava.core.oauth.OAuth20Service; + +import java.io.OutputStream; import java.io.UnsupportedEncodingException; import java.net.URLDecoder; @@ -20,9 +22,10 @@ public class OdnoklassnikiOAuthService extends OAuth20Service { public OdnoklassnikiOAuthService(DefaultApi20 api, String apiKey, String apiSecret, String callback, - String defaultScope, String responseType, String userAgent, HttpClientConfig httpClientConfig, - HttpClient httpClient) { - super(api, apiKey, apiSecret, callback, defaultScope, responseType, userAgent, httpClientConfig, httpClient); + String defaultScope, String responseType, OutputStream debugStream, String userAgent, + HttpClientConfig httpClientConfig, HttpClient httpClient) { + super(api, apiKey, apiSecret, callback, defaultScope, responseType, debugStream, userAgent, httpClientConfig, + httpClient); } @Override diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/wunderlist/WunderlistOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/wunderlist/WunderlistOAuthService.java index 94e72b044..06a248d9c 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/wunderlist/WunderlistOAuthService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/wunderlist/WunderlistOAuthService.java @@ -1,5 +1,7 @@ package com.github.scribejava.apis.wunderlist; +import java.io.OutputStream; + import com.github.scribejava.apis.WunderlistAPI; import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.httpclient.HttpClientConfig; @@ -9,9 +11,10 @@ public class WunderlistOAuthService extends OAuth20Service { public WunderlistOAuthService(WunderlistAPI api, String apiKey, String apiSecret, String callback, - String defaultScope, String responseType, String userAgent, HttpClientConfig httpClientConfig, - HttpClient httpClient) { - super(api, apiKey, apiSecret, callback, defaultScope, responseType, userAgent, httpClientConfig, httpClient); + String defaultScope, String responseType, OutputStream debugStream, String userAgent, + HttpClientConfig httpClientConfig, HttpClient httpClient) { + super(api, apiKey, apiSecret, callback, defaultScope, responseType, debugStream, userAgent, httpClientConfig, + httpClient); } @Override diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilder.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilder.java index bbc68b571..c35e0429d 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilder.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilder.java @@ -68,7 +68,7 @@ public ServiceBuilderOAuth10a withScope(String scope) { } @Override - public ServiceBuilderOAuth10a debugStream(OutputStream debugStream) { + public ServiceBuilder debugStream(OutputStream debugStream) { Preconditions.checkNotNull(debugStream, "debug stream can't be null"); this.debugStream = debugStream; return this; @@ -101,7 +101,7 @@ public ServiceBuilder userAgent(String userAgent) { } @Override - public ServiceBuilderOAuth10a debug() { + public ServiceBuilder debug() { return debugStream(System.out); } @@ -113,7 +113,7 @@ public OAuth10aService build(DefaultApi10a api) { @Override public OAuth20Service build(DefaultApi20 api) { - return api.createService(apiKey, apiSecret, callback, scope, responseType, userAgent, httpClientConfig, - httpClient); + return api.createService(apiKey, apiSecret, callback, scope, responseType, debugStream, userAgent, + httpClientConfig, httpClient); } } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java index 92ad8fab7..64ad82f00 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java @@ -13,6 +13,8 @@ import com.github.scribejava.core.oauth2.bearersignature.BearerSignatureAuthorizationRequestHeaderField; import com.github.scribejava.core.oauth2.clientauthentication.ClientAuthentication; import com.github.scribejava.core.oauth2.clientauthentication.HttpBasicAuthenticationScheme; + +import java.io.OutputStream; import java.util.Map; /** @@ -106,8 +108,9 @@ public String getAuthorizationUrl(String responseType, String apiKey, String cal } public OAuth20Service createService(String apiKey, String apiSecret, String callback, String defaultScope, - String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - return new OAuth20Service(this, apiKey, apiSecret, callback, defaultScope, responseType, userAgent, + String responseType, OutputStream debugStream, String userAgent, HttpClientConfig httpClientConfig, + HttpClient httpClient) { + return new OAuth20Service(this, apiKey, apiSecret, callback, defaultScope, responseType, debugStream, userAgent, httpClientConfig, httpClient); } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java index 3e67bf1ad..401cba8c9 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java @@ -22,14 +22,12 @@ public class OAuth10aService extends OAuthService { private static final String VERSION = "1.0"; - private final OutputStream debugStream; private final DefaultApi10a api; private final String scope; public OAuth10aService(DefaultApi10a api, String apiKey, String apiSecret, String callback, String scope, OutputStream debugStream, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - super(apiKey, apiSecret, callback, userAgent, httpClientConfig, httpClient); - this.debugStream = debugStream; + super(apiKey, apiSecret, callback, debugStream, userAgent, httpClientConfig, httpClient); this.api = api; this.scope = scope; } @@ -192,15 +190,4 @@ protected void appendSignature(OAuthRequest request) { public DefaultApi10a getApi() { return api; } - - public void log(String messagePattern, Object... params) { - if (debugStream != null) { - final String message = String.format(messagePattern, params) + '\n'; - try { - debugStream.write(message.getBytes("UTF8")); - } catch (IOException | RuntimeException e) { - throw new RuntimeException("there were problems while writting to the debug stream", e); - } - } - } } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java index c80a6496d..ada132d43 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java @@ -1,6 +1,7 @@ package com.github.scribejava.core.oauth; import java.io.IOException; +import java.io.OutputStream; import java.util.concurrent.Future; import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; @@ -28,8 +29,9 @@ public class OAuth20Service extends OAuthService { private final String defaultScope; public OAuth20Service(DefaultApi20 api, String apiKey, String apiSecret, String callback, String defaultScope, - String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - super(apiKey, apiSecret, callback, userAgent, httpClientConfig, httpClient); + String responseType, OutputStream debugStream, String userAgent, HttpClientConfig httpClientConfig, + HttpClient httpClient) { + super(apiKey, apiSecret, callback, debugStream, userAgent, httpClientConfig, httpClient); this.responseType = responseType; this.api = api; this.defaultScope = defaultScope; diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java index 4d514381d..cb8680b1f 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java @@ -12,6 +12,7 @@ import java.io.File; import java.io.IOException; +import java.io.OutputStream; import java.util.ServiceLoader; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; @@ -23,12 +24,14 @@ public abstract class OAuthService implements Closeable { private final String callback; private final String userAgent; private final HttpClient httpClient; + private final OutputStream debugStream; - public OAuthService(String apiKey, String apiSecret, String callback, String userAgent, - HttpClientConfig httpClientConfig, HttpClient httpClient) { + public OAuthService(String apiKey, String apiSecret, String callback, OutputStream debugStream, + String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { this.apiKey = apiKey; this.apiSecret = apiSecret; this.callback = callback; + this.debugStream = debugStream; this.userAgent = userAgent; if (httpClientConfig == null && httpClient == null) { @@ -112,4 +115,15 @@ public Response execute(OAuthRequest request) throws InterruptedException, Execu request.getByteArrayPayload()); } } + + public void log(String messagePattern, Object... params) { + if (debugStream != null) { + final String message = String.format(messagePattern, params) + '\n'; + try { + debugStream.write(message.getBytes("UTF8")); + } catch (IOException | RuntimeException e) { + throw new RuntimeException("there were problems while writting to the debug stream", e); + } + } + } } diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/AbstractClientTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/AbstractClientTest.java index ac4705974..dd94008f6 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/AbstractClientTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/AbstractClientTest.java @@ -44,7 +44,8 @@ public Response getResponse() { @Before public void setUp() { - oAuthService = new OAuth20Service(null, "test", "test", null, null, null, null, null, createNewClient()); + oAuthService = new OAuth20Service(null, "test", "test", null, null, null, System.out, null, null, + createNewClient()); } @After diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ApiUnit.java b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ApiUnit.java index 9b8df0977..cd9e58550 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ApiUnit.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ApiUnit.java @@ -1,5 +1,7 @@ package com.github.scribejava.core.oauth; +import java.io.OutputStream; + import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.httpclient.HttpClientConfig; @@ -20,9 +22,10 @@ protected String getAuthorizationBaseUrl() { @Override public OAuth20ServiceUnit createService(String apiKey, String apiSecret, String callback, String defaultScope, - String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - return new OAuth20ServiceUnit(this, apiKey, apiSecret, callback, defaultScope, responseType, userAgent, - httpClientConfig, httpClient); + String responseType, OutputStream debugStream, String userAgent, HttpClientConfig httpClientConfig, + HttpClient httpClient) { + return new OAuth20ServiceUnit(this, apiKey, apiSecret, callback, defaultScope, responseType, debugStream, + userAgent, httpClientConfig, httpClient); } @Override diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceUnit.java b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceUnit.java index 46cf9ee28..2766b7f2b 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceUnit.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceUnit.java @@ -11,6 +11,7 @@ import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Parameter; +import java.io.OutputStream; import java.util.HashMap; import java.util.Map; import java.util.concurrent.Future; @@ -23,8 +24,10 @@ class OAuth20ServiceUnit extends OAuth20Service { private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); OAuth20ServiceUnit(DefaultApi20 api, String apiKey, String apiSecret, String callback, String defaultScope, - String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - super(api, apiKey, apiSecret, callback, defaultScope, responseType, userAgent, httpClientConfig, httpClient); + String responseType, OutputStream debugStream, String userAgent, HttpClientConfig httpClientConfig, + HttpClient httpClient) { + super(api, apiKey, apiSecret, callback, defaultScope, responseType, debugStream, userAgent, httpClientConfig, + httpClient); } @Override From f9efe2b05f24e456048f310f927cd2eba20916d8 Mon Sep 17 00:00:00 2001 From: Robert Barbey Date: Thu, 1 Aug 2019 09:53:18 +0200 Subject: [PATCH 736/882] Added log messages for creating requests --- .../scribejava/core/oauth/OAuth20Service.java | 34 ++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java index ada132d43..57e7143c2 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java @@ -40,7 +40,15 @@ public OAuth20Service(DefaultApi20 api, String apiKey, String apiSecret, String //protected to facilitate mocking protected OAuth2AccessToken sendAccessTokenRequestSync(OAuthRequest request) throws IOException, InterruptedException, ExecutionException { - return api.getAccessTokenExtractor().extract(execute(request)); + log("send request for access token synchronously to %s", request.getCompleteUrl()); + + final Response response = execute(request); + final String body = response.getBody(); + + log("response status code: %s", response.getCode()); + log("response body: %s", body); + + return api.getAccessTokenExtractor().extract(response); } //protected to facilitate mocking @@ -51,10 +59,16 @@ protected Future sendAccessTokenRequestAsync(OAuthRequest req //protected to facilitate mocking protected Future sendAccessTokenRequestAsync(OAuthRequest request, OAuthAsyncRequestCallback callback) { + log("send request for access token asynchronously to %s", request.getCompleteUrl()); return execute(request, callback, new OAuthRequest.ResponseConverter() { @Override public OAuth2AccessToken convert(Response response) throws IOException { + log("received response for access token"); + final String body = response.getBody(); + + log("response status code: %s", response.getCode()); + log("response body: %s", body); return getApi().getAccessTokenExtractor().extract(response); } }); @@ -117,6 +131,9 @@ protected OAuthRequest createAccessTokenRequest(AccessTokenRequestParams params) if (pkceCodeVerifier != null) { request.addParameter(PKCE.PKCE_CODE_VERIFIER_PARAM, pkceCodeVerifier); } + + log("created access token request with body params [%s], query string params [%s]", request.getBodyParams(), + request.getQueryStringParams()); return request; } @@ -172,6 +189,10 @@ protected OAuthRequest createRefreshTokenRequest(String refreshToken, String sco request.addParameter(OAuthConstants.REFRESH_TOKEN, refreshToken); request.addParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.REFRESH_TOKEN); + + log("created refresh token request with body params [%s], query string params [%s]", request.getBodyParams(), + request.getQueryStringParams()); + return request; } @@ -235,6 +256,9 @@ protected OAuthRequest createAccessTokenPasswordGrantRequest(String username, St api.getClientAuthentication().addClientAuthentication(request, getApiKey(), getApiSecret()); + log("created access token password grant request with body params [%s], query string params [%s]", + request.getBodyParams(), request.getQueryStringParams()); + return request; } @@ -292,6 +316,10 @@ protected OAuthRequest createAccessTokenClientCredentialsGrantRequest(String sco request.addParameter(OAuthConstants.SCOPE, defaultScope); } request.addParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.CLIENT_CREDENTIALS); + + log("created access token client credentials grant request with body params [%s], query string params [%s]", + request.getBodyParams(), request.getQueryStringParams()); + return request; } @@ -361,6 +389,10 @@ protected OAuthRequest createRevokeTokenRequest(String tokenToRevoke, TokenTypeH if (tokenTypeHint != null) { request.addParameter("token_type_hint", tokenTypeHint.getValue()); } + + log("created revoke token request with body params [%s], query string params [%s]", request.getBodyParams(), + request.getQueryStringParams()); + return request; } From f04ffc7d8322377e976f21c7d1f7b41bae4d821f Mon Sep 17 00:00:00 2001 From: Robert Barbey Date: Thu, 1 Aug 2019 10:38:37 +0200 Subject: [PATCH 737/882] Print params as URL-encoded string --- .../scribejava/core/oauth/OAuth20Service.java | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java index 57e7143c2..15cdbf19e 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java @@ -132,8 +132,9 @@ protected OAuthRequest createAccessTokenRequest(AccessTokenRequestParams params) request.addParameter(PKCE.PKCE_CODE_VERIFIER_PARAM, pkceCodeVerifier); } - log("created access token request with body params [%s], query string params [%s]", request.getBodyParams(), - request.getQueryStringParams()); + log("created access token request with body params [%s], query string params [%s]", + request.getBodyParams().asFormUrlEncodedString(), + request.getQueryStringParams().asFormUrlEncodedString()); return request; } @@ -190,8 +191,9 @@ protected OAuthRequest createRefreshTokenRequest(String refreshToken, String sco request.addParameter(OAuthConstants.REFRESH_TOKEN, refreshToken); request.addParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.REFRESH_TOKEN); - log("created refresh token request with body params [%s], query string params [%s]", request.getBodyParams(), - request.getQueryStringParams()); + log("created refresh token request with body params [%s], query string params [%s]", + request.getBodyParams().asFormUrlEncodedString(), + request.getQueryStringParams().asFormUrlEncodedString()); return request; } @@ -257,7 +259,8 @@ protected OAuthRequest createAccessTokenPasswordGrantRequest(String username, St api.getClientAuthentication().addClientAuthentication(request, getApiKey(), getApiSecret()); log("created access token password grant request with body params [%s], query string params [%s]", - request.getBodyParams(), request.getQueryStringParams()); + request.getBodyParams().asFormUrlEncodedString(), + request.getQueryStringParams().asFormUrlEncodedString()); return request; } @@ -318,7 +321,8 @@ protected OAuthRequest createAccessTokenClientCredentialsGrantRequest(String sco request.addParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.CLIENT_CREDENTIALS); log("created access token client credentials grant request with body params [%s], query string params [%s]", - request.getBodyParams(), request.getQueryStringParams()); + request.getBodyParams().asFormUrlEncodedString(), + request.getQueryStringParams().asFormUrlEncodedString()); return request; } @@ -390,8 +394,9 @@ protected OAuthRequest createRevokeTokenRequest(String tokenToRevoke, TokenTypeH request.addParameter("token_type_hint", tokenTypeHint.getValue()); } - log("created revoke token request with body params [%s], query string params [%s]", request.getBodyParams(), - request.getQueryStringParams()); + log("created revoke token request with body params [%s], query string params [%s]", + request.getBodyParams().asFormUrlEncodedString(), + request.getQueryStringParams().asFormUrlEncodedString()); return request; } From cafa5429cffd604894d1e031c1f79fb6cf1cabc9 Mon Sep 17 00:00:00 2001 From: Petr Kopotev Date: Thu, 1 Aug 2019 12:48:29 +0300 Subject: [PATCH 738/882] Add OAuth2.0 for Dropbox APIs with example. --- .../github/scribejava/apis/DropboxApi.java | 30 ++++++++ .../apis/examples/DropboxExample.java | 70 +++++++++++++++++++ 2 files changed, 100 insertions(+) create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/DropboxApi.java create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DropboxExample.java diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/DropboxApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/DropboxApi.java new file mode 100644 index 000000000..19988fe86 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/DropboxApi.java @@ -0,0 +1,30 @@ +package com.github.scribejava.apis; + +import com.github.scribejava.core.builder.api.DefaultApi20; + +/** + * Dropbox.com Api + */ +public class DropboxApi extends DefaultApi20 { + + protected DropboxApi() { + } + + private static class InstanceHolder { + private static final DropboxApi INSTANCE = new DropboxApi(); + } + + public static DropboxApi instance() { + return InstanceHolder.INSTANCE; + } + + @Override + public String getAccessTokenEndpoint() { + return "https://api.dropbox.com/oauth2/token"; + } + + @Override + protected String getAuthorizationBaseUrl() { + return "https://www.dropbox.com/oauth2/authorize"; + } +} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DropboxExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DropboxExample.java new file mode 100644 index 000000000..7aba52e1f --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DropboxExample.java @@ -0,0 +1,70 @@ +package com.github.scribejava.apis.examples; + +import com.github.scribejava.apis.DropboxApi; +import com.github.scribejava.core.builder.ServiceBuilder; +import com.github.scribejava.core.model.OAuth2AccessToken; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.oauth.OAuth20Service; + +import java.io.IOException; +import java.util.Scanner; +import java.util.concurrent.ExecutionException; + +public class DropboxExample { + + private static final String NETWORK_NAME = "Dropbox.com"; + private static final String PROTECTED_RESOURCE_URL + = "https://api.dropboxapi.com/2/users/get_space_usage"; + private static final String PAYLOAD = "null"; + private static final String CONTENT_TYPE_NAME = "Content-Type"; + private static final String CONTENT_TYPE_VALUE = "application/json"; + + public static void main(String... args) throws IOException, InterruptedException, ExecutionException { + // Replace these with your client id and secret + final String clientId = "client id"; + final String clientSecret = "client secret"; + final OAuth20Service service = new ServiceBuilder(clientId) + .apiSecret(clientSecret) + .callback("https://www.example.com/oauth_callback/") + .build(DropboxApi.instance()); + + final Scanner in = new Scanner(System.in); + + System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); + System.out.println(); + + // Obtain the Authorization URL + System.out.println("Fetching the Authorization URL..."); + final String authorizationUrl = service.getAuthorizationUrl(); + System.out.println("Got the Authorization URL!"); + System.out.println("Now go and authorize ScribeJava here:"); + System.out.println(authorizationUrl); + System.out.println("And paste the authorization code here"); + System.out.print(">>"); + final String code = in.nextLine(); + System.out.println(); + + System.out.println("Trading the Authorization Code for an Access Token..."); + final OAuth2AccessToken accessToken = service.getAccessToken(code); + System.out.println("Got the Access Token!"); + System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); + System.out.println(); + + System.out.println("Now we're going to access a protected resource..."); + final OAuthRequest request = new OAuthRequest(Verb.POST, PROTECTED_RESOURCE_URL); + request.addHeader(CONTENT_TYPE_NAME, CONTENT_TYPE_VALUE); + request.setPayload(PAYLOAD); + service.signRequest(accessToken, request); + + final Response response = service.execute(request); + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + + System.out.println(); + System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); + } +} From 32273dbcabe7a84c2324e4d5fbae1120e99579a0 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 13 Aug 2019 11:07:16 +0300 Subject: [PATCH 739/882] Add debug output to OAuth2Service (thanks to https://github.com/rbarbey) --- changelog | 3 + .../github/scribejava/apis/FacebookApi.java | 22 +++++ .../com/github/scribejava/apis/ImgurApi.java | 23 +++++ .../com/github/scribejava/apis/MailruApi.java | 23 +++++ .../scribejava/apis/OdnoklassnikiApi.java | 24 +++++ .../github/scribejava/apis/WunderlistAPI.java | 25 ++++- .../apis/facebook/FacebookService.java | 25 ++++- .../apis/imgur/ImgurOAuthService.java | 23 ++++- .../apis/mailru/MailruOAuthService.java | 25 ++++- .../OdnoklassnikiOAuthService.java | 26 +++++- .../wunderlist/WunderlistOAuthService.java | 22 +++++ .../core/builder/api/DefaultApi20.java | 22 +++++ .../core/oauth/OAuth10aService.java | 51 +++++++--- .../scribejava/core/oauth/OAuth20Service.java | 93 ++++++++++++------- .../scribejava/core/oauth/OAuthService.java | 51 ++++++++-- .../scribejava/core/oauth/OAuth20ApiUnit.java | 22 +++++ .../core/oauth/OAuth20ServiceUnit.java | 22 +++++ 17 files changed, 440 insertions(+), 62 deletions(-) diff --git a/changelog b/changelog index 17adb113e..79c99a206 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,6 @@ +[SNAPSHOT] + * Add debug output to OAuth2Service (thanks to https://github.com/rbarbey) + [6.7.0] * Add OAuth2 support for Meetup.com (thanks to https://github.com/stevedes77) * upgrade okhttp to 4.0.1 and security fix for jackson-databind 2.9.9.1 diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java index 9c3ee7a46..9572b0b8d 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java @@ -71,6 +71,28 @@ public ClientAuthentication getClientAuthentication() { return RequestBodyAuthenticationScheme.instance(); } + /** + * @param apiKey apiKey + * @param apiSecret apiSecret + * @param callback callback + * @param defaultScope defaultScope + * @param responseType responseType + * @param userAgent userAgent + * @param httpClientConfig httpClientConfig + * @param httpClient httpClient + * @return FacebookService + * @deprecated use {@link #createService(java.lang.String, java.lang.String, java.lang.String, java.lang.String, + * java.lang.String, java.io.OutputStream, java.lang.String, com.github.scribejava.core.httpclient.HttpClientConfig, + * com.github.scribejava.core.httpclient.HttpClient)} + */ + @Deprecated + @Override + public FacebookService createService(String apiKey, String apiSecret, String callback, String defaultScope, + String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { + return createService(apiKey, apiSecret, callback, defaultScope, responseType, null, userAgent, httpClientConfig, + httpClient); + } + @Override public FacebookService createService(String apiKey, String apiSecret, String callback, String defaultScope, String responseType, OutputStream debugStream, String userAgent, HttpClientConfig httpClientConfig, diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java index 6c45b1d79..b9c67cac3 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java @@ -16,6 +16,7 @@ protected ImgurApi() { } private static class InstanceHolder { + private static final ImgurApi INSTANCE = new ImgurApi(); } @@ -55,6 +56,28 @@ protected String getAuthorizationBaseUrl() { throw new UnsupportedOperationException("use getAuthorizationUrl instead"); } + /** + * @param apiKey apiKey + * @param apiSecret apiSecret + * @param callback callback + * @param defaultScope defaultScope + * @param responseType responseType + * @param userAgent userAgent + * @param httpClientConfig httpClientConfig + * @param httpClient httpClient + * @return ImgurOAuthService + * @deprecated use {@link #createService(java.lang.String, java.lang.String, java.lang.String, java.lang.String, + * java.lang.String, java.io.OutputStream, java.lang.String, com.github.scribejava.core.httpclient.HttpClientConfig, + * com.github.scribejava.core.httpclient.HttpClient)} + */ + @Deprecated + @Override + public ImgurOAuthService createService(String apiKey, String apiSecret, String callback, String defaultScope, + String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { + return createService(apiKey, apiSecret, callback, defaultScope, responseType, null, userAgent, httpClientConfig, + httpClient); + } + @Override public ImgurOAuthService createService(String apiKey, String apiSecret, String callback, String defaultScope, String responseType, OutputStream debugStream, String userAgent, HttpClientConfig httpClientConfig, diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java index dc1519f50..a9d29c9b7 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java @@ -13,6 +13,7 @@ protected MailruApi() { } private static class InstanceHolder { + private static final MailruApi INSTANCE = new MailruApi(); } @@ -30,6 +31,28 @@ protected String getAuthorizationBaseUrl() { return "https://connect.mail.ru/oauth/authorize"; } + /** + * @param apiKey apiKey + * @param apiSecret apiSecret + * @param callback callback + * @param defaultScope defaultScope + * @param responseType responseType + * @param userAgent userAgent + * @param httpClientConfig httpClientConfig + * @param httpClient httpClient + * @return MailruOAuthService + * @deprecated use {@link #createService(java.lang.String, java.lang.String, java.lang.String, java.lang.String, + * java.lang.String, java.io.OutputStream, java.lang.String, com.github.scribejava.core.httpclient.HttpClientConfig, + * com.github.scribejava.core.httpclient.HttpClient)} + */ + @Deprecated + @Override + public MailruOAuthService createService(String apiKey, String apiSecret, String callback, String defaultScope, + String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { + return createService(apiKey, apiSecret, callback, defaultScope, responseType, null, userAgent, httpClientConfig, + httpClient); + } + @Override public MailruOAuthService createService(String apiKey, String apiSecret, String callback, String defaultScope, String responseType, OutputStream debugStream, String userAgent, HttpClientConfig httpClientConfig, diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java index d6bfe7690..f258344a9 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java @@ -17,6 +17,7 @@ protected OdnoklassnikiApi() { } private static class InstanceHolder { + private static final OdnoklassnikiApi INSTANCE = new OdnoklassnikiApi(); } @@ -34,6 +35,29 @@ protected String getAuthorizationBaseUrl() { return "https://connect.ok.ru/oauth/authorize"; } + /** + * @param apiKey apiKey + * @param apiSecret apiSecret + * @param callback callback + * @param defaultScope defaultScope + * @param responseType responseType + * @param userAgent userAgent + * @param httpClientConfig httpClientConfig + * @param httpClient httpClient + * @return OdnoklassnikiOAuthService + * @deprecated use {@link #createService(java.lang.String, java.lang.String, java.lang.String, java.lang.String, + * java.lang.String, java.io.OutputStream, java.lang.String, com.github.scribejava.core.httpclient.HttpClientConfig, + * com.github.scribejava.core.httpclient.HttpClient)} + */ + @Deprecated + @Override + public OdnoklassnikiOAuthService createService(String apiKey, String apiSecret, String callback, + String defaultScope, String responseType, String userAgent, HttpClientConfig httpClientConfig, + HttpClient httpClient) { + return createService(apiKey, apiSecret, callback, defaultScope, responseType, null, userAgent, httpClientConfig, + httpClient); + } + @Override public OdnoklassnikiOAuthService createService(String apiKey, String apiSecret, String callback, String defaultScope, String responseType, OutputStream debugStream, String userAgent, diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/WunderlistAPI.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/WunderlistAPI.java index 7283c3ecf..97b28d279 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/WunderlistAPI.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/WunderlistAPI.java @@ -6,7 +6,6 @@ import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.httpclient.HttpClientConfig; -import com.github.scribejava.core.oauth.OAuth20Service; import com.github.scribejava.core.oauth2.bearersignature.BearerSignature; import com.github.scribejava.core.oauth2.bearersignature.BearerSignatureURIQueryParameter; import com.github.scribejava.core.oauth2.clientauthentication.ClientAuthentication; @@ -49,8 +48,30 @@ public ClientAuthentication getClientAuthentication() { return RequestBodyAuthenticationScheme.instance(); } + /** + * @param apiKey apiKey + * @param apiSecret apiSecret + * @param callback callback + * @param defaultScope defaultScope + * @param responseType responseType + * @param userAgent userAgent + * @param httpClientConfig httpClientConfig + * @param httpClient httpClient + * @return WunderlistOAuthService + * @deprecated use {@link #createService(java.lang.String, java.lang.String, java.lang.String, java.lang.String, + * java.lang.String, java.io.OutputStream, java.lang.String, com.github.scribejava.core.httpclient.HttpClientConfig, + * com.github.scribejava.core.httpclient.HttpClient)} + */ + @Deprecated @Override - public OAuth20Service createService(String apiKey, String apiSecret, String callback, String defaultScope, + public WunderlistOAuthService createService(String apiKey, String apiSecret, String callback, String defaultScope, + String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { + return createService(apiKey, apiSecret, callback, defaultScope, responseType, null, userAgent, httpClientConfig, + httpClient); + } + + @Override + public WunderlistOAuthService createService(String apiKey, String apiSecret, String callback, String defaultScope, String responseType, OutputStream debugStream, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { return new WunderlistOAuthService(this, apiKey, apiSecret, callback, defaultScope, responseType, debugStream, diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookService.java index f1f79ad88..f54dedc01 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookService.java @@ -1,6 +1,6 @@ package com.github.scribejava.apis.facebook; -import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.apis.FacebookApi; import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.httpclient.HttpClientConfig; import com.github.scribejava.core.model.OAuthRequest; @@ -15,7 +15,28 @@ public class FacebookService extends OAuth20Service { - public FacebookService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String defaultScope, + /** + * @param api api + * @param apiKey apiKey + * @param apiSecret apiSecret + * @param callback callback + * @param defaultScope defaultScope + * @param responseType responseType + * @param userAgent userAgent + * @param httpClientConfig httpClientConfig + * @param httpClient httpClient + * @deprecated use {@link #FacebookService(com.github.scribejava.apis.FacebookApi, java.lang.String, + * java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.io.OutputStream, java.lang.String, + * com.github.scribejava.core.httpclient.HttpClientConfig, com.github.scribejava.core.httpclient.HttpClient) } + */ + @Deprecated + public FacebookService(FacebookApi api, String apiKey, String apiSecret, String callback, String defaultScope, + String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { + this(api, apiKey, apiSecret, callback, defaultScope, responseType, null, userAgent, httpClientConfig, + httpClient); + } + + public FacebookService(FacebookApi api, String apiKey, String apiSecret, String callback, String defaultScope, String responseType, OutputStream debugStream, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { super(api, apiKey, apiSecret, callback, defaultScope, responseType, debugStream, userAgent, httpClientConfig, diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/imgur/ImgurOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/imgur/ImgurOAuthService.java index 589354891..e590cee42 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/imgur/ImgurOAuthService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/imgur/ImgurOAuthService.java @@ -14,7 +14,28 @@ public class ImgurOAuthService extends OAuth20Service { - public ImgurOAuthService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String defaultScope, + /** + * @param api api + * @param apiKey apiKey + * @param apiSecret apiSecret + * @param callback callback + * @param defaultScope defaultScope + * @param responseType responseType + * @param userAgent userAgent + * @param httpClientConfig httpClientConfig + * @param httpClient httpClient + * @deprecated use {@link #ImgurOAuthService(com.github.scribejava.apis.ImgurApi, java.lang.String, + * java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.io.OutputStream, java.lang.String, + * com.github.scribejava.core.httpclient.HttpClientConfig, com.github.scribejava.core.httpclient.HttpClient) } + */ + @Deprecated + public ImgurOAuthService(ImgurApi api, String apiKey, String apiSecret, String callback, String defaultScope, + String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { + this(api, apiKey, apiSecret, callback, defaultScope, responseType, null, userAgent, httpClientConfig, + httpClient); + } + + public ImgurOAuthService(ImgurApi api, String apiKey, String apiSecret, String callback, String defaultScope, String responseType, OutputStream debugStream, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { super(api, apiKey, apiSecret, callback, defaultScope, responseType, debugStream, userAgent, httpClientConfig, diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/mailru/MailruOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/mailru/MailruOAuthService.java index ab8294139..9a6228177 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/mailru/MailruOAuthService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/mailru/MailruOAuthService.java @@ -1,9 +1,9 @@ package com.github.scribejava.apis.mailru; +import com.github.scribejava.apis.MailruApi; import java.net.URLDecoder; import java.util.Map; import java.util.TreeMap; -import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.httpclient.HttpClientConfig; import com.github.scribejava.core.model.OAuthRequest; @@ -18,7 +18,28 @@ public class MailruOAuthService extends OAuth20Service { - public MailruOAuthService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String defaultScope, + /** + * @param api api + * @param apiKey apiKey + * @param apiSecret apiSecret + * @param callback callback + * @param defaultScope defaultScope + * @param responseType responseType + * @param userAgent userAgent + * @param httpClientConfig httpClientConfig + * @param httpClient httpClient + * @deprecated use {@link #MailruOAuthService(com.github.scribejava.apis.MailruApi, java.lang.String, + * java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.io.OutputStream, java.lang.String, + * com.github.scribejava.core.httpclient.HttpClientConfig, com.github.scribejava.core.httpclient.HttpClient) } + */ + @Deprecated + public MailruOAuthService(MailruApi api, String apiKey, String apiSecret, String callback, String defaultScope, + String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { + this(api, apiKey, apiSecret, callback, defaultScope, responseType, null, userAgent, httpClientConfig, + httpClient); + } + + public MailruOAuthService(MailruApi api, String apiKey, String apiSecret, String callback, String defaultScope, String responseType, OutputStream debugStream, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { super(api, apiKey, apiSecret, callback, defaultScope, responseType, debugStream, userAgent, httpClientConfig, diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/odnoklassniki/OdnoklassnikiOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/odnoklassniki/OdnoklassnikiOAuthService.java index a06b3f0c2..0e012b1a4 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/odnoklassniki/OdnoklassnikiOAuthService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/odnoklassniki/OdnoklassnikiOAuthService.java @@ -1,6 +1,6 @@ package com.github.scribejava.apis.odnoklassniki; -import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.apis.OdnoklassnikiApi; import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.httpclient.HttpClientConfig; import com.github.scribejava.core.model.OAuthRequest; @@ -21,7 +21,29 @@ public class OdnoklassnikiOAuthService extends OAuth20Service { - public OdnoklassnikiOAuthService(DefaultApi20 api, String apiKey, String apiSecret, String callback, + /** + * @param api api + * @param apiKey apiKey + * @param apiSecret apiSecret + * @param callback callback + * @param defaultScope defaultScope + * @param responseType responseType + * @param userAgent userAgent + * @param httpClientConfig httpClientConfig + * @param httpClient httpClient + * @deprecated use {@link #OdnoklassnikiOAuthService(com.github.scribejava.apis.OdnoklassnikiApi, java.lang.String, + * java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.io.OutputStream, java.lang.String, + * com.github.scribejava.core.httpclient.HttpClientConfig, com.github.scribejava.core.httpclient.HttpClient) } + */ + @Deprecated + public OdnoklassnikiOAuthService(OdnoklassnikiApi api, String apiKey, String apiSecret, String callback, + String defaultScope, String responseType, String userAgent, HttpClientConfig httpClientConfig, + HttpClient httpClient) { + this(api, apiKey, apiSecret, callback, defaultScope, responseType, null, userAgent, httpClientConfig, + httpClient); + } + + public OdnoklassnikiOAuthService(OdnoklassnikiApi api, String apiKey, String apiSecret, String callback, String defaultScope, String responseType, OutputStream debugStream, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { super(api, apiKey, apiSecret, callback, defaultScope, responseType, debugStream, userAgent, httpClientConfig, diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/wunderlist/WunderlistOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/wunderlist/WunderlistOAuthService.java index 06a248d9c..e28c910e6 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/wunderlist/WunderlistOAuthService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/wunderlist/WunderlistOAuthService.java @@ -10,6 +10,28 @@ public class WunderlistOAuthService extends OAuth20Service { + /** + * @param api api + * @param apiKey apiKey + * @param apiSecret apiSecret + * @param callback callback + * @param defaultScope defaultScope + * @param responseType responseType + * @param userAgent userAgent + * @param httpClientConfig httpClientConfig + * @param httpClient httpClient + * @deprecated use {@link #WunderlistOAuthService(com.github.scribejava.apis.WunderlistAPI, java.lang.String, + * java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.io.OutputStream, java.lang.String, + * com.github.scribejava.core.httpclient.HttpClientConfig, com.github.scribejava.core.httpclient.HttpClient) } + */ + @Deprecated + public WunderlistOAuthService(WunderlistAPI api, String apiKey, String apiSecret, String callback, + String defaultScope, String responseType, String userAgent, HttpClientConfig httpClientConfig, + HttpClient httpClient) { + this(api, apiKey, apiSecret, callback, defaultScope, responseType, null, userAgent, httpClientConfig, + httpClient); + } + public WunderlistOAuthService(WunderlistAPI api, String apiKey, String apiSecret, String callback, String defaultScope, String responseType, OutputStream debugStream, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java index 64ad82f00..8a4d6115a 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java @@ -107,6 +107,28 @@ public String getAuthorizationUrl(String responseType, String apiKey, String cal return parameters.appendTo(getAuthorizationBaseUrl()); } + /** + * + * @param apiKey apiKey + * @param apiSecret apiSecret + * @param callback callback + * @param defaultScope defaultScope + * @param responseType responseType + * @param userAgent userAgent + * @param httpClientConfig httpClientConfig + * @param httpClient httpClient + * @return OAuth20Service + * @deprecated use {@link #createService(java.lang.String, java.lang.String, java.lang.String, java.lang.String, + * java.lang.String, java.io.OutputStream, java.lang.String, com.github.scribejava.core.httpclient.HttpClientConfig, + * com.github.scribejava.core.httpclient.HttpClient)} + */ + @Deprecated + public OAuth20Service createService(String apiKey, String apiSecret, String callback, String defaultScope, + String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { + return createService(apiKey, apiSecret, callback, defaultScope, responseType, userAgent, httpClientConfig, + httpClient); + } + public OAuth20Service createService(String apiKey, String apiSecret, String callback, String defaultScope, String responseType, OutputStream debugStream, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java index 401cba8c9..230a9dbd4 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java @@ -33,15 +33,18 @@ public OAuth10aService(DefaultApi10a api, String apiKey, String apiSecret, Strin } public OAuth1RequestToken getRequestToken() throws IOException, InterruptedException, ExecutionException { - log("obtaining request token from %s", api.getRequestTokenEndpoint()); + if (isDebug()) { + log("obtaining request token from %s", api.getRequestTokenEndpoint()); + } final OAuthRequest request = prepareRequestTokenRequest(); log("sending request..."); final Response response = execute(request); - final String body = response.getBody(); - - log("response status code: %s", response.getCode()); - log("response body: %s", body); + if (isDebug()) { + final String body = response.getBody(); + log("response status code: %s", response.getCode()); + log("response body: %s", body); + } return api.getRequestTokenExtractor().extract(response); } @@ -50,7 +53,9 @@ public Future getRequestTokenAsync() { } public Future getRequestTokenAsync(OAuthAsyncRequestCallback callback) { - log("async obtaining request token from %s", api.getRequestTokenEndpoint()); + if (isDebug()) { + log("async obtaining request token from %s", api.getRequestTokenEndpoint()); + } final OAuthRequest request = prepareRequestTokenRequest(); return execute(request, callback, new OAuthRequest.ResponseConverter() { @Override @@ -66,7 +71,9 @@ protected OAuthRequest prepareRequestTokenRequest() { if (callback == null) { callback = OAuthConstants.OOB; } - log("setting oauth_callback to %s", callback); + if (isDebug()) { + log("setting oauth_callback to %s", callback); + } request.addOAuthParameter(OAuthConstants.CALLBACK, callback); addOAuthParams(request, ""); appendSignature(request); @@ -84,12 +91,16 @@ protected void addOAuthParams(OAuthRequest request, String tokenSecret) { } request.addOAuthParameter(OAuthConstants.SIGNATURE, getSignature(request, tokenSecret)); - log("appended additional OAuth parameters: %s", request.getOauthParameters()); + if (isDebug()) { + log("appended additional OAuth parameters: %s", request.getOauthParameters()); + } } public OAuth1AccessToken getAccessToken(OAuth1RequestToken requestToken, String oauthVerifier) throws IOException, InterruptedException, ExecutionException { - log("obtaining access token from %s", api.getAccessTokenEndpoint()); + if (isDebug()) { + log("obtaining access token from %s", api.getAccessTokenEndpoint()); + } final OAuthRequest request = prepareAccessTokenRequest(requestToken, oauthVerifier); final Response response = execute(request); return api.getAccessTokenExtractor().extract(response); @@ -110,7 +121,9 @@ public Future getAccessTokenAsync(OAuth1RequestToken requestT */ public Future getAccessTokenAsync(OAuth1RequestToken requestToken, String oauthVerifier, OAuthAsyncRequestCallback callback) { - log("async obtaining access token from %s", api.getAccessTokenEndpoint()); + if (isDebug()) { + log("async obtaining access token from %s", api.getAccessTokenEndpoint()); + } final OAuthRequest request = prepareAccessTokenRequest(requestToken, oauthVerifier); return execute(request, callback, new OAuthRequest.ResponseConverter() { @Override @@ -124,19 +137,25 @@ protected OAuthRequest prepareAccessTokenRequest(OAuth1RequestToken requestToken final OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint()); request.addOAuthParameter(OAuthConstants.TOKEN, requestToken.getToken()); request.addOAuthParameter(OAuthConstants.VERIFIER, oauthVerifier); - log("setting token to: %s and verifier to: %s", requestToken, oauthVerifier); + if (isDebug()) { + log("setting token to: %s and verifier to: %s", requestToken, oauthVerifier); + } addOAuthParams(request, requestToken.getTokenSecret()); appendSignature(request); return request; } public void signRequest(OAuth1AccessToken token, OAuthRequest request) { - log("signing request: %s", request.getCompleteUrl()); + if (isDebug()) { + log("signing request: %s", request.getCompleteUrl()); + } if (!token.isEmpty() || api.isEmptyOAuthTokenParamIsRequired()) { request.addOAuthParameter(OAuthConstants.TOKEN, token.getToken()); } - log("setting token to: %s", token); + if (isDebug()) { + log("setting token to: %s", token); + } addOAuthParams(request, token.getTokenSecret()); appendSignature(request); } @@ -161,8 +180,10 @@ private String getSignature(OAuthRequest request, String tokenSecret) { final String baseString = api.getBaseStringExtractor().extract(request); final String signature = api.getSignatureService().getSignature(baseString, getApiSecret(), tokenSecret); - log("base string is: %s", baseString); - log("signature is: %s", signature); + if (isDebug()) { + log("base string is: %s", baseString); + log("signature is: %s", signature); + } return signature; } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java index 15cdbf19e..74997626c 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java @@ -28,6 +28,27 @@ public class OAuth20Service extends OAuthService { private final String responseType; private final String defaultScope; + /** + * @param api api + * @param apiKey apiKey + * @param apiSecret apiSecret + * @param callback callback + * @param defaultScope defaultScope + * @param responseType responseType + * @param userAgent userAgent + * @param httpClientConfig httpClientConfig + * @param httpClient httpClient + * @deprecated use {@link #OAuth20Service(com.github.scribejava.core.builder.api.DefaultApi20, java.lang.String, + * java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.io.OutputStream, java.lang.String, + * com.github.scribejava.core.httpclient.HttpClientConfig, com.github.scribejava.core.httpclient.HttpClient)} + */ + @Deprecated + public OAuth20Service(DefaultApi20 api, String apiKey, String apiSecret, String callback, String defaultScope, + String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { + this(api, apiKey, apiSecret, callback, defaultScope, responseType, null, userAgent, httpClientConfig, + httpClient); + } + public OAuth20Service(DefaultApi20 api, String apiKey, String apiSecret, String callback, String defaultScope, String responseType, OutputStream debugStream, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { @@ -40,13 +61,15 @@ public OAuth20Service(DefaultApi20 api, String apiKey, String apiSecret, String //protected to facilitate mocking protected OAuth2AccessToken sendAccessTokenRequestSync(OAuthRequest request) throws IOException, InterruptedException, ExecutionException { - log("send request for access token synchronously to %s", request.getCompleteUrl()); - + if (isDebug()) { + log("send request for access token synchronously to %s", request.getCompleteUrl()); + } final Response response = execute(request); - final String body = response.getBody(); - - log("response status code: %s", response.getCode()); - log("response body: %s", body); + if (isDebug()) { + log("response status code: %s", response.getCode()); + final String body = response.getBody(); + log("response body: %s", body); + } return api.getAccessTokenExtractor().extract(response); } @@ -59,16 +82,19 @@ protected Future sendAccessTokenRequestAsync(OAuthRequest req //protected to facilitate mocking protected Future sendAccessTokenRequestAsync(OAuthRequest request, OAuthAsyncRequestCallback callback) { - log("send request for access token asynchronously to %s", request.getCompleteUrl()); + if (isDebug()) { + log("send request for access token asynchronously to %s", request.getCompleteUrl()); + } return execute(request, callback, new OAuthRequest.ResponseConverter() { @Override public OAuth2AccessToken convert(Response response) throws IOException { log("received response for access token"); - final String body = response.getBody(); - - log("response status code: %s", response.getCode()); - log("response body: %s", body); + if (isDebug()) { + log("response status code: %s", response.getCode()); + final String body = response.getBody(); + log("response body: %s", body); + } return getApi().getAccessTokenExtractor().extract(response); } }); @@ -131,10 +157,11 @@ protected OAuthRequest createAccessTokenRequest(AccessTokenRequestParams params) if (pkceCodeVerifier != null) { request.addParameter(PKCE.PKCE_CODE_VERIFIER_PARAM, pkceCodeVerifier); } - - log("created access token request with body params [%s], query string params [%s]", - request.getBodyParams().asFormUrlEncodedString(), - request.getQueryStringParams().asFormUrlEncodedString()); + if (isDebug()) { + log("created access token request with body params [%s], query string params [%s]", + request.getBodyParams().asFormUrlEncodedString(), + request.getQueryStringParams().asFormUrlEncodedString()); + } return request; } @@ -190,11 +217,11 @@ protected OAuthRequest createRefreshTokenRequest(String refreshToken, String sco request.addParameter(OAuthConstants.REFRESH_TOKEN, refreshToken); request.addParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.REFRESH_TOKEN); - - log("created refresh token request with body params [%s], query string params [%s]", - request.getBodyParams().asFormUrlEncodedString(), - request.getQueryStringParams().asFormUrlEncodedString()); - + if (isDebug()) { + log("created refresh token request with body params [%s], query string params [%s]", + request.getBodyParams().asFormUrlEncodedString(), + request.getQueryStringParams().asFormUrlEncodedString()); + } return request; } @@ -258,10 +285,11 @@ protected OAuthRequest createAccessTokenPasswordGrantRequest(String username, St api.getClientAuthentication().addClientAuthentication(request, getApiKey(), getApiSecret()); - log("created access token password grant request with body params [%s], query string params [%s]", - request.getBodyParams().asFormUrlEncodedString(), - request.getQueryStringParams().asFormUrlEncodedString()); - + if (isDebug()) { + log("created access token password grant request with body params [%s], query string params [%s]", + request.getBodyParams().asFormUrlEncodedString(), + request.getQueryStringParams().asFormUrlEncodedString()); + } return request; } @@ -320,10 +348,11 @@ protected OAuthRequest createAccessTokenClientCredentialsGrantRequest(String sco } request.addParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.CLIENT_CREDENTIALS); - log("created access token client credentials grant request with body params [%s], query string params [%s]", - request.getBodyParams().asFormUrlEncodedString(), - request.getQueryStringParams().asFormUrlEncodedString()); - + if (isDebug()) { + log("created access token client credentials grant request with body params [%s], query string params [%s]", + request.getBodyParams().asFormUrlEncodedString(), + request.getQueryStringParams().asFormUrlEncodedString()); + } return request; } @@ -394,9 +423,11 @@ protected OAuthRequest createRevokeTokenRequest(String tokenToRevoke, TokenTypeH request.addParameter("token_type_hint", tokenTypeHint.getValue()); } - log("created revoke token request with body params [%s], query string params [%s]", - request.getBodyParams().asFormUrlEncodedString(), - request.getQueryStringParams().asFormUrlEncodedString()); + if (isDebug()) { + log("created revoke token request with body params [%s], query string params [%s]", + request.getBodyParams().asFormUrlEncodedString(), + request.getQueryStringParams().asFormUrlEncodedString()); + } return request; } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java index cb8680b1f..c8101d504 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java @@ -26,6 +26,24 @@ public abstract class OAuthService implements Closeable { private final HttpClient httpClient; private final OutputStream debugStream; + /** + * + * @param apiKey apiKey + * @param apiSecret apiSecret + * @param callback callback + * @param userAgent userAgent + * @param httpClientConfig httpClientConfig + * @param httpClient httpClient + * @deprecated use {@link #OAuthService(java.lang.String, java.lang.String, java.lang.String, java.io.OutputStream, + * java.lang.String, com.github.scribejava.core.httpclient.HttpClientConfig, + * com.github.scribejava.core.httpclient.HttpClient)} + */ + @Deprecated + public OAuthService(String apiKey, String apiSecret, String callback, String userAgent, + HttpClientConfig httpClientConfig, HttpClient httpClient) { + this(apiKey, apiSecret, callback, null, userAgent, httpClientConfig, httpClient); + } + public OAuthService(String apiKey, String apiSecret, String callback, OutputStream debugStream, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { this.apiKey = apiKey; @@ -116,14 +134,33 @@ public Response execute(OAuthRequest request) throws InterruptedException, Execu } } - public void log(String messagePattern, Object... params) { + /** + * No need to wrap usages in {@link #isDebug()}. + * + * @param message message to log + */ + public void log(String message) { if (debugStream != null) { - final String message = String.format(messagePattern, params) + '\n'; - try { - debugStream.write(message.getBytes("UTF8")); - } catch (IOException | RuntimeException e) { - throw new RuntimeException("there were problems while writting to the debug stream", e); - } + log(message, (Object[]) null); } } + + /** + * Wrap usages in {@link #isDebug()}. It was made for optimization - to not calculate "params" in production mode. + * + * @param messagePattern messagePattern + * @param params params + */ + public void log(String messagePattern, Object... params) { + final String message = String.format(messagePattern, params) + '\n'; + try { + debugStream.write(message.getBytes("UTF8")); + } catch (IOException | RuntimeException e) { + throw new RuntimeException("there were problems while writting to the debug stream", e); + } + } + + protected boolean isDebug() { + return debugStream != null; + } } diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ApiUnit.java b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ApiUnit.java index cd9e58550..6ba3e3e20 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ApiUnit.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ApiUnit.java @@ -20,6 +20,28 @@ protected String getAuthorizationBaseUrl() { return "http://localhost:8080/authorize"; } + /** + * @param apiKey apiKey + * @param apiSecret apiSecret + * @param callback callback + * @param defaultScope defaultScope + * @param responseType responseType + * @param userAgent userAgent + * @param httpClientConfig httpClientConfig + * @param httpClient httpClient + * @return OAuth20ServiceUnit + * @deprecated use {@link #createService(java.lang.String, java.lang.String, java.lang.String, java.lang.String, + * java.lang.String, java.io.OutputStream, java.lang.String, com.github.scribejava.core.httpclient.HttpClientConfig, + * com.github.scribejava.core.httpclient.HttpClient)} + */ + @Deprecated + @Override + public OAuth20ServiceUnit createService(String apiKey, String apiSecret, String callback, String defaultScope, + String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { + return createService(apiKey, apiSecret, callback, defaultScope, responseType, null, userAgent, httpClientConfig, + httpClient); + } + @Override public OAuth20ServiceUnit createService(String apiKey, String apiSecret, String callback, String defaultScope, String responseType, OutputStream debugStream, String userAgent, HttpClientConfig httpClientConfig, diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceUnit.java b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceUnit.java index 2766b7f2b..12654051d 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceUnit.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceUnit.java @@ -23,6 +23,28 @@ class OAuth20ServiceUnit extends OAuth20Service { static final int EXPIRES = 3600; private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); + /** + * @param api api + * @param apiKey apiKey + * @param apiSecret apiSecret + * @param callback callback + * @param defaultScope defaultScope + * @param responseType responseType + * @param userAgent userAgent + * @param httpClientConfig httpClientConfig + * @param httpClient httpClient + * @deprecated use {@link #OAuth20ServiceUnit(com.github.scribejava.core.builder.api.DefaultApi20, java.lang.String, + * java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.io.OutputStream, java.lang.String, + * com.github.scribejava.core.httpclient.HttpClientConfig, com.github.scribejava.core.httpclient.HttpClient)} + */ + @Deprecated + OAuth20ServiceUnit(DefaultApi20 api, String apiKey, String apiSecret, String callback, String defaultScope, + String responseType, String userAgent, HttpClientConfig httpClientConfig, + HttpClient httpClient) { + this(api, apiKey, apiSecret, callback, defaultScope, responseType, null, userAgent, httpClientConfig, + httpClient); + } + OAuth20ServiceUnit(DefaultApi20 api, String apiKey, String apiSecret, String callback, String defaultScope, String responseType, OutputStream debugStream, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { From c38249d415974a6040326241ce1c94eef6bf55cc Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 14 Aug 2019 12:51:10 +0300 Subject: [PATCH 740/882] upgrade dependencies --- pom.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 2e3434293..e46cd9bfc 100644 --- a/pom.xml +++ b/pom.xml @@ -56,7 +56,7 @@ com.fasterxml.jackson.core jackson-databind - 2.9.9.1 + 2.9.9.3 junit @@ -106,7 +106,7 @@ com.puppycrawl.tools checkstyle - 8.22 + 8.23 @@ -273,7 +273,7 @@ 7 - 6.16.0 + 6.17.0 From 75afd4a28bc48ddfcecc4a2a10b1b3d951d24d05 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 15 Aug 2019 14:33:43 +0300 Subject: [PATCH 741/882] Add Dropbox API (https://www.dropbox.com/) (thanks to https://github.com/petrkopotev) --- README.md | 1 + changelog | 1 + .../main/java/com/github/scribejava/apis/DropboxApi.java | 1 + .../github/scribejava/apis/examples/DropboxExample.java | 7 +++++-- 4 files changed, 8 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b1ef40366..6872d69ff 100644 --- a/README.md +++ b/README.md @@ -61,6 +61,7 @@ ScribeJava support out-of-box several HTTP clients: * Digg (http://digg.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiggExample.java) * Discord (https://discordapp.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiscordExample.java) * Доктор на работе (https://www.doktornarabote.ru/) +* Dropbox (https://www.dropbox.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DropboxExample.java) * Etsy (https://www.etsy.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/EtsyExample.java) * Facebook (https://www.facebook.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java), [example with Async Apache HTTP client](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncApacheExample.java), [example with Async Ning HTTP client](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java) * Fitbit (https://www.fitbit.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FitbitApi20Example.java) diff --git a/changelog b/changelog index 79c99a206..02f856b96 100644 --- a/changelog +++ b/changelog @@ -1,5 +1,6 @@ [SNAPSHOT] * Add debug output to OAuth2Service (thanks to https://github.com/rbarbey) + * Add Dropbox API (https://www.dropbox.com/) (thanks to https://github.com/petrkopotev) [6.7.0] * Add OAuth2 support for Meetup.com (thanks to https://github.com/stevedes77) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/DropboxApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/DropboxApi.java index 19988fe86..8bbd646f5 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/DropboxApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/DropboxApi.java @@ -11,6 +11,7 @@ protected DropboxApi() { } private static class InstanceHolder { + private static final DropboxApi INSTANCE = new DropboxApi(); } diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DropboxExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DropboxExample.java index 7aba52e1f..4ed799283 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DropboxExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DropboxExample.java @@ -15,12 +15,15 @@ public class DropboxExample { private static final String NETWORK_NAME = "Dropbox.com"; - private static final String PROTECTED_RESOURCE_URL - = "https://api.dropboxapi.com/2/users/get_space_usage"; + private static final String PROTECTED_RESOURCE_URL = "https://api.dropboxapi.com/2/users/get_space_usage"; private static final String PAYLOAD = "null"; private static final String CONTENT_TYPE_NAME = "Content-Type"; private static final String CONTENT_TYPE_VALUE = "application/json"; + private DropboxExample() { + } + + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your client id and secret final String clientId = "client id"; From e61590899577224e5a5d52b1435d710f6034edaf Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 15 Aug 2019 15:29:33 +0300 Subject: [PATCH 742/882] small typo fix --- .../com/github/scribejava/core/builder/api/DefaultApi20.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java index 8a4d6115a..8c69ce2f5 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java @@ -125,7 +125,7 @@ public String getAuthorizationUrl(String responseType, String apiKey, String cal @Deprecated public OAuth20Service createService(String apiKey, String apiSecret, String callback, String defaultScope, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - return createService(apiKey, apiSecret, callback, defaultScope, responseType, userAgent, httpClientConfig, + return createService(apiKey, apiSecret, callback, defaultScope, responseType, null, userAgent, httpClientConfig, httpClient); } From cb9f56d433f389ad86c01670311d2b8d606088eb Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 15 Aug 2019 15:30:15 +0300 Subject: [PATCH 743/882] prepare v6.8.0 --- README.md | 4 ++-- changelog | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 6872d69ff..16cf3d3ce 100644 --- a/README.md +++ b/README.md @@ -130,7 +130,7 @@ You can pull ScribeJava from the central maven repository, just add these to you com.github.scribejava scribejava-apis - 6.7.0 + 6.8.0 ``` @@ -139,7 +139,7 @@ And in case you need just core classes (that's it, without any external API (FB, com.github.scribejava scribejava-core - 6.7.0 + 6.8.0 ``` diff --git a/changelog b/changelog index 02f856b96..013f62039 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,4 @@ -[SNAPSHOT] +[6.8.0] * Add debug output to OAuth2Service (thanks to https://github.com/rbarbey) * Add Dropbox API (https://www.dropbox.com/) (thanks to https://github.com/petrkopotev) From 9e33c17c0222d051f293f7d58f45b077296edf6d Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 15 Aug 2019 15:31:50 +0300 Subject: [PATCH 744/882] [maven-release-plugin] prepare release scribejava-6.8.0 --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index e46cd9bfc..ccf904e3d 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 6.7.1-SNAPSHOT + 6.8.0 ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -34,7 +34,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - HEAD + scribejava-6.8.0 diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 2fe76f005..b6c5c4d7a 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.7.1-SNAPSHOT + 6.8.0 ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 3b8cfb6d0..ea27f8131 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.7.1-SNAPSHOT + 6.8.0 ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 3eb2f9511..b41ee17dd 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.7.1-SNAPSHOT + 6.8.0 ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index 38e123910..0142231eb 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.7.1-SNAPSHOT + 6.8.0 ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index b99eb1bca..636ce905d 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.7.1-SNAPSHOT + 6.8.0 ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 838b87ac5..4b988ec51 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.7.1-SNAPSHOT + 6.8.0 ../pom.xml From 4c516ad78f8dd2ce3de5a08f389d57da106094a0 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 15 Aug 2019 15:31:58 +0300 Subject: [PATCH 745/882] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index ccf904e3d..d70a2626c 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 6.8.0 + 6.8.1-SNAPSHOT ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -34,7 +34,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - scribejava-6.8.0 + HEAD diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index b6c5c4d7a..c95ef2b51 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.8.0 + 6.8.1-SNAPSHOT ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index ea27f8131..995ea03b5 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.8.0 + 6.8.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index b41ee17dd..97657ec57 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.8.0 + 6.8.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index 0142231eb..14fcba8b5 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.8.0 + 6.8.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index 636ce905d..1f6453d20 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.8.0 + 6.8.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 4b988ec51..3006a5d67 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.8.0 + 6.8.1-SNAPSHOT ../pom.xml From 03321f02e1cc91b5d07e13c0c098640912a1f53b Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 15 Aug 2019 16:37:29 +0300 Subject: [PATCH 746/882] drop deprecated --- .../github/scribejava/apis/FacebookApi.java | 22 ------------------ .../com/github/scribejava/apis/ImgurApi.java | 22 ------------------ .../com/github/scribejava/apis/MailruApi.java | 22 ------------------ .../scribejava/apis/OdnoklassnikiApi.java | 23 ------------------- .../github/scribejava/apis/WunderlistAPI.java | 22 ------------------ .../apis/facebook/FacebookService.java | 21 ----------------- .../apis/imgur/ImgurOAuthService.java | 21 ----------------- .../apis/mailru/MailruOAuthService.java | 21 ----------------- .../OdnoklassnikiOAuthService.java | 22 ------------------ .../wunderlist/WunderlistOAuthService.java | 22 ------------------ .../core/builder/api/DefaultApi20.java | 22 ------------------ .../scribejava/core/oauth/OAuth20Service.java | 21 ----------------- .../scribejava/core/oauth/OAuthService.java | 18 --------------- .../scribejava/core/oauth/OAuth20ApiUnit.java | 22 ------------------ .../core/oauth/OAuth20ServiceUnit.java | 22 ------------------ 15 files changed, 323 deletions(-) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java index 9572b0b8d..9c3ee7a46 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java @@ -71,28 +71,6 @@ public ClientAuthentication getClientAuthentication() { return RequestBodyAuthenticationScheme.instance(); } - /** - * @param apiKey apiKey - * @param apiSecret apiSecret - * @param callback callback - * @param defaultScope defaultScope - * @param responseType responseType - * @param userAgent userAgent - * @param httpClientConfig httpClientConfig - * @param httpClient httpClient - * @return FacebookService - * @deprecated use {@link #createService(java.lang.String, java.lang.String, java.lang.String, java.lang.String, - * java.lang.String, java.io.OutputStream, java.lang.String, com.github.scribejava.core.httpclient.HttpClientConfig, - * com.github.scribejava.core.httpclient.HttpClient)} - */ - @Deprecated - @Override - public FacebookService createService(String apiKey, String apiSecret, String callback, String defaultScope, - String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - return createService(apiKey, apiSecret, callback, defaultScope, responseType, null, userAgent, httpClientConfig, - httpClient); - } - @Override public FacebookService createService(String apiKey, String apiSecret, String callback, String defaultScope, String responseType, OutputStream debugStream, String userAgent, HttpClientConfig httpClientConfig, diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java index b9c67cac3..845fd95cb 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java @@ -56,28 +56,6 @@ protected String getAuthorizationBaseUrl() { throw new UnsupportedOperationException("use getAuthorizationUrl instead"); } - /** - * @param apiKey apiKey - * @param apiSecret apiSecret - * @param callback callback - * @param defaultScope defaultScope - * @param responseType responseType - * @param userAgent userAgent - * @param httpClientConfig httpClientConfig - * @param httpClient httpClient - * @return ImgurOAuthService - * @deprecated use {@link #createService(java.lang.String, java.lang.String, java.lang.String, java.lang.String, - * java.lang.String, java.io.OutputStream, java.lang.String, com.github.scribejava.core.httpclient.HttpClientConfig, - * com.github.scribejava.core.httpclient.HttpClient)} - */ - @Deprecated - @Override - public ImgurOAuthService createService(String apiKey, String apiSecret, String callback, String defaultScope, - String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - return createService(apiKey, apiSecret, callback, defaultScope, responseType, null, userAgent, httpClientConfig, - httpClient); - } - @Override public ImgurOAuthService createService(String apiKey, String apiSecret, String callback, String defaultScope, String responseType, OutputStream debugStream, String userAgent, HttpClientConfig httpClientConfig, diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java index a9d29c9b7..b48091594 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java @@ -31,28 +31,6 @@ protected String getAuthorizationBaseUrl() { return "https://connect.mail.ru/oauth/authorize"; } - /** - * @param apiKey apiKey - * @param apiSecret apiSecret - * @param callback callback - * @param defaultScope defaultScope - * @param responseType responseType - * @param userAgent userAgent - * @param httpClientConfig httpClientConfig - * @param httpClient httpClient - * @return MailruOAuthService - * @deprecated use {@link #createService(java.lang.String, java.lang.String, java.lang.String, java.lang.String, - * java.lang.String, java.io.OutputStream, java.lang.String, com.github.scribejava.core.httpclient.HttpClientConfig, - * com.github.scribejava.core.httpclient.HttpClient)} - */ - @Deprecated - @Override - public MailruOAuthService createService(String apiKey, String apiSecret, String callback, String defaultScope, - String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - return createService(apiKey, apiSecret, callback, defaultScope, responseType, null, userAgent, httpClientConfig, - httpClient); - } - @Override public MailruOAuthService createService(String apiKey, String apiSecret, String callback, String defaultScope, String responseType, OutputStream debugStream, String userAgent, HttpClientConfig httpClientConfig, diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java index f258344a9..b87eaa072 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java @@ -35,29 +35,6 @@ protected String getAuthorizationBaseUrl() { return "https://connect.ok.ru/oauth/authorize"; } - /** - * @param apiKey apiKey - * @param apiSecret apiSecret - * @param callback callback - * @param defaultScope defaultScope - * @param responseType responseType - * @param userAgent userAgent - * @param httpClientConfig httpClientConfig - * @param httpClient httpClient - * @return OdnoklassnikiOAuthService - * @deprecated use {@link #createService(java.lang.String, java.lang.String, java.lang.String, java.lang.String, - * java.lang.String, java.io.OutputStream, java.lang.String, com.github.scribejava.core.httpclient.HttpClientConfig, - * com.github.scribejava.core.httpclient.HttpClient)} - */ - @Deprecated - @Override - public OdnoklassnikiOAuthService createService(String apiKey, String apiSecret, String callback, - String defaultScope, String responseType, String userAgent, HttpClientConfig httpClientConfig, - HttpClient httpClient) { - return createService(apiKey, apiSecret, callback, defaultScope, responseType, null, userAgent, httpClientConfig, - httpClient); - } - @Override public OdnoklassnikiOAuthService createService(String apiKey, String apiSecret, String callback, String defaultScope, String responseType, OutputStream debugStream, String userAgent, diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/WunderlistAPI.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/WunderlistAPI.java index 97b28d279..abf19db92 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/WunderlistAPI.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/WunderlistAPI.java @@ -48,28 +48,6 @@ public ClientAuthentication getClientAuthentication() { return RequestBodyAuthenticationScheme.instance(); } - /** - * @param apiKey apiKey - * @param apiSecret apiSecret - * @param callback callback - * @param defaultScope defaultScope - * @param responseType responseType - * @param userAgent userAgent - * @param httpClientConfig httpClientConfig - * @param httpClient httpClient - * @return WunderlistOAuthService - * @deprecated use {@link #createService(java.lang.String, java.lang.String, java.lang.String, java.lang.String, - * java.lang.String, java.io.OutputStream, java.lang.String, com.github.scribejava.core.httpclient.HttpClientConfig, - * com.github.scribejava.core.httpclient.HttpClient)} - */ - @Deprecated - @Override - public WunderlistOAuthService createService(String apiKey, String apiSecret, String callback, String defaultScope, - String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - return createService(apiKey, apiSecret, callback, defaultScope, responseType, null, userAgent, httpClientConfig, - httpClient); - } - @Override public WunderlistOAuthService createService(String apiKey, String apiSecret, String callback, String defaultScope, String responseType, OutputStream debugStream, String userAgent, HttpClientConfig httpClientConfig, diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookService.java index f54dedc01..efb53a4f3 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookService.java @@ -15,27 +15,6 @@ public class FacebookService extends OAuth20Service { - /** - * @param api api - * @param apiKey apiKey - * @param apiSecret apiSecret - * @param callback callback - * @param defaultScope defaultScope - * @param responseType responseType - * @param userAgent userAgent - * @param httpClientConfig httpClientConfig - * @param httpClient httpClient - * @deprecated use {@link #FacebookService(com.github.scribejava.apis.FacebookApi, java.lang.String, - * java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.io.OutputStream, java.lang.String, - * com.github.scribejava.core.httpclient.HttpClientConfig, com.github.scribejava.core.httpclient.HttpClient) } - */ - @Deprecated - public FacebookService(FacebookApi api, String apiKey, String apiSecret, String callback, String defaultScope, - String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - this(api, apiKey, apiSecret, callback, defaultScope, responseType, null, userAgent, httpClientConfig, - httpClient); - } - public FacebookService(FacebookApi api, String apiKey, String apiSecret, String callback, String defaultScope, String responseType, OutputStream debugStream, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/imgur/ImgurOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/imgur/ImgurOAuthService.java index e590cee42..317934e35 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/imgur/ImgurOAuthService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/imgur/ImgurOAuthService.java @@ -14,27 +14,6 @@ public class ImgurOAuthService extends OAuth20Service { - /** - * @param api api - * @param apiKey apiKey - * @param apiSecret apiSecret - * @param callback callback - * @param defaultScope defaultScope - * @param responseType responseType - * @param userAgent userAgent - * @param httpClientConfig httpClientConfig - * @param httpClient httpClient - * @deprecated use {@link #ImgurOAuthService(com.github.scribejava.apis.ImgurApi, java.lang.String, - * java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.io.OutputStream, java.lang.String, - * com.github.scribejava.core.httpclient.HttpClientConfig, com.github.scribejava.core.httpclient.HttpClient) } - */ - @Deprecated - public ImgurOAuthService(ImgurApi api, String apiKey, String apiSecret, String callback, String defaultScope, - String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - this(api, apiKey, apiSecret, callback, defaultScope, responseType, null, userAgent, httpClientConfig, - httpClient); - } - public ImgurOAuthService(ImgurApi api, String apiKey, String apiSecret, String callback, String defaultScope, String responseType, OutputStream debugStream, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/mailru/MailruOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/mailru/MailruOAuthService.java index 9a6228177..a9ff7d77b 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/mailru/MailruOAuthService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/mailru/MailruOAuthService.java @@ -18,27 +18,6 @@ public class MailruOAuthService extends OAuth20Service { - /** - * @param api api - * @param apiKey apiKey - * @param apiSecret apiSecret - * @param callback callback - * @param defaultScope defaultScope - * @param responseType responseType - * @param userAgent userAgent - * @param httpClientConfig httpClientConfig - * @param httpClient httpClient - * @deprecated use {@link #MailruOAuthService(com.github.scribejava.apis.MailruApi, java.lang.String, - * java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.io.OutputStream, java.lang.String, - * com.github.scribejava.core.httpclient.HttpClientConfig, com.github.scribejava.core.httpclient.HttpClient) } - */ - @Deprecated - public MailruOAuthService(MailruApi api, String apiKey, String apiSecret, String callback, String defaultScope, - String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - this(api, apiKey, apiSecret, callback, defaultScope, responseType, null, userAgent, httpClientConfig, - httpClient); - } - public MailruOAuthService(MailruApi api, String apiKey, String apiSecret, String callback, String defaultScope, String responseType, OutputStream debugStream, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/odnoklassniki/OdnoklassnikiOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/odnoklassniki/OdnoklassnikiOAuthService.java index 0e012b1a4..fd1327a6d 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/odnoklassniki/OdnoklassnikiOAuthService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/odnoklassniki/OdnoklassnikiOAuthService.java @@ -21,28 +21,6 @@ public class OdnoklassnikiOAuthService extends OAuth20Service { - /** - * @param api api - * @param apiKey apiKey - * @param apiSecret apiSecret - * @param callback callback - * @param defaultScope defaultScope - * @param responseType responseType - * @param userAgent userAgent - * @param httpClientConfig httpClientConfig - * @param httpClient httpClient - * @deprecated use {@link #OdnoklassnikiOAuthService(com.github.scribejava.apis.OdnoklassnikiApi, java.lang.String, - * java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.io.OutputStream, java.lang.String, - * com.github.scribejava.core.httpclient.HttpClientConfig, com.github.scribejava.core.httpclient.HttpClient) } - */ - @Deprecated - public OdnoklassnikiOAuthService(OdnoklassnikiApi api, String apiKey, String apiSecret, String callback, - String defaultScope, String responseType, String userAgent, HttpClientConfig httpClientConfig, - HttpClient httpClient) { - this(api, apiKey, apiSecret, callback, defaultScope, responseType, null, userAgent, httpClientConfig, - httpClient); - } - public OdnoklassnikiOAuthService(OdnoklassnikiApi api, String apiKey, String apiSecret, String callback, String defaultScope, String responseType, OutputStream debugStream, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/wunderlist/WunderlistOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/wunderlist/WunderlistOAuthService.java index e28c910e6..06a248d9c 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/wunderlist/WunderlistOAuthService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/wunderlist/WunderlistOAuthService.java @@ -10,28 +10,6 @@ public class WunderlistOAuthService extends OAuth20Service { - /** - * @param api api - * @param apiKey apiKey - * @param apiSecret apiSecret - * @param callback callback - * @param defaultScope defaultScope - * @param responseType responseType - * @param userAgent userAgent - * @param httpClientConfig httpClientConfig - * @param httpClient httpClient - * @deprecated use {@link #WunderlistOAuthService(com.github.scribejava.apis.WunderlistAPI, java.lang.String, - * java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.io.OutputStream, java.lang.String, - * com.github.scribejava.core.httpclient.HttpClientConfig, com.github.scribejava.core.httpclient.HttpClient) } - */ - @Deprecated - public WunderlistOAuthService(WunderlistAPI api, String apiKey, String apiSecret, String callback, - String defaultScope, String responseType, String userAgent, HttpClientConfig httpClientConfig, - HttpClient httpClient) { - this(api, apiKey, apiSecret, callback, defaultScope, responseType, null, userAgent, httpClientConfig, - httpClient); - } - public WunderlistOAuthService(WunderlistAPI api, String apiKey, String apiSecret, String callback, String defaultScope, String responseType, OutputStream debugStream, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java index 8c69ce2f5..64ad82f00 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java @@ -107,28 +107,6 @@ public String getAuthorizationUrl(String responseType, String apiKey, String cal return parameters.appendTo(getAuthorizationBaseUrl()); } - /** - * - * @param apiKey apiKey - * @param apiSecret apiSecret - * @param callback callback - * @param defaultScope defaultScope - * @param responseType responseType - * @param userAgent userAgent - * @param httpClientConfig httpClientConfig - * @param httpClient httpClient - * @return OAuth20Service - * @deprecated use {@link #createService(java.lang.String, java.lang.String, java.lang.String, java.lang.String, - * java.lang.String, java.io.OutputStream, java.lang.String, com.github.scribejava.core.httpclient.HttpClientConfig, - * com.github.scribejava.core.httpclient.HttpClient)} - */ - @Deprecated - public OAuth20Service createService(String apiKey, String apiSecret, String callback, String defaultScope, - String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - return createService(apiKey, apiSecret, callback, defaultScope, responseType, null, userAgent, httpClientConfig, - httpClient); - } - public OAuth20Service createService(String apiKey, String apiSecret, String callback, String defaultScope, String responseType, OutputStream debugStream, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java index 74997626c..45b95d0a8 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java @@ -28,27 +28,6 @@ public class OAuth20Service extends OAuthService { private final String responseType; private final String defaultScope; - /** - * @param api api - * @param apiKey apiKey - * @param apiSecret apiSecret - * @param callback callback - * @param defaultScope defaultScope - * @param responseType responseType - * @param userAgent userAgent - * @param httpClientConfig httpClientConfig - * @param httpClient httpClient - * @deprecated use {@link #OAuth20Service(com.github.scribejava.core.builder.api.DefaultApi20, java.lang.String, - * java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.io.OutputStream, java.lang.String, - * com.github.scribejava.core.httpclient.HttpClientConfig, com.github.scribejava.core.httpclient.HttpClient)} - */ - @Deprecated - public OAuth20Service(DefaultApi20 api, String apiKey, String apiSecret, String callback, String defaultScope, - String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - this(api, apiKey, apiSecret, callback, defaultScope, responseType, null, userAgent, httpClientConfig, - httpClient); - } - public OAuth20Service(DefaultApi20 api, String apiKey, String apiSecret, String callback, String defaultScope, String responseType, OutputStream debugStream, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java index c8101d504..996abee6f 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java @@ -26,24 +26,6 @@ public abstract class OAuthService implements Closeable { private final HttpClient httpClient; private final OutputStream debugStream; - /** - * - * @param apiKey apiKey - * @param apiSecret apiSecret - * @param callback callback - * @param userAgent userAgent - * @param httpClientConfig httpClientConfig - * @param httpClient httpClient - * @deprecated use {@link #OAuthService(java.lang.String, java.lang.String, java.lang.String, java.io.OutputStream, - * java.lang.String, com.github.scribejava.core.httpclient.HttpClientConfig, - * com.github.scribejava.core.httpclient.HttpClient)} - */ - @Deprecated - public OAuthService(String apiKey, String apiSecret, String callback, String userAgent, - HttpClientConfig httpClientConfig, HttpClient httpClient) { - this(apiKey, apiSecret, callback, null, userAgent, httpClientConfig, httpClient); - } - public OAuthService(String apiKey, String apiSecret, String callback, OutputStream debugStream, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { this.apiKey = apiKey; diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ApiUnit.java b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ApiUnit.java index 6ba3e3e20..cd9e58550 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ApiUnit.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ApiUnit.java @@ -20,28 +20,6 @@ protected String getAuthorizationBaseUrl() { return "http://localhost:8080/authorize"; } - /** - * @param apiKey apiKey - * @param apiSecret apiSecret - * @param callback callback - * @param defaultScope defaultScope - * @param responseType responseType - * @param userAgent userAgent - * @param httpClientConfig httpClientConfig - * @param httpClient httpClient - * @return OAuth20ServiceUnit - * @deprecated use {@link #createService(java.lang.String, java.lang.String, java.lang.String, java.lang.String, - * java.lang.String, java.io.OutputStream, java.lang.String, com.github.scribejava.core.httpclient.HttpClientConfig, - * com.github.scribejava.core.httpclient.HttpClient)} - */ - @Deprecated - @Override - public OAuth20ServiceUnit createService(String apiKey, String apiSecret, String callback, String defaultScope, - String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - return createService(apiKey, apiSecret, callback, defaultScope, responseType, null, userAgent, httpClientConfig, - httpClient); - } - @Override public OAuth20ServiceUnit createService(String apiKey, String apiSecret, String callback, String defaultScope, String responseType, OutputStream debugStream, String userAgent, HttpClientConfig httpClientConfig, diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceUnit.java b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceUnit.java index 12654051d..2766b7f2b 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceUnit.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceUnit.java @@ -23,28 +23,6 @@ class OAuth20ServiceUnit extends OAuth20Service { static final int EXPIRES = 3600; private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); - /** - * @param api api - * @param apiKey apiKey - * @param apiSecret apiSecret - * @param callback callback - * @param defaultScope defaultScope - * @param responseType responseType - * @param userAgent userAgent - * @param httpClientConfig httpClientConfig - * @param httpClient httpClient - * @deprecated use {@link #OAuth20ServiceUnit(com.github.scribejava.core.builder.api.DefaultApi20, java.lang.String, - * java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.io.OutputStream, java.lang.String, - * com.github.scribejava.core.httpclient.HttpClientConfig, com.github.scribejava.core.httpclient.HttpClient)} - */ - @Deprecated - OAuth20ServiceUnit(DefaultApi20 api, String apiKey, String apiSecret, String callback, String defaultScope, - String responseType, String userAgent, HttpClientConfig httpClientConfig, - HttpClient httpClient) { - this(api, apiKey, apiSecret, callback, defaultScope, responseType, null, userAgent, httpClientConfig, - httpClient); - } - OAuth20ServiceUnit(DefaultApi20 api, String apiKey, String apiSecret, String callback, String defaultScope, String responseType, OutputStream debugStream, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { From 3ec1be264e5aea1cbacd462c4a29ec1f6376d69d Mon Sep 17 00:00:00 2001 From: Omari Christian Date: Fri, 16 Aug 2019 15:29:56 -0700 Subject: [PATCH 747/882] Add Javadoc regarding closing body stream --- .../java/com/github/scribejava/core/model/Response.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/Response.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/Response.java index 4a84c76ef..a1781cacb 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/Response.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/Response.java @@ -5,6 +5,12 @@ import java.util.Map; import com.github.scribejava.core.utils.StreamUtils; +/** + * An HTTP response. + * + *

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

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

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

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

    + * @see OAuth 2 Access Token Specification + *

    */ public class OAuth2AccessToken extends Token { diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 36fe35a07..642286105 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -23,7 +23,7 @@ org.asynchttpclient async-http-client - 2.10.1 + 2.10.3 com.github.scribejava diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index 8a327ffc5..efcced401 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -23,7 +23,7 @@ org.apache.httpcomponents httpclient - 4.5.9 + 4.5.10 org.apache.httpcomponents diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index a02806a75..c7935567c 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -23,7 +23,7 @@ com.squareup.okhttp3 okhttp - 4.1.0 + 4.2.0 com.github.scribejava From b33bd573196c6b0119e0fa539d7a70a0c4c21ada Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 4 Oct 2019 14:42:53 +0300 Subject: [PATCH 762/882] prepare v6.9.0 --- README.md | 4 ++-- changelog | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index adabdd45a..1b1f0665c 100644 --- a/README.md +++ b/README.md @@ -131,7 +131,7 @@ You can pull ScribeJava from the central maven repository, just add these to you com.github.scribejava scribejava-apis - 6.8.1 + 6.9.0 ``` @@ -140,7 +140,7 @@ And in case you need just core classes (that's it, without any external API (FB, com.github.scribejava scribejava-core - 6.8.1 + 6.9.0 ``` diff --git a/changelog b/changelog index 9d727dde3..2075c1bc7 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,4 @@ -[SNAPSHOT] +[6.9.0] * Add Xero API (https://www.xero.com/) (thanks to https://github.com/SidneyAllen) [6.8.1] From 16c9cca7b3d3aeb1db60ae7cb3429e7b45d97abf Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 4 Oct 2019 14:44:14 +0300 Subject: [PATCH 763/882] [maven-release-plugin] prepare release scribejava-6.9.0 --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index 2bd9bdd0e..9b835f686 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 6.8.2-SNAPSHOT + 6.9.0 ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -34,7 +34,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - HEAD + scribejava-6.9.0 diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 69eb60aa8..f8a0c8447 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.8.2-SNAPSHOT + 6.9.0 ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 1abb65221..01166a22e 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.8.2-SNAPSHOT + 6.9.0 ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 642286105..9288ea67b 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.8.2-SNAPSHOT + 6.9.0 ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index efcced401..8b8c380d8 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.8.2-SNAPSHOT + 6.9.0 ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index f2ed3cf2d..2d2e7fad0 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.8.2-SNAPSHOT + 6.9.0 ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index c7935567c..bbd6ca92e 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.8.2-SNAPSHOT + 6.9.0 ../pom.xml From b19ba640cd9c37761ff86039519806d94a12660a Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 4 Oct 2019 14:44:43 +0300 Subject: [PATCH 764/882] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index 9b835f686..72ffeb5e1 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 6.9.0 + 6.9.1-SNAPSHOT ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -34,7 +34,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - scribejava-6.9.0 + HEAD diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index f8a0c8447..fe2dd76c0 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.9.0 + 6.9.1-SNAPSHOT ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 01166a22e..0fc1965c9 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.9.0 + 6.9.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 9288ea67b..7ac157bd8 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.9.0 + 6.9.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index 8b8c380d8..ecb3a4390 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.9.0 + 6.9.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index 2d2e7fad0..1bf4a7f51 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.9.0 + 6.9.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index bbd6ca92e..e468d46fe 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.9.0 + 6.9.1-SNAPSHOT ../pom.xml From ea42bc94876e58d0730e3b871b095878f3f6fc49 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 14 Oct 2019 14:20:14 +0300 Subject: [PATCH 765/882] upgrade okhttp 4.2.0 -> 4.2.2 --- pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 72ffeb5e1..88210b98e 100644 --- a/pom.xml +++ b/pom.xml @@ -67,7 +67,7 @@ com.squareup.okhttp3 mockwebserver - 4.2.0 + 4.2.2 test diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index e468d46fe..7ac66ff5c 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -23,7 +23,7 @@ com.squareup.okhttp3 okhttp - 4.2.0 + 4.2.2 com.github.scribejava From 3a095e2471b6a24bb2e74a6b7bf95a63d98ce387 Mon Sep 17 00:00:00 2001 From: Alex Vidrean Date: Tue, 15 Oct 2019 19:23:46 +0300 Subject: [PATCH 766/882] feat: added polar oauth2 api and example --- .../github/scribejava/apis/PolarAPI20.java | 54 ++++++++++++ .../apis/polar/PolarJsonTokenExtractor.java | 49 +++++++++++ .../apis/polar/PolarOAuth20Service.java | 45 ++++++++++ .../apis/polar/PolarOauth2AccessToken.java | 45 ++++++++++ .../apis/examples/PolarAPI20Example.java | 83 +++++++++++++++++++ 5 files changed, 276 insertions(+) create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/PolarAPI20.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/polar/PolarJsonTokenExtractor.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/polar/PolarOAuth20Service.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/polar/PolarOauth2AccessToken.java create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PolarAPI20Example.java diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/PolarAPI20.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/PolarAPI20.java new file mode 100644 index 000000000..ba3026953 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/PolarAPI20.java @@ -0,0 +1,54 @@ +package com.github.scribejava.apis; + +import com.github.scribejava.apis.polar.PolarJsonTokenExtractor; +import com.github.scribejava.apis.polar.PolarOAuth20Service; +import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.extractors.TokenExtractor; +import com.github.scribejava.core.httpclient.HttpClient; +import com.github.scribejava.core.httpclient.HttpClientConfig; +import com.github.scribejava.core.model.OAuth2AccessToken; +import com.github.scribejava.core.oauth.OAuth20Service; + +import java.io.OutputStream; + +/** + * Polar's OAuth2 client's implementation + * source: https://www.polar.com/accesslink-api/#authentication + */ +public class PolarAPI20 extends DefaultApi20 { + + protected PolarAPI20() { + } + + private static class InstanceHolder { + + private static final PolarAPI20 INSTANCE = new PolarAPI20(); + } + + public static PolarAPI20 instance() { + return PolarAPI20.InstanceHolder.INSTANCE; + } + + @Override + public String getAccessTokenEndpoint() { + return "https://polarremote.com/v2/oauth2/token"; + } + + @Override + protected String getAuthorizationBaseUrl() { + return "https://flow.polar.com/oauth2/authorization"; + } + + @Override + public OAuth20Service createService(String apiKey, String apiSecret, String callback, String defaultScope, String responseType, + OutputStream debugStream, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { + + return new PolarOAuth20Service(this, apiKey, apiSecret, callback, defaultScope, responseType, debugStream, userAgent, + httpClientConfig, httpClient); + } + + @Override + public TokenExtractor getAccessTokenExtractor() { + return PolarJsonTokenExtractor.instance(); + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/polar/PolarJsonTokenExtractor.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/polar/PolarJsonTokenExtractor.java new file mode 100644 index 000000000..dbfee8be2 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/polar/PolarJsonTokenExtractor.java @@ -0,0 +1,49 @@ +package com.github.scribejava.apis.polar; + +import com.fasterxml.jackson.databind.JsonNode; +import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; +import com.github.scribejava.core.model.OAuth2AccessTokenErrorResponse; +import com.github.scribejava.core.oauth2.OAuth2Error; + +import java.io.IOException; + +/** + * Token related documentation: https://www.polar.com/accesslink-api/#token-endpoint + */ +public class PolarJsonTokenExtractor extends OAuth2AccessTokenJsonExtractor { + + protected PolarJsonTokenExtractor() { + } + + private static class InstanceHolder { + + private static final PolarJsonTokenExtractor INSTANCE = new PolarJsonTokenExtractor(); + } + + public static PolarJsonTokenExtractor instance() { + return InstanceHolder.INSTANCE; + } + + @Override + protected PolarOauth2AccessToken createToken(String accessToken, String tokenType, Integer expiresIn, + String refreshToken, String scope, JsonNode response, String rawResponse) { + return new PolarOauth2AccessToken(accessToken, tokenType, expiresIn, refreshToken, scope, + response.get("x_user_id").asText(), rawResponse); + } + + @Override + public void generateError(String rawResponse) throws IOException { + final JsonNode errorNode = OAuth2AccessTokenJsonExtractor.OBJECT_MAPPER.readTree(rawResponse) + .get("errors").get(0); + + OAuth2Error errorCode; + try { + errorCode = OAuth2Error.parseFrom(extractRequiredParameter(errorNode, "errorType", rawResponse).asText()); + } catch (IllegalArgumentException iaE) { + //non oauth standard error code + errorCode = null; + } + + throw new OAuth2AccessTokenErrorResponse(errorCode, errorNode.get("message").asText(), null, rawResponse); + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/polar/PolarOAuth20Service.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/polar/PolarOAuth20Service.java new file mode 100644 index 000000000..238b31084 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/polar/PolarOAuth20Service.java @@ -0,0 +1,45 @@ +package com.github.scribejava.apis.polar; + +import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.httpclient.HttpClient; +import com.github.scribejava.core.httpclient.HttpClientConfig; +import com.github.scribejava.core.model.OAuthConstants; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.oauth.AccessTokenRequestParams; +import com.github.scribejava.core.oauth.OAuth20Service; +import com.github.scribejava.core.pkce.PKCE; + +import java.io.OutputStream; + +public class PolarOAuth20Service extends OAuth20Service { + + public PolarOAuth20Service(DefaultApi20 api, String apiKey, String apiSecret, String callback, String defaultScope, String responseType, + OutputStream debugStream, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { + super(api, apiKey, apiSecret, callback, defaultScope, responseType, debugStream, userAgent, httpClientConfig, httpClient); + } + + @Override + protected OAuthRequest createAccessTokenRequest(AccessTokenRequestParams params) { + final OAuthRequest request = new OAuthRequest(getApi().getAccessTokenVerb(), getApi().getAccessTokenEndpoint()); + + getApi().getClientAuthentication().addClientAuthentication(request, getApiKey(), getApiSecret()); + + request.addBodyParameter(OAuthConstants.CODE, params.getCode()); + final String callback = getCallback(); + if (callback != null) { + request.addBodyParameter(OAuthConstants.REDIRECT_URI, callback); + } + request.addBodyParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.AUTHORIZATION_CODE); + + final String pkceCodeVerifier = params.getPkceCodeVerifier(); + if (pkceCodeVerifier != null) { + request.addBodyParameter(PKCE.PKCE_CODE_VERIFIER_PARAM, pkceCodeVerifier); + } + if (isDebug()) { + log("created access token request with body params [%s], query string params [%s]", + request.getBodyParams().asFormUrlEncodedString(), + request.getQueryStringParams().asFormUrlEncodedString()); + } + return request; + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/polar/PolarOauth2AccessToken.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/polar/PolarOauth2AccessToken.java new file mode 100644 index 000000000..ca1d84b1f --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/polar/PolarOauth2AccessToken.java @@ -0,0 +1,45 @@ +package com.github.scribejava.apis.polar; + +import com.github.scribejava.core.model.OAuth2AccessToken; + +import java.util.Objects; + +public class PolarOauth2AccessToken extends OAuth2AccessToken { + + private String userId; + + public PolarOauth2AccessToken( + String accessToken, String tokenType, Integer expiresIn, String refreshToken, String scope, String userId, String rawResponse) { + super(accessToken, tokenType, expiresIn, refreshToken, scope, rawResponse); + this.userId = userId; + } + + public String getUserId() { + return userId; + } + + @Override + public int hashCode() { + int hash = super.hashCode(); + hash = 37 * hash + Objects.hashCode(userId); + return hash; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + if (!super.equals(obj)) { + return false; + } + + return Objects.equals(userId, ((PolarOauth2AccessToken) obj).getUserId()); + } +} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PolarAPI20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PolarAPI20Example.java new file mode 100644 index 000000000..376ab6e85 --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PolarAPI20Example.java @@ -0,0 +1,83 @@ +package com.github.scribejava.apis.examples; + +import com.github.scribejava.apis.PolarAPI20; +import com.github.scribejava.apis.polar.PolarOauth2AccessToken; +import com.github.scribejava.core.builder.ServiceBuilder; +import com.github.scribejava.core.model.OAuth2AccessToken; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.oauth.OAuth20Service; + +import java.util.Scanner; + +/** + * @author Alex Vidrean + * @since 13-Oct-19 + */ +public class PolarAPI20Example { + + private static final String NETWORK_NAME = "Polar"; + + private static final String PROTECTED_RESOURCE_URL = "https://www.polaraccesslink.com/v3/users/%s"; + + private PolarAPI20Example() { + } + + @SuppressWarnings("PMD.SystemPrintln") + public static void main(String... args) throws Exception { + + // Replace these with your client id and secret fron your app + final String clientId = "1a86ac29-7ea3-473a-81d9-8ea582214558"; + final String clientSecret = "0dc23e1d-b677-4da0-bb14-311949898a95"; + final String scope = "accesslink.read_all"; + final String callback = "http://localhost"; + final OAuth20Service service = new ServiceBuilder(clientId).apiSecret(clientSecret).defaultScope(scope) + //your callback URL to store and handle the authorization code sent by Polar + .callback(callback).build(PolarAPI20.instance()); + final Scanner in = new Scanner(System.in); + + System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); + System.out.println(); + + // Obtain the Authorization URL + System.out.println("Fetching the Authorization URL..."); + final String authorizationUrl = service.getAuthorizationUrl("some_params"); + System.out.println("Got the Authorization URL!"); + System.out.println("Now go and authorize ScribeJava here:"); + System.out.println(authorizationUrl); + System.out.println("And paste the authorization code here"); + System.out.print(">>"); + final String code = in.nextLine(); + System.out.println(); + + System.out.println("Trading the Authorization Code for an Access Token..."); + System.out.println("Got the Access Token!"); + final OAuth2AccessToken oauth2AccessToken = service.getAccessToken(code); + System.out.println("(if your curious it looks like this: " + oauth2AccessToken + ", 'rawResponse'='" + oauth2AccessToken.getRawResponse() + "')"); + System.out.println(); + + if (!(oauth2AccessToken instanceof PolarOauth2AccessToken)) { + System.out.println("oauth2AccessToken is not instance of PolarOAuth2AccessToken. Strange enough. exit."); + return; + } + + final PolarOauth2AccessToken accessToken = (PolarOauth2AccessToken) oauth2AccessToken; + + // Now let's go and ask for a protected resource! + // This will get the profile for this user + System.out.println("Now we're going to access a protected resource..."); + + final OAuthRequest request = new OAuthRequest(Verb.GET, String.format(PROTECTED_RESOURCE_URL, accessToken.getUserId())); + request.addHeader("Accept", "application/json"); + + service.signRequest(accessToken, request); + + System.out.println(); + try (Response response = service.execute(request)) { + System.out.println(response.getCode()); + System.out.println(response.getBody()); + } + System.out.println(); + } +} From 443c243589dbe8fdb6ca450aa3cefa5b7689cd86 Mon Sep 17 00:00:00 2001 From: Alex Vidrean Date: Sun, 20 Oct 2019 11:19:57 +0300 Subject: [PATCH 767/882] refactor: revert adding polar parameters for access token call to BodyParameter fix: removed actual client id and secret from polar example --- .../github/scribejava/apis/polar/PolarOAuth20Service.java | 8 ++++---- .../scribejava/apis/examples/PolarAPI20Example.java | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/polar/PolarOAuth20Service.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/polar/PolarOAuth20Service.java index 238b31084..3b1bbca0c 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/polar/PolarOAuth20Service.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/polar/PolarOAuth20Service.java @@ -24,16 +24,16 @@ protected OAuthRequest createAccessTokenRequest(AccessTokenRequestParams params) getApi().getClientAuthentication().addClientAuthentication(request, getApiKey(), getApiSecret()); - request.addBodyParameter(OAuthConstants.CODE, params.getCode()); + request.addParameter(OAuthConstants.CODE, params.getCode()); final String callback = getCallback(); if (callback != null) { - request.addBodyParameter(OAuthConstants.REDIRECT_URI, callback); + request.addParameter(OAuthConstants.REDIRECT_URI, callback); } - request.addBodyParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.AUTHORIZATION_CODE); + request.addParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.AUTHORIZATION_CODE); final String pkceCodeVerifier = params.getPkceCodeVerifier(); if (pkceCodeVerifier != null) { - request.addBodyParameter(PKCE.PKCE_CODE_VERIFIER_PARAM, pkceCodeVerifier); + request.addParameter(PKCE.PKCE_CODE_VERIFIER_PARAM, pkceCodeVerifier); } if (isDebug()) { log("created access token request with body params [%s], query string params [%s]", diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PolarAPI20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PolarAPI20Example.java index 376ab6e85..3b670de1d 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PolarAPI20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PolarAPI20Example.java @@ -28,10 +28,10 @@ private PolarAPI20Example() { public static void main(String... args) throws Exception { // Replace these with your client id and secret fron your app - final String clientId = "1a86ac29-7ea3-473a-81d9-8ea582214558"; - final String clientSecret = "0dc23e1d-b677-4da0-bb14-311949898a95"; + final String clientId = "your api client"; + final String clientSecret = "your api secret"; final String scope = "accesslink.read_all"; - final String callback = "http://localhost"; + final String callback = "your api callback"; final OAuth20Service service = new ServiceBuilder(clientId).apiSecret(clientSecret).defaultScope(scope) //your callback URL to store and handle the authorization code sent by Polar .callback(callback).build(PolarAPI20.instance()); From cca662cb770b8920e52e2a2a6dcf822db8d5e0e2 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 21 Oct 2019 15:52:24 +0300 Subject: [PATCH 768/882] Add Polar API (https://www.polar.com/) (thanks to https://github.com/vidi42) --- README.md | 1 + changelog | 3 + .../com/github/scribejava/apis/PolarAPI.java | 53 ++++++++++++ .../github/scribejava/apis/PolarAPI20.java | 54 ------------ .../apis/polar/PolarJsonTokenExtractor.java | 4 +- .../apis/polar/PolarOAuth20Service.java | 45 ---------- .../apis/polar/PolarOAuth2AccessToken.java | 45 ++++++++++ .../apis/polar/PolarOAuthService.java | 47 +++++++++++ .../apis/polar/PolarOauth2AccessToken.java | 45 ---------- .../apis/examples/PolarAPI20Example.java | 83 ------------------- .../apis/examples/PolarAPIExample.java | 82 ++++++++++++++++++ 11 files changed, 233 insertions(+), 229 deletions(-) create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/PolarAPI.java delete mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/PolarAPI20.java delete mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/polar/PolarOAuth20Service.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/polar/PolarOAuth2AccessToken.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/polar/PolarOAuthService.java delete mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/polar/PolarOauth2AccessToken.java delete mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PolarAPI20Example.java create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PolarAPIExample.java diff --git a/README.md b/README.md index 1b1f0665c..199e1c7a5 100644 --- a/README.md +++ b/README.md @@ -87,6 +87,7 @@ ScribeJava support out-of-box several HTTP clients: * Misfit (http://misfit.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MisfitExample.java) * NAVER (http://www.naver.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NaverExample.java) * Odnoklassniki Одноклассники (http://ok.ru/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java) +* Polar (https://www.polar.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PolarAPIExample.java) * Pinterest (https://www.pinterest.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java) * 500px (https://500px.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Px500Example.java) * Renren (http://renren.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java) diff --git a/changelog b/changelog index 2075c1bc7..a8de5b3b2 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,6 @@ +[SNAPSHOT] + * Add Polar API (https://www.polar.com/) (thanks to https://github.com/vidi42) + [6.9.0] * Add Xero API (https://www.xero.com/) (thanks to https://github.com/SidneyAllen) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/PolarAPI.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/PolarAPI.java new file mode 100644 index 000000000..01e1651c6 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/PolarAPI.java @@ -0,0 +1,53 @@ +package com.github.scribejava.apis; + +import com.github.scribejava.apis.polar.PolarJsonTokenExtractor; +import com.github.scribejava.apis.polar.PolarOAuthService; +import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.extractors.TokenExtractor; +import com.github.scribejava.core.httpclient.HttpClient; +import com.github.scribejava.core.httpclient.HttpClientConfig; +import com.github.scribejava.core.model.OAuth2AccessToken; + +import java.io.OutputStream; + +/** + * Polar's OAuth2 client's implementation source: https://www.polar.com/accesslink-api/#authentication + */ +public class PolarAPI extends DefaultApi20 { + + protected PolarAPI() { + } + + private static class InstanceHolder { + + private static final PolarAPI INSTANCE = new PolarAPI(); + } + + public static PolarAPI instance() { + return PolarAPI.InstanceHolder.INSTANCE; + } + + @Override + public String getAccessTokenEndpoint() { + return "https://polarremote.com/v2/oauth2/token"; + } + + @Override + protected String getAuthorizationBaseUrl() { + return "https://flow.polar.com/oauth2/authorization"; + } + + @Override + public PolarOAuthService createService(String apiKey, String apiSecret, String callback, String defaultScope, + String responseType, OutputStream debugStream, String userAgent, HttpClientConfig httpClientConfig, + HttpClient httpClient) { + + return new PolarOAuthService(this, apiKey, apiSecret, callback, defaultScope, responseType, debugStream, + userAgent, httpClientConfig, httpClient); + } + + @Override + public TokenExtractor getAccessTokenExtractor() { + return PolarJsonTokenExtractor.instance(); + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/PolarAPI20.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/PolarAPI20.java deleted file mode 100644 index ba3026953..000000000 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/PolarAPI20.java +++ /dev/null @@ -1,54 +0,0 @@ -package com.github.scribejava.apis; - -import com.github.scribejava.apis.polar.PolarJsonTokenExtractor; -import com.github.scribejava.apis.polar.PolarOAuth20Service; -import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.extractors.TokenExtractor; -import com.github.scribejava.core.httpclient.HttpClient; -import com.github.scribejava.core.httpclient.HttpClientConfig; -import com.github.scribejava.core.model.OAuth2AccessToken; -import com.github.scribejava.core.oauth.OAuth20Service; - -import java.io.OutputStream; - -/** - * Polar's OAuth2 client's implementation - * source: https://www.polar.com/accesslink-api/#authentication - */ -public class PolarAPI20 extends DefaultApi20 { - - protected PolarAPI20() { - } - - private static class InstanceHolder { - - private static final PolarAPI20 INSTANCE = new PolarAPI20(); - } - - public static PolarAPI20 instance() { - return PolarAPI20.InstanceHolder.INSTANCE; - } - - @Override - public String getAccessTokenEndpoint() { - return "https://polarremote.com/v2/oauth2/token"; - } - - @Override - protected String getAuthorizationBaseUrl() { - return "https://flow.polar.com/oauth2/authorization"; - } - - @Override - public OAuth20Service createService(String apiKey, String apiSecret, String callback, String defaultScope, String responseType, - OutputStream debugStream, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - - return new PolarOAuth20Service(this, apiKey, apiSecret, callback, defaultScope, responseType, debugStream, userAgent, - httpClientConfig, httpClient); - } - - @Override - public TokenExtractor getAccessTokenExtractor() { - return PolarJsonTokenExtractor.instance(); - } -} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/polar/PolarJsonTokenExtractor.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/polar/PolarJsonTokenExtractor.java index dbfee8be2..efca61631 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/polar/PolarJsonTokenExtractor.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/polar/PolarJsonTokenExtractor.java @@ -25,9 +25,9 @@ public static PolarJsonTokenExtractor instance() { } @Override - protected PolarOauth2AccessToken createToken(String accessToken, String tokenType, Integer expiresIn, + protected PolarOAuth2AccessToken createToken(String accessToken, String tokenType, Integer expiresIn, String refreshToken, String scope, JsonNode response, String rawResponse) { - return new PolarOauth2AccessToken(accessToken, tokenType, expiresIn, refreshToken, scope, + return new PolarOAuth2AccessToken(accessToken, tokenType, expiresIn, refreshToken, scope, response.get("x_user_id").asText(), rawResponse); } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/polar/PolarOAuth20Service.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/polar/PolarOAuth20Service.java deleted file mode 100644 index 3b1bbca0c..000000000 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/polar/PolarOAuth20Service.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.github.scribejava.apis.polar; - -import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.httpclient.HttpClient; -import com.github.scribejava.core.httpclient.HttpClientConfig; -import com.github.scribejava.core.model.OAuthConstants; -import com.github.scribejava.core.model.OAuthRequest; -import com.github.scribejava.core.oauth.AccessTokenRequestParams; -import com.github.scribejava.core.oauth.OAuth20Service; -import com.github.scribejava.core.pkce.PKCE; - -import java.io.OutputStream; - -public class PolarOAuth20Service extends OAuth20Service { - - public PolarOAuth20Service(DefaultApi20 api, String apiKey, String apiSecret, String callback, String defaultScope, String responseType, - OutputStream debugStream, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - super(api, apiKey, apiSecret, callback, defaultScope, responseType, debugStream, userAgent, httpClientConfig, httpClient); - } - - @Override - protected OAuthRequest createAccessTokenRequest(AccessTokenRequestParams params) { - final OAuthRequest request = new OAuthRequest(getApi().getAccessTokenVerb(), getApi().getAccessTokenEndpoint()); - - getApi().getClientAuthentication().addClientAuthentication(request, getApiKey(), getApiSecret()); - - request.addParameter(OAuthConstants.CODE, params.getCode()); - final String callback = getCallback(); - if (callback != null) { - request.addParameter(OAuthConstants.REDIRECT_URI, callback); - } - request.addParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.AUTHORIZATION_CODE); - - final String pkceCodeVerifier = params.getPkceCodeVerifier(); - if (pkceCodeVerifier != null) { - request.addParameter(PKCE.PKCE_CODE_VERIFIER_PARAM, pkceCodeVerifier); - } - if (isDebug()) { - log("created access token request with body params [%s], query string params [%s]", - request.getBodyParams().asFormUrlEncodedString(), - request.getQueryStringParams().asFormUrlEncodedString()); - } - return request; - } -} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/polar/PolarOAuth2AccessToken.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/polar/PolarOAuth2AccessToken.java new file mode 100644 index 000000000..d9ea04035 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/polar/PolarOAuth2AccessToken.java @@ -0,0 +1,45 @@ +package com.github.scribejava.apis.polar; + +import com.github.scribejava.core.model.OAuth2AccessToken; + +import java.util.Objects; + +public class PolarOAuth2AccessToken extends OAuth2AccessToken { + + private final String userId; + + public PolarOAuth2AccessToken(String accessToken, String tokenType, Integer expiresIn, String refreshToken, + String scope, String userId, String rawResponse) { + super(accessToken, tokenType, expiresIn, refreshToken, scope, rawResponse); + this.userId = userId; + } + + public String getUserId() { + return userId; + } + + @Override + public int hashCode() { + int hash = super.hashCode(); + hash = 37 * hash + Objects.hashCode(userId); + return hash; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + if (!super.equals(obj)) { + return false; + } + + return Objects.equals(userId, ((PolarOAuth2AccessToken) obj).getUserId()); + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/polar/PolarOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/polar/PolarOAuthService.java new file mode 100644 index 000000000..e0b0af6f1 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/polar/PolarOAuthService.java @@ -0,0 +1,47 @@ +package com.github.scribejava.apis.polar; + +import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.httpclient.HttpClient; +import com.github.scribejava.core.httpclient.HttpClientConfig; +import com.github.scribejava.core.model.OAuthConstants; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.oauth.AccessTokenRequestParams; +import com.github.scribejava.core.oauth.OAuth20Service; +import com.github.scribejava.core.pkce.PKCE; + +import java.io.OutputStream; + +public class PolarOAuthService extends OAuth20Service { + + public PolarOAuthService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String defaultScope, + String responseType, OutputStream debugStream, String userAgent, HttpClientConfig httpClientConfig, + HttpClient httpClient) { + super(api, apiKey, apiSecret, callback, defaultScope, responseType, debugStream, userAgent, httpClientConfig, + httpClient); + } + + @Override + protected OAuthRequest createAccessTokenRequest(AccessTokenRequestParams params) { + final OAuthRequest request = new OAuthRequest(getApi().getAccessTokenVerb(), getApi().getAccessTokenEndpoint()); + + getApi().getClientAuthentication().addClientAuthentication(request, getApiKey(), getApiSecret()); + + request.addParameter(OAuthConstants.CODE, params.getCode()); + final String callback = getCallback(); + if (callback != null) { + request.addParameter(OAuthConstants.REDIRECT_URI, callback); + } + request.addParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.AUTHORIZATION_CODE); + + final String pkceCodeVerifier = params.getPkceCodeVerifier(); + if (pkceCodeVerifier != null) { + request.addParameter(PKCE.PKCE_CODE_VERIFIER_PARAM, pkceCodeVerifier); + } + if (isDebug()) { + log("created access token request with body params [%s], query string params [%s]", + request.getBodyParams().asFormUrlEncodedString(), + request.getQueryStringParams().asFormUrlEncodedString()); + } + return request; + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/polar/PolarOauth2AccessToken.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/polar/PolarOauth2AccessToken.java deleted file mode 100644 index ca1d84b1f..000000000 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/polar/PolarOauth2AccessToken.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.github.scribejava.apis.polar; - -import com.github.scribejava.core.model.OAuth2AccessToken; - -import java.util.Objects; - -public class PolarOauth2AccessToken extends OAuth2AccessToken { - - private String userId; - - public PolarOauth2AccessToken( - String accessToken, String tokenType, Integer expiresIn, String refreshToken, String scope, String userId, String rawResponse) { - super(accessToken, tokenType, expiresIn, refreshToken, scope, rawResponse); - this.userId = userId; - } - - public String getUserId() { - return userId; - } - - @Override - public int hashCode() { - int hash = super.hashCode(); - hash = 37 * hash + Objects.hashCode(userId); - return hash; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - if (!super.equals(obj)) { - return false; - } - - return Objects.equals(userId, ((PolarOauth2AccessToken) obj).getUserId()); - } -} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PolarAPI20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PolarAPI20Example.java deleted file mode 100644 index 3b670de1d..000000000 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PolarAPI20Example.java +++ /dev/null @@ -1,83 +0,0 @@ -package com.github.scribejava.apis.examples; - -import com.github.scribejava.apis.PolarAPI20; -import com.github.scribejava.apis.polar.PolarOauth2AccessToken; -import com.github.scribejava.core.builder.ServiceBuilder; -import com.github.scribejava.core.model.OAuth2AccessToken; -import com.github.scribejava.core.model.OAuthRequest; -import com.github.scribejava.core.model.Response; -import com.github.scribejava.core.model.Verb; -import com.github.scribejava.core.oauth.OAuth20Service; - -import java.util.Scanner; - -/** - * @author Alex Vidrean - * @since 13-Oct-19 - */ -public class PolarAPI20Example { - - private static final String NETWORK_NAME = "Polar"; - - private static final String PROTECTED_RESOURCE_URL = "https://www.polaraccesslink.com/v3/users/%s"; - - private PolarAPI20Example() { - } - - @SuppressWarnings("PMD.SystemPrintln") - public static void main(String... args) throws Exception { - - // Replace these with your client id and secret fron your app - final String clientId = "your api client"; - final String clientSecret = "your api secret"; - final String scope = "accesslink.read_all"; - final String callback = "your api callback"; - final OAuth20Service service = new ServiceBuilder(clientId).apiSecret(clientSecret).defaultScope(scope) - //your callback URL to store and handle the authorization code sent by Polar - .callback(callback).build(PolarAPI20.instance()); - final Scanner in = new Scanner(System.in); - - System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); - System.out.println(); - - // Obtain the Authorization URL - System.out.println("Fetching the Authorization URL..."); - final String authorizationUrl = service.getAuthorizationUrl("some_params"); - System.out.println("Got the Authorization URL!"); - System.out.println("Now go and authorize ScribeJava here:"); - System.out.println(authorizationUrl); - System.out.println("And paste the authorization code here"); - System.out.print(">>"); - final String code = in.nextLine(); - System.out.println(); - - System.out.println("Trading the Authorization Code for an Access Token..."); - System.out.println("Got the Access Token!"); - final OAuth2AccessToken oauth2AccessToken = service.getAccessToken(code); - System.out.println("(if your curious it looks like this: " + oauth2AccessToken + ", 'rawResponse'='" + oauth2AccessToken.getRawResponse() + "')"); - System.out.println(); - - if (!(oauth2AccessToken instanceof PolarOauth2AccessToken)) { - System.out.println("oauth2AccessToken is not instance of PolarOAuth2AccessToken. Strange enough. exit."); - return; - } - - final PolarOauth2AccessToken accessToken = (PolarOauth2AccessToken) oauth2AccessToken; - - // Now let's go and ask for a protected resource! - // This will get the profile for this user - System.out.println("Now we're going to access a protected resource..."); - - final OAuthRequest request = new OAuthRequest(Verb.GET, String.format(PROTECTED_RESOURCE_URL, accessToken.getUserId())); - request.addHeader("Accept", "application/json"); - - service.signRequest(accessToken, request); - - System.out.println(); - try (Response response = service.execute(request)) { - System.out.println(response.getCode()); - System.out.println(response.getBody()); - } - System.out.println(); - } -} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PolarAPIExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PolarAPIExample.java new file mode 100644 index 000000000..501a8e470 --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PolarAPIExample.java @@ -0,0 +1,82 @@ +package com.github.scribejava.apis.examples; + +import com.github.scribejava.apis.PolarAPI; +import com.github.scribejava.apis.polar.PolarOAuth2AccessToken; +import com.github.scribejava.core.builder.ServiceBuilder; +import com.github.scribejava.core.model.OAuth2AccessToken; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.oauth.OAuth20Service; + +import java.util.Scanner; + +public class PolarAPIExample { + + private static final String NETWORK_NAME = "Polar"; + + private static final String PROTECTED_RESOURCE_URL = "https://www.polaraccesslink.com/v3/users/%s"; + + private PolarAPIExample() { + } + + @SuppressWarnings("PMD.SystemPrintln") + public static void main(String... args) throws Exception { + final String clientId = "your_api_client"; + final String clientSecret = "your_api_secret"; + final String scope = "accesslink.read_all"; + final String callback = "your_api_callback"; + final OAuth20Service service = new ServiceBuilder(clientId) + .apiSecret(clientSecret) + .defaultScope(scope) + //your callback URL to store and handle the authorization code sent by Polar + .callback(callback) + .build(PolarAPI.instance()); + final Scanner in = new Scanner(System.in); + + System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); + System.out.println(); + + // Obtain the Authorization URL + System.out.println("Fetching the Authorization URL..."); + final String authorizationUrl = service.getAuthorizationUrl("some_params"); + System.out.println("Got the Authorization URL!"); + System.out.println("Now go and authorize ScribeJava here:"); + System.out.println(authorizationUrl); + System.out.println("And paste the authorization code here"); + System.out.print(">>"); + final String code = in.nextLine(); + System.out.println(); + + System.out.println("Trading the Authorization Code for an Access Token..."); + System.out.println("Got the Access Token!"); + final OAuth2AccessToken oauth2AccessToken = service.getAccessToken(code); + System.out.println("(if your curious it looks like this: " + oauth2AccessToken + + ", 'rawResponse'='" + oauth2AccessToken.getRawResponse() + "')"); + System.out.println(); + + if (!(oauth2AccessToken instanceof PolarOAuth2AccessToken)) { + System.out.println("oauth2AccessToken is not instance of PolarOAuth2AccessToken. Strange enough. exit."); + return; + } + + final PolarOAuth2AccessToken accessToken = (PolarOAuth2AccessToken) oauth2AccessToken; + + // Now let's go and ask for a protected resource! + // This will get the profile for this user + System.out.println("Now we're going to access a protected resource..."); + + final OAuthRequest request = new OAuthRequest(Verb.GET, String.format(PROTECTED_RESOURCE_URL, + accessToken.getUserId())); + request.addHeader("Accept", "application/json"); + + service.signRequest(accessToken, request); + + System.out.println(); + try (Response response = service.execute(request)) { + System.out.println(response.getCode()); + System.out.println(response.getBody()); + } + System.out.println(); + } +} From 3f1cd63ae5c41dacffced9fc0d73446af9f1ca89 Mon Sep 17 00:00:00 2001 From: bjournaud Date: Thu, 23 Jan 2020 18:15:46 +0100 Subject: [PATCH 769/882] Add proxy option to JDKHttpClient --- .../scribejava/core/httpclient/jdk/JDKHttpClient.java | 7 ++++++- .../core/httpclient/jdk/JDKHttpClientConfig.java | 11 +++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java index 3f4648a77..25212977c 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java @@ -115,7 +115,12 @@ public Response execute(String userAgent, Map headers, Verb http private Response doExecute(String userAgent, Map headers, Verb httpVerb, String completeUrl, BodyType bodyType, Object bodyContents) throws IOException { - final HttpURLConnection connection = (HttpURLConnection) new URL(completeUrl).openConnection(); + final HttpURLConnection connection; + if (config.getProxy() == null) { + connection = (HttpURLConnection) new URL(completeUrl).openConnection(); + }else { + connection = (HttpURLConnection) new URL(completeUrl).openConnection(config.getProxy()); + } connection.setInstanceFollowRedirects(config.isFollowRedirects()); connection.setRequestMethod(httpVerb.name()); if (config.getConnectTimeout() != null) { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClientConfig.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClientConfig.java index cfb97b359..baa431b83 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClientConfig.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClientConfig.java @@ -1,5 +1,7 @@ package com.github.scribejava.core.httpclient.jdk; +import java.net.Proxy; + import com.github.scribejava.core.httpclient.HttpClientConfig; public class JDKHttpClientConfig implements HttpClientConfig { @@ -7,6 +9,7 @@ public class JDKHttpClientConfig implements HttpClientConfig { private Integer connectTimeout; private Integer readTimeout; private boolean followRedirects = true; + private Proxy proxy; @Override public JDKHttpClientConfig createDefaultConfig() { @@ -37,6 +40,14 @@ public boolean isFollowRedirects() { return followRedirects; } + public void setProxy(Proxy proxy) { + this.proxy = proxy; + } + + public Proxy getProxy() { + return proxy; + } + /** * Sets whether the underlying Http Connection follows redirects or not. * From 241969cbee80d2bdefe9fcedd97c52dbe5d6899d Mon Sep 17 00:00:00 2001 From: afkbrb <2w6f8c@gmail.com> Date: Sat, 14 Mar 2020 14:09:47 +0800 Subject: [PATCH 770/882] change "Verfier" to "Verifier" --- .../java/com/github/scribejava/apis/examples/AWeberExample.java | 2 +- .../java/com/github/scribejava/apis/examples/DiggExample.java | 2 +- .../java/com/github/scribejava/apis/examples/FlickrExample.java | 2 +- .../com/github/scribejava/apis/examples/FoursquareExample.java | 2 +- .../com/github/scribejava/apis/examples/FreelancerExample.java | 2 +- .../com/github/scribejava/apis/examples/LinkedInExample.java | 2 +- .../scribejava/apis/examples/LinkedInExampleWithScopes.java | 2 +- .../com/github/scribejava/apis/examples/MediaWikiExample.java | 2 +- .../java/com/github/scribejava/apis/examples/MeetupExample.java | 2 +- .../java/com/github/scribejava/apis/examples/Px500Example.java | 2 +- .../com/github/scribejava/apis/examples/SinaWeiboExample.java | 2 +- .../com/github/scribejava/apis/examples/SkyrockExample.java | 2 +- .../java/com/github/scribejava/apis/examples/TrelloExample.java | 2 +- .../java/com/github/scribejava/apis/examples/TumblrExample.java | 2 +- .../com/github/scribejava/apis/examples/TwitterExample.java | 2 +- .../java/com/github/scribejava/apis/examples/UcozExample.java | 2 +- .../java/com/github/scribejava/apis/examples/XingExample.java | 2 +- .../java/com/github/scribejava/apis/examples/YahooExample.java | 2 +- 18 files changed, 18 insertions(+), 18 deletions(-) diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AWeberExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AWeberExample.java index 635017b52..e61110716 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AWeberExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AWeberExample.java @@ -47,7 +47,7 @@ public static void main(String... args) throws IOException, InterruptedException final String oauthVerifier = in.nextLine(); System.out.println(); - // Trade the Request Token and Verfier for the Access Token + // Trade the Request Token and Verifier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiggExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiggExample.java index 1f84a45ed..eb2820683 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiggExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiggExample.java @@ -50,7 +50,7 @@ public static void main(String... args) throws IOException, InterruptedException final String oauthVerifier = in.nextLine(); System.out.println(); - // Trade the Request Token and Verfier for the Access Token + // Trade the Request Token and Verifier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExample.java index 5da371ca6..8cdf8a209 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExample.java @@ -48,7 +48,7 @@ public static void main(String... args) throws IOException, InterruptedException final String oauthVerifier = in.nextLine(); System.out.println(); - // Trade the Request Token and Verfier for the Access Token + // Trade the Request Token and Verifier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FoursquareExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FoursquareExample.java index c7b09ca2e..6aa3c9435 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FoursquareExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FoursquareExample.java @@ -42,7 +42,7 @@ public static void main(String... args) throws IOException, InterruptedException final String oauthVerifier = in.nextLine(); System.out.println(); - // Trade the Request Token and Verfier for the Access Token + // Trade the Request Token and Verifier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java index 019f7efa0..023d789c4 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java @@ -48,7 +48,7 @@ public static void main(String... args) throws IOException, InterruptedException final String oauthVerifier = in.nextLine(); System.out.println(); - // Trade the Request Token and Verfier for the Access Token + // Trade the Request Token and Verifier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java index abb53baf4..ec1051134 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java @@ -43,7 +43,7 @@ public static void main(String... args) throws IOException, InterruptedException final String oauthVerifier = in.nextLine(); System.out.println(); - // Trade the Request Token and Verfier for the Access Token + // Trade the Request Token and Verifier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java index fe2b395ac..3b795de1f 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java @@ -47,7 +47,7 @@ public static void main(String... args) throws IOException, InterruptedException final String oauthVerifier = in.nextLine(); System.out.println(); - // Trade the Request Token and Verfier for the Access Token + // Trade the Request Token and Verifier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MediaWikiExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MediaWikiExample.java index 8aaef6673..621480013 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MediaWikiExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MediaWikiExample.java @@ -48,7 +48,7 @@ public static void main(String... args) throws IOException, InterruptedException final String oauthVerifier = in.nextLine(); System.out.println(); - // Trade the Request Token and Verfier for the Access Token + // Trade the Request Token and Verifier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java index ad6a9bc25..e3c7c8e8c 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java @@ -42,7 +42,7 @@ public static void main(String... args) throws IOException, InterruptedException final String oauthVerifier = in.nextLine(); System.out.println(); - // Trade the Request Token and Verfier for the Access Token + // Trade the Request Token and Verifier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Px500Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Px500Example.java index c9b06f540..e441cebdd 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Px500Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Px500Example.java @@ -42,7 +42,7 @@ public static void main(String... args) throws IOException, InterruptedException final String oauthVerifier = in.nextLine(); System.out.println(); - // Trade the Request Token and Verfier for the Access Token + // Trade the Request Token and Verifier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeiboExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeiboExample.java index d787aa45e..767ccdbab 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeiboExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeiboExample.java @@ -50,7 +50,7 @@ public static void main(String... args) throws IOException, InterruptedException final String oauthVerifier = in.nextLine(); System.out.println(); - // Trade the Request Token and Verfier for the Access Token + // Trade the Request Token and Verifier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SkyrockExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SkyrockExample.java index 84bc61381..f2c0cf007 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SkyrockExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SkyrockExample.java @@ -42,7 +42,7 @@ public static void main(String... args) throws IOException, InterruptedException final String oauthVerifier = in.nextLine(); System.out.println(); - // Trade the Request Token and Verfier for the Access Token + // Trade the Request Token and Verifier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TrelloExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TrelloExample.java index 65f64592e..737bd768e 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TrelloExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TrelloExample.java @@ -44,7 +44,7 @@ public static void main(String... args) throws IOException, InterruptedException final String oauthVerifier = in.nextLine(); System.out.println(); - // Trade the Request Token and Verfier for the Access Token + // Trade the Request Token and Verifier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TumblrExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TumblrExample.java index 3cd648aee..063b8b9b2 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TumblrExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TumblrExample.java @@ -44,7 +44,7 @@ public static void main(String... args) throws IOException, InterruptedException final String oauthVerifier = in.nextLine(); System.out.println(); - // Trade the Request Token and Verfier for the Access Token + // Trade the Request Token and Verifier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TwitterExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TwitterExample.java index 13a86535b..748fa9034 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TwitterExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TwitterExample.java @@ -42,7 +42,7 @@ public static void main(String... args) throws IOException, InterruptedException final String oauthVerifier = in.nextLine(); System.out.println(); - // Trade the Request Token and Verfier for the Access Token + // Trade the Request Token and Verifier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/UcozExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/UcozExample.java index ae3270020..5760bb36a 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/UcozExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/UcozExample.java @@ -37,7 +37,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.print(">>"); final String oauthVerifier = in.nextLine(); System.out.println(); - // Trade the Request Token and Verfier for the Access Token + // Trade the Request Token and Verifier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XingExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XingExample.java index 6850fadab..ebf946db5 100755 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XingExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XingExample.java @@ -42,7 +42,7 @@ public static void main(String... args) throws IOException, InterruptedException final String oauthVerifier = in.nextLine(); System.out.println(); - // Trade the Request Token and Verfier for the Access Token + // Trade the Request Token and Verifier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/YahooExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/YahooExample.java index ccaedba11..acaa42aea 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/YahooExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/YahooExample.java @@ -43,7 +43,7 @@ public static void main(String... args) throws IOException, InterruptedException final String oauthVerifier = in.nextLine(); System.out.println(); - // Trade the Request Token and Verfier for the Access Token + // Trade the Request Token and Verifier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); From a7b01f632ac4283db7b7833d64b17a717de4bee7 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 19 Mar 2020 18:39:32 +0300 Subject: [PATCH 771/882] update deps --- pmd.xml | 2 +- pom.xml | 18 +++--- .../fitbit/FitBitJsonTokenExtractorTest.java | 62 ++++++------------- .../multipart/MultipartPayload.java | 2 +- .../multipart/MultipartPayloadTest.java | 49 ++++++--------- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 8 files changed, 51 insertions(+), 88 deletions(-) diff --git a/pmd.xml b/pmd.xml index 6c204f770..7b5314710 100644 --- a/pmd.xml +++ b/pmd.xml @@ -93,7 +93,7 @@ - + diff --git a/pom.xml b/pom.xml index 88210b98e..a7a764942 100644 --- a/pom.xml +++ b/pom.xml @@ -56,18 +56,18 @@ com.fasterxml.jackson.core jackson-databind - 2.10.0 + 2.10.3 junit junit - 4.12 + 4.13 test com.squareup.okhttp3 mockwebserver - 4.2.2 + 4.4.1 test @@ -91,7 +91,7 @@ org.apache.maven.plugins maven-jar-plugin - 3.1.2 + 3.2.0 ${project.build.outputDirectory}/META-INF/MANIFEST.MF @@ -101,12 +101,12 @@ org.apache.maven.plugins maven-checkstyle-plugin - 3.1.0 + 3.1.1 com.puppycrawl.tools checkstyle - 8.25 + 8.30 @@ -174,7 +174,7 @@ org.apache.maven.plugins maven-source-plugin - 3.1.0 + 3.2.1 attach-sources @@ -227,7 +227,7 @@ org.apache.maven.plugins maven-pmd-plugin - 3.12.0 + 3.13.0 net.sourceforge.pmd @@ -273,7 +273,7 @@ 7 - 6.17.0 + 6.22.0 diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractorTest.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractorTest.java index e717dbd7b..396377294 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractorTest.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractorTest.java @@ -4,58 +4,34 @@ import com.github.scribejava.core.oauth2.OAuth2Error; import java.io.IOException; -import org.hamcrest.FeatureMatcher; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; -import static org.hamcrest.CoreMatchers.equalTo; +import static org.junit.Assert.assertThrows; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertEquals; +import org.junit.function.ThrowingRunnable; public class FitBitJsonTokenExtractorTest { - private static final String ERROR_DESCRIPTION = "Authorization code invalid: " + - "cbb1c11b23209011e89be71201fa6381464dc0af " + - "Visit https://dev.fitbit.com/docs/oauth2 for more information " + - "on the Fitbit Web API authorization process."; - private static final String ERROR_JSON = "{\"errors\":[{\"errorType\":\"invalid_grant\",\"message\":\"" + - ERROR_DESCRIPTION + "\"}],\"success\":false}"; - - @Rule - public ExpectedException thrown = ExpectedException.none(); + private static final String ERROR_DESCRIPTION = "Authorization code invalid: " + + "cbb1c11b23209011e89be71201fa6381464dc0af " + + "Visit https://dev.fitbit.com/docs/oauth2 for more information " + + "on the Fitbit Web API authorization process."; + private static final String ERROR_JSON = "{\"errors\":[{\"errorType\":\"invalid_grant\",\"message\":\"" + + ERROR_DESCRIPTION + "\"}],\"success\":false}"; @Test public void testErrorExtraction() throws IOException { final FitBitJsonTokenExtractor extractor = new FitBitJsonTokenExtractor(); - - thrown.expect(OAuth2AccessTokenErrorResponse.class); - thrown.expect(new ErrorCodeFeatureMatcher(OAuth2Error.INVALID_GRANT)); - thrown.expect(new ErrorDescriptionFeatureMatcher(ERROR_DESCRIPTION)); - - extractor.generateError(ERROR_JSON); - } - - private static class ErrorCodeFeatureMatcher extends FeatureMatcher { - - private ErrorCodeFeatureMatcher(OAuth2Error expected) { - super(equalTo(expected), "a response with errorCode", "errorCode"); - } - - @Override - protected OAuth2Error featureValueOf(OAuth2AccessTokenErrorResponse actual) { - return actual.getError(); - } - } - - private static class ErrorDescriptionFeatureMatcher extends FeatureMatcher { - - private ErrorDescriptionFeatureMatcher(String expected) { - super(equalTo(expected), "a response with errorDescription", "errorDescription"); - } - - @Override - protected String featureValueOf(OAuth2AccessTokenErrorResponse actual) { - return actual.getErrorDescription(); - } + final OAuth2AccessTokenErrorResponse thrown = assertThrows(OAuth2AccessTokenErrorResponse.class, + new ThrowingRunnable() { + @Override + public void run() throws Throwable { + extractor.generateError(ERROR_JSON); + } + }); + assertSame(OAuth2Error.INVALID_GRANT, thrown.getError()); + assertEquals(ERROR_DESCRIPTION, thrown.getErrorDescription()); } } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/MultipartPayload.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/MultipartPayload.java index 5c9282272..7e3f8cfde 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/MultipartPayload.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/MultipartPayload.java @@ -77,7 +77,7 @@ private static Map composeHeaders(String subtype, String boundar static void checkBoundarySyntax(String boundary) { if (boundary == null || !BOUNDARY_REGEXP.matcher(boundary).matches()) { - throw new IllegalArgumentException("{'boundary'='" + boundary + "'} has invaid syntax. Should be '" + throw new IllegalArgumentException("{'boundary'='" + boundary + "'} has invalid syntax. Should be '" + BOUNDARY_PATTERN + "'."); } } diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/httpclient/multipart/MultipartPayloadTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/httpclient/multipart/MultipartPayloadTest.java index a7989a01e..4abc36ee5 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/httpclient/multipart/MultipartPayloadTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/httpclient/multipart/MultipartPayloadTest.java @@ -1,17 +1,14 @@ package com.github.scribejava.core.httpclient.multipart; -import org.hamcrest.core.StringStartsWith; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; -import org.junit.Rule; +import static org.junit.Assert.assertThrows; +import static org.junit.Assert.assertTrue; import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.function.ThrowingRunnable; public class MultipartPayloadTest { - @Rule - public ExpectedException thrown = ExpectedException.none(); - @Test public void testValidCheckBoundarySyntax() { MultipartPayload.checkBoundarySyntax("0aA'()+_,-./:=?"); @@ -22,47 +19,27 @@ public void testValidCheckBoundarySyntax() { @Test public void testNonValidLastWhiteSpaceCheckBoundarySyntax() { - final String boundary = "0aA'()+_,-./:=? "; - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage( - StringStartsWith.startsWith("{'boundary'='" + boundary + "'} has invaid syntax. Should be '")); - MultipartPayload.checkBoundarySyntax(boundary); + testBoundary("0aA'()+_,-./:=? "); } @Test public void testNonValidEmptyCheckBoundarySyntax() { - final String boundary = ""; - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage( - StringStartsWith.startsWith("{'boundary'='" + boundary + "'} has invaid syntax. Should be '")); - MultipartPayload.checkBoundarySyntax(boundary); + testBoundary(""); } @Test public void testNonValidIllegalSymbolCheckBoundarySyntax() { - final String boundary = "0aA'()+_;,-./:=? "; - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage( - StringStartsWith.startsWith("{'boundary'='" + boundary + "'} has invaid syntax. Should be '")); - MultipartPayload.checkBoundarySyntax(boundary); + testBoundary("0aA'()+_;,-./:=? "); } @Test public void testNonValidTooLongCheckBoundarySyntax() { - final String boundary = "12345678901234567890123456789012345678901234567890123456789012345678901"; - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage( - StringStartsWith.startsWith("{'boundary'='" + boundary + "'} has invaid syntax. Should be '")); - MultipartPayload.checkBoundarySyntax(boundary); + testBoundary("12345678901234567890123456789012345678901234567890123456789012345678901"); } @Test public void testNonValidNullCheckBoundarySyntax() { - final String boundary = null; - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage( - StringStartsWith.startsWith("{'boundary'='" + boundary + "'} has invaid syntax. Should be '")); - MultipartPayload.checkBoundarySyntax(boundary); + testBoundary(null); } @Test @@ -118,4 +95,14 @@ public void testParseBoundaryFromHeader() { assertNull(MultipartPayload.parseBoundaryFromHeader("multipart/subtype; boundary=;123")); assertNull(MultipartPayload.parseBoundaryFromHeader("multipart/subtype; boundary=\"\"123")); } + + private static void testBoundary(final String boundary) { + final IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, new ThrowingRunnable() { + @Override + public void run() throws Throwable { + MultipartPayload.checkBoundarySyntax(boundary); + } + }); + assertTrue(thrown.getMessage().startsWith("{'boundary'='" + boundary + "'} has invalid syntax. Should be '")); + } } diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 7ac157bd8..51553b620 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -23,7 +23,7 @@ org.asynchttpclient async-http-client - 2.10.3 + 2.11.0 com.github.scribejava diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index ecb3a4390..7a0933f34 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -23,7 +23,7 @@ org.apache.httpcomponents httpclient - 4.5.10 + 4.5.12 org.apache.httpcomponents diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 7ac66ff5c..33b6da071 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -23,7 +23,7 @@ com.squareup.okhttp3 okhttp - 4.2.2 + 4.4.1 com.github.scribejava From 7bb59c36799a635f526206af010136669f23c33f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0t=C4=9Bp=C3=A1n=20Schejbal?= Date: Mon, 6 Apr 2020 16:00:25 +0200 Subject: [PATCH 772/882] initial support for device flow --- .../BaseMicrosoftAzureActiveDirectoryApi.java | 5 + .../core/builder/api/DefaultApi20.java | 4 + .../OAuth2AccessTokenJsonExtractor.java | 2 +- .../scribejava/core/model/DeviceCode.java | 38 +++++++ .../scribejava/core/oauth/OAuth20Service.java | 100 +++++++++++++++++- .../scribejava/core/oauth2/OAuth2Error.java | 31 +++++- 6 files changed, 172 insertions(+), 8 deletions(-) create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/model/DeviceCode.java diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/microsoftazureactivedirectory/BaseMicrosoftAzureActiveDirectoryApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/microsoftazureactivedirectory/BaseMicrosoftAzureActiveDirectoryApi.java index 5e4891164..8dc5d5616 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/microsoftazureactivedirectory/BaseMicrosoftAzureActiveDirectoryApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/microsoftazureactivedirectory/BaseMicrosoftAzureActiveDirectoryApi.java @@ -30,6 +30,11 @@ protected String getAuthorizationBaseUrl() { return MSFT_LOGIN_URL + tenant + OAUTH_2 + getEndpointVersionPath() + "/authorize"; } + @Override + public String getDeviceAuthorizationUrl() { + return MSFT_LOGIN_URL + tenant + OAUTH_2 + getEndpointVersionPath() + "/devicecode"; + } + @Override public ClientAuthentication getClientAuthentication() { return RequestBodyAuthenticationScheme.instance(); diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java index 64ad82f00..ad1afcc65 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java @@ -121,4 +121,8 @@ public BearerSignature getBearerSignature() { public ClientAuthentication getClientAuthentication() { return HttpBasicAuthenticationScheme.instance(); } + + public String getDeviceAuthorizationUrl() { + return null; + } } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractor.java b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractor.java index b1b8c4536..c2f483e0e 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractor.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractor.java @@ -93,7 +93,7 @@ protected OAuth2AccessToken createToken(String accessToken, String tokenType, In return new OAuth2AccessToken(accessToken, tokenType, expiresIn, refreshToken, scope, rawResponse); } - protected static JsonNode extractRequiredParameter(JsonNode errorNode, String parameterName, String rawResponse) + public static JsonNode extractRequiredParameter(JsonNode errorNode, String parameterName, String rawResponse) throws OAuthException { final JsonNode value = errorNode.get(parameterName); diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/DeviceCode.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/DeviceCode.java new file mode 100644 index 000000000..8e31fc8aa --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/DeviceCode.java @@ -0,0 +1,38 @@ +package com.github.scribejava.core.model; + +public class DeviceCode { + private String deviceCode; + private String userCode; + private String verificationUri; + private int intervalSeconds; + private long expiresAtMillis; + + public DeviceCode(String deviceCode, String userCode, String verificationUri, + int intervalSeconds, int expiresInSeconds) { + this.deviceCode = deviceCode; + this.userCode = userCode; + this.verificationUri = verificationUri; + this.intervalSeconds = intervalSeconds; + expiresAtMillis = System.currentTimeMillis() + (expiresInSeconds * 1000); + } + + public String getDeviceCode() { + return deviceCode; + } + + public String getUserCode() { + return userCode; + } + + public String getVerificationUri() { + return verificationUri; + } + + public int getIntervalSeconds() { + return intervalSeconds; + } + + public long getExpiresAtMillis() { + return expiresAtMillis; + } +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java index 43a5d1a9f..03a803e04 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java @@ -1,27 +1,38 @@ package com.github.scribejava.core.oauth; -import java.io.IOException; -import java.io.OutputStream; -import java.util.concurrent.Future; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.httpclient.HttpClientConfig; +import com.github.scribejava.core.model.DeviceCode; import com.github.scribejava.core.model.OAuth2AccessToken; +import com.github.scribejava.core.model.OAuth2AccessTokenErrorResponse; import com.github.scribejava.core.model.OAuth2Authorization; import com.github.scribejava.core.model.OAuthAsyncRequestCallback; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.oauth2.OAuth2Error; import com.github.scribejava.core.pkce.PKCE; -import java.util.Map; -import java.util.concurrent.ExecutionException; import com.github.scribejava.core.revoke.TokenTypeHint; +import java.io.IOException; +import java.io.OutputStream; import java.io.UnsupportedEncodingException; import java.net.URLDecoder; +import java.util.Map; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Future; + +import static com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor.extractRequiredParameter; +import static com.github.scribejava.core.oauth2.OAuth2Error.AUTHORIZATION_PENDING; +import static com.github.scribejava.core.oauth2.OAuth2Error.SLOW_DOWN; +import static java.lang.Thread.sleep; public class OAuth20Service extends OAuthService { + protected static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); private static final String VERSION = "2.0"; private final DefaultApi20 api; @@ -490,4 +501,83 @@ public String getResponseType() { public String getDefaultScope() { return defaultScope; } + + /** + * Requests a device code from a server. + * + * @see rfc8628 + * @see + * azure v2-oauth2-device-code + */ + public DeviceCode getDeviceCode() throws InterruptedException, ExecutionException, IOException { + final OAuthRequest request = new OAuthRequest(Verb.POST, api.getDeviceAuthorizationUrl()); + request.addBodyParameter(OAuthConstants.CLIENT_ID, getApiKey()); + request.addBodyParameter(OAuthConstants.SCOPE, getDefaultScope()); + try (Response response = execute(request)) { + final String body = response.getBody(); + if (response.getCode() == 200) { + final JsonNode n = OBJECT_MAPPER.readTree(body); + return new DeviceCode( + extractRequiredParameter(n, "device_code", body).textValue(), + extractRequiredParameter(n, "user_code", body).textValue(), + extractRequiredParameter(n, "verification_uri", body).textValue(), + n.path("interval").asInt(5), + extractRequiredParameter(n, "expires_in", body).intValue()); + } else { + OAuth2AccessTokenJsonExtractor.instance().generateError(body); + throw new IllegalStateException(); // generateError() always throws an exception + } + } + } + + /** + * Attempts to get a token from a server. + * Function {@link #pollDeviceAccessToken(DeviceCode)} is usually used instead of this. + * + * @return token + * @throws OAuth2AccessTokenErrorResponse + * If {@link OAuth2AccessTokenErrorResponse#getError()} is + * {@link OAuth2Error#AUTHORIZATION_PENDING} or {@link OAuth2Error#SLOW_DOWN}, + * another attempt should be made after a while. + * + * @see #getDeviceCode() + */ + public OAuth2AccessToken getAccessTokenDeviceCodeGrant(DeviceCode deviceCode) + throws IOException, InterruptedException, ExecutionException { + final OAuthRequest request = new OAuthRequest(Verb.POST, api.getAccessTokenEndpoint()); + request.addParameter(OAuthConstants.GRANT_TYPE, "urn:ietf:params:oauth:grant-type:device_code"); + request.addBodyParameter(OAuthConstants.CLIENT_ID, getApiKey()); + request.addParameter("device_code", deviceCode.getDeviceCode()); + try (Response response = execute(request)) { + return api.getAccessTokenExtractor().extract(response); + } + } + + /** + * Periodically tries to get a token from a server (waiting for the user to give consent). + * + * @return token + * @throws OAuth2AccessTokenErrorResponse + * Indicates OAuth error. + * + * @see #getDeviceCode() + */ + public OAuth2AccessToken pollDeviceAccessToken(DeviceCode deviceCode) + throws InterruptedException, ExecutionException, IOException { + long intervalMillis = deviceCode.getIntervalSeconds() * 1000; + while (true) { + try { + return getAccessTokenDeviceCodeGrant(deviceCode); + } catch (OAuth2AccessTokenErrorResponse e) { + if (e.getError() != AUTHORIZATION_PENDING) { + if (e.getError() == SLOW_DOWN) { + intervalMillis += 5000; + } else { + throw e; + } + } + } + sleep(intervalMillis); + } + } } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth2/OAuth2Error.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth2/OAuth2Error.java index b5a8d89e6..af8f540f8 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth2/OAuth2Error.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth2/OAuth2Error.java @@ -1,5 +1,10 @@ package com.github.scribejava.core.oauth2; +import java.util.EnumSet; +import java.util.Set; + +import static java.util.Collections.unmodifiableSet; + public enum OAuth2Error { /** * @see RFC 6749, 4.1.2.1 Error Response @@ -67,7 +72,29 @@ public enum OAuth2Error { * @see RFC 7009, 4.1. OAuth Extensions Error * Registration */ - UNSUPPORTED_TOKEN_TYPE("unsupported_token_type"); + UNSUPPORTED_TOKEN_TYPE("unsupported_token_type"), + + /** + * @see rfc8628#section-3.5 + */ + AUTHORIZATION_PENDING("authorization_pending"), + + /** + * @see rfc8628#section-3.5 + */ + SLOW_DOWN("slow_down"), + + /** + * @see rfc8628#section-3.5 + */ + EXPIRED_TOKEN("expired_token"), + ; + + /** + * Unlike {@link #values()} which creates a new array every time, this always + * returns the same immutable object. + */ + public static final Set VALUES = unmodifiableSet(EnumSet.allOf(OAuth2Error.class)); private final String errorString; @@ -76,7 +103,7 @@ public enum OAuth2Error { } public static OAuth2Error parseFrom(String errorString) { - for (OAuth2Error error : OAuth2Error.values()) { + for (OAuth2Error error : VALUES) { if (error.errorString.equals(errorString)) { return error; } From a8578ef2142fa2fca616ade32fff19d9d7423bf3 Mon Sep 17 00:00:00 2001 From: v0o0v Date: Thu, 9 Apr 2020 11:56:47 +0900 Subject: [PATCH 773/882] Add Kakao API --- .../com/github/scribejava/apis/KakaoApi.java | 34 +++++++++ .../apis/examples/KakaoExample.java | 70 +++++++++++++++++++ 2 files changed, 104 insertions(+) create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/KakaoApi.java create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/KakaoExample.java diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/KakaoApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/KakaoApi.java new file mode 100644 index 000000000..948705496 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/KakaoApi.java @@ -0,0 +1,34 @@ +package com.github.scribejava.apis; + +import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.oauth2.clientauthentication.ClientAuthentication; +import com.github.scribejava.core.oauth2.clientauthentication.RequestBodyAuthenticationScheme; + +public class KakaoApi extends DefaultApi20 { + + protected KakaoApi() { + } + + private static class InstanceHolder { + private static final KakaoApi INSTANCE = new KakaoApi(); + } + + public static KakaoApi instance() { + return KakaoApi.InstanceHolder.INSTANCE; + } + + @Override + public String getAccessTokenEndpoint() { + return "https://kauth.kakao.com/oauth/token"; + } + + @Override + protected String getAuthorizationBaseUrl() { + return "https://kauth.kakao.com/oauth/authorize"; + } + + @Override + public ClientAuthentication getClientAuthentication() { + return RequestBodyAuthenticationScheme.instance(); + } +} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/KakaoExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/KakaoExample.java new file mode 100644 index 000000000..89b7b4f1d --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/KakaoExample.java @@ -0,0 +1,70 @@ +package com.github.scribejava.apis.examples; + +import com.github.scribejava.apis.KakaoApi; +import com.github.scribejava.core.builder.ServiceBuilder; +import com.github.scribejava.core.model.OAuth2AccessToken; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.oauth.OAuth20Service; + +import java.io.IOException; +import java.util.Scanner; +import java.util.concurrent.ExecutionException; + +public class KakaoExample { + + private static final String NETWORK_NAME = "Kakao"; + private static final String PROTECTED_RESOURCE_URL = "https://kapi.kakao.com/v2/user/me"; + + private KakaoExample() { + } + + @SuppressWarnings("PMD.SystemPrintln") + public static void main(String... args) throws IOException, InterruptedException, ExecutionException { + // Replace these with your client id and secret + final String clientId = "your client id"; + + final OAuth20Service service = new ServiceBuilder(clientId) + .callback("http://www.example.com/oauth_callback/") + .build(KakaoApi.instance()); + + final Scanner in = new Scanner(System.in, "UTF-8"); + + System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); + System.out.println(); + + // Obtain the Authorization URL + System.out.println("Fetching the Authorization URL..."); + final String authorizationUrl = service.getAuthorizationUrl(); + System.out.println("Got the Authorization URL!"); + System.out.println("Now go and authorize ScribeJava here:"); + System.out.println(authorizationUrl); + System.out.println("And paste the authorization code here"); + System.out.print(">>"); + final String code = in.nextLine(); + System.out.println(); + + System.out.println("Trading the Authorization Code for an Access Token..."); + final OAuth2AccessToken accessToken = service.getAccessToken(code); + + System.out.println("Got the Access Token!"); + System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); + System.out.println(); + + // Now let's go and ask for a protected resource! + System.out.println("Now we're going to access a protected resource..."); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); + service.signRequest(accessToken, request); + try (Response response = service.execute(request)) { + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + } + + System.out.println(); + System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); + + } +} From b2458a8abe0cf8237c491986ba2832031bdcfd33 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 5 May 2020 18:26:52 +0300 Subject: [PATCH 774/882] make Response accept resources to autoclose and autoclose it (thanks to https://github.com/drei01) --- changelog | 1 + .../core/model/OAuthAsyncRequestCallback.java | 5 ++++ .../scribejava/core/model/OAuthRequest.java | 9 ++++++ .../scribejava/core/model/Response.java | 29 +++++++++++++++++-- .../core/oauth/OAuth10aService.java | 8 +++-- .../scribejava/core/oauth/OAuth20Service.java | 5 +++- .../apache/OAuthAsyncCompletionHandler.java | 4 ++- .../OAuthAsyncCompletionHandlerTest.java | 3 ++ .../ning/OAuthAsyncCompletionHandlerTest.java | 2 ++ .../okhttp/OAuthAsyncCompletionHandler.java | 6 ++-- .../httpclient/okhttp/OkHttpHttpClient.java | 6 ++-- .../OAuthAsyncCompletionHandlerTest.java | 3 ++ 12 files changed, 69 insertions(+), 12 deletions(-) diff --git a/changelog b/changelog index a8de5b3b2..8a117fae5 100644 --- a/changelog +++ b/changelog @@ -1,5 +1,6 @@ [SNAPSHOT] * Add Polar API (https://www.polar.com/) (thanks to https://github.com/vidi42) + * make Response accept resources to autoclose and autoclose it (thanks to https://github.com/drei01) [6.9.0] * Add Xero API (https://www.xero.com/) (thanks to https://github.com/SidneyAllen) diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthAsyncRequestCallback.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthAsyncRequestCallback.java index 10f398fc4..466dd98ee 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthAsyncRequestCallback.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthAsyncRequestCallback.java @@ -2,6 +2,11 @@ public interface OAuthAsyncRequestCallback { + /** + * Implementations of this method should close provided response in case it implements {@link java.io.Closeable} + * + * @param response + */ void onCompleted(T response); void onThrowable(Throwable t); diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequest.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequest.java index ca6a32bf0..604d770e7 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequest.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequest.java @@ -400,6 +400,15 @@ public void setCharset(String charsetName) { public interface ResponseConverter { + /** + * Implementations of this method should close provided Response in case response is not included in the return + * Object of type <T> Then responsibility to close response is in on the + * {@link com.github.scribejava.core.model.OAuthAsyncRequestCallback#onCompleted(java.lang.Object) } + * + * @param response + * @return T + * @throws IOException + */ T convert(Response response) throws IOException; } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/Response.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/Response.java index 7cff61694..553c6cda5 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/Response.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/Response.java @@ -20,6 +20,8 @@ public class Response implements Closeable { private final Map headers; private String body; private InputStream stream; + private Closeable[] closeables; + private boolean closed; private Response(int code, String message, Map headers) { this.code = code; @@ -27,9 +29,11 @@ private Response(int code, String message, Map headers) { this.headers = headers; } - public Response(int code, String message, Map headers, InputStream stream) { + public Response(int code, String message, Map headers, InputStream stream, + Closeable... closeables) { this(code, message, headers); this.stream = stream; + this.closeables = closeables; } public Response(int code, String message, Map headers, String body) { @@ -124,8 +128,27 @@ public String toString() { @Override public void close() throws IOException { - if (stream != null) { - stream.close(); + if (closed) { + return; } + IOException ioException = null; + if (closeables != null) { + for (Closeable closeable : closeables) { + if (closeable == null) { + continue; + } + try { + closeable.close(); + } catch (IOException ioE) { + if (ioException != null) { + ioException = ioE; + } + } + } + } + if (ioException != null) { + throw ioException; + } + closed = true; } } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java index 08295d8c0..89fd279b1 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java @@ -61,7 +61,9 @@ public Future getRequestTokenAsync(OAuthAsyncRequestCallback return execute(request, callback, new OAuthRequest.ResponseConverter() { @Override public OAuth1RequestToken convert(Response response) throws IOException { - return getApi().getRequestTokenExtractor().extract(response); + final OAuth1RequestToken token = getApi().getRequestTokenExtractor().extract(response); + response.close(); + return token; } }); } @@ -130,7 +132,9 @@ public Future getAccessTokenAsync(OAuth1RequestToken requestT return execute(request, callback, new OAuthRequest.ResponseConverter() { @Override public OAuth1AccessToken convert(Response response) throws IOException { - return getApi().getAccessTokenExtractor().extract(response); + final OAuth1AccessToken token = getApi().getAccessTokenExtractor().extract(response); + response.close(); + return token; } }); } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java index 43a5d1a9f..b4343d3ad 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java @@ -75,7 +75,9 @@ public OAuth2AccessToken convert(Response response) throws IOException { final String body = response.getBody(); log("response body: %s", body); } - return getApi().getAccessTokenExtractor().extract(response); + final OAuth2AccessToken token = getApi().getAccessTokenExtractor().extract(response); + response.close(); + return token; } }); } @@ -445,6 +447,7 @@ public Future revokeToken(String tokenToRevoke, OAuthAsyncRequestCallback< @Override public Void convert(Response response) throws IOException { checkForErrorRevokeToken(response); + response.close(); return null; } }); diff --git a/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/OAuthAsyncCompletionHandler.java b/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/OAuthAsyncCompletionHandler.java index 4494fea2b..7779b83e7 100644 --- a/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/OAuthAsyncCompletionHandler.java +++ b/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/OAuthAsyncCompletionHandler.java @@ -17,6 +17,7 @@ import com.github.scribejava.core.model.OAuthRequest.ResponseConverter; import com.github.scribejava.core.model.Response; import java.io.IOException; +import java.io.InputStream; import org.apache.http.HttpEntity; public class OAuthAsyncCompletionHandler implements FutureCallback { @@ -44,8 +45,9 @@ public void completed(HttpResponse httpResponse) { final StatusLine statusLine = httpResponse.getStatusLine(); final HttpEntity httpEntity = httpResponse.getEntity(); + final InputStream contentStream = httpEntity == null ? null : httpEntity.getContent(); final Response response = new Response(statusLine.getStatusCode(), statusLine.getReasonPhrase(), headersMap, - httpEntity == null ? null : httpEntity.getContent()); + contentStream, contentStream); @SuppressWarnings("unchecked") final T t = converter == null ? (T) response : converter.convert(response); diff --git a/scribejava-httpclient-apache/src/test/java/com/github/scribejava/httpclient/apache/OAuthAsyncCompletionHandlerTest.java b/scribejava-httpclient-apache/src/test/java/com/github/scribejava/httpclient/apache/OAuthAsyncCompletionHandlerTest.java index c43fbed9e..e1a4ddc9c 100644 --- a/scribejava-httpclient-apache/src/test/java/com/github/scribejava/httpclient/apache/OAuthAsyncCompletionHandlerTest.java +++ b/scribejava-httpclient-apache/src/test/java/com/github/scribejava/httpclient/apache/OAuthAsyncCompletionHandlerTest.java @@ -167,6 +167,7 @@ private static class AllGoodResponseConverter implements OAuthRequest.ResponseCo @Override public String convert(Response response) throws IOException { + response.close(); return "All good"; } } @@ -175,6 +176,7 @@ private static class ExceptionResponseConverter implements OAuthRequest.Response @Override public String convert(Response response) throws IOException { + response.close(); throw new IOException("Failed to convert"); } } @@ -183,6 +185,7 @@ private static class OAuthExceptionResponseConverter implements OAuthRequest.Res @Override public String convert(Response response) throws IOException { + response.close(); throw new OAuthException("bad oauth"); } } diff --git a/scribejava-httpclient-ning/src/test/java/com/github/scribejava/httpclient/ning/OAuthAsyncCompletionHandlerTest.java b/scribejava-httpclient-ning/src/test/java/com/github/scribejava/httpclient/ning/OAuthAsyncCompletionHandlerTest.java index c235061e9..7bc56e1e1 100644 --- a/scribejava-httpclient-ning/src/test/java/com/github/scribejava/httpclient/ning/OAuthAsyncCompletionHandlerTest.java +++ b/scribejava-httpclient-ning/src/test/java/com/github/scribejava/httpclient/ning/OAuthAsyncCompletionHandlerTest.java @@ -84,6 +84,7 @@ private static class AllGoodResponseConverter implements OAuthRequest.ResponseCo @Override public String convert(Response response) throws IOException { + response.close(); return "All good"; } } @@ -92,6 +93,7 @@ private static class OAuthExceptionResponseConverter implements OAuthRequest.Res @Override public String convert(Response response) throws IOException { + response.close(); throw new OAuthException("bad oauth"); } } diff --git a/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OAuthAsyncCompletionHandler.java b/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OAuthAsyncCompletionHandler.java index 8345fa9d1..787b70395 100644 --- a/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OAuthAsyncCompletionHandler.java +++ b/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OAuthAsyncCompletionHandler.java @@ -38,15 +38,15 @@ public void onResponse(Call call, okhttp3.Response okHttpResponse) { try { final Response response = OkHttpHttpClient.convertResponse(okHttpResponse); - try { + try { @SuppressWarnings("unchecked") final T t = converter == null ? (T) response : converter.convert(response); okHttpFuture.setResult(t); if (callback != null) { callback.onCompleted(t); } - } catch (IOException | RuntimeException e) { - okHttpFuture.setException(e); + } catch (IOException | RuntimeException e) { + okHttpFuture.setException(e); if (callback != null) { callback.onThrowable(e); } diff --git a/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java b/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java index 67df4b089..f82697db0 100644 --- a/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java +++ b/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java @@ -17,6 +17,7 @@ import java.util.concurrent.Future; import com.github.scribejava.core.model.Response; import java.io.File; +import java.io.InputStream; import java.util.HashMap; import java.util.concurrent.ExecutionException; import okhttp3.Cache; @@ -192,8 +193,9 @@ static Response convertResponse(okhttp3.Response okHttpResponse) { } final ResponseBody body = okHttpResponse.body(); - return new Response(okHttpResponse.code(), okHttpResponse.message(), headersMap, - body == null ? null : body.byteStream()); + final InputStream bodyStream = body == null ? null : body.byteStream(); + return new Response(okHttpResponse.code(), okHttpResponse.message(), headersMap, bodyStream, bodyStream, body, + okHttpResponse); } } diff --git a/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/OAuthAsyncCompletionHandlerTest.java b/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/OAuthAsyncCompletionHandlerTest.java index 93d3c01f1..6e9f88fe5 100644 --- a/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/OAuthAsyncCompletionHandlerTest.java +++ b/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/OAuthAsyncCompletionHandlerTest.java @@ -179,6 +179,7 @@ private static class AllGoodResponseConverter implements OAuthRequest.ResponseCo @Override public String convert(Response response) throws IOException { + response.close(); return "All good"; } } @@ -187,6 +188,7 @@ private static class ExceptionResponseConverter implements OAuthRequest.Response @Override public String convert(Response response) throws IOException { + response.close(); throw new IOException("Failed to convert"); } } @@ -195,6 +197,7 @@ private static class OAuthExceptionResponseConverter implements OAuthRequest.Res @Override public String convert(Response response) throws IOException { + response.close(); throw new OAuthException("bad oauth"); } } From 43ce7ed67a58882294f78337ce6c267346aa2562 Mon Sep 17 00:00:00 2001 From: Petr Kopotev Date: Thu, 7 May 2020 13:22:17 +0300 Subject: [PATCH 775/882] Add Slack api --- .../com/github/scribejava/apis/SlackApi.java | 39 +++++++ .../apis/slack/SlackJsonTokenExtractor.java | 32 ++++++ .../apis/slack/SlackOAuth2AccessToken.java | 45 ++++++++ .../apis/examples/SlackExample.java | 103 ++++++++++++++++++ 4 files changed, 219 insertions(+) create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/SlackApi.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/slack/SlackJsonTokenExtractor.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/slack/SlackOAuth2AccessToken.java create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SlackExample.java diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/SlackApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/SlackApi.java new file mode 100644 index 000000000..1cfd4436b --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/SlackApi.java @@ -0,0 +1,39 @@ +package com.github.scribejava.apis; + +import com.github.scribejava.apis.fitbit.FitBitJsonTokenExtractor; +import com.github.scribejava.apis.slack.SlackJsonTokenExtractor; +import com.github.scribejava.apis.slack.SlackOAuth2AccessToken; +import com.github.scribejava.core.builder.api.DefaultApi20; + +/** + * Slack.com api + */ +public class SlackApi extends DefaultApi20 { + + protected SlackApi() { + } + + private static class InstanceHolder { + + private static final SlackApi INSTANCE = new SlackApi(); + } + + public static SlackApi instance() { + return SlackApi.InstanceHolder.INSTANCE; + } + + @Override + public String getAccessTokenEndpoint() { + return "https://slack.com/api/oauth.v2.access"; + } + + @Override + protected String getAuthorizationBaseUrl() { + return "https://slack.com/oauth/v2/authorize"; + } + + @Override + public SlackJsonTokenExtractor getAccessTokenExtractor() { + return SlackJsonTokenExtractor.instance(); + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/slack/SlackJsonTokenExtractor.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/slack/SlackJsonTokenExtractor.java new file mode 100644 index 000000000..985cec908 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/slack/SlackJsonTokenExtractor.java @@ -0,0 +1,32 @@ +package com.github.scribejava.apis.slack; + +import com.fasterxml.jackson.databind.JsonNode; +import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; + +public class SlackJsonTokenExtractor extends OAuth2AccessTokenJsonExtractor { + + protected SlackJsonTokenExtractor() { + } + + private static class InstanceHolder { + + private static final SlackJsonTokenExtractor INSTANCE = new SlackJsonTokenExtractor(); + } + + public static SlackJsonTokenExtractor instance() { + return SlackJsonTokenExtractor.InstanceHolder.INSTANCE; + } + + @Override + protected SlackOAuth2AccessToken createToken(String accessToken, String tokenType, Integer expiresIn, + String refreshToken, String scope, JsonNode response, String rawResponse) { + String userAccessToken = ""; + final JsonNode userAccessTokenNode = response.get("authed_user").get("access_token"); + if (userAccessTokenNode != null) { + userAccessToken = userAccessTokenNode.asText(); + } + + return new SlackOAuth2AccessToken(accessToken, tokenType, expiresIn, refreshToken, scope, + userAccessToken, rawResponse); + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/slack/SlackOAuth2AccessToken.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/slack/SlackOAuth2AccessToken.java new file mode 100644 index 000000000..cc0d7b120 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/slack/SlackOAuth2AccessToken.java @@ -0,0 +1,45 @@ +package com.github.scribejava.apis.slack; + +import com.github.scribejava.core.model.OAuth2AccessToken; + +import java.util.Objects; + +public class SlackOAuth2AccessToken extends OAuth2AccessToken { + + private final String userAccessToken; + + public SlackOAuth2AccessToken(String accessToken, String tokenType, Integer expiresIn, String refreshToken, String scope, String userAccessToken, String rawResponse) { + super(accessToken, tokenType, expiresIn, refreshToken, scope, rawResponse); + this.userAccessToken = userAccessToken; + } + + public String getUserAccessToken() { + return userAccessToken; + } + + @Override + public int hashCode() { + int hash = super.hashCode(); + hash = 37 * hash + Objects.hashCode(userAccessToken); + return hash; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + if (!super.equals(obj)) { + return false; + } + + return Objects.equals(userAccessToken, ((SlackOAuth2AccessToken) obj).getUserAccessToken()); + } + +} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SlackExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SlackExample.java new file mode 100644 index 000000000..eb4be91d9 --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SlackExample.java @@ -0,0 +1,103 @@ +package com.github.scribejava.apis.examples; + +import com.github.scribejava.apis.SlackApi; +import com.github.scribejava.apis.slack.SlackOAuth2AccessToken; +import com.github.scribejava.core.builder.ServiceBuilder; +import com.github.scribejava.core.model.OAuth2AccessToken; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.oauth.OAuth20Service; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; +import java.util.Scanner; +import java.util.concurrent.ExecutionException; + +public class SlackExample { + + private static final String NETWORK_NAME = "Slack.com"; + private static final String BOT_RESOURCE_URL = "https://slack.com/api/channels.list"; + private static final String BOT_SCOPE = "channels:read" + private static final String USER_RESOURCE_URL = "https://slack.com/api/users.list"; + private static final String USER_SCOPE = "users:read"; + private static final String PAYLOAD = "null"; + private static final String CONTENT_TYPE_NAME = "Content-Type"; + private static final String CONTENT_TYPE_VALUE = "application/json"; + + private SlackExample() { + } + + @SuppressWarnings("PMD.SystemPrintln") + public static void main(String... args) throws IOException, InterruptedException, ExecutionException { + // Replace these with your client id and secret + final String clientId = "client-id"; + final String clientSecret = "client-secret"; + final OAuth20Service service = new ServiceBuilder(clientId) + .apiSecret(clientSecret) + .callback("https://www.example.com/oauth_callback/") + .defaultScope(BOT_SCOPE) + .build(SlackApi.instance()); + + final Scanner in = new Scanner(System.in); + + System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); + System.out.println(); + + // Obtain the Authorization URL + System.out.println("Fetching the Authorization URL..."); + + final Map additionalParams = new HashMap<>(); + // define user scope if any + additionalParams.put("user_scope", USER_SCOPE); + final String authorizationUrl = service.createAuthorizationUrlBuilder() + .additionalParams(additionalParams) + .build(); + System.out.println("Got the Authorization URL!"); + System.out.println("Now go and authorize ScribeJava here:"); + System.out.println(authorizationUrl); + System.out.println("And paste the authorization code here"); + System.out.print(">>"); + final String code = in.nextLine(); + System.out.println(); + + System.out.println("Trading the Authorization Code for an Access Token..."); + final OAuth2AccessToken accessToken = service.getAccessToken(code); + System.out.println("Got the Access Token!"); + System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); + System.out.println(); + + System.out.println("Getting info using BOT token..."); + final OAuthRequest request = new OAuthRequest(Verb.GET, BOT_RESOURCE_URL); + request.addHeader(CONTENT_TYPE_NAME, CONTENT_TYPE_VALUE); + request.setPayload(PAYLOAD); + service.signRequest(accessToken, request); + + try (Response response = service.execute(request)) { + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + System.out.println(); + } + + System.out.println("Getting info using USER token..."); + final OAuthRequest userRequest = new OAuthRequest(Verb.GET, USER_RESOURCE_URL); + userRequest.addHeader(CONTENT_TYPE_NAME, CONTENT_TYPE_VALUE); + userRequest.setPayload(PAYLOAD); + SlackOAuth2AccessToken token = (SlackOAuth2AccessToken)accessToken; + service.signRequest(token.getUserAccessToken(), userRequest); + + try (Response response = service.execute(userRequest)) { + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + } + + + System.out.println(); + System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); + } +} From fdef16c0a278711491fb87d50bae0e66ca61a102 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 11 May 2020 15:05:49 +0300 Subject: [PATCH 776/882] update deps --- pom.xml | 10 +++++----- .../core/model/OAuthAsyncRequestCallback.java | 2 +- .../com/github/scribejava/core/model/OAuthRequest.java | 4 ++-- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/pom.xml b/pom.xml index a7a764942..e62db482f 100644 --- a/pom.xml +++ b/pom.xml @@ -56,7 +56,7 @@ com.fasterxml.jackson.core jackson-databind - 2.10.3 + 2.11.0 junit @@ -67,7 +67,7 @@ com.squareup.okhttp3 mockwebserver - 4.4.1 + 4.6.0 test @@ -106,7 +106,7 @@ com.puppycrawl.tools checkstyle - 8.30 + 8.32 @@ -187,7 +187,7 @@ org.apache.maven.plugins maven-javadoc-plugin - 3.1.1 + 3.2.0 ${java.home}/bin/javadoc UTF-8 @@ -273,7 +273,7 @@ 7 - 6.22.0 + 6.23.0 diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthAsyncRequestCallback.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthAsyncRequestCallback.java index 466dd98ee..7719314d2 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthAsyncRequestCallback.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthAsyncRequestCallback.java @@ -5,7 +5,7 @@ public interface OAuthAsyncRequestCallback { /** * Implementations of this method should close provided response in case it implements {@link java.io.Closeable} * - * @param response + * @param response response */ void onCompleted(T response); diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequest.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequest.java index 604d770e7..79c66695f 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequest.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequest.java @@ -405,9 +405,9 @@ public interface ResponseConverter { * Object of type <T> Then responsibility to close response is in on the * {@link com.github.scribejava.core.model.OAuthAsyncRequestCallback#onCompleted(java.lang.Object) } * - * @param response + * @param response response * @return T - * @throws IOException + * @throws IOException IOException */ T convert(Response response) throws IOException; } diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 51553b620..fa0ce5dc5 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -23,7 +23,7 @@ org.asynchttpclient async-http-client - 2.11.0 + 2.12.1 com.github.scribejava diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 33b6da071..ea231de3a 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -23,7 +23,7 @@ com.squareup.okhttp3 okhttp - 4.4.1 + 4.6.0 com.github.scribejava From 7f3a902e224a8e02470b7095beebcd46c3a6bf7a Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 29 Jul 2020 17:54:48 +0300 Subject: [PATCH 777/882] fix url encoding in POST payload, it wasn't needed (thanks to https://github.com/max904-github) --- changelog | 1 + .../scribejava/core/model/OAuthRequest.java | 2 +- .../scribejava/core/model/Parameter.java | 4 + .../scribejava/core/model/ParameterList.java | 12 ++ .../scribejava/core/AbstractClientTest.java | 151 +++++++++++++++++- .../scribejava/core/model/RequestTest.java | 3 +- 6 files changed, 162 insertions(+), 11 deletions(-) diff --git a/changelog b/changelog index 8a117fae5..a249f11af 100644 --- a/changelog +++ b/changelog @@ -1,6 +1,7 @@ [SNAPSHOT] * Add Polar API (https://www.polar.com/) (thanks to https://github.com/vidi42) * make Response accept resources to autoclose and autoclose it (thanks to https://github.com/drei01) + * fix url encoding in POST payload, it wasn't needed (thanks to https://github.com/max904-github) [6.9.0] * Add Xero API (https://www.xero.com/) (thanks to https://github.com/SidneyAllen) diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequest.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequest.java index 79c66695f..d8511296b 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequest.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequest.java @@ -360,7 +360,7 @@ public byte[] getByteArrayPayload() { if (byteArrayPayload != null) { return byteArrayPayload; } - final String body = bodyParams.asFormUrlEncodedString(); + final String body = bodyParams.asString(); try { return body.getBytes(getCharset()); } catch (UnsupportedEncodingException uee) { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/Parameter.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/Parameter.java index 9397cb773..962992c46 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/Parameter.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/Parameter.java @@ -16,6 +16,10 @@ public String asUrlEncodedPair() { return OAuthEncoder.encode(key).concat("=").concat(OAuthEncoder.encode(value)); } + public String asPair() { + return key + '=' + value; + } + @Override public boolean equals(Object other) { if (other == null) { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/ParameterList.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/ParameterList.java index 39d806652..c8b2c04a2 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/ParameterList.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/ParameterList.java @@ -65,6 +65,18 @@ public String asFormUrlEncodedString() { return builder.substring(1); } + public String asString() { + if (params.isEmpty()) { + return EMPTY_STRING; + } + + final StringBuilder builder = new StringBuilder(); + for (Parameter p : params) { + builder.append(PARAM_SEPARATOR).append(p.asPair()); + } + return builder.substring(1); + } + public void addAll(ParameterList other) { params.addAll(other.getParams()); } diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/AbstractClientTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/AbstractClientTest.java index 8fe6bb20e..5bd62e9d5 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/AbstractClientTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/AbstractClientTest.java @@ -78,37 +78,172 @@ public void shouldSendGetRequest() throws Exception { } @Test - public void shouldSendPostRequest() throws Exception { + public void shouldSendPostRequestWithEmptyBody() throws Exception { + final String expectedResponseBody = "response body for test shouldSendPostRequest"; + final String expectedRequestBody = ""; + + final MockWebServer server = new MockWebServer(); + server.enqueue(new MockResponse().setBody(expectedResponseBody)); + server.start(); + + final HttpUrl baseUrl = server.url("/testUrl"); + + final OAuthRequest request = new OAuthRequest(Verb.POST, baseUrl.toString()); + try (Response response = oAuthService.execute(request, null).get(30, TimeUnit.SECONDS)) { + assertEquals(expectedResponseBody, response.getBody()); + } + + final RecordedRequest recordedRequest = server.takeRequest(); + assertEquals("POST", recordedRequest.getMethod()); + assertEquals(expectedRequestBody, recordedRequest.getBody().readUtf8()); + + server.shutdown(); + } + + @Test + public void shouldSendPostRequestWithStringBody() throws Exception { final String expectedResponseBody = "response body for test shouldSendPostRequest"; final String expectedRequestBody = "request body"; final MockWebServer server = new MockWebServer(); server.enqueue(new MockResponse().setBody(expectedResponseBody)); + server.start(); + + final HttpUrl baseUrl = server.url("/testUrl"); + + final OAuthRequest request = new OAuthRequest(Verb.POST, baseUrl.toString()); + request.setPayload(expectedRequestBody); + try (Response response = oAuthService.execute(request, null).get(30, TimeUnit.SECONDS)) { + assertEquals(expectedResponseBody, response.getBody()); + } + + final RecordedRequest recordedRequest = server.takeRequest(); + assertEquals("POST", recordedRequest.getMethod()); + assertEquals(expectedRequestBody, recordedRequest.getBody().readUtf8()); + + server.shutdown(); + } + + @Test + public void shouldSendPostRequestWithStringBodyWithSpecialChars() throws Exception { + final String expectedResponseBody = "response body for test shouldSendPostRequest"; + final String expectedRequestBody = "~/!@#$%^&*()_+//\r\n%2F&"; + + final MockWebServer server = new MockWebServer(); server.enqueue(new MockResponse().setBody(expectedResponseBody)); server.start(); final HttpUrl baseUrl = server.url("/testUrl"); - // request with body - OAuthRequest request = new OAuthRequest(Verb.POST, baseUrl.toString()); + final OAuthRequest request = new OAuthRequest(Verb.POST, baseUrl.toString()); request.setPayload(expectedRequestBody); try (Response response = oAuthService.execute(request, null).get(30, TimeUnit.SECONDS)) { assertEquals(expectedResponseBody, response.getBody()); } - RecordedRequest recordedRequest = server.takeRequest(); + final RecordedRequest recordedRequest = server.takeRequest(); + assertEquals("POST", recordedRequest.getMethod()); + assertEquals(expectedRequestBody, recordedRequest.getBody().readUtf8()); + + server.shutdown(); + } + + @Test + public void shouldSendPostRequestWithByteBodyBody() throws Exception { + final String expectedResponseBody = "response body for test shouldSendPostRequest"; + final String expectedRequestBody = "request body"; + + final MockWebServer server = new MockWebServer(); + server.enqueue(new MockResponse().setBody(expectedResponseBody)); + server.start(); + + final HttpUrl baseUrl = server.url("/testUrl"); + + final OAuthRequest request = new OAuthRequest(Verb.POST, baseUrl.toString()); + request.setPayload(expectedRequestBody.getBytes()); + try (Response response = oAuthService.execute(request, null).get(30, TimeUnit.SECONDS)) { + assertEquals(expectedResponseBody, response.getBody()); + } + + final RecordedRequest recordedRequest = server.takeRequest(); + assertEquals("POST", recordedRequest.getMethod()); + assertEquals(expectedRequestBody, recordedRequest.getBody().readUtf8()); + + server.shutdown(); + } + + @Test + public void shouldSendPostRequestWithByteBodyWithSpecialChars() throws Exception { + final String expectedResponseBody = "response body for test shouldSendPostRequest"; + final String expectedRequestBody = "~/!@#$%^&*()_+//\r\n%2F&"; + + final MockWebServer server = new MockWebServer(); + server.enqueue(new MockResponse().setBody(expectedResponseBody)); + server.start(); + + final HttpUrl baseUrl = server.url("/testUrl"); + + final OAuthRequest request = new OAuthRequest(Verb.POST, baseUrl.toString()); + request.setPayload(expectedRequestBody.getBytes()); + try (Response response = oAuthService.execute(request, null).get(30, TimeUnit.SECONDS)) { + assertEquals(expectedResponseBody, response.getBody()); + } + + final RecordedRequest recordedRequest = server.takeRequest(); + assertEquals("POST", recordedRequest.getMethod()); + assertEquals(expectedRequestBody, recordedRequest.getBody().readUtf8()); + + server.shutdown(); + } + + @Test + public void shouldSendPostRequestWithBodyParamsBody() throws Exception { + final String expectedResponseBody = "response body for test shouldSendPostRequest"; + final String expectedRequestBodyParamName = "request body param name"; + final String expectedRequestBodyParamValue = "request body param value"; + final String expectedRequestBody = expectedRequestBodyParamName + '=' + expectedRequestBodyParamValue; + + final MockWebServer server = new MockWebServer(); + server.enqueue(new MockResponse().setBody(expectedResponseBody)); + server.start(); + + final HttpUrl baseUrl = server.url("/testUrl"); + + final OAuthRequest request = new OAuthRequest(Verb.POST, baseUrl.toString()); + request.addBodyParameter(expectedRequestBodyParamName, expectedRequestBodyParamValue); + try (Response response = oAuthService.execute(request, null).get(30, TimeUnit.SECONDS)) { + assertEquals(expectedResponseBody, response.getBody()); + } + + final RecordedRequest recordedRequest = server.takeRequest(); assertEquals("POST", recordedRequest.getMethod()); assertEquals(expectedRequestBody, recordedRequest.getBody().readUtf8()); - // request with empty body - request = new OAuthRequest(Verb.POST, baseUrl.toString()); + server.shutdown(); + } + + @Test + public void shouldSendPostRequestWithBodyParamsBodyWithSpecialChars() throws Exception { + final String expectedResponseBody = "response body for test shouldSendPostRequest"; + final String expectedRequestBodyParamName = "~/!@#$%^&*()_+//\r\n%2F&name"; + final String expectedRequestBodyParamValue = "~/!@#$%^&*()_+//\r\n%2F&value"; + final String expectedRequestBody = expectedRequestBodyParamName + '=' + expectedRequestBodyParamValue; + + final MockWebServer server = new MockWebServer(); + server.enqueue(new MockResponse().setBody(expectedResponseBody)); + server.start(); + + final HttpUrl baseUrl = server.url("/testUrl"); + + final OAuthRequest request = new OAuthRequest(Verb.POST, baseUrl.toString()); + request.addBodyParameter(expectedRequestBodyParamName, expectedRequestBodyParamValue); try (Response response = oAuthService.execute(request, null).get(30, TimeUnit.SECONDS)) { assertEquals(expectedResponseBody, response.getBody()); } - recordedRequest = server.takeRequest(); + final RecordedRequest recordedRequest = server.takeRequest(); assertEquals("POST", recordedRequest.getMethod()); - assertEquals("", recordedRequest.getBody().readUtf8()); + assertEquals(expectedRequestBody, recordedRequest.getBody().readUtf8()); server.shutdown(); } diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/model/RequestTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/model/RequestTest.java index 274ccca23..d0c870dac 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/model/RequestTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/model/RequestTest.java @@ -29,8 +29,7 @@ public void shouldGetQueryStringParameters() { @Test public void shouldSetBodyParamsAndAddContentLength() { - assertEquals("param=value¶m%20with%20spaces=value%20with%20spaces", - new String(postRequest.getByteArrayPayload())); + assertEquals("param=value¶m with spaces=value with spaces", new String(postRequest.getByteArrayPayload())); } @Test From 8b8691940822230a57dff13171bc5fe2a7ad41e8 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 29 Jul 2020 18:05:58 +0300 Subject: [PATCH 778/882] update deps --- pom.xml | 15 ++++++--------- scribejava-httpclient-okhttp/pom.xml | 2 +- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/pom.xml b/pom.xml index e62db482f..2b6955ad0 100644 --- a/pom.xml +++ b/pom.xml @@ -40,15 +40,12 @@ kullfar - Stas Gromov + Stanislav Gromov kullfar@gmail.com all +3 - - +7-909-677-11-16 - @@ -56,7 +53,7 @@ com.fasterxml.jackson.core jackson-databind - 2.11.0 + 2.11.1 junit @@ -67,7 +64,7 @@ com.squareup.okhttp3 mockwebserver - 4.6.0 + 4.8.0 test @@ -77,7 +74,7 @@ org.apache.felix maven-bundle-plugin - 4.2.1 + 5.1.1 bundle-manifest @@ -106,7 +103,7 @@ com.puppycrawl.tools checkstyle - 8.32 + 8.35 @@ -273,7 +270,7 @@ 7 - 6.23.0 + 6.26.0 diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index ea231de3a..cf5ac1998 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -23,7 +23,7 @@ com.squareup.okhttp3 okhttp - 4.6.0 + 4.8.0 com.github.scribejava From 68a73ace2954026d4e0a3789872cdbfd4336da4c Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Sat, 1 Aug 2020 09:53:55 +0300 Subject: [PATCH 779/882] really fix url encoding in POST payload, it was needed for 'application/x-www-form-urlencoded' Content-Type + unit tests (thanks to https://github.com/max904-github) --- changelog | 3 +- .../github/scribejava/apis/SalesforceApi.java | 8 +- .../scribejava/core/model/OAuthRequest.java | 2 +- .../scribejava/core/model/Parameter.java | 4 - .../scribejava/core/model/ParameterList.java | 12 --- .../scribejava/core/AbstractClientTest.java | 84 ++++--------------- .../scribejava/core/model/RequestTest.java | 66 +++++++++++---- 7 files changed, 77 insertions(+), 102 deletions(-) diff --git a/changelog b/changelog index a249f11af..953ac5d16 100644 --- a/changelog +++ b/changelog @@ -1,7 +1,8 @@ [SNAPSHOT] * Add Polar API (https://www.polar.com/) (thanks to https://github.com/vidi42) * make Response accept resources to autoclose and autoclose it (thanks to https://github.com/drei01) - * fix url encoding in POST payload, it wasn't needed (thanks to https://github.com/max904-github) + * fix url encoding in POST payload (it's needed for 'application/x-www-form-urlencoded' Content-Type) + + unit tests (thanks to https://github.com/max904-github) [6.9.0] * Add Xero API (https://www.xero.com/) (thanks to https://github.com/SidneyAllen) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/SalesforceApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/SalesforceApi.java index 57cdd32ac..8760a7fff 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/SalesforceApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/SalesforceApi.java @@ -17,10 +17,9 @@ /** * This class is an implementation of the Salesforce OAuth2 API. - * The default implementation connects to the Salesforce - * production environment. - * If you want to connect to a Sandbox environment you've to use {@link #sandbox()} method to - * get sandbox instance of this API + * + * The default implementation connects to the Salesforce production environment. If you want to connect to a Sandbox + * environment you've to use {@link #sandbox()} method to get sandbox instance of this API */ public class SalesforceApi extends DefaultApi20 { @@ -52,6 +51,7 @@ protected SalesforceApi(String hostName) { } private static class InstanceHolder { + private static final SalesforceApi INSTANCE = new SalesforceApi(PRODUCTION_HOST); } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequest.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequest.java index d8511296b..79c66695f 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequest.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequest.java @@ -360,7 +360,7 @@ public byte[] getByteArrayPayload() { if (byteArrayPayload != null) { return byteArrayPayload; } - final String body = bodyParams.asString(); + final String body = bodyParams.asFormUrlEncodedString(); try { return body.getBytes(getCharset()); } catch (UnsupportedEncodingException uee) { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/Parameter.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/Parameter.java index 962992c46..9397cb773 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/Parameter.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/Parameter.java @@ -16,10 +16,6 @@ public String asUrlEncodedPair() { return OAuthEncoder.encode(key).concat("=").concat(OAuthEncoder.encode(value)); } - public String asPair() { - return key + '=' + value; - } - @Override public boolean equals(Object other) { if (other == null) { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/ParameterList.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/ParameterList.java index c8b2c04a2..39d806652 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/ParameterList.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/ParameterList.java @@ -65,18 +65,6 @@ public String asFormUrlEncodedString() { return builder.substring(1); } - public String asString() { - if (params.isEmpty()) { - return EMPTY_STRING; - } - - final StringBuilder builder = new StringBuilder(); - for (Parameter p : params) { - builder.append(PARAM_SEPARATOR).append(p.asPair()); - } - return builder.substring(1); - } - public void addAll(ParameterList other) { params.addAll(other.getParams()); } diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/AbstractClientTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/AbstractClientTest.java index 5bd62e9d5..c1bc1967e 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/AbstractClientTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/AbstractClientTest.java @@ -19,6 +19,8 @@ import java.util.concurrent.TimeUnit; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertNotNull; public abstract class AbstractClientTest { @@ -78,32 +80,27 @@ public void shouldSendGetRequest() throws Exception { } @Test - public void shouldSendPostRequestWithEmptyBody() throws Exception { - final String expectedResponseBody = "response body for test shouldSendPostRequest"; - final String expectedRequestBody = ""; - + public void shouldSendPostWithApplicationXWwwFormUrlencodedRequestContentTypeHeader() throws Exception { final MockWebServer server = new MockWebServer(); - server.enqueue(new MockResponse().setBody(expectedResponseBody)); + server.enqueue(new MockResponse()); server.start(); final HttpUrl baseUrl = server.url("/testUrl"); final OAuthRequest request = new OAuthRequest(Verb.POST, baseUrl.toString()); - try (Response response = oAuthService.execute(request, null).get(30, TimeUnit.SECONDS)) { - assertEquals(expectedResponseBody, response.getBody()); - } + oAuthService.execute(request, null).get(30, TimeUnit.SECONDS).close(); final RecordedRequest recordedRequest = server.takeRequest(); assertEquals("POST", recordedRequest.getMethod()); - assertEquals(expectedRequestBody, recordedRequest.getBody().readUtf8()); + assertEquals(HttpClient.DEFAULT_CONTENT_TYPE, recordedRequest.getHeader(HttpClient.CONTENT_TYPE)); server.shutdown(); } @Test - public void shouldSendPostRequestWithStringBody() throws Exception { + public void shouldSendPostRequestWithEmptyBody() throws Exception { final String expectedResponseBody = "response body for test shouldSendPostRequest"; - final String expectedRequestBody = "request body"; + final String expectedRequestBody = ""; final MockWebServer server = new MockWebServer(); server.enqueue(new MockResponse().setBody(expectedResponseBody)); @@ -112,7 +109,6 @@ public void shouldSendPostRequestWithStringBody() throws Exception { final HttpUrl baseUrl = server.url("/testUrl"); final OAuthRequest request = new OAuthRequest(Verb.POST, baseUrl.toString()); - request.setPayload(expectedRequestBody); try (Response response = oAuthService.execute(request, null).get(30, TimeUnit.SECONDS)) { assertEquals(expectedResponseBody, response.getBody()); } @@ -120,14 +116,15 @@ public void shouldSendPostRequestWithStringBody() throws Exception { final RecordedRequest recordedRequest = server.takeRequest(); assertEquals("POST", recordedRequest.getMethod()); assertEquals(expectedRequestBody, recordedRequest.getBody().readUtf8()); + assertEquals(HttpClient.DEFAULT_CONTENT_TYPE, recordedRequest.getHeader(HttpClient.CONTENT_TYPE)); server.shutdown(); } @Test - public void shouldSendPostRequestWithStringBodyWithSpecialChars() throws Exception { + public void shouldSendPostRequestWithStringBody() throws Exception { final String expectedResponseBody = "response body for test shouldSendPostRequest"; - final String expectedRequestBody = "~/!@#$%^&*()_+//\r\n%2F&"; + final String expectedRequestBody = "request body"; final MockWebServer server = new MockWebServer(); server.enqueue(new MockResponse().setBody(expectedResponseBody)); @@ -144,6 +141,9 @@ public void shouldSendPostRequestWithStringBodyWithSpecialChars() throws Excepti final RecordedRequest recordedRequest = server.takeRequest(); assertEquals("POST", recordedRequest.getMethod()); assertEquals(expectedRequestBody, recordedRequest.getBody().readUtf8()); + final String contentTypeHeader = recordedRequest.getHeader(HttpClient.CONTENT_TYPE); + assertNotNull(contentTypeHeader); + assertTrue(contentTypeHeader.startsWith(HttpClient.DEFAULT_CONTENT_TYPE)); server.shutdown(); } @@ -168,30 +168,7 @@ public void shouldSendPostRequestWithByteBodyBody() throws Exception { final RecordedRequest recordedRequest = server.takeRequest(); assertEquals("POST", recordedRequest.getMethod()); assertEquals(expectedRequestBody, recordedRequest.getBody().readUtf8()); - - server.shutdown(); - } - - @Test - public void shouldSendPostRequestWithByteBodyWithSpecialChars() throws Exception { - final String expectedResponseBody = "response body for test shouldSendPostRequest"; - final String expectedRequestBody = "~/!@#$%^&*()_+//\r\n%2F&"; - - final MockWebServer server = new MockWebServer(); - server.enqueue(new MockResponse().setBody(expectedResponseBody)); - server.start(); - - final HttpUrl baseUrl = server.url("/testUrl"); - - final OAuthRequest request = new OAuthRequest(Verb.POST, baseUrl.toString()); - request.setPayload(expectedRequestBody.getBytes()); - try (Response response = oAuthService.execute(request, null).get(30, TimeUnit.SECONDS)) { - assertEquals(expectedResponseBody, response.getBody()); - } - - final RecordedRequest recordedRequest = server.takeRequest(); - assertEquals("POST", recordedRequest.getMethod()); - assertEquals(expectedRequestBody, recordedRequest.getBody().readUtf8()); + assertEquals(HttpClient.DEFAULT_CONTENT_TYPE, recordedRequest.getHeader(HttpClient.CONTENT_TYPE)); server.shutdown(); } @@ -199,34 +176,8 @@ public void shouldSendPostRequestWithByteBodyWithSpecialChars() throws Exception @Test public void shouldSendPostRequestWithBodyParamsBody() throws Exception { final String expectedResponseBody = "response body for test shouldSendPostRequest"; - final String expectedRequestBodyParamName = "request body param name"; - final String expectedRequestBodyParamValue = "request body param value"; - final String expectedRequestBody = expectedRequestBodyParamName + '=' + expectedRequestBodyParamValue; - - final MockWebServer server = new MockWebServer(); - server.enqueue(new MockResponse().setBody(expectedResponseBody)); - server.start(); - - final HttpUrl baseUrl = server.url("/testUrl"); - - final OAuthRequest request = new OAuthRequest(Verb.POST, baseUrl.toString()); - request.addBodyParameter(expectedRequestBodyParamName, expectedRequestBodyParamValue); - try (Response response = oAuthService.execute(request, null).get(30, TimeUnit.SECONDS)) { - assertEquals(expectedResponseBody, response.getBody()); - } - - final RecordedRequest recordedRequest = server.takeRequest(); - assertEquals("POST", recordedRequest.getMethod()); - assertEquals(expectedRequestBody, recordedRequest.getBody().readUtf8()); - - server.shutdown(); - } - - @Test - public void shouldSendPostRequestWithBodyParamsBodyWithSpecialChars() throws Exception { - final String expectedResponseBody = "response body for test shouldSendPostRequest"; - final String expectedRequestBodyParamName = "~/!@#$%^&*()_+//\r\n%2F&name"; - final String expectedRequestBodyParamValue = "~/!@#$%^&*()_+//\r\n%2F&value"; + final String expectedRequestBodyParamName = "request_body_param_name"; + final String expectedRequestBodyParamValue = "request_body_param_value"; final String expectedRequestBody = expectedRequestBodyParamName + '=' + expectedRequestBodyParamValue; final MockWebServer server = new MockWebServer(); @@ -244,6 +195,7 @@ public void shouldSendPostRequestWithBodyParamsBodyWithSpecialChars() throws Exc final RecordedRequest recordedRequest = server.takeRequest(); assertEquals("POST", recordedRequest.getMethod()); assertEquals(expectedRequestBody, recordedRequest.getBody().readUtf8()); + assertEquals(HttpClient.DEFAULT_CONTENT_TYPE, recordedRequest.getHeader(HttpClient.CONTENT_TYPE)); server.shutdown(); } diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/model/RequestTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/model/RequestTest.java index d0c870dac..87189632b 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/model/RequestTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/model/RequestTest.java @@ -1,27 +1,21 @@ package com.github.scribejava.core.model; -import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; -import org.junit.Before; import org.junit.Test; -import java.net.MalformedURLException; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertArrayEquals; public class RequestTest { - private OAuthRequest getRequest; - private OAuthRequest postRequest; - - @Before - public void setUp() throws MalformedURLException { - postRequest = new OAuthRequest(Verb.POST, "http://example.com"); + @Test + public void shouldGetQueryStringParameters() { + final OAuthRequest postRequest = new OAuthRequest(Verb.POST, "http://example.com"); postRequest.addBodyParameter("param", "value"); postRequest.addBodyParameter("param with spaces", "value with spaces"); - getRequest = new OAuthRequest(Verb.GET, "http://example.com?qsparam=value&other+param=value+with+spaces"); - } + final OAuthRequest getRequest + = new OAuthRequest(Verb.GET, "http://example.com?qsparam=value&other+param=value+with+spaces"); - @Test - public void shouldGetQueryStringParameters() { assertEquals(2, getRequest.getQueryStringParams().size()); assertEquals(0, postRequest.getQueryStringParams().size()); assertTrue(getRequest.getQueryStringParams().contains(new Parameter("qsparam", "value"))); @@ -29,12 +23,21 @@ public void shouldGetQueryStringParameters() { @Test public void shouldSetBodyParamsAndAddContentLength() { - assertEquals("param=value¶m with spaces=value with spaces", new String(postRequest.getByteArrayPayload())); + final OAuthRequest postRequest = new OAuthRequest(Verb.POST, "http://example.com"); + postRequest.addBodyParameter("param", "value"); + postRequest.addBodyParameter("param with spaces", "value with spaces"); + + assertEquals("param=value¶m%20with%20spaces=value%20with%20spaces", + new String(postRequest.getByteArrayPayload())); } @Test public void shouldSetPayloadAndHeaders() { + final OAuthRequest postRequest = new OAuthRequest(Verb.POST, "http://example.com"); + postRequest.addBodyParameter("param", "value"); + postRequest.addBodyParameter("param with spaces", "value with spaces"); postRequest.setPayload("PAYLOAD"); + assertEquals("PAYLOAD", postRequest.getStringPayload()); } @@ -56,6 +59,41 @@ public void shouldReturnTheCompleteUrl() { @Test public void shouldHandleQueryStringSpaceEncodingProperly() { + final OAuthRequest getRequest + = new OAuthRequest(Verb.GET, "http://example.com?qsparam=value&other+param=value+with+spaces"); + assertTrue(getRequest.getQueryStringParams().contains(new Parameter("other param", "value with spaces"))); } + + @Test + public void shouldNotEncodeInStringPayload() throws Exception { + final String requestBody = "~/!@#$%^&*( )_+//\r\n%2F&"; + + final OAuthRequest postRequest = new OAuthRequest(Verb.POST, "http://example.com"); + postRequest.setPayload(requestBody); + + assertEquals(requestBody, postRequest.getStringPayload()); + } + + @Test + public void shouldNotEncodeInByteBodyPayload() throws Exception { + final byte[] requestBody = "~/!@#$%^&*( )_+//\r\n%2F&".getBytes(); + + final OAuthRequest postRequest = new OAuthRequest(Verb.POST, "http://example.com"); + postRequest.setPayload(requestBody); + + assertArrayEquals(requestBody, postRequest.getByteArrayPayload()); + } + + @Test + public void shouldEncodeInBodyParamsPayload() throws Exception { + final String expectedRequestBodyParamName = "~/!@#$%^&*( )_+//\r\n%2F&name"; + final String expectedRequestBodyParamValue = "~/!@#$%^&*( )_+//\r\n%2F&value"; + final String expectedRequestBody = "~%2F%21%40%23%24%25%5E%26%2A%28%20%29_%2B%2F%2F%0D%0A%252F%26amp%3Bname=" + + "~%2F%21%40%23%24%25%5E%26%2A%28%20%29_%2B%2F%2F%0D%0A%252F%26amp%3Bvalue"; + + final OAuthRequest postRequest = new OAuthRequest(Verb.POST, "http://example.com"); + postRequest.addBodyParameter(expectedRequestBodyParamName, expectedRequestBodyParamValue); + assertArrayEquals(expectedRequestBody.getBytes(), postRequest.getByteArrayPayload()); + } } From dfbf50dd63898c60ac9fa54725cf4408442b3c18 Mon Sep 17 00:00:00 2001 From: max904 Date: Wed, 8 Jan 2020 15:31:57 +0100 Subject: [PATCH 780/882] Implemented Armeria-based http client binding for ScribeJava. Armeria (https://github.com/line/armeria/) is an open-source asynchronous HTTP/2/1 client/server library built on top of Netty and Java 8. Java 8 required to build this http client module. --- pom.xml | 1 + scribejava-httpclient-armeria/pom.xml | 69 +++ .../httpclient/multipart/MultipartUtils.java | 53 +++ .../httpclient/armeria/ArmeriaHttpClient.java | 440 ++++++++++++++++++ .../armeria/ArmeriaHttpClientConfig.java | 104 +++++ .../httpclient/armeria/ArmeriaProvider.java | 16 + ...ibejava.core.httpclient.HttpClientProvider | 1 + .../armeria/ArmeriaHttpClientTest.java | 69 +++ .../test/resources/simplelogger.properties | 29 ++ 9 files changed, 782 insertions(+) create mode 100644 scribejava-httpclient-armeria/pom.xml create mode 100644 scribejava-httpclient-armeria/src/main/java/com/github/scribejava/core/httpclient/multipart/MultipartUtils.java create mode 100644 scribejava-httpclient-armeria/src/main/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClient.java create mode 100644 scribejava-httpclient-armeria/src/main/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClientConfig.java create mode 100644 scribejava-httpclient-armeria/src/main/java/com/github/scribejava/httpclient/armeria/ArmeriaProvider.java create mode 100644 scribejava-httpclient-armeria/src/main/resources/META-INF/services/com.github.scribejava.core.httpclient.HttpClientProvider create mode 100644 scribejava-httpclient-armeria/src/test/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClientTest.java create mode 100644 scribejava-httpclient-armeria/src/test/resources/simplelogger.properties diff --git a/pom.xml b/pom.xml index 2b6955ad0..a5119ada7 100644 --- a/pom.xml +++ b/pom.xml @@ -21,6 +21,7 @@ scribejava-httpclient-ning scribejava-httpclient-okhttp scribejava-httpclient-apache + scribejava-httpclient-armeria diff --git a/scribejava-httpclient-armeria/pom.xml b/scribejava-httpclient-armeria/pom.xml new file mode 100644 index 000000000..e11a41915 --- /dev/null +++ b/scribejava-httpclient-armeria/pom.xml @@ -0,0 +1,69 @@ + + + 4.0.0 + + + com.github.scribejava + scribejava + 6.9.1-SNAPSHOT + ../pom.xml + + + scribejava-httpclient-armeria + ScribeJava Async Armeria Client support + jar + + + + com.github.scribejava + scribejava-core + ${project.version} + + + com.linecorp.armeria + armeria + 0.97.0 + + + com.github.scribejava + scribejava-core + ${project.version} + test-jar + test + + + io.netty + netty-all + 4.1.43.Final + test + + + org.slf4j + slf4j-simple + 1.7.30 + test + + + + + + + maven-compiler-plugin + 3.8.1 + + UTF-8 + 8 + true + + + + org.apache.felix + maven-bundle-plugin + + + org.apache.maven.plugins + maven-jar-plugin + + + + diff --git a/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/core/httpclient/multipart/MultipartUtils.java b/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/core/httpclient/multipart/MultipartUtils.java new file mode 100644 index 000000000..bbbbad078 --- /dev/null +++ b/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/core/httpclient/multipart/MultipartUtils.java @@ -0,0 +1,53 @@ +package com.github.scribejava.core.httpclient.multipart; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.util.List; +import java.util.Map; + +public abstract class MultipartUtils { + + // copied from com.github.scribejava.core.httpclient.jdk.JDKHttpClient#getPayload + public static ByteArrayOutputStream getPayload(MultipartPayload multipartPayload) throws IOException { + final ByteArrayOutputStream os = new ByteArrayOutputStream(); + + final String preamble = multipartPayload.getPreamble(); + if (preamble != null) { + os.write(preamble.getBytes()); + } + final List bodyParts = multipartPayload.getBodyParts(); + if (!bodyParts.isEmpty()) { + final String boundary = multipartPayload.getBoundary(); + final byte[] startBoundary = ("\r\n--" + boundary + "\r\n").getBytes(); + + for (BodyPartPayload bodyPart : bodyParts) { + os.write(startBoundary); + + final Map bodyPartHeaders = bodyPart.getHeaders(); + if (bodyPartHeaders != null) { + for (Map.Entry header : bodyPartHeaders.entrySet()) { + os.write((header.getKey() + ": " + header.getValue() + "\r\n").getBytes()); + } + } + + if (bodyPart instanceof MultipartPayload) { + getPayload((MultipartPayload) bodyPart).writeTo(os); + } else if (bodyPart instanceof ByteArrayBodyPartPayload) { + os.write("\r\n".getBytes()); + os.write(((ByteArrayBodyPartPayload) bodyPart).getPayload()); + } else { + throw new AssertionError(bodyPart.getClass()); + } + } + + os.write(("\r\n--" + boundary + "--\r\n").getBytes()); + final String epilogue = multipartPayload.getEpilogue(); + if (epilogue != null) { + os.write((epilogue + "\r\n").getBytes()); + } + + } + return os; + } + +} diff --git a/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClient.java b/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClient.java new file mode 100644 index 000000000..d3b8a6359 --- /dev/null +++ b/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClient.java @@ -0,0 +1,440 @@ +package com.github.scribejava.httpclient.armeria; + +import com.github.scribejava.core.httpclient.AbstractAsyncOnlyHttpClient; +import com.github.scribejava.core.httpclient.HttpClientConfig; +import com.github.scribejava.core.httpclient.multipart.MultipartPayload; +import com.github.scribejava.core.httpclient.multipart.MultipartUtils; +import com.github.scribejava.core.model.OAuthAsyncRequestCallback; +import com.github.scribejava.core.model.OAuthConstants; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.Verb; +import com.linecorp.armeria.client.ClientFactory; +import com.linecorp.armeria.client.ClientFactoryBuilder; +import com.linecorp.armeria.client.ClientFactoryOptionValue; +import com.linecorp.armeria.client.ClientOptions; +import com.linecorp.armeria.client.Endpoint; +import com.linecorp.armeria.client.WebClient; +import com.linecorp.armeria.client.WebClientBuilder; +import com.linecorp.armeria.client.logging.LoggingClient; +import com.linecorp.armeria.common.AggregatedHttpResponse; +import com.linecorp.armeria.common.HttpData; +import com.linecorp.armeria.common.HttpMethod; +import com.linecorp.armeria.common.HttpResponse; +import com.linecorp.armeria.common.RequestHeaders; +import com.linecorp.armeria.common.RequestHeadersBuilder; +import com.linecorp.armeria.common.SessionProtocol; + +import java.io.File; +import java.io.IOException; +import java.net.URI; +import java.nio.file.Files; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.Future; +import java.util.concurrent.locks.Lock; +import java.util.concurrent.locks.ReentrantReadWriteLock; +import java.util.function.Supplier; + +public class ArmeriaHttpClient extends AbstractAsyncOnlyHttpClient { + + private final ArmeriaHttpClientConfig config; + private final Map httpClients = new HashMap<>(); + private final ReentrantReadWriteLock httpClientsLock = new ReentrantReadWriteLock(); + + public ArmeriaHttpClient() { + this(ArmeriaHttpClientConfig.defaultConfig()); + } + + public ArmeriaHttpClient(ArmeriaHttpClientConfig config) { + this.config = config; + } + + public HttpClientConfig getConfig() { + return config; + } + + /** + * Cleans up HTTP clients collection. + */ + @Override + public void close() { + final Lock writeLock = httpClientsLock.writeLock(); + writeLock.lock(); + try { + httpClients.clear(); + } finally { + writeLock.unlock(); + } + } + + @Override + public Future executeAsync(String userAgent, Map headers, Verb httpVerb, + String completeUrl, byte[] bodyContents, OAuthAsyncRequestCallback callback, + OAuthRequest.ResponseConverter converter) { + return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, + new BytesBody(bodyContents), callback, converter); + } + + @Override + public Future executeAsync(String userAgent, Map headers, Verb httpVerb, + String completeUrl, MultipartPayload bodyContents, OAuthAsyncRequestCallback callback, + OAuthRequest.ResponseConverter converter) { + return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, + new MultipartBody(bodyContents), callback, converter); + } + + @Override + public Future executeAsync(String userAgent, Map headers, Verb httpVerb, + String completeUrl, String bodyContents, OAuthAsyncRequestCallback callback, + OAuthRequest.ResponseConverter converter) { + return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, + new StringBody(bodyContents), callback, converter); + } + + @Override + public Future executeAsync(String userAgent, Map headers, Verb httpVerb, + String completeUrl, File bodyContents, OAuthAsyncRequestCallback callback, + OAuthRequest.ResponseConverter converter) { + return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, + new FileBody(bodyContents), callback, converter); + } + + private CompletableFuture doExecuteAsync(String userAgent, + Map headers, Verb httpVerb, + String completeUrl, Supplier contentSupplier, + OAuthAsyncRequestCallback callback, + OAuthRequest.ResponseConverter converter) { + // Get the URI and Path + final URI uri = URI.create(completeUrl); + final String path = getServicePath(uri); + + // Fetch/Create WebClient instance for a given Endpoint + final WebClient client = getHttpClient(uri); + + // Build HTTP request + final RequestHeadersBuilder headersBuilder = + RequestHeaders.of(getHttpMethod(httpVerb), path).toBuilder(); + headersBuilder.add(headers.entrySet()); + if (userAgent != null) { + headersBuilder.add(OAuthConstants.USER_AGENT_HEADER_NAME, userAgent); + } + + // Build the request body and execute HTTP request + final HttpResponse response; + if (httpVerb.isPermitBody()) { // POST, PUT, PATCH and DELETE methods + final HttpData contents = contentSupplier.get(); + if (httpVerb.isRequiresBody() && contents == null) { // POST or PUT methods + throw new IllegalArgumentException( + "Contents missing for request method " + httpVerb.name()); + } + if (contents != null) { + response = client.execute(headersBuilder.build(), contents); + } else { + response = client.execute(headersBuilder.build()); + } + } else { + response = client.execute(headersBuilder.build()); + } + + // Aggregate HTTP response (asynchronously) and return the result Future + return response.aggregate() + .thenApply(r -> whenResponseComplete(callback, converter, r)) + .exceptionally(e -> completeExceptionally(callback, e)); + } + + //------------------------------------------------------------------------------------------------ + + /** + * Extracts Protocol + Host + Port part from a given endpoint {@link URI} + * @param uri an endpoint {@link URI} + * @return a portion of {@link URI} including a combination of Protocol + Host + Port + * @see #getHttpClient(URI uri) + */ + private String getHostUri(final URI uri) { + final StringBuilder builder = new StringBuilder(); + builder.append(uri.getScheme()).append("://").append(uri.getHost()); + final int port = uri.getPort(); + if (port > 0) { + builder.append(":").append(port); + } + return builder.toString(); + } + + /** + * Extracts service path from a given endpoint {@link URI} + * @param uri an endpoint {@link URI} + * @return service path portion of the {@link URI} + */ + private static String getServicePath(final URI uri) { + final StringBuilder builder = new StringBuilder(); + final String path = uri.getRawPath(); + if (path != null && path.length() > 0) { + builder.append(path); + } else { + builder.append("/"); + } + final String query = uri.getRawQuery(); + if (query != null && query.length() > 0) { + builder.append("?").append(query); + } + return builder.toString(); + } + + /** + * Provides and instance of {@link WebClient} for a given endpoint {@link URI} based on + * a combination of Protocol + Host + Port. + * @param uri an endpoint {@link URI} + * @return {@link WebClient} instance + */ + private WebClient getHttpClient(final URI uri) { + final String hostUri = getHostUri(uri); + + WebClient client; + final Lock readLock = httpClientsLock.readLock(); + readLock.lock(); + try { + client = httpClients.get(hostUri); + } finally { + readLock.unlock(); + } + + if (client != null) { + return client; + } + + client = buildNewHttpClient(uri); + + final Lock writeLock = httpClientsLock.writeLock(); + writeLock.lock(); + try { + if (!httpClients.containsKey(hostUri)) { + httpClients.put(hostUri, client); + return client; + } else { + return httpClients.get(hostUri); + } + } finally { + writeLock.unlock(); + } + } + + /** + * Builds a brand-new instance of {@link WebClient} for a given endpoint {@link URI}. + * Uses {@link ArmeriaHttpClientConfig} to configure the builder and the client. + * @param uri an endpoint {@link URI} + * @return Brand-new {@link WebClient} instance + */ + private WebClient buildNewHttpClient(final URI uri) { + // Build the client and the headers + WebClientBuilder clientBuilder = + getHttpClientBuilder(uri, config.getSessionProtocolPreference()); + + final ClientOptions clientOptions = config.getClientOptions(); + if (clientOptions != null) { + clientBuilder.options(clientOptions); + } + + final ClientFactoryBuilder clientFactoryBuilder = ClientFactory.builder(); + final Collection> clientFactoryOptions = config.getClientFactoryOptions(); + if (clientFactoryOptions != null && !clientFactoryOptions.isEmpty()) { + clientFactoryOptions.forEach(clientFactoryBuilder::option); + } + clientBuilder.factory(clientFactoryBuilder.build()); + + if (config.isLogging()) { + clientBuilder = clientBuilder.decorator(LoggingClient.newDecorator()); + } + + return clientBuilder.build(); + } + + /** + * Provides an instance of {@link WebClientBuilder} for a given endpoint {@link URI} + * @param uri an endpoint {@link URI} + * @param protocolPreference an HTTP protocol generation preference; acceptable values: "h1" or "h2". + * @return {@link WebClientBuilder} instance to build a new {@link WebClient} + */ + private WebClientBuilder getHttpClientBuilder(final URI uri, final SessionProtocol protocolPreference) { + final SessionProtocol sessionProtocol = SessionProtocol.of(uri.getScheme()); + final String host = uri.getHost(); + final int port = uri.getPort(); + final Endpoint endpoint = (port > 0) ? Endpoint.of(host, port) : Endpoint.of(host); + switch(sessionProtocol) { + case HTTP: + if (protocolPreference == SessionProtocol.H1) { + // enforce HTTP/1 protocol + return WebClient.builder(SessionProtocol.H1C, endpoint); + } + break; + case HTTPS: + if (protocolPreference == SessionProtocol.H1) { + // enforce HTTP/1 protocol + return WebClient.builder(SessionProtocol.H1, endpoint); + } + break; + default: + break; + } + return WebClient.builder(sessionProtocol, endpoint); + } + + /** + * Maps {@link Verb} to {@link HttpMethod} + * @param httpVerb a {@link Verb} to match with {@link HttpMethod} + * @return {@link HttpMethod} corresponding to the parameter + */ + private HttpMethod getHttpMethod(final Verb httpVerb) { + switch (httpVerb) { + case GET: + return HttpMethod.GET; + case POST: + return HttpMethod.POST; + case PUT: + return HttpMethod.PUT; + case DELETE: + return HttpMethod.DELETE; + case HEAD: + return HttpMethod.HEAD; + case OPTIONS: + return HttpMethod.OPTIONS; + case TRACE: + return HttpMethod.TRACE; + case PATCH: + return HttpMethod.PATCH; + default: + throw new IllegalArgumentException( + "message build error: unsupported HTTP method: " + httpVerb.name()); + } + } + + //------------------------------------------------------------------------------------------------ + // Response asynchronous handlers + + /** + * Converts {@link AggregatedHttpResponse} to {@link Response} + * @param aggregatedResponse an instance of {@link AggregatedHttpResponse} to convert to {@link Response} + * @return a {@link Response} converted from {@link AggregatedHttpResponse} + */ + private Response convertResponse(final AggregatedHttpResponse aggregatedResponse) { + final Map headersMap = new HashMap<>(aggregatedResponse.headers().size()); + aggregatedResponse.headers() + .forEach((header, value) -> headersMap.put(header.toString(), value)); + return new Response(aggregatedResponse.status().code(), + aggregatedResponse.status().reasonPhrase(), + headersMap, aggregatedResponse.content().toInputStream()); + } + + /** + * Converts {@link AggregatedHttpResponse} to {@link Response} upon its aggregation completion + * and invokes {@link OAuthAsyncRequestCallback} for it. + * @param callback a {@link OAuthAsyncRequestCallback} callback to invoke upon response completion + * @param converter an optional {@link OAuthRequest.ResponseConverter} result converter for {@link Response} + * @param aggregatedResponse a source {@link AggregatedHttpResponse} to handle + * @param converter {@link OAuthRequest.ResponseConverter} specific type or {@link Response} + * @return either instance of {@link Response} or converted result based on {@link OAuthRequest.ResponseConverter} + */ + private T whenResponseComplete(OAuthAsyncRequestCallback callback, + OAuthRequest.ResponseConverter converter, AggregatedHttpResponse aggregatedResponse) { + final Response response = convertResponse(aggregatedResponse); + try { + @SuppressWarnings("unchecked") final T t = + converter == null ? (T) response : converter.convert(response); + if (callback != null) { + callback.onCompleted(t); + } + return t; + } catch (IOException | RuntimeException e) { + return completeExceptionally(callback, e); + } + } + + /** + * Invokes {@link OAuthAsyncRequestCallback} upon {@link Throwable} error result + * @param callback a {@link OAuthAsyncRequestCallback} callback to invoke upon response completion + * @param throwable a {@link Throwable} error result + * @param converter {@link OAuthRequest.ResponseConverter} specific type or {@link Response} + * @return null + */ + private T completeExceptionally(OAuthAsyncRequestCallback callback, Throwable throwable) { + if (callback != null) { + callback.onThrowable(throwable); + } + return null; + } + + //------------------------------------------------------------------------------------------------ + // Body type suppliers + + private static class BytesBody implements Supplier { + + private final byte[] bodyContents; + + BytesBody(final byte[] bodyContents) { + this.bodyContents = bodyContents; + } + + @Override + public HttpData get() { + return (bodyContents != null) ? HttpData.wrap(bodyContents) : null; + } + } + + private static class StringBody implements Supplier { + + private final String bodyContents; + + StringBody(final String bodyContents) { + this.bodyContents = bodyContents; + } + + @Override + public HttpData get() { + return (bodyContents != null) ? HttpData.ofUtf8(bodyContents) : null; + } + } + + private static class FileBody implements Supplier { + + private final File bodyContents; + + FileBody(final File bodyContents) { + this.bodyContents = bodyContents; + } + + @Override + public HttpData get() { + try { + return (bodyContents != null) + ? HttpData.wrap(Files.readAllBytes(bodyContents.toPath())) + : null; + } catch (IOException e) { + throw new RuntimeException(e); + } + } + } + + private static class MultipartBody implements Supplier { + + private final MultipartPayload bodyContents; + + MultipartBody(final MultipartPayload bodyContents) { + this.bodyContents = bodyContents; + } + + @Override + public HttpData get() { + try { + return (bodyContents != null) + ? HttpData.wrap(MultipartUtils.getPayload(bodyContents).toByteArray()) + : null; + } catch (IOException e) { + throw new RuntimeException(e); + } + } + } + + //------------------------------------------------------------------------------------------------ +} diff --git a/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClientConfig.java b/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClientConfig.java new file mode 100644 index 000000000..0b566de4a --- /dev/null +++ b/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClientConfig.java @@ -0,0 +1,104 @@ +package com.github.scribejava.httpclient.armeria; + +import com.github.scribejava.core.httpclient.HttpClientConfig; +import com.linecorp.armeria.client.ClientFactoryOption; +import com.linecorp.armeria.client.ClientFactoryOptionValue; +import com.linecorp.armeria.client.ClientOption; +import com.linecorp.armeria.client.ClientOptions; +import com.linecorp.armeria.client.ClientOptionsBuilder; +import com.linecorp.armeria.common.SessionProtocol; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.Map; + +public class ArmeriaHttpClientConfig implements HttpClientConfig { + + private Map options; + private Map factoryOptions; + private String protocolPreference; + private Boolean logging; + + ClientOptions getClientOptions() { + if (options == null || options.isEmpty()) { + return null; + } + final ClientOptionsBuilder builder = ClientOptions.builder(); + for (Map.Entry optionEntry : options.entrySet()) { + builder.option(ClientOption.valueOf(optionEntry.getKey()), optionEntry.getValue()); + } + return builder.build(); + } + + public Map getOptions() { + return options; + } + + public void setOptions(Map options) { + this.options = options; + } + + Collection> getClientFactoryOptions() { + if (factoryOptions == null || factoryOptions.isEmpty()) { + return Collections.emptyList(); + } + final List> options = new ArrayList<>(); + for (Map.Entry optionEntry : factoryOptions.entrySet()) { + options.add(ClientFactoryOption.valueOf(optionEntry.getKey()).newValue(optionEntry.getValue())); + } + // WARNING: this ClientFactoryOptions.of(options) method will override default channel options of the factory + // and cause NPE + //return ClientFactoryOptions.of(options); + return options; + } + + public Map getFactoryOptions() { + return factoryOptions; + } + + public void setFactoryOptions(Map factoryOptions) { + this.factoryOptions = factoryOptions; + } + + SessionProtocol getSessionProtocolPreference() { + if (protocolPreference == null) { + return SessionProtocol.H1; // default + } + final SessionProtocol protocol = SessionProtocol.of(protocolPreference); + switch(protocol) { + case H1: + case H1C: + return SessionProtocol.H1; + case PROXY: + throw new IllegalArgumentException("protocolPreference - " + SessionProtocol.PROXY.uriText()); + default: + return SessionProtocol.H2; + } + } + + public String getProtocolPreference() { + return protocolPreference; + } + + public void setProtocolPreference(String protocolPreference) { + this.protocolPreference = protocolPreference; + } + + public boolean isLogging() { + return logging != null && logging; + } + + public void setLogging(boolean logging) { + this.logging = logging; + } + + @Override + public HttpClientConfig createDefaultConfig() { + return defaultConfig(); + } + + public static ArmeriaHttpClientConfig defaultConfig() { + return new ArmeriaHttpClientConfig(); + } +} diff --git a/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/httpclient/armeria/ArmeriaProvider.java b/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/httpclient/armeria/ArmeriaProvider.java new file mode 100644 index 000000000..b352a8b07 --- /dev/null +++ b/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/httpclient/armeria/ArmeriaProvider.java @@ -0,0 +1,16 @@ +package com.github.scribejava.httpclient.armeria; + +import com.github.scribejava.core.httpclient.HttpClientProvider; +import com.github.scribejava.core.httpclient.HttpClient; +import com.github.scribejava.core.httpclient.HttpClientConfig; + +public class ArmeriaProvider implements HttpClientProvider { + + @Override + public HttpClient createClient(HttpClientConfig config) { + if (config instanceof ArmeriaHttpClientConfig) { + return new ArmeriaHttpClient((ArmeriaHttpClientConfig) config); + } + return null; + } +} diff --git a/scribejava-httpclient-armeria/src/main/resources/META-INF/services/com.github.scribejava.core.httpclient.HttpClientProvider b/scribejava-httpclient-armeria/src/main/resources/META-INF/services/com.github.scribejava.core.httpclient.HttpClientProvider new file mode 100644 index 000000000..bba338db5 --- /dev/null +++ b/scribejava-httpclient-armeria/src/main/resources/META-INF/services/com.github.scribejava.core.httpclient.HttpClientProvider @@ -0,0 +1 @@ +com.github.scribejava.httpclient.armeria.ArmeriaProvider diff --git a/scribejava-httpclient-armeria/src/test/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClientTest.java b/scribejava-httpclient-armeria/src/test/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClientTest.java new file mode 100644 index 000000000..3cdecee1a --- /dev/null +++ b/scribejava-httpclient-armeria/src/test/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClientTest.java @@ -0,0 +1,69 @@ +package com.github.scribejava.httpclient.armeria; + +import com.github.scribejava.core.AbstractClientTest; +import com.github.scribejava.core.httpclient.HttpClient; +import io.netty.channel.EventLoopGroup; +import io.netty.resolver.AbstractAddressResolver; +import io.netty.resolver.AddressResolver; +import io.netty.resolver.AddressResolverGroup; +import io.netty.util.concurrent.EventExecutor; +import io.netty.util.concurrent.Promise; +import java.net.InetAddress; +import java.net.InetSocketAddress; +import java.util.Collections; +import java.util.List; +import java.util.function.Function; + +public class ArmeriaHttpClientTest extends AbstractClientTest { + + @Override + protected HttpClient createNewClient() { + final ArmeriaHttpClientConfig config = ArmeriaHttpClientConfig.defaultConfig(); + // simulate DNS resolution for a mock address ("kubernetes.docker.internal") + final Function> + addressResolverGroupFactory = eventLoopGroup -> new MockAddressResolverGroup(); + config.setFactoryOptions(// No-Op DNS resolver to avoid resolution issues in the unit test + Collections.singletonMap("ADDRESS_RESOLVER_GROUP_FACTORY", addressResolverGroupFactory)); + // enable client-side HTTP tracing + config.setLogging(true); + return new ArmeriaHttpClient(config); + } + + //------------------------------------------------------------------------------------------------ + // No-Op DNS resolver to avoid resolution issues in the unit test + + static class MockAddressResolverGroup extends AddressResolverGroup { + + private MockAddressResolverGroup() { + } + + protected AddressResolver newResolver(EventExecutor executor) { + return new MockAddressResolver(executor); + } + } + + static class MockAddressResolver extends AbstractAddressResolver { + + private MockAddressResolver(EventExecutor executor) { + super(executor); + } + + protected boolean doIsResolved(InetSocketAddress address) { + return !address.isUnresolved(); + } + + private InetSocketAddress resolveToLoopback(InetSocketAddress unresolvedAddress) { + return new InetSocketAddress(InetAddress.getLoopbackAddress(), unresolvedAddress.getPort()); + } + + protected void doResolve(InetSocketAddress unresolvedAddress, Promise promise) { + promise.setSuccess(resolveToLoopback(unresolvedAddress)); + } + + protected void doResolveAll(InetSocketAddress unresolvedAddress, Promise> promise) { + promise.setSuccess(Collections.singletonList(resolveToLoopback(unresolvedAddress))); + } + } + + //------------------------------------------------------------------------------------------------ +} diff --git a/scribejava-httpclient-armeria/src/test/resources/simplelogger.properties b/scribejava-httpclient-armeria/src/test/resources/simplelogger.properties new file mode 100644 index 000000000..ce703174e --- /dev/null +++ b/scribejava-httpclient-armeria/src/test/resources/simplelogger.properties @@ -0,0 +1,29 @@ +# SLF4J's SimpleLogger configuration file +# Simple implementation of Logger that sends all enabled log messages, for all defined loggers, to System.err. + +# Default logging detail level for all instances of SimpleLogger. +# Must be one of ("trace", "debug", "info", "warn", or "error"). +# If not specified, defaults to "info". +org.slf4j.simpleLogger.defaultLogLevel=debug + +# Set to true if you want the current date and time to be included in output messages. +# Default is false, and will output the number of milliseconds elapsed since startup. +org.slf4j.simpleLogger.showDateTime=true + +# The date and time format to be used in the output messages. +# The pattern describing the date and time format is the same that is used in java.text.SimpleDateFormat. +# If the format is not specified or is invalid, the default format is used. +# The default format is yyyy-MM-dd HH:mm:ss:SSS Z. +org.slf4j.simpleLogger.dateTimeFormat=[HH:mm:ss] + +# Set to true if you want to output the current thread name. +# Defaults to true. +#org.slf4j.simpleLogger.showThreadName=true + +# Set to true if you want the Logger instance name to be included in output messages. +# Defaults to true. +#org.slf4j.simpleLogger.showLogName=true + +# Set to true if you want the last component of the name to be included in output messages. +# Defaults to false. +org.slf4j.simpleLogger.showShortLogName=true From 7c2b4b005fc729ede5fb8e6103f609d53b23d44a Mon Sep 17 00:00:00 2001 From: max904 Date: Mon, 18 May 2020 18:42:16 +0200 Subject: [PATCH 781/882] - upgraded Armeria to the latest version 0.99.5 and removed explicit Netty dependency - reworked ArmeriaHttpClientConfig and added configurations for clientOptions, clientFactory, protocolPreference, retry and logging - added ArmeriaWebClientBuilder to build new WebClient using newWebClient(String scheme, String authority) - adjusted ArmeriaHttpClient and ArmeriaHttpClientTest - added more JavaDoc - removed simplelogger.properties used for tests --- scribejava-httpclient-armeria/pom.xml | 12 +- .../httpclient/armeria/ArmeriaHttpClient.java | 169 ++++--------- .../armeria/ArmeriaHttpClientConfig.java | 237 ++++++++++++------ .../armeria/ArmeriaWebClientBuilder.java | 74 ++++++ .../armeria/ArmeriaHttpClientTest.java | 10 +- .../test/resources/simplelogger.properties | 29 --- 6 files changed, 307 insertions(+), 224 deletions(-) create mode 100644 scribejava-httpclient-armeria/src/main/java/com/github/scribejava/httpclient/armeria/ArmeriaWebClientBuilder.java delete mode 100644 scribejava-httpclient-armeria/src/test/resources/simplelogger.properties diff --git a/scribejava-httpclient-armeria/pom.xml b/scribejava-httpclient-armeria/pom.xml index e11a41915..e8ff5b167 100644 --- a/scribejava-httpclient-armeria/pom.xml +++ b/scribejava-httpclient-armeria/pom.xml @@ -22,19 +22,19 @@ com.linecorp.armeria armeria - 0.97.0 + 0.99.5 com.github.scribejava - scribejava-core + scribejava-apis ${project.version} - test-jar test - io.netty - netty-all - 4.1.43.Final + com.github.scribejava + scribejava-core + ${project.version} + test-jar test diff --git a/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClient.java b/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClient.java index d3b8a6359..fb372f83c 100644 --- a/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClient.java +++ b/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClient.java @@ -1,7 +1,8 @@ package com.github.scribejava.httpclient.armeria; +import static java.util.Objects.requireNonNull; + import com.github.scribejava.core.httpclient.AbstractAsyncOnlyHttpClient; -import com.github.scribejava.core.httpclient.HttpClientConfig; import com.github.scribejava.core.httpclient.multipart.MultipartPayload; import com.github.scribejava.core.httpclient.multipart.MultipartUtils; import com.github.scribejava.core.model.OAuthAsyncRequestCallback; @@ -9,27 +10,18 @@ import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; import com.github.scribejava.core.model.Verb; -import com.linecorp.armeria.client.ClientFactory; -import com.linecorp.armeria.client.ClientFactoryBuilder; -import com.linecorp.armeria.client.ClientFactoryOptionValue; -import com.linecorp.armeria.client.ClientOptions; -import com.linecorp.armeria.client.Endpoint; import com.linecorp.armeria.client.WebClient; -import com.linecorp.armeria.client.WebClientBuilder; -import com.linecorp.armeria.client.logging.LoggingClient; import com.linecorp.armeria.common.AggregatedHttpResponse; import com.linecorp.armeria.common.HttpData; import com.linecorp.armeria.common.HttpMethod; import com.linecorp.armeria.common.HttpResponse; import com.linecorp.armeria.common.RequestHeaders; import com.linecorp.armeria.common.RequestHeadersBuilder; -import com.linecorp.armeria.common.SessionProtocol; import java.io.File; import java.io.IOException; import java.net.URI; import java.nio.file.Files; -import java.util.Collection; import java.util.HashMap; import java.util.Map; import java.util.concurrent.CompletableFuture; @@ -38,10 +30,23 @@ import java.util.concurrent.locks.ReentrantReadWriteLock; import java.util.function.Supplier; +/** + * An implementation of {@link AbstractAsyncOnlyHttpClient} based on + * Armeria HTTP client. + */ public class ArmeriaHttpClient extends AbstractAsyncOnlyHttpClient { - private final ArmeriaHttpClientConfig config; + /** + * A builder of new instances of Armeria's {@link WebClient} + */ + private final ArmeriaWebClientBuilder clientBuilder; + /** + * A list of cached Endpoints. It helps avoiding building a new Endpoint per each request. + */ private final Map httpClients = new HashMap<>(); + /** + * A read/write lock to access the list of cached Endpoints concurrently. + */ private final ReentrantReadWriteLock httpClientsLock = new ReentrantReadWriteLock(); public ArmeriaHttpClient() { @@ -49,15 +54,11 @@ public ArmeriaHttpClient() { } public ArmeriaHttpClient(ArmeriaHttpClientConfig config) { - this.config = config; - } - - public HttpClientConfig getConfig() { - return config; + this.clientBuilder = config.builder(); } /** - * Cleans up HTTP clients collection. + * Cleans up the list of cached Endpoints. */ @Override public void close() { @@ -112,7 +113,7 @@ private CompletableFuture doExecuteAsync(String userAgent, final String path = getServicePath(uri); // Fetch/Create WebClient instance for a given Endpoint - final WebClient client = getHttpClient(uri); + final WebClient client = getClient(uri); // Build HTTP request final RequestHeadersBuilder headersBuilder = @@ -148,55 +149,19 @@ private CompletableFuture doExecuteAsync(String userAgent, //------------------------------------------------------------------------------------------------ /** - * Extracts Protocol + Host + Port part from a given endpoint {@link URI} - * @param uri an endpoint {@link URI} - * @return a portion of {@link URI} including a combination of Protocol + Host + Port - * @see #getHttpClient(URI uri) - */ - private String getHostUri(final URI uri) { - final StringBuilder builder = new StringBuilder(); - builder.append(uri.getScheme()).append("://").append(uri.getHost()); - final int port = uri.getPort(); - if (port > 0) { - builder.append(":").append(port); - } - return builder.toString(); - } - - /** - * Extracts service path from a given endpoint {@link URI} - * @param uri an endpoint {@link URI} - * @return service path portion of the {@link URI} - */ - private static String getServicePath(final URI uri) { - final StringBuilder builder = new StringBuilder(); - final String path = uri.getRawPath(); - if (path != null && path.length() > 0) { - builder.append(path); - } else { - builder.append("/"); - } - final String query = uri.getRawQuery(); - if (query != null && query.length() > 0) { - builder.append("?").append(query); - } - return builder.toString(); - } - - /** - * Provides and instance of {@link WebClient} for a given endpoint {@link URI} based on - * a combination of Protocol + Host + Port. + * Provides an instance of {@link WebClient} for a given endpoint {@link URI} based on an endpoint + * as {@code scheme://authority}. * @param uri an endpoint {@link URI} * @return {@link WebClient} instance */ - private WebClient getHttpClient(final URI uri) { - final String hostUri = getHostUri(uri); + private WebClient getClient(final URI uri) { + final String endpoint = getEndPoint(uri); WebClient client; final Lock readLock = httpClientsLock.readLock(); readLock.lock(); try { - client = httpClients.get(hostUri); + client = httpClients.get(endpoint); } finally { readLock.unlock(); } @@ -205,16 +170,18 @@ private WebClient getHttpClient(final URI uri) { return client; } - client = buildNewHttpClient(uri); + client = clientBuilder.newWebClient( + requireNonNull(uri.getScheme(), "scheme"), + requireNonNull(uri.getAuthority(), "authority")); final Lock writeLock = httpClientsLock.writeLock(); writeLock.lock(); try { - if (!httpClients.containsKey(hostUri)) { - httpClients.put(hostUri, client); + if (!httpClients.containsKey(endpoint)) { + httpClients.put(endpoint, client); return client; } else { - return httpClients.get(hostUri); + return httpClients.get(endpoint); } } finally { writeLock.unlock(); @@ -222,63 +189,35 @@ private WebClient getHttpClient(final URI uri) { } /** - * Builds a brand-new instance of {@link WebClient} for a given endpoint {@link URI}. - * Uses {@link ArmeriaHttpClientConfig} to configure the builder and the client. - * @param uri an endpoint {@link URI} - * @return Brand-new {@link WebClient} instance + * Extracts {@code scheme} and {@code authority} portion of the {@link URI}. + * Assuming the {@link URI} as the following: + * {@code URI = scheme:[//authority]path[?query][#fragment]} */ - private WebClient buildNewHttpClient(final URI uri) { - // Build the client and the headers - WebClientBuilder clientBuilder = - getHttpClientBuilder(uri, config.getSessionProtocolPreference()); - - final ClientOptions clientOptions = config.getClientOptions(); - if (clientOptions != null) { - clientBuilder.options(clientOptions); - } - - final ClientFactoryBuilder clientFactoryBuilder = ClientFactory.builder(); - final Collection> clientFactoryOptions = config.getClientFactoryOptions(); - if (clientFactoryOptions != null && !clientFactoryOptions.isEmpty()) { - clientFactoryOptions.forEach(clientFactoryBuilder::option); - } - clientBuilder.factory(clientFactoryBuilder.build()); - - if (config.isLogging()) { - clientBuilder = clientBuilder.decorator(LoggingClient.newDecorator()); - } - - return clientBuilder.build(); + @SuppressWarnings("StringBufferReplaceableByString") + private static String getEndPoint(final URI uri) { + final StringBuilder builder = new StringBuilder() + .append(requireNonNull(uri.getScheme(), "scheme")) + .append("://").append(requireNonNull(uri.getAuthority(), "authority")); + return builder.toString(); } /** - * Provides an instance of {@link WebClientBuilder} for a given endpoint {@link URI} - * @param uri an endpoint {@link URI} - * @param protocolPreference an HTTP protocol generation preference; acceptable values: "h1" or "h2". - * @return {@link WebClientBuilder} instance to build a new {@link WebClient} + * Extracts {@code path}, {@code query) and {@code fragment} portion of the {@link URI}. + * Assuming the {@link URI} as the following: + * {@code URI = scheme:[//authority]path[?query][#fragment]} */ - private WebClientBuilder getHttpClientBuilder(final URI uri, final SessionProtocol protocolPreference) { - final SessionProtocol sessionProtocol = SessionProtocol.of(uri.getScheme()); - final String host = uri.getHost(); - final int port = uri.getPort(); - final Endpoint endpoint = (port > 0) ? Endpoint.of(host, port) : Endpoint.of(host); - switch(sessionProtocol) { - case HTTP: - if (protocolPreference == SessionProtocol.H1) { - // enforce HTTP/1 protocol - return WebClient.builder(SessionProtocol.H1C, endpoint); - } - break; - case HTTPS: - if (protocolPreference == SessionProtocol.H1) { - // enforce HTTP/1 protocol - return WebClient.builder(SessionProtocol.H1, endpoint); - } - break; - default: - break; + private static String getServicePath(final URI uri) { + final StringBuilder builder = new StringBuilder() + .append(requireNonNull(uri.getPath(), "path")); + final String query = uri.getQuery(); + if (query != null) { + builder.append('?').append(query); } - return WebClient.builder(sessionProtocol, endpoint); + final String fragment = uri.getFragment(); + if (fragment != null) { + builder.append('#').append(fragment); + } + return builder.toString(); } /** @@ -286,7 +225,7 @@ private WebClientBuilder getHttpClientBuilder(final URI uri, final SessionProtoc * @param httpVerb a {@link Verb} to match with {@link HttpMethod} * @return {@link HttpMethod} corresponding to the parameter */ - private HttpMethod getHttpMethod(final Verb httpVerb) { + private static HttpMethod getHttpMethod(final Verb httpVerb) { switch (httpVerb) { case GET: return HttpMethod.GET; diff --git a/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClientConfig.java b/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClientConfig.java index 0b566de4a..97b13e5c3 100644 --- a/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClientConfig.java +++ b/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClientConfig.java @@ -1,104 +1,199 @@ package com.github.scribejava.httpclient.armeria; import com.github.scribejava.core.httpclient.HttpClientConfig; -import com.linecorp.armeria.client.ClientFactoryOption; -import com.linecorp.armeria.client.ClientFactoryOptionValue; -import com.linecorp.armeria.client.ClientOption; +import com.linecorp.armeria.client.ClientFactory; import com.linecorp.armeria.client.ClientOptions; -import com.linecorp.armeria.client.ClientOptionsBuilder; +import com.linecorp.armeria.client.HttpClient; +import com.linecorp.armeria.client.logging.LoggingClient; +import com.linecorp.armeria.client.retry.Backoff; +import com.linecorp.armeria.client.retry.RetryRule; +import com.linecorp.armeria.client.retry.RetryingClient; +import com.linecorp.armeria.common.HttpStatus; import com.linecorp.armeria.common.SessionProtocol; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.Map; +import com.linecorp.armeria.common.logging.LogLevel; +import java.util.function.Function; +import org.slf4j.LoggerFactory; public class ArmeriaHttpClientConfig implements HttpClientConfig { - private Map options; - private Map factoryOptions; - private String protocolPreference; - private Boolean logging; - - ClientOptions getClientOptions() { - if (options == null || options.isEmpty()) { - return null; - } - final ClientOptionsBuilder builder = ClientOptions.builder(); - for (Map.Entry optionEntry : options.entrySet()) { - builder.option(ClientOption.valueOf(optionEntry.getKey()), optionEntry.getValue()); - } - return builder.build(); + private static final SessionProtocol DEFAULT_PROTOCOL_PREFERENCE = SessionProtocol.H1; // H1 or H2 + + private final ClientOptions clientOptions; + private final ClientFactory clientFactory; + private SessionProtocol protocolPreference; + private Function retry; + private Function logging; + + /** + * Creates new {@link ArmeriaHttpClientConfig} using provided {@link ClientOptions} and + * {@link ClientFactory}. + */ + public ArmeriaHttpClientConfig(ClientOptions clientOptions, ClientFactory clientFactory) { + this.clientOptions = clientOptions; + this.clientFactory = clientFactory; + protocolPreference = DEFAULT_PROTOCOL_PREFERENCE; } - public Map getOptions() { - return options; + /** + * Creates new {@link ArmeriaHttpClientConfig} using default settings. + */ + ArmeriaHttpClientConfig() { + this(null, null); } - public void setOptions(Map options) { - this.options = options; - } - - Collection> getClientFactoryOptions() { - if (factoryOptions == null || factoryOptions.isEmpty()) { - return Collections.emptyList(); - } - final List> options = new ArrayList<>(); - for (Map.Entry optionEntry : factoryOptions.entrySet()) { - options.add(ClientFactoryOption.valueOf(optionEntry.getKey()).newValue(optionEntry.getValue())); - } - // WARNING: this ClientFactoryOptions.of(options) method will override default channel options of the factory - // and cause NPE - //return ClientFactoryOptions.of(options); - return options; + /** + * Creates new {@link HttpClientConfig} using default settings. + */ + @Override + public HttpClientConfig createDefaultConfig() { + return defaultConfig(); } - public Map getFactoryOptions() { - return factoryOptions; + /** + * Creates new {@link ArmeriaHttpClientConfig} using default settings. + */ + public static ArmeriaHttpClientConfig defaultConfig() { + return new ArmeriaHttpClientConfig(); } - public void setFactoryOptions(Map factoryOptions) { - this.factoryOptions = factoryOptions; + /** + * Selects which protocol shall take preference when generic protocol scheme used by the URL, + * like {@code http} or {@code https}. + * + * @param protocolPreference specifies which protocol shall take preference. + * Acceptable values: {@code H1}, {@code HTTP1}, {@code HTTP/1.1} for + * {@code HTTP/1.1} and {@code H2}, {@code HTTP2}, {@code HTTP/2} for + * {@code HTTP/2}. + */ + public void protocolPreference(String protocolPreference) { + switch (protocolPreference.toUpperCase()) { + case "H1": + case "HTTP1": + case "HTTP/1.1": + this.protocolPreference = SessionProtocol.H1; + break; + case "H2": + case "HTTP2": + case "HTTP/2": + this.protocolPreference = SessionProtocol.H2; + break; + default: + throw new IllegalArgumentException("Invalid protocolPreference: " + protocolPreference); + } } - SessionProtocol getSessionProtocolPreference() { - if (protocolPreference == null) { - return SessionProtocol.H1; // default - } - final SessionProtocol protocol = SessionProtocol.of(protocolPreference); - switch(protocol) { + /** + * Selects which protocol shall take preference when generic protocol scheme used by the URL, + * like {@code http} or {@code https}. + * + * @param protocolPreference specifies which protocol shall take preference. + * Acceptable values: {@link SessionProtocol#H1} and + * {@link SessionProtocol#H2} + */ + public void protocolPreference(SessionProtocol protocolPreference) { + switch (protocolPreference) { case H1: - case H1C: - return SessionProtocol.H1; - case PROXY: - throw new IllegalArgumentException("protocolPreference - " + SessionProtocol.PROXY.uriText()); + this.protocolPreference = SessionProtocol.H1; + break; + case H2: + this.protocolPreference = SessionProtocol.H2; + break; default: - return SessionProtocol.H2; + throw new IllegalArgumentException("Invalid protocolPreference: " + protocolPreference); } } - public String getProtocolPreference() { - return protocolPreference; + /** + * Sets the client to retry when the remote end-point responds with one of the + * specified {@code statuses}. + * + * Uses a backoff that computes a delay using one of supported functions, such as + * {@code exponential(long, long, double)}, {@code fibonacci(long, long)}, {@code fixed(long)} + * and {@code random(long, long)} chaining with {@code withJitter(double, double)} and + * {@code withMaxAttempts(int)} from the {@code backoff} string that conforms to + * the following format: + *
      + *
    • {@code exponential=[initialDelayMillis:maxDelayMillis:multiplier]} is for + * {@code exponential(long, long, double)} (multiplier will be 2.0 if it's omitted)
    • + *
    • {@code fibonacci=[initialDelayMillis:maxDelayMillis]} is for + * {@code fibonacci(long, long)}
    • + *
    • {@code fixed=[delayMillis]} is for {@code fixed(long)}
    • + *
    • {@code random=[minDelayMillis:maxDelayMillis]} is for {@code random(long, long)}
    • + *
    • {@code jitter=[minJitterRate:maxJitterRate]} is for {@code withJitter(double, double)} + * (if only one jitter value is specified, it will be used for {@code withJitter(double)}
    • + *
    • {@code maxAttempts=[maxAttempts]} is for {@code withMaxAttempts(int)}
    • + *
    + * The order of options does not matter, and the {@code backoff} needs at least one option. + * If you don't specify the base option exponential backoff will be used. If you only specify + * a base option, jitter and maxAttempts will be set by default values. For example: + *
      + *
    • {@code exponential=200:10000:2.0,jitter=0.2} (default)
    • + *
    • {@code exponential=200:10000,jitter=0.2,maxAttempts=50} (multiplier omitted)
    • + *
    • {@code fibonacci=200:10000,jitter=0.2,maxAttempts=50}
    • + *
    • {@code fixed=100,jitter=-0.5:0.2,maxAttempts=10} (fixed backoff with jitter variation)
    • + *
    • {@code random=200:1000} (jitter and maxAttempts will be set by default values)
    • + *
    + * + * @param backoff the specification used to create a retry backoff + * @param statuses the list of HTTP statuses on which to retry + */ + public void retry(String backoff, HttpStatus... statuses) { + final Backoff retryBackoff = Backoff.of(backoff); + final RetryRule retryRule = + RetryRule.builder().onStatus(statuses).onUnprocessed().thenBackoff(retryBackoff); + retry = RetryingClient.newDecorator(retryRule); } - public void setProtocolPreference(String protocolPreference) { - this.protocolPreference = protocolPreference; + /** + * Sets the client to log requests and responses to the specified {@code logger}. + * This method explicitly specifies various log levels. The log level correspond to a value + * of {@link LogLevel} and must use one of the following values: + * {@code ["OFF", "TRACE", "DEBUG", "INFO", "WARN", "ERROR"]} + * + * @param logger the logger name (of {@link org.slf4j.Logger}) to log requests/responses to + * @param requestLevel the log level to use for logging requests, default {@code "DEBUG"} + * @param responseLevel the log level to use for logging responses, default {@code "DEBUG"} + * @param failureResponseLevel the log level to use for logging error responses, + * default {@code "WARN"} + */ + public void logging(String logger, String requestLevel, String responseLevel, + String failureResponseLevel) { + this.logging = LoggingClient.builder() + .logger(LoggerFactory.getLogger(logger)) + .requestLogLevel(LogLevel.valueOf(requestLevel)) + .successfulResponseLogLevel(LogLevel.valueOf(responseLevel)) + .failureResponseLogLevel(LogLevel.valueOf(failureResponseLevel)) + .newDecorator(); } - public boolean isLogging() { - return logging != null && logging; + /** + * Sets the client to log requests and responses to the specified {@code logger} using default + * log levels. + * + * @param logger the logger name (of {@link org.slf4j.Logger}) to log requests/responses to + */ + public void logging(String logger) { + this.logging = LoggingClient.builder() + .logger(LoggerFactory.getLogger(logger)) + .requestLogLevel(LogLevel.DEBUG) + .successfulResponseLogLevel(LogLevel.DEBUG) + .failureResponseLogLevel(LogLevel.WARN) + .newDecorator(); } - public void setLogging(boolean logging) { - this.logging = logging; + /** + * Sets the client to log requests and responses to a default logger using default log levels. + */ + public void logging() { + this.logging = LoggingClient.builder() + .requestLogLevel(LogLevel.DEBUG) + .successfulResponseLogLevel(LogLevel.DEBUG) + .failureResponseLogLevel(LogLevel.WARN) + .newDecorator(); } - @Override - public HttpClientConfig createDefaultConfig() { - return defaultConfig(); - } - - public static ArmeriaHttpClientConfig defaultConfig() { - return new ArmeriaHttpClientConfig(); + ArmeriaWebClientBuilder builder() { + return new ArmeriaWebClientBuilder(clientOptions, clientFactory, protocolPreference, + retry, logging); } } diff --git a/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/httpclient/armeria/ArmeriaWebClientBuilder.java b/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/httpclient/armeria/ArmeriaWebClientBuilder.java new file mode 100644 index 000000000..e79c9c27c --- /dev/null +++ b/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/httpclient/armeria/ArmeriaWebClientBuilder.java @@ -0,0 +1,74 @@ +package com.github.scribejava.httpclient.armeria; + +import com.linecorp.armeria.client.ClientFactory; +import com.linecorp.armeria.client.ClientOptions; +import com.linecorp.armeria.client.Endpoint; +import com.linecorp.armeria.client.HttpClient; +import com.linecorp.armeria.client.WebClient; +import com.linecorp.armeria.client.WebClientBuilder; +import com.linecorp.armeria.client.logging.LoggingClient; +import com.linecorp.armeria.client.retry.RetryingClient; +import com.linecorp.armeria.common.SessionProtocol; +import java.util.function.Function; + +/** + * A builder of {@link WebClient} using supplied configuration parameters. + */ +public class ArmeriaWebClientBuilder { + + private final ClientFactory clientFactory; + private final ClientOptions clientOptions; + private final SessionProtocol protocolPreference; + private final Function retry; + private final Function logging; + + ArmeriaWebClientBuilder(ClientOptions clientOptions, ClientFactory clientFactory, + SessionProtocol protocolPreference, Function retry, + Function logging) { + this.clientOptions = clientOptions; + this.clientFactory = clientFactory; + this.protocolPreference = protocolPreference; + this.retry = retry; + this.logging = logging; + } + + WebClient newWebClient(String scheme, String authority) { + final SessionProtocol protocol = protocol(scheme); + final Endpoint endpoint = Endpoint.parse(authority); + final WebClientBuilder clientBuilder = WebClient.builder(protocol, endpoint); + if (clientOptions != null) { + clientBuilder.options(clientOptions); + } + if (clientFactory != null) { + clientBuilder.factory(clientFactory); + } + if (retry != null) { + clientBuilder.decorator(retry); + } + if (logging != null) { + clientBuilder.decorator(logging); + } + return clientBuilder.build(); + } + + private SessionProtocol protocol(String scheme) { + final SessionProtocol protocol = SessionProtocol.of(scheme); + switch(protocol) { + case HTTP: + if (protocolPreference == SessionProtocol.H1) { + // enforce HTTP/1 protocol + return SessionProtocol.H1C; + } + break; + case HTTPS: + if (protocolPreference == SessionProtocol.H1) { + // enforce HTTP/1 protocol + return SessionProtocol.H1; + } + break; + default: + break; + } + return protocol; + } +} diff --git a/scribejava-httpclient-armeria/src/test/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClientTest.java b/scribejava-httpclient-armeria/src/test/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClientTest.java index 3cdecee1a..508617acf 100644 --- a/scribejava-httpclient-armeria/src/test/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClientTest.java +++ b/scribejava-httpclient-armeria/src/test/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClientTest.java @@ -2,6 +2,8 @@ import com.github.scribejava.core.AbstractClientTest; import com.github.scribejava.core.httpclient.HttpClient; +import com.linecorp.armeria.client.ClientFactory; +import com.linecorp.armeria.common.HttpStatus; import io.netty.channel.EventLoopGroup; import io.netty.resolver.AbstractAddressResolver; import io.netty.resolver.AddressResolver; @@ -22,10 +24,12 @@ protected HttpClient createNewClient() { // simulate DNS resolution for a mock address ("kubernetes.docker.internal") final Function> addressResolverGroupFactory = eventLoopGroup -> new MockAddressResolverGroup(); - config.setFactoryOptions(// No-Op DNS resolver to avoid resolution issues in the unit test - Collections.singletonMap("ADDRESS_RESOLVER_GROUP_FACTORY", addressResolverGroupFactory)); + // No-Op DNS resolver to avoid resolution issues in the unit test + ClientFactory.builder().addressResolverGroupFactory(addressResolverGroupFactory); // enable client-side HTTP tracing - config.setLogging(true); + config.logging("HTTP_TRACE", "INFO", "INFO", "WARN"); + // enable request retry + config.retry("exponential=200:10000,jitter=0.2,maxAttempts=5", HttpStatus.SERVICE_UNAVAILABLE); return new ArmeriaHttpClient(config); } diff --git a/scribejava-httpclient-armeria/src/test/resources/simplelogger.properties b/scribejava-httpclient-armeria/src/test/resources/simplelogger.properties deleted file mode 100644 index ce703174e..000000000 --- a/scribejava-httpclient-armeria/src/test/resources/simplelogger.properties +++ /dev/null @@ -1,29 +0,0 @@ -# SLF4J's SimpleLogger configuration file -# Simple implementation of Logger that sends all enabled log messages, for all defined loggers, to System.err. - -# Default logging detail level for all instances of SimpleLogger. -# Must be one of ("trace", "debug", "info", "warn", or "error"). -# If not specified, defaults to "info". -org.slf4j.simpleLogger.defaultLogLevel=debug - -# Set to true if you want the current date and time to be included in output messages. -# Default is false, and will output the number of milliseconds elapsed since startup. -org.slf4j.simpleLogger.showDateTime=true - -# The date and time format to be used in the output messages. -# The pattern describing the date and time format is the same that is used in java.text.SimpleDateFormat. -# If the format is not specified or is invalid, the default format is used. -# The default format is yyyy-MM-dd HH:mm:ss:SSS Z. -org.slf4j.simpleLogger.dateTimeFormat=[HH:mm:ss] - -# Set to true if you want to output the current thread name. -# Defaults to true. -#org.slf4j.simpleLogger.showThreadName=true - -# Set to true if you want the Logger instance name to be included in output messages. -# Defaults to true. -#org.slf4j.simpleLogger.showLogName=true - -# Set to true if you want the last component of the name to be included in output messages. -# Defaults to false. -org.slf4j.simpleLogger.showShortLogName=true From 6e5c62c69c546b9881d2875ff2ff4d318c0448e6 Mon Sep 17 00:00:00 2001 From: max904 Date: Tue, 26 May 2020 17:26:23 +0200 Subject: [PATCH 782/882] - plugged custom/mock address resolver to optimize the unit test execution --- .../scribejava/httpclient/armeria/ArmeriaHttpClientTest.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/scribejava-httpclient-armeria/src/test/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClientTest.java b/scribejava-httpclient-armeria/src/test/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClientTest.java index 508617acf..1078a563c 100644 --- a/scribejava-httpclient-armeria/src/test/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClientTest.java +++ b/scribejava-httpclient-armeria/src/test/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClientTest.java @@ -20,12 +20,13 @@ public class ArmeriaHttpClientTest extends AbstractClientTest { @Override protected HttpClient createNewClient() { - final ArmeriaHttpClientConfig config = ArmeriaHttpClientConfig.defaultConfig(); // simulate DNS resolution for a mock address ("kubernetes.docker.internal") final Function> addressResolverGroupFactory = eventLoopGroup -> new MockAddressResolverGroup(); // No-Op DNS resolver to avoid resolution issues in the unit test - ClientFactory.builder().addressResolverGroupFactory(addressResolverGroupFactory); + final ClientFactory clientFactory = + ClientFactory.builder().addressResolverGroupFactory(addressResolverGroupFactory).build(); + final ArmeriaHttpClientConfig config = new ArmeriaHttpClientConfig(null, clientFactory); // enable client-side HTTP tracing config.logging("HTTP_TRACE", "INFO", "INFO", "WARN"); // enable request retry From aeed26798f7e4bb1642ca743123de64c98d7603a Mon Sep 17 00:00:00 2001 From: max904 Date: Thu, 28 May 2020 12:02:17 +0200 Subject: [PATCH 783/882] - updated Armeria to version 0.99.6 --- scribejava-httpclient-armeria/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scribejava-httpclient-armeria/pom.xml b/scribejava-httpclient-armeria/pom.xml index e8ff5b167..51c5d8d4b 100644 --- a/scribejava-httpclient-armeria/pom.xml +++ b/scribejava-httpclient-armeria/pom.xml @@ -22,7 +22,7 @@ com.linecorp.armeria armeria - 0.99.5 + 0.99.6 com.github.scribejava From bc7ac12b2144deafdf7df00f83bca39873420f11 Mon Sep 17 00:00:00 2001 From: max904 Date: Thu, 25 Jun 2020 20:26:52 +0200 Subject: [PATCH 784/882] - updated Armeria to version 0.99.7 --- scribejava-httpclient-armeria/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scribejava-httpclient-armeria/pom.xml b/scribejava-httpclient-armeria/pom.xml index 51c5d8d4b..6642e9cad 100644 --- a/scribejava-httpclient-armeria/pom.xml +++ b/scribejava-httpclient-armeria/pom.xml @@ -22,7 +22,7 @@ com.linecorp.armeria armeria - 0.99.6 + 0.99.7 com.github.scribejava From 4fa982bec3832c035c8a408aa08c8c6067962c38 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Sat, 1 Aug 2020 18:49:41 +0300 Subject: [PATCH 785/882] format code --- .../httpclient/multipart/MultipartUtils.java | 74 +-- .../httpclient/armeria/ArmeriaHttpClient.java | 606 +++++++++--------- .../armeria/ArmeriaHttpClientConfig.java | 323 +++++----- .../httpclient/armeria/ArmeriaProvider.java | 12 +- .../armeria/ArmeriaWebClientBuilder.java | 98 +-- .../armeria/ArmeriaHttpClientTest.java | 80 ++- 6 files changed, 592 insertions(+), 601 deletions(-) diff --git a/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/core/httpclient/multipart/MultipartUtils.java b/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/core/httpclient/multipart/MultipartUtils.java index bbbbad078..f995e4b4e 100644 --- a/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/core/httpclient/multipart/MultipartUtils.java +++ b/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/core/httpclient/multipart/MultipartUtils.java @@ -7,47 +7,47 @@ public abstract class MultipartUtils { - // copied from com.github.scribejava.core.httpclient.jdk.JDKHttpClient#getPayload - public static ByteArrayOutputStream getPayload(MultipartPayload multipartPayload) throws IOException { - final ByteArrayOutputStream os = new ByteArrayOutputStream(); + // copied from com.github.scribejava.core.httpclient.jdk.JDKHttpClient#getPayload + public static ByteArrayOutputStream getPayload(MultipartPayload multipartPayload) throws IOException { + final ByteArrayOutputStream os = new ByteArrayOutputStream(); - final String preamble = multipartPayload.getPreamble(); - if (preamble != null) { - os.write(preamble.getBytes()); - } - final List bodyParts = multipartPayload.getBodyParts(); - if (!bodyParts.isEmpty()) { - final String boundary = multipartPayload.getBoundary(); - final byte[] startBoundary = ("\r\n--" + boundary + "\r\n").getBytes(); - - for (BodyPartPayload bodyPart : bodyParts) { - os.write(startBoundary); - - final Map bodyPartHeaders = bodyPart.getHeaders(); - if (bodyPartHeaders != null) { - for (Map.Entry header : bodyPartHeaders.entrySet()) { - os.write((header.getKey() + ": " + header.getValue() + "\r\n").getBytes()); - } + final String preamble = multipartPayload.getPreamble(); + if (preamble != null) { + os.write(preamble.getBytes()); } + final List bodyParts = multipartPayload.getBodyParts(); + if (!bodyParts.isEmpty()) { + final String boundary = multipartPayload.getBoundary(); + final byte[] startBoundary = ("\r\n--" + boundary + "\r\n").getBytes(); + + for (BodyPartPayload bodyPart : bodyParts) { + os.write(startBoundary); + + final Map bodyPartHeaders = bodyPart.getHeaders(); + if (bodyPartHeaders != null) { + for (Map.Entry header : bodyPartHeaders.entrySet()) { + os.write((header.getKey() + ": " + header.getValue() + "\r\n").getBytes()); + } + } + + if (bodyPart instanceof MultipartPayload) { + getPayload((MultipartPayload) bodyPart).writeTo(os); + } else if (bodyPart instanceof ByteArrayBodyPartPayload) { + os.write("\r\n".getBytes()); + os.write(((ByteArrayBodyPartPayload) bodyPart).getPayload()); + } else { + throw new AssertionError(bodyPart.getClass()); + } + } + + os.write(("\r\n--" + boundary + "--\r\n").getBytes()); + final String epilogue = multipartPayload.getEpilogue(); + if (epilogue != null) { + os.write((epilogue + "\r\n").getBytes()); + } - if (bodyPart instanceof MultipartPayload) { - getPayload((MultipartPayload) bodyPart).writeTo(os); - } else if (bodyPart instanceof ByteArrayBodyPartPayload) { - os.write("\r\n".getBytes()); - os.write(((ByteArrayBodyPartPayload) bodyPart).getPayload()); - } else { - throw new AssertionError(bodyPart.getClass()); } - } - - os.write(("\r\n--" + boundary + "--\r\n").getBytes()); - final String epilogue = multipartPayload.getEpilogue(); - if (epilogue != null) { - os.write((epilogue + "\r\n").getBytes()); - } - + return os; } - return os; - } } diff --git a/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClient.java b/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClient.java index fb372f83c..b059d6f04 100644 --- a/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClient.java +++ b/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClient.java @@ -36,344 +36,346 @@ */ public class ArmeriaHttpClient extends AbstractAsyncOnlyHttpClient { - /** - * A builder of new instances of Armeria's {@link WebClient} - */ - private final ArmeriaWebClientBuilder clientBuilder; - /** - * A list of cached Endpoints. It helps avoiding building a new Endpoint per each request. - */ - private final Map httpClients = new HashMap<>(); - /** - * A read/write lock to access the list of cached Endpoints concurrently. - */ - private final ReentrantReadWriteLock httpClientsLock = new ReentrantReadWriteLock(); - - public ArmeriaHttpClient() { - this(ArmeriaHttpClientConfig.defaultConfig()); - } - - public ArmeriaHttpClient(ArmeriaHttpClientConfig config) { - this.clientBuilder = config.builder(); - } - - /** - * Cleans up the list of cached Endpoints. - */ - @Override - public void close() { - final Lock writeLock = httpClientsLock.writeLock(); - writeLock.lock(); - try { - httpClients.clear(); - } finally { - writeLock.unlock(); - } - } - - @Override - public Future executeAsync(String userAgent, Map headers, Verb httpVerb, - String completeUrl, byte[] bodyContents, OAuthAsyncRequestCallback callback, - OAuthRequest.ResponseConverter converter) { - return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, - new BytesBody(bodyContents), callback, converter); - } - - @Override - public Future executeAsync(String userAgent, Map headers, Verb httpVerb, - String completeUrl, MultipartPayload bodyContents, OAuthAsyncRequestCallback callback, - OAuthRequest.ResponseConverter converter) { - return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, - new MultipartBody(bodyContents), callback, converter); - } - - @Override - public Future executeAsync(String userAgent, Map headers, Verb httpVerb, - String completeUrl, String bodyContents, OAuthAsyncRequestCallback callback, - OAuthRequest.ResponseConverter converter) { - return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, - new StringBody(bodyContents), callback, converter); - } - - @Override - public Future executeAsync(String userAgent, Map headers, Verb httpVerb, - String completeUrl, File bodyContents, OAuthAsyncRequestCallback callback, - OAuthRequest.ResponseConverter converter) { - return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, - new FileBody(bodyContents), callback, converter); - } - - private CompletableFuture doExecuteAsync(String userAgent, - Map headers, Verb httpVerb, - String completeUrl, Supplier contentSupplier, - OAuthAsyncRequestCallback callback, - OAuthRequest.ResponseConverter converter) { - // Get the URI and Path - final URI uri = URI.create(completeUrl); - final String path = getServicePath(uri); - - // Fetch/Create WebClient instance for a given Endpoint - final WebClient client = getClient(uri); - - // Build HTTP request - final RequestHeadersBuilder headersBuilder = - RequestHeaders.of(getHttpMethod(httpVerb), path).toBuilder(); - headersBuilder.add(headers.entrySet()); - if (userAgent != null) { - headersBuilder.add(OAuthConstants.USER_AGENT_HEADER_NAME, userAgent); + /** + * A builder of new instances of Armeria's {@link WebClient} + */ + private final ArmeriaWebClientBuilder clientBuilder; + /** + * A list of cached Endpoints. It helps avoiding building a new Endpoint per each request. + */ + private final Map httpClients = new HashMap<>(); + /** + * A read/write lock to access the list of cached Endpoints concurrently. + */ + private final ReentrantReadWriteLock httpClientsLock = new ReentrantReadWriteLock(); + + public ArmeriaHttpClient() { + this(ArmeriaHttpClientConfig.defaultConfig()); } - // Build the request body and execute HTTP request - final HttpResponse response; - if (httpVerb.isPermitBody()) { // POST, PUT, PATCH and DELETE methods - final HttpData contents = contentSupplier.get(); - if (httpVerb.isRequiresBody() && contents == null) { // POST or PUT methods - throw new IllegalArgumentException( - "Contents missing for request method " + httpVerb.name()); - } - if (contents != null) { - response = client.execute(headersBuilder.build(), contents); - } else { - response = client.execute(headersBuilder.build()); - } - } else { - response = client.execute(headersBuilder.build()); + public ArmeriaHttpClient(ArmeriaHttpClientConfig config) { + this.clientBuilder = config.builder(); } - // Aggregate HTTP response (asynchronously) and return the result Future - return response.aggregate() - .thenApply(r -> whenResponseComplete(callback, converter, r)) - .exceptionally(e -> completeExceptionally(callback, e)); - } - - //------------------------------------------------------------------------------------------------ - - /** - * Provides an instance of {@link WebClient} for a given endpoint {@link URI} based on an endpoint - * as {@code scheme://authority}. - * @param uri an endpoint {@link URI} - * @return {@link WebClient} instance - */ - private WebClient getClient(final URI uri) { - final String endpoint = getEndPoint(uri); - - WebClient client; - final Lock readLock = httpClientsLock.readLock(); - readLock.lock(); - try { - client = httpClients.get(endpoint); - } finally { - readLock.unlock(); + /** + * Cleans up the list of cached Endpoints. + */ + @Override + public void close() { + final Lock writeLock = httpClientsLock.writeLock(); + writeLock.lock(); + try { + httpClients.clear(); + } finally { + writeLock.unlock(); + } } - if (client != null) { - return client; + @Override + public Future executeAsync(String userAgent, Map headers, Verb httpVerb, + String completeUrl, byte[] bodyContents, OAuthAsyncRequestCallback callback, + OAuthRequest.ResponseConverter converter) { + return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, + new BytesBody(bodyContents), callback, converter); } - client = clientBuilder.newWebClient( - requireNonNull(uri.getScheme(), "scheme"), - requireNonNull(uri.getAuthority(), "authority")); - - final Lock writeLock = httpClientsLock.writeLock(); - writeLock.lock(); - try { - if (!httpClients.containsKey(endpoint)) { - httpClients.put(endpoint, client); - return client; - } else { - return httpClients.get(endpoint); - } - } finally { - writeLock.unlock(); + @Override + public Future executeAsync(String userAgent, Map headers, Verb httpVerb, + String completeUrl, MultipartPayload bodyContents, OAuthAsyncRequestCallback callback, + OAuthRequest.ResponseConverter converter) { + return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, + new MultipartBody(bodyContents), callback, converter); } - } - - /** - * Extracts {@code scheme} and {@code authority} portion of the {@link URI}. - * Assuming the {@link URI} as the following: - * {@code URI = scheme:[//authority]path[?query][#fragment]} - */ - @SuppressWarnings("StringBufferReplaceableByString") - private static String getEndPoint(final URI uri) { - final StringBuilder builder = new StringBuilder() - .append(requireNonNull(uri.getScheme(), "scheme")) - .append("://").append(requireNonNull(uri.getAuthority(), "authority")); - return builder.toString(); - } - - /** - * Extracts {@code path}, {@code query) and {@code fragment} portion of the {@link URI}. - * Assuming the {@link URI} as the following: - * {@code URI = scheme:[//authority]path[?query][#fragment]} - */ - private static String getServicePath(final URI uri) { - final StringBuilder builder = new StringBuilder() - .append(requireNonNull(uri.getPath(), "path")); - final String query = uri.getQuery(); - if (query != null) { - builder.append('?').append(query); + + @Override + public Future executeAsync(String userAgent, Map headers, Verb httpVerb, + String completeUrl, String bodyContents, OAuthAsyncRequestCallback callback, + OAuthRequest.ResponseConverter converter) { + return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, + new StringBody(bodyContents), callback, converter); } - final String fragment = uri.getFragment(); - if (fragment != null) { - builder.append('#').append(fragment); + + @Override + public Future executeAsync(String userAgent, Map headers, Verb httpVerb, + String completeUrl, File bodyContents, OAuthAsyncRequestCallback callback, + OAuthRequest.ResponseConverter converter) { + return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, + new FileBody(bodyContents), callback, converter); } - return builder.toString(); - } - - /** - * Maps {@link Verb} to {@link HttpMethod} - * @param httpVerb a {@link Verb} to match with {@link HttpMethod} - * @return {@link HttpMethod} corresponding to the parameter - */ - private static HttpMethod getHttpMethod(final Verb httpVerb) { - switch (httpVerb) { - case GET: - return HttpMethod.GET; - case POST: - return HttpMethod.POST; - case PUT: - return HttpMethod.PUT; - case DELETE: - return HttpMethod.DELETE; - case HEAD: - return HttpMethod.HEAD; - case OPTIONS: - return HttpMethod.OPTIONS; - case TRACE: - return HttpMethod.TRACE; - case PATCH: - return HttpMethod.PATCH; - default: - throw new IllegalArgumentException( - "message build error: unsupported HTTP method: " + httpVerb.name()); + + private CompletableFuture doExecuteAsync(String userAgent, + Map headers, Verb httpVerb, + String completeUrl, Supplier contentSupplier, + OAuthAsyncRequestCallback callback, + OAuthRequest.ResponseConverter converter) { + // Get the URI and Path + final URI uri = URI.create(completeUrl); + final String path = getServicePath(uri); + + // Fetch/Create WebClient instance for a given Endpoint + final WebClient client = getClient(uri); + + // Build HTTP request + final RequestHeadersBuilder headersBuilder + = RequestHeaders.of(getHttpMethod(httpVerb), path).toBuilder(); + headersBuilder.add(headers.entrySet()); + if (userAgent != null) { + headersBuilder.add(OAuthConstants.USER_AGENT_HEADER_NAME, userAgent); + } + + // Build the request body and execute HTTP request + final HttpResponse response; + if (httpVerb.isPermitBody()) { // POST, PUT, PATCH and DELETE methods + final HttpData contents = contentSupplier.get(); + if (httpVerb.isRequiresBody() && contents == null) { // POST or PUT methods + throw new IllegalArgumentException( + "Contents missing for request method " + httpVerb.name()); + } + if (contents != null) { + response = client.execute(headersBuilder.build(), contents); + } else { + response = client.execute(headersBuilder.build()); + } + } else { + response = client.execute(headersBuilder.build()); + } + + // Aggregate HTTP response (asynchronously) and return the result Future + return response.aggregate() + .thenApply(r -> whenResponseComplete(callback, converter, r)) + .exceptionally(e -> completeExceptionally(callback, e)); } - } - - //------------------------------------------------------------------------------------------------ - // Response asynchronous handlers - - /** - * Converts {@link AggregatedHttpResponse} to {@link Response} - * @param aggregatedResponse an instance of {@link AggregatedHttpResponse} to convert to {@link Response} - * @return a {@link Response} converted from {@link AggregatedHttpResponse} - */ - private Response convertResponse(final AggregatedHttpResponse aggregatedResponse) { - final Map headersMap = new HashMap<>(aggregatedResponse.headers().size()); - aggregatedResponse.headers() - .forEach((header, value) -> headersMap.put(header.toString(), value)); - return new Response(aggregatedResponse.status().code(), - aggregatedResponse.status().reasonPhrase(), - headersMap, aggregatedResponse.content().toInputStream()); - } - - /** - * Converts {@link AggregatedHttpResponse} to {@link Response} upon its aggregation completion - * and invokes {@link OAuthAsyncRequestCallback} for it. - * @param callback a {@link OAuthAsyncRequestCallback} callback to invoke upon response completion - * @param converter an optional {@link OAuthRequest.ResponseConverter} result converter for {@link Response} - * @param aggregatedResponse a source {@link AggregatedHttpResponse} to handle - * @param converter {@link OAuthRequest.ResponseConverter} specific type or {@link Response} - * @return either instance of {@link Response} or converted result based on {@link OAuthRequest.ResponseConverter} - */ - private T whenResponseComplete(OAuthAsyncRequestCallback callback, - OAuthRequest.ResponseConverter converter, AggregatedHttpResponse aggregatedResponse) { - final Response response = convertResponse(aggregatedResponse); - try { - @SuppressWarnings("unchecked") final T t = - converter == null ? (T) response : converter.convert(response); - if (callback != null) { - callback.onCompleted(t); - } - return t; - } catch (IOException | RuntimeException e) { - return completeExceptionally(callback, e); + + //------------------------------------------------------------------------------------------------ + /** + * Provides an instance of {@link WebClient} for a given endpoint {@link URI} based on an endpoint as + * {@code scheme://authority}. + * + * @param uri an endpoint {@link URI} + * @return {@link WebClient} instance + */ + private WebClient getClient(final URI uri) { + final String endpoint = getEndPoint(uri); + + WebClient client; + final Lock readLock = httpClientsLock.readLock(); + readLock.lock(); + try { + client = httpClients.get(endpoint); + } finally { + readLock.unlock(); + } + + if (client != null) { + return client; + } + + client = clientBuilder.newWebClient( + requireNonNull(uri.getScheme(), "scheme"), + requireNonNull(uri.getAuthority(), "authority")); + + final Lock writeLock = httpClientsLock.writeLock(); + writeLock.lock(); + try { + if (!httpClients.containsKey(endpoint)) { + httpClients.put(endpoint, client); + return client; + } else { + return httpClients.get(endpoint); + } + } finally { + writeLock.unlock(); + } } - } - - /** - * Invokes {@link OAuthAsyncRequestCallback} upon {@link Throwable} error result - * @param callback a {@link OAuthAsyncRequestCallback} callback to invoke upon response completion - * @param throwable a {@link Throwable} error result - * @param converter {@link OAuthRequest.ResponseConverter} specific type or {@link Response} - * @return null - */ - private T completeExceptionally(OAuthAsyncRequestCallback callback, Throwable throwable) { - if (callback != null) { - callback.onThrowable(throwable); + + /** + * Extracts {@code scheme} and {@code authority} portion of the {@link URI}. Assuming the {@link URI} as the + * following: {@code URI = scheme:[//authority]path[?query][#fragment]} + */ + @SuppressWarnings("StringBufferReplaceableByString") + private static String getEndPoint(final URI uri) { + final StringBuilder builder = new StringBuilder() + .append(requireNonNull(uri.getScheme(), "scheme")) + .append("://").append(requireNonNull(uri.getAuthority(), "authority")); + return builder.toString(); } - return null; - } - //------------------------------------------------------------------------------------------------ - // Body type suppliers + /** + * Extracts {@code path}, {@code query) and {@code fragment} portion of the {@link URI}. + * Assuming the {@link URI} as the following: + * {@code URI = scheme:[//authority]path[?query][#fragment]} + */ + private static String getServicePath(final URI uri) { + final StringBuilder builder = new StringBuilder() + .append(requireNonNull(uri.getPath(), "path")); + final String query = uri.getQuery(); + if (query != null) { + builder.append('?').append(query); + } + final String fragment = uri.getFragment(); + if (fragment != null) { + builder.append('#').append(fragment); + } + return builder.toString(); + } - private static class BytesBody implements Supplier { + /** + * Maps {@link Verb} to {@link HttpMethod} + * + * @param httpVerb a {@link Verb} to match with {@link HttpMethod} + * @return {@link HttpMethod} corresponding to the parameter + */ + private static HttpMethod getHttpMethod(final Verb httpVerb) { + switch (httpVerb) { + case GET: + return HttpMethod.GET; + case POST: + return HttpMethod.POST; + case PUT: + return HttpMethod.PUT; + case DELETE: + return HttpMethod.DELETE; + case HEAD: + return HttpMethod.HEAD; + case OPTIONS: + return HttpMethod.OPTIONS; + case TRACE: + return HttpMethod.TRACE; + case PATCH: + return HttpMethod.PATCH; + default: + throw new IllegalArgumentException( + "message build error: unsupported HTTP method: " + httpVerb.name()); + } + } - private final byte[] bodyContents; + //------------------------------------------------------------------------------------------------ + // Response asynchronous handlers + /** + * Converts {@link AggregatedHttpResponse} to {@link Response} + * + * @param aggregatedResponse an instance of {@link AggregatedHttpResponse} to convert to {@link Response} + * @return a {@link Response} converted from {@link AggregatedHttpResponse} + */ + private Response convertResponse(final AggregatedHttpResponse aggregatedResponse) { + final Map headersMap = new HashMap<>(aggregatedResponse.headers().size()); + aggregatedResponse.headers() + .forEach((header, value) -> headersMap.put(header.toString(), value)); + return new Response(aggregatedResponse.status().code(), + aggregatedResponse.status().reasonPhrase(), + headersMap, aggregatedResponse.content().toInputStream()); + } - BytesBody(final byte[] bodyContents) { - this.bodyContents = bodyContents; + /** + * Converts {@link AggregatedHttpResponse} to {@link Response} upon its aggregation completion and invokes + * {@link OAuthAsyncRequestCallback} for it. + * + * @param callback a {@link OAuthAsyncRequestCallback} callback to invoke upon response completion + * @param converter an optional {@link OAuthRequest.ResponseConverter} result converter for {@link Response} + * @param aggregatedResponse a source {@link AggregatedHttpResponse} to handle + * @param converter {@link OAuthRequest.ResponseConverter} specific type or {@link Response} + * @return either instance of {@link Response} or converted result based on {@link OAuthRequest.ResponseConverter} + */ + private T whenResponseComplete(OAuthAsyncRequestCallback callback, + OAuthRequest.ResponseConverter converter, AggregatedHttpResponse aggregatedResponse) { + final Response response = convertResponse(aggregatedResponse); + try { + @SuppressWarnings("unchecked") + final T t + = converter == null ? (T) response : converter.convert(response); + if (callback != null) { + callback.onCompleted(t); + } + return t; + } catch (IOException | RuntimeException e) { + return completeExceptionally(callback, e); + } } - @Override - public HttpData get() { - return (bodyContents != null) ? HttpData.wrap(bodyContents) : null; + /** + * Invokes {@link OAuthAsyncRequestCallback} upon {@link Throwable} error result + * + * @param callback a {@link OAuthAsyncRequestCallback} callback to invoke upon response completion + * @param throwable a {@link Throwable} error result + * @param converter {@link OAuthRequest.ResponseConverter} specific type or {@link Response} + * @return null + */ + private T completeExceptionally(OAuthAsyncRequestCallback callback, Throwable throwable) { + if (callback != null) { + callback.onThrowable(throwable); + } + return null; } - } - private static class StringBody implements Supplier { + //------------------------------------------------------------------------------------------------ + // Body type suppliers + private static class BytesBody implements Supplier { - private final String bodyContents; + private final byte[] bodyContents; - StringBody(final String bodyContents) { - this.bodyContents = bodyContents; - } + BytesBody(final byte[] bodyContents) { + this.bodyContents = bodyContents; + } - @Override - public HttpData get() { - return (bodyContents != null) ? HttpData.ofUtf8(bodyContents) : null; + @Override + public HttpData get() { + return (bodyContents != null) ? HttpData.wrap(bodyContents) : null; + } } - } - private static class FileBody implements Supplier { + private static class StringBody implements Supplier { - private final File bodyContents; + private final String bodyContents; - FileBody(final File bodyContents) { - this.bodyContents = bodyContents; - } + StringBody(final String bodyContents) { + this.bodyContents = bodyContents; + } - @Override - public HttpData get() { - try { - return (bodyContents != null) - ? HttpData.wrap(Files.readAllBytes(bodyContents.toPath())) - : null; - } catch (IOException e) { - throw new RuntimeException(e); - } + @Override + public HttpData get() { + return (bodyContents != null) ? HttpData.ofUtf8(bodyContents) : null; + } } - } - private static class MultipartBody implements Supplier { + private static class FileBody implements Supplier { + + private final File bodyContents; - private final MultipartPayload bodyContents; + FileBody(final File bodyContents) { + this.bodyContents = bodyContents; + } - MultipartBody(final MultipartPayload bodyContents) { - this.bodyContents = bodyContents; + @Override + public HttpData get() { + try { + return (bodyContents != null) + ? HttpData.wrap(Files.readAllBytes(bodyContents.toPath())) + : null; + } catch (IOException e) { + throw new RuntimeException(e); + } + } } - @Override - public HttpData get() { - try { - return (bodyContents != null) - ? HttpData.wrap(MultipartUtils.getPayload(bodyContents).toByteArray()) - : null; - } catch (IOException e) { - throw new RuntimeException(e); - } + private static class MultipartBody implements Supplier { + + private final MultipartPayload bodyContents; + + MultipartBody(final MultipartPayload bodyContents) { + this.bodyContents = bodyContents; + } + + @Override + public HttpData get() { + try { + return (bodyContents != null) + ? HttpData.wrap(MultipartUtils.getPayload(bodyContents).toByteArray()) + : null; + } catch (IOException e) { + throw new RuntimeException(e); + } + } } - } - //------------------------------------------------------------------------------------------------ + //------------------------------------------------------------------------------------------------ } diff --git a/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClientConfig.java b/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClientConfig.java index 97b13e5c3..a0f503222 100644 --- a/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClientConfig.java +++ b/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClientConfig.java @@ -16,184 +16,175 @@ public class ArmeriaHttpClientConfig implements HttpClientConfig { - private static final SessionProtocol DEFAULT_PROTOCOL_PREFERENCE = SessionProtocol.H1; // H1 or H2 + private static final SessionProtocol DEFAULT_PROTOCOL_PREFERENCE = SessionProtocol.H1; // H1 or H2 - private final ClientOptions clientOptions; - private final ClientFactory clientFactory; - private SessionProtocol protocolPreference; - private Function retry; - private Function logging; + private final ClientOptions clientOptions; + private final ClientFactory clientFactory; + private SessionProtocol protocolPreference; + private Function retry; + private Function logging; - /** - * Creates new {@link ArmeriaHttpClientConfig} using provided {@link ClientOptions} and - * {@link ClientFactory}. - */ - public ArmeriaHttpClientConfig(ClientOptions clientOptions, ClientFactory clientFactory) { - this.clientOptions = clientOptions; - this.clientFactory = clientFactory; - protocolPreference = DEFAULT_PROTOCOL_PREFERENCE; - } + /** + * Creates new {@link ArmeriaHttpClientConfig} using provided {@link ClientOptions} and {@link ClientFactory}. + */ + public ArmeriaHttpClientConfig(ClientOptions clientOptions, ClientFactory clientFactory) { + this.clientOptions = clientOptions; + this.clientFactory = clientFactory; + protocolPreference = DEFAULT_PROTOCOL_PREFERENCE; + } - /** - * Creates new {@link ArmeriaHttpClientConfig} using default settings. - */ - ArmeriaHttpClientConfig() { - this(null, null); - } + /** + * Creates new {@link ArmeriaHttpClientConfig} using default settings. + */ + ArmeriaHttpClientConfig() { + this(null, null); + } - /** - * Creates new {@link HttpClientConfig} using default settings. - */ - @Override - public HttpClientConfig createDefaultConfig() { - return defaultConfig(); - } + /** + * Creates new {@link HttpClientConfig} using default settings. + */ + @Override + public HttpClientConfig createDefaultConfig() { + return defaultConfig(); + } - /** - * Creates new {@link ArmeriaHttpClientConfig} using default settings. - */ - public static ArmeriaHttpClientConfig defaultConfig() { - return new ArmeriaHttpClientConfig(); - } + /** + * Creates new {@link ArmeriaHttpClientConfig} using default settings. + */ + public static ArmeriaHttpClientConfig defaultConfig() { + return new ArmeriaHttpClientConfig(); + } - /** - * Selects which protocol shall take preference when generic protocol scheme used by the URL, - * like {@code http} or {@code https}. - * - * @param protocolPreference specifies which protocol shall take preference. - * Acceptable values: {@code H1}, {@code HTTP1}, {@code HTTP/1.1} for - * {@code HTTP/1.1} and {@code H2}, {@code HTTP2}, {@code HTTP/2} for - * {@code HTTP/2}. - */ - public void protocolPreference(String protocolPreference) { - switch (protocolPreference.toUpperCase()) { - case "H1": - case "HTTP1": - case "HTTP/1.1": - this.protocolPreference = SessionProtocol.H1; - break; - case "H2": - case "HTTP2": - case "HTTP/2": - this.protocolPreference = SessionProtocol.H2; - break; - default: - throw new IllegalArgumentException("Invalid protocolPreference: " + protocolPreference); + /** + * Selects which protocol shall take preference when generic protocol scheme used by the URL, like {@code http} or + * {@code https}. + * + * @param protocolPreference specifies which protocol shall take preference. Acceptable values: {@code H1}, + * {@code HTTP1}, {@code HTTP/1.1} for {@code HTTP/1.1} and {@code H2}, {@code HTTP2}, {@code HTTP/2} for + * {@code HTTP/2}. + */ + public void protocolPreference(String protocolPreference) { + switch (protocolPreference.toUpperCase()) { + case "H1": + case "HTTP1": + case "HTTP/1.1": + this.protocolPreference = SessionProtocol.H1; + break; + case "H2": + case "HTTP2": + case "HTTP/2": + this.protocolPreference = SessionProtocol.H2; + break; + default: + throw new IllegalArgumentException("Invalid protocolPreference: " + protocolPreference); + } } - } - /** - * Selects which protocol shall take preference when generic protocol scheme used by the URL, - * like {@code http} or {@code https}. - * - * @param protocolPreference specifies which protocol shall take preference. - * Acceptable values: {@link SessionProtocol#H1} and - * {@link SessionProtocol#H2} - */ - public void protocolPreference(SessionProtocol protocolPreference) { - switch (protocolPreference) { - case H1: - this.protocolPreference = SessionProtocol.H1; - break; - case H2: - this.protocolPreference = SessionProtocol.H2; - break; - default: - throw new IllegalArgumentException("Invalid protocolPreference: " + protocolPreference); + /** + * Selects which protocol shall take preference when generic protocol scheme used by the URL, like {@code http} or + * {@code https}. + * + * @param protocolPreference specifies which protocol shall take preference. Acceptable values: + * {@link SessionProtocol#H1} and {@link SessionProtocol#H2} + */ + public void protocolPreference(SessionProtocol protocolPreference) { + switch (protocolPreference) { + case H1: + this.protocolPreference = SessionProtocol.H1; + break; + case H2: + this.protocolPreference = SessionProtocol.H2; + break; + default: + throw new IllegalArgumentException("Invalid protocolPreference: " + protocolPreference); + } } - } - /** - * Sets the client to retry when the remote end-point responds with one of the - * specified {@code statuses}. - * - * Uses a backoff that computes a delay using one of supported functions, such as - * {@code exponential(long, long, double)}, {@code fibonacci(long, long)}, {@code fixed(long)} - * and {@code random(long, long)} chaining with {@code withJitter(double, double)} and - * {@code withMaxAttempts(int)} from the {@code backoff} string that conforms to - * the following format: - *
      - *
    • {@code exponential=[initialDelayMillis:maxDelayMillis:multiplier]} is for - * {@code exponential(long, long, double)} (multiplier will be 2.0 if it's omitted)
    • - *
    • {@code fibonacci=[initialDelayMillis:maxDelayMillis]} is for - * {@code fibonacci(long, long)}
    • - *
    • {@code fixed=[delayMillis]} is for {@code fixed(long)}
    • - *
    • {@code random=[minDelayMillis:maxDelayMillis]} is for {@code random(long, long)}
    • - *
    • {@code jitter=[minJitterRate:maxJitterRate]} is for {@code withJitter(double, double)} - * (if only one jitter value is specified, it will be used for {@code withJitter(double)}
    • - *
    • {@code maxAttempts=[maxAttempts]} is for {@code withMaxAttempts(int)}
    • - *
    - * The order of options does not matter, and the {@code backoff} needs at least one option. - * If you don't specify the base option exponential backoff will be used. If you only specify - * a base option, jitter and maxAttempts will be set by default values. For example: - *
      - *
    • {@code exponential=200:10000:2.0,jitter=0.2} (default)
    • - *
    • {@code exponential=200:10000,jitter=0.2,maxAttempts=50} (multiplier omitted)
    • - *
    • {@code fibonacci=200:10000,jitter=0.2,maxAttempts=50}
    • - *
    • {@code fixed=100,jitter=-0.5:0.2,maxAttempts=10} (fixed backoff with jitter variation)
    • - *
    • {@code random=200:1000} (jitter and maxAttempts will be set by default values)
    • - *
    - * - * @param backoff the specification used to create a retry backoff - * @param statuses the list of HTTP statuses on which to retry - */ - public void retry(String backoff, HttpStatus... statuses) { - final Backoff retryBackoff = Backoff.of(backoff); - final RetryRule retryRule = - RetryRule.builder().onStatus(statuses).onUnprocessed().thenBackoff(retryBackoff); - retry = RetryingClient.newDecorator(retryRule); - } + /** + * Sets the client to retry when the remote end-point responds with one of the specified {@code statuses}. + * + * Uses a backoff that computes a delay using one of supported functions, such as + * {@code exponential(long, long, double)}, {@code fibonacci(long, long)}, {@code fixed(long)} and + * {@code random(long, long)} chaining with {@code withJitter(double, double)} and {@code withMaxAttempts(int)} from + * the {@code backoff} string that conforms to the following format: + *
      + *
    • {@code exponential=[initialDelayMillis:maxDelayMillis:multiplier]} is for + * {@code exponential(long, long, double)} (multiplier will be 2.0 if it's omitted)
    • + *
    • {@code fibonacci=[initialDelayMillis:maxDelayMillis]} is for {@code fibonacci(long, long)}
    • + *
    • {@code fixed=[delayMillis]} is for {@code fixed(long)}
    • + *
    • {@code random=[minDelayMillis:maxDelayMillis]} is for {@code random(long, long)}
    • + *
    • {@code jitter=[minJitterRate:maxJitterRate]} is for {@code withJitter(double, double)} (if only one jitter + * value is specified, it will be used for {@code withJitter(double)}
    • + *
    • {@code maxAttempts=[maxAttempts]} is for {@code withMaxAttempts(int)}
    • + *
    + * The order of options does not matter, and the {@code backoff} needs at least one option. If you don't specify the + * base option exponential backoff will be used. If you only specify a base option, jitter and maxAttempts will be + * set by default values. For example: + *
      + *
    • {@code exponential=200:10000:2.0,jitter=0.2} (default)
    • + *
    • {@code exponential=200:10000,jitter=0.2,maxAttempts=50} (multiplier omitted)
    • + *
    • {@code fibonacci=200:10000,jitter=0.2,maxAttempts=50}
    • + *
    • {@code fixed=100,jitter=-0.5:0.2,maxAttempts=10} (fixed backoff with jitter variation)
    • + *
    • {@code random=200:1000} (jitter and maxAttempts will be set by default values)
    • + *
    + * + * @param backoff the specification used to create a retry backoff + * @param statuses the list of HTTP statuses on which to retry + */ + public void retry(String backoff, HttpStatus... statuses) { + final Backoff retryBackoff = Backoff.of(backoff); + final RetryRule retryRule + = RetryRule.builder().onStatus(statuses).onUnprocessed().thenBackoff(retryBackoff); + retry = RetryingClient.newDecorator(retryRule); + } - /** - * Sets the client to log requests and responses to the specified {@code logger}. - * This method explicitly specifies various log levels. The log level correspond to a value - * of {@link LogLevel} and must use one of the following values: - * {@code ["OFF", "TRACE", "DEBUG", "INFO", "WARN", "ERROR"]} - * - * @param logger the logger name (of {@link org.slf4j.Logger}) to log requests/responses to - * @param requestLevel the log level to use for logging requests, default {@code "DEBUG"} - * @param responseLevel the log level to use for logging responses, default {@code "DEBUG"} - * @param failureResponseLevel the log level to use for logging error responses, - * default {@code "WARN"} - */ - public void logging(String logger, String requestLevel, String responseLevel, - String failureResponseLevel) { - this.logging = LoggingClient.builder() - .logger(LoggerFactory.getLogger(logger)) - .requestLogLevel(LogLevel.valueOf(requestLevel)) - .successfulResponseLogLevel(LogLevel.valueOf(responseLevel)) - .failureResponseLogLevel(LogLevel.valueOf(failureResponseLevel)) - .newDecorator(); - } + /** + * Sets the client to log requests and responses to the specified {@code logger}. This method explicitly specifies + * various log levels. The log level correspond to a value of {@link LogLevel} and must use one of the following + * values: {@code ["OFF", "TRACE", "DEBUG", "INFO", "WARN", "ERROR"]} + * + * @param logger the logger name (of {@link org.slf4j.Logger}) to log requests/responses to + * @param requestLevel the log level to use for logging requests, default {@code "DEBUG"} + * @param responseLevel the log level to use for logging responses, default {@code "DEBUG"} + * @param failureResponseLevel the log level to use for logging error responses, default {@code "WARN"} + */ + public void logging(String logger, String requestLevel, String responseLevel, + String failureResponseLevel) { + this.logging = LoggingClient.builder() + .logger(LoggerFactory.getLogger(logger)) + .requestLogLevel(LogLevel.valueOf(requestLevel)) + .successfulResponseLogLevel(LogLevel.valueOf(responseLevel)) + .failureResponseLogLevel(LogLevel.valueOf(failureResponseLevel)) + .newDecorator(); + } - /** - * Sets the client to log requests and responses to the specified {@code logger} using default - * log levels. - * - * @param logger the logger name (of {@link org.slf4j.Logger}) to log requests/responses to - */ - public void logging(String logger) { - this.logging = LoggingClient.builder() - .logger(LoggerFactory.getLogger(logger)) - .requestLogLevel(LogLevel.DEBUG) - .successfulResponseLogLevel(LogLevel.DEBUG) - .failureResponseLogLevel(LogLevel.WARN) - .newDecorator(); - } + /** + * Sets the client to log requests and responses to the specified {@code logger} using default log levels. + * + * @param logger the logger name (of {@link org.slf4j.Logger}) to log requests/responses to + */ + public void logging(String logger) { + this.logging = LoggingClient.builder() + .logger(LoggerFactory.getLogger(logger)) + .requestLogLevel(LogLevel.DEBUG) + .successfulResponseLogLevel(LogLevel.DEBUG) + .failureResponseLogLevel(LogLevel.WARN) + .newDecorator(); + } - /** - * Sets the client to log requests and responses to a default logger using default log levels. - */ - public void logging() { - this.logging = LoggingClient.builder() - .requestLogLevel(LogLevel.DEBUG) - .successfulResponseLogLevel(LogLevel.DEBUG) - .failureResponseLogLevel(LogLevel.WARN) - .newDecorator(); - } + /** + * Sets the client to log requests and responses to a default logger using default log levels. + */ + public void logging() { + this.logging = LoggingClient.builder() + .requestLogLevel(LogLevel.DEBUG) + .successfulResponseLogLevel(LogLevel.DEBUG) + .failureResponseLogLevel(LogLevel.WARN) + .newDecorator(); + } - ArmeriaWebClientBuilder builder() { - return new ArmeriaWebClientBuilder(clientOptions, clientFactory, protocolPreference, - retry, logging); - } + ArmeriaWebClientBuilder builder() { + return new ArmeriaWebClientBuilder(clientOptions, clientFactory, protocolPreference, + retry, logging); + } } diff --git a/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/httpclient/armeria/ArmeriaProvider.java b/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/httpclient/armeria/ArmeriaProvider.java index b352a8b07..323eb7599 100644 --- a/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/httpclient/armeria/ArmeriaProvider.java +++ b/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/httpclient/armeria/ArmeriaProvider.java @@ -6,11 +6,11 @@ public class ArmeriaProvider implements HttpClientProvider { - @Override - public HttpClient createClient(HttpClientConfig config) { - if (config instanceof ArmeriaHttpClientConfig) { - return new ArmeriaHttpClient((ArmeriaHttpClientConfig) config); + @Override + public HttpClient createClient(HttpClientConfig config) { + if (config instanceof ArmeriaHttpClientConfig) { + return new ArmeriaHttpClient((ArmeriaHttpClientConfig) config); + } + return null; } - return null; - } } diff --git a/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/httpclient/armeria/ArmeriaWebClientBuilder.java b/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/httpclient/armeria/ArmeriaWebClientBuilder.java index e79c9c27c..6972fadd0 100644 --- a/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/httpclient/armeria/ArmeriaWebClientBuilder.java +++ b/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/httpclient/armeria/ArmeriaWebClientBuilder.java @@ -16,59 +16,59 @@ */ public class ArmeriaWebClientBuilder { - private final ClientFactory clientFactory; - private final ClientOptions clientOptions; - private final SessionProtocol protocolPreference; - private final Function retry; - private final Function logging; + private final ClientFactory clientFactory; + private final ClientOptions clientOptions; + private final SessionProtocol protocolPreference; + private final Function retry; + private final Function logging; - ArmeriaWebClientBuilder(ClientOptions clientOptions, ClientFactory clientFactory, - SessionProtocol protocolPreference, Function retry, - Function logging) { - this.clientOptions = clientOptions; - this.clientFactory = clientFactory; - this.protocolPreference = protocolPreference; - this.retry = retry; - this.logging = logging; - } - - WebClient newWebClient(String scheme, String authority) { - final SessionProtocol protocol = protocol(scheme); - final Endpoint endpoint = Endpoint.parse(authority); - final WebClientBuilder clientBuilder = WebClient.builder(protocol, endpoint); - if (clientOptions != null) { - clientBuilder.options(clientOptions); - } - if (clientFactory != null) { - clientBuilder.factory(clientFactory); - } - if (retry != null) { - clientBuilder.decorator(retry); + ArmeriaWebClientBuilder(ClientOptions clientOptions, ClientFactory clientFactory, + SessionProtocol protocolPreference, Function retry, + Function logging) { + this.clientOptions = clientOptions; + this.clientFactory = clientFactory; + this.protocolPreference = protocolPreference; + this.retry = retry; + this.logging = logging; } - if (logging != null) { - clientBuilder.decorator(logging); - } - return clientBuilder.build(); - } - private SessionProtocol protocol(String scheme) { - final SessionProtocol protocol = SessionProtocol.of(scheme); - switch(protocol) { - case HTTP: - if (protocolPreference == SessionProtocol.H1) { - // enforce HTTP/1 protocol - return SessionProtocol.H1C; + WebClient newWebClient(String scheme, String authority) { + final SessionProtocol protocol = protocol(scheme); + final Endpoint endpoint = Endpoint.parse(authority); + final WebClientBuilder clientBuilder = WebClient.builder(protocol, endpoint); + if (clientOptions != null) { + clientBuilder.options(clientOptions); + } + if (clientFactory != null) { + clientBuilder.factory(clientFactory); } - break; - case HTTPS: - if (protocolPreference == SessionProtocol.H1) { - // enforce HTTP/1 protocol - return SessionProtocol.H1; + if (retry != null) { + clientBuilder.decorator(retry); + } + if (logging != null) { + clientBuilder.decorator(logging); + } + return clientBuilder.build(); + } + + private SessionProtocol protocol(String scheme) { + final SessionProtocol protocol = SessionProtocol.of(scheme); + switch (protocol) { + case HTTP: + if (protocolPreference == SessionProtocol.H1) { + // enforce HTTP/1 protocol + return SessionProtocol.H1C; + } + break; + case HTTPS: + if (protocolPreference == SessionProtocol.H1) { + // enforce HTTP/1 protocol + return SessionProtocol.H1; + } + break; + default: + break; } - break; - default: - break; + return protocol; } - return protocol; - } } diff --git a/scribejava-httpclient-armeria/src/test/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClientTest.java b/scribejava-httpclient-armeria/src/test/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClientTest.java index 1078a563c..728668e8f 100644 --- a/scribejava-httpclient-armeria/src/test/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClientTest.java +++ b/scribejava-httpclient-armeria/src/test/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClientTest.java @@ -18,57 +18,55 @@ public class ArmeriaHttpClientTest extends AbstractClientTest { - @Override - protected HttpClient createNewClient() { - // simulate DNS resolution for a mock address ("kubernetes.docker.internal") - final Function> - addressResolverGroupFactory = eventLoopGroup -> new MockAddressResolverGroup(); - // No-Op DNS resolver to avoid resolution issues in the unit test - final ClientFactory clientFactory = - ClientFactory.builder().addressResolverGroupFactory(addressResolverGroupFactory).build(); - final ArmeriaHttpClientConfig config = new ArmeriaHttpClientConfig(null, clientFactory); - // enable client-side HTTP tracing - config.logging("HTTP_TRACE", "INFO", "INFO", "WARN"); - // enable request retry - config.retry("exponential=200:10000,jitter=0.2,maxAttempts=5", HttpStatus.SERVICE_UNAVAILABLE); - return new ArmeriaHttpClient(config); - } + @Override + protected HttpClient createNewClient() { + // simulate DNS resolution for a mock address ("kubernetes.docker.internal") + final Function> addressResolverGroupFactory = eventLoopGroup -> new MockAddressResolverGroup(); + // No-Op DNS resolver to avoid resolution issues in the unit test + final ClientFactory clientFactory + = ClientFactory.builder().addressResolverGroupFactory(addressResolverGroupFactory).build(); + final ArmeriaHttpClientConfig config = new ArmeriaHttpClientConfig(null, clientFactory); + // enable client-side HTTP tracing + config.logging("HTTP_TRACE", "INFO", "INFO", "WARN"); + // enable request retry + config.retry("exponential=200:10000,jitter=0.2,maxAttempts=5", HttpStatus.SERVICE_UNAVAILABLE); + return new ArmeriaHttpClient(config); + } - //------------------------------------------------------------------------------------------------ - // No-Op DNS resolver to avoid resolution issues in the unit test + //------------------------------------------------------------------------------------------------ + // No-Op DNS resolver to avoid resolution issues in the unit test + static class MockAddressResolverGroup extends AddressResolverGroup { - static class MockAddressResolverGroup extends AddressResolverGroup { + private MockAddressResolverGroup() { + } - private MockAddressResolverGroup() { + protected AddressResolver newResolver(EventExecutor executor) { + return new MockAddressResolver(executor); + } } - protected AddressResolver newResolver(EventExecutor executor) { - return new MockAddressResolver(executor); - } - } + static class MockAddressResolver extends AbstractAddressResolver { - static class MockAddressResolver extends AbstractAddressResolver { + private MockAddressResolver(EventExecutor executor) { + super(executor); + } - private MockAddressResolver(EventExecutor executor) { - super(executor); - } + protected boolean doIsResolved(InetSocketAddress address) { + return !address.isUnresolved(); + } - protected boolean doIsResolved(InetSocketAddress address) { - return !address.isUnresolved(); - } - - private InetSocketAddress resolveToLoopback(InetSocketAddress unresolvedAddress) { - return new InetSocketAddress(InetAddress.getLoopbackAddress(), unresolvedAddress.getPort()); - } + private InetSocketAddress resolveToLoopback(InetSocketAddress unresolvedAddress) { + return new InetSocketAddress(InetAddress.getLoopbackAddress(), unresolvedAddress.getPort()); + } - protected void doResolve(InetSocketAddress unresolvedAddress, Promise promise) { - promise.setSuccess(resolveToLoopback(unresolvedAddress)); - } + protected void doResolve(InetSocketAddress unresolvedAddress, Promise promise) { + promise.setSuccess(resolveToLoopback(unresolvedAddress)); + } - protected void doResolveAll(InetSocketAddress unresolvedAddress, Promise> promise) { - promise.setSuccess(Collections.singletonList(resolveToLoopback(unresolvedAddress))); + protected void doResolveAll(InetSocketAddress unresolvedAddress, Promise> promise) { + promise.setSuccess(Collections.singletonList(resolveToLoopback(unresolvedAddress))); + } } - } - //------------------------------------------------------------------------------------------------ + //------------------------------------------------------------------------------------------------ } From eccd3dd165e28447b7b6f9c574c7ab2289c42617 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Sat, 1 Aug 2020 20:04:50 +0300 Subject: [PATCH 786/882] Add Armeria HTTP client (thanks to https://github.com/max904-github) --- README.md | 1 + changelog | 3 +- pom.xml | 3 + scribejava-apis/pom.xml | 6 + .../apis/examples/Google20ArmeriaExample.java | 118 ++++++ .../core/httpclient/jdk/JDKHttpClient.java | 53 +-- .../multipart/MultipartPayload.java | 52 ++- .../httpclient/multipart/MultipartUtils.java | 35 +- .../httpclient/jdk/JDKHttpClientTest.java | 268 ------------- .../multipart/MultipartPayloadTest.java | 108 ----- .../multipart/MultipartUtilsTest.java | 371 ++++++++++++++++++ .../httpclient/ahc/AhcHttpClient.java | 9 +- scribejava-httpclient-armeria/pom.xml | 28 +- .../httpclient/armeria/ArmeriaHttpClient.java | 126 +++--- .../armeria/ArmeriaHttpClientConfig.java | 146 +------ .../armeria/ArmeriaHttpClientTest.java | 43 +- 16 files changed, 683 insertions(+), 687 deletions(-) create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20ArmeriaExample.java rename {scribejava-httpclient-armeria => scribejava-core}/src/main/java/com/github/scribejava/core/httpclient/multipart/MultipartUtils.java (58%) delete mode 100644 scribejava-core/src/test/java/com/github/scribejava/core/httpclient/multipart/MultipartPayloadTest.java create mode 100644 scribejava-core/src/test/java/com/github/scribejava/core/httpclient/multipart/MultipartUtilsTest.java diff --git a/README.md b/README.md index 199e1c7a5..aa3645dc5 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,7 @@ ScribeJava support out-of-box several HTTP clients: * Async Http Client asynchttpclient 2.x (maven module scribejava-httpclient-ahc) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java) * OkHttp (maven module scribejava-httpclient-okhttp) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubAsyncOkHttpExample.java) * Apache HttpComponents HttpClient (maven module scribejava-httpclient-apache) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncApacheExample.java) + * Armeria HTTP client (required >= java 8) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20ArmeriaExample.java) * any externally created HTTP client [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExternalHttpExample.java) just add corresponding maven modules to your pom diff --git a/changelog b/changelog index 953ac5d16..2a5d5269a 100644 --- a/changelog +++ b/changelog @@ -2,7 +2,8 @@ * Add Polar API (https://www.polar.com/) (thanks to https://github.com/vidi42) * make Response accept resources to autoclose and autoclose it (thanks to https://github.com/drei01) * fix url encoding in POST payload (it's needed for 'application/x-www-form-urlencoded' Content-Type) - + unit tests (thanks to https://github.com/max904-github) + + unit tests (thanks to https://github.com/max904-github) + * Add Armeria HTTP client (thanks to https://github.com/max904-github) [6.9.0] * Add Xero API (https://www.xero.com/) (thanks to https://github.com/SidneyAllen) diff --git a/pom.xml b/pom.xml index a5119ada7..f067fb747 100644 --- a/pom.xml +++ b/pom.xml @@ -146,6 +146,9 @@ UTF-8 ${java.release} true + + -Xlint:-options +
    diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index fe2dd76c0..aac24aa20 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -44,6 +44,12 @@ ${project.version} test
    + + com.github.scribejava + scribejava-httpclient-armeria + ${project.version} + test + diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20ArmeriaExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20ArmeriaExample.java new file mode 100644 index 000000000..04fddb1da --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20ArmeriaExample.java @@ -0,0 +1,118 @@ +package com.github.scribejava.apis.examples; + +import java.util.Random; +import java.util.Scanner; +import com.github.scribejava.apis.GoogleApi20; +import com.github.scribejava.core.builder.ServiceBuilder; +import com.github.scribejava.core.model.OAuth2AccessToken; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.oauth.OAuth20Service; +import com.github.scribejava.httpclient.armeria.ArmeriaHttpClientConfig; +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.ExecutionException; + +public class Google20ArmeriaExample { + + private static final String NETWORK_NAME = "Google Armeria"; + private static final String PROTECTED_RESOURCE_URL = "https://www.googleapis.com/oauth2/v3/userinfo"; + + private Google20ArmeriaExample() { + } + + @SuppressWarnings("PMD.SystemPrintln") + public static void main(String... args) throws InterruptedException, ExecutionException, IOException { + // Replace these with your client id and secret + final String clientId = "your client id"; + final String clientSecret = "your client secret"; + final String secretState = "secret" + new Random().nextInt(999_999); + + try (OAuth20Service service = new ServiceBuilder(clientId) + .apiSecret(clientSecret) + .defaultScope("profile") // replace with desired scope + .callback("http://example.com/callback") + .httpClientConfig(ArmeriaHttpClientConfig.defaultConfig()) + .build(GoogleApi20.instance())) { + final Scanner in = new Scanner(System.in, "UTF-8"); + + System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); + System.out.println(); + + // Obtain the Authorization URL + System.out.println("Fetching the Authorization URL..."); + //pass access_type=offline to get refresh token + //https://developers.google.com/identity/protocols/OAuth2WebServer#preparing-to-start-the-oauth-20-flow + final Map additionalParams = new HashMap<>(); + additionalParams.put("access_type", "offline"); + //force to reget refresh token (if user are asked not the first time) + additionalParams.put("prompt", "consent"); + final String authorizationUrl = service.createAuthorizationUrlBuilder() + .state(secretState) + .additionalParams(additionalParams) + .build(); + System.out.println("Got the Authorization URL!"); + System.out.println("Now go and authorize ScribeJava here:"); + System.out.println(authorizationUrl); + System.out.println("And paste the authorization code here"); + System.out.print(">>"); + final String code = in.nextLine(); + System.out.println(); + + System.out.println("And paste the state from server here. We have set 'secretState'='" + + secretState + "'."); + System.out.print(">>"); + final String value = in.nextLine(); + if (secretState.equals(value)) { + System.out.println("State value does match!"); + } else { + System.out.println("Ooops, state value does not match!"); + System.out.println("Expected = " + secretState); + System.out.println("Got = " + value); + System.out.println(); + } + + System.out.println("Trading the Authorization Code for an Access Token..."); + OAuth2AccessToken accessToken = service.getAccessToken(code); + System.out.println("Got the Access Token!"); + System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + + "')"); + + System.out.println("Refreshing the Access Token..."); + accessToken = service.refreshAccessToken(accessToken.getRefreshToken()); + System.out.println("Refreshed the Access Token!"); + System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + + "')"); + System.out.println(); + + // Now let's go and ask for a protected resource! + System.out.println("Now we're going to access a protected resource..."); + while (true) { + System.out.println("Paste fieldnames to fetch (leave empty to get profile, 'exit' to stop example)"); + System.out.print(">>"); + final String query = in.nextLine(); + System.out.println(); + + final String requestUrl; + if ("exit".equals(query)) { + break; + } else if (query == null || query.isEmpty()) { + requestUrl = PROTECTED_RESOURCE_URL; + } else { + requestUrl = PROTECTED_RESOURCE_URL + "?fields=" + query; + } + + final OAuthRequest request = new OAuthRequest(Verb.GET, requestUrl); + service.signRequest(accessToken, request); + System.out.println(); + try (Response response = service.execute(request)) { + System.out.println(response.getCode()); + System.out.println(response.getBody()); + } + System.out.println(); + } + } + } +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java index 3f4648a77..a18617633 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java @@ -1,10 +1,9 @@ package com.github.scribejava.core.httpclient.jdk; import com.github.scribejava.core.exceptions.OAuthException; -import com.github.scribejava.core.httpclient.multipart.BodyPartPayload; import com.github.scribejava.core.httpclient.HttpClient; -import com.github.scribejava.core.httpclient.multipart.ByteArrayBodyPartPayload; import com.github.scribejava.core.httpclient.multipart.MultipartPayload; +import com.github.scribejava.core.httpclient.multipart.MultipartUtils; import com.github.scribejava.core.model.OAuthAsyncRequestCallback; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.OAuthRequest; @@ -207,7 +206,7 @@ private static void addBody(HttpURLConnection connection, MultipartPayload multi } if (requiresBody) { - final ByteArrayOutputStream os = getPayload(multipartPayload); + final ByteArrayOutputStream os = MultipartUtils.getPayload(multipartPayload); final int contentLength = os.size(); final OutputStream outputStream = prepareConnectionForBodyAndGetOutputStream(connection, contentLength); if (contentLength > 0) { @@ -216,46 +215,16 @@ private static void addBody(HttpURLConnection connection, MultipartPayload multi } } + /** + * @param multipartPayload multipartPayload + * @return ByteArrayOutputStream + * @throws IOException + * @deprecated use {@link com.github.scribejava.core.httpclient.multipart.MultipartUtils#getPayload( + * com.github.scribejava.core.httpclient.multipart.MultipartPayload) } + */ + @Deprecated static ByteArrayOutputStream getPayload(MultipartPayload multipartPayload) throws IOException { - final ByteArrayOutputStream os = new ByteArrayOutputStream(); - - final String preamble = multipartPayload.getPreamble(); - if (preamble != null) { - os.write(preamble.getBytes()); - } - final List bodyParts = multipartPayload.getBodyParts(); - if (!bodyParts.isEmpty()) { - final String boundary = multipartPayload.getBoundary(); - final byte[] startBoundary = ("\r\n--" + boundary + "\r\n").getBytes(); - - for (BodyPartPayload bodyPart : bodyParts) { - os.write(startBoundary); - - final Map bodyPartHeaders = bodyPart.getHeaders(); - if (bodyPartHeaders != null) { - for (Map.Entry header : bodyPartHeaders.entrySet()) { - os.write((header.getKey() + ": " + header.getValue() + "\r\n").getBytes()); - } - } - - if (bodyPart instanceof MultipartPayload) { - getPayload((MultipartPayload) bodyPart).writeTo(os); - } else if (bodyPart instanceof ByteArrayBodyPartPayload) { - os.write("\r\n".getBytes()); - os.write(((ByteArrayBodyPartPayload) bodyPart).getPayload()); - } else { - throw new AssertionError(bodyPart.getClass()); - } - } - - os.write(("\r\n--" + boundary + "--\r\n").getBytes()); - final String epilogue = multipartPayload.getEpilogue(); - if (epilogue != null) { - os.write((epilogue + "\r\n").getBytes()); - } - - } - return os; + return MultipartUtils.getPayload(multipartPayload); } private static OutputStream prepareConnectionForBodyAndGetOutputStream(HttpURLConnection connection, diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/MultipartPayload.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/MultipartPayload.java index 7e3f8cfde..26efa66fe 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/MultipartPayload.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/MultipartPayload.java @@ -5,16 +5,8 @@ import java.util.Collections; import java.util.List; import java.util.Map; -import java.util.regex.Matcher; -import java.util.regex.Pattern; public class MultipartPayload extends BodyPartPayload { - private static final String B_CHARS_NO_SPACE_PATTERN = "0-9a-zA-Z'()+_,-./:=?"; - private static final String B_CHARS_PATTERN = B_CHARS_NO_SPACE_PATTERN + " "; - private static final String BOUNDARY_PATTERN = '[' + B_CHARS_PATTERN + "]{0,69}[" + B_CHARS_NO_SPACE_PATTERN + ']'; - private static final Pattern BOUNDARY_REGEXP = Pattern.compile(BOUNDARY_PATTERN); - private static final Pattern BOUNDARY_FROM_HEADER_REGEXP - = Pattern.compile("; boundary=\"?(" + BOUNDARY_PATTERN + ")\"?"); private static final String DEFAULT_SUBTYPE = "form-data"; @@ -24,7 +16,7 @@ public class MultipartPayload extends BodyPartPayload { private String epilogue; public MultipartPayload() { - this(null, generateDefaultBoundary(), null); + this(null, MultipartUtils.generateDefaultBoundary(), null); } public MultipartPayload(String boundary) { @@ -50,7 +42,7 @@ public MultipartPayload(String subtype, String boundary, Map hea private static Map composeHeaders(String subtype, String boundary, Map headersIn) throws IllegalArgumentException { - checkBoundarySyntax(boundary); + MultipartUtils.checkBoundarySyntax(boundary); final Map headersOut; String contentTypeHeader = headersIn == null ? null : headersIn.get(HttpClient.CONTENT_TYPE); if (contentTypeHeader == null) { @@ -64,7 +56,7 @@ private static Map composeHeaders(String subtype, String boundar } } else { headersOut = headersIn; - final String parsedBoundary = parseBoundaryFromHeader(contentTypeHeader); + final String parsedBoundary = MultipartUtils.parseBoundaryFromHeader(contentTypeHeader); if (parsedBoundary == null) { headersOut.put(HttpClient.CONTENT_TYPE, contentTypeHeader + "; boundary=\"" + boundary + '"'); } else if (!parsedBoundary.equals(boundary)) { @@ -75,28 +67,32 @@ private static Map composeHeaders(String subtype, String boundar return headersOut; } + /** + * + * @param boundary boundary + * @deprecated use + * {@link com.github.scribejava.core.httpclient.multipart.MultipartUtils#checkBoundarySyntax(java.lang.String)} + */ + @Deprecated static void checkBoundarySyntax(String boundary) { - if (boundary == null || !BOUNDARY_REGEXP.matcher(boundary).matches()) { - throw new IllegalArgumentException("{'boundary'='" + boundary + "'} has invalid syntax. Should be '" - + BOUNDARY_PATTERN + "'."); - } + MultipartUtils.checkBoundarySyntax(boundary); } private static String parseOrGenerateBoundary(Map headers) { - final String parsedBoundary = parseBoundaryFromHeader(headers.get(HttpClient.CONTENT_TYPE)); - return parsedBoundary == null ? generateDefaultBoundary() : parsedBoundary; - } - - private static String generateDefaultBoundary() { - return "----ScribeJava----" + System.currentTimeMillis(); - } - + final String parsedBoundary = MultipartUtils.parseBoundaryFromHeader(headers.get(HttpClient.CONTENT_TYPE)); + return parsedBoundary == null ? MultipartUtils.generateDefaultBoundary() : parsedBoundary; + } + + /** + * + * @param contentTypeHeader contentTypeHeader + * @return String + * @deprecated use + * {@link com.github.scribejava.core.httpclient.multipart.MultipartUtils#parseBoundaryFromHeader(java.lang.String)} + */ + @Deprecated static String parseBoundaryFromHeader(String contentTypeHeader) { - if (contentTypeHeader == null) { - return null; - } - final Matcher matcher = BOUNDARY_FROM_HEADER_REGEXP.matcher(contentTypeHeader); - return matcher.find() ? matcher.group(1) : null; + return MultipartUtils.parseBoundaryFromHeader(contentTypeHeader); } public void addFileBodyPart(byte[] fileContent) { diff --git a/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/core/httpclient/multipart/MultipartUtils.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/MultipartUtils.java similarity index 58% rename from scribejava-httpclient-armeria/src/main/java/com/github/scribejava/core/httpclient/multipart/MultipartUtils.java rename to scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/MultipartUtils.java index f995e4b4e..dc42d4d60 100644 --- a/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/core/httpclient/multipart/MultipartUtils.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/MultipartUtils.java @@ -4,10 +4,40 @@ import java.io.IOException; import java.util.List; import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; -public abstract class MultipartUtils { +public class MultipartUtils { + + private static final String B_CHARS_NO_SPACE_PATTERN = "0-9a-zA-Z'()+_,-./:=?"; + private static final String B_CHARS_PATTERN = B_CHARS_NO_SPACE_PATTERN + " "; + private static final String BOUNDARY_PATTERN = '[' + B_CHARS_PATTERN + "]{0,69}[" + B_CHARS_NO_SPACE_PATTERN + ']'; + private static final Pattern BOUNDARY_REGEXP = Pattern.compile(BOUNDARY_PATTERN); + private static final Pattern BOUNDARY_FROM_HEADER_REGEXP + = Pattern.compile("; boundary=\"?(" + BOUNDARY_PATTERN + ")\"?"); + + private MultipartUtils() { + } + + public static void checkBoundarySyntax(String boundary) { + if (boundary == null || !BOUNDARY_REGEXP.matcher(boundary).matches()) { + throw new IllegalArgumentException("{'boundary'='" + boundary + "'} has invalid syntax. Should be '" + + BOUNDARY_PATTERN + "'."); + } + } + + public static String parseBoundaryFromHeader(String contentTypeHeader) { + if (contentTypeHeader == null) { + return null; + } + final Matcher matcher = BOUNDARY_FROM_HEADER_REGEXP.matcher(contentTypeHeader); + return matcher.find() ? matcher.group(1) : null; + } + + public static String generateDefaultBoundary() { + return "----ScribeJava----" + System.currentTimeMillis(); + } - // copied from com.github.scribejava.core.httpclient.jdk.JDKHttpClient#getPayload public static ByteArrayOutputStream getPayload(MultipartPayload multipartPayload) throws IOException { final ByteArrayOutputStream os = new ByteArrayOutputStream(); @@ -49,5 +79,4 @@ public static ByteArrayOutputStream getPayload(MultipartPayload multipartPayload } return os; } - } diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClientTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClientTest.java index 79a4a23f0..6ac1070fa 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClientTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClientTest.java @@ -2,15 +2,6 @@ import com.github.scribejava.core.AbstractClientTest; import com.github.scribejava.core.httpclient.HttpClient; -import com.github.scribejava.core.httpclient.multipart.ByteArrayBodyPartPayload; -import com.github.scribejava.core.httpclient.multipart.FileByteArrayBodyPartPayload; -import com.github.scribejava.core.httpclient.multipart.MultipartPayload; -import java.io.IOException; -import java.util.Collections; -import java.util.LinkedHashMap; -import java.util.Map; -import org.junit.Assert; -import org.junit.Test; public class JDKHttpClientTest extends AbstractClientTest { @@ -18,263 +9,4 @@ public class JDKHttpClientTest extends AbstractClientTest { protected HttpClient createNewClient() { return new JDKHttpClient(); } - - @Test - public void testEmptyMultipartPayload() throws IOException { - final MultipartPayload mP = new MultipartPayload(); - - final StringBuilder sb = new StringBuilder(); - for (Map.Entry header : mP.getHeaders().entrySet()) { - sb.append(header.getKey()) - .append(": ") - .append(header.getValue()) - .append("\r\n"); - } - - sb.append("\r\n").append(JDKHttpClient.getPayload(mP).toString()); - Assert.assertEquals("Content-Type: multipart/form-data; boundary=\"" + mP.getBoundary() + "\"\r\n\r\n", - sb.toString()); - } - - @Test - public void testSimpleMultipartPayload() throws IOException { - final Map headers = new LinkedHashMap<>(); - headers.put("X-Header", "X-Value"); - headers.put("Content-Disposition", "Content-Disposition-Value"); - final MultipartPayload mP = new MultipartPayload("mixed", "simple boundary", headers); - mP.setPreamble("This is the preamble. It is to be ignored, though it\n" - + "is a handy place for composition agents to include an\n" - + "explanatory note to non-MIME conformant readers."); - - mP.addBodyPart(("This is implicitly typed plain US-ASCII text.\n" - + "It does NOT end with a linebreak.").getBytes()); - - final ByteArrayBodyPartPayload bP = new ByteArrayBodyPartPayload( - ("This is explicitly typed plain US-ASCII text.\n" - + "It DOES end with a linebreak.\n").getBytes(), - Collections.singletonMap(HttpClient.CONTENT_TYPE, "text/plain; charset=us-ascii")); - mP.addBodyPart(bP); - - mP.setEpilogue("This is the epilogue. It is also to be ignored."); - - final StringBuilder sb = new StringBuilder(); - for (Map.Entry header : mP.getHeaders().entrySet()) { - sb.append(header.getKey()) - .append(": ") - .append(header.getValue()) - .append("\r\n"); - } - sb.append("\r\n").append(JDKHttpClient.getPayload(mP).toString()); - Assert.assertEquals("X-Header: X-Value\r\n" - + "Content-Disposition: Content-Disposition-Value\r\n" - + "Content-Type: multipart/mixed; boundary=\"simple boundary\"\r\n" - + "\r\n" - + "This is the preamble. It is to be ignored, though it\n" - + "is a handy place for composition agents to include an\n" - + "explanatory note to non-MIME conformant readers." - + "\r\n" - + "--simple boundary\r\n" - + "\r\n" - + "This is implicitly typed plain US-ASCII text.\n" - + "It does NOT end with a linebreak." - + "\r\n" - + "--simple boundary\r\n" - + "Content-Type: text/plain; charset=us-ascii\r\n" - + "\r\n" - + "This is explicitly typed plain US-ASCII text.\n" - + "It DOES end with a linebreak.\n" - + "\r\n" - + "--simple boundary--\r\n" - + "This is the epilogue. It is also to be ignored.\r\n", - sb.toString()); - } - - @Test - public void testCRLFMultipartPayload() throws IOException { - final MultipartPayload mP = new MultipartPayload("simple-boundary"); - mP.addBodyPart("It does NOT end with a linebreak.".getBytes()); - mP.addBodyPart("It does end with a \\r linebreak.\r".getBytes()); - mP.addBodyPart("It does end with a \\n linebreak.\n".getBytes()); - mP.addBodyPart("It does end with a \\r\\n linebreak.\r\n".getBytes()); - mP.addBodyPart("the last one".getBytes()); - - final StringBuilder sb = new StringBuilder(); - for (Map.Entry header : mP.getHeaders().entrySet()) { - sb.append(header.getKey()) - .append(": ") - .append(header.getValue()) - .append("\r\n"); - } - sb.append("\r\n").append(JDKHttpClient.getPayload(mP).toString()); - Assert.assertEquals("Content-Type: multipart/form-data; boundary=\"simple-boundary\"\r\n" - + "\r\n" - + "\r\n" - + "--simple-boundary\r\n" - + "\r\n" - + "It does NOT end with a linebreak." - + "\r\n" - + "--simple-boundary\r\n" - + "\r\n" - + "It does end with a \\r linebreak.\r" - + "\r\n" - + "--simple-boundary\r\n" - + "\r\n" - + "It does end with a \\n linebreak.\n" - + "\r\n" - + "--simple-boundary\r\n" - + "\r\n" - + "It does end with a \\r\\n linebreak.\r\n" - + "\r\n" - + "--simple-boundary\r\n" - + "\r\n" - + "the last one" - + "\r\n" - + "--simple-boundary--\r\n", - sb.toString()); - } - - @Test - public void testFileByteArrayBodyPartPayloadMultipartPayload() throws IOException { - final MultipartPayload mP = new MultipartPayload("testFileByteArrayBodyPartPayloadMultipartPayload boundary"); - mP.addBodyPart(new FileByteArrayBodyPartPayload("fileContent".getBytes(), "name", "filename.ext")); - - final StringBuilder sb = new StringBuilder(); - for (Map.Entry header : mP.getHeaders().entrySet()) { - sb.append(header.getKey()) - .append(": ") - .append(header.getValue()) - .append("\r\n"); - } - - sb.append("\r\n").append(JDKHttpClient.getPayload(mP).toString()); - Assert.assertEquals("Content-Type: multipart/form-data; " - + "boundary=\"testFileByteArrayBodyPartPayloadMultipartPayload boundary\"\r\n" - + "\r\n" - + "\r\n" - + "--testFileByteArrayBodyPartPayloadMultipartPayload boundary\r\n" - + "Content-Disposition: form-data; name=\"name\"; filename=\"filename.ext\"\r\n" - + "\r\n" - + "fileContent" - + "\r\n" - + "--testFileByteArrayBodyPartPayloadMultipartPayload boundary--\r\n", - sb.toString() - ); - } - - @Test - public void testComplexMultipartPayload() throws IOException { - final MultipartPayload mP = new MultipartPayload("mixed", "unique-boundary-1"); - - mP.setPreamble("This is the preamble area of a multipart message.\n" - + "Mail readers that understand multipart format\n" - + "should ignore this preamble.\n" - + "\n" - + "If you are reading this text, you might want to\n" - + "consider changing to a mail reader that understands\n" - + "how to properly display multipart messages.\n"); - - mP.addBodyPart("... Some text appears here ...".getBytes()); - - mP.addBodyPart(("This could have been part of the previous part, but\n" - + "illustrates explicit versus implicit typing of body\n" - + "parts.\n").getBytes(), "text/plain; charset=US-ASCII"); - - final MultipartPayload innerMP = new MultipartPayload("parallel", "unique-boundary-2"); - mP.addBodyPart(innerMP); - - final Map audioHeaders = new LinkedHashMap<>(); - audioHeaders.put("Content-Type", "audio/basic"); - audioHeaders.put("Content-Transfer-Encoding", "base64"); - innerMP.addBodyPart(("... base64-encoded 8000 Hz single-channel\n" - + " mu-law-format audio data goes here ...").getBytes(), audioHeaders); - - final Map imageHeaders = new LinkedHashMap<>(); - imageHeaders.put("Content-Type", "image/jpeg"); - imageHeaders.put("Content-Transfer-Encoding", "base64"); - innerMP.addBodyPart("... base64-encoded image data goes here ...".getBytes(), imageHeaders); - - mP.addBodyPart(("This is enriched.\n" - + "as defined in RFC 1896\n" - + "\n" - + "Isn't it\n" - + "cool?\n").getBytes(), "text/enriched"); - - mP.addBodyPart(("From: (mailbox in US-ASCII)\n" - + "To: (address in US-ASCII)\n" - + "Subject: (subject in US-ASCII)\n" - + "Content-Type: Text/plain; charset=ISO-8859-1\n" - + "Content-Transfer-Encoding: Quoted-printable\n" - + "\n" - + "... Additional text in ISO-8859-1 goes here ...\n").getBytes(), "message/rfc822"); - - final StringBuilder sb = new StringBuilder(); - for (Map.Entry header : mP.getHeaders().entrySet()) { - sb.append(header.getKey()) - .append(": ") - .append(header.getValue()) - .append("\r\n"); - } - sb.append("\r\n").append(JDKHttpClient.getPayload(mP).toString()); - Assert.assertEquals("Content-Type: multipart/mixed; boundary=\"unique-boundary-1\"\r\n" - + "\r\n" - + "This is the preamble area of a multipart message.\n" - + "Mail readers that understand multipart format\n" - + "should ignore this preamble.\n" - + "\n" - + "If you are reading this text, you might want to\n" - + "consider changing to a mail reader that understands\n" - + "how to properly display multipart messages.\n" - + "\r\n" - + "--unique-boundary-1\r\n" - + "\r\n" - + "... Some text appears here ..." - + "\r\n" - + "--unique-boundary-1\r\n" - + "Content-Type: text/plain; charset=US-ASCII\r\n" - + "\r\n" - + "This could have been part of the previous part, but\n" - + "illustrates explicit versus implicit typing of body\n" - + "parts.\n" - + "\r\n" - + "--unique-boundary-1\r\n" - + "Content-Type: multipart/parallel; boundary=\"unique-boundary-2\"\r\n" - + "\r\n" - + "--unique-boundary-2\r\n" - + "Content-Type: audio/basic\r\n" - + "Content-Transfer-Encoding: base64\r\n" - + "\r\n" - + "... base64-encoded 8000 Hz single-channel\n" - + " mu-law-format audio data goes here ..." - + "\r\n" - + "--unique-boundary-2\r\n" - + "Content-Type: image/jpeg\r\n" - + "Content-Transfer-Encoding: base64\r\n" - + "\r\n" - + "... base64-encoded image data goes here ..." - + "\r\n" - + "--unique-boundary-2--\r\n" - + "\r\n" - + "--unique-boundary-1\r\n" - + "Content-Type: text/enriched\r\n" - + "\r\n" - + "This is enriched.\n" - + "as defined in RFC 1896\n" - + "\n" - + "Isn't it\n" - + "cool?\n" - + "\r\n" - + "--unique-boundary-1\r\n" - + "Content-Type: message/rfc822\r\n" - + "\r\n" - + "From: (mailbox in US-ASCII)\n" - + "To: (address in US-ASCII)\n" - + "Subject: (subject in US-ASCII)\n" - + "Content-Type: Text/plain; charset=ISO-8859-1\n" - + "Content-Transfer-Encoding: Quoted-printable\n" - + "\n" - + "... Additional text in ISO-8859-1 goes here ...\n" - + "\r\n" - + "--unique-boundary-1--\r\n", - sb.toString()); - } } diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/httpclient/multipart/MultipartPayloadTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/httpclient/multipart/MultipartPayloadTest.java deleted file mode 100644 index 4abc36ee5..000000000 --- a/scribejava-core/src/test/java/com/github/scribejava/core/httpclient/multipart/MultipartPayloadTest.java +++ /dev/null @@ -1,108 +0,0 @@ -package com.github.scribejava.core.httpclient.multipart; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThrows; -import static org.junit.Assert.assertTrue; -import org.junit.Test; -import org.junit.function.ThrowingRunnable; - -public class MultipartPayloadTest { - - @Test - public void testValidCheckBoundarySyntax() { - MultipartPayload.checkBoundarySyntax("0aA'()+_,-./:=?"); - MultipartPayload.checkBoundarySyntax("0aA'()+_,- ./:=?"); - MultipartPayload.checkBoundarySyntax(" 0aA'()+_,-./:=?"); - MultipartPayload.checkBoundarySyntax("1234567890123456789012345678901234567890123456789012345678901234567890"); - } - - @Test - public void testNonValidLastWhiteSpaceCheckBoundarySyntax() { - testBoundary("0aA'()+_,-./:=? "); - } - - @Test - public void testNonValidEmptyCheckBoundarySyntax() { - testBoundary(""); - } - - @Test - public void testNonValidIllegalSymbolCheckBoundarySyntax() { - testBoundary("0aA'()+_;,-./:=? "); - } - - @Test - public void testNonValidTooLongCheckBoundarySyntax() { - testBoundary("12345678901234567890123456789012345678901234567890123456789012345678901"); - } - - @Test - public void testNonValidNullCheckBoundarySyntax() { - testBoundary(null); - } - - @Test - public void testParseBoundaryFromHeader() { - assertNull(MultipartPayload.parseBoundaryFromHeader(null)); - - assertEquals("0aA'()+_,-./:=?", - MultipartPayload.parseBoundaryFromHeader("multipart/subtype; boundary=\"0aA'()+_,-./:=?\"")); - - assertEquals("0aA'()+_, -./:=?", - MultipartPayload.parseBoundaryFromHeader("multipart/subtype; boundary=\"0aA'()+_, -./:=?\"")); - - assertEquals("0aA'()+_, -./:=?", - MultipartPayload.parseBoundaryFromHeader("multipart/subtype; boundary=\"0aA'()+_, -./:=? \"")); - - assertEquals("0aA'()+_,-./:=?", - MultipartPayload.parseBoundaryFromHeader("multipart/subtype; boundary=0aA'()+_,-./:=?")); - - assertEquals("0aA'()+_, -./:=?", - MultipartPayload.parseBoundaryFromHeader("multipart/subtype; boundary=0aA'()+_, -./:=?")); - - assertEquals("0aA'()+_, -./:=?", - MultipartPayload.parseBoundaryFromHeader("multipart/subtype; boundary=0aA'()+_, -./:=? ")); - - assertEquals(" 0aA'()+_, -./:=?", - MultipartPayload.parseBoundaryFromHeader("multipart/subtype; boundary= 0aA'()+_, -./:=?")); - - assertNull(MultipartPayload.parseBoundaryFromHeader("multipart/subtype; boundar=0aA'()+_, -./:=? ")); - assertNull(MultipartPayload.parseBoundaryFromHeader("multipart/subtype; ")); - assertNull(MultipartPayload.parseBoundaryFromHeader("multipart/subtype;")); - assertNull(MultipartPayload.parseBoundaryFromHeader("multipart/subtype")); - assertNull(MultipartPayload.parseBoundaryFromHeader("multipart/subtype; boundary=")); - - assertEquals("0aA'()+_,", - MultipartPayload.parseBoundaryFromHeader("multipart/subtype; boundary=0aA'()+_,; -./:=? ")); - - assertEquals("0aA'()+_, -./:=?", - MultipartPayload.parseBoundaryFromHeader("multipart/subtype; boundary=\"0aA'()+_, -./:=?")); - - assertEquals("0aA'()+_, -./:=?", - MultipartPayload.parseBoundaryFromHeader("multipart/subtype; boundary=0aA'()+_, -./:=?\"")); - - assertEquals("1234567890123456789012345678901234567890123456789012345678901234567890", - MultipartPayload.parseBoundaryFromHeader("multipart/subtype; " - + "boundary=1234567890123456789012345678901234567890123456789012345678901234567890")); - - assertEquals("1234567890123456789012345678901234567890123456789012345678901234567890", - MultipartPayload.parseBoundaryFromHeader("multipart/subtype; " - + "boundary=12345678901234567890123456789012345678901234567890123456789012345678901")); - - assertNull(MultipartPayload.parseBoundaryFromHeader("multipart/subtype; boundary=")); - assertNull(MultipartPayload.parseBoundaryFromHeader("multipart/subtype; boundary=\"\"")); - assertNull(MultipartPayload.parseBoundaryFromHeader("multipart/subtype; boundary=;123")); - assertNull(MultipartPayload.parseBoundaryFromHeader("multipart/subtype; boundary=\"\"123")); - } - - private static void testBoundary(final String boundary) { - final IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, new ThrowingRunnable() { - @Override - public void run() throws Throwable { - MultipartPayload.checkBoundarySyntax(boundary); - } - }); - assertTrue(thrown.getMessage().startsWith("{'boundary'='" + boundary + "'} has invalid syntax. Should be '")); - } -} diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/httpclient/multipart/MultipartUtilsTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/httpclient/multipart/MultipartUtilsTest.java new file mode 100644 index 000000000..cac5def30 --- /dev/null +++ b/scribejava-core/src/test/java/com/github/scribejava/core/httpclient/multipart/MultipartUtilsTest.java @@ -0,0 +1,371 @@ +package com.github.scribejava.core.httpclient.multipart; + +import com.github.scribejava.core.httpclient.HttpClient; +import java.io.IOException; +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.Map; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertThrows; +import static org.junit.Assert.assertTrue; +import org.junit.Test; +import org.junit.function.ThrowingRunnable; + +public class MultipartUtilsTest { + + @Test + public void testEmptyMultipartPayload() throws IOException { + final MultipartPayload mP = new MultipartPayload(); + + final StringBuilder sb = new StringBuilder(); + for (Map.Entry header : mP.getHeaders().entrySet()) { + sb.append(header.getKey()) + .append(": ") + .append(header.getValue()) + .append("\r\n"); + } + + sb.append("\r\n").append(MultipartUtils.getPayload(mP).toString()); + assertEquals("Content-Type: multipart/form-data; boundary=\"" + mP.getBoundary() + "\"\r\n\r\n", sb.toString()); + } + + @Test + public void testSimpleMultipartPayload() throws IOException { + final Map headers = new LinkedHashMap<>(); + headers.put("X-Header", "X-Value"); + headers.put("Content-Disposition", "Content-Disposition-Value"); + final MultipartPayload mP = new MultipartPayload("mixed", "simple boundary", headers); + mP.setPreamble("This is the preamble. It is to be ignored, though it\n" + + "is a handy place for composition agents to include an\n" + + "explanatory note to non-MIME conformant readers."); + + mP.addBodyPart(("This is implicitly typed plain US-ASCII text.\n" + + "It does NOT end with a linebreak.").getBytes()); + + final ByteArrayBodyPartPayload bP = new ByteArrayBodyPartPayload( + ("This is explicitly typed plain US-ASCII text.\n" + + "It DOES end with a linebreak.\n").getBytes(), + Collections.singletonMap(HttpClient.CONTENT_TYPE, "text/plain; charset=us-ascii")); + mP.addBodyPart(bP); + + mP.setEpilogue("This is the epilogue. It is also to be ignored."); + + final StringBuilder sb = new StringBuilder(); + for (Map.Entry header : mP.getHeaders().entrySet()) { + sb.append(header.getKey()) + .append(": ") + .append(header.getValue()) + .append("\r\n"); + } + sb.append("\r\n").append(MultipartUtils.getPayload(mP).toString()); + assertEquals("X-Header: X-Value\r\n" + + "Content-Disposition: Content-Disposition-Value\r\n" + + "Content-Type: multipart/mixed; boundary=\"simple boundary\"\r\n" + + "\r\n" + + "This is the preamble. It is to be ignored, though it\n" + + "is a handy place for composition agents to include an\n" + + "explanatory note to non-MIME conformant readers." + + "\r\n" + + "--simple boundary\r\n" + + "\r\n" + + "This is implicitly typed plain US-ASCII text.\n" + + "It does NOT end with a linebreak." + + "\r\n" + + "--simple boundary\r\n" + + "Content-Type: text/plain; charset=us-ascii\r\n" + + "\r\n" + + "This is explicitly typed plain US-ASCII text.\n" + + "It DOES end with a linebreak.\n" + + "\r\n" + + "--simple boundary--\r\n" + + "This is the epilogue. It is also to be ignored.\r\n", + sb.toString()); + } + + @Test + public void testCRLFMultipartPayload() throws IOException { + final MultipartPayload mP = new MultipartPayload("simple-boundary"); + mP.addBodyPart("It does NOT end with a linebreak.".getBytes()); + mP.addBodyPart("It does end with a \\r linebreak.\r".getBytes()); + mP.addBodyPart("It does end with a \\n linebreak.\n".getBytes()); + mP.addBodyPart("It does end with a \\r\\n linebreak.\r\n".getBytes()); + mP.addBodyPart("the last one".getBytes()); + + final StringBuilder sb = new StringBuilder(); + for (Map.Entry header : mP.getHeaders().entrySet()) { + sb.append(header.getKey()) + .append(": ") + .append(header.getValue()) + .append("\r\n"); + } + sb.append("\r\n").append(MultipartUtils.getPayload(mP).toString()); + assertEquals("Content-Type: multipart/form-data; boundary=\"simple-boundary\"\r\n" + + "\r\n" + + "\r\n" + + "--simple-boundary\r\n" + + "\r\n" + + "It does NOT end with a linebreak." + + "\r\n" + + "--simple-boundary\r\n" + + "\r\n" + + "It does end with a \\r linebreak.\r" + + "\r\n" + + "--simple-boundary\r\n" + + "\r\n" + + "It does end with a \\n linebreak.\n" + + "\r\n" + + "--simple-boundary\r\n" + + "\r\n" + + "It does end with a \\r\\n linebreak.\r\n" + + "\r\n" + + "--simple-boundary\r\n" + + "\r\n" + + "the last one" + + "\r\n" + + "--simple-boundary--\r\n", + sb.toString()); + } + + @Test + public void testFileByteArrayBodyPartPayloadMultipartPayload() throws IOException { + final MultipartPayload mP = new MultipartPayload("testFileByteArrayBodyPartPayloadMultipartPayload boundary"); + mP.addBodyPart(new FileByteArrayBodyPartPayload("fileContent".getBytes(), "name", "filename.ext")); + + final StringBuilder sb = new StringBuilder(); + for (Map.Entry header : mP.getHeaders().entrySet()) { + sb.append(header.getKey()) + .append(": ") + .append(header.getValue()) + .append("\r\n"); + } + + sb.append("\r\n").append(MultipartUtils.getPayload(mP).toString()); + assertEquals("Content-Type: multipart/form-data; " + + "boundary=\"testFileByteArrayBodyPartPayloadMultipartPayload boundary\"\r\n" + + "\r\n" + + "\r\n" + + "--testFileByteArrayBodyPartPayloadMultipartPayload boundary\r\n" + + "Content-Disposition: form-data; name=\"name\"; filename=\"filename.ext\"\r\n" + + "\r\n" + + "fileContent" + + "\r\n" + + "--testFileByteArrayBodyPartPayloadMultipartPayload boundary--\r\n", + sb.toString() + ); + } + + @Test + public void testComplexMultipartPayload() throws IOException { + final MultipartPayload mP = new MultipartPayload("mixed", "unique-boundary-1"); + + mP.setPreamble("This is the preamble area of a multipart message.\n" + + "Mail readers that understand multipart format\n" + + "should ignore this preamble.\n" + + "\n" + + "If you are reading this text, you might want to\n" + + "consider changing to a mail reader that understands\n" + + "how to properly display multipart messages.\n"); + + mP.addBodyPart("... Some text appears here ...".getBytes()); + + mP.addBodyPart(("This could have been part of the previous part, but\n" + + "illustrates explicit versus implicit typing of body\n" + + "parts.\n").getBytes(), "text/plain; charset=US-ASCII"); + + final MultipartPayload innerMP = new MultipartPayload("parallel", "unique-boundary-2"); + mP.addBodyPart(innerMP); + + final Map audioHeaders = new LinkedHashMap<>(); + audioHeaders.put("Content-Type", "audio/basic"); + audioHeaders.put("Content-Transfer-Encoding", "base64"); + innerMP.addBodyPart(("... base64-encoded 8000 Hz single-channel\n" + + " mu-law-format audio data goes here ...").getBytes(), audioHeaders); + + final Map imageHeaders = new LinkedHashMap<>(); + imageHeaders.put("Content-Type", "image/jpeg"); + imageHeaders.put("Content-Transfer-Encoding", "base64"); + innerMP.addBodyPart("... base64-encoded image data goes here ...".getBytes(), imageHeaders); + + mP.addBodyPart(("This is enriched.\n" + + "as defined in RFC 1896\n" + + "\n" + + "Isn't it\n" + + "cool?\n").getBytes(), "text/enriched"); + + mP.addBodyPart(("From: (mailbox in US-ASCII)\n" + + "To: (address in US-ASCII)\n" + + "Subject: (subject in US-ASCII)\n" + + "Content-Type: Text/plain; charset=ISO-8859-1\n" + + "Content-Transfer-Encoding: Quoted-printable\n" + + "\n" + + "... Additional text in ISO-8859-1 goes here ...\n").getBytes(), "message/rfc822"); + + final StringBuilder sb = new StringBuilder(); + for (Map.Entry header : mP.getHeaders().entrySet()) { + sb.append(header.getKey()) + .append(": ") + .append(header.getValue()) + .append("\r\n"); + } + sb.append("\r\n").append(MultipartUtils.getPayload(mP).toString()); + assertEquals("Content-Type: multipart/mixed; boundary=\"unique-boundary-1\"\r\n" + + "\r\n" + + "This is the preamble area of a multipart message.\n" + + "Mail readers that understand multipart format\n" + + "should ignore this preamble.\n" + + "\n" + + "If you are reading this text, you might want to\n" + + "consider changing to a mail reader that understands\n" + + "how to properly display multipart messages.\n" + + "\r\n" + + "--unique-boundary-1\r\n" + + "\r\n" + + "... Some text appears here ..." + + "\r\n" + + "--unique-boundary-1\r\n" + + "Content-Type: text/plain; charset=US-ASCII\r\n" + + "\r\n" + + "This could have been part of the previous part, but\n" + + "illustrates explicit versus implicit typing of body\n" + + "parts.\n" + + "\r\n" + + "--unique-boundary-1\r\n" + + "Content-Type: multipart/parallel; boundary=\"unique-boundary-2\"\r\n" + + "\r\n" + + "--unique-boundary-2\r\n" + + "Content-Type: audio/basic\r\n" + + "Content-Transfer-Encoding: base64\r\n" + + "\r\n" + + "... base64-encoded 8000 Hz single-channel\n" + + " mu-law-format audio data goes here ..." + + "\r\n" + + "--unique-boundary-2\r\n" + + "Content-Type: image/jpeg\r\n" + + "Content-Transfer-Encoding: base64\r\n" + + "\r\n" + + "... base64-encoded image data goes here ..." + + "\r\n" + + "--unique-boundary-2--\r\n" + + "\r\n" + + "--unique-boundary-1\r\n" + + "Content-Type: text/enriched\r\n" + + "\r\n" + + "This is enriched.\n" + + "as defined in RFC 1896\n" + + "\n" + + "Isn't it\n" + + "cool?\n" + + "\r\n" + + "--unique-boundary-1\r\n" + + "Content-Type: message/rfc822\r\n" + + "\r\n" + + "From: (mailbox in US-ASCII)\n" + + "To: (address in US-ASCII)\n" + + "Subject: (subject in US-ASCII)\n" + + "Content-Type: Text/plain; charset=ISO-8859-1\n" + + "Content-Transfer-Encoding: Quoted-printable\n" + + "\n" + + "... Additional text in ISO-8859-1 goes here ...\n" + + "\r\n" + + "--unique-boundary-1--\r\n", + sb.toString()); + } + + @Test + public void testParseBoundaryFromHeader() { + assertNull(MultipartUtils.parseBoundaryFromHeader(null)); + + assertEquals("0aA'()+_,-./:=?", + MultipartUtils.parseBoundaryFromHeader("multipart/subtype; boundary=\"0aA'()+_,-./:=?\"")); + + assertEquals("0aA'()+_, -./:=?", + MultipartUtils.parseBoundaryFromHeader("multipart/subtype; boundary=\"0aA'()+_, -./:=?\"")); + + assertEquals("0aA'()+_, -./:=?", + MultipartUtils.parseBoundaryFromHeader("multipart/subtype; boundary=\"0aA'()+_, -./:=? \"")); + + assertEquals("0aA'()+_,-./:=?", + MultipartUtils.parseBoundaryFromHeader("multipart/subtype; boundary=0aA'()+_,-./:=?")); + + assertEquals("0aA'()+_, -./:=?", + MultipartUtils.parseBoundaryFromHeader("multipart/subtype; boundary=0aA'()+_, -./:=?")); + + assertEquals("0aA'()+_, -./:=?", + MultipartUtils.parseBoundaryFromHeader("multipart/subtype; boundary=0aA'()+_, -./:=? ")); + + assertEquals(" 0aA'()+_, -./:=?", + MultipartUtils.parseBoundaryFromHeader("multipart/subtype; boundary= 0aA'()+_, -./:=?")); + + assertNull(MultipartUtils.parseBoundaryFromHeader("multipart/subtype; boundar=0aA'()+_, -./:=? ")); + assertNull(MultipartUtils.parseBoundaryFromHeader("multipart/subtype; ")); + assertNull(MultipartUtils.parseBoundaryFromHeader("multipart/subtype;")); + assertNull(MultipartUtils.parseBoundaryFromHeader("multipart/subtype")); + assertNull(MultipartUtils.parseBoundaryFromHeader("multipart/subtype; boundary=")); + + assertEquals("0aA'()+_,", + MultipartUtils.parseBoundaryFromHeader("multipart/subtype; boundary=0aA'()+_,; -./:=? ")); + + assertEquals("0aA'()+_, -./:=?", + MultipartUtils.parseBoundaryFromHeader("multipart/subtype; boundary=\"0aA'()+_, -./:=?")); + + assertEquals("0aA'()+_, -./:=?", + MultipartUtils.parseBoundaryFromHeader("multipart/subtype; boundary=0aA'()+_, -./:=?\"")); + + assertEquals("1234567890123456789012345678901234567890123456789012345678901234567890", + MultipartUtils.parseBoundaryFromHeader("multipart/subtype; " + + "boundary=1234567890123456789012345678901234567890123456789012345678901234567890")); + + assertEquals("1234567890123456789012345678901234567890123456789012345678901234567890", + MultipartUtils.parseBoundaryFromHeader("multipart/subtype; " + + "boundary=12345678901234567890123456789012345678901234567890123456789012345678901")); + + assertNull(MultipartUtils.parseBoundaryFromHeader("multipart/subtype; boundary=")); + assertNull(MultipartUtils.parseBoundaryFromHeader("multipart/subtype; boundary=\"\"")); + assertNull(MultipartUtils.parseBoundaryFromHeader("multipart/subtype; boundary=;123")); + assertNull(MultipartUtils.parseBoundaryFromHeader("multipart/subtype; boundary=\"\"123")); + } + + @Test + public void testValidCheckBoundarySyntax() { + MultipartUtils.checkBoundarySyntax("0aA'()+_,-./:=?"); + MultipartUtils.checkBoundarySyntax("0aA'()+_,- ./:=?"); + MultipartUtils.checkBoundarySyntax(" 0aA'()+_,-./:=?"); + MultipartUtils.checkBoundarySyntax("1234567890123456789012345678901234567890123456789012345678901234567890"); + } + + @Test + public void testNonValidLastWhiteSpaceCheckBoundarySyntax() { + testNotValidBoundary("0aA'()+_,-./:=? "); + } + + @Test + public void testNonValidEmptyCheckBoundarySyntax() { + testNotValidBoundary(""); + } + + @Test + public void testNonValidIllegalSymbolCheckBoundarySyntax() { + testNotValidBoundary("0aA'()+_;,-./:=? "); + } + + @Test + public void testNonValidTooLongCheckBoundarySyntax() { + testNotValidBoundary("12345678901234567890123456789012345678901234567890123456789012345678901"); + } + + @Test + public void testNonValidNullCheckBoundarySyntax() { + testNotValidBoundary(null); + } + + private static void testNotValidBoundary(final String boundary) { + final IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, new ThrowingRunnable() { + @Override + public void run() throws Throwable { + MultipartUtils.checkBoundarySyntax(boundary); + } + }); + assertTrue(thrown.getMessage().startsWith("{'boundary'='" + boundary + "'} has invalid syntax. Should be '")); + } +} diff --git a/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/AhcHttpClient.java b/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/AhcHttpClient.java index 882293a43..4da925590 100644 --- a/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/AhcHttpClient.java +++ b/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/AhcHttpClient.java @@ -42,8 +42,7 @@ public void close() throws IOException { @Override public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, - final byte[] bodyContents, OAuthAsyncRequestCallback callback, - OAuthRequest.ResponseConverter converter) { + byte[] bodyContents, OAuthAsyncRequestCallback callback, OAuthRequest.ResponseConverter converter) { return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, new ByteArrayConsumer(bodyContents), callback, converter); } @@ -58,16 +57,14 @@ public Future executeAsync(String userAgent, Map headers, @Override public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, - final String bodyContents, OAuthAsyncRequestCallback callback, - OAuthRequest.ResponseConverter converter) { + String bodyContents, OAuthAsyncRequestCallback callback, OAuthRequest.ResponseConverter converter) { return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, new StringConsumer(bodyContents), callback, converter); } @Override public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, - final File bodyContents, OAuthAsyncRequestCallback callback, - OAuthRequest.ResponseConverter converter) { + File bodyContents, OAuthAsyncRequestCallback callback, OAuthRequest.ResponseConverter converter) { return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, new FileConsumer(bodyContents), callback, converter); } diff --git a/scribejava-httpclient-armeria/pom.xml b/scribejava-httpclient-armeria/pom.xml index 6642e9cad..b67e66998 100644 --- a/scribejava-httpclient-armeria/pom.xml +++ b/scribejava-httpclient-armeria/pom.xml @@ -9,6 +9,7 @@ ../pom.xml + com.github.scribejava scribejava-httpclient-armeria ScribeJava Async Armeria Client support jar @@ -22,13 +23,7 @@ com.linecorp.armeria armeria - 0.99.7 - - - com.github.scribejava - scribejava-apis - ${project.version} - test + 0.99.8 com.github.scribejava @@ -37,25 +32,10 @@ test-jar test - - org.slf4j - slf4j-simple - 1.7.30 - test - - - maven-compiler-plugin - 3.8.1 - - UTF-8 - 8 - true - - org.apache.felix maven-bundle-plugin @@ -66,4 +46,8 @@ + + + 8 + diff --git a/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClient.java b/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClient.java index b059d6f04..982ddc63a 100644 --- a/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClient.java +++ b/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClient.java @@ -15,11 +15,14 @@ import com.linecorp.armeria.common.HttpData; import com.linecorp.armeria.common.HttpMethod; import com.linecorp.armeria.common.HttpResponse; +import com.linecorp.armeria.common.HttpStatus; +import com.linecorp.armeria.common.MediaType; import com.linecorp.armeria.common.RequestHeaders; import com.linecorp.armeria.common.RequestHeadersBuilder; import java.io.File; import java.io.IOException; +import java.io.InputStream; import java.net.URI; import java.nio.file.Files; import java.util.HashMap; @@ -54,7 +57,7 @@ public ArmeriaHttpClient() { } public ArmeriaHttpClient(ArmeriaHttpClientConfig config) { - this.clientBuilder = config.builder(); + clientBuilder = config.createClientBuilder(); } /** @@ -72,41 +75,36 @@ public void close() { } @Override - public Future executeAsync(String userAgent, Map headers, Verb httpVerb, - String completeUrl, byte[] bodyContents, OAuthAsyncRequestCallback callback, - OAuthRequest.ResponseConverter converter) { - return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, - new BytesBody(bodyContents), callback, converter); + public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, + byte[] bodyContents, OAuthAsyncRequestCallback callback, OAuthRequest.ResponseConverter converter) { + return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, new BytesBody(bodyContents), callback, + converter); } @Override - public Future executeAsync(String userAgent, Map headers, Verb httpVerb, - String completeUrl, MultipartPayload bodyContents, OAuthAsyncRequestCallback callback, + public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, + MultipartPayload bodyContents, OAuthAsyncRequestCallback callback, OAuthRequest.ResponseConverter converter) { - return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, - new MultipartBody(bodyContents), callback, converter); + return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, new MultipartBody(bodyContents), callback, + converter); } @Override - public Future executeAsync(String userAgent, Map headers, Verb httpVerb, - String completeUrl, String bodyContents, OAuthAsyncRequestCallback callback, - OAuthRequest.ResponseConverter converter) { - return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, - new StringBody(bodyContents), callback, converter); + public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, + String bodyContents, OAuthAsyncRequestCallback callback, OAuthRequest.ResponseConverter converter) { + return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, new StringBody(bodyContents), callback, + converter); } @Override - public Future executeAsync(String userAgent, Map headers, Verb httpVerb, - String completeUrl, File bodyContents, OAuthAsyncRequestCallback callback, - OAuthRequest.ResponseConverter converter) { - return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, - new FileBody(bodyContents), callback, converter); + public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, + File bodyContents, OAuthAsyncRequestCallback callback, OAuthRequest.ResponseConverter converter) { + return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, new FileBody(bodyContents), callback, + converter); } - private CompletableFuture doExecuteAsync(String userAgent, - Map headers, Verb httpVerb, - String completeUrl, Supplier contentSupplier, - OAuthAsyncRequestCallback callback, + private CompletableFuture doExecuteAsync(String userAgent, Map headers, Verb httpVerb, + String completeUrl, Supplier contentSupplier, OAuthAsyncRequestCallback callback, OAuthRequest.ResponseConverter converter) { // Get the URI and Path final URI uri = URI.create(completeUrl); @@ -116,8 +114,8 @@ private CompletableFuture doExecuteAsync(String userAgent, final WebClient client = getClient(uri); // Build HTTP request - final RequestHeadersBuilder headersBuilder - = RequestHeaders.of(getHttpMethod(httpVerb), path).toBuilder(); + final RequestHeadersBuilder headersBuilder = RequestHeaders.of(getHttpMethod(httpVerb), path).toBuilder(); + headersBuilder.add(headers.entrySet()); if (userAgent != null) { headersBuilder.add(OAuthConstants.USER_AGENT_HEADER_NAME, userAgent); @@ -128,9 +126,13 @@ private CompletableFuture doExecuteAsync(String userAgent, if (httpVerb.isPermitBody()) { // POST, PUT, PATCH and DELETE methods final HttpData contents = contentSupplier.get(); if (httpVerb.isRequiresBody() && contents == null) { // POST or PUT methods - throw new IllegalArgumentException( - "Contents missing for request method " + httpVerb.name()); + throw new IllegalArgumentException("Contents missing for request method " + httpVerb.name()); + } + + if (headersBuilder.contentType() == null) { + headersBuilder.contentType(MediaType.FORM_DATA); } + if (contents != null) { response = client.execute(headersBuilder.build(), contents); } else { @@ -142,11 +144,10 @@ private CompletableFuture doExecuteAsync(String userAgent, // Aggregate HTTP response (asynchronously) and return the result Future return response.aggregate() - .thenApply(r -> whenResponseComplete(callback, converter, r)) - .exceptionally(e -> completeExceptionally(callback, e)); + .thenApply(aggregatedResponse -> whenResponseComplete(callback, converter, aggregatedResponse)) + .exceptionally(throwable -> completeExceptionally(callback, throwable)); } - //------------------------------------------------------------------------------------------------ /** * Provides an instance of {@link WebClient} for a given endpoint {@link URI} based on an endpoint as * {@code scheme://authority}. @@ -154,7 +155,7 @@ private CompletableFuture doExecuteAsync(String userAgent, * @param uri an endpoint {@link URI} * @return {@link WebClient} instance */ - private WebClient getClient(final URI uri) { + private WebClient getClient(URI uri) { final String endpoint = getEndPoint(uri); WebClient client; @@ -189,23 +190,20 @@ private WebClient getClient(final URI uri) { } /** - * Extracts {@code scheme} and {@code authority} portion of the {@link URI}. Assuming the {@link URI} as the - * following: {@code URI = scheme:[//authority]path[?query][#fragment]} + * Extracts {@code scheme} and {@code authority} portion of the {@link URI}. + * + * Assuming the {@link URI} as the following: {@code URI = scheme:[//authority]path[?query][#fragment]} */ - @SuppressWarnings("StringBufferReplaceableByString") - private static String getEndPoint(final URI uri) { - final StringBuilder builder = new StringBuilder() - .append(requireNonNull(uri.getScheme(), "scheme")) - .append("://").append(requireNonNull(uri.getAuthority(), "authority")); - return builder.toString(); + private static String getEndPoint(URI uri) { + return requireNonNull(uri.getScheme(), "scheme") + "://" + requireNonNull(uri.getAuthority(), "authority"); } /** - * Extracts {@code path}, {@code query) and {@code fragment} portion of the {@link URI}. - * Assuming the {@link URI} as the following: - * {@code URI = scheme:[//authority]path[?query][#fragment]} + * Extracts {@code path}, {@code query} and {@code fragment} portion of the {@link URI}. + * + * Assuming the {@link URI} as the following: {@code URI = scheme:[//authority]path[?query][#fragment]} */ - private static String getServicePath(final URI uri) { + private static String getServicePath(URI uri) { final StringBuilder builder = new StringBuilder() .append(requireNonNull(uri.getPath(), "path")); final String query = uri.getQuery(); @@ -225,7 +223,7 @@ private static String getServicePath(final URI uri) { * @param httpVerb a {@link Verb} to match with {@link HttpMethod} * @return {@link HttpMethod} corresponding to the parameter */ - private static HttpMethod getHttpMethod(final Verb httpVerb) { + private static HttpMethod getHttpMethod(Verb httpVerb) { switch (httpVerb) { case GET: return HttpMethod.GET; @@ -249,7 +247,6 @@ private static HttpMethod getHttpMethod(final Verb httpVerb) { } } - //------------------------------------------------------------------------------------------------ // Response asynchronous handlers /** * Converts {@link AggregatedHttpResponse} to {@link Response} @@ -257,13 +254,14 @@ private static HttpMethod getHttpMethod(final Verb httpVerb) { * @param aggregatedResponse an instance of {@link AggregatedHttpResponse} to convert to {@link Response} * @return a {@link Response} converted from {@link AggregatedHttpResponse} */ - private Response convertResponse(final AggregatedHttpResponse aggregatedResponse) { - final Map headersMap = new HashMap<>(aggregatedResponse.headers().size()); - aggregatedResponse.headers() - .forEach((header, value) -> headersMap.put(header.toString(), value)); - return new Response(aggregatedResponse.status().code(), - aggregatedResponse.status().reasonPhrase(), - headersMap, aggregatedResponse.content().toInputStream()); + private Response convertResponse(AggregatedHttpResponse aggregatedResponse) { + final Map headersMap = new HashMap<>(); + aggregatedResponse.headers().forEach((header, value) -> headersMap.put(header.toString(), value)); + + final HttpStatus status = aggregatedResponse.status(); + final InputStream inputStream = aggregatedResponse.content().toInputStream(); + + return new Response(status.code(), status.reasonPhrase(), headersMap, inputStream, inputStream); } /** @@ -281,8 +279,7 @@ private T whenResponseComplete(OAuthAsyncRequestCallback callback, final Response response = convertResponse(aggregatedResponse); try { @SuppressWarnings("unchecked") - final T t - = converter == null ? (T) response : converter.convert(response); + final T t = converter == null ? (T) response : converter.convert(response); if (callback != null) { callback.onCompleted(t); } @@ -307,13 +304,12 @@ private T completeExceptionally(OAuthAsyncRequestCallback callback, Throw return null; } - //------------------------------------------------------------------------------------------------ // Body type suppliers private static class BytesBody implements Supplier { private final byte[] bodyContents; - BytesBody(final byte[] bodyContents) { + BytesBody(byte[] bodyContents) { this.bodyContents = bodyContents; } @@ -327,7 +323,7 @@ private static class StringBody implements Supplier { private final String bodyContents; - StringBody(final String bodyContents) { + StringBody(String bodyContents) { this.bodyContents = bodyContents; } @@ -341,7 +337,7 @@ private static class FileBody implements Supplier { private final File bodyContents; - FileBody(final File bodyContents) { + FileBody(File bodyContents) { this.bodyContents = bodyContents; } @@ -351,8 +347,8 @@ public HttpData get() { return (bodyContents != null) ? HttpData.wrap(Files.readAllBytes(bodyContents.toPath())) : null; - } catch (IOException e) { - throw new RuntimeException(e); + } catch (IOException ioE) { + throw new RuntimeException(ioE); } } } @@ -361,7 +357,7 @@ private static class MultipartBody implements Supplier { private final MultipartPayload bodyContents; - MultipartBody(final MultipartPayload bodyContents) { + MultipartBody(MultipartPayload bodyContents) { this.bodyContents = bodyContents; } @@ -371,11 +367,9 @@ public HttpData get() { return (bodyContents != null) ? HttpData.wrap(MultipartUtils.getPayload(bodyContents).toByteArray()) : null; - } catch (IOException e) { - throw new RuntimeException(e); + } catch (IOException ioE) { + throw new RuntimeException(ioE); } } } - - //------------------------------------------------------------------------------------------------ } diff --git a/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClientConfig.java b/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClientConfig.java index a0f503222..19fc27f48 100644 --- a/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClientConfig.java +++ b/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClientConfig.java @@ -5,14 +5,9 @@ import com.linecorp.armeria.client.ClientOptions; import com.linecorp.armeria.client.HttpClient; import com.linecorp.armeria.client.logging.LoggingClient; -import com.linecorp.armeria.client.retry.Backoff; -import com.linecorp.armeria.client.retry.RetryRule; import com.linecorp.armeria.client.retry.RetryingClient; -import com.linecorp.armeria.common.HttpStatus; import com.linecorp.armeria.common.SessionProtocol; -import com.linecorp.armeria.common.logging.LogLevel; import java.util.function.Function; -import org.slf4j.LoggerFactory; public class ArmeriaHttpClientConfig implements HttpClientConfig { @@ -26,6 +21,9 @@ public class ArmeriaHttpClientConfig implements HttpClientConfig { /** * Creates new {@link ArmeriaHttpClientConfig} using provided {@link ClientOptions} and {@link ClientFactory}. + * + * @param clientOptions clientOptions + * @param clientFactory clientFactory */ public ArmeriaHttpClientConfig(ClientOptions clientOptions, ClientFactory clientFactory) { this.clientOptions = clientOptions; @@ -33,13 +31,6 @@ public ArmeriaHttpClientConfig(ClientOptions clientOptions, ClientFactory client protocolPreference = DEFAULT_PROTOCOL_PREFERENCE; } - /** - * Creates new {@link ArmeriaHttpClientConfig} using default settings. - */ - ArmeriaHttpClientConfig() { - this(null, null); - } - /** * Creates new {@link HttpClientConfig} using default settings. */ @@ -50,34 +41,11 @@ public HttpClientConfig createDefaultConfig() { /** * Creates new {@link ArmeriaHttpClientConfig} using default settings. - */ - public static ArmeriaHttpClientConfig defaultConfig() { - return new ArmeriaHttpClientConfig(); - } - - /** - * Selects which protocol shall take preference when generic protocol scheme used by the URL, like {@code http} or - * {@code https}. * - * @param protocolPreference specifies which protocol shall take preference. Acceptable values: {@code H1}, - * {@code HTTP1}, {@code HTTP/1.1} for {@code HTTP/1.1} and {@code H2}, {@code HTTP2}, {@code HTTP/2} for - * {@code HTTP/2}. + * @return ArmeriaHttpClientConfig */ - public void protocolPreference(String protocolPreference) { - switch (protocolPreference.toUpperCase()) { - case "H1": - case "HTTP1": - case "HTTP/1.1": - this.protocolPreference = SessionProtocol.H1; - break; - case "H2": - case "HTTP2": - case "HTTP/2": - this.protocolPreference = SessionProtocol.H2; - break; - default: - throw new IllegalArgumentException("Invalid protocolPreference: " + protocolPreference); - } + public static ArmeriaHttpClientConfig defaultConfig() { + return new ArmeriaHttpClientConfig(null, null); } /** @@ -87,104 +55,22 @@ public void protocolPreference(String protocolPreference) { * @param protocolPreference specifies which protocol shall take preference. Acceptable values: * {@link SessionProtocol#H1} and {@link SessionProtocol#H2} */ - public void protocolPreference(SessionProtocol protocolPreference) { - switch (protocolPreference) { - case H1: - this.protocolPreference = SessionProtocol.H1; - break; - case H2: - this.protocolPreference = SessionProtocol.H2; - break; - default: - throw new IllegalArgumentException("Invalid protocolPreference: " + protocolPreference); + public void setProtocolPreference(SessionProtocol protocolPreference) { + if (protocolPreference != SessionProtocol.H1 && protocolPreference != SessionProtocol.H2) { + throw new IllegalArgumentException("Invalid protocolPreference: " + protocolPreference); } + this.protocolPreference = protocolPreference; } - /** - * Sets the client to retry when the remote end-point responds with one of the specified {@code statuses}. - * - * Uses a backoff that computes a delay using one of supported functions, such as - * {@code exponential(long, long, double)}, {@code fibonacci(long, long)}, {@code fixed(long)} and - * {@code random(long, long)} chaining with {@code withJitter(double, double)} and {@code withMaxAttempts(int)} from - * the {@code backoff} string that conforms to the following format: - *
      - *
    • {@code exponential=[initialDelayMillis:maxDelayMillis:multiplier]} is for - * {@code exponential(long, long, double)} (multiplier will be 2.0 if it's omitted)
    • - *
    • {@code fibonacci=[initialDelayMillis:maxDelayMillis]} is for {@code fibonacci(long, long)}
    • - *
    • {@code fixed=[delayMillis]} is for {@code fixed(long)}
    • - *
    • {@code random=[minDelayMillis:maxDelayMillis]} is for {@code random(long, long)}
    • - *
    • {@code jitter=[minJitterRate:maxJitterRate]} is for {@code withJitter(double, double)} (if only one jitter - * value is specified, it will be used for {@code withJitter(double)}
    • - *
    • {@code maxAttempts=[maxAttempts]} is for {@code withMaxAttempts(int)}
    • - *
    - * The order of options does not matter, and the {@code backoff} needs at least one option. If you don't specify the - * base option exponential backoff will be used. If you only specify a base option, jitter and maxAttempts will be - * set by default values. For example: - *
      - *
    • {@code exponential=200:10000:2.0,jitter=0.2} (default)
    • - *
    • {@code exponential=200:10000,jitter=0.2,maxAttempts=50} (multiplier omitted)
    • - *
    • {@code fibonacci=200:10000,jitter=0.2,maxAttempts=50}
    • - *
    • {@code fixed=100,jitter=-0.5:0.2,maxAttempts=10} (fixed backoff with jitter variation)
    • - *
    • {@code random=200:1000} (jitter and maxAttempts will be set by default values)
    • - *
    - * - * @param backoff the specification used to create a retry backoff - * @param statuses the list of HTTP statuses on which to retry - */ - public void retry(String backoff, HttpStatus... statuses) { - final Backoff retryBackoff = Backoff.of(backoff); - final RetryRule retryRule - = RetryRule.builder().onStatus(statuses).onUnprocessed().thenBackoff(retryBackoff); - retry = RetryingClient.newDecorator(retryRule); - } - - /** - * Sets the client to log requests and responses to the specified {@code logger}. This method explicitly specifies - * various log levels. The log level correspond to a value of {@link LogLevel} and must use one of the following - * values: {@code ["OFF", "TRACE", "DEBUG", "INFO", "WARN", "ERROR"]} - * - * @param logger the logger name (of {@link org.slf4j.Logger}) to log requests/responses to - * @param requestLevel the log level to use for logging requests, default {@code "DEBUG"} - * @param responseLevel the log level to use for logging responses, default {@code "DEBUG"} - * @param failureResponseLevel the log level to use for logging error responses, default {@code "WARN"} - */ - public void logging(String logger, String requestLevel, String responseLevel, - String failureResponseLevel) { - this.logging = LoggingClient.builder() - .logger(LoggerFactory.getLogger(logger)) - .requestLogLevel(LogLevel.valueOf(requestLevel)) - .successfulResponseLogLevel(LogLevel.valueOf(responseLevel)) - .failureResponseLogLevel(LogLevel.valueOf(failureResponseLevel)) - .newDecorator(); + public void setRetry(Function retry) { + this.retry = retry; } - /** - * Sets the client to log requests and responses to the specified {@code logger} using default log levels. - * - * @param logger the logger name (of {@link org.slf4j.Logger}) to log requests/responses to - */ - public void logging(String logger) { - this.logging = LoggingClient.builder() - .logger(LoggerFactory.getLogger(logger)) - .requestLogLevel(LogLevel.DEBUG) - .successfulResponseLogLevel(LogLevel.DEBUG) - .failureResponseLogLevel(LogLevel.WARN) - .newDecorator(); - } - - /** - * Sets the client to log requests and responses to a default logger using default log levels. - */ - public void logging() { - this.logging = LoggingClient.builder() - .requestLogLevel(LogLevel.DEBUG) - .successfulResponseLogLevel(LogLevel.DEBUG) - .failureResponseLogLevel(LogLevel.WARN) - .newDecorator(); + public void setLogging(Function logging) { + this.logging = logging; } - ArmeriaWebClientBuilder builder() { - return new ArmeriaWebClientBuilder(clientOptions, clientFactory, protocolPreference, - retry, logging); + ArmeriaWebClientBuilder createClientBuilder() { + return new ArmeriaWebClientBuilder(clientOptions, clientFactory, protocolPreference, retry, logging); } } diff --git a/scribejava-httpclient-armeria/src/test/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClientTest.java b/scribejava-httpclient-armeria/src/test/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClientTest.java index 728668e8f..efad5cd25 100644 --- a/scribejava-httpclient-armeria/src/test/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClientTest.java +++ b/scribejava-httpclient-armeria/src/test/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClientTest.java @@ -3,7 +3,12 @@ import com.github.scribejava.core.AbstractClientTest; import com.github.scribejava.core.httpclient.HttpClient; import com.linecorp.armeria.client.ClientFactory; +import com.linecorp.armeria.client.logging.LoggingClient; +import com.linecorp.armeria.client.retry.Backoff; +import com.linecorp.armeria.client.retry.RetryRule; +import com.linecorp.armeria.client.retry.RetryingClient; import com.linecorp.armeria.common.HttpStatus; +import com.linecorp.armeria.common.logging.LogLevel; import io.netty.channel.EventLoopGroup; import io.netty.resolver.AbstractAddressResolver; import io.netty.resolver.AddressResolver; @@ -15,42 +20,54 @@ import java.util.Collections; import java.util.List; import java.util.function.Function; +import org.slf4j.LoggerFactory; public class ArmeriaHttpClientTest extends AbstractClientTest { @Override protected HttpClient createNewClient() { // simulate DNS resolution for a mock address ("kubernetes.docker.internal") - final Function> addressResolverGroupFactory = eventLoopGroup -> new MockAddressResolverGroup(); + final Function> addressRGF + = eventLoopGroup -> new MockAddressResolverGroup(); // No-Op DNS resolver to avoid resolution issues in the unit test - final ClientFactory clientFactory - = ClientFactory.builder().addressResolverGroupFactory(addressResolverGroupFactory).build(); + final ClientFactory clientFactory = ClientFactory.builder().addressResolverGroupFactory(addressRGF).build(); final ArmeriaHttpClientConfig config = new ArmeriaHttpClientConfig(null, clientFactory); + // enable client-side HTTP tracing - config.logging("HTTP_TRACE", "INFO", "INFO", "WARN"); + config.setLogging(LoggingClient.builder() + .logger(LoggerFactory.getLogger("HTTP_TRACE")) + .requestLogLevel(LogLevel.valueOf("INFO")) + .successfulResponseLogLevel(LogLevel.valueOf("INFO")) + .failureResponseLogLevel(LogLevel.valueOf("WARN")) + .newDecorator()); + // enable request retry - config.retry("exponential=200:10000,jitter=0.2,maxAttempts=5", HttpStatus.SERVICE_UNAVAILABLE); + final Backoff retryBackoff = Backoff.of("exponential=200:10000,jitter=0.2,maxAttempts=5"); + final RetryRule retryRule = RetryRule.builder() + .onStatus(HttpStatus.SERVICE_UNAVAILABLE) + .onUnprocessed() + .thenBackoff(retryBackoff); + config.setRetry(RetryingClient.newDecorator(retryRule)); + return new ArmeriaHttpClient(config); } - //------------------------------------------------------------------------------------------------ // No-Op DNS resolver to avoid resolution issues in the unit test - static class MockAddressResolverGroup extends AddressResolverGroup { - - private MockAddressResolverGroup() { - } + private static class MockAddressResolverGroup extends AddressResolverGroup { + @Override protected AddressResolver newResolver(EventExecutor executor) { return new MockAddressResolver(executor); } } - static class MockAddressResolver extends AbstractAddressResolver { + private static class MockAddressResolver extends AbstractAddressResolver { private MockAddressResolver(EventExecutor executor) { super(executor); } + @Override protected boolean doIsResolved(InetSocketAddress address) { return !address.isUnresolved(); } @@ -59,14 +76,14 @@ private InetSocketAddress resolveToLoopback(InetSocketAddress unresolvedAddress) return new InetSocketAddress(InetAddress.getLoopbackAddress(), unresolvedAddress.getPort()); } + @Override protected void doResolve(InetSocketAddress unresolvedAddress, Promise promise) { promise.setSuccess(resolveToLoopback(unresolvedAddress)); } + @Override protected void doResolveAll(InetSocketAddress unresolvedAddress, Promise> promise) { promise.setSuccess(Collections.singletonList(resolveToLoopback(unresolvedAddress))); } } - - //------------------------------------------------------------------------------------------------ } From e8f8d381fac24662f501a71afc30a7f80aca267b Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 4 Aug 2020 11:11:42 +0300 Subject: [PATCH 787/882] upgrade jackson-databind 2.11.1 -> 2.11.2 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index f067fb747..1f6ca8fb5 100644 --- a/pom.xml +++ b/pom.xml @@ -54,7 +54,7 @@ com.fasterxml.jackson.core jackson-databind - 2.11.1 + 2.11.2 junit From a05870b733a2b6643902aa30d6cd67e6d9c6e861 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 4 Aug 2020 16:30:52 +0300 Subject: [PATCH 788/882] prepare v7.0.0 --- README.md | 4 ++-- changelog | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index aa3645dc5..7e1a5ea34 100644 --- a/README.md +++ b/README.md @@ -133,7 +133,7 @@ You can pull ScribeJava from the central maven repository, just add these to you com.github.scribejava scribejava-apis - 6.9.0 + 7.0.0 ``` @@ -142,7 +142,7 @@ And in case you need just core classes (that's it, without any external API (FB, com.github.scribejava scribejava-core - 6.9.0 + 7.0.0 ``` diff --git a/changelog b/changelog index 2a5d5269a..034418596 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,4 @@ -[SNAPSHOT] +[7.0.0] * Add Polar API (https://www.polar.com/) (thanks to https://github.com/vidi42) * make Response accept resources to autoclose and autoclose it (thanks to https://github.com/drei01) * fix url encoding in POST payload (it's needed for 'application/x-www-form-urlencoded' Content-Type) From 8213f57f1990fd92ec2ed938f1521be267c3cab4 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 4 Aug 2020 16:34:05 +0300 Subject: [PATCH 789/882] [maven-release-plugin] prepare release scribejava-7.0.0 --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-armeria/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 8 files changed, 9 insertions(+), 9 deletions(-) diff --git a/pom.xml b/pom.xml index 1f6ca8fb5..2b530e6fb 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 6.9.1-SNAPSHOT + 7.0.0 ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -35,7 +35,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - HEAD + scribejava-7.0.0 diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index aac24aa20..cf4df4880 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.9.1-SNAPSHOT + 7.0.0 ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 0fc1965c9..935506e28 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.9.1-SNAPSHOT + 7.0.0 ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index fa0ce5dc5..f10367ed3 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.9.1-SNAPSHOT + 7.0.0 ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index 7a0933f34..9c10db72f 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.9.1-SNAPSHOT + 7.0.0 ../pom.xml diff --git a/scribejava-httpclient-armeria/pom.xml b/scribejava-httpclient-armeria/pom.xml index b67e66998..210d1de14 100644 --- a/scribejava-httpclient-armeria/pom.xml +++ b/scribejava-httpclient-armeria/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.9.1-SNAPSHOT + 7.0.0 ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index 1bf4a7f51..758f39a47 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.9.1-SNAPSHOT + 7.0.0 ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index cf5ac1998..ce422e508 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.9.1-SNAPSHOT + 7.0.0 ../pom.xml From 6cb1e3ea1b7c3c35a364366e6a74fea00d431903 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 4 Aug 2020 16:34:13 +0300 Subject: [PATCH 790/882] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-armeria/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 8 files changed, 9 insertions(+), 9 deletions(-) diff --git a/pom.xml b/pom.xml index 2b530e6fb..98a48b4cc 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 7.0.0 + 7.0.1-SNAPSHOT ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -35,7 +35,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - scribejava-7.0.0 + HEAD diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index cf4df4880..1509132ab 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.0.0 + 7.0.1-SNAPSHOT ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 935506e28..52856291f 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.0.0 + 7.0.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index f10367ed3..b604bff4d 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.0.0 + 7.0.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index 9c10db72f..19151acab 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.0.0 + 7.0.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-armeria/pom.xml b/scribejava-httpclient-armeria/pom.xml index 210d1de14..5a78abf22 100644 --- a/scribejava-httpclient-armeria/pom.xml +++ b/scribejava-httpclient-armeria/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.0.0 + 7.0.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index 758f39a47..e1956ea11 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.0.0 + 7.0.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index ce422e508..4a10618f8 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.0.0 + 7.0.1-SNAPSHOT ../pom.xml From 88e598801840ebefd8408a1a8a9a667e9af08982 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 4 Aug 2020 16:42:26 +0300 Subject: [PATCH 791/882] prepare new snapshot --- changelog | 2 ++ .../core/httpclient/jdk/JDKHttpClient.java | 12 ---------- .../multipart/MultipartPayload.java | 23 ------------------- 3 files changed, 2 insertions(+), 35 deletions(-) diff --git a/changelog b/changelog index 034418596..056b84c73 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,5 @@ +[SNAPSHOT] + [7.0.0] * Add Polar API (https://www.polar.com/) (thanks to https://github.com/vidi42) * make Response accept resources to autoclose and autoclose it (thanks to https://github.com/drei01) diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java index a18617633..f386049c7 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java @@ -215,18 +215,6 @@ private static void addBody(HttpURLConnection connection, MultipartPayload multi } } - /** - * @param multipartPayload multipartPayload - * @return ByteArrayOutputStream - * @throws IOException - * @deprecated use {@link com.github.scribejava.core.httpclient.multipart.MultipartUtils#getPayload( - * com.github.scribejava.core.httpclient.multipart.MultipartPayload) } - */ - @Deprecated - static ByteArrayOutputStream getPayload(MultipartPayload multipartPayload) throws IOException { - return MultipartUtils.getPayload(multipartPayload); - } - private static OutputStream prepareConnectionForBodyAndGetOutputStream(HttpURLConnection connection, int contentLength) throws IOException { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/MultipartPayload.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/MultipartPayload.java index 26efa66fe..e68bb6465 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/MultipartPayload.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/MultipartPayload.java @@ -67,34 +67,11 @@ private static Map composeHeaders(String subtype, String boundar return headersOut; } - /** - * - * @param boundary boundary - * @deprecated use - * {@link com.github.scribejava.core.httpclient.multipart.MultipartUtils#checkBoundarySyntax(java.lang.String)} - */ - @Deprecated - static void checkBoundarySyntax(String boundary) { - MultipartUtils.checkBoundarySyntax(boundary); - } - private static String parseOrGenerateBoundary(Map headers) { final String parsedBoundary = MultipartUtils.parseBoundaryFromHeader(headers.get(HttpClient.CONTENT_TYPE)); return parsedBoundary == null ? MultipartUtils.generateDefaultBoundary() : parsedBoundary; } - /** - * - * @param contentTypeHeader contentTypeHeader - * @return String - * @deprecated use - * {@link com.github.scribejava.core.httpclient.multipart.MultipartUtils#parseBoundaryFromHeader(java.lang.String)} - */ - @Deprecated - static String parseBoundaryFromHeader(String contentTypeHeader) { - return MultipartUtils.parseBoundaryFromHeader(contentTypeHeader); - } - public void addFileBodyPart(byte[] fileContent) { addBodyPart(new FileByteArrayBodyPartPayload(fileContent)); } From 6007a9e712c4b7219d86a4e945835fdcd875943d Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Wed, 12 Aug 2020 16:53:07 +0300 Subject: [PATCH 792/882] update armeria and okhttp --- pom.xml | 2 +- .../src/main/java/com/github/scribejava/apis/AWeberApi.java | 1 + .../src/main/java/com/github/scribejava/apis/EtsyApi.java | 1 + .../src/main/java/com/github/scribejava/apis/FlickrApi.java | 1 + .../github/scribejava/apis/polar/PolarOAuth2AccessToken.java | 2 ++ .../src/main/java/com/github/scribejava/core/java8/Base64.java | 2 ++ scribejava-httpclient-armeria/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 8 files changed, 10 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 98a48b4cc..1c48b2b1e 100644 --- a/pom.xml +++ b/pom.xml @@ -65,7 +65,7 @@ com.squareup.okhttp3 mockwebserver - 4.8.0 + 4.8.1 test diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/AWeberApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/AWeberApi.java index 84e5117df..9ad3a185a 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/AWeberApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/AWeberApi.java @@ -12,6 +12,7 @@ protected AWeberApi() { } private static class InstanceHolder { + private static final AWeberApi INSTANCE = new AWeberApi(); } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/EtsyApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/EtsyApi.java index 289f83588..00ca72918 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/EtsyApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/EtsyApi.java @@ -23,6 +23,7 @@ private EtsyApi(String... scopes) { } private static class InstanceHolder { + private static final EtsyApi INSTANCE = new EtsyApi(); } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/FlickrApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/FlickrApi.java index 33432f2bb..eedb89890 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/FlickrApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/FlickrApi.java @@ -29,6 +29,7 @@ protected FlickrApi(FlickrPerm perm) { } private static class InstanceHolder { + private static final FlickrApi INSTANCE = new FlickrApi(); } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/polar/PolarOAuth2AccessToken.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/polar/PolarOAuth2AccessToken.java index d9ea04035..99710728f 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/polar/PolarOAuth2AccessToken.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/polar/PolarOAuth2AccessToken.java @@ -6,6 +6,8 @@ public class PolarOAuth2AccessToken extends OAuth2AccessToken { + private static final long serialVersionUID = 1L; + private final String userId; public PolarOAuth2AccessToken(String accessToken, String tokenType, Integer expiresIn, String refreshToken, diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/java8/Base64.java b/scribejava-core/src/main/java/com/github/scribejava/core/java8/Base64.java index 9e855a617..221e7f24d 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/java8/Base64.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/java8/Base64.java @@ -448,6 +448,7 @@ public static class Decoder { * */ private static final int[] FROM_BASE_64 = new int[256]; + static { Arrays.fill(FROM_BASE_64, -1); for (int i = 0; i < Encoder.TO_BASE_64.length; i++) { @@ -460,6 +461,7 @@ public static class Decoder { * Lookup table for decoding "URL and Filename safe Base64 Alphabet" as specified in Table2 of the RFC 4648. */ private static final int[] FROM_BASE_64_URL = new int[256]; + static { Arrays.fill(FROM_BASE_64_URL, -1); for (int i = 0; i < Encoder.TO_BASE_64_URL.length; i++) { diff --git a/scribejava-httpclient-armeria/pom.xml b/scribejava-httpclient-armeria/pom.xml index 5a78abf22..e1df25813 100644 --- a/scribejava-httpclient-armeria/pom.xml +++ b/scribejava-httpclient-armeria/pom.xml @@ -23,7 +23,7 @@ com.linecorp.armeria armeria - 0.99.8 + 0.99.9 com.github.scribejava diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 4a10618f8..a364d2fcc 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -23,7 +23,7 @@ com.squareup.okhttp3 okhttp - 4.8.0 + 4.8.1 com.github.scribejava From 923d7e4a483914b75380fb3a52765408331f7a3f Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Wed, 26 Aug 2020 16:38:19 +0300 Subject: [PATCH 793/882] add Proxy support (via config's option) to internal JDKHttpClient (thanks to https://github.com/bjournaud) --- changelog | 1 + .../scribejava/core/httpclient/jdk/JDKHttpClient.java | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/changelog b/changelog index 056b84c73..1b58bb61a 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,5 @@ [SNAPSHOT] + * add Proxy support (via config's option) to internal JDKHttpClient (thanks to https://github.com/bjournaud) [7.0.0] * Add Polar API (https://www.polar.com/) (thanks to https://github.com/vidi42) diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java index eb15bec1e..b500ba997 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java @@ -114,11 +114,12 @@ public Response execute(String userAgent, Map headers, Verb http private Response doExecute(String userAgent, Map headers, Verb httpVerb, String completeUrl, BodyType bodyType, Object bodyContents) throws IOException { + final URL url = new URL(completeUrl); final HttpURLConnection connection; if (config.getProxy() == null) { - connection = (HttpURLConnection) new URL(completeUrl).openConnection(); - }else { - connection = (HttpURLConnection) new URL(completeUrl).openConnection(config.getProxy()); + connection = (HttpURLConnection) url.openConnection(); + } else { + connection = (HttpURLConnection) url.openConnection(config.getProxy()); } connection.setInstanceFollowRedirects(config.isFollowRedirects()); connection.setRequestMethod(httpVerb.name()); From cbad67e169e634fa8250aa184a45b59d1fe4c805 Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Thu, 27 Aug 2020 12:16:06 +0300 Subject: [PATCH 794/882] add chaining methods for HTTP clients configs --- .../httpclient/jdk/JDKHttpClientConfig.java | 34 +++++++++++++++++-- .../armeria/ArmeriaHttpClientConfig.java | 17 ++++++++++ .../armeria/ArmeriaHttpClientTest.java | 3 +- .../httpclient/ning/NingHttpClientConfig.java | 5 +++ 4 files changed, 55 insertions(+), 4 deletions(-) diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClientConfig.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClientConfig.java index baa431b83..3b322b0af 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClientConfig.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClientConfig.java @@ -28,6 +28,11 @@ public void setConnectTimeout(Integer connectTimeout) { this.connectTimeout = connectTimeout; } + public JDKHttpClientConfig withConnectTimeout(Integer connectTimeout) { + this.connectTimeout = connectTimeout; + return this; + } + public Integer getReadTimeout() { return readTimeout; } @@ -36,8 +41,9 @@ public void setReadTimeout(Integer readTimeout) { this.readTimeout = readTimeout; } - public boolean isFollowRedirects() { - return followRedirects; + public JDKHttpClientConfig withReadTimeout(Integer readTimeout) { + this.readTimeout = readTimeout; + return this; } public void setProxy(Proxy proxy) { @@ -48,6 +54,15 @@ public Proxy getProxy() { return proxy; } + public JDKHttpClientConfig withProxy(Proxy proxy) { + this.proxy = proxy; + return this; + } + + public boolean isFollowRedirects() { + return followRedirects; + } + /** * Sets whether the underlying Http Connection follows redirects or not. * @@ -60,4 +75,19 @@ public Proxy getProxy() { public void setFollowRedirects(boolean followRedirects) { this.followRedirects = followRedirects; } + + /** + * Sets whether the underlying Http Connection follows redirects or not. + * + * Defaults to true (follow redirects) + * + * @see http://docs.oracle.com/javase/6/docs/api/java/net/HttpURLConnection.html#setInstanceFollowRedirects(boolean) + * @param followRedirects boolean + * @return this for chaining methods invocations + */ + public JDKHttpClientConfig withFollowRedirects(boolean followRedirects) { + this.followRedirects = followRedirects; + return this; + } } diff --git a/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClientConfig.java b/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClientConfig.java index 19fc27f48..f9d494f52 100644 --- a/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClientConfig.java +++ b/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClientConfig.java @@ -33,6 +33,8 @@ public ArmeriaHttpClientConfig(ClientOptions clientOptions, ClientFactory client /** * Creates new {@link HttpClientConfig} using default settings. + * + * @return new {@link HttpClientConfig} using default settings. */ @Override public HttpClientConfig createDefaultConfig() { @@ -62,14 +64,29 @@ public void setProtocolPreference(SessionProtocol protocolPreference) { this.protocolPreference = protocolPreference; } + public ArmeriaHttpClientConfig withProtocolPreference(SessionProtocol protocolPreference) { + setProtocolPreference(protocolPreference); + return this; + } + public void setRetry(Function retry) { this.retry = retry; } + public ArmeriaHttpClientConfig withRetry(Function retry) { + this.retry = retry; + return this; + } + public void setLogging(Function logging) { this.logging = logging; } + public ArmeriaHttpClientConfig withLogging(Function logging) { + this.logging = logging; + return this; + } + ArmeriaWebClientBuilder createClientBuilder() { return new ArmeriaWebClientBuilder(clientOptions, clientFactory, protocolPreference, retry, logging); } diff --git a/scribejava-httpclient-armeria/src/test/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClientTest.java b/scribejava-httpclient-armeria/src/test/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClientTest.java index efad5cd25..c94d6b369 100644 --- a/scribejava-httpclient-armeria/src/test/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClientTest.java +++ b/scribejava-httpclient-armeria/src/test/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClientTest.java @@ -47,9 +47,8 @@ protected HttpClient createNewClient() { .onStatus(HttpStatus.SERVICE_UNAVAILABLE) .onUnprocessed() .thenBackoff(retryBackoff); - config.setRetry(RetryingClient.newDecorator(retryRule)); - return new ArmeriaHttpClient(config); + return new ArmeriaHttpClient(config.withRetry(RetryingClient.newDecorator(retryRule))); } // No-Op DNS resolver to avoid resolution issues in the unit test diff --git a/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/NingHttpClientConfig.java b/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/NingHttpClientConfig.java index 9eb5d83c2..6e8842cc7 100644 --- a/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/NingHttpClientConfig.java +++ b/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/NingHttpClientConfig.java @@ -20,6 +20,11 @@ public void setNingAsyncHttpProviderClassName(String ningAsyncHttpProviderClassN this.ningAsyncHttpProviderClassName = ningAsyncHttpProviderClassName; } + public NingHttpClientConfig withNingAsyncHttpProviderClassName(String ningAsyncHttpProviderClassName) { + this.ningAsyncHttpProviderClassName = ningAsyncHttpProviderClassName; + return this; + } + public AsyncHttpClientConfig getConfig() { return config; } From 440371e35cdbcdb192cb34ccd2438416ae83451b Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Thu, 27 Aug 2020 12:55:28 +0300 Subject: [PATCH 795/882] fix typo (change "Verfier" to "Verifier") (thanks to https://github.com/afkbrb) --- changelog | 1 + 1 file changed, 1 insertion(+) diff --git a/changelog b/changelog index 1b58bb61a..7c3fcde1b 100644 --- a/changelog +++ b/changelog @@ -1,5 +1,6 @@ [SNAPSHOT] * add Proxy support (via config's option) to internal JDKHttpClient (thanks to https://github.com/bjournaud) + * fix typo (change "Verfier" to "Verifier") (thanks to https://github.com/afkbrb) [7.0.0] * Add Polar API (https://www.polar.com/) (thanks to https://github.com/vidi42) From 02efd0069de74ad5b318ee5c561e2a9aba615448 Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Thu, 27 Aug 2020 13:05:53 +0300 Subject: [PATCH 796/882] update armeria to 1.0.0 --- pom.xml | 2 +- scribejava-httpclient-armeria/pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 1c48b2b1e..1f250ab9f 100644 --- a/pom.xml +++ b/pom.xml @@ -167,7 +167,7 @@ org.apache.maven.plugins maven-resources-plugin - 3.1.0 + 3.2.0 UTF-8 diff --git a/scribejava-httpclient-armeria/pom.xml b/scribejava-httpclient-armeria/pom.xml index e1df25813..6e42a82a8 100644 --- a/scribejava-httpclient-armeria/pom.xml +++ b/scribejava-httpclient-armeria/pom.xml @@ -23,7 +23,7 @@ com.linecorp.armeria armeria - 0.99.9 + 1.0.0 com.github.scribejava From 3f7a5cba7ba47c9275ed71a63a9da8f42bd91499 Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Fri, 28 Aug 2020 18:04:01 +0300 Subject: [PATCH 797/882] fix a bit Multipart CRLF handling and improve readability of unit tests --- .../httpclient/multipart/MultipartUtils.java | 11 +- .../multipart/MultipartUtilsTest.java | 125 ++++++++---------- 2 files changed, 59 insertions(+), 77 deletions(-) diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/MultipartUtils.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/MultipartUtils.java index dc42d4d60..4a01817f1 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/MultipartUtils.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/MultipartUtils.java @@ -43,12 +43,12 @@ public static ByteArrayOutputStream getPayload(MultipartPayload multipartPayload final String preamble = multipartPayload.getPreamble(); if (preamble != null) { - os.write(preamble.getBytes()); + os.write((preamble + "\r\n").getBytes()); } final List bodyParts = multipartPayload.getBodyParts(); if (!bodyParts.isEmpty()) { final String boundary = multipartPayload.getBoundary(); - final byte[] startBoundary = ("\r\n--" + boundary + "\r\n").getBytes(); + final byte[] startBoundary = ("--" + boundary + "\r\n").getBytes(); for (BodyPartPayload bodyPart : bodyParts) { os.write(startBoundary); @@ -60,20 +60,21 @@ public static ByteArrayOutputStream getPayload(MultipartPayload multipartPayload } } + os.write("\r\n".getBytes()); if (bodyPart instanceof MultipartPayload) { getPayload((MultipartPayload) bodyPart).writeTo(os); } else if (bodyPart instanceof ByteArrayBodyPartPayload) { - os.write("\r\n".getBytes()); os.write(((ByteArrayBodyPartPayload) bodyPart).getPayload()); } else { throw new AssertionError(bodyPart.getClass()); } + os.write("\r\n".getBytes()); //CRLF for the next (starting or closing) boundary } - os.write(("\r\n--" + boundary + "--\r\n").getBytes()); + os.write(("--" + boundary + "--").getBytes()); final String epilogue = multipartPayload.getEpilogue(); if (epilogue != null) { - os.write((epilogue + "\r\n").getBytes()); + os.write(("\r\n" + epilogue).getBytes()); } } diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/httpclient/multipart/MultipartUtilsTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/httpclient/multipart/MultipartUtilsTest.java index cac5def30..6d26743ba 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/httpclient/multipart/MultipartUtilsTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/httpclient/multipart/MultipartUtilsTest.java @@ -18,16 +18,18 @@ public class MultipartUtilsTest { public void testEmptyMultipartPayload() throws IOException { final MultipartPayload mP = new MultipartPayload(); - final StringBuilder sb = new StringBuilder(); + final StringBuilder headersString = new StringBuilder(); for (Map.Entry header : mP.getHeaders().entrySet()) { - sb.append(header.getKey()) + headersString.append(header.getKey()) .append(": ") .append(header.getValue()) .append("\r\n"); } - sb.append("\r\n").append(MultipartUtils.getPayload(mP).toString()); - assertEquals("Content-Type: multipart/form-data; boundary=\"" + mP.getBoundary() + "\"\r\n\r\n", sb.toString()); + assertEquals("Content-Type: multipart/form-data; boundary=\"" + mP.getBoundary() + "\"\r\n", + headersString.toString()); + + assertEquals("", MultipartUtils.getPayload(mP).toString()); } @Test @@ -51,36 +53,34 @@ public void testSimpleMultipartPayload() throws IOException { mP.setEpilogue("This is the epilogue. It is also to be ignored."); - final StringBuilder sb = new StringBuilder(); + final StringBuilder headersString = new StringBuilder(); for (Map.Entry header : mP.getHeaders().entrySet()) { - sb.append(header.getKey()) + headersString.append(header.getKey()) .append(": ") .append(header.getValue()) .append("\r\n"); } - sb.append("\r\n").append(MultipartUtils.getPayload(mP).toString()); + assertEquals("X-Header: X-Value\r\n" + "Content-Disposition: Content-Disposition-Value\r\n" - + "Content-Type: multipart/mixed; boundary=\"simple boundary\"\r\n" - + "\r\n" - + "This is the preamble. It is to be ignored, though it\n" + + "Content-Type: multipart/mixed; boundary=\"simple boundary\"\r\n", + headersString.toString()); + + assertEquals("This is the preamble. It is to be ignored, though it\n" + "is a handy place for composition agents to include an\n" + "explanatory note to non-MIME conformant readers." - + "\r\n" - + "--simple boundary\r\n" + + "\r\n--simple boundary\r\n" + "\r\n" + "This is implicitly typed plain US-ASCII text.\n" + "It does NOT end with a linebreak." - + "\r\n" - + "--simple boundary\r\n" + + "\r\n--simple boundary\r\n" + "Content-Type: text/plain; charset=us-ascii\r\n" + "\r\n" + "This is explicitly typed plain US-ASCII text.\n" + "It DOES end with a linebreak.\n" - + "\r\n" - + "--simple boundary--\r\n" - + "This is the epilogue. It is also to be ignored.\r\n", - sb.toString()); + + "\r\n--simple boundary--" + + "\r\nThis is the epilogue. It is also to be ignored.", + MultipartUtils.getPayload(mP).toString()); } @Test @@ -92,39 +92,33 @@ public void testCRLFMultipartPayload() throws IOException { mP.addBodyPart("It does end with a \\r\\n linebreak.\r\n".getBytes()); mP.addBodyPart("the last one".getBytes()); - final StringBuilder sb = new StringBuilder(); + final StringBuilder headersString = new StringBuilder(); for (Map.Entry header : mP.getHeaders().entrySet()) { - sb.append(header.getKey()) + headersString.append(header.getKey()) .append(": ") .append(header.getValue()) .append("\r\n"); } - sb.append("\r\n").append(MultipartUtils.getPayload(mP).toString()); - assertEquals("Content-Type: multipart/form-data; boundary=\"simple-boundary\"\r\n" - + "\r\n" - + "\r\n" - + "--simple-boundary\r\n" + + assertEquals("Content-Type: multipart/form-data; boundary=\"simple-boundary\"\r\n", headersString.toString()); + + assertEquals("--simple-boundary\r\n" + "\r\n" + "It does NOT end with a linebreak." - + "\r\n" - + "--simple-boundary\r\n" + + "\r\n--simple-boundary\r\n" + "\r\n" + "It does end with a \\r linebreak.\r" - + "\r\n" - + "--simple-boundary\r\n" + + "\r\n--simple-boundary\r\n" + "\r\n" + "It does end with a \\n linebreak.\n" - + "\r\n" - + "--simple-boundary\r\n" + + "\r\n--simple-boundary\r\n" + "\r\n" + "It does end with a \\r\\n linebreak.\r\n" - + "\r\n" - + "--simple-boundary\r\n" + + "\r\n--simple-boundary\r\n" + "\r\n" + "the last one" - + "\r\n" - + "--simple-boundary--\r\n", - sb.toString()); + + "\r\n--simple-boundary--", + MultipartUtils.getPayload(mP).toString()); } @Test @@ -132,27 +126,24 @@ public void testFileByteArrayBodyPartPayloadMultipartPayload() throws IOExceptio final MultipartPayload mP = new MultipartPayload("testFileByteArrayBodyPartPayloadMultipartPayload boundary"); mP.addBodyPart(new FileByteArrayBodyPartPayload("fileContent".getBytes(), "name", "filename.ext")); - final StringBuilder sb = new StringBuilder(); + final StringBuilder headersString = new StringBuilder(); for (Map.Entry header : mP.getHeaders().entrySet()) { - sb.append(header.getKey()) + headersString.append(header.getKey()) .append(": ") .append(header.getValue()) .append("\r\n"); } - sb.append("\r\n").append(MultipartUtils.getPayload(mP).toString()); assertEquals("Content-Type: multipart/form-data; " - + "boundary=\"testFileByteArrayBodyPartPayloadMultipartPayload boundary\"\r\n" - + "\r\n" - + "\r\n" - + "--testFileByteArrayBodyPartPayloadMultipartPayload boundary\r\n" + + "boundary=\"testFileByteArrayBodyPartPayloadMultipartPayload boundary\"\r\n", + headersString.toString()); + + assertEquals("--testFileByteArrayBodyPartPayloadMultipartPayload boundary\r\n" + "Content-Disposition: form-data; name=\"name\"; filename=\"filename.ext\"\r\n" + "\r\n" + "fileContent" - + "\r\n" - + "--testFileByteArrayBodyPartPayloadMultipartPayload boundary--\r\n", - sb.toString() - ); + + "\r\n--testFileByteArrayBodyPartPayloadMultipartPayload boundary--", + MultipartUtils.getPayload(mP).toString()); } @Test @@ -201,54 +192,46 @@ public void testComplexMultipartPayload() throws IOException { + "\n" + "... Additional text in ISO-8859-1 goes here ...\n").getBytes(), "message/rfc822"); - final StringBuilder sb = new StringBuilder(); + final StringBuilder headersString = new StringBuilder(); for (Map.Entry header : mP.getHeaders().entrySet()) { - sb.append(header.getKey()) + headersString.append(header.getKey()) .append(": ") .append(header.getValue()) .append("\r\n"); } - sb.append("\r\n").append(MultipartUtils.getPayload(mP).toString()); - assertEquals("Content-Type: multipart/mixed; boundary=\"unique-boundary-1\"\r\n" - + "\r\n" - + "This is the preamble area of a multipart message.\n" + assertEquals("Content-Type: multipart/mixed; boundary=\"unique-boundary-1\"\r\n", headersString.toString()); + + assertEquals("This is the preamble area of a multipart message.\n" + "Mail readers that understand multipart format\n" + "should ignore this preamble.\n" + "\n" + "If you are reading this text, you might want to\n" + "consider changing to a mail reader that understands\n" + "how to properly display multipart messages.\n" - + "\r\n" - + "--unique-boundary-1\r\n" + + "\r\n--unique-boundary-1\r\n" + "\r\n" + "... Some text appears here ..." - + "\r\n" - + "--unique-boundary-1\r\n" + + "\r\n--unique-boundary-1\r\n" + "Content-Type: text/plain; charset=US-ASCII\r\n" + "\r\n" + "This could have been part of the previous part, but\n" + "illustrates explicit versus implicit typing of body\n" + "parts.\n" - + "\r\n" - + "--unique-boundary-1\r\n" + + "\r\n--unique-boundary-1\r\n" + "Content-Type: multipart/parallel; boundary=\"unique-boundary-2\"\r\n" - + "\r\n" - + "--unique-boundary-2\r\n" + + "\r\n--unique-boundary-2\r\n" + "Content-Type: audio/basic\r\n" + "Content-Transfer-Encoding: base64\r\n" + "\r\n" + "... base64-encoded 8000 Hz single-channel\n" + " mu-law-format audio data goes here ..." - + "\r\n" - + "--unique-boundary-2\r\n" + + "\r\n--unique-boundary-2\r\n" + "Content-Type: image/jpeg\r\n" + "Content-Transfer-Encoding: base64\r\n" + "\r\n" + "... base64-encoded image data goes here ..." - + "\r\n" - + "--unique-boundary-2--\r\n" - + "\r\n" - + "--unique-boundary-1\r\n" + + "\r\n--unique-boundary-2--" + + "\r\n--unique-boundary-1\r\n" + "Content-Type: text/enriched\r\n" + "\r\n" + "This is enriched.\n" @@ -256,8 +239,7 @@ public void testComplexMultipartPayload() throws IOException { + "\n" + "Isn't it\n" + "cool?\n" - + "\r\n" - + "--unique-boundary-1\r\n" + + "\r\n--unique-boundary-1\r\n" + "Content-Type: message/rfc822\r\n" + "\r\n" + "From: (mailbox in US-ASCII)\n" @@ -267,9 +249,8 @@ public void testComplexMultipartPayload() throws IOException { + "Content-Transfer-Encoding: Quoted-printable\n" + "\n" + "... Additional text in ISO-8859-1 goes here ...\n" - + "\r\n" - + "--unique-boundary-1--\r\n", - sb.toString()); + + "\r\n--unique-boundary-1--", + MultipartUtils.getPayload(mP).toString()); } @Test From 5ac44578dcd0d8e113a0b36e045404b2600c2ac9 Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Tue, 8 Sep 2020 16:04:30 +0300 Subject: [PATCH 798/882] fix Multipart support in JDKHttpClient (thanks to https://github.com/eos1d3) --- changelog | 1 + 1 file changed, 1 insertion(+) diff --git a/changelog b/changelog index 7c3fcde1b..27e0079c8 100644 --- a/changelog +++ b/changelog @@ -1,6 +1,7 @@ [SNAPSHOT] * add Proxy support (via config's option) to internal JDKHttpClient (thanks to https://github.com/bjournaud) * fix typo (change "Verfier" to "Verifier") (thanks to https://github.com/afkbrb) + * fix Multipart support in JDKHttpClient (thanks to https://github.com/eos1d3) [7.0.0] * Add Polar API (https://www.polar.com/) (thanks to https://github.com/vidi42) From 92b86e4702d0be7bdc4189ee4fff788c313b3c54 Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Tue, 8 Sep 2020 16:14:07 +0300 Subject: [PATCH 799/882] update deps --- pom.xml | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/pom.xml b/pom.xml index 1f250ab9f..9a740ad66 100644 --- a/pom.xml +++ b/pom.xml @@ -104,7 +104,7 @@ com.puppycrawl.tools checkstyle - 8.35 + 8.36 @@ -126,11 +126,6 @@ maven-clean-plugin 3.1.0
    - - org.apache.maven.plugins - maven-enforcer-plugin - 1.4.1 - org.apache.maven.plugins maven-install-plugin @@ -274,7 +269,7 @@ 7 - 6.26.0 + 6.27.0 From 6388969b8d07021b90486f2d25ce8e23816913a1 Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Tue, 8 Sep 2020 17:47:54 +0300 Subject: [PATCH 800/882] prepare v7.1.0 --- README.md | 4 ++-- changelog | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 7e1a5ea34..c239f14ba 100644 --- a/README.md +++ b/README.md @@ -133,7 +133,7 @@ You can pull ScribeJava from the central maven repository, just add these to you com.github.scribejava scribejava-apis - 7.0.0 + 7.1.0 ``` @@ -142,7 +142,7 @@ And in case you need just core classes (that's it, without any external API (FB, com.github.scribejava scribejava-core - 7.0.0 + 7.1.0 ``` diff --git a/changelog b/changelog index 27e0079c8..5b618aa08 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,4 @@ -[SNAPSHOT] +[7.1.0] * add Proxy support (via config's option) to internal JDKHttpClient (thanks to https://github.com/bjournaud) * fix typo (change "Verfier" to "Verifier") (thanks to https://github.com/afkbrb) * fix Multipart support in JDKHttpClient (thanks to https://github.com/eos1d3) From 3374f30eaa93c904849dbd62886d63da9b1e1b58 Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Tue, 8 Sep 2020 18:04:11 +0300 Subject: [PATCH 801/882] [maven-release-plugin] prepare release scribejava-7.1.0 --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-armeria/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 8 files changed, 9 insertions(+), 9 deletions(-) diff --git a/pom.xml b/pom.xml index 9a740ad66..cae7d8ad2 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 7.0.1-SNAPSHOT + 7.1.0 ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -35,7 +35,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - HEAD + scribejava-7.1.0 diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 1509132ab..974e02f65 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.0.1-SNAPSHOT + 7.1.0 ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 52856291f..aa935d40c 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.0.1-SNAPSHOT + 7.1.0 ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index b604bff4d..f67ca4090 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.0.1-SNAPSHOT + 7.1.0 ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index 19151acab..a63371ad3 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.0.1-SNAPSHOT + 7.1.0 ../pom.xml diff --git a/scribejava-httpclient-armeria/pom.xml b/scribejava-httpclient-armeria/pom.xml index 6e42a82a8..1ea52a7d9 100644 --- a/scribejava-httpclient-armeria/pom.xml +++ b/scribejava-httpclient-armeria/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.0.1-SNAPSHOT + 7.1.0 ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index e1956ea11..7ec8fcdfa 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.0.1-SNAPSHOT + 7.1.0 ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index a364d2fcc..245389246 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.0.1-SNAPSHOT + 7.1.0 ../pom.xml From 785d997806ace82c67b7f711d9f36e60132d5d42 Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Tue, 8 Sep 2020 18:04:35 +0300 Subject: [PATCH 802/882] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-armeria/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 8 files changed, 9 insertions(+), 9 deletions(-) diff --git a/pom.xml b/pom.xml index cae7d8ad2..d803884d8 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 7.1.0 + 7.1.1-SNAPSHOT ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -35,7 +35,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - scribejava-7.1.0 + HEAD diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 974e02f65..5ab03a194 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.1.0 + 7.1.1-SNAPSHOT ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index aa935d40c..108ed7484 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.1.0 + 7.1.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index f67ca4090..5501543c0 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.1.0 + 7.1.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index a63371ad3..96ff1daf6 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.1.0 + 7.1.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-armeria/pom.xml b/scribejava-httpclient-armeria/pom.xml index 1ea52a7d9..e11eae975 100644 --- a/scribejava-httpclient-armeria/pom.xml +++ b/scribejava-httpclient-armeria/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.1.0 + 7.1.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index 7ec8fcdfa..3a10d359b 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.1.0 + 7.1.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 245389246..3b087ff4e 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.1.0 + 7.1.1-SNAPSHOT ../pom.xml From fc54cd7d81e89a15bdee3cc822978300d3ddc60f Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Tue, 8 Sep 2020 18:53:14 +0300 Subject: [PATCH 803/882] Revert "[maven-release-plugin] prepare for next development iteration" This reverts commit 785d997806ace82c67b7f711d9f36e60132d5d42. --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-armeria/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 8 files changed, 9 insertions(+), 9 deletions(-) diff --git a/pom.xml b/pom.xml index d803884d8..cae7d8ad2 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 7.1.1-SNAPSHOT + 7.1.0 ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -35,7 +35,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - HEAD + scribejava-7.1.0 diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 5ab03a194..974e02f65 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.1.1-SNAPSHOT + 7.1.0 ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 108ed7484..aa935d40c 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.1.1-SNAPSHOT + 7.1.0 ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 5501543c0..f67ca4090 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.1.1-SNAPSHOT + 7.1.0 ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index 96ff1daf6..a63371ad3 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.1.1-SNAPSHOT + 7.1.0 ../pom.xml diff --git a/scribejava-httpclient-armeria/pom.xml b/scribejava-httpclient-armeria/pom.xml index e11eae975..1ea52a7d9 100644 --- a/scribejava-httpclient-armeria/pom.xml +++ b/scribejava-httpclient-armeria/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.1.1-SNAPSHOT + 7.1.0 ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index 3a10d359b..7ec8fcdfa 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.1.1-SNAPSHOT + 7.1.0 ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 3b087ff4e..245389246 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.1.1-SNAPSHOT + 7.1.0 ../pom.xml From d908a3a8bf4fc3c60fd6dd7b03849ec30163d5ab Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Tue, 8 Sep 2020 18:53:20 +0300 Subject: [PATCH 804/882] Revert "[maven-release-plugin] prepare release scribejava-7.1.0" This reverts commit 3374f30eaa93c904849dbd62886d63da9b1e1b58. --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-armeria/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 8 files changed, 9 insertions(+), 9 deletions(-) diff --git a/pom.xml b/pom.xml index cae7d8ad2..9a740ad66 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 7.1.0 + 7.0.1-SNAPSHOT ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -35,7 +35,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - scribejava-7.1.0 + HEAD diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 974e02f65..1509132ab 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.1.0 + 7.0.1-SNAPSHOT ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index aa935d40c..52856291f 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.1.0 + 7.0.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index f67ca4090..b604bff4d 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.1.0 + 7.0.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index a63371ad3..19151acab 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.1.0 + 7.0.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-armeria/pom.xml b/scribejava-httpclient-armeria/pom.xml index 1ea52a7d9..6e42a82a8 100644 --- a/scribejava-httpclient-armeria/pom.xml +++ b/scribejava-httpclient-armeria/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.1.0 + 7.0.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index 7ec8fcdfa..e1956ea11 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.1.0 + 7.0.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 245389246..a364d2fcc 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.1.0 + 7.0.1-SNAPSHOT ../pom.xml From c55dd67d16205582e7a74e7394df3b821cc38375 Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Tue, 8 Sep 2020 18:53:25 +0300 Subject: [PATCH 805/882] Revert "prepare v7.1.0" This reverts commit 6388969b8d07021b90486f2d25ce8e23816913a1. --- README.md | 4 ++-- changelog | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index c239f14ba..7e1a5ea34 100644 --- a/README.md +++ b/README.md @@ -133,7 +133,7 @@ You can pull ScribeJava from the central maven repository, just add these to you com.github.scribejava scribejava-apis - 7.1.0 + 7.0.0 ``` @@ -142,7 +142,7 @@ And in case you need just core classes (that's it, without any external API (FB, com.github.scribejava scribejava-core - 7.1.0 + 7.0.0 ``` diff --git a/changelog b/changelog index 5b618aa08..27e0079c8 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,4 @@ -[7.1.0] +[SNAPSHOT] * add Proxy support (via config's option) to internal JDKHttpClient (thanks to https://github.com/bjournaud) * fix typo (change "Verfier" to "Verifier") (thanks to https://github.com/afkbrb) * fix Multipart support in JDKHttpClient (thanks to https://github.com/eos1d3) From 8aae9804c8d6bb28ca1ddb6b03a207aff2aa7651 Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Tue, 8 Sep 2020 18:54:55 +0300 Subject: [PATCH 806/882] prepare v7.1.1 --- README.md | 4 ++-- changelog | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 7e1a5ea34..e6426bc00 100644 --- a/README.md +++ b/README.md @@ -133,7 +133,7 @@ You can pull ScribeJava from the central maven repository, just add these to you com.github.scribejava scribejava-apis - 7.0.0 + 7.1.1 ``` @@ -142,7 +142,7 @@ And in case you need just core classes (that's it, without any external API (FB, com.github.scribejava scribejava-core - 7.0.0 + 7.1.1 ``` diff --git a/changelog b/changelog index 27e0079c8..926f3af56 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,4 @@ -[SNAPSHOT] +[7.1.1] * add Proxy support (via config's option) to internal JDKHttpClient (thanks to https://github.com/bjournaud) * fix typo (change "Verfier" to "Verifier") (thanks to https://github.com/afkbrb) * fix Multipart support in JDKHttpClient (thanks to https://github.com/eos1d3) From 101c1039fe70d0092a8a995d92ba99a7e461e4ef Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Tue, 8 Sep 2020 18:56:07 +0300 Subject: [PATCH 807/882] [maven-release-plugin] prepare release scribejava-7.1.1 --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-armeria/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 8 files changed, 9 insertions(+), 9 deletions(-) diff --git a/pom.xml b/pom.xml index 9a740ad66..d9d0d1802 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 7.0.1-SNAPSHOT + 7.1.1 ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -35,7 +35,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - HEAD + scribejava-7.1.1 diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 1509132ab..891373d8e 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.0.1-SNAPSHOT + 7.1.1 ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 52856291f..47ee01211 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.0.1-SNAPSHOT + 7.1.1 ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index b604bff4d..e6fd0e903 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.0.1-SNAPSHOT + 7.1.1 ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index 19151acab..f5a0e5537 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.0.1-SNAPSHOT + 7.1.1 ../pom.xml diff --git a/scribejava-httpclient-armeria/pom.xml b/scribejava-httpclient-armeria/pom.xml index 6e42a82a8..968e883b4 100644 --- a/scribejava-httpclient-armeria/pom.xml +++ b/scribejava-httpclient-armeria/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.0.1-SNAPSHOT + 7.1.1 ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index e1956ea11..0f857c963 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.0.1-SNAPSHOT + 7.1.1 ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index a364d2fcc..3449005e8 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.0.1-SNAPSHOT + 7.1.1 ../pom.xml From 7d128d31a4dfe3bee7e3edd5732cf4fa19d0c89e Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Tue, 8 Sep 2020 18:56:15 +0300 Subject: [PATCH 808/882] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-armeria/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 8 files changed, 9 insertions(+), 9 deletions(-) diff --git a/pom.xml b/pom.xml index d9d0d1802..69c7cb46d 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 7.1.1 + 7.1.2-SNAPSHOT ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -35,7 +35,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - scribejava-7.1.1 + HEAD diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 891373d8e..24dbcaa1e 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.1.1 + 7.1.2-SNAPSHOT ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 47ee01211..79a016cf2 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.1.1 + 7.1.2-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index e6fd0e903..6b6d8578b 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.1.1 + 7.1.2-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index f5a0e5537..393c4fc83 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.1.1 + 7.1.2-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-armeria/pom.xml b/scribejava-httpclient-armeria/pom.xml index 968e883b4..9c7325e58 100644 --- a/scribejava-httpclient-armeria/pom.xml +++ b/scribejava-httpclient-armeria/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.1.1 + 7.1.2-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index 0f857c963..cf992b25a 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.1.1 + 7.1.2-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 3449005e8..0ad7a7540 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.1.1 + 7.1.2-SNAPSHOT ../pom.xml From 01aa0b2526d50f3ee1caa8c13404ac951aa67661 Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Thu, 17 Sep 2020 19:50:32 +0300 Subject: [PATCH 809/882] * add Kakao API (https://kakao.com/) (thanks to https://github.com/v0o0v) --- README.md | 1 + changelog | 3 +++ .../src/main/java/com/github/scribejava/apis/HHApi.java | 1 + .../src/main/java/com/github/scribejava/apis/KakaoApi.java | 1 + .../java/com/github/scribejava/apis/examples/KakaoExample.java | 2 +- 5 files changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e6426bc00..f3d1c4149 100644 --- a/README.md +++ b/README.md @@ -77,6 +77,7 @@ ScribeJava support out-of-box several HTTP clients: * HiOrg-Server (https://www.hiorg-server.de/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HiOrgServerExample.java) * Imgur (http://imgur.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ImgurExample.java) * Kaixin 开心网 (http://www.kaixin001.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Kaixin20Example.java) +* Kakao (https://kakao.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/KakaoExample.java) * Keycloak (https://www.keycloak.org/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/KeycloakExample.java) * LinkedIn (https://www.linkedin.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedIn20Example.java), [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java), [example with custom scopes](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java) * Mail.Ru (https://mail.ru/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java), [example with Async Ning HTTP Client](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java) diff --git a/changelog b/changelog index 926f3af56..a30a391ea 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,6 @@ +[SNAPSHOT] + * add Kakao API (https://kakao.com/) (thanks to https://github.com/v0o0v) + [7.1.1] * add Proxy support (via config's option) to internal JDKHttpClient (thanks to https://github.com/bjournaud) * fix typo (change "Verfier" to "Verifier") (thanks to https://github.com/afkbrb) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/HHApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/HHApi.java index bd1224fe6..61476eaef 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/HHApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/HHApi.java @@ -10,6 +10,7 @@ protected HHApi() { } private static class InstanceHolder { + private static final HHApi INSTANCE = new HHApi(); } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/KakaoApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/KakaoApi.java index 948705496..6587fe32f 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/KakaoApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/KakaoApi.java @@ -10,6 +10,7 @@ protected KakaoApi() { } private static class InstanceHolder { + private static final KakaoApi INSTANCE = new KakaoApi(); } diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/KakaoExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/KakaoExample.java index 89b7b4f1d..643182ea8 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/KakaoExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/KakaoExample.java @@ -22,7 +22,7 @@ private KakaoExample() { @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { - // Replace these with your client id and secret + // Replace this with your client id final String clientId = "your client id"; final OAuth20Service service = new ServiceBuilder(clientId) From acb09724868ad29da24ab9ce210418c606922428 Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Tue, 22 Sep 2020 16:48:20 +0300 Subject: [PATCH 810/882] support chunks in JDKHttpClient's Multipart (thanks to https://github.com/eos1d3) --- changelog | 1 + .../httpclient/multipart/BodyPartPayload.java | 6 +- .../multipart/ByteArrayBodyPartPayload.java | 36 +++- .../FileByteArrayBodyPartPayload.java | 25 +++ .../multipart/MultipartPayload.java | 65 +++++++ .../httpclient/multipart/MultipartUtils.java | 3 +- .../scribejava/core/model/OAuthRequest.java | 171 +++++++++++++++++- .../multipart/MultipartUtilsTest.java | 35 ++-- 8 files changed, 316 insertions(+), 26 deletions(-) diff --git a/changelog b/changelog index a30a391ea..9f29b77ef 100644 --- a/changelog +++ b/changelog @@ -1,5 +1,6 @@ [SNAPSHOT] * add Kakao API (https://kakao.com/) (thanks to https://github.com/v0o0v) + * support chunks in JDKHttpClient's Multipart (thanks to https://github.com/eos1d3) [7.1.1] * add Proxy support (via config's option) to internal JDKHttpClient (thanks to https://github.com/bjournaud) diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/BodyPartPayload.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/BodyPartPayload.java index ee426176b..ddd6e9cb2 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/BodyPartPayload.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/BodyPartPayload.java @@ -13,7 +13,7 @@ public BodyPartPayload() { } public BodyPartPayload(String contentType) { - this(contentType == null ? null : Collections.singletonMap(HttpClient.CONTENT_TYPE, contentType)); + this(convertContentTypeToHeaders(contentType)); } public BodyPartPayload(Map headers) { @@ -23,4 +23,8 @@ public BodyPartPayload(Map headers) { public Map getHeaders() { return headers; } + + protected static Map convertContentTypeToHeaders(String contentType) { + return contentType == null ? null : Collections.singletonMap(HttpClient.CONTENT_TYPE, contentType); + } } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/ByteArrayBodyPartPayload.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/ByteArrayBodyPartPayload.java index 7fd0d6d98..c706d7481 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/ByteArrayBodyPartPayload.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/ByteArrayBodyPartPayload.java @@ -5,22 +5,46 @@ public class ByteArrayBodyPartPayload extends BodyPartPayload { private final byte[] payload; + private final int off; + private final int len; - public ByteArrayBodyPartPayload(byte[] payload) { + public ByteArrayBodyPartPayload(byte[] payload, int off, int len, Map headers) { + super(headers); this.payload = payload; + this.off = off; + this.len = len; + } + + public ByteArrayBodyPartPayload(byte[] payload, Map headers) { + this(payload, 0, payload.length, headers); } public ByteArrayBodyPartPayload(byte[] payload, String contentType) { - super(contentType); - this.payload = payload; + this(payload, convertContentTypeToHeaders(contentType)); } - public ByteArrayBodyPartPayload(byte[] payload, Map headers) { - super(headers); - this.payload = payload; + public ByteArrayBodyPartPayload(byte[] payload, int off, int len, String contentType) { + this(payload, off, len, convertContentTypeToHeaders(contentType)); + } + + public ByteArrayBodyPartPayload(byte[] payload) { + this(payload, (Map) null); + } + + public ByteArrayBodyPartPayload(byte[] payload, int off, int len) { + this(payload, off, len, (Map) null); } public byte[] getPayload() { return payload; } + + public int getOff() { + return off; + } + + public int getLen() { + return len; + } + } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/FileByteArrayBodyPartPayload.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/FileByteArrayBodyPartPayload.java index 524977819..41b3e72bf 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/FileByteArrayBodyPartPayload.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/FileByteArrayBodyPartPayload.java @@ -11,26 +11,51 @@ public FileByteArrayBodyPartPayload(byte[] payload) { this(payload, null); } + public FileByteArrayBodyPartPayload(byte[] payload, int off, int len) { + this(payload, off, len, null); + } + public FileByteArrayBodyPartPayload(byte[] payload, String name) { this(payload, name, null); } + public FileByteArrayBodyPartPayload(byte[] payload, int off, int len, String name) { + this(payload, off, len, name, null); + } + public FileByteArrayBodyPartPayload(byte[] payload, String name, String filename) { this(null, payload, name, filename); } + public FileByteArrayBodyPartPayload(byte[] payload, int off, int len, String name, String filename) { + this(null, payload, off, len, name, filename); + } + public FileByteArrayBodyPartPayload(String contentType, byte[] payload) { this(contentType, payload, null); } + public FileByteArrayBodyPartPayload(String contentType, byte[] payload, int off, int len) { + this(contentType, payload, off, len, null); + } + public FileByteArrayBodyPartPayload(String contentType, byte[] payload, String name) { this(contentType, payload, name, null); } + public FileByteArrayBodyPartPayload(String contentType, byte[] payload, int off, int len, String name) { + this(contentType, payload, off, len, name, null); + } + public FileByteArrayBodyPartPayload(String contentType, byte[] payload, String name, String filename) { super(payload, composeHeaders(contentType, name, filename)); } + public FileByteArrayBodyPartPayload(String contentType, byte[] payload, int off, int len, String name, + String filename) { + super(payload, off, len, composeHeaders(contentType, name, filename)); + } + private static Map composeHeaders(String contentType, String name, String filename) { String contentDispositionHeader = "form-data"; diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/MultipartPayload.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/MultipartPayload.java index e68bb6465..6f7a5b093 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/MultipartPayload.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/MultipartPayload.java @@ -72,26 +72,71 @@ private static String parseOrGenerateBoundary(Map headers) { return parsedBoundary == null ? MultipartUtils.generateDefaultBoundary() : parsedBoundary; } + /** + * + * @param fileContent fileContent + * @deprecated use {@link #addBodyPart(com.github.scribejava.core.httpclient.multipart.BodyPartPayload)} + */ + @Deprecated public void addFileBodyPart(byte[] fileContent) { addBodyPart(new FileByteArrayBodyPartPayload(fileContent)); } + /** + * + * @param fileContent fileContent + * @param name name + * @deprecated use {@link #addBodyPart(com.github.scribejava.core.httpclient.multipart.BodyPartPayload)} + */ + @Deprecated public void addFileBodyPart(byte[] fileContent, String name) { addBodyPart(new FileByteArrayBodyPartPayload(fileContent, name)); } + /** + * + * @param fileContent fileContent + * @param name name + * @param filename filename + * @deprecated use {@link #addBodyPart(com.github.scribejava.core.httpclient.multipart.BodyPartPayload)} + */ + @Deprecated public void addFileBodyPart(byte[] fileContent, String name, String filename) { addBodyPart(new FileByteArrayBodyPartPayload(fileContent, name, filename)); } + /** + * + * @param contentType contentType + * @param fileContent fileContent + * @deprecated use {@link #addBodyPart(com.github.scribejava.core.httpclient.multipart.BodyPartPayload)} + */ + @Deprecated public void addFileBodyPart(String contentType, byte[] fileContent) { addBodyPart(new FileByteArrayBodyPartPayload(contentType, fileContent)); } + /** + * + * @param contentType contentType + * @param fileContent fileContent + * @param name name + * @deprecated use {@link #addBodyPart(com.github.scribejava.core.httpclient.multipart.BodyPartPayload)} + */ + @Deprecated public void addFileBodyPart(String contentType, byte[] fileContent, String name) { addBodyPart(new FileByteArrayBodyPartPayload(contentType, fileContent, name)); } + /** + * + * @param contentType contentType + * @param fileContent fileContent + * @param name name + * @param filename filename + * @deprecated use {@link #addBodyPart(com.github.scribejava.core.httpclient.multipart.BodyPartPayload)} + */ + @Deprecated public void addFileBodyPart(String contentType, byte[] fileContent, String name, String filename) { addBodyPart(new FileByteArrayBodyPartPayload(contentType, fileContent, name, filename)); } @@ -108,14 +153,34 @@ public void addBodyPart(MultipartPayload multipartPayload) { bodyParts.add(multipartPayload); } + /** + * + * @param bodyPartPayload bodyPartPayload + * @deprecated use {@link #addBodyPart(com.github.scribejava.core.httpclient.multipart.BodyPartPayload)} + */ + @Deprecated public void addBodyPart(byte[] bodyPartPayload) { addBodyPart(new ByteArrayBodyPartPayload(bodyPartPayload)); } + /** + * + * @param bodyPartPayload bodyPartPayload + * @param contentType contentType + * @deprecated use {@link #addBodyPart(com.github.scribejava.core.httpclient.multipart.BodyPartPayload)} + */ + @Deprecated public void addBodyPart(byte[] bodyPartPayload, String contentType) { addBodyPart(new ByteArrayBodyPartPayload(bodyPartPayload, contentType)); } + /** + * + * @param bodyPartPayload bodyPartPayload + * @param headers headers + * @deprecated use {@link #addBodyPart(com.github.scribejava.core.httpclient.multipart.BodyPartPayload)} + */ + @Deprecated public void addBodyPart(byte[] bodyPartPayload, Map headers) { addBodyPart(new ByteArrayBodyPartPayload(bodyPartPayload, headers)); } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/MultipartUtils.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/MultipartUtils.java index 4a01817f1..bdbeaf542 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/MultipartUtils.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/MultipartUtils.java @@ -64,7 +64,8 @@ public static ByteArrayOutputStream getPayload(MultipartPayload multipartPayload if (bodyPart instanceof MultipartPayload) { getPayload((MultipartPayload) bodyPart).writeTo(os); } else if (bodyPart instanceof ByteArrayBodyPartPayload) { - os.write(((ByteArrayBodyPartPayload) bodyPart).getPayload()); + final ByteArrayBodyPartPayload byteArrayBodyPart = (ByteArrayBodyPartPayload) bodyPart; + os.write(byteArrayBodyPart.getPayload(), byteArrayBodyPart.getOff(), byteArrayBodyPart.getLen()); } else { throw new AssertionError(bodyPart.getClass()); } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequest.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequest.java index 79c66695f..2194545fa 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequest.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequest.java @@ -1,6 +1,7 @@ package com.github.scribejava.core.model; import com.github.scribejava.core.exceptions.OAuthException; +import com.github.scribejava.core.httpclient.multipart.BodyPartPayload; import com.github.scribejava.core.httpclient.multipart.FileByteArrayBodyPartPayload; import com.github.scribejava.core.httpclient.multipart.MultipartPayload; import java.io.File; @@ -160,100 +161,268 @@ public void initMultipartPayload(String subtype, String boundary, Map headers) { initMultipartPayload(); addByteArrayBodyPartPayloadInMultipartPayload(bodyPartPayload, headers); } + /** + * + * @param bodyPartPayload bodyPartPayload + * @deprecated use + * {@link #addBodyPartPayloadInMultipartPayload(com.github.scribejava.core.httpclient.multipart.BodyPartPayload)} + */ + @Deprecated public void addByteArrayBodyPartPayloadInMultipartPayload(byte[] bodyPartPayload) { multipartPayload.addBodyPart(bodyPartPayload); } + /** + * + * @param bodyPartPayload bodyPartPayload + * @param contentType contentType + * @deprecated use + * {@link #addBodyPartPayloadInMultipartPayload(com.github.scribejava.core.httpclient.multipart.BodyPartPayload)} + */ + @Deprecated public void addByteArrayBodyPartPayloadInMultipartPayload(byte[] bodyPartPayload, String contentType) { multipartPayload.addBodyPart(bodyPartPayload, contentType); } + /** + * + * @param bodyPartPayload bodyPartPayload + * @param headers headers + * @deprecated use + * {@link #addBodyPartPayloadInMultipartPayload(com.github.scribejava.core.httpclient.multipart.BodyPartPayload)} + */ + @Deprecated public void addByteArrayBodyPartPayloadInMultipartPayload(byte[] bodyPartPayload, Map headers) { multipartPayload.addBodyPart(bodyPartPayload, headers); } + /** + * + * @param fileContent fileContent + * @deprecated use + * {@link #setBodyPartPayloadInMultipartPayload(com.github.scribejava.core.httpclient.multipart.BodyPartPayload)} + */ + @Deprecated public void setFileByteArrayBodyPartPayloadInMultipartPayload(byte[] fileContent) { initMultipartPayload(); addFileByteArrayBodyPartPayloadInMultipartPayload(fileContent); } + /** + * + * @param contentType contentType + * @param fileContent fileContent + * @deprecated use + * {@link #setBodyPartPayloadInMultipartPayload(com.github.scribejava.core.httpclient.multipart.BodyPartPayload)} + */ + @Deprecated public void setFileByteArrayBodyPartPayloadInMultipartPayload(String contentType, byte[] fileContent) { initMultipartPayload(); addFileByteArrayBodyPartPayloadInMultipartPayload(contentType, fileContent); } + /** + * + * @param fileContent fileContent + * @param name name + * @deprecated use + * {@link #setBodyPartPayloadInMultipartPayload(com.github.scribejava.core.httpclient.multipart.BodyPartPayload)} + */ + @Deprecated public void setFileByteArrayBodyPartPayloadInMultipartPayload(byte[] fileContent, String name) { initMultipartPayload(); addFileByteArrayBodyPartPayloadInMultipartPayload(fileContent, name); } + /** + * + * @param contentType contentType + * @param fileContent fileContent + * @param name name + * @deprecated use + * {@link #setBodyPartPayloadInMultipartPayload(com.github.scribejava.core.httpclient.multipart.BodyPartPayload)} + */ + @Deprecated public void setFileByteArrayBodyPartPayloadInMultipartPayload(String contentType, byte[] fileContent, String name) { initMultipartPayload(); addFileByteArrayBodyPartPayloadInMultipartPayload(contentType, fileContent, name); } + /** + * + * @param fileContent fileContent + * @param name name + * @param filename filename + * @deprecated use + * {@link #setBodyPartPayloadInMultipartPayload(com.github.scribejava.core.httpclient.multipart.BodyPartPayload)} + */ + @Deprecated public void setFileByteArrayBodyPartPayloadInMultipartPayload(byte[] fileContent, String name, String filename) { initMultipartPayload(); addFileByteArrayBodyPartPayloadInMultipartPayload(fileContent, name, filename); } + /** + * + * @param contentType contentType + * @param fileContent fileContent + * @param name name + * @param filename filename + * @deprecated use + * {@link #setBodyPartPayloadInMultipartPayload(com.github.scribejava.core.httpclient.multipart.BodyPartPayload)} + */ + @Deprecated public void setFileByteArrayBodyPartPayloadInMultipartPayload(String contentType, byte[] fileContent, String name, String filename) { initMultipartPayload(); addFileByteArrayBodyPartPayloadInMultipartPayload(contentType, fileContent, name, filename); } + /** + * + * @param fileByteArrayBodyPartPayload fileByteArrayBodyPartPayload + * @deprecated use + * {@link #setBodyPartPayloadInMultipartPayload(com.github.scribejava.core.httpclient.multipart.BodyPartPayload)} + */ + @Deprecated public void setFileByteArrayBodyPartPayloadInMultipartPayload( FileByteArrayBodyPartPayload fileByteArrayBodyPartPayload) { + setBodyPartPayloadInMultipartPayload(fileByteArrayBodyPartPayload); + } + + public void setBodyPartPayloadInMultipartPayload(BodyPartPayload bodyPartPayload) { initMultipartPayload(); - addFileByteArrayBodyPartPayloadInMultipartPayload(fileByteArrayBodyPartPayload); + addBodyPartPayloadInMultipartPayload(bodyPartPayload); } + /** + * + * @param fileContent fileContent + * @deprecated use + * {@link #addBodyPartPayloadInMultipartPayload(com.github.scribejava.core.httpclient.multipart.BodyPartPayload)} + */ + @Deprecated public void addFileByteArrayBodyPartPayloadInMultipartPayload(byte[] fileContent) { multipartPayload.addFileBodyPart(fileContent); } + /** + * + * @param contentType contentType + * @param fileContent fileContent + * @deprecated use + * {@link #addBodyPartPayloadInMultipartPayload(com.github.scribejava.core.httpclient.multipart.BodyPartPayload)} + */ + @Deprecated public void addFileByteArrayBodyPartPayloadInMultipartPayload(String contentType, byte[] fileContent) { multipartPayload.addFileBodyPart(contentType, fileContent); } + /** + * + * @param fileContent fileContent + * @param name name + * @deprecated use + * {@link #addBodyPartPayloadInMultipartPayload(com.github.scribejava.core.httpclient.multipart.BodyPartPayload)} + */ + @Deprecated public void addFileByteArrayBodyPartPayloadInMultipartPayload(byte[] fileContent, String name) { multipartPayload.addFileBodyPart(fileContent, name); } + /** + * @param contentType contentType + * @param fileContent fileContent + * @param name name + * @deprecated use + * {@link #addBodyPartPayloadInMultipartPayload(com.github.scribejava.core.httpclient.multipart.BodyPartPayload)} + */ + @Deprecated public void addFileByteArrayBodyPartPayloadInMultipartPayload(String contentType, byte[] fileContent, String name) { multipartPayload.addFileBodyPart(contentType, fileContent, name); } + /** + * + * @param fileContent fileContent + * @param name name + * @param filename filename + * @deprecated use + * {@link #addBodyPartPayloadInMultipartPayload(com.github.scribejava.core.httpclient.multipart.BodyPartPayload)} + */ + @Deprecated public void addFileByteArrayBodyPartPayloadInMultipartPayload(byte[] fileContent, String name, String filename) { multipartPayload.addFileBodyPart(fileContent, name, filename); } + /** + * @param contentType contentType + * @param fileContent fileContent + * @param name name + * @param filename filename + * @deprecated use + * {@link #addBodyPartPayloadInMultipartPayload(com.github.scribejava.core.httpclient.multipart.BodyPartPayload)} + */ + @Deprecated public void addFileByteArrayBodyPartPayloadInMultipartPayload(String contentType, byte[] fileContent, String name, String filename) { multipartPayload.addFileBodyPart(contentType, fileContent, name, filename); } + /** + * + * @param fileByteArrayBodyPartPayload fileByteArrayBodyPartPayload + * @deprecated use + * {@link #addBodyPartPayloadInMultipartPayload(com.github.scribejava.core.httpclient.multipart.BodyPartPayload)} + */ + @Deprecated public void addFileByteArrayBodyPartPayloadInMultipartPayload( FileByteArrayBodyPartPayload fileByteArrayBodyPartPayload) { multipartPayload.addBodyPart(fileByteArrayBodyPartPayload); } + public void addBodyPartPayloadInMultipartPayload(BodyPartPayload bodyPartPayload) { + multipartPayload.addBodyPart(bodyPartPayload); + } + /** * Set body payload. This method is used when the HTTP body is not a form-url-encoded string, but another thing. * Like for example XML. Note: The contents are not part of the OAuth signature diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/httpclient/multipart/MultipartUtilsTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/httpclient/multipart/MultipartUtilsTest.java index 6d26743ba..c726dd9a7 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/httpclient/multipart/MultipartUtilsTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/httpclient/multipart/MultipartUtilsTest.java @@ -42,8 +42,8 @@ public void testSimpleMultipartPayload() throws IOException { + "is a handy place for composition agents to include an\n" + "explanatory note to non-MIME conformant readers."); - mP.addBodyPart(("This is implicitly typed plain US-ASCII text.\n" - + "It does NOT end with a linebreak.").getBytes()); + mP.addBodyPart(new ByteArrayBodyPartPayload(("This is implicitly typed plain US-ASCII text.\n" + + "It does NOT end with a linebreak.").getBytes())); final ByteArrayBodyPartPayload bP = new ByteArrayBodyPartPayload( ("This is explicitly typed plain US-ASCII text.\n" @@ -86,11 +86,11 @@ public void testSimpleMultipartPayload() throws IOException { @Test public void testCRLFMultipartPayload() throws IOException { final MultipartPayload mP = new MultipartPayload("simple-boundary"); - mP.addBodyPart("It does NOT end with a linebreak.".getBytes()); - mP.addBodyPart("It does end with a \\r linebreak.\r".getBytes()); - mP.addBodyPart("It does end with a \\n linebreak.\n".getBytes()); - mP.addBodyPart("It does end with a \\r\\n linebreak.\r\n".getBytes()); - mP.addBodyPart("the last one".getBytes()); + mP.addBodyPart(new ByteArrayBodyPartPayload("It does NOT end with a linebreak.".getBytes())); + mP.addBodyPart(new ByteArrayBodyPartPayload("It does end with a \\r linebreak.\r".getBytes())); + mP.addBodyPart(new ByteArrayBodyPartPayload("It does end with a \\n linebreak.\n".getBytes())); + mP.addBodyPart(new ByteArrayBodyPartPayload("It does end with a \\r\\n linebreak.\r\n".getBytes())); + mP.addBodyPart(new ByteArrayBodyPartPayload("the last one".getBytes())); final StringBuilder headersString = new StringBuilder(); for (Map.Entry header : mP.getHeaders().entrySet()) { @@ -158,11 +158,11 @@ public void testComplexMultipartPayload() throws IOException { + "consider changing to a mail reader that understands\n" + "how to properly display multipart messages.\n"); - mP.addBodyPart("... Some text appears here ...".getBytes()); + mP.addBodyPart(new ByteArrayBodyPartPayload("... Some text appears here ...".getBytes())); - mP.addBodyPart(("This could have been part of the previous part, but\n" + mP.addBodyPart(new ByteArrayBodyPartPayload(("This could have been part of the previous part, but\n" + "illustrates explicit versus implicit typing of body\n" - + "parts.\n").getBytes(), "text/plain; charset=US-ASCII"); + + "parts.\n").getBytes(), "text/plain; charset=US-ASCII")); final MultipartPayload innerMP = new MultipartPayload("parallel", "unique-boundary-2"); mP.addBodyPart(innerMP); @@ -170,27 +170,28 @@ public void testComplexMultipartPayload() throws IOException { final Map audioHeaders = new LinkedHashMap<>(); audioHeaders.put("Content-Type", "audio/basic"); audioHeaders.put("Content-Transfer-Encoding", "base64"); - innerMP.addBodyPart(("... base64-encoded 8000 Hz single-channel\n" - + " mu-law-format audio data goes here ...").getBytes(), audioHeaders); + innerMP.addBodyPart(new ByteArrayBodyPartPayload(("... base64-encoded 8000 Hz single-channel\n" + + " mu-law-format audio data goes here ...").getBytes(), audioHeaders)); final Map imageHeaders = new LinkedHashMap<>(); imageHeaders.put("Content-Type", "image/jpeg"); imageHeaders.put("Content-Transfer-Encoding", "base64"); - innerMP.addBodyPart("... base64-encoded image data goes here ...".getBytes(), imageHeaders); + innerMP.addBodyPart(new ByteArrayBodyPartPayload("... base64-encoded image data goes here ...".getBytes(), + imageHeaders)); - mP.addBodyPart(("This is enriched.\n" + mP.addBodyPart(new ByteArrayBodyPartPayload(("This is enriched.\n" + "as defined in RFC 1896\n" + "\n" + "Isn't it\n" - + "cool?\n").getBytes(), "text/enriched"); + + "cool?\n").getBytes(), "text/enriched")); - mP.addBodyPart(("From: (mailbox in US-ASCII)\n" + mP.addBodyPart(new ByteArrayBodyPartPayload(("From: (mailbox in US-ASCII)\n" + "To: (address in US-ASCII)\n" + "Subject: (subject in US-ASCII)\n" + "Content-Type: Text/plain; charset=ISO-8859-1\n" + "Content-Transfer-Encoding: Quoted-printable\n" + "\n" - + "... Additional text in ISO-8859-1 goes here ...\n").getBytes(), "message/rfc822"); + + "... Additional text in ISO-8859-1 goes here ...\n").getBytes(), "message/rfc822")); final StringBuilder headersString = new StringBuilder(); for (Map.Entry header : mP.getHeaders().entrySet()) { From 08d6ecb0bc140b4f25bafea489e77ae7bc6f350c Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Mon, 9 Nov 2020 10:17:28 +0300 Subject: [PATCH 811/882] add support for OAuth 2.0 Device Authorization Grant (RFC 8628) (thanks to https://github.com/rebarbora-mckvak) --- README.md | 1 + changelog | 1 + .../github/scribejava/apis/GoogleApi20.java | 19 +- ...oogleDeviceAuthorizationJsonExtractor.java | 25 ++ .../BaseMicrosoftAzureActiveDirectoryApi.java | 5 - ...ogle20DeviceAuthorizationGrantExample.java | 82 ++++++ .../apis/examples/Google20Example.java | 4 +- .../core/builder/api/DefaultApi20.java | 16 +- .../extractors/AbstractJsonExtractor.java | 22 ++ .../DeviceAuthorizationJsonExtractor.java | 64 +++++ .../OAuth2AccessTokenJsonExtractor.java | 18 +- .../core/model/DeviceAuthorization.java | 105 ++++++++ .../scribejava/core/model/DeviceCode.java | 38 --- .../scribejava/core/oauth/OAuth20Service.java | 241 ++++++++++++------ .../scribejava/core/oauth2/OAuth2Error.java | 21 +- 15 files changed, 496 insertions(+), 166 deletions(-) create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/google/GoogleDeviceAuthorizationJsonExtractor.java create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20DeviceAuthorizationGrantExample.java create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/extractors/AbstractJsonExtractor.java create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/extractors/DeviceAuthorizationJsonExtractor.java create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/model/DeviceAuthorization.java delete mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/model/DeviceCode.java diff --git a/README.md b/README.md index f3d1c4149..8c7f3a07a 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,7 @@ ScribeJava support out-of-box several HTTP clients: * [RFC 6750](https://tools.ietf.org/html/rfc6750) The OAuth 2.0 Authorization Framework: Bearer Token Usage * [RFC 7636](https://tools.ietf.org/html/rfc7636) Proof Key for Code Exchange by OAuth Public Clients (PKCE), [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20WithPKCEExample.java) * [RFC 7009](https://tools.ietf.org/html/rfc7009) OAuth 2.0 Token Revocation, [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20RevokeExample.java) + * [RFC 8628](https://tools.ietf.org/html/rfc8628) OAuth 2.0 Device Authorization Grant [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20DeviceAuthorizationGrantExample.java) * [RFC 5849](https://tools.ietf.org/html/rfc5849) The OAuth 1.0 Protocol, [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TwitterExample.java) ### Supports all (50+) major 1.0a and 2.0 OAuth APIs out-of-the-box diff --git a/changelog b/changelog index 9f29b77ef..c029807e2 100644 --- a/changelog +++ b/changelog @@ -1,6 +1,7 @@ [SNAPSHOT] * add Kakao API (https://kakao.com/) (thanks to https://github.com/v0o0v) * support chunks in JDKHttpClient's Multipart (thanks to https://github.com/eos1d3) + * add support for OAuth 2.0 Device Authorization Grant (RFC 8628) (thanks to https://github.com/rebarbora-mckvak) [7.1.1] * add Proxy support (via config's option) to internal JDKHttpClient (thanks to https://github.com/bjournaud) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/GoogleApi20.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/GoogleApi20.java index b4ab24d39..e3de4c746 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/GoogleApi20.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/GoogleApi20.java @@ -1,7 +1,9 @@ package com.github.scribejava.apis; +import com.github.scribejava.apis.google.GoogleDeviceAuthorizationJsonExtractor; import com.github.scribejava.apis.openid.OpenIdJsonTokenExtractor; import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.extractors.DeviceAuthorizationJsonExtractor; import com.github.scribejava.core.extractors.TokenExtractor; import com.github.scribejava.core.model.OAuth2AccessToken; @@ -11,6 +13,7 @@ protected GoogleApi20() { } private static class InstanceHolder { + private static final GoogleApi20 INSTANCE = new GoogleApi20(); } @@ -20,12 +23,12 @@ public static GoogleApi20 instance() { @Override public String getAccessTokenEndpoint() { - return "https://www.googleapis.com/oauth2/v4/token"; + return "https://oauth2.googleapis.com/token"; } @Override protected String getAuthorizationBaseUrl() { - return "https://accounts.google.com/o/oauth2/auth"; + return "https://accounts.google.com/o/oauth2/v2/auth"; } @Override @@ -35,6 +38,16 @@ public TokenExtractor getAccessTokenExtractor() { @Override public String getRevokeTokenEndpoint() { - return "https://accounts.google.com/o/oauth2/revoke"; + return "https://oauth2.googleapis.com/revoke"; + } + + @Override + public String getDeviceAuthorizationEndpoint() { + return "https://oauth2.googleapis.com/device/code"; + } + + @Override + public DeviceAuthorizationJsonExtractor getDeviceAuthorizationExtractor() { + return GoogleDeviceAuthorizationJsonExtractor.instance(); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/google/GoogleDeviceAuthorizationJsonExtractor.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/google/GoogleDeviceAuthorizationJsonExtractor.java new file mode 100644 index 000000000..d3dd77772 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/google/GoogleDeviceAuthorizationJsonExtractor.java @@ -0,0 +1,25 @@ +package com.github.scribejava.apis.google; + +import com.github.scribejava.core.extractors.DeviceAuthorizationJsonExtractor; + +public class GoogleDeviceAuthorizationJsonExtractor extends DeviceAuthorizationJsonExtractor { + + protected GoogleDeviceAuthorizationJsonExtractor() { + } + + private static class InstanceHolder { + + private static final GoogleDeviceAuthorizationJsonExtractor INSTANCE + = new GoogleDeviceAuthorizationJsonExtractor(); + } + + public static GoogleDeviceAuthorizationJsonExtractor instance() { + return GoogleDeviceAuthorizationJsonExtractor.InstanceHolder.INSTANCE; + } + + @Override + protected String getVerificationUriParamName() { + return "verification_url"; + } + +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/microsoftazureactivedirectory/BaseMicrosoftAzureActiveDirectoryApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/microsoftazureactivedirectory/BaseMicrosoftAzureActiveDirectoryApi.java index 8dc5d5616..5e4891164 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/microsoftazureactivedirectory/BaseMicrosoftAzureActiveDirectoryApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/microsoftazureactivedirectory/BaseMicrosoftAzureActiveDirectoryApi.java @@ -30,11 +30,6 @@ protected String getAuthorizationBaseUrl() { return MSFT_LOGIN_URL + tenant + OAUTH_2 + getEndpointVersionPath() + "/authorize"; } - @Override - public String getDeviceAuthorizationUrl() { - return MSFT_LOGIN_URL + tenant + OAUTH_2 + getEndpointVersionPath() + "/devicecode"; - } - @Override public ClientAuthentication getClientAuthentication() { return RequestBodyAuthenticationScheme.instance(); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20DeviceAuthorizationGrantExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20DeviceAuthorizationGrantExample.java new file mode 100644 index 000000000..fc361e13f --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20DeviceAuthorizationGrantExample.java @@ -0,0 +1,82 @@ +package com.github.scribejava.apis.examples; + +import com.github.scribejava.core.builder.ServiceBuilder; +import com.github.scribejava.apis.GoogleApi20; +import com.github.scribejava.core.model.DeviceAuthorization; +import com.github.scribejava.core.model.OAuth2AccessToken; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.oauth.OAuth20Service; +import java.io.IOException; +import java.util.Scanner; +import java.util.concurrent.ExecutionException; + +public class Google20DeviceAuthorizationGrantExample { + + private static final String NETWORK_NAME = "Google"; + private static final String PROTECTED_RESOURCE_URL = "https://www.googleapis.com/oauth2/v3/userinfo"; + + private Google20DeviceAuthorizationGrantExample() { + } + + @SuppressWarnings("PMD.SystemPrintln") + public static void main(String... args) throws IOException, InterruptedException, ExecutionException { + // Replace these with your client id and secret + final String clientId = "your client id"; + final String clientSecret = "your_client_secret"; + + final OAuth20Service service = new ServiceBuilder(clientId) + .debug() + .apiSecret(clientSecret) + .defaultScope("profile") // replace with desired scope + .build(GoogleApi20.instance()); + final Scanner in = new Scanner(System.in, "UTF-8"); + + System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); + System.out.println(); + + System.out.println("Requesting a set of verification codes..."); + + final DeviceAuthorization deviceAuthorization = service.getDeviceAuthorizationCodes(); + System.out.println("Got the Device Authorization Codes!"); + System.out.println(deviceAuthorization); + + System.out.println("Now go and authorize ScribeJava. Visit: " + deviceAuthorization.getVerificationUri() + + " and enter the code: " + deviceAuthorization.getUserCode()); + if (deviceAuthorization.getVerificationUriComplete() != null) { + System.out.println("Or visit " + deviceAuthorization.getVerificationUriComplete()); + } + + System.out.println("Polling for an Access Token..."); + final OAuth2AccessToken accessToken = service.pollAccessTokenDeviceAuthorizationGrant(deviceAuthorization); + + System.out.println("Got the Access Token!"); + System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); + + // Now let's go and ask for a protected resource! + System.out.println("Now we're going to access a protected resource..."); + while (true) { + System.out.println("Paste fieldnames to fetch (leave empty to get profile, 'exit' to stop the example)"); + System.out.print(">>"); + final String query = in.nextLine(); + System.out.println(); + final String requestUrl; + if ("exit".equals(query)) { + break; + } else if (query == null || query.isEmpty()) { + requestUrl = PROTECTED_RESOURCE_URL; + } else { + requestUrl = PROTECTED_RESOURCE_URL + "?fields=" + query; + } + final OAuthRequest request = new OAuthRequest(Verb.GET, requestUrl); + service.signRequest(accessToken, request); + System.out.println(); + try (Response response = service.execute(request)) { + System.out.println(response.getCode()); + System.out.println(response.getBody()); + } + System.out.println(); + } + } +} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java index 6631849bf..ca70409f4 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java @@ -25,8 +25,8 @@ private Google20Example() { @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your client id and secret - final String clientId = "your client id"; - final String clientSecret = "your client secret"; + final String clientId = "your_client_id"; + final String clientSecret = "your_client_secret"; final String secretState = "secret" + new Random().nextInt(999_999); final OAuth20Service service = new ServiceBuilder(clientId) .apiSecret(clientSecret) diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java index ad1afcc65..76ef6dbce 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java @@ -1,5 +1,6 @@ package com.github.scribejava.core.builder.api; +import com.github.scribejava.core.extractors.DeviceAuthorizationJsonExtractor; import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; import com.github.scribejava.core.extractors.TokenExtractor; import com.github.scribejava.core.httpclient.HttpClient; @@ -122,7 +123,18 @@ public ClientAuthentication getClientAuthentication() { return HttpBasicAuthenticationScheme.instance(); } - public String getDeviceAuthorizationUrl() { - return null; + /** + * RFC 8628 OAuth 2.0 Device Authorization Grant + * + * @see RFC 8628 + * @return the device authorization endpoint + */ + public String getDeviceAuthorizationEndpoint() { + throw new UnsupportedOperationException( + "This API doesn't support Device Authorization Grant or we have no info about this"); + } + + public DeviceAuthorizationJsonExtractor getDeviceAuthorizationExtractor() { + return DeviceAuthorizationJsonExtractor.instance(); } } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/AbstractJsonExtractor.java b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/AbstractJsonExtractor.java new file mode 100644 index 000000000..4a592a706 --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/AbstractJsonExtractor.java @@ -0,0 +1,22 @@ +package com.github.scribejava.core.extractors; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.github.scribejava.core.exceptions.OAuthException; + +public abstract class AbstractJsonExtractor { + + protected static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); + + protected static JsonNode extractRequiredParameter(JsonNode errorNode, String parameterName, String rawResponse) + throws OAuthException { + final JsonNode value = errorNode.get(parameterName); + + if (value == null) { + throw new OAuthException("Response body is incorrect. Can't extract a '" + parameterName + + "' from this: '" + rawResponse + "'", null); + } + + return value; + } +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/DeviceAuthorizationJsonExtractor.java b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/DeviceAuthorizationJsonExtractor.java new file mode 100644 index 000000000..14e09f28d --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/DeviceAuthorizationJsonExtractor.java @@ -0,0 +1,64 @@ +package com.github.scribejava.core.extractors; + +import static com.github.scribejava.core.extractors.AbstractJsonExtractor.OBJECT_MAPPER; +import static com.github.scribejava.core.extractors.AbstractJsonExtractor.extractRequiredParameter; +import com.fasterxml.jackson.databind.JsonNode; +import com.github.scribejava.core.model.DeviceAuthorization; +import java.io.IOException; +import com.github.scribejava.core.model.Response; + +public class DeviceAuthorizationJsonExtractor extends AbstractJsonExtractor { + + protected DeviceAuthorizationJsonExtractor() { + } + + private static class InstanceHolder { + + private static final DeviceAuthorizationJsonExtractor INSTANCE = new DeviceAuthorizationJsonExtractor(); + } + + public static DeviceAuthorizationJsonExtractor instance() { + return InstanceHolder.INSTANCE; + } + + public DeviceAuthorization extract(Response response) throws IOException { + + final String body = response.getBody(); + + if (response.getCode() != 200) { + generateError(body); + } + return createDeviceAuthorization(body); + } + + public void generateError(String rawResponse) throws IOException { + OAuth2AccessTokenJsonExtractor.instance().generateError(rawResponse); + } + + private DeviceAuthorization createDeviceAuthorization(String rawResponse) throws IOException { + + final JsonNode response = OBJECT_MAPPER.readTree(rawResponse); + + final DeviceAuthorization deviceAuthorization = new DeviceAuthorization( + extractRequiredParameter(response, "device_code", rawResponse).textValue(), + extractRequiredParameter(response, "user_code", rawResponse).textValue(), + extractRequiredParameter(response, getVerificationUriParamName(), rawResponse).textValue(), + extractRequiredParameter(response, "expires_in", rawResponse).intValue()); + + final JsonNode intervalSeconds = response.get("interval"); + if (intervalSeconds != null) { + deviceAuthorization.setIntervalSeconds(intervalSeconds.asInt(5)); + } + + final JsonNode verificationUriComplete = response.get("verification_uri_complete"); + if (verificationUriComplete != null) { + deviceAuthorization.setVerificationUriComplete(verificationUriComplete.asText()); + } + + return deviceAuthorization; + } + + protected String getVerificationUriParamName() { + return "verification_uri"; + } +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractor.java b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractor.java index c2f483e0e..96ff82de5 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractor.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractor.java @@ -1,10 +1,8 @@ package com.github.scribejava.core.extractors; import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; import java.io.IOException; import java.net.URI; -import com.github.scribejava.core.exceptions.OAuthException; import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuth2AccessTokenErrorResponse; import com.github.scribejava.core.model.OAuthConstants; @@ -15,9 +13,7 @@ /** * JSON (default) implementation of {@link TokenExtractor} for OAuth 2.0 */ -public class OAuth2AccessTokenJsonExtractor implements TokenExtractor { - - protected static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); +public class OAuth2AccessTokenJsonExtractor extends AbstractJsonExtractor implements TokenExtractor { protected OAuth2AccessTokenJsonExtractor() { } @@ -92,16 +88,4 @@ protected OAuth2AccessToken createToken(String accessToken, String tokenType, In String refreshToken, String scope, JsonNode response, String rawResponse) { return new OAuth2AccessToken(accessToken, tokenType, expiresIn, refreshToken, scope, rawResponse); } - - public static JsonNode extractRequiredParameter(JsonNode errorNode, String parameterName, String rawResponse) - throws OAuthException { - final JsonNode value = errorNode.get(parameterName); - - if (value == null) { - throw new OAuthException("Response body is incorrect. Can't extract a '" + parameterName - + "' from this: '" + rawResponse + "'", null); - } - - return value; - } } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/DeviceAuthorization.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/DeviceAuthorization.java new file mode 100644 index 000000000..dfdc42c36 --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/DeviceAuthorization.java @@ -0,0 +1,105 @@ +package com.github.scribejava.core.model; + +/** + * Device Authorization Response + * + * @see rfc8628 + */ +public class DeviceAuthorization { + + /** + * device_code + * + * REQUIRED. The device verification code. + */ + private final String deviceCode; + + /** + * user_code + * + * REQUIRED. The end-user verification code. + */ + private final String userCode; + + /** + * verification_uri + * + * REQUIRED. The end-user verification URI on the authorization server. The URI should be short and easy to remember + * as end users will be asked to manually type it into their user agent. + */ + private final String verificationUri; + + /** + * verification_uri_complete + * + * OPTIONAL. A verification URI that includes the "user_code" (or other information with the same function as the + * "user_code"), which is designed for non-textual transmission. + */ + private String verificationUriComplete; + + /** + * expires_in + * + * REQUIRED. The lifetime in seconds of the "device_code" and "user_code". + */ + private final int expiresInSeconds; + + /** + * interval + * + * OPTIONAL. The minimum amount of time in seconds that the client SHOULD wait between polling requests to the token + * endpoint. If no value is provided, clients MUST use 5 as the default. + */ + private int intervalSeconds = 5; + + public DeviceAuthorization(String deviceCode, String userCode, String verificationUri, int expiresInSeconds) { + this.deviceCode = deviceCode; + this.userCode = userCode; + this.verificationUri = verificationUri; + this.expiresInSeconds = expiresInSeconds; + } + + public void setVerificationUriComplete(String verificationUriComplete) { + this.verificationUriComplete = verificationUriComplete; + } + + public void setIntervalSeconds(int intervalSeconds) { + this.intervalSeconds = intervalSeconds; + } + + public String getDeviceCode() { + return deviceCode; + } + + public String getUserCode() { + return userCode; + } + + public String getVerificationUri() { + return verificationUri; + } + + public String getVerificationUriComplete() { + return verificationUriComplete; + } + + public long getExpiresInSeconds() { + return expiresInSeconds; + } + + public int getIntervalSeconds() { + return intervalSeconds; + } + + @Override + public String toString() { + return "DeviceAuthorization{" + + "'deviceCode'='" + deviceCode + + "', 'userCode'='" + userCode + + "', 'verificationUri'='" + verificationUri + + "', 'verificationUriComplete'='" + verificationUriComplete + + "', 'expiresInSeconds'='" + expiresInSeconds + + "', 'intervalSeconds'='" + intervalSeconds + "'}"; + } + +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/DeviceCode.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/DeviceCode.java deleted file mode 100644 index 8e31fc8aa..000000000 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/DeviceCode.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.github.scribejava.core.model; - -public class DeviceCode { - private String deviceCode; - private String userCode; - private String verificationUri; - private int intervalSeconds; - private long expiresAtMillis; - - public DeviceCode(String deviceCode, String userCode, String verificationUri, - int intervalSeconds, int expiresInSeconds) { - this.deviceCode = deviceCode; - this.userCode = userCode; - this.verificationUri = verificationUri; - this.intervalSeconds = intervalSeconds; - expiresAtMillis = System.currentTimeMillis() + (expiresInSeconds * 1000); - } - - public String getDeviceCode() { - return deviceCode; - } - - public String getUserCode() { - return userCode; - } - - public String getVerificationUri() { - return verificationUri; - } - - public int getIntervalSeconds() { - return intervalSeconds; - } - - public long getExpiresAtMillis() { - return expiresAtMillis; - } -} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java index 75e515f60..9b30fb9b5 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java @@ -1,12 +1,10 @@ package com.github.scribejava.core.oauth; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.httpclient.HttpClientConfig; -import com.github.scribejava.core.model.DeviceCode; +import com.github.scribejava.core.model.DeviceAuthorization; import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuth2AccessTokenErrorResponse; import com.github.scribejava.core.model.OAuth2Authorization; @@ -26,13 +24,7 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; -import static com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor.extractRequiredParameter; -import static com.github.scribejava.core.oauth2.OAuth2Error.AUTHORIZATION_PENDING; -import static com.github.scribejava.core.oauth2.OAuth2Error.SLOW_DOWN; -import static java.lang.Thread.sleep; - public class OAuth20Service extends OAuthService { - protected static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); private static final String VERSION = "2.0"; private final DefaultApi20 api; @@ -57,8 +49,7 @@ protected OAuth2AccessToken sendAccessTokenRequestSync(OAuthRequest request) try (Response response = execute(request)) { if (isDebug()) { log("response status code: %s", response.getCode()); - final String body = response.getBody(); - log("response body: %s", body); + log("response body: %s", response.getBody()); } return api.getAccessTokenExtractor().extract(response); @@ -83,10 +74,9 @@ public OAuth2AccessToken convert(Response response) throws IOException { log("received response for access token"); if (isDebug()) { log("response status code: %s", response.getCode()); - final String body = response.getBody(); - log("response body: %s", body); + log("response body: %s", response.getBody()); } - final OAuth2AccessToken token = getApi().getAccessTokenExtractor().extract(response); + final OAuth2AccessToken token = api.getAccessTokenExtractor().extract(response); response.close(); return token; } @@ -150,11 +140,7 @@ protected OAuthRequest createAccessTokenRequest(AccessTokenRequestParams params) if (pkceCodeVerifier != null) { request.addParameter(PKCE.PKCE_CODE_VERIFIER_PARAM, pkceCodeVerifier); } - if (isDebug()) { - log("created access token request with body params [%s], query string params [%s]", - request.getBodyParams().asFormUrlEncodedString(), - request.getQueryStringParams().asFormUrlEncodedString()); - } + logRequestWithParams("access token", request); return request; } @@ -168,9 +154,7 @@ public Future refreshAccessTokenAsync(String refreshToken, St public OAuth2AccessToken refreshAccessToken(String refreshToken) throws IOException, InterruptedException, ExecutionException { - final OAuthRequest request = createRefreshTokenRequest(refreshToken, null); - - return sendAccessTokenRequestSync(request); + return refreshAccessToken(refreshToken, (String) null); } public OAuth2AccessToken refreshAccessToken(String refreshToken, String scope) @@ -210,11 +194,9 @@ protected OAuthRequest createRefreshTokenRequest(String refreshToken, String sco request.addParameter(OAuthConstants.REFRESH_TOKEN, refreshToken); request.addParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.REFRESH_TOKEN); - if (isDebug()) { - log("created refresh token request with body params [%s], query string params [%s]", - request.getBodyParams().asFormUrlEncodedString(), - request.getQueryStringParams().asFormUrlEncodedString()); - } + + logRequestWithParams("refresh token", request); + return request; } @@ -278,11 +260,8 @@ protected OAuthRequest createAccessTokenPasswordGrantRequest(String username, St api.getClientAuthentication().addClientAuthentication(request, getApiKey(), getApiSecret()); - if (isDebug()) { - log("created access token password grant request with body params [%s], query string params [%s]", - request.getBodyParams().asFormUrlEncodedString(), - request.getQueryStringParams().asFormUrlEncodedString()); - } + logRequestWithParams("access token password grant", request); + return request; } @@ -341,11 +320,8 @@ protected OAuthRequest createAccessTokenClientCredentialsGrantRequest(String sco } request.addParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.CLIENT_CREDENTIALS); - if (isDebug()) { - log("created access token client credentials grant request with body params [%s], query string params [%s]", - request.getBodyParams().asFormUrlEncodedString(), - request.getQueryStringParams().asFormUrlEncodedString()); - } + logRequestWithParams("access token client credentials grant", request); + return request; } @@ -416,11 +392,7 @@ protected OAuthRequest createRevokeTokenRequest(String tokenToRevoke, TokenTypeH request.addParameter("token_type_hint", tokenTypeHint.getValue()); } - if (isDebug()) { - log("created revoke token request with body params [%s], query string params [%s]", - request.getBodyParams().asFormUrlEncodedString(), - request.getQueryStringParams().asFormUrlEncodedString()); - } + logRequestWithParams("revoke token", request); return request; } @@ -505,82 +477,183 @@ public String getDefaultScope() { return defaultScope; } + protected OAuthRequest createDeviceAuthorizationCodesRequest(String scope) { + final OAuthRequest request = new OAuthRequest(Verb.POST, api.getDeviceAuthorizationEndpoint()); + request.addParameter(OAuthConstants.CLIENT_ID, getApiKey()); + if (scope != null) { + request.addParameter(OAuthConstants.SCOPE, scope); + } else if (defaultScope != null) { + request.addParameter(OAuthConstants.SCOPE, defaultScope); + } + + logRequestWithParams("Device Authorization Codes", request); + + return request; + } + + /** + * Requests a set of verification codes from the authorization server with the default scope + * + * @see RFC 8628 + * + * @return DeviceAuthorization + * @throws InterruptedException InterruptedException + * @throws ExecutionException ExecutionException + * @throws IOException IOException + */ + public DeviceAuthorization getDeviceAuthorizationCodes() + throws InterruptedException, ExecutionException, IOException { + return getDeviceAuthorizationCodes((String) null); + } + /** - * Requests a device code from a server. + * Requests a set of verification codes from the authorization server * - * @see rfc8628 - * @see - * azure v2-oauth2-device-code + * @see RFC 8628 + * + * @param scope scope + * @return DeviceAuthorization + * @throws InterruptedException InterruptedException + * @throws ExecutionException ExecutionException + * @throws IOException IOException */ - public DeviceCode getDeviceCode() throws InterruptedException, ExecutionException, IOException { - final OAuthRequest request = new OAuthRequest(Verb.POST, api.getDeviceAuthorizationUrl()); - request.addBodyParameter(OAuthConstants.CLIENT_ID, getApiKey()); - request.addBodyParameter(OAuthConstants.SCOPE, getDefaultScope()); + public DeviceAuthorization getDeviceAuthorizationCodes(String scope) + throws InterruptedException, ExecutionException, IOException { + final OAuthRequest request = createDeviceAuthorizationCodesRequest(scope); + try (Response response = execute(request)) { - final String body = response.getBody(); - if (response.getCode() == 200) { - final JsonNode n = OBJECT_MAPPER.readTree(body); - return new DeviceCode( - extractRequiredParameter(n, "device_code", body).textValue(), - extractRequiredParameter(n, "user_code", body).textValue(), - extractRequiredParameter(n, "verification_uri", body).textValue(), - n.path("interval").asInt(5), - extractRequiredParameter(n, "expires_in", body).intValue()); - } else { - OAuth2AccessTokenJsonExtractor.instance().generateError(body); - throw new IllegalStateException(); // generateError() always throws an exception + if (isDebug()) { + log("got DeviceAuthorizationCodes response"); + log("response status code: %s", response.getCode()); + log("response body: %s", response.getBody()); } + return api.getDeviceAuthorizationExtractor().extract(response); } } + public Future getDeviceAuthorizationCodes( + OAuthAsyncRequestCallback callback) { + return getDeviceAuthorizationCodes(null, callback); + } + + public Future getDeviceAuthorizationCodes(String scope, + OAuthAsyncRequestCallback callback) { + final OAuthRequest request = createDeviceAuthorizationCodesRequest(scope); + + return execute(request, callback, new OAuthRequest.ResponseConverter() { + @Override + public DeviceAuthorization convert(Response response) throws IOException { + final DeviceAuthorization deviceAuthorization = api.getDeviceAuthorizationExtractor().extract(response); + response.close(); + return deviceAuthorization; + } + }); + } + + public Future getDeviceAuthorizationCodesAsync() { + return getDeviceAuthorizationCodesAsync(null); + } + + public Future getDeviceAuthorizationCodesAsync(String scope) { + return getDeviceAuthorizationCodes(scope, null); + } + + protected OAuthRequest createAccessTokenDeviceAuthorizationGrantRequest(DeviceAuthorization deviceAuthorization) { + final OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint()); + request.addParameter(OAuthConstants.GRANT_TYPE, "urn:ietf:params:oauth:grant-type:device_code"); + request.addParameter("device_code", deviceAuthorization.getDeviceCode()); + api.getClientAuthentication().addClientAuthentication(request, getApiKey(), getApiSecret()); + return request; + } + /** * Attempts to get a token from a server. - * Function {@link #pollDeviceAccessToken(DeviceCode)} is usually used instead of this. * + * Function {@link #pollAccessTokenDeviceAuthorizationGrant(com.github.scribejava.core.model.DeviceAuthorization)} + * is usually used instead of this. + * + * @param deviceAuthorization deviceAuthorization * @return token - * @throws OAuth2AccessTokenErrorResponse - * If {@link OAuth2AccessTokenErrorResponse#getError()} is - * {@link OAuth2Error#AUTHORIZATION_PENDING} or {@link OAuth2Error#SLOW_DOWN}, - * another attempt should be made after a while. * - * @see #getDeviceCode() + * @throws java.lang.InterruptedException InterruptedException + * @throws java.util.concurrent.ExecutionException ExecutionException + * @throws java.io.IOException IOException + * @throws OAuth2AccessTokenErrorResponse If {@link OAuth2AccessTokenErrorResponse#getError()} is + * {@link com.github.scribejava.core.oauth2.OAuth2Error#AUTHORIZATION_PENDING} or + * {@link com.github.scribejava.core.oauth2.OAuth2Error#SLOW_DOWN}, another attempt should be made after a while. + * + * @see #getDeviceAuthorizationCodes() */ - public OAuth2AccessToken getAccessTokenDeviceCodeGrant(DeviceCode deviceCode) - throws IOException, InterruptedException, ExecutionException { - final OAuthRequest request = new OAuthRequest(Verb.POST, api.getAccessTokenEndpoint()); - request.addParameter(OAuthConstants.GRANT_TYPE, "urn:ietf:params:oauth:grant-type:device_code"); - request.addBodyParameter(OAuthConstants.CLIENT_ID, getApiKey()); - request.addParameter("device_code", deviceCode.getDeviceCode()); + public OAuth2AccessToken getAccessTokenDeviceAuthorizationGrant(DeviceAuthorization deviceAuthorization) + throws InterruptedException, ExecutionException, IOException { + final OAuthRequest request = createAccessTokenDeviceAuthorizationGrantRequest(deviceAuthorization); + try (Response response = execute(request)) { + if (isDebug()) { + log("got AccessTokenDeviceAuthorizationGrant response"); + log("response status code: %s", response.getCode()); + log("response body: %s", response.getBody()); + } return api.getAccessTokenExtractor().extract(response); } } + public Future getAccessTokenDeviceAuthorizationGrant(DeviceAuthorization deviceAuthorization, + OAuthAsyncRequestCallback callback) { + final OAuthRequest request = createAccessTokenDeviceAuthorizationGrantRequest(deviceAuthorization); + + return execute(request, callback, new OAuthRequest.ResponseConverter() { + @Override + public OAuth2AccessToken convert(Response response) throws IOException { + final OAuth2AccessToken accessToken = api.getAccessTokenExtractor().extract(response); + response.close(); + return accessToken; + } + }); + } + + public Future getAccessTokenDeviceAuthorizationGrantAsync( + DeviceAuthorization deviceAuthorization) { + return getAccessTokenDeviceAuthorizationGrant(deviceAuthorization, null); + } + /** - * Periodically tries to get a token from a server (waiting for the user to give consent). + * Periodically tries to get a token from a server (waiting for the user to give consent). Sync only version. No + * Async variants yet, one should implement async scenarios themselves. * + * @param deviceAuthorization deviceAuthorization * @return token - * @throws OAuth2AccessTokenErrorResponse - * Indicates OAuth error. + * @throws java.lang.InterruptedException InterruptedException + * @throws java.util.concurrent.ExecutionException ExecutionException + * @throws java.io.IOException IOException + * @throws OAuth2AccessTokenErrorResponse Indicates OAuth error. * - * @see #getDeviceCode() + * @see #getDeviceAuthorizationCodes() */ - public OAuth2AccessToken pollDeviceAccessToken(DeviceCode deviceCode) + public OAuth2AccessToken pollAccessTokenDeviceAuthorizationGrant(DeviceAuthorization deviceAuthorization) throws InterruptedException, ExecutionException, IOException { - long intervalMillis = deviceCode.getIntervalSeconds() * 1000; + long intervalMillis = deviceAuthorization.getIntervalSeconds() * 1000; while (true) { try { - return getAccessTokenDeviceCodeGrant(deviceCode); + return getAccessTokenDeviceAuthorizationGrant(deviceAuthorization); } catch (OAuth2AccessTokenErrorResponse e) { - if (e.getError() != AUTHORIZATION_PENDING) { - if (e.getError() == SLOW_DOWN) { + if (e.getError() != OAuth2Error.AUTHORIZATION_PENDING) { + if (e.getError() == OAuth2Error.SLOW_DOWN) { intervalMillis += 5000; } else { throw e; } } } - sleep(intervalMillis); + Thread.sleep(intervalMillis); + } + } + + private void logRequestWithParams(String requestDescription, OAuthRequest request) { + if (isDebug()) { + log("created " + requestDescription + " request with body params [%s], query string params [%s]", + request.getBodyParams().asFormUrlEncodedString(), + request.getQueryStringParams().asFormUrlEncodedString()); } } } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth2/OAuth2Error.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth2/OAuth2Error.java index af8f540f8..b1422bcae 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth2/OAuth2Error.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth2/OAuth2Error.java @@ -3,8 +3,6 @@ import java.util.EnumSet; import java.util.Set; -import static java.util.Collections.unmodifiableSet; - public enum OAuth2Error { /** * @see RFC 6749, 4.1.2.1 Error Response @@ -23,6 +21,7 @@ public enum OAuth2Error { /** * @see RFC 6749, 4.1.2.1 Error Response * @see RFC 6749, 4.2.2.1 Error Response + * @see RFC 8628, 3.5. Device Access Token Response */ ACCESS_DENIED("access_denied"), /** @@ -73,28 +72,20 @@ public enum OAuth2Error { * Registration */ UNSUPPORTED_TOKEN_TYPE("unsupported_token_type"), - /** - * @see rfc8628#section-3.5 + * @see RFC 8628, 3.5. Device Access Token Response */ AUTHORIZATION_PENDING("authorization_pending"), - /** - * @see rfc8628#section-3.5 + * @see RFC 8628, 3.5. Device Access Token Response */ SLOW_DOWN("slow_down"), - /** - * @see rfc8628#section-3.5 + * @see RFC 8628, 3.5. Device Access Token Response */ - EXPIRED_TOKEN("expired_token"), - ; + EXPIRED_TOKEN("expired_token"); - /** - * Unlike {@link #values()} which creates a new array every time, this always - * returns the same immutable object. - */ - public static final Set VALUES = unmodifiableSet(EnumSet.allOf(OAuth2Error.class)); + private static final Set VALUES = EnumSet.allOf(OAuth2Error.class); private final String errorString; From 0d4d766a33bf0426cb8f7245684d6afbd94c2755 Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Mon, 9 Nov 2020 12:19:26 +0300 Subject: [PATCH 812/882] update deps --- pom.xml | 10 +++++----- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-armeria/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index 69c7cb46d..546dc3989 100644 --- a/pom.xml +++ b/pom.xml @@ -54,18 +54,18 @@ com.fasterxml.jackson.core jackson-databind - 2.11.2 + 2.11.3 junit junit - 4.13 + 4.13.1 test com.squareup.okhttp3 mockwebserver - 4.8.1 + 4.9.0 test @@ -104,7 +104,7 @@ com.puppycrawl.tools checkstyle - 8.36 + 8.37 @@ -269,7 +269,7 @@ 7 - 6.27.0 + 6.29.0 diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index 393c4fc83..347d90675 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -23,7 +23,7 @@ org.apache.httpcomponents httpclient - 4.5.12 + 4.5.13 org.apache.httpcomponents diff --git a/scribejava-httpclient-armeria/pom.xml b/scribejava-httpclient-armeria/pom.xml index 9c7325e58..89961e482 100644 --- a/scribejava-httpclient-armeria/pom.xml +++ b/scribejava-httpclient-armeria/pom.xml @@ -23,7 +23,7 @@ com.linecorp.armeria armeria - 1.0.0 + 1.2.0 com.github.scribejava diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 0ad7a7540..2c113d597 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -23,7 +23,7 @@ com.squareup.okhttp3 okhttp - 4.8.1 + 4.9.0 com.github.scribejava From 22b0ce7caef5663732e15d13fda5052f6e6a774c Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Mon, 9 Nov 2020 12:28:03 +0300 Subject: [PATCH 813/882] add Ian Strachan donation --- donate.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/donate.md b/donate.md index 50f782838..ee6a1a6e7 100644 --- a/donate.md +++ b/donate.md @@ -10,4 +10,5 @@ ps.If you can't for any reason use above methods, let me know, we will find the Hall of fame "Donors" (in alphabetical order, if you don't want to be here, just put a note along with the donation):
    1.Douglas Ross from USA
    -2.Your name can be here. +2.Ian Strachan
    +3.Your name can be here. From d3c3da84eec775b01acf6a5d94658ca6ec31dca3 Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Tue, 10 Nov 2020 11:51:00 +0300 Subject: [PATCH 814/882] update changelog, add "update Google API URLs" entry --- changelog | 1 + 1 file changed, 1 insertion(+) diff --git a/changelog b/changelog index c029807e2..1b590452c 100644 --- a/changelog +++ b/changelog @@ -2,6 +2,7 @@ * add Kakao API (https://kakao.com/) (thanks to https://github.com/v0o0v) * support chunks in JDKHttpClient's Multipart (thanks to https://github.com/eos1d3) * add support for OAuth 2.0 Device Authorization Grant (RFC 8628) (thanks to https://github.com/rebarbora-mckvak) + * update Google API URLs [7.1.1] * add Proxy support (via config's option) to internal JDKHttpClient (thanks to https://github.com/bjournaud) From 7a35ddc1dea4df338857b02fc3f8fbff755e4c30 Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Tue, 10 Nov 2020 12:12:05 +0300 Subject: [PATCH 815/882] prepare v8.0.0 --- README.md | 4 ++-- changelog | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 8c7f3a07a..02384b033 100644 --- a/README.md +++ b/README.md @@ -135,7 +135,7 @@ You can pull ScribeJava from the central maven repository, just add these to you com.github.scribejava scribejava-apis - 7.1.1 + 8.0.0 ``` @@ -144,7 +144,7 @@ And in case you need just core classes (that's it, without any external API (FB, com.github.scribejava scribejava-core - 7.1.1 + 8.0.0 ``` diff --git a/changelog b/changelog index 1b590452c..f46c83239 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,4 @@ -[SNAPSHOT] +[8.0.0] * add Kakao API (https://kakao.com/) (thanks to https://github.com/v0o0v) * support chunks in JDKHttpClient's Multipart (thanks to https://github.com/eos1d3) * add support for OAuth 2.0 Device Authorization Grant (RFC 8628) (thanks to https://github.com/rebarbora-mckvak) From 4e76471398cf47143b56a6ba762363d5bb9a210c Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Tue, 10 Nov 2020 12:13:28 +0300 Subject: [PATCH 816/882] [maven-release-plugin] prepare release scribejava-8.0.0 --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-armeria/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 8 files changed, 9 insertions(+), 9 deletions(-) diff --git a/pom.xml b/pom.xml index 546dc3989..a695b50c0 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 7.1.2-SNAPSHOT + 8.0.0 ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -35,7 +35,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - HEAD + scribejava-8.0.0 diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 24dbcaa1e..2acf02fb0 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.1.2-SNAPSHOT + 8.0.0 ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 79a016cf2..f3c027aaa 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.1.2-SNAPSHOT + 8.0.0 ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 6b6d8578b..358e8e73f 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.1.2-SNAPSHOT + 8.0.0 ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index 347d90675..fa367ff4a 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.1.2-SNAPSHOT + 8.0.0 ../pom.xml diff --git a/scribejava-httpclient-armeria/pom.xml b/scribejava-httpclient-armeria/pom.xml index 89961e482..074345d6a 100644 --- a/scribejava-httpclient-armeria/pom.xml +++ b/scribejava-httpclient-armeria/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.1.2-SNAPSHOT + 8.0.0 ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index cf992b25a..08971a209 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.1.2-SNAPSHOT + 8.0.0 ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 2c113d597..6d038e039 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.1.2-SNAPSHOT + 8.0.0 ../pom.xml From 788389b8cb9addfce956f051f9f6d645cc03d329 Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Tue, 10 Nov 2020 12:13:36 +0300 Subject: [PATCH 817/882] [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 818/882] 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 819/882] 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 820/882] 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 821/882] 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 822/882] 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 823/882] 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 824/882] 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 825/882] [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 826/882] [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 827/882] 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 828/882] 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 829/882] 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 830/882] 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 831/882] 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 832/882] 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 833/882] 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 834/882] 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 835/882] 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 836/882] 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 837/882] 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 838/882] 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 839/882] 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 840/882] 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 841/882] 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 842/882] 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 843/882] [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 844/882] [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 845/882] 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 846/882] * 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 847/882] 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 848/882] 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 849/882] [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 850/882] [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 851/882] * 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 852/882] 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 853/882] 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 854/882] [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 855/882] [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 856/882] 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 857/882] 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 858/882] 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 859/882] 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 860/882] 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 861/882] [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 862/882] 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 863/882] 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 864/882] 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 865/882] 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 866/882] 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 867/882] 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 868/882] 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 869/882] 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 870/882] 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 871/882] 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 872/882] 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 873/882] 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 874/882] 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 875/882] 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 876/882] [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 877/882] [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 878/882] 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 879/882] [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 880/882] [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 881/882] 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 882/882] 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