feat: send auth credentials on all STAC API requests#71
Draft
alukach wants to merge 8 commits into
Draft
Conversation
c7982f1 to
cbe1c46
Compare
…cope, restore comments
cbe1c46 to
84397dd
Compare
84397dd to
88c662d
Compare
alukach
commented
May 16, 2026
| authority: process.env.REACT_APP_OIDC_AUTHORITY, | ||
| clientId: process.env.REACT_APP_OIDC_CLIENT_ID | ||
| } | ||
| : undefined; |
Member
Author
There was a problem hiding this comment.
This was just some simplification to remove packages/client/src/auth/resolveAuthConfig.ts which seemed unnecessary
Otherwise useStacApi probes the landing page (and useCollections fetches) once without auth, then again when the token arrives. App.tsx already gates content rendering on isLoading, so no consumer hooks need the context during this window.
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
Reads (
GET) against the configured STAC API now carryAuthorization: Bearer <token>whenever the user is authenticated — matching the behavior that mutations already had. The hand-rolled header incollectionTransactionis retired; all requests flow through one central injection point, scoped to URLs underREACT_APP_STAC_API.Before:
useCollection,useItem,useStacSearch, and the localuseCollectionshook all issued anonymous requests. On a protected STAC API (e.g. the eoAPI develop deployment with the STAC Authentication extension'sauth:refsannotations), this produced 401s or reduced data for logged-in users.After: every request to the STAC API base URL includes the bearer token when one is available. When the user logs out, the header disappears on the next request.
How I did it
StacApiAuthBridgeinmain.tsxreads the current token fromuseAuth()and does two things on every token change:options={{ headers: { Authorization } }}intoStacApiProvider, so everystac-reacthook that consumes the sharedStacApiinstance picks up the authed headers.setApiAuthToken(token), so the staticApi.fetch(used for mutations and any direct reads) can inject the header without needing to be a hook.Api.fetch(packages/client/src/api/index.ts) attaches the header only when the URL is underREACT_APP_STAC_API(path-boundary normalized, so/stac-admincannot match a/stacbase). Caller-provided headers still win on key collision — that's covered by a test.packages/client/src/pages/CollectionList/useCollections.tsis an outlier: it callsuseStacApi(url)directly becausestac-react@0.1.0-alpha.10doesn't re-exportuseStacApiContext. It now readsuseAuth()itself and passes the same options down, mirroring the bridge.collectionTransaction(packages/client/src/pages/CollectionForm/index.tsx) drops itstokenparameter and the hand-rolledAuthorization: Bearer …header. Mutations now carry exactly one Authorization header, injected centrally.No changes to
stac-reactwere needed — the installed version already mergesoptions.headersinto every fetch, and re-passing a newoptionsobject on token change triggers the provider to rebuild itsStacApi. Design notes and the skipped-alternative rationale are indocs/plans/2026-04-23-authed-get-requests-design.mdanddocs/plans/2026-04-23-authed-get-requests.md.Tests
Added
packages/client/src/api/index.test.ts— 5 unit tests pinning down the injection rules:Authorizationoverrides injected oneREACT_APP_STAC_APIunset → no headerFull suite: 108 passing.
How you can test it
.envat a protected STAC API:npm run client:serveand open DevTools → Network.eoapi.develop.eoepca.org/stac/*should have noAuthorizationheader. Public data or 401s are both fine depending on server config.Authorization: Bearer <token>. Collection list, collection detail, items list, search — all should return authed data.PUTshould succeed with exactly oneAuthorizationheader in the request.npx jest— all 108 tests pass.