---
title: ASWebAuthenticationSession
framework: authenticationservices
role: symbol
role_heading: Class
path: authenticationservices/aswebauthenticationsession
---

# ASWebAuthenticationSession

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

## Declaration

```swift
class ASWebAuthenticationSession
```

## Mentioned in

Authenticating a User Through a Web Service Supporting Single Sign-On in a Web Browser App

## Overview

Overview Use an ASWebAuthenticationSession instance to authenticate a user through a web service, including one run by a third party. Initialize the session with a URL that points to the authentication webpage. When the user starts the authentication session, the operating system shows a modal view telling them which domain the app is authenticating with and asking whether to proceed. If the user proceeds with the authentication attempt, a browser loads and displays the page, from which the user can authenticate. In iOS, the browser is a secure, embedded web view. In macOS, the system opens the user’s default browser if it supports web authentication sessions, or Safari otherwise. On completion, the service sends a callback URL to the session with an authentication token. The session passes this URL back to the app through a completion handler. ASWebAuthenticationSession ensures that only the calling app’s session receives the authentication callback, even when more than one app registers the same callback URL scheme. For more details, see Authenticating a User Through a Web Service.

## Topics

### Creating a session

- [init(url:callback:completionHandler:)](authenticationservices/aswebauthenticationsession/init(url:callback:completionhandler:)-6nut7.md)
- [ASWebAuthenticationSession.Callback](authenticationservices/aswebauthenticationsession/callback.md)
- [ASWebAuthenticationSession.CompletionHandler](authenticationservices/aswebauthenticationsession/completionhandler.md)

### Configuring a session

- [prefersEphemeralWebBrowserSession](authenticationservices/aswebauthenticationsession/prefersephemeralwebbrowsersession.md)

### Starting and Stopping a Session

- [canStart](authenticationservices/aswebauthenticationsession/canstart.md)
- [start()](authenticationservices/aswebauthenticationsession/start().md)
- [cancel()](authenticationservices/aswebauthenticationsession/cancel().md)

### Presenting a Session

- [presentationContextProvider](authenticationservices/aswebauthenticationsession/presentationcontextprovider.md)
- [ASWebAuthenticationPresentationContextProviding](authenticationservices/aswebauthenticationpresentationcontextproviding.md)

### Recognizing Errors

- [ASWebAuthenticationSessionError](authenticationservices/aswebauthenticationsessionerror.md)
- [ASWebAuthenticationSessionErrorDomain](authenticationservices/aswebauthenticationsessionerrordomain.md)
- [ASWebAuthenticationSessionError.Code](authenticationservices/aswebauthenticationsessionerror/code.md)

### Instance properties

- [additionalHeaderFields](authenticationservices/aswebauthenticationsession/additionalheaderfields.md)

### Deprecated symbols

- [init(url:callbackURLScheme:completionHandler:)](authenticationservices/aswebauthenticationsession/init(url:callbackurlscheme:completionhandler:)-7fpox.md)

### Initializers

- [init(URL:callback:completionHandler:)](authenticationservices/aswebauthenticationsession/init(url:callback:completionhandler:)-6y7n6.md)
- [init(URL:callbackURLScheme:completionHandler:)](authenticationservices/aswebauthenticationsession/init(url:callbackurlscheme:completionhandler:)-7evyf.md)

## Relationships

### Inherits From

- [NSObject](objectivec/nsobject-swift.class.md)

### Conforms To

- [CVarArg](swift/cvararg.md)
- [CustomDebugStringConvertible](swift/customdebugstringconvertible.md)
- [CustomStringConvertible](swift/customstringconvertible.md)
- [Equatable](swift/equatable.md)
- [Hashable](swift/hashable.md)
- [NSObjectProtocol](objectivec/nsobjectprotocol.md)

## See Also

### Web authentication sessions

- [Authenticating a User Through a Web Service](authenticationservices/authenticating-a-user-through-a-web-service.md)
- [Securing Logins with iCloud Keychain Verification Codes](authenticationservices/securing-logins-with-icloud-keychain-verification-codes.md)
- [WebAuthenticationSession](authenticationservices/webauthenticationsession.md)
- [Supporting Single Sign-On in a Web Browser App](authenticationservices/supporting-single-sign-on-in-a-web-browser-app.md)
- [ASWebAuthenticationSessionWebBrowserSessionManager](authenticationservices/aswebauthenticationsessionwebbrowsersessionmanager.md)
- [ASWebAuthenticationSessionWebBrowserSupportCapabilities](bundleresources/information-property-list/aswebauthenticationsessionwebbrowsersupportcapabilities.md)
