Skip to content

Commit f5e1d8d

Browse files
author
Mikey
committed
Removed OAuth import
1 parent ac34b7e commit f5e1d8d

File tree

1 file changed

+30
-13
lines changed

1 file changed

+30
-13
lines changed

Part 1/main.py

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,43 @@
11
from quart import Quart, render_template, request, session
2-
from .oauth import Oauth
3-
2+
from quart_discord import DiscordOAuth2Session
43

54
app = Quart(__name__)
65
app.config["SECRET_KEY"] = "test123"
6+
app.config["DISCORD_CLIENT_ID"] = 1234567890 # Discord client ID.
7+
app.config["DISCORD_CLIENT_SECRET"] = "SHHHH" # Discord client secret.
8+
app.config["DISCORD_REDIRECT_URI"] = "" # URL to your callback endpoint.
9+
10+
discord = DiscordOAuth2Session(app)
711

812
@app.route("/")
913
async def home():
10-
return await render_template("index.html",discord_url= Oauth.discord_login_url)
14+
return await render_template("index.html",discord_url="login url here")
1115

1216
@app.route("/login")
1317
async def login():
14-
code = request.args.get("code")
15-
16-
at = Oauth.get_access_token(code)
17-
session["token"] = at
18-
19-
user = Oauth.get_user_json(at)
20-
user_name, user_id = user.get("username"), user.get("discriminator")
21-
22-
return f"Success, logged in as {user_name}#{user_id}"
23-
18+
"""The function that logs the user in.
19+
20+
It will redirect them to your Discord OAuth2 Flow,
21+
and they will then be redirected back to your callback
22+
endpoint, or REDIRECT_URI.
23+
"""
24+
return await discord.create_session()
25+
26+
@app.route("/callback")
27+
async def callback():
28+
"""Callback.
29+
30+
This will handle the authentication of
31+
the user, and create the session and cookies.
32+
"""
33+
await discord.callback()
34+
user = await discord.fetch_user()
35+
return f"Hello, {user.name}#{user.discriminator}! <img src='{user.avatar_url}'>"
36+
37+
@app.route('/logout')
38+
async def logout():
39+
"""Logs out the user by REVOKING!!! their token."""
40+
discord.revoke()
2441

2542
if __name__ == "__main__":
2643
app.run(debug=True)

0 commit comments

Comments
 (0)