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 WebAuthenticationSession 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. WebAuthenticationSession 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+.

Supported Platforms/Implementations:

  • iOS
  • MacOS

Properties

callbackURLScheme String?
The custom URL scheme that the app expects in the callback URL.
final
hashCode int
The hash code for this object.
no setterinherited
id String
ID used internally.
latefinal
initialSettings WebAuthenticationSessionSettings?
Initial settings.
latefinal
onComplete WebAuthenticationSessionCompletionHandler?
A completion handler the session calls when it completes successfully, or when the user cancels the session.
getter/setter pair
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.
final

Methods

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

Operators

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

Static Properties

debugLoggingSettings DebugLoggingSettings
Debug settings.
getter/setter pair

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.