Skip to content

Commit 7819c45

Browse files
macarthurorTomWFox
andcommitted
Encrypting Current User and Local Storage (#695)
* Encrypting Current User and Local Storage * Update based in the js-sdk Pull requests #1036 * Encrypting Current User reminder * secure-ls correction and typo fixed * Update _includes/js/users.md drafting Co-Authored-By: Tom Fox <13188249+TomWFox@users.noreply.github.com> * Update _includes/js/users.md drafting Co-Authored-By: Tom Fox <13188249+TomWFox@users.noreply.github.com> * Update _includes/js/users.md drafting Co-Authored-By: Tom Fox <13188249+TomWFox@users.noreply.github.com> * Update _includes/js/users.md drafting Co-Authored-By: Tom Fox <13188249+TomWFox@users.noreply.github.com> * Update _includes/js/users.md drafting Co-Authored-By: Tom Fox <13188249+TomWFox@users.noreply.github.com> Co-authored-by: Tom Fox <13188249+TomWFox@users.noreply.github.com>
1 parent f8045bd commit 7819c45

File tree

5 files changed

+443
-397
lines changed

5 files changed

+443
-397
lines changed

Gemfile.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,12 @@ GEM
2424
ethon (0.11.0)
2525
ffi (>= 1.3.0)
2626
eventmachine (1.2.7)
27+
eventmachine (1.2.7-x64-mingw32)
2728
execjs (2.7.0)
2829
faraday (0.15.4)
2930
multipart-post (>= 1.2, < 3)
3031
ffi (1.9.25)
32+
ffi (1.9.25-x64-mingw32)
3133
forwardable-extended (2.6.0)
3234
gemoji (3.0.0)
3335
github-pages (193)
@@ -207,6 +209,8 @@ GEM
207209
multipart-post (2.0.0)
208210
nokogiri (1.8.5)
209211
mini_portile2 (~> 2.3.0)
212+
nokogiri (1.8.5-x64-mingw32)
213+
mini_portile2 (~> 2.3.0)
210214
octokit (4.13.0)
211215
sawyer (~> 0.8.0, >= 0.5.3)
212216
pathutil (0.16.2)
@@ -240,6 +244,7 @@ GEM
240244

241245
PLATFORMS
242246
ruby
247+
x64-mingw32
243248

244249
DEPENDENCIES
245250
github-pages

_includes/js/local-datastore.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,29 @@ The Parse JS SDK (Version 2.2.0+) provides a local datastore which can be used t
44

55
There are a couple of side effects of enabling the local datastore that you should be aware of. When enabled, there will only be one instance of any given `Parse.Object`. For example, imagine you have an instance of the `"GameScore"` class with an `objectId` of `"xWMyZ4YEGZ"`, and then you issue a `Parse.Query` for all instances of `"GameScore"` with that `objectId`. The result will be the same instance of the object you already have in memory.
66

7+
Also if you don't want to show the data in the local storage you can use [secure-ls](https://github.com/softvar/secure-ls) to Encrypt it.
8+
9+
```javascript
10+
import SecureLS from 'secure-ls';
11+
const ls = new SecureLS({ isCompression: false });
12+
13+
Parse.enableLocalDatastore();
14+
Parse.setLocalDatastoreController({
15+
fromPinWithName: name => ls.get(name),
16+
pinWithName: (name, objects) => ls.set(name, JSON.stringify(objects)),
17+
unPinWithName: name => ls.remove(name),
18+
getAllContents: () => {
19+
let data = {};
20+
ls.getAllKeys().forEach((key) => {
21+
const value = ls.get(key).data;
22+
data[key] = value.includes('{') ? JSON.parse(value) : value;
23+
})
24+
return data;
25+
},
26+
clear: () => ls.removeAll()
27+
});
28+
```
29+
730
## Pinning
831

932
You can store a `Parse.Object` in the local datastore by pinning it. Pinning a `Parse.Object` is recursive, just like saving, so any objects that are pointed to by the one you are pinning will also be pinned. When an object is pinned, every time you update it by fetching or saving new data, the copy in the local datastore will be updated automatically. You don't need to worry about it at all.

_includes/js/users.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,22 @@ The `Parse.User` obtained from `Parse.User.current()` will always be authenticat
136136

137137
If you need to check if a `Parse.User` is authenticated, you can invoke the `authenticated` method. You do not need to check `authenticated` with `Parse.User` objects that are obtained via an authenticated method.
138138

139+
## Encrypting Current User
140+
141+
Often you may want to be more careful with user information stored in the browser, if this is the case you can encrypt the current user object:
142+
143+
```javascript
144+
145+
Parse.enableEncryptedUser();
146+
Parse.secret = 'my Secrey Key';
147+
148+
```
149+
* It's important to remember that this function will not work if `Parse.secret` is not set.
150+
* Also note that this only works in the browser.
151+
152+
Now the record in Local Storage looks like a random string and only can be read using `Parse.User.current()`
153+
You can check if this feature is enabled with the function `Parse.isEncryptedUserEnabled()`.
154+
139155
## Security For Other Objects
140156

141157
The same security model that applies to the `Parse.User` can be applied to other objects. For any object, you can specify which users are allowed to read the object, and which users are allowed to modify an object. To support this type of security, each object has an [access control list](http://en.wikipedia.org/wiki/Access_control_list), implemented by the `Parse.ACL` class.

0 commit comments

Comments
 (0)