Authentication
To use Channelize.io JavaScript SDK, user authentication with Channelize.io server is required which will return the access token in response. This access token would be used in the header of Application API calls.
Steps for Authentication
Follow the below steps for user authentication using JavaScript SDK:
Log in to Channelize.io using our login API call or the login methods of our SDK. This login function will provide you access token in response.
Save the User ID and the issued access token to your securely managed persistent storage.
When the user tries to log in to your application, you have to load the user ID and access token from the storage, and then pass them to the
channelize.connect()
method.You have to initialize the Javascript SDK before connecting, by passing Public Key.
NOTE: We save logged-in user object and access token in local storage so that we don’t have to verify access token at every time connect method is called.
Login
Channelize.io server provides two login options.
Login With UserID
This login method is useful for any of the below use-cases:
- Channelize.io real-time messaging is an integration inside your main application and you wants the user to auto-login to the messaging interface with the login in main Application.
- If the email address or password is not mandatory to login into your main application.
- If you do not want to save the user's email and password on your Channelize.io server.
You just need to pass userId and pmClientServerToken in channelize.loginWithUserId()
method.
channelize.loginWithUserId(userId, pmClientServerToken, function (err, res) {
});
Function Params
This table lists all possible parameters this function supports.
Name | Type | Description |
---|---|---|
userId | String | The unique ID of the user. |
pmClientServerToken | String | Specifies the token for specific user stored in your application. |
pmClientServerToken is loginToken which is generated by your main application server when the user login into your application and saves this along with the userId. This token is verified by the Channelize.io server using the login token callback URL which is configured in the Channelize.io Dashboard under App Settings > Security. This token ensures that only authenticated users can login to the Channelize.io server.
The client access token URL is POST API call which is developed at your end which will verify pmClientServerToken at your end, delete the token and respond with 200 status code.
Callback Params
err
Indicates if there is an error. It will be null if there is no error.res
Indicates the response having access token and login user objects.
Response Object Keys
id
Indicates the accessToken.user
Indicates the login user's object. You can run various methods on this object. These methods are listed and explained in the user's section.
Login With Email And Password
Use this login method to build Standalone chat applications where email & password are mandatory for users to login. You just need to pass email and password in channelize.loginWithEmailPassword()
method.
channelize.loginWithEmailPassword(email, password, function (err, res) {
});
Function Params
This table lists all possible parameters this function supports.
Name | Type | Description |
---|---|---|
String | The unique email address of the user. | |
password | String | The login password of the user. |
Callback Params
err
Indicates if there is an error. It will be null if there is no error.res
Indicates the response having access token and login user objects.
Response Object Keys
id
Indicates the accessToken.user
Indicates the login user's object. You can run various methods on this object. A list of these methods will be explained in the user's section.
Connect
To establish a connection with the Channelize.io server you need to pass UserID & Access Token to Channelize.connect()
method. Once the connection is established, you will be able to call SDK’s methods and register event callbacks without any error.
var channelize = new Channelize.client({publicKey: YOUR_PUBLIC_KEY});
channelize.connect(userId, accessToken, function (err, res) {
});
Function Params
This table lists all possible parameters this function supports.
Name | Type | Description |
---|---|---|
userId | String | The unique ID of the user. |
accessToken | String | The accessToken of the user. |
Callback Params
err
Indicates if there is any error. It will be null if there is no error.res
Indicates the response of the connect function and will be true if the connection is established successfully.
Disconnect
Disconnect the user from the Channelize.io server by simply passing the deviceID to the Channelize.disconnect()
method. Post disconnection, you will not be able to call SDK’s methods and will not receive event callbacks from the Channelize.io server.
deviceId
is registered when you register push notification token by using push notification token API call. It is unique for every mobile device as well as a web browser.
channelize.disconnect(deviceId, function (err, res) {
});
Function Params
This table lists all possible parameters this function supports.
Name | Type | Description |
---|---|---|
deviceId | String | Specifies the device ID. This device ID should be the unique id of your device (Android/iOS OR Web Browser). If you do not have device ID, you can send it null. |
Callback Params
err
Indicates if there is any error. It will be null if there is no error.res
Indicates the response. It will be empty for this method.