This repository has been archived by the owner on Dec 15, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 472
Improve headers, add locale #211
Open
michikrug
wants to merge
2
commits into
pogodevorg:develop
Choose a base branch
from
michikrug:PR-headers
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,21 +40,33 @@ | |
|
||
class AuthPtc(Auth): | ||
|
||
PTC_LOGIN_URL1 = 'https://sso.pokemon.com/sso/oauth2.0/authorize?client_id=mobile-app_pokemon-go&redirect_uri=https%3A%2F%2Fwww.nianticlabs.com%2Fpokemongo%2Ferror' | ||
PTC_LOGIN_URL2 = 'https://sso.pokemon.com/sso/login?service=http%3A%2F%2Fsso.pokemon.com%2Fsso%2Foauth2.0%2FcallbackAuthorize' | ||
PTC_LOGIN_URL1 = 'https://sso.pokemon.com/sso/oauth2.0/authorize' | ||
PTC_LOGIN_URL2 = 'https://sso.pokemon.com/sso/login' | ||
PTC_LOGIN_OAUTH = 'https://sso.pokemon.com/sso/oauth2.0/accessToken' | ||
PTC_LOGIN_CLIENT_SECRET = 'w8ScCUXJQc6kXKw8FiOhd8Fixzht18Dq3PEVkUCP5ZPxtgyWsbTvWHFLm2wNY0JR' | ||
|
||
def __init__(self, username=None, password=None, user_agent=None, timeout=None): | ||
def __init__(self, username=None, password=None, user_agent=None, timeout=None, locale=None): | ||
Auth.__init__(self) | ||
|
||
self._auth_provider = 'ptc' | ||
|
||
self._session = requests.session() | ||
self._session.headers = {'User-Agent': user_agent or 'pokemongo/1 CFNetwork/811.4.18 Darwin/16.5.0', 'Host': 'sso.pokemon.com', 'X-Unity-Version': '5.5.1f1'} | ||
self._username = username | ||
self._password = password | ||
self.timeout = timeout or 15 | ||
|
||
self.locale = locale or 'en_US' | ||
self.timeout = timeout or 10 | ||
|
||
self._session = requests.session() | ||
|
||
self._session.headers = { | ||
'Accept': '*/*', | ||
'Host': 'sso.pokemon.com', | ||
'Connection': 'keep-alive', | ||
'User-Agent': user_agent or 'pokemongo/1 CFNetwork/811.4.18 Darwin/16.5.0', | ||
'Accept-Language': self.locale.lower().replace('_', '-'), | ||
'Accept-Encoding': 'gzip-deflate', | ||
'X-Unity-Version': '5.5.1f1' | ||
} | ||
|
||
def set_proxy(self, proxy_config): | ||
self._session.proxies = proxy_config | ||
|
@@ -70,7 +82,7 @@ def user_login(self, username=None, password=None, retry=True): | |
now = get_time() | ||
|
||
try: | ||
r = self._session.get(self.PTC_LOGIN_URL1, timeout=self.timeout) | ||
r = self._session.get(self.PTC_LOGIN_URL1, params={'client_id': 'mobile-app_pokemon-go', 'redirect_uri': 'https://www.nianticlabs.com/pokemongo/error', 'locale': self.locale}, timeout=self.timeout) | ||
except Timeout: | ||
raise AuthTimeoutException('Auth GET timed out.') | ||
except RequestException as e: | ||
|
@@ -82,13 +94,14 @@ def user_login(self, username=None, password=None, retry=True): | |
'_eventId': 'submit', | ||
'username': self._username, | ||
'password': self._password, | ||
'locale': self.locale | ||
}) | ||
except (ValueError, AttributeError) as e: | ||
self.log.error('PTC User Login Error - invalid JSON response: {}'.format(e)) | ||
raise AuthException('Invalid JSON response: {}'.format(e)) | ||
|
||
try: | ||
r = self._session.post(self.PTC_LOGIN_URL2, data=data, timeout=self.timeout, allow_redirects=False) | ||
r = self._session.post(self.PTC_LOGIN_URL2, params={'service': 'http://sso.pokemon.com/sso/oauth2.0/callbackAuthorize'}, headers={'Content-Type': 'application/x-www-form-urlencoded'}, data=data, timeout=self.timeout, allow_redirects=False) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here |
||
except Timeout: | ||
raise AuthTimeoutException('Auth POST timed out.') | ||
except RequestException as e: | ||
|
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make these params a variable, like in the other changes