Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added means to create a provider that uses GET methods for the authentication urls #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
target
.settings
.project
.classpath
8 changes: 1 addition & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<groupId>oauth.signpost</groupId>
<artifactId>oauth-signpost</artifactId>
<packaging>pom</packaging>
<version>1.2.1.1</version>
<version>1.2.1.2-SNAPSHOT</version>
<name>oauth-signpost</name>
<description>
A simple, light-weight, and modular OAuth client library for the
Expand Down Expand Up @@ -119,12 +119,6 @@
<name>Signpost Snapshot Repository</name>
<url>http://oss.sonatype.org/content/repositories/signpost-snapshots/</url>
</snapshotRepository>
<!--
<site>
<id>site-staging</id>
<url>site-preview</url>
</site>
-->
</distributionManagement>

<reporting>
Expand Down
2 changes: 1 addition & 1 deletion signpost-commonshttp4/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java"/>
<classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
7 changes: 3 additions & 4 deletions signpost-commonshttp4/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<parent>
<artifactId>oauth-signpost</artifactId>
<groupId>oauth.signpost</groupId>
<version>1.2.1.1</version>
<version>1.2.1.2-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>signpost-commonshttp4</artifactId>
Expand All @@ -12,7 +12,7 @@
<dependency>
<groupId>oauth.signpost</groupId>
<artifactId>signpost-core</artifactId>
<version>1.2.1.1</version>
<version>${project.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
Expand All @@ -30,10 +30,9 @@
<dependency>
<groupId>oauth.signpost</groupId>
<artifactId>signpost-core</artifactId>
<version>1.2.1.1</version>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.impl.client.DefaultHttpClient;
Expand All @@ -43,19 +44,31 @@ public CommonsHttpOAuthProvider(String requestTokenEndpointUrl, String accessTok
this.httpClient = new DefaultHttpClient();
}

public CommonsHttpOAuthProvider(String requestTokenEndpointUrl, String accessTokenEndpointUrl,
String authorizationWebsiteUrl, final String httpMethod) {
super(requestTokenEndpointUrl, accessTokenEndpointUrl, authorizationWebsiteUrl, httpMethod);
this.httpClient = new DefaultHttpClient();
}

public CommonsHttpOAuthProvider(String requestTokenEndpointUrl, String accessTokenEndpointUrl,
String authorizationWebsiteUrl, HttpClient httpClient) {
super(requestTokenEndpointUrl, accessTokenEndpointUrl, authorizationWebsiteUrl);
this.httpClient = httpClient;
}


public CommonsHttpOAuthProvider(String requestTokenEndpointUrl, String accessTokenEndpointUrl,
String authorizationWebsiteUrl, HttpClient httpClient, String httpMethod) {
super(requestTokenEndpointUrl, accessTokenEndpointUrl, authorizationWebsiteUrl, httpMethod);
this.httpClient = httpClient;
}

public void setHttpClient(HttpClient httpClient) {
this.httpClient = httpClient;
}

@Override
protected HttpRequest createRequest(String endpointUrl) throws Exception {
HttpPost request = new HttpPost(endpointUrl);
HttpUriRequest request = this.method.equals(HTTP_POST) ? new HttpPost(endpointUrl) : new HttpGet(endpointUrl);
return new HttpRequestAdapter(request);
}

Expand Down
2 changes: 1 addition & 1 deletion signpost-core/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java"/>
<classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
2 changes: 1 addition & 1 deletion signpost-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<parent>
<artifactId>oauth-signpost</artifactId>
<groupId>oauth.signpost</groupId>
<version>1.2.1.1</version>
<version>1.2.1.2-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>signpost-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
* @author Matthias Kaeppler
*/
public abstract class AbstractOAuthProvider implements OAuthProvider {

private static final long serialVersionUID = 1L;

private String requestTokenEndpointUrl;
Expand All @@ -47,14 +46,25 @@ public abstract class AbstractOAuthProvider implements OAuthProvider {
private boolean isOAuth10a;

private transient OAuthProviderListener listener;


protected final String method;

public AbstractOAuthProvider(String requestTokenEndpointUrl, String accessTokenEndpointUrl,
String authorizationWebsiteUrl) {
String authorizationWebsiteUrl, final String httpMethod) {
this.requestTokenEndpointUrl = requestTokenEndpointUrl;
this.accessTokenEndpointUrl = accessTokenEndpointUrl;
this.authorizationWebsiteUrl = authorizationWebsiteUrl;
this.responseParameters = new HttpParameters();
this.defaultHeaders = new HashMap<String, String>();
if (null == httpMethod || !(httpMethod.toUpperCase().equals("GET") || httpMethod.toUpperCase().equals("POST"))) {
throw new IllegalArgumentException("You must specify a valid httpMethod (GET or POST)");
}
this.method = httpMethod;
}

public AbstractOAuthProvider(String requestTokenEndpointUrl, String accessTokenEndpointUrl,
String authorizationWebsiteUrl) {
this(requestTokenEndpointUrl, accessTokenEndpointUrl, authorizationWebsiteUrl, OAuthProvider.HTTP_POST);
}

public String retrieveRequestToken(OAuthConsumer consumer, String callbackUrl)
Expand Down
2 changes: 2 additions & 0 deletions signpost-core/src/main/java/oauth/signpost/OAuthProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@
* @see OAuthProviderListener
*/
public interface OAuthProvider extends Serializable {
public static final String HTTP_GET = "GET";
public static final String HTTP_POST = "POST";

/**
* Queries the service provider for a request token.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,16 @@ public DefaultOAuthProvider(String requestTokenEndpointUrl, String accessTokenEn
String authorizationWebsiteUrl) {
super(requestTokenEndpointUrl, accessTokenEndpointUrl, authorizationWebsiteUrl);
}

public DefaultOAuthProvider(String requestTokenEndpointUrl, String accessTokenEndpointUrl,
String authorizationWebsiteUrl, final String httpMethod) {
super(requestTokenEndpointUrl, accessTokenEndpointUrl, authorizationWebsiteUrl, httpMethod);
}

protected HttpRequest createRequest(String endpointUrl) throws MalformedURLException,
IOException {
HttpURLConnection connection = (HttpURLConnection) new URL(endpointUrl).openConnection();
connection.setRequestMethod("POST");
connection.setRequestMethod(this.method);
connection.setAllowUserInteraction(false);
connection.setRequestProperty("Content-Length", "0");
return new HttpURLConnectionRequestAdapter(connection);
Expand Down
2 changes: 1 addition & 1 deletion signpost-jetty6/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java"/>
<classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
6 changes: 3 additions & 3 deletions signpost-jetty6/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<parent>
<artifactId>oauth-signpost</artifactId>
<groupId>oauth.signpost</groupId>
<version>1.2.1.1</version>
<version>1.2.1.2-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>signpost-jetty6</artifactId>
Expand All @@ -12,7 +12,7 @@
<dependency>
<groupId>oauth.signpost</groupId>
<artifactId>signpost-core</artifactId>
<version>1.2.1.1</version>
<version>${project.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
Expand All @@ -24,7 +24,7 @@
<dependency>
<groupId>oauth.signpost</groupId>
<artifactId>signpost-core</artifactId>
<version>1.2.1.1</version>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
Expand Down