Skip to content

Commit a0eab4e

Browse files
committed
Adjusting IdToken key, RT target behavior, and authority_type value
1 parent 63bf224 commit a0eab4e

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

msal/token_cache.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,9 @@ def add(self, event, now=None):
115115
"local_account_id": decoded_id_token.get(
116116
"oid", decoded_id_token.get("sub")),
117117
"username": decoded_id_token.get("preferred_username"),
118-
"authority_type": "AAD", # Always AAD?
118+
"authority_type":
119+
"ADFS" if realm == "adfs"
120+
else "MSSTS", # MSSTS means AAD v2 for both AAD & MSA
119121
# "client_info": response.get("client_info"), # Optional
120122
}
121123

@@ -126,6 +128,7 @@ def add(self, event, now=None):
126128
self.CredentialType.ID_TOKEN,
127129
event.get("client_id", ""),
128130
realm or "",
131+
"" # Albeit irrelevant, schema requires an empty scope here
129132
]).lower()
130133
self._cache.setdefault(self.CredentialType.ID_TOKEN, {})[key] = {
131134
"credential_type": self.CredentialType.ID_TOKEN,
@@ -164,7 +167,7 @@ def _build_rt_key(
164167
cls.CredentialType.REFRESH_TOKEN,
165168
client_id or "",
166169
"", # RT is cross-tenant in AAD
167-
target,
170+
target or "", # raw value could be None if deserialized from other SDK
168171
]).lower()
169172

170173
def remove_rt(self, rt_item):

tests/test_token_cache.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def testAdd(self):
7272
'realm': 'contoso',
7373
'local_account_id': "object1234",
7474
'username': "John Doe",
75-
'authority_type': "AAD",
75+
'authority_type': "MSSTS",
7676
},
7777
self.cache._cache["Account"].get('uid.utid-login.example.com-contoso')
7878
)
@@ -86,7 +86,7 @@ def testAdd(self):
8686
'client_id': 'my_client_id',
8787
},
8888
self.cache._cache["IdToken"].get(
89-
'uid.utid-login.example.com-idtoken-my_client_id-contoso')
89+
'uid.utid-login.example.com-idtoken-my_client_id-contoso-')
9090
)
9191

9292

0 commit comments

Comments
 (0)