ti.identity
A collection of API's to authenticate with your device: Keychain/Keystore, Touch ID and Face ID
Install
A module is a zip you unpack in your project. There is no installer command yet - a ti module install is planned but does not exist today, so the steps below are the ones that work.
1. Download the release archive
2. Unpack it at your project root
cd /path/to/your-project unzip ~/Downloads/ti.identity-android-3.2.0.zipThe archive already contains the full path, so it lands in place:
- modules/android/ti.identity/3.2.0/
3. Add it to
tiapp.xml<modules> <module platform="android" version="3.2.0">ti.identity</module> </modules>The
platformattribute is the packager’s name for the platform, which isiphonefor iOS - the same word the archive uses in its own path.4. Require it from your app
const mod = require('ti.identity');
Manifest
Android 3.1.1
- Minimum SDK
- 9.0.0
- Module API version
- 4
- Architectures
- arm64-v8a, armeabi-v7a, x86, x86_64
- GUID
- c3d987a8-8bd4-42cd-a3e4-2a75952d1ea0
- Author
- Hans Knoechel
- License
- Specify your license
- Copyright
- Copyright (c) 2017 by Your Company
API reference
Compiled from tidev/titanium-identity@3.2.0 (83431fe).
Modules.Identity
Extends Titanium.Module
Allows a Titanium application to use the iOS Touch ID / Face ID authentication mechanism.
Touch ID / Face ID are security mechanisms that use biometric sensors to authenticate the user.
Requirements
The Identity module is available with the Titanium SDK starting with Release 6.3.0. This module only works with devices running iOS 8 and later.
Getting Started
Add the module as a dependency to your application by adding a <module> item to the
[modules](api:Modules) element of your tiapp.xml file:
<ti:app>
<!-- ... -->
[modules](api:Modules)
<module platform="iphone">ti.identity</module>
</modules>
<!-- ... -->
</ti:app>
Use require() to access the module from JavaScript:
var Identity = require('ti.identity');
The Identity variable is a reference to the module. Make API calls using this reference:
Identity.authenticate({
reason: 'Verify to modify personal settings',
callback: function(e) {
Ti.API.info(e);
}
});
Lifetime Notes (iOS-only)
The current context will, once evaluated, be used until it's instance gets released or invalidated. You can you use the Modules.Identity.invalidate method to force the user to be prompted every time a new authentication is triggered. On iOS 9 and later, this can also be called to cancel a current evaluation of an auth-context, e.g. to hide the auth-dialoag.
Distinguish between Touch ID and Face ID
Use the Modules.Identity.biometryType to receive the currently used biometry type. See an example of using the property to create a personalized interface when using Touch ID and Face ID:
var authPhrase = 'Unknown';
if (TiIdentity.biometryType === TiIdentity.BIOMETRY_TYPE_FACE_ID) { // Face ID
authPhrase = 'Face ID';
} else if (TiIdentity.biometryType === TiIdentity.BIOMETRY_TYPE_TOUCH_ID) { // Touch ID
authPhrase = 'Touch ID';
}
Face ID Requirements (iOS only)
For Face ID to work properly, you need to add a <key> item to the
<plist> element of your tiapp.xml file:
<ti:app>
<!-- ... -->
<ios>
<!-- ... -->
<plist>
<dict>
<key>NSFaceIDUsageDescription</key>
[string](api:Global.String)Why you need Face ID.</string>
</dict>
</plist>
<!-- ... -->
</ios>
<!-- ... -->
</ti:app>
Native Keychain Integration
For more infos regarding the keychain integration, check the "KeychainItem" "documentation.
Sample Application
The module contains a sample application in the
<TITANIUM_SDK_HOME>/modules/iphone/ti.identity/<VERSION>/example/ folder.
Properties 40
Constraint logic operation - When using more than one constraint, all must be satisfied.
Security: Application provided password for data encryption key generation. This is not a constraint but additional item encryption mechanism.
Constraint - Device passcode.
Constraint logic operation - When using more than one constraint, at least one of them must be satisfied.
Create access control for private key operations (i.e. sign operation).
Constraint - Touch ID (any finger). Touch ID must be available and at least one finger must be enrolled. Item is still accessible by Touch ID even if fingers are added or removed.
Constraint - Touch ID from the set of currently enrolled fingers. Touch ID must be available and at least one finger must be enrolled. When fingers are added or removed, the item is invalidated.
User presence policy using Touch ID, Face ID or Passcode. Touch ID / Face ID does not have to be available or enrolled. Item is still accessible by Touch ID / Face ID even if fingers are added or removed.
Item data can only be accessed once the device has been unlocked after a restart. This is recommended for items that need to be accesible by background applications. Items with this attribute will migrate to a new device when using encrypted backups.
Item data can only be accessed once the device has been unlocked after a restart. This is recommended for items that need to be accessible by background applications. Items with this attribute will never migrate to a new device, so after a backup is restored to a new device these items will be missing.
Item data can always be accessed regardless of the lock state of the device. This is not recommended for anything except system use. Items with this attribute will migrate to a new device when using encrypted backups.
Value is a Number on Android, a String on iOS.
Item data can always be accessed regardless of the lock state of the device. This option is not recommended for anything except system use. Items with this attribute will never migrate to a new device, so after a backup is restored to a new device, these items will be missing.
Value is a Number on Android, a String on iOS.
Item data can only be accessed while the device is unlocked. This class is only available if a passcode is set on the device. This is recommended for items that only need to be accessible while the application is in the foreground. Items with this attribute will never migrate to a new device, so after a backup is restored to a new device, these items will be missing. No items can be stored in this class on devices without a passcode. Disabling the device passcode will cause all items in this class to be deleted.
Value is a Number on Android, a String on iOS.
Item data can only be accessed while the device is unlocked. This is recommended for items that only need be accesible while the application is in the foreground. Items with this attribute will migrate to a new device when using encrypted backups.
Item data can only be accessed while the device is unlocked. This is recommended for items that only need be accesible while the application is in the foreground. Items with this attribute will never migrate to a new device, so after a backup is restored to a new device, these items will be missing.
Device owner was authenticated using a biometric method.
A biometric authentication is required. If there are no biometrics available or not enrolled, policy evaluation will fail. If Touch ID / Face ID is locked out, passcode is required as the first step to unlock with Touch ID.
Touch ID authentication dialog contains a cancel button with default title
"Cancel" which can be customized using cancelTitle property and a fallback
button with default title "Enter Password" which can be customized using
fallbackTitle property. Fallback button is initially hidden and shows up
after first unsuccessful Touch ID attempt. Tapping cancel button or fallback
button causes evaluatePolicy call to fail, returning a distinct error code.
Biometric authentication will get locked after 5 unsuccessful attempts. After that, users have to unlock it by entering passcode.
Device owner was authenticated using a biometric method or the Apple Watch.
Device owner was authenticated by Touch ID or device passcode.
Touch ID or passcode authentication is required. If Touch ID is available, enrolled and not locked out, user is asked for it first, otherwise they are asked to enter device passcode. If passcode is not enabled, policy evaluation will fail.
Touch ID authentication dialog behaves similarly as the one used by
AUTHENTICATION_POLICY_BIOMETRICS. However, instead of "Enter Password"
button there is "Enter Passcode" button which, when tapped, switches the
authentication method and allows users to enter device passcode.
Passcode authentication will get locked after 6 unsuccessful attempts with progressively increased backoff delay.
Device owner was authenticated using the Apple Watch.
Sets the global authentication policy used in this Touch ID / Face ID context.
You should set this property before checking the availability or
starting the authentication. By default, AUTHENTICATION_POLICY_BIOMETRICS
will be used to authenticate using the Touch ID / Face ID sensor only. Using the
AUTHENTICATION_POLICY_PASSCODE constant will still try to authenticate
with Touch ID / Face ID first and use the passcode as the fallback.
Default: Modules.Identity.AUTHENTICATION_POLICY_BIOMETRICS
The device supports Face ID.
Used as a return-value for Modules.Identity.biometryType.
The device does not support biometry.
Used as a return-value for Modules.Identity.biometryType.
The device supports Touch ID.
Used as a return-value for Modules.Identity.biometryType.
Indicates the type of the biometry supported by the device.
This property is set only when Modules.Identity.isSupported succeeds for a biometric policy. The default value is Modules.Identity.BIOMETRY_TYPE_NONE.
Default: Modules.Identity.BIOMETRY_TYPE_NONE
Constant indicating that the app cancelled authentication.
Constant indicating that the authentication was not successful.
Authentication was not successful, because there were too many failed biometry attempts and biometry is now locked. Passcode is required to unlock biometry, e.g. evaluating Modules.Identity.authenticate will ask for passcode as a prerequisite.
Authentication could not start, because biometry is not available on the device.
Authentication could not start, because biometry has no enrolled identities.
Constant indicating that there is an invalid context.
Constant indicating that the passcode is not set for the device.
Constant indicating that iOS cancelled authentication, for example, if another application enters the foreground.
Deprecated since 10.0.0
This constant has deprecated in iOS. Use <Modules.Identity.ERROR_BIOMETRY_LOCKOUT> instead.
Constant indicating that Touch ID has locked out. Note: This constant has been deprecated for iOS 11 and later. Use Modules.Identity.ERROR_BIOMETRY_LOCKOUT for apps targeting iOS 11 and later.
Deprecated since 10.0.0
Use <Modules.Identity.ERROR_BIOMETRY_NOT_AVAILABLE> instead.
Constant indicating that Touch ID is not available on the device. Note: This constant has been deprecated for iOS 11 and later. Use Modules.Identity.ERROR_BIOMETRY_NOT_AVAILABLE for apps targeting iOS 11 and later.
Deprecated since 10.0.0
Use <Modules.Identity.ERROR_BIOMETRY_NOT_ENROLLED> instead.
Constant indicating that Touch ID does not have any enrolled fingerprints. Note: This constant has been deprecated for iOS 11 and later. Use <Modules.Identity.ERROR_BIOMETRY_NOT_ENROLLED for apps targeting iOS 11 and later.
Constant indicating that the user canceled authentication.
Constant indicating that the user tapped the fallback button to enter their passcode.
Returns true if the has biometric hardware to perform face authentication
Returns true if the device has biometric hardware to detect a fingerprint.
Returns true if the device has biometric hardware to perform iris authentication.
Methods 5
Initiates the biometric authentication process.
A special note for Android:
When you call this method in Android, it will either authenticate the fingerprint or it will fallback to the device's password, pin or pattern which is the case when biometric means of identification is not available. If you provide an incorrect fingerprint and receive an error message "Unable to recognize fingerprint", do not call authenticate. Instead, get the user to try again. If you call authenticate, it will end up in a bad state. This flow will be improved in the next update for Android.
| Parameters | Type | Description |
|---|---|---|
| params | IdentityAuthenticationType | Dictionary of arguments passed to the method, e.g. the reason to autheicate and the callback. 9 fields
|
Create KeychainItem.
| Parameters | Type | Description |
|---|---|---|
| params | KeychainItemType | Dictionary of arguments passed to the method. 7 fields
|
Checks to see if device is configured for biometric authentication.
On Android this takes into account the authenticationPolicy.
Example:
var Identity = require("ti.identity");
var result = Identity.deviceCanAuthenticate();
if (!result.canAuthenticate) {
alert('Message: ' + result.error + '\nCode: ' + result.code);
} else {
alert('Device can authenticate');
}
invalidate
since 6.1.0Invalidates the current biometric dialog.
The context is invalidated automatically when it is (auto)released.
This method allows invalidating it manually while it is still in scope. Invalidation terminates any existing policy evaluation and the respective call will fail with Modules.Identity.ERROR_APP_CANCELLED. After the context has been invalidated, it can not be used for policy evaluation and an attempt to do so will fail with Modules.Identity.ERROR_INVALID_CONTEXT.
See the "Lifetime Notes (iOS-only)" paragraph in the module paragraph for more infos.
Determines if the current device supports Touch ID or Face ID.
This module is only supported on Android 6.0 or newer. So, this method always returns
false on older versions of Android.
Modules.Identity.KeychainItem
Extends Titanium.Module
Represents a keychain item to communicate with the native iOS Keychain and Android Keystore.
The following example demonstrates the basic usage to save, read and delete values with the native iOS Keychain and/or Android Keystore:
var Identity = require('ti.identity');
// Create a keychain item
var keychainItem = Identity.createKeychainItem({
identifier: 'password'
});
// Triggered when the keychain item was successfully saved
keychainItem.addEventListener('save', function(e) {
// Notify the user that the operation succeeded or failed
});
// Write to the keychain
keychainItem.save('s3cr3t_p4$$w0rd');
For advanced security options, you can specify accessibility mode to the keychain that will be applied when writing items to the keychain, for example:
var Identity = require('ti.identity');
// Create a keychain item
var keychainItem = Identity.createKeychainItem({
identifier: 'mypassword',
service: 'my_service', // iOS only. Defaults to 'ti.touchid' for backwards compatibility
accessGroup: '<YOUR-TEAM-ID>.com.appc.identitytest',
accessibilityMode: Identity.ACCESSIBLE_WHEN_PASSCODE_SET_THIS_DEVICE_ONLY,
accessControlMode: Identity.ACCESS_CONTROL_TOUCH_ID_ANY,
// Pass more native options to the keychain. Since there are hundrets of them,
// look up the value of the constant and pass it here. Example:
options: {
// The value of kSecUseOperationPrompt
'u_OpPrompt': 'Please authenticate yourself!'
}
});
Methods 5
fetchExistence
since 6.1.0Asynchronously determines whether or not a value of the specified identifier exists in the keychain item.
| Parameters | Type | Description |
|---|---|---|
| result | Callback | Use the event key |
read
since 6.1.0Reads an existing value to the native keychain.
The Modules.Identity.KeychainItem.read event is triggered when
an item is fetched. If an error occurs, the error key informs you
about the exact error.
reset
since 6.1.0Resets an existing value from the native keychain.
The Modules.Identity.KeychainItem.reset event is triggered when
a new item is saved. If an error occurs, the error key informs you
about the exact error.
save
since 6.1.0Saves a new value to the native keychain.
The Modules.Identity.KeychainItem.save event is triggered when
a new item is saved. If an error occurs, the error key informs you
about the exact error.
On Android this will also overwrite any existing value.
| Parameters | Type | Description |
|---|---|---|
| value | String | The value to be stored in the native keychain. |
update
since 6.1.0Updates an existing value to the native keychain.
The Modules.Identity.KeychainItem.update event is triggered when
an item is updated. If an error occurs, the error key informs you
about the exact error.
| Parameters | Type | Description |
|---|---|---|
| value | String | The value to be stored in the native keychain. |
Events 4
read
since 6.1.0Triggered when a new keychain item is read (or an error occurred).
reset
since 6.1.0Triggered when a new keychain item is reset (or an error occurred).
save
since 6.1.0Triggered when a new keychain item is saved (or an error occurred).
update
since 6.1.0Triggered when a new keychain item is updated (or an error occurred).