@lowdefy/api 4.0.0-alpha.15 → 4.0.0-alpha.18
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/dist/routes/auth/callbacks/addUserFieldsToSession.js +20 -0
- package/dist/routes/auth/callbacks/addUserFieldsToToken.js +35 -0
- package/dist/routes/auth/callbacks/createCallbacks.js +5 -5
- package/dist/routes/auth/callbacks/createJWTCallback.js +11 -2
- package/dist/routes/auth/callbacks/createRedirectCallback.js +1 -1
- package/dist/routes/auth/callbacks/createSessionCallback.js +11 -3
- package/dist/routes/auth/callbacks/createSignInCallback.js +1 -1
- package/dist/routes/auth/createProviders.js +1 -1
- package/dist/routes/auth/events/createCreateUserEvent.js +1 -1
- package/dist/routes/auth/events/createEvents.js +7 -7
- package/dist/routes/auth/events/createLinkAccountEvent.js +1 -1
- package/dist/routes/auth/events/createSessionEvent.js +1 -1
- package/dist/routes/auth/events/createSignInEvent.js +1 -1
- package/dist/routes/auth/events/createSignOutEvent.js +1 -1
- package/dist/routes/auth/events/createUpdateUserEvent.js +1 -1
- package/dist/routes/auth/getNextAuthConfig.js +5 -4
- package/package.json +8 -8
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2022 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/ function addUserFieldsToSession(context, { session , token , authConfig }) {
|
|
16
|
+
Object.keys(authConfig.userFields).forEach((fieldName)=>{
|
|
17
|
+
session.user[fieldName] = token[fieldName];
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
export default addUserFieldsToSession;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2022 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/ import { get } from '@lowdefy/helpers';
|
|
16
|
+
function addUserFieldsToToken(context, { account , authConfig , profile , token }) {
|
|
17
|
+
// const { debug } = context.logger;
|
|
18
|
+
const objects = {
|
|
19
|
+
account,
|
|
20
|
+
profile
|
|
21
|
+
};
|
|
22
|
+
// TODO: Add when debug is fixed.
|
|
23
|
+
// debug('Adding userFields to user. Available provider data is:');
|
|
24
|
+
// debug(objects);
|
|
25
|
+
Object.entries(authConfig.userFields).forEach(([lowdefyFieldName, providerFieldName])=>{
|
|
26
|
+
const value = get(objects, providerFieldName);
|
|
27
|
+
// debug(
|
|
28
|
+
// `Adding provider field "${providerFieldName}" with value ${JSON.stringify(
|
|
29
|
+
// value
|
|
30
|
+
// )} as "${lowdefyFieldName}"`
|
|
31
|
+
// );
|
|
32
|
+
token[lowdefyFieldName] = value;
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
export default addUserFieldsToToken;
|
|
@@ -16,24 +16,24 @@
|
|
|
16
16
|
import createRedirectCallback from './createRedirectCallback.js';
|
|
17
17
|
import createSessionCallback from './createSessionCallback.js';
|
|
18
18
|
import createSignInCallback from './createSignInCallback.js';
|
|
19
|
-
function createCallbacks({ authConfig , plugins }) {
|
|
19
|
+
function createCallbacks(context, { authConfig , plugins }) {
|
|
20
20
|
const callbacks = {
|
|
21
|
-
session: createSessionCallback({
|
|
21
|
+
session: createSessionCallback(context, {
|
|
22
22
|
authConfig,
|
|
23
23
|
plugins
|
|
24
24
|
})
|
|
25
25
|
};
|
|
26
|
-
const jwt = createJWTCallback({
|
|
26
|
+
const jwt = createJWTCallback(context, {
|
|
27
27
|
authConfig,
|
|
28
28
|
plugins
|
|
29
29
|
});
|
|
30
30
|
if (jwt) callbacks.jwt = jwt;
|
|
31
|
-
const redirect = createRedirectCallback({
|
|
31
|
+
const redirect = createRedirectCallback(context, {
|
|
32
32
|
authConfig,
|
|
33
33
|
plugins
|
|
34
34
|
});
|
|
35
35
|
if (redirect) callbacks.redirect = redirect;
|
|
36
|
-
const signIn = createSignInCallback({
|
|
36
|
+
const signIn = createSignInCallback(context, {
|
|
37
37
|
authConfig,
|
|
38
38
|
plugins
|
|
39
39
|
});
|
|
@@ -12,8 +12,9 @@
|
|
|
12
12
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
13
|
See the License for the specific language governing permissions and
|
|
14
14
|
limitations under the License.
|
|
15
|
-
*/ import
|
|
16
|
-
|
|
15
|
+
*/ import addUserFieldsToToken from './addUserFieldsToToken.js';
|
|
16
|
+
import createCallbackPlugins from './createCallbackPlugins.js';
|
|
17
|
+
function createJWTCallback(context, { authConfig , plugins }) {
|
|
17
18
|
const jwtCallbackPlugins = createCallbackPlugins({
|
|
18
19
|
authConfig,
|
|
19
20
|
plugins,
|
|
@@ -45,6 +46,14 @@ function createJWTCallback({ authConfig , plugins }) {
|
|
|
45
46
|
updated_at,
|
|
46
47
|
...token
|
|
47
48
|
};
|
|
49
|
+
if (authConfig.userFields) {
|
|
50
|
+
addUserFieldsToToken(context, {
|
|
51
|
+
authConfig,
|
|
52
|
+
account,
|
|
53
|
+
profile,
|
|
54
|
+
token
|
|
55
|
+
});
|
|
56
|
+
}
|
|
48
57
|
}
|
|
49
58
|
for (const plugin of jwtCallbackPlugins){
|
|
50
59
|
token = await plugin.fn({
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
See the License for the specific language governing permissions and
|
|
14
14
|
limitations under the License.
|
|
15
15
|
*/ import createCallbackPlugins from './createCallbackPlugins.js';
|
|
16
|
-
function createRedirectCallback({ authConfig , plugins }) {
|
|
16
|
+
function createRedirectCallback(context, { authConfig , plugins }) {
|
|
17
17
|
const redirectCallbackPlugins = createCallbackPlugins({
|
|
18
18
|
authConfig,
|
|
19
19
|
plugins,
|
|
@@ -12,15 +12,15 @@
|
|
|
12
12
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
13
|
See the License for the specific language governing permissions and
|
|
14
14
|
limitations under the License.
|
|
15
|
-
*/ import
|
|
16
|
-
|
|
15
|
+
*/ import addUserFieldsToSession from './addUserFieldsToSession.js';
|
|
16
|
+
import createCallbackPlugins from './createCallbackPlugins.js';
|
|
17
|
+
function createSessionCallback(context, { authConfig , plugins }) {
|
|
17
18
|
const sessionCallbackPlugins = createCallbackPlugins({
|
|
18
19
|
authConfig,
|
|
19
20
|
plugins,
|
|
20
21
|
type: 'session'
|
|
21
22
|
});
|
|
22
23
|
async function sessionCallback({ session , token , user }) {
|
|
23
|
-
// console.log({ session, token, user });
|
|
24
24
|
if (token) {
|
|
25
25
|
const { sub , name , given_name , family_name , middle_name , nickname , preferred_username , profile , picture , website , email , email_verified , gender , birthdate , zoneinfo , locale , phone_number , phone_number_verified , address , updated_at , } = token;
|
|
26
26
|
session.user = {
|
|
@@ -46,8 +46,16 @@ function createSessionCallback({ authConfig , plugins }) {
|
|
|
46
46
|
updated_at,
|
|
47
47
|
...session.user
|
|
48
48
|
};
|
|
49
|
+
if (authConfig.userFields) {
|
|
50
|
+
addUserFieldsToSession(context, {
|
|
51
|
+
authConfig,
|
|
52
|
+
session,
|
|
53
|
+
token
|
|
54
|
+
});
|
|
55
|
+
}
|
|
49
56
|
}
|
|
50
57
|
for (const plugin of sessionCallbackPlugins){
|
|
58
|
+
// eslint-disable-next-line no-param-reassign
|
|
51
59
|
session = await plugin.fn({
|
|
52
60
|
properties: plugin.properties ?? {},
|
|
53
61
|
session,
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
See the License for the specific language governing permissions and
|
|
14
14
|
limitations under the License.
|
|
15
15
|
*/ import createCallbackPlugins from './createCallbackPlugins.js';
|
|
16
|
-
function createSignInCallback({ authConfig , plugins }) {
|
|
16
|
+
function createSignInCallback(context, { authConfig , plugins }) {
|
|
17
17
|
const signInCallbackPlugins = createCallbackPlugins({
|
|
18
18
|
authConfig,
|
|
19
19
|
plugins,
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
// Callback url to configure with provider will be: {{ protocol }}{{ host }}/api/auth/callback/{{ providerId }}
|
|
17
17
|
// This depends on providerId, which might cause some issues if users copy an example and change the id.
|
|
18
18
|
// We need to allow users to configure ids, since they might have more than one of the same type.
|
|
19
|
-
function createProviders({ authConfig , plugins }) {
|
|
19
|
+
function createProviders(context, { authConfig , plugins }) {
|
|
20
20
|
return authConfig.providers.map((providerConfig)=>plugins.providers[providerConfig.type]({
|
|
21
21
|
...providerConfig.properties,
|
|
22
22
|
id: providerConfig.id
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
See the License for the specific language governing permissions and
|
|
14
14
|
limitations under the License.
|
|
15
15
|
*/ import createEventPlugins from './createEventPlugins.js';
|
|
16
|
-
function createCreateUserEvent({ authConfig , plugins }) {
|
|
16
|
+
function createCreateUserEvent(context, { authConfig , plugins }) {
|
|
17
17
|
const createUserPlugins = createEventPlugins({
|
|
18
18
|
authConfig,
|
|
19
19
|
plugins,
|
|
@@ -18,34 +18,34 @@ import createSessionEvent from './createSessionEvent.js';
|
|
|
18
18
|
import createSignInEvent from './createSignInEvent.js';
|
|
19
19
|
import createSignOutEvent from './createSignOutEvent.js';
|
|
20
20
|
import createUpdateUserEvent from './createUpdateUserEvent.js';
|
|
21
|
-
function createEvents({ authConfig , plugins }) {
|
|
21
|
+
function createEvents(context, { authConfig , plugins }) {
|
|
22
22
|
const events = {};
|
|
23
|
-
const createUser = createCreateUserEvent({
|
|
23
|
+
const createUser = createCreateUserEvent(context, {
|
|
24
24
|
authConfig,
|
|
25
25
|
plugins
|
|
26
26
|
});
|
|
27
27
|
if (createUser) events.createUser = createUser;
|
|
28
|
-
const linkAccount = createLinkAccountEvent({
|
|
28
|
+
const linkAccount = createLinkAccountEvent(context, {
|
|
29
29
|
authConfig,
|
|
30
30
|
plugins
|
|
31
31
|
});
|
|
32
32
|
if (linkAccount) events.linkAccount = linkAccount;
|
|
33
|
-
const session = createSessionEvent({
|
|
33
|
+
const session = createSessionEvent(context, {
|
|
34
34
|
authConfig,
|
|
35
35
|
plugins
|
|
36
36
|
});
|
|
37
37
|
if (session) events.session = session;
|
|
38
|
-
const signIn = createSignInEvent({
|
|
38
|
+
const signIn = createSignInEvent(context, {
|
|
39
39
|
authConfig,
|
|
40
40
|
plugins
|
|
41
41
|
});
|
|
42
42
|
if (signIn) events.signIn = signIn;
|
|
43
|
-
const signOut = createSignOutEvent({
|
|
43
|
+
const signOut = createSignOutEvent(context, {
|
|
44
44
|
authConfig,
|
|
45
45
|
plugins
|
|
46
46
|
});
|
|
47
47
|
if (signOut) events.signOut = signOut;
|
|
48
|
-
const updateUser = createUpdateUserEvent({
|
|
48
|
+
const updateUser = createUpdateUserEvent(context, {
|
|
49
49
|
authConfig,
|
|
50
50
|
plugins
|
|
51
51
|
});
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
See the License for the specific language governing permissions and
|
|
14
14
|
limitations under the License.
|
|
15
15
|
*/ import createEventPlugins from './createEventPlugins.js';
|
|
16
|
-
function createLinkAccountEvent({ authConfig , plugins }) {
|
|
16
|
+
function createLinkAccountEvent(context, { authConfig , plugins }) {
|
|
17
17
|
const linkAccountPlugins = createEventPlugins({
|
|
18
18
|
authConfig,
|
|
19
19
|
plugins,
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
See the License for the specific language governing permissions and
|
|
14
14
|
limitations under the License.
|
|
15
15
|
*/ import createEventPlugins from './createEventPlugins.js';
|
|
16
|
-
function createSessionEvent({ authConfig , plugins }) {
|
|
16
|
+
function createSessionEvent(context, { authConfig , plugins }) {
|
|
17
17
|
const sessionPlugins = createEventPlugins({
|
|
18
18
|
authConfig,
|
|
19
19
|
plugins,
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
See the License for the specific language governing permissions and
|
|
14
14
|
limitations under the License.
|
|
15
15
|
*/ import createEventPlugins from './createEventPlugins.js';
|
|
16
|
-
function createSignInEvent({ authConfig , plugins }) {
|
|
16
|
+
function createSignInEvent(context, { authConfig , plugins }) {
|
|
17
17
|
const signInPlugins = createEventPlugins({
|
|
18
18
|
authConfig,
|
|
19
19
|
plugins,
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
See the License for the specific language governing permissions and
|
|
14
14
|
limitations under the License.
|
|
15
15
|
*/ import createEventPlugins from './createEventPlugins.js';
|
|
16
|
-
function createSignOutEvent({ authConfig , plugins }) {
|
|
16
|
+
function createSignOutEvent(context, { authConfig , plugins }) {
|
|
17
17
|
const signInPlugins = createEventPlugins({
|
|
18
18
|
authConfig,
|
|
19
19
|
plugins,
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
See the License for the specific language governing permissions and
|
|
14
14
|
limitations under the License.
|
|
15
15
|
*/ import createEventPlugins from './createEventPlugins.js';
|
|
16
|
-
function createUpdateUserEvent({ authConfig , plugins }) {
|
|
16
|
+
function createUpdateUserEvent(context, { authConfig , plugins }) {
|
|
17
17
|
const updateUserPlugins = createEventPlugins({
|
|
18
18
|
authConfig,
|
|
19
19
|
plugins,
|
|
@@ -20,9 +20,10 @@ import createEvents from './events/createEvents.js';
|
|
|
20
20
|
import createProviders from './createProviders.js';
|
|
21
21
|
const nextAuthConfig = {};
|
|
22
22
|
let initialized = false;
|
|
23
|
-
function getNextAuthConfig({ authJson , plugins }) {
|
|
23
|
+
function getNextAuthConfig(context, { authJson , plugins }) {
|
|
24
24
|
if (initialized) return nextAuthConfig;
|
|
25
25
|
const secrets = getSecretsFromEnv();
|
|
26
|
+
// TODO: Add logger
|
|
26
27
|
const operatorsParser = new NodeParser({
|
|
27
28
|
operators: {
|
|
28
29
|
_secret
|
|
@@ -38,15 +39,15 @@ function getNextAuthConfig({ authJson , plugins }) {
|
|
|
38
39
|
if (operatorErrors.length > 0) {
|
|
39
40
|
throw new Error(operatorErrors[0]);
|
|
40
41
|
}
|
|
41
|
-
nextAuthConfig.callbacks = createCallbacks({
|
|
42
|
+
nextAuthConfig.callbacks = createCallbacks(context, {
|
|
42
43
|
authConfig,
|
|
43
44
|
plugins
|
|
44
45
|
});
|
|
45
|
-
nextAuthConfig.events = createEvents({
|
|
46
|
+
nextAuthConfig.events = createEvents(context, {
|
|
46
47
|
authConfig,
|
|
47
48
|
plugins
|
|
48
49
|
});
|
|
49
|
-
nextAuthConfig.providers = createProviders({
|
|
50
|
+
nextAuthConfig.providers = createProviders(context, {
|
|
50
51
|
authConfig,
|
|
51
52
|
plugins
|
|
52
53
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lowdefy/api",
|
|
3
|
-
"version": "4.0.0-alpha.
|
|
3
|
+
"version": "4.0.0-alpha.18",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"description": "",
|
|
6
6
|
"homepage": "https://lowdefy.com",
|
|
@@ -41,15 +41,15 @@
|
|
|
41
41
|
"test": "yarn node --experimental-vm-modules $(yarn bin jest)"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@lowdefy/ajv": "4.0.0-alpha.
|
|
45
|
-
"@lowdefy/helpers": "4.0.0-alpha.
|
|
46
|
-
"@lowdefy/node-utils": "4.0.0-alpha.
|
|
47
|
-
"@lowdefy/nunjucks": "4.0.0-alpha.
|
|
48
|
-
"@lowdefy/operators": "4.0.0-alpha.
|
|
44
|
+
"@lowdefy/ajv": "4.0.0-alpha.18",
|
|
45
|
+
"@lowdefy/helpers": "4.0.0-alpha.18",
|
|
46
|
+
"@lowdefy/node-utils": "4.0.0-alpha.18",
|
|
47
|
+
"@lowdefy/nunjucks": "4.0.0-alpha.18",
|
|
48
|
+
"@lowdefy/operators": "4.0.0-alpha.18",
|
|
49
|
+
"@lowdefy/operators-js": "4.0.0-alpha.18"
|
|
49
50
|
},
|
|
50
51
|
"devDependencies": {
|
|
51
52
|
"@jest/globals": "28.1.0",
|
|
52
|
-
"@lowdefy/operators-js": "4.0.0-alpha.15",
|
|
53
53
|
"@swc/cli": "0.1.57",
|
|
54
54
|
"@swc/core": "1.2.194",
|
|
55
55
|
"@swc/jest": "0.2.21",
|
|
@@ -58,5 +58,5 @@
|
|
|
58
58
|
"publishConfig": {
|
|
59
59
|
"access": "public"
|
|
60
60
|
},
|
|
61
|
-
"gitHead": "
|
|
61
|
+
"gitHead": "9ba94a9ab39be2a165b3a58043fbb33f26b48ae3"
|
|
62
62
|
}
|