@@ -66,24 +66,25 @@ public OAuthSignatureCalculatorInstance() throws NoSuchAlgorithmException {
66
66
}
67
67
68
68
public void sign (ConsumerKey consumerAuth , RequestToken userAuth , Request request , RequestBuilderBase <?> requestBuilder ) throws InvalidKeyException {
69
- String percentEncodedNonce = generatePercentEncodedNonce ();
69
+ String nonce = generateNonce ();
70
70
long timestamp = generateTimestamp ();
71
- sign (consumerAuth , userAuth , request , requestBuilder , percentEncodedNonce , timestamp );
71
+ sign (consumerAuth , userAuth , request , requestBuilder , timestamp , nonce );
72
72
}
73
73
74
- private String generatePercentEncodedNonce () {
74
+ private String generateNonce () {
75
75
ThreadLocalRandom .current ().nextBytes (nonceBuffer );
76
76
// let's use base64 encoding over hex, slightly more compact than hex or decimals
77
- return Utf8UrlEncoder . percentEncodeQueryElement ( Base64 .encode (nonceBuffer ) );
77
+ return Base64 .encode (nonceBuffer );
78
78
}
79
79
80
80
private static long generateTimestamp () {
81
81
return System .currentTimeMillis () / 1000L ;
82
82
}
83
83
84
- void sign (ConsumerKey consumerAuth , RequestToken userAuth , Request request , RequestBuilderBase <?> requestBuilder , String percentEncodedNonce , long timestamp ) throws InvalidKeyException {
84
+ void sign (ConsumerKey consumerAuth , RequestToken userAuth , Request request , RequestBuilderBase <?> requestBuilder , long timestamp , String nonce ) throws InvalidKeyException {
85
+ String percentEncodedNonce = Utf8UrlEncoder .percentEncodeQueryElement (nonce );
85
86
String signature = calculateSignature (consumerAuth , userAuth , request , timestamp , percentEncodedNonce );
86
- String headerValue = constructAuthHeader (consumerAuth , userAuth , signature , percentEncodedNonce , timestamp );
87
+ String headerValue = constructAuthHeader (consumerAuth , userAuth , signature , timestamp , percentEncodedNonce );
87
88
requestBuilder .setHeader (HttpHeaderNames .AUTHORIZATION , headerValue );
88
89
}
89
90
@@ -170,7 +171,7 @@ private byte[] digest(ConsumerKey consumerAuth, RequestToken userAuth, ByteBuffe
170
171
return mac .doFinal ();
171
172
}
172
173
173
- String constructAuthHeader (ConsumerKey consumerAuth , RequestToken userAuth , String signature , String percentEncodedNonce , long oauthTimestamp ) {
174
+ String constructAuthHeader (ConsumerKey consumerAuth , RequestToken userAuth , String signature , long oauthTimestamp , String percentEncodedNonce ) {
174
175
StringBuilder sb = StringBuilderPool .DEFAULT .stringBuilder ();
175
176
sb .append ("OAuth " );
176
177
sb .append (KEY_OAUTH_CONSUMER_KEY ).append ("=\" " ).append (consumerAuth .getPercentEncodedKey ()).append ("\" , " );
0 commit comments