Skip to content

feat: per-profile API URL with hidden --api-url on login #1486

Open

Description

@l2ysho

Note

TL;DR: apify login --api-url <url> stores the API, issuer and Console URLs on the profile. --profile then picks the environment. No APIFY_CLIENT_BASE_URL on every command.

Problem

  • P1. The CLI cannot tell which environment a token belongs to. Tokens are opaque.
  • P2. Non-production use needs APIFY_CLIENT_BASE_URL on every command.
  • P3. login guesses localhost:3333 from the Console URL. Staging is not covered.
  • P4. Device flow issuer defaults to production and is not linked to the API URL.

Proposal

  • S1. Hidden --api-url flag on login, for device flow and token login. Default https://api.apify.com.
  • S2. Discover the issuer and Console URLs from <api-url>/.well-known/oauth-authorization-server, which redirects to the issuer metadata.
  • S3. Store apiBaseUrl, issuer and consoleUrl on the profile.
  • S4. Commands use the profile's URLs. APIFY_CLIENT_BASE_URL still overrides them.
  • S5. Profile key:
    • production: userId (unchanged)
    • other environments: userId@host:port, e.g. AvSUC7C6j2Vlf52Zh@localhost:3333
  • S6. auth list shows an API column only when a non-production profile exists.
  • S7. Remove the localhost guess in login.

Notes

  • N1. Production-only users see no change: same keys, no new fields, no migration.
  • N2. A URL that normalizes to https://api.apify.com counts as production.
  • N3. Accept https only, plus http for localhost and 127.0.0.1.
  • N4. If discovery fails, token login still works. Device flow stops with an error.
  • N5. Check that : is legal in keyring account names on macOS, libsecret and Windows. If not, use another separator.
  • N6. apify run passes APIFY_API_BASE_URL to the Actor.
  • N7. This reverses the auth.json v2 #1419 decision against per-profile URLs. The use case is several environments with --profile.

Related

🤖 Generated with Claude Code

Activity

  1. l2ysho commented on Oct 9, 2026

    @l2ysho
    ContributorAuthor

    @DaveHanns @patrikbraborec what do you say about this? it is not big deal to do and it should help people who use different environments (staging, localhost)

  2. patrikbraborec commented on Oct 12, 2026

    @patrikbraborec
    Contributor

    Yeah, not 100% about the flag name, but otherwise it sounds good. We could also somehow coordinate this with local runtime (@Pijukatel), if it is possible -- but maybe these are different things. Anyway, I was thinking that will local runtime, you would just use this time of command to either:

    • work on local runtime
    • staging
    • prod
  3. Pijukatel commented on Oct 12, 2026

    @Pijukatel
    Contributor

    I am not sure what the end goal is here, but from a local runtime point of view, I do not see any benefit so far. When redirecting the CLI to the local runtime (due to env vars being set, or through apify runtime connect), the local runtime just takes the token apify login -t ... or uses whatever was already logged in, it can be valid token for real platform, or fake token as well. Maybe I am missing the point here?

    Anyway, from my point of view, at least the first two problems are correct behavior:

    P1. The CLI cannot tell which environment a token belongs to. Tokens are opaque.
    P2. Non-production use needs APIFY_CLIENT_BASE_URL on every command

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

    t-buildersIssues owned by the Builders team.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions