Implement client session statuses endpoint properly (#17033)
This commit is contained in:
parent
ff71cbc4f3
commit
998b708c78
6 changed files with 23 additions and 43 deletions
|
@ -11,7 +11,6 @@ import { IdentityProviders } from "./resources/identityProviders.js";
|
||||||
import { Realms } from "./resources/realms.js";
|
import { Realms } from "./resources/realms.js";
|
||||||
import { Roles } from "./resources/roles.js";
|
import { Roles } from "./resources/roles.js";
|
||||||
import { ServerInfo } from "./resources/serverInfo.js";
|
import { ServerInfo } from "./resources/serverInfo.js";
|
||||||
import { Sessions } from "./resources/sessions.js";
|
|
||||||
import { Users } from "./resources/users.js";
|
import { Users } from "./resources/users.js";
|
||||||
import { UserStorageProvider } from "./resources/userStorageProvider.js";
|
import { UserStorageProvider } from "./resources/userStorageProvider.js";
|
||||||
import { WhoAmI } from "./resources/whoAmI.js";
|
import { WhoAmI } from "./resources/whoAmI.js";
|
||||||
|
@ -44,7 +43,6 @@ export class KeycloakAdminClient {
|
||||||
public serverInfo: ServerInfo;
|
public serverInfo: ServerInfo;
|
||||||
public whoAmI: WhoAmI;
|
public whoAmI: WhoAmI;
|
||||||
public attackDetection: AttackDetection;
|
public attackDetection: AttackDetection;
|
||||||
public sessions: Sessions;
|
|
||||||
public authenticationManagement: AuthenticationManagement;
|
public authenticationManagement: AuthenticationManagement;
|
||||||
public cache: Cache;
|
public cache: Cache;
|
||||||
|
|
||||||
|
@ -78,7 +76,6 @@ export class KeycloakAdminClient {
|
||||||
this.authenticationManagement = new AuthenticationManagement(this);
|
this.authenticationManagement = new AuthenticationManagement(this);
|
||||||
this.serverInfo = new ServerInfo(this);
|
this.serverInfo = new ServerInfo(this);
|
||||||
this.whoAmI = new WhoAmI(this);
|
this.whoAmI = new WhoAmI(this);
|
||||||
this.sessions = new Sessions(this);
|
|
||||||
this.attackDetection = new AttackDetection(this);
|
this.attackDetection = new AttackDetection(this);
|
||||||
this.cache = new Cache(this);
|
this.cache = new Cache(this);
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
export interface ClientSessionStat {
|
||||||
|
id: string;
|
||||||
|
clientId: string;
|
||||||
|
active: string;
|
||||||
|
offline: string;
|
||||||
|
}
|
|
@ -17,6 +17,7 @@ import type GlobalRequestResult from "../defs/globalRequestResult.js";
|
||||||
import type GroupRepresentation from "../defs/groupRepresentation.js";
|
import type GroupRepresentation from "../defs/groupRepresentation.js";
|
||||||
import type { ManagementPermissionReference } from "../defs/managementPermissionReference.js";
|
import type { ManagementPermissionReference } from "../defs/managementPermissionReference.js";
|
||||||
import type ComponentTypeRepresentation from "../defs/componentTypeRepresentation.js";
|
import type ComponentTypeRepresentation from "../defs/componentTypeRepresentation.js";
|
||||||
|
import type { ClientSessionStat } from "../defs/clientSessionStat.js";
|
||||||
|
|
||||||
export class Realms extends Resource {
|
export class Realms extends Resource {
|
||||||
/**
|
/**
|
||||||
|
@ -294,6 +295,15 @@ export class Realms extends Resource {
|
||||||
/**
|
/**
|
||||||
* Sessions
|
* Sessions
|
||||||
*/
|
*/
|
||||||
|
public getClientSessionStats = this.makeRequest<
|
||||||
|
{ realm: string },
|
||||||
|
ClientSessionStat[]
|
||||||
|
>({
|
||||||
|
method: "GET",
|
||||||
|
path: "/{realm}/client-session-stats",
|
||||||
|
urlParamKeys: ["realm"],
|
||||||
|
});
|
||||||
|
|
||||||
public logoutAll = this.makeRequest<{ realm: string }, void>({
|
public logoutAll = this.makeRequest<{ realm: string }, void>({
|
||||||
method: "POST",
|
method: "POST",
|
||||||
path: "/{realm}/logout-all",
|
path: "/{realm}/logout-all",
|
||||||
|
|
|
@ -1,18 +0,0 @@
|
||||||
import Resource from "./resource.js";
|
|
||||||
import type KeycloakAdminClient from "../index.js";
|
|
||||||
|
|
||||||
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,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -374,6 +374,13 @@ describe("Realms", () => {
|
||||||
currentRealmName = created.realmName;
|
currentRealmName = created.realmName;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("gets client session stats", async () => {
|
||||||
|
const sessionStats = await kcAdminClient.realms.getClientSessionStats({
|
||||||
|
realm: currentRealmName,
|
||||||
|
});
|
||||||
|
expect(sessionStats).to.be.ok;
|
||||||
|
});
|
||||||
|
|
||||||
it("push revocation", async () => {
|
it("push revocation", async () => {
|
||||||
const push = await kcAdminClient.realms.pushRevocation({
|
const push = await kcAdminClient.realms.pushRevocation({
|
||||||
realm: currentRealmName,
|
realm: currentRealmName,
|
||||||
|
|
|
@ -1,22 +0,0 @@
|
||||||
// tslint:disable:no-unused-expression
|
|
||||||
import * as chai from "chai";
|
|
||||||
import { KeycloakAdminClient } from "../src/client.js";
|
|
||||||
import { credentials } from "./constants.js";
|
|
||||||
|
|
||||||
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");
|
|
||||||
});
|
|
||||||
});
|
|
Loading…
Reference in a new issue