Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Serialize AT token_type and expose in result
  • Loading branch information
bgavrilMS committed Sep 23, 2019
commit 5fff3b4fd846def550d1ef9732edd60f6aac39e4
2 changes: 1 addition & 1 deletion msal/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ def _acquire_token_silent_from_cache_and_possibly_refresh_it(
logger.debug("Cache hit an AT")
return { # Mimic a real response
"access_token": entry["secret"],
"token_type": "Bearer",
"token_type": entry["token_type"] or "Bearer",
"expires_in": int(expires_in), # OAuth2 specs defines it as int
}
return self._acquire_token_silent_by_finding_rt_belongs_to_me_or_my_family(
Expand Down
5 changes: 3 additions & 2 deletions msal/token_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,11 @@ def __add(self, event, now=None):
"client_id": event.get("client_id"),
"target": target,
"realm": realm,
"token_type": response.get("token_type") or "Bearer",
"cached_at": str(now), # Schema defines it as a string
"expires_on": str(now + expires_in), # Same here
"extended_expires_on": str(now + ext_expires_in) # Same here
}
"extended_expires_on": str(now + ext_expires_in) # Same here
}
self.modify(self.CredentialType.ACCESS_TOKEN, at, at)

if client_info:
Expand Down
9 changes: 7 additions & 2 deletions tests/test_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,14 +167,18 @@ def setUp(self):
self.client_id = "my_app"
self.access_token = "access token for testing authority aliases"
self.cache = msal.SerializableTokenCache()
self.token_type = "some_other_token_type"
self.cache.add({
"client_id": self.client_id,
"scope": self.scopes,
"token_endpoint": "https://{}/common/oauth2/v2.0/token".format(
self.environment_in_cache),
"response": TokenCacheTestCase.build_response(
uid=uid, utid=utid,
access_token=self.access_token, refresh_token="some refresh token"),
uid=uid,
utid=utid,
access_token=self.access_token,
token_type=self.token_type,
refresh_token="some refresh token"),
}) # The add(...) helper populates correct home_account_id for future searching

def test_get_accounts(self):
Expand All @@ -193,4 +197,5 @@ def test_acquire_token_silent(self):
at = app.acquire_token_silent(self.scopes, self.account)
self.assertNotEqual(None, at)
self.assertEqual(self.access_token, at.get('access_token'))
self.assertEqual(self.token_type, at.get('token_type'))

6 changes: 4 additions & 2 deletions tests/test_token_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ def build_id_token(
@staticmethod
def build_response( # simulate a response from AAD
uid=None, utid=None, # If present, they will form client_info
access_token=None, expires_in=3600, token_type="some type",
access_token=None, expires_in=3600,
token_type="some type",
refresh_token=None,
foci=None,
id_token=None, # or something generated by build_id_token()
Expand Down Expand Up @@ -83,6 +84,7 @@ def testAddByAad(self):
'realm': 'contoso',
'secret': 'an access token',
'target': 's2 s1 s3',
'token_type': 'some type',
},
self.cache._cache["AccessToken"].get(
'uid.utid-login.example.com-accesstoken-my_client_id-contoso-s2 s1 s3')
Expand Down Expand Up @@ -155,6 +157,7 @@ def testAddByAdfs(self):
'realm': 'adfs',
'secret': 'an access token',
'target': 's2 s1 s3',
'token_type': 'some type',
},
self.cache._cache["AccessToken"].get(
'subject-fs.msidlab8.com-accesstoken-my_client_id-adfs-s2 s1 s3')
Expand Down Expand Up @@ -203,7 +206,6 @@ def testAddByAdfs(self):
"appmetadata-fs.msidlab8.com-my_client_id")
)


class SerializableTokenCacheTestCase(TokenCacheTestCase):
# Run all inherited test methods, and have extra check in tearDown()

Expand Down