slumber icon indicating copy to clipboard operation
slumber copied to clipboard

how can it support TokenAuthentication

Open diluke1600 opened this issue 9 years ago • 3 comments

diluke1600 avatar Jan 22 '16 08:01 diluke1600

You have to be quite more concrete, and define "TokenAuthentication", to get any kind of helpful answer.

jhermann avatar Jan 22 '16 15:01 jhermann

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

rocktavious avatar Jul 12 '16 18:07 rocktavious

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.

Lcstyle avatar Feb 13 '18 02:02 Lcstyle