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.
All the values that are provided to the context manager are automatically stored in secure storage.
Set API environment
Changes the environment the SDK operates against. It can be changed at any time, although it is recommended to set it up through the SdkConfig builder instead.
- Kotlin
- Java
- Swift
- JavaScript
- C#
- Python
sdk.contextManager().setApiEnvironment(ApiEnvironment.PROD)
sdk.contextManager().setApiEnvironment(ApiEnvironment.PROD);
sdk.contextManager().setApiEnvironment(apiEnvironment: ApiEnvironment.prod)
sdk.contextManager().setApiEnvironment("PROD");
// Not implemented yet
// Not implemented yet
Get API environment
Returns the environment the SDK is currently operating against. Defaults to PROD when it has never been set.
- Kotlin
- Java
- Swift
- JavaScript
- C#
- Python
// Returns an ApiEnvironment
val apiEnvironment = sdk.contextManager().getApiEnvironment()
// Returns an ApiEnvironment
var apiEnvironment = sdk.contextManager().getApiEnvironment();
// Returns an ApiEnvironment
let apiEnvironment = sdk.contextManager().getApiEnvironment()
// Returns a string
const apiEnvironment = sdk.contextManager().getApiEnvironment();
// Returns an ApiEnvironment
var apiEnvironment = sdk.GetContextManager().GetApiEnvironment();
# Returns a str
apiEnvironment = sdk.contextManager.get_api_environment()
Set cloud auth token
If the SDK was initialized without an authentication token, you can provide or update the token using this function, also it is set automatically by login, register, refresh-token and the automatic refresh. Passing null removes the stored token.
- Kotlin
- Java
- Swift
- JavaScript
- C#
- Python
sdk.contextManager().setCloudAuthToken("AUTH_TOKEN")
sdk.contextManager().setCloudAuthToken("AUTH_TOKEN");
sdk.contextManager().setCloudAuthToken(token: "AUTH_TOKEN")
sdk.contextManager().setCloudAuthToken("AUTH_TOKEN");
sdk.GetContextManager().SetCloudAuthToken("AUTH_TOKEN");
sdk.contextManager.set_cloud_auth_token("AUTH_TOKEN")
Get cloud auth token
- Kotlin
- Java
- Swift
- JavaScript
- C#
- Python
val token = sdk.contextManager().getCloudAuthToken()
var token = sdk.contextManager().getCloudAuthToken();
let token = sdk.contextManager().getCloudAuthToken()
const token = sdk.contextManager().getCloudAuthToken();
var token = sdk.GetContextManager().GetCloudAuthToken();
token = sdk.contextManager.get_cloud_auth_token()
Is cloud auth token invalid or expired
Checks whether the cloud auth token from the context can still be used:
- A token that is missing, invalid or expires within the next 24 hours is first refreshed with the stored refresh token. This is a network request, performed regardless of checkServerInvalidation.
- It returns true only when the token could not be refreshed and is missing, invalid or past its expiration. A token that could not be refreshed but has not expired yet is still valid, since the backend accepts it until then.
- When checkServerInvalidation is true, a token that passes the checks above is also verified with the backend (an additional network request). When false, the token might be accepted even if it has been invalidated on the server.
- Kotlin
- Java
- Swift
- JavaScript
- C#
- Python
// Returns a Boolean
val result = sdk.contextManager().isCloudAuthTokenInvalidOrExpired(true)
// Returns a CompletableFuture<Boolean>
var result = sdk.contextManager().isCloudAuthTokenInvalidOrExpiredAsync(true);
// Returns a Bool asynchronously
let result = await sdk.contextManager().isCloudAuthTokenInvalidOrExpired(checkServerInvalidation: true)
// Returns a Promise<boolean>
const result = await sdk.contextManager().isCloudAuthTokenInvalidOrExpired(true);
// Returns a Task<bool>
var result = await sdk.GetContextManager().IsCloudAuthTokenInvalidOrExpired(checkServerInvalidation: true);
# Returns a Future[SimpleNamespace]
result = await sdk.contextManager.is_cloud_auth_token_invalid_or_expired(True)
Set cloud refresh token
It is set automatically by login, register, and refresh-tokens. Passing null removes the stored token.
While a refresh token is stored, the SDK refreshes the cloud auth token automatically: before a request, when the auth token is missing, invalid or expires within the next 24 hours, and once more after an unauthorized response. A refresh token rejected by the backend is removed from the context.
- Kotlin
- Java
- Swift
- JavaScript
- C#
- Python
sdk.contextManager().setCloudRefreshToken("REFRESH_TOKEN")
sdk.contextManager().setCloudRefreshToken("REFRESH_TOKEN");
sdk.contextManager().setCloudRefreshToken(token: "REFRESH_TOKEN")
sdk.contextManager().setCloudRefreshToken("REFRESH_TOKEN");
sdk.GetContextManager().SetCloudRefreshToken("REFRESH_TOKEN");
sdk.contextManager.set_cloud_refresh_token("REFRESH_TOKEN")
Get cloud refresh token
- Kotlin
- Java
- Swift
- JavaScript
- C#
- Python
val token = sdk.contextManager().getCloudRefreshToken()
var token = sdk.contextManager().getCloudRefreshToken();
let token = sdk.contextManager().getCloudRefreshToken()
const token = sdk.contextManager().getCloudRefreshToken();
var token = sdk.GetContextManager().GetCloudRefreshToken();
token = sdk.contextManager.get_cloud_refresh_token()
Set fusion host
Sets the host of the on-premise Fusion server used by the fusion resource. It can be changed at any time, although it is recommended to set it up through the SdkConfig builder instead.
- Kotlin
- Java
- Swift
- JavaScript
- C#
- Python
sdk.contextManager().setFusionHost(URI("http://localhost:27700"))
sdk.contextManager().setFusionHost(URI.create("http://localhost:27700"));
sdk.contextManager().setFusionHost(host: NSURLComponents(string: "http://localhost:27700")!)
sdk.contextManager().setFusionHost("http://localhost:27700");
sdk.GetContextManager().SetFusionHost("http://localhost:27700");
sdk.contextManager.set_fusion_host("http://localhost:27700")
Get fusion host
Returns the currently configured Fusion host. Defaults to http://localhost:27700 when it has never been set.
- Kotlin
- Java
- Swift
- JavaScript
- C#
- Python
// Returns a URI
val fusionHost = sdk.contextManager().getFusionHost()
// Returns a URI
var fusionHost = sdk.contextManager().getFusionHost();
// Returns an NSURLComponents
let fusionHost = sdk.contextManager().getFusionHost()
// Returns a string
const fusionHost = sdk.contextManager().getFusionHost();
// Returns a string
var fusionHost = sdk.GetContextManager().GetFusionHost();
# Returns a str
fusionHost = sdk.contextManager.get_fusion_host()
Set fusion auth token
It is set automatically by fusion login.
- Kotlin
- Java
- Swift
- JavaScript
- C#
- Python
sdk.contextManager().setFusionAuthToken("FUSION_AUTH_TOKEN")
sdk.contextManager().setFusionAuthToken("FUSION_AUTH_TOKEN");
sdk.contextManager().setFusionAuthToken(token: "FUSION_AUTH_TOKEN")
sdk.contextManager().setFusionAuthToken("FUSION_AUTH_TOKEN");
sdk.GetContextManager().SetFusionAuthToken("FUSION_AUTH_TOKEN");
sdk.contextManager.set_fusion_auth_token("FUSION_AUTH_TOKEN")
Get fusion auth token
- Kotlin
- Java
- Swift
- JavaScript
- C#
- Python
val token = sdk.contextManager().getFusionAuthToken()
var token = sdk.contextManager().getFusionAuthToken();
let token = sdk.contextManager().getFusionAuthToken()
const token = sdk.contextManager().getFusionAuthToken();
var token = sdk.GetContextManager().GetFusionAuthToken();
token = sdk.contextManager.get_fusion_auth_token()
Set user ID
Sets the user identifier used by the secure lock operations. It is usually set for you by set operation context, register ephemeral key and verify ephemeral key.
- Kotlin
- Java
- Swift
- JavaScript
- C#
- Python
sdk.contextManager().setUserId(USER_ID)
sdk.contextManager().setUserId(USER_ID);
sdk.contextManager().setUserId(userId: USER_ID)
sdk.contextManager().setUserId("USER_ID");
sdk.GetContextManager().SetUserId(USER_ID);
sdk.contextManager.set_user_id("USER_ID")
Get user ID
- Kotlin
- Java
- Swift
- JavaScript
- C#
- Python
// Returns a UUID
val userId = sdk.contextManager().getUserId()
// Returns a UUID
var userId = sdk.contextManager().getUserId();
// Returns an NSUUID
let userId = sdk.contextManager().getUserId()
// Returns a string
const userId = sdk.contextManager().getUserId();
// Returns a Guid
var userId = sdk.GetContextManager().GetUserId();
# Returns a str
userId = sdk.contextManager.get_user_id()
Set user email
Sets the email address associated with the context. It is set automatically by login and registration.
- Kotlin
- Java
- Swift
- JavaScript
- C#
- Python
sdk.contextManager().setUserEmail("EMAIL")
sdk.contextManager().setUserEmail("EMAIL");
sdk.contextManager().setUserEmail(email: "EMAIL")
sdk.contextManager().setUserEmail("EMAIL");
sdk.GetContextManager().SetUserEmail("EMAIL");
sdk.contextManager.set_user_email("EMAIL")
Get user email
- Kotlin
- Java
- Swift
- JavaScript
- C#
- Python
val email = sdk.contextManager().getUserEmail()
var email = sdk.contextManager().getUserEmail();
let email = sdk.contextManager().getUserEmail()
const email = sdk.contextManager().getUserEmail();
var email = sdk.GetContextManager().GetUserEmail();
email = sdk.contextManager.get_user_email()
Set certificate chain
Sets the certificate chain used to sign the secure lock operations. It is usually set for you by set operation context, register ephemeral key and verify ephemeral key.
Only the first certificate of the chain is inspected by is certificate chain invalid or expired.
- Kotlin
- Java
- Swift
- JavaScript
- C#
- Python
sdk.contextManager().setCertificateChain(USER_CERTIFICATE_CHAIN_LIST)
sdk.contextManager().setCertificateChain(USER_CERTIFICATE_CHAIN_LIST);
sdk.contextManager().setCertificateChain(certificateChain: USER_CERTIFICATE_CHAIN_LIST)
sdk.contextManager().setCertificateChain(USER_CERTIFICATE_CHAIN_LIST);
// Not implemented yet
// Not implemented yet
Get certificate chain
Returns the stored certificate chain, or null when none has been set.
- Kotlin
- Java
- Swift
- JavaScript
- C#
- Python
// Returns a List<X509Certificate>
val certificateChain = sdk.contextManager().getCertificateChain()
// Returns a List<X509Certificate>
var certificateChain = sdk.contextManager().getCertificateChain();
// Returns a [String]
let certificateChain = sdk.contextManager().getCertificateChain()
// Returns a string[]
const certificateChain = sdk.contextManager().getCertificateChain();
// Not implemented yet
// Not implemented yet
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).
- Kotlin
- Java
- Swift
- JavaScript
- C#
- Python
val result = sdk.contextManager().isCertificateChainInvalidOrExpired()
var result = sdk.contextManager().isCertificateChainInvalidOrExpired();
let result = sdk.contextManager().isCertificateChainInvalidOrExpired()
const result = sdk.contextManager().isCertificateChainInvalidOrExpired();
var result = sdk.GetContextManager().IsCertificateChainInvalidOrExpired();
result = sdk.contextManager.is_certificate_chain_invalid_or_expired()
Set key pair
Sets the key pair used to sign the secure lock operations. It is usually set for you by set operation context, register ephemeral key and verify ephemeral key.
Setting a new key pair does not mark it as verified. Use set key pair verified, or register it through register ephemeral key plus and verify ephemeral key.
- Kotlin
- Java
- Swift
- JavaScript
- C#
- Python
sdk.contextManager().setKeyPair(KEY_PAIR)
sdk.contextManager().setKeyPair(KEY_PAIR);
sdk.contextManager().setKeyPair(
publicKey: PUBLIC_KEY,
privateKey: PRIVATE_KEY
)
sdk.contextManager().setKeyPair(PUBLIC_KEY, PRIVATE_KEY);
// Not implemented yet
// Not implemented yet
Get key pair
Returns the stored key pair, or null when either the public or the private key is missing.
- Kotlin
- Java
- Swift
- JavaScript
- C#
- Python
// Returns a KeyPair
val keyPair = sdk.contextManager().getKeyPair()
// Returns a KeyPair
var keyPair = sdk.contextManager().getKeyPair();
// Returns a Crypto.KeyPair
let keyPair = sdk.contextManager().getKeyPair()
// Returns a Crypto.KeyPair
const keyPair = sdk.contextManager().getKeyPair();
// Not implemented yet
// Not implemented yet
Set key pair verified
Marks a public key as verified, meaning it has successfully completed two-factor verification. Pass null to clear the verification.
Is key pair verified compares the value stored here against the current public key, so setting a key pair that does not match clears the verified state in practice.
- Kotlin
- Java
- Swift
- JavaScript
- C#
- Python
sdk.contextManager().setKeyPairVerified(PUBLIC_KEY)
sdk.contextManager().setKeyPairVerified(PUBLIC_KEY);
sdk.contextManager().setKeyPairVerified(publicKey: PUBLIC_KEY)
sdk.contextManager().setKeyPairVerified(PUBLIC_KEY);
// Not implemented yet
// Not implemented yet
Is key pair verified
Checks if the current key pair from the context has been verified.
- Kotlin
- Java
- Swift
- JavaScript
- C#
- Python
val result = sdk.contextManager().isKeyPairVerified()
var result = sdk.contextManager().isKeyPairVerified();
let result = sdk.contextManager().isKeyPairVerified()
const result = sdk.contextManager().isKeyPairVerified();
var result = sdk.GetContextManager().IsKeyPairVerified();
result = sdk.contextManager.is_key_pair_verified()
Is key pair valid
Checks if the current key pair from the context is valid.
- Kotlin
- Java
- Swift
- JavaScript
- C#
- Python
val result = sdk.contextManager().isKeyPairValid()
var result = sdk.contextManager().isKeyPairValid();
let result = sdk.contextManager().isKeyPairValid()
const result = sdk.contextManager().isKeyPairValid();
var result = sdk.GetContextManager().IsKeyPairValid();
result = sdk.contextManager.is_key_pair_valid()
Set operation context
- Kotlin
- Java
- Swift
- JavaScript
- C#
- Python
sdk.contextManager().setOperationContext(
userId = USER_ID,
certificateChain = USER_CERTIFICATE_CHAIN_LIST,
keyPair = KEY_PAIR,
isKeyPairVerified = IS_KEY_PAIR_VERIFIED
)
sdk.contextManager().setOperationContext(USER_ID, USER_CERTIFICATE_CHAIN_LIST, KEY_PAIR, IS_KEY_PAIR_VERIFIED);
sdk.contextManager().setOperationContext(
userId: USER_ID,
certificateChain: USER_CERTIFICATE_CHAIN_LIST,
publicKey: PUBLIC_KEY,
privateKey: PRIVATE_KEY,
isKeyPairVerified: IS_KEY_PAIR_VERIFIED
)
sdk.contextManager().setOperationContext(
"USER_ID",
USER_CERTIFICATE_CHAIN_LIST,
PUBLIC_KEY,
PRIVATE_KEY
);
sdk.GetContextManager().SetOperationContext(
userId: USER_ID,
certificateChain: USER_CERTIFICATE_CHAIN,
publicKey: PUBLIC_KEY,
privateKey: PRIVATE_KEY
);
sdk.contextManager.set_operation_context(
"USER_ID",
"USER_CERTIFICATE_CHAIN_AS_STRING",
"BASE64_PUBLIC_KEY",
"BASE64_PRIVATE_KEY"
)
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. The first check to fail determines the returned state. checkServerInvalidation behaves as described in is cloud auth token invalid or expired.
- Kotlin
- Java
- Swift
- JavaScript
- C#
- Python
// Returns a ContextState
val result = sdk.contextManager().getContextState(true)
// Returns a CompletableFuture<ContextState>
var result = sdk.contextManager().getContextStateAsync(true);
// Returns a ContextState asynchronously
let result = await sdk.contextManager().getContextState(checkServerInvalidation: true)
// Returns a Promise<string>
const result = await sdk.contextManager().getContextState(true);
// Returns a Task<ContextState>
var result = await sdk.GetContextManager().GetContextState(checkServerInvalidation: true);
# Returns a Future[SimpleNamespace]
result = await sdk.contextManager.get_context_state(True)
Clear context
This function removes all stored context fields from the secure storage.
- Kotlin
- Java
- Swift
- JavaScript
- C#
- Python
sdk.contextManager().clearContext()
sdk.contextManager().clearContext();
sdk.contextManager().clearContext()
sdk.contextManager().clearContext();
sdk.GetContextManager().ClearContext();
sdk.contextManager.clear_context()