Home / Class/ SecurityScopes Class — fastapi Architecture

SecurityScopes Class — fastapi Architecture

Architecture documentation for the SecurityScopes class in oauth2.py from the fastapi codebase.

Entity Profile

Dependency Diagram

graph TD
  416e637a_6fc2_b0ac_63a4_25b01b3770b8["SecurityScopes"]
  efdd0530_d49f_83d3_f1d5_e8884b1b9602["oauth2.py"]
  416e637a_6fc2_b0ac_63a4_25b01b3770b8 -->|defined in| efdd0530_d49f_83d3_f1d5_e8884b1b9602
  09c5b92b_43dd_bfe6_dd93_f94e762da840["__init__()"]
  416e637a_6fc2_b0ac_63a4_25b01b3770b8 -->|method| 09c5b92b_43dd_bfe6_dd93_f94e762da840

Relationship Graph

Source Code

fastapi/security/oauth2.py lines 653–693

class SecurityScopes:
    """
    This is a special class that you can define in a parameter in a dependency to
    obtain the OAuth2 scopes required by all the dependencies in the same chain.

    This way, multiple dependencies can have different scopes, even when used in the
    same *path operation*. And with this, you can access all the scopes required in
    all those dependencies in a single place.

    Read more about it in the
    [FastAPI docs for OAuth2 scopes](https://fastapi.tiangolo.com/advanced/security/oauth2-scopes/).
    """

    def __init__(
        self,
        scopes: Annotated[
            Optional[list[str]],
            Doc(
                """
                This will be filled by FastAPI.
                """
            ),
        ] = None,
    ):
        self.scopes: Annotated[
            list[str],
            Doc(
                """
                The list of all the scopes required by dependencies.
                """
            ),
        ] = scopes or []
        self.scope_str: Annotated[
            str,
            Doc(
                """
                All the scopes required by all the dependencies in a single string
                separated by spaces, as defined in the OAuth2 specification.
                """
            ),
        ] = " ".join(self.scopes)

Domain

Frequently Asked Questions

What is the SecurityScopes class?
SecurityScopes is a class in the fastapi codebase, defined in fastapi/security/oauth2.py.
Where is SecurityScopes defined?
SecurityScopes is defined in fastapi/security/oauth2.py at line 653.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free