mirror of
https://github.com/outline/outline.git
synced 2026-11-25 15:15:15 +03:00
* refactor: Add jobId hook to BaseTask for deduplicating queued jobs * fix: Drop jobId from APIImportTask, it re-schedules itself while active
55 lines
1.3 KiB
TypeScript
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}`
|
|
);
|
|
}
|
|
}
|