Fix authentication and error handling for cloud registries#225
Open
vsbuffalo wants to merge 2 commits into
Open
Fix authentication and error handling for cloud registries#225vsbuffalo wants to merge 2 commits into
vsbuffalo wants to merge 2 commits into
Conversation
Changes isinstance check to hasattr for more flexible auth backend support. This allows authentication headers to be properly applied for all auth backends that implement get_auth_header(), not just TokenAuth instances. Fixes authentication issues with OAuth2 tokens and custom auth backends.
When registry returns non-JSON responses (e.g., HTML error pages), attempting to parse with r.json() causes JSONDecodeError. This commonly occurs with authentication failures or when hitting web portals instead of registry APIs. Changes: - Replace r.json() calls with descriptive HTTP status messages - Add fallback for capitalized Location header (some registries use "Location") - Provide actionable error messages for debugging authentication issues This prevents confusing "Expecting value: line 1 column 1 (char 0)" errors and helps users understand the actual problem (auth, permissions, connectivity).
vsoch
reviewed
Sep 27, 2025
Contributor
vsoch
left a comment
There was a problem hiding this comment.
Very thorough, and is reasonable and overall LGTM. Could you please update the CHANGELOG and bump the version?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Thank you again for oras-py! I have found a few more issues and have included a
PR below. I will also try to submit a PR soon for #217 (I was able to address
that downstream so less pressing, but I will submit PR soon).
Problems Fixed
1. Authentication headers not being applied consistently
The
do_request()method only adds authentication headers when very specific conditions are met:This restrictive check causes authentication to fail in several scenarios:
TokenAuthinstances2. JSONDecodeError on non-JSON registry responses
When registries return non-JSON responses (e.g., HTML error pages from web portals), the code attempts to parse them with
r.json(), resulting in confusing errors:This commonly occurs with any cloud registry when:
Solutions
Commit 1: Use duck typing for auth header application
Relaxes the authentication check to use duck typing, which is more Pythonic and flexible:
Note: In the future, defining an auth interface with a Python Protocol could make the contract more explicit, but the current duck typing approach works well and is less opinionated of a design choice.
Commit 2: Improve error handling for non-JSON responses
r.json()calls in error handling with descriptive HTTP status messagesLocationheader (some registries use "Location" instead of "location")Benefits
get_auth_header(), we can use itTokenAuthclassTesting
All unit tests pass. I have tested with OAuth2 bearer token authentication (Azure Container Registry):
Verified with cloud registry implementations including Azure Container Registry.
Compatibility
Both changes are fully backward compatible:
BasicAuth,TokenAuth) already haveget_auth_header()method