NWLoginBuilder
public class NWLoginBuilder
The class capable of building Login Flows
Precondition
user is not already logged and there aren’t any current running Login Flow at the momentExample of usage:
do {
let builder = try Newton.getSharedInstance()
.getLoginBuilder()
.setCustomData(cData: NWSimpleObject(fromDictionary: ["aString": "aValue"])!)
.setOnFlowCompleteCallback { error in
DispatchQueue.main.async { () -> Void in
if let error = error {
print("Login Flow completed with Error: \(error)")
} else {
print("Login Flow went well")
}
}
}
let oAuthFlow = try builder.getOAuthLoginFlow()
oAuthFlow.startLoginFlow()
} catch NWError.NewtonNotInitialized(let reason) {
print("Newton not initialized: \(reason)")
} catch NWError.NewtonError(code: NWError.LoginBuilderError, message: let reason, statusCode: _, error: _, extra: _) {
print("Login builder Error: \(reason)")
} catch {
print("Unknown Error: \(error)")
}
-
Set the global callback to be informed when the login flow built has finished
Declaration
Swift
public func setOnFlowCompleteCallback(callback: @escaping FlowCompleteCallback) -> NWLoginBuilder
Parameters
callback
FlowCompleteCallback callback
Return Value
the Builder itself for chaining purposes
-
Set the custom data to be sent along with the Login identify event if everything works fine
Declaration
Swift
public func setCustomData(cData: NWSimpleObject) -> NWLoginBuilder
Parameters
cData
the SimpleObject carried
Return Value
the Builder itself for chaining purposes
-
Dummy Method only for Frameworks alignments
Declaration
Swift
public func setAllowCustomLoginSession() -> NWLoginBuilder
-
set the Custom Identifier of the legacy user
Declaration
Swift
public func setCustomID(customId: String) -> NWLoginBuilder
Parameters
customId
a String representing the unique identifier
Return Value
the Builder itself for chaining purposes
-
build a NWCustomLoginFlow
Example of Custom Login flow creation:
do { let builder = try Newton.getSharedInstance() .getLoginBuilder() .setCustomID(customId: "523761678216") } catch NWError.NewtonNotInitialized(let reason) { print("Newton not initialized: \(reason)") } catch NWError.NewtonError(code: NWError.LoginBuilderError, message: let reason, statusCode: _, error: _, extra: _) { print("Login builder Error: \(reason)") } catch { print("Unknown Error: \(error)") }
Warning
A check if there aren’t any other login flow in progress is madeWarning
The User must be not already logged inThrows
LoginBuilderError if LoginFlow requirements are not metPrecondition
the customId has been setDeclaration
Swift
public func getCustomLoginFlow() throws -> NWCustomLoginFlow
Return Value
the NWCustomLoginFlow object built
-
Set the OAuth provider involved in the LoginFlow
Declaration
Swift
public func setOAuthProvider(provider: OAuthProvider) -> NWLoginBuilder
Parameters
provider
the OAuthProvider object
Return Value
the Builder itself for chaining purposes
-
Manually set the OAuth Access Token In case the Client Access Token is already known, this method is used to create a Login Flow wich does not perform user interaction
Warning
This must be used in exclusion with the setOAuthClientId
Declaration
Swift
public func setAccessToken(token: String) -> NWLoginBuilder
Parameters
token
the Sting representation of the token
Return Value
the Builder itself for chaining purposes
-
Set the OAuth Client identifier to perform the OAuth v.2 authentication
Declaration
Swift
public func setOAuthClientID(clientId: String) -> NWLoginBuilder
Parameters
clientId
the String representation of the application on the provider
Return Value
the Builder itself for chaining purposes
-
Dummy Method only for Frameworks alignments
Declaration
Swift
public func setReturnUrl(url: String) -> NWLoginBuilder
Parameters
url
an unused Url
Return Value
the Builder itself for chaining purposes
-
Dummy Method only for Frameworks alignments
Declaration
Swift
public func setWaitingUrl(url: String) -> NWLoginBuilder
Parameters
url
an unused Url
Return Value
the Builder itself for chaining purposes
-
Dummy Method only for Frameworks alignments
Declaration
Swift
public func setErrorUrl(url: String) -> NWLoginBuilder
Parameters
url
an unused Url
Return Value
the Builder itself for chaining purposes
-
Build an OAuthLoginFlow object
Example of OAuth Login flow with Facebook:
do { let builder = try Newton.getSharedInstance() .getLoginBuilder() .setOAuthProvider(provider: OAuthProvider(provider: .Facebook)) .setAccessToken(token: "aToken") let flow = try getOAuthLoginFlow() } catch NWError.NewtonNotInitialized(let reason) { print("Newton not initialized: \(reason)") } catch NWError.NewtonError(code: NWError.LoginBuilderError, message: let reason, statusCode: _, error: _, extra: _) { print("Login builder Error: \(reason)") } catch { print("Unknown Error: \(error)") }
Warning
A check if there aren’t any other login flow in progress is madeWarning
The User must be not already logged in
Throws
LoginBuilderError if LoginFlow requirements are not met
Precondition
the OAuth ClientID or AccessToken has been set and the OAuth provider too
Declaration
Swift
public func getOAuthLoginFlow() throws -> NWOAuthLoginFlow
Return Value
the NWOAuthLoginFlow object built
-
// Set the email address
Declaration
Swift
public func setEmail(email: String) -> NWLoginBuilder
Parameters
email
the String of the email address
Return Value
the Builder itself for chaining purposes
-
// Set the password
Declaration
Swift
public func setPassword(password: String) -> NWLoginBuilder
Parameters
password
the password String (at least 1 character)
Return Value
the Builder itself for chaining purposes
-
// Set the product email params. This could be needed by the mail sender to have a customization of some of the parameter
Declaration
Swift
public func setProductEmailParams(params: NWSimpleObject) -> NWLoginBuilder
Parameters
params
NWSimpleObject
Return Value
the Builder itself for chaining purposes
-
// Set the user properties. the bucket of user properties to be attached to the user as soon as it will be signed up
Declaration
Swift
public func setUserProperties(userProperties: NWSimpleObject) -> NWLoginBuilder
Parameters
userProperties
NWSimpleObject
Return Value
the Builder itself for chaining purposes
-
Build an Email Password Login Flow object
Example of Email Password Login flow:
do { let builder = try Newton.getSharedInstance() .getLoginBuilder() .setEmail(email: "pippo@gmail.com") .setPassword(pin: "1234") let flow = try getEmailLoginFlow() } catch NWError.NewtonNotInitialized(let reason) { print("Newton not initialized: \(reason)") } catch NWError.NewtonError(code: NWError.LoginBuilderError, message: let reason, statusCode: _, error: _, extra: _) { print("Login builder Error: \(reason)") } catch { print("Unknown Error: \(error)") }
Warning
A check if there aren’t any other login flow in progress is madeWarning
The User must be not already logged in
Throws
LoginBuilderError if LoginFlow requirements are not met
Precondition
the EMAIL and Password have been set
Declaration
Swift
public func getEmailLoginFlow() throws -> NWEmailPasswordLoginFlow
Return Value
the EmailLoginFlow object built
-
Build an Email Forgot Flow object
Example of Email Forgot Login flow:
do { let builder = try Newton.getSharedInstance() .getLoginBuilder() .setEmail(email: "pippo@gmail.com") let flow = try getEmailForgotFlow() } catch NWError.NewtonNotInitialized(let reason) { print("Newton not initialized: \(reason)") } catch NWError.NewtonError(code: NWError.LoginBuilderError, message: let reason, statusCode: _, error: _, extra: _) { print("Login builder Error: \(reason)") } catch { print("Unknown Error: \(error)") }
Warning
A check if there aren’t any other login flow in progress is madeWarning
The User must be not already logged in
Throws
LoginBuilderError if LoginFlow requirements are not met
Precondition
the EMAIL have been set
Declaration
Swift
public func getEmailForgotFlow() throws -> NWEmailForgotFlow
Return Value
the ForgotPasswordLoginFlow object built
-
Build an Email Resend Flow object
Example of Email Resend Login flow:
do { let builder = try Newton.getSharedInstance() .getLoginBuilder() .setEmail(email: "pippo@gmail.com") let flow = try getEmailResendFlow() } catch NWError.NewtonNotInitialized(let reason) { print("Newton not initialized: \(reason)") } catch NWError.NewtonError(code: NWError.LoginBuilderError, message: let reason, statusCode: _, error: _, extra: _) { print("Login builder Error: \(reason)") } catch { print("Unknown Error: \(error)") }
Warning
A check if there aren’t any other login flow in progress is madeWarning
The User must be not already logged in
Throws
LoginBuilderError if LoginFlow requirements are not met
Precondition
the EMAIL have been set
Declaration
Swift
public func getEmailResendFlow() throws -> NWEmailResendFlow
Return Value
the ForgotPasswordLoginFlow object built
-
Build an Email Signup Flow object
Example of Email Signup flow:
do { let builder = try Newton.getSharedInstance() .getLoginBuilder() .setEmail(email: "pippo@gmail.com") .setPassword(password: "123456") let flow = try getEmailSignupFlow() } catch NWError.NewtonNotInitialized(let reason) { print("Newton not initialized: \(reason)") } catch NWError.NewtonError(code: NWError.LoginBuilderError, message: let reason, statusCode: _, error: _, extra: _) { print("Login builder Error: \(reason)") } catch { print("Unknown Error: \(error)") }
Warning
A check if there aren’t any other login flow in progress is madeWarning
The User must be not already logged in
Throws
LoginBuilderError if LoginFlow requirements are not met
Precondition
the EMAIL have been set
Precondition
the PASSWORD have been set
Declaration
Swift
public func getEmailSignupFlow() throws -> NWEmailSignupLoginFlow
Return Value
the ForgotPasswordLoginFlow object built
-
Set the MSISDN number
Attention
International prefix (like
+39
) must be passedDeclaration
Swift
public func setMSISDN(msisdn: String) -> NWLoginBuilder
Parameters
msisdn
the String of the MSISDN number
Return Value
the Builder itself for chaining purposes
-
Set the PIN provided at subscription time
Declaration
Swift
public func setPIN(pin: String) -> NWLoginBuilder
Parameters
pin
The String of the PIN
Return Value
the Builder itself for chaining purposes
-
Build an MSISDNPINLoginFlow object
Example of MSISDN Login flow with PIN creation:
do { let builder = try Newton.getSharedInstance() .getLoginBuilder() .setMSISDN(msisdn: "+39333123156") .setPIN(pin: "1234") let flow = try getMSISDPINLoginFlow() } catch NWError.NewtonNotInitialized(let reason) { print("Newton not initialized: \(reason)") } catch NWError.NewtonError(code: NWError.LoginBuilderError, message: let reason, statusCode: _, error: _, extra: _) { print("Login builder Error: \(reason)") } catch { print("Unknown Error: \(error)") }
Warning
A check if there aren’t any other login flow in progress is madeWarning
The User must be not already logged in
Throws
LoginBuilderError if LoginFlow requirements are not met
Precondition
the MSISDN and the PIN have been set
Declaration
Swift
public func getMSISDPINLoginFlow() throws -> NWMSISDNPINLoginFlow
Return Value
the MSISDNPINLoginFlow object built
-
Build a MSISDN User’s number recogntion login flow
Example of MSISDN Login flow with User Number Recognition creation:
do { let builder = try Newton.getSharedInstance() .getLoginBuilder() let flow = try getMSISDNURLoginFlow() } catch NWError.NewtonNotInitialized(let reason) { print("Newton not initialized: \(reason)") } catch NWError.NewtonError(code: NWError.LoginBuilderError, message: let reason, statusCode: _, error: _, extra: _) { print("Login builder Error: \(reason)") } catch { print("Unknown Error: \(error)") }
Warning
A check if there aren’t any other login flow in progress is madeWarning
The User must be not already logged in
Throws
LoginBuilderError if LoginFlow requirements are not met
Declaration
Swift
public func getMSISDNURLoginFlow() throws -> NWMSISDNUserRecognitionLoginFlow
Return Value
the NWMSISDNUserRecognitionLoginFlow object built
-
Set the External unique identifier of the User
Declaration
Swift
public func setExternalID(externalId: String) -> NWLoginBuilder
Parameters
externalId
the String of the external identifier
Return Value
the NWLoginBuilder object
-
Build an External login flow
Example of External Login flow creation:
do { let builder = try Newton.getSharedInstance() .setExternalID(externalId: "GAIA_UNIQUE_ID") .getLoginBuilder() let flow = try getExternalLoginFlow() } catch NWError.NewtonNotInitialized(let reason) { print("Newton not initialized: \(reason)") } catch NWError.NewtonError(code: NWError.LoginBuilderError, message: let reason, statusCode: _, error: _, extra: _) { print("Login builder Error: \(reason)") } catch { print("Unknown Error: \(error)") }
Warning
A check if there aren’t any other login flow in progress is madeWarning
The User must be not already logged in
Throws
LoginBuilderError if LoginFlow requirements are not met
Precondition
the ExternalId has been set
Declaration
Swift
public func getExternalLoginFlow() throws -> NWExternalLoginFlow
Return Value
the NWExternalLoginFlow object built
-
Set the unique identifier of the Offer
Declaration
Swift
public func setOfferId(offerId: String) -> NWLoginBuilder
Parameters
offerId
the Offer unique identifier
Return Value
the NWLoginBuilder object
-
Build a Payment Receipt login flow
Example of Payment Receipt Login flow creation:
do { let builder = try Newton.getSharedInstance() .setOfferId(offerId: "E621E1F8C36C495A93FC0C247A3E6E5F") .getLoginBuilder() let flow = try getPaymentReceiptLoginFlow() } catch NWError.NewtonNotInitialized(let reason) { print("Newton not initialized: \(reason)") } catch NWError.NewtonError(code: NWError.LoginBuilderError, message: let reason, statusCode: _, error: _, extra: _) { print("Login builder Error: \(reason)") } catch { print("Unknown Error: \(error)") }
Warning
A check if there aren’t any other login flow in progress is madeWarning
The User must be not already logged in
Throws
LoginBuilderError if LoginFlow requirements are not met
Precondition
the Offer Id has been set
Declaration
Swift
public func getPaymentReceiptLoginFlow() throws -> NWPaymentReceiptLoginFlow
Return Value
the NWPaymentReceiptLoginFlow object built
-
Set the Pony String retrieved from Mobile Fingerprint
Declaration
Swift
public func setPony(pony: String) -> NWLoginBuilder
Parameters
pony
the JSON encoding of a string
Return Value
the NWLoginBuilder object
-
Build a Mobile Fingerprint login flow
Example of Mobile Fingerprint Login flow creation:
do { let builder = try Newton.getSharedInstance() .setPony(pony: "{\"user_id\": \"C_hdusihd238dbc\", \"session_id\": \"8as978s9acys9cyas9cys\"}") .getLoginBuilder() let flow = try getMFPLoginFlow() } catch NWError.NewtonNotInitialized(let reason) { print("Newton not initialized: \(reason)") } catch NWError.NewtonError(code: NWError.LoginBuilderError, message: let reason, statusCode: _, error: _, extra: _) { print("Login builder Error: \(reason)") } catch { print("Unknown Error: \(error)") }
Warning
A check if there aren’t any other login flow in progress is madeWarning
The User must be not already logged in
Throws
LoginBuilderError if LoginFlow requirements are not met
Precondition
the Pony has been explicitly set
Declaration
Swift
public func getMFPLoginFlow() throws -> NWMFPLoginFlow
Return Value
the NWMFPLoginFlow object built