Custom-URL-scheme icon indicating copy to clipboard operation
Custom-URL-scheme copied to clipboard

iPhone - not redirecting back to the application

Open aubrey-fowler opened this issue 4 years ago • 0 comments

I have an app written with AngularJS 1.5.3, Cordova, and Ionic v1.

I'm using these 2 plugins to implement some SSO (Single-Sign-On) functionality.


ionic info

Ionic:

   ionic (Ionic CLI) : 4.10.3 (C:\Users\User\node_modules\ionic)
   Ionic Framework   : ionic1 1.3.5
   @ionic/v1-toolkit : 1.0.22

Cordova:

   cordova (Cordova CLI) : 8.1.2 ([email protected])
   Cordova Platforms     : android 8.1.0, ios 6.1.0, browser 5.0.4, windows 4.4.3
   Cordova Plugins       : cordova-plugin-ionic-webview 4.1.3, (and 17 other plugins)

System:

   Android SDK Tools : 26.1.1 (C:\Users\User\Documents\Android\sdk)
   NodeJS            : v10.21.0 (C:\Program Files\nodejs\node.exe)
   npm               : 6.14.4
   OS                : Windows 10


config.xml


    <plugin name="cordova-plugin-inappbrowser" spec="^4.0.0">
        <variable name="usewkwebview" value="true" />
    </plugin>
	
    <plugin name="cordova-plugin-customurlscheme" spec="https://github.com/EddyVerbruggen/Custom-URL-scheme.git">
        <variable name="URL_SCHEME" value="selfserviceapp" />
        <variable name="ANDROID_SCHEME" value=" " />
        <variable name="ANDROID_HOST" value=" " />
        <variable name="ANDROID_PATHPREFIX" value="/" />
    </plugin>

As I'm using cordova-ios 6.1.0 I'm using WkWebView only.

<platform name="ios">
    <preference name="WKWebViewOnly" value="true" />

package.json

 "dependencies": {
    "cordova-android": "^8.1.0",
	"cordova-ios": "^6.1.0",
    "cordova-android-support-gradle-release": "^3.0.1",
    "cordova-plugin-camera": "^4.1.0",
    "cordova-plugin-compat": "^1.2.0",
    "cordova-plugin-customurlscheme": "git+https://github.com/EddyVerbruggen/Custom-URL-scheme.git",
    "cordova-plugin-device": "^2.0.3",
    "cordova-plugin-file": "^6.0.2",
    "cordova-plugin-geolocation": "^4.0.2",
    "cordova-plugin-inappbrowser": "^4.0.0",
    "cordova-plugin-network-information": "^2.0.2",
    "cordova-plugin-safariviewcontroller": "^1.6.0",
    "cordova-plugin-save-image": "^0.3.0",
    "cordova-plugin-settings-hook": "^0.2.7",
    "cordova-plugin-splashscreen": "^5.0.4",
    "cordova-plugin-statusbar": "^2.4.3",
    "cordova-plugin-whitelist": "^1.3.4",
    "cordova.plugins.diagnostic": "^4.0.12",
    "ionic-plugin-keyboard": "^2.2.1",
    "natives": "^1.1.6"
  },


    "plugins": {
      "cordova-plugin-splashscreen": {},
      "cordova-plugin-statusbar": {},
      "cordova-plugin-compat": {},
      "cordova-plugin-device": {},
      "cordova-plugin-settings-hook": {},
      "cordova-plugin-save-image": {},
      "cordova-plugin-file": {},
      "cordova-plugin-network-information": {},
      "cordova-plugin-whitelist": {},
      "ionic-plugin-keyboard": {},
      "cordova-plugin-safariviewcontroller": {},
      "cordova-plugin-camera": {},
      "cordova-plugin-geolocation": {},
      "cordova.plugins.diagnostic": {
        "ANDROID_SUPPORT_VERSION": "28.+"
      },
      "cordova-android-support-gradle-release": {
        "ANDROID_SUPPORT_VERSION": "27.+"
      },
      "cordova-plugin-customurlscheme": {
        "URL_SCHEME": "selfserviceapp",
        "ANDROID_SCHEME": " ",
        "ANDROID_HOST": " ",
        "ANDROID_PATHPREFIX": "/"
      },
      "cordova-plugin-inappbrowser": {
        "usewkwebview": "true"
      }
    }

The app will open the Identity provider in a browser, the user will log in there, and then the user will be re-directed back to the application.

It's working perfectly on Android but for iOS it does not redirect back to the application.

It stays on the browser page and the user has to manually click the 'done' button to redirect back to the application.

*-Info.plist

Screenshot (270)

2020-08-18

code snippet:

on window object

var handleOpenURL = null;

window['handleOpenURL'] = function (url) {

    if (handleOpenURL) {
        handleOpenURL(url);
    }

};


        self.openUrl = function (url) {

            return new Promise(function (resolve, reject) {

                try {

                    SafariViewController.isAvailable(function (available) {
                        if (available) {

                            self.hideSpinner();

                            handleOpenURL = function (url) {

                                if (url.startsWith(ClientConfig.config.redirect_uri)) {
                                    self.processAuthCodeResponse(url)
                                        .then(function (token) {
                                            resolve(token);
                                        })
                                        .catch(function(error) {
                                            reject(error);
                                        })
                                        .finally(function() {
                                            window['SafariViewController'].hide();
                                        });
                                }
                            }

                            SafariViewController.show({
                                url: url
                            })

                        } else {
                            alert(' Browser Not Available! ');
                        }

                    });

                }
                catch (error) {
                    reject(error);
                }

            });

        };

aubrey-fowler avatar Aug 18 '20 10:08 aubrey-fowler