83 lines
1.9 KiB
Markdown
Raw Normal View History

2015-05-20 17:33:48 +02:00
# react-native-keychain
Keychain Access for React Native
2015-05-20 20:39:52 +02:00
Currently functionality is limited to just storing internet and generic passwords.
2015-05-20 20:39:52 +02:00
## Installation
`$ npm install react-native-keychain`
### Option: Manually
2015-05-20 20:39:52 +02: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`.
### 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 20:39:52 +02:00
## Usage
2015-05-20 20:41:10 +02:00
See `KeychainExample` for fully working project example.
2015-05-20 20:39:52 +02:00
```js
2015-07-06 12:49:20 +02:00
var Keychain = require('react-native-keychain');
2015-05-20 20:39:52 +02:00
var username = 'zuck';
var password = 'poniesRgr8';
2015-05-29 18:25:56 +02: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 20:39:52 +02:00
Keychain
.setInternetCredentials(server, username, password)
.then(function() {
2015-05-29 18:25:56 +02:00
console.log('Credentials saved successfully!');
2015-05-20 20:39:52 +02:00
});
Keychain
.getInternetCredentials(server)
.then(function(credentials) {
2015-05-29 18:25:56 +02:00
console.log('Credentials successfully loaded for user ' + credentials.username);
2015-05-20 20:39:52 +02:00
});
Keychain
.resetInternetCredentials(server)
2015-05-29 18:25:56 +02:00
.then(function() {
console.log('Credentials successfully deleted');
2015-05-20 20:39:52 +02:00
});
```
2015-10-29 11:40:11 -04:00
## Todo
- [x] iOS support
- [ ] Android support
- [ ] Storing objects as JSON
- [ ] Expose wider selection of underlying native APIs
2015-05-20 20:39:52 +02:00
## License
MIT © Joel Arvidsson 2015