Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
class GetAccessToken(APIView):
authentication_classes = [authentication.UserBasicAuthentication]
permission_classes = [permissions.UserIsAuthenticated]
model = djangorestframework.basictoken.models.BasicToken
def post(self, request, *args, **kwargs):
token = self.model.objects.get_or_create(user=request.user)
return Response({'key': token.key})
@tomchristie

This comment has been minimized.

Copy link
Owner Author

commented Sep 7, 2012

class GetAccessToken(APIView):
authentication_classes = [authentication.UserBasicAuthentication]
permission_classes = [permissions.UserIsAuthenticated]
model = djangorestframework.basictoken.models.BasicToken

def post(self, request, *args, **kwargs):
    token = self.model.objects.get_or_create(user=request.user)
    return Response({'token': token.token, 'key': token.key})
@tomchristie

This comment has been minimized.

Copy link
Owner Author

commented Sep 7, 2012

Ooops, that didn't quite work.

@mjumbewu

This comment has been minimized.

Copy link

commented Sep 7, 2012

If a user has more than one key, how would the view know which to choose?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.