mirror of
https://github.com/logto-io/logto.git
synced 2025-01-06 20:40:08 -05:00
feat: fetch client info from DB, close #3
This commit is contained in:
parent
39100b2da3
commit
ac2574d51c
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: {
|
jwks: {
|
||||||
keys,
|
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: {
|
features: {
|
||||||
revocation: { enabled: true },
|
revocation: { enabled: true },
|
||||||
introspection: { enabled: true },
|
introspection: { enabled: true },
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { AdapterFactory } from 'oidc-provider';
|
import { AdapterFactory, AllClientMetadata } from 'oidc-provider';
|
||||||
import {
|
import {
|
||||||
consumeInstanceById,
|
consumeInstanceById,
|
||||||
destoryInstanceById,
|
destoryInstanceById,
|
||||||
|
@ -6,9 +6,31 @@ import {
|
||||||
findPayloadByPayloadField,
|
findPayloadByPayloadField,
|
||||||
revokeInstanceByGrantId,
|
revokeInstanceByGrantId,
|
||||||
upsertInstance,
|
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> {
|
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 {
|
return {
|
||||||
upsert: async (id, payload, expiresIn) => upsertInstance(modelName, id, payload, expiresIn),
|
upsert: async (id, payload, expiresIn) => upsertInstance(modelName, id, payload, expiresIn),
|
||||||
find: async (id) => findPayloadById(modelName, id),
|
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