UserAccountManager

This class acts as a manager that provides methods to access user accounts that are currently logged in, and can be used to add new user accounts.

Author

bhariharan

Properties

Link copied to clipboard
val EXTRA_USER_SWITCH_TYPE: String = "com.salesforce.USER_SWITCH_TYPE"
Represents how the current user has been switched to, as found in an intent sent to a BroadcastReceiver filtering USER_SWITCH_INTENT_ACTION.
Link copied to clipboard
val USER_SWITCH_INTENT_ACTION: String = "com.salesforce.USERSWITCHED"
Link copied to clipboard
A switch has occurred between two authenticated users.
Link copied to clipboard
The first user has logged in and is being switched to.
Link copied to clipboard
An additional user has logged in and is being switched to.
Link copied to clipboard
A user has a logged out and another authenticated user is being switched to.

Functions

Link copied to clipboard
open fun buildAccount(@NonNull userAccount: UserAccount): Account
Resolves the persisted Account whose account name and Salesforce identity match the supplied user.
Link copied to clipboard
Builds a UserAccount object from the saved account.
Link copied to clipboard
Get rid of cached current user account
Link copied to clipboard
Clears the stored current user info from shared preferences.
Link copied to clipboard
open fun createAccount(userAccount: UserAccount): Bundle
Create AccountManager Account from the given UserAccount
Link copied to clipboard
Returns whether the specified user account exists or not.
Link copied to clipboard
fun UserAccountManager.downgradeFromDPoP(userAccount: UserAccount, onSuccess: (userAccount: UserAccount) -> Unit, onFailure: (error: String, errorDesc: String?, e: Throwable?) -> Unit)

Downgrades the userAccount's existing DPoP-bound refresh token to a Bearer (non-DPoP) one, in place — same consumer key, redirect URI, and scopes the account already uses. This is a same-config convenience over migrateRefreshToken with useDPoP = false: no re-consent is expected because nothing about the connected app / External Client App configuration changes.

Link copied to clipboard
Returns a list of authenticated users.
Link copied to clipboard
Returns a cached value of the current user.
Link copied to clipboard
Returns the current user logged in.
Link copied to clipboard
Returns the current user logged in.
Link copied to clipboard
Returns a singleton instance of this class.
Link copied to clipboard
Returns the stored org ID.
Link copied to clipboard
Returns the stored user ID.
Link copied to clipboard
Retrieves a stored user account from org ID and user ID.
Link copied to clipboard
fun UserAccountManager.migrateRefreshToken(userAccount: UserAccount? = getInstance().currentUser, appConfig: OAuthConfig, onMigrationSuccess: (userAccount: UserAccount) -> Unit, onMigrationError: (error: String, errorDesc: String?, e: Throwable?) -> Unit)

Attempts to migrate the userAccount to the provided Connected App or External Client Application appConfig.

fun UserAccountManager.migrateRefreshToken(userAccount: UserAccount? = getInstance().currentUser, appConfig: OAuthConfig, useDPoP: Boolean?, onMigrationSuccess: (userAccount: UserAccount) -> Unit, onMigrationError: (error: String, errorDesc: String?, e: Throwable?) -> Unit)

Attempts to migrate the userAccount to the provided Connected App or External Client Application appConfig, with an explicit per-call DPoP intent.

Link copied to clipboard
open fun refreshToken(@Nullable userAccount: UserAccount)
Attempts to refresh the access token for this user by making an API call to the "/token" endpoint.
Link copied to clipboard
fun sendUserSwitchIntent(userSwitchType: Int, extras: Bundle)
Broadcasts an intent that a user switch has occurred.
Link copied to clipboard
open fun signoutCurrentUser(frontActivity: Activity)
open fun signoutCurrentUser(frontActivity: Activity, showLoginPage: Boolean)
open fun signoutCurrentUser(frontActivity: Activity, showLoginPage: Boolean, reason: OAuth2.LogoutReason)
Logs the current user out.
Link copied to clipboard
open fun signoutUser(@NonNull userAccount: UserAccount, frontActivity: Activity)
open fun signoutUser(@NonNull userAccount: UserAccount, frontActivity: Activity, showLoginPage: Boolean)
open fun signoutUser(@NonNull userAccount: UserAccount, frontActivity: Activity, showLoginPage: Boolean, reason: OAuth2.LogoutReason)
Logs the specified user out.
Link copied to clipboard
open fun storeCurrentUserInfo(userId: String, orgId: String)
Stores the current active user's user ID and org ID in a shared preference file.
Link copied to clipboard
open fun switchToNewUser()
Kicks off the login flow to switch to a new user.
Link copied to clipboard
open fun switchToUser(user: UserAccount)
open fun switchToUser(user: UserAccount, userSwitchType: Int, extras: Bundle)
Switches to the specified user account.
Link copied to clipboard
open fun updateAccount(account: Account, userAccount: UserAccount): Bundle
Update AccountManager Account for the given UserAccount
Link copied to clipboard
fun UserAccountManager.upgradeToDPoP(userAccount: UserAccount, onSuccess: (userAccount: UserAccount) -> Unit, onFailure: (error: String, errorDesc: String?, e: Throwable?) -> Unit)

Upgrades the userAccount's existing Bearer (non-DPoP) refresh token to a DPoP-bound one, in place — same consumer key, redirect URI, and scopes the account already uses. This is a same-config convenience over migrateRefreshToken with useDPoP = true: no re-consent is expected because nothing about the connected app / External Client App configuration changes.