Class

ASWebAuthenticationSession

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.

Declaration

class ASWebAuthenticationSession : NSObject

Overview

An ASWebAuthenticationSession object can be used to authenticate a user with a web service, even if the web service is run by a third party. ASWebAuthenticationSession 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 ASWebAuthenticationSession.CompletionHandler.

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.plist, or set the scheme to init(url:callbackURLScheme:completionHandler:) argument in the initializer.

If the user has already logged into the web service in Safari or other apps via ASWebAuthenticationSession, 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 ASWebAuthenticationSessionError.Code.canceledLogin.

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 ASWebAuthenticationSessionError.Code.canceledLogin.

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.

Topics

Type Aliases

typealias ASWebAuthenticationSession.CompletionHandler

A completion handler for the web authentications session.

Instance Methods

func cancel()

Cancel a web authentication session.

func start() -> Bool

A Boolean value indicating whether the web authentication session starts successfully.

Relationships

Inherits From

Conforms To

See Also

Sharing Data with Safari