Package com.unblu.sdk.core.auth
Class UnbluAuthHelper
java.lang.Object
com.unblu.sdk.core.auth.UnbluAuthHelper
Helper class providing authentication utilities for Unblu integration.
Includes methods for token-based authentication and handling 2FA flows.
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
authenticateWithToken
(android.content.Context context, UnbluClientConfiguration configuration, String authenticationToken, BiConsumer<String, Map<String, String>> success, android.webkit.ValueCallback<String> failure) Authenticates using a previously obtained token and collects cookies from the response.static void
authenticateWithTokenAndLoginWith2FA
(android.app.Activity activity, 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.static void
createAuthenticationToken
(android.content.Context context, UnbluClientConfiguration configuration, String username, String password, android.webkit.ValueCallback<String> success, android.webkit.ValueCallback<String> failure) Creates an authentication token from username and password using Unblu's REST API.static void
createAuthTokenAndLoginWith2FA
(android.app.Activity activity, UnbluClientConfiguration configuration, String username, 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 WebViewstatic String
getAuthToken
(UnbluClientConfiguration configuration) Returns the authentication token stored in preferences.
-
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.
-
getAuthToken
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 benull
, 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 benull
, in which case a default configuration will be used.onResult
- Callback returning a pair: success flag and optional error message.
-