From 6194299dfe383e9022c7cd8ba27ebaac957af0a6 Mon Sep 17 00:00:00 2001 From: Andrew Crites Date: Wed, 26 Apr 2017 12:24:56 -0400 Subject: [PATCH 1/2] feat(keychain): adding keychain plugin ionic-native for cordova ios keychain plugin --- src/@ionic-native/plugins/keychain/index.ts | 94 +++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 src/@ionic-native/plugins/keychain/index.ts diff --git a/src/@ionic-native/plugins/keychain/index.ts b/src/@ionic-native/plugins/keychain/index.ts new file mode 100644 index 0000000000..8f013f78e0 --- /dev/null +++ b/src/@ionic-native/plugins/keychain/index.ts @@ -0,0 +1,94 @@ +import { Injectable } from '@angular/core'; +import { Cordova, Plugin } from '@ionic-native/core'; + + +/** + * @name Keychain + * @description + * Get and set data in the iOS Keychain + * + * Requires Cordova plugin: `cordova-plugin-ios-keychain`. For more info, please see the [Keychain plugin docs](https://github.com/driftyco/cordova-plugin-ios-keychain). + * + * @usage + * ```typescript + * import { Keychain } from '@ionic-native/keychain'; + * + * constructor(private keychain: Keychain) { } + * + * ... + * + * this.keychain.set(key, value).then(() => { + * this.keychain.get(key) + * .then(value => console.log('Got value', value)) + * .catch(err => console.error('Error getting', err)); + * }) + * .catch(err => console.error('Error setting', err)); + * ``` + */ +@Plugin({ + pluginName: 'Keychain', + plugin: 'cordova-plugin-ios-keychain', + pluginRef: 'window.Keychain', + repo: 'https://github.com/driftyco/cordova-plugin-ios-keychain/', + platforms: ['iOS'] +}) +@Injectable() +export class Keychain { + + /** + * Retrieves a value for a key + * + * @param {string} key the key to retrieve + * @param {string} TouchIDMessage the message to show underneath the TouchID prompt (if any) + */ + @Cordova({ + callbackOrder: 'reverse' + }) + get(key: string, touchIDMessage: string): Promise { return; } + + /** + * Sets a value for a key + * + * @param {string} key the key to set + * @param {string|number|boolean} value the value to set + * @param {boolean} useTouchID whether to store the value with security such that TouchID will be needed to grab it + */ + @Cordova({ + callbackOrder: 'reverse' + }) + set(key: string, value: string|number|boolean, useTouchID: boolean): Promise { return; } + + /** + * Gets a JSON value for a key + * + * @param {string} key the key to retrieve + * @param {string} TouchIDMessage the message to show underneath the TouchID prompt (if any) + */ + @Cordova({ + callbackOrder: 'reverse' + }) + getJson(key: string, touchIDMessage: string): Promise { return; } + + /** + * Sets a JSON value for a key + * + * @param {string} key the key to set + * @param {any} value the value to set + * @param {boolean} Wether to store the value with security such that TouchID will be needed to grab it + */ + @Cordova({ + callbackOrder: 'reverse' + }) + setJson(key: string, obj: any, useTouchId: boolean): Promise { return; } + + /** + * Removes a value for a key + * + * @param {string} key the key to remove + */ + @Cordova({ + callbackOrder: 'reverse' + }) + remove(key: string): Promise { return; } + +} From ade3eeced02bf3fea0d7d31e2b22ff5262621fae Mon Sep 17 00:00:00 2001 From: Andrew Crites Date: Wed, 26 Apr 2017 12:26:40 -0400 Subject: [PATCH 2/2] feat(keychain): make touchID params optional in type def --- src/@ionic-native/plugins/keychain/index.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/@ionic-native/plugins/keychain/index.ts b/src/@ionic-native/plugins/keychain/index.ts index 8f013f78e0..9d00021d6b 100644 --- a/src/@ionic-native/plugins/keychain/index.ts +++ b/src/@ionic-native/plugins/keychain/index.ts @@ -44,7 +44,7 @@ export class Keychain { @Cordova({ callbackOrder: 'reverse' }) - get(key: string, touchIDMessage: string): Promise { return; } + get(key: string, touchIDMessage?: string): Promise { return; } /** * Sets a value for a key @@ -56,7 +56,7 @@ export class Keychain { @Cordova({ callbackOrder: 'reverse' }) - set(key: string, value: string|number|boolean, useTouchID: boolean): Promise { return; } + set(key: string, value: string|number|boolean, useTouchID?: boolean): Promise { return; } /** * Gets a JSON value for a key @@ -67,7 +67,7 @@ export class Keychain { @Cordova({ callbackOrder: 'reverse' }) - getJson(key: string, touchIDMessage: string): Promise { return; } + getJson(key: string, touchIDMessage?: string): Promise { return; } /** * Sets a JSON value for a key @@ -79,7 +79,7 @@ export class Keychain { @Cordova({ callbackOrder: 'reverse' }) - setJson(key: string, obj: any, useTouchId: boolean): Promise { return; } + setJson(key: string, obj: any, useTouchId?: boolean): Promise { return; } /** * Removes a value for a key