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.LoginBuilderError(let reason) {
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) -> NWLoginBuilderParameters
callbackFlowCompleteCallback 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) -> NWLoginBuilderParameters
cDatathe 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) -> NWLoginBuilderParameters
customIda 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.LoginBuilderError(let reason) { 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 -> NWCustomLoginFlowReturn Value
the NWCustomLoginFlow object built
-
Set the OAuth provider involved in the LoginFlow
Declaration
Swift
public func setOAuthProvider(provider: OAuthProvider) -> NWLoginBuilderParameters
providerthe 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) -> NWLoginBuilderParameters
tokenthe 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) -> NWLoginBuilderParameters
clientIdthe 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) -> NWLoginBuilderParameters
urlan unused Url
Return Value
the Builder itself for chaining purposes
-
Dummy Method only for Frameworks alignments
Declaration
Swift
public func setWaitingUrl(url: String) -> NWLoginBuilderParameters
urlan unused Url
Return Value
the Builder itself for chaining purposes
-
Dummy Method only for Frameworks alignments
Declaration
Swift
public func setErrorUrl(url: String) -> NWLoginBuilderParameters
urlan 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.LoginBuilderError(let reason) { 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 -> NWOAuthLoginFlowReturn Value
the NWOAuthLoginFlow object built
-
Set the MSISDN number
Attention
International prefix (like
+39
) must be passedDeclaration
Swift
public func setMSISDN(msisdn: String) -> NWLoginBuilderParameters
msisdnthe 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) -> NWLoginBuilderParameters
pinThe 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.LoginBuilderError(let reason) { 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 -> NWMSISDNPINLoginFlowReturn 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.LoginBuilderError(let reason) { 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 -> NWMSISDNUserRecognitionLoginFlowReturn Value
the NWMSISDNUserRecognitionLoginFlow object built
-
Set the External unique identifier of the User
Declaration
Swift
public func setExternalID(externalId: String) -> NWLoginBuilderParameters
externalIdthe String of the external identifier
Return Value
the MSISDNPINLoginFlow object built
-
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.LoginBuilderError(let reason) { 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 -> NWExternalLoginFlowReturn Value
the NWExternalLoginFlow object built
NWLoginBuilder Class Reference