17
17
public abstract class OAuthBaseClient {
18
18
protected String baseUrl ;
19
19
protected Context context ;
20
- protected OAuthTokenClient client ;
20
+ protected OAuthTokenClient tokenClient ;
21
21
protected SharedPreferences prefs ;
22
22
protected SharedPreferences .Editor editor ;
23
23
protected OAuthAccessHandler accessHandler ;
@@ -48,7 +48,7 @@ public static OAuthBaseClient getInstance(Class<? extends OAuthBaseClient> klass
48
48
public OAuthBaseClient (Context c , BaseApi apiInstance , String consumerUrl , String consumerKey , String consumerSecret , String callbackUrl ) {
49
49
this .baseUrl = consumerUrl ;
50
50
this .callbackUrl = callbackUrl ;
51
- client = new OAuthTokenClient (apiInstance , consumerKey ,
51
+ tokenClient = new OAuthTokenClient (apiInstance , consumerKey ,
52
52
consumerSecret , callbackUrl , new OAuthTokenClient .OAuthTokenHandler () {
53
53
54
54
// Store request token and launch the authorization URL in the browser
@@ -70,21 +70,21 @@ public void onReceivedRequestToken(Token requestToken, String authorizeUrl, Stri
70
70
OAuthBaseClient .this .context .startActivity (intent );
71
71
}
72
72
73
- // Store the access token in preferences, set the token in the client and fire the success callback
73
+ // Store the access token in preferences, set the token in the tokenClient and fire the success callback
74
74
@ Override
75
75
public void onReceivedAccessToken (Token accessToken , String oAuthVersion ) {
76
76
77
77
if (oAuthVersion == OAUTH1_VERSION ) {
78
78
OAuth1AccessToken oAuth1AccessToken = (OAuth1AccessToken ) accessToken ;
79
79
80
- client .setAccessToken (accessToken );
80
+ tokenClient .setAccessToken (accessToken );
81
81
editor .putString (OAuthConstants .TOKEN , oAuth1AccessToken .getToken ());
82
82
editor .putString (OAuthConstants .TOKEN_SECRET , oAuth1AccessToken .getTokenSecret ());
83
83
editor .putInt (OAuthConstants .VERSION , 1 );
84
84
editor .commit ();
85
85
} else if (oAuthVersion == OAUTH2_VERSION ) {
86
86
OAuth2AccessToken oAuth2AccessToken = (OAuth2AccessToken ) accessToken ;
87
- client .setAccessToken (accessToken );
87
+ tokenClient .setAccessToken (accessToken );
88
88
editor .putString (OAuthConstants .TOKEN , oAuth2AccessToken .getAccessToken ());
89
89
editor .putString (OAuthConstants .SCOPE , oAuth2AccessToken .getScope ());
90
90
editor .putString (OAuthConstants .REFRESH_TOKEN , oAuth2AccessToken .getRefreshToken ());
@@ -106,24 +106,24 @@ public void onFailure(Exception e) {
106
106
// Store preferences namespaced by the class and consumer key used
107
107
this .prefs = this .context .getSharedPreferences ("OAuth_" + apiInstance .getClass ().getSimpleName () + "_" + consumerKey , 0 );
108
108
this .editor = this .prefs .edit ();
109
- // Set access token in the client if already stored in preferences
109
+ // Set access token in the tokenClient if already stored in preferences
110
110
if (this .checkAccessToken () != null ) {
111
- client .setAccessToken (this .checkAccessToken ());
111
+ tokenClient .setAccessToken (this .checkAccessToken ());
112
112
}
113
113
}
114
114
115
115
// Fetches a request token and retrieve and authorization url
116
116
// Should open a browser in onReceivedRequestToken once the url has been received
117
117
public void connect () {
118
- client .fetchRequestToken ();
118
+ tokenClient .fetchRequestToken ();
119
119
}
120
120
121
121
// Retrieves access token given authorization url
122
122
public void authorize (Uri uri , OAuthAccessHandler handler ) {
123
123
this .accessHandler = handler ;
124
124
if (checkAccessToken () == null && uri != null ) {
125
125
// TODO: check UriServiceCallback with intent:// scheme
126
- client .fetchAccessToken (getOAuth1RequestToken (), uri );
126
+ tokenClient .fetchAccessToken (getOAuth1RequestToken (), uri );
127
127
128
128
} else if (checkAccessToken () != null ) { // already have access token
129
129
this .accessHandler .onLoginSuccess ();
@@ -143,8 +143,8 @@ public Token checkAccessToken() {
143
143
return null ;
144
144
}
145
145
146
- protected OAuthTokenClient getClient () {
147
- return client ;
146
+ protected OAuthTokenClient getTokenClient () {
147
+ return tokenClient ;
148
148
}
149
149
150
150
// Returns the request token stored during the request token phase
@@ -165,17 +165,17 @@ protected String getApiUrl(String path) {
165
165
166
166
// Removes the access tokens (for signing out)
167
167
public void clearAccessToken () {
168
- client .setAccessToken (null );
168
+ tokenClient .setAccessToken (null );
169
169
editor .remove (OAuthConstants .TOKEN );
170
170
editor .remove (OAuthConstants .TOKEN_SECRET );
171
171
editor .remove (OAuthConstants .REFRESH_TOKEN );
172
172
editor .remove (OAuthConstants .SCOPE );
173
173
editor .commit ();
174
174
}
175
175
176
- // Returns true if the client is authenticated; false otherwise.
176
+ // Returns true if the tokenClient is authenticated; false otherwise.
177
177
public boolean isAuthenticated () {
178
- return client .getAccessToken () != null ;
178
+ return tokenClient .getAccessToken () != null ;
179
179
}
180
180
181
181
// Sets the flags used when launching browser to authenticate through OAuth
0 commit comments