Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1932ad28c1 | ||
|
|
7f89dc3546 | ||
|
|
f3c0a179f3 | ||
|
|
d800ece6a6 |
No files matched your search
@@ -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
|
|
||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
The MIT License
|
The MIT License
|
||||||
|
|
||||||
Copyright (c) 2010 Pablo Fernandez
|
Copyright (c) 2010 Pablo Fenandez
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
+1
-15
@@ -1,7 +1,5 @@
|
|||||||
h2. Welcome to the home of Scribe, the simple OAuth Java lib!
|
h2. Welcome to the home of Scribe, the simple OAuth Java lib!
|
||||||
|
|
||||||
!https://secure.travis-ci.org/fernandezpablo85/scribe-java.png?branch=master(travis-ci-status)!
|
|
||||||
|
|
||||||
h1. Why use Scribe?
|
h1. Why use Scribe?
|
||||||
|
|
||||||
h3. Dead Simple
|
h3. Dead Simple
|
||||||
@@ -65,7 +63,7 @@ You can pull scribe from a maven repository, just add this to your __pom.xml__ f
|
|||||||
@<dependency>@
|
@<dependency>@
|
||||||
@<groupId>org.scribe</groupId>@
|
@<groupId>org.scribe</groupId>@
|
||||||
@<artifactId>scribe</artifactId>@
|
@<artifactId>scribe</artifactId>@
|
||||||
@<version>1.3.0</version>@
|
@<version>1.2.1</version>@
|
||||||
@</dependency>@
|
@</dependency>@
|
||||||
|
|
||||||
h1. Getting started in less than 2 minutes
|
h1. Getting started in less than 2 minutes
|
||||||
@@ -74,18 +72,6 @@ Check the "Getting Started":http://wiki.github.com/fernandezpablo85/scribe-java/
|
|||||||
|
|
||||||
h1. Please Read the "FAQ":http://wiki.github.com/fernandezpablo85/scribe-java/faq before creating an issue :)
|
h1. 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
|
||||||
|
|||||||
+3
-29
@@ -56,33 +56,7 @@
|
|||||||
* FEATURE: Added support for Vkontakte (thanks dotbg)
|
* FEATURE: Added support for Vkontakte (thanks dotbg)
|
||||||
* FEATURE: Added Sohu Weibo, Netease Weibo & Sina Weibo Apis (thanks Arthur Wang)
|
* FEATURE: Added Sohu Weibo, Netease Weibo & Sina Weibo Apis (thanks Arthur Wang)
|
||||||
* FEATURE: Added support for persistent Http Connections (thanks Craig Minton)
|
* FEATURE: Added support for persistent Http Connections (thanks Craig Minton)
|
||||||
|
|
||||||
[1.2.2]
|
[1.2.2]
|
||||||
* FIX: Added support for JDK 1.5. Issue #146 (thanks Sripathi Krishnan)
|
* FIX: Fixed error while setting connection timeouts
|
||||||
* FIX: Invalid character constant error message. Issue #137 (thanks Scott Scoble)
|
* FEATURE: Plurk Api
|
||||||
* FEATURE: Added a Api class to handle windows live authentication. Issue #135 (thanks Tomas Lin)
|
* FEATURE: Windows Live Api
|
||||||
* 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,7 +4,7 @@
|
|||||||
<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.2.1</version>
|
||||||
<name>Scribe OAuth Library</name>
|
<name>Scribe OAuth Library</name>
|
||||||
<description>The best OAuth library out there</description>
|
<description>The best OAuth library out there</description>
|
||||||
<url>http://github.com/fernandezpablo85/scribe-java</url>
|
<url>http://github.com/fernandezpablo85/scribe-java</url>
|
||||||
@@ -63,8 +63,8 @@
|
|||||||
<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>
|
<plugin>
|
||||||
|
|||||||
@@ -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,6 +1,5 @@
|
|||||||
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.*;
|
||||||
@@ -22,7 +21,6 @@ public class ServiceBuilder
|
|||||||
private Api api;
|
private Api api;
|
||||||
private String scope;
|
private String scope;
|
||||||
private SignatureType signatureType;
|
private SignatureType signatureType;
|
||||||
private OutputStream debugStream;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default constructor
|
* Default constructor
|
||||||
@@ -30,8 +28,6 @@ public class ServiceBuilder
|
|||||||
public ServiceBuilder()
|
public ServiceBuilder()
|
||||||
{
|
{
|
||||||
this.callback = OAuthConstants.OUT_OF_BAND;
|
this.callback = OAuthConstants.OUT_OF_BAND;
|
||||||
this.signatureType = SignatureType.Header;
|
|
||||||
this.debugStream = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -84,7 +80,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;
|
||||||
}
|
}
|
||||||
@@ -140,19 +136,6 @@ public class ServiceBuilder
|
|||||||
this.signatureType = type;
|
this.signatureType = type;
|
||||||
return this;
|
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 +147,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(new OAuthConfig(apiKey, apiSecret, callback, signatureType, scope));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -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());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -7,19 +7,19 @@ public class DropBoxApi extends DefaultApi10a
|
|||||||
@Override
|
@Override
|
||||||
public String getAccessTokenEndpoint()
|
public String getAccessTokenEndpoint()
|
||||||
{
|
{
|
||||||
return "https://api.dropbox.com/1/oauth/access_token";
|
return "https://api.dropbox.com/0/oauth/access_token";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getAuthorizationUrl(Token requestToken)
|
public String getAuthorizationUrl(Token requestToken)
|
||||||
{
|
{
|
||||||
return "https://www.dropbox.com/1/oauth/authorize?oauth_token="+requestToken.getToken();
|
return "https://www.dropbox.com/0/oauth/authorize?oauth_token="+requestToken.getToken();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getRequestTokenEndpoint()
|
public String getRequestTokenEndpoint()
|
||||||
{
|
{
|
||||||
return "https://api.dropbox.com/1/oauth/request_token";
|
return "https://api.dropbox.com/0/oauth/request_token";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,21 +1,34 @@
|
|||||||
package org.scribe.builder.api;
|
package org.scribe.builder.api;
|
||||||
|
|
||||||
import org.scribe.model.Token;
|
import org.scribe.model.Token;
|
||||||
|
import org.scribe.model.Verb;
|
||||||
|
|
||||||
public class EvernoteApi extends DefaultApi10a
|
public class EvernoteApi extends DefaultApi10a
|
||||||
{
|
{
|
||||||
private static final String AUTHORIZATION_URL = "https://www.evernote.com/OAuth.action?oauth_token=%s";
|
private static final String AUTHORIZATION_URL = "https://www.evernote.com/OAuth.action?oauth_token=%s";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
public Verb getRequestTokenVerb()
|
||||||
|
{
|
||||||
|
return Verb.GET;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String getRequestTokenEndpoint()
|
public String getRequestTokenEndpoint()
|
||||||
{
|
{
|
||||||
return "https://www.evernote.com/oauth";
|
return "https://www.evernote.com/oauth";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Verb getAccessTokenVerb()
|
||||||
|
{
|
||||||
|
return Verb.GET;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getAccessTokenEndpoint()
|
public String getAccessTokenEndpoint()
|
||||||
{
|
{
|
||||||
return "https://www.evernote.com/oauth";
|
return "https://www.evernote.com/oauth";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -26,24 +39,24 @@ public class EvernoteApi extends DefaultApi10a
|
|||||||
|
|
||||||
public static class Sandbox extends EvernoteApi
|
public static class Sandbox extends EvernoteApi
|
||||||
{
|
{
|
||||||
private static final String SANDBOX_URL = "https://sandbox.evernote.com";
|
private static final String SANDBOX_URL = "https://sandbox.evernote.com/oauth";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getRequestTokenEndpoint()
|
public String getRequestTokenEndpoint()
|
||||||
{
|
{
|
||||||
return SANDBOX_URL + "/oauth";
|
return SANDBOX_URL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getAccessTokenEndpoint()
|
public String getAccessTokenEndpoint()
|
||||||
{
|
{
|
||||||
return SANDBOX_URL + "/oauth";
|
return SANDBOX_URL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getAuthorizationUrl(Token requestToken)
|
public String getAuthorizationUrl(Token requestToken)
|
||||||
{
|
{
|
||||||
return String.format(SANDBOX_URL + "/OAuth.action?oauth_token=%s", requestToken.getToken());
|
return String.format(SANDBOX_URL + "?oauth_token=%s", requestToken.getToken());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3,6 +3,7 @@ package org.scribe.builder.api;
|
|||||||
import org.scribe.model.*;
|
import org.scribe.model.*;
|
||||||
|
|
||||||
import org.scribe.utils.*;
|
import org.scribe.utils.*;
|
||||||
|
import static org.scribe.utils.URLUtils.*;
|
||||||
|
|
||||||
public class FacebookApi extends DefaultApi20
|
public class FacebookApi extends DefaultApi20
|
||||||
{
|
{
|
||||||
@@ -23,11 +24,11 @@ public class FacebookApi extends DefaultApi20
|
|||||||
// Append scope if present
|
// Append scope if present
|
||||||
if(config.hasScope())
|
if(config.hasScope())
|
||||||
{
|
{
|
||||||
return String.format(SCOPED_AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()), OAuthEncoder.encode(config.getScope()));
|
return String.format(SCOPED_AUTHORIZE_URL, config.getApiKey(), formURLEncode(config.getCallback()), formURLEncode(config.getScope()));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return String.format(AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()));
|
return String.format(AUTHORIZE_URL, config.getApiKey(), formURLEncode(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";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -18,7 +18,7 @@ public class Foursquare2Api extends DefaultApi20
|
|||||||
public String getAuthorizationUrl(OAuthConfig config)
|
public String getAuthorizationUrl(OAuthConfig config)
|
||||||
{
|
{
|
||||||
Preconditions.checkValidUrl(config.getCallback(), "Must provide a valid url as callback. Foursquare2 does not support OOB");
|
Preconditions.checkValidUrl(config.getCallback(), "Must provide a valid url as callback. Foursquare2 does not support OOB");
|
||||||
return String.format(AUTHORIZATION_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()));
|
return String.format(AUTHORIZATION_URL, config.getApiKey(), URLUtils.formURLEncode(config.getCallback()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -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,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,9 +1,13 @@
|
|||||||
package org.scribe.builder.api;
|
package org.scribe.builder.api;
|
||||||
|
|
||||||
import org.scribe.extractors.*;
|
import org.scribe.extractors.*;
|
||||||
|
|
||||||
import org.scribe.model.*;
|
import org.scribe.model.*;
|
||||||
|
|
||||||
import org.scribe.utils.*;
|
import org.scribe.utils.*;
|
||||||
|
|
||||||
|
import static org.scribe.utils.URLUtils.*;
|
||||||
|
|
||||||
public class LiveApi extends DefaultApi20
|
public class LiveApi extends DefaultApi20
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -24,11 +28,10 @@ public class LiveApi extends DefaultApi20
|
|||||||
// Append scope if present
|
// Append scope if present
|
||||||
if (config.hasScope())
|
if (config.hasScope())
|
||||||
{
|
{
|
||||||
return String.format(SCOPED_AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()), OAuthEncoder.encode(config.getScope()));
|
return String.format(SCOPED_AUTHORIZE_URL, config.getApiKey(), formURLEncode(config.getCallback()), formURLEncode(config.getScope()));
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
{
|
{
|
||||||
return String.format(AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()));
|
return String.format(AUTHORIZE_URL, config.getApiKey(), formURLEncode(config.getCallback()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -5,7 +5,7 @@ import org.scribe.model.Token;
|
|||||||
public class PlurkApi extends DefaultApi10a
|
public class PlurkApi extends DefaultApi10a
|
||||||
{
|
{
|
||||||
private static final String REQUEST_TOKEN_URL = "http://www.plurk.com/OAuth/request_token";
|
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 AUTHORIZE_URL = "http://www.plurk.com/OAuth/authorize?oauth_token=%s";
|
||||||
private static final String ACCESS_TOKEN_URL = "http://www.plurk.com/OAuth/access_token";
|
private static final String ACCESS_TOKEN_URL = "http://www.plurk.com/OAuth/access_token";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -17,7 +17,7 @@ public class PlurkApi extends DefaultApi10a
|
|||||||
@Override
|
@Override
|
||||||
public String getAuthorizationUrl(Token requestToken)
|
public String getAuthorizationUrl(Token requestToken)
|
||||||
{
|
{
|
||||||
return String.format(AUTHORIZATION_URL, requestToken.getToken());
|
return String.format(AUTHORIZE_URL, requestToken.getToken());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -25,15 +25,4 @@ public class PlurkApi extends DefaultApi10a
|
|||||||
{
|
{
|
||||||
return ACCESS_TOKEN_URL;
|
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,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.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());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -40,27 +40,4 @@ public class TwitterApi extends DefaultApi10a
|
|||||||
return "https://" + REQUEST_TOKEN_RESOURCE;
|
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{}
|
|
||||||
}
|
}
|
||||||
@@ -25,11 +25,11 @@ public class VkontakteApi extends DefaultApi20
|
|||||||
Preconditions.checkValidUrl(config.getCallback(), "Valid url is required for a callback. Vkontakte does not support OOB");
|
Preconditions.checkValidUrl(config.getCallback(), "Valid url is required for a callback. Vkontakte does not support OOB");
|
||||||
if(config.hasScope())// Appending scope if present
|
if(config.hasScope())// Appending scope if present
|
||||||
{
|
{
|
||||||
return String.format(SCOPED_AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()), OAuthEncoder.encode(config.getScope()));
|
return String.format(SCOPED_AUTHORIZE_URL, config.getApiKey(), URLUtils.formURLEncode(config.getCallback()),URLUtils.formURLEncode(config.getScope()));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return String.format(AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()));
|
return String.format(AUTHORIZE_URL, config.getApiKey(), URLUtils.formURLEncode(config.getCallback()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import org.scribe.services.*;
|
|||||||
|
|
||||||
public class YammerApi extends DefaultApi10a
|
public class YammerApi extends DefaultApi10a
|
||||||
{
|
{
|
||||||
private static final String AUTHORIZATION_URL = "https://www.yammer.com/oauth/authorize?oauth_token=%s";
|
private static final String AUTHORIZATION_URL = "'https://www.yammer.com/oauth/authorize?oauth_token=%s'";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getRequestTokenEndpoint()
|
public String getRequestTokenEndpoint()
|
||||||
|
|||||||
@@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -8,7 +8,6 @@ package org.scribe.exceptions;
|
|||||||
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
|
* Default constructor
|
||||||
@@ -18,7 +17,7 @@ public class OAuthSignatureException extends OAuthException
|
|||||||
*/
|
*/
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
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.*;
|
||||||
@@ -21,19 +23,20 @@ public class BaseStringExtractorImpl implements BaseStringExtractor
|
|||||||
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, String> params = new HashMap<String, String>();
|
||||||
params.addAll(request.getQueryStringParams());
|
MapUtils.decodeAndAppendEntries(request.getQueryStringParams(), params);
|
||||||
params.addAll(request.getBodyParams());
|
MapUtils.decodeAndAppendEntries(request.getBodyParams(), params);
|
||||||
params.addAll(new ParameterList(request.getOauthParameters()));
|
MapUtils.decodeAndAppendEntries(request.getOauthParameters(), params);
|
||||||
return params.sort().asOauthBaseString();
|
params = MapUtils.sort(params);
|
||||||
|
return URLUtils.percentEncode(MapUtils.concatSortedPercentEncodedParams(params));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkPreconditions(OAuthRequest request)
|
private void checkPreconditions(OAuthRequest request)
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ public class HeaderExtractorImpl implements HeaderExtractor
|
|||||||
{
|
{
|
||||||
header.append(PARAM_SEPARATOR);
|
header.append(PARAM_SEPARATOR);
|
||||||
}
|
}
|
||||||
header.append(String.format("%s=\"%s\"", key, OAuthEncoder.encode(parameters.get(key))));
|
header.append(String.format("%s=\"%s\"", key, URLUtils.percentEncode(parameters.get(key))));
|
||||||
}
|
}
|
||||||
return header.toString();
|
return header.toString();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import org.scribe.utils.*;
|
|||||||
|
|
||||||
public class JsonTokenExtractor implements AccessTokenExtractor
|
public class JsonTokenExtractor implements AccessTokenExtractor
|
||||||
{
|
{
|
||||||
private Pattern accessTokenPattern = Pattern.compile("\"access_token\":\\s*\"(\\S*?)\"");
|
private Pattern accessTokenPattern = Pattern.compile("\"access_token\":\"(\\S*?)\"");
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Token extract(String response)
|
public Token extract(String response)
|
||||||
@@ -25,4 +25,4 @@ public class JsonTokenExtractor implements AccessTokenExtractor
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -12,7 +12,7 @@ import org.scribe.utils.*;
|
|||||||
*/
|
*/
|
||||||
public class TokenExtractor20Impl implements AccessTokenExtractor
|
public class TokenExtractor20Impl implements AccessTokenExtractor
|
||||||
{
|
{
|
||||||
private static final String TOKEN_REGEX = "access_token=([^&]+)";
|
private static final String TOKEN_REGEX = "access_token=(\\S*?)(&(\\S*))?";
|
||||||
private static final String EMPTY_SECRET = "";
|
private static final String EMPTY_SECRET = "";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -23,9 +23,9 @@ public class TokenExtractor20Impl implements AccessTokenExtractor
|
|||||||
Preconditions.checkEmptyString(response, "Response body is incorrect. Can't extract a token from an empty string");
|
Preconditions.checkEmptyString(response, "Response body is incorrect. Can't extract a token from an empty string");
|
||||||
|
|
||||||
Matcher matcher = Pattern.compile(TOKEN_REGEX).matcher(response);
|
Matcher matcher = Pattern.compile(TOKEN_REGEX).matcher(response);
|
||||||
if (matcher.find())
|
if (matcher.matches())
|
||||||
{
|
{
|
||||||
String token = OAuthEncoder.decode(matcher.group(1));
|
String token = URLUtils.formURLDecode(matcher.group(1));
|
||||||
return new Token(token, EMPTY_SECRET, response);
|
return new Token(token, EMPTY_SECRET, response);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ import org.scribe.utils.*;
|
|||||||
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 TOKEN_REGEX = Pattern.compile("oauth_token=([^&]+)");
|
||||||
private static final Pattern SECRET_REGEX = Pattern.compile("oauth_token_secret=([^&]*)");
|
private static final Pattern SECRET_REGEX = Pattern.compile("oauth_token_secret=([^&]+)");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
@@ -34,7 +34,7 @@ public class TokenExtractorImpl implements RequestTokenExtractor, AccessTokenExt
|
|||||||
Matcher matcher = p.matcher(response);
|
Matcher matcher = p.matcher(response);
|
||||||
if (matcher.find() && matcher.groupCount() >= 1)
|
if (matcher.find() && matcher.groupCount() >= 1)
|
||||||
{
|
{
|
||||||
return OAuthEncoder.decode(matcher.group(1));
|
return URLUtils.formURLDecode(matcher.group(1));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
package org.scribe.model;
|
package org.scribe.model;
|
||||||
|
|
||||||
import java.io.*;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parameter object that groups OAuth config values
|
* Parameter object that groups OAuth config values
|
||||||
*
|
*
|
||||||
@@ -14,21 +12,19 @@ public class OAuthConfig
|
|||||||
private final String callback;
|
private final String callback;
|
||||||
private final SignatureType signatureType;
|
private final SignatureType signatureType;
|
||||||
private final String scope;
|
private final String scope;
|
||||||
private final OutputStream debugStream;
|
|
||||||
|
|
||||||
public OAuthConfig(String key, String secret)
|
public OAuthConfig(String key, String secret)
|
||||||
{
|
{
|
||||||
this(key, secret, null, null, null, null);
|
this(key, secret, null, null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public OAuthConfig(String key, String secret, String callback, SignatureType type, String scope, OutputStream stream)
|
public OAuthConfig(String key, String secret, String callback, SignatureType type, String scope)
|
||||||
{
|
{
|
||||||
this.apiKey = key;
|
this.apiKey = key;
|
||||||
this.apiSecret = secret;
|
this.apiSecret = secret;
|
||||||
this.callback = callback;
|
this.callback = callback != null ? callback : OAuthConstants.OUT_OF_BAND;
|
||||||
this.signatureType = type;
|
this.signatureType = (type != null) ? type : SignatureType.Header;
|
||||||
this.scope = scope;
|
this.scope = scope;
|
||||||
this.debugStream = stream;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getApiKey()
|
public String getApiKey()
|
||||||
@@ -60,20 +56,4 @@ public class OAuthConfig
|
|||||||
{
|
{
|
||||||
return scope != null;
|
return scope != null;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
public void log(String message)
|
|
||||||
{
|
|
||||||
if (debugStream != null)
|
|
||||||
{
|
|
||||||
message = message + "\n";
|
|
||||||
try
|
|
||||||
{
|
|
||||||
debugStream.write(message.getBytes("UTF8"));
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
throw new RuntimeException("there were problems while writting to the debug stream", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -7,6 +7,7 @@ import java.util.*;
|
|||||||
import java.util.concurrent.TimeUnit;
|
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
|
||||||
@@ -16,13 +17,11 @@ 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, String> querystringParams;
|
||||||
private ParameterList bodyParams;
|
private Map<String, String> bodyParams;
|
||||||
private Map<String, String> headers;
|
private Map<String, String> headers;
|
||||||
private String payload = null;
|
private String payload = null;
|
||||||
private HttpURLConnection connection;
|
private HttpURLConnection connection;
|
||||||
@@ -42,8 +41,8 @@ class Request
|
|||||||
{
|
{
|
||||||
this.verb = verb;
|
this.verb = verb;
|
||||||
this.url = url;
|
this.url = url;
|
||||||
this.querystringParams = new ParameterList();
|
this.querystringParams = new HashMap<String, String>();
|
||||||
this.bodyParams = new ParameterList();
|
this.bodyParams = new HashMap<String, String>();
|
||||||
this.headers = new HashMap<String, String>();
|
this.headers = new HashMap<String, String>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,33 +59,22 @@ class Request
|
|||||||
{
|
{
|
||||||
createConnection();
|
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
|
private void createConnection() throws IOException
|
||||||
{
|
{
|
||||||
String completeUrl = getCompleteUrl();
|
String effectiveUrl = URLUtils.appendParametersToQueryString(url, querystringParams);
|
||||||
if (connection == null)
|
if (connection == null)
|
||||||
{
|
{
|
||||||
System.setProperty("http.keepAlive", connectionKeepAlive ? "true" : "false");
|
System.setProperty("http.keepAlive", connectionKeepAlive ? "true" : "false");
|
||||||
connection = (HttpURLConnection) new URL(completeUrl).openConnection();
|
connection = (HttpURLConnection) new URL(effectiveUrl).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());
|
||||||
@@ -115,12 +103,6 @@ class Request
|
|||||||
void addBody(HttpURLConnection conn, byte[] content) throws IOException
|
void addBody(HttpURLConnection conn, byte[] content) throws IOException
|
||||||
{
|
{
|
||||||
conn.setRequestProperty(CONTENT_LENGTH, String.valueOf(content.length));
|
conn.setRequestProperty(CONTENT_LENGTH, String.valueOf(content.length));
|
||||||
|
|
||||||
// Set default content type if none is set.
|
|
||||||
if (conn.getRequestProperty(CONTENT_TYPE) == null)
|
|
||||||
{
|
|
||||||
conn.setRequestProperty(CONTENT_TYPE, DEFAULT_CONTENT_TYPE);
|
|
||||||
}
|
|
||||||
conn.setDoOutput(true);
|
conn.setDoOutput(true);
|
||||||
conn.getOutputStream().write(content);
|
conn.getOutputStream().write(content);
|
||||||
}
|
}
|
||||||
@@ -144,7 +126,7 @@ class Request
|
|||||||
*/
|
*/
|
||||||
public void addBodyParameter(String key, String value)
|
public void addBodyParameter(String key, String value)
|
||||||
{
|
{
|
||||||
this.bodyParams.add(key, value);
|
this.bodyParams.put(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -155,7 +137,7 @@ class Request
|
|||||||
*/
|
*/
|
||||||
public void addQuerystringParameter(String key, String value)
|
public void addQuerystringParameter(String key, String value)
|
||||||
{
|
{
|
||||||
this.querystringParams.add(key, value);
|
this.querystringParams.put(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -184,20 +166,20 @@ class Request
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a {@link ParameterList} with the query string parameters.
|
* Get a {@link Map} of 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.
|
* @throws OAuthException if the URL is not valid
|
||||||
*/
|
*/
|
||||||
public ParameterList getQueryStringParams()
|
public Map<String, String> getQueryStringParams()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
ParameterList result = new ParameterList();
|
Map<String, String> params = new HashMap<String, String>();
|
||||||
String queryString = new URL(url).getQuery();
|
String queryString = new URL(url).getQuery();
|
||||||
result.addQuerystring(queryString);
|
params.putAll(MapUtils.queryStringToMap(queryString));
|
||||||
result.addAll(querystringParams);
|
params.putAll(this.querystringParams);
|
||||||
return result;
|
return params;
|
||||||
}
|
}
|
||||||
catch (MalformedURLException mue)
|
catch (MalformedURLException mue)
|
||||||
{
|
{
|
||||||
@@ -206,11 +188,11 @@ class Request
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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, String> getBodyParams()
|
||||||
{
|
{
|
||||||
return bodyParams;
|
return bodyParams;
|
||||||
}
|
}
|
||||||
@@ -256,7 +238,7 @@ class Request
|
|||||||
byte[] getByteBodyContents()
|
byte[] getByteBodyContents()
|
||||||
{
|
{
|
||||||
if (bytePayload != null) return bytePayload;
|
if (bytePayload != null) return bytePayload;
|
||||||
String body = (payload != null) ? payload : bodyParams.asFormUrlEncodedString();
|
String body = (payload != null) ? payload : URLUtils.formURLEncodeMap(bodyParams);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return body.getBytes(getCharset());
|
return body.getBytes(getCharset());
|
||||||
@@ -332,7 +314,7 @@ class Request
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets whether the underlying Http Connection is persistent or not.
|
* Sets wether the underlying Http Connection is persistent or not.
|
||||||
*
|
*
|
||||||
* @see http://download.oracle.com/javase/1.5.0/docs/guide/net/http-keepalive.html
|
* @see http://download.oracle.com/javase/1.5.0/docs/guide/net/http-keepalive.html
|
||||||
* @param connectionKeepAlive
|
* @param connectionKeepAlive
|
||||||
|
|||||||
@@ -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.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -28,11 +27,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 +51,7 @@ public class Response
|
|||||||
return headers;
|
return headers;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isSuccessful()
|
private boolean wasSuccessful()
|
||||||
{
|
{
|
||||||
return getCode() >= 200 && getCode() < 400;
|
return getCode() >= 200 && getCode() < 400;
|
||||||
}
|
}
|
||||||
@@ -101,9 +100,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)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -57,22 +57,4 @@ public class Token implements Serializable
|
|||||||
{
|
{
|
||||||
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("","");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -4,11 +4,10 @@ import java.util.*;
|
|||||||
|
|
||||||
import org.scribe.builder.api.*;
|
import org.scribe.builder.api.*;
|
||||||
import org.scribe.model.*;
|
import org.scribe.model.*;
|
||||||
import org.scribe.utils.*;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* OAuth 1.0a implementation of {@link OAuthService}
|
* OAuth 1.0a implementation of {@link OAuthService}
|
||||||
*
|
*
|
||||||
* @author Pablo Fernandez
|
* @author Pablo Fernandez
|
||||||
*/
|
*/
|
||||||
public class OAuth10aServiceImpl implements OAuthService
|
public class OAuth10aServiceImpl implements OAuthService
|
||||||
@@ -20,7 +19,7 @@ public class OAuth10aServiceImpl implements OAuthService
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Default constructor
|
* Default constructor
|
||||||
*
|
*
|
||||||
* @param api OAuth1.0a api information
|
* @param api OAuth1.0a api information
|
||||||
* @param config OAuth 1.0a configuration param object
|
* @param config OAuth 1.0a configuration param object
|
||||||
*/
|
*/
|
||||||
@@ -35,21 +34,12 @@ public class OAuth10aServiceImpl implements OAuthService
|
|||||||
*/
|
*/
|
||||||
public Token getRequestToken()
|
public Token getRequestToken()
|
||||||
{
|
{
|
||||||
config.log("obtaining request token from " + api.getRequestTokenEndpoint());
|
|
||||||
OAuthRequest request = new OAuthRequest(api.getRequestTokenVerb(), api.getRequestTokenEndpoint());
|
OAuthRequest request = new OAuthRequest(api.getRequestTokenVerb(), api.getRequestTokenEndpoint());
|
||||||
|
|
||||||
config.log("setting oauth_callback to " + config.getCallback());
|
|
||||||
request.addOAuthParameter(OAuthConstants.CALLBACK, config.getCallback());
|
request.addOAuthParameter(OAuthConstants.CALLBACK, config.getCallback());
|
||||||
addOAuthParams(request, OAuthConstants.EMPTY_TOKEN);
|
addOAuthParams(request, OAuthConstants.EMPTY_TOKEN);
|
||||||
appendSignature(request);
|
addSignature(request);
|
||||||
|
|
||||||
config.log("sending request...");
|
|
||||||
Response response = request.send();
|
Response response = request.send();
|
||||||
String body = response.getBody();
|
return api.getRequestTokenExtractor().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)
|
||||||
@@ -61,8 +51,6 @@ public class OAuth10aServiceImpl implements OAuthService
|
|||||||
request.addOAuthParameter(OAuthConstants.VERSION, getVersion());
|
request.addOAuthParameter(OAuthConstants.VERSION, getVersion());
|
||||||
if(config.hasScope()) request.addOAuthParameter(OAuthConstants.SCOPE, config.getScope());
|
if(config.hasScope()) request.addOAuthParameter(OAuthConstants.SCOPE, config.getScope());
|
||||||
request.addOAuthParameter(OAuthConstants.SIGNATURE, getSignature(request, token));
|
request.addOAuthParameter(OAuthConstants.SIGNATURE, getSignature(request, token));
|
||||||
|
|
||||||
config.log("appended additional OAuth parameters: " + MapUtils.toString(request.getOauthParameters()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -70,14 +58,11 @@ public class OAuth10aServiceImpl implements OAuthService
|
|||||||
*/
|
*/
|
||||||
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(api.getAccessTokenVerb(), api.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);
|
addSignature(request);
|
||||||
Response response = request.send();
|
Response response = request.send();
|
||||||
return api.getAccessTokenExtractor().extract(response.getBody());
|
return api.getAccessTokenExtractor().extract(response.getBody());
|
||||||
}
|
}
|
||||||
@@ -87,16 +72,9 @@ public class OAuth10aServiceImpl implements OAuthService
|
|||||||
*/
|
*/
|
||||||
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);
|
addSignature(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -114,31 +92,22 @@ public class OAuth10aServiceImpl implements OAuthService
|
|||||||
{
|
{
|
||||||
return api.getAuthorizationUrl(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 = api.getBaseStringExtractor().extract(request);
|
String baseString = api.getBaseStringExtractor().extract(request);
|
||||||
String signature = api.getSignatureService().getSignature(baseString, config.getApiSecret(), token.getSecret());
|
return 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 addSignature(OAuthRequest request)
|
||||||
{
|
{
|
||||||
switch (config.getSignatureType())
|
switch (config.getSignatureType())
|
||||||
{
|
{
|
||||||
case Header:
|
case Header:
|
||||||
config.log("using Http Header signature");
|
|
||||||
|
|
||||||
String oauthHeader = api.getHeaderExtractor().extract(request);
|
String oauthHeader = api.getHeaderExtractor().extract(request);
|
||||||
request.addHeader(OAuthConstants.HEADER, oauthHeader);
|
request.addHeader(OAuthConstants.HEADER, oauthHeader);
|
||||||
break;
|
break;
|
||||||
case QueryString:
|
case QueryString:
|
||||||
config.log("using Querystring signature");
|
|
||||||
|
|
||||||
for (Map.Entry<String, String> entry : request.getOauthParameters().entrySet())
|
for (Map.Entry<String, String> entry : request.getOauthParameters().entrySet())
|
||||||
{
|
{
|
||||||
request.addQuerystringParameter(entry.getKey(), entry.getValue());
|
request.addQuerystringParameter(entry.getKey(), entry.getValue());
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ public class HMACSha1SignatureService implements SignatureService
|
|||||||
{
|
{
|
||||||
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, URLUtils.percentEncode(apiSecret) + '&' + URLUtils.percentEncode(tokenSecret));
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ public class PlaintextSignatureService implements SignatureService
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
Preconditions.checkEmptyString(apiSecret, "Api secret cant be null or empty string");
|
Preconditions.checkEmptyString(apiSecret, "Api secret cant be null or empty string");
|
||||||
return OAuthEncoder.encode(apiSecret) + '&' + OAuthEncoder.encode(tokenSecret);
|
return URLUtils.percentEncode(apiSecret) + '&' + URLUtils.percentEncode(tokenSecret);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -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,22 +1,94 @@
|
|||||||
package org.scribe.utils;
|
package org.scribe.utils;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author: Pablo Fernandez
|
* Utils for {@link Map} manipulation
|
||||||
|
*
|
||||||
|
* @author Pablo Fernandez
|
||||||
*/
|
*/
|
||||||
public class MapUtils
|
public class MapUtils
|
||||||
{
|
{
|
||||||
public static <K,V> String toString(Map<K,V> map)
|
private static final String EMPTY_STRING = "";
|
||||||
{
|
private static final String PAIR_SEPARATOR = "=";
|
||||||
if (map == null) return "";
|
private static final String PARAM_SEPARATOR = "&";
|
||||||
if (map.isEmpty()) return "{}";
|
|
||||||
|
|
||||||
StringBuilder result = new StringBuilder();
|
/**
|
||||||
for(Map.Entry<K,V> entry : map.entrySet())
|
* Sorts a Map
|
||||||
|
*
|
||||||
|
* @param map unsorted map
|
||||||
|
* @return sorted map
|
||||||
|
*/
|
||||||
|
public static final Map<String, String> sort(Map<String, String> map)
|
||||||
|
{
|
||||||
|
Preconditions.checkNotNull(map, "Cannot sort a null object.");
|
||||||
|
|
||||||
|
Map<String, String> sorted = new LinkedHashMap<String, String>();
|
||||||
|
for (String key : getSortedKeys(map))
|
||||||
{
|
{
|
||||||
result.append(String.format(", %s -> %s ", entry.getKey().toString(), entry.getValue().toString()));
|
sorted.put(key, map.get(key));
|
||||||
}
|
}
|
||||||
return "{" + result.substring(1) + "}";
|
return sorted;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static List<String> getSortedKeys(Map<String, String> map)
|
||||||
|
{
|
||||||
|
List<String> keys = new ArrayList<String>(map.keySet());
|
||||||
|
Collections.sort(keys);
|
||||||
|
return keys;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Form-urlDecodes and appends all keys from the source {@link Map} to the
|
||||||
|
* target {@link Map}
|
||||||
|
*
|
||||||
|
* @param source Map from where the keys get copied and decoded
|
||||||
|
* @param target Map where the decoded keys are copied to
|
||||||
|
*/
|
||||||
|
public static void decodeAndAppendEntries(Map<String, String> source, Map<String, String> target)
|
||||||
|
{
|
||||||
|
for (String key: source.keySet())
|
||||||
|
{
|
||||||
|
target.put(URLUtils.percentEncode(key), URLUtils.percentEncode(source.get(key)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Concats a key-value map into a querystring-like String
|
||||||
|
*
|
||||||
|
* @param params key-value map
|
||||||
|
* @return querystring-like String
|
||||||
|
*/
|
||||||
|
public static String concatSortedPercentEncodedParams(Map<String, String> params)
|
||||||
|
{
|
||||||
|
StringBuilder result = new StringBuilder();
|
||||||
|
for (String key : params.keySet())
|
||||||
|
{
|
||||||
|
result.append(key).append(PAIR_SEPARATOR);
|
||||||
|
result.append(params.get(key)).append(PARAM_SEPARATOR);
|
||||||
|
}
|
||||||
|
return result.toString().substring(0, result.length() - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses and form-urldecodes a querystring-like string into a map
|
||||||
|
*
|
||||||
|
* @param queryString querystring-like String
|
||||||
|
* @return a map with the form-urldecoded parameters
|
||||||
|
*/
|
||||||
|
public static Map<String, String> queryStringToMap(String queryString)
|
||||||
|
{
|
||||||
|
Map<String, String> result = new HashMap<String, String>();
|
||||||
|
if (queryString != null && queryString.length() > 0)
|
||||||
|
{
|
||||||
|
for (String param : queryString.split(PARAM_SEPARATOR))
|
||||||
|
{
|
||||||
|
String pair[] = param.split(PAIR_SEPARATOR);
|
||||||
|
String key = URLUtils.formURLDecode(pair[0]);
|
||||||
|
String value = pair.length > 1 ? URLUtils.formURLDecode(pair[1]) : EMPTY_STRING;
|
||||||
|
result.put(key, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -12,9 +12,7 @@ import org.scribe.model.OAuthConstants;
|
|||||||
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";
|
||||||
|
private static final Pattern URL_PATTERN = Pattern.compile("[a-zA-Z_-]+://\\S+");
|
||||||
// scheme = alpha *( alpha | digit | "+" | "-" | "." )
|
|
||||||
private static final Pattern URL_PATTERN = Pattern.compile("^[a-zA-Z][a-zA-Z0-9+.-]*://\\S+");
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks that an object is not null.
|
* Checks that an object is not null.
|
||||||
|
|||||||
@@ -0,0 +1,151 @@
|
|||||||
|
package org.scribe.utils;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
import java.net.*;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Utils to deal with URL and url-encodings
|
||||||
|
*
|
||||||
|
* @author Pablo Fernandez
|
||||||
|
*/
|
||||||
|
public class URLUtils
|
||||||
|
{
|
||||||
|
private static final String EMPTY_STRING = "";
|
||||||
|
private static final String UTF_8 = "UTF-8";
|
||||||
|
private static final String PAIR_SEPARATOR = "=";
|
||||||
|
private static final String PARAM_SEPARATOR = "&";
|
||||||
|
private static final char QUERY_STRING_SEPARATOR = '?';
|
||||||
|
|
||||||
|
private static final String ERROR_MSG = String.format("Cannot find specified encoding: %s", UTF_8);
|
||||||
|
|
||||||
|
private static final Set<EncodingRule> ENCODING_RULES;
|
||||||
|
|
||||||
|
static
|
||||||
|
{
|
||||||
|
Set<EncodingRule> rules = new HashSet<EncodingRule>();
|
||||||
|
rules.add(new EncodingRule("*","%2A"));
|
||||||
|
rules.add(new EncodingRule("+","%20"));
|
||||||
|
rules.add(new EncodingRule("%7E", "~"));
|
||||||
|
ENCODING_RULES = Collections.unmodifiableSet(rules);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Turns a map into a form-urlencoded string
|
||||||
|
*
|
||||||
|
* @param map any map
|
||||||
|
* @return form-url-encoded string
|
||||||
|
*/
|
||||||
|
public static String formURLEncodeMap(Map<String, String> map)
|
||||||
|
{
|
||||||
|
Preconditions.checkNotNull(map, "Cannot url-encode a null object");
|
||||||
|
return (map.size() <= 0) ? EMPTY_STRING : doFormUrlEncode(map);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String doFormUrlEncode(Map<String, String> map)
|
||||||
|
{
|
||||||
|
StringBuffer encodedString = new StringBuffer(map.size() * 20);
|
||||||
|
for (String key : map.keySet())
|
||||||
|
{
|
||||||
|
encodedString.append(PARAM_SEPARATOR).append(formURLEncode(key));
|
||||||
|
if(map.get(key) != null)
|
||||||
|
{
|
||||||
|
encodedString.append(PAIR_SEPARATOR).append(formURLEncode(map.get(key)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return encodedString.toString().substring(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Percent encodes a string
|
||||||
|
*
|
||||||
|
* @param string plain string
|
||||||
|
* @return percent encoded string
|
||||||
|
*/
|
||||||
|
public static String percentEncode(String string)
|
||||||
|
{
|
||||||
|
String encoded = formURLEncode(string);
|
||||||
|
for (EncodingRule rule : ENCODING_RULES)
|
||||||
|
{
|
||||||
|
encoded = rule.apply(encoded);
|
||||||
|
}
|
||||||
|
return encoded;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Translates a string into application/x-www-form-urlencoded format
|
||||||
|
*
|
||||||
|
* @param plain
|
||||||
|
* @return form-urlencoded string
|
||||||
|
*/
|
||||||
|
public static String formURLEncode(String string)
|
||||||
|
{
|
||||||
|
Preconditions.checkNotNull(string, "Cannot encode null string");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return URLEncoder.encode(string, UTF_8);
|
||||||
|
}
|
||||||
|
catch (UnsupportedEncodingException uee)
|
||||||
|
{
|
||||||
|
throw new IllegalStateException(ERROR_MSG, uee);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Decodes a application/x-www-form-urlencoded string
|
||||||
|
*
|
||||||
|
* @param string form-urlencoded string
|
||||||
|
* @return plain string
|
||||||
|
*/
|
||||||
|
public static String formURLDecode(String string)
|
||||||
|
{
|
||||||
|
Preconditions.checkNotNull(string, "Cannot decode null string");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return URLDecoder.decode(string, UTF_8);
|
||||||
|
}
|
||||||
|
catch (UnsupportedEncodingException uee)
|
||||||
|
{
|
||||||
|
throw new IllegalStateException(ERROR_MSG, uee);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Append given parameters to the query string of the url
|
||||||
|
*
|
||||||
|
* @param url the url to append parameters to
|
||||||
|
* @param params any map
|
||||||
|
* @return new url with parameters on query string
|
||||||
|
*/
|
||||||
|
public static String appendParametersToQueryString(String url, Map<String, String> params)
|
||||||
|
{
|
||||||
|
Preconditions.checkNotNull(url, "Cannot append to null URL");
|
||||||
|
String queryString = URLUtils.formURLEncodeMap(params);
|
||||||
|
if (queryString.equals(EMPTY_STRING))
|
||||||
|
{
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
url += url.indexOf(QUERY_STRING_SEPARATOR) != -1 ? PARAM_SEPARATOR : QUERY_STRING_SEPARATOR;
|
||||||
|
url += queryString;
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final class EncodingRule
|
||||||
|
{
|
||||||
|
private final String ch;
|
||||||
|
private final String toCh;
|
||||||
|
|
||||||
|
EncodingRule(String ch, String toCh)
|
||||||
|
{
|
||||||
|
this.ch = ch;
|
||||||
|
this.toCh = toCh;
|
||||||
|
}
|
||||||
|
|
||||||
|
String apply(String string) {
|
||||||
|
return string.replace(ch, toCh);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -46,9 +46,9 @@ public class ServiceBuilderTest
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=IllegalArgumentException.class)
|
@Test(expected=IllegalArgumentException.class)
|
||||||
public void shouldNotAcceptNullAsCallback()
|
public void shouldNotAcceptAnInvalidUrlAsCallback()
|
||||||
{
|
{
|
||||||
builder.provider(ApiMock.class).apiKey("key").apiSecret("secret").callback(null).build();
|
builder.provider(ApiMock.class).apiKey("key").apiSecret("secret").callback("example.com").build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -63,7 +63,8 @@ public class ServiceBuilderTest
|
|||||||
public static class ApiMock implements Api
|
public static class ApiMock implements Api
|
||||||
{
|
{
|
||||||
public static OAuthConfig config;
|
public static OAuthConfig config;
|
||||||
|
|
||||||
|
@Override
|
||||||
public OAuthService createService(OAuthConfig config)
|
public OAuthService createService(OAuthConfig config)
|
||||||
{
|
{
|
||||||
ApiMock.config = config;
|
ApiMock.config = config;
|
||||||
|
|||||||
@@ -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,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,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,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! :)");
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,62 +0,0 @@
|
|||||||
package org.scribe.examples;
|
|
||||||
|
|
||||||
import java.util.Scanner;
|
|
||||||
|
|
||||||
import org.scribe.builder.ServiceBuilder;
|
|
||||||
import org.scribe.builder.api.MeetupApi;
|
|
||||||
import org.scribe.model.OAuthRequest;
|
|
||||||
import org.scribe.model.Response;
|
|
||||||
import org.scribe.model.Token;
|
|
||||||
import org.scribe.model.Verb;
|
|
||||||
import org.scribe.model.Verifier;
|
|
||||||
import org.scribe.oauth.OAuthService;
|
|
||||||
|
|
||||||
public class MeetupExample
|
|
||||||
{
|
|
||||||
private static final String PROTECTED_RESOURCE_URL = "http://api.meetup.com/2/member/self";
|
|
||||||
|
|
||||||
public static void main(String[] args)
|
|
||||||
{
|
|
||||||
OAuthService service = new ServiceBuilder()
|
|
||||||
.provider(MeetupApi.class)
|
|
||||||
.apiKey("j1khkp0dus323ftve0sdcv6ffe")
|
|
||||||
.apiSecret("6s6gt6q59gvfjtsvgcmht62gq4")
|
|
||||||
.build();
|
|
||||||
Scanner in = new Scanner(System.in);
|
|
||||||
|
|
||||||
System.out.println("=== Meetup's OAuth Workflow ===");
|
|
||||||
System.out.println();
|
|
||||||
|
|
||||||
// Obtain the Request Token
|
|
||||||
System.out.println("Fetching the Request Token...");
|
|
||||||
Token requestToken = service.getRequestToken();
|
|
||||||
System.out.println("Got the Request Token!");
|
|
||||||
System.out.println();
|
|
||||||
|
|
||||||
System.out.println("Now go and authorize Scribe here:");
|
|
||||||
System.out.println(service.getAuthorizationUrl(requestToken));
|
|
||||||
System.out.println("And paste the verifier here");
|
|
||||||
System.out.print(">>");
|
|
||||||
Verifier verifier = new Verifier(in.nextLine());
|
|
||||||
System.out.println();
|
|
||||||
|
|
||||||
// Trade the Request Token and Verfier for the Access Token
|
|
||||||
System.out.println("Trading the Request Token for an Access Token...");
|
|
||||||
Token accessToken = service.getAccessToken(requestToken, verifier);
|
|
||||||
System.out.println("Got the Access Token!");
|
|
||||||
System.out.println("(if your curious it looks like this: " + accessToken + " )");
|
|
||||||
System.out.println();
|
|
||||||
|
|
||||||
// Now let's go and ask for a protected resource!
|
|
||||||
System.out.println("Now we're going to access a protected resource...");
|
|
||||||
OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL);
|
|
||||||
service.signRequest(accessToken, request);
|
|
||||||
Response response = request.send();
|
|
||||||
System.out.println("Got it! Lets see what we found...");
|
|
||||||
System.out.println();
|
|
||||||
System.out.println(response.getBody());
|
|
||||||
|
|
||||||
System.out.println();
|
|
||||||
System.out.println("Thats it man! Go and build something awesome with Scribe! :)");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,60 +0,0 @@
|
|||||||
package org.scribe.examples;
|
|
||||||
|
|
||||||
import java.util.Scanner;
|
|
||||||
|
|
||||||
import org.scribe.builder.*;
|
|
||||||
import org.scribe.builder.api.*;
|
|
||||||
import org.scribe.model.*;
|
|
||||||
import org.scribe.oauth.*;
|
|
||||||
|
|
||||||
public class Px500Example
|
|
||||||
{
|
|
||||||
private static final String PROTECTED_RESOURCE_URL = "https://api.500px.com/v1/";
|
|
||||||
|
|
||||||
public static void main(String[] args)
|
|
||||||
{
|
|
||||||
OAuthService service = new ServiceBuilder()
|
|
||||||
.provider(Px500Api.class)
|
|
||||||
.apiKey("your-api-key")
|
|
||||||
.apiSecret("your-api-secret")
|
|
||||||
.build();
|
|
||||||
Scanner in = new Scanner(System.in);
|
|
||||||
|
|
||||||
System.out.println("=== 500Px's OAuth Workflow ===");
|
|
||||||
System.out.println();
|
|
||||||
|
|
||||||
// Obtain the Request Token
|
|
||||||
System.out.println("Fetching the Request Token...");
|
|
||||||
Token requestToken = service.getRequestToken();
|
|
||||||
System.out.println("Got the Request Token!");
|
|
||||||
System.out.println();
|
|
||||||
|
|
||||||
System.out.println("Now go and authorize Scribe here:");
|
|
||||||
System.out.println(service.getAuthorizationUrl(requestToken));
|
|
||||||
System.out.println("And paste the verifier here");
|
|
||||||
System.out.print(">>");
|
|
||||||
Verifier verifier = new Verifier(in.nextLine());
|
|
||||||
System.out.println();
|
|
||||||
|
|
||||||
// Trade the Request Token and Verfier for the Access Token
|
|
||||||
System.out.println("Trading the Request Token for an Access Token...");
|
|
||||||
Token accessToken = service.getAccessToken(requestToken, verifier);
|
|
||||||
System.out.println("Got the Access Token!");
|
|
||||||
System.out.println("(if your curious it looks like this: " + accessToken + " )");
|
|
||||||
System.out.println();
|
|
||||||
|
|
||||||
// Now let's go and ask for a protected resource!
|
|
||||||
System.out.println("Now we're going to access a protected resource...");
|
|
||||||
OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL);
|
|
||||||
service.signRequest(accessToken, request);
|
|
||||||
Response response = request.send();
|
|
||||||
System.out.println("Got it! Lets see what we found...");
|
|
||||||
System.out.println();
|
|
||||||
System.out.println(response.getBody());
|
|
||||||
|
|
||||||
System.out.println();
|
|
||||||
System.out.println("Thats it man! Go and build something awesome with Scribe! :)");
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,108 +0,0 @@
|
|||||||
package org.scribe.examples;
|
|
||||||
|
|
||||||
import org.scribe.builder.*;
|
|
||||||
import org.scribe.builder.api.*;
|
|
||||||
import org.scribe.model.*;
|
|
||||||
import org.scribe.oauth.*;
|
|
||||||
import java.nio.charset.*;
|
|
||||||
import java.security.*;
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
public class RenrenExample
|
|
||||||
{
|
|
||||||
private static final String NETWORK_NAME = "Renren";
|
|
||||||
private static final String PROTECTED_RESOURCE_URL = "http://api.renren.com/restserver.do";
|
|
||||||
private static final Token EMPTY_TOKEN = null;
|
|
||||||
|
|
||||||
public static void main(String[] args)
|
|
||||||
{
|
|
||||||
// Replace these with your own api key and secret
|
|
||||||
String apiKey = "your api key";
|
|
||||||
String apiSecret = "your api secret";
|
|
||||||
OAuthService service = new ServiceBuilder()
|
|
||||||
.provider(RenrenApi.class)
|
|
||||||
.apiKey(apiKey)
|
|
||||||
.apiSecret(apiSecret)
|
|
||||||
.scope("status_update publish_feed")
|
|
||||||
.callback("http://your.doman.com/oauth/renren")
|
|
||||||
.build();
|
|
||||||
Scanner in = new Scanner(System.in);
|
|
||||||
|
|
||||||
System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ===");
|
|
||||||
System.out.println();
|
|
||||||
|
|
||||||
// Obtain the Authorization URL
|
|
||||||
System.out.println("Fetching the Authorization URL...");
|
|
||||||
String authorizationUrl = service.getAuthorizationUrl(EMPTY_TOKEN);
|
|
||||||
System.out.println("Got the Authorization URL!");
|
|
||||||
System.out.println("Now go and authorize Scribe here:");
|
|
||||||
System.out.println(authorizationUrl);
|
|
||||||
System.out.println("And paste the authorization code here");
|
|
||||||
System.out.print(">>");
|
|
||||||
Verifier verifier = new Verifier(in.nextLine());
|
|
||||||
System.out.println();
|
|
||||||
|
|
||||||
// Trade the Request Token and Verfier for the Access Token
|
|
||||||
System.out.println("Trading the Request Token for an Access Token...");
|
|
||||||
Token accessToken = service.getAccessToken(EMPTY_TOKEN, verifier);
|
|
||||||
System.out.println("Got the Access Token!");
|
|
||||||
System.out.println("(if your curious it looks like this: " + accessToken + " )");
|
|
||||||
System.out.println();
|
|
||||||
|
|
||||||
// Now let's go and ask for a protected resource!
|
|
||||||
System.out.println("Now we're going to access a protected resource...");
|
|
||||||
OAuthRequest request = new OAuthRequest(Verb.POST, PROTECTED_RESOURCE_URL);
|
|
||||||
Map<String, String> parameters = new HashMap<String, String>();
|
|
||||||
parameters.put("method", "users.getInfo");
|
|
||||||
parameters.put("format", "json");
|
|
||||||
parameters.put("v", "1.0");
|
|
||||||
|
|
||||||
List<String> sigString = new ArrayList<String>(parameters.size() + 1);
|
|
||||||
for (Map.Entry<String, String> entry : parameters.entrySet())
|
|
||||||
{
|
|
||||||
request.addQuerystringParameter(entry.getKey(), entry.getValue());
|
|
||||||
sigString.add(String.format("%s=%s", entry.getKey(), entry.getValue()));
|
|
||||||
}
|
|
||||||
sigString.add(String.format("%s=%s", OAuthConstants.ACCESS_TOKEN, accessToken.getToken()));
|
|
||||||
Collections.sort(sigString);
|
|
||||||
StringBuilder b = new StringBuilder();
|
|
||||||
for (String param : sigString)
|
|
||||||
{
|
|
||||||
b.append(param);
|
|
||||||
}
|
|
||||||
b.append(apiSecret);
|
|
||||||
System.out.println("Sig string: " + b.toString());
|
|
||||||
request.addQuerystringParameter("sig", md5(b.toString()));
|
|
||||||
service.signRequest(accessToken, request);
|
|
||||||
Response response = request.send();
|
|
||||||
System.out.println("Got it! Lets see what we found...");
|
|
||||||
System.out.println();
|
|
||||||
System.out.println(response.getCode());
|
|
||||||
System.out.println(response.getBody());
|
|
||||||
|
|
||||||
System.out.println();
|
|
||||||
System.out.println("Thats it man! Go and build something awesome with Scribe! :)");
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String md5(String orgString)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
java.security.MessageDigest md = MessageDigest.getInstance("MD5");
|
|
||||||
byte[] array = md.digest(orgString.getBytes(Charset.forName("UTF-8")));
|
|
||||||
StringBuffer sb = new StringBuffer();
|
|
||||||
for (int i = 0; i < array.length; ++i)
|
|
||||||
{
|
|
||||||
sb.append(Integer.toHexString((array[i] & 0xFF) | 0x100).substring(1, 3));
|
|
||||||
}
|
|
||||||
return sb.toString();
|
|
||||||
}
|
|
||||||
catch (NoSuchAlgorithmException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,63 +0,0 @@
|
|||||||
package org.scribe.examples;
|
|
||||||
|
|
||||||
import org.scribe.builder.*;
|
|
||||||
import org.scribe.builder.api.*;
|
|
||||||
import org.scribe.model.*;
|
|
||||||
import org.scribe.oauth.*;
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
public class SinaWeibo2Example
|
|
||||||
{
|
|
||||||
private static final String NETWORK_NAME = "SinaWeibo";
|
|
||||||
private static final String PROTECTED_RESOURCE_URL = "https://api.weibo.com/2/account/get_uid.json";
|
|
||||||
private static final Token EMPTY_TOKEN = null;
|
|
||||||
|
|
||||||
public static void main(String[] args)
|
|
||||||
{
|
|
||||||
// Replace these with your own api key and secret
|
|
||||||
String apiKey = "your_api_key";
|
|
||||||
String apiSecret = "your_api_secret";
|
|
||||||
OAuthService service = new ServiceBuilder()
|
|
||||||
.provider(SinaWeiboApi20.class)
|
|
||||||
.apiKey(apiKey)
|
|
||||||
.apiSecret(apiSecret)
|
|
||||||
.callback("http://www.dajie.com/oauth/sina")
|
|
||||||
.build();
|
|
||||||
Scanner in = new Scanner(System.in);
|
|
||||||
|
|
||||||
System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ===");
|
|
||||||
System.out.println();
|
|
||||||
|
|
||||||
// Obtain the Authorization URL
|
|
||||||
System.out.println("Fetching the Authorization URL...");
|
|
||||||
String authorizationUrl = service.getAuthorizationUrl(EMPTY_TOKEN);
|
|
||||||
System.out.println("Got the Authorization URL!");
|
|
||||||
System.out.println("Now go and authorize Scribe here:");
|
|
||||||
System.out.println(authorizationUrl);
|
|
||||||
System.out.println("And paste the authorization code here");
|
|
||||||
System.out.print(">>");
|
|
||||||
Verifier verifier = new Verifier(in.nextLine());
|
|
||||||
System.out.println();
|
|
||||||
|
|
||||||
// Trade the Request Token and Verifier for the Access Token
|
|
||||||
System.out.println("Trading the Request Token for an Access Token...");
|
|
||||||
Token accessToken = service.getAccessToken(EMPTY_TOKEN, verifier);
|
|
||||||
System.out.println("Got the Access Token!");
|
|
||||||
System.out.println("(if your curious it looks like this: " + accessToken + " )");
|
|
||||||
System.out.println();
|
|
||||||
|
|
||||||
// Now let's go and ask for a protected resource!
|
|
||||||
System.out.println("Now we're going to access a protected resource...");
|
|
||||||
OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL);
|
|
||||||
service.signRequest(accessToken, request);
|
|
||||||
Response response = request.send();
|
|
||||||
System.out.println("Got it! Lets see what we found...");
|
|
||||||
System.out.println();
|
|
||||||
System.out.println(response.getCode());
|
|
||||||
System.out.println(response.getBody());
|
|
||||||
|
|
||||||
System.out.println();
|
|
||||||
System.out.println("Thats it man! Go and build something awesome with Scribe! :)");
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,61 +0,0 @@
|
|||||||
package org.scribe.examples;
|
|
||||||
|
|
||||||
import java.util.Scanner;
|
|
||||||
|
|
||||||
import org.scribe.builder.*;
|
|
||||||
import org.scribe.builder.api.*;
|
|
||||||
import org.scribe.model.*;
|
|
||||||
import org.scribe.oauth.*;
|
|
||||||
|
|
||||||
public class SkyrockExample
|
|
||||||
{
|
|
||||||
private static final String PROTECTED_RESOURCE_URL = "https://api.skyrock.com/v2/user/get.json";
|
|
||||||
|
|
||||||
public static void main(String[] args)
|
|
||||||
{
|
|
||||||
OAuthService service = new ServiceBuilder()
|
|
||||||
.provider(SkyrockApi.class)
|
|
||||||
.apiKey("your-api-key")
|
|
||||||
.apiSecret("your-api-secret")
|
|
||||||
.build();
|
|
||||||
Scanner in = new Scanner(System.in);
|
|
||||||
|
|
||||||
System.out.println("=== Skyrock's OAuth Workflow ===");
|
|
||||||
System.out.println();
|
|
||||||
|
|
||||||
// Obtain the Request Token
|
|
||||||
System.out.println("Fetching the Request Token...");
|
|
||||||
Token requestToken = service.getRequestToken();
|
|
||||||
System.out.println("Got the Request Token!");
|
|
||||||
System.out.println();
|
|
||||||
|
|
||||||
System.out.println("Now go and authorize Scribe here:");
|
|
||||||
System.out.println(service.getAuthorizationUrl(requestToken));
|
|
||||||
System.out.println("And paste the verifier here");
|
|
||||||
System.out.print(">>");
|
|
||||||
Verifier verifier = new Verifier(in.nextLine());
|
|
||||||
System.out.println();
|
|
||||||
|
|
||||||
// Trade the Request Token and Verfier for the Access Token
|
|
||||||
System.out.println("Trading the Request Token for an Access Token...");
|
|
||||||
Token accessToken = service.getAccessToken(requestToken, verifier);
|
|
||||||
System.out.println("Got the Access Token!");
|
|
||||||
System.out.println("(if your curious it looks like this: " + accessToken + " )");
|
|
||||||
System.out.println();
|
|
||||||
|
|
||||||
// Now let's go and ask for a protected resource!
|
|
||||||
System.out.println("Now we're going to access a protected resource...");
|
|
||||||
OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL);
|
|
||||||
service.signRequest(accessToken, request);
|
|
||||||
Response response = request.send();
|
|
||||||
System.out.println("Got it! Lets see what we found...");
|
|
||||||
System.out.println();
|
|
||||||
System.out.println(response.getCode());
|
|
||||||
System.out.println(response.getBody());
|
|
||||||
|
|
||||||
System.out.println();
|
|
||||||
System.out.println("Thats it man! Go and build something awesome with Scribe! :)");
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -9,7 +9,7 @@ import org.scribe.oauth.*;
|
|||||||
|
|
||||||
public class TwitterExample
|
public class TwitterExample
|
||||||
{
|
{
|
||||||
private static final String PROTECTED_RESOURCE_URL = "https://api.twitter.com/1/statuses/update.json";
|
private static final String PROTECTED_RESOURCE_URL = "http://api.twitter.com/1/account/verify_credentials.xml";
|
||||||
|
|
||||||
public static void main(String[] args)
|
public static void main(String[] args)
|
||||||
{
|
{
|
||||||
@@ -45,8 +45,7 @@ public class TwitterExample
|
|||||||
|
|
||||||
// Now let's go and ask for a protected resource!
|
// Now let's go and ask for a protected resource!
|
||||||
System.out.println("Now we're going to access a protected resource...");
|
System.out.println("Now we're going to access a protected resource...");
|
||||||
OAuthRequest request = new OAuthRequest(Verb.POST, PROTECTED_RESOURCE_URL);
|
OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL);
|
||||||
request.addBodyParameter("status", "this is sparta! *");
|
|
||||||
service.signRequest(accessToken, request);
|
service.signRequest(accessToken, request);
|
||||||
Response response = request.send();
|
Response response = request.send();
|
||||||
System.out.println("Got it! Lets see what we found...");
|
System.out.println("Got it! Lets see what we found...");
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ public class BaseStringExtractorTest
|
|||||||
OAuthRequest request = new OAuthRequest(Verb.GET, "http://example.com");
|
OAuthRequest request = new OAuthRequest(Verb.GET, "http://example.com");
|
||||||
extractor.extract(request);
|
extractor.extract(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldProperlyEncodeSpaces()
|
public void shouldProperlyEncodeSpaces()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -35,15 +35,6 @@ public class TokenExtractor20Test
|
|||||||
assertEquals("", extracted.getSecret());
|
assertEquals("", extracted.getSecret());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void shouldExtractTokenFromResponseWithManyParameters()
|
|
||||||
{
|
|
||||||
String response = "access_token=foo1234&other_stuff=yeah_we_have_this_too&number=42";
|
|
||||||
Token extracted = extractor.extract(response);
|
|
||||||
assertEquals("foo1234", extracted.getToken());
|
|
||||||
assertEquals("", extracted.getSecret());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test(expected = OAuthException.class)
|
@Test(expected = OAuthException.class)
|
||||||
public void shouldThrowExceptionIfTokenIsAbsent()
|
public void shouldThrowExceptionIfTokenIsAbsent()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -43,15 +43,6 @@ public class TokenExtractorTest
|
|||||||
assertEquals("hh5s93j4hdidpola", extracted.getToken());
|
assertEquals("hh5s93j4hdidpola", extracted.getToken());
|
||||||
assertEquals("hdhd0244k9j7ao03", extracted.getSecret());
|
assertEquals("hdhd0244k9j7ao03", extracted.getSecret());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void shouldExtractTokenWithEmptySecret()
|
|
||||||
{
|
|
||||||
String response = "oauth_token=hh5s93j4hdidpola&oauth_token_secret=";
|
|
||||||
Token extracted = extractor.extract(response);
|
|
||||||
assertEquals("hh5s93j4hdidpola", extracted.getToken());
|
|
||||||
assertEquals("", extracted.getSecret());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test(expected = OAuthException.class)
|
@Test(expected = OAuthException.class)
|
||||||
public void shouldThrowExceptionIfTokenIsAbsent()
|
public void shouldThrowExceptionIfTokenIsAbsent()
|
||||||
|
|||||||
@@ -22,12 +22,6 @@ public class ConnectionStub extends HttpURLConnection
|
|||||||
headers.put(key, value);
|
headers.put(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getRequestProperty(String s)
|
|
||||||
{
|
|
||||||
return headers.get(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Map<String, String> getHeaders()
|
public Map<String, String> getHeaders()
|
||||||
{
|
{
|
||||||
return headers;
|
return headers;
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package org.scribe.model;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
import org.junit.*;
|
||||||
|
|
||||||
|
public class OAuthConfigTest
|
||||||
|
{
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldReturnDefaultValuesIfNotSet()
|
||||||
|
{
|
||||||
|
OAuthConfig config = new OAuthConfig("key", "secret");
|
||||||
|
assertEquals(OAuthConstants.OUT_OF_BAND, config.getCallback());
|
||||||
|
assertEquals(SignatureType.Header, config.getSignatureType());
|
||||||
|
assertFalse(config.hasScope());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldOverrideDefaultsIfSet()
|
||||||
|
{
|
||||||
|
OAuthConfig config = new OAuthConfig("key", "secret", "http://callback", SignatureType.Header, "scope");
|
||||||
|
assertEquals("http://callback", config.getCallback());
|
||||||
|
assertEquals("key", config.getApiKey());
|
||||||
|
assertEquals("secret", config.getApiSecret());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,91 +0,0 @@
|
|||||||
package org.scribe.model;
|
|
||||||
|
|
||||||
import org.junit.Assert;
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.junit.Assert.assertNotSame;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author: Pablo Fernandez
|
|
||||||
*/
|
|
||||||
public class ParameterListTest
|
|
||||||
{
|
|
||||||
private ParameterList params;
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void setup()
|
|
||||||
{
|
|
||||||
this.params = new ParameterList();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
|
||||||
public void shouldThrowExceptionWhenAppendingNullMapToQuerystring()
|
|
||||||
{
|
|
||||||
String url = null;
|
|
||||||
params.appendTo(url);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void shouldAppendNothingToQuerystringIfGivenEmptyMap()
|
|
||||||
{
|
|
||||||
String url = "http://www.example.com";
|
|
||||||
Assert.assertEquals(url, params.appendTo(url));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void shouldAppendParametersToSimpleUrl()
|
|
||||||
{
|
|
||||||
String url = "http://www.example.com";
|
|
||||||
String expectedUrl = "http://www.example.com?param1=value1¶m2=value%20with%20spaces";
|
|
||||||
|
|
||||||
params.add("param1", "value1");
|
|
||||||
params.add("param2", "value with spaces");
|
|
||||||
|
|
||||||
url = params.appendTo(url);
|
|
||||||
Assert.assertEquals(url, expectedUrl);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void shouldAppendParametersToUrlWithQuerystring()
|
|
||||||
{
|
|
||||||
String url = "http://www.example.com?already=present";
|
|
||||||
String expectedUrl = "http://www.example.com?already=present¶m1=value1¶m2=value%20with%20spaces";
|
|
||||||
|
|
||||||
params.add("param1", "value1");
|
|
||||||
params.add("param2", "value with spaces");
|
|
||||||
|
|
||||||
url = params.appendTo(url);
|
|
||||||
Assert.assertEquals(url, expectedUrl);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void shouldProperlySortParameters()
|
|
||||||
{
|
|
||||||
params.add("param1", "v1");
|
|
||||||
params.add("param6", "v2");
|
|
||||||
params.add("a_param", "v3");
|
|
||||||
params.add("param2", "v4");
|
|
||||||
Assert.assertEquals("a_param=v3¶m1=v1¶m2=v4¶m6=v2", params.sort().asFormUrlEncodedString());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void shouldProperlySortParametersWithTheSameName()
|
|
||||||
{
|
|
||||||
params.add("param1", "v1");
|
|
||||||
params.add("param6", "v2");
|
|
||||||
params.add("a_param", "v3");
|
|
||||||
params.add("param1", "v4");
|
|
||||||
Assert.assertEquals("a_param=v3¶m1=v1¶m1=v4¶m6=v2", params.sort().asFormUrlEncodedString());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void shouldNotModifyTheOriginalParameterList()
|
|
||||||
{
|
|
||||||
params.add("param1", "v1");
|
|
||||||
params.add("param6", "v2");
|
|
||||||
|
|
||||||
assertNotSame(params, params.sort());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -6,6 +6,7 @@ import org.junit.*;
|
|||||||
|
|
||||||
public class RequestTest
|
public class RequestTest
|
||||||
{
|
{
|
||||||
|
|
||||||
private Request getRequest;
|
private Request getRequest;
|
||||||
private Request postRequest;
|
private Request postRequest;
|
||||||
private ConnectionStub connection;
|
private ConnectionStub connection;
|
||||||
@@ -34,7 +35,8 @@ public class RequestTest
|
|||||||
{
|
{
|
||||||
assertEquals(2, getRequest.getQueryStringParams().size());
|
assertEquals(2, getRequest.getQueryStringParams().size());
|
||||||
assertEquals(0, postRequest.getQueryStringParams().size());
|
assertEquals(0, postRequest.getQueryStringParams().size());
|
||||||
assertTrue(getRequest.getQueryStringParams().contains(new Parameter("qsparam", "value")));
|
assertTrue(getRequest.getQueryStringParams().containsKey("qsparam"));
|
||||||
|
assertTrue(getRequest.getQueryStringParams().get("qsparam").equals("value"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -50,7 +52,7 @@ public class RequestTest
|
|||||||
@Test
|
@Test
|
||||||
public void shouldSetBodyParamsAndAddContentLength()
|
public void shouldSetBodyParamsAndAddContentLength()
|
||||||
{
|
{
|
||||||
assertEquals("param=value¶m%20with%20spaces=value%20with%20spaces", postRequest.getBodyContents());
|
assertEquals("param=value¶m+with+spaces=value+with+spaces", postRequest.getBodyContents());
|
||||||
postRequest.send();
|
postRequest.send();
|
||||||
assertTrue(connection.getHeaders().containsKey("Content-Length"));
|
assertTrue(connection.getHeaders().containsKey("Content-Length"));
|
||||||
}
|
}
|
||||||
@@ -73,56 +75,9 @@ public class RequestTest
|
|||||||
assertEquals(3, request.getQueryStringParams().size());
|
assertEquals(3, request.getQueryStringParams().size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void shouldReturnTheCompleteUrl()
|
|
||||||
{
|
|
||||||
Request request = new Request(Verb.GET, "http://example.com?one=val");
|
|
||||||
request.addQuerystringParameter("two", "other val");
|
|
||||||
request.addQuerystringParameter("more", "params");
|
|
||||||
assertEquals("http://example.com?one=val&two=other%20val&more=params", request.getCompleteUrl());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldHandleQueryStringSpaceEncodingProperly()
|
public void shouldHandleQueryStringSpaceEncodingProperly()
|
||||||
{
|
{
|
||||||
assertTrue(getRequest.getQueryStringParams().contains(new Parameter("other param","value with spaces")));
|
assertTrue(getRequest.getQueryStringParams().get("other param").equals("value with spaces"));
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void shouldAutomaticallyAddContentTypeForPostRequestsWithBytePayload()
|
|
||||||
{
|
|
||||||
postRequest.addPayload("PAYLOAD".getBytes());
|
|
||||||
postRequest.send();
|
|
||||||
assertEquals(Request.DEFAULT_CONTENT_TYPE, connection.getHeaders().get("Content-Type"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void shouldAutomaticallyAddContentTypeForPostRequestsWithStringPayload()
|
|
||||||
{
|
|
||||||
postRequest.addPayload("PAYLOAD");
|
|
||||||
postRequest.send();
|
|
||||||
assertEquals(Request.DEFAULT_CONTENT_TYPE, connection.getHeaders().get("Content-Type"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void shouldAutomaticallyAddContentTypeForPostRequestsWithBodyParameters()
|
|
||||||
{
|
|
||||||
postRequest.send();
|
|
||||||
assertEquals(Request.DEFAULT_CONTENT_TYPE, connection.getHeaders().get("Content-Type"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void shouldBeAbleToOverrideItsContentType()
|
|
||||||
{
|
|
||||||
postRequest.addHeader("Content-Type", "my-content-type");
|
|
||||||
postRequest.send();
|
|
||||||
assertEquals("my-content-type", connection.getHeaders().get("Content-Type"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void shouldNotAddContentTypeForGetRequests()
|
|
||||||
{
|
|
||||||
getRequest.send();
|
|
||||||
assertFalse(connection.getHeaders().containsKey("Content-Type"));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,66 +0,0 @@
|
|||||||
package org.scribe.services;
|
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
|
||||||
|
|
||||||
import org.junit.*;
|
|
||||||
import org.apache.commons.codec.binary.*;
|
|
||||||
import java.security.*;
|
|
||||||
import java.security.spec.*;
|
|
||||||
|
|
||||||
public class RSASha1SignatureServiceTest
|
|
||||||
{
|
|
||||||
|
|
||||||
RSASha1SignatureService service = new RSASha1SignatureService(getPrivateKey());
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void shouldReturnSignatureMethodString()
|
|
||||||
{
|
|
||||||
String expected = "RSA-SHA1";
|
|
||||||
assertEquals(expected, service.getSignatureMethod());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void shouldReturnSignature()
|
|
||||||
{
|
|
||||||
String apiSecret = "api secret";
|
|
||||||
String tokenSecret = "token secret";
|
|
||||||
String baseString = "base string";
|
|
||||||
String signature = "LUNRzQAlpdNyM9mLXm96Va6g/qVNnEAb7p7K1KM0g8IopOFQJPoOO7cvppgt7w3QyhijWJnCmvqXaaIAGrqvdyr3fIzBULh8D/iZQUNLMi08GCOA34P81XBvsc7A5uJjPDsGhJg2MzoVJ8nWJhU/lMMk4c92S1WGskeoDofRwpo=";
|
|
||||||
assertEquals(signature, service.getSignature(baseString, apiSecret, tokenSecret));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*Created primary key using openssl.
|
|
||||||
*
|
|
||||||
* openssl req -x509 -nodes -days 365 -newkey rsa:1024 -sha1 -subj '/C=GB/ST=/L=Manchester/CN=www.example.com' -keyout myrsakey.pem -out /tmp/myrsacert.pem
|
|
||||||
* openssl pkcs8 -in myrsakey.pem -topk8 -nocrypt -out myrsakey.pk8
|
|
||||||
*/
|
|
||||||
private static PrivateKey getPrivateKey()
|
|
||||||
{
|
|
||||||
String str = "MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAMPQ5BCMxlUq2TYy\n"+
|
|
||||||
"iRIoEUsz6HGTJhHuasS2nx1Se4Co3lxwxyubVdFj8AuhHNJSmJvjlpbTsGOjLZpr\n"+
|
|
||||||
"HyDEDdJmf1Fensh1MhUnBZ4a7uLrZrKzFHHJdamX9pxapB89vLeHlCot9hVXdrZH\n"+
|
|
||||||
"nNtg6FdmRKH/8gbs8iDyIayFvzYDAgMBAAECgYA+c9MpTBy9cQsR9BAvkEPjvkx2\n"+
|
|
||||||
"XL4ZnfbDgpNA4Nuu7yzsQrPjPomiXMNkkiAFHH67yVxwAlgRjyuuQlgNNTpKvyQt\n"+
|
|
||||||
"XcHxffnU0820VmE23M+L7jg2TlB3+rUnEDmDvCoyjlwGDR6lNb7t7Fgg2iR+iaov\n"+
|
|
||||||
"0iVzz+l9w0slRlyGsQJBAPWXW2m3NmFgqfDxtw8fsKC2y8o17/cnPjozRGtWb8LQ\n"+
|
|
||||||
"g3VCb8kbOFHOYNGazq3M7+wD1qILF2h/HecgK9eQrZ0CQQDMHXoJMfKKbrFrTKgE\n"+
|
|
||||||
"zyggO1gtuT5OXYeFewMEb5AbDI2FfSc2YP7SHij8iQ2HdukBrbTmi6qxh3HmIR58\n"+
|
|
||||||
"I/AfAkEA0Y9vr0tombsUB8cZv0v5OYoBZvCTbMANtzfb4AOHpiKqqbohDOevLQ7/\n"+
|
|
||||||
"SpvgVCmVaDz2PptcRAyEBZ5MCssneQJAB2pmvaDH7Ambfod5bztLfOhLCtY5EkXJ\n"+
|
|
||||||
"n6rZcDbRaHorRhdG7m3VtDKOUKZ2DF7glkQGV33phKukErVPUzlHBwJAScD9TqaG\n"+
|
|
||||||
"wJ3juUsVtujV23SnH43iMggXT7m82STpPGam1hPfmqu2Z0niePFo927ogQ7H1EMJ\n"+
|
|
||||||
"UHgqXmuvk2X/Ww==";
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
KeyFactory fac = KeyFactory.getInstance("RSA");
|
|
||||||
PKCS8EncodedKeySpec privKeySpec = new PKCS8EncodedKeySpec(Base64.decodeBase64(str.getBytes()));
|
|
||||||
return fac.generatePrivate(privKeySpec);
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,35 +1,53 @@
|
|||||||
package org.scribe.utils;
|
package org.scribe.utils;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
import org.junit.*;
|
import org.junit.*;
|
||||||
|
|
||||||
/**
|
|
||||||
* @author: Pablo Fernandez
|
|
||||||
*/
|
|
||||||
public class MapUtilsTest
|
public class MapUtilsTest
|
||||||
{
|
{
|
||||||
|
|
||||||
@Test
|
private Map<String, String> unsorted;
|
||||||
public void shouldPrettyPrintMap()
|
|
||||||
|
@Before
|
||||||
|
public void setup()
|
||||||
{
|
{
|
||||||
Map<Integer, String> map = new HashMap<Integer, String>();
|
unsorted = new LinkedHashMap<String, String>();
|
||||||
map.put(1, "one");
|
unsorted.put("d", "fourth");
|
||||||
map.put(2, "two");
|
unsorted.put("a", "first");
|
||||||
map.put(3, "three");
|
unsorted.put("c", "third");
|
||||||
map.put(4, "four");
|
unsorted.put("b", "second");
|
||||||
Assert.assertEquals("{ 1 -> one , 2 -> two , 3 -> three , 4 -> four }", MapUtils.toString(map));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldHandleEmptyMap()
|
public void shouldSortMap()
|
||||||
{
|
{
|
||||||
Map<Integer, String> map = new HashMap<Integer, String>();
|
Map<String, String> sorted = MapUtils.sort(unsorted);
|
||||||
Assert.assertEquals("{}", MapUtils.toString(map));
|
List<String> values = new ArrayList<String>(sorted.values());
|
||||||
|
assertEquals("first", values.get(0));
|
||||||
|
assertEquals("second", values.get(1));
|
||||||
|
assertEquals("third", values.get(2));
|
||||||
|
assertEquals("fourth", values.get(3));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldHandleNullInputs()
|
public void shouldNotModifyTheOriginalMap()
|
||||||
{
|
{
|
||||||
Assert.assertEquals("", MapUtils.toString(null));
|
Map<String, String> sorted = MapUtils.sort(unsorted);
|
||||||
|
assertNotSame(sorted, unsorted);
|
||||||
|
|
||||||
|
List<String> values = new ArrayList<String>(unsorted.values());
|
||||||
|
assertEquals("fourth", values.get(0));
|
||||||
|
assertEquals("first", values.get(1));
|
||||||
|
assertEquals("third", values.get(2));
|
||||||
|
assertEquals("second", values.get(3));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
public void shouldThrowExceptionForNullMap()
|
||||||
|
{
|
||||||
|
MapUtils.sort(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,70 +0,0 @@
|
|||||||
package org.scribe.utils;
|
|
||||||
|
|
||||||
import org.junit.*;
|
|
||||||
import static org.junit.Assert.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author: Pablo Fernandez
|
|
||||||
*/
|
|
||||||
public class OAuthEncoderTest
|
|
||||||
{
|
|
||||||
@Test
|
|
||||||
public void shouldPercentEncodeString()
|
|
||||||
{
|
|
||||||
String plain = "this is a test &^";
|
|
||||||
String encoded = "this%20is%20a%20test%20%26%5E";
|
|
||||||
assertEquals(encoded, OAuthEncoder.encode(plain));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void shouldFormURLDecodeString()
|
|
||||||
{
|
|
||||||
String encoded = "this+is+a+test+%26%5E";
|
|
||||||
String plain = "this is a test &^";
|
|
||||||
assertEquals(plain, OAuthEncoder.decode(encoded));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void shouldPercentEncodeAllSpecialCharacters()
|
|
||||||
{
|
|
||||||
String plain = "!*'();:@&=+$,/?#[]";
|
|
||||||
String encoded = "%21%2A%27%28%29%3B%3A%40%26%3D%2B%24%2C%2F%3F%23%5B%5D";
|
|
||||||
assertEquals(encoded, OAuthEncoder.encode(plain));
|
|
||||||
assertEquals(plain, OAuthEncoder.decode(encoded));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void shouldNotPercentEncodeReservedCharacters()
|
|
||||||
{
|
|
||||||
String plain = "abcde123456-._~";
|
|
||||||
String encoded = plain;
|
|
||||||
assertEquals(encoded, OAuthEncoder.encode(plain));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
|
||||||
public void shouldThrowExceptionIfStringToEncodeIsNull()
|
|
||||||
{
|
|
||||||
String toEncode = null;
|
|
||||||
OAuthEncoder.encode(toEncode);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
|
||||||
public void shouldThrowExceptionIfStringToDecodeIsNull()
|
|
||||||
{
|
|
||||||
String toDecode = null;
|
|
||||||
OAuthEncoder.decode(toDecode);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void shouldPercentEncodeCorrectlyTwitterCodingExamples()
|
|
||||||
{
|
|
||||||
// These tests are part of the Twitter dev examples here -> https://dev.twitter.com/docs/auth/percent-encoding-parameters
|
|
||||||
String sources[] = {"Ladies + Gentlemen", "An encoded string!", "Dogs, Cats & Mice"};
|
|
||||||
String encoded[] = {"Ladies%20%2B%20Gentlemen", "An%20encoded%20string%21", "Dogs%2C%20Cats%20%26%20Mice"};
|
|
||||||
|
|
||||||
for(int i = 0; i < sources.length; i++)
|
|
||||||
{
|
|
||||||
Assert.assertEquals(encoded[i], OAuthEncoder.encode(sources[i]));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -43,25 +43,16 @@ public class PreconditionsTest
|
|||||||
Preconditions.checkValidUrl(null, ERROR_MSG);
|
Preconditions.checkValidUrl(null, ERROR_MSG);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void shouldAllowValidUrls()
|
public void shouldAllowValidUrls()
|
||||||
{
|
{
|
||||||
Preconditions.checkValidUrl("http://www.example.com", ERROR_MSG);
|
Preconditions.checkValidUrl("http://www.example.com", ERROR_MSG);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void shouldAllowSSLUrls()
|
public void shouldAllowSSLUrls()
|
||||||
{
|
{
|
||||||
Preconditions.checkValidUrl("https://www.example.com", ERROR_MSG);
|
Preconditions.checkValidUrl("https://www.example.com", ERROR_MSG);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void shouldAllowSpecialCharsInScheme()
|
|
||||||
{
|
|
||||||
Preconditions.checkValidUrl("custom+9.3-1://www.example.com", ERROR_MSG);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void shouldAllowNonStandarProtocolsForAndroid()
|
public void shouldAllowNonStandarProtocolsForAndroid()
|
||||||
{
|
{
|
||||||
Preconditions.checkValidUrl("x-url-custom://www.example.com", ERROR_MSG);
|
Preconditions.checkValidUrl("x-url-custom://www.example.com", ERROR_MSG);
|
||||||
@@ -73,13 +64,6 @@ public class PreconditionsTest
|
|||||||
Preconditions.checkValidUrl("$weird*://www.example.com", ERROR_MSG);
|
Preconditions.checkValidUrl("$weird*://www.example.com", ERROR_MSG);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
|
||||||
public void shouldNotAllowUnderscoreInScheme()
|
|
||||||
{
|
|
||||||
Preconditions.checkValidUrl("http_custom://www.example.com", ERROR_MSG);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void shouldAllowOutOfBandAsValidCallbackValue()
|
public void shouldAllowOutOfBandAsValidCallbackValue()
|
||||||
{
|
{
|
||||||
Preconditions.checkValidOAuthCallback("oob", ERROR_MSG);
|
Preconditions.checkValidOAuthCallback("oob", ERROR_MSG);
|
||||||
|
|||||||
@@ -0,0 +1,166 @@
|
|||||||
|
package org.scribe.utils;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
import org.junit.*;
|
||||||
|
|
||||||
|
public class URLUtilsTest
|
||||||
|
{
|
||||||
|
@Test
|
||||||
|
public void shouldPercentEncodeMap()
|
||||||
|
{
|
||||||
|
Map<String, String> params = new LinkedHashMap<String, String>();
|
||||||
|
params.put("key", "value");
|
||||||
|
params.put("key with spaces", "value with spaces");
|
||||||
|
params.put("&symbols!", "#!");
|
||||||
|
|
||||||
|
String expected = "key=value&key+with+spaces=value+with+spaces&%26symbols%21=%23%21";
|
||||||
|
assertEquals(expected, URLUtils.formURLEncodeMap(params));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldReturnEmptyStringForEmptyMap()
|
||||||
|
{
|
||||||
|
Map<String, String> params = new LinkedHashMap<String, String>();
|
||||||
|
String expected = "";
|
||||||
|
assertEquals(expected, URLUtils.formURLEncodeMap(params));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldFormURLEncodeMapWithMissingValues()
|
||||||
|
{
|
||||||
|
Map<String, String> params = new LinkedHashMap<String, String>();
|
||||||
|
params.put("key", "value");
|
||||||
|
params.put("key with spaces", null);
|
||||||
|
|
||||||
|
String expected = "key=value&key+with+spaces";
|
||||||
|
assertEquals(expected, URLUtils.formURLEncodeMap(params));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldPercentEncodeString()
|
||||||
|
{
|
||||||
|
String toEncode = "this is a test &^";
|
||||||
|
String expected = "this%20is%20a%20test%20%26%5E";
|
||||||
|
assertEquals(expected, URLUtils.percentEncode(toEncode));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldFormURLEncodeString()
|
||||||
|
{
|
||||||
|
String toEncode = "this is a test &^";
|
||||||
|
String expected = "this+is+a+test+%26%5E";
|
||||||
|
assertEquals(expected, URLUtils.formURLEncode(toEncode));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldFormURLDecodeString()
|
||||||
|
{
|
||||||
|
String toDecode = "this+is+a+test+%26%5E";
|
||||||
|
String expected = "this is a test &^";
|
||||||
|
assertEquals(expected, URLUtils.formURLDecode(toDecode));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldPercentEncodeAllSpecialCharacters()
|
||||||
|
{
|
||||||
|
String plain = "!*'();:@&=+$,/?#[]";
|
||||||
|
String encoded = "%21%2A%27%28%29%3B%3A%40%26%3D%2B%24%2C%2F%3F%23%5B%5D";
|
||||||
|
assertEquals(encoded, URLUtils.percentEncode(plain));
|
||||||
|
assertEquals(plain, URLUtils.formURLDecode(encoded));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldNotPercentEncodeReservedCharacters()
|
||||||
|
{
|
||||||
|
String plain = "abcde123456-._~";
|
||||||
|
String encoded = plain;
|
||||||
|
assertEquals(encoded, URLUtils.percentEncode(plain));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
public void shouldThrowExceptionIfMapIsNull()
|
||||||
|
{
|
||||||
|
Map<String, String> nullMap = null;
|
||||||
|
URLUtils.formURLEncodeMap(nullMap);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
public void shouldThrowExceptionIfStringToEncodeIsNull()
|
||||||
|
{
|
||||||
|
String toEncode = null;
|
||||||
|
URLUtils.percentEncode(toEncode);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
public void shouldThrowExceptionIfStringToDecodeIsNull()
|
||||||
|
{
|
||||||
|
String toDecode = null;
|
||||||
|
URLUtils.formURLDecode(toDecode);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
public void shouldThrowExceptionWhenAppendingNullMapToQuerystring()
|
||||||
|
{
|
||||||
|
String url = "http://www.example.com";
|
||||||
|
Map<String, String> nullMap = null;
|
||||||
|
URLUtils.appendParametersToQueryString(url, nullMap);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldAppendNothingToQuerystringIfGivenEmptyMap()
|
||||||
|
{
|
||||||
|
String url = "http://www.example.com";
|
||||||
|
Map<String, String> emptyMap = new HashMap<String, String>();
|
||||||
|
String newUrl = URLUtils.appendParametersToQueryString(url, emptyMap);
|
||||||
|
Assert.assertEquals(url, newUrl);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldAppendParametersToSimpleUrl()
|
||||||
|
{
|
||||||
|
String url = "http://www.example.com";
|
||||||
|
String expectedUrl = "http://www.example.com?param1=value1¶m2=value+with+spaces";
|
||||||
|
|
||||||
|
Map<String, String> params = new HashMap<String, String>();
|
||||||
|
params.put("param1", "value1");
|
||||||
|
params.put("param2", "value with spaces");
|
||||||
|
|
||||||
|
url = URLUtils.appendParametersToQueryString(url, params);
|
||||||
|
Assert.assertEquals(url, expectedUrl);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldAppendParametersToUrlWithQuerystring()
|
||||||
|
{
|
||||||
|
String url = "http://www.example.com?already=present";
|
||||||
|
String expectedUrl = "http://www.example.com?already=present¶m1=value1¶m2=value+with+spaces";
|
||||||
|
|
||||||
|
Map<String, String> params = new HashMap<String, String>();
|
||||||
|
params.put("param1", "value1");
|
||||||
|
params.put("param2", "value with spaces");
|
||||||
|
|
||||||
|
url = URLUtils.appendParametersToQueryString(url, params);
|
||||||
|
Assert.assertEquals(url, expectedUrl);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldPercentEncodePlusSymbol()
|
||||||
|
{
|
||||||
|
String plain = "7aEP+jNAwvjc0mjhqg0nuXPf";
|
||||||
|
String encoded = "7aEP%2BjNAwvjc0mjhqg0nuXPf";
|
||||||
|
|
||||||
|
Assert.assertEquals(encoded, URLUtils.percentEncode(plain));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldURLDecodePlusSymbol()
|
||||||
|
{
|
||||||
|
String encoded = "oauth_verifier=7aEP%2BjNAwvjc0mjhqg0nuXPf";
|
||||||
|
String expected = "oauth_verifier=7aEP+jNAwvjc0mjhqg0nuXPf";
|
||||||
|
|
||||||
|
Assert.assertEquals(expected, URLUtils.formURLDecode(encoded));
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user