The XignSys SDK offers a way to determine the state of a given factor associated with a personalized identity manager.
This can be helpful before adding or changing a factor. The
function Personalizer.getAuthenticationFactorState(idmIdentifier:type:)
will return an enum of the type AuthenticationFactorState which can have one of the following states:
notEnrolled - Factor is not enrolled and can be enrolled.enrolled - Factor is enrolled and can be used.revoked - Factor was revoked and cannot be enrolled. For example, the biometric factor can only be enrolled once per
personalization/activation. To re-enroll the factor the personalization/activation must be performed again.unsupported - Factor is unsupported. This is the case for factors that cannot be enrolled on the device or are still
in development.Currently, the following AuthenticationType types are supported across all devices and can be checked:
AuthenticationType.deviceAuthenticationType.pinAuthenticationType.biometricThe example below shows how the state of the AuthenticationType.biometric can be checked and the result be handled.
The needed idmIdentifier can for example be retrieved as described in the
chapter List personalized identity managers.
internal func getAuthenticationFactorState(
idmIdentifier: String
) throws {
// Retrieve the personalizer component that offers this utility function
let personalizer: Personalizer = XignSdk.shared.personalizer
// Checks the state of the biometric factor
let biometricFactorState: AuthenticationFactorState = try personalizer.getAuthenticationFactorState(
idmIdentifier: idmIdentifier,
type: AuthenticatorType.biometric
)
switch biometricFactorState {
case .notEnrolled:
// The factor is currently not enrolled and can be enrolled. The follwoing function can be used to enroll
// the factor:
let authInitData: AuthenticationInitializationData =
try personalizer.startAddAuthenticationFactorSynchronous(
idmIdentifier,
AuthenticatorType.biometric
)
// For further handling please take a look at the chapter `Add Factor` of the `Utility processes`.
case .enrolled:
// The factor is enrolled and ready to use, no further handling is required.
YourImplementation.proceedWithProcess(idmIdentifier: idmIdentifier)
case .revoked:
YourImplementation.showUserHowToSetUpNewBiometricFactor(idmIdentifier: idmIdentifier)
case .unsupported:
// The factor is unsupported and can not be enrolled. Depending on the purpose of implemented check
// either an error dialog can be displayed or the case can silently be ignored.
YourImplementation.showUserInfoDialog()
}
}
internal fun getAuthenticationFactorState(
idmIdentifier: String
) {
// Retrieve the personalizer component that offers this utility function
val personalizer: Personalizer = XignSdk.shared.personalizer
// Checks the state of the biometric factor
val biometricFactorState: AuthenticationFactorState = personalizer.getAuthenticationFactorState(
idmIdentifier = idmIdentifier,
type = AuthenticatorType.BIOMETRIC
)
when (biometricFactorState) {
AuthenticationFactorState.NOT_ENROLLED -> {
// The factor is currently not enrolled and can be enrolled. The follwoing function can be used to enroll
// the factor:
val authInitData: AuthenticationInitializationData =
personalizer.startAddAuthenticationFactorSynchronous(
idmIdentifier,
AuthenticatorType.BIOMETRIC
)
// For further handling please take a look at the chapter `Add Factor` of the `Utility processes`.
}
AuthenticationFactorState.ENROLLED -> {
// The factor is enrolled and ready to use, no further handling is required.
}
AuthenticationFactorState.REVOKED -> {
YourImplementation.showUserHowToSetUpNewBiomectricFactor(idmIdentifier)
}
AuthenticationFactorState.UNSUPPORTED -> {
// The factor is unsupported and can not be enrolled. Depending on the purpose of implemented check
// either an error dialog can be displayed or the case can silently be ignored.
YourImplementation.showUserInfoDialog()
}
}
}