@@ -52,9 +52,11 @@ public class OAuthSignatureCalculator
52
52
private static final String KEY_OAUTH_TIMESTAMP = "oauth_timestamp" ;
53
53
private static final String KEY_OAUTH_TOKEN = "oauth_token" ;
54
54
private static final String KEY_OAUTH_VERSION = "oauth_version" ;
55
+ private static final String KEY_X_AUTH_MODE = "x_auth_mode" ;
55
56
56
57
private static final String OAUTH_VERSION_1_0 = "1.0" ;
57
58
private static final String OAUTH_SIGNATURE_METHOD = "HMAC-SHA1" ;
59
+ private static final String OAUTH_REVERSE_AUTH = "reverse_auth" ;
58
60
59
61
/**
60
62
* To generate Nonce, need some (pseudo)randomness; no need for
@@ -70,15 +72,27 @@ public class OAuthSignatureCalculator
70
72
71
73
protected final RequestToken userAuth ;
72
74
75
+ protected final Boolean useReverseAuth ;
76
+
73
77
/**
74
78
* @param consumerAuth Consumer key to use for signature calculation
75
79
* @param userAuth Request/access token to use for signature calculation
76
80
*/
77
81
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 ) {
78
91
mac = new ThreadSafeHMAC (consumerAuth , userAuth );
79
92
this .consumerAuth = consumerAuth ;
80
93
this .userAuth = userAuth ;
81
94
random = new Random (System .identityHashCode (this ) + System .currentTimeMillis ());
95
+ this .useReverseAuth = useReverseAuth ;
82
96
}
83
97
84
98
//@Override // silly 1.5; doesn't allow this for interfaces
@@ -130,6 +144,8 @@ public String calculateSignature(String method, String baseURL, long oauthTimest
130
144
allParameters .add (KEY_OAUTH_TIMESTAMP , String .valueOf (oauthTimestamp ));
131
145
allParameters .add (KEY_OAUTH_TOKEN , userAuth .getKey ());
132
146
allParameters .add (KEY_OAUTH_VERSION , OAUTH_VERSION_1_0 );
147
+ if (useReverseAuth )
148
+ allParameters .add (KEY_X_AUTH_MODE , OAUTH_REVERSE_AUTH );
133
149
134
150
if (formParams != null ) {
135
151
for (Map .Entry <String , List <String >> entry : formParams ) {
@@ -180,6 +196,8 @@ public String constructAuthHeader(String signature, String nonce, long oauthTime
180
196
sb .append ("\" , " );
181
197
182
198
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 ("\" " );
183
201
return sb .toString ();
184
202
}
185
203
0 commit comments