Skip to main content

Discord OAuth2 extension for Quart using modern Discord Libraries.

Project description

Quart-Discord

PyPI Read the Docs

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[discordpy]

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

Documentation

Head over to documentation for full API reference.

Project details


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.2b1.tar.gz (15.7 kB view details)

Uploaded Source

Built Distribution

Quart_Discord_any-2.2.2b1-py3-none-any.whl (20.5 kB view details)

Uploaded Python 3

File details

Details for the file Quart-Discord-any-2.2.2b1.tar.gz.

File metadata

  • Download URL: Quart-Discord-any-2.2.2b1.tar.gz
  • Upload date:
  • Size: 15.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for Quart-Discord-any-2.2.2b1.tar.gz
Algorithm Hash digest
SHA256 420d48e72aed818e7922274864c7bdf5d55a560b8a41e986648b8f418a77bcfe
MD5 7f61fe814b169c0a9c81485914c21c5a
BLAKE2b-256 2699158dff20871b6da94844ffedbef95a73f8263cd67fbfcf02d8f903f62c10

See more details on using hashes here.

File details

Details for the file Quart_Discord_any-2.2.2b1-py3-none-any.whl.

File metadata

File hashes

Hashes for Quart_Discord_any-2.2.2b1-py3-none-any.whl
Algorithm Hash digest
SHA256 63f6c2e214d5dc73f8f4c9b3c64aed687b2b4b2f7e1822e29ae7de4e274cb6ab
MD5 5a2b757e0cc53df107df5e2b2ff708f4
BLAKE2b-256 fc472d9c50a423c6d6327c49a32b15daf7298c2ad1ac306a18eb170a1808976a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page