Revoke oauth2 access tokens when a user clears sessions.

This commit is contained in:
Logan Hanks
2012-08-27 15:44:40 -07:00
parent 1d50982611
commit 02f1490cb6
2 changed files with 11 additions and 0 deletions

View File

@@ -668,6 +668,10 @@ class ApiController(RedditController, OAuth2ResourceController):
form.set_html('.status',
_('all other sessions have been logged out'))
form.set_inputs(curpass = "")
# deauthorize all access tokens
OAuth2AccessToken.revoke_all_by_user(c.user)
# run the change password command to get a new salt
change_password(c.user, password)
# the password salt has changed, so the user's cookie has been

View File

@@ -326,6 +326,13 @@ class OAuth2AccessToken(Token):
else:
tba._commit()
@classmethod
def revoke_all_by_user(cls, account):
"""Revokes all access tokens for a given user Account."""
tokens = cls._by_user(account)
for token in tokens:
token.revoke()
@classmethod
def _by_user(cls, account):
"""Returns a (possibly empty) list of valid access tokens for a given user Account."""