0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2025-03-31 22:51:25 -05:00

feat(schema): update application db ()

* feat(schema): update appliaction db

update application db

* ci(schema): cr fix application table schema typo

fix application table schema typo
This commit is contained in:
simeng-li 2022-01-11 11:58:58 +08:00 committed by GitHub
parent 14d8b18c1d
commit b9f9847ec0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 38 additions and 12 deletions
packages
core/src
schemas
src
db-entries
foundations
tables

View file

@ -13,14 +13,20 @@ import {
upsertInstance,
} from '@/queries/oidc-model-instance';
import { getApplicationTypeString } from './utils';
export default function postgresAdapter(modelName: string): ReturnType<AdapterFactory> {
if (modelName === 'Client') {
const reject = async () => Promise.reject(new Error('Not implemented'));
const transpileClient = ({
id,
id: client_id,
name: client_name,
type,
oidcClientMetadata,
}: ApplicationDBEntry): AllClientMetadata => ({
client_id: id,
client_id,
client_name,
application_type: getApplicationTypeString(type),
grant_types: ['authorization_code', 'refresh_token'],
token_endpoint_auth_method: 'none',
...snakecaseKeys(oidcClientMetadata),

View file

@ -1,14 +1,10 @@
import { ApplicationType, OidcClientMetadata } from '@logto/schemas';
const getApplicationTypeString = (type: ApplicationType) =>
export const getApplicationTypeString = (type: ApplicationType) =>
type === ApplicationType.Native ? 'native' : 'web';
export const buildOidcClientMetadata = (
type: ApplicationType,
metadata?: OidcClientMetadata
): OidcClientMetadata => ({
export const buildOidcClientMetadata = (metadata?: OidcClientMetadata): OidcClientMetadata => ({
redirectUris: [],
postLogoutRedirectUris: [],
...metadata,
applicationType: getApplicationTypeString(type),
});

View file

@ -37,7 +37,7 @@ export default function applicationRoutes<T extends AuthedRouter>(router: T) {
id: applicationId(),
type,
name,
oidcClientMetadata: buildOidcClientMetadata(type, oidcClientMetadata),
oidcClientMetadata: buildOidcClientMetadata(oidcClientMetadata),
...rest,
});
return next();
@ -74,7 +74,7 @@ export default function applicationRoutes<T extends AuthedRouter>(router: T) {
ctx.body = await updateApplicationById(id, {
...body,
oidcClientMetadata: buildOidcClientMetadata(body.type ?? application.type, {
oidcClientMetadata: buildOidcClientMetadata({
...application.oidcClientMetadata,
...body.oidcClientMetadata,
}),

View file

@ -13,24 +13,33 @@ import { ApplicationType } from './custom-types';
export type ApplicationDBEntry = {
id: string;
name: string;
description?: string | null;
type: ApplicationType;
oidcClientMetadata: OidcClientMetadata;
idTokenTtl?: number;
refreshTokenTtl?: number;
createdAt?: number;
};
export type Application = {
id: string;
name: string;
description: string | null;
type: ApplicationType;
oidcClientMetadata: OidcClientMetadata;
idTokenTtl: number;
refreshTokenTtl: number;
createdAt: number;
};
const guard: Guard<ApplicationDBEntry> = z.object({
id: z.string(),
name: z.string(),
description: z.string().optional(),
type: z.nativeEnum(ApplicationType),
oidcClientMetadata: oidcClientMetadataGuard,
idTokenTtl: z.number().optional(),
refreshTokenTtl: z.number().optional(),
createdAt: z.number().optional(),
});
@ -40,10 +49,22 @@ export const Applications: GeneratedSchema<ApplicationDBEntry> = Object.freeze({
fields: {
id: 'id',
name: 'name',
description: 'description',
type: 'type',
oidcClientMetadata: 'oidc_client_metadata',
idTokenTtl: 'id_token_ttl',
refreshTokenTtl: 'refresh_token_ttl',
createdAt: 'created_at',
},
fieldKeys: ['id', 'name', 'type', 'oidcClientMetadata', 'createdAt'],
fieldKeys: [
'id',
'name',
'description',
'type',
'oidcClientMetadata',
'idTokenTtl',
'refreshTokenTtl',
'createdAt',
],
guard,
});

View file

@ -15,9 +15,9 @@ export const oidcModelInstancePayloadGuard = z
export type OidcModelInstancePayload = z.infer<typeof oidcModelInstancePayloadGuard>;
export const oidcClientMetadataGuard = z.object({
applicationType: z.enum(['web', 'native']),
redirectUris: z.string().array(),
postLogoutRedirectUris: z.string().array(),
logoUri: z.string().optional(),
});
export type OidcClientMetadata = z.infer<typeof oidcClientMetadataGuard>;

View file

@ -3,8 +3,11 @@ create type application_type as enum ('Native', 'SPA', 'Traditional');
create table applications (
id varchar(128) not null,
name varchar(256) not null,
description text,
type application_type not null,
oidc_client_metadata jsonb /* @use OidcClientMetadata */ not null,
id_token_ttl bigint not null default(86400),
refresh_token_ttl bigint not null default(2592000),
created_at timestamptz not null default(now()),
primary key (id)
);