Skip to content

Support split-domain Alexa auth/runtime for EU accounts#8

Open
6leonardo wants to merge 1 commit intobuddyh:mainfrom
6leonardo:fix/amazon-local-routing
Open

Support split-domain Alexa auth/runtime for EU accounts#8
6leonardo wants to merge 1 commit intobuddyh:mainfrom
6leonardo:fix/amazon-local-routing

Conversation

@6leonardo
Copy link

@6leonardo 6leonardo commented Mar 1, 2026

Summary

  • add amazon_local config for local marketplace/runtime routing
  • keep amazon_domain for auth/token exchange
  • auth flow supports --domain (base) + --country (marketplace), aligned with alexa-cookie-cli usage
  • improve CSRF discovery with fallback hosts
  • improve history/activity CSRF + privacy endpoint fallback domains
  • update README with new auth flow and config fields

Why

EU/IT accounts often authenticate via amazon.com but require local/runtime endpoint handling. This fixes mixed-domain behavior and reduces CSRF/history failures.

Tested

  • alexacli devices -v
  • alexacli command "turn on lights" -d "Living Room" -v
  • alexacli history -v (fallback behavior)

Config example

{
  "refresh_token": "Atnr|...",
  "amazon_domain": "amazon.com",
  "amazon_local": "amazon.it"
}

Copilot AI review requested due to automatic review settings March 1, 2026 11:27
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds split-domain support so EU accounts can authenticate/token-exchange against one Amazon domain while routing marketplace/runtime/API traffic through a local domain, improving CSRF and history/privacy endpoint reliability.

Changes:

  • Extend config to include amazon_local alongside amazon_domain, with sensible fallback behavior.
  • Add NewClientWithLocal(...) and update runtime/CSRF/history endpoint routing to prefer the local domain with multiple fallbacks.
  • Update CLI auth flow + README to document the split-domain login/config approach.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
internal/config/config.go Adds amazon_local to config and defaults it to amazon_domain when omitted.
internal/api/client.go Introduces local-domain routing, adds CSRF/history fallback hosts, and adjusts regional endpoint selection.
cmd/alexa/root.go Constructs API client using amazon_domain + amazon_local.
cmd/alexa/auth.go Adds --country (local domain) to browser auth flow and persists it as amazon_local.
README.md Documents split-domain auth flow and new config fields.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +95 to 97
cmd.Flags().StringVar(&domain, "domain", "amazon.com", "Base Amazon domain for login/token exchange (usually amazon.com)")
cmd.Flags().StringVar(&country, "country", "amazon.it", "Marketplace country page for login (e.g. amazon.it, amazon.de)")

Copy link

Copilot AI Mar 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new --country flag defaults to amazon.it, which means running alexacli auth with no flags will save AmazonLocal=amazon.it and initialize the API client against the IT/EU runtime endpoints even for US accounts. This can break device listing/commands for users who previously relied on the default amazon.com behavior. Consider defaulting --country to an empty string (or amazon.com) and normalizing after flag parsing (e.g., if empty then set to domain) before calling runBrowserAuth/NewClientWithLocal and before saving config.

Copilot uses AI. Check for mistakes.
req.Header.Set("anti-csrftoken-a2z", c.activityCSRF)
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Accept", "application/json, text/plain, */*")
req.Header.Set("Accept-Language", "it-IT,it;q=0.9,en-US;q=0.8,en;q=0.7")
Copy link

Copilot AI Mar 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GetCustomerHistoryRecords now hard-codes Accept-Language to Italian (it-IT,...). This will send the wrong locale for non-IT accounts and can affect server-side routing/CSRF behavior. Use the client’s derived locale (e.g. c.locale() / c.localDomain()) to build this header instead of a fixed value.

Suggested change
req.Header.Set("Accept-Language", "it-IT,it;q=0.9,en-US;q=0.8,en;q=0.7")
if locale := c.locale(); locale != "" {
req.Header.Set("Accept-Language", locale)
}

Copilot uses AI. Check for mistakes.
@6leonardo 6leonardo force-pushed the fix/amazon-local-routing branch from 33fd459 to ff6cbab Compare March 1, 2026 12:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants