Authority Client
Der AuthorityClient bietet authentifizierten Zugriff auf die ProcessCube Authority API — in zwei Stufen:
API-Übersicht
Stufe 1 — Allgemein: request()
Für beliebige Authority-API-Aufrufe. Der Token wird automatisch beschafft und als Cookie gesendet:
import { AuthorityClient } from '@5minds/processcube_app_sdk/server';
const authority = new AuthorityClient();
// Beliebiger API-Aufruf
const response = await authority.request('GET', '/acr/username_password/admin/users');
if (response.ok) {
console.log(response.data);
}Stufe 2 — Convenience-Methoden
Vordefinierte Methoden für häufige User-Admin-Operationen:
import { AuthorityClient } from '@5minds/processcube_app_sdk/server';
const authority = new AuthorityClient();
// Claim setzen
await authority.updateClaim('user@example.com', 'email_verified', true);
// Scope hinzufügen
await authority.addScope('user@example.com', 'premium_content');
// Gruppe zuweisen
await authority.addGroup('user@example.com', 'Partner-Netzwerk');
// User soft-deleten
const result = await authority.deleteUser('user@example.com', { fullDelete: false });| Methode | HTTP | Beschreibung |
|---|---|---|
updateClaim(username, claimName, claimValue) | PATCH | Setzt einen Claim auf dem User-Account |
addScope(username, scopeName) | PATCH | Fügt einen Scope zum User hinzu |
addGroup(username, groupName) | PATCH | Fügt den User einer Gruppe hinzu |
deleteUser(username, { fullDelete? }) | DELETE | Löscht oder soft-deleted einen User |
Alle Methoden geben ein AuthorityResponse<T> zurück mit ok, status und data.
Beispiel: Vorher / Nachher
Vorher (ohne SDK-Helper)
export default async function (payload: any) {
const response = await fetch(`${process.env.PROCESSCUBE_AUTHORITY_URL}/token`, {
method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
body: new URLSearchParams({
grant_type: 'client_credentials',
client_id: process.env.PROCESSCUBE_SERVER_CLIENT_ID!,
client_secret: process.env.PROCESSCUBE_SERVER_CLIENT_SECRET!,
scope: 'upe_admin engine_read engine_write',
}).toString(),
});
const { access_token } = await response.json();
const result = await fetch(
`${process.env.PROCESSCUBE_AUTHORITY_URL}/acr/username_password/admin/user/${payload.email}/delete`,
{
method: 'DELETE',
headers: {
Cookie: `access_token=${access_token}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({ fullDelete: false }),
}
);
return { completed_successful: result.ok };
}Nachher (mit Authority Client)
import { AuthorityClient } from '@5minds/processcube_app_sdk/server';
export default async function (payload: any) {
const authority = new AuthorityClient();
const result = await authority.deleteUser(payload.email, { fullDelete: false });
return { completed_successful: result.ok };
}