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:
commit
9b876467a2
5 changed files with 20 additions and 28 deletions
|
@ -7,22 +7,22 @@ import {
|
||||||
revokeInstanceByGrantId,
|
revokeInstanceByGrantId,
|
||||||
upsertInstance,
|
upsertInstance,
|
||||||
} from '@/queries/oidc-model-instance';
|
} from '@/queries/oidc-model-instance';
|
||||||
import { findClientById } from '@/queries/oidc-client';
|
import { findApplicationById } from '@/queries/application';
|
||||||
import { OidcClientDBEntry } from '@logto/schemas';
|
import { ApplicationDBEntry } from '@logto/schemas';
|
||||||
|
|
||||||
export default function postgresAdapter(modelName: string): ReturnType<AdapterFactory> {
|
export default function postgresAdapter(modelName: string): ReturnType<AdapterFactory> {
|
||||||
if (modelName === 'Client') {
|
if (modelName === 'Client') {
|
||||||
const reject = async () => Promise.reject(new Error('Not implemented'));
|
const reject = async () => Promise.reject(new Error('Not implemented'));
|
||||||
const tranpileClient = ({ clientId, metadata }: OidcClientDBEntry): AllClientMetadata => ({
|
const tranpileClient = ({ id, oidcClientMetadata }: ApplicationDBEntry): AllClientMetadata => ({
|
||||||
client_id: clientId,
|
client_id: id,
|
||||||
grant_types: ['authorization_code', 'refresh_token'],
|
grant_types: ['authorization_code', 'refresh_token'],
|
||||||
token_endpoint_auth_method: 'none',
|
token_endpoint_auth_method: 'none',
|
||||||
...metadata,
|
...oidcClientMetadata,
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
upsert: reject,
|
upsert: reject,
|
||||||
find: async (id) => tranpileClient(await findClientById(id)),
|
find: async (id) => tranpileClient(await findApplicationById(id)),
|
||||||
findByUserCode: reject,
|
findByUserCode: reject,
|
||||||
findByUid: reject,
|
findByUid: reject,
|
||||||
consume: reject,
|
consume: reject,
|
||||||
|
|
13
packages/core/src/queries/application.ts
Normal file
13
packages/core/src/queries/application.ts
Normal 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}
|
||||||
|
`);
|
|
@ -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}
|
|
||||||
`);
|
|
|
@ -8,7 +8,6 @@ export type ApplicationDBEntry = {
|
||||||
id: string;
|
id: string;
|
||||||
name: string;
|
name: string;
|
||||||
type: ApplicationType;
|
type: ApplicationType;
|
||||||
oidcClientId: string;
|
|
||||||
oidcClientMetadata: OidcClientMetadata;
|
oidcClientMetadata: OidcClientMetadata;
|
||||||
createdAt: number;
|
createdAt: number;
|
||||||
};
|
};
|
||||||
|
@ -19,9 +18,8 @@ export const Applications = Object.freeze({
|
||||||
id: 'id',
|
id: 'id',
|
||||||
name: 'name',
|
name: 'name',
|
||||||
type: 'type',
|
type: 'type',
|
||||||
oidcClientId: 'oidc_client_id',
|
|
||||||
oidcClientMetadata: 'oidc_client_metadata',
|
oidcClientMetadata: 'oidc_client_metadata',
|
||||||
createdAt: 'created_at',
|
createdAt: 'created_at',
|
||||||
},
|
},
|
||||||
fieldKeys: ['id', 'name', 'type', 'oidcClientId', 'oidcClientMetadata', 'createdAt'],
|
fieldKeys: ['id', 'name', 'type', 'oidcClientMetadata', 'createdAt'],
|
||||||
} as const);
|
} as const);
|
||||||
|
|
|
@ -4,13 +4,7 @@ create table applications (
|
||||||
id varchar(128) not null,
|
id varchar(128) not null,
|
||||||
name varchar(256) not null,
|
name varchar(256) not null,
|
||||||
type application_type not null,
|
type application_type not null,
|
||||||
oidc_client_id varchar(128) not null,
|
|
||||||
oidc_client_metadata jsonb /* @use OidcClientMetadata */ not null,
|
oidc_client_metadata jsonb /* @use OidcClientMetadata */ not null,
|
||||||
created_at bigint not null default(extract(epoch from now())),
|
created_at bigint not null default(extract(epoch from now())),
|
||||||
primary key (id)
|
primary key (id)
|
||||||
);
|
);
|
||||||
|
|
||||||
create index applications__oidc_client_id
|
|
||||||
on applications (
|
|
||||||
oidc_client_id
|
|
||||||
);
|
|
||||||
|
|
Loading…
Reference in a new issue