Skip to content

Commit

Permalink
Apply allowedDomains to headers and query parameters #313
Browse files Browse the repository at this point in the history
  • Loading branch information
m-mohr committed May 12, 2023
1 parent da6793b commit 77a7c7a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ Must be set to `true` if a `catalogUrl` is not given as otherwise you won't be a
#### allowedDomains

You can list additional domains (e.g. `example.com`) that private data is sent to, e.g. authentication data.
This applies to query paramaters and request headers.

#### apiCatalogPriority

Expand Down Expand Up @@ -332,6 +333,7 @@ The value for the [`crossorigin` attribute](https://developer.mozilla.org/en-US/
***experimental***

The headers given in this option are added to all requests that are sent to the selected STAC catalog or API.
This is affected by [`allowedDomains`](#alloweddomains).

Example: `{'Authorization': 'Bearer 134567984623223'}` adds a Bearer token to the HTTP headers.

Expand All @@ -342,6 +344,7 @@ Please note that this option can only be provided through a config file and is n
***experimental***

The query parameters given in this option are added to all requests that are sent to the selected STAC catalog or API.
This is affected by [`allowedDomains`](#alloweddomains).

Example: `{'f': 'json'}` adds a `f` query parameter to the HTTP URL, e.g. `https://example.com?f=json`.

Expand All @@ -352,7 +355,7 @@ Please note that this option can only be provided through a config file and is n
***experimental***

This allows to enable a simple authentication form where a user can input a token, an API key or similar things.
It is disabled by default (`null`). If enabled, the token provided by the user can be used in the HTTP headers or in the query parameters of the requests.
It is disabled by default (`null`). If enabled, the token provided by the user can be used in the HTTP headers or in the query parameters of the requests. This option is affected by [`allowedDomains`](#alloweddomains).

There are four options you can set in the `authConfig` object:

Expand Down
13 changes: 10 additions & 3 deletions src/store/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,31 @@ export async function stacRequest(cx, link) {
let headers = {
'Accept-Language': cx.getters.acceptedLanguages
};
Object.assign(headers, cx.state.requestHeaders);
if (Utils.isObject(link)) {
let method = typeof link.method === 'string' ? link.method.toLowerCase() : 'get';
let url = cx.getters.getRequestUrl(link.href);
if (!cx.getters.isExternalUrl(url)) {
Object.assign(headers, cx.state.requestHeaders);
}
if (Utils.isObject(link.headers)) {
Object.assign(headers, link.headers);
}
opts = {
method,
url: cx.getters.getRequestUrl(link.href),
url,
headers,
data: link.body
// ToDo: Support for merge property from STAC API
};
}
else if (typeof link === 'string') {
let url = cx.getters.getRequestUrl(link);
if (!cx.getters.isExternalUrl(url)) {
Object.assign(headers, cx.state.requestHeaders);
}
opts = {
method: 'get',
url: cx.getters.getRequestUrl(link),
url,
headers
};
}
Expand Down

0 comments on commit 77a7c7a

Please sign in to comment.