Skip to content

Commit

Permalink
fix get code from npsso
Browse files Browse the repository at this point in the history
  • Loading branch information
Swilder-M committed Mar 22, 2023
1 parent 51e9024 commit aff2a3a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@
gist_content = ''
for record in show_records[:5]:
line = [
truncate_strings(record['name'], 18).ljust(18),
record['playDuration'].ljust(15),
generate_bar_chart(record['progress'], 14),
truncate_strings(record['name'], 17).ljust(18),
record['playDuration'].ljust(16),
generate_bar_chart(record['progress'], 13),
str(record['progress']).rjust(3) + '%'
]
line = ' '.join(line)
Expand Down
11 changes: 7 additions & 4 deletions src/psn.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@ def __init__(self,

def requester(self, method, api, **kwargs):
headers = kwargs.get('headers', {})
if not headers.get('Authorization'):
if not headers.get('Authorization') and self.access_token:
headers['Authorization'] = f'Bearer {self.access_token}'
if not headers.get('Content-Type'):
headers['Content-Type'] = 'application/json'
if not headers.get('Accept-Language'):
headers['Accept-Language'] = self.language
if not headers.get('User-Agent'):
headers['User-Agent'] = 'PlayStation/21090100 CFNetwork/1126 Darwin/19.5.0'
kwargs['headers'] = headers

if api.startswith('oauth/'):
Expand Down Expand Up @@ -103,8 +105,8 @@ def refresh_access_token(self):

def get_access_token_from_npsso(self):
if not self.npsso:
raise Exception('No npsso code')

raise Exception('No npsso code, you should get a new one from '
'https://ca.account.sony.com/api/v1/ssocookie')
params = {
'access_type': 'offline',
'client_id': '09515159-7237-4370-9b40-3806e67c0891',
Expand All @@ -116,7 +118,8 @@ def get_access_token_from_npsso(self):
resp = self.requester(method='GET', api='oauth/authorize',
params=params, cookies=cookies, allow_redirects=False)
if resp.status_code != 302:
raise Exception('Invalid npsso code, you should get a new one from https://ca.account.sony.com/api/v1/ssocookie')
raise Exception('Invalid npsso code, you should get a new one from '
'https://ca.account.sony.com/api/v1/ssocookie')
code = resp.headers['Location'].split('code=')[1].split('&')[0]

data = {
Expand Down

0 comments on commit aff2a3a

Please sign in to comment.