Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions auth/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,14 @@ def create_bearer_token(cls, user_id):
A token object, or None if one could not be created.
"""
return cls.token_model.create(user_id, 'bearer')

@classmethod
def delete_bearer_token(cls, user_id, token):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you envision this method being called when a User instance is available? My guess is that a logout endpoint would unfold like so:

  • Verify the provided access token and retrieve the current user
  • Delete the access token

If that flow is correct, would it be more appropriate to bind this method to the instance? e.g.

def delete_bearer_token(self, token):
   self.token_model.get_key(self.get_id(), 'bearer', token).delete()

Feel free to disagree. And thanks again for the PR!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great point!

"""Deletes a given bearer authorization token.

:param user_id:
User unique ID.
:param token:
A string with the authorization token.
"""
cls.token_model.get_key(user_id, 'bearer', token).delete()