From e5154327bcefe929565743f4de0364258b1c175c Mon Sep 17 00:00:00 2001 From: Phillip Ho Date: Tue, 25 Feb 2025 07:26:09 +0800 Subject: [PATCH 1/2] chore: allow passing teamId to service-utils auth --- packages/service-utils/src/cf-worker/index.ts | 1 + packages/service-utils/src/core/api.ts | 10 ++++++++-- packages/service-utils/src/core/authorize/index.ts | 3 ++- packages/service-utils/src/core/types.ts | 2 ++ packages/service-utils/src/node/index.ts | 1 + 5 files changed, 14 insertions(+), 3 deletions(-) diff --git a/packages/service-utils/src/cf-worker/index.ts b/packages/service-utils/src/cf-worker/index.ts index f669427c0a4..7339c9e3df0 100644 --- a/packages/service-utils/src/cf-worker/index.ts +++ b/packages/service-utils/src/cf-worker/index.ts @@ -157,6 +157,7 @@ export async function extractAuthorizationData( origin, bundleId, secretKeyHash, + teamId: authInput.teamId, targetAddress: authInput.targetAddress, }; } diff --git a/packages/service-utils/src/core/api.ts b/packages/service-utils/src/core/api.ts index 2b8e7c6e224..fd61f697526 100644 --- a/packages/service-utils/src/core/api.ts +++ b/packages/service-utils/src/core/api.ts @@ -158,9 +158,15 @@ export async function fetchTeamAndProject( config: CoreServiceConfig, ): Promise { const { apiUrl, serviceApiKey } = config; + const { teamId, clientId } = authData; - const clientId = authData.clientId; - const url = `${apiUrl}/v2/keys/use${clientId ? `?clientId=${clientId}` : ""}`; + const url = new URL("/v2/keys/use", apiUrl); + if (clientId) { + url.searchParams.set("clientId", clientId); + } + if (teamId) { + url.searchParams.set("teamId", teamId); + } const response = await fetch(url, { method: "GET", headers: { diff --git a/packages/service-utils/src/core/authorize/index.ts b/packages/service-utils/src/core/authorize/index.ts index 3e6e5045c9e..29fef274aa5 100644 --- a/packages/service-utils/src/core/authorize/index.ts +++ b/packages/service-utils/src/core/authorize/index.ts @@ -18,6 +18,7 @@ export type AuthorizationInput = { jwt: string | null; hashedJWT: string | null; targetAddress?: string | string[]; + teamId?: string; // IMPORTANT: this is a stringified boolean! Only pass in true or false here. IK it's not ideal, but it's required to pass it in the headers. useWalletAuth?: string | null; }; @@ -46,7 +47,7 @@ export async function authorize( const cacheKey = authData.secretKeyHash ? `key-v2:secret-key:${authData.secretKeyHash}` : authData.hashedJWT - ? `key-v2:dashboard-jwt:${authData.hashedJWT}` + ? `key-v2:dashboard-jwt:${authData.hashedJWT}:${authData.teamId ?? "default"}` : authData.clientId ? `key-v2:client-id:${authData.clientId}` : null; diff --git a/packages/service-utils/src/core/types.ts b/packages/service-utils/src/core/types.ts index e0f3164acb2..4869d5a19fa 100644 --- a/packages/service-utils/src/core/types.ts +++ b/packages/service-utils/src/core/types.ts @@ -1,6 +1,8 @@ export type CoreAuthInput = { // for passing it from the subdomain or path or other service specific things clientId?: string; + // For providing a specific team the user is trying to authenticate for. Used only for dashboard auth. + teamId?: string; // for passing in the address target in RPC or bundler services targetAddress?: string | string[]; }; diff --git a/packages/service-utils/src/node/index.ts b/packages/service-utils/src/node/index.ts index 1770048769b..b1b32a60d34 100644 --- a/packages/service-utils/src/node/index.ts +++ b/packages/service-utils/src/node/index.ts @@ -167,6 +167,7 @@ export function extractAuthorizationData( origin, bundleId, targetAddress: authInput.targetAddress, + teamId: authInput.teamId, useWalletAuth, }; } From 9edd18de051fa852fd00633373ffb28dfead074d Mon Sep 17 00:00:00 2001 From: Phillip Ho Date: Tue, 25 Feb 2025 07:33:02 +0800 Subject: [PATCH 2/2] add changeset --- .changeset/cuddly-plants-wait.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/cuddly-plants-wait.md diff --git a/.changeset/cuddly-plants-wait.md b/.changeset/cuddly-plants-wait.md new file mode 100644 index 00000000000..820a2662464 --- /dev/null +++ b/.changeset/cuddly-plants-wait.md @@ -0,0 +1,5 @@ +--- +"@thirdweb-dev/service-utils": patch +--- + +chore: Allow passing teamId with dashboard auth