NWLoginBuilder

public class NWLoginBuilder

The class capable of building Login Flows

  • Building is always possible via a build call, provided that all the parameters which a Login Flow should know are provided before the build call is done
  • It can be provided a parameter via a set call
  • When a partcular Login flow is built, if one or more parameters are missing the build throw an exception
  • If a build is successful you can create even more copies of the same login flow, and everyone of them will be ready to be started, even if the builder object dies and is recycled from the memory
  • Precondition

    user is not already logged and there aren’t any current running Login Flow at the moment

    Example 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) -> 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.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 made

      Warning

      The User must be not already logged in

      Throws

      LoginBuilderError if LoginFlow requirements are not met

      Precondition

      the customId has been set

      Declaration

      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.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 made

      Warning

      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 MSISDN number

      Attention

      International prefix (like +39) must be passed

      Declaration

      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.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 made

      Warning

      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.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 made

      Warning

      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.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 made

      Warning

      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.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 made

      Warning

      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.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 made

      Warning

      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