Skip to content

Commit

Permalink
fix: auth JWKS endpoint
Browse files Browse the repository at this point in the history
The original implementation of the endpoint returned
a string instead of a JSON object. This fixes the
return value to be the JSON object.
  • Loading branch information
Ben Lu committed Feb 2, 2024
1 parent ebb55ce commit 2de48c1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
5 changes: 3 additions & 2 deletions openedx/core/djangoapps/user_authn/views/auth.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
""" Views related to auth. """


import json
from common.djangoapps.util.json_request import JsonResponse
from django.conf import settings

Expand All @@ -13,4 +13,5 @@ def get_public_signing_jwks(request):
if not jwt_dict.get('JWT_PUBLIC_SIGNING_JWK_SET'):
return JsonResponse({'error': 'JWK set is not found'}, status=400)
jwks = jwt_dict['JWT_PUBLIC_SIGNING_JWK_SET']
return JsonResponse(jwks, status=200)
# jwks is a string here, need to convert it to dict
return JsonResponse(json.loads(jwks), status=200)
4 changes: 2 additions & 2 deletions openedx/core/djangoapps/user_authn/views/tests/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ def _get_jwks(self, accepts='application/json'):

return self.client.get(url, HTTP_ACCEPT=accepts)

@mock.patch.dict(settings.JWT_AUTH, {'JWT_PUBLIC_SIGNING_JWK_SET': None})
@mock.patch.dict(settings.JWT_AUTH, {'JWT_PUBLIC_SIGNING_JWK_SET': ''})
def test_get_public_signing_jwks_with_no_jwk_set(self):
""" Test JWT_PUBLIC_SIGNING_JWK_SET is undefined """
resp = self._get_jwks()
content = json.loads(resp.content)
assert resp.status_code == 400
assert 'JWK set is not found' in content['error']

@mock.patch.dict(settings.JWT_AUTH, {'JWT_PUBLIC_SIGNING_JWK_SET': {'keys': []}})
@mock.patch.dict(settings.JWT_AUTH, {'JWT_PUBLIC_SIGNING_JWK_SET': '{"keys": []}'})
def test_get_public_signing_jwks_with_jwk_set(self):
""" Test JWT_PUBLIC_SIGNING_JWK_SET is defined """
resp = self._get_jwks()
Expand Down

0 comments on commit 2de48c1

Please sign in to comment.