@@ -40,15 +40,12 @@ public OAuth10aService(DefaultApi10a api, OAuthConfig config) {
4040 *
4141 * @return request token
4242 */
43- public OAuth1RequestToken getRequestToken () {
43+ public final OAuth1RequestToken getRequestToken () {
4444 final OAuthConfig config = getConfig ();
4545 config .log ("obtaining request token from " + api .getRequestTokenEndpoint ());
4646 final OAuthRequest request = new OAuthRequest (api .getRequestTokenVerb (), api .getRequestTokenEndpoint (), this );
4747
48- config .log ("setting oauth_callback to " + config .getCallback ());
49- request .addOAuthParameter (OAuthConstants .CALLBACK , config .getCallback ());
50- addOAuthParams (request , "" );
51- appendSignature (request );
48+ prepareRequestTokenRequest (request );
5249
5350 config .log ("sending request..." );
5451 final Response response = request .send ();
@@ -59,6 +56,29 @@ public OAuth1RequestToken getRequestToken() {
5956 return api .getRequestTokenExtractor ().extract (body );
6057 }
6158
59+ public final Future <OAuth1RequestToken > getRequestTokenAsync (
60+ OAuthAsyncRequestCallback <OAuth1RequestToken > callback ) {
61+ final OAuthConfig config = getConfig ();
62+ config .log ("async obtaining request token from " + api .getRequestTokenEndpoint ());
63+ final OAuthRequestAsync request
64+ = new OAuthRequestAsync (api .getRequestTokenVerb (), api .getRequestTokenEndpoint (), this );
65+ prepareRequestTokenRequest (request );
66+ return request .sendAsync (callback , new OAuthRequestAsync .ResponseConverter <OAuth1RequestToken >() {
67+ @ Override
68+ public OAuth1RequestToken convert (Response response ) throws IOException {
69+ return getApi ().getRequestTokenExtractor ().extract (response .getBody ());
70+ }
71+ });
72+ }
73+
74+ protected void prepareRequestTokenRequest (AbstractRequest request ) {
75+ final OAuthConfig config = getConfig ();
76+ config .log ("setting oauth_callback to " + config .getCallback ());
77+ request .addOAuthParameter (OAuthConstants .CALLBACK , config .getCallback ());
78+ addOAuthParams (request , "" );
79+ appendSignature (request );
80+ }
81+
6282 private void addOAuthParams (AbstractRequest request , String tokenSecret ) {
6383 final OAuthConfig config = getConfig ();
6484 request .addOAuthParameter (OAuthConstants .TIMESTAMP , api .getTimestampService ().getTimestampInSeconds ());
0 commit comments