Compare commits

1 Commits
Author SHA1 Message Date
Pablo Fernandez 450a3382cc Added multiparameter functionallity 2010-09-13 19:47:17 -03:00
129 changed files with 561 additions and 4971 deletions

No files matched your search

-5
View File
@@ -5,11 +5,6 @@
.project .project
.settings .settings
# IntelliJ Idea settings
.idea
scribe.iml
# Binaries # Binaries
target target
-5
View File
@@ -1,5 +0,0 @@
# kickstart travis.
language: java
# need to override travis 'install' since it will try gpg sign and fail.
install: mvn clean package -DskipTests=true
-21
View File
@@ -1,21 +0,0 @@
The MIT License
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
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
+3 -35
View File
@@ -1,6 +1,6 @@
h2. Welcome to the home of Scribe, the simple OAuth Java lib! !http://img411.imageshack.us/img411/2851/scribelogo.png!
!https://secure.travis-ci.org/fernandezpablo85/scribe-java.png?branch=master(travis-ci-status)! h2. Welcome to the home of Scribe, the simple OAuth Java lib!
h1. Why use Scribe? h1. Why use Scribe?
@@ -20,12 +20,10 @@ h3. Threadsafe
Hit Scribe as hard and with many threads as you like. Hit Scribe as hard and with many threads as you like.
h3. Supports all major 1.0a and 2.0 OAuth APIs out-of-the-box h3. Supports all major OAuth APIs out-of-the-box
* Google * Google
* Facebook
* Yahoo * Yahoo
* LinkedIn * LinkedIn
@@ -34,14 +32,6 @@ h3. Supports all major 1.0a and 2.0 OAuth APIs out-of-the-box
* Foursquare * 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 * 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 h3. Small and modular
@@ -58,34 +48,12 @@ Good test coverage to keep you safe from harm.
When something bad actually happens, Scribe's meaningful error messages will tell you exactly what went wrong, when and where. When something bad actually happens, Scribe's meaningful error messages will tell you exactly what went wrong, when and where.
h3. Pull it from Maven! (new)
You can pull scribe from a maven repository, just add this to your __pom.xml__ file:
@<dependency>@
@<groupId>org.scribe</groupId>@
@<artifactId>scribe</artifactId>@
@<version>1.3.0</version>@
@</dependency>@
h1. Getting started in less than 2 minutes h1. Getting started in less than 2 minutes
Check the "Getting Started":http://wiki.github.com/fernandezpablo85/scribe-java/getting-started page and start rocking! Check the "Getting Started":http://wiki.github.com/fernandezpablo85/scribe-java/getting-started page and start rocking!
h1. Please Read the "FAQ":http://wiki.github.com/fernandezpablo85/scribe-java/faq before creating an issue :) h1. 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 h1. About me
"LinkedIn profile":http://www.linkedin.com/in/fernandezpablo85 "LinkedIn profile":http://www.linkedin.com/in/fernandezpablo85
-2
View File
@@ -1,2 +0,0 @@
#!/bin/sh
mvn source:jar javadoc:jar package gpg:sign repository:bundle-create -Dgpg.passphrase=$1
-88
View File
@@ -1,88 +0,0 @@
[1.0.6]
* FEATURE: Available in maven central repositories.
[1.0.7]
* FEATURE: Added support for Yammer and Evernote ( thanks oparrsih )
* FIX: Fixed bug that preventing setting the scope param on Google Api
[1.0.8]
* FEATURE: Added setConnectTimeout and setReadTimeout for the Request Object
* 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
+4 -54
View File
@@ -4,44 +4,8 @@
<groupId>org.scribe</groupId> <groupId>org.scribe</groupId>
<artifactId>scribe</artifactId> <artifactId>scribe</artifactId>
<packaging>jar</packaging> <packaging>jar</packaging>
<version>1.3.1</version> <version>1.0.1</version>
<name>Scribe OAuth Library</name> <name>OAuth Library</name>
<description>The best OAuth library out there</description>
<url>http://github.com/fernandezpablo85/scribe-java</url>
<parent>
<groupId>org.sonatype.oss</groupId>
<artifactId>oss-parent</artifactId>
<version>5</version>
</parent>
<developers>
<developer>
<id>fernandezpablo85</id>
<name>Pablo Fernandez</name>
<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>
<license>
<name>MIT</name>
<url>http://github.com/fernandezpablo85/scribe-java/blob/master/LICENSE.txt</url>
</license>
</licenses>
<scm>
<connection>scm:http://github.com/fernandezpablo85/scribe-java.git</connection>
<developerConnection>scm:http://github.com/fernandezpablo85/scribe-java.git</developerConnection>
<url>http://github.com/fernandezpablo85/scribe-java.git</url>
</scm>
<dependencies> <dependencies>
<dependency> <dependency>
@@ -54,7 +18,6 @@
<groupId>junit</groupId> <groupId>junit</groupId>
<artifactId>junit</artifactId> <artifactId>junit</artifactId>
<version>4.8.1</version> <version>4.8.1</version>
<scope>test</scope>
</dependency> </dependency>
</dependencies> </dependencies>
@@ -63,23 +26,10 @@
<plugin> <plugin>
<artifactId>maven-compiler-plugin</artifactId> <artifactId>maven-compiler-plugin</artifactId>
<configuration> <configuration>
<source>1.5</source> <source>1.6</source>
<target>1.5</target> <target>1.6</target>
</configuration> </configuration>
</plugin> </plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins> </plugins>
</build> </build>
</project> </project>
@@ -1,290 +0,0 @@
<?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>
@@ -1,7 +0,0 @@
#Organize Import Order
#Tue Feb 21 20:29:55 GMT 2012
4=java
3=javax
2=org
1=org.boncey
0=com
@@ -1,8 +1,8 @@
package org.scribe.builder; package org.scribe.builder;
import java.io.*;
import org.scribe.builder.api.*; import org.scribe.builder.api.*;
import org.scribe.exceptions.*; import org.scribe.exceptions.*;
import org.scribe.model.*; import org.scribe.model.*;
import org.scribe.oauth.*; import org.scribe.oauth.*;
import org.scribe.utils.*; import org.scribe.utils.*;
@@ -20,18 +20,10 @@ public class ServiceBuilder
private String apiSecret; private String apiSecret;
private String callback; private String callback;
private Api api; private Api api;
private String scope;
private SignatureType signatureType;
private OutputStream debugStream;
/**
* Default constructor
*/
public ServiceBuilder() public ServiceBuilder()
{ {
this.callback = OAuthConstants.OUT_OF_BAND; this.callback = OAuthConstants.OUT_OF_BAND;
this.signatureType = SignatureType.Header;
this.debugStream = null;
} }
/** /**
@@ -60,22 +52,7 @@ public class ServiceBuilder
} }
return api; 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 * Adds an OAuth callback url
* *
@@ -84,7 +61,7 @@ public class ServiceBuilder
*/ */
public ServiceBuilder callback(String callback) public ServiceBuilder callback(String callback)
{ {
Preconditions.checkNotNull(callback, "Callback can't be null"); Preconditions.checkValidOAuthCallback(callback, "Callback must be a valid URL or 'oob'");
this.callback = callback; this.callback = callback;
return this; return this;
} }
@@ -115,45 +92,6 @@ public class ServiceBuilder
return this; return this;
} }
/**
* Configures the OAuth scope. This is only necessary in some APIs (like Google's).
*
* @param scope The OAuth scope
* @return the {@link ServiceBuilder} instance for method chaining
*/
public ServiceBuilder scope(String scope)
{
Preconditions.checkEmptyString(scope, "Invalid OAuth scope");
this.scope = scope;
return this;
}
/**
* Configures the signature type, choose between header, querystring, etc. Defaults to Header
*
* @param scope The OAuth scope
* @return the {@link ServiceBuilder} instance for method chaining
*/
public ServiceBuilder signatureType(SignatureType type)
{
Preconditions.checkNotNull(type, "Signature type can't be null");
this.signatureType = type;
return this;
}
public ServiceBuilder debugStream(OutputStream stream)
{
Preconditions.checkNotNull(stream, "debug stream can't be null");
this.debugStream = stream;
return this;
}
public ServiceBuilder debug()
{
this.debugStream(System.out);
return this;
}
/** /**
* Returns the fully configured {@link OAuthService} * Returns the fully configured {@link OAuthService}
* *
@@ -164,6 +102,6 @@ public class ServiceBuilder
Preconditions.checkNotNull(api, "You must specify a valid api through the provider() method"); Preconditions.checkNotNull(api, "You must specify a valid api through the provider() method");
Preconditions.checkEmptyString(apiKey, "You must provide an api key"); Preconditions.checkEmptyString(apiKey, "You must provide an api key");
Preconditions.checkEmptyString(apiSecret, "You must provide an api secret"); Preconditions.checkEmptyString(apiSecret, "You must provide an api secret");
return api.createService(new OAuthConfig(apiKey, apiSecret, callback, signatureType, scope, debugStream)); return api.createService(apiKey, apiSecret, callback);
} }
} }
@@ -1,6 +1,5 @@
package org.scribe.builder.api; package org.scribe.builder.api;
import org.scribe.model.*;
import org.scribe.oauth.*; import org.scribe.oauth.*;
/** /**
@@ -17,9 +16,8 @@ public interface Api
* @param apiKey your application api key * @param apiKey your application api key
* @param apiSecret your application api secret * @param apiSecret your application api secret
* @param callback the callback url (or 'oob' for out of band OAuth) * @param callback the callback url (or 'oob' for out of band OAuth)
* @param scope the OAuth scope
* *
* @return fully configured {@link OAuthService} * @return fully configured {@link OAuthService}
*/ */
OAuthService createService(OAuthConfig config); OAuthService createService(String apiKey, String apiSecret, String callback);
} }
@@ -1,26 +0,0 @@
package org.scribe.builder.api;
import org.scribe.model.*;
public class ConstantContactApi extends DefaultApi10a
{
private static final String AUTHORIZE_URL = "https://oauth.constantcontact.com/ws/oauth/confirm_access?oauth_token=%s";
@Override
public String getAccessTokenEndpoint()
{
return "https://oauth.constantcontact.com/ws/oauth/access_token";
}
@Override
public String getAuthorizationUrl(Token requestToken)
{
return String.format(AUTHORIZE_URL, requestToken.getToken());
}
@Override
public String getRequestTokenEndpoint()
{
return "https://oauth.constantcontact.com/ws/oauth/request_token";
}
}
@@ -5,137 +5,74 @@ import org.scribe.model.*;
import org.scribe.oauth.*; import org.scribe.oauth.*;
import org.scribe.services.*; import org.scribe.services.*;
/**
* Default implementation of the OAuth protocol, version 1.0a
*
* This class is meant to be extended by concrete implementations of the API,
* providing the endpoints and endpoint-http-verbs.
*
* If your Api adheres to the 1.0a protocol correctly, you just need to extend
* this class and define the getters for your endpoints.
*
* If your Api does something a bit different, you can override the different
* extractors or services, in order to fine-tune the process. Please read the
* javadocs of the interfaces to get an idea of what to do.
*
* @author Pablo Fernandez
*
*/
public abstract class DefaultApi10a implements Api public abstract class DefaultApi10a implements Api
{ {
/**
* Returns the access token extractor.
*
* @return access token extractor
*/
public AccessTokenExtractor getAccessTokenExtractor() public AccessTokenExtractor getAccessTokenExtractor()
{ {
return new TokenExtractorImpl(); return new TokenExtractorImpl();
} }
/**
* Returns the base string extractor.
*
* @return base string extractor
*/
public BaseStringExtractor getBaseStringExtractor() public BaseStringExtractor getBaseStringExtractor()
{ {
return new BaseStringExtractorImpl(); return new BaseStringExtractorImpl();
} }
/**
* Returns the header extractor.
*
* @return header extractor
*/
public HeaderExtractor getHeaderExtractor() public HeaderExtractor getHeaderExtractor()
{ {
return new HeaderExtractorImpl(); return new HeaderExtractorImpl();
} }
/**
* Returns the request token extractor.
*
* @return request token extractor
*/
public RequestTokenExtractor getRequestTokenExtractor() public RequestTokenExtractor getRequestTokenExtractor()
{ {
return new TokenExtractorImpl(); return new TokenExtractorImpl();
} }
/**
* Returns the signature service.
*
* @return signature service
*/
public SignatureService getSignatureService() public SignatureService getSignatureService()
{ {
return new HMACSha1SignatureService(); return new HMACSha1SignatureService();
} }
/**
* Returns the timestamp service.
*
* @return timestamp service
*/
public TimestampService getTimestampService() public TimestampService getTimestampService()
{ {
return new TimestampServiceImpl(); return new TimestampServiceImpl();
} }
/**
* Returns the verb for the access token endpoint (defaults to POST)
*
* @return access token endpoint verb
*/
public Verb getAccessTokenVerb() public Verb getAccessTokenVerb()
{ {
return Verb.POST; return Verb.POST;
} }
/**
* Returns the verb for the request token endpoint (defaults to POST)
*
* @return request token endpoint verb
*/
public Verb getRequestTokenVerb() public Verb getRequestTokenVerb()
{ {
return Verb.POST; return Verb.POST;
} }
/**
* Returns the URL that receives the request token requests.
*
* @return request token URL
*/
public abstract String getRequestTokenEndpoint(); public abstract String getRequestTokenEndpoint();
/**
* Returns the URL that receives the access token requests.
*
* @return access token URL
*/
public abstract String getAccessTokenEndpoint(); public abstract String getAccessTokenEndpoint();
/** @Override
* Returns the URL where you should redirect your users to authenticate public OAuthService createService(String apiKey, String apiSecret, String callback)
* your application.
*
* @param requestToken the request token you need to authorize
* @return the URL where you should redirect your users
*/
public abstract String getAuthorizationUrl(Token requestToken);
/**
* Returns the {@link OAuthService} for this Api
*
* @param apiKey Key
* @param apiSecret Api Secret
* @param callback OAuth callback (either URL or 'oob')
* @param scope OAuth scope (optional)
*/
public OAuthService createService(OAuthConfig config)
{ {
return new OAuth10aServiceImpl(this, config); 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;
}
} }
@@ -1,70 +0,0 @@
package org.scribe.builder.api;
import org.scribe.extractors.*;
import org.scribe.model.*;
import org.scribe.oauth.*;
/**
* Default implementation of the OAuth protocol, version 2.0 (draft 11)
*
* This class is meant to be extended by concrete implementations of the API,
* providing the endpoints and endpoint-http-verbs.
*
* If your Api adheres to the 2.0 (draft 11) protocol correctly, you just need to extend
* this class and define the getters for your endpoints.
*
* If your Api does something a bit different, you can override the different
* extractors or services, in order to fine-tune the process. Please read the
* javadocs of the interfaces to get an idea of what to do.
*
* @author Diego Silveira
*
*/
public abstract class DefaultApi20 implements Api
{
/**
* Returns the access token extractor.
*
* @return access token extractor
*/
public AccessTokenExtractor getAccessTokenExtractor()
{
return new TokenExtractor20Impl();
}
/**
* Returns the verb for the access token endpoint (defaults to GET)
*
* @return access token endpoint verb
*/
public Verb getAccessTokenVerb()
{
return Verb.GET;
}
/**
* Returns the URL that receives the access token requests.
*
* @return access token URL
*/
public abstract String getAccessTokenEndpoint();
/**
* Returns the URL where you should redirect your users to authenticate
* your application.
*
* @param config OAuth 2.0 configuration param object
* @return the URL where you should redirect your users
*/
public abstract String getAuthorizationUrl(OAuthConfig config);
/**
* {@inheritDoc}
*/
public OAuthService createService(OAuthConfig config)
{
return new OAuth20ServiceImpl(this, config);
}
}
@@ -1,29 +0,0 @@
package org.scribe.builder.api;
import org.scribe.model.*;
public class DiggApi extends DefaultApi10a
{
private static final String AUTHORIZATION_URL = "http://digg.com/oauth/authorize?oauth_token=%s";
private static final String BASE_URL = "http://services.digg.com/oauth/";
@Override
public String getRequestTokenEndpoint()
{
return BASE_URL + "request_token";
}
@Override
public String getAccessTokenEndpoint()
{
return BASE_URL + "access_token";
}
@Override
public String getAuthorizationUrl(Token requestToken)
{
return String.format(AUTHORIZATION_URL, requestToken.getToken());
}
}
@@ -1,25 +0,0 @@
package org.scribe.builder.api;
import org.scribe.model.*;
public class DropBoxApi extends DefaultApi10a
{
@Override
public String getAccessTokenEndpoint()
{
return "https://api.dropbox.com/1/oauth/access_token";
}
@Override
public String getAuthorizationUrl(Token requestToken)
{
return "https://www.dropbox.com/1/oauth/authorize?oauth_token="+requestToken.getToken();
}
@Override
public String getRequestTokenEndpoint()
{
return "https://api.dropbox.com/1/oauth/request_token";
}
}
@@ -1,49 +0,0 @@
package org.scribe.builder.api;
import org.scribe.model.Token;
public class EvernoteApi extends DefaultApi10a
{
private static final String AUTHORIZATION_URL = "https://www.evernote.com/OAuth.action?oauth_token=%s";
@Override
public String getRequestTokenEndpoint()
{
return "https://www.evernote.com/oauth";
}
@Override
public String getAccessTokenEndpoint()
{
return "https://www.evernote.com/oauth";
}
@Override
public String getAuthorizationUrl(Token requestToken)
{
return String.format(AUTHORIZATION_URL, requestToken.getToken());
}
public static class Sandbox extends EvernoteApi
{
private static final String SANDBOX_URL = "https://sandbox.evernote.com";
@Override
public String getRequestTokenEndpoint()
{
return SANDBOX_URL + "/oauth";
}
@Override
public String getAccessTokenEndpoint()
{
return SANDBOX_URL + "/oauth";
}
@Override
public String getAuthorizationUrl(Token requestToken)
{
return String.format(SANDBOX_URL + "/OAuth.action?oauth_token=%s", requestToken.getToken());
}
}
}
@@ -1,33 +0,0 @@
package org.scribe.builder.api;
import org.scribe.model.*;
import org.scribe.utils.*;
public class FacebookApi extends DefaultApi20
{
private static final String AUTHORIZE_URL = "https://www.facebook.com/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()));
}
}
}
@@ -1,40 +0,0 @@
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";
}
}
@@ -1,29 +0,0 @@
package org.scribe.builder.api;
import org.scribe.extractors.*;
import org.scribe.model.*;
import org.scribe.utils.*;
public class Foursquare2Api extends DefaultApi20
{
private static final String AUTHORIZATION_URL = "https://foursquare.com/oauth2/authenticate?client_id=%s&response_type=code&redirect_uri=%s";
@Override
public String getAccessTokenEndpoint()
{
return "https://foursquare.com/oauth2/access_token?grant_type=authorization_code";
}
@Override
public String getAuthorizationUrl(OAuthConfig config)
{
Preconditions.checkValidUrl(config.getCallback(), "Must provide a valid url as callback. Foursquare2 does not support OOB");
return String.format(AUTHORIZATION_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()));
}
@Override
public AccessTokenExtractor getAccessTokenExtractor()
{
return new JsonTokenExtractor();
}
}
@@ -1,11 +1,7 @@
package org.scribe.builder.api; package org.scribe.builder.api;
import org.scribe.model.Token;
public class FoursquareApi extends DefaultApi10a public class FoursquareApi extends DefaultApi10a
{ {
private static final String AUTHORIZATION_URL = "http://foursquare.com/oauth/authorize?oauth_token=%s";
@Override @Override
public String getAccessTokenEndpoint() public String getAccessTokenEndpoint()
{ {
@@ -17,10 +13,4 @@ public class FoursquareApi extends DefaultApi10a
{ {
return "http://foursquare.com/oauth/request_token"; return "http://foursquare.com/oauth/request_token";
} }
@Override
public String getAuthorizationUrl(Token requestToken)
{
return String.format(AUTHORIZATION_URL, requestToken.getToken());
}
} }
@@ -1,61 +0,0 @@
package org.scribe.builder.api;
import org.scribe.model.*;
public class FreelancerApi extends DefaultApi10a
{
private static final String AUTHORIZATION_URL = "http://www.freelancer.com/users/api-token/auth.php?oauth_token=%s";
@Override
public String getAccessTokenEndpoint()
{
return "http://api.freelancer.com/RequestAccessToken/requestAccessToken.xml?";
}
@Override
public String getRequestTokenEndpoint()
{
return "http://api.freelancer.com/RequestRequestToken/requestRequestToken.xml";
}
@Override
public Verb getAccessTokenVerb()
{
return Verb.GET;
}
@Override
public Verb getRequestTokenVerb()
{
return Verb.GET;
}
@Override
public String getAuthorizationUrl(Token requestToken)
{
return String.format(AUTHORIZATION_URL, requestToken.getToken());
}
public static class Sandbox extends FreelancerApi
{
private static final String SANDBOX_AUTHORIZATION_URL = "http://www.sandbox.freelancer.com/users/api-token/auth.php";
@Override
public String getRequestTokenEndpoint()
{
return "http://api.sandbox.freelancer.com/RequestRequestToken/requestRequestToken.xml";
}
@Override
public String getAccessTokenEndpoint()
{
return "http://api.sandbox.freelancer.com/RequestAccessToken/requestAccessToken.xml?";
}
@Override
public String getAuthorizationUrl(Token requestToken)
{
return String.format(SANDBOX_AUTHORIZATION_URL + "?oauth_token=%s", requestToken.getToken());
}
}
}
@@ -1,29 +0,0 @@
package org.scribe.builder.api;
import org.scribe.model.Token;
public class GetGlueApi extends DefaultApi10a
{
private static final String AUTHORIZE_URL = "http://getglue.com/oauth/authorize?oauth_token=%s";
private static final String REQUEST_TOKEN_RESOURCE = "https://api.getglue.com/oauth/request_token";
private static final String ACCESS_TOKEN_RESOURCE = "https://api.getglue.com/oauth/access_token";
@Override
public String getAccessTokenEndpoint()
{
return ACCESS_TOKEN_RESOURCE;
}
@Override
public String getRequestTokenEndpoint()
{
return REQUEST_TOKEN_RESOURCE;
}
@Override
public String getAuthorizationUrl(Token requestToken)
{
return String.format(AUTHORIZE_URL, requestToken.getToken());
}
}
@@ -1,38 +1,16 @@
package org.scribe.builder.api; package org.scribe.builder.api;
import org.scribe.model.*;
public class GoogleApi extends DefaultApi10a public class GoogleApi extends DefaultApi10a
{ {
private static final String AUTHORIZATION_URL = "https://www.google.com/accounts/OAuthAuthorizeToken?oauth_token=%s";
@Override @Override
public String getAccessTokenEndpoint() public String getAccessTokenEndpoint()
{ {
return "https://www.google.com/accounts/OAuthGetAccessToken"; return "https://www.google.com/accounts/OAuthGetRequestToken";
} }
@Override @Override
public String getRequestTokenEndpoint() public String getRequestTokenEndpoint()
{ {
return "https://www.google.com/accounts/OAuthGetRequestToken"; return "https://www.google.com/accounts/OAuthGetAccessToken";
}
@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());
} }
} }
@@ -1,32 +0,0 @@
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());
}
}
@@ -1,40 +0,0 @@
package org.scribe.builder.api;
import org.scribe.model.*;
public class KaixinApi extends DefaultApi10a
{
private static final String REQUEST_TOKEN_URL = "http://api.kaixin001.com/oauth/request_token";
private static final String ACCESS_TOKEN_URL = "http://api.kaixin001.com/oauth/access_token";
private static final String AUTHORIZE_URL = "http://api.kaixin001.com/oauth/authorize?oauth_token=%s";
@Override
public String getRequestTokenEndpoint()
{
return REQUEST_TOKEN_URL;
}
@Override
public String getAccessTokenEndpoint()
{
return ACCESS_TOKEN_URL;
}
@Override
public String getAuthorizationUrl(Token requestToken)
{
return String.format(AUTHORIZE_URL, requestToken.getToken());
}
@Override
public Verb getRequestTokenVerb()
{
return Verb.GET;
}
@Override
public Verb getAccessTokenVerb()
{
return Verb.GET;
}
}
@@ -1,41 +0,0 @@
package org.scribe.builder.api;
import org.scribe.extractors.*;
import org.scribe.model.*;
import org.scribe.utils.*;
/**
* Kaixin(http://www.kaixin001.com/) open platform api based on OAuth 2.0.
*/
public class KaixinApi20 extends DefaultApi20
{
private static final String AUTHORIZE_URL = "http://api.kaixin001.com/oauth2/authorize?client_id=%s&redirect_uri=%s&response_type=code";
private static final String SCOPED_AUTHORIZE_URL = AUTHORIZE_URL + "&scope=%s";
@Override
public AccessTokenExtractor getAccessTokenExtractor()
{
return new JsonTokenExtractor();
}
@Override
public String getAccessTokenEndpoint()
{
return "https://api.kaixin001.com/oauth2/access_token?grant_type=authorization_code";
}
@Override
public String getAuthorizationUrl(OAuthConfig config)
{
// Append scope if present
if (config.hasScope())
{
return String.format(SCOPED_AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()), OAuthEncoder.encode(config.getScope()));
}
else
{
return String.format(AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()));
}
}
}
@@ -1,10 +1,10 @@
package org.scribe.builder.api; package org.scribe.builder.api;
import org.scribe.model.*; import org.scribe.extensions.linkedin.*;
import org.scribe.extractors.*;
public class LinkedInApi extends DefaultApi10a public class LinkedInApi extends DefaultApi10a
{ {
private static final String AUTHORIZE_URL = "https://api.linkedin.com/uas/oauth/authorize?oauth_token=%s";
@Override @Override
public String getAccessTokenEndpoint() public String getAccessTokenEndpoint()
@@ -19,9 +19,9 @@ public class LinkedInApi extends DefaultApi10a
} }
@Override @Override
public String getAuthorizationUrl(Token requestToken) public BaseStringExtractor getBaseStringExtractor()
{ {
return String.format(AUTHORIZE_URL, requestToken.getToken()); return new LinkedInBaseStringExtractorImpl();
} }
} }
@@ -1,40 +0,0 @@
package org.scribe.builder.api;
import org.scribe.extractors.*;
import org.scribe.model.*;
import org.scribe.utils.*;
public class LiveApi extends DefaultApi20
{
private static final String AUTHORIZE_URL = "https://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();
}
}
@@ -1,28 +0,0 @@
package org.scribe.builder.api;
import org.scribe.model.Token;
public class LoveFilmApi extends DefaultApi10a
{
private static final String REQUEST_TOKEN_URL = "http://openapi.lovefilm.com/oauth/request_token";
private static final String ACCESS_TOKEN_URL = "http://openapi.lovefilm.com/oauth/access_token";
private static final String AUTHORIZE_URL = "https://www.lovefilm.com/activate?oauth_token=%s";
@Override
public String getRequestTokenEndpoint()
{
return REQUEST_TOKEN_URL;
}
@Override
public String getAccessTokenEndpoint()
{
return ACCESS_TOKEN_URL;
}
@Override
public String getAuthorizationUrl(Token requestToken)
{
return String.format(AUTHORIZE_URL, requestToken.getToken());
}
}
@@ -1,30 +0,0 @@
package org.scribe.builder.api;
import org.scribe.model.Token;
/**
* OAuth access to the Meetup.com API.
* For more information visit http://www.meetup.com/api
*/
public class MeetupApi extends DefaultApi10a
{
private static final String AUTHORIZE_URL = "http://www.meetup.com/authenticate?oauth_token=%s";
@Override
public String getRequestTokenEndpoint()
{
return "http://api.meetup.com/oauth/request/";
}
@Override
public String getAccessTokenEndpoint()
{
return "http://api.meetup.com/oauth/access/";
}
@Override
public String getAuthorizationUrl(Token requestToken)
{
return String.format(AUTHORIZE_URL, requestToken.getToken());
}
}
@@ -1,29 +0,0 @@
package org.scribe.builder.api;
import org.scribe.model.Token;
public class MisoApi extends DefaultApi10a
{
private static final String AUTHORIZE_URL = "http://gomiso.com/oauth/authorize?oauth_token=%s";
private static final String REQUEST_TOKEN_RESOURCE = "http://gomiso.com/oauth/request_token";
private static final String ACCESS_TOKEN_RESOURCE = "http://gomiso.com/oauth/access_token";
@Override
public String getAccessTokenEndpoint()
{
return ACCESS_TOKEN_RESOURCE;
}
@Override
public String getRequestTokenEndpoint()
{
return REQUEST_TOKEN_RESOURCE;
}
@Override
public String getAuthorizationUrl(Token requestToken)
{
return String.format(AUTHORIZE_URL, requestToken.getToken());
}
}
@@ -1,28 +0,0 @@
package org.scribe.builder.api;
import org.scribe.model.Token;
public class NetProspexApi extends DefaultApi10a
{
private static final String REQUEST_TOKEN_URL = "https://api.netprospex.com/1.0/oauth/request-token";
private static final String ACCESS_TOKEN_URL = "https://api.netprospex.com/1.0/oauth/access-token";
private static final String AUTHORIZE_URL = "https://api.netprospex.com/1.0/oauth/authorize?oauth_token=%s";
@Override
public String getRequestTokenEndpoint()
{
return REQUEST_TOKEN_URL;
}
@Override
public String getAccessTokenEndpoint()
{
return ACCESS_TOKEN_URL;
}
@Override
public String getAuthorizationUrl(Token requestToken)
{
return String.format(AUTHORIZE_URL, requestToken.getToken());
}
}
@@ -1,47 +0,0 @@
package org.scribe.builder.api;
import org.scribe.model.*;
public class NeteaseWeibooApi extends DefaultApi10a
{
private static final String REQUEST_TOKEN_URL = "http://api.t.163.com/oauth/request_token";
private static final String ACCESS_TOKEN_URL = "http://api.t.163.com/oauth/access_token";
private static final String AUTHORIZE_URL = "http://api.t.163.com/oauth/authorize?oauth_token=%s";
private static final String AUTHENTICATE_URL = "http://api.t.163.com/oauth/authenticate?oauth_token=%s";
@Override
public String getRequestTokenEndpoint()
{
return REQUEST_TOKEN_URL;
}
@Override
public String getAccessTokenEndpoint()
{
return ACCESS_TOKEN_URL;
}
@Override
/**
* this method will ignore your callback
* if you're creating a desktop client please choose this url
* else your can call getAuthenticateUrl
*
* via http://open.t.163.com/wiki/index.php?title=%E8%AF%B7%E6%B1%82%E7%94%A8%E6%88%B7%E6%8E%88%E6%9D%83Token(oauth/authorize)
*/
public String getAuthorizationUrl(Token requestToken)
{
return String.format(AUTHORIZE_URL, requestToken.getToken());
}
/**
* this method is for web client with callback url
* if you're creating a desktop client please call getAuthorizationUrl
*
* via http://open.t.163.com/wiki/index.php?title=%E8%AF%B7%E6%B1%82%E7%94%A8%E6%88%B7%E6%8E%88%E6%9D%83Token(oauth/authenticate)
*/
public String getAuthenticateUrl(Token requestToken)
{
return String.format(AUTHENTICATE_URL, requestToken.getToken());
}
}
@@ -1,39 +0,0 @@
package org.scribe.builder.api;
import org.scribe.model.Token;
public class PlurkApi extends DefaultApi10a
{
private static final String REQUEST_TOKEN_URL = "http://www.plurk.com/OAuth/request_token";
private static final String AUTHORIZATION_URL = "http://www.plurk.com/OAuth/authorize?oauth_token=%s";
private static final String ACCESS_TOKEN_URL = "http://www.plurk.com/OAuth/access_token";
@Override
public String getRequestTokenEndpoint()
{
return REQUEST_TOKEN_URL;
}
@Override
public String getAuthorizationUrl(Token requestToken)
{
return String.format(AUTHORIZATION_URL, requestToken.getToken());
}
@Override
public String getAccessTokenEndpoint()
{
return ACCESS_TOKEN_URL;
}
public 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());
}
}
}
@@ -1,26 +0,0 @@
package org.scribe.builder.api;
import org.scribe.model.*;
public class Px500Api extends DefaultApi10a
{
private static final String AUTHORIZATION_URL = "https://api.500px.com/v1/oauth/authorize?oauth_token=%s";
@Override
public String getAccessTokenEndpoint()
{
return "https://api.500px.com/v1/oauth/access_token";
}
@Override
public String getRequestTokenEndpoint()
{
return "https://api.500px.com/v1/oauth/request_token";
}
@Override
public String getAuthorizationUrl(Token requestToken)
{
return String.format(AUTHORIZATION_URL, requestToken.getToken());
}
}
@@ -1,28 +0,0 @@
package org.scribe.builder.api;
import org.scribe.model.*;
public class QWeiboApi extends DefaultApi10a
{
private static final String REQUEST_TOKEN_URL = "https://open.t.qq.com/cgi-bin/request_token";
private static final String ACCESS_TOKEN_URL = "https://open.t.qq.com/cgi-bin/access_token";
private static final String AUTHORIZE_URL = "https://open.t.qq.com/cgi-bin/authorize?oauth_token=%s";
@Override
public String getRequestTokenEndpoint()
{
return REQUEST_TOKEN_URL;
}
@Override
public String getAccessTokenEndpoint()
{
return ACCESS_TOKEN_URL;
}
@Override
public String getAuthorizationUrl(Token requestToken)
{
return String.format(AUTHORIZE_URL, requestToken.getToken());
}
}
@@ -1,40 +0,0 @@
package org.scribe.builder.api;
import org.scribe.extractors.*;
import org.scribe.model.*;
import org.scribe.utils.*;
/**
* Renren(http://www.renren.com/) OAuth 2.0 based api.
*/
public class RenrenApi extends DefaultApi20
{
private static final String AUTHORIZE_URL = "https://graph.renren.com/oauth/authorize?client_id=%s&redirect_uri=%s&response_type=code";
private static final String SCOPED_AUTHORIZE_URL = AUTHORIZE_URL + "&scope=%s";
@Override
public AccessTokenExtractor getAccessTokenExtractor()
{
return new JsonTokenExtractor();
}
@Override
public String getAccessTokenEndpoint()
{
return "https://graph.renren.com/oauth/token?grant_type=authorization_code";
}
@Override
public String getAuthorizationUrl(OAuthConfig config)
{
// Append scope if present
if (config.hasScope())
{
return String.format(SCOPED_AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()), OAuthEncoder.encode(config.getScope()));
}
else
{
return String.format(AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()));
}
}
}
@@ -1,40 +0,0 @@
package org.scribe.builder.api;
import org.scribe.model.*;
public class SapoApi extends DefaultApi10a
{
private static final String AUTHORIZE_URL = "https://id.sapo.pt/oauth/authorize?oauth_token=%s";
private static final String ACCESS_URL = "https://id.sapo.pt/oauth/access_token";
private static final String REQUEST_URL = "https://id.sapo.pt/oauth/request_token";
@Override
public String getAccessTokenEndpoint()
{
return ACCESS_URL;
}
@Override
public String getRequestTokenEndpoint()
{
return REQUEST_URL;
}
@Override
public String getAuthorizationUrl(Token requestToken)
{
return String.format(AUTHORIZE_URL, requestToken.getToken());
}
@Override
public Verb getRequestTokenVerb()
{
return Verb.GET;
}
@Override
public Verb getAccessTokenVerb()
{
return Verb.GET;
}
}
@@ -1,29 +0,0 @@
package org.scribe.builder.api;
import org.scribe.model.Token;
/**
* @author: Pablo Fernandez
*/
public class SimpleGeoApi extends DefaultApi10a
{
private static final String ENDPOINT = "these are not used since SimpleGeo uses 2 legged OAuth";
@Override
public String getRequestTokenEndpoint()
{
return ENDPOINT;
}
@Override
public String getAccessTokenEndpoint()
{
return ENDPOINT;
}
@Override
public String getAuthorizationUrl(Token requestToken)
{
return ENDPOINT;
}
}
@@ -1,28 +0,0 @@
package org.scribe.builder.api;
import org.scribe.model.*;
public class SinaWeiboApi extends DefaultApi10a
{
private static final String REQUEST_TOKEN_URL = "http://api.t.sina.com.cn/oauth/request_token";
private static final String ACCESS_TOKEN_URL = "http://api.t.sina.com.cn/oauth/access_token";
private static final String AUTHORIZE_URL = "http://api.t.sina.com.cn/oauth/authorize?oauth_token=%s";
@Override
public String getRequestTokenEndpoint()
{
return REQUEST_TOKEN_URL;
}
@Override
public String getAccessTokenEndpoint()
{
return ACCESS_TOKEN_URL;
}
@Override
public String getAuthorizationUrl(Token requestToken)
{
return String.format(AUTHORIZE_URL, requestToken.getToken());
}
}
@@ -1,46 +0,0 @@
package org.scribe.builder.api;
import org.scribe.extractors.*;
import org.scribe.model.*;
import org.scribe.utils.*;
/**
* SinaWeibo OAuth 2.0 api.
*/
public class SinaWeiboApi20 extends DefaultApi20
{
private static final String AUTHORIZE_URL = "https://api.weibo.com/oauth2/authorize?client_id=%s&redirect_uri=%s&response_type=code";
private static final String SCOPED_AUTHORIZE_URL = AUTHORIZE_URL + "&scope=%s";
@Override
public Verb getAccessTokenVerb()
{
return Verb.POST;
}
@Override
public AccessTokenExtractor getAccessTokenExtractor()
{
return new JsonTokenExtractor();
}
@Override
public String getAccessTokenEndpoint()
{
return "https://api.weibo.com/oauth2/access_token?grant_type=authorization_code";
}
@Override
public String getAuthorizationUrl(OAuthConfig config)
{
// Append scope if present
if (config.hasScope())
{
return String.format(SCOPED_AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()), OAuthEncoder.encode(config.getScope()));
}
else
{
return String.format(AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()));
}
}
}
@@ -1,35 +0,0 @@
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());
}
}
@@ -1,28 +0,0 @@
package org.scribe.builder.api;
import org.scribe.model.*;
public class SohuWeiboApi extends DefaultApi10a
{
private static final String REQUEST_TOKEN_URL = "http://api.t.sohu.com/oauth/request_token";
private static final String ACCESS_TOKEN_URL = "http://api.t.sohu.com/oauth/access_token";
private static final String AUTHORIZE_URL = "http://api.t.sohu.com/oauth/authorize?oauth_token=%s";
@Override
public String getRequestTokenEndpoint()
{
return REQUEST_TOKEN_URL;
}
@Override
public String getAccessTokenEndpoint()
{
return ACCESS_TOKEN_URL;
}
@Override
public String getAuthorizationUrl(Token requestToken)
{
return String.format(AUTHORIZE_URL, requestToken.getToken());
}
}
@@ -1,28 +0,0 @@
package org.scribe.builder.api;
import org.scribe.model.Token;
public class TumblrApi extends DefaultApi10a
{
private static final String AUTHORIZE_URL = "https://www.tumblr.com/oauth/authorize?oauth_token=%s";
private static final String REQUEST_TOKEN_RESOURCE = "http://www.tumblr.com/oauth/request_token";
private static final String ACCESS_TOKEN_RESOURCE = "http://www.tumblr.com/oauth/access_token";
@Override
public String getAccessTokenEndpoint()
{
return ACCESS_TOKEN_RESOURCE;
}
@Override
public String getRequestTokenEndpoint()
{
return REQUEST_TOKEN_RESOURCE;
}
@Override
public String getAuthorizationUrl(Token requestToken)
{
return String.format(AUTHORIZE_URL, requestToken.getToken());
}
}
@@ -1,66 +1,16 @@
package org.scribe.builder.api; package org.scribe.builder.api;
import org.scribe.model.Token;
public class TwitterApi extends DefaultApi10a 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 @Override
public String getAccessTokenEndpoint() public String getAccessTokenEndpoint()
{ {
return "http://" + ACCESS_TOKEN_RESOURCE; return "http://twitter.com/oauth/access_token";
} }
@Override @Override
public String getRequestTokenEndpoint() public String getRequestTokenEndpoint()
{ {
return "http://" + REQUEST_TOKEN_RESOURCE; return "http://twitter.com/oauth/request_token";
} }
@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,26 +0,0 @@
package org.scribe.builder.api;
import org.scribe.model.Token;
public class VimeoApi extends DefaultApi10a
{
private static final String AUTHORIZATION_URL = "http://vimeo.com/oauth/authorize?oauth_token=%s";
@Override
public String getAccessTokenEndpoint()
{
return "http://vimeo.com/oauth/access_token";
}
@Override
public String getRequestTokenEndpoint()
{
return "http://vimeo.com/oauth/request_token";
}
@Override
public String getAuthorizationUrl(Token requestToken)
{
return String.format(AUTHORIZATION_URL, requestToken.getToken());
}
}
@@ -1,41 +0,0 @@
package org.scribe.builder.api;
import org.scribe.extractors.*;
import org.scribe.utils.*;
import org.scribe.model.*;
/**
* @author Boris G. Tsirkin <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,11 +1,7 @@
package org.scribe.builder.api; package org.scribe.builder.api;
import org.scribe.model.Token;
public class YahooApi extends DefaultApi10a public class YahooApi extends DefaultApi10a
{ {
private static final String AUTHORIZE_URL = "https://api.login.yahoo.com/oauth/v2/request_auth?oauth_token=%s";
@Override @Override
public String getAccessTokenEndpoint() public String getAccessTokenEndpoint()
{ {
@@ -17,10 +13,4 @@ public class YahooApi extends DefaultApi10a
{ {
return "https://api.login.yahoo.com/oauth/v2/get_request_token"; 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,33 +0,0 @@
package org.scribe.builder.api;
import org.scribe.model.*;
import org.scribe.services.*;
public class YammerApi extends DefaultApi10a
{
private static final String AUTHORIZATION_URL = "https://www.yammer.com/oauth/authorize?oauth_token=%s";
@Override
public String getRequestTokenEndpoint()
{
return "https://www.yammer.com/oauth/request_token";
}
@Override
public String getAccessTokenEndpoint()
{
return "https://www.yammer.com/oauth/access_token";
}
@Override
public String getAuthorizationUrl(Token requestToken)
{
return String.format(AUTHORIZATION_URL, requestToken.getToken());
}
@Override
public SignatureService getSignatureService()
{
return new PlaintextSignatureService();
}
}
@@ -1,14 +0,0 @@
package org.scribe.exceptions;
/**
* @author: Pablo Fernandez
*/
public class OAuthConnectionException extends OAuthException
{
private static final String MSG = "There was a problem while creating a connection to the remote service.";
public OAuthConnectionException(Exception e)
{
super(MSG, e);
}
}
@@ -1,33 +1,18 @@
package org.scribe.exceptions; package org.scribe.exceptions;
/**
* Default scribe exception.
* Represents a problem in the OAuth signing process
*
* @author Pablo Fernandez
*/
public class OAuthException extends RuntimeException public class OAuthException extends RuntimeException
{ {
/**
* Default constructor
* @param message message explaining what went wrong
* @param e original exception
*/
public OAuthException(String message, Exception e) public OAuthException(String message, Exception e)
{ {
super(message, e); super(message, e);
} }
/**
* No-exception constructor. Used when there is no original exception
*
* @param message message explaining what went wrong
*/
public OAuthException(String message) public OAuthException(String message)
{ {
super(message, null); super(message, null);
} }
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
} }
@@ -2,11 +2,6 @@ package org.scribe.exceptions;
import org.scribe.model.*; import org.scribe.model.*;
/**
* Specialized exception that represents a missing OAuth parameter.
*
* @author Pablo Fernandez
*/
public class OAuthParametersMissingException extends OAuthException public class OAuthParametersMissingException extends OAuthException
{ {
@@ -14,11 +9,6 @@ public class OAuthParametersMissingException extends OAuthException
private static final String MSG = "Could not find oauth parameters in request: %s. " private static final String MSG = "Could not find oauth parameters in request: %s. "
+ "OAuth parameters must be specified with the addOAuthParameter() method"; + "OAuth parameters must be specified with the addOAuthParameter() method";
/**
* Default constructor.
*
* @param request OAuthRequest that caused the error
*/
public OAuthParametersMissingException(OAuthRequest request) public OAuthParametersMissingException(OAuthRequest request)
{ {
super(String.format(MSG, request)); super(String.format(MSG, request));
@@ -1,24 +1,12 @@
package org.scribe.exceptions; package org.scribe.exceptions;
/**
* Specialized exception that represents a problem in the signature
*
* @author Pablo Fernandez
*/
public class OAuthSignatureException extends OAuthException public class OAuthSignatureException extends OAuthException
{ {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private static final String MSG = "Error while signing string: %s";
/**
* Default constructor
*
* @param stringToSign plain string that gets signed (HMAC-SHA, etc)
* @param e original exception
*/
public OAuthSignatureException(String stringToSign, Exception e) public OAuthSignatureException(String stringToSign, Exception e)
{ {
super(String.format(MSG, stringToSign), e); super("Error while signing string: " + stringToSign, e);
} }
} }
@@ -0,0 +1,15 @@
package org.scribe.extensions.linkedin;
import org.scribe.extractors.*;
import org.scribe.model.*;
public class LinkedInBaseStringExtractorImpl extends BaseStringExtractorImpl
{
@Override
public String extract(OAuthRequest request)
{
String baseString = super.extract(request);
return baseString.replace("%7E", "~");
}
}
@@ -2,18 +2,7 @@ package org.scribe.extractors;
import org.scribe.model.*; import org.scribe.model.*;
/**
* Simple command object that extracts a {@link Token} from a String
*
* @author Pablo Fernandez
*/
public interface AccessTokenExtractor public interface AccessTokenExtractor
{ {
/**
* Extracts the access token from the contents of an Http Response
*
* @param response the contents of the response
* @return OAuth access token
*/
public Token extract(String response); public Token extract(String response);
} }
@@ -2,20 +2,7 @@ package org.scribe.extractors;
import org.scribe.model.*; import org.scribe.model.*;
/**
* Simple command object that extracts a base string from a {@link OAuthRequest}
*
* @author Pablo Fernandez
*/
public interface BaseStringExtractor public interface BaseStringExtractor
{ {
/**
* Extracts an url-encoded base string from the {@link OAuthRequest}.
*
* See <a href="http://oauth.net/core/1.0/#anchor14">the oauth spec</a> for more info on this.
*
* @param request the OAuthRequest
* @return the url-encoded base string
*/
String extract(OAuthRequest request); String extract(OAuthRequest request);
} }
@@ -1,39 +1,33 @@
package org.scribe.extractors; package org.scribe.extractors;
import java.util.*;
import org.scribe.exceptions.*; import org.scribe.exceptions.*;
import org.scribe.model.*; import org.scribe.model.*;
import org.scribe.utils.*; import org.scribe.utils.*;
/**
* Default implementation of {@link BaseStringExtractor}. Conforms to OAuth 1.0a
*
* @author Pablo Fernandez
*
*/
public class BaseStringExtractorImpl implements BaseStringExtractor public class BaseStringExtractorImpl implements BaseStringExtractor
{ {
private static final String AMPERSAND_SEPARATED_STRING = "%s&%s&%s"; private static final String AMPERSAND_SEPARATED_STRING = "%s&%s&%s";
/**
* {@inheritDoc}
*/
public String extract(OAuthRequest request) public String extract(OAuthRequest request)
{ {
checkPreconditions(request); checkPreconditions(request);
String verb = OAuthEncoder.encode(request.getVerb().name()); String verb = URLUtils.percentEncode(request.getVerb().name());
String url = OAuthEncoder.encode(request.getSanitizedUrl()); String url = URLUtils.percentEncode(request.getSanitizedUrl());
String params = getSortedAndEncodedParams(request); String params = getSortedAndEncodedParams(request);
return String.format(AMPERSAND_SEPARATED_STRING, verb, url, params); return String.format(AMPERSAND_SEPARATED_STRING, verb, url, params);
} }
private String getSortedAndEncodedParams(OAuthRequest request) private String getSortedAndEncodedParams(OAuthRequest request)
{ {
ParameterList params = new ParameterList(); Map<String, List<String>> params = new HashMap<String, List<String>>();
params.addAll(request.getQueryStringParams()); params.putAll(request.getQueryStringParams());
params.addAll(request.getBodyParams()); params.putAll(request.getBodyParams());
params.addAll(new ParameterList(request.getOauthParameters())); params.putAll(MapUtils.toListMap(request.getOauthParameters()));
return params.sort().asOauthBaseString(); params = MapUtils.sort(params);
return URLUtils.percentEncode(URLUtils.formURLEncodeMap(params));
} }
private void checkPreconditions(OAuthRequest request) private void checkPreconditions(OAuthRequest request)
@@ -2,18 +2,7 @@ package org.scribe.extractors;
import org.scribe.model.*; import org.scribe.model.*;
/**
* Simple command object that generates an OAuth Authorization header to include in the request.
*
* @author Pablo Fernandez
*/
public interface HeaderExtractor public interface HeaderExtractor
{ {
/**
* Generates an OAuth 'Authorization' Http header to include in requests as the signature.
*
* @param request the OAuthRequest to inspect and generate the header
* @return the Http header value
*/
String extract(OAuthRequest request); String extract(OAuthRequest request);
} }
@@ -6,35 +6,22 @@ import org.scribe.exceptions.*;
import org.scribe.model.*; import org.scribe.model.*;
import org.scribe.utils.*; import org.scribe.utils.*;
/**
* Default implementation of {@link HeaderExtractor}. Conforms to OAuth 1.0a
*
* @author Pablo Fernandez
*
*/
public class HeaderExtractorImpl implements HeaderExtractor public class HeaderExtractorImpl implements HeaderExtractor
{ {
private static final String PARAM_SEPARATOR = ", ";
private static final String PREAMBLE = "OAuth "; private static final String PREAMBLE = "OAuth ";
/**
* {@inheritDoc}
*/
public String extract(OAuthRequest request) public String extract(OAuthRequest request)
{ {
checkPreconditions(request); checkPreconditions(request);
Map<String, String> parameters = request.getOauthParameters(); Map<String, String> parameters = request.getOauthParameters();
StringBuffer header = new StringBuffer(parameters.size() * 20); StringBuffer header = new StringBuffer();
header.append(PREAMBLE); header.append(PREAMBLE);
for (String key : parameters.keySet()) for (String key : parameters.keySet())
{ {
if(header.length() > PREAMBLE.length()) addToHeader(header, key, parameters.get(key));
{
header.append(PARAM_SEPARATOR);
}
header.append(String.format("%s=\"%s\"", key, OAuthEncoder.encode(parameters.get(key))));
} }
return header.toString(); return removeTrail(header);
} }
private void checkPreconditions(OAuthRequest request) private void checkPreconditions(OAuthRequest request)
@@ -47,4 +34,13 @@ public class HeaderExtractorImpl implements HeaderExtractor
} }
} }
private void addToHeader(StringBuffer header, String name, String value)
{
header.append(String.format("%s=\"%s\", ", name, URLUtils.percentEncode(value)));
}
private String removeTrail(StringBuffer header)
{
return header.toString().substring(0, header.length() - 2);
}
} }
@@ -1,28 +0,0 @@
package org.scribe.extractors;
import java.util.regex.*;
import org.scribe.exceptions.*;
import org.scribe.model.*;
import org.scribe.utils.*;
public class JsonTokenExtractor implements AccessTokenExtractor
{
private Pattern accessTokenPattern = Pattern.compile("\"access_token\":\\s*\"(\\S*?)\"");
@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);
}
}
}
@@ -2,18 +2,8 @@ package org.scribe.extractors;
import org.scribe.model.*; import org.scribe.model.*;
/**
* Simple command object that extracts a {@link Token} from a String
*
* @author Pablo Fernandez
*/
public interface RequestTokenExtractor public interface RequestTokenExtractor
{ {
/**
* Extracts the request token from the contents of an Http Response
*
* @param response the contents of the response
* @return OAuth access token
*/
public Token extract(String response); public Token extract(String response);
} }
@@ -1,36 +0,0 @@
package org.scribe.extractors;
import java.util.regex.*;
import org.scribe.exceptions.*;
import org.scribe.model.*;
import org.scribe.utils.*;
/**
* Default implementation of {@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);
}
}
}
@@ -6,39 +6,24 @@ import org.scribe.exceptions.*;
import org.scribe.model.*; import org.scribe.model.*;
import org.scribe.utils.*; import org.scribe.utils.*;
/**
* Default implementation of {@RequestTokenExtractor} and {@AccessTokenExtractor}. Conforms to OAuth 1.0a
*
* The process for extracting access and request tokens is similar so this class can do both things.
*
* @author Pablo Fernandez
*/
public class TokenExtractorImpl implements RequestTokenExtractor, AccessTokenExtractor public class TokenExtractorImpl implements RequestTokenExtractor, AccessTokenExtractor
{ {
private static final Pattern TOKEN_REGEX = Pattern.compile("oauth_token=([^&]+)");
private static final Pattern SECRET_REGEX = Pattern.compile("oauth_token_secret=([^&]*)");
/** private static final String TOKEN_REGEX = "oauth_token=(\\S*)&oauth_token_secret=(\\S*?)(&(.*))?";
* {@inheritDoc}
*/
public Token extract(String response) public Token extract(String response)
{ {
Preconditions.checkEmptyString(response, "Response body is incorrect. Can't extract a token from an empty string"); Preconditions.checkEmptyString(response, "Cant extract a token from null object or an empty string.");
String token = extract(response, TOKEN_REGEX);
String secret = extract(response, SECRET_REGEX);
return new Token(token, secret, response);
}
private String extract(String response, Pattern p) Matcher matcher = Pattern.compile(TOKEN_REGEX).matcher(response);
{ if (matcher.matches())
Matcher matcher = p.matcher(response);
if (matcher.find() && matcher.groupCount() >= 1)
{ {
return OAuthEncoder.decode(matcher.group(1)); String token = URLUtils.percentDecode(matcher.group(1));
} String secret = URLUtils.percentDecode(matcher.group(2));
else return new Token(token, secret);
} else
{ {
throw new OAuthException("Response body is incorrect. Can't extract token and secret from this: '" + response + "'", null); throw new OAuthException("Could not find request token or secret in response: " + response, null);
} }
} }
} }
+53 -49
View File
@@ -1,79 +1,83 @@
package org.scribe.model; package org.scribe.model;
import java.io.*;
/**
* Parameter object that groups OAuth config values
*
* @author Pablo Fernandez
*/
public class OAuthConfig public class OAuthConfig
{ {
private final String apiKey; private String apiKey;
private final String apiSecret; private String apiSecret;
private final String callback; private String callback;
private final SignatureType signatureType; private String requestTokenEndpoint;
private final String scope; private String accessTokenEndpoint;
private final OutputStream debugStream; private Verb requestTokenVerb;
private Verb accessTokenVerb;
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() public String getApiKey()
{ {
return apiKey; return apiKey;
} }
public void setApiKey(String apiKey)
{
this.apiKey = apiKey;
}
public String getApiSecret() public String getApiSecret()
{ {
return apiSecret; return apiSecret;
} }
public void setApiSecret(String apiSecret)
{
this.apiSecret = apiSecret;
}
public String getCallback() public String getCallback()
{ {
return callback; return callback != null ? callback : OAuthConstants.OUT_OF_BAND;
} }
public SignatureType getSignatureType() public void setCallback(String callback)
{ {
return signatureType; this.callback = callback;
} }
public String getScope() public String getRequestTokenEndpoint()
{ {
return scope; return requestTokenEndpoint;
} }
public boolean hasScope() public void setRequestTokenEndpoint(String requestTokenEndpoint)
{ {
return scope != null; this.requestTokenEndpoint = requestTokenEndpoint;
} }
public void log(String message) public String getAccessTokenEndpoint()
{ {
if (debugStream != null) return accessTokenEndpoint;
{
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;
}
}
@@ -19,6 +19,7 @@ package org.scribe.model;
* This class contains OAuth constants, used project-wide * This class contains OAuth constants, used project-wide
* *
* @author Pablo Fernandez * @author Pablo Fernandez
*
*/ */
public class OAuthConstants public class OAuthConstants
{ {
@@ -37,13 +38,4 @@ public class OAuthConstants
public static final String VERIFIER = "oauth_verifier"; public static final String VERIFIER = "oauth_verifier";
public static final String HEADER = "Authorization"; public static final String HEADER = "Authorization";
public static final Token EMPTY_TOKEN = new Token("", ""); 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,6 @@
package org.scribe.model;
public class OAuthParams
{
}
@@ -2,38 +2,18 @@ package org.scribe.model;
import java.util.*; import java.util.*;
/**
* The representation of an OAuth HttpRequest.
*
* Adds OAuth-related functionality to the {@link Request}
*
* @author Pablo Fernandez
*/
public class OAuthRequest extends Request public class OAuthRequest extends Request
{ {
private static final String OAUTH_PREFIX = "oauth_"; private static final String OAUTH_PREFIX = "oauth_";
private Map<String, String> oauthParameters; private Map<String, String> oauthParameters;
/**
* Default constructor.
*
* @param verb Http verb/method
* @param url resource URL
*/
public OAuthRequest(Verb verb, String url) public OAuthRequest(Verb verb, String url)
{ {
super(verb, url); super(verb, url);
this.oauthParameters = new HashMap<String, String>(); this.oauthParameters = new HashMap<String, String>();
} }
/**
* Adds an OAuth parameter.
*
* @param key name of the parameter
* @param value value of the parameter
*
* @throws IllegalArgumentException if the parameter is not an OAuth parameter
*/
public void addOAuthParameter(String key, String value) public void addOAuthParameter(String key, String value)
{ {
oauthParameters.put(checkKey(key), value); oauthParameters.put(checkKey(key), value);
@@ -41,21 +21,15 @@ public class OAuthRequest extends Request
private String checkKey(String key) private String checkKey(String key)
{ {
if (key.startsWith(OAUTH_PREFIX) || key.equals(OAuthConstants.SCOPE)) if (!key.startsWith(OAUTH_PREFIX))
{
throw new IllegalArgumentException(String.format("OAuth parameters must start with '%s'", OAUTH_PREFIX));
} else
{ {
return key; return key;
}
else
{
throw new IllegalArgumentException(String.format("OAuth parameters must either be '%s' or start with '%s'", OAuthConstants.SCOPE, OAUTH_PREFIX));
} }
} }
/**
* Returns the {@link Map} containing the key-value pair of parameters.
*
* @return parameters as map
*/
public Map<String, String> getOauthParameters() public Map<String, String> getOauthParameters()
{ {
return oauthParameters; return oauthParameters;
@@ -1,50 +0,0 @@
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);
}
}
@@ -1,114 +0,0 @@
package org.scribe.model;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import org.scribe.utils.OAuthEncoder;
import org.scribe.utils.Preconditions;
/**
* @author: Pablo Fernandez
*/
public class ParameterList
{
private static final char QUERY_STRING_SEPARATOR = '?';
private static final String PARAM_SEPARATOR = "&";
private static final String PAIR_SEPARATOR = "=";
private static final String EMPTY_STRING = "";
private final List<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;
}
}
+64 -169
View File
@@ -2,11 +2,10 @@ package org.scribe.model;
import java.io.*; import java.io.*;
import java.net.*; import java.net.*;
import java.nio.charset.*;
import java.util.*; import java.util.*;
import java.util.concurrent.TimeUnit;
import org.scribe.exceptions.*; import org.scribe.exceptions.*;
import org.scribe.utils.*;
/** /**
* Represents an HTTP Request object * Represents an HTTP Request object
@@ -15,22 +14,16 @@ import org.scribe.exceptions.*;
*/ */
class Request class Request
{ {
private static final String CONTENT_LENGTH = "Content-Length"; 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 String url;
private Verb verb; private Verb verb;
private ParameterList querystringParams; private Map<String, List<String>> bodyParams;
private ParameterList bodyParams;
private Map<String, String> headers; private Map<String, String> headers;
private String payload = null; private String payload = null;
private Integer timeout = null;
private HttpURLConnection connection; 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 * Creates a new Http Request
@@ -42,9 +35,16 @@ class Request
{ {
this.verb = verb; this.verb = verb;
this.url = url; this.url = url;
this.querystringParams = new ParameterList(); this.bodyParams = new HashMap<String, List<String>>();
this.bodyParams = new ParameterList();
this.headers = new HashMap<String, String>(); this.headers = new HashMap<String, String>();
try
{
connection = (HttpURLConnection) new URL(url).openConnection();
if(timeout != null) connection.setConnectTimeout(timeout);
} catch (IOException ioe)
{
throw new OAuthException("Could not open connection to: " + url, ioe);
}
} }
/** /**
@@ -58,50 +58,20 @@ class Request
{ {
try try
{ {
createConnection();
return doSend(); return doSend();
} } catch (IOException ioe)
catch (Exception e)
{ {
throw new OAuthConnectionException(e); throw new OAuthException("Problems while creating connection", ioe);
} }
} }
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 Response doSend() throws IOException
{ {
connection.setRequestMethod(this.verb.name()); connection.setRequestMethod(this.verb.name());
if (connectTimeout != null)
{
connection.setConnectTimeout(connectTimeout.intValue());
}
if (readTimeout != null)
{
connection.setReadTimeout(readTimeout.intValue());
}
addHeaders(connection); addHeaders(connection);
if (verb.equals(Verb.PUT) || verb.equals(Verb.POST)) if (verb.equals(Verb.PUT) || verb.equals(Verb.POST))
{ {
addBody(connection, getByteBodyContents()); addBody(connection, getBodyContents());
} }
return new Response(connection); return new Response(connection);
} }
@@ -112,24 +82,18 @@ class Request
conn.setRequestProperty(key, headers.get(key)); conn.setRequestProperty(key, headers.get(key));
} }
void addBody(HttpURLConnection conn, byte[] content) throws IOException void addBody(HttpURLConnection conn, String content) throws IOException
{ {
conn.setRequestProperty(CONTENT_LENGTH, String.valueOf(content.length)); conn.setRequestProperty(CONTENT_LENGTH, String.valueOf(content.getBytes().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.setDoOutput(true);
conn.getOutputStream().write(content); conn.getOutputStream().write(content.getBytes());
} }
/** /**
* Add an HTTP Header to the Request * Add an HTTP Header to the Request
* *
* @param key the header name * @param name
* @param value the header value * @param value
*/ */
public void addHeader(String key, String value) public void addHeader(String key, String value)
{ {
@@ -139,23 +103,19 @@ class Request
/** /**
* Add a body Parameter (for POST/ PUT Requests) * Add a body Parameter (for POST/ PUT Requests)
* *
* @param key the parameter name * @param name
* @param value the parameter value * @param value
*/ */
public void addBodyParameter(String key, String value) public void addBodyParameter(String key, String value)
{ {
this.bodyParams.add(key, value); if(bodyParams.get(key) != null)
} {
bodyParams.get(key).add(value);
/** }
* Add a QueryString parameter else
* {
* @param key the parameter name bodyParams.put(key, Arrays.asList(value));
* @param value the parameter value }
*/
public void addQuerystringParameter(String key, String value)
{
this.querystringParams.add(key, value);
} }
/** /**
@@ -166,7 +126,7 @@ class Request
* *
* Note: The contents are not part of the OAuth signature * Note: The contents are not part of the OAuth signature
* *
* @param payload the body of the request * @param payload
*/ */
public void addPayload(String payload) public void addPayload(String payload)
{ {
@@ -174,43 +134,45 @@ class Request
} }
/** /**
* Overloaded version for byte arrays * Get a {@link Map} of the query string parameters.
*
* @param payload
*/
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. * @return a map containing the query string parameters
* @throws OAuthException if the request URL is not valid.
*/ */
public ParameterList getQueryStringParams() public Map<String, List<String>> getQueryStringParams()
{ {
try try
{ {
ParameterList result = new ParameterList(); Map<String, List<String>> params = new HashMap<String, List<String>>();
String queryString = new URL(url).getQuery(); String query = new URL(url).getQuery();
result.addQuerystring(queryString); if (query != null)
result.addAll(querystringParams); {
return result; for (String param : query.split("&"))
} {
catch (MalformedURLException mue) String pair[] = param.split("=");
String key = pair[0], value = pair[1];
if(params.get(key)!= null)
{
params.get(key).add(value);
}
else
{
params.put(key, Arrays.asList(value));
}
}
}
return params;
} catch (MalformedURLException mue)
{ {
throw new OAuthException("Malformed URL", mue); throw new OAuthException("Malformed URL", mue);
} }
} }
/** /**
* Obtains a {@link ParameterList} of the body parameters. * Obtains a {@link Map} of the body parameters.
* *
* @return a {@link ParameterList}containing the body parameters. * @return a map containing the body parameters.
*/ */
public ParameterList getBodyParams() public Map<String, List<String>> getBodyParams()
{ {
return bodyParams; return bodyParams;
} }
@@ -239,32 +201,10 @@ class Request
* Returns the body of the request * Returns the body of the request
* *
* @return form encoded string * @return form encoded string
* @throws OAuthException if the charset chosen is not supported
*/ */
public String getBodyContents() public String getBodyContents()
{ {
try return (payload != null) ? payload : URLUtils.formURLEncodeMap(bodyParams);
{
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);
}
} }
/** /**
@@ -288,60 +228,15 @@ class Request
} }
/** /**
* Returns the connection charset. Defaults to {@link Charset} defaultCharset if not set * Sets the connection timeout in milliseconds for the underlying {@link HttpURLConnection}
*
* @return charset
*/
public String getCharset()
{
return charset == null ? Charset.defaultCharset().name() : charset;
}
/**
* Sets the connect timeout for the underlying {@link HttpURLConnection}
* *
* @param duration duration of the timeout * @param timeout in milliseconds
*
* @param unit unit of time (milliseconds, seconds, etc)
*/ */
public void setConnectTimeout(int duration, TimeUnit unit) public void setTimeout(int timeout)
{ {
this.connectTimeout = unit.toMillis(duration); this.timeout = timeout;
} }
/**
* Sets the read timeout for the underlying {@link HttpURLConnection}
*
* @param duration duration of the timeout
*
* @param unit unit of time (milliseconds, seconds, etc)
*/
public void setReadTimeout(int duration, TimeUnit unit)
{
this.readTimeout = unit.toMillis(duration);
}
/**
* Set the charset of the body of the request
*
* @param charsetName name of the charset of the request
*/
public void setCharset(String charsetName)
{
this.charset = charsetName;
}
/**
* Sets whether the underlying Http Connection is persistent or not.
*
* @see http://download.oracle.com/javase/1.5.0/docs/guide/net/http-keepalive.html
* @param connectionKeepAlive
*/
public void setConnectionKeepAlive(boolean connectionKeepAlive)
{
this.connectionKeepAlive = connectionKeepAlive;
}
/* /*
* We need this in order to stub the connection object for test cases * We need this in order to stub the connection object for test cases
*/ */
+14 -8
View File
@@ -4,7 +4,6 @@ import java.io.*;
import java.net.*; import java.net.*;
import java.util.*; import java.util.*;
import org.scribe.exceptions.*;
import org.scribe.utils.*; import org.scribe.utils.*;
/** /**
@@ -14,6 +13,7 @@ import org.scribe.utils.*;
*/ */
public class Response public class Response
{ {
private static final String EMPTY = ""; private static final String EMPTY = "";
private int code; private int code;
@@ -28,11 +28,11 @@ public class Response
connection.connect(); connection.connect();
code = connection.getResponseCode(); code = connection.getResponseCode();
headers = parseHeaders(connection); headers = parseHeaders(connection);
stream = isSuccessful() ? connection.getInputStream() : connection.getErrorStream(); stream = wasSuccessful() ? connection.getInputStream() : connection.getErrorStream();
} } catch (UnknownHostException e)
catch (UnknownHostException e)
{ {
throw new OAuthException("The IP address of a host could not be determined.", e); code = 404;
body = EMPTY;
} }
} }
@@ -52,7 +52,12 @@ public class Response
return headers; return headers;
} }
public boolean isSuccessful() /**
* Checks if the code is in the successful or redirect range.
*
* @return true if successful
*/
private boolean wasSuccessful()
{ {
return getCode() >= 200 && getCode() < 400; return getCode() >= 200 && getCode() < 400;
} }
@@ -101,9 +106,10 @@ public class Response
/** /**
* Obtains a single HTTP Header value, or null if undefined * Obtains a single HTTP Header value, or null if undefined
* *
* @param name the header name. * @param header
* name
* *
* @return header value or null. * @return header value or null
*/ */
public String getHeader(String name) public String getHeader(String name)
{ {
@@ -1,7 +0,0 @@
package org.scribe.model;
public enum SignatureType
{
Header,
QueryString
}
+2 -50
View File
@@ -1,36 +1,15 @@
package org.scribe.model; package org.scribe.model;
import java.io.Serializable; public class Token
/**
* Represents an OAuth token (either request or access token) and its secret
*
* @author Pablo Fernandez
*/
public class Token implements Serializable
{ {
private static final long serialVersionUID = 715000866082812683L;
private final String token; private final String token;
private final String secret; private final String secret;
private final String rawResponse;
/**
* Default constructor
*
* @param token token value
* @param secret token secret
*/
public Token(String token, String secret) public Token(String token, String secret)
{
this(token, secret, null);
}
public Token(String token, String secret, String rawResponse)
{ {
this.token = token; this.token = token;
this.secret = secret; this.secret = secret;
this.rawResponse = rawResponse;
} }
public String getToken() public String getToken()
@@ -43,36 +22,9 @@ public class Token implements Serializable
return secret; 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 @Override
public String toString() public String toString()
{ {
return String.format("Token[%s , %s]", token, secret); return String.format("Token[%s , %s]", token, secret);
} }
/**
* Returns true if the token is empty (token = "", secret = "")
*/
public boolean isEmpty()
{
return "".equals(this.token) && "".equals(this.secret);
}
/**
* Factory method that returns an empty token (token = "", secret = "").
*
* Useful for two legged OAuth.
*/
public static Token empty()
{
return new Token("","");
}
} }
@@ -1,25 +1,12 @@
package org.scribe.model; package org.scribe.model;
import org.scribe.utils.*;
/**
* Represents an OAuth verifier code.
*
* @author Pablo Fernandez
*/
public class Verifier public class Verifier
{ {
private final String value; private final String value;
/**
* Default constructor.
*
* @param value verifier value
*/
public Verifier(String value) public Verifier(String value)
{ {
Preconditions.checkNotNull(value, "Must provide a valid string as verifier");
this.value = value; this.value = value;
} }
@@ -1,149 +1,86 @@
package org.scribe.oauth; package org.scribe.oauth;
import java.util.*; import org.scribe.extractors.*;
import org.scribe.builder.api.*;
import org.scribe.model.*; import org.scribe.model.*;
import org.scribe.utils.*; import org.scribe.services.*;
/**
* OAuth 1.0a implementation of {@link OAuthService}
*
* @author Pablo Fernandez
*/
public class OAuth10aServiceImpl implements OAuthService public class OAuth10aServiceImpl implements OAuthService
{ {
private static final String VERSION = "1.0"; private static final String VERSION = "1.0";
private OAuthConfig config; private OAuthConfig config;
private DefaultApi10a api; private SignatureService signatureService;
private TimestampService timestampService;
private BaseStringExtractor baseStringExtractor;
private HeaderExtractor headerExtractor;
private RequestTokenExtractor rtExtractor;
private AccessTokenExtractor atExtractor;
/** public OAuth10aServiceImpl(SignatureService signatureService, TimestampService timestampService, BaseStringExtractor baseStringExtractor,
* Default constructor HeaderExtractor headerExtractor, RequestTokenExtractor rtExtractor, AccessTokenExtractor atExtractor, OAuthConfig config)
*
* @param api OAuth1.0a api information
* @param config OAuth 1.0a configuration param object
*/
public OAuth10aServiceImpl(DefaultApi10a api, OAuthConfig config)
{ {
this.api = api; this.signatureService = signatureService;
this.timestampService = timestampService;
this.baseStringExtractor = baseStringExtractor;
this.headerExtractor = headerExtractor;
this.rtExtractor = rtExtractor;
this.atExtractor = atExtractor;
this.config = config; this.config = config;
} }
/**
* {@inheritDoc}
*/
public Token getRequestToken() public Token getRequestToken()
{ {
config.log("obtaining request token from " + api.getRequestTokenEndpoint()); OAuthRequest request = new OAuthRequest(config.getRequestTokenVerb(), config.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); addOAuthParams(request, OAuthConstants.EMPTY_TOKEN);
appendSignature(request); addOAuthHeader(request);
config.log("sending request...");
Response response = request.send(); Response response = request.send();
String body = response.getBody(); return rtExtractor.extract(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) private void addOAuthParams(OAuthRequest request, Token token)
{ {
request.addOAuthParameter(OAuthConstants.TIMESTAMP, api.getTimestampService().getTimestampInSeconds()); request.addOAuthParameter(OAuthConstants.TIMESTAMP, timestampService.getTimestampInSeconds());
request.addOAuthParameter(OAuthConstants.NONCE, api.getTimestampService().getNonce()); request.addOAuthParameter(OAuthConstants.NONCE, timestampService.getNonce());
request.addOAuthParameter(OAuthConstants.CONSUMER_KEY, config.getApiKey()); request.addOAuthParameter(OAuthConstants.CONSUMER_KEY, config.getApiKey());
request.addOAuthParameter(OAuthConstants.SIGN_METHOD, api.getSignatureService().getSignatureMethod()); request.addOAuthParameter(OAuthConstants.SIGN_METHOD, signatureService.getSignatureMethod());
request.addOAuthParameter(OAuthConstants.VERSION, getVersion()); request.addOAuthParameter(OAuthConstants.VERSION, getVersion());
if(config.hasScope()) request.addOAuthParameter(OAuthConstants.SCOPE, config.getScope()); request.addOAuthParameter(OAuthConstants.CALLBACK, config.getCallback());
request.addOAuthParameter(OAuthConstants.SIGNATURE, getSignature(request, token)); request.addOAuthParameter(OAuthConstants.SIGNATURE, getSignature(request, token));
config.log("appended additional OAuth parameters: " + MapUtils.toString(request.getOauthParameters()));
} }
/**
* {@inheritDoc}
*/
public Token getAccessToken(Token requestToken, Verifier verifier) public Token getAccessToken(Token requestToken, Verifier verifier)
{ {
config.log("obtaining access token from " + api.getAccessTokenEndpoint()); OAuthRequest request = new OAuthRequest(config.getAccessTokenVerb(), config.getAccessTokenEndpoint());
OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint());
request.addOAuthParameter(OAuthConstants.TOKEN, requestToken.getToken()); request.addOAuthParameter(OAuthConstants.TOKEN, requestToken.getToken());
request.addOAuthParameter(OAuthConstants.VERIFIER, verifier.getValue()); request.addOAuthParameter(OAuthConstants.VERIFIER, verifier.getValue());
config.log("setting token to: " + requestToken + " and verifier to: " + verifier);
addOAuthParams(request, requestToken); addOAuthParams(request, requestToken);
appendSignature(request); addOAuthHeader(request);
Response response = request.send(); Response response = request.send();
return api.getAccessTokenExtractor().extract(response.getBody()); return atExtractor.extract(response.getBody());
} }
/**
* {@inheritDoc}
*/
public void signRequest(Token token, OAuthRequest request) public void signRequest(Token token, OAuthRequest request)
{ {
config.log("signing request: " + request.getCompleteUrl()); request.addOAuthParameter(OAuthConstants.TOKEN, token.getToken());
// Do not append the token if empty. This is for two legged OAuth calls.
if (!token.isEmpty())
{
request.addOAuthParameter(OAuthConstants.TOKEN, token.getToken());
}
config.log("setting token to: " + token);
addOAuthParams(request, token); addOAuthParams(request, token);
appendSignature(request); addOAuthHeader(request);
} }
/**
* {@inheritDoc}
*/
public String getVersion() public String getVersion()
{ {
return VERSION; return VERSION;
} }
/**
* {@inheritDoc}
*/
public String getAuthorizationUrl(Token requestToken)
{
return api.getAuthorizationUrl(requestToken);
}
private String getSignature(OAuthRequest request, Token token) private String getSignature(OAuthRequest request, Token token)
{ {
config.log("generating signature..."); String baseString = baseStringExtractor.extract(request);
String baseString = api.getBaseStringExtractor().extract(request); return signatureService.getSignature(baseString, config.getApiSecret(), token.getSecret());
String signature = api.getSignatureService().getSignature(baseString, config.getApiSecret(), token.getSecret());
config.log("base string is: " + baseString);
config.log("signature is: " + signature);
return signature;
} }
private void appendSignature(OAuthRequest request) private void addOAuthHeader(OAuthRequest request)
{ {
switch (config.getSignatureType()) String oauthHeader = headerExtractor.extract(request);
{ request.addHeader(OAuthConstants.HEADER, oauthHeader);
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;
}
} }
} }
@@ -1,72 +0,0 @@
package org.scribe.oauth;
import org.scribe.builder.api.*;
import org.scribe.model.*;
public class OAuth20ServiceImpl implements OAuthService
{
private static final String VERSION = "2.0";
private final DefaultApi20 api;
private final OAuthConfig config;
/**
* Default constructor
*
* @param api OAuth2.0 api information
* @param config OAuth 2.0 configuration param object
*/
public OAuth20ServiceImpl(DefaultApi20 api, OAuthConfig config)
{
this.api = api;
this.config = config;
}
/**
* {@inheritDoc}
*/
public Token getAccessToken(Token requestToken, Verifier verifier)
{
OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint());
request.addQuerystringParameter(OAuthConstants.CLIENT_ID, config.getApiKey());
request.addQuerystringParameter(OAuthConstants.CLIENT_SECRET, config.getApiSecret());
request.addQuerystringParameter(OAuthConstants.CODE, verifier.getValue());
request.addQuerystringParameter(OAuthConstants.REDIRECT_URI, config.getCallback());
if(config.hasScope()) request.addQuerystringParameter(OAuthConstants.SCOPE, config.getScope());
Response response = request.send();
return api.getAccessTokenExtractor().extract(response.getBody());
}
/**
* {@inheritDoc}
*/
public Token getRequestToken()
{
throw new UnsupportedOperationException("Unsupported operation, please use 'getAuthorizationUrl' and redirect your users there");
}
/**
* {@inheritDoc}
*/
public String getVersion()
{
return VERSION;
}
/**
* {@inheritDoc}
*/
public void signRequest(Token accessToken, OAuthRequest request)
{
request.addQuerystringParameter(OAuthConstants.ACCESS_TOKEN, accessToken.getToken());
}
/**
* {@inheritDoc}
*/
public String getAuthorizationUrl(Token requestToken)
{
return api.getAuthorizationUrl(config);
}
}
@@ -2,52 +2,13 @@ package org.scribe.oauth;
import org.scribe.model.*; import org.scribe.model.*;
/**
* The main Scribe object.
*
* A facade responsible for the retrieval of request and access tokens and for the signing of HTTP requests.
*
* @author Pablo Fernandez
*/
public interface OAuthService public interface OAuthService
{ {
/**
* Retrieve the request token.
*
* @return request token
*/
public Token getRequestToken(); public Token getRequestToken();
/**
* Retrieve the access token
*
* @param requestToken request token (obtained previously)
* @param verifier verifier code
* @return access token
*/
public Token getAccessToken(Token requestToken, Verifier verifier); public Token getAccessToken(Token requestToken, Verifier verifier);
/**
* Signs am OAuth request
*
* @param accessToken access token (obtained previously)
* @param request request to sign
*/
public void signRequest(Token accessToken, OAuthRequest request); public void signRequest(Token accessToken, OAuthRequest request);
/**
* Returns the OAuth version of the service.
*
* @return oauth version as string
*/
public String getVersion(); public String getVersion();
/**
* Returns the URL where you should redirect your users to authenticate
* your application.
*
* @param requestToken the request token you need to authorize
* @return the URL where you should redirect your users
*/
public String getAuthorizationUrl(Token requestToken);
} }
@@ -7,30 +7,22 @@ import org.apache.commons.codec.binary.*;
import org.scribe.exceptions.*; import org.scribe.exceptions.*;
import org.scribe.utils.*; import org.scribe.utils.*;
/**
* HMAC-SHA1 implementation of {@SignatureService}
*
* @author Pablo Fernandez
*
*/
public class HMACSha1SignatureService implements SignatureService public class HMACSha1SignatureService implements SignatureService
{ {
private static final String EMPTY_STRING = ""; private static final String EMPTY_STRING = "";
private static final String CARRIAGE_RETURN = "\r\n"; private static final String CARRIAGE_RETURN = "\r\n";
private static final String UTF8 = "UTF-8"; private static final String UTF8 = "UTF-8";
private static final String HMAC_SHA1 = "HmacSHA1"; private static final String HMAC_SHA1 = "HmacSHA1";
private static final String METHOD = "HMAC-SHA1"; private static final String METHOD = "HMAC-SHA1";
/**
* {@inheritDoc}
*/
public String getSignature(String baseString, String apiSecret, String tokenSecret) public String getSignature(String baseString, String apiSecret, String tokenSecret)
{ {
try try
{ {
Preconditions.checkEmptyString(baseString, "Base string cant be null or empty string"); Preconditions.checkEmptyString(baseString, "Base string cant be null or empty string");
Preconditions.checkEmptyString(apiSecret, "Api secret cant be null or empty string"); Preconditions.checkEmptyString(apiSecret, "Api secret cant be null or empty string");
return doSign(baseString, OAuthEncoder.encode(apiSecret) + '&' + OAuthEncoder.encode(tokenSecret)); return doSign(baseString, apiSecret + '&' + tokenSecret);
} }
catch (Exception e) catch (Exception e)
{ {
@@ -47,9 +39,6 @@ public class HMACSha1SignatureService implements SignatureService
return new String(Base64.encodeBase64(bytes)).replace(CARRIAGE_RETURN, EMPTY_STRING); return new String(Base64.encodeBase64(bytes)).replace(CARRIAGE_RETURN, EMPTY_STRING);
} }
/**
* {@inheritDoc}
*/
public String getSignatureMethod() public String getSignatureMethod()
{ {
return METHOD; return METHOD;
@@ -1,40 +0,0 @@
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;
}
}
@@ -1,47 +0,0 @@
package org.scribe.services;
import org.apache.commons.codec.binary.*;
import org.scribe.exceptions.*;
import java.security.*;
/**
* A signature service that uses the RSA-SHA1 algorithm.
*/
public class RSASha1SignatureService implements SignatureService
{
private static final String METHOD = "RSA-SHA1";
private static final String RSA_SHA1 = "SHA1withRSA";
private PrivateKey privateKey;
public RSASha1SignatureService(PrivateKey privateKey)
{
this.privateKey = privateKey;
}
/**
* {@inheritDoc}
*/
public String getSignature(String baseString, String apiSecret, String tokenSecret)
{
try
{
Signature signature = Signature.getInstance(RSA_SHA1);
signature.initSign(privateKey);
signature.update(baseString.getBytes());
return new String(Base64.encodeBase64(signature.sign(), false));
}
catch (Exception e)
{
throw new OAuthSignatureException(baseString, e);
}
}
/**
* {@inheritDoc}
*/
public String getSignatureMethod()
{
return METHOD;
}
}
@@ -1,28 +1,8 @@
package org.scribe.services; package org.scribe.services;
/**
* Signs a base string, returning the OAuth signature
*
* @author Pablo Fernandez
*
*/
public interface SignatureService public interface SignatureService
{ {
/**
* Returns the signature
*
* @param baseString url-encoded string to sign
* @param apiSecret api secret for your app
* @param tokenSecret token secret (empty string for the request token step)
*
* @return signature
*/
public String getSignature(String baseString, String apiSecret, String tokenSecret); public String getSignature(String baseString, String apiSecret, String tokenSecret);
/**
* Returns the signature method/algorithm
*
* @return
*/
public String getSignatureMethod(); public String getSignatureMethod();
} }
@@ -1,25 +1,9 @@
package org.scribe.services; package org.scribe.services;
/**
* Unix epoch timestamp generator.
*
* This class is useful for stubbing in tests.
*
* @author Pablo Fernandez
*/
public interface TimestampService public interface TimestampService
{ {
/**
* Returns the unix epoch timestamp in seconds
*
* @return timestamp
*/
public String getTimestampInSeconds(); public String getTimestampInSeconds();
/**
* Returns a nonce (unique value for each request)
*
* @return nonce
*/
public String getNonce(); public String getNonce();
} }
@@ -2,35 +2,22 @@ package org.scribe.services;
import java.util.*; import java.util.*;
/**
* Implementation of {@link TimestampService} using plain java classes.
*
* @author Pablo Fernandez
*/
public class TimestampServiceImpl implements TimestampService public class TimestampServiceImpl implements TimestampService
{ {
private Timer timer; private Timer timer;
/**
* Default constructor.
*/
public TimestampServiceImpl() public TimestampServiceImpl()
{ {
timer = new Timer(); timer = new Timer();
} }
/**
* {@inheritDoc}
*/
public String getNonce() public String getNonce()
{ {
Long ts = getTs(); Long ts = getTs();
return String.valueOf(ts + timer.getRandomInteger()); return String.valueOf(ts + timer.getRandomInteger());
} }
/**
* {@inheritDoc}
*/
public String getTimestampInSeconds() public String getTimestampInSeconds()
{ {
return String.valueOf(getTs()); return String.valueOf(getTs());
@@ -46,19 +33,14 @@ public class TimestampServiceImpl implements TimestampService
this.timer = timer; this.timer = timer;
} }
/**
* Inner class that uses {@link System} for generating the timestamps.
*
* @author Pablo Fernandez
*/
static class Timer static class Timer
{ {
Long getMilis() public Long getMilis()
{ {
return System.currentTimeMillis(); return System.currentTimeMillis();
} }
Integer getRandomInteger() public Integer getRandomInteger()
{ {
return new Random().nextInt(); return new Random().nextInt();
} }
+33 -12
View File
@@ -1,22 +1,43 @@
package org.scribe.utils; package org.scribe.utils;
import java.util.Map; import java.util.*;
/**
* @author: Pablo Fernandez
*/
public class MapUtils public class MapUtils
{ {
public static <K,V> String toString(Map<K,V> map)
{
if (map == null) return "";
if (map.isEmpty()) return "{}";
StringBuilder result = new StringBuilder(); public static final Map<String, List<String>> sort(Map<String, List<String>> map)
for(Map.Entry<K,V> entry : map.entrySet()) {
Preconditions.checkNotNull(map, "Cannot sort a null object.");
Map<String, List<String>> sorted = new LinkedHashMap<String, List<String>>();
for (String key : getSortedKeys(map))
{ {
result.append(String.format(", %s -> %s ", entry.getKey().toString(), entry.getValue().toString())); if(map.get(key).size() > 1)
{
Collections.sort(map.get(key));
}
sorted.put(key, map.get(key));
} }
return "{" + result.substring(1) + "}"; return sorted;
}
private static List<String> getSortedKeys(Map<String, List<String>> map)
{
List<String> keys = new ArrayList<String>(map.keySet());
Collections.sort(keys);
return keys;
}
@SuppressWarnings("unchecked")
public static final <T> Map<String, List<T>> toListMap(Map<String, T> map)
{
Preconditions.checkNotNull(map, "Cannot sort a null object.");
Map<String, List<T>> result = new HashMap<String, List<T>>();
for (Map.Entry<String, T> entry : map.entrySet())
{
result.put(entry.getKey(), Arrays.asList(entry.getValue()));
}
return result;
} }
} }
@@ -1,62 +0,0 @@
package org.scribe.utils;
import java.io.*;
import java.net.*;
import java.util.*;
import java.util.regex.*;
import org.scribe.exceptions.*;
/**
* @author: Pablo Fernandez
*/
public class OAuthEncoder
{
private static String CHARSET = "UTF-8";
private static final Map<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);
}
}
}
@@ -1,65 +1,27 @@
package org.scribe.utils; package org.scribe.utils;
import java.util.regex.Pattern;
import org.scribe.model.OAuthConstants; import org.scribe.model.OAuthConstants;
/**
* Utils for checking preconditions and invariants
*
* @author Pablo Fernandez
*/
public class Preconditions public class Preconditions
{ {
private static final String DEFAULT_MESSAGE = "Received an invalid parameter"; private static final String DEFAULT_MESSAGE = "Received an invalid parameter";
// scheme = alpha *( alpha | digit | "+" | "-" | "." )
private static final Pattern URL_PATTERN = Pattern.compile("^[a-zA-Z][a-zA-Z0-9+.-]*://\\S+");
/**
* Checks that an object is not null.
*
* @param object any object
* @param errorMsg error message
*
* @throws IllegalArgumentException if the object is null
*/
public static void checkNotNull(Object object, String errorMsg) public static void checkNotNull(Object object, String errorMsg)
{ {
check(object != null, errorMsg); check(object != null, errorMsg);
} }
/**
* Checks that a string is not null or empty
*
* @param string any string
* @param errorMsg error message
*
* @throws IllegalArgumentException if the string is null or empty
*/
public static void checkEmptyString(String string, String errorMsg) public static void checkEmptyString(String string, String errorMsg)
{ {
check(string != null && !string.trim().equals(""), errorMsg); check(string != null && !string.trim().equals(""), errorMsg);
} }
/**
* Checks that a URL is valid
*
* @param url any string
* @param errorMsg error message
*/
public static void checkValidUrl(String url, String errorMsg) public static void checkValidUrl(String url, String errorMsg)
{ {
checkEmptyString(url, errorMsg); checkEmptyString(url, errorMsg);
check(isUrl(url), errorMsg); check(isUrl(url), errorMsg);
} }
/**
* Checks that a URL is a valid OAuth callback
*
* @param url any string
* @param errorMsg error message
*/
public static void checkValidOAuthCallback(String url, String errorMsg) public static void checkValidOAuthCallback(String url, String errorMsg)
{ {
checkEmptyString(url, errorMsg); checkEmptyString(url, errorMsg);
@@ -69,14 +31,14 @@ public class Preconditions
} }
} }
private static boolean isUrl(String url) static boolean isUrl(String url)
{ {
return URL_PATTERN.matcher(url).matches(); return url.startsWith("http://") || url.startsWith("https://");
} }
private static void check(boolean requirements, String error) private static void check(boolean requirements, String error)
{ {
String message = (error == null || error.trim().length() <= 0) ? DEFAULT_MESSAGE : error; String message = (error == null || error.trim().isEmpty()) ? DEFAULT_MESSAGE : error;
if (!requirements) if (!requirements)
{ {
throw new IllegalArgumentException(message); throw new IllegalArgumentException(message);
@@ -2,19 +2,9 @@ package org.scribe.utils;
import java.io.*; import java.io.*;
/**
* Utils to deal with Streams.
*
* @author Pablo Fernandez
*/
public class StreamUtils public class StreamUtils
{ {
/**
* Returns the stream contents as an UTF-8 encoded string
*
* @param is input stream
* @return string contents
*/
public static String getStreamContents(InputStream is) public static String getStreamContents(InputStream is)
{ {
Preconditions.checkNotNull(is, "Cannot get String from a null object"); Preconditions.checkNotNull(is, "Cannot get String from a null object");
@@ -36,7 +26,7 @@ public class StreamUtils
return out.toString(); return out.toString();
} catch (IOException ioe) } catch (IOException ioe)
{ {
throw new IllegalStateException("Error while reading response body", ioe); throw new RuntimeException("Error while reading response body", ioe);
} }
} }
} }
@@ -0,0 +1,66 @@
package org.scribe.utils;
import java.io.*;
import java.net.*;
import java.util.*;
import org.scribe.exceptions.*;
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);
public static String formURLEncodeMap(Map<String, List<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, List<String>> map)
{
StringBuffer encodedString = new StringBuffer();
for (String key : map.keySet())
{
for(String value: map.get(key))
{
encodedString.append(percentEncode(key)).append(PAIR_SEPARATOR).append(percentEncode(value)).append(PARAM_SEPARATOR);
}
}
return removeTrailingSeparator(encodedString);
}
private static String removeTrailingSeparator(StringBuffer buffer)
{
return buffer.toString().substring(0, buffer.length() - 1);
}
public static String percentEncode(String string)
{
Preconditions.checkNotNull(string, "Cannot encode null string");
try
{
return URLEncoder.encode(string, UTF_8);
} catch (UnsupportedEncodingException uee)
{
throw new OAuthException(ERROR_MSG, uee);
}
}
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);
}
}
}
@@ -1,73 +0,0 @@
package org.scribe.builder;
import static org.junit.Assert.*;
import org.junit.*;
import org.scribe.builder.api.*;
import org.scribe.model.*;
import org.scribe.oauth.*;
public class ServiceBuilderTest
{
private ServiceBuilder builder;
@Before
public void setup()
{
builder = new ServiceBuilder();
}
@Test
public void shouldReturnConfigDefaultValues()
{
builder.provider(ApiMock.class).apiKey("key").apiSecret("secret").build();
assertEquals(ApiMock.config.getApiKey(), "key");
assertEquals(ApiMock.config.getApiSecret(), "secret");
assertEquals(ApiMock.config.getCallback(), OAuthConstants.OUT_OF_BAND);
assertEquals(ApiMock.config.getSignatureType(), SignatureType.Header);
}
@Test
public void shouldAcceptValidCallbackUrl()
{
builder.provider(ApiMock.class).apiKey("key").apiSecret("secret").callback("http://example.com").build();
assertEquals(ApiMock.config.getApiKey(), "key");
assertEquals(ApiMock.config.getApiSecret(), "secret");
assertEquals(ApiMock.config.getCallback(), "http://example.com");
}
@Test
public void shouldAcceptASignatureType()
{
builder.provider(ApiMock.class).apiKey("key").apiSecret("secret").signatureType(SignatureType.QueryString).build();
assertEquals(ApiMock.config.getApiKey(), "key");
assertEquals(ApiMock.config.getApiSecret(), "secret");
assertEquals(ApiMock.config.getSignatureType(), SignatureType.QueryString);
}
@Test(expected=IllegalArgumentException.class)
public void shouldNotAcceptNullAsCallback()
{
builder.provider(ApiMock.class).apiKey("key").apiSecret("secret").callback(null).build();
}
@Test
public void shouldAcceptAnScope()
{
builder.provider(ApiMock.class).apiKey("key").apiSecret("secret").scope("rss-api").build();
assertEquals(ApiMock.config.getApiKey(), "key");
assertEquals(ApiMock.config.getApiSecret(), "secret");
assertEquals(ApiMock.config.getScope(), "rss-api");
}
public static class ApiMock implements Api
{
public static OAuthConfig config;
public OAuthService createService(OAuthConfig config)
{
ApiMock.config = config;
return null;
}
}
}
@@ -1,65 +0,0 @@
package org.scribe.examples;
import java.util.*;
import org.scribe.builder.*;
import org.scribe.builder.api.*;
import org.scribe.model.*;
import org.scribe.oauth.*;
public class DiggExample
{
private static final String NETWORK_NAME = "Digg";
private static final String PROTECTED_RESOURCE_URL = "http://services.digg.com/2.0/comment.digg";
public static void main(String[] args)
{
// Replace these with your own api key and secret
String apiKey = "myKey";
String apiSecret = "mySecret";
OAuthService service = new ServiceBuilder().provider(DiggApi.class).apiKey(apiKey).apiSecret(apiSecret).build();
Scanner in = new Scanner(System.in);
System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ===");
System.out.println();
// Obtain the Request Token
System.out.println("Fetching the Request Token...");
Token requestToken = service.getRequestToken();
System.out.println("Got the Request Token!");
System.out.println();
// Obtain the Authorization URL
System.out.println("Fetching the Authorization URL...");
String authorizationUrl = service.getAuthorizationUrl(requestToken);
System.out.println("Got the Authorization URL!");
System.out.println("Now go and authorize Scribe here:");
System.out.println(authorizationUrl);
System.out.println("And paste the authorization code here");
System.out.print(">>");
Verifier verifier = new Verifier(in.nextLine());
System.out.println();
// Trade the Request Token and Verfier for the Access Token
System.out.println("Trading the Request Token for an Access Token...");
Token accessToken = service.getAccessToken(requestToken, verifier);
System.out.println("Got the Access Token!");
System.out.println("(if your curious it looks like this: " + accessToken + " )");
System.out.println();
// Now let's go and ask for a protected resource!
System.out.println("Now we're going to access a protected resource...");
OAuthRequest request = new OAuthRequest(Verb.POST, PROTECTED_RESOURCE_URL);
request.addBodyParameter("comment_id", "20100729223726:4fef610331ee46a3b5cbd740bf71313e");
service.signRequest(accessToken, request);
Response response = request.send();
System.out.println("Got it! Lets see what we found...");
System.out.println();
System.out.println(response.getCode());
System.out.println(response.getBody());
System.out.println();
System.out.println("Thats it man! Go and build something awesome with Scribe! :)");
}
}
@@ -1,64 +0,0 @@
package org.scribe.examples;
import java.util.*;
import org.scribe.builder.*;
import org.scribe.builder.api.*;
import org.scribe.model.*;
import org.scribe.oauth.*;
public class FacebookExample
{
private static final String NETWORK_NAME = "Facebook";
private static final String PROTECTED_RESOURCE_URL = "https://graph.facebook.com/me";
private static final Token EMPTY_TOKEN = null;
public static void main(String[] args)
{
// Replace these with your own api key and secret
String apiKey = "your_app_id";
String apiSecret = "your_api_secret";
OAuthService service = new ServiceBuilder()
.provider(FacebookApi.class)
.apiKey(apiKey)
.apiSecret(apiSecret)
.callback("http://www.example.com/oauth_callback/")
.build();
Scanner in = new Scanner(System.in);
System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ===");
System.out.println();
// Obtain the Authorization URL
System.out.println("Fetching the Authorization URL...");
String authorizationUrl = service.getAuthorizationUrl(EMPTY_TOKEN);
System.out.println("Got the Authorization URL!");
System.out.println("Now go and authorize Scribe here:");
System.out.println(authorizationUrl);
System.out.println("And paste the authorization code here");
System.out.print(">>");
Verifier verifier = new Verifier(in.nextLine());
System.out.println();
// Trade the Request Token and Verfier for the Access Token
System.out.println("Trading the Request Token for an Access Token...");
Token accessToken = service.getAccessToken(EMPTY_TOKEN, verifier);
System.out.println("Got the Access Token!");
System.out.println("(if your curious it looks like this: " + accessToken + " )");
System.out.println();
// Now let's go and ask for a protected resource!
System.out.println("Now we're going to access a protected resource...");
OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL);
service.signRequest(accessToken, request);
Response response = request.send();
System.out.println("Got it! Lets see what we found...");
System.out.println();
System.out.println(response.getCode());
System.out.println(response.getBody());
System.out.println();
System.out.println("Thats it man! Go and build something awesome with Scribe! :)");
}
}
@@ -1,59 +0,0 @@
package org.scribe.examples;
import org.scribe.builder.*;
import org.scribe.builder.api.*;
import org.scribe.model.*;
import org.scribe.oauth.*;
import java.util.*;
public class FlickrExample
{
private static final String PROTECTED_RESOURCE_URL = "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! :)");
}
}
@@ -1,63 +0,0 @@
package org.scribe.examples;
import java.util.*;
import org.scribe.builder.*;
import org.scribe.builder.api.*;
import org.scribe.model.*;
import org.scribe.oauth.*;
public class Foursquare2Example
{
private static final String PROTECTED_RESOURCE_URL = "https://api.foursquare.com/v2/users/self/friends?oauth_token=";
private static final Token EMPTY_TOKEN = null;
public static void main(String[] args)
{
// Replace these with your own api key and secret
String apiKey = "FEGFXJUFANVVDHVSNUAMUKTTXCP1AJQD53E33XKJ44YP1S4I";
String apiSecret = "AYWKUL5SWPNC0CTQ202QXRUG2NLZYXMRA34ZSDW4AUYBG2RC";
OAuthService service = new ServiceBuilder()
.provider(Foursquare2Api.class)
.apiKey(apiKey)
.apiSecret(apiSecret)
.callback("http://localhost:9000/")
.build();
Scanner in = new Scanner(System.in);
System.out.println("=== Foursquare2's OAuth Workflow ===");
System.out.println();
// Obtain the Authorization URL
System.out.println("Fetching the Authorization URL...");
String authorizationUrl = service.getAuthorizationUrl(EMPTY_TOKEN);
System.out.println("Got the Authorization URL!");
System.out.println("Now go and authorize Scribe here:");
System.out.println(authorizationUrl);
System.out.println("And paste the authorization code here");
System.out.print(">>");
Verifier verifier = new Verifier(in.nextLine());
System.out.println();
// Trade the Request Token and Verfier for the Access Token
System.out.println("Trading the Request Token for an Access Token...");
Token accessToken = service.getAccessToken(EMPTY_TOKEN, verifier);
System.out.println("Got the Access Token!");
System.out.println("(if your curious it looks like this: " + accessToken + " )");
System.out.println();
// Now let's go and ask for a protected resource!
System.out.println("Now we're going to access a protected resource...");
OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL + accessToken.getToken());
service.signRequest(accessToken, request);
Response response = request.send();
System.out.println("Got it! Lets see what we found...");
System.out.println();
System.out.println(response.getCode());
System.out.println(response.getBody());
System.out.println();
System.out.println("Thats it man! Go and build something awesome with Scribe! :)");
}
}
@@ -9,6 +9,7 @@ import org.scribe.oauth.*;
public class FoursquareExample 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"; private static final String PROTECTED_RESOURCE_URL = "http://api.foursquare.com/v1/user";
public static void main(String[] args) public static void main(String[] args)
@@ -30,7 +31,7 @@ public class FoursquareExample
System.out.println(); System.out.println();
System.out.println("Now go and authorize Scribe here:"); System.out.println("Now go and authorize Scribe here:");
System.out.println(service.getAuthorizationUrl(requestToken)); System.out.println(AUTHORIZE_URL + requestToken.getToken());
System.out.println("And paste the verifier here"); System.out.println("And paste the verifier here");
System.out.print(">>"); System.out.print(">>");
Verifier verifier = new Verifier(in.nextLine()); Verifier verifier = new Verifier(in.nextLine());
@@ -1,66 +0,0 @@
package org.scribe.examples;
import java.util.*;
import org.scribe.builder.*;
import org.scribe.builder.api.*;
import org.scribe.model.*;
import org.scribe.oauth.*;
public class FreelancerExample
{
private static final String NETWORK_NAME = "Freelancer";
private static final String AUTHORIZE_URL = "http://www.sandbox.freelancer.com/users/api-token/auth.php?oauth_token=";
private static final String PROTECTED_RESOURCE_URL = "http://api.sandbox.freelancer.com/Job/getJobList.json";
private static final String SCOPE = "http://api.sandbox.freelancer.com";
public static void main(String[] args)
{
OAuthService service = new ServiceBuilder()
.provider(FreelancerApi.Sandbox.class)
.signatureType(SignatureType.QueryString)
.apiKey("7f5a168a0bfdbd15b4a9ea2a969661c731cdea56")
.apiSecret("7bb8961b94873802f1c5344f671a518e087f5785")
.scope(SCOPE)
.build();
Scanner in = new Scanner(System.in);
System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ===");
System.out.println();
// Obtain the Request Token
System.out.println("Fetching the Request Token...");
Token requestToken = service.getRequestToken();
System.out.println("Got the Request Token!");
System.out.println("(if your curious it looks like this: " + requestToken + " )");
System.out.println();
System.out.println("Now go and authorize Scribe here:");
System.out.println(AUTHORIZE_URL + requestToken.getToken());
System.out.println("And paste the verifier here");
System.out.print(">>");
Verifier verifier = new Verifier(in.nextLine());
System.out.println();
// Trade the Request Token and Verfier for the Access Token
System.out.println("Trading the Request Token for an Access Token...");
Token accessToken = service.getAccessToken(requestToken, verifier);
System.out.println("Got the Access Token!");
System.out.println("(if your curious it looks like this: " + accessToken + " )");
System.out.println();
// Now let's go and ask for a protected resource!
System.out.println("Now we're going to access a protected resource...");
OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL);
service.signRequest(accessToken, request);
request.addHeader("GData-Version", "3.0");
Response response = request.send();
System.out.println("Got it! Lets see what we found...");
System.out.println();
System.out.println(response.getCode());
System.out.println(response.getBody());
System.out.println();
System.out.println("Thats it man! Go and build something awesome with Scribe! :)");
}
}
@@ -1,66 +0,0 @@
package org.scribe.examples;
import java.util.*;
import org.scribe.builder.*;
import org.scribe.builder.api.*;
import org.scribe.model.*;
import org.scribe.oauth.*;
public class GoogleExample
{
private static final String NETWORK_NAME = "Google";
private static final String AUTHORIZE_URL = "https://www.google.com/accounts/OAuthAuthorizeToken?oauth_token=";
private static final String PROTECTED_RESOURCE_URL = "https://docs.google.com/feeds/default/private/full/";
private static final String SCOPE = "https://docs.google.com/feeds/";
public static void main(String[] args)
{
OAuthService service = new ServiceBuilder()
.provider(GoogleApi.class)
.apiKey("anonymous")
.apiSecret("anonymous")
.scope(SCOPE)
.build();
Scanner in = new Scanner(System.in);
System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ===");
System.out.println();
// Obtain the Request Token
System.out.println("Fetching the Request Token...");
Token requestToken = service.getRequestToken();
System.out.println("Got the Request Token!");
System.out.println("(if your curious it looks like this: " + requestToken + " )");
System.out.println();
System.out.println("Now go and authorize Scribe here:");
System.out.println(AUTHORIZE_URL + requestToken.getToken());
System.out.println("And paste the verifier here");
System.out.print(">>");
Verifier verifier = new Verifier(in.nextLine());
System.out.println();
// Trade the Request Token and Verfier for the Access Token
System.out.println("Trading the Request Token for an Access Token...");
Token accessToken = service.getAccessToken(requestToken, verifier);
System.out.println("Got the Access Token!");
System.out.println("(if your curious it looks like this: " + accessToken + " )");
System.out.println();
// Now let's go and ask for a protected resource!
System.out.println("Now we're going to access a protected resource...");
OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL);
service.signRequest(accessToken, request);
request.addHeader("GData-Version", "3.0");
Response response = request.send();
System.out.println("Got it! Lets see what we found...");
System.out.println();
System.out.println(response.getCode());
System.out.println(response.getBody());
System.out.println();
System.out.println("Thats it man! Go and build something awesome with Scribe! :)");
}
}
@@ -1,58 +0,0 @@
package org.scribe.examples;
import org.scribe.builder.*;
import org.scribe.builder.api.*;
import org.scribe.model.*;
import org.scribe.oauth.*;
import java.util.*;
public class ImgUrExample
{
private static final String PROTECTED_RESOURCE_URL = "http://api.imgur.com/2/account.json";
public static void main(String[] args)
{
// Replace these with your own api key and secret (you'll need an read/write api key)
String apiKey = "your_app_id";
String apiSecret = "your_api_secret";
OAuthService service = new ServiceBuilder().provider(ImgUrApi.class).apiKey(apiKey).apiSecret(apiSecret).build();
Scanner in = new Scanner(System.in);
System.out.println("=== ImgUr's OAuth Workflow ===");
System.out.println();
// Obtain the Request Token
System.out.println("Fetching the Request Token...");
Token requestToken = service.getRequestToken();
System.out.println("Got the Request Token!");
System.out.println();
System.out.println("Now go and authorize Scribe here:");
String authorizationUrl = service.getAuthorizationUrl(requestToken);
System.out.println(authorizationUrl);
System.out.println("And paste the verifier here");
System.out.print(">>");
Verifier verifier = new Verifier(in.nextLine());
System.out.println();
// Trade the Request Token and Verfier for the Access Token
System.out.println("Trading the Request Token for an Access Token...");
Token accessToken = service.getAccessToken(requestToken, verifier);
System.out.println("Got the Access Token!");
System.out.println("(if your curious it looks like this: " + accessToken + " )");
System.out.println();
// Now let's go and ask for a protected resource!
System.out.println("Now we're going to access a protected resource...");
OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL);
service.signRequest(accessToken, request);
Response response = request.send();
System.out.println("Got it! Lets see what we found...");
System.out.println();
System.out.println(response.getBody());
System.out.println();
System.out.println("Thats it man! Go and build something awesome with Scribe! :)");
}
}
@@ -1,63 +0,0 @@
package org.scribe.examples;
import org.scribe.builder.*;
import org.scribe.builder.api.*;
import org.scribe.model.*;
import org.scribe.oauth.*;
import java.util.*;
public class Kaixin20Example
{
private static final String NETWORK_NAME = "Kaixin";
private static final String PROTECTED_RESOURCE_URL = "https://api.kaixin001.com/users/me.json";
private static final Token EMPTY_TOKEN = null;
public static void main(String[] args)
{
// Replace these with your own api key and secret
String apiKey = "your api key";
String apiSecret = "your api secret";
OAuthService service = new ServiceBuilder()
.provider(KaixinApi20.class)
.apiKey(apiKey)
.apiSecret(apiSecret)
.callback("http://your.domain.com/handle")
.build();
Scanner in = new Scanner(System.in);
System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ===");
System.out.println();
// Obtain the Authorization URL
System.out.println("Fetching the Authorization URL...");
String authorizationUrl = service.getAuthorizationUrl(EMPTY_TOKEN);
System.out.println("Got the Authorization URL!");
System.out.println("Now go and authorize Scribe here:");
System.out.println(authorizationUrl);
System.out.println("And paste the authorization code here");
System.out.print(">>");
Verifier verifier = new Verifier(in.nextLine());
System.out.println();
// Trade the Request Token and Verifier for the Access Token
System.out.println("Trading the Request Token for an Access Token...");
Token accessToken = service.getAccessToken(EMPTY_TOKEN, verifier);
System.out.println("Got the Access Token!");
System.out.println("(if your curious it looks like this: " + accessToken + " )");
System.out.println();
// Now let's go and ask for a protected resource!
System.out.println("Now we're going to access a protected resource...");
OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL);
service.signRequest(accessToken, request);
Response response = request.send();
System.out.println("Got it! Lets see what we found...");
System.out.println();
System.out.println(response.getCode());
System.out.println(response.getBody());
System.out.println();
System.out.println("Thats it man! Go and build something awesome with Scribe! :)");
}
}
@@ -9,17 +9,18 @@ import org.scribe.oauth.*;
public class LinkedInExample 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)"; private static final String PROTECTED_RESOURCE_URL = "http://api.linkedin.com/v1/people/~/connections:(id,last-name)";
public static void main(String[] args) public static void main(String[] args)
{ {
OAuthService service = new ServiceBuilder() OAuthService service = new ServiceBuilder()
.provider(LinkedInApi.class) .provider(LinkedInApi.class)
.apiKey("CiEgwWDkA5BFpNrc0RfGyVuSlOh4tig5kOTZ9q97qcXNrFl7zqk-Ts7DqRGaKDCV") .apiKey("CiEgwWDkA5BFpNrc0RfGyVuSlOh4tig5kOTZ9q97qcXNrFl7zqk-Ts7DqRGaKDCV")
.apiSecret("dhho4dfoCmiQXrkw4yslork5XWLFnPSuMR-8gscPVjY4jqFFHPYWJKgpFl4uLTM6") .apiSecret("dhho4dfoCmiQXrkw4yslork5XWLFnPSuMR-8gscPVjY4jqFFHPYWJKgpFl4uLTM6")
.build(); .build();
Scanner in = new Scanner(System.in);
Scanner in = new Scanner(System.in);
System.out.println("=== LinkedIn's OAuth Workflow ==="); System.out.println("=== LinkedIn's OAuth Workflow ===");
System.out.println(); System.out.println();
@@ -30,7 +31,7 @@ public class LinkedInExample
System.out.println(); System.out.println();
System.out.println("Now go and authorize Scribe here:"); System.out.println("Now go and authorize Scribe here:");
System.out.println(service.getAuthorizationUrl(requestToken)); System.out.println(AUTHORIZE_URL + requestToken.getToken());
System.out.println("And paste the verifier here"); System.out.println("And paste the verifier here");
System.out.print(">>"); System.out.print(">>");
Verifier verifier = new Verifier(in.nextLine()); Verifier verifier = new Verifier(in.nextLine());
@@ -54,6 +55,8 @@ public class LinkedInExample
System.out.println(); System.out.println();
System.out.println("Thats it man! Go and build something awesome with Scribe! :)"); System.out.println("Thats it man! Go and build something awesome with Scribe! :)");
System.out.println(service.getRequestToken());
} }
} }
Loaded 100 of 129 files, more files were not shown because too many files have changed in this diff. Show more