Skip to content

Commit 1355f09

Browse files
committed
Merge commit '1901846d4f50b431cd3cd7af2298c41eff06110a'
2 parents 7784000 + 1901846 commit 1355f09

File tree

6 files changed

+25
-9
lines changed

6 files changed

+25
-9
lines changed

backend/flask/app/__init__.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
from flask_migrate import Migrate
44
from flask_restful import Api
55
from flask_sqlalchemy import SQLAlchemy
6-
from twitch import TwitchClient
6+
from twitch import TwitchHelix
7+
from twitch.constants import OAUTH_SCOPE_USER_READ_EMAIL
78

89
from . import config as config
9-
from .consts import TWITCH_EXTENSION_CLIENT_ID
10+
from .consts import TWITCH_EXTENSION_CLIENT_ID, TWITCH_EXTENSION_CLIENT_SECRET
1011

1112
app = Flask(__name__, static_folder='/frontend/dist/static', template_folder='/frontend/dist')
1213
app.config.from_object(config)
@@ -15,7 +16,11 @@
1516
migrate = Migrate(app, db)
1617
cors = CORS(app)
1718

18-
twitchClient = TwitchClient(client_id=TWITCH_EXTENSION_CLIENT_ID)
19+
twitchClient = TwitchHelix(
20+
client_id=TWITCH_EXTENSION_CLIENT_ID,
21+
client_secret=TWITCH_EXTENSION_CLIENT_SECRET,
22+
scopes=[OAUTH_SCOPE_USER_READ_EMAIL]
23+
)
1924

2025
from . import models
2126
from . import apis

backend/flask/app/apis/common.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,14 @@ def update_twitch_rc(decoded_token, twitch_extension_version, rc):
7575
}
7676
token = jwt.encode(token_data, TWITCH_EXTENSION_SECRET).decode("utf-8")
7777

78-
url = 'https://api.twitch.tv/extensions/' + TWITCH_EXTENSION_CLIENT_ID + '/' + \
79-
twitch_extension_version + '/required_configuration?channel_id=' + decoded_token['channel_id']
78+
url = 'https://api.twitch.tv/helix/extensions/required_configuration?broadcaster_id=' + decoded_token['channel_id']
8079

8180
r = None
8281
try:
8382
r = requests.put(url, data={
84-
'required_configuration': ','.join(rc) if rc else 'nope'
83+
'required_configuration': ','.join(rc) if rc else 'nope',
84+
'extension_id': TWITCH_EXTENSION_CLIENT_ID,
85+
'extension_version': twitch_extension_version,
8586
}, headers={
8687
'Authorization': 'Bearer ' + token,
8788
'Client-Id': TWITCH_EXTENSION_CLIENT_ID

backend/flask/app/consts.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from datetime import timedelta
44

55
TWITCH_EXTENSION_SECRET = base64.b64decode(os.environ['TWITCH_EXTENSION_SECRET'])
6+
TWITCH_EXTENSION_CLIENT_SECRET = os.environ['TWITCH_EXTENSION_CLIENT_SECRET']
67
TWITCH_EXTENSION_CLIENT_ID = os.environ['TWITCH_EXTENSION_CLIENT_ID']
78
TWITCH_EXTENSION_VERSION = os.environ['TWITCH_EXTENSION_VERSION']
89
TWITCH_EXTENSION_OWNER_ID = os.environ['TWITCH_EXTENSION_OWNER_ID']

backend/flask/app/utils.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
from . import twitchClient
2+
from requests.exceptions import RequestException
23

34

45
def twitch_channel_name_to_id(channel_name):
5-
channels = twitchClient.users.translate_usernames_to_ids([channel_name])
6+
try:
7+
channels = twitchClient.get_users(login_names=channel_name)
8+
except RequestException as e:
9+
if e.response.status_code != 401:
10+
raise e
11+
twitchClient.get_oauth()
12+
channels = twitchClient.get_users(login_names=channel_name)
13+
614
if channels and len(channels) > 0:
715
channel = channels[0]
816
return channel.id

backend/flask/requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ Flask-RESTful==0.3.8
66
flask-cors==3.0.3
77
psycopg2==2.7.3
88
PyJWT==1.5.2
9-
requests==2.18.4
9+
requests==2.27.1
1010
uWSGI==2.0.15
11-
python-twitch-client==0.3.0
11+
python-twitch-client==0.7.1

settings.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
API_HOSTNAME=localhost:8088
22
POSTGRES_PASSWORD=passwordpassworpasswopasswpasspaspap
33
TWITCH_EXTENSION_SECRET=asdf
4+
TWITCH_EXTENSION_CLIENT_SECRET=asdf
45
TWITCH_EXTENSION_CLIENT_ID=asdf
56
TWITCH_EXTENSION_VERSION=0.0.1
67
TWITCH_EXTENSION_OWNER_ID=0

0 commit comments

Comments
 (0)