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

Commit

Permalink
added support for associated policies
Browse files Browse the repository at this point in the history
also fixed type of find permissions
  • Loading branch information
edewit committed Jan 3, 2022
1 parent 49da19d commit f98a0d0
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 6 deletions.
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 {
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

0 comments on commit f98a0d0

Please sign in to comment.