Authentication and Users
Every user has 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 |
Create session token
To create an application session use the following code:
To create a user session use the following code:
To create a session with guest user use the following code:
Upgrade session token (user login)
If you have an application session, you can upgrade it to a user session by calling signIn
method:
Authentication via social provider
Flutter SDK provides support for next social providers:
CubeProvider.FACEBOOK
;CubeProvider.TWITTER
;
The generalized method for signing-in via social provider is:
Get Facebook Access token
In order to use Facebook authentication you need to get an Access token first. Flutter has a few plugins that provide this feature. We will use the flutter_facebook_auth in our example. First, you must configure each supported platform according to the plugin official documentation web page. Then you can request the login via Facebook API and sign in to ConnectyCube using its credentials. Follow the code below on how to do this:
Get Twitter Auth token and Auth Token Secret
In order to use Twitter authentication you need to get an Auth token and Auth Token Secret first. Flutter has a few plugins that provide this feature. We will use the twitter_login in our example. First, you must configure each supported platform according to the plugin README. Then you can request the login via Twitter API and sign in to ConnectyCube using its credentials. Follow the code below on how to do this:
Authentication via phone number
Sign In with phone number is supported with Firebase Phone Authentication.
The detailed guides on How to configure Firebase in your project and How to get accessToken
are
presented in our separated section How to Setup Firebase.
After receiving the accessToken
you can use it for authentication using next API:
Authentication via Firebase Emaiil/Google Sign-In:
This authentication method supports Firebase Email/password sign-in and Google Sign-In.
The detailed guides on How to configure Firebase in your project
and How to get accessToken
are
presented in our separated section How to Setup Firebase.
After receiving the accessToken
you can use it for authentication using next API:
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:
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:
Session expiration
Expiration time for session token is 2 hours after last request to API. If you perform query with expired token,
you will receive the error Required session does not exist. In this case you need to recreate a session token.
Use CubeSessionManager
to get information about current session state.
ConnectyCube Flutter SDK has the special callbаck for automatic session restoring. Just set it during the initialization ConnectyCube Flutter SDK in your project.
Destroy session token
To destroy a session use the following code:
User signup
Only login (or email) + password are required.
User profile update
If you want to change your password, you need to provide 2 fields: password
and oldPassword
. 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.
Now, other users can get you avatar:
Password reset
It’s possible to reset a password via email:
If provided email is valid - an email with password reset instruction will be sent to it.
Retrieve users
Retrieve user by ID
Retrieve users by IDs
Retrieve user by login
Retrieve user by email
Retrieve users by full name
Retrieve user by phone number
Retrieve user by external ID
Retrieve users by tags
Retrieve users by parameters
There is an available function for getting users by all available parameters and filters provided by link
Delete user
A user can delete himself from the platform: