ADD CROSS DOMAIN SUPPORT

This commit is contained in:
Carl-Gerhard Lindesvärd
2024-06-26 22:35:29 +02:00
parent a0c8199474
commit 41143ca5f8
26 changed files with 514 additions and 126 deletions

View File

@@ -2,7 +2,7 @@ import type { RawRequestDefaultExpression } from 'fastify';
import jwt from 'jsonwebtoken';
import { verifyPassword } from '@openpanel/common';
import type { IServiceClient } from '@openpanel/db';
import type { Client, IServiceClient } from '@openpanel/db';
import { ClientType, db } from '@openpanel/db';
import { logger } from './logger';
@@ -36,7 +36,7 @@ class SdkAuthError extends Error {
export async function validateSdkRequest(
headers: RawRequestDefaultExpression['headers']
): Promise<string> {
): Promise<Client> {
const clientIdNew = headers['openpanel-client-id'] as string;
const clientIdOld = headers['mixan-client-id'] as string;
const clientSecretNew = headers['openpanel-client-secret'] as string;
@@ -83,17 +83,17 @@ export async function validateSdkRequest(
});
if (domainAllowed) {
return client.projectId;
return client;
}
if (client.cors === '*' && origin) {
return client.projectId;
return client;
}
}
if (client.secret && clientSecret) {
if (await verifyPassword(clientSecret, client.secret)) {
return client.projectId;
return client;
}
}