Skip to content

Commit a2cc187

Browse files
MoemenMostafaihadeed
authored andcommitted
feat(keychain-touch-id): add KeychainTouchId plugin (#1837)
1 parent 1c6a3a3 commit a2cc187

File tree

1 file changed

+106
-0
lines changed
  • src/@ionic-native/plugins/keychain-touch-id

1 file changed

+106
-0
lines changed
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
import { Injectable } from '@angular/core';
2+
import { Plugin, Cordova, IonicNativePlugin } from '@ionic-native/core';
3+
4+
/**
5+
* @name Keychain Touch Id
6+
* @description
7+
* A cordova plugin adding the iOS TouchID / Android fingerprint to your
8+
* app and allowing you to store a password securely in the device keychain.
9+
*
10+
* @usage
11+
* ```typescript
12+
* import { KeychainTouchId } from '@ionic-native/keychain-touch-id';
13+
*
14+
*
15+
* constructor(private keychainTouchId: KeychainTouchId) { }
16+
*
17+
* ...
18+
*
19+
*
20+
* this.keychainTouchId.isAvailable()
21+
* .then((res: any) => console.log(res))
22+
* .catch((error: any) => console.error(error));
23+
*
24+
* ```
25+
*/
26+
@Plugin({
27+
pluginName: 'KeychainTouchId',
28+
plugin: 'cordova-plugin-keychain-touch-id',
29+
pluginRef: 'plugins.touchid',
30+
repo: 'https://github.com/sjhoeksma/cordova-plugin-keychain-touch-id',
31+
platforms: ['Android', 'iOS']
32+
})
33+
@Injectable()
34+
export class KeychainTouchId extends IonicNativePlugin {
35+
36+
/**
37+
* Check if Touch ID / Fingerprint is supported by the device
38+
*
39+
* @return {Promise<any>} Returns a promise that resolves when there is hardware support
40+
*/
41+
@Cordova()
42+
isAvailable(): Promise<any> {
43+
return;
44+
}
45+
46+
/**
47+
* Encrypts and Saves a password under the key in the device keychain, which can be retrieved after
48+
* successful authentication using fingerprint
49+
*
50+
* @param key {string} the key you want to store
51+
* @param password {string} the password you want to encrypt and store
52+
* @return {Promise<any>} Returns a promise that resolves when there is a result
53+
*/
54+
@Cordova()
55+
save(key: string, passwrod: string): Promise<any> {
56+
return;
57+
}
58+
59+
/**
60+
* Opens the fingerprint dialog, for the given key, showing an additional message. Promise will resolve
61+
* with the password stored in keychain or will resolve an error code, where -1 indicated not available.
62+
*
63+
* @param key {string} the key you want to retrieve from keychain
64+
* @param message {string} a message to the user
65+
* @return {Promise<any>} Returns a promise that resolves when the key value is successfully retrieved or an error
66+
*/
67+
@Cordova()
68+
verify(key: string, message: string): Promise<any> {
69+
return;
70+
}
71+
72+
/**
73+
* Checks if there is a password stored within the keychain for the given key.
74+
*
75+
* @param key {string} the key you want to check from keychain
76+
* @return {Promise<any>} Returns a promise that resolves with success if the key
77+
* is available or failure if key is not
78+
*/
79+
@Cordova()
80+
has(key: string): Promise<any> {
81+
return;
82+
}
83+
84+
/**
85+
* Deletes the password stored under given key from the keychain.
86+
*
87+
* @param key {string} the key you want to delete from keychain
88+
* @return {Promise<any>} Returns a promise that resolves with success if the key
89+
* is deleted or failure if key is not
90+
*/
91+
@Cordova()
92+
delete(key: string): Promise<any> {
93+
return;
94+
}
95+
96+
/**
97+
* Sets the language of the fingerprint dialog
98+
*
99+
* @param locale {string} locale subtag from this list
100+
* https://www.iana.org/assignments/language-subtag-registry/language-subtag-registry
101+
*
102+
*/
103+
@Cordova()
104+
setLocale(locale: string): void { }
105+
106+
}

0 commit comments

Comments
 (0)