Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from flask import Flask, redirect, url_for, render_template
- from flask_discord import DiscordOAuth2Session, requires_authorization, Unauthorized
- import os
- os.environ["OAUTHLIB_INSECURE_TRANSPORT"] = "1"
- app = Flask(__name__)
- app.secret_key = 'YOUR-APP-SECRET'
- app.config["DISCORD_CLIENT_ID"] = 0123456789
- app.config["DISCORD_CLIENT_SECRET"] = 'YOUR-CLIENT-SECRET'
- app.config["DISCORD_REDIRECT_URI"] = 'http://localhost:5000/callback'
- discord = DiscordOAuth2Session(app)
- @app.route('/')
- def home():
- return render_template('home.html')
- @app.route('/login')
- def login():
- return discord.create_session(scope=["identify", "email"])
- @app.route('/callback')
- def callback():
- discord.callback()
- return redirect(url_for("dashboard"))
- @app.route('/dashboard')
- @requires_authorization
- def dashboard():
- user = discord.fetch_user()
- return render_template('dash.html', user=user)
- @app.errorhandler(Unauthorized)
- def redirect_unauthorized(e):
- return redirect(url_for("login"))
- if __name__ == "__main__":
- app.run(debug=True)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement