Added support for Google's 'scope' param

This commit is contained in:
Pablo Fernandez committed 2010-10-20 10:25:26 -03:00
1 parent c3f113f39b
commit 1f94997120
6 files changed
+48 -3

No files matched your search

@@ -20,6 +20,7 @@ public class ServiceBuilder
private String apiSecret;
private String callback;
private Api api;
private String scope;
public ServiceBuilder()
{
@@ -92,6 +93,18 @@ public class ServiceBuilder
return this;
}
/**
* Configures the OAuth scope. This is only necessary in some APIs (like Google's).
*
* @param scope The OAuth scope
* @return the {@link ServiceBuilder} instance for method chaining
*/
public ServiceBuilder scope(String scope)
{
this.scope = scope;
return this;
}
/**
* Returns the fully configured {@link OAuthService}
*
@@ -102,6 +115,6 @@ public class ServiceBuilder
Preconditions.checkNotNull(api, "You must specify a valid api through the provider() method");
Preconditions.checkEmptyString(apiKey, "You must provide an api key");
Preconditions.checkEmptyString(apiSecret, "You must provide an api secret");
return api.createService(apiKey, apiSecret, callback);
return api.createService(apiKey, apiSecret, callback, scope);
}
}
@@ -20,4 +20,16 @@ public interface Api
* @return fully configured {@link OAuthService}
*/
OAuthService createService(String apiKey, String apiSecret, String callback);
/**
* Creates an {@link OAuthService}
*
* @param apiKey your application api key
* @param apiSecret your application api secret
* @param callback the callback url (or 'oob' for out of band OAuth)
* @param scope the OAuth scope
*
* @return fully configured {@link OAuthService}
*/
OAuthService createService(String apiKey, String apiSecret, String callback, String scope);
}
@@ -50,7 +50,6 @@ public abstract class DefaultApi10a implements Api
public abstract String getRequestTokenEndpoint();
public abstract String getAccessTokenEndpoint();
@Override
public OAuthService createService(String apiKey, String apiSecret, String callback)
{
return new OAuth10aServiceImpl( getSignatureService(),
@@ -61,6 +60,13 @@ public abstract class DefaultApi10a implements Api
getAccessTokenExtractor(),
createConfig(apiKey, apiSecret, callback));
}
public OAuthService createService(String apiKey, String apiSecret, String callback, String scope)
{
OAuthService service = createService(apiKey, apiSecret, callback);
service.addScope(scope);
return service;
}
private OAuthConfig createConfig(String apiKey, String apiSecret, String callback)
{