do not include the token in the signature if it's empty

This commit is contained in:
Pablo Fernandez committed 2012-06-22 13:28:05 -03:00
1 parent 2f55386995
commit 97fa26fce7
2 files changed
+26 -4

No files matched your search

+18
View File
@@ -57,4 +57,22 @@ public class Token implements Serializable
{
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("","");
}
}
@@ -8,7 +8,7 @@ import org.scribe.utils.*;
/**
* OAuth 1.0a implementation of {@link OAuthService}
*
*
* @author Pablo Fernandez
*/
public class OAuth10aServiceImpl implements OAuthService
@@ -20,7 +20,7 @@ public class OAuth10aServiceImpl implements OAuthService
/**
* Default constructor
*
*
* @param api OAuth1.0a api information
* @param config OAuth 1.0a configuration param object
*/
@@ -88,8 +88,12 @@ public class OAuth10aServiceImpl implements OAuthService
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);
appendSignature(request);
@@ -110,7 +114,7 @@ public class OAuth10aServiceImpl implements OAuthService
{
return api.getAuthorizationUrl(requestToken);
}
private String getSignature(OAuthRequest request, Token token)
{
config.log("generating signature...");