Skip to content
This repository has been archived by the owner on Apr 19, 2023. It is now read-only.

Added support for assosiated policies #352

Merged
merged 1 commit into from Jan 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 20 additions & 5 deletions src/resources/clients.ts
Expand Up @@ -17,15 +17,18 @@ import KeyStoreConfig from '../defs/keystoreConfig';
import ResourceServerRepresentation from '../defs/resourceServerRepresentation';
import ScopeRepresentation from '../defs/scopeRepresentation';

export interface ClientQuery {
export interface PaginatedQuery {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, it makes a lot of sense to split this out into a separate type. Perhaps it should be a level higher up though as a separate type from clients?

first?: number;
max?: number;
}

export interface ClientQuery extends PaginatedQuery {
clientId?: string;
viewableOnly?: boolean;
search?: boolean;
}

export interface PolicyQuery {
export interface PolicyQuery extends PaginatedQuery {
id?: string;
name?: string;
type?: string;
Expand All @@ -34,8 +37,6 @@ export interface PolicyQuery {
permission?: string;
owner?: string;
fields?: string;
first?: number;
max?: number;
}

export class Clients extends Resource<{realm?: string}> {
Expand Down Expand Up @@ -729,7 +730,12 @@ export class Clients extends Resource<{realm?: string}> {
* Permissions
*/
public findPermissions = this.makeRequest<
{id: string; name: string},
{
id: string;
name?: string;
resource?: string;
scope?: string;
} & PaginatedQuery,
PolicyRepresentation[]
>({
method: 'GET',
Expand Down Expand Up @@ -793,6 +799,15 @@ export class Clients extends Resource<{realm?: string}> {
urlParamKeys: ['id', 'permissionId'],
});

public getAssociatedPolicies = this.makeRequest<
{id: string; permissionId: string},
PolicyRepresentation[]
>({
method: 'GET',
path: '/{id}/authz/resource-server/policy/{permissionId}/associatedPolicies',
urlParamKeys: ['id', 'permissionId'],
});

public getOfflineSessionCount = this.makeRequest<
{id: string},
{count: number}
Expand Down
19 changes: 18 additions & 1 deletion test/clients.spec.ts
Expand Up @@ -1218,7 +1218,14 @@ describe('Clients', () => {
scopes: scopes.map((scope) => scope.id!),
},
);
expect(permission).to.be.ok;

const p = await kcAdminClient.clients.findPermissions({
id: currentClient.id!,
name: permissionConfig.name,
});

expect(p.length).to.be.eq(1);
expect(p[0].logic).to.be.eq(permissionConfig.logic);
});

it('get associated scopes for permission', async () => {
Expand All @@ -1231,6 +1238,16 @@ describe('Clients', () => {
);
});

it('get associated policies for permission', async () => {
const result = await kcAdminClient.clients.getAssociatedPolicies({
id: currentClient.id!,
permissionId: permission.id!,
});

expect(result.length).to.be.eq(1);
expect(result[0].id).to.be.eq(policy.id);
});

it('get associated resources for permission', async () => {
const result = await kcAdminClient.clients.getAssociatedResources({
id: currentClient.id!,
Expand Down