import os
import pydantic
import socket
+import starlette
import typing
from . import apiv1
tags=["Authentication"],
)
+class HTTPBearer(fastapi.security.HTTPBearer):
+ """
+ This is a custom implementation of HTTPBearer which also supports WebSockets
+ """
+ # This works because fastapi.Request and fastapi.WebSocket both inherit from
+ # starlette's HTTPConnection.
+ async def __call__(self, request: starlette.requests.HTTPConnection) \
+ -> typing.Optional[fastapi.security.HTTPAuthorizationCredentials]:
+ return await super().__call__(request)
+
# Class to extract the Bearer token from the request headers
-security = fastapi.security.HTTPBearer()
+security = HTTPBearer()
async def get_current_principal(
credentials: fastapi.security.HTTPAuthorizationCredentials = fastapi.Depends(security)