Authentication (iOS)

Initialization

Calls to the SDK mainly go through the ReachFive class, to start using it add the following import:

import R5SDK

Initialize the SDK by calling the ReachFive.initWith method with the following parameters:

  • domain (required): the domain dedicated to the client, this parameter will be used by the SDK to establish calls to the APIs

  • provider (optional): Array<R5ProviderData> - allows to pass the different providers configuration (Facebook, Google, Twitter…) directly to the SDK. If this parameter is omitted then this configuration is retrieved by a call to the ReachFive backend.

  • onInitFinishCallback: R5InitFinishedCallback callback when initialization is complete

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

    let callback :R5InitFinishedCallback = { providers, error in
        if let err = error {
            NSLog(">> onLoginWithProvider callback, SIM Native SDK Init Error \n \(String(describing: err.message))");
        } else {
            NSLog(">> onLoginWithProvider: SDK Initialized, providers = \(String(describing: providers))");
        }
    }

    ReachFive.initWith(domain: "YOUR_DOMAIN", clientId: "YOUR_CLIENT_ID", provider: nil, onInitFinishCallback: callback)

    return true
}

func applicationDidBecomeActive(_ application: UIApplication) {
    ReachFive.didBecomeActive()
}


func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
    return ReachFive.application(app, open: url, sourceApplication: options[UIApplicationOpenURLOptionsKey.sourceApplication] as! String, annotation: options[UIApplicationOpenURLOptionsKey.annotation])
}

func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
    return ReachFive.application(application, open: url, sourceApplication: sourceApplication, annotation: annotation)
}

Login process

Before calling the login you have to define a callback to process the response:

let callback :R5LoginViewControlleCallback = { response, error in
    if let userInfo = rsp.userInfo {

        // handle successfull response

    } else {

        // handle error

    }
}

The login process can be triggered:

  • By invoking the login for a specific provider

    ReachFive.shared.loginWith(provider: .r5Google, origin: "homepage", onView: self, onLoginResponse: callback)

An optional origin parameter can be specified and allows to distinguish the screen at the origin of the connection (e.g. home or basket).

  • By invoking the login with a password request

    ReachFive.shared.newPasswordLoginRequest(userName: email, password: password, r5loginCallback: passwordCallback)

Signup process

Before calling the signup method, you must define a callback to process the response:

let signupCallback :R5SignupViewControlleCallback = { response, error in
  if let rsp = response {
      // Do something
            } else {
                if let err = error {
                    if let message = err.message {
                      // Display error message
                    }
                }
            }
        }
  • The signup process can be triggered:

    ReachFive.shared.newSignupRequest(email: email, password: password, isAutoLogin: false, r5SignupCallback: signupCallback)

Responses

R5LoginResponse

Field Type Description

accessToken

NSString

Access token

userinfo

R5UserInfo

Connected user data

R5Error

Field Type Description

code

NSString

Error Code

message

R5UserInfo

Error Message

Exceptions

Here are the different error categories in the application:

Configuration issues

These errors occur following a problem of configuration of the application or the platform.

  • FETCH_PROVIDERS_EMPTY_LIST_CODE, FETCH_PROVIDERS_WITHOUT_ITEMS_CODE, FETCH_PROVIDERS_NULL_OR_BADFORMAT_CODE: Platform configuration error

  • FACEBOOK_NATIVE_CONNECTION_UNAVAILABLE_CODE: Facebook SDK not available

  • GOOGLE_NATIVE_CONNECTION_UNAVAILABLE_CODE: Google SDK not available

ReachFive API call issues

These errors may occur when a call to ReachFive APIs fails. The user must be given the opportunity to try again later to reconnect.

  • FETCH_PROVIDERS_REQUEST_ERROR_CODE: Error when calling the Webservice to recover the configuration

  • WEBSERVICE_LOGIN_REQUEST_ERROR_CODE, WEBSERVICE_LOGIN_REPONSE_NULL_CODE: Error when calling the Webservice login

Provider issues

These errors are reported by the SDK. It can come as well from the failure of network calls as from unknown errors returned by the providers, Usually, it is necessary to give the user the possibility to try again later to reconnect.

  • FACEBOOK_NATIVE_CONNECTION_ERROR_CODE: An error occurred when connecting to Facebook

  • FACEBOOK_NATIVE_CONNECTION_EMPTY_ACCESS_TOKEN_CODE: Access token not returned by Facebook

  • GOOGLE_NATIVE_CONNECTION_ERROR_CODE: An error occurred when connecting to Google

  • GOOGLE_NATIVE_CONNECTION_EMPTY_ACCESS_TOKEN_CODE: Access token not returned by Google

  • WEBVIEW_ERROR_CODE: An error occurred when connecting to other providers

Connection request cancelled

Information sent when the user decides not to continue his connection process.

  • FACEBOOK_NATIVE_CONNECTION_CANCELLED_CODE: User has cancelled Facebook connection