Metadata-Version: 2.1
Name: Flaskcord
Version: 0.1.70
Summary: Discord OAuth2 extension for Flask.
Home-page: https://github.com/Vinny-Bot/Flaskcord
Author: The Cosmos & Vinny contributors
Author-email: dev@vinny.pp.ua
License: MIT
Platform: any
Classifier: Framework :: Flask
Classifier: Environment :: Web Environment
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content
Classifier: Topic :: Software Development :: Libraries :: Python Modules
License-File: LICENSE
Requires-Dist: Flask
Requires-Dist: pyjwt>=2.4.0
Requires-Dist: requests
Requires-Dist: oauthlib
Requires-Dist: cachetools
Requires-Dist: requests_oauthlib
Provides-Extra: docs
Requires-Dist: sphinx>=7.4.6; extra == "docs"


=====================
Flaskcord
=====================

.. image:: https://img.shields.io/pypi/v/flaskcord?style=for-the-badge
   :target: https://pypi.org/project/flaskcord/

.. image:: https://img.shields.io/readthedocs/flaskcord?style=for-the-badge
   :target: https://flaskcord.readthedocs.io/en/latest/

.. image:: https://img.shields.io/discord/1258233857358958633?label=Vinny%20Support%20Server&logo=Discord&style=for-the-badge
   :target: https://discord.gg/FgyJJV24XF

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

Installation
============

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

.. code-block:: sh

   python3 -m pip install flaskcord

Basic Example
=============

.. code-block:: python

   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. 

.. _documentation: https://flaskcord.readthedocs.io/en/latest/
