Create a user
You should create a user in your Sendbird application to initiate conversations in channels. A user is identified by its unique user ID, and additionally have a changeable nickname, profile image, and so on. Users are at the core of all conversations. Sendbird applications are made up of users who chat in either Open Channels or Group Channels. Using this API, it is possible to have fine grained control over your users and what those users can do. To learn more about users, see User overview.
Access token vs. Session token
When a user logs into the Sendbird system through the SDKs, you should authenticate the user with either an access token or a session token. It is possible to log in just using a user ID, but a more secure authentication process using tokens is strongly recommended for most production environments.
Between the two types of tokens, session tokens are considered more secure because they expire after a given time while access tokens are valid until explicitly revoked.
Session tokens are issued by calling the /users/{user_id}/token
endpoint after a user is created.
Access tokens are issued when a user is updated or created with the issue_access_token
property set to true
.
If either type of token is issued for a user, it must be provided to the Sendbird server each time the user logs in by using the SDK's connect methods. If you delete a user's token, the user won't be able to log in until a new token is issued.
Deprecation Information
Issuing session tokens through the /users/{user_id}
endpoint is now deprecated and it's replaced with the /users/{user_id}/token
endpoint for higher efficiency. For those who are currently using the old endpoint, you can start issuing tokens using the new endpoint. For those who wish to replace the old endpoint with the new /users/{user_id}/token
endpoint, there may be an issue with the session token length if the cache in your app has a limit imposed on the token string length. The new session tokens can have a string of from 119 to 168 characters.
A session token generated by the new endpoint provides efficient authentication between the end user and the Sendbird server. Unlike the previous method of issuing session tokens, the new session tokens aren't stored in the Sendbird database. This method improves the server's performance when a customer tries to issue a lot of tokens at once. After a session token is issued, the end user is connected to the Sendbird server for a set time period. Once the token expires, the user must request a new session token.
It is recommended that you cache the session tokens of your users in their devices locally and use the cached tokens when logging in to the Sendbird server. If you issue a new session token every time a user logs in to the server, multiple login attempts with different tokens of the user can occur simultaneously. Then, some sessions of the user can be locked out depending on the number of the attempts.
Access token | Deprecated session token | New session token | |
---|---|---|---|
| /users/{user_id}/access_token |
| /users/{user_id}/token |
| No specific endpoint. Set |
| /users/{user_id}/token |
Used for | Stateful authentication |
| Stateless authentication |
Work as | Permanent credential to the system |
| Temporary credential to the system |
Valid or active until | Revoked |
| Timestamp set when issued (default: the next 7 days from now) |
Identification for | The user account |
| The user's current session |
Tokens per user | Up to 10 (valid) |
| No limit |
If exceeded the limit | The oldest token is revoked and the new one is added to the list. |
| No limit |
Auto-revocation | No |
| Yes (by default, the system revokes the expired tokens) |
HTTP request
Request body
The following table lists the properties of an HTTP request that this action supports.
Properties
Required | Type | Description |
---|---|---|
user_id | string | Specifies a user's unique ID. Maximum length is 80 characters. |
nickname | string | Specifies the user's nickname. Maximum length is 80 characters. |
profile_url | string | Specifies the URL of the user's profile image. If left empty, no profile image is set for the user. Maximum length is 2,048 characters. If the |
profile_file | binary | Specifies the file of the user's profile image. An acceptable image is limited to a JPG, JPEG, or PNG file of up to 5 MB. When passing a file, you should send a multipart request. If the |
Optional | Type | Description |
---|---|---|
issue_access_token | boolean | Determines whether to create an access token for the user. If set to |
metadata | nested object | Specifies a |
| boolean | (Deprecated) Determines whether to create a session token for the user. If set to |
| long | (Deprecated) Specifies the time for the issued session token to expire in Unix milliseconds format. The length should be 13. If a value of this property is not specified and the |
Responses
If successful, this action returns a user resource in the response body.
Error
In the case of an error, an error object like below is returned. See the error codes section for more details.