slumber
slumber copied to clipboard
how can it support TokenAuthentication
You have to be quite more concrete, and define "TokenAuthentication", to get any kind of helpful answer.
This is how i've been doing it against my services that are using django-rest-framework
import slumber
class CUSTOMAPI(slumber.API):
def __init__(self, *args, **kwargs):
token = kwargs.pop('token', None)
super(CUSTOMAPI, self).__init__(*args, **kwargs)
if token is None:
data = dict(zip(["username", "password"],
self._store["session"].auth))
token = self.token.post(data=data)["token"]
self._store['session'].auth = None
self._store['session'].headers['Authorization'] = "Token " + token
def _get_resource(self, **kwargs):
return self.resource_class(**kwargs)
Would be nice if this was somehow built-in to slumber since its the recommended tool of choice for using it against django-rest-framework
any traction on this, seems like a no-brainer to put the token in the auth header for DRF.
@rocktavious's code definitely works though, was able to move forward with that workaround.