feat(auth-extension): annotate links with auth:refs if#138
Merged
Conversation
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.
What I'm changing
Links in STAC responses now receive
auth:refsannotations when they point to endpoints protected by a CQL2 filter (items_filterorcollections_filter), even whendefault_public=true. Previously, filter-protected endpoints were advertised as public in link metadata, misleading clients about which requests require authentication.This PR also renames
MatchResult.is_privatetoMatchResult.uses_auth, which better describes the semantics — an endpoint may be nominally public yet still invoke the auth pipeline because a filter is applied.How I did it
items_filter_pathandcollections_filter_pathparameters to the shared find_match() utility inutils/requests.py. When a path matches either pattern, find_match now returnsMatchResult(uses_auth=True)regardless ofdefault_public.app.pyintoAuthenticationExtensionMiddleware, so link annotation uses the same matching logic as the OpenAPI middleware.match.is_privatechecks withmatch.uses_authinAuthenticationExtensionMiddlewareandEnforceAuthMiddleware._path_has_filterhelper fromUpdateOpenApiMiddleware; that logic now lives infind_match().TestFilterPathAnnotationtest class covering: items-filter match, collections-filter match, both filters together, non-matching links, no filters configured, and absolute-URL hrefs.How you can test it
default_public=trueand setitems_filter(and/orcollections_filter) to a CQL2 filter generator.GET /collections/{id}."auth:refs": ["<your auth scheme name>"], while unprotected links (e.g.self,root) do not.GET /) withcollections_filterconfigured and confirm the data link carriesauth:refs.pytest tests/test_auth_extension.py -k TestFilterPathAnnotationto exercise the new test cases.