當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。