55import android .content .SharedPreferences ;
66import android .net .Uri ;
77
8+ import androidx .annotation .Nullable ;
9+
810import com .github .scribejava .core .builder .api .BaseApi ;
911import com .github .scribejava .core .model .OAuth1AccessToken ;
1012import com .github .scribejava .core .model .OAuth1RequestToken ;
@@ -46,11 +48,11 @@ public static OAuthBaseClient getInstance(Class<? extends OAuthBaseClient> klass
4648 return instance ;
4749 }
4850
49- public OAuthBaseClient (Context c , final BaseApi apiInstance , String consumerUrl , final String consumerKey , final String consumerSecret , String callbackUrl ) {
51+ public OAuthBaseClient (Context c , final BaseApi apiInstance , String consumerUrl , final String consumerKey , final String consumerSecret , @ Nullable String scope , String callbackUrl ) {
5052 this .baseUrl = consumerUrl ;
5153 this .callbackUrl = callbackUrl ;
5254 tokenClient = new OAuthTokenClient (apiInstance , consumerKey ,
53- consumerSecret , callbackUrl , new OAuthTokenClient .OAuthTokenHandler () {
55+ consumerSecret , callbackUrl , scope , new OAuthTokenClient .OAuthTokenHandler () {
5456
5557 // Store request token and launch the authorization URL in the browser
5658 @ Override
@@ -86,8 +88,7 @@ public void onReceivedAccessToken(Token accessToken, String oAuthVersion) {
8688 editor .commit ();
8789 } else if (oAuthVersion == OAUTH2_VERSION ) {
8890 OAuth2AccessToken oAuth2AccessToken = (OAuth2AccessToken ) accessToken ;
89-
90- //TODO(rhu) - create client for OAuth2 cases
91+ instantiateClient (consumerKey , consumerSecret , oAuth2AccessToken );
9192 tokenClient .setAccessToken (accessToken );
9293 editor .putString (OAuthConstants .TOKEN , oAuth2AccessToken .getAccessToken ());
9394 editor .putString (OAuthConstants .SCOPE , oAuth2AccessToken .getScope ());
@@ -122,8 +123,10 @@ public void instantiateClient(String consumerKey, String consumerSecret, Token t
122123
123124 if (token instanceof OAuth1AccessToken ) {
124125 client = OAuthAsyncHttpClient .create (consumerKey , consumerSecret , (OAuth1AccessToken )(token ));
126+ } else if (token instanceof OAuth2AccessToken ){
127+ client = OAuthAsyncHttpClient .create ((OAuth2AccessToken ) token );
125128 } else {
126-
129+ throw new IllegalStateException ( "unrecognized token type" + token );
127130 }
128131
129132 }
@@ -138,7 +141,7 @@ public void authorize(Uri uri, OAuthAccessHandler handler) {
138141 this .accessHandler = handler ;
139142 if (checkAccessToken () == null && uri != null ) {
140143 // TODO: check UriServiceCallback with intent:// scheme
141- tokenClient .fetchAccessToken (getOAuth1RequestToken (), uri );
144+ tokenClient .fetchAccessToken (checkAccessToken (), uri );
142145
143146 } else if (checkAccessToken () != null ) { // already have access token
144147 this .accessHandler .onLoginSuccess ();
0 commit comments