@lowdefy/plugin-next-auth 0.0.0-experimental-20260806121008 → 0.0.0-experimental-20260827092002
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/types.js +0 -4
- package/package.json +3 -11
- package/dist/auth/strategies/apiKey.js +0 -60
- package/dist/auth/strategies/jwt.js +0 -137
- package/dist/auth/strategies.js +0 -20
package/dist/types.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lowdefy/plugin-next-auth",
|
|
3
|
-
"version": "0.0.0-experimental-
|
|
3
|
+
"version": "0.0.0-experimental-20260827092002",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"description": "",
|
|
6
6
|
"homepage": "https://lowdefy.com",
|
|
@@ -29,28 +29,21 @@
|
|
|
29
29
|
"exports": {
|
|
30
30
|
".": "./dist/index.js",
|
|
31
31
|
"./auth/providers": "./dist/auth/providers.js",
|
|
32
|
-
"./auth/strategies": "./dist/auth/strategies.js",
|
|
33
32
|
"./types": "./dist/types.js"
|
|
34
33
|
},
|
|
35
34
|
"files": [
|
|
36
35
|
"dist/*"
|
|
37
36
|
],
|
|
38
|
-
"dependencies": {
|
|
39
|
-
"@lowdefy/helpers": "0.0.0-experimental-20260806121008",
|
|
40
|
-
"jose": "^6.2.3"
|
|
41
|
-
},
|
|
42
37
|
"peerDependencies": {
|
|
43
38
|
"@auth/core": ">=0.41.2"
|
|
44
39
|
},
|
|
45
40
|
"devDependencies": {
|
|
46
41
|
"@auth/core": "0.41.2",
|
|
47
|
-
"@
|
|
48
|
-
"@lowdefy/node-utils": "0.0.0-experimental-20260806121008",
|
|
42
|
+
"@lowdefy/node-utils": "0.0.0-experimental-20260827092002",
|
|
49
43
|
"@swc/cli": "0.8.1",
|
|
50
44
|
"@swc/core": "1.15.32",
|
|
51
45
|
"@swc/jest": "0.2.39",
|
|
52
46
|
"jest": "28.1.3",
|
|
53
|
-
"jest-environment-node": "28.1.3",
|
|
54
47
|
"react": "18.2.0",
|
|
55
48
|
"react-dom": "18.2.0"
|
|
56
49
|
},
|
|
@@ -59,7 +52,6 @@
|
|
|
59
52
|
},
|
|
60
53
|
"scripts": {
|
|
61
54
|
"build": "swc src --out-dir dist --config-file ../../../../.swcrc --cli-config-file ../../../../.swc-cli.json --copy-files",
|
|
62
|
-
"clean": "rm -rf dist"
|
|
63
|
-
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js"
|
|
55
|
+
"clean": "rm -rf dist"
|
|
64
56
|
}
|
|
65
57
|
}
|
|
@@ -1,60 +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 { createHash, timingSafeEqual } from 'node:crypto';
|
|
16
|
-
import { type } from '@lowdefy/helpers';
|
|
17
|
-
function sha256(value) {
|
|
18
|
-
return createHash('sha256').update(value).digest();
|
|
19
|
-
}
|
|
20
|
-
// Static API key strategy - reads a dedicated header (default X-API-Key, set
|
|
21
|
-
// by build) and compares against the configured keys. Both sides are hashed
|
|
22
|
-
// to SHA-256 before timingSafeEqual: the digests are a fixed 32 bytes, so the
|
|
23
|
-
// comparison runs in constant time without a length fast-path that would leak
|
|
24
|
-
// key length through timing.
|
|
25
|
-
function apiKey({ logger, properties, strategyId }) {
|
|
26
|
-
const headerName = properties.headerName;
|
|
27
|
-
const keys = properties.keys.map((key, index)=>{
|
|
28
|
-
const keyId = type.isNone(key.id) ? String(index) : key.id;
|
|
29
|
-
if (!type.isString(key.value)) {
|
|
30
|
-
throw new Error(`Auth strategy "${strategyId}" key "${keyId}" did not resolve to a string. Check the _secret operator reference and that the secret is set.`);
|
|
31
|
-
}
|
|
32
|
-
// Secrets are opaque at build time; strength checks are startup warnings.
|
|
33
|
-
if (key.value.length < 32) {
|
|
34
|
-
logger.warn(`Auth strategy "${strategyId}" key "${keyId}" is shorter than 32 characters. Use a long random value, e.g. \`openssl rand -hex 32\`.`);
|
|
35
|
-
}
|
|
36
|
-
return {
|
|
37
|
-
digest: sha256(key.value),
|
|
38
|
-
id: keyId
|
|
39
|
-
};
|
|
40
|
-
});
|
|
41
|
-
return async function verify({ headers }) {
|
|
42
|
-
const presented = headers.get(headerName);
|
|
43
|
-
if (!presented) {
|
|
44
|
-
return null;
|
|
45
|
-
}
|
|
46
|
-
const presentedDigest = sha256(presented);
|
|
47
|
-
const match = keys.find((key)=>timingSafeEqual(presentedDigest, key.digest));
|
|
48
|
-
if (type.isNone(match)) {
|
|
49
|
-
return null;
|
|
50
|
-
}
|
|
51
|
-
// Synthetic caller id with per-key audit identity - the key index stands
|
|
52
|
-
// in when the config sets no key id.
|
|
53
|
-
return {
|
|
54
|
-
user: {
|
|
55
|
-
id: `apiKey:${strategyId}:${match.id}`
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
export default apiKey;
|
|
@@ -1,137 +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 { createRemoteJWKSet, jwtVerify } from 'jose';
|
|
16
|
-
import { get, type } from '@lowdefy/helpers';
|
|
17
|
-
// Prototype-pollution vectors - build rejects reserved claimMapping fields,
|
|
18
|
-
// and reserved claim paths resolve to no claim here as defense in depth: the
|
|
19
|
-
// id claim then rejects the token, and any other mapping entry is skipped.
|
|
20
|
-
const reservedKeys = new Set([
|
|
21
|
-
'__proto__',
|
|
22
|
-
'constructor',
|
|
23
|
-
'prototype',
|
|
24
|
-
'__defineGetter__',
|
|
25
|
-
'__defineSetter__',
|
|
26
|
-
'__lookupGetter__',
|
|
27
|
-
'__lookupSetter__'
|
|
28
|
-
]);
|
|
29
|
-
function readClaim({ claimPath, payload }) {
|
|
30
|
-
if (String(claimPath).split('.').some((segment)=>reservedKeys.has(segment))) {
|
|
31
|
-
return undefined;
|
|
32
|
-
}
|
|
33
|
-
return get(payload, claimPath);
|
|
34
|
-
}
|
|
35
|
-
function toRoles(value) {
|
|
36
|
-
if (type.isArray(value)) {
|
|
37
|
-
return value.filter((role)=>type.isString(role));
|
|
38
|
-
}
|
|
39
|
-
if (type.isString(value)) {
|
|
40
|
-
return [
|
|
41
|
-
value
|
|
42
|
-
];
|
|
43
|
-
}
|
|
44
|
-
return [];
|
|
45
|
-
}
|
|
46
|
-
// JWT strategy - verifies third-party Bearer tokens locally with jose, HMAC
|
|
47
|
-
// (secret) or JWKS (jwksUri; createRemoteJWKSet caches keys and handles
|
|
48
|
-
// rotation). Build guarantees exactly one of secret/jwksUri and a non-empty
|
|
49
|
-
// algorithms allowlist - the allowlist is what stops an `alg: none` or
|
|
50
|
-
// downgraded-algorithm token from verifying.
|
|
51
|
-
function jwt({ logger, properties, strategyId }) {
|
|
52
|
-
const { algorithms, audience, issuer, jwksUri, secret } = properties;
|
|
53
|
-
const claimMapping = properties.claimMapping ?? {};
|
|
54
|
-
let key;
|
|
55
|
-
if (!type.isNone(secret)) {
|
|
56
|
-
if (!type.isString(secret)) {
|
|
57
|
-
throw new Error(`Auth strategy "${strategyId}" "secret" did not resolve to a string. Check the _secret operator reference and that the secret is set.`);
|
|
58
|
-
}
|
|
59
|
-
// Secrets are opaque at build time; strength checks are startup warnings.
|
|
60
|
-
if (secret.length < 32) {
|
|
61
|
-
logger.warn(`Auth strategy "${strategyId}" "secret" is shorter than 32 characters. Use a long random value, e.g. \`openssl rand -base64 32\`.`);
|
|
62
|
-
}
|
|
63
|
-
key = new TextEncoder().encode(secret);
|
|
64
|
-
} else {
|
|
65
|
-
key = createRemoteJWKSet(new URL(jwksUri));
|
|
66
|
-
}
|
|
67
|
-
return async function verify({ headers, logger: requestLogger }) {
|
|
68
|
-
const authorization = headers.get('authorization');
|
|
69
|
-
if (!authorization || !authorization.startsWith('Bearer ')) {
|
|
70
|
-
return null;
|
|
71
|
-
}
|
|
72
|
-
const token = authorization.slice('Bearer '.length).trim();
|
|
73
|
-
let payload;
|
|
74
|
-
try {
|
|
75
|
-
({ payload } = await jwtVerify(token, key, {
|
|
76
|
-
algorithms,
|
|
77
|
-
audience,
|
|
78
|
-
issuer
|
|
79
|
-
}));
|
|
80
|
-
} catch (error) {
|
|
81
|
-
// An invalid token is not this strategy's caller - resolution moves on
|
|
82
|
-
// to the next strategy instead of failing the request.
|
|
83
|
-
(requestLogger ?? logger).debug({
|
|
84
|
-
event: 'auth_strategy_token_rejected',
|
|
85
|
-
strategyId,
|
|
86
|
-
err: error
|
|
87
|
-
}, `Auth strategy "${strategyId}" rejected a Bearer token: ${error.message}`);
|
|
88
|
-
return null;
|
|
89
|
-
}
|
|
90
|
-
const idClaim = claimMapping.id ?? 'sub';
|
|
91
|
-
const id = readClaim({
|
|
92
|
-
claimPath: idClaim,
|
|
93
|
-
payload
|
|
94
|
-
});
|
|
95
|
-
if (type.isNone(id)) {
|
|
96
|
-
// A caller without an identity cannot be authenticated - a signed token
|
|
97
|
-
// missing the id claim is rejected, not promoted to an id-less caller.
|
|
98
|
-
(requestLogger ?? logger).debug({
|
|
99
|
-
event: 'auth_strategy_token_rejected',
|
|
100
|
-
strategyId
|
|
101
|
-
}, `Auth strategy "${strategyId}" rejected a Bearer token: the "${idClaim}" id claim is missing.`);
|
|
102
|
-
return null;
|
|
103
|
-
}
|
|
104
|
-
const user = {
|
|
105
|
-
id
|
|
106
|
-
};
|
|
107
|
-
const attributes = {};
|
|
108
|
-
let roles = [];
|
|
109
|
-
Object.entries(claimMapping).forEach(([field, claimPath])=>{
|
|
110
|
-
if (field === 'id') {
|
|
111
|
-
return;
|
|
112
|
-
}
|
|
113
|
-
const value = readClaim({
|
|
114
|
-
claimPath,
|
|
115
|
-
payload
|
|
116
|
-
});
|
|
117
|
-
if (field === 'roles') {
|
|
118
|
-
roles = toRoles(value);
|
|
119
|
-
return;
|
|
120
|
-
}
|
|
121
|
-
if (type.isNone(value)) {
|
|
122
|
-
return;
|
|
123
|
-
}
|
|
124
|
-
if (field.startsWith('attributes.')) {
|
|
125
|
-
attributes[field.slice('attributes.'.length)] = value;
|
|
126
|
-
return;
|
|
127
|
-
}
|
|
128
|
-
user[field] = value;
|
|
129
|
-
});
|
|
130
|
-
return {
|
|
131
|
-
attributes,
|
|
132
|
-
roles,
|
|
133
|
-
user
|
|
134
|
-
};
|
|
135
|
-
};
|
|
136
|
-
}
|
|
137
|
-
export default jwt;
|
package/dist/auth/strategies.js
DELETED
|
@@ -1,20 +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
|
-
*/ // API auth strategy verifier factories. Each factory receives a strategy's
|
|
16
|
-
// resolved properties at startup and returns an async verify({ headers,
|
|
17
|
-
// logger }) that resolves a match or null - strategy order and caller
|
|
18
|
-
// assembly live in @lowdefy/api's resolveStrategyCaller.
|
|
19
|
-
export { default as apiKey } from './strategies/apiKey.js';
|
|
20
|
-
export { default as jwt } from './strategies/jwt.js';
|