diff options
Diffstat (limited to 'main/src/cgeo/geocaching/network/OAuth.java')
| -rw-r--r-- | main/src/cgeo/geocaching/network/OAuth.java | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/main/src/cgeo/geocaching/network/OAuth.java b/main/src/cgeo/geocaching/network/OAuth.java index 6740096..c033660 100644 --- a/main/src/cgeo/geocaching/network/OAuth.java +++ b/main/src/cgeo/geocaching/network/OAuth.java @@ -5,6 +5,8 @@ import cgeo.geocaching.utils.CryptUtils; import ch.boye.httpclientandroidlib.NameValuePair; import org.apache.commons.lang3.StringUtils; +import org.eclipse.jdt.annotation.NonNull; +import org.eclipse.jdt.annotation.Nullable; import java.util.ArrayList; import java.util.Date; @@ -16,8 +18,8 @@ public class OAuth { final String method, final boolean https, final Parameters params, - final String token, - final String tokenSecret, + @Nullable final String token, + @Nullable final String tokenSecret, final String consumerKey, final String consumerSecret) { params.put( @@ -31,11 +33,21 @@ public class OAuth { final List<String> paramsEncoded = new ArrayList<String>(); for (final NameValuePair nameValue : params) { - paramsEncoded.add(nameValue.getName() + "=" + Network.rfc3986URLEncode(nameValue.getValue())); + paramsEncoded.add(nameValue.getName() + "=" + OAuth.percentEncode(nameValue.getValue())); } final String keysPacked = consumerSecret + "&" + StringUtils.defaultString(tokenSecret); // both even if empty some of them! - final String requestPacked = method + "&" + Network.rfc3986URLEncode((https ? "https" : "http") + "://" + host + path) + "&" + Network.rfc3986URLEncode(StringUtils.join(paramsEncoded.toArray(), '&')); + final String requestPacked = method + "&" + OAuth.percentEncode((https ? "https" : "http") + "://" + host + path) + "&" + OAuth.percentEncode(StringUtils.join(paramsEncoded.toArray(), '&')); params.put("oauth_signature", CryptUtils.base64Encode(CryptUtils.hashHmac(requestPacked, keysPacked))); } + + /** + * percent encode following http://tools.ietf.org/html/rfc5849#section-3.6 + * + * @param url + * @return + */ + static String percentEncode(@NonNull String url) { + return StringUtils.replace(Network.rfc3986URLEncode(url), "*", "%2A"); + } } |
