Skip to content

Commit 9ea686a

Browse files
Added OAuth 2.0 classes
1 parent 7e92db3 commit 9ea686a

File tree

3 files changed

+36
-6
lines changed

3 files changed

+36
-6
lines changed
Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,42 @@
11
package org.scribe.builder.api;
22

3-
import org.scribe.model.OAuthConfig;
4-
import org.scribe.oauth.OAuthService;
3+
import org.scribe.model.*;
4+
import org.scribe.oauth.*;
55

6-
public class DefaultApi20 implements Api
6+
/**
7+
* Default implementation of the OAuth protocol, version 2.0 (draft 11)
8+
*
9+
* This class is meant to be extended by concrete implementations of the API,
10+
* providing the endpoints and endpoint-http-verbs.
11+
*
12+
* If your Api adheres to the 2.0 (draft 11) protocol correctly, you just need to extend
13+
* this class and define the getters for your endpoints.
14+
*
15+
* If your Api does something a bit different, you can override the different
16+
* extractors or services, in order to fine-tune the process. Please read the
17+
* javadocs of the interfaces to get an idea of what to do.
18+
*
19+
* @author Diego Silveira
20+
*
21+
*/
22+
public abstract class DefaultApi20 implements Api
723
{
824

9-
@Override
25+
/**
26+
* Returns the URL where you should redirect your users to authenticate
27+
* your application.
28+
*
29+
* @param config OAuth 2.0 configuration param object
30+
* @return the URL where you should redirect your users
31+
*/
32+
public abstract String getAuthorizationUrl(OAuthConfig config);
33+
34+
/**
35+
* {@inheritDoc}
36+
*/
1037
public OAuthService createService(OAuthConfig config, String scope)
1138
{
12-
return null;
39+
return new OAuth20ServiceImpl(this, config);
1340
}
1441

1542
}

src/main/java/org/scribe/model/OAuthConstants.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,7 @@ public class OAuthConstants
3838
public static final String HEADER = "Authorization";
3939
public static final Token EMPTY_TOKEN = new Token("", "");
4040
public static final String SCOPE = "scope";
41+
42+
//OAuth 2.0
43+
public static final String ACCESS_TOKEN = "access_token";
4144
}

src/main/java/org/scribe/oauth/OAuth20ServiceImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public String getVersion()
5959
*/
6060
public void signRequest(Token accessToken, OAuthRequest request)
6161
{
62-
request.addParameter(OAuthConstants.ACCESS_TOKEN, accessToken.getToken());
62+
request.addQuerystringParam(OAuthConstants.ACCESS_TOKEN, accessToken.getToken());
6363
}
6464

6565
/**

0 commit comments

Comments
 (0)