@lowdefy/api 6.0.0 → 7.0.0
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/context/applySystemTrust.js +45 -0
- package/dist/context/createApiContext.js +18 -3
- package/dist/context/createAuthorizeOutcome.js +91 -0
- package/dist/context/createBoundSystemContext.js +33 -0
- package/dist/context/createEvaluateOperators.js +10 -3
- package/dist/context/createRequestSignal.js +47 -0
- package/dist/context/createSystemContext.js +80 -0
- package/dist/context/getCanonicalUrl.js +27 -0
- package/dist/context/getCurrentEnvironment.js +27 -0
- package/dist/context/isSameOriginRequest.js +85 -0
- package/dist/context/isWebSocketOriginAllowed.js +63 -0
- package/dist/context/normalizeInjectedCaller.js +58 -0
- package/dist/context/parseRequestBody.js +32 -0
- package/dist/context/readMemberships.js +71 -0
- package/dist/context/resolveAuthentication.js +758 -0
- package/dist/context/resolveStrategyCaller.js +7 -3
- package/dist/csp/addNonceToElements.js +23 -0
- package/dist/csp/createContentSecurityPolicy.js +45 -0
- package/dist/csp/getWebSocketSources.js +36 -0
- package/dist/email/renderAuthEmail.js +99 -0
- package/dist/index.js +22 -5
- package/dist/response/buildEndpointResult.js +3 -1
- package/dist/response/createWireProjection.js +88 -0
- package/dist/response/formatErrorForAgent.js +35 -0
- package/dist/response/normalizeErrorSources.js +10 -13
- package/dist/response/redactErrorResponse.js +42 -8
- package/dist/response/redactResponse.js +17 -10
- package/dist/routes/agent/authorizeAgent.js +17 -5
- package/dist/routes/agent/callAgent.js +12 -2
- package/dist/routes/agent/collectChatFiles.js +39 -0
- package/dist/routes/agent/prepareAgent.js +29 -4
- package/dist/routes/auth/buildAdminPlugin.js +33 -0
- package/dist/routes/auth/buildCaptchaPlugin.js +61 -0
- package/dist/routes/auth/buildMcpTokenPlugin.js +77 -0
- package/dist/routes/auth/buildOauthPostLogin.js +73 -0
- package/dist/routes/auth/buildPhoneNumberPlugin.js +57 -0
- package/dist/routes/auth/buildProviders.js +61 -0
- package/dist/routes/auth/createAsMetadataHandler.js +27 -0
- package/dist/routes/auth/createAuthLogger.js +31 -0
- package/dist/routes/auth/createMcpAccessTokenClaims.js +52 -0
- package/dist/routes/auth/createOnAPIError.js +41 -0
- package/dist/routes/auth/createSendEmail.js +54 -0
- package/dist/routes/auth/ensureMcpTokenIndexes.js +48 -0
- package/dist/routes/auth/getAuthEnforcement.js +41 -0
- package/dist/routes/auth/getBetterAuth.js +107 -0
- package/dist/routes/auth/getBetterAuthConfig.js +767 -0
- package/dist/routes/auth/handleAuthRequest.js +43 -0
- package/dist/routes/auth/hooks/authHookPoints.js +204 -0
- package/dist/routes/auth/hooks/buildEngineHooks.js +68 -0
- package/dist/routes/auth/hooks/buildHooks.js +112 -0
- package/dist/routes/auth/{callbacks/addUserFieldsToSession.js → hooks/composeAfterSlot.js} +11 -13
- package/dist/routes/auth/hooks/composeBeforeSlot.js +41 -0
- package/dist/routes/auth/hooks/createHookDispatch.js +59 -0
- package/dist/routes/auth/hooks/createUserAfterHook.js +36 -0
- package/dist/routes/auth/hooks/createUserBeforeHook.js +50 -0
- package/dist/routes/auth/hooks/findHookUser.js +27 -0
- package/dist/routes/auth/modelNames.js +30 -0
- package/dist/routes/auth/organizations/OrganizationKeyError.js +28 -0
- package/dist/routes/auth/organizations/authorizeRole.js +27 -0
- package/dist/routes/auth/organizations/buildOrganizationPlugin.js +178 -0
- package/dist/routes/auth/organizations/createAcceptActiveOrgGuardHook.js +57 -0
- package/dist/routes/auth/organizations/createAcceptExistingMemberHook.js +120 -0
- package/dist/routes/auth/organizations/createActiveOrgPolicyHook.js +403 -0
- package/dist/routes/auth/organizations/createAdmissionGateHook.js +50 -0
- package/dist/routes/auth/organizations/createAfterAcceptInvitationHook.js +90 -0
- package/dist/routes/auth/organizations/createAutoJoinHook.js +68 -0
- package/dist/routes/auth/organizations/createEmailSendGate.js +59 -0
- package/dist/routes/auth/organizations/createExpiredInvitationGate.js +76 -0
- package/dist/routes/auth/organizations/ensureAuthIndexes.js +122 -0
- package/dist/routes/auth/organizations/ensureOrganization.js +132 -0
- package/dist/routes/auth/organizations/findPendingInvitation.js +43 -0
- package/dist/routes/auth/organizations/getHookRequestHeaders.js +24 -0
- package/dist/routes/auth/organizations/getOrganizationBinding.js +65 -0
- package/dist/routes/auth/organizations/isEmailAdmitted.js +89 -0
- package/dist/routes/auth/organizations/organizationAccessControl.js +94 -0
- package/dist/routes/auth/organizations/resolvePinnedOrganization.js +62 -0
- package/dist/routes/auth/requestHooks/beginTwoFactorChallenge.js +145 -0
- package/dist/routes/auth/requestHooks/buildRequestHooks.js +288 -0
- package/dist/routes/auth/requestHooks/createOauthPostLoginHook.js +43 -0
- package/dist/routes/auth/requestHooks/createTwoFactorChallengeHook.js +59 -0
- package/dist/routes/auth/requestHooks/dispatchRequestHooks.js +47 -0
- package/dist/routes/auth/requestHooks/redirectToChallenge.js +79 -0
- package/dist/routes/auth/requestHooks/resolveTwoFactorPageUrl.js +31 -0
- package/dist/routes/auth/resolveCookiePrefix.js +30 -0
- package/dist/routes/auth/sanitizeSessionResponse.js +27 -0
- package/dist/routes/auth/strategies/getAuthStrategies.js +1 -1
- package/dist/routes/connections/checkUnwalledReach.js +37 -0
- package/dist/routes/connections/getConnectionConfig.js +6 -1
- package/dist/routes/connections/resolveTenantPreflight.js +226 -0
- package/dist/routes/connections/resolveUnwalledReach.js +144 -0
- package/dist/routes/endpoints/acceptDetachedEndpoint.js +50 -0
- package/dist/routes/endpoints/authorizeApiEndpoint.js +13 -4
- package/dist/routes/endpoints/callEndpoint.js +23 -7
- package/dist/routes/endpoints/control/controlFor.js +4 -7
- package/dist/routes/endpoints/control/controlIf.js +4 -8
- package/dist/routes/endpoints/control/controlLog.js +6 -14
- package/dist/routes/endpoints/control/controlParallelFor.js +65 -29
- package/dist/routes/endpoints/control/controlReject.js +36 -16
- package/dist/routes/endpoints/control/controlReturn.js +32 -9
- package/dist/routes/endpoints/control/controlSetState.js +4 -8
- package/dist/routes/endpoints/control/controlSwitch.js +4 -8
- package/dist/routes/endpoints/control/controlThrow.js +20 -21
- package/dist/routes/endpoints/control/controlTry.js +30 -11
- package/dist/routes/endpoints/control/controlWhile.js +55 -0
- package/dist/routes/endpoints/control/handleControl.js +3 -1
- package/dist/routes/endpoints/createWebhookAnswer.js +78 -0
- package/dist/routes/endpoints/evaluateRoutineOperators.js +27 -0
- package/dist/routes/endpoints/forwardScheduledEndpoint.js +21 -15
- package/dist/routes/endpoints/getEndpointConfig.js +18 -8
- package/dist/routes/endpoints/getEnvironmentSchedules.js +5 -7
- package/dist/routes/endpoints/getSchemaValidator.js +39 -0
- package/dist/routes/endpoints/handleAgentCall.js +25 -9
- package/dist/routes/endpoints/handleAuthStep.js +214 -0
- package/dist/routes/endpoints/handleDescribeDynamicPolicy.js +64 -0
- package/dist/routes/endpoints/handleEndpointCall.js +46 -12
- package/dist/routes/endpoints/handleRenderNotification.js +29 -12
- package/dist/routes/endpoints/handleRequest.js +13 -6
- package/dist/routes/endpoints/handleValidateDynamic.js +106 -0
- package/dist/routes/endpoints/handleValidateSchema.js +22 -22
- package/dist/routes/endpoints/invokeEndpoint.js +27 -3
- package/dist/routes/endpoints/operatorScope.js +28 -0
- package/dist/routes/{auth/events/createEventPlugins.js → endpoints/parseWebhookBody.js} +10 -6
- package/dist/routes/endpoints/resolveCallBinding.js +91 -0
- package/dist/routes/endpoints/resolveCronEnvironment.js +7 -6
- package/dist/routes/endpoints/resolveStepOrganizationId.js +64 -0
- package/dist/routes/endpoints/runDetachedEndpoint.js +64 -18
- package/dist/routes/endpoints/runRoutine.js +64 -5
- package/dist/routes/endpoints/runScheduledEndpoint.js +19 -11
- package/dist/routes/endpoints/runWebhookEndpoint.js +70 -23
- package/dist/routes/endpoints/runWebhookVerify.js +129 -0
- package/dist/routes/endpoints/scheduleBackground.js +10 -0
- package/dist/routes/endpoints/test/runTest.js +48 -11
- package/dist/routes/endpoints/validatePayload.js +144 -0
- package/dist/routes/log/logClientError.js +7 -4
- package/dist/routes/mcp/createMcpServer.js +143 -64
- package/dist/routes/mcp/getMcpJwks.js +93 -0
- package/dist/routes/mcp/getMcpResourceBinding.js +41 -0
- package/dist/routes/mcp/getMcpUri.js +69 -0
- package/dist/routes/mcp/oauthResourceLifecycle.js +122 -0
- package/dist/routes/mcp/runAfterToolCall.js +50 -0
- package/dist/routes/notifications/resolveNotificationLinks.js +39 -11
- package/dist/routes/page/dynamic/checkDynamicContent.js +81 -0
- package/dist/routes/page/dynamic/checkLiteralContent.js +242 -0
- package/dist/routes/page/dynamic/createContentError.js +34 -0
- package/dist/routes/page/dynamic/flagIconsOutsidePage.js +39 -0
- package/dist/routes/page/dynamic/flagTypesOutsidePage.js +44 -0
- package/dist/routes/page/dynamic/getPropertiesSchemaErrors.js +35 -0
- package/dist/routes/page/dynamic/loadDynamicArtifacts.js +52 -0
- package/dist/routes/page/dynamic/policy/checkAction.js +204 -0
- package/dist/routes/page/dynamic/policy/checkEvents.js +163 -0
- package/dist/routes/page/dynamic/policy/checkPolicy.js +313 -0
- package/dist/routes/page/dynamic/policy/checkValue.js +214 -0
- package/dist/routes/page/dynamic/policy/collectUrlKinds.js +117 -0
- package/dist/routes/page/dynamic/policy/findEmbeddedUrls.js +54 -0
- package/dist/routes/page/dynamic/policy/findSerializerKeys.js +50 -0
- package/dist/routes/page/dynamic/policy/isAllowedUrl.js +53 -0
- package/dist/routes/{auth/createAdapter.js → page/dynamic/policy/isUnderState.js} +5 -9
- package/dist/routes/page/dynamic/policy/normalizeUrlText.js +25 -0
- package/dist/routes/page/dynamic/resolveDynamicContent.js +89 -37
- package/dist/routes/page/dynamic/unescapeOperators.js +21 -4
- package/dist/routes/page/dynamic/validateFragment.js +17 -58
- package/dist/routes/page/getPageConfig.js +76 -6
- package/dist/routes/request/authorizeRequest.js +21 -6
- package/dist/routes/request/callRequest.js +21 -3
- package/dist/routes/request/callRequestResolver.js +55 -6
- package/dist/routes/request/checkConnectionRead.js +1 -1
- package/dist/routes/request/checkConnectionWrite.js +1 -1
- package/dist/routes/request/createWalledResolver.js +75 -0
- package/dist/routes/request/evaluateOperators.js +8 -12
- package/dist/routes/request/getRequestConfig.js +19 -3
- package/dist/routes/request/maskCredentialProperties.js +34 -0
- package/dist/routes/request/resolveTenancy.js +223 -0
- package/dist/routes/request/validateSchemas.js +7 -6
- package/dist/routes/{auth/callbacks/createCallbackPlugins.js → rootConfig/getAppEvents.js} +7 -6
- package/dist/routes/rootConfig/getHomeAndMenus.js +23 -16
- package/dist/routes/{auth/events/createSessionEvent.js → rootConfig/getPagePaths.js} +16 -18
- package/dist/routes/rootConfig/getRootConfig.js +9 -3
- package/dist/routes/rootConfig/menus/filterMenuList.js +5 -2
- package/dist/routes/websocket/authorizeWebsocket.js +19 -4
- package/dist/routes/websocket/createChannelRegistry.js +39 -14
- package/dist/routes/websocket/createWebSocketConnection.js +162 -28
- package/dist/routes/websocket/getCallerFingerprint.js +31 -0
- package/dist/routes/websocket/prepareChannel.js +29 -1
- package/dist/routes/websocket/resolveWebsocketCaller.js +40 -0
- package/dist/test/testContext.js +16 -11
- package/package.json +28 -12
- package/dist/context/createAuthorize.js +0 -45
- package/dist/response/omitErrorProps.js +0 -51
- package/dist/routes/auth/callbacks/addUserFieldsToToken.js +0 -30
- package/dist/routes/auth/callbacks/createCallbacks.js +0 -46
- package/dist/routes/auth/callbacks/createJWTCallback.js +0 -77
- package/dist/routes/auth/callbacks/createRedirectCallback.js +0 -41
- package/dist/routes/auth/callbacks/createSessionCallback.js +0 -81
- package/dist/routes/auth/callbacks/createSignInCallback.js +0 -40
- package/dist/routes/auth/callbacks/validateSessionRoles.js +0 -33
- package/dist/routes/auth/createLogger.js +0 -35
- package/dist/routes/auth/createPrefixedCookies.js +0 -52
- package/dist/routes/auth/createProviders.js +0 -25
- package/dist/routes/auth/events/createCreateUserEvent.js +0 -41
- package/dist/routes/auth/events/createEvents.js +0 -56
- package/dist/routes/auth/events/createLinkAccountEvent.js +0 -43
- package/dist/routes/auth/events/createSignInEvent.js +0 -46
- package/dist/routes/auth/events/createSignOutEvent.js +0 -43
- package/dist/routes/auth/events/createUpdateUserEvent.js +0 -41
- package/dist/routes/auth/getAuthConfig.js +0 -86
- package/dist/routes/auth/resolveCookies.js +0 -37
- package/dist/routes/log/formatValidationError.js +0 -31
- /package/dist/{routes/notifications → email}/resolveThemeLogo.js +0 -0
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Copyright 2020-2026 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 createJWTCallback from './createJWTCallback.js';
|
|
16
|
-
import createRedirectCallback from './createRedirectCallback.js';
|
|
17
|
-
import createSessionCallback from './createSessionCallback.js';
|
|
18
|
-
import createSignInCallback from './createSignInCallback.js';
|
|
19
|
-
function createCallbacks({ authConfig, logger, plugins }) {
|
|
20
|
-
const callbacks = {
|
|
21
|
-
session: createSessionCallback({
|
|
22
|
-
authConfig,
|
|
23
|
-
logger,
|
|
24
|
-
plugins
|
|
25
|
-
})
|
|
26
|
-
};
|
|
27
|
-
const jwt = createJWTCallback({
|
|
28
|
-
authConfig,
|
|
29
|
-
logger,
|
|
30
|
-
plugins
|
|
31
|
-
});
|
|
32
|
-
if (jwt) callbacks.jwt = jwt;
|
|
33
|
-
const redirect = createRedirectCallback({
|
|
34
|
-
authConfig,
|
|
35
|
-
logger,
|
|
36
|
-
plugins
|
|
37
|
-
});
|
|
38
|
-
if (redirect) callbacks.redirect = redirect;
|
|
39
|
-
const signIn = createSignInCallback({
|
|
40
|
-
authConfig,
|
|
41
|
-
plugins
|
|
42
|
-
});
|
|
43
|
-
if (signIn) callbacks.signIn = signIn;
|
|
44
|
-
return callbacks;
|
|
45
|
-
}
|
|
46
|
-
export default createCallbacks;
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Copyright 2020-2026 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 addUserFieldsToToken from './addUserFieldsToToken.js';
|
|
16
|
-
import createCallbackPlugins from './createCallbackPlugins.js';
|
|
17
|
-
function createJWTCallback({ authConfig, logger, plugins }) {
|
|
18
|
-
const jwtCallbackPlugins = createCallbackPlugins({
|
|
19
|
-
authConfig,
|
|
20
|
-
plugins,
|
|
21
|
-
type: 'jwt'
|
|
22
|
-
});
|
|
23
|
-
async function jwtCallback({ token, user, account, profile, isNewUser }) {
|
|
24
|
-
if (profile) {
|
|
25
|
-
const { id, sub, name, given_name, family_name, middle_name, nickname, preferred_username, profile: profile_claim, picture, website, email, email_verified, gender, birthdate, zoneinfo, locale, phone_number, phone_number_verified, address, updated_at } = profile;
|
|
26
|
-
token = {
|
|
27
|
-
id,
|
|
28
|
-
sub,
|
|
29
|
-
name,
|
|
30
|
-
given_name,
|
|
31
|
-
family_name,
|
|
32
|
-
middle_name,
|
|
33
|
-
nickname,
|
|
34
|
-
preferred_username,
|
|
35
|
-
profile: profile_claim,
|
|
36
|
-
picture,
|
|
37
|
-
website,
|
|
38
|
-
email,
|
|
39
|
-
email_verified,
|
|
40
|
-
gender,
|
|
41
|
-
birthdate,
|
|
42
|
-
zoneinfo,
|
|
43
|
-
locale,
|
|
44
|
-
phone_number,
|
|
45
|
-
phone_number_verified,
|
|
46
|
-
address,
|
|
47
|
-
updated_at,
|
|
48
|
-
...token
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
if (profile || user) {
|
|
52
|
-
if (authConfig.userFields) {
|
|
53
|
-
addUserFieldsToToken({
|
|
54
|
-
authConfig,
|
|
55
|
-
account,
|
|
56
|
-
logger,
|
|
57
|
-
profile,
|
|
58
|
-
token,
|
|
59
|
-
user
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
for (const plugin of jwtCallbackPlugins){
|
|
64
|
-
token = await plugin.fn({
|
|
65
|
-
properties: plugin.properties ?? {},
|
|
66
|
-
account,
|
|
67
|
-
isNewUser,
|
|
68
|
-
profile,
|
|
69
|
-
token,
|
|
70
|
-
user
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
return token;
|
|
74
|
-
}
|
|
75
|
-
return jwtCallback;
|
|
76
|
-
}
|
|
77
|
-
export default createJWTCallback;
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Copyright 2020-2026 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 defaultRedirect({ url, baseUrl }) {
|
|
17
|
-
if (url.startsWith('/')) return `${baseUrl}${url}`;
|
|
18
|
-
else if (new URL(url).origin === baseUrl) return url;
|
|
19
|
-
return baseUrl;
|
|
20
|
-
}
|
|
21
|
-
function createRedirectCallback({ authConfig, plugins }) {
|
|
22
|
-
const redirectCallbackPlugins = createCallbackPlugins({
|
|
23
|
-
authConfig,
|
|
24
|
-
plugins,
|
|
25
|
-
type: 'redirect'
|
|
26
|
-
});
|
|
27
|
-
if (redirectCallbackPlugins.length === 0) return defaultRedirect;
|
|
28
|
-
if (redirectCallbackPlugins.length !== 1) {
|
|
29
|
-
throw new Error('More than one auth redirect callbacks are configured. Only one is allowed.');
|
|
30
|
-
}
|
|
31
|
-
const [plugin] = redirectCallbackPlugins;
|
|
32
|
-
function redirectCallback({ url, baseUrl }) {
|
|
33
|
-
return plugin.fn({
|
|
34
|
-
properties: plugin.properties ?? {},
|
|
35
|
-
baseUrl,
|
|
36
|
-
url
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
return redirectCallback;
|
|
40
|
-
}
|
|
41
|
-
export default createRedirectCallback;
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Copyright 2020-2026 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 crypto from 'crypto';
|
|
16
|
-
import addUserFieldsToSession from './addUserFieldsToSession.js';
|
|
17
|
-
import createCallbackPlugins from './createCallbackPlugins.js';
|
|
18
|
-
import validateSessionRoles from './validateSessionRoles.js';
|
|
19
|
-
function createSessionCallback({ authConfig, plugins }) {
|
|
20
|
-
const sessionCallbackPlugins = createCallbackPlugins({
|
|
21
|
-
authConfig,
|
|
22
|
-
plugins,
|
|
23
|
-
type: 'session'
|
|
24
|
-
});
|
|
25
|
-
async function sessionCallback({ session, token, user }) {
|
|
26
|
-
const identifier = user ? user.id ?? user.sub ?? user.email : token.id ?? token.sub ?? token.email;
|
|
27
|
-
if (token) {
|
|
28
|
-
const { id, 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;
|
|
29
|
-
session.user = {
|
|
30
|
-
id,
|
|
31
|
-
sub,
|
|
32
|
-
name,
|
|
33
|
-
given_name,
|
|
34
|
-
family_name,
|
|
35
|
-
middle_name,
|
|
36
|
-
nickname,
|
|
37
|
-
preferred_username,
|
|
38
|
-
profile,
|
|
39
|
-
picture,
|
|
40
|
-
website,
|
|
41
|
-
email,
|
|
42
|
-
email_verified,
|
|
43
|
-
gender,
|
|
44
|
-
birthdate,
|
|
45
|
-
zoneinfo,
|
|
46
|
-
locale,
|
|
47
|
-
phone_number,
|
|
48
|
-
phone_number_verified,
|
|
49
|
-
address,
|
|
50
|
-
updated_at,
|
|
51
|
-
...session.user
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
if (authConfig.userFields) {
|
|
55
|
-
addUserFieldsToSession({
|
|
56
|
-
authConfig,
|
|
57
|
-
session,
|
|
58
|
-
token,
|
|
59
|
-
user
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
for (const plugin of sessionCallbackPlugins){
|
|
63
|
-
// eslint-disable-next-line no-param-reassign
|
|
64
|
-
session = await plugin.fn({
|
|
65
|
-
properties: plugin.properties ?? {},
|
|
66
|
-
session,
|
|
67
|
-
token,
|
|
68
|
-
user
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
validateSessionRoles({
|
|
72
|
-
session
|
|
73
|
-
});
|
|
74
|
-
// TODO: Should this be session.hashed_id or session.user.hashed_id
|
|
75
|
-
// Only session.user will be available using the _user operator
|
|
76
|
-
session.hashed_id = crypto.createHash('sha256').update(identifier ?? '').digest('base64');
|
|
77
|
-
return session;
|
|
78
|
-
}
|
|
79
|
-
return sessionCallback;
|
|
80
|
-
}
|
|
81
|
-
export default createSessionCallback;
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Copyright 2020-2026 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;
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Copyright 2020-2026 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 { ConfigError } from '@lowdefy/errors';
|
|
16
|
-
import { type } from '@lowdefy/helpers';
|
|
17
|
-
function validateSessionRoles({ session }) {
|
|
18
|
-
const roles = session?.user?.roles;
|
|
19
|
-
if (type.isNone(roles)) return;
|
|
20
|
-
if (!Array.isArray(roles)) {
|
|
21
|
-
throw new ConfigError('session.user.roles must be an array of strings. Check auth.userFields configuration and custom session callback plugins.', {
|
|
22
|
-
received: roles
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
for (const role of roles){
|
|
26
|
-
if (!type.isString(role)) {
|
|
27
|
-
throw new ConfigError('session.user.roles must be an array of strings. Check auth.userFields configuration and custom session callback plugins.', {
|
|
28
|
-
received: roles
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
export default validateSessionRoles;
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Copyright 2020-2026 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
|
-
*/ const authWarnings = {
|
|
16
|
-
NEXTAUTH_URL: 'NEXTAUTH_URL - Environment variable NEXTAUTH_URL is missing. Set it in your .env file. On Vercel, VERCEL_URL is used automatically.',
|
|
17
|
-
NO_SECRET: 'NO_SECRET - No `secret` configured. In development a temporary secret is generated, but production requires an explicit secret.',
|
|
18
|
-
DEBUG_ENABLED: 'DEBUG_ENABLED - NextAuth debug mode is enabled. This is meant for development only — remove it before deploying to production.',
|
|
19
|
-
EXPERIMENTAL_API: 'EXPERIMENTAL_API - An experimental NextAuth API is in use. It may change or be removed in a future version.'
|
|
20
|
-
};
|
|
21
|
-
function createLogger({ logger }) {
|
|
22
|
-
return {
|
|
23
|
-
// Auth.js v5 logger contract: error(error), warn(code), debug(message, metadata).
|
|
24
|
-
error: (error)=>{
|
|
25
|
-
logger.error(error);
|
|
26
|
-
},
|
|
27
|
-
warn: (code)=>{
|
|
28
|
-
logger.warn(authWarnings[code] ?? code);
|
|
29
|
-
},
|
|
30
|
-
debug: (code, metadata)=>{
|
|
31
|
-
logger.debug(metadata, code);
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
export default createLogger;
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Copyright 2020-2026 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 slugifyPrefix(value) {
|
|
16
|
-
return String(value).trim().toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-+|-+$/g, '');
|
|
17
|
-
}
|
|
18
|
-
// Injects an app-specific prefix into each Auth.js cookie name so multiple apps
|
|
19
|
-
// on the same host do not share a cookie jar (browsers do not scope cookies by
|
|
20
|
-
// port). Only names are overridden — Auth.js v5 deep-merges `config.cookies`
|
|
21
|
-
// into its defaults, so cookie options (httpOnly, secure, maxAge) stay in sync
|
|
22
|
-
// with @auth/core's per-request defaults. Names mirror defaultCookies in
|
|
23
|
-
// @auth/core/lib/utils/cookie.js.
|
|
24
|
-
function createPrefixedCookies({ prefix, useSecureCookies }) {
|
|
25
|
-
const securePrefix = useSecureCookies ? '__Secure-' : '';
|
|
26
|
-
const hostPrefix = useSecureCookies ? '__Host-' : '';
|
|
27
|
-
return {
|
|
28
|
-
sessionToken: {
|
|
29
|
-
name: `${securePrefix}${prefix}.authjs.session-token`
|
|
30
|
-
},
|
|
31
|
-
callbackUrl: {
|
|
32
|
-
name: `${securePrefix}${prefix}.authjs.callback-url`
|
|
33
|
-
},
|
|
34
|
-
csrfToken: {
|
|
35
|
-
name: `${hostPrefix}${prefix}.authjs.csrf-token`
|
|
36
|
-
},
|
|
37
|
-
pkceCodeVerifier: {
|
|
38
|
-
name: `${securePrefix}${prefix}.authjs.pkce.code_verifier`
|
|
39
|
-
},
|
|
40
|
-
state: {
|
|
41
|
-
name: `${securePrefix}${prefix}.authjs.state`
|
|
42
|
-
},
|
|
43
|
-
nonce: {
|
|
44
|
-
name: `${securePrefix}${prefix}.authjs.nonce`
|
|
45
|
-
},
|
|
46
|
-
webauthnChallenge: {
|
|
47
|
-
name: `${securePrefix}${prefix}.authjs.challenge`
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
export { slugifyPrefix };
|
|
52
|
-
export default createPrefixedCookies;
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Copyright 2020-2026 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;
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Copyright 2020-2026 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;
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Copyright 2020-2026 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;
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Copyright 2020-2026 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;
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Copyright 2020-2026 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;
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Copyright 2020-2026 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;
|