acebase-server 1.9.0 → 1.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/acebase-server.js +7 -3
- package/src/routes/docs.js +7 -0
- package/src/ts/routes/auth-change-password.yaml +3 -2
- package/src/ts/routes/auth-delete.yaml +3 -2
- package/src/ts/routes/auth-forgot-password.yaml +3 -2
- package/src/ts/routes/auth-reset-password.yaml +3 -2
- package/src/ts/routes/auth-signin.yaml +3 -2
- package/src/ts/routes/auth-signout.yaml +4 -3
- package/src/ts/routes/auth-signup.yaml +3 -2
- package/src/ts/routes/auth-state.yaml +3 -2
- package/src/ts/routes/auth-update.yaml +3 -2
- package/src/ts/routes/auth-verify-email.yaml +3 -2
- package/src/ts/routes/docs.ts +7 -0
- package/src/ts/routes/oauth2-init.yaml +63 -0
- package/src/ts/routes/oauth2-refresh.yaml +65 -0
- package/src/ts/routes/oauth2-signin.yaml +66 -0
package/package.json
CHANGED
package/src/acebase-server.js
CHANGED
|
@@ -1617,12 +1617,16 @@ class AceBaseServer extends EventEmitter {
|
|
|
1617
1617
|
const callbackUrl = req.query.callbackUrl;
|
|
1618
1618
|
const options = Object.keys(req.query).filter(key => key.startsWith('option_')).reduce((options, key) => {
|
|
1619
1619
|
const name = key.slice(7);
|
|
1620
|
-
|
|
1620
|
+
let value = req.query[key];
|
|
1621
|
+
if (['true','false'].includes(value)) { value = value === 'true'; }
|
|
1622
|
+
else if (/^\-?[0-9]+$/.test(value)) { value = parseInt(value); }
|
|
1623
|
+
options[name] = value;
|
|
1624
|
+
return options;
|
|
1621
1625
|
}, {});
|
|
1622
1626
|
const signedInUid = req.user && req.user.uid;
|
|
1623
1627
|
const provider = this.authProviders[providerName];
|
|
1624
1628
|
if (!provider) {
|
|
1625
|
-
throw new Error(`Provider ${
|
|
1629
|
+
throw new Error(`Provider ${providerName} is not available, or not properly configured by the db admin`);
|
|
1626
1630
|
}
|
|
1627
1631
|
// Create secure state so it cannot be tampered with. hash it with a server-only known salt: the generated admin password salt
|
|
1628
1632
|
await this.ready();
|
|
@@ -1954,7 +1958,7 @@ class AceBaseServer extends EventEmitter {
|
|
|
1954
1958
|
|
|
1955
1959
|
app.get(`/info/${dbname}`, (req, res) => {
|
|
1956
1960
|
const info = {
|
|
1957
|
-
version: '1.9.
|
|
1961
|
+
version: '1.9.1', // TODO: Load from package.json
|
|
1958
1962
|
time: Date.now(),
|
|
1959
1963
|
process: process.pid
|
|
1960
1964
|
};
|
package/src/routes/docs.js
CHANGED
|
@@ -18,6 +18,13 @@ const addRoute = (app) => {
|
|
|
18
18
|
email: 'me@appy.one'
|
|
19
19
|
},
|
|
20
20
|
},
|
|
21
|
+
tags: [{
|
|
22
|
+
name: 'auth',
|
|
23
|
+
description: 'User authentication endpoints'
|
|
24
|
+
}, {
|
|
25
|
+
name: 'oauth2',
|
|
26
|
+
description: 'User authentication using 3rd party OAuth2 providers'
|
|
27
|
+
}],
|
|
21
28
|
components: {
|
|
22
29
|
securitySchemes: {
|
|
23
30
|
bearerAuth: {
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/auth/{dbname}/forgot_password:
|
|
2
|
-
tags:
|
|
3
|
-
- auth
|
|
4
2
|
post:
|
|
3
|
+
tags:
|
|
4
|
+
- auth
|
|
5
|
+
summary: Issue a password reset
|
|
5
6
|
description: Issues a password reset for a user that forgot their password. User must have an email address in the database.
|
|
6
7
|
parameters:
|
|
7
8
|
- name: dbname
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/auth/{dbname}/reset_password:
|
|
2
|
-
tags:
|
|
3
|
-
- auth
|
|
4
2
|
post:
|
|
3
|
+
tags:
|
|
4
|
+
- auth
|
|
5
|
+
summary: Completes a password reset
|
|
5
6
|
description: Completes a password reset request for a user account with a code sent to the email address by the `forgot_password` endpoint
|
|
6
7
|
parameters:
|
|
7
8
|
- name: dbname
|
package/src/ts/routes/docs.ts
CHANGED
|
@@ -19,6 +19,13 @@ const addRoute = (app: Express) => {
|
|
|
19
19
|
},
|
|
20
20
|
// servers: [`http://${config.server.host}:${config.server.port}`]
|
|
21
21
|
},
|
|
22
|
+
tags: [{
|
|
23
|
+
name: 'auth',
|
|
24
|
+
description: 'User authentication endpoints'
|
|
25
|
+
}, {
|
|
26
|
+
name: 'oauth2',
|
|
27
|
+
description: 'User authentication using 3rd party OAuth2 providers'
|
|
28
|
+
}],
|
|
22
29
|
components: {
|
|
23
30
|
securitySchemes: {
|
|
24
31
|
bearerAuth: {
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/oauth2/{dbname}/init:
|
|
2
|
+
get:
|
|
3
|
+
tags:
|
|
4
|
+
- auth
|
|
5
|
+
- oauth2
|
|
6
|
+
summary: Starts an OAuth2 flow
|
|
7
|
+
description: Starts a 3rd party OAuth2 authentication flow. This allows a user to sign in (and sign up) using an external auth provider such as Facebook, Google etc. The client app has to call this endpoint to get an url to redirect the user to kick off the OAuth2 flow. If the client is already authenticated, the external account will be linked to the existing user. The provider used must have been added to the server configuration with `server.configAuthProvider(provider, config)`. In the Javascript client, this OAuth2 flow can be kicked off with `client.auth.startAuthProviderSignIn(provider, callbackUrl, options)` or (browser only) `client.auth.signInWithRedirect(provider)` which uses the current url as `callbackUrl`.
|
|
8
|
+
parameters:
|
|
9
|
+
- name: dbname
|
|
10
|
+
in: path
|
|
11
|
+
description: name of the database
|
|
12
|
+
required: true
|
|
13
|
+
schema:
|
|
14
|
+
type: string
|
|
15
|
+
example: mydb
|
|
16
|
+
- name: provider
|
|
17
|
+
in: query
|
|
18
|
+
description: External OAuth2 provider name
|
|
19
|
+
required: true
|
|
20
|
+
schema:
|
|
21
|
+
type: string
|
|
22
|
+
example: facebook
|
|
23
|
+
- name: callbackUrl
|
|
24
|
+
in: query
|
|
25
|
+
description: The url to redirect the user to after they successfully authenticated, or canceled. If the signin is successful, this url is called with a `result` query parameter (eg `https://my.website.com/oauth2/callback?result=eufy3f73gfvjbwe314f...`) that can be used by the AceBase client to finish the OAuth2 flow with `client.auth.finishAuthProviderSignIn(result)`, or `client.auth.getRedirectResult()`. If the signin fails, this url will be called with query parameters `provider`, `error`, and optionally an additional `reason` and `description`, eg `https://my.website.com/oauth2/callback?error=canceled&reason=user_canceled&description=The+user+canceled+the+auth+request`
|
|
26
|
+
required: true
|
|
27
|
+
schema:
|
|
28
|
+
type: string
|
|
29
|
+
format: url
|
|
30
|
+
example: https://my.website.com/oauth2/callback
|
|
31
|
+
- name: option_[name]
|
|
32
|
+
in: query
|
|
33
|
+
description: Additional option to pass to the auth provider. For example `force_reauthentication` can be set for Dropbox by setting `option_force_reauthentication` to `true`
|
|
34
|
+
required: false
|
|
35
|
+
schema:
|
|
36
|
+
type: string
|
|
37
|
+
example: true
|
|
38
|
+
- name: option_force_reauthentication
|
|
39
|
+
in: query
|
|
40
|
+
required: false
|
|
41
|
+
description: Example option, triggers Dropbox to force the user to sign in instead of using the currently signed in user
|
|
42
|
+
schema:
|
|
43
|
+
type: string
|
|
44
|
+
example: true
|
|
45
|
+
responses:
|
|
46
|
+
200:
|
|
47
|
+
description: Returns a JSON object containing the redirectUrl to send the end user to
|
|
48
|
+
content:
|
|
49
|
+
'application/json':
|
|
50
|
+
schema:
|
|
51
|
+
type: object
|
|
52
|
+
properties:
|
|
53
|
+
redirectUrl:
|
|
54
|
+
type: string
|
|
55
|
+
example:
|
|
56
|
+
redirectUrl: https://www.facebook.com/v7.0/dialog/oauth?response_type=code&client_id=[configured facebook client id]&scope=[configured scopes]&redirect_uri=[url set by AceBase]&state=[state set by AceBase]}
|
|
57
|
+
500:
|
|
58
|
+
description: If anything goes wrong on the server, it returns the actual error text in plain text
|
|
59
|
+
content:
|
|
60
|
+
'text/plain':
|
|
61
|
+
schema:
|
|
62
|
+
type: string
|
|
63
|
+
example: Some error text
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/oauth2/{dbname}/refresh:
|
|
2
|
+
get:
|
|
3
|
+
tags:
|
|
4
|
+
- auth
|
|
5
|
+
- oauth2
|
|
6
|
+
summary: Refreshes an OAuth2 access token
|
|
7
|
+
description: Refreshes an OAuth2 provider's access token using the refresh token given by the auth provider at signin.
|
|
8
|
+
parameters:
|
|
9
|
+
- name: dbname
|
|
10
|
+
in: path
|
|
11
|
+
description: name of the database
|
|
12
|
+
required: true
|
|
13
|
+
schema:
|
|
14
|
+
type: string
|
|
15
|
+
example: mydb
|
|
16
|
+
- name: provider
|
|
17
|
+
in: query
|
|
18
|
+
description: External OAuth2 provider name
|
|
19
|
+
required: true
|
|
20
|
+
schema:
|
|
21
|
+
type: string
|
|
22
|
+
example: facebook
|
|
23
|
+
- name: refresh_token
|
|
24
|
+
in: query
|
|
25
|
+
description: A refresh token from the OAuth2 signin result
|
|
26
|
+
required: true
|
|
27
|
+
schema:
|
|
28
|
+
type: string
|
|
29
|
+
example: erfiyh3rfig3fuyb3rjfg3u7refc...
|
|
30
|
+
responses:
|
|
31
|
+
200:
|
|
32
|
+
description: Returns a JSON object containing new access and refresh tokens and expiry information
|
|
33
|
+
content:
|
|
34
|
+
'application/json':
|
|
35
|
+
schema:
|
|
36
|
+
type: object
|
|
37
|
+
properties:
|
|
38
|
+
name:
|
|
39
|
+
type: string
|
|
40
|
+
description: Provider name
|
|
41
|
+
example: facebook
|
|
42
|
+
access_token:
|
|
43
|
+
type: string
|
|
44
|
+
description: New access token
|
|
45
|
+
example: fkw3ygfi74g25foli2n4vo7h2vto72g4...
|
|
46
|
+
refresh_token:
|
|
47
|
+
type: string
|
|
48
|
+
description: New refresh token
|
|
49
|
+
example: 32lo548jnl34tv73h4l5nbb35ithn3jt...
|
|
50
|
+
expires_in:
|
|
51
|
+
type: integer
|
|
52
|
+
description: Amount of seconds these tokens remain valid. A new refresh will have to be done before they expire.
|
|
53
|
+
example: 3600
|
|
54
|
+
example:
|
|
55
|
+
name: facebook
|
|
56
|
+
access_token: fkw3ygfi74g25foli2n4vo7h2vto72g4...
|
|
57
|
+
refresh_token: 32lo548jnl34tv73h4l5nbb35ithn3jt...
|
|
58
|
+
expires_in: 3600
|
|
59
|
+
500:
|
|
60
|
+
description: If anything goes wrong on the server, it returns the actual error text in plain text
|
|
61
|
+
content:
|
|
62
|
+
'text/plain':
|
|
63
|
+
schema:
|
|
64
|
+
type: string
|
|
65
|
+
example: Some error text
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/oauth2/{dbname}/signin:
|
|
2
|
+
get:
|
|
3
|
+
tags:
|
|
4
|
+
- auth
|
|
5
|
+
- oauth2
|
|
6
|
+
summary: Finishes an OAuth2 flow
|
|
7
|
+
description: Finishes a 3rd party OAuth2 authentication flow. This is the url you have to add to your oAuth2 provider's allowed callback urls; the auth provider will redirect the login result to this address so AceBase auth can handle the signin and then redirect the user to the callbackUrl you provided in the oauth2 init endpoint.
|
|
8
|
+
parameters:
|
|
9
|
+
- name: dbname
|
|
10
|
+
in: path
|
|
11
|
+
description: name of the database
|
|
12
|
+
required: true
|
|
13
|
+
schema:
|
|
14
|
+
type: string
|
|
15
|
+
example: mydb
|
|
16
|
+
- name: state
|
|
17
|
+
in: query
|
|
18
|
+
description: info about the initial oauth2 request (generated by AceBase)
|
|
19
|
+
required: true
|
|
20
|
+
schema:
|
|
21
|
+
type: string
|
|
22
|
+
example: sefwerg44tgwefvq3g4rbqewrgbqebwdfbwsergq34t...
|
|
23
|
+
- name: code
|
|
24
|
+
in: query
|
|
25
|
+
required: false
|
|
26
|
+
description: If signin is successful, contains the authorization code AceBase will use to request access and refresh tokens from the OAuth2 provider.
|
|
27
|
+
schema:
|
|
28
|
+
type: string
|
|
29
|
+
example: erfuihqrf7g3rfgh3rifhwre8f73efuh3eifh...
|
|
30
|
+
- name: error
|
|
31
|
+
in: query
|
|
32
|
+
description: If an error occurred, the error code
|
|
33
|
+
required: false
|
|
34
|
+
schema:
|
|
35
|
+
type: string
|
|
36
|
+
example: canceled
|
|
37
|
+
- name: error_reason
|
|
38
|
+
in: query
|
|
39
|
+
description: If an error occurred, the error reason
|
|
40
|
+
required: false
|
|
41
|
+
schema:
|
|
42
|
+
type: string
|
|
43
|
+
example: user_canceled
|
|
44
|
+
- name: error_description
|
|
45
|
+
in: query
|
|
46
|
+
description: If an error occurred, the error description
|
|
47
|
+
required: false
|
|
48
|
+
schema:
|
|
49
|
+
type: string
|
|
50
|
+
example: The user canceled the auth request
|
|
51
|
+
responses:
|
|
52
|
+
200:
|
|
53
|
+
description: Redirects the user to the callbackUrl you provided in the init endpoint
|
|
54
|
+
headers:
|
|
55
|
+
Location:
|
|
56
|
+
schema:
|
|
57
|
+
type: string
|
|
58
|
+
format: url
|
|
59
|
+
example: https://my.website.com/oauth2/callback?result=er32f32g2erv2erv23g315g..
|
|
60
|
+
500:
|
|
61
|
+
description: If anything goes wrong on the server, it returns the actual error text in plain text
|
|
62
|
+
content:
|
|
63
|
+
'text/plain':
|
|
64
|
+
schema:
|
|
65
|
+
type: string
|
|
66
|
+
example: Some error text
|