I am getting ERR_UNKNOWN_URL_SCHEME
error in chrome on redirection in in-app browser for Federated authentication in React Native using deep-linking for callback URL. The issue appears only if 2-Step Verification is turned on in Google account. Following are the details of the issue and steps to reproduce it.
Platform: Android 10, 11, 12
Device type: Physical device
Issue appears in these Chrome browser versions:
The issue does NOT appear in Chrome browser version: 87.0.4280.141
Package version: react-native-inappbrowser-reborn version: ^3.6.3
Also tried on expo-web-browser version: 9.2.0
inAppbrowser.openAuth(...)
/openAuthSessionAsync(...)
to sign in using Google as identity provider<your_scheme>: links are blocked
with error code = ERR_UNKNOWN_URL_SCHEME
. See this screenshot:In AndroidManifest.xml, this is how my deep linking URL (let's say "my_scheme") is configured:
<intent-filter android:label="filter_react_native">
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:scheme="my_scheme"/>
</intent-filter>
This is how I call the openAuth
function from react-native-inappbrowser-reborn
const { type, url: newUrl } = await InAppBrowser.openAuth(
url,
redirectUrl,
{
showInRecents: true, // browser dismisses when set to false
forceCloseOnRedirection: false, // same issue when set to true
showTitle: false,
enableUrlBarHiding: true,
enableDefaultShare: false,
ephemeralWebSession: false,
}
);
And for expo-web-browser
module, here is how I have called openAuthSessionAsync
:
const { type, url: newUrl } = await WebBrowser.openAuthSessionAsync(
url,
redirectUrl,
{
showInRecents: true,
toolbarColor: Colors.primaryVariant,
createTask: false,
},
);
I tried to use other means of 2-Step verification such as SMS/Authenticator app code. In both cases, even if I put the app in background to either open my SMS app or Authenticator app(Google Authenticator) and then again switch back to the React Native app, in-app browser redirects to the React-Native app just fine and I don't get this ERR_UNKNOWN_URL_SCEME
issue.
This issue exists in both the in-app browser modules (expo-web-browser
as well as react-native-inappbrowser-reborn
).
Somehow this Google authentication overlay to confirm the identity breaks redirection to React-Native app using the deeplinked URL. The issue does not appear when 2-Step Verification using the Device is already responded using Yes or it is not configured at all and the app signs in seamlessly.
Any help or pointers to solution would be appreciated. Let me know in the comments if more details are required.
I noticed that this issue has been fixed in the newer versions of Android System Webview and corresponding versions of Chrome-based browsers.
To ensure the user is using the latest version of webview: programmatically check the package name of the default webview app installed in Android and then check it's version. If the version is older than 105.x(a fairly new version on which the issue seems to be fixed), show a dialog box informing the user to update the webview app along with a button to redirect to the Google Play Store page of that webview package. This would require you to write a small native module code for Android.
But I believe this may not be required in 2023, now that almost all users would have upgraded to the latest version, but still, the above check is good to have just in case a similar issue originating from the webview pops-up in the future.