'Returns two-tuple of (user, token) if access token authentication
succeeds, raises an AuthenticationFailed (HTTP 401) if authentication
fails or None if the user did not try to authenticate using an access
token.'

def authenticate(self, *args, **kwargs):

    try:
        return super(OAuth2AuthenticationAllowInactiveUser, self).authenticate(*args, **kwargs)
    except AuthenticationFailed as exc:
        if isinstance(exc.detail, dict):
            developer_message = exc.detail['developer_message']
            error_code = exc.detail['error_code']
        else:
            developer_message = exc.detail
            if ('No    credentials    provided' in developer_message):
                error_code = OAUTH2_TOKEN_ERROR_NOT_PROVIDED
            elif ('Token    string    should    not    contain    spaces' in developer_message):
                error_code = OAUTH2_TOKEN_ERROR_MALFORMED
            else:
                error_code = OAUTH2_TOKEN_ERROR
        raise AuthenticationFailed({u'error_code': error_code, u'developer_message': developer_message})
