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


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

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


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

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>