Skip to content

Commit 06ac646

Browse files
committed
Add base_path as server in openapi spec
1 parent ad4b2eb commit 06ac646

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

src/stac_auth_proxy/app.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ async def lifespan(app: FastAPI):
106106
public_endpoints=settings.public_endpoints,
107107
private_endpoints=settings.private_endpoints,
108108
default_public=settings.default_public,
109+
root_path=settings.root_path,
109110
)
110111

111112
if settings.items_filter:

src/stac_auth_proxy/middleware/UpdateOpenApiMiddleware.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class OpenApiMiddleware(JsonResponseMiddleware):
2323
private_endpoints: EndpointMethods
2424
public_endpoints: EndpointMethods
2525
default_public: bool
26+
root_path: str = ""
2627
oidc_auth_scheme_name: str = "oidcAuth"
2728

2829
json_content_type_expr: str = r"application/(vnd\.oai\.openapi\+json?|json)"
@@ -45,12 +46,19 @@ def should_transform_response(self, request: Request, scope: Scope) -> bool:
4546

4647
def transform_json(self, data: dict[str, Any], request: Request) -> dict[str, Any]:
4748
"""Augment the OpenAPI spec with auth information."""
49+
# Add servers field with base path if root_path is set
50+
if self.root_path:
51+
data["servers"] = [{"url": self.root_path}]
52+
53+
# Add security scheme
4854
components = data.setdefault("components", {})
4955
securitySchemes = components.setdefault("securitySchemes", {})
5056
securitySchemes[self.oidc_auth_scheme_name] = {
5157
"type": "openIdConnect",
5258
"openIdConnectUrl": self.oidc_config_url,
5359
}
60+
61+
# Add security to private endpoints
5462
for path, method_config in data["paths"].items():
5563
for method, config in method_config.items():
5664
match = find_match(

0 commit comments

Comments
 (0)