本文整理汇总了Python中oic.oauth2.message.ErrorResponse.to_json方法的典型用法代码示例。如果您正苦于以下问题:Python ErrorResponse.to_json方法的具体用法?Python ErrorResponse.to_json怎么用?Python ErrorResponse.to_json使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类oic.oauth2.message.ErrorResponse
的用法示例。
在下文中一共展示了ErrorResponse.to_json方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _func
# 需要导入模块: from oic.oauth2.message import ErrorResponse [as 别名]
# 或者: from oic.oauth2.message.ErrorResponse import to_json [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 to_json [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 to_json [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 to_json [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
示例5: CheckErrorResponse
# 需要导入模块: from oic.oauth2.message import ErrorResponse [as 别名]
# 或者: from oic.oauth2.message.ErrorResponse import to_json [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
示例6: _func
# 需要导入模块: from oic.oauth2.message import ErrorResponse [as 别名]
# 或者: from oic.oauth2.message.ErrorResponse import to_json [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
示例7: _func
# 需要导入模块: from oic.oauth2.message import ErrorResponse [as 别名]
# 或者: from oic.oauth2.message.ErrorResponse import to_json [as 别名]
def _func(self, conv):
_response = conv.last_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
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.protocol_response.append((err, query))
except MissingRequiredAttribute:
self._message = "Expected an error message"
self._status = CRITICAL
else:
self._message = "Expected an error message"
self._status = CRITICAL
return res
示例8: handle_registration_info
# 需要导入模块: from oic.oauth2.message import ErrorResponse [as 别名]
# 或者: from oic.oauth2.message.ErrorResponse import to_json [as 别名]
def handle_registration_info(self, response):
if response.status_code == 200:
resp = RegistrationResponse().deserialize(response.text, "json")
self.store_response(resp, response.text)
self.store_registration_info(resp)
else:
err = ErrorResponse().deserialize(response.text, "json")
raise PyoidcError("Registration failed: %s" % err.to_json())
return resp
示例9: CheckErrorResponse
# 需要导入模块: from oic.oauth2.message import ErrorResponse [as 别名]
# 或者: from oic.oauth2.message.ErrorResponse import to_json [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
示例10: client_info
# 需要导入模块: from oic.oauth2.message import ErrorResponse [as 别名]
# 或者: from oic.oauth2.message.ErrorResponse import to_json [as 别名]
def client_info(self, client_id):
_cinfo = self.cdb[client_id].copy()
if not valid_client_info(_cinfo):
err = ErrorResponse(
error="invalid_client",
error_description="Invalid client secret")
return BadRequest(err.to_json(), content="application/json")
try:
_cinfo["redirect_uris"] = self._tuples_to_uris(
_cinfo["redirect_uris"])
except KeyError:
pass
msg = ClientInfoResponse(**_cinfo)
return Response(msg.to_json(), content="application/json")
示例11: CheckErrorResponse
# 需要导入模块: from oic.oauth2.message import ErrorResponse [as 别名]
# 或者: from oic.oauth2.message.ErrorResponse import to_json [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
示例12: test_parse_access_token_response
# 需要导入模块: from oic.oauth2.message import ErrorResponse [as 别名]
# 或者: from oic.oauth2.message.ErrorResponse import to_json [as 别名]
def test_parse_access_token_response():
client = Client()
at = AccessTokenResponse(access_token="SlAV32hkKG", token_type="Bearer",
refresh_token="8xLOxBtZp8", expires_in=3600)
atj = at.to_json()
ATR = AccessTokenResponse
atr = client.parse_response(ATR, info=atj)
assert _eq(atr.keys(), ['access_token', 'token_type', 'expires_in',
'refresh_token'])
uec = at.to_urlencoded()
raises(ValueError, 'client.parse_response(ATR, info=uec)')
uatr = client.parse_response(ATR, info=uec, sformat="urlencoded")
assert _eq(uatr.keys(), ['access_token', 'token_type', 'expires_in',
'refresh_token'])
huec = "%s?%s" % ("https://example.com/token", uec)
uatr = client.parse_response(ATR, info=huec, sformat="urlencoded")
assert _eq(uatr.keys(), ['access_token', 'token_type', 'expires_in',
'refresh_token'])
err = ErrorResponse(error="invalid_request",
error_description="Something was missing",
error_uri="http://example.com/error_message.html")
jerr = err.to_json()
uerr = err.to_urlencoded()
_ = client.parse_response(ATR, info=jerr)
_ = client.parse_response(ATR, info=uerr, sformat="urlencoded")
raises(Exception,
'client.parse_response(ATR, info=jerr, sformat="urlencoded")')
raises(Exception, "client.parse_response(ATR, info=uerr)")
raises(Exception,
'client.parse_response(ATR, info=jerr, sformat="focus")')
示例13: test_parse_error_resp
# 需要导入模块: from oic.oauth2.message import ErrorResponse [as 别名]
# 或者: from oic.oauth2.message.ErrorResponse import to_json [as 别名]
def test_parse_error_resp(self):
err = ErrorResponse(error="invalid_request",
error_description="Something was missing",
error_uri="http://example.com/error_message.html")
jerr = err.to_json()
uerr = err.to_urlencoded()
_ = self.client.parse_response(AccessTokenResponse, info=jerr)
_ = self.client.parse_response(AccessTokenResponse, info=uerr,
sformat="urlencoded")
with pytest.raises(ResponseError):
self.client.parse_response(AccessTokenResponse, info=jerr, sformat="urlencoded")
with pytest.raises(ValueError):
self.client.parse_response(AccessTokenResponse, info=uerr)
with pytest.raises(FormatError):
self.client.parse_response(AccessTokenResponse, info=jerr, sformat="focus")
示例14: _error
# 需要导入模块: from oic.oauth2.message import ErrorResponse [as 别名]
# 或者: from oic.oauth2.message.ErrorResponse import to_json [as 别名]
def _error(error, descr=None):
response = ErrorResponse(error=error, error_description=descr)
return Response(response.to_json(), content="application/json",
status="400 Bad Request")
示例15: _error
# 需要导入模块: from oic.oauth2.message import ErrorResponse [as 别名]
# 或者: from oic.oauth2.message.ErrorResponse import to_json [as 别名]
def _error(self, environ, start_response, error, descr=None):
response = ErrorResponse(error=error, error_description=descr)
resp = Response(response.to_json(), content="application/json",
status="400 Bad Request")
return resp(environ, start_response)