Skip to content

Commit 5e8884f

Browse files
committed
feat: x-api-key header schema login injection
1 parent cd97337 commit 5e8884f

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

.env.example.prod

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ EXPORT_METRICS=true
3333
# coma separated allowed origins
3434
ALLOWED_ORIGINS=csv,includehttp
3535

36+
# if set to true login component with x-api-key header will be injected
37+
# into swagger
38+
# INJECT_SWAGGER_X_API_KEY_HEADER_AUTH=true
39+
3640
# project related
3741

3842
# CONFIG_MODULE: one of: flare, songbird, coston2, coston

project/settings/common.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,18 @@
150150
"COMPONENT_SPLIT_REQUEST": True,
151151
}
152152

153+
if os.environ.get("INJECT_SWAGGER_X_API_KEY_HEADER_AUTH", "false") == "true":
154+
SPECTACULAR_SETTINGS["APPEND_COMPONENTS"] = {
155+
"securitySchemes": {
156+
"ApiKeyAuth": {
157+
"type": "apiKey",
158+
"in": "header",
159+
"name": "x-api-key",
160+
}
161+
}
162+
}
163+
SPECTACULAR_SETTINGS["SECURITY"] = [{"ApiKeyAuth": []}]
164+
153165
# django-types
154166
from django.db.models.query import QuerySet
155167

0 commit comments

Comments
 (0)