The QuickBlox Developer Hub

Welcome to the QuickBlox developer hub. You'll find comprehensive guides and documentation to help you start working with QuickBlox as quickly as possible, as well as support if you get stuck. Let's jump right in!

Get Started    

Authentication

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.

Session token rights

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

Session Token Type
Description

Application session token

This kind of access token is needed to read the app data. Has only READ access to resources. The expiration time after the last REST API request is 2 hours.

User session token

The user token is the most commonly used type of token. This kind of access token is needed any time the app calls an API to read, modify or write a specific user's data on their behalf. Has READ/WRITE access to resources. The expiration time after the last REST API request is 2 hours.

Session token management

You can track session states using QBSessionManager class and SessionListener listener.

QBSessionManager.getInstance().addListener(new QBSessionManager.QBSessionListener() {
    @Override
    public void onSessionCreated(QBSession session) {
        // calls when session was created firstly or after it has been expired
    }
 
    @Override
    public void onSessionUpdated(QBSessionParameters sessionParameters) {
        // calls when user signed in or signed up
        // QBSessionParameters stores information about signed in user. 
    }
 
    @Override
    public void onSessionDeleted() {
        // calls when user signed Out or session was deleted 
    }
 
    @Override
    public void onSessionRestored(QBSession session) {
        // calls when session was restored from local storage
    }
 
    @Override
    public void onSessionExpired() {
        // calls when session is expired
    }
 
    @Override
    public void onProviderSessionExpired(String provider) {
        // calls when provider's access token is expired or invalid 
    }
});
QBSessionManager.getInstance().addListener(object : QBSessionManager.QBSessionListener {
    override fun onSessionCreated(session: QBSession) {
        // calls when session was created firstly or after it has been expired
    }

    override fun onSessionUpdated(sessionParameters: QBSessionParameters) {
        // calls when user signed in or signed up
        // QBSessionParameters stores information about signed in user.
    }

    override fun onSessionDeleted() {
        // calls when user signed Out or session was deleted
    }

    override fun onSessionRestored(session: QBSession) {
        // calls when session was restored from local storage
    }

    override fun onSessionExpired() {
        // calls when session is expired
    }

    override fun onProviderSessionExpired(provider: String) {
        // calls when provider's access token is expired or invalid
    }
})

Session token details

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

QBSessionParameters sessionParameters = QBSessionManager.getInstance().getSessionParameters();
sessionParameters.getUserId();
sessionParameters.getUserLogin();
sessionParameters.getUserEmail();
sessionParameters.getSocialProvider();
sessionParameters.getAccessToken();
val sessionParameters = QBSessionManager.getInstance().getSessionParameters()
sessionParameters.userId
sessionParameters.userLogin
sessionParameters.userEmail
sessionParameters.socialProvider
sessionParameters.accessToken

Also, you can check whether you are logged in or not.

boolean isLoggedIn = QBSessionManager.getInstance().getSessionParameters() != null;
val isLoggedIn = QBSessionManager.getInstance().sessionParameters != null

Authentication via phone number

Sign in with a phone number is supported with Firebase integration. In order to implement authentication via phone number functionality, you need to configure the Firebase project and API key.

  1. Create and configure your Firebase project and obtain the API key.
  2. Find your FCM server key following your Firebase console => Cloud Messaging section.
  3. Copy your FCM server key to your Dashboard => Your App => Push Notifications => Certificates & API keys. Select the environment for which you are adding the key and hit Save key. Use the same key for development and production zones. Add your FCM server key to your Dashboard.
QBUsers.signInUsingFirebase("thisIsProjectIDFromFirebase", "thisIsAccessTokenFromFirebase").performAsync(new QBEntityCallback<QBUser>() {
    @Override
    public void onSuccess(QBUser qbUser, Bundle bundle) {
           
    }

    @Override
    public void onError(QBResponseException e) {
        
    }
});
QBUsers.signInUsingFirebase("thisIsProjectIDFromFirebase", "thisIsAccessTokenFromFirebase").performAsync(object : QBEntityCallback<QBUser> {
    override fun onSuccess(qbUser: QBUser?, bundle: Bundle?) {
        
    }

    override fun onError(e: QBResponseException?) {
        
    }
})

Sign up user

If a current user doesn't exist, you can create them by calling signUp() method.

final QBUser user = new QBUser();
user.setLogin("Javck");
user.setPassword("javckpassword");

QBUsers.signUp(user).performAsync(new QBEntityCallback<QBUser>() {
    @Override
    public void onSuccess(QBUser qbUser, Bundle bundle) {
        
    }

    @Override
    public void onError(QBResponseException e) {
        
    }
});
val user = QBUser()
user.login = "Javck"
user.password = "javckpassword"

QBUsers.signUp(user).performAsync(object : QBEntityCallback<QBUser> {
    override fun onSuccess(qbUser: QBUser?, bundle: Bundle?) {
        
    }

    override fun onError(e: QBResponseException?) {
        
    }
})

Log in user

For login as the user, you need only login (or email) and password. Other fields are optional. If you have an application session, you can upgrade it to a user session by calling signIn() method.

final QBUser user = new QBUser();
user.setLogin("Javck");
user.setPassword("javckpassword");

QBUsers.signIn(user).performAsync(new QBEntityCallback<QBUser>() {
    @Override
    public void onSuccess(QBUser user, Bundle args) {
        
    }

    @Override
    public void onError(QBResponseException error) {
        
    }
});
val user = QBUser()
user.login = "Javck"
user.password = "javckpassword"

QBUsers.signIn(user).performAsync(object : QBEntityCallback<QBUser> {
    override fun onSuccess(user: QBUser?, args: Bundle?) {
        
    }

    override fun onError(error: QBResponseException?) {
        
    }
})

Log out user

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

QBUsers.signOut().performAsync(new QBEntityCallback<Void>() {
    @Override
    public void onSuccess(Void aVoid, Bundle bundle) {
        
    }

    @Override
    public void onError(QBResponseException e) {
        
    }
});
QBUsers.signOut().performAsync(object : QBEntityCallback<Void> {
    override fun onSuccess(aVoid: Void?, bundle: Bundle?) {
        
    }

    override fun onError(e: QBResponseException?) {
        
    }
})

Session expiration

QuickBlox Android SDK will automatically renew your current session. There is no need to manually call createSession() method. After login, a session is available for 2 hours. When the session expires, any request method will firstly renew it and then execute itself.

Destroy session token

To destroy an application session use the following code.

QBAuth.deleteSession().performAsync(new QBEntityCallback<Void>() {
    @Override
    public void onSuccess(Void aVoid, Bundle bundle) {
        
    }

    @Override
    public void onError(QBResponseException e) {
        
    }
});
QBAuth.deleteSession().performAsync(object : QBEntityCallback<Void> {
    override fun onSuccess(aVoid: Void?, bundle: Bundle?) {
        
    }

    override fun onError(e: QBResponseException?) {
        
    }
})

Updated about a month ago


What's Next

Users

Authentication


Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.