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.
Release files for Flaskcord 0.1.70
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| flaskcord-0.1.70.tar.gz | 20.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| Flaskcord-0.1.70-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 46.3 kB
Release files / flaskcord-0.1.70.tar.gz
| Download URL | flaskcord-0.1.70.tar.gz |
|---|---|
| Size | 20.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
227aab0ddc96edab43c8262b8aa51b06a0a2718a20490bb71a07bdeb6e82d5c9
|
|
BLAKE2b-256 checksum How to use checksums |
4a88e9338424134aa10f70b0c8f37b616401630c3389dff20fca63550f719140
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.4
|
Release files / Flaskcord-0.1.70-py3-none-any.whl
| Download URL | Flaskcord-0.1.70-py3-none-any.whl |
|---|---|
| Size | 26.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
473434b13a523c51792f5dcc12b1a08f3e469a2975990076c488aecb75afe914
|
|
BLAKE2b-256 checksum How to use checksums |
a114e1217f385a08055e1df3ffd1d058212dcf5b6516b6056faf9e90400b8ce7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.4
|