Skip to content

Commit db77aad

Browse files
authored
chore(core,console): remove dev feature guard (#7443)
remove dev feature guard
1 parent 127e92f commit db77aad

File tree

8 files changed

+65
-33
lines changed

8 files changed

+65
-33
lines changed

.changeset/fluffy-actors-knock.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@logto/schemas": minor
3+
---
4+
5+
feat: introduced new `oidc_session_extensions` table
6+
7+
This change introduces a new table named `oidc_session_extensions` to the Logto database schema. This table is designed to store additional user session-related data for OpenID Connect (OIDC) sessions, allowing for more flexible and extensible session management.

.changeset/large-carrots-think.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@logto/console": minor
3+
---
4+
5+
add user interaction context to custom token claims script
6+
7+
This change introduces the ability to access user interaction details in the custom token claims script within Logto console. The `interaction` context includes information about the user's interaction event, user ID, and verification records, allowing developers to create dynamic and context-aware token claims.

.changeset/twenty-buttons-chew.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
"@logto/core": minor
3+
---
4+
5+
feat: add user interaction details to the custom token claims context
6+
7+
This update introduces a key feature that allows the storage of user interaction details in the `oidc_session_extensions` table for future reference.
8+
9+
Developers can now access user interaction data associated with the current token's authentication session through the context in the custom token claims script, enabling the creation of tailored token claims.
10+
11+
Key Changes:
12+
13+
- Store interaction details: User interaction details are now stored in the oidc_session_extensions table, providing a historical reference for the associated authentication session.
14+
- Access user interaction details: In the custom token claims script, developers can retrieve user interaction details through the `context.interaction` property, allowing for the creation of dynamic and context-aware token claims. Logto will use the `sessionUid` to query the `oidc_session_extensions` table and retrieve the user interaction details.
15+
- Interaction Context Includes:
16+
- `interactionEvent`: The event that triggered the interaction, such as `SignIn`, `Register`.
17+
- `userId`: The unique identifier of the user involved in the interaction.
18+
- `verificationRecords`: An array of verification records, providing details about the verification methods used for user identification and any MFA verification if enabled.
19+
20+
Example Use Case:
21+
Developers can read the verification records from the interaction context. If an Enterprise SSO verification record is found, they can pass the user profile from the Enterprise SSO identities as additional token claims.
22+
23+
```ts
24+
const ssoVerification = verifications.find(
25+
(record) => record.type === "EnterpriseSso"
26+
);
27+
28+
if (ssoVerification) {
29+
return {
30+
enterpriseSsoIdentityId:
31+
enterpriseSsoVerification?.enterpriseSsoUserInfo?.id,
32+
familyName: enterpriseSsoVerification?.enterpriseSsoUserInfo?.familyName,
33+
};
34+
}
35+
```

packages/console/src/pages/CustomizeJwtDetails/MainContent/SettingsSection/InstructionTab/index.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { useState } from 'react';
55
import { useFormContext } from 'react-hook-form';
66
import { useTranslation } from 'react-i18next';
77

8-
import { isDevFeaturesEnabled } from '@/consts/env';
98
import { type JwtCustomizerForm } from '@/pages/CustomizeJwtDetails/type';
109
import {
1110
denyAccessCodeExample,
@@ -99,7 +98,7 @@ function InstructionTab({ isActive }: Props) {
9998
/>
10099
</GuideCard>
101100
)}
102-
{tokenType === LogtoJwtTokenKeyType.AccessToken && isDevFeaturesEnabled && (
101+
{tokenType === LogtoJwtTokenKeyType.AccessToken && (
103102
<GuideCard
104103
name={CardType.InteractionData}
105104
isExpanded={expendCard === CardType.InteractionData}

packages/console/src/pages/CustomizeJwtDetails/utils/config.tsx

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,9 @@ import {
88
InteractionEvent,
99
} from '@logto/schemas';
1010
import { type EditorProps } from '@monaco-editor/react';
11-
import { conditional } from '@silverhand/essentials';
1211

1312
import TokenFileIcon from '@/assets/icons/token-file-icon.svg?react';
1413
import UserFileIcon from '@/assets/icons/user-file-icon.svg?react';
15-
import { isDevFeaturesEnabled } from '@/consts/env.js';
1614

1715
import type { ModelSettings } from '../MainContent/MonacoCodeEditor/type.js';
1816

@@ -34,7 +32,7 @@ declare interface CustomJwtClaims extends Record<string, any> {}
3432
*
3533
* @param {${JwtCustomizerTypeDefinitionKey.JwtCustomizerUserContext}} user - The user info associated with the token.
3634
* @param {${JwtCustomizerTypeDefinitionKey.JwtCustomizerGrantContext}} [grant] - The grant context associated with the token.
37-
* ${isDevFeaturesEnabled ? `@param {${JwtCustomizerTypeDefinitionKey.JwtCustomizerUserInteractionContext}} [interaction] - The user interaction context associated with the token.` : ''}
35+
* @param {${JwtCustomizerTypeDefinitionKey.JwtCustomizerUserInteractionContext}} [interaction] - The user interaction context associated with the token.
3836
*/
3937
declare type Context = {
4038
/**
@@ -48,7 +46,7 @@ declare type Context = {
4846
/**
4947
* The user interaction context associated with the token.
5048
*/
51-
${isDevFeaturesEnabled ? `interaction?: ${JwtCustomizerTypeDefinitionKey.JwtCustomizerUserInteractionContext};` : ''}
49+
interaction?: ${JwtCustomizerTypeDefinitionKey.JwtCustomizerUserInteractionContext};
5250
}
5351
5452
declare type Payload = {
@@ -59,9 +57,9 @@ declare type Payload = {
5957
/**
6058
* Logto internal data that can be used to pass additional information.
6159
*
62-
* @param {${JwtCustomizerTypeDefinitionKey.JwtCustomizerUserContext}} user
63-
* @param {${JwtCustomizerTypeDefinitionKey.JwtCustomizerGrantContext}} [grant]
64-
* ${isDevFeaturesEnabled ? `@param {${JwtCustomizerTypeDefinitionKey.JwtCustomizerUserInteractionContext}} [interaction]` : ''}
60+
* @params {${JwtCustomizerTypeDefinitionKey.JwtCustomizerUserContext}} user
61+
* @params {${JwtCustomizerTypeDefinitionKey.JwtCustomizerGrantContext}} [grant]
62+
* @params {${JwtCustomizerTypeDefinitionKey.JwtCustomizerUserInteractionContext}} [interaction]
6563
*/
6664
context: Context;
6765
/**
@@ -275,7 +273,7 @@ const defaultUserInteractionContext: Partial<JwtCustomizerUserInteractionContext
275273
export const defaultUserTokenContextData = {
276274
user: defaultUserContext,
277275
grant: defaultGrantContext,
278-
...conditional(isDevFeaturesEnabled && { interaction: defaultUserInteractionContext }),
276+
interaction: defaultUserInteractionContext,
279277
};
280278

281279
export const accessTokenPayloadTestModel: ModelSettings = {

packages/core/src/libraries/session.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ import { z } from 'zod';
77
import type Queries from '#src/tenants/Queries.js';
88
import assertThat from '#src/utils/assert-that.js';
99

10-
import { EnvSet } from '../env-set/index.js';
11-
1210
const updateInteractionResult = async (
1311
ctx: Context,
1412
provider: Provider,
@@ -96,11 +94,6 @@ const saveInteractionLastSubmissionToSession = async (
9694
queries: Queries,
9795
interactionDetails: Awaited<ReturnType<Provider['interactionDetails']>>
9896
) => {
99-
// TODO: Remove this check when the feature is ready to be released. @simeng
100-
if (!EnvSet.values.isDevFeaturesEnabled) {
101-
return;
102-
}
103-
10497
const { session, lastSubmission } = interactionDetails;
10598

10699
if (!session || !lastSubmission) {

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,6 @@ const getInteractionLastSubmission = async (
101101
queries: Queries,
102102
{ accountId, sessionUid }: AccessToken
103103
) => {
104-
// TODO: Remove this check when the feature is ready to be released. @simeng
105-
if (!EnvSet.values.isDevFeaturesEnabled) {
106-
return;
107-
}
108-
109104
// Session UID and account ID are required to fetch the interaction data.
110105
if (!accountId || !sessionUid) {
111106
return;

packages/integration-tests/src/tests/api/oidc/get-access-token.test.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import {
2626
import { assignUsersToRole, createRole, deleteRole } from '#src/api/role.js';
2727
import { createScope, deleteScope } from '#src/api/scope.js';
2828
import MockClient, { defaultConfig } from '#src/client/index.js';
29-
import { isDevFeaturesEnabled, logtoUrl } from '#src/constants.js';
29+
import { logtoUrl } from '#src/constants.js';
3030
import { initExperienceClient, processSession } from '#src/helpers/client.js';
3131
import { createUserByAdmin } from '#src/helpers/index.js';
3232
import { enableAllPasswordSignInMethods } from '#src/helpers/sign-in-experience.js';
@@ -143,16 +143,14 @@ describe('get access token', () => {
143143
// The guest user has password.
144144
expect(getAccessTokenPayload(accessToken)).toHaveProperty('hasPassword', true);
145145

146-
if (isDevFeaturesEnabled) {
147-
expect(getAccessTokenPayload(accessToken)).toHaveProperty(
148-
'interactionEvent',
149-
InteractionEvent.SignIn
150-
);
151-
expect(getAccessTokenPayload(accessToken)).toHaveProperty(
152-
'verificationType',
153-
VerificationType.Password
154-
);
155-
}
146+
expect(getAccessTokenPayload(accessToken)).toHaveProperty(
147+
'interactionEvent',
148+
InteractionEvent.SignIn
149+
);
150+
expect(getAccessTokenPayload(accessToken)).toHaveProperty(
151+
'verificationType',
152+
VerificationType.Password
153+
);
156154

157155
await deleteJwtCustomizer('access-token');
158156
});

0 commit comments

Comments
 (0)