Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add email field to UserMappingView #11

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions common/djangoapps/third_party_auth/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class UserMappingSerializer(serializers.Serializer): # pylint: disable=abstract
provider = None
username = serializers.SerializerMethodField()
remote_id = serializers.SerializerMethodField()
email = serializers.SerializerMethodField()

def __init__(self, *args, **kwargs):
self.provider = kwargs['context'].get('provider', None)
Expand All @@ -21,3 +22,7 @@ def get_username(self, social_user):
def get_remote_id(self, social_user):
""" Gets remote id from social user based on provider """
return self.provider.get_remote_id_from_social_auth(social_user)

def get_email(self, social_user):
""" Gets the edx email from a social user """
return social_user.user.email
5 changes: 4 additions & 1 deletion common/djangoapps/third_party_auth/api/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@

def get_mapping_data_by_usernames(usernames):
""" Generate mapping data used in response """
return [{'username': username, 'remote_id': 'remote_' + username} for username in usernames]
return [
{"username": username, "remote_id": "remote_" + username, "email": f"{username}@example.com"}
for username in usernames
]


class TpaAPITestCase(ThirdPartyAuthTestMixin, APITestCase):
Expand Down
2 changes: 2 additions & 0 deletions common/djangoapps/third_party_auth/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,8 @@ class UserMappingView(ListAPIView):
* username: The edx username

* remote_id: The Id from third party auth provider

* email: The edx email
"""
authentication_classes = (JwtAuthentication, BearerAuthentication, )
permission_classes = (TPA_PERMISSIONS, )
Expand Down
Loading