-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(secure-storage): Add Secure Storage Wrapper (#347)
* Add SecureStorage plugin. * Add SecureStorage plugin. * Added create() and removed init() to provide more consistency to ionic-native plugins. Edited comments to reflect changes. * Removed init and comment edit.
- Loading branch information
Showing
2 changed files
with
95 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import { CordovaInstance, Plugin } from './plugin'; | ||
|
||
declare var cordova: any; | ||
|
||
/** | ||
* @name Secure Storage | ||
* @description | ||
* This plugin gets, sets and removes key,value pairs from a device's secure storage. | ||
* | ||
* Requires Cordova plugin: `cordova-plugin-secure-storage`. For more info, please see the [Cordova Secure Storage docs](https://github.com/Crypho/cordova-plugin-secure-storage). | ||
* | ||
* @usage | ||
* | ||
* ```typescript | ||
* import { SecureStorage } from 'ionic-native'; | ||
* | ||
* let secureStorage: SecureStorage = new SecureStorage(); | ||
* secureStorage.create('my_store_name') | ||
* .then( | ||
* () => console.log('Success'), | ||
* error => console.log(error); | ||
* ); | ||
* | ||
* secureStorage.get('myitem') | ||
* .then( | ||
* data => console.log(data), | ||
* error => console.log(error) | ||
* ); | ||
* | ||
* secureStorage.set('myitem', 'myvalue') | ||
* .then( | ||
* data => console.log(data), | ||
* error => console.log(error) | ||
* ); | ||
* | ||
* secureStorage.remove('myitem') | ||
* .then( | ||
* data => console.log(data), | ||
* error => console.log(error) | ||
* ); | ||
* ``` | ||
*/ | ||
@Plugin({ | ||
plugin: 'cordova-plugin-secure-storage', | ||
pluginRef: 'plugins.securestorage', | ||
repo: 'https://github.com/Crypho/cordova-plugin-secure-storage', | ||
platforms: ['Android', 'iOS', 'Windows Phone', 'Browser'] | ||
}) | ||
export class SecureStorage { | ||
|
||
private _objectInstance: any; | ||
|
||
constructor() {} | ||
|
||
/** | ||
* Creates a namespaced storage. | ||
* @param store {string} | ||
*/ | ||
create(store: string): Promise<any> { | ||
return new Promise((res, rej) => { | ||
this._objectInstance = new cordova.plugins.SecureStorage(res, rej, store); | ||
}); | ||
} | ||
|
||
/** | ||
* Gets a stored item | ||
* @param reference {string} | ||
*/ | ||
@CordovaInstance({ | ||
callbackOrder: 'reverse' | ||
}) | ||
get(reference: string): Promise<any> { return; } | ||
|
||
/** | ||
* Stores a value | ||
* @param reference {string} | ||
* @param value {string} | ||
*/ | ||
@CordovaInstance({ | ||
callbackOrder: 'reverse' | ||
}) | ||
set(reference: string, value: string): Promise<any> { return; } | ||
|
||
/** | ||
* Removes a single stored item | ||
* @param reference {string} | ||
*/ | ||
@CordovaInstance({ | ||
callbackOrder: 'reverse' | ||
}) | ||
remove(reference: string): Promise<any> { return; } | ||
} |