2015-05-20 15:33:48 +00:00
|
|
|
# react-native-keychain
|
|
|
|
Keychain Access for React Native
|
2015-05-20 18:39:52 +00:00
|
|
|
|
2015-10-29 15:38:50 +00:00
|
|
|
Currently functionality is limited to just storing internet and generic passwords.
|
2015-05-20 18:39:52 +00:00
|
|
|
|
|
|
|
## Installation
|
|
|
|
|
2015-10-29 15:38:50 +00:00
|
|
|
`$ npm install react-native-keychain`
|
|
|
|
|
|
|
|
### Option: Manually
|
|
|
|
|
2015-05-20 18:39:52 +00:00
|
|
|
* Right click on Libraries, select **Add files to "…"** and select `node_modules/react-native-keychain/RNKeychain.xcodeproj`
|
|
|
|
* Select your project and under **Build Phases** -> **Link Binary With Libraries**, press the + and select `libRNKeychain.a`.
|
|
|
|
|
2015-10-29 15:38:50 +00:00
|
|
|
### Option: With [CocoaPods](https://cocoapods.org/)
|
|
|
|
|
|
|
|
Add the following to your `Podfile` and run `pod update`:
|
|
|
|
|
|
|
|
```
|
|
|
|
pod 'RNKeychain', :path => 'node_modules/react-native-keychain'
|
|
|
|
```
|
2015-05-20 18:39:52 +00:00
|
|
|
|
|
|
|
## Usage
|
|
|
|
|
2015-05-20 18:41:10 +00:00
|
|
|
See `KeychainExample` for fully working project example.
|
|
|
|
|
2015-05-20 18:39:52 +00:00
|
|
|
```js
|
2015-07-06 10:49:20 +00:00
|
|
|
var Keychain = require('react-native-keychain');
|
2015-05-20 18:39:52 +00:00
|
|
|
|
|
|
|
var username = 'zuck';
|
|
|
|
var password = 'poniesRgr8';
|
2015-05-29 16:25:56 +00:00
|
|
|
|
|
|
|
// Generic Password, service argument optional
|
|
|
|
Keychain
|
|
|
|
.setGenericPassword(username, password)
|
|
|
|
.then(function() {
|
|
|
|
console.log('Credentials saved successfully!');
|
|
|
|
});
|
|
|
|
|
|
|
|
Keychain
|
|
|
|
.getGenericPassword()
|
|
|
|
.then(function(credentials) {
|
|
|
|
console.log('Credentials successfully loaded for user ' + credentials.username);
|
|
|
|
});
|
|
|
|
|
|
|
|
Keychain
|
|
|
|
.resetGenericPassword()
|
|
|
|
.then(function() {
|
|
|
|
console.log('Credentials successfully deleted');
|
|
|
|
});
|
|
|
|
|
|
|
|
// Internet Password, server argument required
|
|
|
|
var server = 'http://facebook.com';
|
2015-05-20 18:39:52 +00:00
|
|
|
Keychain
|
|
|
|
.setInternetCredentials(server, username, password)
|
|
|
|
.then(function() {
|
2015-05-29 16:25:56 +00:00
|
|
|
console.log('Credentials saved successfully!');
|
2015-05-20 18:39:52 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
Keychain
|
|
|
|
.getInternetCredentials(server)
|
|
|
|
.then(function(credentials) {
|
2015-05-29 16:25:56 +00:00
|
|
|
console.log('Credentials successfully loaded for user ' + credentials.username);
|
2015-05-20 18:39:52 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
Keychain
|
|
|
|
.resetInternetCredentials(server)
|
2015-05-29 16:25:56 +00:00
|
|
|
.then(function() {
|
|
|
|
console.log('Credentials successfully deleted');
|
2015-05-20 18:39:52 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
```
|
|
|
|
|
2015-10-29 15:40:11 +00:00
|
|
|
## Todo
|
|
|
|
|
|
|
|
- [x] iOS support
|
|
|
|
- [ ] Android support
|
|
|
|
- [ ] Storing objects as JSON
|
|
|
|
- [ ] Expose wider selection of underlying native APIs
|
|
|
|
|
2015-05-20 18:39:52 +00:00
|
|
|
## License
|
|
|
|
MIT © Joel Arvidsson 2015
|