A class that manages sharing a one-time login between Safari and an app, which can also be used for automatic login for associated apps.
- iOS 12.0+
ASWeb object can be used to authenticate a user with a web service, even if the web service is run by a third party.
ASWeb puts the user in control of whether they want to use their existing logged-in session from Safari.
The app provides a URL that points to the authentication webpage. The page will be loaded in a secure view controller. From the webpage, the user can authenticate herself and grant access to the app. On completion, the service will send a callback URL with an authentication token, and this URL will be passed to the app by
The callback URL usually has a custom URL scheme. For the app to receive the callback URL, it needs to either register the custom URL scheme in its
Info, or set the scheme to
init(url: argument in the initializer.
If the user has already logged into the web service in Safari or other apps via
ASWeb, it is possible to share the existing login information. An alert will be presented to get the user's consent for sharing their existing login information. If the user cancels the alert, the session will be canceled, and the completion handler will be called with the error code
If the user taps Cancel when showing the login webpage for the web service, the session will be canceled, and the completion handler will be called with the error code
The app can cancel the session by calling
cancel(). This will also dismiss the view controller that is showing the web service's login page.