Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ionic Native Keychain #1420

Merged
merged 2 commits into from
Apr 27, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 94 additions & 0 deletions src/@ionic-native/plugins/keychain/index.ts
Original file line number Diff line number Diff line change
@@ -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<any> { 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<any> { 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<any> { 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<any> { return; }

/**
* Removes a value for a key
*
* @param {string} key the key to remove
*/
@Cordova({
callbackOrder: 'reverse'
})
remove(key: string): Promise<any> { return; }

}