User Authentication
As in the Quick Start section, you can connect to chat as an anonymous user by not setting a user, or initializing an ASAPPUser
with a null customer identifier. However, many chat use cases might require ASAPP to know the identity of the user.
To connect as an identified user, please specify a customer 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 map with keys and values agreed upon with ASAPP. Please ask your Implementation Manager if you have questions.
Example:
Handle Login Buttons
If you connect to chat anonymously, you may be asked to log in when necessary by being shown a message button:
If you then tap the Sign In button, the SDK will use the ASAPPUserLoginHandler
to call to the application. Due to the asynchronous nature of this flow, your application should use the activity lifecycle to provide a result to the SDK.
How to Implement the Sign In Flow
- Implement the
ASAPPUserLoginHandler
and start your application’sLoginActivity
, including the given request code. - If a user successfully signs into your application, update the user instance and then finish your
LoginActivity
withActivity.RESULT_OK
. - In case a user cancels the operation, finish your
LoginActivity
withActivity.RESULT_CANCELED
.
After your LoginActivity
finishes, the SDK will capture the result and resume the chat conversation.
Token Expiration and Refreshing the Context
If the provided token has expired, the SDK will call the ASAPPRequestContextProvider with an refreshContext
parameter set to true
indicating that the context must be refreshed. In that case, please make sure to return a map with fresh credentials that can be used to authenticate the user. In case an API call is required to refresh the credentials, make sure to block the calling thread until the updated context can be returned.
Was this page helpful?