Files
CommunitySolidServer/src/identity/interaction/client-credentials/DeleteClientCredentialsHandler.ts
Joachim Van Herwegen a47f5236ef feat: Full rework of account management
Complete rewrite of the account management and related systems.
Makes the architecture more modular,
allowing for easier extensions and configurations.
2023-10-06 11:04:40 +02:00

33 lines
1.3 KiB
TypeScript

import type { EmptyObject } from '../../../util/map/MapUtil';
import type { AccountStore } from '../account/util/AccountStore';
import { ensureResource, getRequiredAccount } from '../account/util/AccountUtil';
import type { JsonRepresentation } from '../InteractionUtil';
import type { JsonInteractionHandlerInput } from '../JsonInteractionHandler';
import { JsonInteractionHandler } from '../JsonInteractionHandler';
import type { ClientCredentialsStore } from './util/ClientCredentialsStore';
/**
* Handles the deletion of client credentials tokens.
*/
export class DeleteClientCredentialsHandler extends JsonInteractionHandler<EmptyObject> {
private readonly accountStore: AccountStore;
private readonly clientCredentialsStore: ClientCredentialsStore;
public constructor(accountStore: AccountStore, clientCredentialsStore: ClientCredentialsStore) {
super();
this.accountStore = accountStore;
this.clientCredentialsStore = clientCredentialsStore;
}
public async handle({ target, accountId }: JsonInteractionHandlerInput): Promise<JsonRepresentation<EmptyObject>> {
const account = await getRequiredAccount(this.accountStore, accountId);
const id = ensureResource(account.clientCredentials, target.path);
// This also deletes it from the account
await this.clientCredentialsStore.delete(id, account);
return { json: {}};
}
}