Skip to content

Fix auth on EU workspaces: preserve Authorization across regional redirect - #12

Closed
kevduc wants to merge 4 commits into
segment-integrations:masterfrom
kevduc:fix/eu-redirect-auth
Closed

Fix auth on EU workspaces: preserve Authorization across regional redirect#12
kevduc wants to merge 4 commits into
segment-integrations:masterfrom
kevduc:fix/eu-redirect-auth

Conversation

@kevduc

@kevduc kevduc commented May 1, 2026

Copy link
Copy Markdown

Summary

EU-region Segment workspaces could not authenticate via segmentcli: auth and every subsequent command returned Supplied token is not authorized. (or Authorization header is required). Root cause is that api.segmentapis.com 30x's to a regional host (e.g. eu1.api.segmentapis.com) for EU workspaces, and Apple's URLSession strips the Authorization header on redirect by default — the followed request arrives unauthenticated.

This PR adds a URLSessionTaskDelegate that re-attaches Authorization (and Accept) on redirect, and routes every PAPI endpoint (/, /sources, /sources/<id>/edge-functions/...) through the new redirect-aware session.

Also adds a Claude Code skill (.claude/skills/segmentcli/SKILL.md) that documents the CLI's commands, auth/profile model, and read-only vs side-effecting operations.

Commits

  1. Fix auth on EU workspaces: re-attach Authorization on redirect — introduces PAPIRedirectDelegate and routes authenticate() through it; adds Accept: application/vnd.segment.v1+json.
  2. Route remaining endpoints through redirect-aware session — switches PAPISources and PAPIEdgeFunctions from URLSession.shared to PAPI.shared.session.
  3. Add Claude Code skill for segmentcli — repo-shipped skill, auto-loaded in Claude Code.
  4. Tidy PAPI.swift — compact comments, drop diagnostic debug prints.

Test plan

Tested against an EU workspace:

  • segmentcli auth <Profile> <Token> — succeeds (previously failed with Supplied token is not authorized.)
  • segmentcli profile list — shows the saved workspace
  • segmentcli sources list — returns the full source list (previously failed with 401)
  • segmentcli liveplugins latest <sourceId> — authenticates, server reports per-source state
  • Build passes (sudo make install, release config)

No public-facing API or flag changes — --staging still works, no new --eu flag (Public API is single-host; the redirect is server-driven).

kevduc and others added 4 commits May 1, 2026 02:44
Segment Public API redirects api.segmentapis.com -> eu1.api.segmentapis.com
for EU workspaces. URLSession strips Authorization headers on redirect by
default, causing the auth probe to receive a 401 "Authorization header is
required". A URLSessionTaskDelegate now re-attaches the original
Authorization (and Accept) headers on redirect.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
PAPISources and PAPIEdgeFunctions used URLSession.shared, which strips
Authorization on redirect — causing 401s on EU workspaces (US host
30x's to eu1.api.segmentapis.com). Switch them to PAPI.shared.session
so the existing redirect delegate re-attaches the auth header.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Squashes the long endpoint comment and redirect-delegate explanation
into single lines, collapses the duplicated header re-attach blocks
into a loop, and removes the SEGMENTCLI_DEBUG print block that was
only used during diagnosis.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Documents the CLI's commands, auth/profile model, EU-workspace behavior
(redirect-aware), read-only vs side-effecting commands, and common
workflows. Loaded automatically by Claude Code when working in this repo.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@kevduc

kevduc commented May 1, 2026

Copy link
Copy Markdown
Author

Closing to recreate from a clean fork — the previous force-pushed history is still referenced by the timeline event of this PR. Reopening shortly from a fresh branch with no pre-sanitization commits.

@kevduc kevduc closed this May 1, 2026
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.

1 participant