Skip to content

Github access_token never stored #344

@LeonardoGentile

Description

@LeonardoGentile

I'm not using the default web flow but calling the do_auth from my custom method:

user = backend.do_auth(access_token, ajax=True)

The problem is that GithubOAuth2 backend never stores the access_token in the extra_data field.

I came up extending the GithubOauth2 backend:

class GithubOAuth2Extented(GithubOAuth2):
    """docstring for GithubOAuth2Extented"""

    # overriding parent method because it did not saved the access_token
    def user_data(self, access_token, *args, **kwargs):
        """Loads user data from service"""
        data = self._user_data(access_token)
        if not data.get('email'):
            try:
                email = self._user_data(access_token, '/emails')[0]
            except (HTTPError, IndexError, ValueError, TypeError):
                email = ''

            if isinstance(email, dict):
                email = email.get('email', '')
            data['email'] = email

        # Added by me
        data['access_token'] = access_token
        return data
        super(GithubOAuth2Extented, self).user_data()

Not sure if it is the best solution tough

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions