当前位置: 首页>>代码示例>>Python>>正文


Python security.OAuth2PasswordBearer方法代码示例

本文整理汇总了Python中fastapi.security.OAuth2PasswordBearer方法的典型用法代码示例。如果您正苦于以下问题:Python security.OAuth2PasswordBearer方法的具体用法?Python security.OAuth2PasswordBearer怎么用?Python security.OAuth2PasswordBearer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在fastapi.security的用法示例。


在下文中一共展示了security.OAuth2PasswordBearer方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __call__

# 需要导入模块: from fastapi import security [as 别名]
# 或者: from fastapi.security import OAuth2PasswordBearer [as 别名]
def __call__(self, request: Request):
        """
        Provides the functionality to act as a Dependency

        :param Request request: The incoming request, this is set automatically
            by FastAPI
        :return: The user object or None
        :raises: The not_authenticated_exception if set by the user
        """

        if self.not_authenticated_exception is None:
            self.oauth_scheme = OAuth2PasswordBearer(tokenUrl=self.tokenUrl)
        else:
            # we handle Exception raising
            self.oauth_scheme = OAuth2PasswordBearer(tokenUrl=self.tokenUrl, auto_error=False)

        token = await self.oauth_scheme(request)
        if token is not None:
            return await self.get_current_user(token)

        # No token is present in the request and no Exception has been raised yet
        raise self.not_authenticated_exception 
开发者ID:MushroomMaula,项目名称:fastapi_login,代码行数:24,代码来源:fastapi_login.py

示例2: __init__

# 需要导入模块: from fastapi import security [as 别名]
# 或者: from fastapi.security import OAuth2PasswordBearer [as 别名]
def __init__(self, name: str = "mock"):
        super().__init__(name, logout=True)
        self.scheme = OAuth2PasswordBearer("/login", auto_error=False) 
开发者ID:frankie567,项目名称:fastapi-users,代码行数:5,代码来源:conftest.py

示例3: __init__

# 需要导入模块: from fastapi import security [as 别名]
# 或者: from fastapi.security import OAuth2PasswordBearer [as 别名]
def __init__(
        self,
        secret: str,
        lifetime_seconds: int,
        tokenUrl: str = "/login",
        name: str = "jwt",
    ):
        super().__init__(name, logout=False)
        self.scheme = OAuth2PasswordBearer(tokenUrl, auto_error=False)
        self.secret = secret
        self.lifetime_seconds = lifetime_seconds 
开发者ID:frankie567,项目名称:fastapi-users,代码行数:13,代码来源:jwt.py


注:本文中的fastapi.security.OAuth2PasswordBearer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。