Skip to content

Instantly share code, notes, and snippets.

@tomchristie
Created September 7, 2012 15:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomchristie/3667231 to your computer and use it in GitHub Desktop.
Save tomchristie/3667231 to your computer and use it in GitHub Desktop.
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
Copy link
Author

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
Copy link
Author

Ooops, that didn't quite work.

@mjumbewu
Copy link

mjumbewu 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