Commit c0479fb7 by muhammad-ammar

use users anonymous id for subject field in JWT

parent 3603ede5
...@@ -12,6 +12,7 @@ from oauth2_provider.tests.factories import ClientFactory ...@@ -12,6 +12,7 @@ from oauth2_provider.tests.factories import ClientFactory
from provider.constants import CONFIDENTIAL from provider.constants import CONFIDENTIAL
from openedx.core.lib.token_utils import get_id_token from openedx.core.lib.token_utils import get_id_token
from student.models import anonymous_id_for_user
from student.tests.factories import UserFactory, UserProfileFactory from student.tests.factories import UserFactory, UserProfileFactory
...@@ -53,7 +54,7 @@ class TestIdTokenGeneration(TestCase): ...@@ -53,7 +54,7 @@ class TestIdTokenGeneration(TestCase):
'exp': calendar.timegm(expiration.utctimetuple()), 'exp': calendar.timegm(expiration.utctimetuple()),
'iat': calendar.timegm(now.utctimetuple()), 'iat': calendar.timegm(now.utctimetuple()),
'aud': self.oauth2_client.client_id, 'aud': self.oauth2_client.client_id,
'sub': self.user.id, # pylint: disable=no-member 'sub': anonymous_id_for_user(self.user, None),
} }
self.assertEqual(payload, expected_payload) self.assertEqual(payload, expected_payload)
......
...@@ -6,7 +6,7 @@ from django.core.exceptions import ImproperlyConfigured ...@@ -6,7 +6,7 @@ from django.core.exceptions import ImproperlyConfigured
import jwt import jwt
from provider.oauth2.models import Client from provider.oauth2.models import Client
from student.models import UserProfile from student.models import UserProfile, anonymous_id_for_user
def get_id_token(user, client_name): def get_id_token(user, client_name):
...@@ -54,7 +54,7 @@ def get_id_token(user, client_name): ...@@ -54,7 +54,7 @@ def get_id_token(user, client_name):
'exp': now + datetime.timedelta(seconds=expires_in), 'exp': now + datetime.timedelta(seconds=expires_in),
'iat': now, 'iat': now,
'aud': client.client_id, 'aud': client.client_id,
'sub': user.id, 'sub': anonymous_id_for_user(user, None),
} }
return jwt.encode(payload, client.client_secret) return jwt.encode(payload, client.client_secret)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment