Skip to content

IDC login fails with REQUEST_BODY_INVALID when profile does not support getUsageLimits #130

Description

@quanhk711

Describe the bug
IAM Identity Center (IdC) login fails with 400 REQUEST_BODY_INVALID when the selected CodeWhisperer/Q Developer profile does not support the getUsageLimits API. A valid token is actually issued during the device-code flow, but the auth callback throws on the optional usage check and aborts the entire login.

To Reproduce
Steps to reproduce the behavior:

  1. Configure ~/.config/opencode/kiro.json for IdC with a profile ARN whose profile does not support the usage-limits API (e.g. a QDefaultProfile):
    • idc_start_url: https://<org>.awsapps.com/start
    • idc_region: eu-west-1
    • idc_profile_arn: arn:aws:codewhisperer:us-east-1:<acct>:profile/<id>
  2. Run opencode auth login.
  3. Select provider kiro → login method IAM Identity Center with Profile ARN.
  4. Complete the device-code sign-in at the verification URL.
  5. See error: Failed to authorize: IDC authorization failed: Status: 400 (ValidationException) [<request-id>]: {"message":"Improperly formed request.","reason":"REQUEST_BODY_INVALID"}.

Expected behavior
Login should succeed. A failure of the optional getUsageLimits call (usage tracking is optional) should never block authentication — it should be skipped gracefully, the same way FEATURE_NOT_SUPPORTED already is. Setting usage_tracking_enabled: false should also skip the usage call during login.

Screenshots
Log from ~/.config/opencode/kiro-logs/plugin.log:
INFO: IDC authorize: resolved defaults {"oidcRegion":"eu-west-1","startUrl":"https://.awsapps.com"}
WARN: fetchUsageLimits failed during auth {"error":"Status: 400 (ValidationException) ...REQUEST_BODY_INVALID"}
ERROR: IDC auth callback failed Error: Status: 400 ...REQUEST_BODY_INVALID
at fetchUsageLimits (dist/plugin/usage.js:47:27)
at async dist/core/auth/idc-auth-method.js:95:39

Direct API test against q.us-east-1.amazonaws.com/getUsageLimits with a valid token + profile ARN (this profile supports none of the param combos):

Attempt (params) HTTP Body
AGENTIC_REQUEST + AI_EDITOR 403 FEATURE_NOT_SUPPORTED
AI_EDITOR only 403 FEATURE_NOT_SUPPORTED
CONVERSATION + AI_EDITOR 400 REQUEST_BODY_INVALID
no resourceType 403 FEATURE_NOT_SUPPORTED

Desktop (please complete the following information):

  • OS: macOS (darwin, Apple Silicon / arm64)
  • Browser: N/A (CLI / OpenCode)
  • Version: @zhafron/opencode-kiro-auth@2.0.0; auth method: IAM Identity Center with Profile ARN

Smartphone (please complete the following information):

  • Device: N/A
  • OS: N/A
  • Browser: N/A
  • Version: N/A

Additional context
Root cause is in the auth callback in dist/core/auth/idc-auth-method.js (~line 113), which only swallows FEATURE_NOT_SUPPORTED:

if (errMsg.includes('FEATURE_NOT_SUPPORTED')) {
    // skip usage check
} else {
    throw e; // REQUEST_BODY_INVALID lands here and aborts login
}
Suggested fix  treat REQUEST_BODY_INVALID the same as FEATURE_NOT_SUPPORTED:
if (errMsg.includes('FEATURE_NOT_SUPPORTED') || errMsg.includes('REQUEST_BODY_INVALID')) {
    usage = { usedCount: 0, limitCount: 0, email: undefined };
} else {
    throw e;
}
Also consider honoring usage_tracking_enabled: false during login  currently that flag is only checked at runtime (auth-handler / usage-tracker), not in the login path, so fetchUsageLimits is called unconditionally and setting the flag alone does not fix login.
Workaround: patching the condition above lets login complete (email falls back to a placeholder, token is stored and works).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions