diff --git a/packages/core/src/init/oidc.ts b/packages/core/src/init/oidc.ts index 90448ab8a..9241dcdf9 100644 --- a/packages/core/src/init/oidc.ts +++ b/packages/core/src/init/oidc.ts @@ -34,15 +34,6 @@ export default async function initOidc(app: Koa, port: number): Promise { + if (modelName === 'Client') { + const reject = async () => Promise.reject(new Error('Not implemented')); + const tranpileClient = ({ clientId, metadata }: OidcClientDBEntry): AllClientMetadata => ({ + client_id: clientId, + grant_types: ['authorization_code', 'refresh_token'], + token_endpoint_auth_method: 'none', + ...metadata, + }); + + return { + upsert: reject, + find: async (id) => tranpileClient(await findClientById(id)), + findByUserCode: reject, + findByUid: reject, + consume: reject, + destroy: reject, + revokeByGrantId: reject, + }; + } + return { upsert: async (id, payload, expiresIn) => upsertInstance(modelName, id, payload, expiresIn), find: async (id) => findPayloadById(modelName, id), diff --git a/packages/core/src/queries/oidc-client.ts b/packages/core/src/queries/oidc-client.ts new file mode 100644 index 000000000..6a9a66b7d --- /dev/null +++ b/packages/core/src/queries/oidc-client.ts @@ -0,0 +1,13 @@ +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} +`); diff --git a/packages/core/src/queries/oidc-adapter.ts b/packages/core/src/queries/oidc-model-instance.ts similarity index 100% rename from packages/core/src/queries/oidc-adapter.ts rename to packages/core/src/queries/oidc-model-instance.ts