Skip to content

Commit 9ab8deb

Browse files
authored
Merge pull request #110 from anxdpanic/pr_isengard
add oauth2 token validation used with helix api
2 parents ecd5fb3 + 66a2685 commit 9ab8deb

4 files changed

Lines changed: 44 additions & 1 deletion

File tree

resources/lib/twitch/api/helix/streams.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,17 @@ def get_streams(game_id=list(), user_id=list(),
3838
return q
3939

4040

41+
# required scope: user:read:follows
42+
@query
43+
def get_followed(user_id, after='MA==', first=20, use_app_token=False):
44+
q = Qry('streams', use_app_token=use_app_token)
45+
q.add_param(keys.AFTER, Cursor.validate(after), 'MA==')
46+
q.add_param(keys.FIRST, IntRange(1, 100).validate(first), 20)
47+
q.add_param(keys.USER_ID, user_id)
48+
49+
return q
50+
51+
4152
# required scope: none
4253
@query
4354
def get_metadata(game_id=list(), user_id=list(),

resources/lib/twitch/oauth/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@
99
See LICENSES/GPL-3.0-only for more information.
1010
"""
1111

12-
__all__ = ['v5', 'default', 'helix', 'clients']
12+
__all__ = ['v5', 'default', 'helix', 'clients', 'validation']
1313

1414
from . import v5 # V5 is deprecated and will be removed entirely on TBD
1515
from . import helix
1616
from . import v5 as default
1717
from . import clients
18+
from . import validation
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# -*- encoding: utf-8 -*-
2+
"""
3+
4+
Copyright (C) 2022 script.module.python.twitch
5+
6+
This file is part of script.module.python.twitch
7+
8+
SPDX-License-Identifier: GPL-3.0-only
9+
See LICENSES/GPL-3.0-only for more information.
10+
"""
11+
12+
from ..queries import OAuthValidationQuery as Qry
13+
from ..queries import query
14+
15+
16+
@query
17+
def validate(token=None):
18+
q = Qry(token)
19+
return q

resources/lib/twitch/queries.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
_uploads_baseurl = 'https://uploads.twitch.tv/'
2929
_gql_baseurl = 'https://gql.twitch.tv/gql'
3030
_oauth_baseurl = 'https://api.twitch.tv/kraken/oauth2/'
31+
_oauthid_baseurl = 'https://id.twitch.tv/oauth2/'
3132

3233

3334
class _Query(object):
@@ -196,6 +197,17 @@ def __init__(self, path, headers={}, data={}, method=methods.GET):
196197
self.add_path(path)
197198

198199

200+
class OAuthValidationQuery(JsonQuery):
201+
def __init__(self, token=None):
202+
_headers = {}
203+
if token:
204+
_headers['Authorization'] = token
205+
if 'Authorization' not in _headers:
206+
_headers.setdefault('Authorization', 'OAuth {access_token}'.format(access_token=OAUTH_TOKEN))
207+
super(JsonQuery, self).__init__(_oauthid_baseurl, _headers, {}, methods.GET)
208+
self.add_path('validate')
209+
210+
199211
class ClipsQuery(JsonQuery):
200212
def __init__(self, path='', headers={}, data={}, method=methods.POST):
201213
_headers = deepcopy(headers)

0 commit comments

Comments
 (0)