202 Commits
Author SHA1 Message Date
Pablo Fernandez cf9c4be00c bounce version for release and updated changelog 2012-05-08 22:13:50 -07:00
Pablo Fernandez b35ea8d8ed Merge pull request #264 from niQo/master
Support for Skyrock.com API
2012-05-01 15:30:05 -07:00
niQo 5ad8059b08 Added Skyrock.com support 2012-05-01 23:35:28 +02:00
Pablo Fernandez 294c3115d5 Merge pull request #260 from sethhitch/master
Support the Evernote API
2012-04-30 10:14:30 -07:00
Seth Hitchings d721204939 Allow empty oauth_token_secret values 2012-04-30 09:45:49 -07:00
Pablo Fernandez 965a1ecd3f Merge pull request #248 from adamnengland/master
Digg API added
2012-04-29 12:06:54 -07:00
Pablo Fernandez ebe4b0e7db Merge pull request #259 from bubuntux/master
Update Dropbox api
2012-04-29 12:06:24 -07:00
Julio Gutierrez 8c8bcfcafd Update Dropbox 2012-04-29 00:34:55 -07:00
Pablo Fernandez 8ceebf2ded specific exception for connection problems 2012-04-28 21:03:11 -07:00
Seth Hitchings 0a45342004 Remove EvernoteAuthToken 2012-04-27 13:27:13 -07:00
Pablo Fernandez 3f4189607c Merge pull request #257 from sethhitch/urlscheme
Allow digits in URL schemes per RFC
2012-04-27 13:17:16 -07:00
Seth Hitchings 5c030ca360 Full Evernote API support 2012-04-27 11:36:36 -07:00
Seth Hitchings d39f7ab3fc Allow digits in URL schemes per RFC 2012-04-27 11:25:04 -07:00
Pablo Fernandez 89ddd131e4 removed key and secret from sina weibo example 2012-04-25 14:19:09 -03:00
Adam England 13d1eaea0a Updating code style 2012-04-18 19:32:33 -05:00
Adam England 488fc1451a Added Digg Support
Refactoring
2012-04-16 23:10:08 -05:00
Pablo Fernandez 1208fd815a wrong filename 2012-04-12 01:04:10 -03:00
Pablo Fernandez ed65d25697 Merge pull request #246 from ponyloky/master
Freelancer Api
2012-04-11 20:53:06 -07:00
ponyloky d35ef44b02 This should add missing commit 2012-04-12 00:46:59 -03:00
ponyloky 129337d4d4 Adding missing commit 2012-04-12 00:44:43 -03:00
ponyloky 90081a572c Tested and completed 2012-04-11 19:52:13 -03:00
ponyloky 2538b96545 Fixing import formatting 2012-04-06 15:44:15 -03:00
Pablo Fernandez 6ae769e35e Merge pull request #244 from matthewmichihara/master
Small typo fix
2012-04-05 07:01:55 -07:00
ponyloky b50aeba5cb Fixing indentation 2012-04-05 00:51:20 -03:00
ponyloky 3132a9dfe7 Adding support for the Freelancer.com API 2012-04-05 00:44:54 -03:00
Matthew Michihara f9af115645 Fix StackOverflow typo 2012-04-04 19:39:33 -07:00
Pablo Fernandez 6752167925 travis status badge 2012-03-30 20:42:02 -03:00
Pablo Fernandez b83113a025 override travis default install script 2012-03-30 20:36:30 -03:00
Pablo Fernandez 9fbc9b2d72 Merge pull request #241 from dhruvchandna/master
Added support for 500px Api
2012-03-30 15:58:22 -07:00
Dhruv Chandna 4bb6e49b61 Revert "Removed the @Override annotation as it resulted in a compilation error."
This reverts commit 4aa6256487.
2012-03-30 13:00:03 -05:00
Dhruv Chandna 98801d7b86 Used * imports 2012-03-30 11:20:42 -05:00
Dhruv Chandna dbc1bd9c85 Used * imports 2012-03-30 09:39:42 -05:00
Dhruv Chandna 92ffe2cc03 Removed new line at the end of the file 2012-03-30 09:38:41 -05:00
Dhruv Chandna 4aa6256487 Removed the @Override annotation as it resulted in a compilation error. 2012-03-30 09:34:29 -05:00
Dhruv Chandna 9c631674d2 Added support for 500px.com. Also removed the '@Override' annotation from JsonTokenExtractor.java 2012-03-29 14:28:44 -05:00
Pablo Fernandez f4c36ab27a handle execptions while writting to the debug stream. Thanks @waabox 2012-03-21 14:29:15 -03:00
Pablo Fernandez 60872fe55f kickstart travis 2012-03-13 22:57:48 -03:00
Pablo Fernandez 84dd4660e2 travis config file 2012-03-13 21:51:29 -03:00
Pablo Fernandez d746a013ea Update changelog.txt 2012-03-09 17:38:14 -03:00
Pablo Fernandez 7b45840df3 Merge pull request #227 from dwursteisen/master
Added ImgUr Api support
2012-03-09 12:36:34 -08:00
dwursteisen 0967770d43 Code reformat : 2 spaces indentation, brace oppening on the next line, ... 2012-03-08 21:41:01 +01:00
George Cao 69fff5b2c4 Added Kaixin2, Renren and SinaWeibo2 Apis and examples. 2012-03-06 12:58:27 -03:00
Pablo Fernandez ceae6f85cc Merge pull request #233 from acrosa/master
spell your name right yo
2012-03-05 04:33:30 -08:00
Ale d1df7a7fb0 spell your name right yo 2012-03-05 02:23:24 -08:00
Pablo Fernandez b702f097a2 throw an exception when host is not found 2012-03-04 20:56:33 -03:00
Pablo Fernandez 4536f71188 link to forks wikipage 2012-03-04 19:13:08 -03:00
dwursteisen 42ef871a61 Added ImgUr support 2012-02-25 00:22:18 +01:00
Pablo Fernandez 74f53a4d07 Merge pull request #226 from harmsk/1.3.1
Query string params are not rfc3986
2012-02-22 09:45:56 -08:00
Pablo Fernandez b8378a35f2 Merge pull request #220 from boncey/master
OAuth for Flickr plus eclipse formatting rules
2012-02-21 15:42:52 -08:00
boncey 9e848993f6 Removed line length and reformatted 2012-02-21 23:13:05 +00:00
boncey 1e05fc0828 Eclipse formatter and importorder config 2012-02-21 20:31:33 +00:00
boncey 4dd7aa0bc2 Reformatted code to scribe's standards 2012-02-21 20:27:33 +00:00
Kyle J. Harms 79d26389e7 Query string parameters are being encoded into x-www-form-urlencoded format, however OAuth spec requires rfc3986. 2012-02-21 14:14:46 -06:00
mason55 bef18c570e Added GetGlue api 2012-02-14 19:07:58 -03:00
mason55 56235d9b15 Updated Tumblr and Miso classes for clearer handling of endpoints 2012-02-08 08:44:17 -05:00
mason55 0254d551d6 Added Tumblr and Miso support 2012-02-07 22:14:28 -05:00
boncey b13181af35 Removed blank line 2012-01-29 17:09:40 +00:00
boncey e000757d24 Added FlickrExample
Example for Flickr OAuth
2012-01-28 17:08:36 +00:00
boncey 41777bc0d0 Removed unused callback method 2012-01-26 23:23:42 +00:00
boncey bfbba77e4c Added Flickr endpoint (not yet tested) 2012-01-14 10:00:33 +00:00
Jay Prall 762e1004f8 include NetProspex support 2012-01-02 09:59:06 -03:00
softprops f77391eca4 Add meetup.com oauth adapter 2012-01-02 09:49:54 -03:00
Pablo Fernandez 6cfdf973f8 relaxed restrictions on OAuth callbacks 2011-12-28 11:45:45 -03:00
Pablo Fernandez aa5e27b263 linked to debug mode wiki 2011-12-17 00:53:18 -03:00
Pablo Fernandez b5f75628bb updated changelog 2011-12-16 22:25:49 -03:00
Pablo Fernandez 0a63f935d2 added 'debug' method to service builder 2011-12-16 16:13:57 -03:00
Pablo Fernandez 61c0b4cc9f getCompleteUrl method for getting the whole url (host+resource+querystring) 2011-12-14 17:50:02 -03:00
Pablo Fernandez 3f366589ea bounced version numbers 2011-12-14 17:22:19 -03:00
Pablo Fernandez 83b62f6079 removed URLUtils 2011-12-14 16:18:06 -03:00
Pablo Fernandez b380b3af3d removed MapUtils 2011-12-14 15:46:07 -03:00
Pablo Fernandez ce531cdc38 first step towards ParameterList refactoring 2011-12-14 13:31:12 -03:00
Pablo Fernandez 56561acdac added reference to stackoverflow tag 2011-11-30 18:00:08 -03:00
Pablo Fernandez 05988a63cd Twitter examples about percent encoding
see: https://dev.twitter.com/docs/auth/percent-encoding-parameters
2011-11-07 15:36:13 -03:00
Pablo Fernandez 611c6464f2 added SimpleGeo Api to changelog 2011-09-25 23:32:20 -03:00
Pablo Fernandez 7fba153218 fixed mistake in changelog, soundcloud is going to be in release 2.0 2011-09-25 23:30:50 -03:00
Pablo Fernandez 9070edd20a bounced version numbers for release 2011-09-25 23:22:19 -03:00
liuce 78fd342d92 Added Kaixin and QWeibo Apis 2011-09-25 20:28:58 -03:00
Pablo Fernandez 7510111d28 changed method name for javabean convention 2011-09-25 20:12:53 -03:00
Pablo Fernandez 852368e0a7 Sapo Api support 2011-09-25 20:12:23 -03:00
Pablo Fernandez dbf00c9227 added features to changelog 2011-09-25 20:12:23 -03:00
Pablo Fernandez ce139bb28b Merge pull request #147 from dreamcwli/master
Mobile Plurk Api
2011-09-25 16:11:49 -07:00
Pablo Fernandez 40c8a27bb0 SimpleGeo Api (just for 2 Legged OAuth) 2011-09-25 19:26:38 -03:00
Pablo Fernandez ae3a1b11c9 added default content type 2011-09-25 19:14:57 -03:00
Pablo Fernandez 24babbae02 better error messages when scribe can't establish a network connection 2011-09-25 16:37:49 -03:00
Pablo Fernandez 9f4569fbbc made token extraction regex easier and added a test case for multiple parameters 2011-09-24 16:56:07 -03:00
Pablo Fernandez 7e7d3ff7e0 Twitter's /authenticate endpoint 2011-09-19 18:43:22 -03:00
Pablo Fernandez dcd13835ba moved map functions to MapUtils 2011-08-29 10:53:38 -03:00
Pablo Fernandez daf45d7078 documented changes so far 2011-08-29 10:53:38 -03:00
Pablo Fernandez 8a7336b7d4 added intellij ignores 2011-08-29 10:53:00 -03:00
Pablo Fernandez 207df8a3d4 Merge pull request #150 from sripathikrishnan/master
Scribe Release - 1.2.2
2011-08-29 06:43:04 -07:00
Sripathi Krishnan 4f8315f7f7 Bumping release number in pom.xml snippet in README 2011-08-29 16:59:20 +05:30
Sripathi Krishnan e719c73d92 Bumping release version to 1.2.2 2011-08-29 16:52:42 +05:30
Chia-Wei Li c6bff31353 Move MobilePlurkApi into PlurkApi 2011-08-27 19:32:16 +08:00
Chia-Wei Li 27b1fc390b Fix MobilePlurkApi naming 2011-08-25 13:43:10 +08:00
Chia-Wei Li b917140078 Merge remote-tracking branch 'upstream/master' 2011-08-25 13:24:52 +08:00
Chia-Wei Li 9cdebd1ca6 Add Mobile Plurk API 2011-08-25 11:28:38 +08:00
Pablo Fernandez 2238c2da51 Merge pull request #146 from sripathikrishnan/master
Issue # 145 : Change source and target compatibility to 1.5
2011-08-23 06:03:55 -07:00
Sripathi Krishnan bf9a4bac68 Issue # 145 : Changing source and target compatibility to 1.5
This allows the library to be used in JDK 5 as well as JDK 6
2011-08-23 16:12:33 +05:30
Pablo Fernandez d8e384f9c7 Merge pull request #137 from wscoble/live-example-eclipse-fix
fixed "invalid character constant" message from eclipse
2011-08-08 12:44:45 -07:00
Scott Scoble 35ca23f442 fixed "invalid character constant" message from eclipse 2011-08-08 00:28:23 -07:00
Pablo Fernandez 93602c4120 Merge pull request #135 from tomaslin/master
Windows Live oAuth Support
2011-08-02 09:04:26 -07:00
Tomas Lin 62b43855c2 wrapped line format 2011-08-02 15:56:43 +01:00
Tomas Lin a62fa36da0 added windows live support and example 2011-08-02 13:05:54 +01:00
Chia-Wei Li 0390ae7eb7 Fix naming convention 2011-07-20 19:47:32 +08:00
Pablo Fernandez 1d59fbd014 Merge pull request #130 from dreamcwli/master
Add Plurk API
2011-07-18 05:56:13 -07:00
Chia-Wei Li 79fa710e47 Fix code style 2011-07-17 14:01:31 +08:00
Chia-Wei Li 079ce6a2c2 Add Plurk API 2011-07-17 11:48:16 +08:00
Pablo Fernandez c86d7174af Merge pull request #124 from thepizzle/master
fixed NPE when setting connection timeouts.
2011-06-29 19:19:31 -07:00
Pablo Fernandez 5f47bebced bounced version number for release 2011-06-27 12:18:58 -03:00
ThePizzle 10c56bda27 Fix indentation and remove commented code 2011-06-09 09:23:33 -04:00
ThePizzle 1be46776e5 Set timeout parameters in doSend() to avoid NPE 2011-06-08 17:15:53 -04:00
Pablo Fernandez cc5a0a0471 missing entry on changelog 2011-06-03 16:49:30 -03:00
Pablo Fernandez 0c3fc722b1 enable persistent http connections 2011-06-03 16:46:16 -03:00
Arthur Wang 203cf83dc0 Added Sohu Weibo api and example. 2011-06-03 10:56:37 -03:00
Arthur Wang 7b587c3d1d Added Netease Weibo(t.163.com) api and example. 2011-06-03 10:50:17 -03:00
Arthur Wang f89279c682 Added Sina Weibo Api and example. 2011-06-03 10:46:29 -03:00
Pablo Fernandez 7b6b9056d3 multipart request support 2011-06-02 09:31:39 -03:00
Boris ca7950004b Implemented Vkontakte.ru support 2011-05-25 18:40:57 -03:00
Pablo Fernandez 543b53475f changelog charset update 2011-05-07 13:18:52 -03:00
Pablo Fernandez de1ac1f467 request charset handling 2011-05-07 13:15:35 -03:00
Pablo Fernandez 97f45d75e7 bounced version numbers for release 2011-05-04 12:00:45 -03:00
Pablo Fernandez 624fdfb714 removed unused statics 2011-04-29 15:08:35 -03:00
Pablo Fernandez bd51ae9f25 Added plaintext signature for Yammer Api and fixed fucked up indentation 2011-04-29 15:05:09 -03:00
Pablo Fernandez 40ab98d506 added Twitter SSL support 2011-04-27 11:44:55 -03:00
Pablo Fernandez 0abe7f80d4 fixed bug in facebook url generation 2011-04-25 19:21:00 -03:00
Pablo Fernandez 592b1b5fdd Added scope to facebook api 2011-04-25 13:24:11 -03:00
Pablo Fernandez 2112d3d8a9 Added scopes to 2.0 apis 2011-04-25 13:23:37 -03:00
Pablo Fernandez 109c93b4e4 Moved scope inside OAuthConfig 2011-04-25 13:15:25 -03:00
Pablo Fernandez 41b6da1a44 bounced version on pom.xml 2011-04-19 22:59:30 -03:00
Pablo Fernandez 91cb9b8407 changed readme to last version 2011-04-19 22:56:59 -03:00
Pablo Fernandez c265e730a3 removed auto-generated comments 2011-04-19 22:52:36 -03:00
Matthew Laudato 5719d7a18a Support for ConstantContact REST API 2011-04-19 22:42:25 -03:00
Pablo Fernandez 8abdde928a added convenience methods for the builder api 2011-04-19 22:32:32 -03:00
Pablo Fernandez 193dcd2e25 added SignatureType and querystring signing functionallity 2011-04-19 22:17:23 -03:00
Pablo Fernandez 931236561a rename method
to support both querystring and header signatures
2011-04-19 22:04:06 -03:00
Pablo Fernandez 5f40e0dca0 removed unused extractor (JsonTokenExtractor handles this) 2011-04-19 21:51:36 -03:00
Tom Tasche 8afb142b7f Add Foursquare2 API and example 2011-04-19 21:50:12 -03:00
Pablo Fernandez bfcf0655da added Dropbox Api 2011-04-13 19:03:56 -03:00
Pablo Fernandez db88d53807 made extractor independent of token/secret order 2011-04-13 19:02:45 -03:00
Pablo Fernandez cbfd88d749 removed picture from readme since link is broken 2011-04-11 14:06:39 -03:00
Pablo Fernandez 1eb0b1003c Added raw string to Token, for retrieving additional parameters 2011-04-11 14:06:08 -03:00
Stuart Grimshaw 75bcb0013d Added Lovefilm Api and example 2011-03-30 00:37:44 -03:00
Stuart Grimshaw 145c009fc3 Fix for HttpUrlConnection on pre-Gingerbread Android devices 2011-03-30 00:24:12 -03:00
Pablo Fernandez 72901165f8 updated readme with new pom version 2011-03-30 00:09:46 -03:00
Stuart Grimshaw 4f23cfaf20 Moved callback header above call to addOAthParams so it gets properly
signed.
2011-03-29 19:06:19 -03:00
Pablo Fernandez 5c0d150547 Added mvn-bundle script 2011-03-13 10:49:31 -03:00
Pablo Fernandez 6bdae4999e Fixed wrong method call 2011-03-13 10:44:31 -03:00
Pablo Fernandez c441b7d8a4 Merged Diego's changes for OAuth2.0 server-side flow 2011-03-13 10:40:09 -03:00
Pablo Fernandez d8ab4ba404 oauth_callback param should only be sent on the request_token request 2011-03-13 10:25:52 -03:00
Pablo Fernandez 6923d3311f Added facebook and 2.0 info on readme 2011-03-13 10:21:43 -03:00
Pablo Fernandez 0832613b60 Changed artifact version in README 2011-03-13 10:21:43 -03:00
Pablo Fernandez 73a53b363a Fixed RequestTests 2011-03-13 10:21:43 -03:00
Pablo Fernandez 16b3475926 Added uitilty method to MapUtils for appending and encoding parameters 2011-03-13 10:21:42 -03:00
Pablo Fernandez 22367de553 Changed getQuerystringParameters impl to form-urldecode the parameters 2011-03-13 10:21:42 -03:00
Pablo Fernandez 906a979e63 Removed encoding in Verifier constructor 2011-03-13 10:21:42 -03:00
Pablo Fernandez bb872e4466 Changed percentEncodings 2011-03-13 10:21:42 -03:00
Pablo Fernandez d19c5d6e35 Removed Verifier test (unused) 2011-03-13 10:21:42 -03:00
Pablo Fernandez e0e8df98d3 Added formURLEncode/Decode methods 2011-03-13 10:21:39 -03:00
diegossilveira de8f0d621d Changed the Facebook example to conform to the OAuth 2.0 server-side flow 2011-02-10 22:09:18 -02:00
diegossilveira db37744fa3 Fixed package imports 2011-02-10 21:54:46 -02:00
diegossilveira 02f3d4dac2 Changed the Facebook example to conform to the OAuth 2.0 server-side flow 2011-02-10 17:13:03 -02:00
diegossilveira 7385d3702e Added specific token extractor for OAuth 2.0 2011-02-10 17:09:11 -02:00
diegossilveira 581e2b6d84 Changed the getAccessToken() method implementation to conform to the OAuth 2.0 server-side flow 2011-02-10 17:03:28 -02:00
diegossilveira 08aebb5fb1 Added specific constants for OAuth 2.0 2011-02-10 16:56:10 -02:00
diegossilveira c7176c97e2 Added access_token related methods to OAuth 2.0 APIs 2011-02-10 16:54:28 -02:00
Pablo Fernandez 70358ad651 Added specific tests for + symbol encoding 2011-01-31 16:15:18 -03:00
dustin norlander 0f39d37ddc add api() method to service builder 2011-01-26 10:27:35 -03:00
Pablo Fernandez da3a3f4a0d Removed isEmpty for old VM compatibility 2011-01-19 13:41:41 -03:00
Pablo Fernandez 380d858b13 Changed version number for release 2011-01-16 12:45:26 -03:00
Pablo Fernandez 9c4f5bc337 Refactored OOB checking in fbook api 2011-01-13 23:50:36 -03:00
Pablo Fernandez 09ee10dbd1 Added builder tests 2011-01-13 23:50:32 -03:00
Pablo Fernandez 690b9d4e21 (minor) removed specific import 2011-01-12 21:46:27 -03:00
diegossilveira 080dd962a9 Encoding the callback url 2011-01-12 18:05:50 -02:00
Pablo Fernandez 40bb525374 Added url params before making the connection
Renamed method to keep consistency
2011-01-10 15:04:26 -03:00
Pablo Fernandez 8e23e81c57 Explicited that you need a personal pair of keys to use Facebook's example 2011-01-09 21:37:44 -03:00
Pablo Fernandez 1f055d7eeb Minor exception handling refactoring 2011-01-09 16:10:00 -03:00
Pablo Fernandez 1f36fd0f32 Added Facebook Api and example 2011-01-09 15:58:58 -03:00
Pablo Fernandez 9ea686a3f8 Added OAuth 2.0 classes 2011-01-09 15:51:34 -03:00
Pablo Fernandez 7e92db3413 Added functionallity for appending querystring params once the request is created 2011-01-09 15:44:14 -03:00
Pablo Fernandez f6c3cb9bdb Lazy http connection creation 2011-01-09 15:34:19 -03:00
Pablo Fernandez 088fc5e443 Renamed OAuth 2.0 service class 2011-01-09 14:43:56 -03:00
Pablo Fernandez 27bac50073 Added append parameters to URL method 2011-01-09 14:14:08 -03:00
Pablo Fernandez 6fc5146706 Added Diego to list of developers 2011-01-09 13:56:34 -03:00
Pablo Fernandez 0e5ae92d3e Added exceptions to both token methods on 2.0 service
Rebased 1.0.9
2011-01-07 13:24:18 -03:00
Pablo Fernandez c145ee8842 Added Evernote playground api 2011-01-07 13:15:29 -03:00
Pablo Fernandez bdfd14309f Added some more apis to the readme 2011-01-07 13:15:29 -03:00
Pablo Fernandez 82f03604c3 Added OAuth2 service props 2011-01-07 13:15:29 -03:00
Pablo Fernandez 5ac849313d Added authorization URL to the Apis 2011-01-07 13:15:26 -03:00
Pablo Fernandez c12da16a38 Made 2.0 impl fit the internal refactor 2011-01-07 13:10:43 -03:00
Pablo Fernandez b78ca90df4 Added plumbing code for 2.0 2011-01-07 13:10:43 -03:00
Pablo Fernandez 577c18c752 corrected javadocs to reflect changes 2011-01-07 13:10:43 -03:00
Pablo Fernandez 41cbee06d7 Minor name refactor 2011-01-07 13:10:43 -03:00
Pablo Fernandez 8eb2062e95 Used OAuthConfig when possible instead of bunch of Strings 2011-01-07 13:10:43 -03:00
Pablo Fernandez 8f0760664f Removed endpoints and verbs from config (they are in the Api object anyways) 2011-01-07 13:10:42 -03:00
Pablo Fernandez 0be82d6832 OAuth 1.0a service refactor to remove many properties 2011-01-07 13:10:39 -03:00
Pablo Fernandez d0fa8689cb Added changes to changelog and version to pom 2010-11-30 15:05:10 -03:00
roger 896e738156 Signature test fixed. New reference signature as api & token secret must be urlencoded. 2010-11-30 15:01:12 -03:00
roger cf84381127 Added URLDecoding to verifier 2010-11-30 14:49:47 -03:00
klakegg 806d548629 Parameters scope and oauth_callback are needed in the request_token step only. 2010-11-30 14:25:42 -03:00
Roger 959c093620 keyString for SecretKey must be encoded 2010-11-30 14:10:57 -03:00
Pablo Fernandez fc2c46bd3a Changed GoogleApi to use GET 2010-11-23 17:35:42 -03:00
klakegg f1ecabdb52 Token implements Serializable - nice to have when creating web service. 2010-11-23 17:29:24 -03:00
112 changed files with 4219 additions and 588 deletions

No files matched your search

+5
View File
@@ -5,6 +5,11 @@
.project
.settings
# IntelliJ Idea settings
.idea
scribe.iml
# Binaries
target
+5
View File
@@ -0,0 +1,5 @@
# kickstart travis.
language: java
# need to override travis 'install' since it will try gpg sign and fail.
install: mvn clean package -DskipTests=true
+1 -1
View File
@@ -1,6 +1,6 @@
The MIT License
Copyright (c) 2010 Pablo Fenandez
Copyright (c) 2010 Pablo Fernandez
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
+26 -4
View File
@@ -1,7 +1,7 @@
!http://img411.imageshack.us/img411/2851/scribelogo.png!
h2. Welcome to the home of Scribe, the simple OAuth Java lib!
!https://secure.travis-ci.org/fernandezpablo85/scribe-java.png?branch=master(travis-ci-status)!
h1. Why use Scribe?
h3. Dead Simple
@@ -20,10 +20,12 @@ h3. Threadsafe
Hit Scribe as hard and with many threads as you like.
h3. Supports all major OAuth APIs out-of-the-box
h3. Supports all major 1.0a and 2.0 OAuth APIs out-of-the-box
* Google
* Facebook
* Yahoo
* LinkedIn
@@ -32,6 +34,14 @@ h3. Supports all major OAuth APIs out-of-the-box
* Foursquare
* Evernote
* Vimeo
* Yammer
* Windows Live
* and many more! check the "examples folder":http://github.com/fernandezpablo85/scribe-java/tree/master/src/test/java/org/scribe/examples
h3. Small and modular
@@ -55,7 +65,7 @@ You can pull scribe from a maven repository, just add this to your __pom.xml__ f
@<dependency>@
@<groupId>org.scribe</groupId>@
@<artifactId>scribe</artifactId>@
@<version>1.0.6</version>@
@<version>1.3.0</version>@
@</dependency>@
h1. Getting started in less than 2 minutes
@@ -64,6 +74,18 @@ Check the "Getting Started":http://wiki.github.com/fernandezpablo85/scribe-java/
h1. Please Read the "FAQ":http://wiki.github.com/fernandezpablo85/scribe-java/faq before creating an issue :)
h1. Questions?
Feel free to drop me an email, but there's already a "StackOverflow":http://stackoverflow.com tag for "scribe":http://stackoverflow.com/questions/tagged/scribe you should use. I'm subscribed to it so I'll pick the question immediately.
Note that it really helps to run scribe on "debug mode":https://github.com/fernandezpablo85/scribe-java/wiki/debug-mode (since 1.3.0), to get additional info. To do this simply call the @.debug()@ method on the @ServiceBuilder@.
h1. Forks
Looking for a scribe variation? check the "Fork List":https://github.com/fernandezpablo85/scribe-java/wiki/Forks
If you have a useful fork that should be listed there please contact me (see About me).
h1. About me
"LinkedIn profile":http://www.linkedin.com/in/fernandezpablo85
Executable
+2
View File
@@ -0,0 +1,2 @@
#!/bin/sh
mvn source:jar javadoc:jar package gpg:sign repository:bundle-create -Dgpg.passphrase=$1
+73
View File
@@ -13,3 +13,76 @@
* FIX: Fixed Evernote Api (uses GET for request and access tokens)
* REFACTOR: URLEncoding stuff. LinkedIn specific decoder is no longer needed
* FEATURE: Added Google example
[1.0.9]
* FEATURE: Token made Serializable
* FIX: Google Api encoding issues (thanks @roger and @klakegg)
[1.1.0]
* FEATURE: OAuth 2.0 Support and Facebook support out of the box (thanks Diego Silveira)
* REFACTOR: Api creation and OAuthService refactors
* REFACTOR: Connections are created lazily (just before sending the request)
[1.1.1]
* FIX: Removed isEmpty() from OAuth2.0 code in order to support older JVMs
* FEATURE: Overloaded provider() method to support instances as well as classes (thanks dustismo)
* FIX: White-space parameter bug (thanks Krogoth)
* FEATURE: OAuth 2.0 now implements server-flow (thanks Diego Silveira)
[1.1.2]
* FIX: Fixed ugly bug that made 1.1.1 practically unusable (thanks Stubbs)
[1.1.3]
* FEATURE: Added rawResponse to Token, for extracting additional parameters (thanks Dirk McCormick)
* FEATURE: Added Dropbox Api
* FIX: Token responses now work despite of the token/secret order
* FEATURE: Added Foursquare OAuth 2.0 Api (thanks Tom Tasche)
* FEATURE: Added support for OAuth1.0a signatures via querystring parameters
* FEATURE: Added ConstantContact Api (thanks Matthew Laudato)
[1.2]
* REFACTOR: Moved scope inside OAuthConfig (breaks backwards compatibility)
* FEATURE: Added scopes to Facebook 2.0 Api
* FEATURE: Added Plaintext signature for Yammer
* FEATURE: Added Twitter SSL endpoints (use TwitterApi.SSL.class)
[1.2.1]
* FEATURE: Added custom charset support to Request (thanks Eric Genet)
* FEATURE: Added support for Vkontakte (thanks dotbg)
* FEATURE: Added Sohu Weibo, Netease Weibo & Sina Weibo Apis (thanks Arthur Wang)
* FEATURE: Added support for persistent Http Connections (thanks Craig Minton)
[1.2.2]
* FIX: Added support for JDK 1.5. Issue #146 (thanks Sripathi Krishnan)
* FIX: Invalid character constant error message. Issue #137 (thanks Scott Scoble)
* FEATURE: Added a Api class to handle windows live authentication. Issue #135 (thanks Tomas Lin)
* FEATURE: Added refresh token feature for Yahoo! API. Issue #134 (thanks Aaron Foltz)
* FEATURE: Added support for Plurk API. Issue #130 (thanks Chia-Wei Li)
* FIX: Request.setConnectTimeout() and setReadTimeout() throw NPE. Issue #123 (thanks thepizzle)
[1.2.3]
* FEATURE: Added default Content-Type header
* FEATURE: Sapo Api
* FEATURE: Plurk Mobile Api
* FEATURE: Kaixin and QWeibo Apis
* FEATURE: SimpleGeo Api
[1.3.0]
* FEATURE: Multiple parameters with the same name supported.
* FEAUTRE: 'debug' mode that logs useful information about the signature making
[1.3.1]
* FEATURE: Meetup.com Api
* FEATURE: NetProspex Api
* FEATURE: Kaixin2, SinaWeibo2 and Renren Apis
* FEATURE: ImgUr Api
* FEATURE: Freelancer Api (thanks Juan Palacios!)
* FIX: Allow digits in url schemes
* FEATURE: Specific exception for connection problems (OAuthConnectionException)
* FIX: Dropbox Api and Evernote Api updated to their latests versions
* FIX: Digg and Skyrock Apis
+9 -3
View File
@@ -4,7 +4,7 @@
<groupId>org.scribe</groupId>
<artifactId>scribe</artifactId>
<packaging>jar</packaging>
<version>1.0.8</version>
<version>1.3.1</version>
<name>Scribe OAuth Library</name>
<description>The best OAuth library out there</description>
<url>http://github.com/fernandezpablo85/scribe-java</url>
@@ -22,6 +22,12 @@
<email>fernandezpablo85@gmail.com</email>
<timezone>-3</timezone>
</developer>
<developer>
<id>diegossilveira</id>
<name>Diego Silveira</name>
<email>diegossilveira@gmail.com</email>
<timezone>-3</timezone>
</developer>
</developers>
<licenses>
@@ -57,8 +63,8 @@
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
<plugin>
@@ -0,0 +1,290 @@
<?xml version="1.0" encoding="UTF-8"?><profiles version="12">
<profile kind="CodeFormatterProfile" name="scribe" version="12">
<setting id="org.eclipse.jdt.core.formatter.comment.insert_new_line_before_root_tags" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.disabling_tag" value="@formatter:off"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_annotation" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_parameters" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_type_declaration" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_arguments" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_anonymous_type_declaration" value="next_line"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_case" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_brace_in_array_initializer" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.comment.new_lines_at_block_boundaries" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_annotation_declaration" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_closing_brace_in_array_initializer" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_annotation" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_field" value="1"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_while" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.use_on_off_tags" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_annotation_type_member_declaration" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_else_in_if_statement" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_prefix_operator" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.keep_else_statement_on_same_line" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_ellipsis" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.comment.insert_new_line_for_parameter" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_annotation_type_declaration" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.indent_breaks_compare_to_cases" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_multiple_fields" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_expressions_in_array_initializer" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_conditional_expression" value="80"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_for" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_binary_operator" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_question_in_wildcard" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_array_initializer" value="next_line"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_enum_constant" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_finally_in_try_statement" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_local_variable" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_catch_in_try_statement" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_while" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.blank_lines_after_package" value="1"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_parameters" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.continuation_indentation" value="2"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_postfix_operator" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_method_invocation" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_arguments" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_superinterfaces" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_new_chunk" value="1"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_binary_operator" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_package" value="0"/>
<setting id="org.eclipse.jdt.core.compiler.source" value="1.7"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_constant_arguments" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_constructor_declaration" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.comment.format_line_comments" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_arguments" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_declarations" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.join_wrapped_lines" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_block" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_explicit_constructor_call" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_invocation_arguments" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_member_type" value="1"/>
<setting id="org.eclipse.jdt.core.formatter.align_type_members_on_columns" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_enum_constant" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_for" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_method_declaration" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_switch" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_unary_operator" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_case" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.comment.indent_parameter_description" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_declaration" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_switch" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_declaration" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_parameters" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_block_comment" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_type_declaration" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.lineSplit" value="9999"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_if" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_brackets_in_array_type_reference" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_parenthesized_expression" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_explicitconstructorcall_arguments" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_constructor_declaration" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_first_class_body_declaration" value="0"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_method" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.indentation.size" value="2"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_declaration" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.enabling_tag" value="@formatter:on"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_enum_constant" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_superclass_in_type_declaration" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_assignment" value="0"/>
<setting id="org.eclipse.jdt.core.compiler.problem.assertIdentifier" value="error"/>
<setting id="org.eclipse.jdt.core.formatter.tabulation.char" value="space"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_parameters" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_try_resources" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_prefix_operator" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.indent_statements_compare_to_body" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_method" value="1"/>
<setting id="org.eclipse.jdt.core.formatter.wrap_outer_expressions_when_nested" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.format_guardian_clause_on_one_line" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_for" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_cast" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_labeled_statement" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_annotation_type_declaration" value="next_line"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_method_body" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_method_declaration" value="0"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_invocation" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_try" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_allocation_expression" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_constant" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_annotation" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation_type_declaration" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_throws" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_if" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_switch" value="next_line"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_throws" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_return" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_question_in_conditional" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_question_in_wildcard" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_try" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_allocation_expression" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.comment.preserve_white_space_between_code_and_line_comments" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_throw" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_arguments" value="do not insert"/>
<setting id="org.eclipse.jdt.core.compiler.problem.enumIdentifier" value="error"/>
<setting id="org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_switch" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_ellipsis" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_block" value="next_line"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_inits" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_method_declaration" value="next_line"/>
<setting id="org.eclipse.jdt.core.formatter.compact_else_if" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.wrap_before_or_operator_multicatch" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_array_initializer" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_increments" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.format_line_comment_starting_on_first_column" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_reference" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_field" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_enum_constant" value="next_line"/>
<setting id="org.eclipse.jdt.core.formatter.comment.indent_root_tags" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_declarations" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_union_type_in_multicatch" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_explicitconstructorcall_arguments" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_switch" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_parameters" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_superinterfaces" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_allocation_expression" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.tabulation.size" value="2"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_type_reference" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_closing_brace_in_block" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_reference" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_constant" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_arguments" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_constructor_declaration" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_throws" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_if" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_javadoc_comment" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_constructor_declaration" value="32"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_assignment_operator" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_assignment_operator" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.indent_empty_lines" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_synchronized" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_closing_paren_in_cast" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_parameters" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_block_in_case" value="next_line"/>
<setting id="org.eclipse.jdt.core.formatter.number_of_empty_lines_to_preserve" value="1"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_declaration" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_catch" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_constructor_declaration" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_invocation" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_reference" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_qualified_allocation_expression" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_and_in_type_parameter" value="insert"/>
<setting id="org.eclipse.jdt.core.compiler.compliance" value="1.7"/>
<setting id="org.eclipse.jdt.core.formatter.continuation_indentation_for_array_initializer" value="2"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_brackets_in_array_allocation_expression" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_at_in_annotation_type_declaration" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_cast" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_unary_operator" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_parameterized_type_reference" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_anonymous_type_declaration" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.keep_empty_array_initializer_on_one_line" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_declaration" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.keep_imple_if_on_one_line" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_parameters" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_parameters" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_at_end_of_file_if_missing" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_for" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_labeled_statement" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_parameterized_type_reference" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_type_declaration" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_binary_expression" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_enum_declaration" value="next_line"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_type" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_while" value="do not insert"/>
<setting id="org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode" value="enabled"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_try" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.put_empty_statement_on_new_line" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_label" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_parameter" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_parameters" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_invocation" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_while_in_do_statement" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.comment.format_javadoc_comments" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.comment.line_length" value="9999"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_package" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.blank_lines_between_import_groups" value="1"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_constant_arguments" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_semicolon" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_constructor_declaration" value="next_line"/>
<setting id="org.eclipse.jdt.core.formatter.number_of_blank_lines_at_beginning_of_method_body" value="0"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_conditional" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_type_header" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation_type_member_declaration" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.wrap_before_binary_operator" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_declaration_header" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.blank_lines_between_type_declarations" value="1"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_synchronized" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.indent_statements_compare_to_block" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_enum_declaration" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.join_lines_in_comments" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_question_in_conditional" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_field_declarations" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_compact_if" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_inits" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_cases" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_array_initializer" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_default" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_and_in_type_parameter" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_constructor_declaration" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_imports" value="1"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_assert" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.comment.format_html" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_method_declaration" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_parameters" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_allocation_expression" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_anonymous_type_declaration" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_conditional" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_parameterized_type_reference" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_for" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_postfix_operator" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.comment.format_source_code" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_synchronized" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_allocation_expression" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_throws" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_brace_in_array_initializer" value="insert"/>
<setting id="org.eclipse.jdt.core.compiler.codegen.targetPlatform" value="1.7"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_resources_in_try" value="80"/>
<setting id="org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation" value="0"/>
<setting id="org.eclipse.jdt.core.formatter.comment.format_header" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.comment.format_block_comments" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_enum_constant" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_enum_constants" value="48"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_block" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_annotation_declaration_header" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_parenthesized_expression" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_parenthesized_expression" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_catch" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_local_declarations" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_switch" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_increments" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_invocation" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_assert" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_type_declaration" value="next_line"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_array_initializer" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_braces_in_array_initializer" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_declaration" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_for" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_catch" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_parameterized_type_reference" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_field_declarations" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_annotation" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_parameterized_type_reference" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_invocation_arguments" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.comment.new_lines_at_javadoc_boundaries" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.blank_lines_after_imports" value="1"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_local_declarations" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_constant_header" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_for" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.never_indent_line_comments_on_first_column" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_try_resources" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_arguments" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.never_indent_block_comments_on_first_column" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.keep_then_statement_on_same_line" value="false"/>
</profile>
</profiles>
@@ -0,0 +1,7 @@
#Organize Import Order
#Tue Feb 21 20:29:55 GMT 2012
4=java
3=javax
2=org
1=org.boncey
0=com
@@ -1,8 +1,8 @@
package org.scribe.builder;
import java.io.*;
import org.scribe.builder.api.*;
import org.scribe.exceptions.*;
import org.scribe.model.*;
import org.scribe.oauth.*;
import org.scribe.utils.*;
@@ -21,6 +21,8 @@ public class ServiceBuilder
private String callback;
private Api api;
private String scope;
private SignatureType signatureType;
private OutputStream debugStream;
/**
* Default constructor
@@ -28,6 +30,8 @@ public class ServiceBuilder
public ServiceBuilder()
{
this.callback = OAuthConstants.OUT_OF_BAND;
this.signatureType = SignatureType.Header;
this.debugStream = null;
}
/**
@@ -56,7 +60,22 @@ public class ServiceBuilder
}
return api;
}
/**
* Configures the {@link Api}
*
* Overloaded version. Let's you use an instance instead of a class.
*
* @param api instance of {@link Api}s
* @return the {@link ServiceBuilder} instance for method chaining
*/
public ServiceBuilder provider(Api api)
{
Preconditions.checkNotNull(api, "Api cannot be null");
this.api = api;
return this;
}
/**
* Adds an OAuth callback url
*
@@ -65,7 +84,7 @@ public class ServiceBuilder
*/
public ServiceBuilder callback(String callback)
{
Preconditions.checkValidOAuthCallback(callback, "Callback must be a valid URL or 'oob'");
Preconditions.checkNotNull(callback, "Callback can't be null");
this.callback = callback;
return this;
}
@@ -108,6 +127,32 @@ public class ServiceBuilder
this.scope = scope;
return this;
}
/**
* Configures the signature type, choose between header, querystring, etc. Defaults to Header
*
* @param scope The OAuth scope
* @return the {@link ServiceBuilder} instance for method chaining
*/
public ServiceBuilder signatureType(SignatureType type)
{
Preconditions.checkNotNull(type, "Signature type can't be null");
this.signatureType = type;
return this;
}
public ServiceBuilder debugStream(OutputStream stream)
{
Preconditions.checkNotNull(stream, "debug stream can't be null");
this.debugStream = stream;
return this;
}
public ServiceBuilder debug()
{
this.debugStream(System.out);
return this;
}
/**
* Returns the fully configured {@link OAuthService}
@@ -119,6 +164,6 @@ public class ServiceBuilder
Preconditions.checkNotNull(api, "You must specify a valid api through the provider() method");
Preconditions.checkEmptyString(apiKey, "You must provide an api key");
Preconditions.checkEmptyString(apiSecret, "You must provide an api secret");
return api.createService(apiKey, apiSecret, callback, scope);
return api.createService(new OAuthConfig(apiKey, apiSecret, callback, signatureType, scope, debugStream));
}
}
@@ -1,5 +1,6 @@
package org.scribe.builder.api;
import org.scribe.model.*;
import org.scribe.oauth.*;
/**
@@ -20,5 +21,5 @@ public interface Api
*
* @return fully configured {@link OAuthService}
*/
OAuthService createService(String apiKey, String apiSecret, String callback, String scope);
OAuthService createService(OAuthConfig config);
}
@@ -0,0 +1,26 @@
package org.scribe.builder.api;
import org.scribe.model.*;
public class ConstantContactApi extends DefaultApi10a
{
private static final String AUTHORIZE_URL = "https://oauth.constantcontact.com/ws/oauth/confirm_access?oauth_token=%s";
@Override
public String getAccessTokenEndpoint()
{
return "https://oauth.constantcontact.com/ws/oauth/access_token";
}
@Override
public String getAuthorizationUrl(Token requestToken)
{
return String.format(AUTHORIZE_URL, requestToken.getToken());
}
@Override
public String getRequestTokenEndpoint()
{
return "https://oauth.constantcontact.com/ws/oauth/request_token";
}
}
@@ -8,52 +8,97 @@ import org.scribe.services.*;
/**
* Default implementation of the OAuth protocol, version 1.0a
*
* This class is meant to be extended by concrete implementations of the API.
* This class is meant to be extended by concrete implementations of the API,
* providing the endpoints and endpoint-http-verbs.
*
* If your Api adheres to the 1.0a protocol correctly, you just need to extend
* this class and define the getters for your endpoints.
*
* If your Api does something a bit different, you can override the different
* extractors or services, in order to fine-tune the process. Please read the
* javadocs of the interfaces to get an idea of what to do.
*
* @author Pablo Fernandez
*
*/
public abstract class DefaultApi10a implements Api
{
protected AccessTokenExtractor getAccessTokenExtractor()
/**
* Returns the access token extractor.
*
* @return access token extractor
*/
public AccessTokenExtractor getAccessTokenExtractor()
{
return new TokenExtractorImpl();
}
protected BaseStringExtractor getBaseStringExtractor()
/**
* Returns the base string extractor.
*
* @return base string extractor
*/
public BaseStringExtractor getBaseStringExtractor()
{
return new BaseStringExtractorImpl();
}
protected HeaderExtractor getHeaderExtractor()
/**
* Returns the header extractor.
*
* @return header extractor
*/
public HeaderExtractor getHeaderExtractor()
{
return new HeaderExtractorImpl();
}
protected RequestTokenExtractor getRequestTokenExtractor()
/**
* Returns the request token extractor.
*
* @return request token extractor
*/
public RequestTokenExtractor getRequestTokenExtractor()
{
return new TokenExtractorImpl();
}
protected SignatureService getSignatureService()
/**
* Returns the signature service.
*
* @return signature service
*/
public SignatureService getSignatureService()
{
return new HMACSha1SignatureService();
}
protected TimestampService getTimestampService()
/**
* Returns the timestamp service.
*
* @return timestamp service
*/
public TimestampService getTimestampService()
{
return new TimestampServiceImpl();
}
protected Verb getAccessTokenVerb()
/**
* Returns the verb for the access token endpoint (defaults to POST)
*
* @return access token endpoint verb
*/
public Verb getAccessTokenVerb()
{
return Verb.POST;
}
protected Verb getRequestTokenVerb()
/**
* Returns the verb for the request token endpoint (defaults to POST)
*
* @return request token endpoint verb
*/
public Verb getRequestTokenVerb()
{
return Verb.POST;
}
@@ -63,14 +108,23 @@ public abstract class DefaultApi10a implements Api
*
* @return request token URL
*/
protected abstract String getRequestTokenEndpoint();
public abstract String getRequestTokenEndpoint();
/**
* Returns the URL that receives the access token requests.
*
* @return access token URL
*/
protected abstract String getAccessTokenEndpoint();
public abstract String getAccessTokenEndpoint();
/**
* Returns the URL where you should redirect your users to authenticate
* your application.
*
* @param requestToken the request token you need to authorize
* @return the URL where you should redirect your users
*/
public abstract String getAuthorizationUrl(Token requestToken);
/**
* Returns the {@link OAuthService} for this Api
@@ -80,35 +134,8 @@ public abstract class DefaultApi10a implements Api
* @param callback OAuth callback (either URL or 'oob')
* @param scope OAuth scope (optional)
*/
public OAuthService createService(String apiKey, String apiSecret, String callback, String scope)
public OAuthService createService(OAuthConfig config)
{
OAuthService service = createService(apiKey, apiSecret, callback);
service.addScope(scope);
return service;
return new OAuth10aServiceImpl(this, config);
}
private OAuthService createService(String apiKey, String apiSecret, String callback)
{
return new OAuth10aServiceImpl( getSignatureService(),
getTimestampService(),
getBaseStringExtractor(),
getHeaderExtractor(),
getRequestTokenExtractor(),
getAccessTokenExtractor(),
createConfig(apiKey, apiSecret, callback));
}
private OAuthConfig createConfig(String apiKey, String apiSecret, String callback)
{
OAuthConfig config = new OAuthConfig();
config.setRequestTokenVerb(getRequestTokenVerb());
config.setRequestTokenEndpoint(getRequestTokenEndpoint());
config.setAccessTokenVerb(getAccessTokenVerb());
config.setAccessTokenEndpoint(getAccessTokenEndpoint());
config.setApiKey(apiKey);
config.setApiSecret(apiSecret);
config.setCallback(callback);
return config;
}
}
@@ -0,0 +1,70 @@
package org.scribe.builder.api;
import org.scribe.extractors.*;
import org.scribe.model.*;
import org.scribe.oauth.*;
/**
* Default implementation of the OAuth protocol, version 2.0 (draft 11)
*
* This class is meant to be extended by concrete implementations of the API,
* providing the endpoints and endpoint-http-verbs.
*
* If your Api adheres to the 2.0 (draft 11) protocol correctly, you just need to extend
* this class and define the getters for your endpoints.
*
* If your Api does something a bit different, you can override the different
* extractors or services, in order to fine-tune the process. Please read the
* javadocs of the interfaces to get an idea of what to do.
*
* @author Diego Silveira
*
*/
public abstract class DefaultApi20 implements Api
{
/**
* Returns the access token extractor.
*
* @return access token extractor
*/
public AccessTokenExtractor getAccessTokenExtractor()
{
return new TokenExtractor20Impl();
}
/**
* Returns the verb for the access token endpoint (defaults to GET)
*
* @return access token endpoint verb
*/
public Verb getAccessTokenVerb()
{
return Verb.GET;
}
/**
* Returns the URL that receives the access token requests.
*
* @return access token URL
*/
public abstract String getAccessTokenEndpoint();
/**
* Returns the URL where you should redirect your users to authenticate
* your application.
*
* @param config OAuth 2.0 configuration param object
* @return the URL where you should redirect your users
*/
public abstract String getAuthorizationUrl(OAuthConfig config);
/**
* {@inheritDoc}
*/
public OAuthService createService(OAuthConfig config)
{
return new OAuth20ServiceImpl(this, config);
}
}
@@ -0,0 +1,29 @@
package org.scribe.builder.api;
import org.scribe.model.*;
public class DiggApi extends DefaultApi10a
{
private static final String AUTHORIZATION_URL = "http://digg.com/oauth/authorize?oauth_token=%s";
private static final String BASE_URL = "http://services.digg.com/oauth/";
@Override
public String getRequestTokenEndpoint()
{
return BASE_URL + "request_token";
}
@Override
public String getAccessTokenEndpoint()
{
return BASE_URL + "access_token";
}
@Override
public String getAuthorizationUrl(Token requestToken)
{
return String.format(AUTHORIZATION_URL, requestToken.getToken());
}
}
@@ -0,0 +1,25 @@
package org.scribe.builder.api;
import org.scribe.model.*;
public class DropBoxApi extends DefaultApi10a
{
@Override
public String getAccessTokenEndpoint()
{
return "https://api.dropbox.com/1/oauth/access_token";
}
@Override
public String getAuthorizationUrl(Token requestToken)
{
return "https://www.dropbox.com/1/oauth/authorize?oauth_token="+requestToken.getToken();
}
@Override
public String getRequestTokenEndpoint()
{
return "https://api.dropbox.com/1/oauth/request_token";
}
}
@@ -1,30 +1,49 @@
package org.scribe.builder.api;
import org.scribe.model.Verb;
import org.scribe.model.Token;
public class EvernoteApi extends DefaultApi10a
{
@Override
protected Verb getRequestTokenVerb()
{
return Verb.GET;
}
private static final String AUTHORIZATION_URL = "https://www.evernote.com/OAuth.action?oauth_token=%s";
@Override
@Override
public String getRequestTokenEndpoint()
{
return "https://www.evernote.com/oauth";
}
@Override
protected Verb getAccessTokenVerb()
{
return Verb.GET;
}
return "https://www.evernote.com/oauth";
}
@Override
public String getAccessTokenEndpoint()
{
return "https://www.evernote.com/oauth";
return "https://www.evernote.com/oauth";
}
@Override
public String getAuthorizationUrl(Token requestToken)
{
return String.format(AUTHORIZATION_URL, requestToken.getToken());
}
public static class Sandbox extends EvernoteApi
{
private static final String SANDBOX_URL = "https://sandbox.evernote.com";
@Override
public String getRequestTokenEndpoint()
{
return SANDBOX_URL + "/oauth";
}
@Override
public String getAccessTokenEndpoint()
{
return SANDBOX_URL + "/oauth";
}
@Override
public String getAuthorizationUrl(Token requestToken)
{
return String.format(SANDBOX_URL + "/OAuth.action?oauth_token=%s", requestToken.getToken());
}
}
}
@@ -0,0 +1,33 @@
package org.scribe.builder.api;
import org.scribe.model.*;
import org.scribe.utils.*;
public class FacebookApi extends DefaultApi20
{
private static final String AUTHORIZE_URL = "https://www.facebook.com/dialog/oauth?client_id=%s&redirect_uri=%s";
private static final String SCOPED_AUTHORIZE_URL = AUTHORIZE_URL + "&scope=%s";
@Override
public String getAccessTokenEndpoint()
{
return "https://graph.facebook.com/oauth/access_token";
}
@Override
public String getAuthorizationUrl(OAuthConfig config)
{
Preconditions.checkValidUrl(config.getCallback(), "Must provide a valid url as callback. Facebook does not support OOB");
// Append scope if present
if(config.hasScope())
{
return String.format(SCOPED_AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()), OAuthEncoder.encode(config.getScope()));
}
else
{
return String.format(AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()));
}
}
}
@@ -0,0 +1,40 @@
package org.scribe.builder.api;
import org.scribe.model.*;
/**
* OAuth API for Flickr.
*
* @author Darren Greaves
* @see <a href="http://www.flickr.com/services/api/">Flickr API</a>
*/
public class FlickrApi extends DefaultApi10a
{
/**
* {@inheritDoc}
*/
@Override
public String getAccessTokenEndpoint()
{
return "http://www.flickr.com/services/oauth/access_token";
}
/**
* {@inheritDoc}
*/
@Override
public String getAuthorizationUrl(Token requestToken)
{
return "http://www.flickr.com/services/oauth/authorize?oauth_token=" + requestToken.getToken();
}
/**
* {@inheritDoc}
*/
@Override
public String getRequestTokenEndpoint()
{
return "http://www.flickr.com/services/oauth/request_token";
}
}
@@ -0,0 +1,29 @@
package org.scribe.builder.api;
import org.scribe.extractors.*;
import org.scribe.model.*;
import org.scribe.utils.*;
public class Foursquare2Api extends DefaultApi20
{
private static final String AUTHORIZATION_URL = "https://foursquare.com/oauth2/authenticate?client_id=%s&response_type=code&redirect_uri=%s";
@Override
public String getAccessTokenEndpoint()
{
return "https://foursquare.com/oauth2/access_token?grant_type=authorization_code";
}
@Override
public String getAuthorizationUrl(OAuthConfig config)
{
Preconditions.checkValidUrl(config.getCallback(), "Must provide a valid url as callback. Foursquare2 does not support OOB");
return String.format(AUTHORIZATION_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()));
}
@Override
public AccessTokenExtractor getAccessTokenExtractor()
{
return new JsonTokenExtractor();
}
}
@@ -1,16 +1,26 @@
package org.scribe.builder.api;
import org.scribe.model.Token;
public class FoursquareApi extends DefaultApi10a
{
private static final String AUTHORIZATION_URL = "http://foursquare.com/oauth/authorize?oauth_token=%s";
@Override
protected String getAccessTokenEndpoint()
public String getAccessTokenEndpoint()
{
return "http://foursquare.com/oauth/access_token";
}
@Override
protected String getRequestTokenEndpoint()
public String getRequestTokenEndpoint()
{
return "http://foursquare.com/oauth/request_token";
}
@Override
public String getAuthorizationUrl(Token requestToken)
{
return String.format(AUTHORIZATION_URL, requestToken.getToken());
}
}
@@ -0,0 +1,61 @@
package org.scribe.builder.api;
import org.scribe.model.*;
public class FreelancerApi extends DefaultApi10a
{
private static final String AUTHORIZATION_URL = "http://www.freelancer.com/users/api-token/auth.php?oauth_token=%s";
@Override
public String getAccessTokenEndpoint()
{
return "http://api.freelancer.com/RequestAccessToken/requestAccessToken.xml?";
}
@Override
public String getRequestTokenEndpoint()
{
return "http://api.freelancer.com/RequestRequestToken/requestRequestToken.xml";
}
@Override
public Verb getAccessTokenVerb()
{
return Verb.GET;
}
@Override
public Verb getRequestTokenVerb()
{
return Verb.GET;
}
@Override
public String getAuthorizationUrl(Token requestToken)
{
return String.format(AUTHORIZATION_URL, requestToken.getToken());
}
public static class Sandbox extends FreelancerApi
{
private static final String SANDBOX_AUTHORIZATION_URL = "http://www.sandbox.freelancer.com/users/api-token/auth.php";
@Override
public String getRequestTokenEndpoint()
{
return "http://api.sandbox.freelancer.com/RequestRequestToken/requestRequestToken.xml";
}
@Override
public String getAccessTokenEndpoint()
{
return "http://api.sandbox.freelancer.com/RequestAccessToken/requestAccessToken.xml?";
}
@Override
public String getAuthorizationUrl(Token requestToken)
{
return String.format(SANDBOX_AUTHORIZATION_URL + "?oauth_token=%s", requestToken.getToken());
}
}
}
@@ -0,0 +1,29 @@
package org.scribe.builder.api;
import org.scribe.model.Token;
public class GetGlueApi extends DefaultApi10a
{
private static final String AUTHORIZE_URL = "http://getglue.com/oauth/authorize?oauth_token=%s";
private static final String REQUEST_TOKEN_RESOURCE = "https://api.getglue.com/oauth/request_token";
private static final String ACCESS_TOKEN_RESOURCE = "https://api.getglue.com/oauth/access_token";
@Override
public String getAccessTokenEndpoint()
{
return ACCESS_TOKEN_RESOURCE;
}
@Override
public String getRequestTokenEndpoint()
{
return REQUEST_TOKEN_RESOURCE;
}
@Override
public String getAuthorizationUrl(Token requestToken)
{
return String.format(AUTHORIZE_URL, requestToken.getToken());
}
}
@@ -1,16 +1,38 @@
package org.scribe.builder.api;
import org.scribe.model.*;
public class GoogleApi extends DefaultApi10a
{
private static final String AUTHORIZATION_URL = "https://www.google.com/accounts/OAuthAuthorizeToken?oauth_token=%s";
@Override
protected String getAccessTokenEndpoint()
public String getAccessTokenEndpoint()
{
return "https://www.google.com/accounts/OAuthGetAccessToken";
}
@Override
protected String getRequestTokenEndpoint()
public String getRequestTokenEndpoint()
{
return "https://www.google.com/accounts/OAuthGetRequestToken";
}
@Override
public Verb getAccessTokenVerb()
{
return Verb.GET;
}
@Override
public Verb getRequestTokenVerb()
{
return Verb.GET;
}
@Override
public String getAuthorizationUrl(Token requestToken)
{
return String.format(AUTHORIZATION_URL, requestToken.getToken());
}
}
@@ -0,0 +1,32 @@
package org.scribe.builder.api;
import org.scribe.model.*;
/**
* OAuth API for ImgUr
*
* @author David Wursteisen
* @see <a href="http://api.imgur.com/#authapi">ImgUr API</a>
*/
public class ImgUrApi extends DefaultApi10a
{
@Override
public String getRequestTokenEndpoint()
{
return "https://api.imgur.com/oauth/request_token";
}
@Override
public String getAccessTokenEndpoint()
{
return "https://api.imgur.com/oauth/access_token";
}
@Override
public String getAuthorizationUrl(Token requestToken)
{
return String.format("https://api.imgur.com/oauth/authorize?oauth_token=%s", requestToken.getToken());
}
}
@@ -0,0 +1,40 @@
package org.scribe.builder.api;
import org.scribe.model.*;
public class KaixinApi extends DefaultApi10a
{
private static final String REQUEST_TOKEN_URL = "http://api.kaixin001.com/oauth/request_token";
private static final String ACCESS_TOKEN_URL = "http://api.kaixin001.com/oauth/access_token";
private static final String AUTHORIZE_URL = "http://api.kaixin001.com/oauth/authorize?oauth_token=%s";
@Override
public String getRequestTokenEndpoint()
{
return REQUEST_TOKEN_URL;
}
@Override
public String getAccessTokenEndpoint()
{
return ACCESS_TOKEN_URL;
}
@Override
public String getAuthorizationUrl(Token requestToken)
{
return String.format(AUTHORIZE_URL, requestToken.getToken());
}
@Override
public Verb getRequestTokenVerb()
{
return Verb.GET;
}
@Override
public Verb getAccessTokenVerb()
{
return Verb.GET;
}
}
@@ -0,0 +1,41 @@
package org.scribe.builder.api;
import org.scribe.extractors.*;
import org.scribe.model.*;
import org.scribe.utils.*;
/**
* Kaixin(http://www.kaixin001.com/) open platform api based on OAuth 2.0.
*/
public class KaixinApi20 extends DefaultApi20
{
private static final String AUTHORIZE_URL = "http://api.kaixin001.com/oauth2/authorize?client_id=%s&redirect_uri=%s&response_type=code";
private static final String SCOPED_AUTHORIZE_URL = AUTHORIZE_URL + "&scope=%s";
@Override
public AccessTokenExtractor getAccessTokenExtractor()
{
return new JsonTokenExtractor();
}
@Override
public String getAccessTokenEndpoint()
{
return "https://api.kaixin001.com/oauth2/access_token?grant_type=authorization_code";
}
@Override
public String getAuthorizationUrl(OAuthConfig config)
{
// Append scope if present
if (config.hasScope())
{
return String.format(SCOPED_AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()), OAuthEncoder.encode(config.getScope()));
}
else
{
return String.format(AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()));
}
}
}
@@ -1,16 +1,27 @@
package org.scribe.builder.api;
import org.scribe.model.*;
public class LinkedInApi extends DefaultApi10a
{
private static final String AUTHORIZE_URL = "https://api.linkedin.com/uas/oauth/authorize?oauth_token=%s";
@Override
protected String getAccessTokenEndpoint()
public String getAccessTokenEndpoint()
{
return "https://api.linkedin.com/uas/oauth/accessToken";
}
@Override
protected String getRequestTokenEndpoint()
public String getRequestTokenEndpoint()
{
return "https://api.linkedin.com/uas/oauth/requestToken";
}
@Override
public String getAuthorizationUrl(Token requestToken)
{
return String.format(AUTHORIZE_URL, requestToken.getToken());
}
}
@@ -0,0 +1,40 @@
package org.scribe.builder.api;
import org.scribe.extractors.*;
import org.scribe.model.*;
import org.scribe.utils.*;
public class LiveApi extends DefaultApi20
{
private static final String AUTHORIZE_URL = "https://oauth.live.com/authorize?client_id=%s&redirect_uri=%s&response_type=code";
private static final String SCOPED_AUTHORIZE_URL = AUTHORIZE_URL + "&scope=%s";
@Override
public String getAccessTokenEndpoint()
{
return "https://oauth.live.com/token?grant_type=authorization_code";
}
@Override
public String getAuthorizationUrl(OAuthConfig config)
{
Preconditions.checkValidUrl(config.getCallback(), "Must provide a valid url as callback. Live does not support OOB");
// Append scope if present
if (config.hasScope())
{
return String.format(SCOPED_AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()), OAuthEncoder.encode(config.getScope()));
}
else
{
return String.format(AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()));
}
}
@Override
public AccessTokenExtractor getAccessTokenExtractor()
{
return new JsonTokenExtractor();
}
}
@@ -0,0 +1,28 @@
package org.scribe.builder.api;
import org.scribe.model.Token;
public class LoveFilmApi extends DefaultApi10a
{
private static final String REQUEST_TOKEN_URL = "http://openapi.lovefilm.com/oauth/request_token";
private static final String ACCESS_TOKEN_URL = "http://openapi.lovefilm.com/oauth/access_token";
private static final String AUTHORIZE_URL = "https://www.lovefilm.com/activate?oauth_token=%s";
@Override
public String getRequestTokenEndpoint()
{
return REQUEST_TOKEN_URL;
}
@Override
public String getAccessTokenEndpoint()
{
return ACCESS_TOKEN_URL;
}
@Override
public String getAuthorizationUrl(Token requestToken)
{
return String.format(AUTHORIZE_URL, requestToken.getToken());
}
}
@@ -0,0 +1,30 @@
package org.scribe.builder.api;
import org.scribe.model.Token;
/**
* OAuth access to the Meetup.com API.
* For more information visit http://www.meetup.com/api
*/
public class MeetupApi extends DefaultApi10a
{
private static final String AUTHORIZE_URL = "http://www.meetup.com/authenticate?oauth_token=%s";
@Override
public String getRequestTokenEndpoint()
{
return "http://api.meetup.com/oauth/request/";
}
@Override
public String getAccessTokenEndpoint()
{
return "http://api.meetup.com/oauth/access/";
}
@Override
public String getAuthorizationUrl(Token requestToken)
{
return String.format(AUTHORIZE_URL, requestToken.getToken());
}
}
@@ -0,0 +1,29 @@
package org.scribe.builder.api;
import org.scribe.model.Token;
public class MisoApi extends DefaultApi10a
{
private static final String AUTHORIZE_URL = "http://gomiso.com/oauth/authorize?oauth_token=%s";
private static final String REQUEST_TOKEN_RESOURCE = "http://gomiso.com/oauth/request_token";
private static final String ACCESS_TOKEN_RESOURCE = "http://gomiso.com/oauth/access_token";
@Override
public String getAccessTokenEndpoint()
{
return ACCESS_TOKEN_RESOURCE;
}
@Override
public String getRequestTokenEndpoint()
{
return REQUEST_TOKEN_RESOURCE;
}
@Override
public String getAuthorizationUrl(Token requestToken)
{
return String.format(AUTHORIZE_URL, requestToken.getToken());
}
}
@@ -0,0 +1,28 @@
package org.scribe.builder.api;
import org.scribe.model.Token;
public class NetProspexApi extends DefaultApi10a
{
private static final String REQUEST_TOKEN_URL = "https://api.netprospex.com/1.0/oauth/request-token";
private static final String ACCESS_TOKEN_URL = "https://api.netprospex.com/1.0/oauth/access-token";
private static final String AUTHORIZE_URL = "https://api.netprospex.com/1.0/oauth/authorize?oauth_token=%s";
@Override
public String getRequestTokenEndpoint()
{
return REQUEST_TOKEN_URL;
}
@Override
public String getAccessTokenEndpoint()
{
return ACCESS_TOKEN_URL;
}
@Override
public String getAuthorizationUrl(Token requestToken)
{
return String.format(AUTHORIZE_URL, requestToken.getToken());
}
}
@@ -0,0 +1,47 @@
package org.scribe.builder.api;
import org.scribe.model.*;
public class NeteaseWeibooApi extends DefaultApi10a
{
private static final String REQUEST_TOKEN_URL = "http://api.t.163.com/oauth/request_token";
private static final String ACCESS_TOKEN_URL = "http://api.t.163.com/oauth/access_token";
private static final String AUTHORIZE_URL = "http://api.t.163.com/oauth/authorize?oauth_token=%s";
private static final String AUTHENTICATE_URL = "http://api.t.163.com/oauth/authenticate?oauth_token=%s";
@Override
public String getRequestTokenEndpoint()
{
return REQUEST_TOKEN_URL;
}
@Override
public String getAccessTokenEndpoint()
{
return ACCESS_TOKEN_URL;
}
@Override
/**
* this method will ignore your callback
* if you're creating a desktop client please choose this url
* else your can call getAuthenticateUrl
*
* via http://open.t.163.com/wiki/index.php?title=%E8%AF%B7%E6%B1%82%E7%94%A8%E6%88%B7%E6%8E%88%E6%9D%83Token(oauth/authorize)
*/
public String getAuthorizationUrl(Token requestToken)
{
return String.format(AUTHORIZE_URL, requestToken.getToken());
}
/**
* this method is for web client with callback url
* if you're creating a desktop client please call getAuthorizationUrl
*
* via http://open.t.163.com/wiki/index.php?title=%E8%AF%B7%E6%B1%82%E7%94%A8%E6%88%B7%E6%8E%88%E6%9D%83Token(oauth/authenticate)
*/
public String getAuthenticateUrl(Token requestToken)
{
return String.format(AUTHENTICATE_URL, requestToken.getToken());
}
}
@@ -0,0 +1,39 @@
package org.scribe.builder.api;
import org.scribe.model.Token;
public class PlurkApi extends DefaultApi10a
{
private static final String REQUEST_TOKEN_URL = "http://www.plurk.com/OAuth/request_token";
private static final String AUTHORIZATION_URL = "http://www.plurk.com/OAuth/authorize?oauth_token=%s";
private static final String ACCESS_TOKEN_URL = "http://www.plurk.com/OAuth/access_token";
@Override
public String getRequestTokenEndpoint()
{
return REQUEST_TOKEN_URL;
}
@Override
public String getAuthorizationUrl(Token requestToken)
{
return String.format(AUTHORIZATION_URL, requestToken.getToken());
}
@Override
public String getAccessTokenEndpoint()
{
return ACCESS_TOKEN_URL;
}
public class Mobile extends PlurkApi
{
private static final String AUTHORIZATION_URL = "http://www.plurk.com/m/authorize?oauth_token=%s";
@Override
public String getAuthorizationUrl(Token requestToken)
{
return String.format(AUTHORIZATION_URL, requestToken.getToken());
}
}
}
@@ -0,0 +1,26 @@
package org.scribe.builder.api;
import org.scribe.model.*;
public class Px500Api extends DefaultApi10a
{
private static final String AUTHORIZATION_URL = "https://api.500px.com/v1/oauth/authorize?oauth_token=%s";
@Override
public String getAccessTokenEndpoint()
{
return "https://api.500px.com/v1/oauth/access_token";
}
@Override
public String getRequestTokenEndpoint()
{
return "https://api.500px.com/v1/oauth/request_token";
}
@Override
public String getAuthorizationUrl(Token requestToken)
{
return String.format(AUTHORIZATION_URL, requestToken.getToken());
}
}
@@ -0,0 +1,28 @@
package org.scribe.builder.api;
import org.scribe.model.*;
public class QWeiboApi extends DefaultApi10a
{
private static final String REQUEST_TOKEN_URL = "https://open.t.qq.com/cgi-bin/request_token";
private static final String ACCESS_TOKEN_URL = "https://open.t.qq.com/cgi-bin/access_token";
private static final String AUTHORIZE_URL = "https://open.t.qq.com/cgi-bin/authorize?oauth_token=%s";
@Override
public String getRequestTokenEndpoint()
{
return REQUEST_TOKEN_URL;
}
@Override
public String getAccessTokenEndpoint()
{
return ACCESS_TOKEN_URL;
}
@Override
public String getAuthorizationUrl(Token requestToken)
{
return String.format(AUTHORIZE_URL, requestToken.getToken());
}
}
@@ -0,0 +1,40 @@
package org.scribe.builder.api;
import org.scribe.extractors.*;
import org.scribe.model.*;
import org.scribe.utils.*;
/**
* Renren(http://www.renren.com/) OAuth 2.0 based api.
*/
public class RenrenApi extends DefaultApi20
{
private static final String AUTHORIZE_URL = "https://graph.renren.com/oauth/authorize?client_id=%s&redirect_uri=%s&response_type=code";
private static final String SCOPED_AUTHORIZE_URL = AUTHORIZE_URL + "&scope=%s";
@Override
public AccessTokenExtractor getAccessTokenExtractor()
{
return new JsonTokenExtractor();
}
@Override
public String getAccessTokenEndpoint()
{
return "https://graph.renren.com/oauth/token?grant_type=authorization_code";
}
@Override
public String getAuthorizationUrl(OAuthConfig config)
{
// Append scope if present
if (config.hasScope())
{
return String.format(SCOPED_AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()), OAuthEncoder.encode(config.getScope()));
}
else
{
return String.format(AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()));
}
}
}
@@ -0,0 +1,40 @@
package org.scribe.builder.api;
import org.scribe.model.*;
public class SapoApi extends DefaultApi10a
{
private static final String AUTHORIZE_URL = "https://id.sapo.pt/oauth/authorize?oauth_token=%s";
private static final String ACCESS_URL = "https://id.sapo.pt/oauth/access_token";
private static final String REQUEST_URL = "https://id.sapo.pt/oauth/request_token";
@Override
public String getAccessTokenEndpoint()
{
return ACCESS_URL;
}
@Override
public String getRequestTokenEndpoint()
{
return REQUEST_URL;
}
@Override
public String getAuthorizationUrl(Token requestToken)
{
return String.format(AUTHORIZE_URL, requestToken.getToken());
}
@Override
public Verb getRequestTokenVerb()
{
return Verb.GET;
}
@Override
public Verb getAccessTokenVerb()
{
return Verb.GET;
}
}
@@ -0,0 +1,29 @@
package org.scribe.builder.api;
import org.scribe.model.Token;
/**
* @author: Pablo Fernandez
*/
public class SimpleGeoApi extends DefaultApi10a
{
private static final String ENDPOINT = "these are not used since SimpleGeo uses 2 legged OAuth";
@Override
public String getRequestTokenEndpoint()
{
return ENDPOINT;
}
@Override
public String getAccessTokenEndpoint()
{
return ENDPOINT;
}
@Override
public String getAuthorizationUrl(Token requestToken)
{
return ENDPOINT;
}
}
@@ -0,0 +1,28 @@
package org.scribe.builder.api;
import org.scribe.model.*;
public class SinaWeiboApi extends DefaultApi10a
{
private static final String REQUEST_TOKEN_URL = "http://api.t.sina.com.cn/oauth/request_token";
private static final String ACCESS_TOKEN_URL = "http://api.t.sina.com.cn/oauth/access_token";
private static final String AUTHORIZE_URL = "http://api.t.sina.com.cn/oauth/authorize?oauth_token=%s";
@Override
public String getRequestTokenEndpoint()
{
return REQUEST_TOKEN_URL;
}
@Override
public String getAccessTokenEndpoint()
{
return ACCESS_TOKEN_URL;
}
@Override
public String getAuthorizationUrl(Token requestToken)
{
return String.format(AUTHORIZE_URL, requestToken.getToken());
}
}
@@ -0,0 +1,46 @@
package org.scribe.builder.api;
import org.scribe.extractors.*;
import org.scribe.model.*;
import org.scribe.utils.*;
/**
* SinaWeibo OAuth 2.0 api.
*/
public class SinaWeiboApi20 extends DefaultApi20
{
private static final String AUTHORIZE_URL = "https://api.weibo.com/oauth2/authorize?client_id=%s&redirect_uri=%s&response_type=code";
private static final String SCOPED_AUTHORIZE_URL = AUTHORIZE_URL + "&scope=%s";
@Override
public Verb getAccessTokenVerb()
{
return Verb.POST;
}
@Override
public AccessTokenExtractor getAccessTokenExtractor()
{
return new JsonTokenExtractor();
}
@Override
public String getAccessTokenEndpoint()
{
return "https://api.weibo.com/oauth2/access_token?grant_type=authorization_code";
}
@Override
public String getAuthorizationUrl(OAuthConfig config)
{
// Append scope if present
if (config.hasScope())
{
return String.format(SCOPED_AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()), OAuthEncoder.encode(config.getScope()));
}
else
{
return String.format(AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()));
}
}
}
@@ -0,0 +1,35 @@
package org.scribe.builder.api;
import org.scribe.model.*;
/**
* OAuth API for Skyrock.
*
* @author Nicolas Quiénot
* @see <a href="http://www.skyrock.com/developer/">Skyrock.com API</a>
*/
public class SkyrockApi extends DefaultApi10a
{
private static final String API_ENDPOINT = "https://api.skyrock.com/v2";
private static final String REQUEST_TOKEN_RESOURCE = "/oauth/initiate";
private static final String AUTHORIZE_URL = "/oauth/authorize?oauth_token=%s";
private static final String ACCESS_TOKEN_RESOURCE = "/oauth/token";
@Override
public String getAccessTokenEndpoint()
{
return API_ENDPOINT + ACCESS_TOKEN_RESOURCE;
}
@Override
public String getRequestTokenEndpoint()
{
return API_ENDPOINT + REQUEST_TOKEN_RESOURCE;
}
@Override
public String getAuthorizationUrl(Token requestToken)
{
return String.format(API_ENDPOINT + AUTHORIZE_URL, requestToken.getToken());
}
}
@@ -0,0 +1,28 @@
package org.scribe.builder.api;
import org.scribe.model.*;
public class SohuWeiboApi extends DefaultApi10a
{
private static final String REQUEST_TOKEN_URL = "http://api.t.sohu.com/oauth/request_token";
private static final String ACCESS_TOKEN_URL = "http://api.t.sohu.com/oauth/access_token";
private static final String AUTHORIZE_URL = "http://api.t.sohu.com/oauth/authorize?oauth_token=%s";
@Override
public String getRequestTokenEndpoint()
{
return REQUEST_TOKEN_URL;
}
@Override
public String getAccessTokenEndpoint()
{
return ACCESS_TOKEN_URL;
}
@Override
public String getAuthorizationUrl(Token requestToken)
{
return String.format(AUTHORIZE_URL, requestToken.getToken());
}
}
@@ -0,0 +1,28 @@
package org.scribe.builder.api;
import org.scribe.model.Token;
public class TumblrApi extends DefaultApi10a
{
private static final String AUTHORIZE_URL = "https://www.tumblr.com/oauth/authorize?oauth_token=%s";
private static final String REQUEST_TOKEN_RESOURCE = "http://www.tumblr.com/oauth/request_token";
private static final String ACCESS_TOKEN_RESOURCE = "http://www.tumblr.com/oauth/access_token";
@Override
public String getAccessTokenEndpoint()
{
return ACCESS_TOKEN_RESOURCE;
}
@Override
public String getRequestTokenEndpoint()
{
return REQUEST_TOKEN_RESOURCE;
}
@Override
public String getAuthorizationUrl(Token requestToken)
{
return String.format(AUTHORIZE_URL, requestToken.getToken());
}
}
@@ -1,16 +1,66 @@
package org.scribe.builder.api;
import org.scribe.model.Token;
public class TwitterApi extends DefaultApi10a
{
private static final String AUTHORIZE_URL = "https://api.twitter.com/oauth/authorize?oauth_token=%s";
private static final String REQUEST_TOKEN_RESOURCE = "api.twitter.com/oauth/request_token";
private static final String ACCESS_TOKEN_RESOURCE = "api.twitter.com/oauth/access_token";
@Override
protected String getAccessTokenEndpoint()
public String getAccessTokenEndpoint()
{
return "http://api.twitter.com/oauth/access_token";
return "http://" + ACCESS_TOKEN_RESOURCE;
}
@Override
protected String getRequestTokenEndpoint()
public String getRequestTokenEndpoint()
{
return "http://api.twitter.com/oauth/request_token";
return "http://" + REQUEST_TOKEN_RESOURCE;
}
@Override
public String getAuthorizationUrl(Token requestToken)
{
return String.format(AUTHORIZE_URL, requestToken.getToken());
}
public static class SSL extends TwitterApi
{
@Override
public String getAccessTokenEndpoint()
{
return "https://" + ACCESS_TOKEN_RESOURCE;
}
@Override
public String getRequestTokenEndpoint()
{
return "https://" + REQUEST_TOKEN_RESOURCE;
}
}
/**
* Twitter 'friendlier' authorization endpoint for OAuth.
*
* Uses SSL.
*/
public static class Authenticate extends SSL
{
private static final String AUTHENTICATE_URL = "https://api.twitter.com/oauth/authenticate?oauth_token=%s";
@Override
public String getAuthorizationUrl(Token requestToken)
{
return String.format(AUTHENTICATE_URL, requestToken.getToken());
}
}
/**
* Just an alias to the default (SSL) authorization endpoint.
*
* Need to include this for symmetry with 'Authenticate' only.
*/
public static class Authorize extends SSL{}
}
@@ -1,16 +1,26 @@
package org.scribe.builder.api;
import org.scribe.model.Token;
public class VimeoApi extends DefaultApi10a
{
private static final String AUTHORIZATION_URL = "http://vimeo.com/oauth/authorize?oauth_token=%s";
@Override
protected String getAccessTokenEndpoint()
public String getAccessTokenEndpoint()
{
return "http://vimeo.com/oauth/access_token";
}
@Override
protected String getRequestTokenEndpoint()
public String getRequestTokenEndpoint()
{
return "http://vimeo.com/oauth/request_token";
}
@Override
public String getAuthorizationUrl(Token requestToken)
{
return String.format(AUTHORIZATION_URL, requestToken.getToken());
}
}
@@ -0,0 +1,41 @@
package org.scribe.builder.api;
import org.scribe.extractors.*;
import org.scribe.utils.*;
import org.scribe.model.*;
/**
* @author Boris G. Tsirkin <mail@dotbg.name>
* @since 20.4.2011
*/
public class VkontakteApi extends DefaultApi20
{
private static final String AUTHORIZE_URL = "https://api.vkontakte.ru/oauth/authorize?client_id=%s&redirect_uri=%s&response_type=code";
private static final String SCOPED_AUTHORIZE_URL = String.format("%s&scope=%%s", AUTHORIZE_URL);
@Override
public String getAccessTokenEndpoint()
{
return "https://api.vkontakte.ru/oauth/access_token";
}
@Override
public String getAuthorizationUrl(OAuthConfig config)
{
Preconditions.checkValidUrl(config.getCallback(), "Valid url is required for a callback. Vkontakte does not support OOB");
if(config.hasScope())// Appending scope if present
{
return String.format(SCOPED_AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()), OAuthEncoder.encode(config.getScope()));
}
else
{
return String.format(AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()));
}
}
@Override
public AccessTokenExtractor getAccessTokenExtractor()
{
return new JsonTokenExtractor();
}
}
@@ -1,16 +1,26 @@
package org.scribe.builder.api;
import org.scribe.model.Token;
public class YahooApi extends DefaultApi10a
{
private static final String AUTHORIZE_URL = "https://api.login.yahoo.com/oauth/v2/request_auth?oauth_token=%s";
@Override
protected String getAccessTokenEndpoint()
public String getAccessTokenEndpoint()
{
return "https://api.login.yahoo.com/oauth/v2/get_token";
}
@Override
protected String getRequestTokenEndpoint()
public String getRequestTokenEndpoint()
{
return "https://api.login.yahoo.com/oauth/v2/get_request_token";
}
@Override
public String getAuthorizationUrl(Token requestToken)
{
return String.format(AUTHORIZE_URL, requestToken.getToken());
}
}
@@ -1,18 +1,33 @@
package org.scribe.builder.api;
import org.scribe.model.*;
import org.scribe.services.*;
public class YammerApi extends DefaultApi10a
{
private static final String AUTHORIZATION_URL = "'https://www.yammer.com/oauth/authorize?oauth_token=%s'";
@Override
public String getRequestTokenEndpoint()
@Override
public String getRequestTokenEndpoint()
{
return "https://www.yammer.com/oauth/request_token";
}
return "https://www.yammer.com/oauth/request_token";
}
@Override
public String getAccessTokenEndpoint()
@Override
public String getAccessTokenEndpoint()
{
return "https://www.yammer.com/oauth/access_token";
}
return "https://www.yammer.com/oauth/access_token";
}
@Override
public String getAuthorizationUrl(Token requestToken)
{
return String.format(AUTHORIZATION_URL, requestToken.getToken());
}
@Override
public SignatureService getSignatureService()
{
return new PlaintextSignatureService();
}
}
@@ -0,0 +1,14 @@
package org.scribe.exceptions;
/**
* @author: Pablo Fernandez
*/
public class OAuthConnectionException extends OAuthException
{
private static final String MSG = "There was a problem while creating a connection to the remote service.";
public OAuthConnectionException(Exception e)
{
super(MSG, e);
}
}
@@ -8,6 +8,7 @@ package org.scribe.exceptions;
public class OAuthSignatureException extends OAuthException
{
private static final long serialVersionUID = 1L;
private static final String MSG = "Error while signing string: %s";
/**
* Default constructor
@@ -17,7 +18,7 @@ public class OAuthSignatureException extends OAuthException
*/
public OAuthSignatureException(String stringToSign, Exception e)
{
super("Error while signing string: " + stringToSign, e);
super(String.format(MSG, stringToSign), e);
}
}
@@ -1,7 +1,5 @@
package org.scribe.extractors;
import java.util.*;
import org.scribe.exceptions.*;
import org.scribe.model.*;
import org.scribe.utils.*;
@@ -23,20 +21,19 @@ public class BaseStringExtractorImpl implements BaseStringExtractor
public String extract(OAuthRequest request)
{
checkPreconditions(request);
String verb = URLUtils.percentEncode(request.getVerb().name());
String url = URLUtils.percentEncode(request.getSanitizedUrl());
String verb = OAuthEncoder.encode(request.getVerb().name());
String url = OAuthEncoder.encode(request.getSanitizedUrl());
String params = getSortedAndEncodedParams(request);
return String.format(AMPERSAND_SEPARATED_STRING, verb, url, params);
}
private String getSortedAndEncodedParams(OAuthRequest request)
{
Map<String, String> params = new HashMap<String, String>();
params.putAll(request.getQueryStringParams());
params.putAll(request.getBodyParams());
params.putAll(request.getOauthParameters());
params = MapUtils.sort(params);
return URLUtils.percentEncode(URLUtils.formURLEncodeMap(params));
ParameterList params = new ParameterList();
params.addAll(request.getQueryStringParams());
params.addAll(request.getBodyParams());
params.addAll(new ParameterList(request.getOauthParameters()));
return params.sort().asOauthBaseString();
}
private void checkPreconditions(OAuthRequest request)
@@ -32,7 +32,7 @@ public class HeaderExtractorImpl implements HeaderExtractor
{
header.append(PARAM_SEPARATOR);
}
header.append(String.format("%s=\"%s\"", key, URLUtils.percentEncode(parameters.get(key))));
header.append(String.format("%s=\"%s\"", key, OAuthEncoder.encode(parameters.get(key))));
}
return header.toString();
}
@@ -0,0 +1,28 @@
package org.scribe.extractors;
import java.util.regex.*;
import org.scribe.exceptions.*;
import org.scribe.model.*;
import org.scribe.utils.*;
public class JsonTokenExtractor implements AccessTokenExtractor
{
private Pattern accessTokenPattern = Pattern.compile("\"access_token\":\\s*\"(\\S*?)\"");
@Override
public Token extract(String response)
{
Preconditions.checkEmptyString(response, "Cannot extract a token from a null or empty String");
Matcher matcher = accessTokenPattern.matcher(response);
if(matcher.find())
{
return new Token(matcher.group(1), "", response);
}
else
{
throw new OAuthException("Cannot extract an acces token. Response was: " + response);
}
}
}
@@ -0,0 +1,36 @@
package org.scribe.extractors;
import java.util.regex.*;
import org.scribe.exceptions.*;
import org.scribe.model.*;
import org.scribe.utils.*;
/**
* Default implementation of {@AccessTokenExtractor}. Conforms to OAuth 2.0
*
*/
public class TokenExtractor20Impl implements AccessTokenExtractor
{
private static final String TOKEN_REGEX = "access_token=([^&]+)";
private static final String EMPTY_SECRET = "";
/**
* {@inheritDoc}
*/
public Token extract(String response)
{
Preconditions.checkEmptyString(response, "Response body is incorrect. Can't extract a token from an empty string");
Matcher matcher = Pattern.compile(TOKEN_REGEX).matcher(response);
if (matcher.find())
{
String token = OAuthEncoder.decode(matcher.group(1));
return new Token(token, EMPTY_SECRET, response);
}
else
{
throw new OAuthException("Response body is incorrect. Can't extract a token from this: '" + response + "'", null);
}
}
}
@@ -15,7 +15,8 @@ import org.scribe.utils.*;
*/
public class TokenExtractorImpl implements RequestTokenExtractor, AccessTokenExtractor
{
private static final String TOKEN_REGEX = "oauth_token=(\\S*)&oauth_token_secret=(\\S*?)(&(.*))?";
private static final Pattern TOKEN_REGEX = Pattern.compile("oauth_token=([^&]+)");
private static final Pattern SECRET_REGEX = Pattern.compile("oauth_token_secret=([^&]*)");
/**
* {@inheritDoc}
@@ -23,16 +24,21 @@ public class TokenExtractorImpl implements RequestTokenExtractor, AccessTokenExt
public Token extract(String response)
{
Preconditions.checkEmptyString(response, "Response body is incorrect. Can't extract a token from an empty string");
String token = extract(response, TOKEN_REGEX);
String secret = extract(response, SECRET_REGEX);
return new Token(token, secret, response);
}
Matcher matcher = Pattern.compile(TOKEN_REGEX).matcher(response);
if (matcher.matches())
private String extract(String response, Pattern p)
{
Matcher matcher = p.matcher(response);
if (matcher.find() && matcher.groupCount() >= 1)
{
String token = URLUtils.percentDecode(matcher.group(1));
String secret = URLUtils.percentDecode(matcher.group(2));
return new Token(token, secret);
} else
return OAuthEncoder.decode(matcher.group(1));
}
else
{
throw new OAuthException("Response body is incorrect. Can't extract a token from this: '" + response + "'", null);
throw new OAuthException("Response body is incorrect. Can't extract token and secret from this: '" + response + "'", null);
}
}
}
+44 -53
View File
@@ -1,5 +1,7 @@
package org.scribe.model;
import java.io.*;
/**
* Parameter object that groups OAuth config values
*
@@ -7,82 +9,71 @@ package org.scribe.model;
*/
public class OAuthConfig
{
private String apiKey;
private String apiSecret;
private String callback;
private String requestTokenEndpoint;
private String accessTokenEndpoint;
private Verb requestTokenVerb;
private Verb accessTokenVerb;
private final String apiKey;
private final String apiSecret;
private final String callback;
private final SignatureType signatureType;
private final String scope;
private final OutputStream debugStream;
public OAuthConfig(String key, String secret)
{
this(key, secret, null, null, null, null);
}
public OAuthConfig(String key, String secret, String callback, SignatureType type, String scope, OutputStream stream)
{
this.apiKey = key;
this.apiSecret = secret;
this.callback = callback;
this.signatureType = type;
this.scope = scope;
this.debugStream = stream;
}
public String getApiKey()
{
return apiKey;
}
public void setApiKey(String apiKey)
{
this.apiKey = apiKey;
}
public String getApiSecret()
{
return apiSecret;
}
public void setApiSecret(String apiSecret)
{
this.apiSecret = apiSecret;
}
public String getCallback()
{
return callback != null ? callback : OAuthConstants.OUT_OF_BAND;
return callback;
}
public void setCallback(String callback)
public SignatureType getSignatureType()
{
this.callback = callback;
return signatureType;
}
public String getRequestTokenEndpoint()
public String getScope()
{
return requestTokenEndpoint;
return scope;
}
public void setRequestTokenEndpoint(String requestTokenEndpoint)
public boolean hasScope()
{
this.requestTokenEndpoint = requestTokenEndpoint;
return scope != null;
}
public String getAccessTokenEndpoint()
public void log(String message)
{
return accessTokenEndpoint;
if (debugStream != null)
{
message = message + "\n";
try
{
debugStream.write(message.getBytes("UTF8"));
}
catch (Exception e)
{
throw new RuntimeException("there were problems while writting to the debug stream", e);
}
}
}
public void setAccessTokenEndpoint(String accessTokenEndpoint)
{
this.accessTokenEndpoint = accessTokenEndpoint;
}
public Verb getRequestTokenVerb()
{
return requestTokenVerb != null ? requestTokenVerb : Verb.GET;
}
public void setRequestTokenVerb(Verb requestTokenVerb)
{
this.requestTokenVerb = requestTokenVerb;
}
public Verb getAccessTokenVerb()
{
return accessTokenVerb != null ? accessTokenVerb : Verb.GET;
}
public void setAccessTokenVerb(Verb accessTokenVerb)
{
this.accessTokenVerb = accessTokenVerb;
}
}
}
@@ -38,4 +38,12 @@ public class OAuthConstants
public static final String HEADER = "Authorization";
public static final Token EMPTY_TOKEN = new Token("", "");
public static final String SCOPE = "scope";
//OAuth 2.0
public static final String ACCESS_TOKEN = "access_token";
public static final String CLIENT_ID = "client_id";
public static final String CLIENT_SECRET = "client_secret";
public static final String REDIRECT_URI = "redirect_uri";
public static final String CODE = "code";
}
@@ -0,0 +1,50 @@
package org.scribe.model;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import org.scribe.exceptions.OAuthException;
import org.scribe.utils.OAuthEncoder;
/**
* @author: Pablo Fernandez
*/
public class Parameter implements Comparable<Parameter>
{
private static final String UTF = "UTF8";
private final String key;
private final String value;
public Parameter(String key, String value)
{
this.key = key;
this.value = value;
}
public String asUrlEncodedPair()
{
return OAuthEncoder.encode(key).concat("=").concat(OAuthEncoder.encode(value));
}
public boolean equals(Object other)
{
if(other == null) return false;
if(other == this) return true;
if(!(other instanceof Parameter)) return false;
Parameter otherParam = (Parameter) other;
return otherParam.key.equals(key) && otherParam.value.equals(value);
}
public int hashCode()
{
return key.hashCode() + value.hashCode();
}
public int compareTo(Parameter parameter)
{
int keyDiff = key.compareTo(parameter.key);
return keyDiff != 0 ? keyDiff : value.compareTo(parameter.value);
}
}
@@ -0,0 +1,114 @@
package org.scribe.model;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import org.scribe.utils.OAuthEncoder;
import org.scribe.utils.Preconditions;
/**
* @author: Pablo Fernandez
*/
public class ParameterList
{
private static final char QUERY_STRING_SEPARATOR = '?';
private static final String PARAM_SEPARATOR = "&";
private static final String PAIR_SEPARATOR = "=";
private static final String EMPTY_STRING = "";
private final List<Parameter> params;
public ParameterList()
{
params = new ArrayList<Parameter>();
}
ParameterList(List<Parameter> params)
{
this.params = new ArrayList<Parameter>(params);
}
public ParameterList(Map<String, String> map)
{
this();
for(Map.Entry<String, String> entry : map.entrySet())
{
params.add(new Parameter(entry.getKey(), entry.getValue()));
}
}
public void add(String key, String value)
{
params.add(new Parameter(key, value));
}
public String appendTo(String url)
{
Preconditions.checkNotNull(url, "Cannot append to null URL");
String queryString = asFormUrlEncodedString();
if (queryString.equals(EMPTY_STRING))
{
return url;
}
else
{
url += url.indexOf(QUERY_STRING_SEPARATOR) != -1 ? PARAM_SEPARATOR : QUERY_STRING_SEPARATOR;
url += queryString;
return url;
}
}
public String asOauthBaseString()
{
return OAuthEncoder.encode(asFormUrlEncodedString());
}
public String asFormUrlEncodedString()
{
if (params.size() == 0) return EMPTY_STRING;
StringBuilder builder = new StringBuilder();
for(Parameter p : params)
{
builder.append('&').append(p.asUrlEncodedPair());
}
return builder.toString().substring(1);
}
public void addAll(ParameterList other)
{
params.addAll(other.params);
}
public void addQuerystring(String queryString)
{
if (queryString != null && queryString.length() > 0)
{
for (String param : queryString.split(PARAM_SEPARATOR))
{
String pair[] = param.split(PAIR_SEPARATOR);
String key = OAuthEncoder.decode(pair[0]);
String value = pair.length > 1 ? OAuthEncoder.decode(pair[1]) : EMPTY_STRING;
params.add(new Parameter(key, value));
}
}
}
public boolean contains(Parameter param)
{
return params.contains(param);
}
public int size()
{
return params.size();
}
public ParameterList sort()
{
ParameterList sorted = new ParameterList(params);
Collections.sort(sorted.params);
return sorted;
}
}
+149 -41
View File
@@ -2,11 +2,11 @@ package org.scribe.model;
import java.io.*;
import java.net.*;
import java.nio.charset.*;
import java.util.*;
import java.util.concurrent.TimeUnit;
import org.scribe.exceptions.*;
import org.scribe.utils.*;
/**
* Represents an HTTP Request object
@@ -16,13 +16,21 @@ import org.scribe.utils.*;
class Request
{
private static final String CONTENT_LENGTH = "Content-Length";
private static final String CONTENT_TYPE = "Content-Type";
public static final String DEFAULT_CONTENT_TYPE = "application/x-www-form-urlencoded";
private String url;
private Verb verb;
private Map<String, String> bodyParams;
private ParameterList querystringParams;
private ParameterList bodyParams;
private Map<String, String> headers;
private String payload = null;
private HttpURLConnection connection;
private String charset;
private byte[] bytePayload = null;
private boolean connectionKeepAlive = false;
private Long connectTimeout = null;
private Long readTimeout = null;
/**
* Creates a new Http Request
@@ -34,15 +42,9 @@ class Request
{
this.verb = verb;
this.url = url;
this.bodyParams = new HashMap<String, String>();
this.querystringParams = new ParameterList();
this.bodyParams = new ParameterList();
this.headers = new HashMap<String, String>();
try
{
connection = (HttpURLConnection) new URL(url).openConnection();
} catch (IOException ioe)
{
throw new OAuthException("Could not open connection to: " + url, ioe);
}
}
/**
@@ -56,20 +58,50 @@ class Request
{
try
{
createConnection();
return doSend();
} catch (IOException ioe)
{
throw new OAuthException("Problems while creating connection", ioe);
}
catch (Exception e)
{
throw new OAuthConnectionException(e);
}
}
private void createConnection() throws IOException
{
String completeUrl = getCompleteUrl();
if (connection == null)
{
System.setProperty("http.keepAlive", connectionKeepAlive ? "true" : "false");
connection = (HttpURLConnection) new URL(completeUrl).openConnection();
}
}
/**
* Returns the complete url (host + resource + encoded querystring parameters).
*
* @return the complete url.
*/
public String getCompleteUrl()
{
return querystringParams.appendTo(url);
}
Response doSend() throws IOException
{
connection.setRequestMethod(this.verb.name());
if (connectTimeout != null)
{
connection.setConnectTimeout(connectTimeout.intValue());
}
if (readTimeout != null)
{
connection.setReadTimeout(readTimeout.intValue());
}
addHeaders(connection);
if (verb.equals(Verb.PUT) || verb.equals(Verb.POST))
{
addBody(connection, getBodyContents());
addBody(connection, getByteBodyContents());
}
return new Response(connection);
}
@@ -80,11 +112,17 @@ class Request
conn.setRequestProperty(key, headers.get(key));
}
void addBody(HttpURLConnection conn, String content) throws IOException
void addBody(HttpURLConnection conn, byte[] content) throws IOException
{
conn.setRequestProperty(CONTENT_LENGTH, String.valueOf(content.getBytes().length));
conn.setRequestProperty(CONTENT_LENGTH, String.valueOf(content.length));
// Set default content type if none is set.
if (conn.getRequestProperty(CONTENT_TYPE) == null)
{
conn.setRequestProperty(CONTENT_TYPE, DEFAULT_CONTENT_TYPE);
}
conn.setDoOutput(true);
conn.getOutputStream().write(content.getBytes());
conn.getOutputStream().write(content);
}
/**
@@ -106,7 +144,18 @@ class Request
*/
public void addBodyParameter(String key, String value)
{
this.bodyParams.put(key, value);
this.bodyParams.add(key, value);
}
/**
* Add a QueryString parameter
*
* @param key the parameter name
* @param value the parameter value
*/
public void addQuerystringParameter(String key, String value)
{
this.querystringParams.add(key, value);
}
/**
@@ -125,37 +174,43 @@ class Request
}
/**
* Get a {@link Map} of the query string parameters.
*
* @return a map containing the query string parameters
* Overloaded version for byte arrays
*
* @param payload
*/
public Map<String, String> getQueryStringParams()
public void addPayload(byte[] payload)
{
this.bytePayload = payload;
}
/**
* Get a {@link ParameterList} with the query string parameters.
*
* @return a {@link ParameterList} containing the query string parameters.
* @throws OAuthException if the request URL is not valid.
*/
public ParameterList getQueryStringParams()
{
try
{
Map<String, String> params = new HashMap<String, String>();
String query = new URL(url).getQuery();
if (query != null)
{
for (String param : query.split("&"))
{
String pair[] = param.split("=");
params.put(pair[0], pair[1]);
}
}
return params;
} catch (MalformedURLException mue)
ParameterList result = new ParameterList();
String queryString = new URL(url).getQuery();
result.addQuerystring(queryString);
result.addAll(querystringParams);
return result;
}
catch (MalformedURLException mue)
{
throw new OAuthException("Malformed URL", mue);
}
}
/**
* Obtains a {@link Map} of the body parameters.
* Obtains a {@link ParameterList} of the body parameters.
*
* @return a map containing the body parameters.
* @return a {@link ParameterList}containing the body parameters.
*/
public Map<String, String> getBodyParams()
public ParameterList getBodyParams()
{
return bodyParams;
}
@@ -184,10 +239,32 @@ class Request
* Returns the body of the request
*
* @return form encoded string
* @throws OAuthException if the charset chosen is not supported
*/
public String getBodyContents()
{
return (payload != null) ? payload : URLUtils.formURLEncodeMap(bodyParams);
try
{
return new String(getByteBodyContents(),getCharset());
}
catch(UnsupportedEncodingException uee)
{
throw new OAuthException("Unsupported Charset: "+charset, uee);
}
}
byte[] getByteBodyContents()
{
if (bytePayload != null) return bytePayload;
String body = (payload != null) ? payload : bodyParams.asFormUrlEncodedString();
try
{
return body.getBytes(getCharset());
}
catch(UnsupportedEncodingException uee)
{
throw new OAuthException("Unsupported Charset: "+getCharset(), uee);
}
}
/**
@@ -210,6 +287,16 @@ class Request
return headers;
}
/**
* Returns the connection charset. Defaults to {@link Charset} defaultCharset if not set
*
* @return charset
*/
public String getCharset()
{
return charset == null ? Charset.defaultCharset().name() : charset;
}
/**
* Sets the connect timeout for the underlying {@link HttpURLConnection}
*
@@ -219,7 +306,7 @@ class Request
*/
public void setConnectTimeout(int duration, TimeUnit unit)
{
this.connection.setConnectTimeout((int) unit.toMillis(duration));
this.connectTimeout = unit.toMillis(duration);
}
/**
@@ -231,9 +318,30 @@ class Request
*/
public void setReadTimeout(int duration, TimeUnit unit)
{
this.connection.setReadTimeout((int) unit.toMillis(duration));
this.readTimeout = unit.toMillis(duration);
}
/**
* Set the charset of the body of the request
*
* @param charsetName name of the charset of the request
*/
public void setCharset(String charsetName)
{
this.charset = charsetName;
}
/**
* Sets whether the underlying Http Connection is persistent or not.
*
* @see http://download.oracle.com/javase/1.5.0/docs/guide/net/http-keepalive.html
* @param connectionKeepAlive
*/
public void setConnectionKeepAlive(boolean connectionKeepAlive)
{
this.connectionKeepAlive = connectionKeepAlive;
}
/*
* We need this in order to stub the connection object for test cases
*/
+8 -8
View File
@@ -4,6 +4,7 @@ import java.io.*;
import java.net.*;
import java.util.*;
import org.scribe.exceptions.*;
import org.scribe.utils.*;
/**
@@ -27,11 +28,11 @@ public class Response
connection.connect();
code = connection.getResponseCode();
headers = parseHeaders(connection);
stream = wasSuccessful() ? connection.getInputStream() : connection.getErrorStream();
} catch (UnknownHostException e)
stream = isSuccessful() ? connection.getInputStream() : connection.getErrorStream();
}
catch (UnknownHostException e)
{
code = 404;
body = EMPTY;
throw new OAuthException("The IP address of a host could not be determined.", e);
}
}
@@ -51,7 +52,7 @@ public class Response
return headers;
}
private boolean wasSuccessful()
public boolean isSuccessful()
{
return getCode() >= 200 && getCode() < 400;
}
@@ -100,10 +101,9 @@ public class Response
/**
* Obtains a single HTTP Header value, or null if undefined
*
* @param header
* name
* @param name the header name.
*
* @return header value or null
* @return header value or null.
*/
public String getHeader(String name)
{
@@ -0,0 +1,7 @@
package org.scribe.model;
public enum SignatureType
{
Header,
QueryString
}
+21 -1
View File
@@ -1,14 +1,19 @@
package org.scribe.model;
import java.io.Serializable;
/**
* Represents an OAuth token (either request or access token) and its secret
*
* @author Pablo Fernandez
*/
public class Token
public class Token implements Serializable
{
private static final long serialVersionUID = 715000866082812683L;
private final String token;
private final String secret;
private final String rawResponse;
/**
* Default constructor
@@ -17,9 +22,15 @@ public class Token
* @param secret token secret
*/
public Token(String token, String secret)
{
this(token, secret, null);
}
public Token(String token, String secret, String rawResponse)
{
this.token = token;
this.secret = secret;
this.rawResponse = rawResponse;
}
public String getToken()
@@ -32,6 +43,15 @@ public class Token
return secret;
}
public String getRawResponse()
{
if (rawResponse == null)
{
throw new IllegalStateException("This token object was not constructed by scribe and does not have a rawResponse");
}
return rawResponse;
}
@Override
public String toString()
{
@@ -1,5 +1,7 @@
package org.scribe.model;
import org.scribe.utils.*;
/**
* Represents an OAuth verifier code.
*
@@ -7,6 +9,7 @@ package org.scribe.model;
*/
public class Verifier
{
private final String value;
/**
@@ -16,6 +19,7 @@ public class Verifier
*/
public Verifier(String value)
{
Preconditions.checkNotNull(value, "Must provide a valid string as verifier");
this.value = value;
}
@@ -1,8 +1,10 @@
package org.scribe.oauth;
import org.scribe.extractors.*;
import java.util.*;
import org.scribe.builder.api.*;
import org.scribe.model.*;
import org.scribe.services.*;
import org.scribe.utils.*;
/**
* OAuth 1.0a implementation of {@link OAuthService}
@@ -11,40 +13,21 @@ import org.scribe.services.*;
*/
public class OAuth10aServiceImpl implements OAuthService
{
private static final String NO_SCOPE = null;
private static final String VERSION = "1.0";
private OAuthConfig config;
private SignatureService signatureService;
private TimestampService timestampService;
private BaseStringExtractor baseStringExtractor;
private HeaderExtractor headerExtractor;
private RequestTokenExtractor rtExtractor;
private AccessTokenExtractor atExtractor;
private String scope;
private DefaultApi10a api;
/**
* Default constructor
*
* @param signatureService OAuth 1.0a signature service
* @param timestampService OAuth 1.0a timestamp service
* @param baseStringExtractor OAuth 1.0a base string extractor
* @param headerExtractor OAuth 1.0a http header extractor
* @param rtExtractor OAuth 1.0a request token extractor
* @param atExtractor OAuth 1.0a access token extractor
* @param api OAuth1.0a api information
* @param config OAuth 1.0a configuration param object
*/
public OAuth10aServiceImpl(SignatureService signatureService, TimestampService timestampService, BaseStringExtractor baseStringExtractor,
HeaderExtractor headerExtractor, RequestTokenExtractor rtExtractor, AccessTokenExtractor atExtractor, OAuthConfig config)
public OAuth10aServiceImpl(DefaultApi10a api, OAuthConfig config)
{
this.signatureService = signatureService;
this.timestampService = timestampService;
this.baseStringExtractor = baseStringExtractor;
this.headerExtractor = headerExtractor;
this.rtExtractor = rtExtractor;
this.atExtractor = atExtractor;
this.api = api;
this.config = config;
this.scope = NO_SCOPE;
}
/**
@@ -52,23 +35,34 @@ public class OAuth10aServiceImpl implements OAuthService
*/
public Token getRequestToken()
{
OAuthRequest request = new OAuthRequest(config.getRequestTokenVerb(), config.getRequestTokenEndpoint());
config.log("obtaining request token from " + api.getRequestTokenEndpoint());
OAuthRequest request = new OAuthRequest(api.getRequestTokenVerb(), api.getRequestTokenEndpoint());
config.log("setting oauth_callback to " + config.getCallback());
request.addOAuthParameter(OAuthConstants.CALLBACK, config.getCallback());
addOAuthParams(request, OAuthConstants.EMPTY_TOKEN);
addOAuthHeader(request);
appendSignature(request);
config.log("sending request...");
Response response = request.send();
return rtExtractor.extract(response.getBody());
String body = response.getBody();
config.log("response status code: " + response.getCode());
config.log("response body: " + body);
return api.getRequestTokenExtractor().extract(body);
}
private void addOAuthParams(OAuthRequest request, Token token)
{
request.addOAuthParameter(OAuthConstants.TIMESTAMP, timestampService.getTimestampInSeconds());
request.addOAuthParameter(OAuthConstants.NONCE, timestampService.getNonce());
request.addOAuthParameter(OAuthConstants.TIMESTAMP, api.getTimestampService().getTimestampInSeconds());
request.addOAuthParameter(OAuthConstants.NONCE, api.getTimestampService().getNonce());
request.addOAuthParameter(OAuthConstants.CONSUMER_KEY, config.getApiKey());
request.addOAuthParameter(OAuthConstants.SIGN_METHOD, signatureService.getSignatureMethod());
request.addOAuthParameter(OAuthConstants.SIGN_METHOD, api.getSignatureService().getSignatureMethod());
request.addOAuthParameter(OAuthConstants.VERSION, getVersion());
request.addOAuthParameter(OAuthConstants.CALLBACK, config.getCallback());
if(scope != NO_SCOPE) request.addOAuthParameter(OAuthConstants.SCOPE, scope);
if(config.hasScope()) request.addOAuthParameter(OAuthConstants.SCOPE, config.getScope());
request.addOAuthParameter(OAuthConstants.SIGNATURE, getSignature(request, token));
config.log("appended additional OAuth parameters: " + MapUtils.toString(request.getOauthParameters()));
}
/**
@@ -76,13 +70,16 @@ public class OAuth10aServiceImpl implements OAuthService
*/
public Token getAccessToken(Token requestToken, Verifier verifier)
{
OAuthRequest request = new OAuthRequest(config.getAccessTokenVerb(), config.getAccessTokenEndpoint());
config.log("obtaining access token from " + api.getAccessTokenEndpoint());
OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint());
request.addOAuthParameter(OAuthConstants.TOKEN, requestToken.getToken());
request.addOAuthParameter(OAuthConstants.VERIFIER, verifier.getValue());
config.log("setting token to: " + requestToken + " and verifier to: " + verifier);
addOAuthParams(request, requestToken);
addOAuthHeader(request);
appendSignature(request);
Response response = request.send();
return atExtractor.extract(response.getBody());
return api.getAccessTokenExtractor().extract(response.getBody());
}
/**
@@ -90,9 +87,12 @@ public class OAuth10aServiceImpl implements OAuthService
*/
public void signRequest(Token token, OAuthRequest request)
{
config.log("signing request: " + request.getCompleteUrl());
request.addOAuthParameter(OAuthConstants.TOKEN, token.getToken());
config.log("setting token to: " + token);
addOAuthParams(request, token);
addOAuthHeader(request);
appendSignature(request);
}
/**
@@ -106,20 +106,40 @@ public class OAuth10aServiceImpl implements OAuthService
/**
* {@inheritDoc}
*/
public void addScope(String scope)
public String getAuthorizationUrl(Token requestToken)
{
this.scope = scope;
return api.getAuthorizationUrl(requestToken);
}
private String getSignature(OAuthRequest request, Token token)
{
String baseString = baseStringExtractor.extract(request);
return signatureService.getSignature(baseString, config.getApiSecret(), token.getSecret());
config.log("generating signature...");
String baseString = api.getBaseStringExtractor().extract(request);
String signature = api.getSignatureService().getSignature(baseString, config.getApiSecret(), token.getSecret());
config.log("base string is: " + baseString);
config.log("signature is: " + signature);
return signature;
}
private void addOAuthHeader(OAuthRequest request)
private void appendSignature(OAuthRequest request)
{
String oauthHeader = headerExtractor.extract(request);
request.addHeader(OAuthConstants.HEADER, oauthHeader);
switch (config.getSignatureType())
{
case Header:
config.log("using Http Header signature");
String oauthHeader = api.getHeaderExtractor().extract(request);
request.addHeader(OAuthConstants.HEADER, oauthHeader);
break;
case QueryString:
config.log("using Querystring signature");
for (Map.Entry<String, String> entry : request.getOauthParameters().entrySet())
{
request.addQuerystringParameter(entry.getKey(), entry.getValue());
}
break;
}
}
}
@@ -0,0 +1,72 @@
package org.scribe.oauth;
import org.scribe.builder.api.*;
import org.scribe.model.*;
public class OAuth20ServiceImpl implements OAuthService
{
private static final String VERSION = "2.0";
private final DefaultApi20 api;
private final OAuthConfig config;
/**
* Default constructor
*
* @param api OAuth2.0 api information
* @param config OAuth 2.0 configuration param object
*/
public OAuth20ServiceImpl(DefaultApi20 api, OAuthConfig config)
{
this.api = api;
this.config = config;
}
/**
* {@inheritDoc}
*/
public Token getAccessToken(Token requestToken, Verifier verifier)
{
OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint());
request.addQuerystringParameter(OAuthConstants.CLIENT_ID, config.getApiKey());
request.addQuerystringParameter(OAuthConstants.CLIENT_SECRET, config.getApiSecret());
request.addQuerystringParameter(OAuthConstants.CODE, verifier.getValue());
request.addQuerystringParameter(OAuthConstants.REDIRECT_URI, config.getCallback());
if(config.hasScope()) request.addQuerystringParameter(OAuthConstants.SCOPE, config.getScope());
Response response = request.send();
return api.getAccessTokenExtractor().extract(response.getBody());
}
/**
* {@inheritDoc}
*/
public Token getRequestToken()
{
throw new UnsupportedOperationException("Unsupported operation, please use 'getAuthorizationUrl' and redirect your users there");
}
/**
* {@inheritDoc}
*/
public String getVersion()
{
return VERSION;
}
/**
* {@inheritDoc}
*/
public void signRequest(Token accessToken, OAuthRequest request)
{
request.addQuerystringParameter(OAuthConstants.ACCESS_TOKEN, accessToken.getToken());
}
/**
* {@inheritDoc}
*/
public String getAuthorizationUrl(Token requestToken)
{
return api.getAuthorizationUrl(config);
}
}
@@ -41,11 +41,13 @@ public interface OAuthService
* @return oauth version as string
*/
public String getVersion();
/**
* Adds the 'scope' parameter. This is **not** a default OAuth parameter and the setting is optional.
* Returns the URL where you should redirect your users to authenticate
* your application.
*
* @param scope OAuth Api scope (optional)
* @param requestToken the request token you need to authorize
* @return the URL where you should redirect your users
*/
public void addScope(String scope);
public String getAuthorizationUrl(Token requestToken);
}
@@ -30,7 +30,7 @@ public class HMACSha1SignatureService implements SignatureService
{
Preconditions.checkEmptyString(baseString, "Base string cant be null or empty string");
Preconditions.checkEmptyString(apiSecret, "Api secret cant be null or empty string");
return doSign(baseString, apiSecret + '&' + tokenSecret);
return doSign(baseString, OAuthEncoder.encode(apiSecret) + '&' + OAuthEncoder.encode(tokenSecret));
}
catch (Exception e)
{
@@ -0,0 +1,40 @@
package org.scribe.services;
import org.scribe.exceptions.*;
import org.scribe.utils.*;
/**
* plaintext implementation of {@SignatureService}
*
* @author Pablo Fernandez
*
*/
public class PlaintextSignatureService implements SignatureService
{
private static final String METHOD = "plaintext";
/**
* {@inheritDoc}
*/
public String getSignature(String baseString, String apiSecret, String tokenSecret)
{
try
{
Preconditions.checkEmptyString(apiSecret, "Api secret cant be null or empty string");
return OAuthEncoder.encode(apiSecret) + '&' + OAuthEncoder.encode(tokenSecret);
}
catch (Exception e)
{
throw new OAuthSignatureException(baseString, e);
}
}
/**
* {@inheritDoc}
*/
public String getSignatureMethod()
{
return METHOD;
}
}
+9 -23
View File
@@ -1,36 +1,22 @@
package org.scribe.utils;
import java.util.*;
import java.util.Map;
/**
* Utils for {@link Map} manipulation
*
* @author Pablo Fernandez
* @author: Pablo Fernandez
*/
public class MapUtils
{
/**
* Sorts a Map
*
* @param map unsorted map
* @return sorted map
*/
public static final Map<String, String> sort(Map<String, String> map)
public static <K,V> String toString(Map<K,V> map)
{
Preconditions.checkNotNull(map, "Cannot sort a null object.");
if (map == null) return "";
if (map.isEmpty()) return "{}";
Map<String, String> sorted = new LinkedHashMap<String, String>();
for (String key : getSortedKeys(map))
StringBuilder result = new StringBuilder();
for(Map.Entry<K,V> entry : map.entrySet())
{
sorted.put(key, map.get(key));
result.append(String.format(", %s -> %s ", entry.getKey().toString(), entry.getValue().toString()));
}
return sorted;
}
private static List<String> getSortedKeys(Map<String, String> map)
{
List<String> keys = new ArrayList<String>(map.keySet());
Collections.sort(keys);
return keys;
return "{" + result.substring(1) + "}";
}
}
@@ -0,0 +1,62 @@
package org.scribe.utils;
import java.io.*;
import java.net.*;
import java.util.*;
import java.util.regex.*;
import org.scribe.exceptions.*;
/**
* @author: Pablo Fernandez
*/
public class OAuthEncoder
{
private static String CHARSET = "UTF-8";
private static final Map<String, String> ENCODING_RULES;
static
{
Map<String, String> rules = new HashMap<String, String>();
rules.put("*", "%2A");
rules.put("+", "%20");
rules.put("%7E", "~");
ENCODING_RULES = Collections.unmodifiableMap(rules);
}
public static String encode(String plain)
{
Preconditions.checkNotNull(plain, "Cannot encode null object");
String encoded = "";
try
{
encoded = URLEncoder.encode(plain, CHARSET);
}
catch (UnsupportedEncodingException uee)
{
throw new OAuthException("Charset not found while encoding string: " + CHARSET, uee);
}
for(Map.Entry<String, String> rule : ENCODING_RULES.entrySet())
{
encoded = applyRule(encoded, rule.getKey(), rule.getValue());
}
return encoded;
}
private static String applyRule(String encoded, String toReplace, String replacement)
{
return encoded.replaceAll(Pattern.quote(toReplace), replacement);
}
public static String decode(String encoded)
{
Preconditions.checkNotNull(encoded, "Cannot decode null object");
try
{
return URLDecoder.decode(encoded, CHARSET);
}
catch(UnsupportedEncodingException uee)
{
throw new OAuthException("Charset not found while decoding string: " + CHARSET, uee);
}
}
}
@@ -12,7 +12,9 @@ import org.scribe.model.OAuthConstants;
public class Preconditions
{
private static final String DEFAULT_MESSAGE = "Received an invalid parameter";
private static final Pattern URL_PATTERN = Pattern.compile("[a-zA-Z_-]+://\\S+");
// scheme = alpha *( alpha | digit | "+" | "-" | "." )
private static final Pattern URL_PATTERN = Pattern.compile("^[a-zA-Z][a-zA-Z0-9+.-]*://\\S+");
/**
* Checks that an object is not null.
@@ -36,7 +36,7 @@ public class StreamUtils
return out.toString();
} catch (IOException ioe)
{
throw new RuntimeException("Error while reading response body", ioe);
throw new IllegalStateException("Error while reading response body", ioe);
}
}
}
@@ -1,118 +0,0 @@
package org.scribe.utils;
import java.io.*;
import java.net.*;
import java.util.*;
import org.scribe.exceptions.*;
/**
* Utils to deal with URL and url-encodings
*
* @author Pablo Fernandez
*/
public class URLUtils
{
private static final String EMPTY_STRING = "";
private static final String UTF_8 = "UTF-8";
private static final char PAIR_SEPARATOR = '=';
private static final char PARAM_SEPARATOR = '&';
private static final String ERROR_MSG = String.format("Cannot find specified encoding: %s", UTF_8);
private static final Set<EncodingRule> ENCODING_RULES;
static
{
Set<EncodingRule> rules = new HashSet<EncodingRule>();
rules.add(new EncodingRule("*","%2A"));
rules.add(new EncodingRule("+","%20"));
rules.add(new EncodingRule("%7E", "~"));
ENCODING_RULES = Collections.unmodifiableSet(rules);
}
/**
* Turns a map into a form-url-encoded string (key=value&key2=value2)
*
* @param map any map
* @return form-url-encoded string
*/
public static String formURLEncodeMap(Map<String, String> map)
{
Preconditions.checkNotNull(map, "Cannot url-encode a null object");
return (map.size() <= 0) ? EMPTY_STRING : doFormUrlEncode(map);
}
private static String doFormUrlEncode(Map<String, String> map)
{
StringBuffer encodedString = new StringBuffer(map.size() * 20);
for (String key : map.keySet())
{
if(encodedString.length() > 0)
{
encodedString.append(PARAM_SEPARATOR);
}
encodedString.append(percentEncode(key)).append(PAIR_SEPARATOR).append(percentEncode(map.get(key)));
}
return encodedString.toString();
}
/**
* Percent encodes a string
*
* @param plain
* @return percent encoded string
*/
public static String percentEncode(String string)
{
Preconditions.checkNotNull(string, "Cannot encode null string");
try
{
String encoded = URLEncoder.encode(string, UTF_8);
for(EncodingRule rule : ENCODING_RULES)
{
encoded = rule.apply(encoded);
}
return encoded;
}
catch (UnsupportedEncodingException uee)
{
throw new OAuthException(ERROR_MSG, uee);
}
}
/**
* Percent decodes a string
*
* @param string percent encoded string
* @return plain string
*/
public static String percentDecode(String string)
{
Preconditions.checkNotNull(string, "Cannot decode null string");
try
{
return URLDecoder.decode(string, UTF_8);
}
catch (UnsupportedEncodingException uee)
{
throw new OAuthException(ERROR_MSG, uee);
}
}
private static final class EncodingRule
{
private final String ch;
private final String toCh;
EncodingRule(String ch, String toCh)
{
this.ch = ch;
this.toCh = toCh;
}
String apply(String string) {
return string.replace(ch, toCh);
}
}
}
@@ -0,0 +1,73 @@
package org.scribe.builder;
import static org.junit.Assert.*;
import org.junit.*;
import org.scribe.builder.api.*;
import org.scribe.model.*;
import org.scribe.oauth.*;
public class ServiceBuilderTest
{
private ServiceBuilder builder;
@Before
public void setup()
{
builder = new ServiceBuilder();
}
@Test
public void shouldReturnConfigDefaultValues()
{
builder.provider(ApiMock.class).apiKey("key").apiSecret("secret").build();
assertEquals(ApiMock.config.getApiKey(), "key");
assertEquals(ApiMock.config.getApiSecret(), "secret");
assertEquals(ApiMock.config.getCallback(), OAuthConstants.OUT_OF_BAND);
assertEquals(ApiMock.config.getSignatureType(), SignatureType.Header);
}
@Test
public void shouldAcceptValidCallbackUrl()
{
builder.provider(ApiMock.class).apiKey("key").apiSecret("secret").callback("http://example.com").build();
assertEquals(ApiMock.config.getApiKey(), "key");
assertEquals(ApiMock.config.getApiSecret(), "secret");
assertEquals(ApiMock.config.getCallback(), "http://example.com");
}
@Test
public void shouldAcceptASignatureType()
{
builder.provider(ApiMock.class).apiKey("key").apiSecret("secret").signatureType(SignatureType.QueryString).build();
assertEquals(ApiMock.config.getApiKey(), "key");
assertEquals(ApiMock.config.getApiSecret(), "secret");
assertEquals(ApiMock.config.getSignatureType(), SignatureType.QueryString);
}
@Test(expected=IllegalArgumentException.class)
public void shouldNotAcceptNullAsCallback()
{
builder.provider(ApiMock.class).apiKey("key").apiSecret("secret").callback(null).build();
}
@Test
public void shouldAcceptAnScope()
{
builder.provider(ApiMock.class).apiKey("key").apiSecret("secret").scope("rss-api").build();
assertEquals(ApiMock.config.getApiKey(), "key");
assertEquals(ApiMock.config.getApiSecret(), "secret");
assertEquals(ApiMock.config.getScope(), "rss-api");
}
public static class ApiMock implements Api
{
public static OAuthConfig config;
public OAuthService createService(OAuthConfig config)
{
ApiMock.config = config;
return null;
}
}
}
@@ -0,0 +1,65 @@
package org.scribe.examples;
import java.util.*;
import org.scribe.builder.*;
import org.scribe.builder.api.*;
import org.scribe.model.*;
import org.scribe.oauth.*;
public class DiggExample
{
private static final String NETWORK_NAME = "Digg";
private static final String PROTECTED_RESOURCE_URL = "http://services.digg.com/2.0/comment.digg";
public static void main(String[] args)
{
// Replace these with your own api key and secret
String apiKey = "myKey";
String apiSecret = "mySecret";
OAuthService service = new ServiceBuilder().provider(DiggApi.class).apiKey(apiKey).apiSecret(apiSecret).build();
Scanner in = new Scanner(System.in);
System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ===");
System.out.println();
// Obtain the Request Token
System.out.println("Fetching the Request Token...");
Token requestToken = service.getRequestToken();
System.out.println("Got the Request Token!");
System.out.println();
// Obtain the Authorization URL
System.out.println("Fetching the Authorization URL...");
String authorizationUrl = service.getAuthorizationUrl(requestToken);
System.out.println("Got the Authorization URL!");
System.out.println("Now go and authorize Scribe here:");
System.out.println(authorizationUrl);
System.out.println("And paste the authorization code here");
System.out.print(">>");
Verifier verifier = new Verifier(in.nextLine());
System.out.println();
// Trade the Request Token and Verfier for the Access Token
System.out.println("Trading the Request Token for an Access Token...");
Token accessToken = service.getAccessToken(requestToken, verifier);
System.out.println("Got the Access Token!");
System.out.println("(if your curious it looks like this: " + accessToken + " )");
System.out.println();
// Now let's go and ask for a protected resource!
System.out.println("Now we're going to access a protected resource...");
OAuthRequest request = new OAuthRequest(Verb.POST, PROTECTED_RESOURCE_URL);
request.addBodyParameter("comment_id", "20100729223726:4fef610331ee46a3b5cbd740bf71313e");
service.signRequest(accessToken, request);
Response response = request.send();
System.out.println("Got it! Lets see what we found...");
System.out.println();
System.out.println(response.getCode());
System.out.println(response.getBody());
System.out.println();
System.out.println("Thats it man! Go and build something awesome with Scribe! :)");
}
}
@@ -0,0 +1,64 @@
package org.scribe.examples;
import java.util.*;
import org.scribe.builder.*;
import org.scribe.builder.api.*;
import org.scribe.model.*;
import org.scribe.oauth.*;
public class FacebookExample
{
private static final String NETWORK_NAME = "Facebook";
private static final String PROTECTED_RESOURCE_URL = "https://graph.facebook.com/me";
private static final Token EMPTY_TOKEN = null;
public static void main(String[] args)
{
// Replace these with your own api key and secret
String apiKey = "your_app_id";
String apiSecret = "your_api_secret";
OAuthService service = new ServiceBuilder()
.provider(FacebookApi.class)
.apiKey(apiKey)
.apiSecret(apiSecret)
.callback("http://www.example.com/oauth_callback/")
.build();
Scanner in = new Scanner(System.in);
System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ===");
System.out.println();
// Obtain the Authorization URL
System.out.println("Fetching the Authorization URL...");
String authorizationUrl = service.getAuthorizationUrl(EMPTY_TOKEN);
System.out.println("Got the Authorization URL!");
System.out.println("Now go and authorize Scribe here:");
System.out.println(authorizationUrl);
System.out.println("And paste the authorization code here");
System.out.print(">>");
Verifier verifier = new Verifier(in.nextLine());
System.out.println();
// Trade the Request Token and Verfier for the Access Token
System.out.println("Trading the Request Token for an Access Token...");
Token accessToken = service.getAccessToken(EMPTY_TOKEN, verifier);
System.out.println("Got the Access Token!");
System.out.println("(if your curious it looks like this: " + accessToken + " )");
System.out.println();
// Now let's go and ask for a protected resource!
System.out.println("Now we're going to access a protected resource...");
OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL);
service.signRequest(accessToken, request);
Response response = request.send();
System.out.println("Got it! Lets see what we found...");
System.out.println();
System.out.println(response.getCode());
System.out.println(response.getBody());
System.out.println();
System.out.println("Thats it man! Go and build something awesome with Scribe! :)");
}
}
@@ -0,0 +1,59 @@
package org.scribe.examples;
import org.scribe.builder.*;
import org.scribe.builder.api.*;
import org.scribe.model.*;
import org.scribe.oauth.*;
import java.util.*;
public class FlickrExample
{
private static final String PROTECTED_RESOURCE_URL = "http://api.flickr.com/services/rest/";
public static void main(String[] args)
{
// Replace these with your own api key and secret
String apiKey = "your_app_id";
String apiSecret = "your_api_secret";
OAuthService service = new ServiceBuilder().provider(FlickrApi.class).apiKey(apiKey).apiSecret(apiSecret).build();
Scanner in = new Scanner(System.in);
System.out.println("=== Flickr's OAuth Workflow ===");
System.out.println();
// Obtain the Request Token
System.out.println("Fetching the Request Token...");
Token requestToken = service.getRequestToken();
System.out.println("Got the Request Token!");
System.out.println();
System.out.println("Now go and authorize Scribe here:");
String authorizationUrl = service.getAuthorizationUrl(requestToken);
System.out.println(authorizationUrl + "&perms=read");
System.out.println("And paste the verifier here");
System.out.print(">>");
Verifier verifier = new Verifier(in.nextLine());
System.out.println();
// Trade the Request Token and Verfier for the Access Token
System.out.println("Trading the Request Token for an Access Token...");
Token accessToken = service.getAccessToken(requestToken, verifier);
System.out.println("Got the Access Token!");
System.out.println("(if your curious it looks like this: " + accessToken + " )");
System.out.println();
// Now let's go and ask for a protected resource!
System.out.println("Now we're going to access a protected resource...");
OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL);
request.addQuerystringParameter("method", "flickr.test.login");
service.signRequest(accessToken, request);
Response response = request.send();
System.out.println("Got it! Lets see what we found...");
System.out.println();
System.out.println(response.getBody());
System.out.println();
System.out.println("Thats it man! Go and build something awesome with Scribe! :)");
}
}
@@ -0,0 +1,63 @@
package org.scribe.examples;
import java.util.*;
import org.scribe.builder.*;
import org.scribe.builder.api.*;
import org.scribe.model.*;
import org.scribe.oauth.*;
public class Foursquare2Example
{
private static final String PROTECTED_RESOURCE_URL = "https://api.foursquare.com/v2/users/self/friends?oauth_token=";
private static final Token EMPTY_TOKEN = null;
public static void main(String[] args)
{
// Replace these with your own api key and secret
String apiKey = "FEGFXJUFANVVDHVSNUAMUKTTXCP1AJQD53E33XKJ44YP1S4I";
String apiSecret = "AYWKUL5SWPNC0CTQ202QXRUG2NLZYXMRA34ZSDW4AUYBG2RC";
OAuthService service = new ServiceBuilder()
.provider(Foursquare2Api.class)
.apiKey(apiKey)
.apiSecret(apiSecret)
.callback("http://localhost:9000/")
.build();
Scanner in = new Scanner(System.in);
System.out.println("=== Foursquare2's OAuth Workflow ===");
System.out.println();
// Obtain the Authorization URL
System.out.println("Fetching the Authorization URL...");
String authorizationUrl = service.getAuthorizationUrl(EMPTY_TOKEN);
System.out.println("Got the Authorization URL!");
System.out.println("Now go and authorize Scribe here:");
System.out.println(authorizationUrl);
System.out.println("And paste the authorization code here");
System.out.print(">>");
Verifier verifier = new Verifier(in.nextLine());
System.out.println();
// Trade the Request Token and Verfier for the Access Token
System.out.println("Trading the Request Token for an Access Token...");
Token accessToken = service.getAccessToken(EMPTY_TOKEN, verifier);
System.out.println("Got the Access Token!");
System.out.println("(if your curious it looks like this: " + accessToken + " )");
System.out.println();
// Now let's go and ask for a protected resource!
System.out.println("Now we're going to access a protected resource...");
OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL + accessToken.getToken());
service.signRequest(accessToken, request);
Response response = request.send();
System.out.println("Got it! Lets see what we found...");
System.out.println();
System.out.println(response.getCode());
System.out.println(response.getBody());
System.out.println();
System.out.println("Thats it man! Go and build something awesome with Scribe! :)");
}
}
@@ -9,7 +9,6 @@ import org.scribe.oauth.*;
public class FoursquareExample
{
private static final String AUTHORIZE_URL = "http://foursquare.com/oauth/authorize?oauth_token=";
private static final String PROTECTED_RESOURCE_URL = "http://api.foursquare.com/v1/user";
public static void main(String[] args)
@@ -31,7 +30,7 @@ public class FoursquareExample
System.out.println();
System.out.println("Now go and authorize Scribe here:");
System.out.println(AUTHORIZE_URL + requestToken.getToken());
System.out.println(service.getAuthorizationUrl(requestToken));
System.out.println("And paste the verifier here");
System.out.print(">>");
Verifier verifier = new Verifier(in.nextLine());
@@ -0,0 +1,66 @@
package org.scribe.examples;
import java.util.*;
import org.scribe.builder.*;
import org.scribe.builder.api.*;
import org.scribe.model.*;
import org.scribe.oauth.*;
public class FreelancerExample
{
private static final String NETWORK_NAME = "Freelancer";
private static final String AUTHORIZE_URL = "http://www.sandbox.freelancer.com/users/api-token/auth.php?oauth_token=";
private static final String PROTECTED_RESOURCE_URL = "http://api.sandbox.freelancer.com/Job/getJobList.json";
private static final String SCOPE = "http://api.sandbox.freelancer.com";
public static void main(String[] args)
{
OAuthService service = new ServiceBuilder()
.provider(FreelancerApi.Sandbox.class)
.signatureType(SignatureType.QueryString)
.apiKey("7f5a168a0bfdbd15b4a9ea2a969661c731cdea56")
.apiSecret("7bb8961b94873802f1c5344f671a518e087f5785")
.scope(SCOPE)
.build();
Scanner in = new Scanner(System.in);
System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ===");
System.out.println();
// Obtain the Request Token
System.out.println("Fetching the Request Token...");
Token requestToken = service.getRequestToken();
System.out.println("Got the Request Token!");
System.out.println("(if your curious it looks like this: " + requestToken + " )");
System.out.println();
System.out.println("Now go and authorize Scribe here:");
System.out.println(AUTHORIZE_URL + requestToken.getToken());
System.out.println("And paste the verifier here");
System.out.print(">>");
Verifier verifier = new Verifier(in.nextLine());
System.out.println();
// Trade the Request Token and Verfier for the Access Token
System.out.println("Trading the Request Token for an Access Token...");
Token accessToken = service.getAccessToken(requestToken, verifier);
System.out.println("Got the Access Token!");
System.out.println("(if your curious it looks like this: " + accessToken + " )");
System.out.println();
// Now let's go and ask for a protected resource!
System.out.println("Now we're going to access a protected resource...");
OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL);
service.signRequest(accessToken, request);
request.addHeader("GData-Version", "3.0");
Response response = request.send();
System.out.println("Got it! Lets see what we found...");
System.out.println();
System.out.println(response.getCode());
System.out.println(response.getBody());
System.out.println();
System.out.println("Thats it man! Go and build something awesome with Scribe! :)");
}
}
@@ -0,0 +1,58 @@
package org.scribe.examples;
import org.scribe.builder.*;
import org.scribe.builder.api.*;
import org.scribe.model.*;
import org.scribe.oauth.*;
import java.util.*;
public class ImgUrExample
{
private static final String PROTECTED_RESOURCE_URL = "http://api.imgur.com/2/account.json";
public static void main(String[] args)
{
// Replace these with your own api key and secret (you'll need an read/write api key)
String apiKey = "your_app_id";
String apiSecret = "your_api_secret";
OAuthService service = new ServiceBuilder().provider(ImgUrApi.class).apiKey(apiKey).apiSecret(apiSecret).build();
Scanner in = new Scanner(System.in);
System.out.println("=== ImgUr's OAuth Workflow ===");
System.out.println();
// Obtain the Request Token
System.out.println("Fetching the Request Token...");
Token requestToken = service.getRequestToken();
System.out.println("Got the Request Token!");
System.out.println();
System.out.println("Now go and authorize Scribe here:");
String authorizationUrl = service.getAuthorizationUrl(requestToken);
System.out.println(authorizationUrl);
System.out.println("And paste the verifier here");
System.out.print(">>");
Verifier verifier = new Verifier(in.nextLine());
System.out.println();
// Trade the Request Token and Verfier for the Access Token
System.out.println("Trading the Request Token for an Access Token...");
Token accessToken = service.getAccessToken(requestToken, verifier);
System.out.println("Got the Access Token!");
System.out.println("(if your curious it looks like this: " + accessToken + " )");
System.out.println();
// Now let's go and ask for a protected resource!
System.out.println("Now we're going to access a protected resource...");
OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL);
service.signRequest(accessToken, request);
Response response = request.send();
System.out.println("Got it! Lets see what we found...");
System.out.println();
System.out.println(response.getBody());
System.out.println();
System.out.println("Thats it man! Go and build something awesome with Scribe! :)");
}
}
@@ -0,0 +1,63 @@
package org.scribe.examples;
import org.scribe.builder.*;
import org.scribe.builder.api.*;
import org.scribe.model.*;
import org.scribe.oauth.*;
import java.util.*;
public class Kaixin20Example
{
private static final String NETWORK_NAME = "Kaixin";
private static final String PROTECTED_RESOURCE_URL = "https://api.kaixin001.com/users/me.json";
private static final Token EMPTY_TOKEN = null;
public static void main(String[] args)
{
// Replace these with your own api key and secret
String apiKey = "your api key";
String apiSecret = "your api secret";
OAuthService service = new ServiceBuilder()
.provider(KaixinApi20.class)
.apiKey(apiKey)
.apiSecret(apiSecret)
.callback("http://your.domain.com/handle")
.build();
Scanner in = new Scanner(System.in);
System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ===");
System.out.println();
// Obtain the Authorization URL
System.out.println("Fetching the Authorization URL...");
String authorizationUrl = service.getAuthorizationUrl(EMPTY_TOKEN);
System.out.println("Got the Authorization URL!");
System.out.println("Now go and authorize Scribe here:");
System.out.println(authorizationUrl);
System.out.println("And paste the authorization code here");
System.out.print(">>");
Verifier verifier = new Verifier(in.nextLine());
System.out.println();
// Trade the Request Token and Verifier for the Access Token
System.out.println("Trading the Request Token for an Access Token...");
Token accessToken = service.getAccessToken(EMPTY_TOKEN, verifier);
System.out.println("Got the Access Token!");
System.out.println("(if your curious it looks like this: " + accessToken + " )");
System.out.println();
// Now let's go and ask for a protected resource!
System.out.println("Now we're going to access a protected resource...");
OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL);
service.signRequest(accessToken, request);
Response response = request.send();
System.out.println("Got it! Lets see what we found...");
System.out.println();
System.out.println(response.getCode());
System.out.println(response.getBody());
System.out.println();
System.out.println("Thats it man! Go and build something awesome with Scribe! :)");
}
}
@@ -9,18 +9,17 @@ import org.scribe.oauth.*;
public class LinkedInExample
{
private static final String AUTHORIZE_URL = "https://api.linkedin.com/uas/oauth/authorize?oauth_token=";
private static final String PROTECTED_RESOURCE_URL = "http://api.linkedin.com/v1/people/~/connections:(id,last-name)";
public static void main(String[] args)
{
OAuthService service = new ServiceBuilder()
.provider(LinkedInApi.class)
.apiKey("CiEgwWDkA5BFpNrc0RfGyVuSlOh4tig5kOTZ9q97qcXNrFl7zqk-Ts7DqRGaKDCV")
.apiSecret("dhho4dfoCmiQXrkw4yslork5XWLFnPSuMR-8gscPVjY4jqFFHPYWJKgpFl4uLTM6")
.build();
.provider(LinkedInApi.class)
.apiKey("CiEgwWDkA5BFpNrc0RfGyVuSlOh4tig5kOTZ9q97qcXNrFl7zqk-Ts7DqRGaKDCV")
.apiSecret("dhho4dfoCmiQXrkw4yslork5XWLFnPSuMR-8gscPVjY4jqFFHPYWJKgpFl4uLTM6")
.build();
Scanner in = new Scanner(System.in);
System.out.println("=== LinkedIn's OAuth Workflow ===");
System.out.println();
@@ -31,7 +30,7 @@ public class LinkedInExample
System.out.println();
System.out.println("Now go and authorize Scribe here:");
System.out.println(AUTHORIZE_URL + requestToken.getToken());
System.out.println(service.getAuthorizationUrl(requestToken));
System.out.println("And paste the verifier here");
System.out.print(">>");
Verifier verifier = new Verifier(in.nextLine());
@@ -0,0 +1,64 @@
package org.scribe.examples;
import java.util.*;
import org.scribe.builder.*;
import org.scribe.builder.api.*;
import org.scribe.model.*;
import org.scribe.oauth.*;
public class LiveExample
{
private static final String PROTECTED_RESOURCE_URL = "https://api.foursquare.com/v2/users/self/friends?oauth_token=";
private static final Token EMPTY_TOKEN = null;
public static void main(String[] args)
{
// Replace these with your own api key and secret
String apiKey = "";
String apiSecret = "";
OAuthService service = new ServiceBuilder()
.provider(LiveApi.class)
.apiKey(apiKey)
.apiSecret(apiSecret)
.scope("wl.basic")
.callback("http://localhost:9000/")
.build();
Scanner in = new Scanner(System.in);
System.out.println("=== Windows Live's OAuth Workflow ===");
System.out.println();
// Obtain the Authorization URL
System.out.println("Fetching the Authorization URL...");
String authorizationUrl = service.getAuthorizationUrl(EMPTY_TOKEN);
System.out.println("Got the Authorization URL!");
System.out.println("Now go and authorize Scribe here:");
System.out.println(authorizationUrl);
System.out.println("And paste the authorization code here");
System.out.print(">>");
Verifier verifier = new Verifier(in.nextLine());
System.out.println();
// Trade the Request Token and Verfier for the Access Token
System.out.println("Trading the Request Token for an Access Token...");
Token accessToken = service.getAccessToken(EMPTY_TOKEN, verifier);
System.out.println("Got the Access Token!");
System.out.println("(if your curious it looks like this: " + accessToken + " )");
System.out.println();
// Now let's go and ask for a protected resource!
System.out.println("Now we're going to access a protected resource...");
OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL + accessToken.getToken());
service.signRequest(accessToken, request);
Response response = request.send();
System.out.println("Got it! Lets see what we found...");
System.out.println();
System.out.println(response.getCode());
System.out.println(response.getBody());
System.out.println();
System.out.println("Thats it man! Go and build something awesome with Scribe! :)");
}
}
@@ -0,0 +1,64 @@
package org.scribe.examples;
import java.util.*;
import org.scribe.builder.*;
import org.scribe.builder.api.*;
import org.scribe.model.*;
import org.scribe.oauth.*;
public class LoveFilmExample
{
private static final String NETWORK_NAME = "LoveFilm";
private static final String PROTECTED_RESOURCE_URL = "https://api.lovefilm.com/users";
public static void main(String[] args)
{
// Replace these with your own api key and secret
String apiKey = "your_key";
String apiSecret = "your_secret";
OAuthService service = new ServiceBuilder().provider(LoveFilmApi.class).apiKey(apiKey).apiSecret(apiSecret).build();
Scanner in = new Scanner(System.in);
System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ===");
System.out.println();
// Grab a request token.
System.out.println("Fetching request token.");
Token requestToken = service.getRequestToken();
System.out.println("Got it ... ");
System.out.println(requestToken.getToken());
// Obtain the Authorization URL
System.out.println("Fetching the Authorization URL...");
String authorizationUrl = service.getAuthorizationUrl(requestToken);
System.out.println("Got the Authorization URL!");
System.out.println("Now go and authorize Scribe here:");
System.out.println(authorizationUrl);
System.out.println("And paste the authorization code here");
System.out.print(">>");
Verifier verifier = new Verifier(in.nextLine());
System.out.println();
// Trade the Request Token and Verfier for the Access Token
System.out.println("Trading the Request Token for an Access Token...");
Token accessToken = service.getAccessToken(requestToken, verifier);
System.out.println("Got the Access Token!");
System.out.println("(if your curious it looks like this: " + accessToken + " )");
System.out.println();
// Now let's go and ask for a protected resource!
System.out.println("Now we're going to access a protected resource...");
OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL);
service.signRequest(accessToken, request);
Response response = request.send();
System.out.println("Got it! Lets see what we found...");
System.out.println();
System.out.println(response.getCode());
System.out.println(response.getBody());
System.out.println();
System.out.println("Thats it man! Go and build something awesome with Scribe! :)");
}
}
@@ -0,0 +1,62 @@
package org.scribe.examples;
import java.util.Scanner;
import org.scribe.builder.ServiceBuilder;
import org.scribe.builder.api.MeetupApi;
import org.scribe.model.OAuthRequest;
import org.scribe.model.Response;
import org.scribe.model.Token;
import org.scribe.model.Verb;
import org.scribe.model.Verifier;
import org.scribe.oauth.OAuthService;
public class MeetupExample
{
private static final String PROTECTED_RESOURCE_URL = "http://api.meetup.com/2/member/self";
public static void main(String[] args)
{
OAuthService service = new ServiceBuilder()
.provider(MeetupApi.class)
.apiKey("j1khkp0dus323ftve0sdcv6ffe")
.apiSecret("6s6gt6q59gvfjtsvgcmht62gq4")
.build();
Scanner in = new Scanner(System.in);
System.out.println("=== Meetup's OAuth Workflow ===");
System.out.println();
// Obtain the Request Token
System.out.println("Fetching the Request Token...");
Token requestToken = service.getRequestToken();
System.out.println("Got the Request Token!");
System.out.println();
System.out.println("Now go and authorize Scribe here:");
System.out.println(service.getAuthorizationUrl(requestToken));
System.out.println("And paste the verifier here");
System.out.print(">>");
Verifier verifier = new Verifier(in.nextLine());
System.out.println();
// Trade the Request Token and Verfier for the Access Token
System.out.println("Trading the Request Token for an Access Token...");
Token accessToken = service.getAccessToken(requestToken, verifier);
System.out.println("Got the Access Token!");
System.out.println("(if your curious it looks like this: " + accessToken + " )");
System.out.println();
// Now let's go and ask for a protected resource!
System.out.println("Now we're going to access a protected resource...");
OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL);
service.signRequest(accessToken, request);
Response response = request.send();
System.out.println("Got it! Lets see what we found...");
System.out.println();
System.out.println(response.getBody());
System.out.println();
System.out.println("Thats it man! Go and build something awesome with Scribe! :)");
}
}
@@ -0,0 +1,68 @@
package org.scribe.examples;
import java.util.*;
import org.scribe.builder.*;
import org.scribe.builder.api.*;
import org.scribe.model.*;
import org.scribe.oauth.*;
public class NeteaseWeiboExample
{
private static final String NETWORK_NAME = "NetEase(163.com) Weibo";
private static final String PROTECTED_RESOURCE_URL = "http://api.t.163.com/account/verify_credentials.json";
public static void main(String[] args)
{
// Replace these with your own api key and secret
String apiKey = "your key";
String apiSecret = "your secret";
OAuthService service = new ServiceBuilder()
.provider(NeteaseWeibooApi.class)
.apiKey(apiKey)
.apiSecret(apiSecret)
.build();
Scanner in = new Scanner(System.in);
System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ===");
System.out.println();
// Grab a request token.
System.out.println("Fetching request token.");
Token requestToken = service.getRequestToken();
System.out.println("Got it ... ");
System.out.println(requestToken.getToken());
// Obtain the Authorization URL
System.out.println("Fetching the Authorization URL...");
String authorizationUrl = service.getAuthorizationUrl(requestToken);
System.out.println("Got the Authorization URL!");
System.out.println("Now go and authorize Scribe here:");
System.out.println(authorizationUrl);
System.out.println("And paste the authorization code here");
System.out.print(">>");
Verifier verifier = new Verifier(in.nextLine());
System.out.println();
// Trade the Request Token and Verfier for the Access Token
System.out.println("Trading the Request Token for an Access Token...");
Token accessToken = service.getAccessToken(requestToken, verifier);
System.out.println("Got the Access Token!");
System.out.println("(if your curious it looks like this: "
+ accessToken + " )");
System.out.println();
// Now let's go and ask for a protected resource!
System.out.println("Now we're going to access a protected resource...");
OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL);
service.signRequest(accessToken, request);
Response response = request.send();
System.out.println("Got it! Lets see what we found...");
System.out.println();
System.out.println(response.getCode());
System.out.println(response.getBody());
System.out.println();
System.out.println("Thats it man! Go and build something awesome with Scribe! :)");
}
}
@@ -0,0 +1,60 @@
package org.scribe.examples;
import java.util.Scanner;
import org.scribe.builder.*;
import org.scribe.builder.api.*;
import org.scribe.model.*;
import org.scribe.oauth.*;
public class Px500Example
{
private static final String PROTECTED_RESOURCE_URL = "https://api.500px.com/v1/";
public static void main(String[] args)
{
OAuthService service = new ServiceBuilder()
.provider(Px500Api.class)
.apiKey("your-api-key")
.apiSecret("your-api-secret")
.build();
Scanner in = new Scanner(System.in);
System.out.println("=== 500Px's OAuth Workflow ===");
System.out.println();
// Obtain the Request Token
System.out.println("Fetching the Request Token...");
Token requestToken = service.getRequestToken();
System.out.println("Got the Request Token!");
System.out.println();
System.out.println("Now go and authorize Scribe here:");
System.out.println(service.getAuthorizationUrl(requestToken));
System.out.println("And paste the verifier here");
System.out.print(">>");
Verifier verifier = new Verifier(in.nextLine());
System.out.println();
// Trade the Request Token and Verfier for the Access Token
System.out.println("Trading the Request Token for an Access Token...");
Token accessToken = service.getAccessToken(requestToken, verifier);
System.out.println("Got the Access Token!");
System.out.println("(if your curious it looks like this: " + accessToken + " )");
System.out.println();
// Now let's go and ask for a protected resource!
System.out.println("Now we're going to access a protected resource...");
OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL);
service.signRequest(accessToken, request);
Response response = request.send();
System.out.println("Got it! Lets see what we found...");
System.out.println();
System.out.println(response.getBody());
System.out.println();
System.out.println("Thats it man! Go and build something awesome with Scribe! :)");
}
}
@@ -0,0 +1,108 @@
package org.scribe.examples;
import org.scribe.builder.*;
import org.scribe.builder.api.*;
import org.scribe.model.*;
import org.scribe.oauth.*;
import java.nio.charset.*;
import java.security.*;
import java.util.*;
public class RenrenExample
{
private static final String NETWORK_NAME = "Renren";
private static final String PROTECTED_RESOURCE_URL = "http://api.renren.com/restserver.do";
private static final Token EMPTY_TOKEN = null;
public static void main(String[] args)
{
// Replace these with your own api key and secret
String apiKey = "your api key";
String apiSecret = "your api secret";
OAuthService service = new ServiceBuilder()
.provider(RenrenApi.class)
.apiKey(apiKey)
.apiSecret(apiSecret)
.scope("status_update publish_feed")
.callback("http://your.doman.com/oauth/renren")
.build();
Scanner in = new Scanner(System.in);
System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ===");
System.out.println();
// Obtain the Authorization URL
System.out.println("Fetching the Authorization URL...");
String authorizationUrl = service.getAuthorizationUrl(EMPTY_TOKEN);
System.out.println("Got the Authorization URL!");
System.out.println("Now go and authorize Scribe here:");
System.out.println(authorizationUrl);
System.out.println("And paste the authorization code here");
System.out.print(">>");
Verifier verifier = new Verifier(in.nextLine());
System.out.println();
// Trade the Request Token and Verfier for the Access Token
System.out.println("Trading the Request Token for an Access Token...");
Token accessToken = service.getAccessToken(EMPTY_TOKEN, verifier);
System.out.println("Got the Access Token!");
System.out.println("(if your curious it looks like this: " + accessToken + " )");
System.out.println();
// Now let's go and ask for a protected resource!
System.out.println("Now we're going to access a protected resource...");
OAuthRequest request = new OAuthRequest(Verb.POST, PROTECTED_RESOURCE_URL);
Map<String, String> parameters = new HashMap<String, String>();
parameters.put("method", "users.getInfo");
parameters.put("format", "json");
parameters.put("v", "1.0");
List<String> sigString = new ArrayList<String>(parameters.size() + 1);
for (Map.Entry<String, String> entry : parameters.entrySet())
{
request.addQuerystringParameter(entry.getKey(), entry.getValue());
sigString.add(String.format("%s=%s", entry.getKey(), entry.getValue()));
}
sigString.add(String.format("%s=%s", OAuthConstants.ACCESS_TOKEN, accessToken.getToken()));
Collections.sort(sigString);
StringBuilder b = new StringBuilder();
for (String param : sigString)
{
b.append(param);
}
b.append(apiSecret);
System.out.println("Sig string: " + b.toString());
request.addQuerystringParameter("sig", md5(b.toString()));
service.signRequest(accessToken, request);
Response response = request.send();
System.out.println("Got it! Lets see what we found...");
System.out.println();
System.out.println(response.getCode());
System.out.println(response.getBody());
System.out.println();
System.out.println("Thats it man! Go and build something awesome with Scribe! :)");
}
public static String md5(String orgString)
{
try
{
java.security.MessageDigest md = MessageDigest.getInstance("MD5");
byte[] array = md.digest(orgString.getBytes(Charset.forName("UTF-8")));
StringBuffer sb = new StringBuffer();
for (int i = 0; i < array.length; ++i)
{
sb.append(Integer.toHexString((array[i] & 0xFF) | 0x100).substring(1, 3));
}
return sb.toString();
}
catch (NoSuchAlgorithmException e)
{
e.printStackTrace();
}
return null;
}
}
@@ -0,0 +1,63 @@
package org.scribe.examples;
import org.scribe.builder.*;
import org.scribe.builder.api.*;
import org.scribe.model.*;
import org.scribe.oauth.*;
import java.util.*;
public class SinaWeibo2Example
{
private static final String NETWORK_NAME = "SinaWeibo";
private static final String PROTECTED_RESOURCE_URL = "https://api.weibo.com/2/account/get_uid.json";
private static final Token EMPTY_TOKEN = null;
public static void main(String[] args)
{
// Replace these with your own api key and secret
String apiKey = "your_api_key";
String apiSecret = "your_api_secret";
OAuthService service = new ServiceBuilder()
.provider(SinaWeiboApi20.class)
.apiKey(apiKey)
.apiSecret(apiSecret)
.callback("http://www.dajie.com/oauth/sina")
.build();
Scanner in = new Scanner(System.in);
System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ===");
System.out.println();
// Obtain the Authorization URL
System.out.println("Fetching the Authorization URL...");
String authorizationUrl = service.getAuthorizationUrl(EMPTY_TOKEN);
System.out.println("Got the Authorization URL!");
System.out.println("Now go and authorize Scribe here:");
System.out.println(authorizationUrl);
System.out.println("And paste the authorization code here");
System.out.print(">>");
Verifier verifier = new Verifier(in.nextLine());
System.out.println();
// Trade the Request Token and Verifier for the Access Token
System.out.println("Trading the Request Token for an Access Token...");
Token accessToken = service.getAccessToken(EMPTY_TOKEN, verifier);
System.out.println("Got the Access Token!");
System.out.println("(if your curious it looks like this: " + accessToken + " )");
System.out.println();
// Now let's go and ask for a protected resource!
System.out.println("Now we're going to access a protected resource...");
OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL);
service.signRequest(accessToken, request);
Response response = request.send();
System.out.println("Got it! Lets see what we found...");
System.out.println();
System.out.println(response.getCode());
System.out.println(response.getBody());
System.out.println();
System.out.println("Thats it man! Go and build something awesome with Scribe! :)");
}
}
@@ -0,0 +1,68 @@
package org.scribe.examples;
import java.util.*;
import org.scribe.builder.*;
import org.scribe.builder.api.*;
import org.scribe.model.*;
import org.scribe.oauth.*;
public class SinaWeiboExample
{
private static final String NETWORK_NAME = "SinaWeibo";
private static final String PROTECTED_RESOURCE_URL = "http://api.t.sina.com.cn/account/verify_credentials.json";
public static void main(String[] args)
{
// Replace these with your own api key and secret
String apiKey = "your key";
String apiSecret = "your secret";
OAuthService service = new ServiceBuilder()
.provider(SinaWeiboApi.class)
.apiKey(apiKey)
.apiSecret(apiSecret)
.build();
Scanner in = new Scanner(System.in);
System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ===");
System.out.println();
// Grab a request token.
System.out.println("Fetching request token.");
Token requestToken = service.getRequestToken();
System.out.println("Got it ... ");
System.out.println(requestToken.getToken());
// Obtain the Authorization URL
System.out.println("Fetching the Authorization URL...");
String authorizationUrl = service.getAuthorizationUrl(requestToken);
System.out.println("Got the Authorization URL!");
System.out.println("Now go and authorize Scribe here:");
System.out.println(authorizationUrl);
System.out.println("And paste the authorization code here");
System.out.print(">>");
Verifier verifier = new Verifier(in.nextLine());
System.out.println();
// Trade the Request Token and Verfier for the Access Token
System.out.println("Trading the Request Token for an Access Token...");
Token accessToken = service.getAccessToken(requestToken, verifier);
System.out.println("Got the Access Token!");
System.out.println("(if your curious it looks like this: "
+ accessToken + " )");
System.out.println();
// Now let's go and ask for a protected resource!
System.out.println("Now we're going to access a protected resource...");
OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL);
service.signRequest(accessToken, request);
Response response = request.send();
System.out.println("Got it! Lets see what we found...");
System.out.println();
System.out.println(response.getCode());
System.out.println(response.getBody());
System.out.println();
System.out.println("Thats it man! Go and build something awesome with Scribe! :)");
}
}
@@ -0,0 +1,61 @@
package org.scribe.examples;
import java.util.Scanner;
import org.scribe.builder.*;
import org.scribe.builder.api.*;
import org.scribe.model.*;
import org.scribe.oauth.*;
public class SkyrockExample
{
private static final String PROTECTED_RESOURCE_URL = "https://api.skyrock.com/v2/user/get.json";
public static void main(String[] args)
{
OAuthService service = new ServiceBuilder()
.provider(SkyrockApi.class)
.apiKey("your-api-key")
.apiSecret("your-api-secret")
.build();
Scanner in = new Scanner(System.in);
System.out.println("=== Skyrock's OAuth Workflow ===");
System.out.println();
// Obtain the Request Token
System.out.println("Fetching the Request Token...");
Token requestToken = service.getRequestToken();
System.out.println("Got the Request Token!");
System.out.println();
System.out.println("Now go and authorize Scribe here:");
System.out.println(service.getAuthorizationUrl(requestToken));
System.out.println("And paste the verifier here");
System.out.print(">>");
Verifier verifier = new Verifier(in.nextLine());
System.out.println();
// Trade the Request Token and Verfier for the Access Token
System.out.println("Trading the Request Token for an Access Token...");
Token accessToken = service.getAccessToken(requestToken, verifier);
System.out.println("Got the Access Token!");
System.out.println("(if your curious it looks like this: " + accessToken + " )");
System.out.println();
// Now let's go and ask for a protected resource!
System.out.println("Now we're going to access a protected resource...");
OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL);
service.signRequest(accessToken, request);
Response response = request.send();
System.out.println("Got it! Lets see what we found...");
System.out.println();
System.out.println(response.getCode());
System.out.println(response.getBody());
System.out.println();
System.out.println("Thats it man! Go and build something awesome with Scribe! :)");
}
}
@@ -0,0 +1,68 @@
package org.scribe.examples;
import java.util.*;
import org.scribe.builder.*;
import org.scribe.builder.api.*;
import org.scribe.model.*;
import org.scribe.oauth.*;
public class SohuWeiboExample
{
private static final String NETWORK_NAME = "SohuWeibo";
private static final String PROTECTED_RESOURCE_URL = "http://api.t.sohu.com/account/verify_credentials.json";
public static void main(String[] args)
{
// Replace these with your own api key and secret
String apiKey = "your_key";
String apiSecret = "your_secret";
OAuthService service = new ServiceBuilder()
.provider(SohuWeiboApi.class)
.apiKey(apiKey)
.apiSecret(apiSecret)
.build();
Scanner in = new Scanner(System.in);
System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ===");
System.out.println();
// Grab a request token.
System.out.println("Fetching request token.");
Token requestToken = service.getRequestToken();
System.out.println("Got it ... ");
System.out.println(requestToken.getToken());
// Obtain the Authorization URL
System.out.println("Fetching the Authorization URL...");
String authorizationUrl = service.getAuthorizationUrl(requestToken);
System.out.println("Got the Authorization URL!");
System.out.println("Now go and authorize Scribe here:");
System.out.println(authorizationUrl);
System.out.println("And paste the authorization code here");
System.out.print(">>");
Verifier verifier = new Verifier(in.nextLine());
System.out.println();
// Trade the Request Token and Verfier for the Access Token
System.out.println("Trading the Request Token for an Access Token...");
Token accessToken = service.getAccessToken(requestToken, verifier);
System.out.println("Got the Access Token!");
System.out.println("(if your curious it looks like this: "
+ accessToken + " )");
System.out.println();
// Now let's go and ask for a protected resource!
System.out.println("Now we're going to access a protected resource...");
OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL);
service.signRequest(accessToken, request);
Response response = request.send();
System.out.println("Got it! Lets see what we found...");
System.out.println();
System.out.println(response.getCode());
System.out.println(response.getBody());
System.out.println();
System.out.println("Thats it man! Go and build something awesome with Scribe! :)");
}
}
@@ -9,8 +9,7 @@ import org.scribe.oauth.*;
public class TwitterExample
{
private static final String AUTHORIZE_URL = "https://api.twitter.com/oauth/authorize?oauth_token=";
private static final String PROTECTED_RESOURCE_URL = "http://api.twitter.com/1/account/verify_credentials.xml";
private static final String PROTECTED_RESOURCE_URL = "https://api.twitter.com/1/statuses/update.json";
public static void main(String[] args)
{
@@ -31,7 +30,7 @@ public class TwitterExample
System.out.println();
System.out.println("Now go and authorize Scribe here:");
System.out.println(AUTHORIZE_URL + requestToken.getToken());
System.out.println(service.getAuthorizationUrl(requestToken));
System.out.println("And paste the verifier here");
System.out.print(">>");
Verifier verifier = new Verifier(in.nextLine());
@@ -46,7 +45,8 @@ public class TwitterExample
// 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);
OAuthRequest request = new OAuthRequest(Verb.POST, PROTECTED_RESOURCE_URL);
request.addBodyParameter("status", "this is sparta! *");
service.signRequest(accessToken, request);
Response response = request.send();
System.out.println("Got it! Lets see what we found...");
@@ -0,0 +1,68 @@
package org.scribe.examples;
import org.scribe.builder.*;
import org.scribe.builder.api.*;
import org.scribe.model.*;
import org.scribe.oauth.*;
import java.util.*;
/**
* @author Boris G. Tsirkin <mail@dotbg.name>
* @since 20.4.2011
*/
public class VkontakteExample
{
private static final String NETWORK_NAME = "Vkontakte.ru";
private static final String PROTECTED_RESOURCE_URL = "https://api.vkontakte.ru/method/friends.get";
private static final Token EMPTY_TOKEN = null;
public static void main(String[] args)
{
// Replace these with your own api key and secret
final String clientId = "your app id";
final String apiSecret = "your api secret";
OAuthService service = new ServiceBuilder()
.provider(VkontakteApi.class)
.apiKey(clientId)
.apiSecret(apiSecret)
.scope("friends,wall,offline") // replace with desired scope
.callback("http://your.site.com/callback")
.build();
Scanner in = new Scanner(System.in);
System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ===");
System.out.println();
// Obtain the Authorization URL
System.out.println("Fetching the Authorization URL...");
String authorizationUrl = service.getAuthorizationUrl(EMPTY_TOKEN);
System.out.println("Got the Authorization URL!");
System.out.println("Now go and authorize Scribe here:");
System.out.println(authorizationUrl);
System.out.println("And paste the authorization code here");
System.out.print(">>");
Verifier verifier = new Verifier(in.nextLine());
System.out.println();
// Trade the Request Token and Verfier for the Access Token
System.out.println("Trading the Request Token for an Access Token...");
Token accessToken = service.getAccessToken(EMPTY_TOKEN, verifier);
System.out.println("Got the Access Token!");
System.out.println("(if your curious it looks like this: " + accessToken + " )");
System.out.println();
// Now let's go and ask for a protected resource!
System.out.println("Now we're going to access a protected resource...");
OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL);
service.signRequest(accessToken, request);
Response response = request.send();
System.out.println("Got it! Lets see what we found...");
System.out.println();
System.out.println(response.getCode());
System.out.println(response.getBody());
System.out.println();
System.out.println("Thats it man! Go and build something awesome with Scribe! :)");
}
}
@@ -9,20 +9,18 @@ import org.scribe.oauth.*;
public class YahooExample
{
private static final String NETWORK_NAME = "Yahoo";
private static final String AUTHORIZE_URL = "https://api.login.yahoo.com/oauth/v2/request_auth?oauth_token=";
private static final String PROTECTED_RESOURCE_URL = "http://social.yahooapis.com/v1/user/A6ROU63MXWDCW3Y5MGCYWVHDJI/profile/status?format=json";
public static void main(String[] args)
{
OAuthService service = new ServiceBuilder()
.provider(YahooApi.class)
.apiKey("dj0yJmk9TXZDWVpNVVdGaVFmJmQ9WVdrOWMweHZXbkZLTkhVbWNHbzlNVEl5TWprd05qUTJNZy0tJnM9Y29uc3VtZXJzZWNyZXQmeD0wMw--")
.apiSecret("262be559f92a2be20c4c039419018f2b48cdfce9")
.build();
.provider(YahooApi.class)
.apiKey("dj0yJmk9TXZDWVpNVVdGaVFmJmQ9WVdrOWMweHZXbkZLTkhVbWNHbzlNVEl5TWprd05qUTJNZy0tJnM9Y29uc3VtZXJzZWNyZXQmeD0wMw--")
.apiSecret("262be559f92a2be20c4c039419018f2b48cdfce9")
.build();
Scanner in = new Scanner(System.in);
System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ===");
System.out.println("=== Yahoo's OAuth Workflow ===");
System.out.println();
// Obtain the Request Token
@@ -32,7 +30,7 @@ public class YahooExample
System.out.println();
System.out.println("Now go and authorize Scribe here:");
System.out.println(AUTHORIZE_URL + requestToken.getToken());
System.out.println(service.getAuthorizationUrl(requestToken));
System.out.println("And paste the verifier here");
System.out.print(">>");
Verifier verifier = new Verifier(in.nextLine());
@@ -41,7 +41,7 @@ public class BaseStringExtractorTest
OAuthRequest request = new OAuthRequest(Verb.GET, "http://example.com");
extractor.extract(request);
}
@Test
public void shouldProperlyEncodeSpaces()
{
Loaded 100 of 112 files, more files were not shown because too many files have changed in this diff. Show more