Skip to content
This repository was archived by the owner on Sep 29, 2023. It is now read-only.

Commit be39feb

Browse files
authored
Federated flow fix (#240)
1 parent 6f0c475 commit be39feb

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

adal/token_request.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,9 @@ def _perform_wstrust_assertion_oauth_exchange(self, wstrust_response):
190190

191191
return self._oauth_get_token(oauth_parameters)
192192

193-
def _perform_wstrust_exchange(self, wstrust_endpoint, wstrust_endpoint_version, username, password):
193+
def _perform_wstrust_exchange(self, wstrust_endpoint, wstrust_endpoint_version, cloud_audience_urn, username, password):
194194

195-
wstrust = self._create_wstrust_request(wstrust_endpoint, "urn:federation:MicrosoftOnline",
195+
wstrust = self._create_wstrust_request(wstrust_endpoint, cloud_audience_urn,
196196
wstrust_endpoint_version)
197197
result = wstrust.acquire_token(username, password)
198198

@@ -204,15 +204,16 @@ def _perform_wstrust_exchange(self, wstrust_endpoint, wstrust_endpoint_version,
204204

205205
return result
206206

207-
def _perform_username_password_for_access_token_exchange(self, wstrust_endpoint, wstrust_endpoint_version,
207+
def _perform_username_password_for_access_token_exchange(self, wstrust_endpoint, wstrust_endpoint_version, cloud_audience_urn,
208208
username, password):
209-
wstrust_response = self._perform_wstrust_exchange(wstrust_endpoint, wstrust_endpoint_version,
209+
wstrust_response = self._perform_wstrust_exchange(wstrust_endpoint, wstrust_endpoint_version, cloud_audience_urn,
210210
username, password)
211211
return self._perform_wstrust_assertion_oauth_exchange(wstrust_response)
212212

213213
def _get_token_username_password_federated(self, username, password):
214214
self._log.debug("Acquiring token with username password for federated user")
215215

216+
cloud_audience_urn = self._user_realm.cloud_audience_urn
216217
if not self._user_realm.federation_metadata_url:
217218
self._log.warn("Unable to retrieve federationMetadataUrl from AAD. "
218219
"Attempting fallback to AAD supplied endpoint.")
@@ -228,7 +229,7 @@ def _get_token_username_password_federated(self, username, password):
228229

229230
return self._perform_username_password_for_access_token_exchange(
230231
self._user_realm.federation_active_auth_url,
231-
wstrust_version, username, password)
232+
wstrust_version, cloud_audience_urn, username, password)
232233
else:
233234
mex_endpoint = self._user_realm.federation_metadata_url
234235
self._log.debug(
@@ -253,6 +254,7 @@ def _get_token_username_password_federated(self, username, password):
253254
raise AdalError('AAD did not return a WSTrust endpoint. Unable to proceed.')
254255

255256
return self._perform_username_password_for_access_token_exchange(wstrust_endpoint, wstrust_version,
257+
cloud_audience_urn,
256258
username, password)
257259
@staticmethod
258260
def _parse_wstrust_version_from_federation_active_authurl(federation_active_authurl):

adal/user_realm.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ def __init__(self, call_context, user_principle, authority_url):
5757
self.account_type = None
5858
self.federation_metadata_url = None
5959
self.federation_active_auth_url = None
60+
self.cloud_audience_urn = None
6061
self._user_principle = user_principle
6162
self._authority_url = authority_url
6263

@@ -131,6 +132,7 @@ def _parse_discovery_response(self, body):
131132
self.federation_protocol = protocol
132133
self.federation_metadata_url = response['federation_metadata_url']
133134
self.federation_active_auth_url = response['federation_active_auth_url']
135+
self.cloud_audience_urn = response.get('cloud_audience_urn', "urn:federation:MicrosoftOnline")
134136

135137
self._log_parsed_response()
136138

adal/wstrust_request.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@
4141

4242
class WSTrustRequest(object):
4343

44-
def __init__(self, call_context, watrust_endpoint_url, applies_to, wstrust_endpoint_version):
44+
def __init__(self, call_context, wstrust_endpoint_url, applies_to, wstrust_endpoint_version):
4545
self._log = log.Logger('WSTrustRequest', call_context['log_context'])
4646
self._call_context = call_context
47-
self._wstrust_endpoint_url = watrust_endpoint_url
47+
self._wstrust_endpoint_url = wstrust_endpoint_url
4848
self._applies_to = applies_to
4949
self._wstrust_endpoint_version = wstrust_endpoint_version
5050

0 commit comments

Comments
 (0)