Skip to main content

Quart Discord Authorization Library

Project description

Quart-Authorization

A Library For Quart Discord Authorization

Note: This Fixed Version Of This Package

Whats Changed In This Package?

  • Some Errors Fixed Like Unclosed Clients
  • logout() Function Errors Fixed
  • Added .is_logged() Function

Usage

from Quart_Authorization_Discord import DiscordOauth2Client
from Quart import Quart, redirect, url_for, render_template_string

app = Quart(__name__)
app.secret_key = b"random bytes representing quart secret key"
app.config['DISCORD_CLIENT_ID'] = "Client ID here"
app.config['DISCORD_CLIENT_SECRET'] = 'CLIENT_SECRET_HERE'
app.config['SCOPES'] = ['identify', 'guilds']
app.config['DISCORD_REDIRECT_URI'] = 'http://127.0.0.1:5000/callback'
app.config['DISCORD_BOT_TOKEN'] = "Token"

client = DiscordOauth2Client(app)

@app.route("/")
async def index():
    if client.is_logged():
        return "You Are Already Logged In, Go To This Page: /me"
    else:
        return "You Are Not Logged In, Go To Authorization: /login"

@app.route("/login")
async def login():
    return await client.create_session()

@app.route("/logout")
async def logout():
    await client.logout()
    return redirect(url_for("index"))

@app.route("/callback")
async def callback():
    await client.callback()
    return redirect(url_for("index"))

@app.route("/me")
@client.is_logged_in # Checks If User Logged In, Raises 401
async def me():
    user = await client.fetch_user()
    return await render_template_string("""<html><head></head>
<body><p>You Are Succesfully Logged In As {{user.name}}</p>
</html>    
""",user=user)

@app.errorhandler(401)
async def handle_unathorized(e):
    return redirect(url_for("login"))

if __name__ == "__main__":
    app.run()

This Package Still On Development.

Bugs And Errors Can Be Found While Using. Please Contact Me If You Found Any Of These.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

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