|
6 | 6 | import json |
7 | 7 | import logging |
8 | 8 | import os |
9 | | -import socket |
10 | 9 | import sys |
11 | 10 | import time |
12 | 11 | from urllib.parse import urlparse # Python 3+ |
@@ -146,7 +145,10 @@ class ManagedIdentityClient(object): |
146 | 145 | (like what a ``PublicClientApplication`` does), |
147 | 146 | not a token with application permissions for an app. |
148 | 147 | """ |
149 | | - __instance, _tenant = None, "managed_identity" # Placeholders |
| 148 | + __instance = "localhost" # We used to get this value from socket.getfqdn() |
| 149 | + # but it is unreliable because getfqdn() either hangs or returns empty value |
| 150 | + # on some misconfigured machines |
| 151 | + _tenant = "managed_identity" |
150 | 152 | _TOKEN_SOURCE = "token_source" |
151 | 153 | _TOKEN_SOURCE_IDP = "identity_provider" |
152 | 154 | _TOKEN_SOURCE_CACHE = "cache" |
@@ -252,11 +254,6 @@ def __init__( |
252 | 254 | self._token_cache = token_cache or TokenCache() |
253 | 255 | self._client_capabilities = client_capabilities |
254 | 256 |
|
255 | | - def _get_instance(self): |
256 | | - if self.__instance is None: |
257 | | - self.__instance = socket.getfqdn() # Moved from class definition to here |
258 | | - return self.__instance |
259 | | - |
260 | 257 | def acquire_token_for_client( |
261 | 258 | self, |
262 | 259 | *, |
@@ -302,7 +299,7 @@ def acquire_token_for_client( |
302 | 299 | target=[resource], |
303 | 300 | query=dict( |
304 | 301 | client_id=client_id_in_cache, |
305 | | - environment=self._get_instance(), |
| 302 | + environment=self.__instance, |
306 | 303 | realm=self._tenant, |
307 | 304 | home_account_id=None, |
308 | 305 | ), |
@@ -344,7 +341,7 @@ def acquire_token_for_client( |
344 | 341 | client_id=client_id_in_cache, |
345 | 342 | scope=[resource], |
346 | 343 | token_endpoint="https://{}/{}".format( |
347 | | - self._get_instance(), self._tenant), |
| 344 | + self.__instance, self._tenant), |
348 | 345 | response=result, |
349 | 346 | params={}, |
350 | 347 | data={}, |
|
0 commit comments