User Manager

The User Manager

To acquire the single instance of the UserManager call sdk.getUserManager().

The logged status of the user can be observed from the getStatusLiveData() method.
Possible values and their expected values are:

  • NotLoggedIn: Initial state
  • Initializing: Either user was previously logged-in and the UserManager is recovering the saved information on a background thread; or a login command was just executed and it’s being processed. On both cases the status should update shortly.
  • Ready: The Login/Initialization completed successfully and the functions of the UserManager can be used.
  • LoggingOut: A logout execution have been triggered and it’s being processed

Additionally NotLoggedIn and LoggingOut contains a user-friendly message string and a Reason enum.
When a LoggingOut occurs, the message and reason will be copied over to the following NotLoggedIn status.
The Reason values are:

  • NotLoggedIn: Initial state as soon as the UserManager is instantiated.
  • UserNotAuthorised: The user is not authorized with the Smartspaces backend. This might happen due to a login failed (wrong username/password/token) or due to a revoked authorization on the backend side (HTTP-401403).
  • EncryptionFailure: There was a problem initializing the SDK due to an encryption issue. The data is cleared during LoggingOut and a new call to login() should pass without issues on the next attempt.
  • ClientApplicationRequestedLogout: The client app called the logout() method.


The UserManager provides 3 different types of login for the user

  • Username and Password
  • OAuth2
  • external Token Login

Login via username and password

val result : LiveData<SimpleResponse<Void>> = userManager.usernamePasswordLoginLiveData(username, password)
      .onSuccess {
        // login success
      .onFail { exception ->
        // login fail

Login via OAuth2

To login with OAuth2 you have to do the login in an external Webview and add a deep-link back into the app.
The deep-link URI have to be configured on the backend.
The URL to call for the external url consists of the BASE_URL + /auth/ + OAUTH_ID


val uri = Uri.parse("${baseUrl}/auth/${oauthId}")
    .launchUrl(activity, uri)


We recommend the use CustomTabsIntent class of Android. All security conscious oauth2 providers blocks the usage of built-in WebView. To use the CustomTabsIntent you have to add implementation "<latest>" as a dependency into your build.gradle file

After the login succeeded the WebView will deep-link back into your application which will receive the redirectedUrl on the Intent to login to the SDK.

val result : LiveData<SimpleResponse<Void>>  = userManager.oAuth2LoginLiveData(intent.dataString)

The result of the login operation can be observed similarly to the username and password login

Login using external Token

To login the user using server-to-server pre-shared authentication token your backend has to register a token for the user on the Smartspaces Server and provide it to the following method.

val result : LiveData<SimpleResponse<Void>> = userManager.externalTokenLoginLiveData(authToken)

The result of the login operation can be observed similarly to the username and password login

Login failed

If the login failed the state of the UserManager will be UserManager.Status.NotAuthorized and then UserManager.Status.NotLoggedIn for all login variations. UserManager.Status.NotAuthorized also has a message string with the explanation, why the authorization failed.


To logout a user simply call the logout() method:


This method doesn’t return a LiveData<Response> because its result can be directly observed on the UserManager status

Change Password

You can only change the password, if you are using login via username and password

You can change the password of a logged in user, like in the following example:

val result : LiveData<SimpleResponse<Void>> = userManager.changePasswordLiveData(oldPassword, newPassword, newPasswordConfirm)
      .onSuccess {
        // change password success
      .onFail { exception ->
        // change password fail


To get all available user information (f.e. email, firstname, lastname, salutation) use the following code

val user : LiveData<User> = userManager.getUserLiveData().onSuccess()
user.observe(this, Observer { user ->
    user?.let {