aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/network/OAuth.java
diff options
context:
space:
mode:
Diffstat (limited to 'main/src/cgeo/geocaching/network/OAuth.java')
-rw-r--r--main/src/cgeo/geocaching/network/OAuth.java18
1 files changed, 6 insertions, 12 deletions
diff --git a/main/src/cgeo/geocaching/network/OAuth.java b/main/src/cgeo/geocaching/network/OAuth.java
index cfc62fc..4f1fcc0 100644
--- a/main/src/cgeo/geocaching/network/OAuth.java
+++ b/main/src/cgeo/geocaching/network/OAuth.java
@@ -6,10 +6,8 @@ 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;
import java.util.List;
public class OAuth {
@@ -18,16 +16,15 @@ public class OAuth {
final String method,
final boolean https,
final Parameters params,
- @Nullable final String token,
- @Nullable final String tokenSecret,
+ final OAuthTokens tokens,
final String consumerKey,
final String consumerSecret) {
params.put(
"oauth_consumer_key", consumerKey,
"oauth_nonce", CryptUtils.md5(Long.toString(System.currentTimeMillis())),
"oauth_signature_method", "HMAC-SHA1",
- "oauth_timestamp", Long.toString(new Date().getTime() / 1000),
- "oauth_token", StringUtils.defaultString(token),
+ "oauth_timestamp", Long.toString(System.currentTimeMillis() / 1000),
+ "oauth_token", StringUtils.defaultString(tokens.getTokenPublic()),
"oauth_version", "1.0");
params.sort();
@@ -36,19 +33,16 @@ public class OAuth {
paramsEncoded.add(nameValue.getName() + "=" + OAuth.percentEncode(nameValue.getValue()));
}
- final String keysPacked = consumerSecret + "&" + StringUtils.defaultString(tokenSecret); // both even if empty some of them!
+ final String keysPacked = consumerSecret + "&" + StringUtils.defaultString(tokens.getTokenSecret()); // both even if empty some of them!
final @NonNull String joinedParams = StringUtils.join(paramsEncoded.toArray(), '&');
final String requestPacked = method + "&" + OAuth.percentEncode((https ? "https" : "http") + "://" + host + path) + "&" + OAuth.percentEncode(joinedParams);
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
+ * Percent encode following http://tools.ietf.org/html/rfc5849#section-3.6
*/
- static String percentEncode(@NonNull String url) {
+ static String percentEncode(@NonNull final String url) {
return StringUtils.replace(Network.rfc3986URLEncode(url), "*", "%2A");
}
}