1

I am building an iOS application that allows user to signup and login to the enterprise system. Let's name it MyAuthApp which will be used as an authentication app for other (CallingApp) applications within the organisation.

Brief requirements are such:

  1. Event triggered in CallingApp (eg. user taps on button "login using MyAuthApp")
  2. MyAuthApp opens automatically, giving user login options
  3. User provides credentials in MyAuthApp
  4. Upon successful authentication in MyAuthApp, a callback is returned to CallingApp with the auth token
  5. CallingApp becomes active and with a valid token, user is able to use CallingApp as needed.

I tried using x-callback-url (https://x-callback-url.com/implementation/) and followed this example (https://github.com/palash89/InterAppCommunication).

MyAuthApp's scheme is registered in CallingApp's info.plist file and vice versa.

MyAuthApp is launched upon event triggered in CallingApp.

let urlStr = "myAuthApp://x-callback-url/auth?x-success=sourceapp://x-callback-url/authSuccess&x-source=callingApp&x-error=sourceapp://x-callback-url/authError"
    if let url = URL.init(string: urlStr), UIApplication.shared.canOpenURL(url) {
      UIApplication.shared.open(url)
    }

Upon receiving auth data, Calling App is launched with token as parameter.

let urlStr = "callingApp://x-callback-url/authSuccess?x-source=myAuthApp&token=\(token)"
    if let url = URL.init(string: urlStr), UIApplication.shared.canOpenURL(url)){
       UIApplication.shared.open(url)
    }

Problem here is, MyAuthApp needs to register CallingApp's scheme in info.plist. This means, every time a new app starts supporting MyAuthApp, MyAuthApp's info.plist needs to be changed.

Is there a way to avoid this dependency? MyAuthApp should not be aware of CallingApp's identity and should ideally return the token by using a callback instead of launching the CallingApp.

curiosolio
  • 11
  • 2
  • This may be helpful - from the documentation for `canOptionURL`: *"Unlike this method, the openURL:options:completionHandler: method isn’t constrained by the LSApplicationQueriesSchemes requirement. If an app is available to handle the URL, the system will launch it, even if you haven’t declared the scheme."*. – HangarRash Nov 15 '22 at 02:27
  • Yes, there is no real need to query for the URL - Just open it; The app passed you that URL as the return, so presumably it is installed and will respond to that URL. – Paulw11 Nov 15 '22 at 03:21
  • Thanks for the suggestion, HangarRash and Paulw11. I have removed the canOpenURL method in the target app (MyAuthApp) and it works just nice without the LSApplicationQueriesSchemes requirement in info.plist. – curiosolio Nov 15 '22 at 05:04

0 Answers0