Skip to content

Authentication and Users

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 TypeDescription
Application session tokenThis kind of access token is needed to read the app data. Has only READ access to resources
User session tokenThe 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:

//for now can be checked

Session token details

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


Also you can check whether you are logged in or not:

val isSignedIn = ConnectycubeSessionManager.activeSession.user != 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 -> })

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 need to use an external database to authenticate ConnectyCube application users. It allows you to integrate your existing users base with ConnectyCube easily and works the same way as Facebook/Twitter SSO.

With Custom Identity Provider feature you can continue using your user database instead of storing/copying user data to ConnectyCube database.

More info available on a dedicated Custom Identity Provider guide page.

After the Custom Identity Provider configuration, you can use same ConnectyCube user login API to authenticate ConnectyCube users against an external identity provider base.

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 -> })

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 -> })

User signup

val userTags = listOf("iphone", "apple")
val userToSignUp = ConnectycubeUser(login = "marvin18", password = "supersecurepwd").apply {
email = ""
fullName = "Marvin Simon"
phone = "47802323143"
website = ""
tags = userTags.joinToString(",")
ConnectyCube.signUp(userToSignUp, { user -> }, { 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 -> })

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 ->
val jo = JsonObject()
jo.add("avatar_uid", JsonPrimitive(cubeFile.uid))
user.customData = jo.toString()
ConnectyCube.updateUser(user, { user -> }, { error -> })
}, errorCallback = { ex -> })

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)

Password reset

It’s possible to reset a password via email:

ConnectyCube.resetPassword("", {}, { error -> })

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 -> })

Retrieve user by login

ConnectyCube.getUserByLogin("amigo", {user -> }, { error -> })

Retrieve user by email

ConnectyCube.getUserByEmail("", {user -> }, { error -> })

Retrieve users by full name

ConnectyCube.getUsersByFullName("Marvin Samuel", {usersResult -> }, { error -> })

Retrieve user by phone number

ConnectyCube.getUserByPhoneNumber("+4427123314", {user -> }, { 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) {

Retrieve users by tags

val userTags = setOf("iphone")
ConnectyCube.getUsersByTags(userTags, {usersResult -> }, { error -> })

Delete user

A user can delete himself from the platform:

ConnectyCube.deleteUser({}, { error -> })