{"action":"opened","issue":{"url":"https://api.github.com/repos/PhilipGarnero/django-rest-framework-social-oauth2/issues/10","labels_url":"https://api.github.com/repos/PhilipGarnero/django-rest-framework-social-oauth2/issues/10/labels{/name}","comments_url":"https://api.github.com/repos/PhilipGarnero/django-rest-framework-social-oauth2/issues/10/comments","events_url":"https://api.github.com/repos/PhilipGarnero/django-rest-framework-social-oauth2/issues/10/events","html_url":"https://github.com/PhilipGarnero/django-rest-framework-social-oauth2/issues/10","id":99812405,"number":10,"title":"AttributeError: 'generator' object has no attribute 'session'","user":{"login":"mikeedwards","id":57811,"avatar_url":"https://avatars.githubusercontent.com/u/57811?v=3","gravatar_id":"","url":"https://api.github.com/users/mikeedwards","html_url":"https://github.com/mikeedwards","followers_url":"https://api.github.com/users/mikeedwards/followers","following_url":"https://api.github.com/users/mikeedwards/following{/other_user}","gists_url":"https://api.github.com/users/mikeedwards/gists{/gist_id}","starred_url":"https://api.github.com/users/mikeedwards/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mikeedwards/subscriptions","organizations_url":"https://api.github.com/users/mikeedwards/orgs","repos_url":"https://api.github.com/users/mikeedwards/repos","events_url":"https://api.github.com/users/mikeedwards/events{/privacy}","received_events_url":"https://api.github.com/users/mikeedwards/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-08-08T16:27:04Z","updated_at":"2015-08-08T16:27:04Z","closed_at":null,"body":"Ok, this is a really weird error and it passes through a few modules.\r\n\r\nWhen I try to POST to auth/convert-token, like so:\r\n```\r\ncurl -X POST -d \"grant_type=convert_token&client_id=<client_id>&client_secret=<client_secret>&backend=facebook&token=<token>\" http://localhost:8000/auth/convert-token\r\n```\r\n\r\nI get the error:\r\n`AttributeError: 'generator' object has no attribute 'session'`\r\n\r\nI notice that `ConvertTokenView` calls the `OAuthLibMixin` for `create_token_response`:\r\n\r\n__(see rest_framework_social_oauth2/views.py line 34)__\r\n```\r\nclass ConvertTokenView(CsrfExemptMixin, OAuthLibMixin, View):\r\n    \"\"\"\r\n    Implements an endpoint to provide access tokens\r\n    The endpoint is used in the following flows:\r\n    * Authorization code\r\n    * Password\r\n    * Client credentials\r\n    \"\"\"\r\n    server_class = SocialTokenServer\r\n    validator_class = oauth2_settings.OAUTH2_VALIDATOR_CLASS\r\n    oauthlib_backend_class = KeepRequestCore\r\n\r\n    def post(self, request, *args, **kwargs):\r\n        url, headers, body, status = self.create_token_response(request)\r\n        response = HttpResponse(content=body, status=status)\r\n\r\n        for k, v in headers.items():\r\n            response[k] = v\r\n        return response\r\n```\r\n\r\nThis leads down a winding path that eventually gets to oauthlib. In the code below, the header value for `'Django-request-object'` goes from being a `WSGIRequest` to a `generator` without any output, the result of the `encode` method here:\r\n\r\n__(see oauthlib/common.py line 380)__\r\n`self.headers = CaseInsensitiveDict(encode(headers or {}))`\r\n\r\nThe problem, then, is that by the time the request gets back to the `SocialTokenGrant` class in your library here:\r\n\r\n__(see rest_framework_social_oauth2/oauth2_grants.py line 80)__\r\n```\r\n        # TODO: Find a better way to pass the django request object\r\n        strategy = load_strategy(request=request.headers[\"Django-request-object\"])\r\n```\r\nIt's no longer a real request. And, a few calls down the chain in python-social-auth, it blows up:\r\n\r\n__(see social/strategies/django_strategy.py line 30__\r\n```\r\nclass DjangoStrategy(BaseStrategy):\r\n    DEFAULT_TEMPLATE_STRATEGY = DjangoTemplateStrategy\r\n\r\n    def __init__(self, storage, request=None, tpl=None):\r\n        self.request = request\r\n        self.session = request.session if request else {}\r\n        super(DjangoStrategy, self).__init__(storage, tpl)\r\n```\r\n\r\nand produces the error:\r\n`AttributeError: 'generator' object has no attribute 'session'`\r\n\r\n\r\nAny idea how to work around this? Is there another way to get back to the Django request without having to rely on the headers coming through?\r\n\r\nHere are the relevant parts of my requirements.txt:\r\n\r\n```\r\nDjango==1.8.1\r\ndjangorestframework==3.1.2\r\nsix==1.9.0\r\nwsgiref==0.1.2\r\npython-social-auth==0.2.12\r\ndjango-oauth-toolkit==0.9.0\r\ndjango-rest-framework-social-oauth2==1.0.0\r\n```\r\n\r\nand settings.py\r\n\r\n```\r\nAUTHENTICATION_BACKENDS = (\r\n    # Facebook OAuth2\r\n    'social.backends.facebook.FacebookAppOAuth2',\r\n    'social.backends.facebook.FacebookOAuth2',\r\n\r\n    # django-rest-framework-social-oauth2\r\n    'rest_framework_social_oauth2.backends.DjangoOAuth2',\r\n\r\n    # Django\r\n    'django.contrib.auth.backends.ModelBackend',\r\n)\r\n\r\n\r\nREST_FRAMEWORK = {\r\n    'DEFAULT_AUTHENTICATION_CLASSES': (\r\n        'rest_framework.authentication.TokenAuthentication',\r\n        'oauth2_provider.ext.rest_framework.OAuth2Authentication',\r\n        'rest_framework_social_oauth2.authentication.SocialAuthentication',\r\n    ),\r\n    'DEFAULT_PERMISSION_CLASSES': (\r\n        'rest_framework.permissions.IsAuthenticated',\r\n    ),\r\n}\r\n\r\nSOCIAL_AUTH_FACEBOOK_KEY = env_var('SOCIAL_AUTH_FACEBOOK_KEY')\r\nSOCIAL_AUTH_FACEBOOK_SECRET = env_var('SOCIAL_AUTH_FACEBOOK_SECRET')\r\n\r\nTEMPLATE_CONTEXT_PROCESSORS = (\r\n    'django.contrib.auth.context_processors.auth',\r\n    'django.template.context_processors.debug',\r\n    'django.template.context_processors.i18n',\r\n    'django.template.context_processors.media',\r\n    'django.template.context_processors.static',\r\n    'django.template.context_processors.tz',\r\n    'django.contrib.messages.context_processors.messages',\r\n    'social.apps.django_app.context_processors.backends',\r\n    'social.apps.django_app.context_processors.login_redirect',\r\n)\r\n\r\nMIDDLEWARE_CLASSES = (\r\n    'django.contrib.sessions.middleware.SessionMiddleware',\r\n    'django.middleware.common.CommonMiddleware',\r\n    'django.middleware.csrf.CsrfViewMiddleware',\r\n    'django.contrib.auth.middleware.AuthenticationMiddleware',\r\n    'django.contrib.auth.middleware.SessionAuthenticationMiddleware',\r\n    'django.contrib.messages.middleware.MessageMiddleware',\r\n    'django.middleware.clickjacking.XFrameOptionsMiddleware',\r\n    'django.middleware.security.SecurityMiddleware',\r\n    'social.apps.django_app.middleware.SocialAuthExceptionMiddleware',\r\n)\r\n```\r\n"}}