mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-07-31 20:32:20 +03:00
* feat(oauth): add Kiro long-lived API key auth (#6587) New /api/oauth/kiro/api-key route + KiroService.validateApiKey let a Kiro account be linked with a long-lived AWS CodeWhisperer/Kiro API key instead of the interactive OAuth device flow, with live per-account model discovery (ListAvailableModels, 5-minute cache) layered over the existing static registry fallback. Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com> * fix(changelog): re-restore #6587 bullet after release sync Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com> * fix(merge): restore #6126 clinepass files reverted by release auto-resolve + baseline re-merge The release sync's auto-resolve reverted sibling PR #6126's clinepass work (registry, catalog, oauth constants, clineAuth.ts, token-refresh case, tests) and the file-size baseline — all outside this PR's scope. Restored to the release versions, re-applied only this PR's own baseline entries, restored the #6126 CHANGELOG bullet (re-inserting only this PR's own). Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com> * chore(quality): freeze public-creds FP — AWS region default in validateApiKey signature Same class as the existing minimax fn-param FPs: CRED_KEY_RE matches the apiKey: param annotation and captures the region default "us-east-1", which is not a credential. Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com> * fix(kiro): keep hard-failure reject semantics + kill public-creds fn-param FP at the source - getKiroUsage: exhausted non-auth attempts now REJECT with the last HTTP-status failure in the pre-#6587 format (usage-service-hardening relies on it); auth failures keep the soft social-auth message. - validateApiKey: region default moved out of the parameter list (the check-public-creds CRED_KEY_RE matches the apiKey: annotation and flags any literal in the signature); drops the brittle line-keyed allowlist entry. Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com> --------- Co-authored-by: strangersp <strangersp@users.noreply.github.com> Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com> Co-authored-by: Diego Rodrigues de Sa e Souza <diegosouza.pw@gmail.com>
63 lines
2.4 KiB
TypeScript
63 lines
2.4 KiB
TypeScript
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
|
|
import { KiroService } from "../../src/lib/oauth/services/kiro.ts";
|
|
|
|
test("KiroService.validateApiKey validates via ListAvailableProfiles with API_KEY token type", async () => {
|
|
const service = new KiroService();
|
|
const originalFetch = globalThis.fetch;
|
|
|
|
globalThis.fetch = (async (url: string, init?: RequestInit) => {
|
|
assert.equal(url, "https://q.eu-central-1.amazonaws.com");
|
|
const headers = init?.headers as Record<string, string>;
|
|
assert.equal(headers.Authorization, "Bearer kiro-api-key");
|
|
assert.equal(headers.tokentype, "API_KEY");
|
|
assert.equal(headers["x-amz-target"], "AmazonCodeWhispererService.ListAvailableProfiles");
|
|
return new Response(
|
|
JSON.stringify({
|
|
profiles: [
|
|
{ arn: "arn:aws:codewhisperer:us-east-1:1:profile/OTHER" },
|
|
{ arn: "arn:aws:codewhisperer:eu-central-1:1:profile/MATCH" },
|
|
],
|
|
}),
|
|
{ status: 200, headers: { "Content-Type": "application/json" } }
|
|
);
|
|
}) as typeof fetch;
|
|
|
|
try {
|
|
const credential = await service.validateApiKey(" kiro-api-key ", "eu-central-1");
|
|
assert.equal(credential.accessToken, "kiro-api-key");
|
|
assert.equal(credential.refreshToken, null);
|
|
assert.equal(credential.authMethod, "api_key");
|
|
assert.equal(credential.region, "eu-central-1");
|
|
assert.equal(credential.profileArn, "arn:aws:codewhisperer:eu-central-1:1:profile/MATCH");
|
|
} finally {
|
|
globalThis.fetch = originalFetch;
|
|
}
|
|
});
|
|
|
|
test("KiroService.validateApiKey accepts API keys when profile discovery is denied", async () => {
|
|
const service = new KiroService();
|
|
const originalFetch = globalThis.fetch;
|
|
|
|
globalThis.fetch = (async () =>
|
|
new Response(
|
|
JSON.stringify({
|
|
__type: "com.amazon.aws.codewhisperer#AccessDeniedException",
|
|
message: "API key authentication is not supported for this operation.",
|
|
}),
|
|
{ status: 403, headers: { "Content-Type": "application/json" } }
|
|
)) as typeof fetch;
|
|
|
|
try {
|
|
const credential = await service.validateApiKey(" kiro-api-key ", "us-east-1");
|
|
assert.equal(credential.accessToken, "kiro-api-key");
|
|
assert.equal(credential.refreshToken, null);
|
|
assert.equal(credential.authMethod, "api_key");
|
|
assert.equal(credential.region, "us-east-1");
|
|
assert.equal(credential.profileArn, null);
|
|
} finally {
|
|
globalThis.fetch = originalFetch;
|
|
}
|
|
});
|