DittoAuthenticator
public class DittoAuthenticator
Provides access to authentication information and methods for logging on to
Ditto Cloud. Relevant when using an onlineWithAuthentication or an
online identity.
-
The authentication delegate for this Ditto instance as provided via
DittoIdentity.onlineWithAuthentication().Phased out in 4.x —
DittoIdentityand with itDittoAuthenticationDelegateis being phased out, please useDittoConfig-based APIs instead and set theDittoAuthenticationExpirationHandler. This API will be replaced byDittoAuthenticationExpirationHandlerin v5.Declaration
Swift
public weak var delegate: DittoAuthenticationDelegate? { get } -
The handler that will be called when authentication for this Ditto instance is about to expire.
Important
This API is in preview and provides a closure-based replacement for thedelegateproperty, offering a more modern approach to handling authentication expiration events in v5.Assign a closure to this property to be notified before authentication expires, allowing you to login or perform other necessary actions.
Important
If the Ditto instance was initialized with
connectset toserver(url:)this property must be set and the handler must properly authenticate when triggered.See also
DittoSwiftError/authenticationError(reason:)andDittoSwiftError/AuthenticationErrorReason/expirationHandlerMissing(message:)Declaration
Swift
public var expirationHandler: DittoAuthenticationExpirationHandler? { get set } -
Returns the current authentication status.
Declaration
Swift
public var status: DittoAuthenticationStatus { get } -
Convenience method allowing you to pass the provider directly as a string instead of
DittoAuthenticationProvider.Declaration
Swift
public func login( token: String, provider: String, completion: @escaping (String?, DittoError?) -> Void ) -
Log in to Ditto with a third-party token.
The completion closure will be called once, whether the login attempt succeeds or fails. If it has failed then the optional
DittoErrorwill be non-nil, otherwise it will benil. Regardless of whether or not the login attempt succeeds the optionalStringargument will be non-nilif the auth webhook endpoint returned any JSON value under theclientInfokey. That JSON string is what will be passed via theString?argument, if it’s provided.@param token the authentication token required to log in. @param provider the name of the authentication provider. @param completion a closure that will get called when the login attempt has completed.
Declaration
Swift
public func login( token: String, provider: DittoAuthenticationProvider, completion: @escaping (String?, DittoError?) -> Void ) -
Convenience method allowing you to pass the provider directly as a string instead of
DittoAuthenticationProvider.Declaration
Swift
@available(*, deprecated, message: "Use `login(﹚` instead.") public func loginWithCredentials( username: String, password: String, provider: String, completion: @escaping (DittoError?) -> Void ) -
Log in to Ditto with a username and password.
@param username the username component of the credentials used for log in. @param password the password component of the credentials used for log in. @param provider the name of the authentication provider. @param completion a closure that will get called when the login attempt has completed.
Declaration
Swift
@available(*, deprecated, message: "Use `login(﹚` instead.") public func loginWithCredentials( username: String, password: String, provider: DittoAuthenticationProvider, completion: @escaping (DittoError?) -> Void ) -
Log out of Ditto.
This will stop sync, shut down all replication sessions, and remove any cached authentication credentials. Use the optional
cleanupclosure to perform any required cleanup.Note that this does not remove any data from the store. The ditto instance returned in the cleanup closure will no longer be authorized for write transactions, e.g.
remove(), however, data may be evicted.@param cleanup an optional closure that will be called with the relevant
Dittoinstance as the sole argument that allows you to perform any required cleanup of the store as part of the logout process.Declaration
Swift
public func logout(cleanup: ((Ditto) -> Void)? = nil) -
Registers a block that will be called whenever authentication
statuschanges. Returns aDittoObserverthat needs to be retained as long as you want to receive the updates.Declaration
Swift
public func observeStatus(_ block: @escaping (DittoAuthenticationStatus) -> Void) -> DittoObserver
-
Log in to Ditto with a third-party token.
@param token the authentication token required to log in. @param provider the name of the authentication provider. @param completion a closure that will get called when the login attempt has completed.
Declaration
Swift
@available(*, deprecated, message: "Use `login` that provides access to the clientInfo JSON string in the completion closure instead.") public func loginWithToken( _ token: String, provider: String, completion: @escaping (DittoSwiftError?) -> Void ) -
A Combine publisher that shares authentication status.
See moreDeclaration
Swift
struct StatusPublisher : Publisher -
A Combine publisher for authentication status changes.
Declaration
Swift
func statusPublisher() -> StatusPublisherReturn Value
A
StatusPublisherwhich has an output ofDittoAuthenticationStatus.