Skip to content

Commit

Permalink
chore: update
Browse files Browse the repository at this point in the history
  • Loading branch information
darcyYe committed May 11, 2024
1 parent 65a0823 commit 6e15784
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 19 deletions.
33 changes: 14 additions & 19 deletions packages/core/src/oidc/extra-token-claims.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,35 +106,30 @@ export const getExtraTokenClaimsForJwtCustomization = async (
.map((field) => [field, Reflect.get(token, field)])
);

const commonPayload = {
script,
environmentVariables,
token: readOnlyToken,
};

// We pass context to the cloud API only when it is a user's access token.
const logtoUserInfo = conditional(
!isTokenClientCredentials &&
token.accountId &&
(await libraries.jwtCustomizers.getUserContext(token.accountId))
);

const payload: CustomJwtFetcher = isTokenClientCredentials
? {
...commonPayload,
tokenType: LogtoJwtTokenKeyType.ClientCredentials,
}
: {
...commonPayload,
tokenType: LogtoJwtTokenKeyType.AccessToken,
// TODO (LOG-8555): the newly added `UserProfile` type includes undefined fields and can not be directly assigned to `Json` type. And the `undefined` fields should be removed by zod guard.
// eslint-disable-next-line no-restricted-syntax
context: { user: logtoUserInfo as Record<string, Json> },
};
const payload: CustomJwtFetcher = {
script,
environmentVariables,
token: readOnlyToken,
...(isTokenClientCredentials
? { tokenType: LogtoJwtTokenKeyType.ClientCredentials }

Check warning on line 121 in packages/core/src/oidc/extra-token-claims.ts

View check run for this annotation

Codecov / codecov/patch

packages/core/src/oidc/extra-token-claims.ts#L116-L121

Added lines #L116 - L121 were not covered by tests
: {
tokenType: LogtoJwtTokenKeyType.AccessToken,
// TODO (LOG-8555): the newly added `UserProfile` type includes undefined fields and can not be directly assigned to `Json` type. And the `undefined` fields should be removed by zod guard.

Check warning on line 124 in packages/core/src/oidc/extra-token-claims.ts

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

packages/core/src/oidc/extra-token-claims.ts#L124

[no-warning-comments] Unexpected 'todo' comment: 'TODO (LOG-8555): the newly added...'.
// `context` parameter is only eligible for user's access token for now.

Check warning on line 125 in packages/core/src/oidc/extra-token-claims.ts

View check run for this annotation

Codecov / codecov/patch

packages/core/src/oidc/extra-token-claims.ts#L125

Added line #L125 was not covered by tests
// eslint-disable-next-line no-restricted-syntax
context: { user: logtoUserInfo as Record<string, Json> },
}),
};

if (EnvSet.values.isCloud) {
const client = await cloudConnection.getClient();
// `context` parameter is only eligible for user's access token for now.
return await client.post(`/api/services/custom-jwt`, {
body: payload,
search: {},
Expand Down
9 changes: 9 additions & 0 deletions packages/toolkit/core-kit/src/custom-jwt/script-execution.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
import { runInNewContext } from 'node:vm';

/**
* This function is used to execute a named function in a customized code script in a local
* virtual machine with the given payload as input.
*
* @param script Custom code snippet.
* @param functionName The name of the function to be executed.
* @param payload The input payload for the function.
* @returns The result of the function execution.
*/
export const runScriptFunctionInLocalVm = async (
script: string,
functionName: string,
Expand Down

0 comments on commit 6e15784

Please sign in to comment.