Skip to content

install: retry without token when authenticated requests fail#1968

Draft
devm33 wants to merge 1 commit intomainfrom
install-auth-fallback
Draft

install: retry without token when authenticated requests fail#1968
devm33 wants to merge 1 commit intomainfrom
install-auth-fallback

Conversation

@devm33
Copy link
Member

@devm33 devm33 commented Mar 11, 2026

Summary

When a GITHUB_TOKEN is set but belongs to a GitHub org member whose token hasn't been SSO-authorized, SAML enforcement rejects the request — causing the install to fail even though the repo is public.

This adds a download() helper that tries with the token first, then automatically retries without it on failure. The same retry logic is applied to the git ls-remote call used for prerelease version detection.

Changes

  • Added download() helper function that:
    1. Attempts the request with the auth token (stderr suppressed)
    2. On failure, prints a warning and retries without the token
    3. Reports curl/wget not found if neither is available
  • Replaced inline curl/wget calls for tarball and checksums downloads with download()
  • Added retry-without-auth fallback to git ls-remote for prerelease detection

Behavior

Scenario Result
No GITHUB_TOKEN set Unauthenticated request (no change)
Valid token Authenticated request succeeds on first try
Token rejected (SAML/SSO) Warning printed, unauthenticated retry succeeds
Token rejected + repo actually private Warning printed, unauthenticated retry also fails → error

Tokens from GitHub org members that haven't been SSO-authorized for
the org will be rejected by SAML enforcement, causing downloads to
fail. Add a download() helper that tries with the token first, then
falls back to an unauthenticated request on failure. Apply the same
retry logic to the git ls-remote call for prerelease detection.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Comment on lines +47 to +70
# Download a file, retrying without auth on failure (e.g. SAML enforcement)
download() {
local url="$1" output="$2"
if command -v curl >/dev/null 2>&1; then
if [ ${#CURL_AUTH[@]} -gt 0 ]; then
if curl -fsSL "${CURL_AUTH[@]}" "$url" -o "$output" 2>/dev/null; then
return 0
fi
echo "Warning: Authenticated request failed, retrying without token..." >&2
fi
curl -fsSL "$url" -o "$output"
elif command -v wget >/dev/null 2>&1; then
if [ ${#WGET_AUTH[@]} -gt 0 ]; then
if wget -qO "$output" "${WGET_AUTH[@]}" "$url" 2>/dev/null; then
return 0
fi
echo "Warning: Authenticated request failed, retrying without token..." >&2
fi
wget -qO "$output" "$url"
else
echo "Error: Neither curl nor wget found. Please install one of them." >&2
return 1
fi
}
Copy link
Contributor

Choose a reason for hiding this comment

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

praise: stderr messaging informing users = 🧑‍🍳 💋

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