Android SDK Authentication

SDK authentication is the process of verifying the identity of the SDK that is used to communicate with an external service or platform. In the case of WebEngage, authentication is required to ensure that your application is authorized to access the WebEngage API and interact with the platform.

Prerequisite

Authenticate

You can generate a JWT token as part of your application. The WebEngage SDK will append the current user’s last known JWT to network requests made to WebEngage API. The JWT will be included in the Authorization header of each API request as a bearer token.

WebEngage.get().setSecurityToken(cuid,token);
WebEngage.get().setSecurityToken(cuid,token);

Callbacks

For listening to any errors in the Authentication process, you will have to implement the onSecurityException method of the WESecurityCallback interface. After implementing this, you will receive the error map in the onSecurityException. You can regenerate your JWT token if required and set it again in this method

class WebEngageManager implements WESecurityCallback{
  
  @Override
  public void onSecurityException(Map<String, Object> errorDetails) {
    //callback implementation
    Log.e(TAG, "errorDetails " + errorDetails.get("error"));
    Log.e(TAG, "errorCode " + errorDetails.get("status"));
  }
}
class WebEngageManager : WESecurityCallback {
	override fun onSecurityException(errorDetails: MutableMap<String, Any>) {
		Log.e("TAG", "errorDetails ${errorDetails["error"]}")
		Log.e("TAG", "errorDetails ${errorDetails["status"]}")
	}
}
keydescriptionsample value
errorError map with details for the failure.{response={message=Invalid JWT token passed, status=UID_MISMATCH}}
statusError code the network request.401