@lowdefy/api 0.0.0-experimental-20260813120102 → 0.0.0-experimental-20260814133003
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/createApiContext.js +3 -18
- package/dist/context/createAuthorize.js +45 -0
- package/dist/context/createEvaluateOperators.js +1 -2
- package/dist/index.js +4 -12
- package/dist/routes/agent/prepareAgent.js +11 -7
- package/dist/routes/auth/{organizations/getHookRequestHeaders.js → callbacks/addUserFieldsToSession.js} +13 -9
- package/dist/routes/auth/callbacks/addUserFieldsToToken.js +30 -0
- package/dist/routes/auth/{hooks/composeAfterSlot.js → callbacks/createCallbackPlugins.js} +6 -11
- package/dist/routes/auth/callbacks/createCallbacks.js +46 -0
- package/dist/routes/auth/callbacks/createJWTCallback.js +77 -0
- package/dist/routes/auth/callbacks/createRedirectCallback.js +41 -0
- package/dist/routes/auth/callbacks/createSessionCallback.js +81 -0
- package/dist/routes/auth/callbacks/createSignInCallback.js +40 -0
- package/dist/routes/auth/callbacks/validateSessionRoles.js +33 -0
- package/dist/routes/auth/{strategies/getAuthStrategies.js → createAdapter.js} +8 -15
- package/dist/routes/auth/createLogger.js +35 -0
- package/dist/routes/auth/createPrefixedCookies.js +52 -0
- package/dist/routes/auth/createProviders.js +25 -0
- package/dist/routes/auth/events/createCreateUserEvent.js +41 -0
- package/dist/routes/auth/{modelNames.js → events/createEventPlugins.js} +7 -15
- 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/getAuthConfig.js +86 -0
- package/dist/routes/auth/resolveCookies.js +37 -0
- package/dist/routes/endpoints/addStepResult.js +2 -12
- package/dist/routes/endpoints/authorizeApiEndpoint.js +3 -18
- package/dist/routes/endpoints/callEndpoint.js +14 -13
- package/dist/routes/endpoints/control/controlSetState.js +2 -13
- package/dist/routes/endpoints/getEndpointConfig.js +3 -19
- package/dist/routes/endpoints/handleEndpointCall.js +1 -14
- package/dist/routes/endpoints/handleRenderNotification.js +1 -1
- package/dist/routes/endpoints/handleRequest.js +1 -8
- package/dist/routes/endpoints/runDetachedEndpoint.js +25 -37
- package/dist/routes/endpoints/runRoutine.js +1 -9
- package/dist/routes/endpoints/runScheduledEndpoint.js +20 -14
- package/dist/routes/endpoints/runWebhookEndpoint.js +26 -53
- package/dist/routes/endpoints/test/runTest.js +4 -3
- package/dist/routes/page/getPageConfig.js +5 -55
- package/dist/routes/request/authorizeRequest.js +3 -20
- package/dist/routes/request/callRequest.js +2 -10
- package/dist/routes/request/callRequestResolver.js +2 -6
- package/dist/routes/request/getRequestConfig.js +3 -19
- package/dist/routes/rootConfig/menus/filterMenuList.js +2 -5
- package/dist/routes/websocket/authorizeWebsocket.js +3 -12
- package/dist/routes/websocket/createChannelRegistry.js +5 -14
- package/dist/routes/websocket/prepareChannel.js +1 -13
- package/dist/test/testContext.js +8 -18
- package/package.json +9 -14
- package/dist/context/applySystemTrust.js +0 -33
- package/dist/context/createAuthorizeOutcome.js +0 -91
- package/dist/context/createSystemContext.js +0 -78
- package/dist/context/normalizeInjectedCaller.js +0 -50
- package/dist/context/resolveAuthentication.js +0 -240
- package/dist/context/resolveStrategyCaller.js +0 -60
- package/dist/email/renderAuthEmail.js +0 -98
- package/dist/response/buildEndpointResult.js +0 -33
- package/dist/response/normalizeErrorSources.js +0 -64
- package/dist/response/omitErrorProps.js +0 -51
- package/dist/response/redactErrorResponse.js +0 -30
- package/dist/response/redactResponse.js +0 -31
- package/dist/routes/auth/buildAdminPlugin.js +0 -33
- package/dist/routes/auth/buildCaptchaPlugin.js +0 -61
- package/dist/routes/auth/buildPhoneNumberPlugin.js +0 -57
- package/dist/routes/auth/buildProviders.js +0 -51
- package/dist/routes/auth/createAuthLogger.js +0 -31
- package/dist/routes/auth/createSendEmail.js +0 -49
- package/dist/routes/auth/getAuthEnforcement.js +0 -41
- package/dist/routes/auth/getBetterAuth.js +0 -72
- package/dist/routes/auth/getBetterAuthConfig.js +0 -523
- package/dist/routes/auth/hooks/authHookPoints.js +0 -192
- package/dist/routes/auth/hooks/buildEngineHooks.js +0 -57
- package/dist/routes/auth/hooks/buildHooks.js +0 -111
- package/dist/routes/auth/hooks/composeBeforeSlot.js +0 -41
- package/dist/routes/auth/hooks/createHookDispatch.js +0 -59
- package/dist/routes/auth/hooks/createUserAfterHook.js +0 -33
- package/dist/routes/auth/hooks/createUserBeforeHook.js +0 -47
- package/dist/routes/auth/hooks/findHookUser.js +0 -27
- package/dist/routes/auth/organizations/OrganizationKeyError.js +0 -28
- package/dist/routes/auth/organizations/authorizeRole.js +0 -27
- package/dist/routes/auth/organizations/buildOrganizationPlugin.js +0 -131
- package/dist/routes/auth/organizations/createActiveOrgPolicyHook.js +0 -237
- package/dist/routes/auth/organizations/createAdmissionGateHook.js +0 -50
- package/dist/routes/auth/organizations/createAfterAcceptInvitationHook.js +0 -90
- package/dist/routes/auth/organizations/createAutoJoinHook.js +0 -67
- package/dist/routes/auth/organizations/createMagicLinkSendGate.js +0 -58
- package/dist/routes/auth/organizations/ensureOrganization.js +0 -132
- package/dist/routes/auth/organizations/findPendingInvitation.js +0 -43
- package/dist/routes/auth/organizations/getOrganizationBinding.js +0 -65
- package/dist/routes/auth/organizations/isEmailAdmitted.js +0 -89
- package/dist/routes/auth/organizations/organizationAccessControl.js +0 -94
- package/dist/routes/auth/organizations/resolvePinnedOrganization.js +0 -61
- package/dist/routes/auth/requestHooks/beginTwoFactorChallenge.js +0 -145
- package/dist/routes/auth/requestHooks/buildRequestHooks.js +0 -179
- package/dist/routes/auth/requestHooks/createTwoFactorChallengeHook.js +0 -59
- package/dist/routes/auth/requestHooks/dispatchRequestHooks.js +0 -45
- package/dist/routes/auth/requestHooks/matchOAuthCallback.js +0 -47
- package/dist/routes/auth/requestHooks/redirectToChallenge.js +0 -79
- package/dist/routes/auth/requestHooks/resolveTwoFactorPageUrl.js +0 -31
- package/dist/routes/auth/resolveCookiePrefix.js +0 -30
- package/dist/routes/auth/strategies/createAuthStrategies.js +0 -77
- package/dist/routes/connections/resolveTenantPreflight.js +0 -172
- package/dist/routes/endpoints/handleAuthStep.js +0 -204
- package/dist/routes/endpoints/resolveStepOrganizationId.js +0 -64
- package/dist/routes/endpoints/runWebhookVerify.js +0 -111
- package/dist/routes/request/resolveTenant.js +0 -111
- /package/dist/{email → routes/notifications}/resolveThemeLogo.js +0 -0
|
@@ -12,14 +12,11 @@
|
|
|
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
|
|
15
|
+
*/ import createAuthorize from './createAuthorize.js';
|
|
16
16
|
import createReadConfigFile from './createReadConfigFile.js';
|
|
17
|
-
import getAuthEnforcement from '../routes/auth/getAuthEnforcement.js';
|
|
18
|
-
import getOrganizationBinding from '../routes/auth/organizations/getOrganizationBinding.js';
|
|
19
17
|
import resolveLocale from './resolveLocale.js';
|
|
20
18
|
function createApiContext(context) {
|
|
21
|
-
|
|
22
|
-
// dev/e2e caller) before this runs - never assigned here.
|
|
19
|
+
context.user = context?.session?.user;
|
|
23
20
|
if (context.i18n?.defaultLocale) {
|
|
24
21
|
const active = resolveLocale({
|
|
25
22
|
i18n: context.i18n,
|
|
@@ -32,19 +29,7 @@ function createApiContext(context) {
|
|
|
32
29
|
} else {
|
|
33
30
|
context.i18n = undefined;
|
|
34
31
|
}
|
|
35
|
-
|
|
36
|
-
// _organization operator and the org-scoped admin steps; null when auth
|
|
37
|
-
// (or organizations) is not configured.
|
|
38
|
-
context.organization = getOrganizationBinding({
|
|
39
|
-
auth: context.auth ?? null
|
|
40
|
-
});
|
|
41
|
-
// The retained build-time authorization facts - the enrolment floor, the exempt
|
|
42
|
-
// enrolment page, and the unlisted-page-id default. null when auth is not
|
|
43
|
-
// configured, in which case nothing is protected and nothing is required.
|
|
44
|
-
context.authEnforcement = getAuthEnforcement({
|
|
45
|
-
auth: context.auth ?? null
|
|
46
|
-
});
|
|
47
|
-
context.authorizeOutcome = createAuthorizeOutcome(context);
|
|
32
|
+
context.authorize = createAuthorize(context);
|
|
48
33
|
context.readConfigFile = createReadConfigFile(context);
|
|
49
34
|
}
|
|
50
35
|
export default createApiContext;
|
|
@@ -0,0 +1,45 @@
|
|
|
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
|
+
function createAuthorize({ session, system = false }) {
|
|
17
|
+
// Next-auth getSession provides a session object if the user is authenticated
|
|
18
|
+
// else session will be null
|
|
19
|
+
const authenticated = !!session;
|
|
20
|
+
const roles = session?.user?.roles ?? [];
|
|
21
|
+
if (!Array.isArray(roles)) {
|
|
22
|
+
throw new ConfigError('session.user.roles must be an array of strings.', {
|
|
23
|
+
received: roles
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
function authorize(config) {
|
|
27
|
+
// A system context (scheduled, webhook, detached runs) was authorized at the
|
|
28
|
+
// transport layer, so nested endpoint calls are never gated on a user session.
|
|
29
|
+
if (system === true) return true;
|
|
30
|
+
const { auth } = config;
|
|
31
|
+
if (auth.public === true) return true;
|
|
32
|
+
if (auth.public === false) {
|
|
33
|
+
if (auth.roles) {
|
|
34
|
+
return authenticated && auth.roles.some((role)=>roles.includes(role));
|
|
35
|
+
}
|
|
36
|
+
return authenticated;
|
|
37
|
+
}
|
|
38
|
+
throw new ConfigError('auth.public must be true or false.', {
|
|
39
|
+
received: auth.public,
|
|
40
|
+
configKey: config['~k']
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
return authorize;
|
|
44
|
+
}
|
|
45
|
+
export default createAuthorize;
|
|
@@ -14,13 +14,12 @@
|
|
|
14
14
|
limitations under the License.
|
|
15
15
|
*/ import { ServerParser } from '@lowdefy/operators';
|
|
16
16
|
function createEvaluateOperators(context) {
|
|
17
|
-
const { appMeta, i18n, jsMap, operators,
|
|
17
|
+
const { appMeta, i18n, jsMap, operators, secrets, user } = context;
|
|
18
18
|
const operatorsParser = new ServerParser({
|
|
19
19
|
i18n,
|
|
20
20
|
jsMap,
|
|
21
21
|
lowdefyApp: appMeta,
|
|
22
22
|
operators,
|
|
23
|
-
organization,
|
|
24
23
|
secrets,
|
|
25
24
|
user
|
|
26
25
|
});
|
package/dist/index.js
CHANGED
|
@@ -12,28 +12,20 @@
|
|
|
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
|
-
import callAgent from './routes/agent/callAgent.js';
|
|
15
|
+
*/ import callAgent from './routes/agent/callAgent.js';
|
|
17
16
|
import callEndpoint from './routes/endpoints/callEndpoint.js';
|
|
18
17
|
import getEndpointConfig from './routes/endpoints/getEndpointConfig.js';
|
|
19
18
|
import callRequest from './routes/request/callRequest.js';
|
|
20
19
|
import createApiContext from './context/createApiContext.js';
|
|
21
20
|
import createChannelRegistry from './routes/websocket/createChannelRegistry.js';
|
|
22
|
-
import createSystemContext from './context/createSystemContext.js';
|
|
23
21
|
import createWebSocketConnection from './routes/websocket/createWebSocketConnection.js';
|
|
24
|
-
import
|
|
25
|
-
import
|
|
22
|
+
import createSessionCallback from './routes/auth/callbacks/createSessionCallback.js';
|
|
23
|
+
import getAuthConfig from './routes/auth/getAuthConfig.js';
|
|
26
24
|
import getHomeAndMenus from './routes/rootConfig/getHomeAndMenus.js';
|
|
27
25
|
import getPageConfig from './routes/page/getPageConfig.js';
|
|
28
26
|
import getRootConfig from './routes/rootConfig/getRootConfig.js';
|
|
29
27
|
import logClientError from './routes/log/logClientError.js';
|
|
30
|
-
import normalizeInjectedCaller from './context/normalizeInjectedCaller.js';
|
|
31
|
-
import redactErrorResponse from './response/redactErrorResponse.js';
|
|
32
|
-
import redactResponse from './response/redactResponse.js';
|
|
33
|
-
import resolveAuthentication from './context/resolveAuthentication.js';
|
|
34
|
-
import resolvePinnedOrganization from './routes/auth/organizations/resolvePinnedOrganization.js';
|
|
35
|
-
import resolveTenantPreflight from './routes/connections/resolveTenantPreflight.js';
|
|
36
28
|
import runDetachedEndpoint from './routes/endpoints/runDetachedEndpoint.js';
|
|
37
29
|
import runWebhookEndpoint from './routes/endpoints/runWebhookEndpoint.js';
|
|
38
30
|
import runScheduledEndpoint from './routes/endpoints/runScheduledEndpoint.js';
|
|
39
|
-
export {
|
|
31
|
+
export { callAgent, callEndpoint, getEndpointConfig, callRequest, createApiContext, createChannelRegistry, createSessionCallback, createWebSocketConnection, getAuthConfig, getHomeAndMenus, getPageConfig, getRootConfig, logClientError, runDetachedEndpoint, runWebhookEndpoint, runScheduledEndpoint };
|
|
@@ -12,8 +12,7 @@
|
|
|
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 { type } from '@lowdefy/helpers';
|
|
16
|
-
import buildEndpointResult from '../../response/buildEndpointResult.js';
|
|
15
|
+
*/ import { serializer, type } from '@lowdefy/helpers';
|
|
17
16
|
import getEndpointConfig from '../endpoints/getEndpointConfig.js';
|
|
18
17
|
import invokeEndpoint from '../endpoints/invokeEndpoint.js';
|
|
19
18
|
import getAgentConfig from './getAgentConfig.js';
|
|
@@ -81,11 +80,16 @@ async function prepareAgent(context, { agentId, agentContext, endpointDepth = 0,
|
|
|
81
80
|
payload,
|
|
82
81
|
endpointDepth
|
|
83
82
|
});
|
|
84
|
-
|
|
85
|
-
error,
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
83
|
+
const success = ![
|
|
84
|
+
'error',
|
|
85
|
+
'reject'
|
|
86
|
+
].includes(status);
|
|
87
|
+
return {
|
|
88
|
+
error: serializer.serialize(error),
|
|
89
|
+
response: serializer.serialize(response),
|
|
90
|
+
status: success ? 'success' : status,
|
|
91
|
+
success
|
|
92
|
+
};
|
|
89
93
|
},
|
|
90
94
|
getEndpointConfig: async ({ endpointId })=>{
|
|
91
95
|
return getEndpointConfig(context, {
|
|
@@ -12,13 +12,17 @@
|
|
|
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
|
-
*/
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
15
|
+
*/ import { get, set } from '@lowdefy/helpers';
|
|
16
|
+
function addUserFieldsToSession({ session, token, authConfig, user }) {
|
|
17
|
+
if (token) {
|
|
18
|
+
Object.keys(authConfig.userFields).forEach((fieldName)=>{
|
|
19
|
+
set(session.user, fieldName, get(token, fieldName));
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
if (user) {
|
|
23
|
+
Object.keys(authConfig.userFields).forEach((fieldName)=>{
|
|
24
|
+
set(session.user, fieldName, get(user, fieldName));
|
|
25
|
+
});
|
|
26
|
+
}
|
|
23
27
|
}
|
|
24
|
-
export default
|
|
28
|
+
export default addUserFieldsToSession;
|
|
@@ -0,0 +1,30 @@
|
|
|
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 { get, set } from '@lowdefy/helpers';
|
|
16
|
+
function addUserFieldsToToken({ account, authConfig, logger, profile, token, user }) {
|
|
17
|
+
const objects = {
|
|
18
|
+
account,
|
|
19
|
+
profile,
|
|
20
|
+
user
|
|
21
|
+
};
|
|
22
|
+
logger.debug('Adding userFields to user. Available provider data is:');
|
|
23
|
+
logger.debug(objects);
|
|
24
|
+
Object.entries(authConfig.userFields).forEach(([lowdefyFieldName, providerFieldName])=>{
|
|
25
|
+
const value = get(objects, providerFieldName);
|
|
26
|
+
logger.debug(`Adding provider field "${providerFieldName}" with value ${JSON.stringify(value)} as "${lowdefyFieldName}"`);
|
|
27
|
+
set(token, lowdefyFieldName, value);
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
export default addUserFieldsToToken;
|
|
@@ -12,15 +12,10 @@
|
|
|
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
|
-
*/
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
return async function afterSlot(data, ctx) {
|
|
21
|
-
for (const hook of hooks){
|
|
22
|
-
await hook(data, ctx);
|
|
23
|
-
}
|
|
24
|
-
};
|
|
15
|
+
*/ function createCallbackPlugins({ authConfig, plugins, type }) {
|
|
16
|
+
return authConfig.callbacks.map((callbackConfig)=>({
|
|
17
|
+
fn: plugins.callbacks[callbackConfig.type],
|
|
18
|
+
properties: callbackConfig.properties
|
|
19
|
+
})).filter((callback)=>callback.fn.meta.type === type);
|
|
25
20
|
}
|
|
26
|
-
export default
|
|
21
|
+
export default createCallbackPlugins;
|
|
@@ -0,0 +1,46 @@
|
|
|
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;
|
|
@@ -0,0 +1,77 @@
|
|
|
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;
|
|
@@ -0,0 +1,41 @@
|
|
|
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;
|
|
@@ -0,0 +1,81 @@
|
|
|
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;
|
|
@@ -0,0 +1,40 @@
|
|
|
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;
|
|
@@ -0,0 +1,33 @@
|
|
|
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;
|
|
@@ -12,20 +12,13 @@
|
|
|
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
|
-
*/
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
strategies = createAuthStrategies({
|
|
23
|
-
appMeta,
|
|
24
|
-
authJson,
|
|
25
|
-
logger,
|
|
26
|
-
plugins,
|
|
27
|
-
secrets
|
|
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
|
|
28
22
|
});
|
|
29
|
-
return strategies;
|
|
30
23
|
}
|
|
31
|
-
export default
|
|
24
|
+
export default createAdapter;
|
|
@@ -0,0 +1,35 @@
|
|
|
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;
|