diff --git a/webapp/configurations.py b/webapp/configurations.py index 1fed45e..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", token_redirect_url = f'{request.url_root[:-1]}{url_for('twitchReceiveToken')}') diff --git a/webapp/twitch_auth.py b/webapp/twitch_auth.py index fdfdde2..4994f81 100644 --- a/webapp/twitch_auth.py +++ b/webapp/twitch_auth.py @@ -1,6 +1,6 @@ import logging -from flask import request, redirect, url_for +from flask import render_template, request, redirect, url_for from twitchAPI.twitch import Twitch from twitchAPI.type import TwitchAPIException from twitchAPI.oauth import UserAuthenticator @@ -13,13 +13,16 @@ 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 - url = f'{request.url_root[:-1]}{url_for('twitchReceiveToken')}' helper = ConfigurationHelper() twitch = await Twitch(helper.getValue('twitch_client_id'), helper.getValue('twitch_client_secret')) - auth = UserAuthenticator(twitch, USER_SCOPE, url=url) + auth = UserAuthenticator(twitch, USER_SCOPE, url=_buildUrl()) return redirect(auth.return_auth_url()) @webapp.route("/configurations/twitch/receive-token") @@ -43,3 +46,10 @@ async def twitchReceiveToken(): 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