@@ -18,6 +18,7 @@ public abstract class OAuthBaseClient {
18
18
protected String baseUrl ;
19
19
protected Context context ;
20
20
protected OAuthTokenClient tokenClient ;
21
+ protected OAuthAsyncHttpClient client ;
21
22
protected SharedPreferences prefs ;
22
23
protected SharedPreferences .Editor editor ;
23
24
protected OAuthAccessHandler accessHandler ;
@@ -45,7 +46,7 @@ public static OAuthBaseClient getInstance(Class<? extends OAuthBaseClient> klass
45
46
return instance ;
46
47
}
47
48
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 ) {
49
50
this .baseUrl = consumerUrl ;
50
51
this .callbackUrl = callbackUrl ;
51
52
tokenClient = new OAuthTokenClient (apiInstance , consumerKey ,
@@ -78,12 +79,15 @@ public void onReceivedAccessToken(Token accessToken, String oAuthVersion) {
78
79
OAuth1AccessToken oAuth1AccessToken = (OAuth1AccessToken ) accessToken ;
79
80
80
81
tokenClient .setAccessToken (accessToken );
82
+ instantiateClient (consumerKey , consumerSecret , oAuth1AccessToken );
81
83
editor .putString (OAuthConstants .TOKEN , oAuth1AccessToken .getToken ());
82
84
editor .putString (OAuthConstants .TOKEN_SECRET , oAuth1AccessToken .getTokenSecret ());
83
85
editor .putInt (OAuthConstants .VERSION , 1 );
84
86
editor .commit ();
85
87
} else if (oAuthVersion == OAUTH2_VERSION ) {
86
88
OAuth2AccessToken oAuth2AccessToken = (OAuth2AccessToken ) accessToken ;
89
+
90
+ //TODO(rhu) - create client for OAuth2 cases
87
91
tokenClient .setAccessToken (accessToken );
88
92
editor .putString (OAuthConstants .TOKEN , oAuth2AccessToken .getAccessToken ());
89
93
editor .putString (OAuthConstants .SCOPE , oAuth2AccessToken .getScope ());
@@ -107,11 +111,22 @@ public void onFailure(Exception e) {
107
111
this .prefs = this .context .getSharedPreferences ("OAuth_" + apiInstance .getClass ().getSimpleName () + "_" + consumerKey , 0 );
108
112
this .editor = this .prefs .edit ();
109
113
// 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 );
112
118
}
113
119
}
114
120
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
+ }
115
130
// Fetches a request token and retrieve and authorization url
116
131
// Should open a browser in onReceivedRequestToken once the url has been received
117
132
public void connect () {
0 commit comments