Visitar URL original
Merge branch 'master' into feature/3.4.0-maintainer-agent · oauthlib/oauthlib@9bf9b97 · GitHub
Skip to content

Commit 9bf9b97

Browse files
authored
Merge branch 'master' into feature/3.4.0-maintainer-agent
2 parents 1ba7429 + c21b611 commit 9bf9b97

7 files changed

Lines changed: 23 additions & 57 deletions

File tree

‎CHANGELOG.rst‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ Changelog
33

44
3.4.0 (unreleased):
55
------------------
6+
OAuth2.0 Provider:
7+
* **Breaking**: Removed JSONP support from token revocation endpoint. JSONP has been superseded by CORS for cross-origin requests. The ``enable_jsonp`` parameter has been removed from ``RevocationEndpoint`` and the ``callback`` parameter has been removed from ``prepare_token_revocation_request``.
8+
69
Misc:
710
* #930: Add devcontainer, Add Python3.14, Python3.14t.
811
* Add OAuthLib Maintainer agent for automated issue/PR triage and release management.

‎oauthlib/oauth2/rfc6749/clients/base.py‎

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ def prepare_refresh_token_request(self, token_url, refresh_token=None,
320320
return token_url, FORM_ENC_HEADERS, body
321321

322322
def prepare_token_revocation_request(self, revocation_url, token,
323-
token_type_hint="access_token", body='', callback=None, **kwargs):
323+
token_type_hint="access_token", body='', **kwargs):
324324
"""Prepare a token revocation request.
325325
326326
:param revocation_url: Provider token revocation endpoint URL.
@@ -329,14 +329,9 @@ def prepare_token_revocation_request(self, revocation_url, token,
329329
``"refresh_token"``. This is optional and if you wish to not pass it you
330330
must provide ``token_type_hint=None``.
331331
:param body:
332-
:param callback: A jsonp callback such as ``package.callback`` to be invoked
333-
upon receiving the response. Not that it should not include a () suffix.
334332
:param kwargs: Additional parameters to included in the request.
335333
:returns: The prepared request tuple with (url, headers, body).
336334
337-
Note that JSONP request may use GET requests as the parameters will
338-
be added to the request URL query as opposed to the request body.
339-
340335
An example of a revocation request
341336
342337
.. code-block:: http
@@ -348,30 +343,18 @@ def prepare_token_revocation_request(self, revocation_url, token,
348343
349344
token=45ghiukldjahdnhzdauz&token_type_hint=refresh_token
350345
351-
An example of a jsonp revocation request
352-
353-
.. code-block:: http
354-
355-
GET /revoke?token=agabcdefddddafdd&callback=package.myCallback HTTP/1.1
356-
Host: server.example.com
357-
Content-Type: application/x-www-form-urlencoded
358-
Authorization: Basic czZCaGRSa3F0MzpnWDFmQmF0M2JW
359-
360-
and an error response
361-
362-
.. code-block:: javascript
363-
364-
package.myCallback({"error":"unsupported_token_type"});
365-
366346
Note that these requests usually require client credentials, client_id in
367347
the case for public clients and provider specific authentication
368348
credentials for confidential clients.
369349
"""
370350
if not is_secure_transport(revocation_url):
371351
raise InsecureTransportError()
372352

353+
if 'callback' in kwargs:
354+
raise TypeError("prepare_token_revocation_request() got an unexpected keyword argument 'callback'")
355+
373356
return prepare_token_revocation_request(revocation_url, token,
374-
token_type_hint=token_type_hint, body=body, callback=callback,
357+
token_type_hint=token_type_hint, body=body,
375358
**kwargs)
376359

377360
def parse_request_body_response(self, body, scope=None, **kwargs):

‎oauthlib/oauth2/rfc6749/endpoints/revocation.py‎

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,11 @@ class RevocationEndpoint(BaseEndpoint):
2727
valid_token_types = ('access_token', 'refresh_token')
2828
valid_request_methods = ('POST',)
2929

30-
def __init__(self, request_validator, supported_token_types=None,
31-
enable_jsonp=False):
30+
def __init__(self, request_validator, supported_token_types=None):
3231
BaseEndpoint.__init__(self)
3332
self.request_validator = request_validator
3433
self.supported_token_types = (
3534
supported_token_types or self.valid_token_types)
36-
self.enable_jsonp = enable_jsonp
3735

3836
@catch_errors_and_unavailability
3937
def create_revocation_response(self, uri, http_method='POST', body=None,
@@ -69,18 +67,13 @@ def create_revocation_response(self, uri, http_method='POST', body=None,
6967
except OAuth2Error as e:
7068
log.debug('Client error during validation of %r. %r.', request, e)
7169
response_body = e.json
72-
if self.enable_jsonp and request.callback:
73-
response_body = '{}({});'.format(request.callback, response_body)
7470
resp_headers.update(e.headers)
7571
return resp_headers, response_body, e.status_code
7672

7773
self.request_validator.revoke_token(request.token,
7874
request.token_type_hint, request)
7975

80-
response_body = ''
81-
if self.enable_jsonp and request.callback:
82-
response_body = request.callback + '();'
83-
return {}, response_body, 200
76+
return {}, '', 200
8477

8578
def validate_revocation_request(self, request):
8679
"""Ensure the request is valid.

‎oauthlib/oauth2/rfc6749/parameters.py‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ def prepare_token_request(grant_type, body='', include_client_id=True, code_veri
172172

173173

174174
def prepare_token_revocation_request(url, token, token_type_hint="access_token",
175-
callback=None, body='', **kwargs):
175+
body='', **kwargs):
176176
"""Prepare a token revocation request.
177177
178178
The client constructs the request by including the following parameters
@@ -216,17 +216,16 @@ def prepare_token_revocation_request(url, token, token_type_hint="access_token",
216216
if token_type_hint:
217217
params.append(('token_type_hint', token_type_hint))
218218

219+
if 'callback' in kwargs:
220+
raise TypeError("prepare_token_revocation_request() got an unexpected keyword argument 'callback'")
221+
219222
for k in kwargs:
220223
if kwargs[k]:
221224
params.append((str(k), kwargs[k]))
222225

223226
headers = {'Content-Type': 'application/x-www-form-urlencoded'}
224227

225-
if callback:
226-
params.append(('callback', callback))
227-
return add_params_to_uri(url, params), headers, body
228-
else:
229-
return url, headers, add_params_to_qs(body, params)
228+
return url, headers, add_params_to_qs(body, params)
230229

231230

232231
def parse_authorization_code_response(uri, state=None):

‎tests/oauth2/rfc6749/clients/test_base.py‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -237,13 +237,6 @@ def test_revocation_request(self):
237237
self.assertEqual(h, {'Content-Type': 'application/x-www-form-urlencoded'})
238238
self.assertEqual(b, 'token=%s&token_type_hint=refresh_token' % token)
239239

240-
# JSONP
241-
u, h, b = client.prepare_token_revocation_request(
242-
url, token, callback='hello.world')
243-
self.assertURLEqual(u, url + '?callback=hello.world&token=%s&token_type_hint=access_token' % token)
244-
self.assertEqual(h, {'Content-Type': 'application/x-www-form-urlencoded'})
245-
self.assertEqual(b, '')
246-
247240
def test_prepare_authorization_request(self):
248241
redirect_url = 'https://example.com/callback/'
249242
scopes = 'read'

‎tests/oauth2/rfc6749/endpoints/test_revocation_endpoint.py‎

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -88,19 +88,6 @@ def test_revoke_token_public_client_authentication_failed(self):
8888
self.assertEqual(loads(b)['error'], 'invalid_client')
8989
self.assertEqual(s, 401)
9090

91-
def test_revoke_with_callback(self):
92-
endpoint = RevocationEndpoint(self.validator, enable_jsonp=True)
93-
callback = 'package.hello_world'
94-
for token_type in ('access_token', 'refresh_token', 'invalid'):
95-
body = urlencode([('token', 'foo'),
96-
('token_type_hint', token_type),
97-
('callback', callback)])
98-
h, b, s = endpoint.create_revocation_response(self.uri,
99-
headers=self.headers, body=body)
100-
self.assertEqual(h, {})
101-
self.assertEqual(b, callback + '();')
102-
self.assertEqual(s, 200)
103-
10491
def test_revoke_unsupported_token(self):
10592
endpoint = RevocationEndpoint(self.validator,
10693
supported_token_types=['access_token'])

‎tests/oauth2/rfc6749/test_parameters.py‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,14 @@ def test_prepare_token_request(self):
208208
self.assertFormBodyEqual(prepare_token_request(**self.cred_grant), self.cred_body)
209209
self.assertFormBodyEqual(prepare_token_request(**self.grant_body_pkce), self.auth_grant_body_pkce)
210210

211+
def test_prepare_token_revocation_request_rejects_callback(self):
212+
with self.assertRaisesRegex(
213+
TypeError,
214+
"prepare_token_revocation_request\\(\\) got an unexpected keyword argument 'callback'"):
215+
prepare_token_revocation_request(
216+
"https://server.example.com/revoke", "token", callback="jsonp"
217+
)
218+
211219
def test_grant_response(self):
212220
"""Verify correct parameter parsing and validation for auth code responses."""
213221
params = parse_authorization_code_response(self.grant_response)

0 commit comments

Comments
 (0)