mirror of
https://github.com/outline/outline.git
synced 2026-06-13 11:25:03 +03:00
a06671e8ce
This PR contains the necessary work to make Outline an OAuth provider including: - OAuth app registration - OAuth app management - Private / public apps (Public in cloud only) - Full OAuth 2.0 spec compatible authentication flow - Granular scopes - User token management screen in settings - Associated API endpoints for programatic access
56 lines
1.6 KiB
TypeScript
56 lines
1.6 KiB
TypeScript
import "./bootstrap";
|
|
import { Transaction } from "sequelize";
|
|
import { ApiKey } from "@server/models";
|
|
import { sequelize } from "@server/storage/database";
|
|
import { hash } from "@server/utils/crypto";
|
|
|
|
let page = parseInt(process.argv[2], 10);
|
|
page = Number.isNaN(page) ? 0 : page;
|
|
|
|
export default async function main(exit = false, limit = 100) {
|
|
const work = async (page: number): Promise<void> => {
|
|
console.log(`Backfill apiKey hash… page ${page}`);
|
|
let apiKeys: ApiKey[] = [];
|
|
await sequelize.transaction(async (transaction) => {
|
|
apiKeys = await ApiKey.unscoped().findAll({
|
|
attributes: ["id", "secret", "value", "hash"],
|
|
limit,
|
|
offset: page * limit,
|
|
order: [["createdAt", "ASC"]],
|
|
lock: Transaction.LOCK.UPDATE,
|
|
transaction,
|
|
});
|
|
|
|
for (const apiKey of apiKeys) {
|
|
try {
|
|
if (!apiKey.hash) {
|
|
console.log(`Migrating ${apiKey.id}…`);
|
|
apiKey.value = apiKey.secret;
|
|
apiKey.hash = hash(apiKey.secret);
|
|
// @ts-expect-error secret is deprecated
|
|
apiKey.secret = null;
|
|
await apiKey.save({ transaction });
|
|
}
|
|
} catch (err) {
|
|
console.error(`Failed at ${apiKey.id}:`, err);
|
|
continue;
|
|
}
|
|
}
|
|
});
|
|
return apiKeys.length === limit ? work(page + 1) : undefined;
|
|
};
|
|
|
|
await work(page);
|
|
|
|
console.log("Backfill complete");
|
|
|
|
if (exit) {
|
|
process.exit(0);
|
|
}
|
|
}
|
|
|
|
// In the test suite we import the script rather than run via node CLI
|
|
if (process.env.NODE_ENV !== "test") {
|
|
void main(true);
|
|
}
|