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

Unable to log in via Facebook on Android #231

Open
maxcodes opened this issue Oct 12, 2018 · 4 comments
Open

Unable to log in via Facebook on Android #231

maxcodes opened this issue Oct 12, 2018 · 4 comments

Comments

@maxcodes
Copy link

maxcodes commented Oct 12, 2018

I'm having the exact same issue as #202. Copy-pasta:

This is only on Android. iOS works fine.

It seems the issue is related to the default callback: http://localhost/facebook. Facebook doesn't allow http callbacks anymore, so we're kind of stuck here. I tried all possible combinations of settings, even tried https://localhost/facebook just for the funz, but that didn't work either.

I'm investigating and can probably send a PR fix, but any pointers would be very helpful. Thanks!

@maxcodes
Copy link
Author

So, I managed to fix this by changing one line in the OAuthManagerModule.java. Instead of using http://localhost/facebook as a callback, I changed it to https://localhost/facebook both in the Facebook Valid OAuth Redirect URIs and here:

  @ReactMethod
  public void authorize(
    final String providerName, 
    @Nullable final ReadableMap params, 
    final Callback callback) 
  {
    try {
      final OAuthManagerModule self = this;
      final HashMap<String,Object> cfg = this.getConfiguration(providerName);
      final String authVersion = (String) cfg.get("auth_version");
      Activity activity = this.getCurrentActivity();
      FragmentManager fragmentManager = activity.getFragmentManager();
      String callbackUrl = "http://localhost/" + providerName; # <--- change this line to https

      ...

Happy to send a PR if this is the recommended way of fixing it 🙂

@maxcodes
Copy link
Author

So, the above snippet works if you're only working with facebook, but obviously breaks the other providers. The final snippet looks like this:

patch-package
--- a/node_modules/react-native-oauth/android/src/main/java/io/fullstack/oauth/OAuthManagerModule.java
+++ b/node_modules/react-native-oauth/android/src/main/java/io/fullstack/oauth/OAuthManagerModule.java
@@ -114,7 +114,12 @@ class OAuthManagerModule extends ReactContextBaseJavaModule {
       final String authVersion = (String) cfg.get("auth_version");
       Activity activity = this.getCurrentActivity();
       FragmentManager fragmentManager = activity.getFragmentManager();
-      String callbackUrl = "http://localhost/" + providerName;
+      String callbackUrl;
+      if (providerName.equals("facebook")) {
+        callbackUrl = "https://localhost/" + providerName;
+      } else {
+        callbackUrl = "http://localhost/" + providerName;
+      }
       
       OAuthManagerOnAccessTokenListener listener = new OAuthManagerOnAccessTokenListener() {
         public void onRequestTokenError(final Exception ex) {

@francoro
Copy link

francoro commented Mar 18, 2019

@maxcodes Hi max, I have question. This code you put above work also when the user is using LTE not wifi? My question is because use localhost , is okay that for LTE ?

Thanks

@maxcodes
Copy link
Author

Hey @francoro, I don't remember that being a problem, since localhost always refers to the local device. Cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants