From 5bd875cae9e207f4f67b822976b1f30d93496f64 Mon Sep 17 00:00:00 2001 From: thec0sm0s Date: Fri, 11 Sep 2020 10:20:48 +0530 Subject: [PATCH] =?UTF-8?q?=E2=9C=94=20Docs=20improvements?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- docs/introduction.rst | 25 ++++++++++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2e4ca7e..3df6c8e 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ from flask_discord import DiscordOAuth2Session, requires_authorization, Unauthor app = Flask(__name__) app.secret_key = b"random bytes representing flask secret key" -os.environ["OAUTHLIB_INSECURE_TRANSPORT"] = "true" # !! Only in development environment. +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. diff --git a/docs/introduction.rst b/docs/introduction.rst index cf9d09a..bc8482b 100644 --- a/docs/introduction.rst +++ b/docs/introduction.rst @@ -54,8 +54,8 @@ in exchange for fetching user's details and display them on web page. app = Flask(__name__) app.secret_key = b"random bytes representing flask secret key" - os.environ["OAUTHLIB_INSECURE_TRANSPORT"] = "true" # !! Only in development environment. # OAuth2 must make use of HTTPS in production environment. + 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. @@ -99,3 +99,26 @@ in exchange for fetching user's details and display them on web page. if __name__ == "__main__": app.run() + +**Lazy initialization with flask factory pattern** + +.. code-block:: python3 + + from flask_discord import DiscordOAuth2Session + + discord = DiscordOAuth2Session() + + def get_app(): + app = Flask(__name__) + + app.secret_key = b"random bytes representing flask secret key" + # OAuth2 must make use of HTTPS in production environment. + 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.init_app(app) + + return app