Authentication

public final class Authentication : ObservableObject, OrangeChatLoggable

An object representing the authentication of a OrangeChatManager instance.

Instance is created in the OrangeChatManager instance and is accessible by using OrangeChatManager.authentication.

Two kinds of authentication methods are available:

  • the custom authentication method, for applications using an ad hoc authentication mechanism,
  • the authentication with one-time password SMS, which uses identities directly managed by the back-end application, using the user phone number.

Stored Properties

  • The current app identifier

    Declaration

    Swift

    @Published
    public var appIdentifier: String { get set }
  • The current authenticated state.

    Declaration

    Swift

    @Published
    public var state: AuthenticationState { get set }
  • The current authenticated user of the application. This property is nil when there is currently no valid authentication.

    Declaration

    Swift

    public var authenticatedUser: User? { get }
  • To know if a user is authenticated.

    Declaration

    Swift

    public var isAuthenticated: Bool { get }
  • To get the authentication token if a user is authenticated.

    Declaration

    Swift

    public var authenticationToken: String? { get }

Credential Authentication

  • Log in the current user with the custom method provider.

    Declaration

    Swift

    public func login(withProvider identifier: String, and credentials: String, for msisdn: String)

    Parameters

    withProvider

    The identifier of the custom provider.

    credentials

    The credentials used to authenticate with the custom method provider.

    msisdn

    The user’s phone number in E164 format (e.g. +33699999999).

OTP Athentication

  • Begin the authentication of the current user with the one-time password SMS authentication.

    There is no need to worry about creating an account for the first time or logging in. This method checks whether a phone number entered exists in the application and acts on the answer. If the account does not exist, then it is created. In both cases, a one-time password verification code is sent by SMS to verify the user’s identity.

    Declaration

    Swift

    public func requestOtpSMS(for msisdn: String)

    Parameters

    msisdn

    The user’s phone number in E164 format (e.g. +33699999999).

  • Log in the current user.

    This method succeeds when there is currently no authenticated user and the one-time password is valid.

    Declaration

    Swift

    public func login(withOTP: String)

    Parameters

    withOTP

    The one-time password received by SMS.

  • Log out the current user.

    Declaration

    Swift

    public func logout()
  • Update the presence of the current user of the application.

    The presence of the current user need to be updated each time:

    • he or she logs in or out of the application,
    • the application moves and comes back to the background.

    Declaration

    Swift

    public func update(presence: Presence) -> OrangeChatPublisher<Void>

    Parameters

    presence

    The presence of the current user of the application.

    Return Value

    A publisher with a Void value.

  • Retrieve the information of a user related to his phone number.

    Declaration

    Swift

    public func retrieveUserInformation(with msisdn: String) -> OrangeChatPublisher<User>

    Parameters

    msisdn

    The phone number of the researched user in the database.

    Return Value

    A publisher with a User value corresponding to the found user.

  • Retrieve the information of a user related to his id.

    Declaration

    Swift

    public func user(from userId: OrangeChatKey) -> OrangeChatPublisher<User>

    Parameters

    userId

    The id of the user in database

    Return Value

    A publisher with a User value corresponding to the found user.

  • Retrieve the user id related to his phone number.

    Declaration

    Swift

    public func uid(for msisdn: String) -> OrangeChatPublisher<OrangeChatKey>

    Parameters

    msisdn

    The phone number of the researched user in the database.

    Return Value

    A publisher with the id associated to the phone number.