IdentityVaultUser
The main class which you can extend in order to implement vault usage.
Typeparam
must extend DefaultSession
Usage
_28interface MyCustomSession extends DefaultSession {_28 // username & token are inherited_28 email: string;_28 age: number;_28 nicknames: string[];_28}_28_28export class IdentityService extends IonicIdentityVaultUser<MyCustomSession> {_28_28constructor(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
_10getPlugin(): 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
Name | Type | Description |
---|---|---|
session | T | the 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
Name | Type |
---|---|
state | VaultConfig |
Returns: any
onPasscodeRequest
Called when attempting passcode unlock to allow for user defined passcode prompts.
Parameters
Name | Type | Description |
---|---|---|
isPasscodeSetRequest | boolean | Whether 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
Name | Type | Description |
---|---|---|
err | VaultError | The VaultError or that occurred. |
Returns: any
onSessionRestored
Called when the session object is restored.
Parameters
Name | Type | Description |
---|---|---|
session | T | The DefaultSession or user defined session that occurred. |
Returns: any
onSetupError
Called when there is an error during vault setup
Parameters
Name | Type | Description |
---|---|---|
error | VaultError | The VaultError that occurred. |
Returns: any
onUnlockOnReadyError
Called when the automatically unlocking the vault after it is ready fails.
Parameters
Name | Type | Description |
---|---|---|
err | VaultError | The VaultError or that occurred. |
Returns: any
onVaultLocked
Called when the vault has been locked
Parameters
Name | Type | Description |
---|---|---|
event | LockEvent | The data about the lock event LockEvent |
Returns: any
onVaultReady
Called when the vault is ready
Parameters
Name | Type |
---|---|
state | VaultConfig |
Returns: any
- A promise that resolves when the vault is successfully configured and available.
onVaultUnlocked
Called when the vault has been unlocked
Parameters
Name | Type |
---|---|
state | VaultConfig |
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
Name | Type | Description |
---|---|---|
session | T | the 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
Name | Type | Description |
---|---|---|
authMode | AuthMode | The AuthMode to use. |
Returns: Promise<void>
setBiometricsEnabled
Enable/Disable Biometric authentication
Throws
VaultError - if biometrics is unavailable or the vault is locked
Parameters
Name | Type | Description |
---|---|---|
isBiometricsEnabled | boolean | whether or not biometrics should be enabled |
Returns: Promise<void>
setHideScreenOnBackground
Set whether or not the screen will be obscured in app switcher mode
Parameters
Name | Type |
---|---|
enabled | boolean |
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
Name | Type | Description |
---|---|---|
isPasscodeEnabled | boolean | whether 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
Name | Type |
---|---|
authMode? | AuthMode |
Returns: Promise<void>