Skip to content

Commit 05159b5

Browse files
committed
adds the ability to do reverse auth
1 parent 677afc6 commit 05159b5

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

api/src/main/java/com/ning/http/client/oauth/OAuthSignatureCalculator.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,11 @@ public class OAuthSignatureCalculator
5252
private static final String KEY_OAUTH_TIMESTAMP = "oauth_timestamp";
5353
private static final String KEY_OAUTH_TOKEN = "oauth_token";
5454
private static final String KEY_OAUTH_VERSION = "oauth_version";
55+
private static final String KEY_X_AUTH_MODE = "x_auth_mode";
5556

5657
private static final String OAUTH_VERSION_1_0 = "1.0";
5758
private static final String OAUTH_SIGNATURE_METHOD = "HMAC-SHA1";
59+
private static final String OAUTH_REVERSE_AUTH = "reverse_auth";
5860

5961
/**
6062
* To generate Nonce, need some (pseudo)randomness; no need for
@@ -70,15 +72,27 @@ public class OAuthSignatureCalculator
7072

7173
protected final RequestToken userAuth;
7274

75+
protected final Boolean useReverseAuth;
76+
7377
/**
7478
* @param consumerAuth Consumer key to use for signature calculation
7579
* @param userAuth Request/access token to use for signature calculation
7680
*/
7781
public OAuthSignatureCalculator(ConsumerKey consumerAuth, RequestToken userAuth) {
82+
this(consumerAuth, userAuth, false);
83+
}
84+
85+
/**
86+
* @param consumerAuth Consumer key to use for signature calculation
87+
* @param userAuth Request/access token to use for signature calculation
88+
* @param useReverseAuth Whether or not to use the reverse auth signature or the regular one
89+
*/
90+
public OAuthSignatureCalculator(ConsumerKey consumerAuth, RequestToken userAuth, Boolean useReverseAuth ) {
7891
mac = new ThreadSafeHMAC(consumerAuth, userAuth);
7992
this.consumerAuth = consumerAuth;
8093
this.userAuth = userAuth;
8194
random = new Random(System.identityHashCode(this) + System.currentTimeMillis());
95+
this.useReverseAuth = useReverseAuth;
8296
}
8397

8498
//@Override // silly 1.5; doesn't allow this for interfaces
@@ -130,6 +144,8 @@ public String calculateSignature(String method, String baseURL, long oauthTimest
130144
allParameters.add(KEY_OAUTH_TIMESTAMP, String.valueOf(oauthTimestamp));
131145
allParameters.add(KEY_OAUTH_TOKEN, userAuth.getKey());
132146
allParameters.add(KEY_OAUTH_VERSION, OAUTH_VERSION_1_0);
147+
if (useReverseAuth)
148+
allParameters.add(KEY_X_AUTH_MODE, OAUTH_REVERSE_AUTH);
133149

134150
if (formParams != null) {
135151
for (Map.Entry<String, List<String>> entry : formParams) {
@@ -180,6 +196,8 @@ public String constructAuthHeader(String signature, String nonce, long oauthTime
180196
sb.append("\", ");
181197

182198
sb.append(KEY_OAUTH_VERSION).append("=\"").append(OAUTH_VERSION_1_0).append("\"");
199+
if (useReverseAuth)
200+
sb.append(KEY_X_AUTH_MODE).append("=\"").append(OAUTH_REVERSE_AUTH).append("\"");
183201
return sb.toString();
184202
}
185203

0 commit comments

Comments
 (0)