Skip to main content

Discord OAuth2 extension for Quart.

Project description

quartcord

PyPI Build Documentation Status

Table of Contents

About

Discord OAuth2 extension for Quart.

Installation

Requirements

  • Quart
  • pyjwt
  • aiohttp
  • oauthlib
  • discord.py
  • cachetools
  • Async-OAuthlib

Setup

To install current latest release you can use following command:

python -m pip install quartcord

Basic Example

from quart import Quart, redirect, url_for
from quartcord 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()

Documentation

Head over to documentation for full API reference.

Support

Credits

License

MIT License

Copyright © 2023 Sayan "Sn1F3rt" Bhattacharyya

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

quartcord-1.0.1.tar.gz (15.3 kB view hashes)

Uploaded Source

Built Distribution

quartcord-1.0.1-py3-none-any.whl (18.6 kB view hashes)

Uploaded Python 3

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