Installation
Follow these steps to install Identity Vault into your app.
Installation
If you have not already setup Ionic Enterprise in your app, follow the one-time setup steps.
Next, install the plugin:
- Capacitor
- Cordova
npm install @ionic-enterprise/identity-vault
npx cap sync
ionic cordova plugin add @ionic-enterprise/identity-vault
Update the native project config files:
_10// iOS - Info.plist_10<key>NSFaceIDUsageDescription</key>_10<string>Use Face ID to authenticate yourself and login</string>_10_10// Android - No additional changes needed
Configuring the Vault
The IonicIdentityVaultUser
class takes a generic session type which represents the type of the session you'll store in the vault. You can use the DefaultSession or extend the class to create a custom session. In the constructor of your Identity
service, the vault is configured by providing options to the super()
call:
_35interface MyCustomSession extends DefaultSession {_35 // username & token are inherited_35 email: string;_35 age: number;_35 nicknames: string[];_35}_35_35export class IdentityService extends IonicIdentityVaultUser<MyCustomSession> {_35_35constructor(private http: HttpClient, private router: Router, platform: Platform) {_35 super(platform, {_35 authMode: AuthMode.BiometricAndPasscode, // Use biometrics auth with passcode fallback_35 restoreSessionOnReady: false, // whether or not to immediately attempt to restore the session when the vault is ready_35 unlockOnReady: false, // set true to auto prompt the user to unlock when vault is ready_35 unlockOnAccess: true, // set to true to auto prompt the user to unlock on first read access_35 lockAfter: 5000, // lock after 5 seconds in the background_35 hideScreenOnBackground: true // when in app launcher mode hide the current screen and display the splashscreen_35 });_35_35 onVaultUnlocked(config: VaultConfig) {_35 //Route to my home page_35 }_35_35 onVaultLocked() {_35 //Route to my login page_35 }_35_35 async onPasscodeRequest(isPasscodeSetRequest: boolean) {_35 // Display a custom Passcode prompt and return the passcode as a string_35 // or return undefined to use the build in native prompts. isPasscodeSetRequest_35 // is true when attempting to set a new passcode on the vault, you can use_35 // it to do something like prompt the user twice for the pin._35 }_35_35}