def ensure_valid_oauth(
key: str,
secret: str,
request: t.Any,
parser_cls: t.Type = _FlaskOAuthValidator
) -> None:
"""Make sure the given oauth key and secret is valid for the given request.
:param str key: The oauth key to be used for validating.
:param str secret: The oauth secret to be used for validating.
:param object request: The request that should be validated.
:param RequestValidatorMixin parser_cls: The class used to parse the given
``request`` it should subclass :py:class:`RequestValidatorMixin` and
should at least override the
:func:`RequestValidatorMixin.parse_request` method.
:returns: Nothing
"""
validator = parser_cls(key, secret)
if not validator.is_valid_request(request):
raise PermissionException(
'No valid oauth request could be found.',
'The given request is not a valid oauth request.',
APICodes.INVALID_OAUTH_REQUEST, 400
)
评论列表
文章目录