From 11fe40d9c5eba1225e1c4a1b706638bbb444c160 Mon Sep 17 00:00:00 2001 From: Phillip Ho Date: Sun, 8 Jun 2025 17:18:08 +0800 Subject: [PATCH 1/2] chore: pass allowImpersonation flag to /v2/keys/use --- .changeset/whole-ends-like.md | 5 +++++ packages/service-utils/src/core/api.ts | 16 ++++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 .changeset/whole-ends-like.md diff --git a/.changeset/whole-ends-like.md b/.changeset/whole-ends-like.md new file mode 100644 index 00000000000..e95f16f0cb9 --- /dev/null +++ b/.changeset/whole-ends-like.md @@ -0,0 +1,5 @@ +--- +"@thirdweb-dev/service-utils": patch +--- + +chore: pass allowImpersonation to auth server diff --git a/packages/service-utils/src/core/api.ts b/packages/service-utils/src/core/api.ts index e76c232011c..50b9df62d46 100644 --- a/packages/service-utils/src/core/api.ts +++ b/packages/service-utils/src/core/api.ts @@ -27,12 +27,21 @@ export type CoreServiceConfig = { * The number of times to retry the auth request. Default = 3. */ retryCount?: number; + /** + * Allow staff members to read data from this service for troubleshooting purposes. Default = false. + */ + allowImpersonation?: boolean; }; export type TeamAndProjectResponse = { authMethod: "secretKey" | "publishableKey" | "jwt" | "teamId"; team: TeamResponse; - project?: ProjectResponse | null; + project?: ProjectResponse; + impersonatedBy?: { + id: string; + email: string; + // Ommitting the full account details + }; }; export type ApiResponse = { @@ -250,7 +259,7 @@ export async function fetchTeamAndProject( authData: AuthorizationInput, config: CoreServiceConfig, ): Promise { - const { apiUrl, serviceApiKey } = config; + const { apiUrl, serviceApiKey, allowImpersonation } = config; const { teamId, clientId } = authData; const url = new URL("/v2/keys/use", apiUrl); @@ -260,6 +269,9 @@ export async function fetchTeamAndProject( if (teamId) { url.searchParams.set("teamId", teamId); } + if (allowImpersonation) { + url.searchParams.set("allowImpersonation", "true"); + } // compute the appropriate auth headers based on the auth data const authHeaders = getAuthHeaders(authData, serviceApiKey); From f8668746f52a47457ad0fe6e1758d0d0a6deed06 Mon Sep 17 00:00:00 2001 From: Phillip Ho Date: Sun, 8 Jun 2025 17:58:28 +0800 Subject: [PATCH 2/2] Update api.ts --- packages/service-utils/src/core/api.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/service-utils/src/core/api.ts b/packages/service-utils/src/core/api.ts index 50b9df62d46..bb9f141e208 100644 --- a/packages/service-utils/src/core/api.ts +++ b/packages/service-utils/src/core/api.ts @@ -40,7 +40,7 @@ export type TeamAndProjectResponse = { impersonatedBy?: { id: string; email: string; - // Ommitting the full account details + // Omitting the full account details }; };