A library to make the discord authentication system easier for Quart Users
Project description
#Quart-OAuth2-Discord.py
A library to make the discord authentication system easier for Quart Users.
To install this library:
$ python3 -m pip install Quart-OAuth2-Discord.py
If you're in Windows:
python -m pip install Quart-OAuth2-Discord.py
An example of Quart-app-with-Discord-Bot
from typing import List
from quart import Quart, redirect, render_template_string, request, url_for
from quart_oauth2_discord_py import DiscordOauth2Client, Guild
app = Quart(__name__)
app.secret_key = b"random bytes representing quart secret key"
app.config['DISCORD_CLIENT_ID'] = "Client ID here"
app.config['DISCORD_CLIENT_SECRET'] = 'CLIENT_SECRET_HERE'
app.config['SCOPES'] = ['identify', 'guilds']
app.config['DISCORD_REDIRECT_URI'] = 'http://127.0.0.1:5000/callback'
app.config['DISCORD_BOT_TOKEN'] = None
client = DiscordOauth2Client(app)
@app.route('/')
async def index():
return "Hello!"
@app.route('/login/', methods=['GET'])
async def login():
return await client.create_session()
@app.route('/callback')
async def callback():
await client.callback()
return redirect(url_for('index'))
def return_guild_names_owner(guilds_: List[Guild]):
# print(list(sorted([fetch_guild.name for fetch_guild in guilds_ if fetch_guild.is_owner_of_guild()])))
return list(sorted([fetch_guild.name for fetch_guild in guilds_ if fetch_guild.is_owner_of_guild()]))
def search_guilds_for_name(guilds_, query):
# print(list(sorted([fetch_guild.name for fetch_guild in guilds_ if fetch_guild.is_owner_of_guild() and fetch_guild.name == query])))
return list(sorted([fetch_guild.name for fetch_guild in guilds_ if fetch_guild.is_owner_of_guild() and fetch_guild.name == query]))
@app.route('/guilds')
async def guilds():
template_string = """
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Guilds</title>
</head>
<body>
<h1>Your guilds: </h1>
<ol>
{% for guild_name in guild_names %}
<li>{{ guild_name }}</li>
{% endfor %}
</ol>
</body>
</html>
"""
if request.args.get('guild_name'):
return await render_template_string(template_string, guild_names=search_guilds_for_name(await client.fetch_guilds(), request.args.get('guild_name')))
return await render_template_string(template_string, guild_names=return_guild_names_owner(await client.fetch_guilds()))
@app.route('/me')
@client.is_logged_in
async def me():
user = await client.fetch_user()
image = user.avatar_url
# noinspection HtmlUnknownTarget
return await render_template_string("""
<html lang="en">
<body>
<p>Login Successful</p>
<img src="{{ image_url }}" alt="Avatar url">
</body>
</html>
""", image_url=image)
if __name__ == '__main__':
app.run()
This is not yet documented. It will be documented soon.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file Quart_OAuth2_Discord.py-0.1.0.tar.gz.
File metadata
- Download URL: Quart_OAuth2_Discord.py-0.1.0.tar.gz
- Upload date:
- Size: 6.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.0.10 CPython/3.9.0rc2 Windows/10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
caf6706a57fb4cd52e379deb9e8f6f11cbc43174b085b79a1120156f0f06568a
|
|
| MD5 |
ab5a0075eefff5df1bf3396531858953
|
|
| BLAKE2b-256 |
f934a0f9f07956026adf7ffda93533a03e8d6d9b452cd75f228b506a89114ca1
|
File details
Details for the file Quart_OAuth2_Discord.py-0.1.0-py3-none-any.whl.
File metadata
- Download URL: Quart_OAuth2_Discord.py-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.0.10 CPython/3.9.0rc2 Windows/10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
053b3ba369b4574d2d695f358bd233bdae191e9a3574befd3866efcad83eeb5b
|
|
| MD5 |
a3a063891208fd0ef54c24c9b4e22773
|
|
| BLAKE2b-256 |
4689300e7a87f1b6cd7b2bfe2ce81a8a5bb3e5b4a38a3c10afbc52fadee49345
|