I’m constructing an iOS software that permits consumer to signup and login to the enterprise system. Let’s title it MyAuthApp which will probably be used as an authentication app for different (CallingApp) purposes throughout the organisation.
Transient necessities are such:
- Even triggered in CallingApp (eg. consumer faucets on button "login utilizing MyAuthApp")
- MyAuthApp opens routinely, giving consumer login choices
- Consumer offers credentials in MyAuthApp
- Upon profitable authentication in MyAuthApp, a callback is returned to CallingApp with the auth token
- CallingApp turns into energetic and with a legitimate token, consumer is ready to use CallingApp as wanted.
I attempted utilizing x-callback-url (https://x-callback-url.com/implementation/) and adopted this instance (https://github.com/palash89/InterAppCommunication).
MyAuthApp’s scheme is registered in CallingApp’s data.plist file and vice versa.
MyAuthApp is launched upon occasion 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 knowledge, 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)
}
Downside right here is, MyAuthApp must register CallingApp’s scheme in data.plist. This implies, each time a brand new app begins supporting MyAuthApp, MyAuthApp’s data.plist must be modified.
Is there a solution to keep away from this dependency? MyAuthApp shouldn’t be conscious of CallingApp’s id and will ideally return the token through the use of a callback as an alternative of launching the CallingApp.