Skip to content

Commit d2a45a9

Browse files
committed
improve documentation
1 parent 9a66800 commit d2a45a9

File tree

3 files changed

+58
-12
lines changed

3 files changed

+58
-12
lines changed

docs/user-guide/tips.md

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
## CORS
44

5-
The STAC Auth Proxy does not modify the [CORS response headers](https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/CORS#the_http_response_headers) from the upstream STAC API. All CORS configuration must be handled by the upstream API.
5+
The STAC Auth Proxy does not modify the [CORS response headers](https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/CORS#the_http_response_headers) from the upstream STAC API. All CORS configuration must be handled by the upstream API.
66

77
Because the STAC Auth Proxy introduces authentication, the upstream API’s CORS settings may need adjustment to support credentials. In most cases, this means:
88

9-
* [`Access-Control-Allow-Credentials`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Access-Control-Allow-Credentials) must be `true`
10-
* [`Access-Control-Allow-Origin`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Access-Control-Allow-Origin) must _not_ be `*`[^CORSNotSupportingCredentials]
9+
- [`Access-Control-Allow-Credentials`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Access-Control-Allow-Credentials) must be `true`
10+
- [`Access-Control-Allow-Origin`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Access-Control-Allow-Origin) must _not_ be `*`[^CORSNotSupportingCredentials]
1111

1212
[^CORSNotSupportingCredentials]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/CORS/Errors/CORSNotSupportingCredentials
1313

@@ -32,13 +32,40 @@ Rather than performing the login flow, the Swagger UI can be configured to accep
3232
```sh
3333
OPENAPI_AUTH_SCHEME_NAME=jwtAuth
3434
OPENAPI_AUTH_SCHEME_OVERRIDE='{
35-
"type": "http",
36-
"scheme": "bearer",
37-
"bearerFormat": "JWT",
35+
"type": "http",
36+
"scheme": "bearer",
37+
"bearerFormat": "JWT",
3838
"description": "Paste your raw JWT here. This API uses Bearer token authorization."
3939
}'
4040
```
4141

42-
## Runtime Customization
42+
## Non-proxy Configuration
4343

44-
While the project is designed to work out-of-the-box as an application, it might not address every projects needs. When the need for customization arises, the codebase can instead be treated as a library of components that can be used to augment any [ASGI](https://asgi.readthedocs.io/en/latest/)-compliant webserver (e.g. [Django](https://docs.djangoproject.com/en/3.0/topics/async/), [Falcon](https://falconframework.org/), [FastAPI](https://github.com/tiangolo/fastapi), [Litestar](https://litestar.dev/), [Responder](https://responder.readthedocs.io/en/latest/), [Sanic](https://sanic.dev/), [Starlette](https://www.starlette.io/)). Review [`app.py`](https://github.com/developmentseed/stac-auth-proxy/blob/main/src/stac_auth_proxy/app.py) to get a sense of how we make use of the various components to construct a FastAPI application.
44+
While the project is designed to work out-of-the-box as an application, it might not address every projects needs. When the need for customization arises, the codebase can instead be treated as a library of components that can be used to augment a FastAPI server. This may look something like the following:
45+
46+
```py
47+
from fastapi import FastAPI
48+
from stac_fastapi.api.app import StacApi
49+
from stac_auth_proxy import build_lifespan, configure_app, Settings as StacAuthSettings
50+
51+
# Create Auth Settings
52+
auth_settings = StacAuthSettings(
53+
upstream_url='https://stac-server',
54+
oidc_discovery_url='https://auth-server/.well-known/openid-configuration',
55+
)
56+
57+
# Setup App
58+
app = FastAPI(
59+
...
60+
lifespan=build_lifespan(auth_settings),
61+
)
62+
63+
# Apply STAC Auth Proxy middleware
64+
configure_app(app, auth_settings)
65+
66+
# Setup STAC API
67+
api = StacApi(
68+
app,
69+
...
70+
)
71+
```

src/stac_auth_proxy/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88

99
from .app import configure_app, create_app
1010
from .config import Settings
11+
from .lifespan import build_lifespan
1112

1213
__all__ = [
14+
"build_lifespan",
1315
"create_app",
1416
"configure_app",
1517
"Settings",

src/stac_auth_proxy/app.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"""
77

88
import logging
9-
from typing import Optional
9+
from typing import Any, Optional
1010

1111
from fastapi import FastAPI
1212
from starlette_cramjam.middleware import CompressionMiddleware
@@ -30,9 +30,26 @@
3030
logger = logging.getLogger(__name__)
3131

3232

33-
def configure_app(app: FastAPI, settings: Optional[Settings] = None) -> FastAPI:
34-
"""Apply routes and middleware to a FastAPI app."""
35-
settings = settings or Settings()
33+
def configure_app(
34+
app: FastAPI,
35+
settings: Optional[Settings] = None,
36+
**settings_kwargs: Any,
37+
) -> FastAPI:
38+
"""
39+
Apply routes and middleware to a FastAPI app.
40+
41+
Parameters
42+
----------
43+
app : FastAPI
44+
The FastAPI app to configure.
45+
settings : Settings | None, optional
46+
Pre-built settings instance. If omitted, a new one is constructed from
47+
``settings_kwargs``.
48+
**settings_kwargs : Any
49+
Keyword arguments used to configure the health and conformance checks if
50+
``settings`` is not provided.
51+
"""
52+
settings = settings or Settings(**settings_kwargs)
3653

3754
#
3855
# Route Handlers

0 commit comments

Comments
 (0)