Skip to content

Commit

Permalink
Merge branch 'master' into django_5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
dopry authored Nov 10, 2023
2 parents a13d2e0 + f580e2e commit 402b26e
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 8 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: 3.8
python-version: '3.12'

- name: Install dependencies
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
django-version: '4.2'

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
Expand Down
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/psf/black
rev: 23.9.1
rev: 23.10.1
hooks:
- id: black
exclude: ^(oauth2_provider/migrations/|tests/migrations/)
Expand All @@ -26,6 +26,6 @@ repos:
- id: flake8
exclude: ^(oauth2_provider/migrations/|tests/migrations/)
- repo: https://github.com/sphinx-contrib/sphinx-lint
rev: v0.6.8
rev: v0.8.1
hooks:
- id: sphinx-lint
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Antoine Laurent
Anvesh Agarwal
Aristóbulo Meneses
Aryan Iyappan
Asaf Klibansky
Ash Christopher
Asif Saif Uddin
Bart Merenda
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* #1273 Add caching of loading of OIDC private key.
* #1285 Add post_logout_redirect_uris field in application views.
* #1311 Add option to disable client_secret hashing to allow verifying JWTs' signatures.
* #1337 Gracefully handle expired or deleted refresh tokens, in `validate_user`.
* #1350 Support Python 3.12 and Django 5.0

### Fixed
Expand Down
6 changes: 4 additions & 2 deletions oauth2_provider/oauth2_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -725,8 +725,10 @@ def get_original_scopes(self, refresh_token, request, *args, **kwargs):
# validate_refresh_token.
rt = request.refresh_token_instance
if not rt.access_token_id:
return AccessToken.objects.get(source_refresh_token_id=rt.id).scope

try:
return AccessToken.objects.get(source_refresh_token_id=rt.id).scope
except AccessToken.DoesNotExist:
return []
return rt.access_token.scope

def validate_refresh_token(self, refresh_token, client, request, *args, **kwargs):
Expand Down
33 changes: 33 additions & 0 deletions tests/test_authorization_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -1002,6 +1002,39 @@ def test_refresh_repeating_requests_non_rotating_tokens(self):
response = self.client.post(reverse("oauth2_provider:token"), data=token_request_data, **auth_headers)
self.assertEqual(response.status_code, 200)

def test_refresh_with_deleted_token(self):
"""
Ensure that using a deleted refresh token returns 400
"""
self.client.login(username="test_user", password="123456")
authorization_code = self.get_auth()

token_request_data = {
"grant_type": "authorization_code",
"scope": "read write",
"code": authorization_code,
"redirect_uri": "http://example.org",
}
auth_headers = get_basic_auth_header(self.application.client_id, CLEARTEXT_SECRET)

# get a refresh token
response = self.client.post(reverse("oauth2_provider:token"), data=token_request_data, **auth_headers)

content = json.loads(response.content.decode("utf-8"))
rt = content["refresh_token"]

token_request_data = {
"grant_type": "refresh_token",
"refresh_token": rt,
"scope": "read write",
}

# delete the access token
AccessToken.objects.filter(token=content["access_token"]).delete()

response = self.client.post(reverse("oauth2_provider:token"), data=token_request_data, **auth_headers)
self.assertEqual(response.status_code, 400)

def test_basic_auth_bad_authcode(self):
"""
Request an access token using a bad authorization code
Expand Down

0 comments on commit 402b26e

Please sign in to comment.