Files
outline/server/queues/tasks/RevokeDynamicOAuthClientsTask.ts
T
Tom Moor bc992fb22a refactor: Add jobId hook to BaseTask for deduplicating queued jobs (#13890)
* refactor: Add jobId hook to BaseTask for deduplicating queued jobs

* fix: Drop jobId from APIImportTask, it re-schedules itself while active
2026-09-25 23:44:16 +00:00

55 lines
1.3 KiB
TypeScript

import Logger from "@server/logging/Logger";
import {
OAuthAuthentication,
OAuthAuthorizationCode,
OAuthClient,
} from "@server/models";
import { sequelize } from "@server/storage/database";
import { BaseTask } from "./base/BaseTask";
type Props = {
teamId: string;
};
/**
* Task to revoke the outstanding authorization codes and access tokens held by
* dynamically registered OAuth clients in a team.
*/
export default class RevokeDynamicOAuthClientsTask extends BaseTask<Props> {
protected jobId({ teamId }: Props) {
return `revoke-dynamic-oauth-clients:${teamId}`;
}
public async perform({ teamId }: Props) {
const clients = await OAuthClient.findAll({
attributes: ["id"],
where: {
teamId,
createdById: null,
},
});
if (!clients.length) {
return;
}
const oauthClientIds = clients.map((client) => client.id);
await sequelize.transaction(async (transaction) => {
await OAuthAuthentication.destroy({
where: { oauthClientId: oauthClientIds },
transaction,
});
await OAuthAuthorizationCode.destroy({
where: { oauthClientId: oauthClientIds },
transaction,
});
});
Logger.info(
"task",
`Revoked access for ${clients.length} dynamic OAuth clients in team ${teamId}`
);
}
}