|
2 | 2 |
|
3 | 3 | from twitch import CLIENT_ID |
4 | 4 | from twitch import scopes |
5 | | -from oauthlib.oauth2 import MobileApplicationClient |
| 5 | +from six.moves.urllib_parse import urlsplit, urlencode |
6 | 6 |
|
7 | 7 |
|
8 | 8 | class MobileClient: |
9 | 9 | _auth_base_url = 'https://api.twitch.tv/kraken/oauth2/authorize' |
10 | 10 |
|
11 | 11 | def __init__(self, client_id=''): |
12 | 12 | self.client_id = client_id if client_id else CLIENT_ID |
13 | | - self.client = MobileApplicationClient(client_id=client_id) |
14 | | - self.parse_request_uri_response = self.client.parse_request_uri_response |
15 | 13 |
|
16 | | - def prepare_request_uri(self, redirect_uri='http://localhost:3000/', scope=list()): |
17 | | - return self.client.prepare_request_uri(self._auth_base_url, redirect_uri=redirect_uri, scope=scope) |
| 14 | + def prepare_request_uri(self, redirect_uri='http://localhost:3000/', scope=list(), force_verify=False, state=''): |
| 15 | + params = {'response_type': 'token', |
| 16 | + 'client_id': self.client_id, |
| 17 | + 'redirect_uri': redirect_uri, |
| 18 | + 'scope': ' '.join(scope), |
| 19 | + 'force_verify': str(force_verify).lower(), |
| 20 | + 'state': state} |
| 21 | + params = urlencode(params) |
| 22 | + url = '{base_uri}?{params}'.format(base_uri=self._auth_base_url, params=params) |
| 23 | + return url |
| 24 | + |
| 25 | + @staticmethod |
| 26 | + def parse_implicit_response(url): |
| 27 | + pairs = urlsplit(url).fragment.split('&') |
| 28 | + fragment = dict() |
| 29 | + for pair in pairs: |
| 30 | + key, value = pair.split('=') |
| 31 | + fragment[key] = value |
| 32 | + return {'access_token': fragment.get('access_token'), 'scope': fragment.get('scope', '').split('+'), 'state': fragment.get('state')} |
0 commit comments