Discord OAuth2 extension for Quart using modern Discord Libraries.
Project description
Quart-Discord
Discord OAuth2 extension for Quart using py-cord, nextcord, or the deprecated discord.py.
Installation
To install current latest release use one of the following commands:
For py-cord: (My recommendation)
python3 -m pip install Quart-Discord-any[pycord]
For nextcord:
python3 -m pip install Quart-Discord-any[nextcord]
For the deprecated discord.py:
python3 -m pip install Quart-Discord-any[discord.py]
You MUST install one of the extras!
Basic Example
from quart import Quart, redirect, url_for
from quart_discord import DiscordOAuth2Session, requires_authorization, Unauthorized
app = Quart(__name__)
app.secret_key = b"random bytes representing quart secret key"
app.config["DISCORD_CLIENT_ID"] = 490732332240863233 # Discord client ID.
app.config["DISCORD_CLIENT_SECRET"] = "" # Discord client secret.
app.config["DISCORD_REDIRECT_URI"] = "" # URL to your callback endpoint.
app.config["DISCORD_BOT_TOKEN"] = "" # Required to access BOT resources.
discord = DiscordOAuth2Session(app)
@app.route("/login/")
async def login():
return await discord.create_session()
@app.route("/callback/")
async def callback():
await discord.callback()
return redirect(url_for(".me"))
@app.errorhandler(Unauthorized)
async def redirect_unauthorized(e):
return redirect(url_for("login"))
@app.route("/me/")
@requires_authorization
async def me():
user = await discord.fetch_user()
return f"""
<html>
<head>
<title>{user.name}</title>
</head>
<body>
<img src='{user.avatar_url}' />
</body>
</html>"""
if __name__ == "__main__":
app.run()
For an example to the working application, check test_app.py
Requirements
- Quart
- Async-OAuthlib
- cachetools
- discord.py
Documentation
Head over to documentation for full API reference.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Quart-Discord-any-2.2.1b2.tar.gz
(15.2 kB
view hashes)
Built Distribution
Close
Hashes for Quart-Discord-any-2.2.1b2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 32b79e056cfdbbbc1c8e1be45f58d96bc67c7ed1f7fee63dc30da36f88912d08 |
|
MD5 | 485073ae2f32e737e6dc7257827d7cfe |
|
BLAKE2b-256 | ba858fdac2747ae2cbfe641eb61ab26d519a0ba2ffbe049652db73f1f5ff8df2 |
Close
Hashes for Quart_Discord_any-2.2.1b2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 33d3dd164b1d0fc9e2b031ad1befd760605a25bbd677b0eb65cbbfd3e4ee87a9 |
|
MD5 | 4f30c28688c97f94e5bf4470e341463c |
|
BLAKE2b-256 | 83ef8683a40bc26dac14d01a2f61e3b9bfc9b57faa1802d962ce7dc9b74193ca |