react-native-inappbrowser: Exception: The provided scheme is not valid iOS 14.5

Make sure to check the demo app(s) for sample usage

Checked

Make sure to check the existing issues in this repository

Checked, couldn’t find any issue related to this one

If the demo apps cannot help and there is no issue for your problem, tell us about it

Please, ensure your title is less than 63 characters long and starts with a capital letter.

Which platform(s) does your issue occur on?

  • iOS
  • iOS 14.5 only
  • both

Please, provide the following version numbers that your issue occurs with:

  • CLI: 4.13.1
  • Plugin(s):
"dependencies": {
    "@apollo/client": "^3.3.15",
    "@react-keycloak/native": "^0.5.2",
    "@react-native-async-storage/async-storage": "^1.15.4",
    "@react-native-community/masked-view": "^0.1.11",
    "@react-navigation/native": "^5.9.4",
    "@react-navigation/stack": "^5.14.4",
    "apollo-upload-client": "^14.1.3",
    "graphql": "^15.5.0",
    "i18next": "^20.2.2",
    "ramda": "^0.27.1",
    "react": "^17.0.2",
    "react-i18next": "^11.8.13",
    "react-native": "^0.64.0",
    "react-native-gesture-handler": "^1.10.3",
    "react-native-inappbrowser-reborn": "^3.5.1",
    "react-native-reanimated": "^2.1.0",
    "react-native-safe-area-context": "^3.2.0",
    "react-native-screens": "^3.1.1",
    "react-native-sensitive-info": "^6.0.0-alpha.9"
  },
  "devDependencies": {
    "@babel/core": "^7.13.16",
    "@babel/runtime": "^7.13.17",
    "@graphql-codegen/cli": "^1.21.4",
    "@graphql-codegen/fragment-matcher": "^2.0.1",
    "@graphql-codegen/introspection": "^1.18.2",
    "@graphql-codegen/typed-document-node": "^1.18.5",
    "@graphql-codegen/typescript": "^1.22.0",
    "@graphql-codegen/typescript-apollo-client-helpers": "^1.1.5",
    "@graphql-codegen/typescript-operations": "^1.17.16",
    "@graphql-codegen/typescript-react-apollo": "^2.2.4",
    "@react-native-community/eslint-config": "^2.0.0",
    "@types/jest": "^26.0.23",
    "@types/ramda": "^0.27.40",
    "@types/react-native": "^0.64.4",
    "@types/react-test-renderer": "^17.0.1",
    "babel-jest": "^26.6.3",
    "concurrently": "^6.0.2",
    "eslint": "^7.25.0",
    "jest": "^26.6.3",
    "metro-react-native-babel-preset": "^0.66.0",
    "react-test-renderer": "17.0.2",
    "typescript": "^4.2.4"
  },

Please, tell us how to recreate the issue in as much detail as possible.

I am using react-native-keycloak and opened the issue on that repo too https://github.com/react-keycloak/react-native-keycloak/issues/38, but most likely it’s related to the Inappbrowser.

Is there any code involved?

  • provide a code example to recreate the problem
  • (EVEN BETTER) provide a .zip with application or refer to a repository with application where the problem is reproducible. err

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 21
  • Comments: 19 (3 by maintainers)

Commits related to this issue

Most upvoted comments

If you’re using patch-package, placing the following in ./patches/react-native-inappbrowser-reborn+3.5.1.patch should fix things.

diff --git a/node_modules/react-native-inappbrowser-reborn/ios/RNInAppBrowser.m b/node_modules/react-native-inappbrowser-reborn/ios/RNInAppBrowser.m
index 674e8f1..81f069e 100644
--- a/node_modules/react-native-inappbrowser-reborn/ios/RNInAppBrowser.m
+++ b/node_modules/react-native-inappbrowser-reborn/ios/RNInAppBrowser.m
@@ -90,15 +90,17 @@ RCT_EXPORT_METHOD(openAuth:(NSString *)authURL
       }
     };
 
+    NSString *escapedRedirectURL = [redirectURL stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLHostAllowedCharacterSet]];
+
     if (@available(iOS 12.0, *)) {
       webAuthSession = [[ASWebAuthenticationSession alloc]
         initWithURL:url
-        callbackURLScheme:redirectURL
+        callbackURLScheme:escapedRedirectURL
         completionHandler:completionHandler];
     } else {
       authSession = [[SFAuthenticationSession alloc]
         initWithURL:url
-        callbackURLScheme:redirectURL
+        callbackURLScheme:escapedRedirectURL
         completionHandler:completionHandler];
     }

Also @dani-z as a quick work-around (obvi not ideal solution) I was able to get around this for now by changing the RNInAppBrowser.m file in the dependency itself to escape the callback URL:

NSString *escapedRedirectURL = [redirectURL stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLHostAllowedCharacterSet]];


    if (@available(iOS 12.0, *)) {
      webAuthSession = [[ASWebAuthenticationSession alloc]
        initWithURL:url
        callbackURLScheme:escapedRedirectURL
        completionHandler:completionHandler];
    } else {
      authSession = [[SFAuthenticationSession alloc]
        initWithURL:url
        callbackURLScheme:escapedRedirectURL
        completionHandler:completionHandler];
    }

Use encodeURIComponent(scheme)

Seems on iOS works any scheme now.

const scheme = 'my-scheme';
InAppBrowser.openAuth(url, Platform.OS == 'ios' ?  scheme : `${scheme}://my-host`);

I checked on device that it works on iOS 14.5 with Facebook, Google and Apple sign in.

Ok @maoapp, you’re the new maintainer here, thanks for your help merging these changes! ❤️

Ok, let me check this weekend, any pull request is welcome!

Also experiencing this issue.

sme here

Same

the same here

Hi @jdnichollsc. Unfortunately I might not have time to share a demo anytime soon as I am caught with work but will try. The schema I am using is myapp://home

Also, please note I was using react-native-keycloak package, but as described in the issue linked to that repo, the problem seems to be with the inappbrowser

Confirm that I am also having the same issue after upgrading to Xcode 12.5 / iOS 14.5