Skip to content

Commit 6808304

Browse files
committed
Merge pull request #440 from flovilmart/flovilmart.enable-anon-users
Adds ability to disable anonymous users
2 parents b1a9536 + c0bd5d2 commit 6808304

File tree

5 files changed

+25
-4
lines changed

5 files changed

+25
-4
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ The client keys used with Parse are no longer necessary with parse-server. If y
4141
* filesAdapter - The default behavior (GridStore) can be changed by creating an adapter class (see [`FilesAdapter.js`](https://github.com/ParsePlatform/parse-server/blob/master/src/Adapters/Files/FilesAdapter.js))
4242
* databaseAdapter (unfinished) - The backing store can be changed by creating an adapter class (see `DatabaseAdapter.js`)
4343
* loggerAdapter - The default behavior/transport (File) can be changed by creating an adapter class (see [`LoggerAdapter.js`](https://github.com/ParsePlatform/parse-server/blob/master/src/Adapters/Logger/LoggerAdapter.js))
44-
44+
* enableAnonymousUsers - Defaults to true. Set to false to disable anonymous users.
4545
---
4646

4747
### Usage

spec/RestCreate.spec.js

+19
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,25 @@ describe('rest create', () => {
100100
done();
101101
});
102102
});
103+
104+
it('handles no anonymous users config', (done) => {
105+
var NoAnnonConfig = Object.assign({}, config, {enableAnonymousUsers: false});
106+
var data1 = {
107+
authData: {
108+
anonymous: {
109+
id: '00000000-0000-0000-0000-000000000001'
110+
}
111+
}
112+
};
113+
rest.create(NoAnnonConfig, auth.nobody(NoAnnonConfig), '_User', data1).then(() => {
114+
fail("Should throw an error");
115+
done();
116+
}, (err) => {
117+
expect(err.code).toEqual(Parse.Error.UNSUPPORTED_SERVICE);
118+
expect(err.message).toEqual('This authentication method is unsupported.');
119+
done();
120+
})
121+
});
103122

104123
it('test facebook signup and login', (done) => {
105124
var data = {

src/Config.js

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ function Config(applicationId, mount) {
2020
this.restAPIKey = cacheInfo.restAPIKey;
2121
this.fileKey = cacheInfo.fileKey;
2222
this.facebookAppIds = cacheInfo.facebookAppIds;
23+
this.enableAnonymousUsers = cacheInfo.enableAnonymousUsers;
2324

2425
this.database = DatabaseAdapter.getDatabaseConnection(applicationId);
2526
this.filesController = cacheInfo.filesController;

src/RestWrite.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,8 @@ RestWrite.prototype.validateAuthData = function() {
150150
var facebookData = this.data.authData.facebook;
151151
var anonData = this.data.authData.anonymous;
152152

153-
if (anonData === null ||
154-
(anonData && anonData.id)) {
153+
if (this.config.enableAnonymousUsers === true && (anonData === null ||
154+
(anonData && anonData.id))) {
155155
return this.handleAnonymousAuthData();
156156
} else if (facebookData === null ||
157157
(facebookData && facebookData.id && facebookData.access_token)) {

src/index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ function ParseServer(args) {
104104
restAPIKey: args.restAPIKey || '',
105105
fileKey: args.fileKey || 'invalid-file-key',
106106
facebookAppIds: args.facebookAppIds || [],
107-
filesController: filesController
107+
filesController: filesController,
108+
enableAnonymousUsers: args.enableAnonymousUsers || true
108109
};
109110

110111
// To maintain compatibility. TODO: Remove in v2.1

0 commit comments

Comments
 (0)