qbo_auth: realmId шифруется, /callback отвечает 302, no-cache; требования Intuit: раздел E по оригиналу, ручные тесты через /tests
All checks were successful
ci / test (push) Successful in 38s
ci / deploy (push) Successful in 2m38s

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-23 09:21:39 +03:00
parent b0a68930b1
commit e90b9f352d
7 changed files with 65 additions and 34 deletions

View File

@@ -52,10 +52,24 @@ export class PgStore implements Store {
return row && row.fresh ? row.environment : null;
}
/** realmId хранится зашифрованным (требование Intuit); открытое значение из старых записей читается как есть. */
private readRealm(v: string): string {
return v.startsWith("v1.") ? decrypt(v, this.key) : v;
}
/** Однократно шифрует realm_id в уже существующих записях (вызывается при старте). */
async encryptExistingRealms(): Promise<number> {
const r = await this.pool.query("select environment, realm_id from qbo_connection where realm_id not like 'v1.%'");
for (const row of r.rows as Array<{ environment: string; realm_id: string }>) {
await this.pool.query("update qbo_connection set realm_id = $2 where environment = $1", [row.environment, encrypt(row.realm_id, this.key)]);
}
return r.rows.length;
}
private toConn(row: Record<string, unknown>): Connection {
return {
environment: row.environment as Env,
realmId: row.realm_id as string,
realmId: this.readRealm(row.realm_id as string),
accessToken: decrypt(row.access_token_enc as string, this.key),
refreshToken: decrypt(row.refresh_token_enc as string, this.key),
accessExpiresAt: row.access_expires_at as Date,
@@ -86,7 +100,7 @@ export class PgStore implements Store {
refresh_token_enc = excluded.refresh_token_enc, access_expires_at = excluded.access_expires_at,
refresh_expires_at = excluded.refresh_expires_at, authorized_at = excluded.authorized_at,
refreshed_at = excluded.refreshed_at, status = excluded.status`,
[c.environment, c.realmId, encrypt(c.accessToken, this.key), encrypt(c.refreshToken, this.key), c.accessExpiresAt, c.refreshExpiresAt, c.authorizedAt, c.refreshedAt, c.status],
[c.environment, encrypt(c.realmId, this.key), encrypt(c.accessToken, this.key), encrypt(c.refreshToken, this.key), c.accessExpiresAt, c.refreshExpiresAt, c.authorizedAt, c.refreshedAt, c.status],
);
},
remove: async () => {