From a86f57a4667a799200b6354f9d43b22e58393131 Mon Sep 17 00:00:00 2001 From: Gao Sun Date: Tue, 10 Aug 2021 21:26:49 +0800 Subject: [PATCH] refactor: remove `oidc_client_id` --- packages/core/src/oidc/adapter.ts | 11 ++++------- packages/core/src/queries/application.ts | 4 ++-- packages/schemas/src/db-entries/application.ts | 4 +--- packages/schemas/tables/applications.sql | 6 ------ 4 files changed, 7 insertions(+), 18 deletions(-) diff --git a/packages/core/src/oidc/adapter.ts b/packages/core/src/oidc/adapter.ts index bb64eaec5..fcd1b6fa2 100644 --- a/packages/core/src/oidc/adapter.ts +++ b/packages/core/src/oidc/adapter.ts @@ -7,17 +7,14 @@ import { revokeInstanceByGrantId, upsertInstance, } from '@/queries/oidc-model-instance'; -import { findApplicationByClientId } from '@/queries/application'; +import { findApplicationById } from '@/queries/application'; import { ApplicationDBEntry } from '@logto/schemas'; export default function postgresAdapter(modelName: string): ReturnType { if (modelName === 'Client') { const reject = async () => Promise.reject(new Error('Not implemented')); - const tranpileClient = ({ - oidcClientId, - oidcClientMetadata, - }: ApplicationDBEntry): AllClientMetadata => ({ - client_id: oidcClientId, + const tranpileClient = ({ id, oidcClientMetadata }: ApplicationDBEntry): AllClientMetadata => ({ + client_id: id, grant_types: ['authorization_code', 'refresh_token'], token_endpoint_auth_method: 'none', ...oidcClientMetadata, @@ -25,7 +22,7 @@ export default function postgresAdapter(modelName: string): ReturnType tranpileClient(await findApplicationByClientId(id)), + find: async (id) => tranpileClient(await findApplicationById(id)), findByUserCode: reject, findByUid: reject, consume: reject, diff --git a/packages/core/src/queries/application.ts b/packages/core/src/queries/application.ts index d7f28dde9..fdc7df5db 100644 --- a/packages/core/src/queries/application.ts +++ b/packages/core/src/queries/application.ts @@ -5,9 +5,9 @@ import { sql } from 'slonik'; const { table, fields } = convertToIdentifiers(Applications); -export const findApplicationByClientId = async (clientId: string) => +export const findApplicationById = async (id: string) => pool.one(sql` select ${sql.join(Object.values(fields), sql`, `)} from ${table} - where ${fields.oidcClientId}=${clientId} + where ${fields.id}=${id} `); diff --git a/packages/schemas/src/db-entries/application.ts b/packages/schemas/src/db-entries/application.ts index 075affd2b..f7be7c6b7 100644 --- a/packages/schemas/src/db-entries/application.ts +++ b/packages/schemas/src/db-entries/application.ts @@ -8,7 +8,6 @@ export type ApplicationDBEntry = { id: string; name: string; type: ApplicationType; - oidcClientId: string; oidcClientMetadata: OidcClientMetadata; createdAt: number; }; @@ -19,9 +18,8 @@ export const Applications = Object.freeze({ id: 'id', name: 'name', type: 'type', - oidcClientId: 'oidc_client_id', oidcClientMetadata: 'oidc_client_metadata', createdAt: 'created_at', }, - fieldKeys: ['id', 'name', 'type', 'oidcClientId', 'oidcClientMetadata', 'createdAt'], + fieldKeys: ['id', 'name', 'type', 'oidcClientMetadata', 'createdAt'], } as const); diff --git a/packages/schemas/tables/applications.sql b/packages/schemas/tables/applications.sql index 52ee02539..3da48ba74 100644 --- a/packages/schemas/tables/applications.sql +++ b/packages/schemas/tables/applications.sql @@ -4,13 +4,7 @@ create table applications ( id varchar(128) not null, name varchar(256) not null, type application_type not null, - oidc_client_id varchar(128) not null, oidc_client_metadata jsonb /* @use OidcClientMetadata */ not null, created_at bigint not null default(extract(epoch from now())), primary key (id) ); - -create index applications__oidc_client_id -on applications ( - oidc_client_id -);