{"action":"created","issue":{"url":"https://api.github.com/repos/linuxlewis/channels-api/issues/31","repository_url":"https://api.github.com/repos/linuxlewis/channels-api","labels_url":"https://api.github.com/repos/linuxlewis/channels-api/issues/31/labels{/name}","comments_url":"https://api.github.com/repos/linuxlewis/channels-api/issues/31/comments","events_url":"https://api.github.com/repos/linuxlewis/channels-api/issues/31/events","html_url":"https://github.com/linuxlewis/channels-api/issues/31","id":243405462,"node_id":"MDU6SXNzdWUyNDM0MDU0NjI=","number":31,"title":"Django REST token authentication","user":{"login":"rbuzu","id":11333503,"node_id":"MDQ6VXNlcjExMzMzNTAz","avatar_url":"https://avatars1.githubusercontent.com/u/11333503?v=4","gravatar_id":"","url":"https://api.github.com/users/rbuzu","html_url":"https://github.com/rbuzu","followers_url":"https://api.github.com/users/rbuzu/followers","following_url":"https://api.github.com/users/rbuzu/following{/other_user}","gists_url":"https://api.github.com/users/rbuzu/gists{/gist_id}","starred_url":"https://api.github.com/users/rbuzu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rbuzu/subscriptions","organizations_url":"https://api.github.com/users/rbuzu/orgs","repos_url":"https://api.github.com/users/rbuzu/repos","events_url":"https://api.github.com/users/rbuzu/events{/privacy}","received_events_url":"https://api.github.com/users/rbuzu/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2017-07-17T14:01:36Z","updated_at":"2018-07-24T12:48:32Z","closed_at":null,"author_association":"NONE","body":"Hi,\r\n\r\nI'm trying to implement authentication using tokens generated by django-rest-framework.\r\n\r\nUsing this gist: https://gist.github.com/leonardoo/9574251b3c7eefccd84fc38905110ce4\r\n\r\nI've managed to do this:\r\n\r\nConsumer\r\n\r\n```\r\nclass APIDemultiplexer(RestTokenConsumerMixin, WebsocketDemultiplexer):\r\n    rest_user = True\r\n\r\n    def connect(self, message, **kwargs):\r\n        Group('users').add(message.reply_channel)\r\n\r\n        # user here is correct instance of User from given token\r\n        print(message.user)\r\n        Group('users').send({\r\n            'text': json.dumps({\r\n                \"accepted\": \"True\",\r\n            })\r\n        })\r\n    consumers = {\r\n        'campaigns': CampaignBinding.consumer\r\n    }\r\n```\r\n\r\nResource binding\r\n\r\n```\r\nclass CampaignBinding(ResourceBinding):\r\n\r\n    model = Campaign\r\n    stream = \"campaigns\"\r\n    serializer_class = CampaignSerializer\r\n    queryset = Campaign.objects.all()\r\n    permission_classes = (AllowAny,)\r\n   \r\n    def get_serializer_context(self):\r\n        # user here is Anonymous\r\n        print(self.user)\r\n        # I need user instance inside self.message\r\n        return {'request': self.message}\r\n```\r\n\r\nMy request\r\n`ws://localhost:8000/?token=ef0ef25fcfc75c0db91bbbccc062f0ab5786dc34`\r\n\r\nThe thing is that I can access User instance only inside Consumer and User instance is not propagated to ResourceBinding. Is there some obvious way to access ser from token inside ResourceBinding?\r\n\r\nAny help would be appreciated.\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/linuxlewis/channels-api/issues/comments/407394538","html_url":"https://github.com/linuxlewis/channels-api/issues/31#issuecomment-407394538","issue_url":"https://api.github.com/repos/linuxlewis/channels-api/issues/31","id":407394538,"node_id":"MDEyOklzc3VlQ29tbWVudDQwNzM5NDUzOA==","user":{"login":"maxblax","id":23218626,"node_id":"MDQ6VXNlcjIzMjE4NjI2","avatar_url":"https://avatars0.githubusercontent.com/u/23218626?v=4","gravatar_id":"","url":"https://api.github.com/users/maxblax","html_url":"https://github.com/maxblax","followers_url":"https://api.github.com/users/maxblax/followers","following_url":"https://api.github.com/users/maxblax/following{/other_user}","gists_url":"https://api.github.com/users/maxblax/gists{/gist_id}","starred_url":"https://api.github.com/users/maxblax/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/maxblax/subscriptions","organizations_url":"https://api.github.com/users/maxblax/orgs","repos_url":"https://api.github.com/users/maxblax/repos","events_url":"https://api.github.com/users/maxblax/events{/privacy}","received_events_url":"https://api.github.com/users/maxblax/received_events","type":"User","site_admin":false},"created_at":"2018-07-24T12:48:32Z","updated_at":"2018-07-24T12:48:32Z","author_association":"NONE","body":"Would be adorable of you indeed @gromsterus \r\nIn need for this feature. "}}
{"actor":{"display_login":"maxblax"}}