Skip to content

Commit 0241833

Browse files
author
Kévin Poirot
committed
Add custom authentication
1 parent ddcd4d0 commit 0241833

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

ADVANCE.md

+29
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,35 @@ $ docker run -d \
4545
--name parse-server \
4646
yongjhih/parse-server
4747
```
48+
49+
## How to use with custom authentication
50+
###
51+
52+
You can add (multiple) custom authentication provider with the environment variables defined below.
53+
54+
Mandatory module path: `AUTH_MYAUTH_MODULE=PATH_TO_MODULE`
55+
56+
Optional module option: `AUTH_MYAUTH_MY_OPTION=value`
57+
58+
Replace `MYAUTH` by your custom authentication name __without__ any underscore.
59+
60+
Replace `MY_OPTION` by your custom authentication parameter name.
61+
62+
### Example
63+
```sh
64+
$ docker run -d \
65+
-e APP_ID=${APP_ID} \
66+
-e MASTER_KEY=${MASTER_KEY} \
67+
-e AUTH_MYAUTH_MODULE=${AUTH_MYAUTH_MODULE} \
68+
-e AUTH_MYAUTH_OPTION=${AUTH_MYAUTH_OPTION} \
69+
-e AUTH_MYAUTH_ANOTHER_OPTION=${AUTH_MYAUTH_ANOTHER_OPTION} \
70+
-e MASTER_KEY=${MASTER_KEY} \
71+
-p 1337:1337 \
72+
--link mongo \
73+
--name parse-server \
74+
yongjhih/parse-server:dev
75+
```
76+
4877
## How to specify parse-server version
4978
Specify parse-server:2.2.10:
5079
```sh

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ $ APP_ID=YOUR_APP_ID MASTER_KEY=YOUR_MASTER_KEY PARSE_DASHBOARD_ALLOW_INSECURE_H
110110
## :zap: Advance topics
111111
* [How to use with existing mongodb with DATABASE_URI](ADVANCE.md#how-to-use-with-existing-mongodb-with-database_uri)
112112
* [How to use with existing parse-cloud-code](ADVANCE.md#how-to-use-with-existing-parse-cloud-code)
113+
* [How to use with custom authentication](ADVANCE.md#how-to-use-with-custom-authentication)
113114
* [How to specify parse-server version](ADVANCE.md#how-to-specify-parse-server-version)
114115
* [How to specify latest commit of parse-server](ADVANCE.md#how-to-specify-latest-commit-of-parseplatformparse-server-of-image)
115116
* [How to start parse dashboard as standalone](ADVANCE.md#how-to-start-parse-dashboard-as-standalone)

index.js

+18
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,23 @@ if (process.env.DATABASE_TIMEOUT) {
205205
};
206206
}
207207

208+
var auth = {};
209+
for (var env in process.env) {
210+
if (!process.env.hasOwnProperty(env)) {
211+
return;
212+
}
213+
214+
var env_parameters = /^AUTH_([^_]*)_(.+)/.exec(env);
215+
216+
if (env_parameters !== null) {
217+
if (typeof auth[env_parameters[1].toLowerCase()] === "undefined") {
218+
auth[env_parameters[1].toLowerCase()] = {};
219+
}
220+
221+
auth[env_parameters[1].toLowerCase()][env_parameters[2].toLowerCase()] = process.env[env];
222+
}
223+
}
224+
208225
var api = new ParseServer({
209226
databaseURI: databaseUri || 'mongodb://localhost:27017/dev',
210227
databaseOptions: databaseOptions,
@@ -222,6 +239,7 @@ var api = new ParseServer({
222239
fileKey: process.env.FILE_KEY,
223240
filesAdapter: filesAdapter,
224241

242+
auth: auth,
225243
facebookAppIds: facebookAppIds,
226244
maxUploadSize: process.env.MAX_UPLOAD_SIZE,
227245
push: pushConfig,

0 commit comments

Comments
 (0)