Class UnbluAuthHelper

java.lang.Object
com.unblu.sdk.core.auth.UnbluAuthHelper

public class UnbluAuthHelper extends Object
Helper class providing authentication utilities for Unblu integration. Includes methods for token-based authentication and handling 2FA flows.
  • Method Details

    • createAuthenticationToken

      public static void createAuthenticationToken(@NonNull android.content.Context context, @NonNull UnbluClientConfiguration configuration, @NonNull String username, @NonNull String password, @NonNull android.webkit.ValueCallback<String> success, @NonNull android.webkit.ValueCallback<String> failure)
      Creates an authentication token from username and password using Unblu's REST API. Stores the token, cookie prefix, and device identifier in preferences.
      Parameters:
      context - Android context.
      configuration - The Unblu client configuration.
      username - The username to authenticate.
      password - The password to authenticate.
      success - Callback invoked with the token string on success.
      failure - Callback invoked with an error message on failure.
    • authenticateWithToken

      public static void authenticateWithToken(@NonNull android.content.Context context, @NonNull UnbluClientConfiguration configuration, @NonNull String authenticationToken, @NonNull BiConsumer<String,Map<String,String>> success, @NonNull android.webkit.ValueCallback<String> failure)
      Authenticates using a previously obtained token and collects cookies from the response.
      Parameters:
      context - Android context.
      configuration - The Unblu client configuration.
      authenticationToken - The token to authenticate with.
      success - Callback with the response body and cookie map on success.
      failure - Callback with an error message on failure.
    • authenticateWithAccessToken

      public static void authenticateWithAccessToken(@NonNull UnbluClientConfiguration configuration, @NonNull android.webkit.ValueCallback<UnbluClientConfiguration> success, @NonNull android.webkit.ValueCallback<String> failure)
      Exchanges the visitor JWT set with UnbluClientConfiguration.Builder.setAccessToken(String) for Unblu session cookies, without starting the SDK. Use it for authenticated calls made outside a started SDK, e.g. UnbluWebApiHelper.getOwnNotificationCount(android.content.Context, com.unblu.sdk.core.configuration.UnbluClientConfiguration, android.webkit.ValueCallback<com.unblu.sdk.core.UnbluWebApiHelper.NotificationCountResult>, android.webkit.ValueCallback<java.lang.String>).

      The returned cookies are a credential, like the JWT: never log them, store them only in secure storage and drop them on logout.

      Parameters:
      configuration - The Unblu client configuration providing base URL, entry path, API key and access token.
      success - Callback invoked on the main thread with a copy of the configuration whose custom cookies contain the session cookies.
      failure - Callback invoked on the main thread with an error message (including the HTTP status) on failure.
    • buildOkHttpClient

      public static okhttp3.OkHttpClient buildOkHttpClient(@NonNull android.content.Context context)
      Builds an OkHttpClient instance, optionally configured with a client certificate if available in preferences.
    • getAuthToken

      public static String getAuthToken(@NonNull UnbluClientConfiguration configuration)
      Returns the authentication token stored in preferences.
      Parameters:
      configuration - The Unblu client configuration.
      Returns:
      The token if available, or null otherwise.
    • authenticateWithTokenAndLoginWith2FA

      public static void authenticateWithTokenAndLoginWith2FA(android.app.Activity activity, @NonNull UnbluClientConfiguration configuration, String token, com.unblu.sdk.core.internal.webview.UnbluTwoFactorAuthErrorUIConfig errorUIConfig, Consumer<androidx.core.util.Pair<Boolean,String>> onResult)
      Authenticates with the given token and shows the 2FA WebView if needed.
      Parameters:
      activity - The calling activity.
      configuration - The Unblu client configuration.
      token - The token to use for authentication (or null to use stored token).
      errorUIConfig - (Optional) The UI configuration used to customize the appearance of the error view and buttons. Can be null, in which case a default configuration will be used.
      onResult - Callback returning a pair: success flag and optional error message.
    • createAuthTokenAndLoginWith2FA

      public static void createAuthTokenAndLoginWith2FA(android.app.Activity activity, @NonNull UnbluClientConfiguration configuration, @NonNull String username, @NonNull String password, com.unblu.sdk.core.internal.webview.UnbluTwoFactorAuthErrorUIConfig errorUIConfig, Consumer<androidx.core.util.Pair<Boolean,String>> onResult)
      - Creates an authentication token using username/password - Waits for the device identifier - Authenticates with the token - Launches 2FA WebView
      Parameters:
      activity - The calling activity.
      configuration - The Unblu client configuration.
      username - The login username.
      password - The login password.
      errorUIConfig - (Optional) The UI configuration used to customize the appearance of the error view and buttons. Can be null, in which case a default configuration will be used.
      onResult - Callback returning a pair: success flag and optional error message.