Add revoke method to purge discord session data

This commit is contained in:
thecosmos
2019-05-20 09:45:48 +05:30
parent f91bdca7d9
commit 93fafcc9d1
2 changed files with 14 additions and 0 deletions

View File

@@ -23,6 +23,11 @@ class DiscordOAuth2HttpClient(abc.ABC):
""" """
SESSION_KEYS = [
"discord_oauth2_state",
"discord_oauth2_token",
]
def __init__(self, client_id, client_secret, redirect_uri): def __init__(self, client_id, client_secret, redirect_uri):
self.client_id = client_id self.client_id = client_id
self.client_secret = client_secret self.client_secret = client_secret

View File

@@ -59,6 +59,15 @@ class DiscordOAuth2Session(_http.DiscordOAuth2HttpClient):
) )
session["discord_oauth2_token"] = token session["discord_oauth2_token"] = token
def revoke(self):
"""This method clears current discord token, state and all session data from flask
session <http://flask.pocoo.org/docs/1.0/api/#flask.session>. Which means user will have
to go through discord authorization token grant flow again.
"""
for session_key in self.SESSION_KEYS:
session.pop(session_key)
def fetch_user(self): def fetch_user(self):
return models.User(self.get("/users/@me")) return models.User(self.get("/users/@me"))