本文整理汇总了Python中oic.oauth2.message.ErrorResponse.verify方法的典型用法代码示例。如果您正苦于以下问题:Python ErrorResponse.verify方法的具体用法?Python ErrorResponse.verify怎么用?Python ErrorResponse.verify使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类oic.oauth2.message.ErrorResponse
的用法示例。
在下文中一共展示了ErrorResponse.verify方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _func
# 需要导入模块: from oic.oauth2.message import ErrorResponse [as 别名]
# 或者: from oic.oauth2.message.ErrorResponse import verify [as 别名]
def _func(self, conv):
res = {}
try:
_response = last_http_response(conv)
except NoSuchEvent:
return res
try:
_content = last_raw_response(conv)
except NoSuchEvent:
return res
if _response.status_code == 400:
err = ErrorResponse().deserialize(_content, "json")
err.verify()
res["content"] = err.to_json()
conv.events.store(EV_PROTOCOL_RESPONSE, err)
elif _response.status_code in [301, 302, 303]:
pass
elif _response.status_code in SUCCESSFUL:
err = ErrorResponse().deserialize(_content, "json")
err.verify()
res["content"] = err.to_json()
conv.events.store(EV_PROTOCOL_RESPONSE, err)
else:
self._message = "Expected a 400 error message"
self._status = CRITICAL
return res
示例2: _func
# 需要导入模块: from oic.oauth2.message import ErrorResponse [as 别名]
# 或者: from oic.oauth2.message.ErrorResponse import verify [as 别名]
def _func(self, environ):
_response = environ["response"]
_content = environ["content"]
res = {}
if _response.status_code >= 400 :
self._status = self.status
self._message = self.msg
if "application/json" in _response.headers["content-type"]:
try:
err = ErrorResponse().deserialize(_content, "json")
self._message = err.to_json()
except Exception:
res["content"] = _content
else:
res["content"] = _content
res["url"] = environ["url"]
res["http_status"] = _response.status_code
else:
# might still be an error message
try:
err = ErrorResponse().deserialize(_content, "json")
err.verify()
self._message = err.to_json()
self._status = self.status
except Exception:
pass
res["url"] = environ["url"]
return res
示例3: _func
# 需要导入模块: from oic.oauth2.message import ErrorResponse [as 别名]
# 或者: from oic.oauth2.message.ErrorResponse import verify [as 别名]
def _func(self, conv):
_response = conv.last_response
_content = conv.last_content
res = {}
if _response.status_code >= 400:
self._status = self.status
self._message = self.msg
if CONT_JSON in _response.headers["content-type"]:
try:
err = ErrorResponse().deserialize(_content, "json")
self._message = err.to_json()
except Exception:
res["content"] = _content
else:
res["content"] = _content
res["url"] = conv.position
res["http_status"] = _response.status_code
else:
# might still be an error message
try:
err = ErrorResponse().deserialize(_content, "json")
err.verify()
self._message = err.to_json()
self._status = self.status
except Exception:
pass
res["url"] = conv.position
return res
示例4: _func
# 需要导入模块: from oic.oauth2.message import ErrorResponse [as 别名]
# 或者: from oic.oauth2.message.ErrorResponse import verify [as 别名]
def _func(self, conv):
_response = conv.events.last_item(EV_HTTP_RESPONSE)
res = {}
try:
_loc = _response.headers["location"]
if "?" in _loc:
query = _loc.split("?")[1]
elif "#" in _loc:
query = _loc.split("#")[1]
else: # ???
self._message = "Expected a redirect"
self._status = CRITICAL
return res
env_id = conv.events.store(EV_RESPONSE, query)
except (KeyError, AttributeError):
self._message = "Expected a redirect"
self._status = CRITICAL
return res
if _response.status_code == 302:
err = ErrorResponse().deserialize(query, "urlencoded")
try:
err.verify()
res["content"] = err.to_json()
conv.events.store(EV_PROTOCOL_RESPONSE, err, env_id)
except MissingRequiredAttribute:
self._message = "Expected an error message"
self._status = CRITICAL
else:
self._message = "Expected an error message"
self._status = CRITICAL
return res
示例5: _func
# 需要导入模块: from oic.oauth2.message import ErrorResponse [as 别名]
# 或者: from oic.oauth2.message.ErrorResponse import verify [as 别名]
def _func(self, conv):
res = {}
response = conv.last_response
if response.status_code == 302:
_loc = response.headers["location"]
if "?" in _loc:
_query = _loc.split("?")[1]
elif "#" in _loc:
_query = _loc.split("#")[1]
else:
self._message = "Faulty error message"
self._status = ERROR
return
try:
err = ErrorResponse().deserialize(_query, "urlencoded")
err.verify()
# res["temp"] = err
res["message"] = err.to_dict()
except Exception:
self._message = "Faulty error message"
self._status = ERROR
else:
self._message = "Expected a redirect with an error message"
self._status = ERROR
return res
示例6: _func
# 需要导入模块: from oic.oauth2.message import ErrorResponse [as 别名]
# 或者: from oic.oauth2.message.ErrorResponse import verify [as 别名]
def _func(self, conv):
_response = conv.last_response
_content = conv.last_content
_client = conv.client
res = {}
if _response.status_code == 400:
err = ErrorResponse().deserialize(_content, "json")
err.verify()
if err["error"] in ["consent_required", "interaction_required"]:
# This is OK
res["content"] = err.to_json()
conv.protocol_response.append((err, _content))
else:
self._message = "Not an error I expected"
self._status = CRITICAL
elif _response.status_code in [301, 302]:
_loc = _response.headers["location"]
callback = False
for url in _client.redirect_uris:
if _loc.startswith(url):
callback = True
break
if not callback:
self._message = "Not valid to not redirect back to RP"
self._status = ERROR
return res
if "?" in _loc:
_query = _loc.split("?")[1]
elif "#" in _loc:
_query = _loc.split("#")[1]
else: # ???
self._message = "Expected info in the redirect"
self._status = CRITICAL
return res
try:
err = ErrorResponse().deserialize(_query, "urlencoded")
err.verify()
if err["error"] in ["consent_required", "interaction_required",
"login_required"]:
# This is OK
res["content"] = err.to_json()
conv.protocol_response.append((err, _query))
else:
self._message = "Not an error I expected '%s'" % err[
"error"]
self._status = CRITICAL
except:
resp = AuthorizationResponse().deserialize(_query, "urlencoded")
resp.verify()
res["content"] = resp.to_json()
conv.protocol_response.append((resp, _query))
else: # should not get anything else
self._message = "Not an response I expected"
self._status = CRITICAL
return res
示例7: CheckErrorResponse
# 需要导入模块: from oic.oauth2.message import ErrorResponse [as 别名]
# 或者: from oic.oauth2.message.ErrorResponse import verify [as 别名]
class CheckErrorResponse(ExpectedError):
"""
Checks that the HTTP response status is outside the 200 or 300 range
or that an JSON encoded error message has been received
"""
cid = "check-error-response"
msg = "OP error"
def _func(self, conv):
res = {}
# did I get one, should only be one
try:
instance, _ = get_protocol_response(conv, ErrorResponse)[0]
except ValueError:
pass
else:
return res
_response = conv.last_response
_content = conv.last_content
if _response.status_code >= 400:
content_type = _response.headers["content-type"]
if content_type is None:
res["content"] = _content
elif CONT_JSON in content_type:
try:
self.err = ErrorResponse().deserialize(_content, "json")
self.err.verify()
res["content"] = self.err.to_json()
except Exception:
res["content"] = _content
else:
res["content"] = _content
elif _response.status_code in [300, 301, 302, 303]:
pass
else:
# might still be an error message
try:
self.err = ErrorResponse().deserialize(_content, "json")
self.err.verify()
res["content"] = self.err.to_json()
except Exception:
self._message = "Expected an error message"
self._status = CRITICAL
res["url"] = conv.position
return res
示例8: CheckErrorResponse
# 需要导入模块: from oic.oauth2.message import ErrorResponse [as 别名]
# 或者: from oic.oauth2.message.ErrorResponse import verify [as 别名]
class CheckErrorResponse(ExpectedError):
"""
Checks that the HTTP response status is outside the 200 or 300 range
or that an JSON encoded error message has been received
"""
cid = "check-error-response"
msg = "OP error"
def _func(self, conv):
res = {}
# did I get one, should only be one
try:
_ = get_protocol_response(conv, ErrorResponse)[0]
except ValueError:
pass
else:
return res
try:
_response = last_http_response(conv)
except NoSuchEvent:
return {}
if _response.status_code >= 400:
content_type = _response.headers["content-type"]
_content = _response.text
if content_type is None:
res["content"] = _content
elif CONT_JSON in content_type:
try:
self.err = ErrorResponse().deserialize(_content, "json")
self.err.verify()
res["content"] = self.err.to_json()
except Exception:
res["content"] = _content
else:
res["content"] = _content
elif _response.status_code in [300, 301, 302, 303]:
pass
else:
# Should never get here
self._message = 'Not an error message ??'
self._status = WARNING
return res
示例9: CheckErrorResponse
# 需要导入模块: from oic.oauth2.message import ErrorResponse [as 别名]
# 或者: from oic.oauth2.message.ErrorResponse import verify [as 别名]
class CheckErrorResponse(ExpectedError):
"""
Checks that the HTTP response status is outside the 200 or 300 range
or that an JSON encoded error message has been received
"""
cid = "check-error-response"
msg = "OP error"
def _func(self, conv):
_response = conv.last_response
_content = conv.last_content
res = {}
if _response.status_code >= 400:
content_type = _response.headers["content-type"]
if content_type is None:
res["content"] = _content
elif CONT_JSON in content_type:
try:
self.err = ErrorResponse().deserialize(_content, "json")
self.err.verify()
res["content"] = self.err.to_json()
#res["temp"] = err
except Exception:
res["content"] = _content
else:
res["content"] = _content
else:
# might still be an error message
try:
self.err = ErrorResponse().deserialize(_content, "json")
self.err.verify()
res["content"] = self.err.to_json()
except Exception:
self._message = "Expected error message"
self._status = CRITICAL
res["url"] = conv.position
return res