本文整理汇总了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,
)
示例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