mirror of
https://github.com/logto-io/logto.git
synced 2024-12-30 20:33:54 -05:00
feat: fetch client info from DB, close #3
This commit is contained in:
parent
69015b5eee
commit
6639cb12df
4 changed files with 37 additions and 11 deletions
|
@ -34,15 +34,6 @@ export default async function initOidc(app: Koa, port: number): Promise<Provider
|
|||
jwks: {
|
||||
keys,
|
||||
},
|
||||
clients: [
|
||||
{
|
||||
client_id: 'foo',
|
||||
redirect_uris: ['http://localhost:3000/callback'],
|
||||
grant_types: ['authorization_code', 'refresh_token'],
|
||||
token_endpoint_auth_method: 'none',
|
||||
post_logout_redirect_uris: ['http://localhost:3000'],
|
||||
},
|
||||
],
|
||||
features: {
|
||||
revocation: { enabled: true },
|
||||
introspection: { enabled: true },
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { AdapterFactory } from 'oidc-provider';
|
||||
import { AdapterFactory, AllClientMetadata } from 'oidc-provider';
|
||||
import {
|
||||
consumeInstanceById,
|
||||
destoryInstanceById,
|
||||
|
@ -6,9 +6,31 @@ import {
|
|||
findPayloadByPayloadField,
|
||||
revokeInstanceByGrantId,
|
||||
upsertInstance,
|
||||
} from '@/queries/oidc-adapter';
|
||||
} from '@/queries/oidc-model-instance';
|
||||
import { findClientById } from '@/queries/oidc-client';
|
||||
import { OidcClientDBEntry } from '@logto/schemas';
|
||||
|
||||
export default function postgresAdapter(modelName: string): ReturnType<AdapterFactory> {
|
||||
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),
|
||||
|
|
13
packages/core/src/queries/oidc-client.ts
Normal file
13
packages/core/src/queries/oidc-client.ts
Normal file
|
@ -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<OidcClientDBEntry>(sql`
|
||||
select ${sql.join(Object.values(fields), sql`, `)}
|
||||
from ${table}
|
||||
where ${fields.clientId}=${clientId}
|
||||
`);
|
Loading…
Reference in a new issue