Skip to content
This repository was archived by the owner on Jun 1, 2023. It is now read-only.

Commit 84efd7b

Browse files
committed
Refactored to allow more flexibility.
1 parent 7df38ee commit 84efd7b

1 file changed

Lines changed: 37 additions & 21 deletions

File tree

src/oidcrp/oauth2/__init__.py

Lines changed: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,41 @@ def set_client_id(self, client_id):
103103
self.client_id = client_id
104104
self.service_context.client_id = client_id
105105

106+
def get_response(self, service, url, method="GET", body=None, response_body_type="",
107+
headers=None, **kwargs):
108+
"""
109+
110+
:param url:
111+
:param method:
112+
:param body:
113+
:param response_body_type:
114+
:param headers:
115+
:param kwargs:
116+
:return:
117+
"""
118+
try:
119+
resp = self.http(url, method, data=body, headers=headers)
120+
except Exception as err:
121+
logger.error('Exception on request: {}'.format(err))
122+
raise
123+
124+
if 300 <= resp.status_code < 400:
125+
return {'http_response': resp}
126+
127+
if "keyjar" not in kwargs:
128+
kwargs["keyjar"] = service.service_context.keyjar
129+
if not response_body_type:
130+
response_body_type = service.response_body_type
131+
132+
if response_body_type == 'html':
133+
return resp.text
134+
135+
if body:
136+
kwargs['request_body'] = body
137+
138+
return self.parse_request_response(service, resp,
139+
response_body_type, **kwargs)
140+
106141
def service_request(self, service, url, method="GET", body=None,
107142
response_body_type="", headers=None, **kwargs):
108143
"""
@@ -124,28 +159,9 @@ def service_request(self, service, url, method="GET", body=None,
124159

125160
logger.debug(REQUEST_INFO.format(url, method, body, headers))
126161

127-
try:
128-
resp = self.http(url, method, data=body, headers=headers)
129-
except Exception as err:
130-
logger.error('Exception on request: {}'.format(err))
131-
raise
132-
133-
if "keyjar" not in kwargs:
134-
kwargs["keyjar"] = service.service_context.keyjar
135-
if not response_body_type:
136-
response_body_type = service.response_body_type
137-
138-
if 300 <= resp.status_code < 400:
139-
return {'http_response': resp}
140-
141-
if response_body_type == 'html':
142-
return resp.text
143-
144-
if body:
145-
kwargs['request_body'] = body
162+
response = self.get_response(service, url, method, body, response_body_type, headers,
163+
**kwargs)
146164

147-
response = self.parse_request_response(service, resp,
148-
response_body_type, **kwargs)
149165
if 'error' in response:
150166
pass
151167
else:

0 commit comments

Comments
 (0)