Skip to main content
Version: 4.3

IdentityVaultUser

The main class which you can extend in order to implement vault usage.

Typeparam#

must extend DefaultSession

Usage#

interface MyCustomSession extends DefaultSession {
// username & token are inherited
email: string;
age: number;
nicknames: string[];
}
export class IdentityService extends IonicIdentityVaultUser<MyCustomSession> {
constructor(private http: HttpClient, private router: Router, platform: Platform) {
super(platform, {
authMode: AuthMode.BiometricAndPasscode,
restoreSessionOnReady: false,
unlockOnReady: false, // set true to auto prompt the user to unlock when vault is ready
unlockOnAccess: true,
lockAfter: 5000, // lock after 5 seconds in the background
hideScreenOnBackground: true
});
onVaultUnlocked(config: VaultConfig) {
//Route to my home page
}
onVaultLocked(event: LockEvent) {
//Route to my login page
}
}

Methods#

getAuthMode#

Get the AuthMode for the vault.

Returns: Promise<AuthMode>

getBiometricType#

Get the type of biometrics the device supports

Returns: Promise<BiometricType>

the type of biometrics the device supports

getPlugin#

Returns the underlying Plugin Implementation. This can be overriden in the sub class service to allow for a customer browser implementation. Note that when overriding this with a browser implementation you should use the storeValue/getValue functions with the key session to store & retrieve the session as described or by DefaultSession or the interface that extends it.

Usage#

getPlugin(): IonicNativeAuthPlugin {
if (this.platform.is('cordova')) {
return super.getPlugin();
}
// MyCustomerBrowserImplementation must implement the IonicNativeAuthPlugin interface
// make sure getValue('session') & storeValue('session') store & retrieve the session.
return MyCustomBrowserImplementation();
}

Returns: IonicNativeAuthPlugin

getSession#

The stored session data

Returns: Promise<undefined | T>

Get the session from memory (without checking the vault for it)

Returns: Promise<undefined | T>

getVault#

Get raw access to the underlying vault api

Returns: Promise<IdentityVault>

hasStoredSession#

Check if there are any saved sessions in the vault

Returns: Promise<boolean>

isBiometricsAvailable#

Check whether or not biometrics is supported by the device and has been configured by the current user of the device

Returns: Promise<boolean>

whether or not biometrics is available

isBiometricsEnabled#

Check whether or not biometrics is enabled on the vault

Returns: Promise<boolean>

whether or not biometrics is enabled

isBiometricsSupported#

Check whether or not biometrics is supported by the device

Returns: Promise<boolean>

whether or not biometrics is supported

isPasscodeEnabled#

Check if passcode authentication is enabled for the vault

Returns: Promise<boolean>

whether or not the passcode is enabled

isSecureStorageModeEnabled#

Check if AuthMode.SecureStorage is enabled for the vault

Returns: Promise<boolean>

whether or not the secure storage mode is enabled

lockOut#

Lock the user out without clearing their secure session information from the vault

Returns: Promise<void>

login#

Login a new session for the user. This method will clear the vault & any stored PIN for previously stored sessions.

Parameters#

NameTypeDescription
sessionTthe session to store
authMode?AuthMode-

Returns: Promise<void>

logout#

Log the user out entirely, and forget any stored authentication tokens

Returns: Promise<void>

onConfigChange#

Called when there has been a configuration change in the vault

Parameters#

NameType
stateVaultConfig

Returns: any

onPasscodeRequest#

Called when attempting passcode unlock to allow for user defined passcode prompts.

Parameters#

NameTypeDescription
isPasscodeSetRequestbooleanWhether or not this is a request to set the passcode.

Returns: Promise<string | void>

  • a string to use as the passcode of undefined to use native prompts

onSessionRestoreError#

Called when the session fails to auto restore

Parameters#

NameTypeDescription
errVaultErrorThe VaultError or that occurred.

Returns: any

onSessionRestored#

Called when the session object is restored.

Parameters#

NameTypeDescription
sessionTThe DefaultSession or user defined session that occurred.

Returns: any

onSetupError#

Called when there is an error during vault setup

Parameters#

NameTypeDescription
errorVaultErrorThe VaultError that occurred.

Returns: any

onUnlockOnReadyError#

Called when the automatically unlocking the vault after it is ready fails.

Parameters#

NameTypeDescription
errVaultErrorThe VaultError or that occurred.

Returns: any

onVaultLocked#

Called when the vault has been locked

Parameters#

NameTypeDescription
eventLockEventThe data about the lock event LockEvent

Returns: any

onVaultReady#

Called when the vault is ready

Parameters#

NameType
stateVaultConfig

Returns: any

  • A promise that resolves when the vault is successfully configured and available.

onVaultUnlocked#

Called when the vault has been unlocked

Parameters#

NameType
stateVaultConfig

Returns: any

ready#

Promise ensuring the user vault is ready to be accessed or denoting an error in setup;

Returns: Promise<void>

  • A promise that resolves when the vault is succesfully configured and available.

restoreSession#

Restore the session from the vault

Returns: Promise<undefined | T>

saveSession#

Store the session to the vault

Parameters#

NameTypeDescription
sessionTthe session to store

Returns: Promise<void>

setAuthMode#

Set the AuthMode for the vault. The vault must be unlocked or this will throw an error.

Throws#

VaultError - If the vault is locked or the mode is unavailale due to device hardware

Parameters#

NameTypeDescription
authModeAuthModeThe AuthMode to use.

Returns: Promise<void>

setBiometricsEnabled#

Enable/Disable Biometric authentication

Throws#

VaultError - if biometrics is unavailable or the vault is locked

Parameters#

NameTypeDescription
isBiometricsEnabledbooleanwhether or not biometrics should be enabled

Returns: Promise<void>

setHideScreenOnBackground#

Set whether or not the screen will be obscured in app switcher mode

Parameters#

NameType
enabledboolean

Returns: Promise<void>

void

setPasscode#

Set or change the passcode for the user This will call the onPasscodeRequest handler to allow for user defined passcode prompt. You can get more fine grain contol using the IdentityVault directly by calling getVault

Throws#

VaultError - if the vault is locked, passcode is disabled, user canceled pin prompt, or pin was mismatched

Returns: Promise<void>

setPasscodeEnabled#

Enable/Disable passcode authentication. This will cause setPasscode to fire if passcode setup is required causing the onPasscodeRequest handler to fire to allow for user defined passcode prompt. You can get more fine grain contol using the IdentityVault directly by calling getVault

Throws#

VaultError - if the vault is locked

Parameters#

NameTypeDescription
isPasscodeEnabledbooleanwhether or not passcode should be enabled

Returns: Promise<void>

unlock#

Unlock the user's vault using the AuthMode configured for the vault or the override passed in to the call. This will call the onPasscodeRequest handler if the specified AuthMode allows for it to allow for user defined passcode prompt You can get more fine grain contol using the IdentityVault directly by calling getVault

Parameters#

NameType
authMode?AuthMode

Returns: Promise<void>