Skip to content

Commit bfbe536

Browse files
Initial commit
0 parents  commit bfbe536

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+2540
-0
lines changed

.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
# Eclipse specific settings
3+
4+
.classpath
5+
.project
6+
.settings
7+
8+
# Binaries
9+
10+
target

README.textile

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
!http://img411.imageshack.us/img411/2851/scribelogo.png!
2+
3+
h1. Welcome
4+
5+
h3. Welcome to the *new* home of **Scribe**
6+
7+
h1. Why use Scribe?
8+
9+
h3. Dead Simple
10+
11+
Who said OAuth was difficult? Configuring scribe is so easy your grandma can do it! check it out:
12+
13+
OAuthService service = new ServiceBuilder()
14+
.provider(LinkedInApi.class)
15+
.apiKey(YOUR_API_KEY)
16+
.apiSecret(YOUR_API_SECRET)
17+
.build();
18+
19+
That **single line** (added newlines for readability) is the only thing you need to configure scribe with LinkedIn's OAuth API for example.
20+
21+
h3. Threadsafe
22+
23+
Hit Scribe as hard and with many threads as you like.
24+
25+
h3. Supports all major OAuth APIs out-of-the-box
26+
27+
logos here
28+
29+
h3. Small and modular
30+
31+
Scribe's code is small (about 1k LOC) and simple to understand. No smart-ass or "clever" hacks here.
32+
33+
h3. Stable & bulletproof
34+
35+
Test coverage of about x% to keep you safe from harm.
36+
37+
When something bad actually happens, Scribe's meaningful error messages will tell you exactly what went wrong, when and where.
38+
39+
h1. Getting started in less than 2 minutes
40+
41+
Check the "Getting Started":http://wiki.github.com/fernandezpablo85/scribe/getting-started page and start rocking!
42+
43+
h1. Please Read the "FAQ":http://wiki.github.com/fernandezpablo85/scribe/faq before creating an issue :)
44+
45+
h1. About me
46+
47+
LinkedIn "profile":http://linkedinprofile
48+
49+
Email me: fernandezpablo85 at gmail.com
50+
51+
Follow me: "@fernandezpablo":http://twitter.com/fernandezpablo

pom.xml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>org.scribe</groupId>
5+
<artifactId>scribe</artifactId>
6+
<packaging>jar</packaging>
7+
<version>1.0.0</version>
8+
<name>OAuth Library</name>
9+
10+
<dependencies>
11+
<dependency>
12+
<groupId>commons-codec</groupId>
13+
<artifactId>commons-codec</artifactId>
14+
<version>1.4</version>
15+
</dependency>
16+
17+
<dependency>
18+
<groupId>junit</groupId>
19+
<artifactId>junit</artifactId>
20+
<version>4.8.1</version>
21+
</dependency>
22+
23+
</dependencies>
24+
<build>
25+
<plugins>
26+
<plugin>
27+
<artifactId>maven-compiler-plugin</artifactId>
28+
<configuration>
29+
<source>1.6</source>
30+
<target>1.6</target>
31+
</configuration>
32+
</plugin>
33+
</plugins>
34+
</build>
35+
</project>
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
package org.scribe.builder;
2+
3+
import org.scribe.builder.api.*;
4+
import org.scribe.exceptions.*;
5+
6+
import org.scribe.model.*;
7+
import org.scribe.oauth.*;
8+
import org.scribe.utils.*;
9+
10+
/**
11+
* Implementation of the Builder pattern, with a fluent interface that creates a
12+
* {@link OAuthService}
13+
*
14+
* @author Pablo Fernandez
15+
*
16+
*/
17+
public class ServiceBuilder
18+
{
19+
private String apiKey;
20+
private String apiSecret;
21+
private String callback;
22+
private Api api;
23+
24+
public ServiceBuilder()
25+
{
26+
this.callback = OAuthConstants.OUT_OF_BAND;
27+
}
28+
29+
/**
30+
* Configures the {@link Api}
31+
*
32+
* @param apiClass the class of one of the existent {@link Api}s on org.scribe.api package
33+
* @return the {@link ServiceBuilder} instance for method chaining
34+
*/
35+
public ServiceBuilder provider(Class<? extends Api> apiClass)
36+
{
37+
this.api = createApi(apiClass);
38+
return this;
39+
}
40+
41+
private Api createApi(Class<? extends Api> apiClass)
42+
{
43+
Preconditions.checkNotNull(apiClass, "Api class cannot be null");
44+
Api api;
45+
try
46+
{
47+
api = apiClass.newInstance();
48+
}
49+
catch(Exception e)
50+
{
51+
throw new OAuthException("Error while creating the Api object", e);
52+
}
53+
return api;
54+
}
55+
56+
/**
57+
* Adds an OAuth callback url
58+
*
59+
* @param callback callback url. Must be a valid url or 'oob' for out of band OAuth
60+
* @return the {@link ServiceBuilder} instance for method chaining
61+
*/
62+
public ServiceBuilder callback(String callback)
63+
{
64+
Preconditions.checkValidOAuthCallback(callback, "Callback must be a valid URL or 'oob'");
65+
this.callback = callback;
66+
return this;
67+
}
68+
69+
/**
70+
* Configures the api key
71+
*
72+
* @param apiKey The api key for your application
73+
* @return the {@link ServiceBuilder} instance for method chaining
74+
*/
75+
public ServiceBuilder apiKey(String apiKey)
76+
{
77+
Preconditions.checkEmptyString(apiKey, "Invalid Api key");
78+
this.apiKey = apiKey;
79+
return this;
80+
}
81+
82+
/**
83+
* Configures the api secret
84+
*
85+
* @param apiSecret The api secret for your application
86+
* @return the {@link ServiceBuilder} instance for method chaining
87+
*/
88+
public ServiceBuilder apiSecret(String apiSecret)
89+
{
90+
Preconditions.checkEmptyString(apiSecret, "Invalid Api secret");
91+
this.apiSecret = apiSecret;
92+
return this;
93+
}
94+
95+
/**
96+
* Returns the fully configured {@link OAuthService}
97+
*
98+
* @return fully configured {@link OAuthService}
99+
*/
100+
public OAuthService build()
101+
{
102+
Preconditions.checkNotNull(api, "You must specify a valid api through the provider() method");
103+
Preconditions.checkEmptyString(apiKey, "You must provide an api key");
104+
Preconditions.checkEmptyString(apiSecret, "You must provide an api secret");
105+
return api.createService(apiKey, apiSecret, callback);
106+
}
107+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package org.scribe.builder.api;
2+
3+
import org.scribe.oauth.*;
4+
5+
/**
6+
* Contains all the configuration needed to instantiate a valid {@link OAuthService}
7+
*
8+
* @author Pablo Fernandez
9+
*
10+
*/
11+
public interface Api
12+
{
13+
/**
14+
* Creates an {@link OAuthService}
15+
*
16+
* @param apiKey your application api key
17+
* @param apiSecret your application api secret
18+
* @param callback the callback url (or 'oob' for out of band OAuth)
19+
*
20+
* @return fully configured {@link OAuthService}
21+
*/
22+
OAuthService createService(String apiKey, String apiSecret, String callback);
23+
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
package org.scribe.builder.api;
2+
3+
import org.scribe.extractors.*;
4+
import org.scribe.model.OAuthConfig;
5+
import org.scribe.model.Request.Verb;
6+
import org.scribe.oauth.OAuth10aServiceImpl;
7+
import org.scribe.oauth.OAuthService;
8+
import org.scribe.services.*;
9+
10+
public abstract class DefaultApi10a implements Api
11+
{
12+
public AccessTokenExtractor getAccessTokenExtractor()
13+
{
14+
return new TokenExtractorImpl();
15+
}
16+
17+
public BaseStringExtractor getBaseStringExtractor()
18+
{
19+
return new BaseStringExtractorImpl();
20+
}
21+
22+
public HeaderExtractor getHeaderExtractor()
23+
{
24+
return new HeaderExtractorImpl();
25+
}
26+
27+
public RequestTokenExtractor getRequestTokenExtractor()
28+
{
29+
return new TokenExtractorImpl();
30+
}
31+
32+
public SignatureService getSignatureService()
33+
{
34+
return new HMACSha1SignatureService();
35+
}
36+
37+
public TimestampService getTimestampService()
38+
{
39+
return new TimestampServiceImpl();
40+
}
41+
42+
public Verb getAccessTokenVerb()
43+
{
44+
return Verb.POST;
45+
}
46+
47+
public Verb getRequestTokenVerb()
48+
{
49+
return Verb.POST;
50+
}
51+
52+
public abstract String getRequestTokenEndpoint();
53+
public abstract String getAccessTokenEndpoint();
54+
55+
@Override
56+
public OAuthService createService(String apiKey, String apiSecret, String callback)
57+
{
58+
return new OAuth10aServiceImpl( getSignatureService(),
59+
getTimestampService(),
60+
getBaseStringExtractor(),
61+
getHeaderExtractor(),
62+
getRequestTokenExtractor(),
63+
getAccessTokenExtractor(),
64+
createConfig(apiKey, apiSecret, callback));
65+
}
66+
67+
private OAuthConfig createConfig(String apiKey, String apiSecret, String callback)
68+
{
69+
OAuthConfig config = new OAuthConfig();
70+
config.setRequestTokenVerb(getRequestTokenVerb());
71+
config.setRequestTokenEndpoint(getRequestTokenEndpoint());
72+
config.setAccessTokenVerb(getAccessTokenVerb());
73+
config.setAccessTokenEndpoint(getAccessTokenEndpoint());
74+
config.setApiKey(apiKey);
75+
config.setApiSecret(apiSecret);
76+
config.setCallback(callback);
77+
return config;
78+
}
79+
80+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package org.scribe.builder.api;
2+
3+
public class FoursquareApi extends DefaultApi10a
4+
{
5+
@Override
6+
public String getAccessTokenEndpoint()
7+
{
8+
throw new UnsupportedOperationException();
9+
}
10+
11+
@Override
12+
public String getRequestTokenEndpoint()
13+
{
14+
throw new UnsupportedOperationException();
15+
}
16+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package org.scribe.builder.api;
2+
3+
public class GoogleApi extends DefaultApi10a
4+
{
5+
@Override
6+
public String getAccessTokenEndpoint()
7+
{
8+
throw new UnsupportedOperationException();
9+
}
10+
11+
@Override
12+
public String getRequestTokenEndpoint()
13+
{
14+
throw new UnsupportedOperationException();
15+
}
16+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package org.scribe.builder.api;
2+
3+
import org.scribe.extensions.linkedin.*;
4+
import org.scribe.extractors.*;
5+
6+
public class LinkedInApi extends DefaultApi10a
7+
{
8+
9+
@Override
10+
public String getAccessTokenEndpoint()
11+
{
12+
return "https://api.linkedin.com/uas/oauth/accessToken";
13+
}
14+
15+
@Override
16+
public String getRequestTokenEndpoint()
17+
{
18+
return "https://api.linkedin.com/uas/oauth/requestToken";
19+
}
20+
21+
@Override
22+
public BaseStringExtractor getBaseStringExtractor()
23+
{
24+
return new LinkedInBaseStringExtractorImpl();
25+
}
26+
27+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package org.scribe.builder.api;
2+
3+
public class SalesForceApi extends DefaultApi10a
4+
{
5+
@Override
6+
public String getAccessTokenEndpoint()
7+
{
8+
return "https://login.salesforce.com/_nc_external/system/security/oauth/AccessTokenHandler";
9+
}
10+
11+
@Override
12+
public String getRequestTokenEndpoint()
13+
{
14+
return "https://login.salesforce.com/_nc_external/system/security/oauth/RequestTokenHandler";
15+
}
16+
}

0 commit comments

Comments
 (0)