Skip to content

Handle OAuth2AccessTokenErrorResponse exception when attempting to parse access token. #138

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import com.facebook.react.bridge.ReactContext;
import com.github.scribejava.core.exceptions.OAuthConnectionException;
import com.github.scribejava.core.model.OAuth2AccessTokenErrorResponse;
import com.github.scribejava.core.model.OAuth1AccessToken;
import com.github.scribejava.core.model.OAuth1RequestToken;
import com.github.scribejava.core.model.OAuth2AccessToken;
Expand Down Expand Up @@ -367,6 +368,11 @@ protected OAuth2AccessToken doInBackground(Void... params) {
Log.e(TAG, "OAuth connection exception: " + ex.getMessage());
ex.printStackTrace();
return null;
} catch (OAuth2AccessTokenErrorResponse ex)
{
Log.e(TAG, "Failed to extract access token: " + ex.getMessage());
mCtrl.onError(-1, ex.getMessage(), "Failed to extract access token.");
return null;
} catch (IOException ex) {
Log.e(TAG, "An exception occurred getRequestToken: " + ex.getMessage());
ex.printStackTrace();
Expand Down
12 changes: 12 additions & 0 deletions android/src/main/java/io/fullstack/oauth/OAuthManagerModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,18 @@ public void onRequestTokenError(final Exception ex) {
Log.e(TAG, "Exception with request token: " + ex.getMessage());
_credentialsStore.delete(providerName);
_credentialsStore.commit();

WritableMap error = Arguments.createMap();
error.putString("message", ex.getMessage());

// In an invalid client situation we will get two errors, first for the invalid client, and second for the null access token
// we really want to report the invalid client error because it provides better feedback
try {
callback.invoke(error);
} catch (Exception e2)
{
Log.e(TAG, "exception with request: callback failed: " + e2.getMessage() );
}
}
public void onOAuth1AccessToken(final OAuth1AccessToken accessToken) {
_credentialsStore.store(providerName, accessToken);
Expand Down