Skip to main content
Every user needs to authenticate with QuickBlox before using any QuickBlox functionality. When someone connects with an application using QuickBlox, the application needs to obtain a session token which provides temporary secure access to QuickBlox APIs. A session token is an opaque string that identifies a user and an application. Visit Key Concepts page to learn the most important QuickBlox concepts.

Before you begin

  1. Register a QuickBlox account. This is a matter of a few minutes and you will be able to use this account to build your apps.
  2. Configure QuickBlox SDK for your app. Check out Setup page for more details.

Session token rights

There are different types of session tokens to support different use cases.

Get session

At any time you can get details about your current session.
JavaScript

Create session

To create an application session, use the following code.
JavaScript
To create a user session, use the following code.
JavaScript

Sign up user

Before you log in the user, you must create the user on QuickBlox. Recommendations are below:
  1. For POCs/MVPs: Create the user using the QuickBlox Dashboard or in client app with application session token.
  2. For production apps: Use the QuickBlox Create User API with API key on your backend to create the user when your user signs up in your app.
SecurityIt’s recommended to disable permission to create users with application session on production apps once user creation is implemented on your backend.
You can create a user with application session token in client app by calling create() method.
JavaScript

Log in user

QuickBlox provides four types of user authentication: login/email and password, social, phone number, and custom identity provider login.

Login/email and password

Standard login lets you log in a user just by login (or email) and password. Other fields are optional. Thus, the QuickBlox server requests a users database for a match. If there is a match, a user session is created.
JavaScript

Social

Authenticate with QuickBlox using a social network access token.
JavaScript

Phone number

A sign-in with a phone number is supported with Firebase integration. In order to implement authentication via phone number functionality, follow this Firebase document. Don’t forget to enable phone number sign-in for your Firebase project. To learn how to do this, see this Firebase document. To send a verification code to the user’s phone and sign in the user on Firebase with the received verification code, use the snippet below.
JavaScript
To log in the user to QuickBlox, use the login() method and pass authParams to it. The ID token of the Firebase user is received as a result of the getIdToken() method.
JavaScript
Pass the following arguments to the login() method. The authParams object includes the following fields.

Custom identity provider

You can authenticate your application users from the external database with QuickBlox via Custom Identity Provider (CIdP). Just specify the user ID and access token as a password to authenticate with QuickBlox. Review Custom Identity Provider page for more details on the feature.
JavaScript
This feature is available for customers on the Enterprise plan only. Take advantage of Enterprise features to unlock new value and opportunities for users. For more information and if you want to request a Demo, please contact us by mail: enterprise@quickblox.com.

Log out user

If you have a user session, you can downgrade it to an application session by calling logout() method.
JavaScript

Session expiration

The expiration time for a session token is 2 hours. If you will perform a query with an expired token, you will receive an error: Required session does not exist. In this case, you have to recreate the session token. In JS SDK since version 2.14.1 we have a listener to find if the session token has expired.
JavaScript
If you use JS SDK version early then 2.14.1 in order to found out the session has expired you should use code below to initialize JS SDK.
JavaScript

Destroy session token

To destroy a session, use the following code.
JavaScript

Set existing session

Typically, a session token is stored in SDK after successful login and used for every subsequent API call. However, you may want to obtain and store the session on your server for better security. In this case, since the version JS SDK 2.14.1, you can set the existing session token into SDK using the startSessionWithToken(sessionToken, callBack) method. It’s can be application or user token. Don’t forget to Init and log in user if you pass the application token.
JavaScript