This repository has been archived by the owner on Apr 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 392
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dbef692
commit 1c3633f
Showing
290 changed files
with
28,985 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule map
updated
from 05a3f1 to b9627b
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
""" | ||
pgoapi - Pokemon Go API | ||
Copyright (c) 2016 tjado <https://github.com/tejado> | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | ||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR | ||
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE | ||
OR OTHER DEALINGS IN THE SOFTWARE. | ||
Author: tjado <https://github.com/tejado> | ||
""" | ||
|
||
from __future__ import absolute_import | ||
|
||
from pgoapi.exceptions import PleaseInstallProtobufVersion3 | ||
|
||
import pkg_resources | ||
import logging | ||
|
||
__title__ = 'pgoapi' | ||
__version__ = '1.1.7' | ||
__author__ = 'tjado' | ||
__license__ = 'MIT License' | ||
__copyright__ = 'Copyright (c) 2016 tjado <https://github.com/tejado>' | ||
|
||
protobuf_exist = False | ||
protobuf_version = 0 | ||
try: | ||
protobuf_version = pkg_resources.get_distribution("protobuf").version | ||
protobuf_exist = True | ||
except: | ||
pass | ||
|
||
if (not protobuf_exist) or (int(protobuf_version[:1]) < 3): | ||
raise PleaseInstallProtobufVersion3() | ||
|
||
from pgoapi.pgoapi import PGoApi | ||
from pgoapi.rpc_api import RpcApi | ||
from pgoapi.auth import Auth | ||
|
||
logging.getLogger("pgoapi").addHandler(logging.NullHandler()) | ||
logging.getLogger("rpc_api").addHandler(logging.NullHandler()) | ||
logging.getLogger("utilities").addHandler(logging.NullHandler()) | ||
logging.getLogger("auth").addHandler(logging.NullHandler()) | ||
logging.getLogger("auth_ptc").addHandler(logging.NullHandler()) | ||
logging.getLogger("auth_google").addHandler(logging.NullHandler()) | ||
|
||
try: | ||
import requests.packages.urllib3 | ||
requests.packages.urllib3.disable_warnings() | ||
except: | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
""" | ||
pgoapi - Pokemon Go API | ||
Copyright (c) 2016 tjado <https://github.com/tejado> | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | ||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR | ||
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE | ||
OR OTHER DEALINGS IN THE SOFTWARE. | ||
Author: tjado <https://github.com/tejado> | ||
""" | ||
|
||
from __future__ import absolute_import | ||
|
||
import logging | ||
from pgoapi.utilities import get_time, get_format_time_diff | ||
|
||
class Auth: | ||
|
||
def __init__(self): | ||
self.log = logging.getLogger(__name__) | ||
|
||
self._auth_provider = None | ||
|
||
self._login = False | ||
|
||
""" | ||
oauth2 uses refresh tokens (which basically never expires) | ||
to get an access_token which is only valid for a certain time) | ||
""" | ||
self._refresh_token = None | ||
self._access_token = None | ||
self._access_token_expiry = 0 | ||
# TODO: can be removed | ||
self._auth_token = None | ||
|
||
""" | ||
Pokemon Go uses internal tickets, like an internal | ||
session to keep a user logged in over a certain time (30 minutes) | ||
""" | ||
self._ticket_expire = None | ||
self._ticket_start = None | ||
self._ticket_end = None | ||
|
||
def get_name(self): | ||
return self._auth_provider | ||
|
||
def is_login(self): | ||
return self._login | ||
|
||
def get_token(self): | ||
return self._access_token | ||
|
||
def has_ticket(self): | ||
if self._ticket_expire and self._ticket_start and self._ticket_end: | ||
return True | ||
else: | ||
return False | ||
|
||
def set_ticket(self, params): | ||
self._ticket_expire, self._ticket_start, self._ticket_end = params | ||
|
||
def is_new_ticket(self, new_ticket_time_ms): | ||
if self._ticket_expire is None or new_ticket_time_ms > self._ticket_expire: | ||
return True | ||
else: | ||
return False | ||
|
||
def check_ticket(self): | ||
if self.has_ticket(): | ||
now_ms = get_time(ms = True) | ||
if now_ms < (self._ticket_expire - 10000): | ||
h, m, s = get_format_time_diff(now_ms, self._ticket_expire, True) | ||
self.log.debug('Session Ticket still valid for further %02d:%02d:%02d hours (%s < %s)', h, m, s, now_ms, self._ticket_expire) | ||
return True | ||
else: | ||
self.log.debug('Removed expired Session Ticket (%s < %s)', now_ms, self._ticket_expire) | ||
self._ticket_expire, self._ticket_start, self._ticket_end = (None, None, None) | ||
return False | ||
else: | ||
return False | ||
|
||
def get_ticket(self): | ||
if self.check_ticket(): | ||
return (self._ticket_expire, self._ticket_start, self._ticket_end) | ||
else: | ||
return False | ||
|
||
def user_login(self, username, password): | ||
raise NotImplementedError() | ||
|
||
def set_refresh_token(self, username, password): | ||
raise NotImplementedError() | ||
|
||
def get_access_token(self, force_refresh = False): | ||
raise NotImplementedError() | ||
|
||
|
||
def check_access_token(self): | ||
""" | ||
Add few seconds to now so the token get refreshed | ||
before it invalidates in the middle of the request | ||
""" | ||
now_s = get_time() + 120 | ||
|
||
if self._access_token is not None: | ||
if self._access_token_expiry == 0: | ||
self.log.debug('No Access Token Expiry found - assuming it is still valid!') | ||
return True | ||
elif self._access_token_expiry > now_s: | ||
h, m, s = get_format_time_diff(now_s, self._access_token_expiry, False) | ||
self.log.debug('Access Token still valid for further %02d:%02d:%02d hours (%s < %s)', h, m, s, now_s, self._access_token_expiry) | ||
return True | ||
else: | ||
self.log.info('Access Token expired!') | ||
return False | ||
else: | ||
self.log.debug('No Access Token available!') | ||
return False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
""" | ||
pgoapi - Pokemon Go API | ||
Copyright (c) 2016 tjado <https://github.com/tejado> | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | ||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR | ||
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE | ||
OR OTHER DEALINGS IN THE SOFTWARE. | ||
Author: tjado <https://github.com/tejado> | ||
""" | ||
|
||
from __future__ import absolute_import | ||
|
||
import six | ||
import logging | ||
|
||
from pgoapi.auth import Auth | ||
from pgoapi.exceptions import AuthException | ||
from gpsoauth import perform_master_login, perform_oauth | ||
|
||
class AuthGoogle(Auth): | ||
|
||
GOOGLE_LOGIN_ANDROID_ID = '9774d56d682e549c' | ||
GOOGLE_LOGIN_SERVICE= 'audience:server:client_id:848232511240-7so421jotr2609rmqakceuu1luuq0ptb.apps.googleusercontent.com' | ||
GOOGLE_LOGIN_APP = 'com.nianticlabs.pokemongo' | ||
GOOGLE_LOGIN_CLIENT_SIG = '321187995bc7cdc2b5fc91b11a96e2baa8602c62' | ||
|
||
def __init__(self): | ||
Auth.__init__(self) | ||
|
||
self._auth_provider = 'google' | ||
self._refresh_token = None | ||
self._proxy = None | ||
|
||
def set_proxy(self, proxy_config): | ||
self._proxy = proxy_config | ||
|
||
def user_login(self, username, password): | ||
self.log.info('Google User Login for: {}'.format(username)) | ||
|
||
if not isinstance(username, six.string_types) or not isinstance(password, six.string_types): | ||
raise AuthException("Username/password not correctly specified") | ||
|
||
user_login = perform_master_login(username, password, self.GOOGLE_LOGIN_ANDROID_ID, proxy=self._proxy) | ||
|
||
try: | ||
refresh_token = user_login.get('Token', None) | ||
except ConnectionError as e: | ||
raise AuthException("Caught ConnectionError: %s", e) | ||
|
||
if refresh_token is not None: | ||
self._refresh_token = refresh_token | ||
self.log.info('Google User Login successful.') | ||
else: | ||
self._refresh_token = None | ||
raise AuthException("Invalid Google Username/password") | ||
|
||
self.get_access_token() | ||
return self._login | ||
|
||
def set_refresh_token(self, refresh_token): | ||
self.log.info('Google Refresh Token provided by user') | ||
self._refresh_token = refresh_token | ||
|
||
def get_access_token(self, force_refresh = False): | ||
token_validity = self.check_access_token() | ||
|
||
if token_validity is True and force_refresh is False: | ||
self.log.debug('Using cached Google Access Token') | ||
return self._access_token | ||
else: | ||
if force_refresh: | ||
self.log.info('Forced request of Google Access Token!') | ||
else: | ||
self.log.info('Request Google Access Token...') | ||
|
||
token_data = perform_oauth(None, self._refresh_token, self.GOOGLE_LOGIN_ANDROID_ID, self.GOOGLE_LOGIN_SERVICE, self.GOOGLE_LOGIN_APP, | ||
self.GOOGLE_LOGIN_CLIENT_SIG, proxy=self._proxy) | ||
|
||
access_token = token_data.get('Auth', None) | ||
if access_token is not None: | ||
self._access_token = access_token | ||
self._access_token_expiry = int(token_data.get('Expiry', 0)) | ||
self._login = True | ||
|
||
self.log.info('Google Access Token successfully received.') | ||
self.log.debug('Google Access Token: %s...', self._access_token[:25]) | ||
return self._access_token | ||
else: | ||
self._access_token = None | ||
self._login = False | ||
raise AuthException("Could not receive a Google Access Token") |
Oops, something went wrong.