@lowdefy/api 0.0.0-experimental-20231123101256
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/LICENSE +201 -0
- package/dist/context/createApiContext.js +22 -0
- package/dist/context/createAuthorize.js +33 -0
- package/dist/context/createReadConfigFile.js +31 -0
- package/dist/context/errors.js +33 -0
- package/dist/index.js +22 -0
- package/dist/routes/auth/callbacks/addUserFieldsToSession.js +28 -0
- package/dist/routes/auth/callbacks/addUserFieldsToToken.js +30 -0
- package/dist/routes/auth/callbacks/createCallbackPlugins.js +21 -0
- package/dist/routes/auth/callbacks/createCallbacks.js +46 -0
- package/dist/routes/auth/callbacks/createJWTCallback.js +76 -0
- package/dist/routes/auth/callbacks/createRedirectCallback.js +41 -0
- package/dist/routes/auth/callbacks/createSessionCallback.js +76 -0
- package/dist/routes/auth/callbacks/createSignInCallback.js +40 -0
- package/dist/routes/auth/createAdapter.js +24 -0
- package/dist/routes/auth/createLogger.js +34 -0
- package/dist/routes/auth/createProviders.js +25 -0
- package/dist/routes/auth/events/createCreateUserEvent.js +41 -0
- package/dist/routes/auth/events/createEventPlugins.js +21 -0
- package/dist/routes/auth/events/createEvents.js +56 -0
- package/dist/routes/auth/events/createLinkAccountEvent.js +43 -0
- package/dist/routes/auth/events/createSessionEvent.js +34 -0
- package/dist/routes/auth/events/createSignInEvent.js +46 -0
- package/dist/routes/auth/events/createSignOutEvent.js +43 -0
- package/dist/routes/auth/events/createUpdateUserEvent.js +41 -0
- package/dist/routes/auth/getNextAuthConfig.js +73 -0
- package/dist/routes/page/getPageConfig.js +26 -0
- package/dist/routes/request/authorizeRequest.js +32 -0
- package/dist/routes/request/callRequest.js +92 -0
- package/dist/routes/request/callRequestResolver.js +40 -0
- package/dist/routes/request/checkConnectionRead.js +29 -0
- package/dist/routes/request/checkConnectionWrite.js +29 -0
- package/dist/routes/request/evaluateOperators.js +43 -0
- package/dist/routes/request/getConnection.js +31 -0
- package/dist/routes/request/getConnectionConfig.js +42 -0
- package/dist/routes/request/getRequestConfig.js +31 -0
- package/dist/routes/request/getRequestResolver.js +31 -0
- package/dist/routes/request/validateSchemas.js +39 -0
- package/dist/routes/rootConfig/getHomeAndMenus.js +56 -0
- package/dist/routes/rootConfig/getLowdefyGlobal.js +19 -0
- package/dist/routes/rootConfig/getRootConfig.js +28 -0
- package/dist/routes/rootConfig/menus/filterMenuList.js +41 -0
- package/dist/routes/rootConfig/menus/filterMenus.js +29 -0
- package/dist/routes/rootConfig/menus/getMenus.js +22 -0
- package/dist/test/testContext.js +38 -0
- package/package.json +59 -0
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2023 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 createCallbackPlugins from './createCallbackPlugins.js';
|
|
16
|
+
function createSignInCallback({ authConfig, plugins }) {
|
|
17
|
+
const signInCallbackPlugins = createCallbackPlugins({
|
|
18
|
+
authConfig,
|
|
19
|
+
plugins,
|
|
20
|
+
type: 'signIn'
|
|
21
|
+
});
|
|
22
|
+
if (signInCallbackPlugins.length === 0) return undefined;
|
|
23
|
+
async function signInCallback({ account, credentials, email, profile, user }) {
|
|
24
|
+
let allowSignIn = true;
|
|
25
|
+
for (const plugin of signInCallbackPlugins){
|
|
26
|
+
allowSignIn = await plugin.fn({
|
|
27
|
+
properties: plugin.properties ?? {},
|
|
28
|
+
account,
|
|
29
|
+
credentials,
|
|
30
|
+
email,
|
|
31
|
+
profile,
|
|
32
|
+
user
|
|
33
|
+
});
|
|
34
|
+
if (allowSignIn === false) break;
|
|
35
|
+
}
|
|
36
|
+
return allowSignIn;
|
|
37
|
+
}
|
|
38
|
+
return signInCallback;
|
|
39
|
+
}
|
|
40
|
+
export default createSignInCallback;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2023 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 createAdapter({ authConfig, plugins }) {
|
|
16
|
+
const adapterConfig = authConfig.adapter;
|
|
17
|
+
if (!adapterConfig) {
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
20
|
+
return plugins.adapters[adapterConfig.type]({
|
|
21
|
+
properties: adapterConfig.properties
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
export default createAdapter;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2023 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 createLogger({ logger }) {
|
|
16
|
+
return {
|
|
17
|
+
error: (code, metadata)=>logger.error({
|
|
18
|
+
code,
|
|
19
|
+
metadata,
|
|
20
|
+
event: 'auth_error'
|
|
21
|
+
}),
|
|
22
|
+
warn: (code, metadata)=>logger.warn({
|
|
23
|
+
code,
|
|
24
|
+
metadata,
|
|
25
|
+
event: 'auth_warning'
|
|
26
|
+
}),
|
|
27
|
+
debug: (code, metadata)=>logger.debug({
|
|
28
|
+
code,
|
|
29
|
+
metadata,
|
|
30
|
+
event: 'auth_debug'
|
|
31
|
+
})
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
export default createLogger;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2023 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
|
+
*/ // TODO: docs:
|
|
16
|
+
// Callback url to configure with provider will be: {{ protocol }}{{ host }}/api/auth/callback/{{ providerId }}
|
|
17
|
+
// This depends on providerId, which might cause some issues if users copy an example and change the id.
|
|
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 }) {
|
|
20
|
+
return authConfig.providers.map((providerConfig)=>plugins.providers[providerConfig.type]({
|
|
21
|
+
...providerConfig.properties,
|
|
22
|
+
id: providerConfig.id
|
|
23
|
+
}));
|
|
24
|
+
}
|
|
25
|
+
export default createProviders;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2023 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 createEventPlugins from './createEventPlugins.js';
|
|
16
|
+
function createCreateUserEvent({ authConfig, logger, plugins }) {
|
|
17
|
+
const createUserPlugins = createEventPlugins({
|
|
18
|
+
authConfig,
|
|
19
|
+
plugins,
|
|
20
|
+
type: 'createUser'
|
|
21
|
+
});
|
|
22
|
+
async function createUserEvent({ user }) {
|
|
23
|
+
logger.info({
|
|
24
|
+
event: 'auth_create_user',
|
|
25
|
+
user: {
|
|
26
|
+
id: user.id,
|
|
27
|
+
roles: user.roles,
|
|
28
|
+
sub: user.sub,
|
|
29
|
+
session_id: user.session_id
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
for (const plugin of createUserPlugins){
|
|
33
|
+
await plugin.fn({
|
|
34
|
+
properties: plugin.properties ?? {},
|
|
35
|
+
user
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return createUserEvent;
|
|
40
|
+
}
|
|
41
|
+
export default createCreateUserEvent;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2023 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 createEventPlugins({ authConfig, plugins, type }) {
|
|
16
|
+
return authConfig.events.map((eventConfig)=>({
|
|
17
|
+
fn: plugins.events[eventConfig.type],
|
|
18
|
+
properties: eventConfig.properties
|
|
19
|
+
})).filter((event)=>event.fn.meta.type === type);
|
|
20
|
+
}
|
|
21
|
+
export default createEventPlugins;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2023 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 createCreateUserEvent from './createCreateUserEvent.js';
|
|
16
|
+
import createLinkAccountEvent from './createLinkAccountEvent.js';
|
|
17
|
+
import createSessionEvent from './createSessionEvent.js';
|
|
18
|
+
import createSignInEvent from './createSignInEvent.js';
|
|
19
|
+
import createSignOutEvent from './createSignOutEvent.js';
|
|
20
|
+
import createUpdateUserEvent from './createUpdateUserEvent.js';
|
|
21
|
+
function createEvents({ authConfig, logger, plugins }) {
|
|
22
|
+
const events = {
|
|
23
|
+
createUser: createCreateUserEvent({
|
|
24
|
+
authConfig,
|
|
25
|
+
logger,
|
|
26
|
+
plugins
|
|
27
|
+
}),
|
|
28
|
+
linkAccount: createLinkAccountEvent({
|
|
29
|
+
authConfig,
|
|
30
|
+
logger,
|
|
31
|
+
plugins
|
|
32
|
+
}),
|
|
33
|
+
signIn: createSignInEvent({
|
|
34
|
+
authConfig,
|
|
35
|
+
logger,
|
|
36
|
+
plugins
|
|
37
|
+
}),
|
|
38
|
+
signOut: createSignOutEvent({
|
|
39
|
+
authConfig,
|
|
40
|
+
logger,
|
|
41
|
+
plugins
|
|
42
|
+
}),
|
|
43
|
+
updateUser: createUpdateUserEvent({
|
|
44
|
+
authConfig,
|
|
45
|
+
logger,
|
|
46
|
+
plugins
|
|
47
|
+
})
|
|
48
|
+
};
|
|
49
|
+
const session = createSessionEvent({
|
|
50
|
+
authConfig,
|
|
51
|
+
plugins
|
|
52
|
+
});
|
|
53
|
+
if (session) events.session = session;
|
|
54
|
+
return events;
|
|
55
|
+
}
|
|
56
|
+
export default createEvents;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2023 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 createEventPlugins from './createEventPlugins.js';
|
|
16
|
+
function createLinkAccountEvent({ authConfig, logger, plugins }) {
|
|
17
|
+
const linkAccountPlugins = createEventPlugins({
|
|
18
|
+
authConfig,
|
|
19
|
+
plugins,
|
|
20
|
+
type: 'linkAccount'
|
|
21
|
+
});
|
|
22
|
+
async function linkAccountEvent({ account, profile, user }) {
|
|
23
|
+
logger.info({
|
|
24
|
+
event: 'auth_link_account',
|
|
25
|
+
user: {
|
|
26
|
+
id: user.id,
|
|
27
|
+
roles: user.roles,
|
|
28
|
+
sub: user.sub,
|
|
29
|
+
session_id: user.session_id
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
for (const plugin of linkAccountPlugins){
|
|
33
|
+
await plugin.fn({
|
|
34
|
+
properties: plugin.properties ?? {},
|
|
35
|
+
account,
|
|
36
|
+
profile,
|
|
37
|
+
user
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return linkAccountEvent;
|
|
42
|
+
}
|
|
43
|
+
export default createLinkAccountEvent;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2023 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 createEventPlugins from './createEventPlugins.js';
|
|
16
|
+
function createSessionEvent({ authConfig, plugins }) {
|
|
17
|
+
const sessionPlugins = createEventPlugins({
|
|
18
|
+
authConfig,
|
|
19
|
+
plugins,
|
|
20
|
+
type: 'session'
|
|
21
|
+
});
|
|
22
|
+
if (sessionPlugins.length === 0) return undefined;
|
|
23
|
+
async function sessionEvent({ session, token }) {
|
|
24
|
+
for (const plugin of sessionPlugins){
|
|
25
|
+
await plugin.fn({
|
|
26
|
+
properties: plugin.properties ?? {},
|
|
27
|
+
session,
|
|
28
|
+
token
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return sessionEvent;
|
|
33
|
+
}
|
|
34
|
+
export default createSessionEvent;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2023 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 createEventPlugins from './createEventPlugins.js';
|
|
16
|
+
function createSignInEvent({ authConfig, logger, plugins }) {
|
|
17
|
+
const signInPlugins = createEventPlugins({
|
|
18
|
+
authConfig,
|
|
19
|
+
plugins,
|
|
20
|
+
type: 'signIn'
|
|
21
|
+
});
|
|
22
|
+
async function signInEvent({ account, isNewUser, profile, user }) {
|
|
23
|
+
logger.info({
|
|
24
|
+
event: 'auth_sign_in',
|
|
25
|
+
isNewUser,
|
|
26
|
+
provider: account?.provider,
|
|
27
|
+
user: {
|
|
28
|
+
id: user.id,
|
|
29
|
+
roles: user.roles,
|
|
30
|
+
sub: user.sub,
|
|
31
|
+
session_id: user.session_id
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
for (const plugin of signInPlugins){
|
|
35
|
+
await plugin.fn({
|
|
36
|
+
properties: plugin.properties ?? {},
|
|
37
|
+
account,
|
|
38
|
+
isNewUser,
|
|
39
|
+
profile,
|
|
40
|
+
user
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return signInEvent;
|
|
45
|
+
}
|
|
46
|
+
export default createSignInEvent;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2023 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 createEventPlugins from './createEventPlugins.js';
|
|
16
|
+
function createSignOutEvent({ authConfig, logger, plugins }) {
|
|
17
|
+
const signOutPlugins = createEventPlugins({
|
|
18
|
+
authConfig,
|
|
19
|
+
plugins,
|
|
20
|
+
type: 'signOut'
|
|
21
|
+
});
|
|
22
|
+
async function signOutEvent({ session, token }) {
|
|
23
|
+
const user = session?.user ?? token;
|
|
24
|
+
logger.info({
|
|
25
|
+
event: 'auth_sign_out',
|
|
26
|
+
user: {
|
|
27
|
+
id: user.id,
|
|
28
|
+
roles: user.roles,
|
|
29
|
+
sub: user.sub,
|
|
30
|
+
session_id: user.session_id
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
for (const plugin of signOutPlugins){
|
|
34
|
+
await plugin.fn({
|
|
35
|
+
properties: plugin.properties ?? {},
|
|
36
|
+
session,
|
|
37
|
+
token
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return signOutEvent;
|
|
42
|
+
}
|
|
43
|
+
export default createSignOutEvent;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2023 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 createEventPlugins from './createEventPlugins.js';
|
|
16
|
+
function createUpdateUserEvent({ authConfig, logger, plugins }) {
|
|
17
|
+
const updateUserPlugins = createEventPlugins({
|
|
18
|
+
authConfig,
|
|
19
|
+
plugins,
|
|
20
|
+
type: 'updateUser'
|
|
21
|
+
});
|
|
22
|
+
async function updateUserEvent({ user }) {
|
|
23
|
+
logger.info({
|
|
24
|
+
event: 'auth_update_user',
|
|
25
|
+
user: {
|
|
26
|
+
id: user.id,
|
|
27
|
+
roles: user.roles,
|
|
28
|
+
sub: user.sub,
|
|
29
|
+
session_id: user.session_id
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
for (const plugin of updateUserPlugins){
|
|
33
|
+
await plugin.fn({
|
|
34
|
+
properties: plugin.properties ?? {},
|
|
35
|
+
user
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return updateUserEvent;
|
|
40
|
+
}
|
|
41
|
+
export default createUpdateUserEvent;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2023 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 { ServerParser } from '@lowdefy/operators';
|
|
16
|
+
import { _secret } from '@lowdefy/operators-js/operators/server';
|
|
17
|
+
import createAdapter from './createAdapter.js';
|
|
18
|
+
import createCallbacks from './callbacks/createCallbacks.js';
|
|
19
|
+
import createEvents from './events/createEvents.js';
|
|
20
|
+
import createLogger from './createLogger.js';
|
|
21
|
+
import createProviders from './createProviders.js';
|
|
22
|
+
const nextAuthConfig = {};
|
|
23
|
+
let initialized = false;
|
|
24
|
+
function getNextAuthConfig({ authJson, logger, plugins, secrets }) {
|
|
25
|
+
if (initialized) return nextAuthConfig;
|
|
26
|
+
const operatorsParser = new ServerParser({
|
|
27
|
+
operators: {
|
|
28
|
+
_secret
|
|
29
|
+
},
|
|
30
|
+
payload: {},
|
|
31
|
+
secrets,
|
|
32
|
+
user: {}
|
|
33
|
+
});
|
|
34
|
+
const { output: authConfig, errors: operatorErrors } = operatorsParser.parse({
|
|
35
|
+
input: authJson,
|
|
36
|
+
location: 'auth'
|
|
37
|
+
});
|
|
38
|
+
if (operatorErrors.length > 0) {
|
|
39
|
+
throw new Error(operatorErrors[0]);
|
|
40
|
+
}
|
|
41
|
+
nextAuthConfig.adapter = createAdapter({
|
|
42
|
+
authConfig,
|
|
43
|
+
logger,
|
|
44
|
+
plugins
|
|
45
|
+
});
|
|
46
|
+
nextAuthConfig.callbacks = createCallbacks({
|
|
47
|
+
authConfig,
|
|
48
|
+
logger,
|
|
49
|
+
plugins
|
|
50
|
+
});
|
|
51
|
+
nextAuthConfig.events = createEvents({
|
|
52
|
+
authConfig,
|
|
53
|
+
logger,
|
|
54
|
+
plugins
|
|
55
|
+
});
|
|
56
|
+
nextAuthConfig.logger = createLogger({
|
|
57
|
+
logger
|
|
58
|
+
});
|
|
59
|
+
nextAuthConfig.providers = createProviders({
|
|
60
|
+
authConfig,
|
|
61
|
+
logger,
|
|
62
|
+
plugins
|
|
63
|
+
});
|
|
64
|
+
nextAuthConfig.debug = authConfig.debug ?? logger?.isLevelEnabled('debug') === true;
|
|
65
|
+
nextAuthConfig.pages = authConfig.authPages;
|
|
66
|
+
nextAuthConfig.session = authConfig.session;
|
|
67
|
+
nextAuthConfig.theme = authConfig.theme;
|
|
68
|
+
nextAuthConfig.cookies = authConfig?.advanced?.cookies;
|
|
69
|
+
nextAuthConfig.originalRedirectCallback = nextAuthConfig.callbacks.redirect;
|
|
70
|
+
initialized = true;
|
|
71
|
+
return nextAuthConfig;
|
|
72
|
+
}
|
|
73
|
+
export default getNextAuthConfig;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2023 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
|
+
*/ async function getPageConfig({ authorize, readConfigFile }, { pageId }) {
|
|
16
|
+
const pageConfig = await readConfigFile(`pages/${pageId}/${pageId}.json`);
|
|
17
|
+
if (pageConfig && authorize(pageConfig)) {
|
|
18
|
+
// eslint-disable-next-line no-unused-vars
|
|
19
|
+
const { auth, ...rest } = pageConfig;
|
|
20
|
+
return {
|
|
21
|
+
...rest
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
export default getPageConfig;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2023 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 { ConfigurationError } from '../../context/errors.js';
|
|
16
|
+
function authorizeRequest({ authorize, logger }, { requestConfig }) {
|
|
17
|
+
if (!authorize(requestConfig)) {
|
|
18
|
+
logger.debug({
|
|
19
|
+
event: 'debug_request_authorize',
|
|
20
|
+
authorized: false,
|
|
21
|
+
auth_config: requestConfig.auth
|
|
22
|
+
});
|
|
23
|
+
// Throw does not exist error to avoid leaking information that request exists to unauthorized users
|
|
24
|
+
throw new ConfigurationError(`Request "${requestConfig.requestId}" does not exist.`);
|
|
25
|
+
}
|
|
26
|
+
logger.debug({
|
|
27
|
+
event: 'debug_request_authorize',
|
|
28
|
+
authorized: true,
|
|
29
|
+
auth_config: requestConfig.auth
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
export default authorizeRequest;
|