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

Commit

Permalink
Fixing some typing issues (#142)
Browse files Browse the repository at this point in the history
* fixes: #40

* fixes: #133

* fixing: #127
  • Loading branch information
edewit authored Mar 5, 2021
1 parent 70a5880 commit c563754
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@keycloak/keycloak-admin-client",
"version": "1.14.7",
"version": "1.14.9",
"description": "keycloak admin client",
"main": "lib/index.js",
"files": [
Expand Down
19 changes: 14 additions & 5 deletions src/resources/clients.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,16 @@ export interface ClientQuery {
}

export interface PolicyQuery {
name: string;
id?: string;
name?: string;
type?: string;
resource?: string;
scope?: string;
permission?: string;
owner?: string;
fields?: string;
first?: number;
max?: number;
}

export class Clients extends Resource<{realm?: string}> {
Expand Down Expand Up @@ -501,15 +510,15 @@ export class Clients extends Resource<{realm?: string}> {
* Policy
*/
public listPolicies = this.makeRequest<
{id: string, name: string},
PolicyQuery,
PolicyRepresentation[]
>({
method: 'GET',
path: '{id}/authz/resource-server/policy',
urlParamKeys: ['id'],
});

public findByName = this.makeRequest<
public findPolicyByName = this.makeRequest<
{id: string; name: string},
PolicyRepresentation
>({
Expand Down Expand Up @@ -559,7 +568,7 @@ export class Clients extends Resource<{realm?: string}> {
policyName: string;
policy: PolicyRepresentation;
}): Promise<PolicyRepresentation> {
const policyFound = await this.findByName({
const policyFound = await this.findPolicyByName({
id: payload.id,
name: payload.policyName,
});
Expand All @@ -568,7 +577,7 @@ export class Clients extends Resource<{realm?: string}> {
{id: payload.id, policyId: policyFound.id, type: payload.policy.type},
payload.policy,
);
return this.findByName({id: payload.id, name: payload.policyName});
return this.findPolicyByName({id: payload.id, name: payload.policyName});
} else {
return this.createPolicy(
{id: payload.id, type: payload.policy.type},
Expand Down
2 changes: 1 addition & 1 deletion src/resources/roles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class Roles extends Resource<{realm?: string}> {
});

public findUsersWithRole = this.makeRequest<
{name: string},
{name: string; first?: number; max?: number},
UserRepresentation[]
>({
method: 'GET',
Expand Down
4 changes: 2 additions & 2 deletions src/utils/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import {defaultBaseUrl, defaultRealm} from './constants';
export type GrantTypes = 'client_credentials' | 'password';

export interface Credentials {
username: string;
password: string;
username?: string;
password?: string;
grantType: GrantTypes;
clientId: string;
clientSecret?: string;
Expand Down
5 changes: 4 additions & 1 deletion test/groupUser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,15 @@ describe('Group user integration', () => {
resourceName: permissions.resource,
});

const policies = await kcAdminClient.clients.listPolicies({id: managementClient.id, resource: permissions.resource, max: 2});
expect(policies).to.have.length(2);

expect(scopes).to.have.length(5);

// Search for the id of the management role
const roleId = scopes.find(scope => scope.name === 'manage').id;

const userPolicy = await kcAdminClient.clients.findByName({id: managementClient.id, name: `policy.manager.${currentGroup.id}`});
const userPolicy = await kcAdminClient.clients.findPolicyByName({id: managementClient.id, name: `policy.manager.${currentGroup.id}`});

expect(userPolicy).to.deep.include({
name: `policy.manager.${currentGroup.id}`,
Expand Down

0 comments on commit c563754

Please sign in to comment.