Skip to content

Commit

Permalink
chore: hide oidcClientMetadata of SAML apps when using GET app APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
darcyYe committed Jan 24, 2025
1 parent 3bc701e commit b684413
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
15 changes: 13 additions & 2 deletions packages/core/src/routes/applications/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
InternalRole,
} from '@logto/schemas';
import { generateStandardId, generateStandardSecret } from '@logto/shared';
import { conditional } from '@silverhand/essentials';
import { cond, conditional } from '@silverhand/essentials';
import { boolean, object, string, z } from 'zod';

import RequestError from '#src/errors/RequestError/index.js';
Expand Down Expand Up @@ -134,7 +134,12 @@ export default function applicationRoutes<T extends ManagementApiRouter>(

// Return totalCount to pagination middleware
ctx.pagination.totalCount = count;
ctx.body = applications;
ctx.body = applications.map((application) =>
application.type === ApplicationType.SAML
? // Hide `oidcClientMetadata` for SAML application
{ ...application, oidcClientMetadata: buildOidcClientMetadata() }
: application
);

return next();
}
Expand Down Expand Up @@ -239,6 +244,12 @@ export default function applicationRoutes<T extends ManagementApiRouter>(

ctx.body = {
...application,
...cond(
// Hide `oidcClientMetadata` for SAML application
application.type === ApplicationType.SAML && {
oidcClientMetadata: buildOidcClientMetadata(),
}
),
isAdmin: includesInternalAdminRole(applicationsRoles),
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
createApplication,
deleteApplication,
getApplications,
getApplication,
updateApplication,
} from '#src/api/application.js';
import {
Expand All @@ -30,6 +31,13 @@ describe('SAML application', () => {
description: 'test',
});

await expect(getApplication(createdSamlApplication.id)).resolves.toContain({
oidcClientMetadata: {
redirectUris: [],
postLogoutRedirectUris: [],
},
});

expect(createdSamlApplication.nameIdFormat).toBe(NameIdFormat.Persistent);

// Check if the SAML application's OIDC metadata redirect URI is properly set.
Expand Down

0 comments on commit b684413

Please sign in to comment.