diff --git a/README.md b/README.md index a68954d..ddfcf9b 100755 --- a/README.md +++ b/README.md @@ -91,7 +91,7 @@ Avant d'installer MamieHenriette, vous devez créer un bot Discord et obtenir so 3. **Configurer le bot** : - Dans le menu latéral, cliquez sur "Bot" - Ajoutez une photo de profil et un pseudo à votre bot - - **Important activez les intents** : + - **Important : activez les intents** : - ☑️ Presence Intent - ☑️ Server Members Intent - ☑️ Message Content Intent diff --git a/requirements.txt b/requirements.txt index 3271e08..0fe17e7 100755 --- a/requirements.txt +++ b/requirements.txt @@ -12,6 +12,7 @@ twitchAPI>=4.5.0 # Nécessaire pour l'hébergement du site web flask>=2.3.2 flask-sqlalchemy>=3.0.3 +flask[async] waitress>=3.0.2 # Nécessaire pour l'appel à l'API Humble Bundle diff --git a/webapp/__init__.py b/webapp/__init__.py index 8620413..c6f55d1 100644 --- a/webapp/__init__.py +++ b/webapp/__init__.py @@ -2,4 +2,4 @@ from flask import Flask webapp = Flask(__name__) -from webapp import commandes, configurations, index, humeurs, messages, moderation, protondb +from webapp import commandes, configurations, index, humeurs, messages, moderation, protondb, twitch_auth diff --git a/webapp/configurations.py b/webapp/configurations.py index 691629a..c795ad8 100644 --- a/webapp/configurations.py +++ b/webapp/configurations.py @@ -25,6 +25,3 @@ def updateConfiguration(): db.session.commit() return redirect(request.referrer) -@webapp.route("/configurations/twitch/help") -def twitchConfigurationHelp(): - return render_template("twitch-aide.html") diff --git a/webapp/static/img/twitch-api-01.jpg b/webapp/static/img/twitch-api-01.jpg index 08d3aa8..e66ad9f 100644 Binary files a/webapp/static/img/twitch-api-01.jpg and b/webapp/static/img/twitch-api-01.jpg differ diff --git a/webapp/static/img/twitch-api-02.jpg b/webapp/static/img/twitch-api-02.jpg index a878973..9c20cba 100644 Binary files a/webapp/static/img/twitch-api-02.jpg and b/webapp/static/img/twitch-api-02.jpg differ diff --git a/webapp/static/img/twitch-api-03.jpg b/webapp/static/img/twitch-api-03.jpg deleted file mode 100644 index 1bd71cf..0000000 Binary files a/webapp/static/img/twitch-api-03.jpg and /dev/null differ diff --git a/webapp/static/img/twitch-api-04.jpg b/webapp/static/img/twitch-api-04.jpg deleted file mode 100644 index 55ec373..0000000 Binary files a/webapp/static/img/twitch-api-04.jpg and /dev/null differ diff --git a/webapp/static/img/twitch-api-05.jpg b/webapp/static/img/twitch-api-05.jpg deleted file mode 100644 index c5bea6a..0000000 Binary files a/webapp/static/img/twitch-api-05.jpg and /dev/null differ diff --git a/webapp/templates/configurations.html b/webapp/templates/configurations.html index 05ceb02..c43917c 100644 --- a/webapp/templates/configurations.html +++ b/webapp/templates/configurations.html @@ -4,24 +4,20 @@
Configurez les tokens Discord, les notifications Humble Bundle et l'API ProtonDB pour la commande !protondb.
-Si vous créer un alias GTA : Grand Theft Auto alors si un utilisateur rentre la commande +
Si vous créez un alias GTA : Grand Theft Auto alors si un utilisateur rentre la commande !protondb GTA 5 cela fera une recherche sur Grand Theft Auto 5.
@@ -45,14 +45,14 @@ - + - +Pour trouver les clés, dans votre navigateur avec l'outil d'inspection ouvert (F12 ou clic droit > Inspecter l'élément dans Firefox/Chrome) faites une recherche de jeux sur protondb, - puis chercher les clés dans les requêtes (onglet Réseau/Network), + puis cherchez les clés dans les requêtes (onglet Réseau/Network), comme le montre cet exemple
diff --git a/webapp/templates/twitch-aide.html b/webapp/templates/twitch-aide.html index 11c1fab..e11aefb 100644 --- a/webapp/templates/twitch-aide.html +++ b/webapp/templates/twitch-aide.html @@ -3,14 +3,15 @@ {% block content %}- Avant toute chose, activez l'authentification à deux facteurs (2FA) : - Guide officiel Twitch pour la 2FA + Avant toute chose, activez l'authentification à deux facteurs (2FA) : + Guide officiel + Twitch pour la 2FA
Rendez-vous sur la console d'applications Twitch et ajoutez une application. Renseignez :
- Ensuite, rendez-vous sur twitchtokengenerator.com et - sélectionnez Custom Scope Target. Dans la section Use My Client Secret and Client - ID, renseignez les deux champs. + Ensuite, retournez sur la page de Configuration, après avoir + enregistré le Client ID et le Client Secret, cliquez sur le lien Obtenir + token et refresh token. Si tout se passe bien les champs Access Token et + Refresh Token sont remplis.
-
-
-- Ensuite, dans la section Available Token Scopes, cochez chat:read et chat:edit. - Puis, dans la même section, cliquez sur Generate token. -
- -
-
-- Suivez la procédure et vous avez votre Access Token et Refresh Token -
- -
-
-
{% endblock %}
\ No newline at end of file
diff --git a/webapp/twitch_auth.py b/webapp/twitch_auth.py
new file mode 100644
index 0000000..4994f81
--- /dev/null
+++ b/webapp/twitch_auth.py
@@ -0,0 +1,55 @@
+import logging
+
+from flask import render_template, request, redirect, url_for
+from twitchAPI.twitch import Twitch
+from twitchAPI.type import TwitchAPIException
+from twitchAPI.oauth import UserAuthenticator
+
+from database import db
+from database.helpers import ConfigurationHelper
+from twitchbot import USER_SCOPE
+from webapp import webapp
+
+
+auth: UserAuthenticator
+
+@webapp.route("/configurations/twitch/help")
+def twitchConfigurationHelp():
+ return render_template("twitch-aide.html", token_redirect_url = _buildUrl())
+
+@webapp.route("/configurations/twitch/request-token")
+async def twitchRequestToken():
+ global auth
+ helper = ConfigurationHelper()
+ twitch = await Twitch(helper.getValue('twitch_client_id'), helper.getValue('twitch_client_secret'))
+ auth = UserAuthenticator(twitch, USER_SCOPE, url=_buildUrl())
+ return redirect(auth.return_auth_url())
+
+@webapp.route("/configurations/twitch/receive-token")
+async def twitchReceiveToken():
+ global auth
+ state = request.args.get('state')
+ code = request.args.get('code')
+ if state != auth.state :
+ logging('bad returned state')
+ return redirect(url_for('openConfigurations'))
+ if code == None :
+ logging('no returned state')
+ return redirect(url_for('openConfigurations'))
+
+ try:
+ token, refresh = await auth.authenticate(user_token=code)
+ helper = ConfigurationHelper()
+ helper.createOrUpdate('twitch_access_token', token)
+ helper.createOrUpdate('twitch_refresh_token', refresh)
+ db.session.commit()
+ except TwitchAPIException as e:
+ logging(e)
+ return redirect(url_for('openConfigurations'))
+
+# hack pas fou mais on estime qu'on sera toujours en ssl en connecté
+def _buildUrl():
+ url = f'{request.url_root[:-1]}{url_for('twitchReceiveToken')}'
+ if url.find('localhost') != -1 : return url
+ url = url.replace('http://', 'https://')
+ return url