better logging for sdk auth
This commit is contained in:
@@ -17,7 +17,7 @@ const eventRouter: FastifyPluginCallback = (fastify, opts, done) => {
|
|||||||
) => {
|
) => {
|
||||||
try {
|
try {
|
||||||
const projectId = await validateSdkRequest(req.headers).catch(
|
const projectId = await validateSdkRequest(req.headers).catch(
|
||||||
() => null
|
req.log.error
|
||||||
);
|
);
|
||||||
if (!projectId) {
|
if (!projectId) {
|
||||||
return reply.status(401).send();
|
return reply.status(401).send();
|
||||||
|
|||||||
@@ -6,7 +6,9 @@ import type { FastifyPluginCallback } from 'fastify';
|
|||||||
const eventRouter: FastifyPluginCallback = (fastify, opts, done) => {
|
const eventRouter: FastifyPluginCallback = (fastify, opts, done) => {
|
||||||
fastify.addHook('preHandler', async (req, reply) => {
|
fastify.addHook('preHandler', async (req, reply) => {
|
||||||
try {
|
try {
|
||||||
const projectId = await validateSdkRequest(req.headers).catch(() => null);
|
const projectId = await validateSdkRequest(req.headers).catch(
|
||||||
|
req.log.error
|
||||||
|
);
|
||||||
if (!projectId) {
|
if (!projectId) {
|
||||||
return reply.status(401).send();
|
return reply.status(401).send();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,11 +23,6 @@ export async function validateSdkRequest(
|
|||||||
const clientSecret = clientSecretNew || clientSecretOld;
|
const clientSecret = clientSecretNew || clientSecretOld;
|
||||||
|
|
||||||
const origin = headers.origin;
|
const origin = headers.origin;
|
||||||
// Temp log
|
|
||||||
logger.info(
|
|
||||||
{ clientId, origin: origin ? origin : 'empty' },
|
|
||||||
'validateSdkRequest'
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!clientId) {
|
if (!clientId) {
|
||||||
throw new Error('Ingestion: Missing client id');
|
throw new Error('Ingestion: Missing client id');
|
||||||
@@ -69,7 +64,12 @@ export async function validateSdkRequest(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new Error('Ingestion: Invalid client secret');
|
logger.error({
|
||||||
|
client,
|
||||||
|
headers,
|
||||||
|
origin,
|
||||||
|
});
|
||||||
|
throw new Error('Ingestion: Invalid cors or secret');
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function validateExportRequest(
|
export async function validateExportRequest(
|
||||||
|
|||||||
Reference in New Issue
Block a user