From 89cf297eff29d84fbe85589f9639d6f13e9632fd Mon Sep 17 00:00:00 2001 From: Gao Sun Date: Tue, 10 Aug 2021 21:11:52 +0800 Subject: [PATCH] refactor(core): adopt new schemas --- packages/core/src/oidc/adapter.ts | 15 +++++++++------ packages/core/src/queries/application.ts | 13 +++++++++++++ packages/core/src/queries/oidc-client.ts | 13 ------------- 3 files changed, 22 insertions(+), 19 deletions(-) create mode 100644 packages/core/src/queries/application.ts delete mode 100644 packages/core/src/queries/oidc-client.ts diff --git a/packages/core/src/oidc/adapter.ts b/packages/core/src/oidc/adapter.ts index 98772fd19..bb64eaec5 100644 --- a/packages/core/src/oidc/adapter.ts +++ b/packages/core/src/oidc/adapter.ts @@ -7,22 +7,25 @@ import { revokeInstanceByGrantId, upsertInstance, } from '@/queries/oidc-model-instance'; -import { findClientById } from '@/queries/oidc-client'; -import { OidcClientDBEntry } from '@logto/schemas'; +import { findApplicationByClientId } 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 = ({ clientId, metadata }: OidcClientDBEntry): AllClientMetadata => ({ - client_id: clientId, + const tranpileClient = ({ + oidcClientId, + oidcClientMetadata, + }: ApplicationDBEntry): AllClientMetadata => ({ + client_id: oidcClientId, grant_types: ['authorization_code', 'refresh_token'], token_endpoint_auth_method: 'none', - ...metadata, + ...oidcClientMetadata, }); return { upsert: reject, - find: async (id) => tranpileClient(await findClientById(id)), + find: async (id) => tranpileClient(await findApplicationByClientId(id)), findByUserCode: reject, findByUid: reject, consume: reject, diff --git a/packages/core/src/queries/application.ts b/packages/core/src/queries/application.ts new file mode 100644 index 000000000..d7f28dde9 --- /dev/null +++ b/packages/core/src/queries/application.ts @@ -0,0 +1,13 @@ +import pool from '@/database/pool'; +import { convertToIdentifiers } from '@/database/utils'; +import { ApplicationDBEntry, Applications } from '@logto/schemas'; +import { sql } from 'slonik'; + +const { table, fields } = convertToIdentifiers(Applications); + +export const findApplicationByClientId = async (clientId: string) => + pool.one(sql` + select ${sql.join(Object.values(fields), sql`, `)} + from ${table} + where ${fields.oidcClientId}=${clientId} +`); diff --git a/packages/core/src/queries/oidc-client.ts b/packages/core/src/queries/oidc-client.ts deleted file mode 100644 index 6a9a66b7d..000000000 --- a/packages/core/src/queries/oidc-client.ts +++ /dev/null @@ -1,13 +0,0 @@ -import pool from '@/database/pool'; -import { convertToIdentifiers } from '@/database/utils'; -import { OidcClientDBEntry, OidcClients } from '@logto/schemas'; -import { sql } from 'slonik'; - -const { table, fields } = convertToIdentifiers(OidcClients); - -export const findClientById = async (clientId: string) => - pool.one(sql` - select ${sql.join(Object.values(fields), sql`, `)} - from ${table} - where ${fields.clientId}=${clientId} -`);