Skip to content

Commit e657d7b

Browse files
ZuSen2ygk
andauthored
Not existing tokens should return 200 within introspection (not 403) (#1012)
* Not existing tokens should return 200 as well Compare with https://datatracker.ietf.org/doc/html/rfc7662 * Finish the PR checklist. Co-authored-by: Alan Crosswell <[email protected]>
1 parent c42423c commit e657d7b

File tree

4 files changed

+8
-7
lines changed

4 files changed

+8
-7
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ Michael Howitz
4747
Paul Dekkers
4848
Paul Oswald
4949
Pavel Tvrdík
50+
Patrick Palacin
5051
Peter Carnesciali
5152
Petr Dlouhý
5253
Rodney Richardson

CHANGELOG.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1717
## [Unreleased]
1818
### Added
1919
* #651 Batch expired token deletions in `cleartokens` management command
20-
21-
### Added
22-
2320
* Added pt-BR translations.
2421

22+
### Fixed
23+
* #1012 Return status for introspecting a nonexistent token from 401 to the correct value of 200 per [RFC 7662](https://datatracker.ietf.org/doc/html/rfc7662#section-2.2).
24+
2525
## [1.6.1] 2021-12-23
2626

2727
### Changed

oauth2_provider/views/introspect.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def get_token_response(token_value=None):
2828
get_access_token_model().objects.select_related("user", "application").get(token=token_value)
2929
)
3030
except ObjectDoesNotExist:
31-
return JsonResponse({"active": False}, status=401)
31+
return JsonResponse({"active": False}, status=200)
3232
else:
3333
if token.is_valid():
3434
data = {
@@ -42,7 +42,7 @@ def get_token_response(token_value=None):
4242
data["username"] = token.user.get_username()
4343
return JsonResponse(data)
4444
else:
45-
return JsonResponse({"active": False})
45+
return JsonResponse({"active": False}, status=200)
4646

4747
def get(self, request, *args, **kwargs):
4848
"""

tests/test_introspection_view.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ def test_view_get_notexisting_token(self):
199199
reverse("oauth2_provider:introspect"), {"token": "kaudawelsch"}, **auth_headers
200200
)
201201

202-
self.assertEqual(response.status_code, 401)
202+
self.assertEqual(response.status_code, 200)
203203
content = response.json()
204204
self.assertIsInstance(content, dict)
205205
self.assertDictEqual(
@@ -269,7 +269,7 @@ def test_view_post_notexisting_token(self):
269269
reverse("oauth2_provider:introspect"), {"token": "kaudawelsch"}, **auth_headers
270270
)
271271

272-
self.assertEqual(response.status_code, 401)
272+
self.assertEqual(response.status_code, 200)
273273
content = response.json()
274274
self.assertIsInstance(content, dict)
275275
self.assertDictEqual(

0 commit comments

Comments
 (0)