{"action":"created","issue":{"url":"https://api.github.com/repos/tomchristie/django-rest-framework/issues/4080","repository_url":"https://api.github.com/repos/tomchristie/django-rest-framework","labels_url":"https://api.github.com/repos/tomchristie/django-rest-framework/issues/4080/labels{/name}","comments_url":"https://api.github.com/repos/tomchristie/django-rest-framework/issues/4080/comments","events_url":"https://api.github.com/repos/tomchristie/django-rest-framework/issues/4080/events","html_url":"https://github.com/tomchristie/django-rest-framework/issues/4080","id":151616280,"number":4080,"title":"Key name in AuthToken authorization","user":{"login":"jpocentek","id":8410171,"avatar_url":"https://avatars.githubusercontent.com/u/8410171?v=3","gravatar_id":"","url":"https://api.github.com/users/jpocentek","html_url":"https://github.com/jpocentek","followers_url":"https://api.github.com/users/jpocentek/followers","following_url":"https://api.github.com/users/jpocentek/following{/other_user}","gists_url":"https://api.github.com/users/jpocentek/gists{/gist_id}","starred_url":"https://api.github.com/users/jpocentek/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jpocentek/subscriptions","organizations_url":"https://api.github.com/users/jpocentek/orgs","repos_url":"https://api.github.com/users/jpocentek/repos","events_url":"https://api.github.com/users/jpocentek/events{/privacy}","received_events_url":"https://api.github.com/users/jpocentek/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2016-04-28T11:24:42Z","updated_at":"2016-05-03T16:35:47Z","closed_at":"2016-04-28T13:56:38Z","body":"The default key for TokenAuthorization is \"Token\". The most often used key is \"Bearer\". Not long ago I tried to change the authentication token name for our REST application. I found class TokenAuthentication on line 142 in authentication.py. It defines method \"authenticate_header\" which returns \"Token\" so I thought that it is possible to override this method and return \"Bearer\". No, it's not possible. I had to override entire class just to change token name. Am I missed something? This actually should be in settings.py file. I don't know if there is other way to define token name. If there is, please, give me link to docs. If it's not possible, I could easily create plugin that takes token name from settings file. Method \"authenticate_header\" seems to be not used at all. This is my modification:\r\n\r\nclass CustomTokenAuthentication(TokenAuthentication):\r\n    \"\"\" Modify default authorization header to much more common 'Bearer'.\r\n    \"\"\"\r\n    header_key = b'bearer'\r\n\r\n    def authenticate(self, request):\r\n        auth = get_authorization_header(request).split()\r\n\r\n        if not auth or auth[0].lower() != self.header_key:\r\n            return None\r\n\r\n        if len(auth) == 1:\r\n            msg = _('Invalid token header. No credentials provided.')\r\n            raise exceptions.AuthenticationFailed(msg)\r\n        elif len(auth) > 2:\r\n            msg = _(\r\n                'Invalid token header. Token string should not contain spaces.'\r\n            )\r\n            raise exceptions.AuthenticationFailed(msg)\r\n\r\n        try:\r\n            token = auth[1].decode()\r\n        except UnicodeError:\r\n            msg = _(\r\n                'Invalid token header. Token string should not contain',\r\n                'invalid characters.'\r\n            )\r\n            raise exceptions.AuthenticationFailed(msg)\r\n\r\n        return self.authenticate_credentials(token)\r\n\r\n    def authenticate_header(self, request):\r\n        return \"Bearer\"\r\n"},"comment":{"url":"https://api.github.com/repos/tomchristie/django-rest-framework/issues/comments/216587420","html_url":"https://github.com/tomchristie/django-rest-framework/issues/4080#issuecomment-216587420","issue_url":"https://api.github.com/repos/tomchristie/django-rest-framework/issues/4080","id":216587420,"user":{"login":"hroncok","id":2401856,"avatar_url":"https://avatars.githubusercontent.com/u/2401856?v=3","gravatar_id":"","url":"https://api.github.com/users/hroncok","html_url":"https://github.com/hroncok","followers_url":"https://api.github.com/users/hroncok/followers","following_url":"https://api.github.com/users/hroncok/following{/other_user}","gists_url":"https://api.github.com/users/hroncok/gists{/gist_id}","starred_url":"https://api.github.com/users/hroncok/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hroncok/subscriptions","organizations_url":"https://api.github.com/users/hroncok/orgs","repos_url":"https://api.github.com/users/hroncok/repos","events_url":"https://api.github.com/users/hroncok/events{/privacy}","received_events_url":"https://api.github.com/users/hroncok/received_events","type":"User","site_admin":false},"created_at":"2016-05-03T16:35:47Z","updated_at":"2016-05-03T16:35:47Z","body":"I've just come across the same problem.\r\n\r\n@tomchristie would you accept a pull request that would set `keyword` class variable to `'Token'` in `TokenAuthorization`, and use it inside it's methods (instead of hardcoding it, as it is done now), so we can then do:\r\n\r\n```python\r\n\r\nclass BearerAuthentication(authentication.TokenAuthentication):\r\n    '''\r\n    Simple token based authentication using utvsapitoken.\r\n\r\n    Clients should authenticate by passing the token key in the 'Authorization'\r\n    HTTP header, prepended with the string 'Bearer '.  For example:\r\n\r\n        Authorization: Bearer 956e252a-513c-48c5-92dd-bfddc364e812\r\n    '''\r\n    keyword = 'Bearer'\r\n\r\n```"}}