AuthenticationMethodInternal

public final class AuthenticationMethodInternal : AuthenticationMultiStepMethod
extension AuthenticationMethodInternal: WebcomCombinable

A method that authenticates the current user using identities directly managed by the back-end.

This method requires that the user provides input during the authentication process. To complete authentication, there are several methods to call, depending on the provider and the authentication mode.

For example, to attach a new identity using the e-mail provider and a static password:

let method = AuthenticationMethodInternal(provider: .eMail, mode: .staticPassword)
Webcom.defaultApplication.authenticationService.initializeAuthentication(with: method, context: .new)
method.setIdentifier("president@whitehouse.gov") // or directly sets the e-mail at initialization
method.setStaticPassword("...")
method.displayName = "Josiah Bartlet"
method.attachIdentity { _ in
    method.setVerificationToken("token received by e-mail")
    Webcom.defaultApplication.authenticationService.continueAuthentication { result in ... }
}

For example, to log-in using an existing identity using the phone provider and a one-time password:

let method = AuthenticationMethodInternal(msisdn: "+12024561111", mode: .oneTimePassword)
Webcom.defaultApplication.authenticationService.initializeAuthentication(with: method, context: .new)
method.requestOneTimePassword { _ in
    method.setOneTimePassword("code received by SMS")
    Webcom.defaultApplication.authenticationService.continueAuthentication { result in ... }
}

Types

Stored Properties

Initializers

  • Creates a new instance.

    If the identifier is not set here, the method setIdentifier(_:) will have to be called.

    For the e-mail provider, the init(eMail:mode:file:line:) initializer can be used. For the phone (SMS) provider, the init(msisdn:mode:sender:file:line:) initializer can be used.

    Declaration

    Swift

    public init(provider: AuthenticationProvider.InternalFamily, mode: Mode? = nil, sender: String? = nil, identifier: String? = nil, file: StaticString = #fileID, line: UInt = #line)

    Parameters

    provider

    The internal provider to use.

    mode

    The authentication mode, or nil to use the default value corresponding to the provider.

    sender

    The sender to be used by the AuthenticationProvider.InternalFamily.phone provider. This parameter is only meaningful when the provider parameter is AuthenticationProvider.InternalFamily.phone. Otherwise it is ignored.

    identifier

    The unique identifier of the user for the provider, or nil to set it later.

    file

    The file from which the method is called. This is used for debugging purposes.

    line

    The line from which the method is called. This is used for debugging purposes.

  • Creates a new instance for the e-mail provider.

    If the e-mail is not set here, the method setIdentifier(_:) will have to be called.

    Declaration

    Swift

    public convenience init(eMail: String?, mode: Mode? = nil, file: StaticString = #fileID, line: UInt = #line)

    Parameters

    eMail

    The e-mail of the user, which is its unique identifier for the provider, or nil to set it later.

    mode

    The authentication mode, or nil to use the default value corresponding to the AuthenticationProvider.InternalFamily.eMail provider.

    file

    The file from which the method is called. This is used for debugging purposes.

    line

    The line from which the method is called. This is used for debugging purposes.

  • Creates a new instance for the phone (SMS) provider.

    The MSISDN must follows the ITU-T recommendation E.164 An optional leading + (plus) sign can be added.

    Examples: 33144442222 or +12024561111

    If the MSISDN is not set here, the method setIdentifier(_:) will have to be called.

    Declaration

    Swift

    public convenience init(msisdn: String?, mode: Mode? = nil, sender: String? = nil, file: StaticString = #fileID, line: UInt = #line)

    Parameters

    msisdn

    The MSISDN of the user, which is its unique identifier for the provider, or nil to set it later.

    mode

    The authentication mode, or nil to use the default value corresponding to the AuthenticationProvider.InternalFamily.phone provider.

    sender

    The sender to be used by the provider.

    file

    The file from which the method is called. This is used for debugging purposes.

    line

    The line from which the method is called. This is used for debugging purposes.

AuthenticationMethod Protocol

API

  • Sets the unique identifier of the user for the provider.

    This method must be called after initializing this instance or just after AuthenticationService.initializeAuthentication(with:context:).

    Declaration

    Swift

    @discardableResult
    public func setIdentifier(_ identifier: String) -> WebcomResult<Void>

    Parameters

    identifier

    The unique identifier of the user for the provider, or nil to set it later.

    Return Value

    A WebcomResult with a void value in case of success or a WebcomError value in case of the failure.

  • Sets the static password of the user.

    Only use this method if the authentication mode is Mode.staticPassword.

    Declaration

    Swift

    @discardableResult
    public func setStaticPassword(_ password: String) -> WebcomResult<Void>

    Parameters

    password

    The password of the user.

    Return Value

    A WebcomResult with a void value in case of success or a WebcomError value in case of the failure.

  • Requests to send a link to the user, which allows him/her to reset his/her password.

    Only use this method if the authentication mode is Mode.staticPassword.

    Declaration

    Swift

    public func requestPasswordResetLink(queue: DispatchQueue? = nil, then completionCallback: WebcomResult<Void>.Callback? = nil)

    Parameters

    queue

    The queue to which the provided callback dispatches. When nil, the default callback queue of the application of this instance is used.

    completionCallback

    The closure to call upon completion. In case of success, it is called with a void value. In case of failure, it is called with a WebcomError value indicating the reason of the failure.

  • Updates the password of the user.

    This method may only by used:

    After using this method, you may safely continue the authentication process using the AuthenticationService.continueAuthentication(queue:then:) method.

    Declaration

    Swift

    public func updatePassword(to newPassword: String, queue: DispatchQueue? = nil, then completionCallback: WebcomResult<Void>.Callback? = nil)

    Parameters

    newPassword

    The new password of the user.

    queue

    The queue to which the provided callback dispatches. When nil, the default callback queue of the application of this instance is used.

    completionCallback

    The closure to call upon completion. In case of success, it is called with a void value. In case of failure, it is called with a WebcomError value indicating the reason of the failure.

  • Attach a new identity to the current user.

    This method is to be used only for sign-up.

    To sign-in, use the setVerificationOneTimePassword(_:) method when the authentication mode is Mode.oneTimePassword or directly the AuthenticationService.continueAuthentication(queue:then:) method when the authentication mode is Mode.staticPassword.

    Declaration

    Swift

    public func attachIdentity(queue: DispatchQueue? = nil, then completionCallback: WebcomResult<Void>.Callback? = nil)

    Parameters

    queue

    The queue to which the provided callback dispatches. When nil, the default callback queue of the application of this instance is used.

    completionCallback

    The closure to call upon completion. In case of success, it is called with a void value. In case of failure, it is called with a WebcomError value indicating the reason of the failure.

  • Requests the verification token again.

    The verification token was normally sent to the user at sign-up. This method may be used to send it again, if the user has not received it or if he/she has lost it. Only use this method if the authentication mode is Mode.staticPassword.

    Declaration

    Swift

    public func requestVerificationTokenAgain(queue: DispatchQueue? = nil, then completionCallback: WebcomResult<Void>.Callback? = nil)

    Parameters

    queue

    The queue to which the provided callback dispatches. When nil, the default callback queue of the application of this instance is used.

    completionCallback

    The closure to call upon completion. In case of success, it is called with a void value. In case of failure, it is called with a WebcomError value indicating the reason of the failure.

  • Sets the verification token sent by the provider for sign-up.

    Only use this method if the authentication mode is Mode.staticPassword. When authentication mode is Mode.oneTimePassword, use the setVerificationOneTimePassword(_:) method instead.

    Declaration

    Swift

    @discardableResult
    public func setVerificationToken(_ token: String) -> WebcomResult<Void>

    Parameters

    token

    The verification token.

    Return Value

    A WebcomResult with a void value in case of success or a WebcomError value in case of the failure.

  • Sets the verification one-time password sent by the provider for sign-up.

    Only use this method if the authentication mode is Mode.oneTimePassword. When authentication mode is Mode.staticPassword, use the setVerificationToken(_:) method instead.

    Declaration

    Swift

    @discardableResult
    public func setVerificationOneTimePassword(_ password: String) -> WebcomResult<Void>

    Parameters

    password

    The verification one-time password.

    Return Value

    A WebcomResult with a void value in case of success or a WebcomError value in case of the failure.

  • Requests the provider to send a one-time password for sign-in.

    For sign-up, use the attachIdentity(queue:then:) method instead.

    For security reasons, this method succeeds when the user has not yet signed-up, but it does nothing in this case.

    Declaration

    Swift

    public func requestOneTimePassword(queue: DispatchQueue? = nil, then completionCallback: WebcomResult<Void>.Callback? = nil)

    Parameters

    queue

    The queue to which the provided callback dispatches. When nil, the default callback queue of the application of this instance is used.

    completionCallback

    The closure to call upon completion. In case of success, it is called with a void value. In case of failure, it is called with a WebcomError value indicating the reason of the failure.

  • Sets the one-time password sent by the provider for sign-in.

    Only use this method when the authentication mode is Mode.oneTimePassword and for sign-in. To set the one-time password for sign-up, use the setVerificationOneTimePassword(_:) method instead. To set the static password for sign-up, use the setStaticPassword(_:) method instead.

    Declaration

    Swift

    @discardableResult
    public func setOneTimePassword(_ password: String) -> WebcomResult<Void>

    Parameters

    password

    The sign-in one-time password.

    Return Value

    A WebcomResult with a void value in case of success or a WebcomError value in case of the failure.

  • Processed an operation on the user profile.

    Important: This method does not trigger any authentication event. The updated profile will only be available the next time the same user will sign in. The user profile is not designed to store business applicative data about the user. For that purpose, use the DatasyncService.

    Declaration

    Swift

    public func processProfileOperation(_ operation: ProfileOperation, queue: DispatchQueue? = nil, then completionCallback: WebcomResult<Void>.Callback? = nil)

    Parameters

    operation

    The operation to process.

    queue

    The queue to which the provided callback dispatches. When nil, the default callback queue of the application of this instance is used.

    completionCallback

    The closure to call upon completion. In case of success, it is called with a void value. In case of failure, it is called with a WebcomError value indicating the reason of the failure.

CustomDebugStringConvertible Protocol

  • Declaration

    Swift

    public var debugDescription: String { get }

Combine Module

  • The type that wraps AuthenticationMethodInternal in order to enrich it with a Combine-based API.

    See also the documentation section of WebcomWrapper for the corresponding wrapped type.

    To use this type, import the following dependency in your code:

    import WebcomCombine
    
    See more

    Declaration

    Swift

    public final class CombineWrapper : WebcomWrapper, CustomDebugStringConvertible
  • The wrapping instance, which has a Combine-based API.

    Declaration

    Swift

    public var forCombine: CombineWrapper { get }