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 ... }
}
-
A value representing the authentication mode.
The default authentication mode for:
AuthenticationProvider.InternalFamily.eMail
is.staticPassword
,AuthenticationProvider.InternalFamily.phone
is.oneTimePassword
.
Declaration
Swift
public enum Mode : Equatable
-
A value representing an operation on the user profile.
See moreDeclaration
Swift
public enum ProfileOperation
-
The provider.
Declaration
Swift
public let internalProvider: AuthenticationProvider.InternalFamily
-
The authentication mode.
Declaration
Swift
public let mode: Mode
-
The sender to be used by the
AuthenticationProvider.InternalFamily.phone
provider. Whennil
, the default sender, defined on the back-end, is used. This parameter is only meaningful wheninternalProvider
isAuthenticationProvider.InternalFamily.phone
. Otherwise, this value is ignored.Declaration
Swift
public let sender: String?
-
The unique identifier of the user for the provider.
Declaration
Swift
public private(set) var identifier: String? { get }
-
The profile of the user.
This property is used by the
attachIdentity(queue:then:)
method.It is not designed to store business applicative data about the user. For that purpose, use the
DatasyncService
.Declaration
Swift
public var profile: [String : Any]
-
The display name of the user.
This property is used by the
attachIdentity(queue:then:)
method.Declaration
Swift
public var displayName: String?
-
The locale used for verification and one-time password messages sent to the user.
It must be in the
ll-CC
format, wherell
is the ISO 639 alpha-2 code for the language andCC
is the ISO 3166 alpha-2 code for the country variant.Example:
en-US
When
nil
, the preferred locale of the user contained in the main bundle is used.This property is used by the
requestPasswordResetLink(queue:then:)
,attachIdentity(queue:then:)
andrequestOneTimePassword(queue:then:)
methods.Declaration
Swift
public var messageLocale: String?
-
The identifier of the template, as defined on the developer console, to use for the password reset message.
This property is used by the
requestPasswordResetLink(queue:then:)
method.Declaration
Swift
public var passwordResetMessageTemplate: String?
-
The identifier of the template, as defined on the developer console, to use for the verification message.
This property is used by the
attachIdentity(queue:then:)
method.Declaration
Swift
public var verificationMessageTemplate: String?
-
The identifier of the template, as defined on the developer console, to use for the one-time password message.
This property is used by the
requestOneTimePassword(queue:then:)
method.Declaration
Swift
public var oneTimePasswordMessageTemplate: String?
-
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, theinit(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 theprovider
.sender
The sender to be used by the
AuthenticationProvider.InternalFamily.phone
provider. This parameter is only meaningful when theprovider
parameter isAuthenticationProvider.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 theAuthenticationProvider.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 theAuthenticationProvider.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.
-
Declaration
Swift
public var provider: AuthenticationProvider { get }
-
Declaration
Swift
public func initializeAuthentication(_: WebcomMarkers.Restricted, for service: AuthenticationService) -> WebcomResult<Void>
-
Declaration
Swift
public func authenticate(_: WebcomMarkers.Restricted, then completionCallback: @escaping WebcomResult<AuthenticationDetails>.Callback)
-
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 aWebcomError
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 aWebcomError
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:
- if the authentication mode is
Mode.staticPassword
, - and the
setStaticPassword(_:)
method has been called before.
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. - if the authentication mode is
-
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 isMode.oneTimePassword
or directly theAuthenticationService.continueAuthentication(queue:then:)
method when the authentication mode isMode.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 isMode.oneTimePassword
, use thesetVerificationOneTimePassword(_:)
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 aWebcomError
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 isMode.staticPassword
, use thesetVerificationToken(_:)
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 aWebcomError
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 thesetVerificationOneTimePassword(_:)
method instead. To set the static password for sign-up, use thesetStaticPassword(_:)
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 aWebcomError
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.
-
Declaration
Swift
public var debugDescription: String { get }
-
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:
See moreimport WebcomCombine
Declaration
Swift
public final class CombineWrapper : WebcomWrapper, CustomDebugStringConvertible
-
The wrapping instance, which has a Combine-based API.
Declaration
Swift
public var forCombine: CombineWrapper { get }