diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml
new file mode 100644
index 000000000..0a2df9277
--- /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://www.paypal.com/paypalme/algr453'] # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
diff --git a/.travis.yml b/.travis.yml
deleted file mode 100644
index a79954ad5..000000000
--- a/.travis.yml
+++ /dev/null
@@ -1,8 +0,0 @@
-language: java
-script: mvn clean package
-jdk:
- - oraclejdk8
- - oraclejdk7
- - openjdk7
-os:
- - linux
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.
diff --git a/README.md b/README.md
index 087c0f430..b90ef2e5f 100644
--- a/README.md
+++ b/README.md
@@ -1,7 +1,6 @@
# Welcome to the home of ScribeJava, the simple OAuth client Java lib!
-[](https://travis-ci.org/scribejava/scribejava)
-[](https://maven-badges.herokuapp.com/maven-central/com.github.scribejava/scribejava)
+[](https://github.com/scribejava/scribejava/blob/master/donate.md) [](https://maven-badges.herokuapp.com/maven-central/com.github.scribejava/scribejava)
# Why use ScribeJava?
@@ -11,70 +10,108 @@
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());
```
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
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)
- * asynchttpclient 2.x (maven module scribejava-httpclient-ahc)
- * OkHttp (maven module scribejava-httpclient-okhttp)
-
- just add corresponding maven modules to your pom
+ * 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)
+ * 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)
-### Supports all major 1.0a and 2.0 OAuth APIs out-of-the-box
+ just add corresponding maven modules to your pom
-* AWeber (http://www.aweber.com/)
-* Box (https://www.box.com/)
-* Digg (http://digg.com/)
+### 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, [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, [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 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
+
+* 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)
+* 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/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiscordExample.java)
* Доктор на работе (https://www.doktornarabote.ru/)
-* 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/)
-* Google (https://www.google.com/)
-* 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/)
-* NAVER (http://www.naver.com/)
-* NetEase (http://www.163.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/)
-* 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/)
-* Twitter (https://twitter.com/)
-* Viadeo (http://viadeo.com/)
-* VK ВКонтакте (http://vk.com/)
-* XING (https://www.xing.com/)
-* Yahoo (https://www.yahoo.com/)
-* Misfit (http://misfit.com/)
+* 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)
+* 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)
+* 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)
+* 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 (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)
+* 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)
+* 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)
+* 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)
+* 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)
### Small and modular
@@ -100,7 +137,7 @@ You can pull ScribeJava from the central maven repository, just add these to you
com.github.scribejava
scribejava-apis
- 4.1.2
+ 8.3.3
```
@@ -109,14 +146,29 @@ And in case you need just core classes (that's it, without any external API (FB,
com.github.scribejava
scribejava-core
- 4.1.2
+ 8.3.3
```
+## How can I help ScribeJava
+
+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 (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
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?
diff --git a/changelog b/changelog
index 01f18217c..e962e073b 100644
--- a/changelog
+++ b/changelog
@@ -1,6 +1,186 @@
-[SNAPSHOT]
+[8.3.3]
+ * update dependencies, including security updates in libraries
+
+[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)
+ (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
+ 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
+ (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
+ * 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)
+ * 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)
+ * 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)
+ * 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)
+ * 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)
+
+[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)
+
+[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)
+
+[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
+
+[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)
+ * 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
+
+[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
+ * 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
+ * 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)
+ * 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)
+
+[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)
+
+[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
+ * 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)
+ * 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)
+ * 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)
+ * 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)
+ * 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
+ * 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)
+ * 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)
+ * 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)
+ * java7 compatible again!
+
+[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)
+ * fix LinkedInApi20 (thanks to https://github.com/jhorowitz-firedrum)
+
+[5.0.0]
+ * 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)
+ * 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)
+ * 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"))
+
+[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)
[4.1.2]
* LinkedIn use Header to sign OAuth2 requests
@@ -8,21 +188,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]
@@ -35,14 +221,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
@@ -51,14 +239,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
@@ -99,8 +290,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]
@@ -142,8 +335,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/checkstyle.xml b/checkstyle.xml
index 9cba55776..f7efbad65 100644
--- a/checkstyle.xml
+++ b/checkstyle.xml
@@ -45,7 +45,6 @@
-
@@ -76,7 +75,6 @@
-
@@ -95,20 +93,22 @@
-
-
-
-
-
+
+
+
+
+
diff --git a/donate.md b/donate.md
new file mode 100644
index 000000000..99d3686dc
--- /dev/null
+++ b/donate.md
@@ -0,0 +1,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.
+
+Thanks in advance!
+
+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
+2.Ian Strachan
+3.Your name can be here.
diff --git a/pmd.xml b/pmd.xml
new file mode 100644
index 000000000..5d93d340b
--- /dev/null
+++ b/pmd.xml
@@ -0,0 +1,124 @@
+
+
+
+
+ This ruleset defines the PMD rules for project "ScribeJava".
+
+
+
+
+
+
+ true
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ true
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/pom.xml b/pom.xml
index 15ee61cda..b484b6a71 100644
--- a/pom.xml
+++ b/pom.xml
@@ -3,7 +3,7 @@
com.github.scribejava
scribejava
pom
- 4.1.3-SNAPSHOT
+ 8.3.4-SNAPSHOT
ScribeJava OAuth Library
The best OAuth library out there
https://github.com/scribejava/scribejava
@@ -16,10 +16,13 @@
scribejava-core
+ scribejava-java8
scribejava-apis
scribejava-httpclient-ahc
scribejava-httpclient-ning
scribejava-httpclient-okhttp
+ scribejava-httpclient-apache
+ scribejava-httpclient-armeria
@@ -30,45 +33,17 @@
- 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
-
+ HEAD
+
kullfar
- Stas Gromov
- s.gromov@hh.ru
- hh.ru
- http://hh.ru
-
- all
-
- +3
-
- 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
+ Stanislav Gromov
+ kullfar@gmail.com
all
@@ -77,25 +52,23 @@
+
+ com.fasterxml.jackson.core
+ jackson-databind
+ 2.14.0
+
junit
junit
- 4.12
+ 4.13.2
test
- com.google.code.gson
- gson
- 2.8.1
+ com.squareup.okhttp3
+ mockwebserver
+ 4.10.0
test
-
- commons-codec
- commons-codec
- 1.10
- compile
- true
-
@@ -103,7 +76,7 @@
org.apache.felix
maven-bundle-plugin
- 3.3.0
+ 5.1.8
bundle-manifest
@@ -117,7 +90,7 @@
org.apache.maven.plugins
maven-jar-plugin
- 3.0.2
+ 3.3.0
${project.build.outputDirectory}/META-INF/MANIFEST.MF
@@ -127,38 +100,56 @@
org.apache.maven.plugins
maven-checkstyle-plugin
- 2.17
+ 3.2.0
com.puppycrawl.tools
checkstyle
- 8.0
+ 10.4
+ org.apache.maven.plugins
maven-release-plugin
2.5.3
true
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+ 2.22.2
+
+
+ org.apache.maven.plugins
+ maven-clean-plugin
+ 3.2.0
+
+
+ org.apache.maven.plugins
+ maven-install-plugin
+ 3.0.1
+
maven-compiler-plugin
- 3.6.1
+ 3.10.1
UTF-8
- 1.7
- 1.7
+ ${java.release}
true
+
+ -Xlint:-options
+
maven-deploy-plugin
- 2.8.2
+ 3.0.0
default-deploy
@@ -172,7 +163,7 @@
org.apache.maven.plugins
maven-resources-plugin
- 3.0.2
+ 3.3.0
UTF-8
@@ -180,7 +171,7 @@
org.apache.maven.plugins
maven-source-plugin
- 3.0.1
+ 3.2.1
attach-sources
@@ -193,9 +184,12 @@
org.apache.maven.plugins
maven-javadoc-plugin
- 2.10.4
+ 3.4.1
+ ${java.home}/bin/javadoc
UTF-8
+ -html5
+ all,-missing
@@ -214,7 +208,9 @@
validate
validate
- ${basedir}/src
+
+ ${basedir}/src
+
checkstyle.xml
UTF-8
true
@@ -225,34 +221,59 @@
+
+ org.apache.maven.plugins
+ maven-pmd-plugin
+ 3.19.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.51.0
+
+
-
- jdk-1.7
-
- 1.7
-
-
-
-
-
- org.apache.maven.plugins
- maven-checkstyle-plugin
- 2.17
-
-
- com.puppycrawl.tools
- checkstyle
- 6.19
-
-
-
-
-
-
-
release-sign-artifacts
@@ -266,7 +287,7 @@
org.apache.maven.plugins
maven-gpg-plugin
- 1.6
+ 3.0.1
sign-artifacts
diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml
index 6993dd3e5..4e51bb8b5 100644
--- a/scribejava-apis/pom.xml
+++ b/scribejava-apis/pom.xml
@@ -5,10 +5,10 @@
com.github.scribejava
scribejava
- 4.1.3-SNAPSHOT
+ 8.3.4-SNAPSHOT
../pom.xml
-
+
com.github.scribejava
scribejava-apis
ScribeJava APIs
@@ -38,6 +38,24 @@
${project.version}
test
+
+ com.github.scribejava
+ scribejava-httpclient-apache
+ ${project.version}
+ test
+
+
+ com.github.scribejava
+ scribejava-httpclient-armeria
+ ${project.version}
+ test
+
+
+ io.netty
+ netty-resolver
+ 4.1.84.Final
+ 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 fe5d86691..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
@@ -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";
@@ -13,6 +12,7 @@ protected AWeberApi() {
}
private static class InstanceHolder {
+
private static final AWeberApi INSTANCE = new AWeberApi();
}
@@ -31,7 +31,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/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/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..58c82e040
--- /dev/null
+++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/AutomaticAPI.java
@@ -0,0 +1,44 @@
+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 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 String getAccessTokenEndpoint() {
+ return ACCESS_TOKEN_ENDPOINT;
+ }
+
+ @Override
+ public String getRefreshTokenEndpoint() {
+ return REFRESH_TOKEN_ENDPOINT;
+ }
+
+ @Override
+ protected String getAuthorizationBaseUrl() {
+ return AUTHORIZE_URL;
+ }
+
+ @Override
+ public ClientAuthentication getClientAuthentication() {
+ return RequestBodyAuthenticationScheme.instance();
+ }
+}
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/DataportenApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/DataportenApi.java
new file mode 100644
index 000000000..5e7ad9ceb
--- /dev/null
+++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/DataportenApi.java
@@ -0,0 +1,27 @@
+package com.github.scribejava.apis;
+
+import com.github.scribejava.core.builder.api.DefaultApi20;
+
+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 String getAccessTokenEndpoint() {
+ return "https://auth.dataporten.no/oauth/token";
+ }
+
+ @Override
+ protected String getAuthorizationBaseUrl() {
+ return "https://auth.dataporten.no/oauth/authorization";
+ }
+}
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/DiscordApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/DiscordApi.java
new file mode 100644
index 000000000..0583b6dc5
--- /dev/null
+++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/DiscordApi.java
@@ -0,0 +1,32 @@
+package com.github.scribejava.apis;
+
+import com.github.scribejava.core.builder.api.DefaultApi20;
+
+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";
+ }
+}
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..8bbd646f5
--- /dev/null
+++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/DropboxApi.java
@@ -0,0 +1,31 @@
+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/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..00ca72918
--- /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;
+
+public class EtsyApi extends DefaultApi10a {
+
+ 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";
+
+ 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 getAuthorizationBaseUrl() {
+ return AUTHORIZE_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 f761aab03..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
@@ -1,17 +1,28 @@
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;
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;
-/**
- * Facebook v2.8 API
- */
public class FacebookApi extends DefaultApi20 {
+ private final String version;
+
protected FacebookApi() {
+ this("3.2");
+ }
+
+ protected FacebookApi(String version) {
+ this.version = version;
}
private static class InstanceHolder {
@@ -23,6 +34,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;
@@ -30,21 +45,34 @@ public Verb getAccessTokenVerb() {
@Override
public String getAccessTokenEndpoint() {
- return "https://graph.facebook.com/v2.8/oauth/access_token";
+ return "https://graph.facebook.com/v" + version + "/oauth/access_token";
}
@Override
public String getRefreshTokenEndpoint() {
- throw new UnsupportedOperationException("Facebook doesn't support refershing tokens");
+ throw new UnsupportedOperationException("Facebook doesn't support refreshing tokens");
}
@Override
protected String getAuthorizationBaseUrl() {
- return "https://www.facebook.com/v2.8/dialog/oauth";
+ return "https://www.facebook.com/v" + version + "/dialog/oauth";
}
@Override
public TokenExtractor getAccessTokenExtractor() {
return FacebookAccessTokenJsonExtractor.instance();
}
+
+ @Override
+ public ClientAuthentication getClientAuthentication() {
+ return RequestBodyAuthenticationScheme.instance();
+ }
+
+ @Override
+ public FacebookService createService(String apiKey, String apiSecret, String callback, String defaultScope,
+ 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/FitbitApi20.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/FitbitApi20.java
new file mode 100644
index 000000000..f6e163978
--- /dev/null
+++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/FitbitApi20.java
@@ -0,0 +1,38 @@
+package com.github.scribejava.apis;
+
+import com.github.scribejava.apis.fitbit.FitBitJsonTokenExtractor;
+import com.github.scribejava.core.builder.api.DefaultApi20;
+
+
+/**
+ * Fitbit's OAuth2 client's implementation
+ * source: https://dev.fitbit.com/docs/oauth2/
+ */
+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 FitBitJsonTokenExtractor getAccessTokenExtractor() {
+ return FitBitJsonTokenExtractor.instance();
+ }
+}
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..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
@@ -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
@@ -30,6 +29,7 @@ protected FlickrApi(FlickrPerm perm) {
}
private static class InstanceHolder {
+
private static final FlickrApi INSTANCE = new FlickrApi();
}
@@ -49,13 +49,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/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/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..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
@@ -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() {
}
@@ -22,7 +21,7 @@ public static FreelancerApi instance() {
@Override
public OAuth1SignatureType getSignatureType() {
- return OAuth1SignatureType.QueryString;
+ return OAuth1SignatureType.QUERY_STRING;
}
@Override
@@ -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/GoogleApi20.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/GoogleApi20.java
index 1e4bd8c6f..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,16 +23,31 @@ 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
public TokenExtractor getAccessTokenExtractor() {
return OpenIdJsonTokenExtractor.instance();
}
+
+ @Override
+ public String getRevokeTokenEndpoint() {
+ 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/HHApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/HHApi.java
index 2a8a8aa12..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
@@ -1,6 +1,8 @@
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 HHApi extends DefaultApi20 {
@@ -8,6 +10,7 @@ protected HHApi() {
}
private static class InstanceHolder {
+
private static final HHApi INSTANCE = new HHApi();
}
@@ -24,4 +27,9 @@ public String getAccessTokenEndpoint() {
protected String getAuthorizationBaseUrl() {
return "https://hh.ru/oauth/authorize";
}
+
+ @Override
+ public ClientAuthentication getClientAuthentication() {
+ return RequestBodyAuthenticationScheme.instance();
+ }
}
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..a69673a25
--- /dev/null
+++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/HiOrgServerApi20.java
@@ -0,0 +1,44 @@
+package com.github.scribejava.apis;
+
+import com.github.scribejava.core.builder.api.DefaultApi20;
+
+/**
+ * OAuth2 API for HiOrg-Server
+ *
+ * @see HiOrg-Server OAuth API documentation
+ */
+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";
+ }
+}
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..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
@@ -1,11 +1,13 @@
package com.github.scribejava.apis;
-import com.github.scribejava.apis.service.ImgurOAuthServiceImpl;
+import com.github.scribejava.apis.imgur.ImgurOAuthService;
import com.github.scribejava.core.builder.api.DefaultApi20;
-import com.github.scribejava.core.model.OAuthConfig;
+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.ParameterList;
-import com.github.scribejava.core.oauth.OAuth20Service;
+
+import java.io.OutputStream;
import java.util.Map;
public class ImgurApi extends DefaultApi20 {
@@ -14,6 +16,7 @@ protected ImgurApi() {
}
private static class InstanceHolder {
+
private static final ImgurApi INSTANCE = new ImgurApi();
}
@@ -27,22 +30,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);
}
@@ -56,11 +57,14 @@ protected String getAuthorizationBaseUrl() {
}
@Override
- public OAuth20Service createService(OAuthConfig config) {
- return new ImgurOAuthServiceImpl(this, config);
+ public ImgurOAuthService createService(String apiKey, String apiSecret, String callback, String defaultScope,
+ 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(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/InstagramApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/InstagramApi.java
new file mode 100644
index 000000000..85e408113
--- /dev/null
+++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/InstagramApi.java
@@ -0,0 +1,59 @@
+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.oauth2.clientauthentication.ClientAuthentication;
+import com.github.scribejava.core.oauth2.clientauthentication.RequestBodyAuthenticationScheme;
+
+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();
+ }
+
+ public static InstagramApi instance() {
+ return InstanceHolder.INSTANCE;
+ }
+
+ @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 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/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/KakaoApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/KakaoApi.java
new file mode 100644
index 000000000..6587fe32f
--- /dev/null
+++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/KakaoApi.java
@@ -0,0 +1,35 @@
+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/main/java/com/github/scribejava/apis/KeycloakApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/KeycloakApi.java
new file mode 100644
index 000000000..ed713b4d0
--- /dev/null
+++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/KeycloakApi.java
@@ -0,0 +1,63 @@
+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;
+
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+
+public class KeycloakApi extends DefaultApi20 {
+
+ private static final ConcurrentMap INSTANCES = new ConcurrentHashMap<>();
+
+ private final String baseUrlWithRealm;
+
+ protected KeycloakApi(String baseUrlWithRealm) {
+ this.baseUrlWithRealm = baseUrlWithRealm;
+ }
+
+ public static KeycloakApi instance() {
+ return instance("http://localhost:8080/", "master");
+ }
+
+ 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);
+ final KeycloakApi alreadyCreatedApi = INSTANCES.putIfAbsent(defaultBaseUrlWithRealm, api);
+ if (alreadyCreatedApi != null) {
+ return alreadyCreatedApi;
+ }
+ }
+ return api;
+ }
+
+ protected static String composeBaseUrlWithRealm(String baseUrl, String realm) {
+ return baseUrl + (baseUrl.endsWith("/") ? "" : "/") + "auth/realms/" + realm;
+ }
+
+ @Override
+ public String getAccessTokenEndpoint() {
+ return baseUrlWithRealm + "/protocol/openid-connect/token";
+ }
+
+ @Override
+ protected String getAuthorizationBaseUrl() {
+ return baseUrlWithRealm + "/protocol/openid-connect/auth";
+ }
+
+ @Override
+ public TokenExtractor getAccessTokenExtractor() {
+ return OpenIdJsonTokenExtractor.instance();
+ }
+
+ @Override
+ public String getRevokeTokenEndpoint() {
+ throw new RuntimeException("Not implemented yet");
+ }
+}
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/LinkedInApi20.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi20.java
index 0d22d705c..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,6 +1,8 @@
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 LinkedInApi20 extends DefaultApi20 {
@@ -24,4 +26,9 @@ public String getAccessTokenEndpoint() {
protected String getAuthorizationBaseUrl() {
return "https://www.linkedin.com/oauth/v2/authorization";
}
+
+ @Override
+ public ClientAuthentication getClientAuthentication() {
+ return RequestBodyAuthenticationScheme.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/MailruApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java
index a67e434c5..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
@@ -1,9 +1,11 @@
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.model.OAuthConfig;
-import com.github.scribejava.apis.service.MailruOAuthServiceImpl;
-import com.github.scribejava.core.oauth.OAuth20Service;
+import com.github.scribejava.core.httpclient.HttpClient;
+import com.github.scribejava.core.httpclient.HttpClientConfig;
public class MailruApi extends DefaultApi20 {
@@ -11,6 +13,7 @@ protected MailruApi() {
}
private static class InstanceHolder {
+
private static final MailruApi INSTANCE = new MailruApi();
}
@@ -29,7 +32,10 @@ protected String getAuthorizationBaseUrl() {
}
@Override
- public OAuth20Service createService(OAuthConfig config) {
- return new MailruOAuthServiceImpl(this, config);
+ public MailruOAuthService createService(String apiKey, String apiSecret, String callback, String defaultScope,
+ 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/MediaWikiApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/MediaWikiApi.java
new file mode 100644
index 000000000..3bb18001d
--- /dev/null
+++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/MediaWikiApi.java
@@ -0,0 +1,77 @@
+package com.github.scribejava.apis;
+
+import com.github.scribejava.core.builder.api.DefaultApi10a;
+
+public class MediaWikiApi extends DefaultApi10a {
+
+ private static class InstanceHolder {
+
+ 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.
+ */
+ 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
+ *
+ * Special:OAuthConsumerRegistration/propose
+ * .
+ *
+ * @return instance
+ */
+ public static MediaWikiApi instance() {
+ return InstanceHolder.INSTANCE;
+ }
+
+ /**
+ * The instance for wikis in the Wikimedia Foundation’s Beta Cluster. Consumers are requested on
+ *
+ * Special:OAuthConsumerRegistration/propose
+ * .
+ *
+ * @return instanceBeta
+ */
+ public static MediaWikiApi instanceBeta() {
+ return BetaInstanceHolder.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/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/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/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..399cf54c9
--- /dev/null
+++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/MicrosoftAzureActiveDirectory20Api.java
@@ -0,0 +1,48 @@
+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
+ *
+ * @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() {
+ this(COMMON_TENANT);
+ }
+
+ protected MicrosoftAzureActiveDirectory20Api(String tenant) {
+ super(tenant);
+ }
+
+ private static class InstanceHolder {
+
+ private static final MicrosoftAzureActiveDirectory20Api INSTANCE = new MicrosoftAzureActiveDirectory20Api();
+ }
+
+ 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
new file mode 100644
index 000000000..9ab4aa291
--- /dev/null
+++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/MicrosoftAzureActiveDirectoryApi.java
@@ -0,0 +1,64 @@
+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
+ *
+ * @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 BaseMicrosoftAzureActiveDirectoryApi {
+
+ private final String resource;
+
+ protected MicrosoftAzureActiveDirectoryApi() {
+ this(COMMON_TENANT, null);
+ }
+
+ protected MicrosoftAzureActiveDirectoryApi(String tenant, String resource) {
+ super(tenant);
+ this.resource = resource;
+ }
+
+ private static class InstanceHolder {
+
+ private static final MicrosoftAzureActiveDirectoryApi INSTANCE = new MicrosoftAzureActiveDirectoryApi();
+ }
+
+ 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/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..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
@@ -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() {
@@ -9,9 +10,6 @@ protected NaverApi() {
private static class InstanceHolder {
private static final NaverApi INSTANCE = new NaverApi();
-
- private InstanceHolder() {
- }
}
public static NaverApi instance() {
@@ -29,7 +27,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/NeteaseWeibooApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/NeteaseWeibooApi.java
deleted file mode 100644
index 91edb38ca..000000000
--- a/scribejava-apis/src/main/java/com/github/scribejava/apis/NeteaseWeibooApi.java
+++ /dev/null
@@ -1,61 +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.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 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 getAuthorizationUrl(OAuth1RequestToken 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(OAuth1Token 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 f8e1a40ef..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
@@ -1,10 +1,15 @@
package com.github.scribejava.apis;
-import com.github.scribejava.apis.service.OdnoklassnikiServiceImpl;
+import java.io.OutputStream;
+
+import com.github.scribejava.apis.odnoklassniki.OdnoklassnikiOAuthService;
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;
+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;
public class OdnoklassnikiApi extends DefaultApi20 {
@@ -12,6 +17,7 @@ protected OdnoklassnikiApi() {
}
private static class InstanceHolder {
+
private static final OdnoklassnikiApi INSTANCE = new OdnoklassnikiApi();
}
@@ -30,12 +36,20 @@ protected String getAuthorizationBaseUrl() {
}
@Override
- public OAuth20Service createService(OAuthConfig config) {
- return new OdnoklassnikiServiceImpl(this, config);
+ public OdnoklassnikiOAuthService createService(String apiKey, String apiSecret, String callback,
+ 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
+ public BearerSignature getBearerSignature() {
+ return BearerSignatureURIQueryParameter.instance();
}
@Override
- public OAuth2SignatureType getSignatureType() {
- return OAuth2SignatureType.BEARER_URI_QUERY_PARAMETER;
+ 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 d93404b5e..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.DefaultApi20;
-import com.github.scribejava.core.builder.api.OAuth2SignatureType;
+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 OAuth2SignatureType getSignatureType() {
- return OAuth2SignatureType.BEARER_URI_QUERY_PARAMETER;
+ public ClientAuthentication getClientAuthentication() {
+ return RequestBodyAuthenticationScheme.instance();
}
}
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/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/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/SalesforceApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/SalesforceApi.java
index 95e5e2816..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
@@ -7,17 +7,19 @@
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;
+import java.util.Arrays;
import javax.net.ssl.SSLSocket;
/**
* 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 {
@@ -49,6 +51,7 @@ protected SalesforceApi(String hostName) {
}
private static class InstanceHolder {
+
private static final SalesforceApi INSTANCE = new SalesforceApi(PRODUCTION_HOST);
}
@@ -82,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;
}
}
@@ -95,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()}
@@ -105,28 +108,23 @@ 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;
- }
- if ("TLSv1.1".equals(protocol)) {
- supportTLSv11 = true;
+ 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;
}
}
- 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");
- }
+ throw new NoSuchAlgorithmException("for Salesforce API to work you need jvm with TLS 1.1 or higher support");
+ }
- context.init(null, null, null);
- SSLContext.setDefault(context);
+ @Override
+ public ClientAuthentication getClientAuthentication() {
+ return RequestBodyAuthenticationScheme.instance();
}
}
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/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/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/SlackApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/SlackApi.java
new file mode 100644
index 000000000..4d834fff1
--- /dev/null
+++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/SlackApi.java
@@ -0,0 +1,37 @@
+package com.github.scribejava.apis;
+
+import com.github.scribejava.apis.slack.SlackJsonTokenExtractor;
+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/SohuWeiboApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/SohuWeiboApi.java
deleted file mode 100644
index 6ef769c6a..000000000
--- a/scribejava-apis/src/main/java/com/github/scribejava/apis/SohuWeiboApi.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 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";
-
- 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 getAuthorizationUrl(OAuth1RequestToken requestToken) {
- return String.format(AUTHORIZE_URL, requestToken.getToken());
- }
-}
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/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 1d7a9e93f..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,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 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 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";
protected TumblrApi() {
}
@@ -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/TutByApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/TutByApi.java
index 6928ba70a..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,9 +1,8 @@
package com.github.scribejava.apis;
+import com.github.scribejava.apis.tutby.TutByBearerSignature;
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;
+import com.github.scribejava.core.oauth2.bearersignature.BearerSignature;
public class TutByApi extends DefaultApi20 {
@@ -29,7 +28,7 @@ protected String getAuthorizationBaseUrl() {
}
@Override
- public OAuth20Service createService(OAuthConfig config) {
- return new TutByOAuthServiceImpl(this, config);
+ public BearerSignature getBearerSignature() {
+ return TutByBearerSignature.instance();
}
}
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
new file mode 100644
index 000000000..1a8992704
--- /dev/null
+++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/UcozApi.java
@@ -0,0 +1,48 @@
+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";
+
+ 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 getAuthorizationBaseUrl() {
+ return AUTHORIZE_URL;
+ }
+
+ @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/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 285cb2cde..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
@@ -1,15 +1,24 @@
package com.github.scribejava.apis;
+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;
public class VkontakteApi extends DefaultApi20 {
+ public static final String VERSION = "5.92";
+
protected VkontakteApi() {
}
private static class InstanceHolder {
+
private static final VkontakteApi INSTANCE = new VkontakteApi();
}
@@ -29,11 +38,21 @@ public String getAccessTokenEndpoint() {
@Override
protected String getAuthorizationBaseUrl() {
- return "https://oauth.vk.com/authorize";
+ return "https://oauth.vk.com/authorize?v=" + VERSION;
+ }
+
+ @Override
+ public BearerSignature getBearerSignature() {
+ return BearerSignatureURIQueryParameter.instance();
+ }
+
+ @Override
+ public ClientAuthentication getClientAuthentication() {
+ return RequestBodyAuthenticationScheme.instance();
}
@Override
- public OAuth2SignatureType getSignatureType() {
- return OAuth2SignatureType.BEARER_URI_QUERY_PARAMETER;
+ public TokenExtractor getAccessTokenExtractor() {
+ return VKJsonTokenExtractor.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
new file mode 100644
index 000000000..abf19db92
--- /dev/null
+++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/WunderlistAPI.java
@@ -0,0 +1,58 @@
+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;
+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;
+
+/**
+ * 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 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,
+ userAgent, httpClientConfig, httpClient);
+ }
+}
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..2141ed007
--- /dev/null
+++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/XeroApi20.java
@@ -0,0 +1,31 @@
+package com.github.scribejava.apis;
+
+import com.github.scribejava.core.builder.api.DefaultApi20;
+
+/**
+ * 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";
+ }
+}
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-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..bc50f6779
--- /dev/null
+++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/YahooApi20.java
@@ -0,0 +1,27 @@
+package com.github.scribejava.apis;
+
+import com.github.scribejava.core.builder.api.DefaultApi20;
+
+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";
+ }
+}
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..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,8 @@
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;
/**
@@ -14,47 +16,47 @@
* '{"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 String code;
+ private final int codeInt;
private final String fbtraceId;
- private final String rawResponse;
- public FacebookAccessTokenErrorResponse(String message, String type, String code, String fbtraceId,
- String rawResponse) {
- 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.code = code;
+ this.codeInt = code;
this.fbtraceId = fbtraceId;
- this.rawResponse = rawResponse;
+ }
+
+ public String getErrorMessage() {
+ return errorMessage;
}
public String getType() {
return type;
}
- public String getCode() {
- return code;
+ public int getCodeInt() {
+ return codeInt;
}
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());
+ int hash = super.hashCode();
+ hash = 83 * hash + Objects.hashCode(errorMessage);
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;
}
@@ -70,17 +72,19 @@ public boolean equals(Object obj) {
if (getClass() != obj.getClass()) {
return false;
}
- final FacebookAccessTokenErrorResponse other = (FacebookAccessTokenErrorResponse) obj;
- if (!Objects.equals(rawResponse, other.getRawResponse())) {
+ 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())) {
return false;
}
- if (!Objects.equals(code, other.getCode())) {
+ if (codeInt != other.getCodeInt()) {
return false;
}
return Objects.equals(fbtraceId, other.getFbtraceId());
@@ -88,8 +92,8 @@ public boolean equals(Object obj) {
@Override
public String toString() {
- return "FacebookAccessTokenErrorResponse{'type'='" + type + "', 'code'='" + code
- + "', 'fbtraceId'='" + fbtraceId + "', 'rawResponse'='" + rawResponse
- + "', 'message'='" + getMessage() + "'}";
+ return "FacebookAccessTokenErrorResponse{'type'='" + type + "', 'codeInt'='" + codeInt
+ + "', 'fbtraceId'='" + fbtraceId + "', 'response'='" + getResponse()
+ + "', 'errorMessage'='" + errorMessage + "'}";
}
}
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..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
@@ -1,18 +1,15 @@
package com.github.scribejava.apis.facebook;
+import com.fasterxml.jackson.databind.JsonNode;
import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor;
-import java.util.regex.Pattern;
+import com.github.scribejava.core.model.Response;
+import java.io.IOException;
/**
* 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() {
}
@@ -33,15 +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
- protected void generateError(String response) {
- extractParameter(response, MESSAGE_REGEX_PATTERN, false);
+ public void generateError(Response response) throws IOException {
+ final JsonNode errorNode = OAuth2AccessTokenJsonExtractor.OBJECT_MAPPER
+ .readTree(response.getBody())
+ .get("error");
- 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(errorNode.get("message").asText(), errorNode.get("type").asText(),
+ errorNode.get("code").asInt(), errorNode.get("fbtrace_id").asText(), response);
}
}
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..efb53a4f3
--- /dev/null
+++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookService.java
@@ -0,0 +1,46 @@
+package com.github.scribejava.apis.facebook;
+
+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;
+import com.github.scribejava.core.oauth.OAuth20Service;
+
+import java.io.OutputStream;
+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(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,
+ 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/fitbit/FitBitJsonTokenExtractor.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractor.java
new file mode 100644
index 000000000..24ed6025a
--- /dev/null
+++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractor.java
@@ -0,0 +1,55 @@
+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;
+
+public class FitBitJsonTokenExtractor extends OAuth2AccessTokenJsonExtractor {
+
+ 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, JsonNode response, String rawResponse) {
+ return new FitBitOAuth2AccessToken(accessToken, tokenType, expiresIn, refreshToken, scope,
+ response.get("user_id").asText(), rawResponse);
+ }
+
+ /**
+ * Related documentation: https://dev.fitbit.com/build/reference/web-api/oauth2/
+ */
+ @Override
+ 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", response.getBody()).asText());
+ } catch (IllegalArgumentException iaE) {
+ //non oauth standard error code
+ errorCode = null;
+ }
+
+ throw new OAuth2AccessTokenErrorResponse(errorCode, errorNode.get("message").asText(), null, 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/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/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);
- }
-}
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..317934e35
--- /dev/null
+++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/imgur/ImgurOAuthService.java
@@ -0,0 +1,53 @@
+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;
+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 {
+
+ 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,
+ httpClient);
+ }
+
+ @Override
+ 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);
+ } else {
+ 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;
+ }
+
+ @Override
+ public void signRequest(String accessToken, OAuthRequest request) {
+ request.addHeader(OAuthConstants.HEADER,
+ accessToken == null ? "Client-ID " + getApiKey() : "Bearer " + accessToken);
+ }
+}
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..bae3454a2
--- /dev/null
+++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/instagram/InstagramAccessTokenErrorResponse.java
@@ -0,0 +1,84 @@
+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.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 OAuthResponseException {
+
+ private static final long serialVersionUID = -1277129706699856895L;
+
+ private final String errorType;
+ private final int code;
+ private final String errorMessage;
+ private final transient Response response;
+
+ public InstagramAccessTokenErrorResponse(String errorType, int code, String errorMessage, Response response)
+ throws IOException {
+ super(response);
+ this.errorType = errorType;
+ this.code = code;
+ this.errorMessage = errorMessage;
+ this.response = response;
+ }
+
+ public String getErrorType() {
+ return errorType;
+ }
+
+ public int getCode() {
+ return code;
+ }
+
+ public String getErrorMessage() {
+ return errorMessage;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null || getClass() != obj.getClass()) {
+ return false;
+ }
+ if (!super.equals(obj)) {
+ return false;
+ }
+
+ final InstagramAccessTokenErrorResponse that = (InstagramAccessTokenErrorResponse) obj;
+ if (!Objects.equals(errorMessage, that.getErrorMessage())) {
+ return false;
+ }
+ return code == that.code && Objects.equals(errorType, that.errorType)
+ && Objects.equals(response, that.response);
+ }
+
+ @Override
+ public int hashCode() {
+ int hash = super.hashCode();
+ hash = 83 * hash + Objects.hashCode(response);
+ hash = 83 * hash + Objects.hashCode(errorMessage);
+ hash = 83 * hash + Objects.hashCode(errorType);
+ hash = 83 * hash + Objects.hashCode(code);
+ return hash;
+ }
+
+ @Override
+ public String toString() {
+ 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
new file mode 100644
index 000000000..8f30b2e96
--- /dev/null
+++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/instagram/InstagramAccessTokenJsonExtractor.java
@@ -0,0 +1,55 @@
+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 Instagram 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());
+ final 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..5de1f3782
--- /dev/null
+++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/instagram/InstagramService.java
@@ -0,0 +1,105 @@
+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.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 {
+
+ 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);
+ }
+
+ /**
+ * 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
+ * @throws java.lang.InterruptedException
+ * @throws java.util.concurrent.ExecutionException
+ * @throws java.io.IOException
+ */
+ 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;
+ }
+}
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..a9ff7d77b
--- /dev/null
+++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/mailru/MailruOAuthService.java
@@ -0,0 +1,74 @@
+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.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.OutputStream;
+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(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,
+ 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/microsoftazureactivedirectory/BaseMicrosoftAzureActiveDirectoryApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/microsoftazureactivedirectory/BaseMicrosoftAzureActiveDirectoryApi.java
new file mode 100644
index 000000000..5e4891164
--- /dev/null
+++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/microsoftazureactivedirectory/BaseMicrosoftAzureActiveDirectoryApi.java
@@ -0,0 +1,41 @@
+package com.github.scribejava.apis.microsoftazureactivedirectory;
+
+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 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 OAUTH_2 = "/oauth2";
+ private final String tenant;
+
+ protected BaseMicrosoftAzureActiveDirectoryApi() {
+ this(COMMON_TENANT);
+ }
+
+ protected BaseMicrosoftAzureActiveDirectoryApi(String tenant) {
+ this.tenant = tenant == null || tenant.isEmpty() ? COMMON_TENANT : tenant;
+ }
+
+ @Override
+ public String getAccessTokenEndpoint() {
+ return MSFT_LOGIN_URL + tenant + OAUTH_2 + getEndpointVersionPath() + "/token";
+ }
+
+ @Override
+ protected String getAuthorizationBaseUrl() {
+ return MSFT_LOGIN_URL + tenant + OAUTH_2 + getEndpointVersionPath() + "/authorize";
+ }
+
+ @Override
+ public ClientAuthentication getClientAuthentication() {
+ return RequestBodyAuthenticationScheme.instance();
+ }
+
+ protected String getEndpointVersionPath() {
+ return "";
+ }
+}
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
new file mode 100644
index 000000000..bfddd523a
--- /dev/null
+++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/microsoftazureactivedirectory/MicrosoftAzureActiveDirectoryBearerSignature.java
@@ -0,0 +1,18 @@
+package com.github.scribejava.apis.microsoftazureactivedirectory;
+
+public class MicrosoftAzureActiveDirectoryBearerSignature extends BaseMicrosoftAzureActiveDirectoryBearerSignature {
+
+ protected MicrosoftAzureActiveDirectoryBearerSignature() {
+ super("application/json; odata=minimalmetadata; streaming=true; charset=utf-8");
+ }
+
+ private static class InstanceHolder {
+
+ private static final MicrosoftAzureActiveDirectoryBearerSignature INSTANCE
+ = new MicrosoftAzureActiveDirectoryBearerSignature();
+ }
+
+ public static MicrosoftAzureActiveDirectoryBearerSignature instance() {
+ return InstanceHolder.INSTANCE;
+ }
+}
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..fd1327a6d
--- /dev/null
+++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/odnoklassniki/OdnoklassnikiOAuthService.java
@@ -0,0 +1,72 @@
+package com.github.scribejava.apis.odnoklassniki;
+
+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;
+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;
+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(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,
+ 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/openid/OpenIdJsonTokenExtractor.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/openid/OpenIdJsonTokenExtractor.java
index bec8b0613..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
@@ -1,15 +1,13 @@
package com.github.scribejava.apis.openid;
+import com.fasterxml.jackson.databind.JsonNode;
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() {
}
@@ -24,8 +22,9 @@ public static OpenIdJsonTokenExtractor instance() {
@Override
protected OpenIdOAuth2AccessToken createToken(String accessToken, String tokenType, Integer expiresIn,
- String refreshToken, String scope, String response) {
+ String refreshToken, String scope, JsonNode response, String rawResponse) {
+ final JsonNode idToken = response.get("id_token");
return new OpenIdOAuth2AccessToken(accessToken, tokenType, expiresIn, refreshToken, scope,
- extractParameter(response, ID_TOKEN_REGEX_PATTERN, false), response);
+ idToken == null ? null : idToken.asText(), rawResponse);
}
}
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/polar/PolarJsonTokenExtractor.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/polar/PolarJsonTokenExtractor.java
new file mode 100644
index 000000000..1258dfe59
--- /dev/null
+++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/polar/PolarJsonTokenExtractor.java
@@ -0,0 +1,55 @@
+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;
+
+/**
+ * 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(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", response.getBody()).asText());
+ } catch (IllegalArgumentException iaE) {
+ //non oauth standard error code
+ errorCode = null;
+ }
+
+ throw new OAuth2AccessTokenErrorResponse(errorCode, errorNode.get("message").asText(), null, response);
+ }
+}
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..99710728f
--- /dev/null
+++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/polar/PolarOAuth2AccessToken.java
@@ -0,0 +1,47 @@
+package com.github.scribejava.apis.polar;
+
+import com.github.scribejava.core.model.OAuth2AccessToken;
+
+import java.util.Objects;
+
+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,
+ 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..c016d6ac7
--- /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.apis.PolarAPI;
+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(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,
+ 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/salesforce/SalesforceJsonTokenExtractor.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/salesforce/SalesforceJsonTokenExtractor.java
index 841276724..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.regex.Pattern;
/**
* 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, JsonNode response, String rawResponse) {
return new SalesforceToken(accessToken, tokenType, expiresIn, refreshToken, scope,
- extractParameter(response, INSTANCE_URL_REGEX_PATTERN, true), response);
+ extractRequiredParameter(response, "instance_url", rawResponse).asText(), rawResponse);
}
}
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/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 c0f74aab6..000000000
--- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthServiceImpl.java
+++ /dev/null
@@ -1,41 +0,0 @@
-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.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 {
-
- 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(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/MailruOAuthServiceImpl.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthServiceImpl.java
deleted file mode 100644
index 3330bb006..000000000
--- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthServiceImpl.java
+++ /dev/null
@@ -1,51 +0,0 @@
-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.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 {
-
- public MailruOAuthServiceImpl(DefaultApi20 api, OAuthConfig config) {
- super(api, config);
- }
-
- @Override
- public void signRequest(OAuth2AccessToken accessToken, OAuthRequest request) {
- // sig = md5(params + secret_key)
- request.addQuerystringParameter("session_key", accessToken.getAccessToken());
- 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 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);
- }
- }
-}
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 fa9ae2e56..000000000
--- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiServiceImpl.java
+++ /dev/null
@@ -1,50 +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.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 static org.apache.commons.codec.digest.DigestUtils.md5Hex;
-
-public class OdnoklassnikiServiceImpl extends OAuth20Service {
-
- public OdnoklassnikiServiceImpl(DefaultApi20 api, OAuthConfig config) {
- super(api, config);
- }
-
- @Override
- 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());
-
- final ParameterList queryParams = request.getQueryStringParams();
- queryParams.addAll(request.getBodyParams());
- 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;
- 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/TutByOAuthServiceImpl.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/TutByOAuthServiceImpl.java
deleted file mode 100644
index f1f14485f..000000000
--- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/TutByOAuthServiceImpl.java
+++ /dev/null
@@ -1,20 +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.OAuthConstants;
-import com.github.scribejava.core.model.OAuthRequest;
-import com.github.scribejava.core.oauth.OAuth20Service;
-
-public class TutByOAuthServiceImpl extends OAuth20Service {
-
- public TutByOAuthServiceImpl(DefaultApi20 api, OAuthConfig config) {
- super(api, config);
- }
-
- @Override
- public void signRequest(OAuth2AccessToken accessToken, OAuthRequest request) {
- request.addQuerystringParameter(OAuthConstants.TOKEN, accessToken.getAccessToken());
- }
-}
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..ca0be7587
--- /dev/null
+++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/slack/SlackJsonTokenExtractor.java
@@ -0,0 +1,34 @@
+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) {
+ final String userAccessToken;
+ final JsonNode userAccessTokenNode = response.get("authed_user").get("access_token");
+ if (userAccessTokenNode == null) {
+ userAccessToken = "";
+ } else {
+ 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..d1d28ad7b
--- /dev/null
+++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/slack/SlackOAuth2AccessToken.java
@@ -0,0 +1,47 @@
+package com.github.scribejava.apis.slack;
+
+import com.github.scribejava.core.model.OAuth2AccessToken;
+
+import java.util.Objects;
+
+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) {
+ 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/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);
+ }
+}
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..a3d14aacf
--- /dev/null
+++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/vk/VKJsonTokenExtractor.java
@@ -0,0 +1,30 @@
+package com.github.scribejava.apis.vk;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor;
+
+/**
+ * additionally parses email
+ */
+public class VKJsonTokenExtractor extends OAuth2AccessTokenJsonExtractor {
+
+ 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, 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/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/main/java/com/github/scribejava/apis/wunderlist/WunderlistOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/wunderlist/WunderlistOAuthService.java
new file mode 100644
index 000000000..06a248d9c
--- /dev/null
+++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/wunderlist/WunderlistOAuthService.java
@@ -0,0 +1,25 @@
+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;
+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 defaultScope, String responseType, OutputStream debugStream, String userAgent,
+ HttpClientConfig httpClientConfig, HttpClient httpClient) {
+ super(api, apiKey, apiSecret, callback, defaultScope, responseType, debugStream, 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/ExampleUtils.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/ExampleUtils.java
new file mode 100644
index 000000000..5f60abcb1
--- /dev/null
+++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/ExampleUtils.java
@@ -0,0 +1,55 @@
+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 TrustAllCertsManager()
+ };
+
+ 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);
+ }
+ }
+
+ 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-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..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
@@ -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/";
@@ -23,6 +23,7 @@ public final 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)
@@ -46,22 +47,22 @@ 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!");
- System.out.println("(if your curious it looks like this: " + accessToken
- + ", 'rawResponse'='" + 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!
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
new file mode 100644
index 000000000..1ab4d3d3c
--- /dev/null
+++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AsanaExample.java
@@ -0,0 +1,82 @@
+package com.github.scribejava.apis.examples;
+
+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;
+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 AsanaExample {
+
+ private static final String PROTECTED_RESOURCE_URL = "https://app.asana.com/api/1.0/users/me";
+
+ 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";
+ final String secretState = "secret" + new Random().nextInt(999_999);
+ final OAuth20Service service = new ServiceBuilder(apiKey)
+ .apiSecret(apiSecret)
+ .callback("https://localhost/")
+ .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(secretState);
+ 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...");
+ 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);
+ 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
new file mode 100644
index 000000000..ae0c299f2
--- /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 class AutomaticExample {
+
+ private static final String NETWORK_NAME = "Automatic";
+ private static final String PROTECTED_RESOURCE_URL = "https://api.automatic.com/user/me/";
+
+ 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";
+ final String clientSecret = "your client secret";
+ final String secretState = "secret" + new Random().nextInt(999_999);
+ final OAuth20Service service = new ServiceBuilder(clientId)
+ .apiSecret(clientSecret)
+ .callback("http://www.example.com/oauth_callback/")
+ .defaultScope("scope:user:profile")
+ .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(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();
+ }
+
+ // 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);
+ 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 de8a1c1ed..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
@@ -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";
@@ -22,6 +22,7 @@ public final 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";
@@ -29,7 +30,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");
@@ -42,9 +42,12 @@ 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.getAuthorizationUrl(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);
@@ -65,12 +68,10 @@ 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("(If you're curious, it looks like this: " + accessToken
- + ", 'rawResponse'='" + accessToken.getRawResponse() + "')");
+ System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')");
System.out.println();
@@ -78,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
new file mode 100644
index 000000000..fe8fada2a
--- /dev/null
+++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DataportenExample.java
@@ -0,0 +1,80 @@
+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 class DataportenExample {
+
+ private static final String NETWORK_NAME = "Dataporten";
+ private static final String PROTECTED_RESOURCE_URL = "https://auth.dataporten.no/userinfo";
+
+ 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";
+ final String clientSecret = "your client secret";
+ final String secretState = "secret" + new Random().nextInt(999_999);
+ final OAuth20Service service = new ServiceBuilder(clientId)
+ .apiSecret(clientSecret)
+ .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(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! :)");
+ }
+}
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..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
@@ -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";
@@ -20,6 +20,7 @@ public final 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";
@@ -49,12 +50,11 @@ 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!");
- System.out.println("(if your curious it looks like this: " + accessToken
- + ", 'rawResponse'='" + 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!
@@ -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
new file mode 100644
index 000000000..f42bde9ec
--- /dev/null
+++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiscordExample.java
@@ -0,0 +1,90 @@
+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 class DiscordExample {
+
+ private static final String NETWORK_NAME = "Discord";
+ private static final String PROTECTED_RESOURCE_URL = "https://discordapp.com/api/users/@me";
+
+ 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";
+ final String clientSecret = "client secret";
+ final String secretState = "secret" + new Random().nextInt(999_999);
+ final OAuth20Service service = new ServiceBuilder(clientId)
+ .apiSecret(clientSecret)
+ .defaultScope("identify") // replace with desired scope
+ .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(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...");
+ 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);
+ 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
new file mode 100644
index 000000000..bcf02624a
--- /dev/null
+++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DropboxExample.java
@@ -0,0 +1,74 @@
+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";
+
+ 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";
+ 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);
+
+ 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
new file mode 100644
index 000000000..ad55cb07c
--- /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 class EtsyExample {
+
+ private static final String PROTECTED_RESOURCE_URL = "https://openapi.etsy.com/v2/users/__SELF__";
+
+ 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")
+ .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("(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.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/FacebookExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java
index 521020e29..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
@@ -12,14 +12,15 @@
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.8/me";
+ private static final String PROTECTED_RESOURCE_URL = "https://graph.facebook.com/v3.2/me";
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";
@@ -27,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(FacebookApi.instance());
@@ -38,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);
@@ -59,24 +59,22 @@ 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("(if your curious it looks like this: " + accessToken
- + ", 'rawResponse'='" + 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!
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
new file mode 100644
index 000000000..e5818a92a
--- /dev/null
+++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FitbitApi20Example.java
@@ -0,0 +1,81 @@
+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;
+import com.github.scribejava.core.model.Response;
+import com.github.scribejava.core.model.Verb;
+import com.github.scribejava.core.oauth.OAuth20Service;
+
+public class FitbitApi20Example {
+
+ private static final String NETWORK_NAME = "Fitbit";
+
+ private static final String PROTECTED_RESOURCE_URL = "https://api.fitbit.com/1/user/%s/profile.json";
+
+ private FitbitApi20Example() {
+ }
+
+ @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 client id";
+ final String clientSecret = "your client secret";
+ final OAuth20Service service = new ServiceBuilder(clientId)
+ .apiSecret(clientSecret)
+ .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());
+ 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...");
+ final OAuth2AccessToken oauth2AccessToken = service.getAccessToken(code);
+ System.out.println("Got the Access Token!");
+ 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.");
+ return;
+ }
+
+ 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,
+ String.format(PROTECTED_RESOURCE_URL, accessToken.getUserId()));
+ request.addHeader("x-li-format", "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/FlickrExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExample.java
index e5809874f..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
@@ -13,13 +13,14 @@
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/";
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";
@@ -47,12 +48,11 @@ 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!");
- System.out.println("(if your curious it looks like this: " + accessToken
- + ", 'rawResponse'='" + 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!
@@ -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 33e6206ef..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
@@ -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=";
@@ -19,6 +19,7 @@ public final 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";
@@ -43,24 +44,22 @@ 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("(if your curious it looks like this: " + accessToken
- + ", 'rawResponse'='" + 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!
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 afaaca188..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
@@ -12,13 +12,14 @@
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";
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")
@@ -41,23 +42,22 @@ 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!");
- System.out.println("(if your curious it looks like this: " + accessToken
- + ", 'rawResponse'='" + 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!
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 fe704ed7a..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
@@ -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";
@@ -19,6 +19,7 @@ public final 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";
@@ -26,7 +27,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");
@@ -49,21 +50,19 @@ 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("(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, 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 a17f896de..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
@@ -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
@@ -23,10 +23,11 @@ public final 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")
- .scope(SCOPE)
+ .withScope(SCOPE)
.build(FreelancerApi.Sandbox.instance());
final Scanner in = new Scanner(System.in);
@@ -37,7 +38,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("(The raw response looks like this: " + requestToken.getRawResponse() + "')");
System.out.println();
System.out.println("Now go and authorize ScribeJava here:");
@@ -47,12 +48,11 @@ 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!");
- System.out.println("(if your curious it looks like this: " + accessToken
- + ", 'rawResponse'='" + 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!
@@ -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 af515b79c..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
@@ -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";
@@ -20,6 +20,7 @@ public final 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";
@@ -27,8 +28,7 @@ public static void main(String... args) throws IOException, InterruptedException
final String secretState = "100";
final OAuth20Service service = new ServiceBuilder(clientId)
.apiSecret(clientSecret)
- .scope("me")
- .state(secretState)
+ .defaultScope("me")
.callback("com.scribejavatest://callback")
.userAgent("ScribeJava")
.build(GeniusApi.instance());
@@ -38,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);
@@ -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 596a14a45..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
@@ -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";
@@ -22,6 +22,7 @@ public final 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";
@@ -29,7 +30,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 +40,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);
@@ -62,24 +62,23 @@ 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("(if your curious it looks like this: " + accessToken
- + ", 'rawResponse'='" + 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!
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 8c3444d92..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
@@ -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";
@@ -20,6 +20,7 @@ public final 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";
@@ -27,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(GitHubApi.instance());
final Scanner in = new Scanner(System.in, "UTF-8");
@@ -37,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);
@@ -58,24 +58,22 @@ 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("(if your curious it looks like this: " + accessToken
- + ", 'rawResponse'='" + 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!
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/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-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..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
@@ -17,14 +17,15 @@
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";
+ private static final String NETWORK_NAME = "Google Async";
+ private static final String PROTECTED_RESOURCE_URL = "https://www.googleapis.com/oauth2/v3/userinfo";
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";
@@ -39,8 +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)
+ .defaultScope("profile") // replace with desired scope
.callback("http://example.com/callback")
.httpClientConfig(clientConfig)
.build(GoogleApi20.instance())) {
@@ -55,9 +55,12 @@ 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.getAuthorizationUrl(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);
@@ -79,18 +82,17 @@ 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("(if your curious it looks like this: " + accessToken
- + ", 'rawResponse'='" + 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 it looks like this: " + accessToken
- + ", 'rawResponse'='" + 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!
@@ -112,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/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 e9e2adf27..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
@@ -14,23 +14,23 @@
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";
+ private static final String NETWORK_NAME = "Google";
+ private static final String PROTECTED_RESOURCE_URL = "https://www.googleapis.com/oauth2/v3/userinfo";
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)
- .scope("profile") // replace with desired scope
- .state(secretState)
+ .defaultScope("profile") // replace with desired scope
.callback("http://example.com/callback")
.build(GoogleApi20.instance());
final Scanner in = new Scanner(System.in, "UTF-8");
@@ -44,9 +44,12 @@ 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.getAuthorizationUrl(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);
@@ -67,18 +70,15 @@ 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("(if your curious it looks like this: " + accessToken
- + ", 'rawResponse'='" + 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 it looks like this: " + accessToken
- + ", 'rawResponse'='" + 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!
@@ -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
new file mode 100644
index 000000000..ba513ca52
--- /dev/null
+++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20RevokeExample.java
@@ -0,0 +1,109 @@
+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 = "Google";
+ private static final String PROTECTED_RESOURCE_URL = "https://www.googleapis.com/oauth2/v3/userinfo";
+
+ 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";
+ final String clientSecret = "your client secret";
+ final String secretState = "secret" + new Random().nextInt(999_999);
+ final OAuth20Service service = new ServiceBuilder(clientId)
+ .apiSecret(clientSecret)
+ .defaultScope("profile") // replace with desired scope
+ .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 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...");
+ final OAuth2AccessToken accessToken = service.getAccessToken(code);
+ 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...");
+ OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL);
+ 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();
+ System.out.println("Revoking token...");
+ service.revokeToken(accessToken.getAccessToken());
+ System.out.println("done.");
+ 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.
+ int responseCode;
+ do {
+ Thread.sleep(1000);
+ request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL);
+ service.signRequest(accessToken, request);
+ System.out.println();
+ 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
new file mode 100644
index 000000000..8c840b8d5
--- /dev/null
+++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20WithPKCEExample.java
@@ -0,0 +1,117 @@
+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.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 java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.ExecutionException;
+
+public class Google20WithPKCEExample {
+
+ private static final String NETWORK_NAME = "Google";
+ private static final String PROTECTED_RESOURCE_URL = "https://www.googleapis.com/oauth2/v3/userinfo";
+
+ 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";
+ final String clientSecret = "your client secret";
+ final String secretState = "secret" + new Random().nextInt(999_999);
+ final OAuth20Service service = new ServiceBuilder(clientId)
+ .apiSecret(clientSecret)
+ .defaultScope("profile") // replace with desired scope
+ .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 user are asked not the first time)
+ additionalParams.put("prompt", "consent");
+
+ 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(authorizationUrlBuilder.build());
+ 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(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() + "')");
+
+ 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-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..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
@@ -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";
@@ -21,6 +21,7 @@ public final 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";
@@ -45,23 +46,21 @@ 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("(if your curious it looks like this: " + accessToken
- + ", 'rawResponse'='" + 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...");
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
new file mode 100644
index 000000000..2602d1257
--- /dev/null
+++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HiOrgServerExample.java
@@ -0,0 +1,92 @@
+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() {
+ }
+
+ @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("basic eigenedaten")
+ .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(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...");
+ 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);
+ 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 35f6d9a31..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
@@ -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";
@@ -20,6 +20,7 @@ public final 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";
@@ -47,20 +48,19 @@ 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("(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());
-
+ 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/InstagramExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/InstagramExample.java
new file mode 100644
index 000000000..9694ba909
--- /dev/null
+++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/InstagramExample.java
@@ -0,0 +1,97 @@
+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! :)");
+
+ 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...");
+ 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/examples/Kaixin20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Kaixin20Example.java
index 6d61a613b..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
@@ -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";
@@ -19,6 +19,7 @@ public final 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";
@@ -47,20 +48,19 @@ 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("(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());
-
+ 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/KakaoExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/KakaoExample.java
new file mode 100644
index 000000000..643182ea8
--- /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 this with your client id
+ 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! :)");
+
+ }
+}
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
new file mode 100644
index 000000000..2d78ffb97
--- /dev/null
+++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/KeycloakExample.java
@@ -0,0 +1,72 @@
+package com.github.scribejava.apis.examples;
+
+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;
+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 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";
+ 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)
+ .defaultScope("openid")
+ .callback(callback)
+ .build(KeycloakApi.instance(baseUrl, realm));
+ 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();
+
+ 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, protectedResourceUrl);
+ 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! :)");
+
+ }
+}
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..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,31 +3,35 @@
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;
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 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)";
+ 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() {
}
+ @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)
.apiSecret(clientSecret)
- .scope("r_basicprofile r_emailaddress") // replace with desired scope
+ .defaultScope(new ScopeBuilder("r_liteprofile", "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 +40,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();
+ 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);
@@ -45,36 +50,36 @@ 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("(if your curious it looks like this: " + accessToken
- + ", 'rawResponse'='" + 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!
- 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);
+ System.out.println();
+ try (Response emailResponse = service.execute(emailRequest)) {
+ System.out.println(emailResponse.getCode());
+ System.out.println(emailResponse.getBody());
+ }
+ System.out.println();
- if ("exit".equals(query)) {
- break;
- }
+ System.out.println("Now we're going to access a protected profile resource...");
- 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();
+ 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);
+ System.out.println();
+ try (Response response = service.execute(request)) {
System.out.println(response.getCode());
System.out.println(response.getBody());
-
- System.out.println();
}
+
+ 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 02ae520c1..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
@@ -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)";
@@ -20,6 +20,7 @@ public final 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")
@@ -42,22 +43,22 @@ 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!");
- System.out.println("(if your curious it looks like this: " + accessToken
- + ", 'rawResponse'='" + 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!
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 a8247f65c..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
@@ -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)";
@@ -20,6 +20,7 @@ public final 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";
@@ -46,22 +47,22 @@ 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!");
- System.out.println("(if your curious it looks like this: " + accessToken
- + ", 'rawResponse'='" + 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!
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 09fabe03a..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
@@ -11,20 +11,21 @@
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";
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 = "";
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);
@@ -43,23 +44,22 @@ 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("(if your curious it looks like this: " + accessToken
- + ", 'rawResponse'='" + 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!
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 2c566e99b..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
@@ -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
@@ -22,6 +22,7 @@ public final 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";
@@ -56,23 +57,23 @@ 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("(if your curious it looks like this: " + accessToken
- + ", 'rawResponse'='" + 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...");
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 f6c620d0f..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
@@ -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
@@ -20,6 +20,7 @@ public final 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";
@@ -45,22 +46,21 @@ 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("(if your curious it looks like this: " + accessToken
- + ", 'rawResponse'='" + 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...");
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
new file mode 100644
index 000000000..621480013
--- /dev/null
+++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MediaWikiExample.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.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 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() {
+ }
+
+ @SuppressWarnings("PMD.SystemPrintln")
+ public static void main(String... args) throws IOException, InterruptedException, ExecutionException {
+ final OAuth10aService service = new ServiceBuilder(CONSUMER_KEY)
+ .apiSecret(CONSUMER_SECRET)
+ .build(MediaWikiApi.instance());
+
+ 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 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("(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);
+ 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
new file mode 100644
index 000000000..f64ec246b
--- /dev/null
+++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Meetup20Example.java
@@ -0,0 +1,70 @@
+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.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 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);
+ 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/MeetupExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java
index c8d6ea911..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
@@ -12,13 +12,14 @@
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";
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")
@@ -41,22 +42,22 @@ 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!");
- System.out.println("(if your curious it looks like this: " + accessToken
- + ", 'rawResponse'='" + 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!
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
new file mode 100644
index 000000000..71f346bc6
--- /dev/null
+++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureActiveDirectory20Example.java
@@ -0,0 +1,63 @@
+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() {
+ }
+
+ @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";
+ final String clientSecret = "client secret here";
+ final OAuth20Service service = new ServiceBuilder(clientId)
+ .apiSecret(clientSecret)
+ .defaultScope("openid User.Read")
+ .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();
+ 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! :)");
+ }
+}
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
new file mode 100644
index 000000000..6c9610f06
--- /dev/null
+++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureActiveDirectoryExample.java
@@ -0,0 +1,70 @@
+package com.github.scribejava.apis.examples;
+
+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;
+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 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 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";
+ final String clientSecret = "client secret here";
+ final OAuth20Service service = new ServiceBuilder(clientId)
+ .apiSecret(clientSecret)
+ .defaultScope("openid")
+ .callback("http://www.example.com/oauth_callback/")
+ .build(MicrosoftAzureActiveDirectoryApi.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! :)");
+ }
+}
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..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
@@ -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
@@ -21,6 +21,7 @@ public final 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";
@@ -28,7 +29,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);
@@ -50,19 +51,19 @@ 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("(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());
+ 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 5d2d5548e..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
@@ -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";
@@ -21,6 +21,7 @@ public final 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";
@@ -28,7 +29,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 +39,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);
@@ -60,23 +60,22 @@ 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("(if your curious it looks like this: " + accessToken
- + ", 'rawResponse'='" + 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!
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/NeteaseWeiboExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NeteaseWeiboExample.java
deleted file mode 100644
index 866c2167b..000000000
--- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NeteaseWeiboExample.java
+++ /dev/null
@@ -1,73 +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 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, 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("(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/OdnoklassnikiExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java
index 8ea048fe8..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
@@ -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
@@ -20,9 +20,10 @@ public final 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";
+ final String clientId = "your api client id";
final String publicKey = "your api public key";
final String secretKey = "your api secret key";
@@ -47,31 +48,28 @@ 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("(if your curious it looks like this: " + accessToken
- + ", 'rawResponse'='" + 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 it looks like this: " + accessToken
- + ", 'rawResponse'='" + 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!
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 1fec439b4..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
@@ -12,21 +12,22 @@
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/?access_token?access_token=";
+ private static final String PROTECTED_RESOURCE_URL = "https://api.pinterest.com/v1/me/";
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";
final String apiSecret = "your_app_secret";
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
+ .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);
@@ -44,23 +45,22 @@ 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("(if your curious it looks like this: " + accessToken
- + ", 'rawResponse'='" + 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!
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...");
- 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/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();
+ }
+}
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..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
@@ -12,13 +12,14 @@
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/";
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")
@@ -41,22 +42,22 @@ 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!");
- System.out.println("(if your curious it looks like this: " + accessToken
- + ", 'rawResponse'='" + 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!
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 1eea7e581..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
@@ -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;
@@ -18,9 +15,13 @@
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;
-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";
@@ -28,13 +29,14 @@ public final 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";
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);
@@ -53,12 +55,10 @@ 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("(if your curious it looks like this: " + accessToken
- + ", 'rawResponse'='" + 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!
@@ -70,25 +70,28 @@ public static void main(String... args) throws IOException, InterruptedException
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()));
+ 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 b = new StringBuilder();
+ final StringBuilder sigBuilder = new StringBuilder();
for (String param : sigString) {
- b.append(param);
+ sigBuilder.append(param);
}
- b.append(apiSecret);
- System.out.println("Sig string: " + b.toString());
- request.addQuerystringParameter("sig", md5(b.toString()));
+ sigBuilder.append(apiSecret);
+
+ final String sig = sigBuilder.toString();
+ 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! :)");
@@ -99,15 +102,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-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..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
@@ -17,19 +17,20 @@
import java.security.NoSuchAlgorithmException;
import java.util.concurrent.ExecutionException;
-public final class SalesforceExample {
+public class SalesforceExample {
private static final String NETWORK_NAME = "Salesforce";
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
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();
@@ -38,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")
@@ -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("(The raw response looks like this: " + accessToken.getRawResponse() + "')");
System.out.println();
System.out.println("instance_url is: " + salesforceAccessToken.getInstanceUrl());
@@ -95,9 +94,11 @@ public static void main(String... args) throws IOException, NoSuchAlgorithmExcep
System.out.println("Full URL: " + url);
final OAuthRequest request = new OAuthRequest(Verb.GET, url);
- final Response response = service.execute(request);
+ service.signRequest(salesforceAccessToken, 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 d057df0d9..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
@@ -20,14 +20,14 @@
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
-public final class SalesforceNingAsyncExample {
+public class SalesforceNingAsyncExample {
private static final String NETWORK_NAME = "Salesforce";
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
@@ -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)
@@ -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("(The raw response 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!
@@ -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 a2bacaff4..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
@@ -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";
@@ -19,6 +19,7 @@ public final 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";
@@ -47,19 +48,19 @@ 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("(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());
+ 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 289f4eb50..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
@@ -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";
@@ -20,6 +20,7 @@ public final 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";
@@ -49,23 +50,23 @@ 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!");
- System.out.println("(if your curious it looks like this: " + accessToken
- + ", 'rawResponse'='" + 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!
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 fcb2f592a..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
@@ -12,13 +12,14 @@
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";
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")
@@ -41,23 +42,23 @@ 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!");
- System.out.println("(if your curious it looks like this: " + accessToken
- + ", 'rawResponse'='" + 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!
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/SlackExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SlackExample.java
new file mode 100644
index 000000000..44a952d16
--- /dev/null
+++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SlackExample.java
@@ -0,0 +1,102 @@
+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);
+ final 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! :)");
+ }
+}
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..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
@@ -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";
@@ -21,6 +21,7 @@ public final 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
@@ -32,7 +33,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 +42,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);
@@ -63,12 +63,10 @@ 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("(if your curious it looks like this: " + accessToken
- + ", 'rawResponse'='" + 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!
@@ -76,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 057f9b27c..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
@@ -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";
@@ -22,6 +22,7 @@ public final 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";
@@ -31,7 +32,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 +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);
@@ -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 + "'.");
@@ -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("(The raw response looks like this: " + accessToken.getRawResponse() + "')");
System.out.println();
// Now let's go and ask for a protected resource!
@@ -79,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 acb791c1c..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
@@ -13,15 +13,16 @@
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 =
- "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() {
}
+ @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";
@@ -31,7 +32,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 +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);
@@ -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("(The raw response looks like this: " + accessToken.getRawResponse() + "')");
System.out.println();
// Now let's go and ask for a protected resource!
@@ -76,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 dea9fc659..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
@@ -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";
@@ -21,6 +21,7 @@ public final 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)
@@ -43,23 +44,22 @@ 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!");
- System.out.println("(if your curious it looks like this: " + accessToken
- + ", 'rawResponse'='" + 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!
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 ec21d3bfb..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
@@ -12,13 +12,14 @@
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";
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")
@@ -43,23 +44,22 @@ 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!");
- System.out.println("(if your curious it looks like this: " + accessToken
- + ", 'rawResponse'='" + 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!
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 daa5f0122..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
@@ -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";
@@ -21,6 +21,7 @@ public final 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";
@@ -44,24 +45,22 @@ 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("(if your curious it looks like this: " + accessToken
- + ", 'rawResponse'='" + 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!
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 620eb7820..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
@@ -12,13 +12,14 @@
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";
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")
@@ -41,23 +42,22 @@ 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!");
- System.out.println("(if your curious it looks like this: " + accessToken
- + ", 'rawResponse'='" + 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!
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/SohuWeiboExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/UcozExample.java
similarity index 51%
rename from scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SohuWeiboExample.java
rename to scribejava-apis/src/test/java/com/github/scribejava/apis/examples/UcozExample.java
index 0cb93b91a..5760bb36a 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/UcozExample.java
@@ -1,72 +1,59 @@
package com.github.scribejava.apis.examples;
-import java.util.Scanner;
+import com.github.scribejava.apis.UcozApi;
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.Scanner;
import java.util.concurrent.ExecutionException;
-public final class SohuWeiboExample {
+public class UcozExample {
- private static final String NETWORK_NAME = "SohuWeibo";
- private static final String PROTECTED_RESOURCE_URL = "http://api.t.sohu.com/account/verify_credentials.json";
+ private static final String PROTECTED_RESOURCE_URL = "http://artmurka.com/uapi/shop/request?page=categories";
- private SohuWeiboExample() {
+ private UcozExample() {
}
+ @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";
- final String apiSecret = "your_secret";
- final OAuth10aService service = new ServiceBuilder(apiKey)
- .apiSecret(apiSecret)
- .build(SohuWeiboApi.instance());
+ final OAuth10aService service = new ServiceBuilder("your_api_key")
+ .apiSecret("your_api_secret")
+ .debug()
+ .build(UcozApi.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());
+ System.out.println("Got the Request Token!");
+ System.out.println();
- // 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.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
+ // 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("(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());
-
+ 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 09dcde65a..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
@@ -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";
@@ -19,6 +19,7 @@ public final 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";
@@ -43,24 +44,22 @@ 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("(if your curious it looks like this: " + accessToken
- + ", 'rawResponse'='" + 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!
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/VkontakteAsyncApacheExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteAsyncApacheExample.java
new file mode 100644
index 000000000..392348b2b
--- /dev/null
+++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteAsyncApacheExample.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.VkontakteApi;
+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 class VkontakteAsyncApacheExample {
+
+ 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 VkontakteAsyncApacheExample() {
+ }
+
+ @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)
+ .callback("http://www.example.com/oauth_callback/")
+ .httpClientConfig(ApacheHttpClientConfig.defaultConfig())
+ .build(VkontakteApi.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(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.getAccessTokenAsync(code).get();
+ 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! :)");
+ }
+ }
+}
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 78%
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 ae8879790..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,14 +14,16 @@
import com.github.scribejava.core.oauth.OAuth20Service;
import java.io.IOException;
-public final class FacebookAsyncNingExample {
+public class VkontakteAsyncNingExample {
- 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 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")
public static void main(String... args) throws InterruptedException, ExecutionException, IOException {
// Replace these with your client id and secret
final String clientId = "your client id";
@@ -35,12 +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)
- .state(secretState)
.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 ===");
@@ -48,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();
+ 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);
@@ -70,24 +71,23 @@ 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("(if your curious it looks like this: " + accessToken
- + ", 'rawResponse'='" + 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!
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/VkontakteClientCredentialsGrantExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteClientCredentialsGrantExample.java
new file mode 100644
index 000000000..3e4d2d363
--- /dev/null
+++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteClientCredentialsGrantExample.java
@@ -0,0 +1,38 @@
+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 class VkontakteClientCredentialsGrantExample {
+
+ private static final String NETWORK_NAME = "vk.com>";
+
+ 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";
+ final String clientSecret = "your client secret";
+ final OAuth20Service service = new ServiceBuilder(clientId)
+ .apiSecret(clientSecret)
+ .defaultScope("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.getRawResponse());
+ 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 240f78e7c..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
@@ -3,29 +3,33 @@
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;
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;
-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";
+ 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 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";
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());
final Scanner in = new Scanner(System.in);
@@ -35,7 +39,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);
@@ -44,24 +51,27 @@ 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...");
- final OAuth2AccessToken accessToken = service.getAccessToken(code);
+ 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!");
- System.out.println("(if your curious it looks like this: " + accessToken
- + ", 'rawResponse'='" + accessToken.getRawResponse() + "')");
+ 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!
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 d16b714d8..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
@@ -14,14 +14,16 @@
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";
+ 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 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";
@@ -35,14 +37,14 @@ 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);
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);
@@ -61,24 +63,23 @@ 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("(if your curious it looks like this: " + accessToken
- + ", 'rawResponse'='" + 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!
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
new file mode 100644
index 000000000..5d3ffd562
--- /dev/null
+++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/WunderlistExample.java
@@ -0,0 +1,73 @@
+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.WunderlistAPI;
+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 WunderlistExample {
+
+ private static final String NETWORK_NAME = "Wunderlist";
+ private static final String PROTECTED_RESOURCE_URL = "https://a.wunderlist.com/api/v1/user";
+
+ 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";
+ final String apiSecret = "apiSecret";
+ 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)
+ .build(WunderlistAPI.instance());
+
+ 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(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(">>");
+ 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("(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! :)");
+ }
+}
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..d66334e40
--- /dev/null
+++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XeroExample.java
@@ -0,0 +1,110 @@
+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.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;
+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 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 and secret
+ 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)
+ // replace with desired scope
+ .defaultScope("openid email profile offline_access accounting.settings accounting.transactions")
+ .callback(callback)
+ .build(XeroApi20.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();
+
+ //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);
+
+ final ObjectMapper objectMapper = new ObjectMapper();
+ final List