As mentioned earlier, the SDK is designed as a singleton and hence can not be instantiated multiple times. Also, trying
to initialize it again after it has already been set up will result in an error. But since some legitimate use cases
require the SDK to be deinitialized, a corresponding function XignSdk.deinitialize is provided.
This function can be used to remove a previously set instance and optionally delete all persistent SDK data as well. It can be used to change the configuration of the SDK without removing any data, for example to include a service configuration that has not been loaded earlier or to offer the user a quick way to depersonalize any XignIn-Manager without the need to select them in case the app supports the usage of multiple identity managers.
After calling this function, the old instance of XignSdk must no longer be used or referenced. Note that using an
invalidated instance can cause unexpected behavior and errors. After a reset, the XignSdk must be reinitialized before
it can be used again.
Warning: If
wipePersistentDatais set totrueall cryptography key are deleted as well. Meaning that if you are using the public cryptography functions of theCryptoManagerto secure your data you can no longer decrypt your data. Make sure to decrypt those data before resetting the SDK.
The following examples shows how the deinitialize function could be used to offer a complete or partial app reset:
private func resetSDK() {
// Ask the user whether to reset the app completely or to keep app data
// such as user settings
let isToBeResetCompletely: Bool = YourImplementation.askUserForReset()
// Reset the SDK and remove all persistent data, e.g. all personalizations
do {
try XignSdk.deinitialize(wipePersistentData: true)
} catch {
// Handle errors
}
// Remove the app's persistent data as well if the user wishes
if isToBeResetCompletely {
YourImplementation.resetAppPersistentData()
}
}
private fun resetSDK(context: Context) {
// Ask the user whether to reset the app completely or to keep app data
// such as user settings
val isToBeResetCompletely: Boolean = YourImplementation.askUserForReset()
// Reset the SDK and remove all persistent data, e.g. all personalizations
try {
XignSdk.deinitialize(context = context, wipePersistentData = true)
} catch (t: Throwable) {
// Handle errors
}
// Remove the app's persistent data as well if the user wishes
if (isToBeResetCompletely) {
YourImplementation.resetAppPersistentData()
}
}
Similar to the example in the section ServiceConfigurations, the following example shows how the configuration of the SDK can be changed by deinitializing it first and reinitializing it with a new configuration.
private func resetForReconfiguration(application: UIApplication) throws {
// Remove the old SDK instance
try XignSdk.deinitialize(wipePersistentData: false)
// Create the new configuration
let sdkConfig: XignSdkConfig = try XignSdkConfig.with { builder in
// add custom key material for on-premise XignIn-Managers
try builder.addServiceConfiguration(
clientId: "92d763f9-034c-44d8-bb2b-4b01b73d5941",
tokenUrl: URL(string: "https://sdk.xignin.dev/api/rp/token")!,
statusUrl: URL(string: "https://sdk.xignin.dev/api/rp/state/check")!,
redirectUrl: URL(string: "https://localhost/")!,
loginUri: URL(string: "https://localhost/")!,
serviceName: "SDK-InApp-EC-Symmetric-Service"
)
// add more configurations if needed
// ...
}
try XignSdk.initialize(application: application, config: sdkConfig)
// After a successful initialization the instance of
// the XignSdk class can be accessed as usual:
let xignSdk: XignSdk = XignSdk.shared
// Important: the old instance of `XignSdk` must no longer be used
// or referenced since this can lead to unexpected behavior!
}
private fun resetForReconfiguration(context: Context) {
// Remove the old SDK instance
XignSdk.deinitialize(context = context, wipePersistentData = false)
// Create the new configuration
val sdkConfig: XignSdkConfig = XignSdkConfig.with { builder ->
// add custom key material for on-premise XignIn-Managers
builder.addServiceConfiguration(
clientId = "92d763f9-034c-44d8-bb2b-4b01b73d5941",
tokenUrl = URL("https://sdk.xignin.dev/api/rp/token"),
statusUrl = URL("https://sdk.xignin.dev/api/rp/state/check"),
redirectUrl = URL("https://localhost/"),
loginUri = URL("https://localhost/"),
serviceName = "SDK-InApp-EC-Symmetric-Service"
)
// add more configurations if needed
// ...
}
XignSdk.initialize(context = context, config = sdkConfig)
// After a successful initialization the instance of
// the XignSdk class can be accessed as usual:
val xignSdk: XignSdk = XignSdk.shared
// Important: the old instance of `XignSdk` must no longer be used
// or referenced since this can lead to unexpected behavior!
}