Skip to content

Commit

Permalink
backend as a parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
maparent committed Mar 6, 2024
1 parent 800028a commit 1554f2a
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/fastapi_oauth2/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ def __init__(
app: ASGIApp,
config: Union[OAuth2Config, dict],
callback: Callable[[Auth, User], Union[Awaitable[None], None]] = None,
backend: Optional[OAuth2Backend]=None,
**kwargs, # AuthenticationMiddleware kwargs
) -> None:
"""Initiates the middleware with the given configuration.
Expand All @@ -141,7 +142,8 @@ def __init__(
elif not isinstance(config, OAuth2Config):
raise TypeError("config is not a valid type")
self.default_application_middleware = app
self.auth_middleware = AuthenticationMiddleware(app, backend=OAuth2Backend(config, callback), **kwargs)
backend = backend or OAuth2Backend(config, callback)
self.auth_middleware = AuthenticationMiddleware(app, backend=backend, **kwargs)

async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None:
if scope["type"] == "http":
Expand Down

0 comments on commit 1554f2a

Please sign in to comment.