mirror of
https://github.com/logto-io/logto.git
synced 2024-12-16 20:26:19 -05:00
feat(core): hide responseTypes and grantTypes from app api
hide responseTypes and grantTypes from application api
This commit is contained in:
parent
7b440d0248
commit
de9f0bf8b7
4 changed files with 26 additions and 1 deletions
|
@ -71,6 +71,7 @@ const grantTypeToExchangeByType: Record<GrantType, token.ExchangeByType> = {
|
||||||
[GrantType.RefreshToken]: token.ExchangeByType.RefreshToken,
|
[GrantType.RefreshToken]: token.ExchangeByType.RefreshToken,
|
||||||
[GrantType.ClientCredentials]: token.ExchangeByType.ClientCredentials,
|
[GrantType.ClientCredentials]: token.ExchangeByType.ClientCredentials,
|
||||||
[GrantType.TokenExchange]: token.ExchangeByType.TokenExchange,
|
[GrantType.TokenExchange]: token.ExchangeByType.TokenExchange,
|
||||||
|
[GrantType.Implicit]: token.ExchangeByType.Implicit,
|
||||||
};
|
};
|
||||||
|
|
||||||
const getExchangeByType = (grantType: unknown): token.ExchangeByType => {
|
const getExchangeByType = (grantType: unknown): token.ExchangeByType => {
|
||||||
|
|
|
@ -260,7 +260,7 @@ export default function applicationRoutes<T extends ManagementApiRouter>(
|
||||||
body,
|
body,
|
||||||
} = ctx.guard;
|
} = ctx.guard;
|
||||||
|
|
||||||
const { isAdmin, protectedAppMetadata, ...rest } = body;
|
const { isAdmin, protectedAppMetadata, oidcClientMetadata, ...rest } = body;
|
||||||
|
|
||||||
// @deprecated
|
// @deprecated
|
||||||
// User can enable the admin access of Machine-to-Machine apps by switching on a toggle on Admin Console.
|
// User can enable the admin access of Machine-to-Machine apps by switching on a toggle on Admin Console.
|
||||||
|
@ -319,6 +319,12 @@ export default function applicationRoutes<T extends ManagementApiRouter>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Prevent hidden fields (grantTypes, responseTypes) from being replaced
|
||||||
|
// Merge oidcClientMetadata if it's provided
|
||||||
|
if (oidcClientMetadata) {
|
||||||
|
await queries.applications.updateApplicationById(id, { oidcClientMetadata }, 'merge');
|
||||||
|
}
|
||||||
|
|
||||||
ctx.body = await (Object.keys(rest).length > 0
|
ctx.body = await (Object.keys(rest).length > 0
|
||||||
? queries.applications.updateApplicationById(id, rest, 'replace')
|
? queries.applications.updateApplicationById(id, rest, 'replace')
|
||||||
: queries.applications.findApplicationById(id));
|
: queries.applications.findApplicationById(id));
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import {
|
import {
|
||||||
|
oidcClientMetadataGuard,
|
||||||
applicationCreateGuard as originalApplicationCreateGuard,
|
applicationCreateGuard as originalApplicationCreateGuard,
|
||||||
applicationPatchGuard as originalApplicationPatchGuard,
|
applicationPatchGuard as originalApplicationPatchGuard,
|
||||||
} from '@logto/schemas';
|
} from '@logto/schemas';
|
||||||
|
@ -7,6 +8,7 @@ import { z } from 'zod';
|
||||||
export const applicationCreateGuard = originalApplicationCreateGuard
|
export const applicationCreateGuard = originalApplicationCreateGuard
|
||||||
.omit({
|
.omit({
|
||||||
protectedAppMetadata: true,
|
protectedAppMetadata: true,
|
||||||
|
oidcClientMetadata: true,
|
||||||
})
|
})
|
||||||
.extend({
|
.extend({
|
||||||
protectedAppMetadata: z
|
protectedAppMetadata: z
|
||||||
|
@ -15,11 +17,19 @@ export const applicationCreateGuard = originalApplicationCreateGuard
|
||||||
origin: z.string(),
|
origin: z.string(),
|
||||||
})
|
})
|
||||||
.optional(),
|
.optional(),
|
||||||
|
// Prevent setting grantTypes and responseTypes in the create guard
|
||||||
|
oidcClientMetadata: oidcClientMetadataGuard
|
||||||
|
.omit({
|
||||||
|
grantTypes: true,
|
||||||
|
responseTypes: true,
|
||||||
|
})
|
||||||
|
.optional(),
|
||||||
});
|
});
|
||||||
|
|
||||||
export const applicationPatchGuard = originalApplicationPatchGuard
|
export const applicationPatchGuard = originalApplicationPatchGuard
|
||||||
.omit({
|
.omit({
|
||||||
protectedAppMetadata: true,
|
protectedAppMetadata: true,
|
||||||
|
oidcClientMetadata: true,
|
||||||
})
|
})
|
||||||
.extend({
|
.extend({
|
||||||
protectedAppMetadata: z
|
protectedAppMetadata: z
|
||||||
|
@ -36,4 +46,11 @@ export const applicationPatchGuard = originalApplicationPatchGuard
|
||||||
.optional(),
|
.optional(),
|
||||||
})
|
})
|
||||||
.optional(),
|
.optional(),
|
||||||
|
// Prevent setting grantTypes and responseTypes in the create guard
|
||||||
|
oidcClientMetadata: oidcClientMetadataGuard
|
||||||
|
.omit({
|
||||||
|
grantTypes: true,
|
||||||
|
responseTypes: true,
|
||||||
|
})
|
||||||
|
.optional(),
|
||||||
});
|
});
|
||||||
|
|
|
@ -21,6 +21,7 @@ export enum ExchangeByType {
|
||||||
RefreshToken = 'RefreshToken',
|
RefreshToken = 'RefreshToken',
|
||||||
ClientCredentials = 'ClientCredentials',
|
ClientCredentials = 'ClientCredentials',
|
||||||
TokenExchange = 'TokenExchange',
|
TokenExchange = 'TokenExchange',
|
||||||
|
Implicit = 'Implicit',
|
||||||
}
|
}
|
||||||
|
|
||||||
export type LogKey = `${Type.ExchangeTokenBy}.${ExchangeByType}` | `${Type.RevokeToken}`;
|
export type LogKey = `${Type.ExchangeTokenBy}.${ExchangeByType}` | `${Type.RevokeToken}`;
|
||||||
|
|
Loading…
Reference in a new issue