Tadeas Kosek commited on
Commit
57c92c0
·
1 Parent(s): be8d0ca

fixes vol4

Browse files
Files changed (2) hide show
  1. app.py +29 -0
  2. interfaces/api/dependencies.py +4 -3
app.py CHANGED
@@ -109,6 +109,35 @@ app = FastAPI(
109
  ]
110
  )
111
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
112
  # Let FastAPI handle OpenAPI generation automatically
113
  # The HTTPBearer scheme in dependencies.py will be automatically detected
114
 
 
109
  ]
110
  )
111
 
112
+ # Configure OpenAPI security scheme
113
+ def custom_openapi():
114
+ if app.openapi_schema:
115
+ return app.openapi_schema
116
+
117
+ from fastapi.openapi.utils import get_openapi
118
+
119
+ openapi_schema = get_openapi(
120
+ title=app.title,
121
+ version=app.version,
122
+ description=app.description,
123
+ routes=app.routes,
124
+ )
125
+
126
+ # Add Bearer token security scheme
127
+ openapi_schema["components"]["securitySchemes"] = {
128
+ "BearerAuth": {
129
+ "type": "http",
130
+ "scheme": "bearer",
131
+ "bearerFormat": "JWT",
132
+ "description": "JWT Bearer token authentication"
133
+ }
134
+ }
135
+
136
+ app.openapi_schema = openapi_schema
137
+ return app.openapi_schema
138
+
139
+ app.openapi = custom_openapi
140
+
141
  # Let FastAPI handle OpenAPI generation automatically
142
  # The HTTPBearer scheme in dependencies.py will be automatically detected
143
 
interfaces/api/dependencies.py CHANGED
@@ -11,6 +11,7 @@ from infrastructure.services.jwt_validation_service import JWTValidationService
11
 
12
  # Create HTTPBearer scheme that will be recognized by OpenAPI
13
  bearer_scheme = HTTPBearer(
 
14
  bearerFormat="JWT",
15
  description="JWT Bearer token authentication"
16
  )
@@ -62,11 +63,11 @@ async def validate_video_file(video: UploadFile) -> UploadFile:
62
 
63
  return video
64
 
65
- async def validate_bearer_token(
66
  credentials = Depends(bearer_scheme)
67
  ) -> str:
68
  """
69
- Extract and validate bearer token from Authorization header.
70
 
71
  Args:
72
  credentials: HTTPAuthorizationCredentials from HTTPBearer scheme
@@ -122,4 +123,4 @@ ValidatedVideo = Annotated[UploadFile, Depends(validate_video_file)]
122
  ExtractionParams = Annotated[ExtractionRequest, Depends(extraction_params)]
123
  Services = Annotated[ServiceContainer, Depends(get_services)]
124
  UseCases = Annotated[UseCaseContainer, Depends(get_use_cases)]
125
- BearerToken = Annotated[str, Depends(validate_bearer_token)]
 
11
 
12
  # Create HTTPBearer scheme that will be recognized by OpenAPI
13
  bearer_scheme = HTTPBearer(
14
+ scheme_name="BearerAuth",
15
  bearerFormat="JWT",
16
  description="JWT Bearer token authentication"
17
  )
 
63
 
64
  return video
65
 
66
+ async def get_validated_token(
67
  credentials = Depends(bearer_scheme)
68
  ) -> str:
69
  """
70
+ Extract and validate bearer token from HTTPBearer scheme.
71
 
72
  Args:
73
  credentials: HTTPAuthorizationCredentials from HTTPBearer scheme
 
123
  ExtractionParams = Annotated[ExtractionRequest, Depends(extraction_params)]
124
  Services = Annotated[ServiceContainer, Depends(get_services)]
125
  UseCases = Annotated[UseCaseContainer, Depends(get_use_cases)]
126
+ BearerToken = Annotated[str, Depends(get_validated_token)]