Skip to content

Unable to log in via Facebook on Android  #231

Description

@maxcodes

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!

Activity

  1. maxcodes commented on Oct 15, 2018

    @maxcodes
    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 🙂

  2. maxcodes commented on Oct 15, 2018

    @maxcodes
    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) {
  3. francoro commented on Mar 18, 2019

    @francoro

    @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

  4. maxcodes commented on Apr 16, 2019

    @maxcodes
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions