Skip to content
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

Is visible #139

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 @@ -45,6 +46,10 @@ public class OAuthManagerFragmentController {
private Runnable onAccessToken;
private OAuthManagerOnAccessTokenListener mListener;

public boolean webViewVisible() {
return this.mWebView != null && this.mWebView.isShown();
}

private void runOnMainThread(Runnable runnable) {
uiHandler.post(runnable);
}
Expand Down Expand Up @@ -367,6 +372,10 @@ 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());
return null;
} catch (IOException ex) {
Log.e(TAG, "An exception occurred getRequestToken: " + ex.getMessage());
ex.printStackTrace();
Expand Down
25 changes: 23 additions & 2 deletions android/src/main/java/io/fullstack/oauth/OAuthManagerModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,25 +137,29 @@ public void onOAuth2AccessToken(final OAuth2AccessToken accessToken) {
}
};

OAuthManagerFragmentController ctrl = null;

if (authVersion.equals("1.0")) {
final OAuth10aService service =
OAuthManagerProviders.getApiFor10aProvider(providerName, cfg, params, callbackUrl);

OAuthManagerFragmentController ctrl =
ctrl =
new OAuthManagerFragmentController(mReactContext, fragmentManager, providerName, service, callbackUrl);

ctrl.requestAuth(cfg, listener);
} else if (authVersion.equals("2.0")) {
final OAuth20Service service =
OAuthManagerProviders.getApiFor20Provider(providerName, cfg, params, callbackUrl);

OAuthManagerFragmentController ctrl =
ctrl =
new OAuthManagerFragmentController(mReactContext, fragmentManager, providerName, service, callbackUrl);

ctrl.requestAuth(cfg, listener);
} else {
Log.d(TAG, "Auth version unknown: " + (String) cfg.get("auth_version"));
}

this.ctrlReference = ctrl;
} catch (Exception ex) {
Log.d(TAG, "Exception in callback " + ex.getMessage());
exceptionCallback(ex, callback);
Expand Down Expand Up @@ -380,6 +384,23 @@ public void deauthorize(final String providerName, final Callback onComplete) {
}
}

private OAuthManagerFragmentController ctrlReference;

@ReactMethod
public void isVisible(final Callback callback)
{
try
{
boolean visible = this.ctrlReference != null && this.ctrlReference.webViewVisible();
WritableMap resp = Arguments.createMap();
resp.putBoolean("visible", visible);
callback.invoke(null, resp);
} catch (Exception e)
{
exceptionCallback(e, callback);
}
}


private HashMap<String,Object> getConfiguration(
final String providerName
Expand Down
4 changes: 4 additions & 0 deletions react-native-oauth.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ export default class OAuthManager {
return promisify('deauthorize')(provider);
}

isVisible() {
return promisify('isVisible')();
}

providers() {
return OAuthManager.providers();
}
Expand Down