Skip to content

Commit

Permalink
Allow missing scope in token response (#245)
Browse files Browse the repository at this point in the history
  • Loading branch information
felix-hilden committed Mar 7, 2021
1 parent a5f58f3 commit 131df27
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
7 changes: 7 additions & 0 deletions docs/src/release_notes.rst
Expand Up @@ -3,6 +3,13 @@

Release notes
=============
Unreleased
----------
Fixed
*****
- :ref:`auth` - allow missing scope in token responses and parse it to
an empty :class:`Scope` (:issue:`245`)

3.6.0 (2021-03-02)
------------------
Added
Expand Down
8 changes: 5 additions & 3 deletions tekore/_auth/expiring/token.py
Expand Up @@ -36,9 +36,11 @@ def __init__(self, token_info: dict, uses_pkce: bool):
self._access_token = token_info['access_token']
self._token_type = token_info['token_type']

self._scope = Scope(*token_info['scope'].split(' '))
if str(self._scope) == '':
self._scope = Scope()
scope = token_info.get('scope', '')
components = scope.split(' ')
if components[0] == '':
components = []
self._scope = Scope(*components)

self._refresh_token = token_info.get('refresh_token', None)
self._expires_at = int(time.time()) + token_info['expires_in']
Expand Down
4 changes: 4 additions & 0 deletions tests/auth/expiring.py
Expand Up @@ -97,24 +97,28 @@ def test_request_client_token(self, app_env):
c = Credentials(app_env[0], app_env[1])
token = c.request_client_token()
assert token.refresh_token is None
assert str(token.scope) == ''

@pytest.mark.asyncio
async def test_async_request_client_token(self, app_env):
c = Credentials(app_env[0], app_env[1], asynchronous=True)
token = await c.request_client_token()
assert token.refresh_token is None
assert str(token.scope) == ''
await c.close()

def test_refresh_user_token(self, app_env, user_refresh):
c = Credentials(app_env[0], app_env[1])
token = c.refresh_user_token(user_refresh)
assert token.refresh_token is not None
assert len(token.scope) > 0

@pytest.mark.asyncio
async def test_async_refresh_user_token(self, app_env, user_refresh):
c = Credentials(app_env[0], app_env[1], asynchronous=True)
token = await c.refresh_user_token(user_refresh)
assert token.refresh_token is not None
assert len(token.scope) > 0
await c.close()

def test_bad_arguments_raises_error(self):
Expand Down

0 comments on commit 131df27

Please sign in to comment.