Contents

init(url:callback:completionHandler:)

Creates a web authentication session instance that uses a callback to evaluate a redirection URL.

Declaration

init(url URL: URL, callback: ASWebAuthenticationSession.Callback, completionHandler: @escaping  ASWebAuthenticationSession.CompletionHandler)

Parameters

  • URL:

    The initial URL pointing to the authentication webpage. This initializer only supports URLs with http:// or https:// schemes.

  • callback:

    An object that describes when the session calls its completion handler.

  • completionHandler:

    A completion handler that the system calls when the session completes successfully, or when the person using the app cancels the request.

Discussion

The following example creates a session that requires a callback with a custom URL scheme, using the customScheme(_:) type method to create the callback parameter:

let session = ASWebAuthenticationSession(
    url: URL(string: "https://example.com/oauth/login/authorize")!,
    callback: .customScheme("myappscheme")
) { callbackURL, error in
    // Handle the session result.
}

See Also

Creating a session