Every user needs to authenticate with ConnectyCube before using any ConnectyCube functionality.
When someone connects with an application using ConnectyCube, the application will need to obtain a session token which provides temporary secure access to ConnectyCube 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 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
Session token management
Android SDK supports automatic session management, so you do not need to create a session token on Android manually:
on your 1st request to API the session token will be created automatically
when the session expires, any further API request will renew it.
You can track session states using ConnectyCubeSessionManager
class and SessionListener
listener:
ConnectycubeSessionManager. isActiveSessionValid ()
ConnectycubeSessionManager. getInstance (). addListener (
object : ConnectycubeSessionManager. SessionListener {
override fun onSessionCreated (session: ConnectycubeSession) {
override fun onSessionUpdated (sessionParameters: ConnectycubeSessionParameters) {
override fun onSessionDeleted () {
override fun onSessionRestored (session: ConnectycubeSession) {
override fun onSessionExpired () {
override fun onProviderSessionExpired (provider: String) {
ConnectycubeSessionManager . getInstance () . addListener ( new ConnectycubeSessionManager. SessionListener () {
public void onSessionCreated ( ConnectycubeSession session ) {
public void onSessionUpdated ( ConnectycubeSessionParameters sessionParameters ) {
public void onSessionDeleted () {
public void onSessionRestored ( ConnectycubeSession session ) {
public void onSessionExpired () {
public void onProviderSessionExpired ( String provider ) {
Session token details
At any time you can get details about your current session token:
ConnectycubeSessionManager.activeSession.user
val sessionParameters = ConnectycubeSessionManager. getInstance ().sessionParameters
sessionParameters.userLogin
sessionParameters.userEmail
sessionParameters.socialProvider
sessionParameters.accessToken
ConnectycubeSessionParameters sessionParameters = ConnectycubeSessionManager . getInstance () . getSessionParameters () ;
sessionParameters . getUserId () ;
sessionParameters . getUserLogin () ;
sessionParameters . getUserEmail () ;
sessionParameters . getSocialProvider () ;
sessionParameters . getAccessToken () ;
Also you can check whether you are logged in or not:
val isSignedIn = ConnectycubeSessionManager.activeSession.user != null
val isSignedIn = ConnectycubeSessionManager. getInstance ().sessionParameters != null
boolean isSignedIn = ConnectycubeSessionManager . getInstance () . getSessionParameters () != null ;
Upgrade session token (user login)
If you have an application session, you can upgrade it to a user session by calling signIn
method:
val userToLogin = ConnectycubeUser (login = "marvin18" , password = "supersecurepwd" )
ConnectyCube. signIn (userToLogin, { user -> }, { error -> })
val user = ConnectycubeUser (). apply {
password = "supersecurepwd"
ConnectycubeUsers. signIn (user). performAsync ( object : EntityCallback<ConnectycubeUser> {
override fun onSuccess (user: ConnectycubeUser, args: Bundle) {
override fun onError (error: ResponseException) {
final ConnectycubeUser user = new ConnectycubeUser () ;
user . setLogin ( " marvin18 " ) ;
user . setPassword ( " supersecurepwd " ) ;
ConnectycubeUsers . signIn ( user ) . performAsync ( new EntityCallback < ConnectycubeUser >() {
public void onSuccess ( ConnectycubeUser user , Bundle args ) {
public void onError ( ResponseException error ) {
Authentication via phone number
Sign In with phone number is supported with Firebase integration .
The whole guide on how to create Firebase project, connect Firebase SDK and implement authentication via phone number is available at our Firebase Setup Guide . Please follow it.
Authentication via external identity provider
Custom Identity Provider (CIdP) feature is necessary if you have your own user database and want to authenticate users in ConnectyCube against it. It works the same way as Facebook/Twitter SSO.
With Custom Identity Provider feature you can continue use your user database instead of storing/copying user data to ConnectyCube database.
CIdP high level integration flow
To get started with CIdP integration, check the Custom Identity Provider guide which describes high level integration flow.
How to login via CIdP
Once you done with the setup mapping in ConnectyCube Dashboard, it’s time to verify the integration.
To perform CIdP login, the same ConnectyCube User Login API is used. You just use existing login request params to pass your external user token:
val userToLogin = ConnectycubeUser (login = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MTIzNDU2Nzg5LCJuYW1lIjoiSm9zZXBoIn0.OpOSSw7e485LOP5PrzScxHb7SR6sAOMRckfFwi4rp7o" )
ConnectyCube. signIn (userToLogin, { user -> }, { error -> })
Once the login is successful, ConnectyCube will create an underalying User entity, so then you can use ConnectyCube APIs in a same way as you do with a normal login. With CIdP we do not have/store any user password in ConnectyCube User entity.
Following further integration, you may need to connect to Chat. In a case of CIdP login, you do not have a user password. In such cases you should use ConnectyCube session token as a password for chat connection. Follow the Connect to Chat with CIdP guide .
Downgrade session token (user logout)
If you have a user session, you can downgrade it to an application session by calling signOut
method:
ConnectyCube. signOut ({ }, { error -> })
ConnectycubeUsers. signOut (). performAsync ( object : EntityCallback<Void?> {
override fun onSuccess (result: Void?, params: Bundle) {
override fun onError (responseException: ResponseException) {
ConnectycubeUsers . signOut () . performAsync ( new EntityCallback < Void >() {
public void onSuccess ( Void result , Bundle params ) {
public void onError ( ResponseException responseException ) {
Session expiration
Expiration time for session token is 2 hours after the last request to API is made. But you do not need to worry about it - with the automatic session token management it will be renewed automatically with next request to API.
Destroy session token
To destroy a session use the following code:
ConnectyCube. destroySession ({ }, { error -> })
ConnectycubeAuth. deleteSession (). performAsync ( object : EntityCallback<Void?> {
override fun onSuccess (result: Void?, params: Bundle) {
override fun onError (responseException: ResponseException) {
ConnectycubeAuth . deleteSession () . performAsync ( new EntityCallback < Void >() {
public void onSuccess ( Void result , Bundle params ) {
public void onError ( ResponseException responseException ) {
User signup
val userTags = listOf ( "iphone" , "apple" )
val userToSignUp = ConnectycubeUser (login = "marvin18" , password = "supersecurepwd" ). apply {
email = "awesomeman@gmail.com"
fullName = "Marvin Simon"
website = "https://dozensofdreams.com"
tags = userTags. joinToString ( "," )
ConnectyCube. signUp (userToSignUp, { user -> }, { error -> })
val userTags = StringifyArrayList <String>(). apply {
val user = ConnectycubeUser ( "marvin18" , "supersecurepwd" ). apply {
password = "supersecurepwd"
email = "awesomeman@gmail.com"
fullName = "Marvin Simon"
website = "https://dozensofdreams.com"
ConnectycubeUsers. signUp (user). performAsync ( object : EntityCallback<ConnectycubeUser> {
override fun onSuccess (user: ConnectycubeUser, args: Bundle) {
override fun onError (error: ResponseException) {
final ConnectycubeUser user = new ConnectycubeUser ( " marvin18 " , " supersecurepwd " ) ;
user . setLogin ( " marvin18 " ) ;
user . setPassword ( " supersecurepwd " ) ;
user . setEmail ( " awesomeman@gmail.com " ) ;
user . setFullName ( " Marvin Simon " ) ;
user . setPhone ( " 47802323143 " ) ;
user . setWebsite ( " https://dozensofdreams.com " ) ;
StringifyArrayList < String > tags = new StringifyArrayList < String >();
ConnectycubeUsers . signUp ( user ) . performAsync ( new EntityCallback < ConnectycubeUser >() {
public void onSuccess ( ConnectycubeUser user , Bundle args ) {
public void onError ( ResponseException error ) {
Only login (or email) + password are required. Other fields are optional.
User profile update
val userToUpdate = ConnectycubeUser (login = "marvin18" , password = "supersecurepwd" )
ConnectyCube. updateUser (userToUpdate, { user -> }, { error -> })
val user = ConnectycubeUser (). apply {
fullName = "Marvin Simon"
ConnectycubeUsers. updateUser (user). performAsync ( object : EntityCallback<ConnectycubeUser> {
override fun onSuccess (user: ConnectycubeUser, args: Bundle) {
override fun onError (error: ResponseException) {
ConnectycubeUser user = new ConnectycubeUser () ;
user . setLogin ( " marvin18 " ) ;
user . setFullName ( " Marvin Simon " ) ;
ConnectycubeUsers . updateUser ( user ) . performAsync ( new EntityCallback < ConnectycubeUser >() {
public void onSuccess ( ConnectycubeUser user , Bundle args ) {
public void onError ( ResponseException error ) {
If you want to change your password, you need to provide 2 parameters: password
and oldPassword
. An updated user
entity will be returned.
User avatar
You can set a user’s avatar. You just need to upload it to the ConnectyCube cloud storage and then connect to user.
val imageFile: File = .. .
ConnectyCube. uploadFile (imageFile.path, successCallback = { cubeFile ->
jo. add ( "avatar_uid" , JsonPrimitive (cubeFile.uid))
user.customData = jo. toString ()
ConnectyCube. updateUser (user, { user -> }, { error -> })
}, errorCallback = { ex -> })
val imageFile: File = .. .
ConnectycubeStorage. uploadFileTask (imageFile, false , null ). performAsync ( object : EntityCallback<ConnectycubeFile> {
override fun onSuccess (connectycubeFile: ConnectycubeFile, params: Bundle) {
jo. add ( "avatar_uid" , JsonPrimitive (connectycubeFile.uid))
user.customData = jo. toString ()
ConnectycubeUsers. updateUser (user). performAsync ( .. .)
override fun onError (responseException: ResponseException) {
ConnectycubeStorage . uploadFileTask ( imageFile, false , null ) . performAsync ( new EntityCallback < ConnectycubeFile >() {
public void onSuccess ( ConnectycubeFile connectycubeFile , Bundle params ) {
JsonObject jo = new JsonObject () ;
jo . add ( " avatar_uid " , new JsonPrimitive ( connectycubeFile .getUid ())) ;
user . setCustomData ( jo . toString ()) ;
ConnectycubeUsers . updateUser ( user ) . performAsync ( ... ) ;
public void onError ( ResponseException responseException ) {
Now, other users can get you avatar:
val obj = JsonParser (). parse (user.customData).asJsonObject
val fileUID = obj. getAsJsonPrimitive ( "avatar_uid" ).asString
val avatarUrl = getPrivateUrlForUID (fileUID)
val obj = JsonParser (). parse (user.customData).asJsonObject
val fileUID = obj. getAsJsonPrimitive ( "avatar_uid" ).asString
val avatarUrl = ConnectycubeFile. getPrivateUrlForUID (fileUID)
JsonObject obj = new JsonParser () . parse ( user . getCustomData ()) . getAsJsonObject () ;
String fileUID = obj . getAsJsonPrimitive ( " avatar_uid " ) . getAsString () ;
String avatarUrl = ConnectycubeFile . getPrivateUrlForUID ( fileUID ) ;
Password reset
It’s possible to reset a password via email:
ConnectyCube. resetPassword ( "awesomeman@gmail.com" , {}, { error -> })
ConnectycubeUsers. resetPassword ( "awesomeman@gmail.com" ). performAsync ( object : EntityCallback<Void?> {
override fun onSuccess (result: Void?, params: Bundle) {
override fun onError (responseException: ResponseException) {
ConnectycubeUsers . resetPassword ( " awesomeman@gmail.com " ) . performAsync ( new EntityCallback < Void >() {
public void onSuccess ( Void result , Bundle params ) {
public void onError ( ResponseException responseException ) {
If provided email is valid - an email with password reset instruction will be sent to it.
Retrieve users
Retrieve users by ID
val usersIds = setOf ( 22 , 23 )
ConnectyCube. getUsersByIds (usersIds, {usersResult -> }, { error -> })
val pagedRequestBuilder = PagedRequestBuilder (). apply {
val usersIds: MutableList<Int> = ArrayList <Int>(). apply {
ConnectycubeUsers. getUsersByIDs (usersIds, pagedRequestBuilder, params). performAsync ( object : EntityCallback<ArrayList<ConnectycubeUser>> {
override fun onSuccess (users: ArrayList<ConnectycubeUser>, args: Bundle) {
override fun onError (error: ResponseException) {
PagedRequestBuilder pagedRequestBuilder = new PagedRequestBuilder () ;
pagedRequestBuilder . setPage ( 1 ) ;
pagedRequestBuilder . setPerPage ( 50 ) ;
List < Integer > usersIds = new ArrayList <>();
Bundle params = new Bundle () ;
ConnectycubeUsers . getUsersByIDs ( usersIds, pagedRequestBuilder, params ) . performAsync ( new EntityCallback < ArrayList < ConnectycubeUser >>() {
public void onSuccess ( ArrayList < ConnectycubeUser > users , Bundle args ) {
public void onError ( ResponseException error ) {
Retrieve user by login
ConnectyCube. getUserByLogin ( "amigo" , {user -> }, { error -> })
ConnectycubeUsers. getUserByLogin ( "amigo" ). performAsync ( object : EntityCallback<ConnectycubeUser> {
override fun onSuccess (user: ConnectycubeUser, args: Bundle) {
override fun onError (error: ResponseException) {
ConnectycubeUsers . getUserByLogin ( " amigo " ) . performAsync ( new EntityCallback < ConnectycubeUser >() {
public void onSuccess ( ConnectycubeUser user , Bundle args ) {
public void onError ( ResponseException error ) {
Retrieve user by email
ConnectyCube. getUserByEmail ( "amigo@gmail.com" , {user -> }, { error -> })
ConnectycubeUsers. getUserByEmail ( "amigo@gmail.com" ). performAsync ( object : EntityCallback<ConnectycubeUser> {
override fun onSuccess (user: ConnectycubeUser, args: Bundle) {
override fun onError (error: ResponseException) {
ConnectycubeUsers . getUserByEmail ( " amigo@gmail.com " ) . performAsync ( new EntityCallback < ConnectycubeUser >() {
public void onSuccess ( ConnectycubeUser user , Bundle args ) {
public void onError ( ResponseException error ) {
Retrieve users by full name
ConnectyCube. getUsersByFullName ( "Marvin Samuel" , {usersResult -> }, { error -> })
val pagedRequestBuilder = PagedRequestBuilder (). apply {
ConnectycubeUsers. getUsersByFullName ( "Marvin Samuel" , pagedRequestBuilder, params)
. performAsync ( object : EntityCallback<ArrayList<ConnectycubeUser>> {
override fun onSuccess (users: ArrayList<ConnectycubeUser>, args: Bundle) {
override fun onError (error: ResponseException) {
PagedRequestBuilder pagedRequestBuilder = new PagedRequestBuilder () ;
pagedRequestBuilder . setPage ( 1 ) ;
pagedRequestBuilder . setPerPage ( 50 ) ;
Bundle params = new Bundle () ;
ConnectycubeUsers . getUsersByFullName ( " Marvin Samuel " , pagedRequestBuilder, params ) . performAsync ( new EntityCallback < ArrayList < ConnectycubeUser >>() {
public void onSuccess ( ArrayList < ConnectycubeUser > users , Bundle args ) {
public void onError ( ResponseException error ) {
Retrieve user by phone number
ConnectyCube. getUserByPhoneNumber ( "+4427123314" , {user -> }, { error -> })
val pagedRequestBuilder = PagedRequestBuilder (). apply {
val usersPhones: ArrayList<String> = ArrayList <String>(). apply {
ConnectycubeUsers. getUsersByPhoneNumbers (usersPhones, pagedRequestBuilder, params)
. performAsync ( object : EntityCallback<ArrayList<ConnectycubeUser>> {
override fun onSuccess (users: ArrayList<ConnectycubeUser>, args: Bundle) {
override fun onError (error: ResponseException) {
PagedRequestBuilder pagedRequestBuilder = new PagedRequestBuilder () ;
pagedRequestBuilder . setPage ( 1 ) ;
pagedRequestBuilder . setPerPage ( 50 ) ;
Bundle params = new Bundle () ;
ArrayList < String > usersPhones = new ArrayList <>();
usersPhones . add ( " +4427123314 " ) ;
ConnectycubeUsers . getUsersByPhoneNumbers ( usersPhones, pagedRequestBuilder, params ) . performAsync ( new EntityCallback < ArrayList < ConnectycubeUser >>() {
public void onSuccess ( ArrayList < ConnectycubeUser > users , Bundle args ) {
public void onError ( ResponseException error ) {
Retrieve user by external ID
ConnectycubeUsers. getUserByExternalId ( "3789" ). performAsync ( object : EntityCallback<ConnectycubeUser> {
override fun onSuccess (users: ConnectycubeUser, args: Bundle) {
override fun onError (error: ResponseException) {
ConnectycubeUsers . getUserByExternalId ( " 3789 " ) . performAsync ( new EntityCallback < ConnectycubeUser >() {
public void onSuccess ( ConnectycubeUser users , Bundle args ) {
public void onError ( ResponseException error ) {
val userTags = setOf ( "iphone" )
ConnectyCube. getUsersByTags (userTags, {usersResult -> }, { error -> })
val pagedRequestBuilder = PagedRequestBuilder (). apply {
val userTags: ArrayList<String> = ArrayList <String>(). apply {
ConnectycubeUsers. getUsersByTags (userTags, pagedRequestBuilder, params)
. performAsync ( object : EntityCallback<ArrayList<ConnectycubeUser>> {
override fun onSuccess (users: ArrayList<ConnectycubeUser>, args: Bundle) {
override fun onError (error: ResponseException) {
PagedRequestBuilder pagedRequestBuilder = new PagedRequestBuilder () ;
pagedRequestBuilder . setPage ( 1 ) ;
pagedRequestBuilder . setPerPage ( 50 ) ;
ArrayList < String > userTags = new ArrayList <>();
Bundle params = new Bundle () ;
ConnectycubeUsers . getUsersByTags ( userTags, pagedRequestBuilder, params ) . performAsync ( new EntityCallback < ArrayList < ConnectycubeUser >>() {
public void onSuccess ( ArrayList < ConnectycubeUser > users , Bundle args ) {
public void onError ( ResponseException error ) {
Delete user
A user can delete himself from the platform:
ConnectyCube. deleteUser ({}, { error -> })
ConnectycubeUsers. deleteUser (). performAsync ( object : EntityCallback<Void?> {
override fun onSuccess (result: Void?, params: Bundle) {
override fun onError (responseException: ResponseException) {
ConnectycubeUsers . deleteUser () . performAsync ( new EntityCallback < Void >() {
public void onSuccess ( Void result , Bundle params ) {
public void onError ( ResponseException responseException ) {