Skip to main content

Context manager

The Context Manager simplifies the usage of complex SDK functions by reducing the number of parameters required when setting the operation context, authentication tokens, and other session data.

info

All the values that are provided to the context manager are automatically stored in secure storage.

Set operation context

sdk.contextManager().setOperationContext(
userId = USER_ID,
certificateChain = USER_CERTIFICATE_CHAIN_LIST,
keyPair = KEY_PAIR,
isKeyPairVerified = IS_KEY_PAIR_VERIFIED
)

Get Context State

Checks the state of the context by verifying that the auth token is valid, the key pair is valid and verified, and the certificate chain is valid. When checkServerInvalidation is set to true, it also checks if the auth token has been invalidated on the backend. This requires a network request. When checkServerInvalidation is false, this server check is skipped, meaning the auth token might be accepted even if it has been invalidated.

// Returns a ContextState
val result = sdk.contextManager().getContextState(true)

Is certificate chain invalid or expired

Checks if the current certificate chain from the context is invalid or expired (we consider it expired if it will expire within the next 7 days).

val result = sdk.contextManager().isCertificateChainInvalidOrExpired()

Is key pair valid

Checks if the current key pair from the context is valid.

val result = sdk.contextManager().isKeyPairValid()

Is key pair verified

Checks if the current key pair from the context has been verified.

val result = sdk.contextManager().isKeyPairVerified()

Set cloud auth token

If the SDK was initialized without an authentication token, you can provide or update the token using this function.

sdk.contextManager().setCloudAuthToken("AUTH_TOKEN")

Get cloud auth token

val token = sdk.contextManager().getCloudAuthToken()

Is cloud auth token invalid or expired

Checks if the current cloud auth token from the context is invalid, expired (we consider it expired if it will expire within the next 24 hours) or invalidated. When checkServerInvalidation is set to true, it also checks if the auth token has been invalidated on the backend. This requires a network request. When checkServerInvalidation is false, this server check is skipped, meaning the auth token might be accepted even if it has been invalidated on the server.

// Returns a Boolean
val result = sdk.contextManager().isCloudAuthTokenInvalidOrExpired(true)

Set cloud refresh token

sdk.contextManager().setCloudRefreshToken("REFRESH_TOKEN")

Get cloud refresh token

val token = sdk.contextManager().getCloudRefreshToken()

Set fusion auth token

sdk.contextManager().setFusionAuthToken("FUSION_AUTH_TOKEN")

Get fusion auth token

val token = sdk.contextManager().getFusionAuthToken()

Clear context

This function removes all stored context fields from the secure storage.

sdk.contextManager().clearContext()