Added social auth response data to session. #640

Closed
wants to merge 1 commit into
from

Projects

None yet

2 participants

@rca
rca commented Mar 20, 2013

For GitHub auth, this gives access to attributes like the user's avatar.

Is this the right way to go about doing this? Or is the data accessible some other way? Thanks!

@rca rca Added social auth response data to session.
For GitHub auth, this gives access to attributes like the user's avatar.
13f304c
@omab
Owner
omab commented Mar 20, 2013

For that purpose is the extra data processing, check the doc at http://django-social-auth.readthedocs.org/en/latest/backends/oauth.html, basically you define in that setting the key names of data you want to store in the UserSocialAuth instance.

@omab omab closed this Mar 20, 2013
@rca
rca commented Mar 20, 2013

I knew there had to be a better way, thanks! However, I'm not understanding the documentation. 😕

I'm looking to get some extra values from GitHub's OAuth response. For example, below is a subset of GitHub's response data:

    {
        'avatar_url': 'https://secure.gravatar.com/avatar/[...]',
        'created_at': '2009-02-11T02:18:24Z',
        'email': 'roberto@baremetal.io',
        'id': 53537,
        'login': 'rca'
        'name': 'Roberto Aguilar',
        [...]
    }

The documentation states to define the setting GITHUB_EXTRA_DATA to access this stuff. From the page you reference, I did not understand why there is a need for a list of 2-tuples, nor where I access this data from once I define it. I added the following to my settings:

GITHUB_EXTRA_DATA = [
    ('avatar_url', 'avatar_url'),
]

Now that I've configured GITHUB_EXTRA_DATA to give me access to avatar_url, how do I access it?

Thanks!

@omab
Owner
omab commented Mar 20, 2013

The two-tuples are in the form key name in response, alias value to store it, the alias was added to uniform the retrieved data between providers, for example if you use Github and Facebook backends, you will know that given any UserSocialAuth instance, you will find the avatar under a same key and avoid any backend-type check to use the correct key.

Once the data is stored, you can access it under the extra_data attribute in the UserSocialAuth instance, for example, given a user instance you can get it in this way:

user.social_auth.get(provider='github').extra_data['avatar_url']
@rca
rca commented Mar 22, 2013

@omab, thanks, got it working. I'm opening up another PR for some doc enhancement.

@rca rca deleted the baremetal-deps:add-extra-response-data-to-session branch Mar 22, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment