Skip to content

Can I exclude paths from fastapi_oauth2 #25

Answered by ArtyomVancyan
marcvs asked this question in Q&A
Discussion options

You must be logged in to vote

You have to create a wrapper middleware that handles your specific case. I suggest the following:

from fastapi import Request
from starlette.datastructures import URL
from starlette.middleware.base import BaseHTTPMiddleware
from starlette.middleware.base import RequestResponseEndpoint
from starlette.types import Receive
from starlette.types import Scope
from starlette.types import Send

class SSROAuth2Middleware(BaseHTTPMiddleware):
    def __init__(self, app, config, callback):
        super().__init__(app)
        self.oauth2_middleware = OAuth2Middleware(app, config, callback)

    async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None:
        if any(route.path == 

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@marcvs
Comment options

Answer selected by marcvs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants