當前位置: 首頁>>代碼示例>>Python>>正文


Python errors.OAuth2Error方法代碼示例

本文整理匯總了Python中oauthlib.oauth2.rfc6749.errors.OAuth2Error方法的典型用法代碼示例。如果您正苦於以下問題:Python errors.OAuth2Error方法的具體用法?Python errors.OAuth2Error怎麽用?Python errors.OAuth2Error使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在oauthlib.oauth2.rfc6749.errors的用法示例。


在下文中一共展示了errors.OAuth2Error方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: generate_token

# 需要導入模塊: from oauthlib.oauth2.rfc6749 import errors [as 別名]
# 或者: from oauthlib.oauth2.rfc6749.errors import OAuth2Error [as 別名]
def generate_token(self, user, password):
        """Takes user and password credentials and generates a new token

        :param user: user
        :param password: password
        :return:
            - dictionary containing token data
        :raises:
            - TokenCreateError: If there was an error generating the new token
        """

        logger.debug("(TOKEN_CREATE) :: User: %s" % user)

        session = OAuth2Session(
            client=LegacyApplicationClient(client_id=self.client_id)
        )

        try:
            return dict(
                session.fetch_token(
                    token_url=self.token_url,
                    username=user,
                    password=password,
                    client_id=self.client_id,
                    client_secret=self.client_secret,
                )
            )
        except OAuth2Error as exception:
            raise TokenCreateError(
                "Error creating user token",
                exception.description,
                exception.status_code,
            ) 
開發者ID:rbw,項目名稱:pysnow,代碼行數:35,代碼來源:oauth_client.py

示例2: acquire_refresh_token_or_str_error

# 需要導入模塊: from oauthlib.oauth2.rfc6749 import errors [as 別名]
# 或者: from oauthlib.oauth2.rfc6749.errors import OAuth2Error [as 別名]
def acquire_refresh_token_or_str_error(
        self, GET: Dict[str, str], expect_state: str
    ) -> Union[OfflineToken, str]:
        if "code" not in GET:
            return 'Expected auth request to include a "code" parameter.'

        if "state" not in GET:
            return 'Expected auth request to include a "state" parameter.'

        session = self._session()
        try:
            token = session.fetch_token(
                client_secret=self.client_secret,
                token_url=self.token_url,
                code=GET["code"],
                include_client_id=True,  # for Intercom
                timeout=30,
            )
        except OAuth2Error as err:
            return str(err)

        # Google secrets are dicts with {'refresh_token':..., 'id_token': ...}
        # Intercom secrets are dicts with {'access_token': ..., 'token': ...}
        # (and access_token == token).

        return token 
開發者ID:CJWorkbench,項目名稱:cjworkbench,代碼行數:28,代碼來源:oauth.py


注:本文中的oauthlib.oauth2.rfc6749.errors.OAuth2Error方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。