Skip to content

Commit 5058945

Browse files
committed
Support customizing auth_scheme
1 parent 3ab2d66 commit 5058945

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

src/stac_auth_proxy/app.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ async def lifespan(app: FastAPI):
111111
private_endpoints=settings.private_endpoints,
112112
default_public=settings.default_public,
113113
root_path=settings.root_path,
114+
auth_scheme_name=settings.openapi_auth_scheme_name,
115+
auth_scheme_override=settings.openapi_auth_scheme_override,
114116
)
115117

116118
if settings.items_filter:

src/stac_auth_proxy/config.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,17 @@ class Settings(BaseSettings):
3939
oidc_discovery_internal_url: HttpUrl
4040

4141
root_path: str = ""
42+
healthz_prefix: str = Field(pattern=_PREFIX_PATTERN, default="/healthz")
4243
wait_for_upstream: bool = True
4344
check_conformance: bool = True
4445
enable_compression: bool = True
45-
enable_authentication_extension: bool = True
46-
healthz_prefix: str = Field(pattern=_PREFIX_PATTERN, default="/healthz")
46+
4747
openapi_spec_endpoint: Optional[str] = Field(pattern=_PREFIX_PATTERN, default=None)
48+
openapi_auth_scheme_name: str = "oidcAuth"
49+
openapi_auth_scheme_override: Optional[dict] = None
4850

4951
# Auth
52+
enable_authentication_extension: bool = True
5053
default_public: bool = False
5154
public_endpoints: EndpointMethodsNoScope = {
5255
r"^/api.html$": ["GET"],

src/stac_auth_proxy/middleware/UpdateOpenApiMiddleware.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import re
44
from dataclasses import dataclass
5-
from typing import Any
5+
from typing import Any, Optional
66

77
from starlette.datastructures import Headers
88
from starlette.requests import Request
@@ -24,7 +24,8 @@ class OpenApiMiddleware(JsonResponseMiddleware):
2424
public_endpoints: EndpointMethods
2525
default_public: bool
2626
root_path: str = ""
27-
oidc_auth_scheme_name: str = "oidcAuth"
27+
auth_scheme_name: str = "oidcAuth"
28+
auth_scheme_override: Optional[dict] = None
2829

2930
json_content_type_expr: str = r"application/(vnd\.oai\.openapi\+json?|json)"
3031

@@ -53,7 +54,7 @@ def transform_json(self, data: dict[str, Any], request: Request) -> dict[str, An
5354
# Add security scheme
5455
components = data.setdefault("components", {})
5556
securitySchemes = components.setdefault("securitySchemes", {})
56-
securitySchemes[self.oidc_auth_scheme_name] = {
57+
securitySchemes[self.auth_scheme_name] = self.auth_scheme_override or {
5758
"type": "openIdConnect",
5859
"openIdConnectUrl": self.oidc_config_url,
5960
}
@@ -70,6 +71,6 @@ def transform_json(self, data: dict[str, Any], request: Request) -> dict[str, An
7071
)
7172
if match.is_private:
7273
config.setdefault("security", []).append(
73-
{self.oidc_auth_scheme_name: match.required_scopes}
74+
{self.auth_scheme_name: match.required_scopes}
7475
)
7576
return data

0 commit comments

Comments
 (0)