From 8c66e25bcea883438cbf1d8d44f7be4ead7f5ad0 Mon Sep 17 00:00:00 2001 From: Roger Hu Date: Sat, 31 Mar 2018 23:49:16 -0700 Subject: [PATCH 01/29] Change to implementation now --- app/build.gradle | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 6c71c0a..ab7e826 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -115,11 +115,11 @@ ext { } dependencies { - compile "com.android.support:appcompat-v7:${supportVersion}" - compile "com.android.support:support-v4:${supportVersion}" - compile 'com.loopj.android:android-async-http:1.4.9' - compile files('libs/codepath-utils.jar') - compile 'com.github.scribejava:scribejava-apis:4.1.1' + implementation "com.android.support:appcompat-v7:${supportVersion}" + implementation "com.android.support:support-v4:${supportVersion}" + implementation 'com.loopj.android:android-async-http:1.4.9' + implementation files('libs/codepath-utils.jar') + implementation 'com.github.scribejava:scribejava-apis:4.1.1' } /*task jar(type: Jar) { From 52e39d18823a885a49a521ee37cfbfc59486520c Mon Sep 17 00:00:00 2001 From: Roger Hu Date: Sat, 31 Mar 2018 23:49:31 -0700 Subject: [PATCH 02/29] Bump Bintray plug-in version --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 8ec92f8..17be393 100644 --- a/build.gradle +++ b/build.gradle @@ -11,7 +11,7 @@ buildscript { } plugins { - id "com.jfrog.bintray" version "1.6" + id "com.jfrog.bintray" version "1.7.3" } bintray { From 4ee7bcf8bebee6aeeac0907d84528acf48bd4e5b Mon Sep 17 00:00:00 2001 From: Roger Hu Date: Sun, 1 Apr 2018 00:16:14 -0700 Subject: [PATCH 03/29] Bump plugin to support dependencies --- build.gradle | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 17be393..42d6ed0 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,6 @@ buildscript { } dependencies { classpath 'com.android.tools.build:gradle:3.0.1' - classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5' } } @@ -14,6 +13,10 @@ plugins { id "com.jfrog.bintray" version "1.7.3" } +plugins { + id "com.github.dcendents.android-maven" version "2.0" +} + bintray { publications = [] configurations = [] From a6071a6355cdd792e8d7ae70e0cbf4dc8f1c77fb Mon Sep 17 00:00:00 2001 From: Roger Hu Date: Sun, 1 Apr 2018 00:24:55 -0700 Subject: [PATCH 04/29] Expose these libs as dependencies --- app/build.gradle | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index ab7e826..49bae1f 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -8,7 +8,7 @@ ext { GROUP = 'com.codepath.libraries' BASE_VERSION = "1.3" - VERSION_NAME = "1.3.0" + VERSION_NAME = "1.3.1" POM_PACKAGING = "aar" POM_DESCRIPTION = "CodePath OAuth Handler" @@ -115,11 +115,11 @@ ext { } dependencies { - implementation "com.android.support:appcompat-v7:${supportVersion}" - implementation "com.android.support:support-v4:${supportVersion}" - implementation 'com.loopj.android:android-async-http:1.4.9' + api "com.android.support:appcompat-v7:${supportVersion}" + api "com.android.support:support-v4:${supportVersion}" + api 'com.loopj.android:android-async-http:1.4.9' implementation files('libs/codepath-utils.jar') - implementation 'com.github.scribejava:scribejava-apis:4.1.1' + api 'com.github.scribejava:scribejava-apis:4.1.1' } /*task jar(type: Jar) { From 5acb770717a102a57377a5e49bbba27ba5d3150b Mon Sep 17 00:00:00 2001 From: Roger Hu Date: Sat, 28 Apr 2018 10:23:13 -0700 Subject: [PATCH 05/29] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3884220..f96b443 100755 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ Next, add this line to your `app/build.gradle` file: ```gradle dependencies { - compile 'com.codepath.libraries:android-oauth-handler:1.2.5' + compile 'com.codepath.libraries:android-oauth-handler:1.3.1' } ``` From dc7ac4cee7e0b7d23ad7a3131e465150256cc47d Mon Sep 17 00:00:00 2001 From: Roger Hu Date: Mon, 28 Jan 2019 10:41:16 -0800 Subject: [PATCH 06/29] bump versions --- .travis.yml | 10 +++------- app/build.gradle | 11 +++++------ build.gradle | 6 +++--- gradle/wrapper/gradle-wrapper.properties | 4 ++-- 4 files changed, 13 insertions(+), 18 deletions(-) diff --git a/.travis.yml b/.travis.yml index cb97c9a..607a3b0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,14 +6,10 @@ android: components: - tools - platform-tools - - build-tools-27.0.3 - - android-27 - - extra-android-m2repository - - extra-google-m2repository - licenses: - - android-sdk-license-.+ + - build-tools-28.0.3 + - android-28 before_install: - - yes | sdkmanager "platforms;android-27" + - yes | sdkmanager "platforms;android-28" script: - "./gradlew build check --daemon" after_failure: "cat $TRAVIS_BUILD_DIR/app/build/outputs/lint-results.xml" diff --git a/app/build.gradle b/app/build.gradle index 49bae1f..9744b4b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -7,8 +7,8 @@ apply plugin: 'com.jfrog.bintray' ext { GROUP = 'com.codepath.libraries' - BASE_VERSION = "1.3" - VERSION_NAME = "1.3.1" + BASE_VERSION = "1.4" + VERSION_NAME = "1.4.0" POM_PACKAGING = "aar" POM_DESCRIPTION = "CodePath OAuth Handler" @@ -32,14 +32,13 @@ group = GROUP archivesBaseName = POM_ARTIFACT_ID android { - compileSdkVersion 27 - buildToolsVersion "27.0.3" + compileSdkVersion 28 defaultConfig { versionCode 1 versionName VERSION_NAME minSdkVersion 14 - targetSdkVersion 27 + targetSdkVersion 28 } // Related to https://github.com/scribejava/scribejava/issues/480 @@ -111,7 +110,7 @@ bintray { } ext { - supportVersion = '27.1.0' + supportVersion = '28.0.0' } dependencies { diff --git a/build.gradle b/build.gradle index 42d6ed0..9d73a49 100644 --- a/build.gradle +++ b/build.gradle @@ -1,11 +1,11 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { repositories { - jcenter() google() + jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:3.0.1' + classpath 'com.android.tools.build:gradle:3.3.0' } } @@ -24,8 +24,8 @@ bintray { allprojects { repositories { - jcenter() google() + jcenter() } } /* diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index d19e467..dc63add 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Sat Mar 31 23:33:37 PDT 2018 +#Mon Jan 28 10:39:02 PST 2019 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip From b53ca0a8ec3fed469934787c25aefdd5cc724797 Mon Sep 17 00:00:00 2001 From: Roger Hu Date: Sun, 11 Aug 2019 00:43:35 -0700 Subject: [PATCH 07/29] Bump to AndroidX --- app/build.gradle | 5 ++--- .../java/com/codepath/oauth/OAuthLoginActionBarActivity.java | 4 +++- app/src/main/java/com/codepath/oauth/OAuthLoginActivity.java | 3 ++- app/src/main/java/com/codepath/oauth/OAuthLoginFragment.java | 3 ++- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 9744b4b..166ec72 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -37,7 +37,7 @@ android { defaultConfig { versionCode 1 versionName VERSION_NAME - minSdkVersion 14 + minSdkVersion 21 targetSdkVersion 28 } @@ -114,8 +114,7 @@ ext { } dependencies { - api "com.android.support:appcompat-v7:${supportVersion}" - api "com.android.support:support-v4:${supportVersion}" + api "androidx.appcompat:appcompat:1.0.2" api 'com.loopj.android:android-async-http:1.4.9' implementation files('libs/codepath-utils.jar') api 'com.github.scribejava:scribejava-apis:4.1.1' diff --git a/app/src/main/java/com/codepath/oauth/OAuthLoginActionBarActivity.java b/app/src/main/java/com/codepath/oauth/OAuthLoginActionBarActivity.java index beea737..6ced975 100755 --- a/app/src/main/java/com/codepath/oauth/OAuthLoginActionBarActivity.java +++ b/app/src/main/java/com/codepath/oauth/OAuthLoginActionBarActivity.java @@ -4,7 +4,9 @@ import android.content.Intent; import android.net.Uri; -import android.support.v7.app.AppCompatActivity; + +import androidx.appcompat.app.AppCompatActivity; + // This is the ActionBarActivity supportv7 version of LoginActivity public abstract class OAuthLoginActionBarActivity extends diff --git a/app/src/main/java/com/codepath/oauth/OAuthLoginActivity.java b/app/src/main/java/com/codepath/oauth/OAuthLoginActivity.java index 53d4a8a..64fa354 100755 --- a/app/src/main/java/com/codepath/oauth/OAuthLoginActivity.java +++ b/app/src/main/java/com/codepath/oauth/OAuthLoginActivity.java @@ -2,7 +2,8 @@ import android.content.Intent; import android.net.Uri; -import android.support.v4.app.FragmentActivity; + +import androidx.fragment.app.FragmentActivity; import com.codepath.utils.GenericsUtil; diff --git a/app/src/main/java/com/codepath/oauth/OAuthLoginFragment.java b/app/src/main/java/com/codepath/oauth/OAuthLoginFragment.java index 10645d2..9fe5c72 100755 --- a/app/src/main/java/com/codepath/oauth/OAuthLoginFragment.java +++ b/app/src/main/java/com/codepath/oauth/OAuthLoginFragment.java @@ -2,7 +2,8 @@ import android.net.Uri; import android.os.Bundle; -import android.support.v4.app.Fragment; + +import androidx.fragment.app.Fragment; import com.codepath.utils.GenericsUtil; From 600d27d3c144c9899f8566db2d8f5432add351bf Mon Sep 17 00:00:00 2001 From: Roger Hu Date: Sun, 11 Aug 2019 06:53:21 -0700 Subject: [PATCH 08/29] Get rid of Async Http Client in general bump version --- app/build.gradle | 3 +- .../codepath/oauth/OAuthAsyncHttpClient.java | 173 ++++++++--------- .../com/codepath/oauth/OAuthBaseClient.java | 8 - .../codepath/oauth/ScribeRequestAdapter.java | 174 ------------------ build.gradle | 2 +- 5 files changed, 76 insertions(+), 284 deletions(-) delete mode 100755 app/src/main/java/com/codepath/oauth/ScribeRequestAdapter.java diff --git a/app/build.gradle b/app/build.gradle index 166ec72..18d635e 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -115,9 +115,10 @@ ext { dependencies { api "androidx.appcompat:appcompat:1.0.2" - api 'com.loopj.android:android-async-http:1.4.9' + api 'com.codepath.libraries:asynchttpclient:0.0.1' implementation files('libs/codepath-utils.jar') api 'com.github.scribejava:scribejava-apis:4.1.1' + api 'com.github.scribejava:scribejava-httpclient-okhttp:4.1.1' } /*task jar(type: Jar) { diff --git a/app/src/main/java/com/codepath/oauth/OAuthAsyncHttpClient.java b/app/src/main/java/com/codepath/oauth/OAuthAsyncHttpClient.java index 8b4a2b5..78f1831 100755 --- a/app/src/main/java/com/codepath/oauth/OAuthAsyncHttpClient.java +++ b/app/src/main/java/com/codepath/oauth/OAuthAsyncHttpClient.java @@ -3,19 +3,20 @@ import android.content.Context; import android.net.Uri; +import com.codepath.asynchttpclient.AsyncHttpClient; import com.codepath.utils.AsyncSimpleTask; import com.github.scribejava.core.builder.ServiceBuilder; import com.github.scribejava.core.builder.api.BaseApi; import com.github.scribejava.core.exceptions.OAuthException; +import com.github.scribejava.core.model.OAuth1AccessToken; import com.github.scribejava.core.model.OAuth1RequestToken; +import com.github.scribejava.core.model.OAuth2AccessToken; +import com.github.scribejava.core.model.OAuthAsyncRequestCallback; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.Token; import com.github.scribejava.core.oauth.OAuth10aService; import com.github.scribejava.core.oauth.OAuth20Service; import com.github.scribejava.core.oauth.OAuthService; -import com.loopj.android.http.AsyncHttpClient; -import com.loopj.android.http.RequestHandle; -import com.loopj.android.http.ResponseHandlerInterface; /* * OAuthAsyncHttpClient is responsible for managing the request and access token exchanges and then @@ -45,86 +46,85 @@ public OAuthAsyncHttpClient(BaseApi apiInstance, String consumerKey, String cons // Once fetched, fire the onReceivedRequestToken for the request token handler // Works for both OAuth1.0a and OAuth2 public void fetchRequestToken() { - new AsyncSimpleTask(new AsyncSimpleTask.AsyncSimpleTaskHandler() { - String authorizeUrl = null; - Exception e = null; - Token requestToken; - - public void doInBackground() { - try { - if (service.getVersion() == "1.0") { - OAuth10aService oAuth10aService = (OAuth10aService) service; - requestToken = oAuth10aService.getRequestToken(); - authorizeUrl = oAuth10aService.getAuthorizationUrl((OAuth1RequestToken) requestToken); - } else if (service.getVersion() == "2.0") { - OAuth20Service oAuth20Service = (OAuth20Service) service; - authorizeUrl = oAuth20Service.getAuthorizationUrl(null); - } - } catch (Exception e) { - this.e = e; + if (service.getVersion() == "1.0") { + final OAuth10aService oAuth10aService = (OAuth10aService) service; + oAuth10aService.getRequestTokenAsync(new OAuthAsyncRequestCallback() { + @Override + public void onCompleted(OAuth1RequestToken requestToken) { + String authorizeUrl = oAuth10aService.getAuthorizationUrl((OAuth1RequestToken) requestToken); + handler.onReceivedRequestToken(requestToken, authorizeUrl, service.getVersion()); + } - } - public void onPostExecute() { - if (e != null) { - handler.onFailure(e); - } else { - handler.onReceivedRequestToken(requestToken, authorizeUrl, service.getVersion()); + @Override + public void onThrowable(Throwable t) { + handler.onFailure(new Exception(t.getMessage())); } - } - }); + }); + } + if (service.getVersion() == "2.0") { + OAuth20Service oAuth20Service = (OAuth20Service) service; + String authorizeUrl = oAuth20Service.getAuthorizationUrl(null); + handler.onReceivedRequestToken(null, authorizeUrl, service.getVersion()); + } } // Get the access token by exchanging the requestToken to the defined URL // Once receiving the access token, fires the onReceivedAccessToken method on the handler public void fetchAccessToken(final Token requestToken, final Uri uri) { - new AsyncSimpleTask(new AsyncSimpleTask.AsyncSimpleTaskHandler() { - Exception e = null; - - public void doInBackground() { - // Fetch the verifier code from redirect url parameters - Uri authorizedUri = uri; - - try { - if (service.getVersion() == "1.0") { - // Use verifier token to fetch access token - - if (authorizedUri.getQuery().contains(OAuthConstants.VERIFIER)) { - String oauth_verifier = authorizedUri.getQueryParameter(OAuthConstants.VERIFIER); - OAuth1RequestToken oAuth1RequestToken = (OAuth1RequestToken) requestToken; - OAuth10aService oAuth10aService = (OAuth10aService) service; - accessToken = oAuth10aService.getAccessToken(oAuth1RequestToken, oauth_verifier); - } - else { // verifier was null - throw new OAuthException("No verifier code was returned with uri '" + uri + "' " + - "and access token cannot be retrieved"); - } - } else if (service.getVersion() == "2.0") { - if (authorizedUri.getQuery().contains(OAuthConstants.CODE)) { - String code = authorizedUri.getQueryParameter(OAuthConstants.CODE); - OAuth20Service oAuth20Service = (OAuth20Service) service; - accessToken = oAuth20Service.getAccessToken(code); - } - else { // verifier was null - throw new OAuthException("No code was returned with uri '" + uri + "' " + - "and access token cannot be retrieved"); - } - } - } catch (Exception e) { - this.e = e; - } + Uri authorizedUri = uri; + + if (service.getVersion() == "1.0") { + // Use verifier token to fetch access token + + if (authorizedUri.getQuery().contains(OAuthConstants.VERIFIER)) { + String oauth_verifier = authorizedUri.getQueryParameter(OAuthConstants.VERIFIER); + OAuth1RequestToken oAuth1RequestToken = (OAuth1RequestToken) requestToken; + OAuth10aService oAuth10aService = (OAuth10aService) service; + + oAuth10aService.getAccessTokenAsync(oAuth1RequestToken, oauth_verifier, + new OAuthAsyncRequestCallback() { + + @Override + public void onCompleted(OAuth1AccessToken oAuth1AccessToken) { + handler.onReceivedAccessToken(oAuth1AccessToken, service.getVersion()); + } + + @Override + public void onThrowable(Throwable e) { + handler.onFailure(new OAuthException(e.getMessage())); + } + }); + } + else { // verifier was null + throw new OAuthException("No verifier code was returned with uri '" + uri + "' " + + "and access token cannot be retrieved"); + } + } else if (service.getVersion() == "2.0") { + if (authorizedUri.getQuery().contains(OAuthConstants.CODE)) { + String code = authorizedUri.getQueryParameter(OAuthConstants.CODE); + OAuth20Service oAuth20Service = (OAuth20Service) service; + oAuth20Service.getAccessToken(code, new OAuthAsyncRequestCallback() { + @Override + public void onCompleted(OAuth2AccessToken accessToken) { + setAccessToken(accessToken); + handler.onReceivedAccessToken(accessToken, service.getVersion()); - public void onPostExecute() { - if (e != null) { - handler.onFailure(e); - } else { - setAccessToken(accessToken); - handler.onReceivedAccessToken(accessToken, service.getVersion()); - } + } + + @Override + public void onThrowable(Throwable t) { + + } + }); } - }); + else { // verifier was null + handler.onFailure(new OAuthException("No code was returned with uri '" + uri + "' " + + "and access token cannot be retrieved")); + } + } } // Set the access token used for signing requests @@ -133,40 +133,13 @@ public void setAccessToken(Token accessToken) { this.accessToken = null; } else { this.accessToken = accessToken; - } + } } public Token getAccessToken() { return this.accessToken; } - - // Send scribe signed request based on the async http client to construct a signed request - // Accepts an HttpEntity which has the underlying entity for the request params - - @Override - protected RequestHandle sendRequest( - cz.msebera.android.httpclient.impl.client.DefaultHttpClient client, - cz.msebera.android.httpclient.protocol.HttpContext httpContext, - cz.msebera.android.httpclient.client.methods.HttpUriRequest uriRequest, - String contentType, ResponseHandlerInterface responseHandler, - Context context) { - - if (this.service != null && accessToken != null) { - try { - ScribeRequestAdapter adapter = new ScribeRequestAdapter(uriRequest); - this.service.signRequest(accessToken, adapter); - return super.sendRequest(client, httpContext, uriRequest, contentType, responseHandler, context); - } catch (Exception e) { - e.printStackTrace(); - } - } else if (accessToken == null) { - throw new OAuthException("Cannot send unauthenticated requests for " + apiInstance.getClass().getSimpleName() + " client. Please attach an access token!"); - } else { // service is null - throw new OAuthException("Cannot send unauthenticated requests for undefined service. Please specify a valid api service!"); - } - return null; // Hopefully never reaches here - } - + // Defines the interface handler for different token handlers public interface OAuthTokenHandler { public void onReceivedRequestToken(Token requestToken, String authorizeUrl, String oAuthVersion); diff --git a/app/src/main/java/com/codepath/oauth/OAuthBaseClient.java b/app/src/main/java/com/codepath/oauth/OAuthBaseClient.java index 1db4680..8b88c7b 100755 --- a/app/src/main/java/com/codepath/oauth/OAuthBaseClient.java +++ b/app/src/main/java/com/codepath/oauth/OAuthBaseClient.java @@ -189,12 +189,4 @@ public static interface OAuthAccessHandler { public void onLoginFailure(Exception e); } - - public void enableProxy() { - client.setProxy(System.getProperty("http.proxyHost"), Integer.parseInt(System.getProperty("http.proxyPort"))); - } - - public void addHeader(String headerName, String headerValue) { - client.addHeader(headerName, headerValue); - } } diff --git a/app/src/main/java/com/codepath/oauth/ScribeRequestAdapter.java b/app/src/main/java/com/codepath/oauth/ScribeRequestAdapter.java deleted file mode 100755 index 12f9aa8..0000000 --- a/app/src/main/java/com/codepath/oauth/ScribeRequestAdapter.java +++ /dev/null @@ -1,174 +0,0 @@ -package com.codepath.oauth; - -import android.net.Uri; - -import com.github.scribejava.core.model.OAuthConstants; -import com.github.scribejava.core.model.OAuthRequest; -import com.github.scribejava.core.model.ParameterList; -import com.github.scribejava.core.model.Verb; - -import java.io.UnsupportedEncodingException; -import java.net.URI; -import java.net.URLDecoder; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import cz.msebera.android.httpclient.NameValuePair; -import cz.msebera.android.httpclient.client.methods.HttpEntityEnclosingRequestBase; -import cz.msebera.android.httpclient.client.methods.HttpRequestBase; -import cz.msebera.android.httpclient.client.methods.HttpUriRequest; -import cz.msebera.android.httpclient.client.utils.URLEncodedUtils; - -/* - * Implements the scribe-java Request interface allowing - * AsyncHttpClient requests to be signed with Scribe. - */ -public class ScribeRequestAdapter extends OAuthRequest { - private cz.msebera.android.httpclient.client.methods.HttpUriRequest httpUriRequest; - private HashMap oauthParameters; - - public ScribeRequestAdapter( - cz.msebera.android.httpclient.client.methods.HttpUriRequest httpUriRequest) { - - super(getMethod(httpUriRequest.getMethod()), httpUriRequest.getURI().toString()); - - this.httpUriRequest = httpUriRequest; - this.oauthParameters = new HashMap(); - } - - public static Verb getMethod(String method) { - switch (method) { - case "GET": - return Verb.GET; - case "POST": - return Verb.POST; - case "DELETE": - return Verb.DELETE; - case "PUT": - return Verb.PUT; - case "PATCH": - return Verb.PATCH; - case "OPTIONS": - return Verb.OPTIONS; - } - throw new IllegalStateException(method); - } - // Adds OAuth parameter with associated value - @Override - public void addOAuthParameter(String key, String value) { - this.oauthParameters.put(key, value); - } - - // Returns OAuth parameters - @Override - public Map getOauthParameters() { - return this.oauthParameters; - } - - // Adds header entry with associated value - @Override - public void addHeader(String key, String value) { - this.httpUriRequest.addHeader(key, value); - } - - // Add query string parameters to the HTTP Request. - @Override - public void addQuerystringParameter(String key, String value) { - // Workaround since some OAuth2 require "access_token" and others "oauth_token" - if (key.equals(OAuthConstants.ACCESS_TOKEN)) { addQuerystringParameter(OAuthConstants.TOKEN, value); } - // Workaround, convert URI to Uri, build on the URL to add the new query parameter and then update the HTTP Request - Uri updatedUri = Uri.parse(httpUriRequest.getURI().toString()).buildUpon().appendQueryParameter(key, value).build(); - ((HttpRequestBase) httpUriRequest).setURI(URI.create(updatedUri.toString())); - } - - // Returns query strings embedded in the URL - @Override - public ParameterList getQueryStringParams() { - try { - return parseQueryParams(); - } catch (UnsupportedEncodingException e) { - return new ParameterList(); - } - } - - // Returns params parsed from the entity body - @Override - public ParameterList getBodyParams() { - if (getVerb() == Verb.GET || getVerb() == Verb.DELETE) { return new ParameterList(); } - else { return parseEntityParams(); } - } - - // Returns the full URL with query strings - @Override - public String getCompleteUrl() { - return getHttpRequest().getURI().toString(); - } - - // Returns the base URL without query strings or host - @Override - public String getSanitizedUrl() { - return getCompleteUrl().replaceAll("\\?.*", "").replace("\\:\\d{4}", ""); - } - - // Returns Verb enum for the request method (i.e Verb.GET) - @Override - public Verb getVerb() { - return Verb.valueOf(getHttpRequest().getMethod()); - } - - // Returns simple string representation of the request - // i.e @Request(GET http://foo.com/bar) - @Override - public String toString() - { - return String.format("@Request(%s %s)", getVerb(), getCompleteUrl()); - } - - // Returns the underlying HTTP request - protected HttpUriRequest getHttpRequest() { - return this.httpUriRequest; - } - - // Parses and returns the entity provided as a ParameterList - private ParameterList parseEntityParams() { - cz.msebera.android.httpclient.HttpEntity entity = null; - List parameters = null; - try{ - entity = ((HttpEntityEnclosingRequestBase) httpUriRequest).getEntity(); - parameters = new ArrayList( URLEncodedUtils.parse(entity)); - } catch (Exception e) { - return new ParameterList(); - } - - ParameterList list = new ParameterList(); - for (NameValuePair pair : parameters) { - list.add(pair.getName(), pair.getValue()); - } - return list; - } - - // Returns the ParameterList of query parameters parsed from the URL string - private ParameterList parseQueryParams() throws UnsupportedEncodingException { - ParameterList params = new ParameterList(); - String queryString = URI.create(getCompleteUrl()).getQuery(); - if (queryString == null) { return params; } - for (String param : queryString.split("&")) { - String pair[] = param.split("="); - String key = URLDecoder.decode(pair[0], "UTF-8"); - String value = ""; - if (pair.length > 1) { - value = URLDecoder.decode(pair[1], "UTF-8"); - } - params.add(new String(key), new String(value)); - } - return params; - } - - @Override - public String getRealm() { - return null; - } - -} diff --git a/build.gradle b/build.gradle index 9d73a49..edb3243 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:3.3.0' + classpath 'com.android.tools.build:gradle:3.4.2' } } From 7a03f9b7ed846baef0c6dd0a451790b31ae86c58 Mon Sep 17 00:00:00 2001 From: Roger Hu Date: Sun, 11 Aug 2019 07:00:59 -0700 Subject: [PATCH 09/29] rename client name --- .../main/java/com/codepath/oauth/OAuthBaseClient.java | 8 ++++---- ...AuthAsyncHttpClient.java => OAuthTokenClient.java} | 11 ++++------- 2 files changed, 8 insertions(+), 11 deletions(-) rename app/src/main/java/com/codepath/oauth/{OAuthAsyncHttpClient.java => OAuthTokenClient.java} (92%) diff --git a/app/src/main/java/com/codepath/oauth/OAuthBaseClient.java b/app/src/main/java/com/codepath/oauth/OAuthBaseClient.java index 8b88c7b..b565302 100755 --- a/app/src/main/java/com/codepath/oauth/OAuthBaseClient.java +++ b/app/src/main/java/com/codepath/oauth/OAuthBaseClient.java @@ -17,7 +17,7 @@ public abstract class OAuthBaseClient { protected String baseUrl; protected Context context; - protected OAuthAsyncHttpClient client; + protected OAuthTokenClient client; protected SharedPreferences prefs; protected SharedPreferences.Editor editor; protected OAuthAccessHandler accessHandler; @@ -48,8 +48,8 @@ public static OAuthBaseClient getInstance(Class klass public OAuthBaseClient(Context c, BaseApi apiInstance, String consumerUrl, String consumerKey, String consumerSecret, String callbackUrl) { this.baseUrl = consumerUrl; this.callbackUrl = callbackUrl; - client = new OAuthAsyncHttpClient(apiInstance, consumerKey, - consumerSecret, callbackUrl, new OAuthAsyncHttpClient.OAuthTokenHandler() { + client = new OAuthTokenClient(apiInstance, consumerKey, + consumerSecret, callbackUrl, new OAuthTokenClient.OAuthTokenHandler() { // Store request token and launch the authorization URL in the browser @Override @@ -143,7 +143,7 @@ public Token checkAccessToken() { return null; } - protected OAuthAsyncHttpClient getClient() { + protected OAuthTokenClient getClient() { return client; } diff --git a/app/src/main/java/com/codepath/oauth/OAuthAsyncHttpClient.java b/app/src/main/java/com/codepath/oauth/OAuthTokenClient.java similarity index 92% rename from app/src/main/java/com/codepath/oauth/OAuthAsyncHttpClient.java rename to app/src/main/java/com/codepath/oauth/OAuthTokenClient.java index 78f1831..6b4f2e3 100755 --- a/app/src/main/java/com/codepath/oauth/OAuthAsyncHttpClient.java +++ b/app/src/main/java/com/codepath/oauth/OAuthTokenClient.java @@ -1,10 +1,7 @@ package com.codepath.oauth; -import android.content.Context; import android.net.Uri; -import com.codepath.asynchttpclient.AsyncHttpClient; -import com.codepath.utils.AsyncSimpleTask; import com.github.scribejava.core.builder.ServiceBuilder; import com.github.scribejava.core.builder.api.BaseApi; import com.github.scribejava.core.exceptions.OAuthException; @@ -19,11 +16,11 @@ import com.github.scribejava.core.oauth.OAuthService; /* - * OAuthAsyncHttpClient is responsible for managing the request and access token exchanges and then + * OAuthTokenClient is responsible for managing the request and access token exchanges and then * signing all requests with the OAuth signature after access token has been retrieved and stored. * The client is based on AsyncHttpClient for async http requests and uses Scribe to manage the OAuth authentication. */ -public class OAuthAsyncHttpClient extends AsyncHttpClient { +public class OAuthTokenClient { private BaseApi apiInstance; private OAuthTokenHandler handler; @@ -31,8 +28,8 @@ public class OAuthAsyncHttpClient extends AsyncHttpClient { private OAuthService service; // Requires the apiClass, consumerKey, consumerSecret and callbackUrl along with the TokenHandler - public OAuthAsyncHttpClient(BaseApi apiInstance, String consumerKey, String consumerSecret, String callbackUrl, - OAuthTokenHandler handler) { + public OAuthTokenClient(BaseApi apiInstance, String consumerKey, String consumerSecret, String callbackUrl, + OAuthTokenHandler handler) { this.apiInstance = apiInstance; this.handler = handler; if (callbackUrl == null) { callbackUrl = OAuthConstants.OUT_OF_BAND; }; From de780840277c7141e9c86b318841e4517bf94830 Mon Sep 17 00:00:00 2001 From: Roger Hu Date: Sun, 11 Aug 2019 07:04:28 -0700 Subject: [PATCH 10/29] rename to token client --- .../com/codepath/oauth/OAuthBaseClient.java | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/com/codepath/oauth/OAuthBaseClient.java b/app/src/main/java/com/codepath/oauth/OAuthBaseClient.java index b565302..3f10c50 100755 --- a/app/src/main/java/com/codepath/oauth/OAuthBaseClient.java +++ b/app/src/main/java/com/codepath/oauth/OAuthBaseClient.java @@ -17,7 +17,7 @@ public abstract class OAuthBaseClient { protected String baseUrl; protected Context context; - protected OAuthTokenClient client; + protected OAuthTokenClient tokenClient; protected SharedPreferences prefs; protected SharedPreferences.Editor editor; protected OAuthAccessHandler accessHandler; @@ -48,7 +48,7 @@ public static OAuthBaseClient getInstance(Class klass public OAuthBaseClient(Context c, BaseApi apiInstance, String consumerUrl, String consumerKey, String consumerSecret, String callbackUrl) { this.baseUrl = consumerUrl; this.callbackUrl = callbackUrl; - client = new OAuthTokenClient(apiInstance, consumerKey, + tokenClient = new OAuthTokenClient(apiInstance, consumerKey, consumerSecret, callbackUrl, new OAuthTokenClient.OAuthTokenHandler() { // Store request token and launch the authorization URL in the browser @@ -70,21 +70,21 @@ public void onReceivedRequestToken(Token requestToken, String authorizeUrl, Stri OAuthBaseClient.this.context.startActivity(intent); } - // Store the access token in preferences, set the token in the client and fire the success callback + // Store the access token in preferences, set the token in the tokenClient and fire the success callback @Override public void onReceivedAccessToken(Token accessToken, String oAuthVersion) { if (oAuthVersion == OAUTH1_VERSION) { OAuth1AccessToken oAuth1AccessToken = (OAuth1AccessToken) accessToken; - client.setAccessToken(accessToken); + tokenClient.setAccessToken(accessToken); editor.putString(OAuthConstants.TOKEN, oAuth1AccessToken.getToken()); editor.putString(OAuthConstants.TOKEN_SECRET, oAuth1AccessToken.getTokenSecret()); editor.putInt(OAuthConstants.VERSION, 1); editor.commit(); } else if (oAuthVersion == OAUTH2_VERSION) { OAuth2AccessToken oAuth2AccessToken = (OAuth2AccessToken) accessToken; - client.setAccessToken(accessToken); + tokenClient.setAccessToken(accessToken); editor.putString(OAuthConstants.TOKEN, oAuth2AccessToken.getAccessToken()); editor.putString(OAuthConstants.SCOPE, oAuth2AccessToken.getScope()); editor.putString(OAuthConstants.REFRESH_TOKEN, oAuth2AccessToken.getRefreshToken()); @@ -106,16 +106,16 @@ public void onFailure(Exception e) { // Store preferences namespaced by the class and consumer key used this.prefs = this.context.getSharedPreferences("OAuth_" + apiInstance.getClass().getSimpleName() + "_" + consumerKey, 0); this.editor = this.prefs.edit(); - // Set access token in the client if already stored in preferences + // Set access token in the tokenClient if already stored in preferences if (this.checkAccessToken() != null) { - client.setAccessToken(this.checkAccessToken()); + tokenClient.setAccessToken(this.checkAccessToken()); } } // Fetches a request token and retrieve and authorization url // Should open a browser in onReceivedRequestToken once the url has been received public void connect() { - client.fetchRequestToken(); + tokenClient.fetchRequestToken(); } // Retrieves access token given authorization url @@ -123,7 +123,7 @@ public void authorize(Uri uri, OAuthAccessHandler handler) { this.accessHandler = handler; if (checkAccessToken() == null && uri != null) { // TODO: check UriServiceCallback with intent:// scheme - client.fetchAccessToken(getOAuth1RequestToken(), uri); + tokenClient.fetchAccessToken(getOAuth1RequestToken(), uri); } else if (checkAccessToken() != null) { // already have access token this.accessHandler.onLoginSuccess(); @@ -143,8 +143,8 @@ public Token checkAccessToken() { return null; } - protected OAuthTokenClient getClient() { - return client; + protected OAuthTokenClient getTokenClient() { + return tokenClient; } // Returns the request token stored during the request token phase @@ -165,7 +165,7 @@ protected String getApiUrl(String path) { // Removes the access tokens (for signing out) public void clearAccessToken() { - client.setAccessToken(null); + tokenClient.setAccessToken(null); editor.remove(OAuthConstants.TOKEN); editor.remove(OAuthConstants.TOKEN_SECRET); editor.remove(OAuthConstants.REFRESH_TOKEN); @@ -173,9 +173,9 @@ public void clearAccessToken() { editor.commit(); } - // Returns true if the client is authenticated; false otherwise. + // Returns true if the tokenClient is authenticated; false otherwise. public boolean isAuthenticated() { - return client.getAccessToken() != null; + return tokenClient.getAccessToken() != null; } // Sets the flags used when launching browser to authenticate through OAuth From 5ddc2846d2cdd588f8f252e2a31e58d04cc6b7fd Mon Sep 17 00:00:00 2001 From: Roger Hu Date: Sun, 11 Aug 2019 07:06:53 -0700 Subject: [PATCH 11/29] add OAuthAsyncHttpClient fix bugs bump versions --- app/build.gradle | 11 +++++--- .../codepath/oauth/OAuthAsyncHttpClient.java | 26 +++++++++++++++++++ .../com/codepath/oauth/OAuthBaseClient.java | 21 ++++++++++++--- .../oauth/OAuthLoginActionBarActivity.java | 4 +-- .../com/codepath/oauth/OAuthTokenClient.java | 9 ++++--- 5 files changed, 60 insertions(+), 11 deletions(-) create mode 100644 app/src/main/java/com/codepath/oauth/OAuthAsyncHttpClient.java diff --git a/app/build.gradle b/app/build.gradle index 18d635e..471e149 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -7,8 +7,8 @@ apply plugin: 'com.jfrog.bintray' ext { GROUP = 'com.codepath.libraries' - BASE_VERSION = "1.4" - VERSION_NAME = "1.4.0" + BASE_VERSION = "2.0" + VERSION_NAME = "2.0.0" POM_PACKAGING = "aar" POM_DESCRIPTION = "CodePath OAuth Handler" @@ -115,10 +115,15 @@ ext { dependencies { api "androidx.appcompat:appcompat:1.0.2" - api 'com.codepath.libraries:asynchttpclient:0.0.1' + api 'com.codepath.libraries:asynchttpclient:0.0.5' implementation files('libs/codepath-utils.jar') api 'com.github.scribejava:scribejava-apis:4.1.1' api 'com.github.scribejava:scribejava-httpclient-okhttp:4.1.1' + implementation 'se.akerfeldt:okhttp-signpost:1.1.0' + implementation 'oauth.signpost:signpost-core:1.2.1.2' + implementation 'com.facebook.stetho:stetho:1.5.1' + implementation 'com.facebook.stetho:stetho-okhttp3:1.5.1' + } /*task jar(type: Jar) { diff --git a/app/src/main/java/com/codepath/oauth/OAuthAsyncHttpClient.java b/app/src/main/java/com/codepath/oauth/OAuthAsyncHttpClient.java new file mode 100644 index 0000000..8b345e7 --- /dev/null +++ b/app/src/main/java/com/codepath/oauth/OAuthAsyncHttpClient.java @@ -0,0 +1,26 @@ +package com.codepath.oauth; + +import com.codepath.asynchttpclient.AsyncHttpClient; +import com.facebook.stetho.okhttp3.StethoInterceptor; +import com.github.scribejava.core.model.OAuth1AccessToken; + +import okhttp3.OkHttpClient; +import se.akerfeldt.okhttp.signpost.OkHttpOAuthConsumer; +import se.akerfeldt.okhttp.signpost.SigningInterceptor; + +public class OAuthAsyncHttpClient extends AsyncHttpClient { + + protected OAuthAsyncHttpClient(OkHttpClient httpClient) { + super(httpClient); + } + + public static OAuthAsyncHttpClient create(String consumerKey, String consumerSecret, OAuth1AccessToken token) { + OkHttpOAuthConsumer consumer = new OkHttpOAuthConsumer(consumerKey, consumerSecret); + consumer.setTokenWithSecret(token.getToken(), token.getTokenSecret()); + OkHttpClient httpClient = new OkHttpClient.Builder().addNetworkInterceptor(new StethoInterceptor()).addInterceptor(new SigningInterceptor(consumer)).build(); + + OAuthAsyncHttpClient asyncHttpClient = new OAuthAsyncHttpClient(httpClient); + return asyncHttpClient; + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/codepath/oauth/OAuthBaseClient.java b/app/src/main/java/com/codepath/oauth/OAuthBaseClient.java index 3f10c50..04ef5fc 100755 --- a/app/src/main/java/com/codepath/oauth/OAuthBaseClient.java +++ b/app/src/main/java/com/codepath/oauth/OAuthBaseClient.java @@ -18,6 +18,7 @@ public abstract class OAuthBaseClient { protected String baseUrl; protected Context context; protected OAuthTokenClient tokenClient; + protected OAuthAsyncHttpClient client; protected SharedPreferences prefs; protected SharedPreferences.Editor editor; protected OAuthAccessHandler accessHandler; @@ -45,7 +46,7 @@ public static OAuthBaseClient getInstance(Class klass return instance; } - public OAuthBaseClient(Context c, BaseApi apiInstance, String consumerUrl, String consumerKey, String consumerSecret, String callbackUrl) { + public OAuthBaseClient(Context c, final BaseApi apiInstance, String consumerUrl, final String consumerKey, final String consumerSecret, String callbackUrl) { this.baseUrl = consumerUrl; this.callbackUrl = callbackUrl; tokenClient = new OAuthTokenClient(apiInstance, consumerKey, @@ -78,12 +79,15 @@ public void onReceivedAccessToken(Token accessToken, String oAuthVersion) { OAuth1AccessToken oAuth1AccessToken = (OAuth1AccessToken) accessToken; tokenClient.setAccessToken(accessToken); + instantiateClient(consumerKey, consumerSecret, oAuth1AccessToken); editor.putString(OAuthConstants.TOKEN, oAuth1AccessToken.getToken()); editor.putString(OAuthConstants.TOKEN_SECRET, oAuth1AccessToken.getTokenSecret()); editor.putInt(OAuthConstants.VERSION, 1); editor.commit(); } else if (oAuthVersion == OAUTH2_VERSION) { OAuth2AccessToken oAuth2AccessToken = (OAuth2AccessToken) accessToken; + + //TODO(rhu) - create client for OAuth2 cases tokenClient.setAccessToken(accessToken); editor.putString(OAuthConstants.TOKEN, oAuth2AccessToken.getAccessToken()); editor.putString(OAuthConstants.SCOPE, oAuth2AccessToken.getScope()); @@ -107,11 +111,22 @@ public void onFailure(Exception e) { this.prefs = this.context.getSharedPreferences("OAuth_" + apiInstance.getClass().getSimpleName() + "_" + consumerKey, 0); this.editor = this.prefs.edit(); // Set access token in the tokenClient if already stored in preferences - if (this.checkAccessToken() != null) { - tokenClient.setAccessToken(this.checkAccessToken()); + Token accessToken = this.checkAccessToken(); + if (accessToken != null) { + tokenClient.setAccessToken(accessToken); + instantiateClient(consumerKey, consumerSecret, accessToken); } } + public void instantiateClient(String consumerKey, String consumerSecret, Token token) { + + if (token instanceof OAuth1AccessToken) { + client = OAuthAsyncHttpClient.create(consumerKey, consumerSecret, (OAuth1AccessToken)(token)); + } else { + + } + + } // Fetches a request token and retrieve and authorization url // Should open a browser in onReceivedRequestToken once the url has been received public void connect() { diff --git a/app/src/main/java/com/codepath/oauth/OAuthLoginActionBarActivity.java b/app/src/main/java/com/codepath/oauth/OAuthLoginActionBarActivity.java index 6ced975..def658f 100755 --- a/app/src/main/java/com/codepath/oauth/OAuthLoginActionBarActivity.java +++ b/app/src/main/java/com/codepath/oauth/OAuthLoginActionBarActivity.java @@ -1,12 +1,12 @@ package com.codepath.oauth; -import com.codepath.utils.GenericsUtil; - import android.content.Intent; import android.net.Uri; import androidx.appcompat.app.AppCompatActivity; +import com.codepath.utils.GenericsUtil; + // This is the ActionBarActivity supportv7 version of LoginActivity public abstract class OAuthLoginActionBarActivity extends diff --git a/app/src/main/java/com/codepath/oauth/OAuthTokenClient.java b/app/src/main/java/com/codepath/oauth/OAuthTokenClient.java index 6b4f2e3..b92c578 100755 --- a/app/src/main/java/com/codepath/oauth/OAuthTokenClient.java +++ b/app/src/main/java/com/codepath/oauth/OAuthTokenClient.java @@ -14,6 +14,7 @@ import com.github.scribejava.core.oauth.OAuth10aService; import com.github.scribejava.core.oauth.OAuth20Service; import com.github.scribejava.core.oauth.OAuthService; +import com.github.scribejava.httpclient.okhttp.OkHttpHttpClientConfig; /* * OAuthTokenClient is responsible for managing the request and access token exchanges and then @@ -34,9 +35,10 @@ public OAuthTokenClient(BaseApi apiInstance, String consumerKey, String consumer this.handler = handler; if (callbackUrl == null) { callbackUrl = OAuthConstants.OUT_OF_BAND; }; this.service = new ServiceBuilder() - .apiKey(consumerKey) - .apiSecret(consumerSecret).callback(callbackUrl) - .build(apiInstance); + .apiKey(consumerKey) + .apiSecret(consumerSecret).callback(callbackUrl) + .httpClientConfig(OkHttpHttpClientConfig.defaultConfig()) + .build(apiInstance); } // Get a request token and the authorization url @@ -85,6 +87,7 @@ public void fetchAccessToken(final Token requestToken, final Uri uri) { @Override public void onCompleted(OAuth1AccessToken oAuth1AccessToken) { + setAccessToken(oAuth1AccessToken); handler.onReceivedAccessToken(oAuth1AccessToken, service.getVersion()); } From 57865a037ba75bc3dee16d55232be5532f9a08f9 Mon Sep 17 00:00:00 2001 From: Roger Hu Date: Sun, 11 Aug 2019 23:24:04 -0700 Subject: [PATCH 12/29] rename directory add this file in --- {app => library}/build.gradle | 0 {app => library}/libs/codepath-utils.jar | Bin {app => library}/src/main/AndroidManifest.xml | 0 .../com/codepath/oauth/OAuthAsyncHttpClient.java | 0 .../java/com/codepath/oauth/OAuthBaseClient.java | 0 .../codepath/oauth/OAuthLoginActionBarActivity.java | 0 .../java/com/codepath/oauth/OAuthLoginActivity.java | 0 .../java/com/codepath/oauth/OAuthLoginFragment.java | 0 .../java/com/codepath/oauth/OAuthTokenClient.java | 0 {app => library}/src/main/res/.gitkeep | 0 {app => library}/src/main/res/layout/.gitkeep | 0 settings.gradle | 2 +- 12 files changed, 1 insertion(+), 1 deletion(-) rename {app => library}/build.gradle (100%) rename {app => library}/libs/codepath-utils.jar (100%) rename {app => library}/src/main/AndroidManifest.xml (100%) rename {app => library}/src/main/java/com/codepath/oauth/OAuthAsyncHttpClient.java (100%) rename {app => library}/src/main/java/com/codepath/oauth/OAuthBaseClient.java (100%) rename {app => library}/src/main/java/com/codepath/oauth/OAuthLoginActionBarActivity.java (100%) rename {app => library}/src/main/java/com/codepath/oauth/OAuthLoginActivity.java (100%) rename {app => library}/src/main/java/com/codepath/oauth/OAuthLoginFragment.java (100%) rename {app => library}/src/main/java/com/codepath/oauth/OAuthTokenClient.java (100%) rename {app => library}/src/main/res/.gitkeep (100%) rename {app => library}/src/main/res/layout/.gitkeep (100%) diff --git a/app/build.gradle b/library/build.gradle similarity index 100% rename from app/build.gradle rename to library/build.gradle diff --git a/app/libs/codepath-utils.jar b/library/libs/codepath-utils.jar similarity index 100% rename from app/libs/codepath-utils.jar rename to library/libs/codepath-utils.jar diff --git a/app/src/main/AndroidManifest.xml b/library/src/main/AndroidManifest.xml similarity index 100% rename from app/src/main/AndroidManifest.xml rename to library/src/main/AndroidManifest.xml diff --git a/app/src/main/java/com/codepath/oauth/OAuthAsyncHttpClient.java b/library/src/main/java/com/codepath/oauth/OAuthAsyncHttpClient.java similarity index 100% rename from app/src/main/java/com/codepath/oauth/OAuthAsyncHttpClient.java rename to library/src/main/java/com/codepath/oauth/OAuthAsyncHttpClient.java diff --git a/app/src/main/java/com/codepath/oauth/OAuthBaseClient.java b/library/src/main/java/com/codepath/oauth/OAuthBaseClient.java similarity index 100% rename from app/src/main/java/com/codepath/oauth/OAuthBaseClient.java rename to library/src/main/java/com/codepath/oauth/OAuthBaseClient.java diff --git a/app/src/main/java/com/codepath/oauth/OAuthLoginActionBarActivity.java b/library/src/main/java/com/codepath/oauth/OAuthLoginActionBarActivity.java similarity index 100% rename from app/src/main/java/com/codepath/oauth/OAuthLoginActionBarActivity.java rename to library/src/main/java/com/codepath/oauth/OAuthLoginActionBarActivity.java diff --git a/app/src/main/java/com/codepath/oauth/OAuthLoginActivity.java b/library/src/main/java/com/codepath/oauth/OAuthLoginActivity.java similarity index 100% rename from app/src/main/java/com/codepath/oauth/OAuthLoginActivity.java rename to library/src/main/java/com/codepath/oauth/OAuthLoginActivity.java diff --git a/app/src/main/java/com/codepath/oauth/OAuthLoginFragment.java b/library/src/main/java/com/codepath/oauth/OAuthLoginFragment.java similarity index 100% rename from app/src/main/java/com/codepath/oauth/OAuthLoginFragment.java rename to library/src/main/java/com/codepath/oauth/OAuthLoginFragment.java diff --git a/app/src/main/java/com/codepath/oauth/OAuthTokenClient.java b/library/src/main/java/com/codepath/oauth/OAuthTokenClient.java similarity index 100% rename from app/src/main/java/com/codepath/oauth/OAuthTokenClient.java rename to library/src/main/java/com/codepath/oauth/OAuthTokenClient.java diff --git a/app/src/main/res/.gitkeep b/library/src/main/res/.gitkeep similarity index 100% rename from app/src/main/res/.gitkeep rename to library/src/main/res/.gitkeep diff --git a/app/src/main/res/layout/.gitkeep b/library/src/main/res/layout/.gitkeep similarity index 100% rename from app/src/main/res/layout/.gitkeep rename to library/src/main/res/layout/.gitkeep diff --git a/settings.gradle b/settings.gradle index e7b4def..d8f14a1 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1 +1 @@ -include ':app' +include ':library' From ffd949d52727eb59a3a65e94394c4ec9b6979dca Mon Sep 17 00:00:00 2001 From: Roger Hu Date: Sun, 11 Aug 2019 23:24:29 -0700 Subject: [PATCH 13/29] bump to Gradle5 --- gradle/wrapper/gradle-wrapper.properties | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index dc63add..f4ac9b0 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Mon Jan 28 10:39:02 PST 2019 +#Sun Aug 11 22:16:42 PDT 2019 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip From d70af0e37ee5a53f6934ffc506758efaac985cc7 Mon Sep 17 00:00:00 2001 From: Roger Hu Date: Tue, 13 Aug 2019 22:28:56 -0700 Subject: [PATCH 14/29] fix Gradle --- build.gradle | 4 ++-- library/build.gradle | 50 ++++++++++++-------------------------------- 2 files changed, 15 insertions(+), 39 deletions(-) diff --git a/build.gradle b/build.gradle index edb3243..8e6261d 100644 --- a/build.gradle +++ b/build.gradle @@ -10,11 +10,11 @@ buildscript { } plugins { - id "com.jfrog.bintray" version "1.7.3" + id "com.jfrog.bintray" version "1.8.4" } plugins { - id "com.github.dcendents.android-maven" version "2.0" + id "com.github.dcendents.android-maven" version "2.1" } bintray { diff --git a/library/build.gradle b/library/build.gradle index 471e149..0b64ac1 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -54,49 +54,16 @@ android { } } -install { - repositories.mavenInstaller { - pom.project { - name POM_NAME - description POM_DESCRIPTION - url POM_URL - inceptionYear '2016' - - packaging 'aar' - group GROUP - artifactId POM_ARTIFACT_ID - version VERSION_NAME - - licenses { - license { - name 'The Apache Software License, Version 2.0' - url 'http://www.apache.org/licenses/LICENSE-2.0.txt' - distribution 'repo' - } - } - scm { - connection POM_SCM_URL - url POM_SCM_CONNECTION - - } - developers { - developer { - name 'CodePath, Inc.' - } - } - } - } -} - bintray { - user = System.getenv('BINTRAY_USER') - key = System.getenv('BINTRAY_API_KEY') + user = project.hasProperty('bintrayUser') ? project.property('bintrayUser') : System.getenv('BINTRAY_USER') + key = project.hasProperty('bintrayApiKey') ? project.property('bintrayApiKey') : System.getenv('BINTRAY_API_KEY') + configurations = ['archives'] // needs apply plugin 'com.jfrog.bintray' to work pkg { repo = 'maven' name = 'android-oauth-handler' -// userOrg = 'codepath' + userOrg = 'codepath' licenses = ['Apache-2.0'] vcsUrl = 'https://github.com/codepath/android-oauth-handler.git' version { @@ -109,6 +76,15 @@ bintray { } +task sourcesJar(type: Jar) { + from android.sourceSets.main.java.srcDirs + archiveClassifier.set("sources") +} + +artifacts { + archives sourcesJar +} + ext { supportVersion = '28.0.0' } From 1167c2b2d0bc21cfeba4a2f97705c7358cd6bdf0 Mon Sep 17 00:00:00 2001 From: Roger Hu Date: Sun, 18 Aug 2019 21:13:43 -0700 Subject: [PATCH 15/29] delete CodePath utils library, move GenericsUtil into this dir --- library/libs/codepath-utils.jar | Bin 4793 -> 0 bytes .../java/com/codepath/utils/GenericsUtil.java | 80 ++++++++++++++++++ 2 files changed, 80 insertions(+) delete mode 100755 library/libs/codepath-utils.jar create mode 100644 library/src/main/java/com/codepath/utils/GenericsUtil.java diff --git a/library/libs/codepath-utils.jar b/library/libs/codepath-utils.jar deleted file mode 100755 index 7294db1dfb79f406c8ccc7c240317ffba0bcc13b..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 4793 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 diff --git a/library/src/main/java/com/codepath/utils/GenericsUtil.java b/library/src/main/java/com/codepath/utils/GenericsUtil.java new file mode 100644 index 0000000..66298f9 --- /dev/null +++ b/library/src/main/java/com/codepath/utils/GenericsUtil.java @@ -0,0 +1,80 @@ +package com.codepath.utils; + +import java.lang.reflect.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + + +@SuppressWarnings("rawtypes") +public class GenericsUtil { + public static List> getTypeArguments(Class baseClass, + Class childClass) { + Map resolvedTypes = new HashMap(); + Type type = childClass; + // start walking up the inheritance hierarchy until we hit baseClass + while (!getClass(type).equals(baseClass)) { + if (type instanceof Class) { + type = ((Class) type).getGenericSuperclass(); + } else { + ParameterizedType parameterizedType = (ParameterizedType) type; + assert parameterizedType != null; + Class rawType = (Class) parameterizedType.getRawType(); + + Type[] actualTypeArguments = parameterizedType + .getActualTypeArguments(); + TypeVariable[] typeParameters = rawType.getTypeParameters(); + for (int i = 0; i < actualTypeArguments.length; i++) { + resolvedTypes + .put(typeParameters[i], actualTypeArguments[i]); + } + + if (!rawType.equals(baseClass)) { + type = rawType.getGenericSuperclass(); + } + } + } + + // finally, for each actual type argument provided to baseClass, + // determine (if possible) + // the raw class for that type argument. + Type[] actualTypeArguments; + if (type instanceof Class) { + actualTypeArguments = ((Class) type).getTypeParameters(); + } else { + assert !(type == null); + actualTypeArguments = ((ParameterizedType) type) + .getActualTypeArguments(); + } + List> typeArgumentsAsClasses = new ArrayList>(); + // resolve types by chasing down type variables. + for (Type baseType : actualTypeArguments) { + while (resolvedTypes.containsKey(baseType)) { + baseType = resolvedTypes.get(baseType); + } + typeArgumentsAsClasses.add(getClass(baseType)); + } + return typeArgumentsAsClasses; + } + + private static Class getClass(Type type) { + if (type instanceof Class) { + return (Class) type; + } else if (type instanceof ParameterizedType) { + return getClass(((ParameterizedType) type).getRawType()); + } else if (type instanceof GenericArrayType) { + Type componentType = ((GenericArrayType) type) + .getGenericComponentType(); + Class componentClass = getClass(componentType); + if (componentClass != null) { + return Array.newInstance(componentClass, 0).getClass(); + } else { + return null; + } + } else { + return null; + } + } + +} From b1c49fc7408559c0811c3a3640ec3d1297906afc Mon Sep 17 00:00:00 2001 From: Roger Hu Date: Sun, 18 Aug 2019 21:14:18 -0700 Subject: [PATCH 16/29] Bump Async Http Client version --- library/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/build.gradle b/library/build.gradle index 0b64ac1..51953bc 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -91,7 +91,7 @@ ext { dependencies { api "androidx.appcompat:appcompat:1.0.2" - api 'com.codepath.libraries:asynchttpclient:0.0.5' + api 'com.codepath.libraries:asynchttpclient:0.0.8' implementation files('libs/codepath-utils.jar') api 'com.github.scribejava:scribejava-apis:4.1.1' api 'com.github.scribejava:scribejava-httpclient-okhttp:4.1.1' From c86a20bfedd38329517af349f2068c0541f7eb95 Mon Sep 17 00:00:00 2001 From: Roger Hu Date: Sun, 18 Aug 2019 21:14:58 -0700 Subject: [PATCH 17/29] kill this line --- library/build.gradle | 1 - 1 file changed, 1 deletion(-) diff --git a/library/build.gradle b/library/build.gradle index 51953bc..c19833d 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -92,7 +92,6 @@ ext { dependencies { api "androidx.appcompat:appcompat:1.0.2" api 'com.codepath.libraries:asynchttpclient:0.0.8' - implementation files('libs/codepath-utils.jar') api 'com.github.scribejava:scribejava-apis:4.1.1' api 'com.github.scribejava:scribejava-httpclient-okhttp:4.1.1' implementation 'se.akerfeldt:okhttp-signpost:1.1.0' From d916ca2fd1bcc87c9967f79ab8158dcf8a2fc501 Mon Sep 17 00:00:00 2001 From: Roger Hu Date: Sun, 18 Aug 2019 21:15:36 -0700 Subject: [PATCH 18/29] bump version --- library/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/build.gradle b/library/build.gradle index c19833d..4be67ea 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -8,7 +8,7 @@ ext { GROUP = 'com.codepath.libraries' BASE_VERSION = "2.0" - VERSION_NAME = "2.0.0" + VERSION_NAME = "2.0.1" POM_PACKAGING = "aar" POM_DESCRIPTION = "CodePath OAuth Handler" From f531e52fc28fd99c7f7ef00a71f24d5a1e22c832 Mon Sep 17 00:00:00 2001 From: Roger Hu Date: Sun, 18 Aug 2019 22:53:26 -0700 Subject: [PATCH 19/29] Support OAuth2 tokens too --- library/build.gradle | 2 +- .../codepath/oauth/OAuthAsyncHttpClient.java | 30 ++++++++++++++++++- .../com/codepath/oauth/OAuthBaseClient.java | 15 ++++++---- .../com/codepath/oauth/OAuthTokenClient.java | 3 +- 4 files changed, 41 insertions(+), 9 deletions(-) diff --git a/library/build.gradle b/library/build.gradle index 4be67ea..d44f271 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -8,7 +8,7 @@ ext { GROUP = 'com.codepath.libraries' BASE_VERSION = "2.0" - VERSION_NAME = "2.0.1" + VERSION_NAME = "2.1.0" POM_PACKAGING = "aar" POM_DESCRIPTION = "CodePath OAuth Handler" diff --git a/library/src/main/java/com/codepath/oauth/OAuthAsyncHttpClient.java b/library/src/main/java/com/codepath/oauth/OAuthAsyncHttpClient.java index 8b345e7..2ddfc23 100644 --- a/library/src/main/java/com/codepath/oauth/OAuthAsyncHttpClient.java +++ b/library/src/main/java/com/codepath/oauth/OAuthAsyncHttpClient.java @@ -3,8 +3,16 @@ import com.codepath.asynchttpclient.AsyncHttpClient; import com.facebook.stetho.okhttp3.StethoInterceptor; import com.github.scribejava.core.model.OAuth1AccessToken; +import com.github.scribejava.core.model.OAuth2AccessToken; +import org.jetbrains.annotations.NotNull; + +import java.io.IOException; + +import okhttp3.Interceptor; import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.Response; import se.akerfeldt.okhttp.signpost.OkHttpOAuthConsumer; import se.akerfeldt.okhttp.signpost.SigningInterceptor; @@ -17,10 +25,30 @@ protected OAuthAsyncHttpClient(OkHttpClient httpClient) { public static OAuthAsyncHttpClient create(String consumerKey, String consumerSecret, OAuth1AccessToken token) { OkHttpOAuthConsumer consumer = new OkHttpOAuthConsumer(consumerKey, consumerSecret); consumer.setTokenWithSecret(token.getToken(), token.getTokenSecret()); - OkHttpClient httpClient = new OkHttpClient.Builder().addNetworkInterceptor(new StethoInterceptor()).addInterceptor(new SigningInterceptor(consumer)).build(); + OkHttpClient httpClient = new OkHttpClient.Builder() + .addNetworkInterceptor(new StethoInterceptor()) + .addInterceptor(new SigningInterceptor(consumer)).build(); OAuthAsyncHttpClient asyncHttpClient = new OAuthAsyncHttpClient(httpClient); return asyncHttpClient; } + public static OAuthAsyncHttpClient create(final OAuth2AccessToken token) { + final String bearer = String.format("Bearer %s", token.getAccessToken()); + + OkHttpClient httpClient = new OkHttpClient.Builder() + .addNetworkInterceptor(new StethoInterceptor()) + .addInterceptor(new Interceptor() { + @NotNull + @Override + public Response intercept(@NotNull Chain chain) throws IOException { + Request originalRequest = chain.request(); + Request authedRequest = originalRequest.newBuilder().header("Authorization", bearer).build(); + return chain.proceed(authedRequest); + } + }).build(); + + OAuthAsyncHttpClient asyncHttpClient = new OAuthAsyncHttpClient(httpClient); + return asyncHttpClient; + } } \ No newline at end of file diff --git a/library/src/main/java/com/codepath/oauth/OAuthBaseClient.java b/library/src/main/java/com/codepath/oauth/OAuthBaseClient.java index 04ef5fc..1b0dcff 100755 --- a/library/src/main/java/com/codepath/oauth/OAuthBaseClient.java +++ b/library/src/main/java/com/codepath/oauth/OAuthBaseClient.java @@ -5,6 +5,8 @@ import android.content.SharedPreferences; import android.net.Uri; +import androidx.annotation.Nullable; + import com.github.scribejava.core.builder.api.BaseApi; import com.github.scribejava.core.model.OAuth1AccessToken; import com.github.scribejava.core.model.OAuth1RequestToken; @@ -46,11 +48,11 @@ public static OAuthBaseClient getInstance(Class klass return instance; } - public OAuthBaseClient(Context c, final BaseApi apiInstance, String consumerUrl, final String consumerKey, final String consumerSecret, String callbackUrl) { + public OAuthBaseClient(Context c, final BaseApi apiInstance, String consumerUrl, final String consumerKey, final String consumerSecret, @Nullable String scope, String callbackUrl) { this.baseUrl = consumerUrl; this.callbackUrl = callbackUrl; tokenClient = new OAuthTokenClient(apiInstance, consumerKey, - consumerSecret, callbackUrl, new OAuthTokenClient.OAuthTokenHandler() { + consumerSecret, callbackUrl, scope, new OAuthTokenClient.OAuthTokenHandler() { // Store request token and launch the authorization URL in the browser @Override @@ -86,8 +88,7 @@ public void onReceivedAccessToken(Token accessToken, String oAuthVersion) { editor.commit(); } else if (oAuthVersion == OAUTH2_VERSION) { OAuth2AccessToken oAuth2AccessToken = (OAuth2AccessToken) accessToken; - - //TODO(rhu) - create client for OAuth2 cases + instantiateClient(consumerKey, consumerSecret, oAuth2AccessToken); tokenClient.setAccessToken(accessToken); editor.putString(OAuthConstants.TOKEN, oAuth2AccessToken.getAccessToken()); editor.putString(OAuthConstants.SCOPE, oAuth2AccessToken.getScope()); @@ -122,8 +123,10 @@ public void instantiateClient(String consumerKey, String consumerSecret, Token t if (token instanceof OAuth1AccessToken) { client = OAuthAsyncHttpClient.create(consumerKey, consumerSecret, (OAuth1AccessToken)(token)); + } else if (token instanceof OAuth2AccessToken){ + client = OAuthAsyncHttpClient.create((OAuth2AccessToken) token); } else { - + throw new IllegalStateException("unrecognized token type" + token); } } @@ -138,7 +141,7 @@ public void authorize(Uri uri, OAuthAccessHandler handler) { this.accessHandler = handler; if (checkAccessToken() == null && uri != null) { // TODO: check UriServiceCallback with intent:// scheme - tokenClient.fetchAccessToken(getOAuth1RequestToken(), uri); + tokenClient.fetchAccessToken(checkAccessToken(), uri); } else if (checkAccessToken() != null) { // already have access token this.accessHandler.onLoginSuccess(); diff --git a/library/src/main/java/com/codepath/oauth/OAuthTokenClient.java b/library/src/main/java/com/codepath/oauth/OAuthTokenClient.java index b92c578..03629b4 100755 --- a/library/src/main/java/com/codepath/oauth/OAuthTokenClient.java +++ b/library/src/main/java/com/codepath/oauth/OAuthTokenClient.java @@ -30,7 +30,7 @@ public class OAuthTokenClient { // Requires the apiClass, consumerKey, consumerSecret and callbackUrl along with the TokenHandler public OAuthTokenClient(BaseApi apiInstance, String consumerKey, String consumerSecret, String callbackUrl, - OAuthTokenHandler handler) { + String scope, OAuthTokenHandler handler) { this.apiInstance = apiInstance; this.handler = handler; if (callbackUrl == null) { callbackUrl = OAuthConstants.OUT_OF_BAND; }; @@ -38,6 +38,7 @@ public OAuthTokenClient(BaseApi apiInstance, String consumerKey, String consumer .apiKey(consumerKey) .apiSecret(consumerSecret).callback(callbackUrl) .httpClientConfig(OkHttpHttpClientConfig.defaultConfig()) + .scope(scope) // OAuth2 requires scope .build(apiInstance); } From 6aab24642036c5dc0ad0a41b03ef9a602c6ea37d Mon Sep 17 00:00:00 2001 From: Roger Hu Date: Mon, 19 Aug 2019 22:18:33 -0700 Subject: [PATCH 20/29] Update README docs --- README.md | 67 +++++++++++++++++++++---------------------------------- 1 file changed, 25 insertions(+), 42 deletions(-) diff --git a/README.md b/README.md index f96b443..4e816c6 100755 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ approach that keeps the details of the OAuth process abstracted from the end-use This library leverages a few key libraries underneath to power the functionality: * [scribe-java](https://github.com/scribejava/scribejava) - Simple OAuth library for handling the authentication flow. - * [Android Async HTTP](https://github.com/loopj/android-async-http) - Simple asynchronous HTTP requests with JSON parsing. + * [Android Async HTTP](https://github.com/codepath/asynchttpclient) - Simple asynchronous HTTP requests with JSON parsing. ## Installation @@ -24,7 +24,7 @@ Next, add this line to your `app/build.gradle` file: ```gradle dependencies { - compile 'com.codepath.libraries:android-oauth-handler:1.3.1' + compile 'com.codepath.libraries:android-oauth-handler:2.1.1' } ``` @@ -51,12 +51,12 @@ public class TwitterClient extends OAuthBaseClient { public TwitterClient(Context context) { super(context, REST_API_INSTANCE, REST_URL, - REST_CONSUMER_KEY, REST_CONSUMER_SECRET, REST_CALLBACK_URL); + REST_CONSUMER_KEY, REST_CONSUMER_SECRET, null, REST_CALLBACK_URL); } // ENDPOINTS BELOW - public void getHomeTimeline(int page, AsyncHttpResponseHandler handler) { + public void getHomeTimeline(int page, JsonHttpResponseHandler handler) { String apiUrl = getApiUrl("statuses/home_timeline.json"); RequestParams params = new RequestParams(); params.put("page", String.valueOf(page)); @@ -169,9 +169,9 @@ with a `JsonHttpResponseHandler` handler: // SomeActivity.java RestClient client = RestClientApp.getRestClient(); client.getHomeTimeline(1, new JsonHttpResponseHandler() { - public void onSuccess(int statusCode, Header[] headers, JSONArray json) { + public void onSuccess(int statusCode, Headers headers, JSON json) { // Response is automatically parsed into a JSONArray - // json.getJSONObject(0).getLong("id"); + // json.jsonArray.getJSONObject(0).getLong("id"); } }); ``` @@ -180,27 +180,18 @@ Based on the JSON response (array or object), you need to declare the expected t ```java RestClient client = RestClientApp.getRestClient(); -client.get("http://www.google.com", new AsyncHttpResponseHandler() { +client.get("http://www.google.com", new JsonHttpResponseHandler() { @Override - public void onSuccess(int statusCode, Header[] headers, String response) { + public void onSuccess(int statusCode, Headers headers, String response) { System.out.println(response); } }); ``` -Check out [Android Async HTTP Docs](http://loopj.com/android-async-http/) for more request creation details. +Check out [Android Async HTTP Docs](https://github.com/codepath/asynchttpclient) for more request creation details. ## Extra Functionality -### Adding Request Headers - -In certain cases, requests will require a particular custom header to be passed through the client. In this case, you can add custom headers to the client that will be added to all requests with: - -```java -RestClient client = RestApplication.getRestClient(); -// Specify the header to append to the request -client.addHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1)"); -``` ### Access Authorization @@ -226,40 +217,32 @@ This can be helpful in cases where you must add a flag such as when encountering You can log out by clearing the access token at any time through the client object: -You can log out by clearing the access token at any time through the client object: - ```java RestClient client = RestApplication.getRestClient(); client.clearAccessToken(); ``` -### Enabling a Proxy +### Debugging -In order to [troubleshoot API calls](http://guides.codepath.com/android/Troubleshooting-API-calls) using a method such as Charles Proxy, you'll want to enable proxy support with: +In order to [troubleshoot API calls](http://guides.codepath.com/android/Troubleshooting-API-calls), you can take advantage of the Stetho library: +Next, initialize Stetho inside your Application object: ```java -RestClient client = RestApplication.getRestClient(); -client.enableProxy(); +public class MyApplication extends Application { + public void onCreate() { + super.onCreate(); + Stetho.initializeWithDefaults(this); + } +} ``` -Proxies are useful for monitoring the network traffic but require a custom SSL certificate to be added to your emulator or device. Because Android API 24 and above now require [explicit control](https://developer.android.com/training/articles/security-config.html) on custom SSL certificates that are used in apps, you will need to allow for added certs to be added by specifying `res/xml/network_security_config.xml` in your app: - +Edit the manifest.xml file in your project. To let the Android operating system know that you have a custom Application class, add an attribute called `android:name` to the manifest’s application tag and set the value to the name of your custom Application class. ```xml - - - - - - - - - + ``` -Inside your AndroidManifest.xml file, make sure to include this `networkSecurityConfig` parameter: - -```xml - Date: Mon, 19 Aug 2019 22:51:59 -0700 Subject: [PATCH 21/29] fix OAuthBaseClient --- .../java/com/codepath/oauth/OAuthBaseClient.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/library/src/main/java/com/codepath/oauth/OAuthBaseClient.java b/library/src/main/java/com/codepath/oauth/OAuthBaseClient.java index 1b0dcff..038a76e 100755 --- a/library/src/main/java/com/codepath/oauth/OAuthBaseClient.java +++ b/library/src/main/java/com/codepath/oauth/OAuthBaseClient.java @@ -62,6 +62,7 @@ public void onReceivedRequestToken(Token requestToken, String authorizeUrl, Stri OAuth1RequestToken oAuth1RequestToken = (OAuth1RequestToken) requestToken; editor.putString(OAUTH1_REQUEST_TOKEN, oAuth1RequestToken.getToken()); editor.putString(OAUTH1_REQUEST_TOKEN_SECRET, oAuth1RequestToken.getTokenSecret()); + editor.putInt(OAuthConstants.VERSION, 1); editor.commit(); } } @@ -141,7 +142,7 @@ public void authorize(Uri uri, OAuthAccessHandler handler) { this.accessHandler = handler; if (checkAccessToken() == null && uri != null) { // TODO: check UriServiceCallback with intent:// scheme - tokenClient.fetchAccessToken(checkAccessToken(), uri); + tokenClient.fetchAccessToken(getOAuth1RequestToken(), uri); } else if (checkAccessToken() != null) { // already have access token this.accessHandler.onLoginSuccess(); @@ -165,10 +166,15 @@ protected OAuthTokenClient getTokenClient() { return tokenClient; } - // Returns the request token stored during the request token phase - protected OAuth1RequestToken getOAuth1RequestToken() { - return new OAuth1RequestToken(prefs.getString(OAUTH1_REQUEST_TOKEN, ""), - prefs.getString(OAUTH1_REQUEST_TOKEN_SECRET, "")); + // Returns the request token stored during the request token phase (OAuth1 only) + protected @Nullable Token getOAuth1RequestToken() { + int oAuthVersion = prefs.getInt(OAuthConstants.VERSION, 0); + + if (oAuthVersion == 1) { + return new OAuth1RequestToken(prefs.getString(OAUTH1_REQUEST_TOKEN, ""), + prefs.getString(OAUTH1_REQUEST_TOKEN_SECRET, "")); + } + return null; } // Assigns the base url for the API From daa736f516edcdb77c27ed3b806df67907235a34 Mon Sep 17 00:00:00 2001 From: Roger Hu Date: Mon, 19 Aug 2019 23:00:55 -0700 Subject: [PATCH 22/29] bump version --- library/build.gradle | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/library/build.gradle b/library/build.gradle index d44f271..71f9e94 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -8,7 +8,7 @@ ext { GROUP = 'com.codepath.libraries' BASE_VERSION = "2.0" - VERSION_NAME = "2.1.0" + VERSION_NAME = "2.1.2" POM_PACKAGING = "aar" POM_DESCRIPTION = "CodePath OAuth Handler" @@ -98,7 +98,6 @@ dependencies { implementation 'oauth.signpost:signpost-core:1.2.1.2' implementation 'com.facebook.stetho:stetho:1.5.1' implementation 'com.facebook.stetho:stetho-okhttp3:1.5.1' - } /*task jar(type: Jar) { From aeaf9bfffb8163c69ec46a2fa0742e293460a690 Mon Sep 17 00:00:00 2001 From: Roger Hu Date: Mon, 19 Aug 2019 23:03:30 -0700 Subject: [PATCH 23/29] add logging lines --- README.md | 2 +- library/build.gradle | 4 +++- .../codepath/oauth/OAuthAsyncHttpClient.java | 17 ++++++++++++++++- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 4e816c6..9a5b758 100755 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ Next, add this line to your `app/build.gradle` file: ```gradle dependencies { - compile 'com.codepath.libraries:android-oauth-handler:2.1.1' + compile 'com.codepath.libraries:android-oauth-handler:2.1.3' } ``` diff --git a/library/build.gradle b/library/build.gradle index 71f9e94..8b52bc3 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -8,7 +8,7 @@ ext { GROUP = 'com.codepath.libraries' BASE_VERSION = "2.0" - VERSION_NAME = "2.1.2" + VERSION_NAME = "2.1.3" POM_PACKAGING = "aar" POM_DESCRIPTION = "CodePath OAuth Handler" @@ -98,6 +98,8 @@ dependencies { implementation 'oauth.signpost:signpost-core:1.2.1.2' implementation 'com.facebook.stetho:stetho:1.5.1' implementation 'com.facebook.stetho:stetho-okhttp3:1.5.1' + implementation "com.squareup.okhttp3:logging-interceptor:4.1.0" + } /*task jar(type: Jar) { diff --git a/library/src/main/java/com/codepath/oauth/OAuthAsyncHttpClient.java b/library/src/main/java/com/codepath/oauth/OAuthAsyncHttpClient.java index 2ddfc23..b9dd7a4 100644 --- a/library/src/main/java/com/codepath/oauth/OAuthAsyncHttpClient.java +++ b/library/src/main/java/com/codepath/oauth/OAuthAsyncHttpClient.java @@ -13,6 +13,7 @@ import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.Response; +import okhttp3.logging.HttpLoggingInterceptor; import se.akerfeldt.okhttp.signpost.OkHttpOAuthConsumer; import se.akerfeldt.okhttp.signpost.SigningInterceptor; @@ -22,10 +23,21 @@ protected OAuthAsyncHttpClient(OkHttpClient httpClient) { super(httpClient); } + private static String BEARER = "Bearer"; + + public static HttpLoggingInterceptor createLogger() { + HttpLoggingInterceptor logger = new HttpLoggingInterceptor(); + logger.level(HttpLoggingInterceptor.Level.HEADERS); + return logger; + } + public static OAuthAsyncHttpClient create(String consumerKey, String consumerSecret, OAuth1AccessToken token) { OkHttpOAuthConsumer consumer = new OkHttpOAuthConsumer(consumerKey, consumerSecret); + HttpLoggingInterceptor logging = createLogger(); + consumer.setTokenWithSecret(token.getToken(), token.getTokenSecret()); OkHttpClient httpClient = new OkHttpClient.Builder() + .addInterceptor(logging) .addNetworkInterceptor(new StethoInterceptor()) .addInterceptor(new SigningInterceptor(consumer)).build(); @@ -34,9 +46,12 @@ public static OAuthAsyncHttpClient create(String consumerKey, String consumerSec } public static OAuthAsyncHttpClient create(final OAuth2AccessToken token) { - final String bearer = String.format("Bearer %s", token.getAccessToken()); + final String bearer = String.format("%s %s", BEARER, token.getAccessToken()); + + HttpLoggingInterceptor logging = createLogger(); OkHttpClient httpClient = new OkHttpClient.Builder() + .addInterceptor(logging) .addNetworkInterceptor(new StethoInterceptor()) .addInterceptor(new Interceptor() { @NotNull From 0efc925d59fa32a7779456d1fc2634a7d0281f4c Mon Sep 17 00:00:00 2001 From: Roger Hu Date: Mon, 19 Aug 2019 23:14:06 -0700 Subject: [PATCH 24/29] fix regression again --- library/build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/build.gradle b/library/build.gradle index 8b52bc3..d0c6189 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -7,8 +7,8 @@ apply plugin: 'com.jfrog.bintray' ext { GROUP = 'com.codepath.libraries' - BASE_VERSION = "2.0" - VERSION_NAME = "2.1.3" + BASE_VERSION = "2.1" + VERSION_NAME = "2.1.4" POM_PACKAGING = "aar" POM_DESCRIPTION = "CodePath OAuth Handler" From e72ea942ea0feb1d985ca0716a9fc588c70fb138 Mon Sep 17 00:00:00 2001 From: lgleasain Date: Mon, 28 Jun 2021 20:52:53 -0400 Subject: [PATCH 25/29] adding in changes so that this will work with api 30 --- library/build.gradle | 14 +++++++------- .../java/com/codepath/oauth/OAuthTokenClient.java | 10 +++++++++- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/library/build.gradle b/library/build.gradle index d0c6189..842e033 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -32,13 +32,13 @@ group = GROUP archivesBaseName = POM_ARTIFACT_ID android { - compileSdkVersion 28 + compileSdkVersion 30 defaultConfig { versionCode 1 versionName VERSION_NAME minSdkVersion 21 - targetSdkVersion 28 + targetSdkVersion 30 } // Related to https://github.com/scribejava/scribejava/issues/480 @@ -90,18 +90,18 @@ ext { } dependencies { - api "androidx.appcompat:appcompat:1.0.2" - api 'com.codepath.libraries:asynchttpclient:0.0.8' + api "androidx.appcompat:appcompat:1.3.0" + api 'com.codepath.libraries:asynchttpclient:2.1.1' api 'com.github.scribejava:scribejava-apis:4.1.1' api 'com.github.scribejava:scribejava-httpclient-okhttp:4.1.1' implementation 'se.akerfeldt:okhttp-signpost:1.1.0' implementation 'oauth.signpost:signpost-core:1.2.1.2' implementation 'com.facebook.stetho:stetho:1.5.1' implementation 'com.facebook.stetho:stetho-okhttp3:1.5.1' - implementation "com.squareup.okhttp3:logging-interceptor:4.1.0" + implementation "com.squareup.okhttp3:logging-interceptor:4.7.2" } -/*task jar(type: Jar) { +task jar(type: Jar) { from android.sourceSets.main.java.srcDirs -}*/ +} diff --git a/library/src/main/java/com/codepath/oauth/OAuthTokenClient.java b/library/src/main/java/com/codepath/oauth/OAuthTokenClient.java index 03629b4..d76079d 100755 --- a/library/src/main/java/com/codepath/oauth/OAuthTokenClient.java +++ b/library/src/main/java/com/codepath/oauth/OAuthTokenClient.java @@ -34,12 +34,20 @@ public OAuthTokenClient(BaseApi apiInstance, String consumerKey, String consumer this.apiInstance = apiInstance; this.handler = handler; if (callbackUrl == null) { callbackUrl = OAuthConstants.OUT_OF_BAND; }; - this.service = new ServiceBuilder() + if(scope == null) { + this.service = new ServiceBuilder() + .apiKey(consumerKey) + .apiSecret(consumerSecret).callback(callbackUrl) + .httpClientConfig(OkHttpHttpClientConfig.defaultConfig()) + .build(apiInstance); + } else { + this.service = new ServiceBuilder() .apiKey(consumerKey) .apiSecret(consumerSecret).callback(callbackUrl) .httpClientConfig(OkHttpHttpClientConfig.defaultConfig()) .scope(scope) // OAuth2 requires scope .build(apiInstance); + } } // Get a request token and the authorization url From fb129fe91e8291554df26c92d93d86b83b883410 Mon Sep 17 00:00:00 2001 From: Roger Hu Date: Mon, 28 Jun 2021 21:23:58 -0700 Subject: [PATCH 26/29] Bump library deps and get rid of Bintray, move to Sonatype make sure to check this file in --- build.gradle | 17 +------- gradle.properties | 20 +++++++++ gradle/wrapper/gradle-wrapper.properties | 2 +- library/build.gradle | 53 +++++++++++++----------- 4 files changed, 52 insertions(+), 40 deletions(-) create mode 100644 gradle.properties diff --git a/build.gradle b/build.gradle index 8e6261d..4055c94 100644 --- a/build.gradle +++ b/build.gradle @@ -2,26 +2,13 @@ buildscript { repositories { google() - jcenter() + mavenCentral() } dependencies { - classpath 'com.android.tools.build:gradle:3.4.2' + classpath 'com.android.tools.build:gradle:4.0.1' } } -plugins { - id "com.jfrog.bintray" version "1.8.4" -} - -plugins { - id "com.github.dcendents.android-maven" version "2.1" -} - -bintray { - publications = [] - configurations = [] -} - allprojects { repositories { google() diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..199d16e --- /dev/null +++ b/gradle.properties @@ -0,0 +1,20 @@ +# Project-wide Gradle settings. +# IDE (e.g. Android Studio) users: +# Gradle settings configured through the IDE *will override* +# any settings specified in this file. +# For more details on how to configure your build environment visit +# http://www.gradle.org/docs/current/userguide/build_environment.html +# Specifies the JVM arguments used for the daemon process. +# The setting is particularly useful for tweaking memory settings. +org.gradle.jvmargs=-Xmx1536m +# When configured, Gradle will run in incubating parallel mode. +# This option should only be used with decoupled projects. More details, visit +# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects +# org.gradle.parallel=true +# AndroidX package structure to make it clearer which packages are bundled with the +# Android operating system, and which are packaged with your app's APK +# https://developer.android.com/topic/libraries/support-library/androidx-rn +android.useAndroidX=true +# Automatically convert third-party libraries to use AndroidX +android.enableJetifier=true + diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index f4ac9b0..dfb6cb5 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip diff --git a/library/build.gradle b/library/build.gradle index 842e033..08ef71c 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -1,14 +1,11 @@ apply plugin: 'com.android.library' -apply plugin: 'com.github.dcendents.android-maven' -apply plugin: 'com.jfrog.bintray' +apply plugin: 'maven-publish' -// https://github.com/bintray/gradle-bintray-plugin/issues/74#issuecomment-168367341 -// https://github.com/dcendents/android-maven-gradle-plugin/issues/9 ext { GROUP = 'com.codepath.libraries' - BASE_VERSION = "2.1" - VERSION_NAME = "2.1.4" + BASE_VERSION = "2.2" + VERSION_NAME = "2.2.0" POM_PACKAGING = "aar" POM_DESCRIPTION = "CodePath OAuth Handler" @@ -54,26 +51,34 @@ android { } } -bintray { - user = project.hasProperty('bintrayUser') ? project.property('bintrayUser') : System.getenv('BINTRAY_USER') - key = project.hasProperty('bintrayApiKey') ? project.property('bintrayApiKey') : System.getenv('BINTRAY_API_KEY') - - configurations = ['archives'] // needs apply plugin 'com.jfrog.bintray' to work - - pkg { - repo = 'maven' - name = 'android-oauth-handler' - userOrg = 'codepath' - licenses = ['Apache-2.0'] - vcsUrl = 'https://github.com/codepath/android-oauth-handler.git' - version { - name = BASE_VERSION - desc = POM_NAME - released = new Date() - vcsTag = VERSION_NAME +afterEvaluate { + publishing { + publications { + // Creates a Maven publication called "release". + release(MavenPublication) { + // Applies the component for the release build variant. + from components.release + + // You can then customize attributes of the publication as shown below. + groupId = GROUP + artifactId = POM_ARTIFACT_ID + version = VERSION_NAME + } } + repositories { + maven { + name = "Sonatype" + credentials { + username = System.getenv('NEXUS_USERNAME') + password = System.getenv('NEXUS_PASSWORD') + } + def releasesRepoUrl = 'https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/' + def snapshotsRepoUrl = 'https://s01.oss.sonatype.org/content/repositories/snapshots/' + url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl + setUrl(url) + } } - + } } task sourcesJar(type: Jar) { From b0d0e140922cf7eed2e44e8f407e93b552be528c Mon Sep 17 00:00:00 2001 From: Roger Hu Date: Sat, 10 Jul 2021 14:29:03 -0700 Subject: [PATCH 27/29] Add GPG signing --- library/build.gradle | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/library/build.gradle b/library/build.gradle index 08ef71c..a5615d6 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -1,5 +1,6 @@ apply plugin: 'com.android.library' apply plugin: 'maven-publish' +apply plugin: 'signing' ext { @@ -81,6 +82,16 @@ afterEvaluate { } } +signing { + // gpg on MacOS is the same as gpg2 + // ln -s /usr/local/bin/gpg /usr/local/bin/gpg2 + // Make sure to populate the variables in gradle.properties + // signing.gnupg.keyName=XXX + // signing.gnupg.passpharse + useGpgCmd() + sign(publishing.publications) +} + task sourcesJar(type: Jar) { from android.sourceSets.main.java.srcDirs archiveClassifier.set("sources") From bb10d670dad9a4c95c8c49e8ebbf2ded2ccd6d4c Mon Sep 17 00:00:00 2001 From: Roger Hu Date: Sat, 10 Jul 2021 14:48:15 -0700 Subject: [PATCH 28/29] Fix for Sonatype publishing --- library/build.gradle | 49 +++++++++++++++++++++++++++++++------------- 1 file changed, 35 insertions(+), 14 deletions(-) diff --git a/library/build.gradle b/library/build.gradle index a5615d6..d95fb57 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -64,22 +64,43 @@ afterEvaluate { groupId = GROUP artifactId = POM_ARTIFACT_ID version = VERSION_NAME + + pom { + name = POM_NAME + url = POM_URL + description = POM_DESCRIPTION + licenses { + license { + name = POM_LICENCE_NAME + url = POM_LICENCE_URL + } + } + developers { + developer { + id = POM_DEVELOPER_ID + name = POM_DEVELOPER_NAME + } + } + scm { + url = POM_SCM_URL + } + } + } + } + repositories { + maven { + name = "Sonatype" + credentials { + username = System.getenv('NEXUS_USERNAME') + password = System.getenv('NEXUS_PASSWORD') + } + def releasesRepoUrl = 'https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/' + def snapshotsRepoUrl = 'https://s01.oss.sonatype.org/content/repositories/snapshots/' + url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl + setUrl(url) } } - repositories { - maven { - name = "Sonatype" - credentials { - username = System.getenv('NEXUS_USERNAME') - password = System.getenv('NEXUS_PASSWORD') - } - def releasesRepoUrl = 'https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/' - def snapshotsRepoUrl = 'https://s01.oss.sonatype.org/content/repositories/snapshots/' - url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl - setUrl(url) - } } - } } signing { @@ -102,7 +123,7 @@ artifacts { } ext { - supportVersion = '28.0.0' + supportVersion = '28.0.0' } dependencies { From 3a7c3a523ef9c574d3bc4b0fb8493548c6a7abff Mon Sep 17 00:00:00 2001 From: Roger Hu Date: Sat, 10 Jul 2021 15:17:06 -0700 Subject: [PATCH 29/29] Bump to 2.3.0 - 2.2.0 was a mistag. --- library/build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/build.gradle b/library/build.gradle index d95fb57..c25a507 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -5,8 +5,8 @@ apply plugin: 'signing' ext { GROUP = 'com.codepath.libraries' - BASE_VERSION = "2.2" - VERSION_NAME = "2.2.0" + BASE_VERSION = "2.3" + VERSION_NAME = "2.3.0" POM_PACKAGING = "aar" POM_DESCRIPTION = "CodePath OAuth Handler"