Skip to content

Commit

Permalink
fix: fix custom jwt api call and add cloud connection scope
Browse files Browse the repository at this point in the history
  • Loading branch information
darcyYe committed Mar 21, 2024
1 parent 15527b6 commit 8d5d9f2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
12 changes: 9 additions & 3 deletions packages/console/src/pages/JwtClaims/SettingsSection/TestTab.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type JsonObject, LogtoJwtTokenPath } from '@logto/schemas';
import { type JsonObject, LogtoJwtTokenPath, LogtoJwtTokenKey } from '@logto/schemas';
import classNames from 'classnames';
import { useCallback, useEffect, useMemo, useState } from 'react';
import { useFormContext, Controller, type ControllerRenderProps } from 'react-hook-form';
Expand Down Expand Up @@ -26,7 +26,7 @@ type Props = {

const userTokenModelSettings = [accessTokenPayloadTestModel, userContextTestModel];
const machineToMachineTokenModelSettings = [clientCredentialsPayloadTestModel];
const testEndpointPath = 'api/config/jwt-customizer/test';
const testEndpointPath = 'api/configs/jwt-customizer/test';

function TestTab({ isActive }: Props) {
const { t } = useTranslation(undefined, { keyPrefix: 'admin_console.jwt_claims' });
Expand Down Expand Up @@ -54,7 +54,13 @@ function TestTab({ isActive }: Props) {

const result = await api
.post(testEndpointPath, {
json: formatFormDataToTestRequestPayload(payload),
json: {
tokenType:
tokenType === LogtoJwtTokenPath.AccessToken
? LogtoJwtTokenKey.AccessToken
: LogtoJwtTokenKey.ClientCredentials,
payload: formatFormDataToTestRequestPayload(payload),
},
})
.json<JsonObject>()
.catch((error: unknown) => {
Expand Down
4 changes: 2 additions & 2 deletions packages/console/src/pages/JwtClaims/utils/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ export const formatFormDataToTestRequestPayload = (data: JwtClaimsFormType) => {
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing -- parse empty string as undefined
script: data.script || undefined,
envVars: formatEnvVariablesFormData(data.environmentVariables),
token: formatSampleCodeStringToJson(data.testSample?.tokenSample) ?? defaultTokenPayload,
context: formatSampleCodeStringToJson(data.testSample?.contextSample) ?? defaultContext,
tokenSample: formatSampleCodeStringToJson(data.testSample?.tokenSample) ?? defaultTokenPayload,
contextSample: formatSampleCodeStringToJson(data.testSample?.contextSample) ?? defaultContext,
};
};

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/libraries/cloud-connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const accessTokenResponseGuard = z.object({
* The scope here can be empty and still work, because the cloud API requests made using this client do not rely on scope verification.
* The `CloudScope.SendEmail` is added for now because it needs to call the cloud email service API.
*/
const scopes: string[] = [CloudScope.SendEmail];
const scopes: string[] = [CloudScope.SendEmail, CloudScope.FetchCustomJwt];
const accessTokenExpirationMargin = 60;

/** The library for connecting to Logto Cloud service. */
Expand Down

0 comments on commit 8d5d9f2

Please sign in to comment.