Authentication

This guide will explain in-depth ChatCamp authentication workflow.

The authentication is the first step in the chat integration into your Javascript 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 Javascript application, you need to initialize ChatCamp with the APP_ID. This APP_ID can be copied from the ChatCamp Dashboard.

CCPClient.initApp(appId: APP_ID)

📘

Note: CCPClient.initApp should be called only once across the entire application. The application:didFinishLaunchingWithOptions: method in your application 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.

CCPClient.connect(uid: USER_ID) { user, error in
    if error == nil {
        //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 iOS 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 iOS application and then use it while connecting to ChatCamp.
CCPClient.connect(uid: USER_ID, accessToken: ACCESS_TOKEN) { user, error in
    if error == nil {
        //You are connected to ChatCamp backend now.
    }
}

Disconnecting from Chat

A user needs to disconnect from ChatCamp Cloud if they do not wish to receive chat related data. It can be used when the user is logging out of your app.

CCPClient.disconnect() { (error) in
	//You are disconnected to ChatCamp backend now.
}