From 93fafcc9d1a208edae98e511471e7d05f76da4df Mon Sep 17 00:00:00 2001 From: thecosmos Date: Mon, 20 May 2019 09:45:48 +0530 Subject: [PATCH] Add revoke method to purge discord session data --- flask_discord/_http.py | 5 +++++ flask_discord/client.py | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/flask_discord/_http.py b/flask_discord/_http.py index 5d066d9..276d9a1 100644 --- a/flask_discord/_http.py +++ b/flask_discord/_http.py @@ -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): self.client_id = client_id self.client_secret = client_secret diff --git a/flask_discord/client.py b/flask_discord/client.py index d03e6aa..d8279d7 100644 --- a/flask_discord/client.py +++ b/flask_discord/client.py @@ -59,6 +59,15 @@ class DiscordOAuth2Session(_http.DiscordOAuth2HttpClient): ) session["discord_oauth2_token"] = token + def revoke(self): + """This method clears current discord token, state and all session data from 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): return models.User(self.get("/users/@me"))