Coder Social home page Coder Social logo

memotic / quart-discord-any Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jnawk/quart-discord

0.0 0.0 0.0 2.19 MB

Discord OAuth2 extension for Quart. An Easier implementation of "Log In With Discord".

License: MIT License

Python 100.00%

quart-discord-any's Introduction

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.

quart-discord-any's People

Contributors

weibeu avatar jnawk avatar williamhatcher avatar riksou avatar dorilahav avatar a-trash-coder avatar bravosierra99 avatar bobmoretti avatar predaaa avatar taarek avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.