{"action":"created","issue":{"url":"https://api.github.com/repos/davesque/django-rest-framework-simplejwt/issues/37","repository_url":"https://api.github.com/repos/davesque/django-rest-framework-simplejwt","labels_url":"https://api.github.com/repos/davesque/django-rest-framework-simplejwt/issues/37/labels{/name}","comments_url":"https://api.github.com/repos/davesque/django-rest-framework-simplejwt/issues/37/comments","events_url":"https://api.github.com/repos/davesque/django-rest-framework-simplejwt/issues/37/events","html_url":"https://github.com/davesque/django-rest-framework-simplejwt/issues/37","id":349433218,"node_id":"MDU6SXNzdWUzNDk0MzMyMTg=","number":37,"title":"AttributeError when trying to access \"is_staff\" or \"is_superuser\" on a TokenUser","user":{"login":"sampaccoud","id":1427165,"node_id":"MDQ6VXNlcjE0MjcxNjU=","avatar_url":"https://avatars3.githubusercontent.com/u/1427165?v=4","gravatar_id":"","url":"https://api.github.com/users/sampaccoud","html_url":"https://github.com/sampaccoud","followers_url":"https://api.github.com/users/sampaccoud/followers","following_url":"https://api.github.com/users/sampaccoud/following{/other_user}","gists_url":"https://api.github.com/users/sampaccoud/gists{/gist_id}","starred_url":"https://api.github.com/users/sampaccoud/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sampaccoud/subscriptions","organizations_url":"https://api.github.com/users/sampaccoud/orgs","repos_url":"https://api.github.com/users/sampaccoud/repos","events_url":"https://api.github.com/users/sampaccoud/events{/privacy}","received_events_url":"https://api.github.com/users/sampaccoud/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-08-10T09:03:00Z","updated_at":"2018-08-10T18:37:54Z","closed_at":null,"author_association":"NONE","body":"## Bug Report\r\n\r\n**Expected behavior/code**\r\nIf I have a JWT token with the \"is_staff\" or \"is_superuser\" property set, I expect these properties to be available on a TokenUser instanciated with this token.\r\n\r\n**Actual Behavior**\r\nA clear and concise description of the behavior.\r\n\r\n**Steps to Reproduce**\r\n\r\n> token = AccessToken()\r\n> token.payload[\"is_staff\"] = True\r\n> user = TokenUser(token)\r\n> user.is_staff\r\n\r\nFile \"/usr/local/lib/python3.6/site-packages/rest_framework_simplejwt/models.py\", line 47, in is_staff\r\n    return self.token.get('is_staff', False)\r\nAttributeError: 'AccessToken' object has no attribute 'get'\r\n\r\n**Environment**\r\n- python: 3.6.5\r\n- django: 2.0.8\r\n- djangorestframework: 3.8.2\r\n- djangorestframework_simplejwt: 3.2.3\r\n\r\n**Possible Solution**\r\nPoke the payload instead of the token itself:\r\n```python\r\n@cached_property\r\ndef is_staff(self):\r\n-     return self.token.get('is_staff', False)\r\n+    return self.token.payload.get('is_staff', False)\r\n\r\n@cached_property\r\ndef is_superuser(self):\r\n-    return self.token.get('is_superuser', False)\r\n+    return self.token.payload.get('is_superuser', False)\r\n```"},"comment":{"url":"https://api.github.com/repos/davesque/django-rest-framework-simplejwt/issues/comments/412169798","html_url":"https://github.com/davesque/django-rest-framework-simplejwt/issues/37#issuecomment-412169798","issue_url":"https://api.github.com/repos/davesque/django-rest-framework-simplejwt/issues/37","id":412169798,"node_id":"MDEyOklzc3VlQ29tbWVudDQxMjE2OTc5OA==","user":{"login":"davesque","id":791437,"node_id":"MDQ6VXNlcjc5MTQzNw==","avatar_url":"https://avatars2.githubusercontent.com/u/791437?v=4","gravatar_id":"","url":"https://api.github.com/users/davesque","html_url":"https://github.com/davesque","followers_url":"https://api.github.com/users/davesque/followers","following_url":"https://api.github.com/users/davesque/following{/other_user}","gists_url":"https://api.github.com/users/davesque/gists{/gist_id}","starred_url":"https://api.github.com/users/davesque/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/davesque/subscriptions","organizations_url":"https://api.github.com/users/davesque/orgs","repos_url":"https://api.github.com/users/davesque/repos","events_url":"https://api.github.com/users/davesque/events{/privacy}","received_events_url":"https://api.github.com/users/davesque/received_events","type":"User","site_admin":false},"created_at":"2018-08-10T18:37:54Z","updated_at":"2018-08-10T18:37:54Z","author_association":"OWNER","body":"Thanks for submitting this issue.  I think those `token.get` statements were just typos that resulted from me forgetting that the token objects only implement part of the dictionary API.  If you'd like, you can make a pull request which makes that modification.  You'll have to update one or two tests as well which will break."}}
{"actor":{"display_login":"davesque"}}