Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(schemas): update logto_configs table related types #5453

Merged
merged 5 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat(core): remove guard definition and refactor code
  • Loading branch information
darcyYe committed Mar 5, 2024
commit 1fd9f8ec506e5b0198fba9093ce595e7c06fa1bf
4 changes: 1 addition & 3 deletions packages/schemas/src/types/logto-config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,11 @@ export enum LogtoJwtTokenKey {
ClientCredentials = 'jwt.clientCredentials',
}

export const jwtCustomizerGuard = z
const jwtCustomizerGuard = z
.object({
script: z.string(),
envVars: z.record(z.string()),
contextSample: jsonObjectGuard,
// This `tokenSample` field will be overridden by the `tokenSample` field once the `tokenType` is determined.
tokenSample: jsonObjectGuard,
})
.partial();

Expand Down
22 changes: 5 additions & 17 deletions packages/schemas/src/types/logto-config/oidc-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,34 +20,22 @@ const baseTokenGuardObject = {
kind: z.string(),
};

// Ref: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/0b7b01b70c4c211a4f69caf05008228ac065413c/types/oidc-provider/index.d.ts#L144
const claimsParameterMemberGuard = z
.object({
essential: z.boolean(),
value: z.string(),
values: z.array(z.string()),
})
.partial()
.catchall(jsonObjectGuard);

// Ref: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/0b7b01b70c4c211a4f69caf05008228ac065413c/types/oidc-provider/index.d.ts#L152
const claimsParameterGuard = z.object({
id_token: z.record(claimsParameterMemberGuard.nullable()).optional(),
userinfo: z.record(claimsParameterMemberGuard.nullable()).optional(),
});

/**
* Ref:
* https://github.com/DefinitelyTyped/DefinitelyTyped/blob/0b7b01b70c4c211a4f69caf05008228ac065413c/types/oidc-provider/index.d.ts#L550
* https://github.com/panva/node-oidc-provider/blob/270af1da83dda4c49edb4aaab48908f737d73379/lib/models/access_token.js#L17
*
* We do not include `claims` field in this guard because we did not enabled the `feature.claimsParameter` in the oidc-provider.
* If we enable the `feature.claimsParameter` feature in the future, we should include and implement the `claims` field guard.
* `feature.claimsParameter`: https://github.com/panva/node-oidc-provider/blob/main/docs/README.md#featuresclaimsparameter
* OIDC claims parameter: https://openid.net/specs/openid-connect-core-1_0.html#ClaimsParameter
*/
export const accessTokenGuard = z
simeng-li marked this conversation as resolved.
Show resolved Hide resolved
.object({
...baseTokenGuardObject,
kind: z.literal('AccessToken'),
accountId: z.string(),
aud: z.string().or(z.array(z.string())),
claims: claimsParameterGuard.optional(),
extra: jsonObjectGuard.optional(),
grantId: z.string(),
scope: z.string().optional(),
Expand Down
Loading