Skip to content

Commit

Permalink
Add support for fetching with credentials (#385)
Browse files Browse the repository at this point in the history
* explicitly set 'credentials' parameter for fetch
  • Loading branch information
Phil Varner authored May 14, 2024
1 parent d2af52d commit cd2bd91
Show file tree
Hide file tree
Showing 13 changed files with 33 additions and 11 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## unreleased

### Changed

- API calls via `fetch` now include configuration for including authentication.
This can be changed with the config FETCH_CREDENTIALS, which defaults to the
browser default of `same-origin`.

## 5.2.0 - 2024-05-08

### Fixed
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ The file `config_helper/config.example.json` is included in this repository as r
| LAYER_LIST_SERVICES | Defines the services used as reference layers for the map. **Limitations:** Currently only WMS services are supported and only `EPSG:4326` or `EPSG:3857` are supported values for defining crs options. If not set or not formatted correctly, reference layer list widget will either be empty or will not render. Formatting should match example in `config.example.json`. | Optional |
| STAC_LINK_ENABLED | If set to `true`, STAC Item link will render in Item Details. | Optional |
| SHOW_ITEM_AUTO_ZOOM | If set to `true`, switch will render in `Filters` list to let the user toggle if the map automatically centers on item footprint when selected item is changed. Default when initialized is auto-zoom not enabled, user must opt-in by turning on (choice will persist for app session). | Optional |
| FETCH_CREDENTIALS | Defines if API calls made from the app should include the authentication used to access the app. Can be set to `same-origin` (default), `include`, or `omit`. | Optional |

### Links

Expand Down
3 changes: 2 additions & 1 deletion src/services/get-aggregate-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ export async function AggregateSearchService(searchParams, gridType) {
store.getState().mainSlice.appConfig.STAC_API_URL
}/aggregate?${searchParams}`,
{
method: 'GET'
credentials:
store.getState().mainSlice.appConfig.FETCH_CREDENTIALS || 'same-origin'
}
)
.then((response) => {
Expand Down
3 changes: 2 additions & 1 deletion src/services/get-aggregations-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ export async function GetCollectionAggregationsService(collectionId) {
store.getState().mainSlice.appConfig.STAC_API_URL
}/collections/${collectionId}/aggregations`,
{
method: 'GET'
credentials:
store.getState().mainSlice.appConfig.FETCH_CREDENTIALS || 'same-origin'
}
)
.then((response) => {
Expand Down
6 changes: 5 additions & 1 deletion src/services/get-all-scenes-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ import {
import { DEFAULT_MAX_SCENES_RENDERED } from '../components/defaults'

async function fetchFeatures(url, abortSignal) {
const response = await fetch(url, { signal: abortSignal })
const response = await fetch(url, {
signal: abortSignal,
credentials:
store.getState().mainSlice.appConfig.FETCH_CREDENTIALS || 'same-origin'
})
const data = await response.json()
clearLayer('clickedSceneImageLayer')

Expand Down
3 changes: 2 additions & 1 deletion src/services/get-collections-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ export async function GetCollectionsService(searchParams) {
await fetch(
`${store.getState().mainSlice.appConfig.STAC_API_URL}/collections`,
{
method: 'GET'
credentials:
store.getState().mainSlice.appConfig.FETCH_CREDENTIALS || 'same-origin'
}
)
.then((response) => {
Expand Down
1 change: 0 additions & 1 deletion src/services/get-config-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ export async function LoadConfigIntoStateService() {
}config/config.json?_cb=${cacheBuster}`

await fetch(configUrl, {
method: 'GET',
cache: 'no-store'
})
.then((response) => {
Expand Down
1 change: 0 additions & 1 deletion src/services/get-local-grid-data-json-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ export async function LoadLocalGridDataService(fileName) {
import.meta.env.BASE_URL
}data/${fileName}.json?_cb=${cacheBuster}`
await fetch(configUrl, {
method: 'GET',
cache: 'no-store'
})
.then((response) => {
Expand Down
5 changes: 4 additions & 1 deletion src/services/get-mosaic-bounds.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { store } from '../redux/store'

export function GetMosaicBoundsService(mosaicURL) {
return new Promise(function (resolve, reject) {
fetch(mosaicURL, {
method: 'GET'
credentials:
store.getState().mainSlice.appConfig.FETCH_CREDENTIALS || 'same-origin'
})
.then((response) => {
if (response.ok) {
Expand Down
3 changes: 2 additions & 1 deletion src/services/get-queryables-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ export function GetCollectionQueryablesService(collectionId) {
store.getState().mainSlice.appConfig.STAC_API_URL
}/collections/${collectionId}/queryables`,
{
method: 'GET'
credentials:
store.getState().mainSlice.appConfig.FETCH_CREDENTIALS || 'same-origin'
}
)
.then((response) => {
Expand Down
3 changes: 2 additions & 1 deletion src/services/get-search-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ export async function SearchService(searchParams, typeOfSearch) {
store.getState().mainSlice.appConfig.STAC_API_URL
}/search?${searchParams}`,
{
method: 'GET'
credentials:
store.getState().mainSlice.appConfig.FETCH_CREDENTIALS || 'same-origin'
}
)
.then((response) => {
Expand Down
3 changes: 2 additions & 1 deletion src/utils/mapHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,8 @@ function addImageOverlay(item) {
const tilerParams = constructSceneTilerParams(_selectedCollectionData.id)

fetch(featureURL, {
method: 'GET'
credentials:
store.getState().mainSlice.appConfig.FETCH_CREDENTIALS || 'same-origin'
})
.then(function (response) {
return response.json()
Expand Down
4 changes: 3 additions & 1 deletion src/utils/searchHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,9 @@ function newMosaicSearch() {
headers: {
'Content-Type': 'application/vnd.titiler.stac-api-query+json'
},
body: JSON.stringify(createMosaicBody)
body: JSON.stringify(createMosaicBody),
credentials:
store.getState().mainSlice.appConfig.FETCH_CREDENTIALS || 'same-origin'
}

AddMosaicService(requestOptions)
Expand Down

0 comments on commit cd2bd91

Please sign in to comment.