mirror of
https://github.com/yawaflua/Flask-Discord.git
synced 2025-12-10 04:19:31 +02:00
Add revoke method to purge discord session data
This commit is contained in:
@@ -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
|
||||||
|
|||||||
@@ -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"))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user