Files
klz-cables.com/.pnpm-store/v10/files/6d/b31d1f4c0b981f81ff8874ae4d63d406959555426560eae91c39254f8908ead1ae2d458b5523dce9a0105fc60158672d5c3e5d968556e2e2c49b5c1b61726d
Marc Mintel 5397309103
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
fix(products): fix breadcrumbs and product filtering (backport from main)
2026-02-24 16:04:21 +01:00

65 lines
2.4 KiB
Plaintext

import crypto from 'crypto';
export const APIKeyAuthentication = (collectionConfig)=>async ({ headers, isGraphQL = false, payload })=>{
const authHeader = headers.get('Authorization');
if (authHeader?.startsWith(`${collectionConfig.slug} API-Key `)) {
const apiKey = authHeader.replace(`${collectionConfig.slug} API-Key `, '');
// TODO: V4 remove extra algorithm check
// api keys saved prior to v3.46.0 will have sha1
const sha1APIKeyIndex = crypto.createHmac('sha1', payload.secret).update(apiKey).digest('hex');
const sha256APIKeyIndex = crypto.createHmac('sha256', payload.secret).update(apiKey).digest('hex');
const apiKeyConstraints = [
{
apiKeyIndex: {
equals: sha1APIKeyIndex
}
},
{
apiKeyIndex: {
equals: sha256APIKeyIndex
}
}
];
try {
const where = {};
if (collectionConfig.auth?.verify) {
where.and = [
{
or: apiKeyConstraints
},
{
_verified: {
not_equals: false
}
}
];
} else {
where.or = apiKeyConstraints;
}
const userQuery = await payload.find({
collection: collectionConfig.slug,
depth: isGraphQL ? 0 : collectionConfig.auth.depth,
limit: 1,
overrideAccess: true,
pagination: false,
where
});
if (userQuery.docs && userQuery.docs.length > 0) {
const user = userQuery.docs[0];
user.collection = collectionConfig.slug;
user._strategy = 'api-key';
return {
user: user
};
}
} catch (ignore) {
return {
user: null
};
}
}
return {
user: null
};
};
//# sourceMappingURL=apiKey.js.map