Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions docs/user-guide/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ The application is configurable via environment variables.
"^/$": ["GET"],
"^/api.html$": ["GET"],
"^/api$": ["GET"],
"^/conformance$": ["GET"],
"^/docs/oauth2-redirect": ["GET"],
"^/healthz": ["GET"]
}
Expand All @@ -143,9 +144,9 @@ The application is configurable via environment variables.

: Path of OpenAPI specification, used for augmenting spec response with auth configuration

**Type:** string or null
**Required:** No, defaults to `null` (disabled)
**Example:** `/api`
**Type:** string or null
**Required:** No, defaults to `/api`
**Example:** `''` (disabled)

### `OPENAPI_AUTH_SCHEME_NAME`

Expand Down Expand Up @@ -175,9 +176,9 @@ The application is configurable via environment variables.

: Path of Swagger UI, used to indicate that a custom Swagger UI should be hosted, typically useful when providing accompanying `SWAGGER_UI_INIT_OAUTH` arguments

**Type:** string or null
**Required:** No, defaults to `null` (disabled)
**Example:** `/api.html`
**Type:** string or null
**Required:** No, defaults to `/api.html`
**Example:** `''` (disabled)

### `SWAGGER_UI_INIT_OAUTH`

Expand Down
17 changes: 12 additions & 5 deletions src/stac_auth_proxy/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,18 +80,25 @@ async def lifespan(app: FastAPI):
# Handlers (place catch-all proxy handler last)
#

if settings.swagger_ui_endpoint:
assert (
settings.openapi_spec_endpoint
), "openapi_spec_endpoint must be set when using swagger_ui_endpoint"
# If we have customized Swagger UI Init settings (e.g. a provided client_id)
# then we need to serve our own Swagger UI in place of the upstream's. This requires
# that we know the Swagger UI endpoint and the OpenAPI spec endpoint.
if all(
[
settings.swagger_ui_endpoint,
settings.openapi_spec_endpoint,
settings.swagger_ui_init_oauth,
]
):
app.add_route(
settings.swagger_ui_endpoint,
SwaggerUI(
openapi_url=settings.openapi_spec_endpoint,
openapi_url=settings.openapi_spec_endpoint, # type: ignore
init_oauth=settings.swagger_ui_init_oauth,
).route,
include_in_schema=False,
)

if settings.healthz_prefix:
app.include_router(
HealthzHandler(upstream_url=str(settings.upstream_url)).router,
Expand Down
9 changes: 7 additions & 2 deletions src/stac_auth_proxy/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,14 @@ class Settings(BaseSettings):
enable_compression: bool = True

# OpenAPI / Swagger UI
openapi_spec_endpoint: Optional[str] = Field(pattern=_PREFIX_PATTERN, default=None)
openapi_spec_endpoint: Optional[str] = Field(
pattern=_PREFIX_PATTERN, default="/api"
)
openapi_auth_scheme_name: str = "oidcAuth"
openapi_auth_scheme_override: Optional[dict] = None
swagger_ui_endpoint: Optional[str] = None
swagger_ui_endpoint: Optional[str] = Field(
pattern=_PREFIX_PATTERN, default="/api.html"
)
swagger_ui_init_oauth: dict = Field(default_factory=dict)

# Auth
Expand All @@ -70,6 +74,7 @@ class Settings(BaseSettings):
r"^/$": ["GET"],
r"^/api.html$": ["GET"],
r"^/api$": ["GET"],
r"^/conformance$": ["GET"],
r"^/docs/oauth2-redirect": ["GET"],
r"^/healthz": ["GET"],
}
Expand Down
Loading