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.

  • Returns the current authentication status.

    Declaration

    Swift

    public var status: DittoAuthenticationStatus { get }
  • 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

    public func loginWithToken(
        _ token: String,
        provider: String,
        completion: @escaping (DittoSwiftError?) -> 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

    public func loginWithCredentials(
        username: String,
        password: String,
        provider: String,
        completion: @escaping (DittoSwiftError?) -> Void
    )
  • Log out of Ditto.

    This will stop sync, shut down all replication sessions, and remove any cached authentication credentials. Note that this does not remove any data from the store. If you wish to delete data from the store then use the optional cleanup closure to perform any required cleanup.

    @param cleanup an optional closure that will be called with the relevant Ditto instance 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 status changes. Returns a DittoObserver that needs to be retained as long as you want to receive the updates.

    Declaration

    Swift

    public func observeStatus(_ block: @escaping (DittoAuthenticationStatus) -> Void) -> DittoObserver
  • Query whether Ditto has a valid authentication token.

    This will only be true when using an onlineWithAuthentication or an online identity, after a successful login. If the authentication token is allowed to expire then it will return false instead.

    @deprecated: use status instead.

    Declaration

    Swift

    @available(*, deprecated, message: "Use `status` property instead.")
    public func isAuthenticated() -> Bool
  • The currently logged-in user ID.

    This will return nil if there is no valid authentication or onlineWithAuthentication/online mode is not being used.

    @deprecated: use status instead.

    Declaration

    Swift

    @available(*, deprecated, message: "Use `status` property instead.")
    public var userID: String? { get }