import requests

from allauth.socialaccount.providers.oauth2.views import (OAuth2Adapter,
                                                          OAuth2LoginView,
                                                          OAuth2CallbackView)
from .provider import GitHubProvider


class GitHubOAuth2Adapter(OAuth2Adapter):
    provider_id = GitHubProvider.id
    access_token_url = 'https://github.com/login/oauth/access_token'
    authorize_url = 'https://github.com/login/oauth/authorize'
    profile_url = 'https://api.github.com/user'
    emails_url = 'https://api.github.com/user/emails'

    def complete_login(self, request, app, token, **kwargs):
        resp = requests.get(self.profile_url,
                            params={'access_token': token.token})
        extra_data = resp.json()
        if not extra_data.get('email'):
            extra_data['email'] = self.get_email(token)
        return self.get_provider().sociallogin_from_response(request,
                                                             extra_data)

    def get_email(self, token):
        email = None
        resp = requests.get(self.emails_url,
                            params={'access_token': token.token})
        emails = resp.json()
        if emails:
            email = emails[0]
            primary_emails = [
                e for e in emails
                if not isinstance(e, dict) or e.get('primary')
            ]
            if primary_emails:
                email = primary_emails[0]
            if isinstance(email, dict):
                email = email.get('email', '')
        return email


oauth2_login = OAuth2LoginView.adapter_view(GitHubOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(GitHubOAuth2Adapter)

@@ -273,16 +273,63 @@
 rovider%0A
+from allauth.socialaccount import app_settings%0A
 %0A%0Aclass 
@@ -848,24 +848,53 @@
 %0A        if 
+app_settings.QUERY_EMAIL and 
 not extra_da

Getting github's email only if SOCIALACCOUNT_QUERY_EMAIL is true