Files
edx-platform/common/djangoapps/third_party_auth/api/serializers.py
Pan Luo f69304373c Implement user mapping API
This mapping API enables the mapping between the edX user ID and the ID
provided by identity provider (IdP). For details, please see
https://github.com/edx/edx-platform/pull/9842
2015-10-27 15:19:42 -07:00

23 lines
831 B
Python

""" Django REST Framework Serializers """
from rest_framework import serializers
class UserMappingSerializer(serializers.Serializer): # pylint: disable=abstract-method
""" Serializer for User Mapping"""
provider = None
username = serializers.SerializerMethodField()
remote_id = serializers.SerializerMethodField()
def __init__(self, *args, **kwargs):
self.provider = kwargs['context'].get('provider', None)
super(UserMappingSerializer, self).__init__(*args, **kwargs)
def get_username(self, social_user):
""" Gets the edx username from a social user """
return social_user.user.username
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)