Skip to content

Commit

Permalink
Merge pull request openedx#34176 from hilltop16/hilltop16/JWKS-endpoi…
Browse files Browse the repository at this point in the history
…nt-fixup

fix: return a JSON object in JWKS endpoint response
  • Loading branch information
hilltop16 authored Feb 3, 2024
2 parents ebb55ce + 2de48c1 commit f7cd677
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 f7cd677

Please sign in to comment.