From 55e04cc683aa916ed5e3ddd1300a458dce7ddbb5 Mon Sep 17 00:00:00 2001 From: Darcy Ye Date: Mon, 25 Mar 2024 14:00:05 +0800 Subject: [PATCH] refactor: reorder code --- packages/core/src/oidc/init.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/packages/core/src/oidc/init.ts b/packages/core/src/oidc/init.ts index 51c61627d..1515abb96 100644 --- a/packages/core/src/oidc/init.ts +++ b/packages/core/src/oidc/init.ts @@ -217,12 +217,6 @@ export default function initOidc( try { const isTokenClientCredentials = token instanceof ctx.oidc.provider.ClientCredentials; - const pickedFields = isTokenClientCredentials - ? ctx.oidc.provider.ClientCredentials.IN_PAYLOAD - : ctx.oidc.provider.AccessToken.IN_PAYLOAD; - const readOnlyToken = Object.fromEntries( - pickedFields.map((field) => [field, Reflect.get(token, field)]) - ); const { script, envVars } = (await trySafe( @@ -237,6 +231,13 @@ export default function initOidc( return; } + const pickedFields = isTokenClientCredentials + ? ctx.oidc.provider.ClientCredentials.IN_PAYLOAD + : ctx.oidc.provider.AccessToken.IN_PAYLOAD; + const readOnlyToken = Object.fromEntries( + pickedFields.map((field) => [field, Reflect.get(token, field)]) + ); + const client = await cloudConnection.getClient(); // We pass context to the cloud API only when it is a user's access token.