Skip to content

Commit 968daa3

Browse files
author
Kadi Kraman
authored
Merge pull request #434 from FormidableLabs/chore/add-token-storage-info
Add token storage recommendations
2 parents 8347079 + 48c0773 commit 968daa3

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,10 @@ Some authentication providers, including examples cited below, require you to pr
416416
> [strongly recommend](https://github.com/openid/AppAuth-Android#utilizing-client-secrets-dangerous) you avoid using static client secrets in your native applications whenever possible. Client secrets derived via a dynamic client registration are safe to use, but static client secrets can be easily extracted from your apps and allow others to impersonate your app and steal user data. If client secrets must be used by the OAuth2 provider you are integrating with, we strongly recommend performing the code exchange step on your backend, where the client secret can be kept hidden.
417417
418418
Having said this, in some cases using client secrets is unavoidable. In these cases, a `clientSecret` parameter can be provided to `authorize`/`refresh` calls when performing a token request.
419-
g
419+
420+
#### Token Storage
421+
422+
Recommendations on secure token storage can be found [here](./docs/token-storage.md).
420423
421424
#### Maintenance Status
422425

docs/token-storage.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
## Token Storage
2+
3+
Once the user has successfully authenticated, you'll have a JWT and possibly a refresh token that should be stored securely.
4+
5+
❗️ __Do not use Async Storage for storing sensitive information__
6+
7+
Async Storage is the simplest method of persisting data across application launches in React Native. However, it is an _unencrypted_ key-value store and should therefore not be used for token storage.
8+
9+
__DO use Secure Storage__
10+
11+
React Native does not come bundled with any way of storing sensitive data, so it is necessary to rely on the underlying platform-specific solutions.
12+
13+
### iOS - Keychain Services
14+
Keychain Services allows you to securely store small chunks of sensitive info for the user. This is an ideal place to store certificates, tokens, passwords, and any other sensitive information that doesn’t belong in Async Storage.
15+
16+
### Android - Secure Shared Preferences
17+
Shared Preferences is the Android equivalent for a persistent key-value data store. Data in Shared Preferences is not encrypted by default. Encrypted Shared Preferences wraps the Shared Preferences class for Android, and automatically encrypts keys and values.
18+
19+
In order to use iOS's Keychain services or Android's Secure Shared Preferences, you either can write a JS<->native interface yourself or use a library which wraps them for you. Some even provide a unified API.
20+
21+
## Related OSS libraries
22+
23+
- [react-native-keychain](https://github.com/oblador/react-native-keychain) - we've had good experiences using this on projects
24+
- [react-native-sensitive-info](https://github.com/mCodex/react-native-sensitive-info) - secure for iOS, but uses Android Shared Preferences for Android (which is not secure). There is however a fork that uses [Android Keystore](https://github.com/mCodex/react-native-sensitive-info/tree/keystore) which is secure
25+
- [redux-persist-sensitive-storage](https://github.com/CodingZeal/redux-persist-sensitive-storage) - wraps `react-native-sensitive-info`, see comments above
26+
- [rn-secure-storage](https://github.com/talut/rn-secure-storage)

0 commit comments

Comments
 (0)