0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2024-12-16 20:26:19 -05:00

Merge pull request #73 from logto-io/gao--adopt-new-schemas

This commit is contained in:
Gao Sun 2021-08-11 16:16:06 +08:00 committed by GitHub
commit 9b876467a2
5 changed files with 20 additions and 28 deletions

View file

@ -7,22 +7,22 @@ import {
revokeInstanceByGrantId,
upsertInstance,
} from '@/queries/oidc-model-instance';
import { findClientById } from '@/queries/oidc-client';
import { OidcClientDBEntry } from '@logto/schemas';
import { findApplicationById } from '@/queries/application';
import { ApplicationDBEntry } 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,
const tranpileClient = ({ id, oidcClientMetadata }: ApplicationDBEntry): AllClientMetadata => ({
client_id: id,
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 findApplicationById(id)),
findByUserCode: reject,
findByUid: reject,
consume: reject,

View file

@ -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 findApplicationById = async (id: string) =>
pool.one<ApplicationDBEntry>(sql`
select ${sql.join(Object.values(fields), sql`, `)}
from ${table}
where ${fields.id}=${id}
`);

View file

@ -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<OidcClientDBEntry>(sql`
select ${sql.join(Object.values(fields), sql`, `)}
from ${table}
where ${fields.clientId}=${clientId}
`);

View file

@ -8,7 +8,6 @@ export type ApplicationDBEntry = {
id: string;
name: string;
type: ApplicationType;
oidcClientId: string;
oidcClientMetadata: OidcClientMetadata;
createdAt: number;
};
@ -19,9 +18,8 @@ export const Applications = Object.freeze({
id: 'id',
name: 'name',
type: 'type',
oidcClientId: 'oidc_client_id',
oidcClientMetadata: 'oidc_client_metadata',
createdAt: 'created_at',
},
fieldKeys: ['id', 'name', 'type', 'oidcClientId', 'oidcClientMetadata', 'createdAt'],
fieldKeys: ['id', 'name', 'type', 'oidcClientMetadata', 'createdAt'],
} as const);

View file

@ -4,13 +4,7 @@ create table applications (
id varchar(128) not null,
name varchar(256) not null,
type application_type not null,
oidc_client_id varchar(128) not null,
oidc_client_metadata jsonb /* @use OidcClientMetadata */ not null,
created_at bigint not null default(extract(epoch from now())),
primary key (id)
);
create index applications__oidc_client_id
on applications (
oidc_client_id
);