ASAP for Mobile Platforms

Authenticating Users in the SDK

To access the tickets they submitted, end-users of your app must have an identity so that they can authenticate themselves as a user of the Zoho Desk portal. This authentication is made possible in Zoho Desk via the JSON Web Token (JWT). 

Zoho Desk supports two types of authentication: Anonymous and JWT.

  • Anonymous - In this type, end-users are considered guest users. They can only submit tickets, view posts in the user community, and chat with a customer support agent. They cannot view the tickets they submitted or actively participate in the user community.

  • JWT - In this type, end-users are considered authenticated users. In addition to the activities that guest users can perform, authenticated users can also view the tickets they submitted and actively participate in the user community (with rights to perform actions, such as following a topic, adding a topic, and adding a comment to existing posts).

For detailed information on how to configure JWT-based user authentication in the ASAP SDK, refer to this document

The following code snippet authenticates users in the SDK. 

if(!isUserLoggedIn) {
    MyApplication.deskInstance.setUserToken("userToken", new DeskCallback.DeskSetUserCallback() {
        @Override
        public void onUserSetSuccess() {
        }
        @Override
        public void onException(DeskException exception) {
        }
    });
} else{
    //User already signed into SDK
}
In the code snippet above: 
  • userToken is the encrypted unique information that identifies the user (email address, for example).
  • setUserToken is the function that inputs the user token of the user. 
  • callback is the DeskCallback.DeskSetUserCallback instance that will be called after userFetch is executed.

The setUserToken function must be executed only if a user has not signed into the SDK. Therefore, you must configure the ASAP add-on to first check if a user has signed in or not. To perform this check, use the following code. 

boolean isUserLoggedIn = MyApplication.deskInstance.isUserSignedIn();

If the value returned is true, it means the user is already signed in to the SDK. So, the setUserToken function need not be executed. 

Logging Users out from the SDK

To log a user out from the SDK, use the following method.

MyApplication.deskInstance.removeUser(new DeskCallback.DeskRemoveUserCallback() {
    @Override
    public void onUserRemoveSuccess() {
        //user removed from SDK.
    }

    @Override
    public void onException(DeskException exception) {
    }
});

After this method is called, the authenticated user is treated as an anonymous user.