WebAuthenticationSession class

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

It is implemented using ASWebAuthenticationSession on iOS 12.0+ and MacOS 10.15+ and SFAuthenticationSession on iOS 11.0.

Use an PlatformWebAuthenticationSession 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. 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, and the session passes this URL back to the app through a completion handler. PlatformWebAuthenticationSession ensures that only the calling app’s session receives the authentication callback, even when more than one app registers the same callback URL scheme.

NOTE: Remember to dispose it when you don't need it anymore.

NOTE for iOS: Available only on iOS 11.0+.

NOTE for MacOS: Available only on MacOS 10.15+.

Officially Supported Platforms/Implementations:

  • iOS
  • MacOS

Constructors

WebAuthenticationSession()
A session that an app uses to authenticate a user through a web service.
WebAuthenticationSession.fromPlatform({required PlatformWebAuthenticationSession platform})
Constructs a WebAuthenticationSession from a specific platform implementation.
WebAuthenticationSession.fromPlatformCreationParams({required PlatformWebAuthenticationSessionCreationParams params})
Constructs a WebAuthenticationSession.

Properties

callbackURLScheme String?
The custom URL scheme that the app expects in the callback URL.
no setter
hashCode int
The hash code for this object.
no setterinherited
id String
ID used internally.
no setter
initialSettings WebAuthenticationSessionSettings?
Initial settings.
no setter
onComplete WebAuthenticationSessionCompletionHandler?
A completion handler the session calls when it completes successfully, or when the user cancels the session.
no setter
platform PlatformWebAuthenticationSession
Implementation of PlatformWebAuthenticationSession for the current platform.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
url WebUri
A URL with the http or https scheme pointing to the authentication webpage.
no setter

Methods

cancel() Future<void>
Cancels the web authentication session.
canStart() Future<bool>
Indicates whether the session can begin.
dispose() Future<void>
Disposes the web authentication session.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
start() Future<bool>
Starts the web authentication session.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Methods

create({required WebUri url, String? callbackURLScheme, WebAuthenticationSessionCompletionHandler? onComplete, WebAuthenticationSessionSettings? initialSettings}) Future<WebAuthenticationSession>
Used to create and initialize a session.
isAvailable() Future<bool>
Returns true if ASWebAuthenticationSession or SFAuthenticationSession is available. Otherwise returns false.