User Authentication
Set an ASAPPUser with a Request Context Provider
As in the Quick Start section, you can connect to chat as an anonymous user by specifying a nil user identifier when initializing an ASAPPUser
. However, many use cases might require ASAPP to know the identity of the customer.
To connect as an identified user, please specify a user identifier string and a request context provider function. This provider will be called from a background thread when the SDK makes requests that require customer authentication with your company’s servers. The request context provider is a function that returns a dictionary with keys and values agreed upon with ASAPP. Please ask your Implementation Manager if you have questions.
Example:
Handle Login Buttons
If a customer connects to chat anonymously, they may be asked to log in when necessary by being shown a message button:
If the customer then taps on the Sign In button, the SDK will call a delegate method: chatViewControllerDidTapUserLoginButton()
. Please implement this method and set ASAPP.user
once the customer has logged in. The SDK will detect the change and then authenticate the user. You may set ASAPP.user
in any thread. Make sure to set the delegate as well: for example, ASAPP.delegate = self
. See ASAPPDelegate
for more details.
Token Expiration and Refresh the Context
In the event that the provided token has expired, the SDK will call the request context provider with an argument that is true, indicating that you must refresh the context. In that case, please make sure to return a dictionary with fresh credentials that the SDK can use to authenticate the user. If the SDK requires an API call to refresh the credentials, please make sure to block the calling thread until you can return the updated context.
Was this page helpful?