Skip to main content

Discord OAuth2 extension for Flask.

Project description

https://img.shields.io/pypi/v/flaskcord?style=for-the-badge https://img.shields.io/readthedocs/flaskcord?style=for-the-badge https://img.shields.io/discord/1258233857358958633?label=Vinny%20Support%20Server&logo=Discord&style=for-the-badge

Discord OAuth2 extension for Flask. Forked from Flaskcord, with support for flask[async]

Installation

To install the current latest release, use the following command:

python3 -m pip install flaskcord

Basic Example

import os

from flask import Flask, redirect, url_for
from flaskcord import DiscordOAuth2Session, requires_authorization, Unauthorized

app = Flask(__name__)

app.secret_key = b"random bytes representing flask secret key"
os.environ["OAUTHLIB_INSECURE_TRANSPORT"] = "true"      # !! Only in development environment.

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/")
def login():
    return discord.create_session()

@app.route("/callback/")
def callback():
    discord.callback()
    return redirect(url_for(".me"))

@app.errorhandler(Unauthorized)
def redirect_unauthorized(e):
    return redirect(url_for("login"))

@app.route("/me/")
@requires_authorization
def me(): # supports async if using flask[async]!
    user = 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()

Requirements

  • Flask

  • requests_oauthlib

  • cachetools

  • discord.py

Documentation

Head over to the 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

flaskcord-0.1.70.tar.gz (20.3 kB view details)

Uploaded Source

Built Distribution

Flaskcord-0.1.70-py3-none-any.whl (26.0 kB view details)

Uploaded Python 3

File details

Details for the file flaskcord-0.1.70.tar.gz.

File metadata

  • Download URL: flaskcord-0.1.70.tar.gz
  • Upload date:
  • Size: 20.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.4

File hashes

Hashes for flaskcord-0.1.70.tar.gz
Algorithm Hash digest
SHA256 227aab0ddc96edab43c8262b8aa51b06a0a2718a20490bb71a07bdeb6e82d5c9
MD5 cbcc6bb9768f3fb409a19775a865d586
BLAKE2b-256 4a88e9338424134aa10f70b0c8f37b616401630c3389dff20fca63550f719140

See more details on using hashes here.

File details

Details for the file Flaskcord-0.1.70-py3-none-any.whl.

File metadata

  • Download URL: Flaskcord-0.1.70-py3-none-any.whl
  • Upload date:
  • Size: 26.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.4

File hashes

Hashes for Flaskcord-0.1.70-py3-none-any.whl
Algorithm Hash digest
SHA256 473434b13a523c51792f5dcc12b1a08f3e469a2975990076c488aecb75afe914
MD5 ac6002be87f9658a1b80fa5c37f9b33c
BLAKE2b-256 a114e1217f385a08055e1df3ffd1d058212dcf5b6516b6056faf9e90400b8ce7

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