Set the Identity
Setting the identity allows you to authorize the user.
Retrieve the configuration parameters
To connect your Sinch Chat client to your Sinch account, you need to set the following parameters in the MainActivity.kt
file:
Parameter | Description |
---|---|
project_id | Get your project ID from your Sinch Dashboard. |
client_id | Get your client ID from your Sinch Dashboard. |
region | Use either EU1 for Europe or US1 for the United States. |
config_id | Populate with "" if you do not have this value |
token_secret | Optional |
Setting the identity
Next, you must actually authorize the user. To do that, call this method as early as possible to authorize the user:
fun setIdentity(config: SinchConfig, identity: SinchIdentity, completion: (Result<Unit>) -> Unit)
You can call this method as many times as you want. Depending on your needs, you can place the method in the MainActivity.kt
file or another file which will be run early in the application lifecycle.
For example:
val currentIdentity = SinchIdentity.SelfSigned({your_user_id}, {signed token})
val currentEnvironment = SinchConfig({client_id}, {project_id}, {config_id}, {region}, {language})
SinchChatSDK.setIdentity(
currentEnvironment,
currentIdentityType
) {
if (it.isSuccess) {
Toast.makeText(this, "Set Identity success", Toast.LENGTH_LONG).show()
Log.d(TAG, "Set Identity success")
} else {
Toast.makeText(this, "Set Identity failed", Toast.LENGTH_LONG).show()
Log.d(TAG, "Set Identity failed with message: ${it.exceptionOrNull()?.message}")
}
}
Generating a signed token
Sinch must recognize your users somehow, and the most secure way to authenticate is with a signed token.
Warning:
It is NOT recommended to sign user_id on mobile app. You should implement this algorithm and serve it from your backend infrastructure via API interface to prevent any kind of attacks.
Write to us if you want to know algorithm how we're signing user_id.
Now you can use SDK functionalities like chat or push. The next step is displaying the chat app.