-
-
Notifications
You must be signed in to change notification settings - Fork 444
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
163 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
// TODO: @darcyYe refactor this file later to remove disable max line comment | ||
Check warning on line 1 in packages/core/src/routes/applications/application.ts GitHub Actions / ESLint Report Analysispackages/core/src/routes/applications/application.ts#L1
|
||
|
||
/* eslint-disable max-lines */ | ||
import type { Role } from '@logto/schemas'; | ||
import { | ||
Applications, | ||
|
@@ -147,10 +147,14 @@ export default function applicationRoutes<T extends ManagementApiRouter>( | |
response: Applications.guard, | ||
status: [200, 400, 422, 500], | ||
}), | ||
|
||
// eslint-disable-next-line complexity | ||
async (ctx, next) => { | ||
const { oidcClientMetadata, protectedAppMetadata, ...rest } = ctx.guard.body; | ||
|
||
if (rest.type === ApplicationType.SAML) { | ||
throw new RequestError('application.use_saml_app_api'); | ||
} | ||
|
||
await Promise.all([ | ||
rest.type === ApplicationType.MachineToMachine && | ||
quota.guardTenantUsageByKey('machineToMachineLimit'), | ||
|
@@ -262,6 +266,11 @@ export default function applicationRoutes<T extends ManagementApiRouter>( | |
|
||
const { isAdmin, protectedAppMetadata, ...rest } = body; | ||
|
||
const pendingUpdateApplication = await queries.applications.findApplicationById(id); | ||
if (pendingUpdateApplication.type === ApplicationType.SAML) { | ||
throw new RequestError('application.use_saml_app_api'); | ||
} | ||
|
||
// @deprecated | ||
// User can enable the admin access of Machine-to-Machine apps by switching on a toggle on Admin Console. | ||
// Since those apps sit in the user tenant, we provide an internal role to apply the necessary scopes. | ||
|
@@ -292,8 +301,7 @@ export default function applicationRoutes<T extends ManagementApiRouter>( | |
} | ||
|
||
if (protectedAppMetadata) { | ||
const { type, protectedAppMetadata: originProtectedAppMetadata } = | ||
await queries.applications.findApplicationById(id); | ||
const { type, protectedAppMetadata: originProtectedAppMetadata } = pendingUpdateApplication; | ||
assertThat(type === ApplicationType.Protected, 'application.protected_application_only'); | ||
assertThat( | ||
originProtectedAppMetadata, | ||
|
@@ -319,9 +327,10 @@ export default function applicationRoutes<T extends ManagementApiRouter>( | |
} | ||
} | ||
|
||
ctx.body = await (Object.keys(rest).length > 0 | ||
? queries.applications.updateApplicationById(id, rest, 'replace') | ||
: queries.applications.findApplicationById(id)); | ||
ctx.body = | ||
Object.keys(rest).length > 0 | ||
? await queries.applications.updateApplicationById(id, rest, 'replace') | ||
: pendingUpdateApplication; | ||
|
||
return next(); | ||
} | ||
|
@@ -359,3 +368,4 @@ export default function applicationRoutes<T extends ManagementApiRouter>( | |
|
||
applicationCustomDataRoutes(router, tenant); | ||
} | ||
/* eslint-enable max-lines */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
packages/schemas/alterations/next-1730712629-add-saml-application-type.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { sql } from '@silverhand/slonik'; | ||
|
||
import type { AlterationScript } from '../lib/types/alteration.js'; | ||
|
||
const alteration: AlterationScript = { | ||
up: async (pool) => { | ||
await pool.query(sql` | ||
alter type application_type add value 'SAML'; | ||
`); | ||
}, | ||
down: async (pool) => { | ||
await pool.query(sql` | ||
alter table organization_application_relations drop constraint application_type; | ||
alter table application_secrets drop constraint application_type; | ||
alter table sso_connector_idp_initiated_auth_configs drop constraint application_type; | ||
drop function check_application_type; | ||
create type application_type_new as enum ('Native', 'SPA', 'Traditional', 'MachineToMachine', 'Protected'); | ||
delete from applications where "type"='SAML'; | ||
alter table applications | ||
alter column "type" type application_type_new | ||
using ("type"::text::application_type_new); | ||
drop type application_type; | ||
alter type application_type_new rename to application_type; | ||
create function check_application_type( | ||
application_id varchar(21), | ||
variadic target_type application_type[] | ||
) returns boolean as | ||
$$ begin | ||
return (select type from applications where id = application_id) = any(target_type); | ||
end; $$ language plpgsql set search_path = public; | ||
alter table organization_application_relations | ||
add constraint application_type | ||
check (check_application_type(application_id, 'MachineToMachine')); | ||
alter table application_secrets | ||
add constraint application_type | ||
check (check_application_type(application_id, 'MachineToMachine', 'Traditional', 'Protected')); | ||
alter table sso_connector_idp_initiated_auth_configs | ||
add constraint application_type | ||
check (check_application_type(default_application_id, 'Traditional', 'SPA')); | ||
`); | ||
}, | ||
}; | ||
|
||
export default alteration; |
20 changes: 20 additions & 0 deletions
20
packages/schemas/alterations/next-1730712645-add-saml-app-third-party-consistency-check.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { sql } from '@silverhand/slonik'; | ||
|
||
import type { AlterationScript } from '../lib/types/alteration.js'; | ||
|
||
const alteration: AlterationScript = { | ||
up: async (pool) => { | ||
await pool.query(sql` | ||
alter table applications | ||
add constraint check_saml_app_third_party_consistency | ||
check (type != 'SAML' OR (type = 'SAML' AND is_third_party = true)); | ||
`); | ||
}, | ||
down: async (pool) => { | ||
await pool.query(sql` | ||
alter table applications drop constraint check_saml_app_third_party_consistency; | ||
`); | ||
}, | ||
}; | ||
|
||
export default alteration; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters