Skip to content

fix: Detect invalid API keys more carefully#792

Open
atheriel wants to merge 1 commit into
mainfrom
aj-more-careful-api-key-validation
Open

fix: Detect invalid API keys more carefully#792
atheriel wants to merge 1 commit into
mainfrom
aj-more-careful-api-key-validation

Conversation

@atheriel

Copy link
Copy Markdown
Contributor

Intent

When credentials come from the command line (or environment variables) rather than the store, we attempt to validate them by hitting the /v1/user endpoint, and error out if this fails.

It turns out that this doesn't work for machine credentials, which aren't associated with a user.

Thankfully the difference between "invalid API key" and "not a user API key" can be detected based on the error code from the response, so this commit draws this exact distinction.

Type of Change

  • Bug Fix
  • New Feature
  • Breaking Change

Automated Tests

Unit tests are included.

Directions for Reviewers

Checklist

  • I have updated CHANGELOG.md to cover notable changes.
  • I have updated all related GitHub issues to reflect their current state.
  • I have run the rsconnect-python-tests-at-night workflow in Connect against this feature branch.

@github-actions

github-actions Bot commented Jun 23, 2026

Copy link
Copy Markdown
PR Preview Action v1.8.1

QR code for preview link

🚀 View preview at
https://posit-dev.github.io/rsconnect-python/pr-preview/pr-792/

Built to branch gh-pages at 2026-06-23 21:15 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

@github-actions

github-actions Bot commented Jun 23, 2026

Copy link
Copy Markdown

☂️ Python Coverage

current status: ✅

Overall Coverage

Lines Covered Coverage Threshold Status
7211 5890 82% 0% 🟢

New Files

No new covered files...

Modified Files

File Coverage Status
rsconnect/api.py 79% 🟢
TOTAL 79% 🟢

updated for commit: a5c8bac by action🐍

When credentials come from the command line (or environment variables)
rather than the store, we attempt to validate them by hitting the
`/v1/user` endpoint, and error out if this fails.

It turns out that this doesn't work for machine credentials, which
aren't associated with a user.

Thankfully the difference between "invalid API key" and "not a user API
key" can be detected based on the error code from the response, so this
commit draws this exact distinction.

Unit tests are included.

Signed-off-by: Aaron Jacobs <aaron.jacobs@posit.co>
@atheriel atheriel force-pushed the aj-more-careful-api-key-validation branch from a13d522 to a5c8bac Compare June 23, 2026 21:15
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