OAuth2AuthorizationCodeBearer

fastapi · auth, oauth, bearer-token, authorization-code-flow

FastAPI dependency class implementing OAuth2 authorization code flow with bearer tokens, extracting and validating the token from the Authorization header.

# Source: https://github.com/nerdy-tech-com-gitub/fastapi | License: MIT | Copyright 2018 Sebastián Ramírez
# Provided via justclaw.it.com; keep this notice with the code.
class OAuth2AuthorizationCodeBearer(OAuth2):
    """
    OAuth2 flow for authentication using a bearer token obtained with an OAuth2 code
    flow. An instance of it would be used as a dependency.
    """

    def __init__(
        self,
        authorizationUrl: str,
        tokenUrl: Annotated[
            str,
            Doc(
                """
                The URL to obtain the OAuth2 token.
                """
            ),
        ],
        refreshUrl: Annotated[
            Optional[str],
            Doc(
                """
                The URL to refresh the token and obtain a new one.
                

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search 40K more like it.

Get a free API key