Authenticating end users
Authentication
The Zendesk SDK supports authentication of end users to enable agents to verify their identity within Zendesk. Complete the steps in Authenticating users before beginning the steps below.
You can find a demo game demonstrating the capability of user authentication on the iOS App Store or Google Play Store.
LoginUser
To authenticate a user, call the LoginAsync
API with your own JWT
.
The JWT
can contain the following fields:
Name | Type | Mandatory | Comment |
---|---|---|---|
external_id | String | Yes | The external id of the user. Required. The maximum length is 255 characters |
name | String | No | The name of the user |
String | No | The email of the user | |
exp | Integer | No | Integer value of the expiry timestamp, in seconds |
C#
var loginResult = await ZendeskMessaging.Instance.LoginAsync("JWT");
if (loginResult.IsSuccess)
{
// ...
}
else
{
// ...
}
LogoutUser
To unauthenticate a user, call the Logout
API.
This function is intended mainly for authenticated users. However, calling Logout
for an unauthenticated user clears all associated data, including their conversation history. Note that this data cannot be recovered, so this action should be used only for testing purposes. When the unauthenticated user next accesses the conversation screen, a new user profile and conversation will be created.
C#
var logoutResult = ZendeskMessaging.Instance.Logout();
if (logoutResult.IsSuccess)
{
// ...
}
else
{
// ...
}
Authentication errors
The most common errors encountered are HTTP 401 unauthorized errors or expiration errors caused by using a JWT
with an expired timestamp. In this case, a new JWT
should be generated and a call made to LoginAsync
.
Authentication merges
When the LoginAsync
API identifies an anonymous user in the Zendesk SDK who already exists in Zendesk (for example, from previous activity on another device), the data from both the anonymous and existing user accounts will be merged. This allows a user to start a conversation anonymously and then log in seamlessly.
For single-conversation, once logged in, the user will see that their previous anonymous conversation has been combined with conversations from their logged-in account, allowing them to continue seamlessly as an authenticated user.
For multi-conversations, once logged in, the user will see that their previous anonymous conversations in the conversation list screen with conversations from their logged-in account, allowing them to continue seamlessly as an authenticated user.
Preventing unwanted authentication merges
If you are using authentication, it's important to authenticate your users prior to displaying the messaging screens. Delaying authentication may result in users engaging in anonymous conversations, complicating their ability to access prior conversations and potentially causing them to create new tickets for existing issues (duplicating tickets).
It is also important to verify that the JWT is not close to expiration when authenticating users before displaying the messaging screens. If the JWT expires while the user is interacting with a conversation, an error must be handled to reauthenticate the user.
For more information and code samples, see Authentication in the Zendesk mobile SDKs.