William 'psyFi' Hatcher e1e0e7bd86 Added tests/.env to .gitignore
2020-08-06 00:03:04 -05:00
2020-07-30 17:31:01 +05:30
2020-07-29 22:47:56 +05:30
2020-08-06 00:03:04 -05:00
2019-05-08 09:51:51 +05:30
2019-05-08 09:49:40 +05:30
2020-07-29 22:47:56 +05:30
2020-07-18 15:09:30 +05:30
2020-07-18 15:09:30 +05:30

Flask-Discord

PyPI Read the Docs Discord

Discord OAuth2 extension for Flask.

Installation

To install current latest release you can use following command:

python3 -m pip install Flask-Discord

Basic Example

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

app = Flask(__name__)

app.secret_key = b"random bytes representing flask 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/")
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():
    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()

For an example to the working application, check test_app.py

Requirements

  • Flask
  • requests_oauthlib
  • cachetools
  • discord.py

Documentation

Head over to documentation for full API reference.

Description
Discord OAuth2 extension for Flask. An Easier implementation of "Log In With Discord".
Readme MIT 2.3 MiB
Languages
Python 100%