@@ -18,6 +18,7 @@ public abstract class OAuthBaseClient {
1818 protected String baseUrl ;
1919 protected Context context ;
2020 protected OAuthTokenClient tokenClient ;
21+ protected OAuthAsyncHttpClient client ;
2122 protected SharedPreferences prefs ;
2223 protected SharedPreferences .Editor editor ;
2324 protected OAuthAccessHandler accessHandler ;
@@ -45,7 +46,7 @@ public static OAuthBaseClient getInstance(Class<? extends OAuthBaseClient> klass
4546 return instance ;
4647 }
4748
48- public OAuthBaseClient (Context c , BaseApi apiInstance , String consumerUrl , String consumerKey , String consumerSecret , String callbackUrl ) {
49+ public OAuthBaseClient (Context c , final BaseApi apiInstance , String consumerUrl , final String consumerKey , final String consumerSecret , String callbackUrl ) {
4950 this .baseUrl = consumerUrl ;
5051 this .callbackUrl = callbackUrl ;
5152 tokenClient = new OAuthTokenClient (apiInstance , consumerKey ,
@@ -78,12 +79,15 @@ public void onReceivedAccessToken(Token accessToken, String oAuthVersion) {
7879 OAuth1AccessToken oAuth1AccessToken = (OAuth1AccessToken ) accessToken ;
7980
8081 tokenClient .setAccessToken (accessToken );
82+ instantiateClient (consumerKey , consumerSecret , oAuth1AccessToken );
8183 editor .putString (OAuthConstants .TOKEN , oAuth1AccessToken .getToken ());
8284 editor .putString (OAuthConstants .TOKEN_SECRET , oAuth1AccessToken .getTokenSecret ());
8385 editor .putInt (OAuthConstants .VERSION , 1 );
8486 editor .commit ();
8587 } else if (oAuthVersion == OAUTH2_VERSION ) {
8688 OAuth2AccessToken oAuth2AccessToken = (OAuth2AccessToken ) accessToken ;
89+
90+ //TODO(rhu) - create client for OAuth2 cases
8791 tokenClient .setAccessToken (accessToken );
8892 editor .putString (OAuthConstants .TOKEN , oAuth2AccessToken .getAccessToken ());
8993 editor .putString (OAuthConstants .SCOPE , oAuth2AccessToken .getScope ());
@@ -107,11 +111,22 @@ public void onFailure(Exception e) {
107111 this .prefs = this .context .getSharedPreferences ("OAuth_" + apiInstance .getClass ().getSimpleName () + "_" + consumerKey , 0 );
108112 this .editor = this .prefs .edit ();
109113 // Set access token in the tokenClient if already stored in preferences
110- if (this .checkAccessToken () != null ) {
111- tokenClient .setAccessToken (this .checkAccessToken ());
114+ Token accessToken = this .checkAccessToken ();
115+ if (accessToken != null ) {
116+ tokenClient .setAccessToken (accessToken );
117+ instantiateClient (consumerKey , consumerSecret , accessToken );
112118 }
113119 }
114120
121+ public void instantiateClient (String consumerKey , String consumerSecret , Token token ) {
122+
123+ if (token instanceof OAuth1AccessToken ) {
124+ client = OAuthAsyncHttpClient .create (consumerKey , consumerSecret , (OAuth1AccessToken )(token ));
125+ } else {
126+
127+ }
128+
129+ }
115130 // Fetches a request token and retrieve and authorization url
116131 // Should open a browser in onReceivedRequestToken once the url has been received
117132 public void connect () {
0 commit comments