0
Fork 0
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:
Gao Sun 2021-07-05 00:14:51 +08:00
parent 69015b5eee
commit 6639cb12df
No known key found for this signature in database
GPG key ID: 0F0EFA2E36639F31
4 changed files with 37 additions and 11 deletions

View file

@ -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 },

View file

@ -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),

View 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}
`);