Class

ASWebAuthenticationSession

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

Declaration

class ASWebAuthenticationSession : NSObject

Overview

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 init(url: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 ASWebAuthenticationSessionError.Code.canceledLogin.

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

Topics

Creating a Session

Configuring a Session

var prefersEphemeralWebBrowserSession: Bool

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

Starting and Stopping a Session

func start() -> Bool

Starts a web authentication session.

func cancel()

Cancels a web authentication session.

Presenting a Session

var presentationContextProvider: ASWebAuthenticationPresentationContextProviding?

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

protocol ASWebAuthenticationPresentationContextProviding

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

Recognizing Errors

struct ASWebAuthenticationSessionError

Errors that a web authentication session can generate.

Relationships

Inherits From

Conforms To