A session that an app uses to authenticate a user through a web service.


@interface ASWebAuthenticationSession : NSObject


Use an ASWebAuthenticationSession instance to authenticate a user through a web service, including one run by a third party. The system lets the user decide whether to use an existing, logged-in session, if one is available.

When you create an authentication session in your app, you provide a URL that points to the authentication webpage. A secure view controller loads and displays the page, from which the user can authenticate and grant access to the app. On completion, the service sends a callback URL to the session with an authentication token, and the session passes this URL back to the app through a completion handler.

The callback URL typically uses a custom URL scheme. For your app to receive the callback URL, either register the custom URL scheme in the app’s Information Property List file, or set the callbackURLScheme argument in the initWithURL:callbackURLScheme:completionHandler: initializer.

If the user has already logged into the web service in Safari or other apps using ASWebAuthenticationSession, it’s possible to share the existing login information. The system presents the user with a dialog asking for consent to share login information. If the user cancels the alert, the session is canceled, and the completion handler is called with the error code ASWebAuthenticationSessionErrorCodeCanceledLogin.

The app can cancel the session by calling the cancel method. This dismisses the view controller showing the web service’s login page.


Creating a Session

- initWithURL:callbackURLScheme:completionHandler:

Creates a web authentication session instance.


A completion handler for the web authentication session.

Configuring a Session


A Boolean value that indicates whether the session should ask the browser for a private authentication session.


Starting and Stopping a Session

- start

Starts a web authentication session.

- cancel

Cancels a web authentication session.

Presenting a Session


A delegate that provides a display context in which the system can present an authentication session to the user.


An interface the session uses to ask a delegate for a presentation context.


Recognizing Errors


The error domain for a web authentication session.


The error code for a web authentication session error.


Inherits From

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software