MCPcopy
hub / github.com/fastapi/fastapi / SecurityScopes

Class SecurityScopes

fastapi/security/oauth2.py:653–693  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

651
652
653class SecurityScopes:
654 """
655 This is a special class that you can define in a parameter in a dependency to
656 obtain the OAuth2 scopes required by all the dependencies in the same chain.
657
658 This way, multiple dependencies can have different scopes, even when used in the
659 same *path operation*. And with this, you can access all the scopes required in
660 all those dependencies in a single place.
661
662 Read more about it in the
663 [FastAPI docs for OAuth2 scopes](https://fastapi.tiangolo.com/advanced/security/oauth2-scopes/).
664 """
665
666 def __init__(
667 self,
668 scopes: Annotated[
669 list[str] | None,
670 Doc(
671 """
672 This will be filled by FastAPI.
673 """
674 ),
675 ] = None,
676 ):
677 self.scopes: Annotated[
678 list[str],
679 Doc(
680 """
681 The list of all the scopes required by dependencies.
682 """
683 ),
684 ] = scopes or []
685 self.scope_str: Annotated[
686 str,
687 Doc(
688 """
689 All the scopes required by all the dependencies in a single string
690 separated by spaces, as defined in the OAuth2 specification.
691 """
692 ),
693 ] = " ".join(self.scopes)

Callers 1

solve_dependenciesFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…