Authentication

This guide will explain in-depth ChatCamp authentication workflow.

The authentication is the first step in the chat integration into your Android application. ChatCamp supports types of authentications: client-side and server-side. Both are discussed in detail below.

Initializing the App

To start using chat SDK into your Android application, you need to initialize ChatCamp with the APP_ID. This APP_ID can be copied from the ChatCamp Dashboard.

ChatCamp.init(this, APP_ID);

📘

Note: ChatCamp.init() should be called only once across the entire application. The OnCreate() function of your application's MainActivity is typically a good place to initialize.

Connecting with User ID

The easiest way to connect a user to chat is with the help of a user ID. If the user ID doesn't exist in ChatCamp database then a new user account is automatically created. This is purely a client side integration as there is no call to your server involved in this implementation. The user ID can be any unique string from your user database such as UID or username or email id.

ChatCamp.connect(USER_ID, new ChatCamp.ConnectListener() {
  @Override
  public void onConnected(User user, ChatCampException e) {
    if(e == null) {
    	//You are connected to ChatCamp backend now.
    }
  }
                        
 });

Connecting with Access Token

A more secure way is to create user via ChatCamp API with an access token. This access token would then be required while connecting to ChatCamp in Android application. This type of authentication requires server-side integration as well.

At a high level, there are three main steps in this authentication type:

  • Create a user with an access token via ChatCamp API. This implementation needs to be done on your server side.
  • Save the access token in your database.
  • Retrieve the access token from your server in your Android application and then use it while connecting to ChatCamp.
ChatCamp.connect(USER_ID, ACCESS_TOKEN, new ChatCamp.ConnectListener() {
  @Override
  public void onConnected(User user, ChatCampException e) {
    if(e == null) {
    	//You are connected to ChatCamp backend now.
    }
  }
                        
 });

📘

Note: You may restrict access to chat via access token only. This can be configured in our ChatCamp Dashboard.

Updating the User Display Name

You may change the display name of user in the chat by using updateUserDisplayName().

ChatCamp.updateUserDisplayName(USER_NAME, new ChatCamp.UserUpdateListener() {
  @Override
  public void onUpdated(User user, ChatCampException e) {
    if(e == null) {
	    //Display name has been updated.
    }
  }
});

Updating the User Avatar Picture

You may set the profile picture of the user by passing their avatar URL with the help of updateAvatarUrl() function.

ChatCamp.updateUserAvatarUrl(AVATAR_URL, new ChatCamp.UserUpdateListener() {
  @Override
  public void onUpdated(User user, ChatCampException e) {
    if(e == null) {
	    //Avatar Url has been updated.
    }
  }
});

Here AVATAR_URL should be a valid image URL.

Updating the User Profile Link

You may set the profile link of the user with the help of updateProfileUrl() function. The URL may point to a web page.

ChatCamp.updateUserProfileUrl(PROFILE_URL, new ChatCamp.UserUpdateListener() {
  @Override
  public void onUpdated(User user, ChatCampException e) {
    if(e == null) {
	    //Profile Url has been updated.
    }
  }
});

Here PROFILE_URL should be a valid URL.