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

Commit

Permalink
added the /client-session-stats endpoint (#107)
Browse files Browse the repository at this point in the history
  • Loading branch information
edewit authored Dec 14, 2020
1 parent 588cb6e commit 86c88c5
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import Keycloak, {
KeycloakInitOptions,
KeycloakInstance,
} from 'keycloak-js';
import {Sessions} from './resources/sessions';

export interface ConnectionConfig {
baseUrl?: string;
Expand All @@ -39,6 +40,7 @@ export class KeycloakAdminClient {
public serverInfo: ServerInfo;
public whoAmI: WhoAmI;
public attackDetection: AttackDetection;
public sessions: Sessions;
public authenticationManagement: AuthenticationManagement;

// Members
Expand Down Expand Up @@ -69,6 +71,7 @@ export class KeycloakAdminClient {
this.authenticationManagement = new AuthenticationManagement(this);
this.serverInfo = new ServerInfo(this);
this.whoAmI = new WhoAmI(this);
this.sessions = new Sessions(this);
this.attackDetection = new AttackDetection(this);
}

Expand Down
19 changes: 19 additions & 0 deletions src/resources/sessions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import Resource from './resource';
import KeycloakAdminClient from '..';

export class Sessions extends Resource<{realm?: string}> {

public find = this.makeRequest<{}, Record<string, any>[]>({
method: 'GET',
});

constructor(client: KeycloakAdminClient) {
super(client, {
path: '/admin/realms/{realm}/client-session-stats',
getUrlParams: () => ({
realm: client.realmName,
}),
getBaseUrl: () => client.baseUrl,
});
}
}
23 changes: 23 additions & 0 deletions test/sessions.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// tslint:disable:no-unused-expression
import * as chai from 'chai';
import {KeycloakAdminClient} from '../src/client';
import {credentials} from './constants';

const expect = chai.expect;

describe('Sessions', () => {
let client: KeycloakAdminClient;

before(async () => {
client = new KeycloakAdminClient();
await client.auth(credentials);
});

it('list sessions', async () => {
const sessions = await client.sessions.find();
expect(sessions).to.be.ok;
expect(sessions.length).to.be.eq(1);
expect(sessions[0].clientId).to.be.eq('admin-cli');
});

});

0 comments on commit 86c88c5

Please sign in to comment.