Prefixed session data with discord to allow users to have their own other OAuth sessions

This commit is contained in:
thecosmos
2019-05-19 17:45:04 +05:30
parent bf49390a4c
commit f91bdca7d9
2 changed files with 6 additions and 6 deletions

View File

@@ -39,7 +39,7 @@ class DiscordOAuth2Session(_http.DiscordOAuth2HttpClient):
scope = scope or request.args.get("scope", str()).split() or configs.DEFAULT_SCOPES
discord_session = self._make_session(scope=scope)
authorization_url, state = discord_session.authorization_url(configs.AUTHORIZATION_BASE_URL)
session["oauth2_state"] = state
session["discord_oauth2_state"] = state
return redirect(authorization_url)
def callback(self):
@@ -51,13 +51,13 @@ class DiscordOAuth2Session(_http.DiscordOAuth2HttpClient):
"""
if request.values.get("error"):
return request.values["error"]
discord = self._make_session(state=session.get("oauth2_state"))
discord = self._make_session(state=session.get("discord_oauth2_state"))
token = discord.fetch_token(
configs.TOKEN_URL,
client_secret=self.client_secret,
authorization_response=request.url
)
session["oauth2_token"] = token
session["discord_oauth2_token"] = token
def fetch_user(self):
return models.User(self.get("/users/@me"))