From 4de664eadc63578f6ee8d1200a9eb916807382ed Mon Sep 17 00:00:00 2001 From: alexvanin Date: Sat, 16 May 2020 10:55:32 +0300 Subject: [PATCH] api: Add oath token to the request header --- .gitignore | 2 ++ main.py | 6 ++++-- twitch.py | 6 ++++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index b2f3174..31f6707 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,7 @@ __pycache__ *.swp .token +.oath +.secret server.conf .*.log diff --git a/main.py b/main.py index d16578d..8ab175c 100755 --- a/main.py +++ b/main.py @@ -5,7 +5,7 @@ import cherrypy from cherrypy.process.plugins import Daemonizer from twitch import TwitchClient -ver = '1.9-pre' +ver = '1.9.0-pre-2' class FleastServer(object): @@ -13,6 +13,8 @@ class FleastServer(object): try: with open('.token', 'r') as reader: self.twitch_token = reader.read().strip() + with open('.oath', 'r') as reader: + self.oath_token = reader.read().strip() with open('./web/fl.html', 'r') as reader: self.index_page = reader.read() with open('./web/fl_template_main.html', 'r') as reader: @@ -21,7 +23,7 @@ class FleastServer(object): self.templ_stream = reader.read() with open('./web/fl_template_lang.html', 'r') as reader: self.templ_lang = reader.read().splitlines() - self.client = TwitchClient(self.twitch_token, freq=1) + self.client = TwitchClient(self.twitch_token, self.oath_token, freq=1) except: print("Cannot read token for twitch app or templates, abort.") exit(1) diff --git a/twitch.py b/twitch.py index e867920..2aa92c9 100644 --- a/twitch.py +++ b/twitch.py @@ -6,13 +6,15 @@ from urllib.parse import quote class TwitchClient: - def __init__(self, token, freq=2): + def __init__(self, token, oath, freq=2): self.token = token + self.oath = oath self.lock = threading.Lock() self.header_v5 = {'Client-ID': self.token, + 'Authorization': 'Bearer ' + self.oath, 'Accept': 'application/vnd.twitchtv.v5+json'} - self.header_v6 = {'Client-ID': self.token} + self.header_v6 = {'Client-ID': self.token, 'Authorization': 'Bearer '+self.oath} self.urlbase_v5 = 'https://api.twitch.tv/kraken' self.urlbase_v6 = 'https://api.twitch.tv/helix'