Skip to content

Commit 6080e2a

Browse files
committed
A reasonable-effort to convert scope to resource
1 parent 2010ae7 commit 6080e2a

File tree

1 file changed

+14
-30
lines changed

1 file changed

+14
-30
lines changed

msal/cloudshell.py

Lines changed: 14 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
import json
88
import logging
99
import os
10+
try: # Python 2
11+
from urlparse import urlparse
12+
except: # Python 3
13+
from urllib.parse import urlparse
1014

1115

1216
logger = logging.getLogger(__name__)
@@ -16,38 +20,18 @@ def _is_running_in_cloud_shell():
1620
return os.environ.get("AZUREPS_HOST_ENVIRONMENT", "").startswith("cloud-shell")
1721

1822

19-
def _scope_to_resource(scope):
20-
cloud_shell_supported_audiences = [ # Came from https://msazure.visualstudio.com/One/_git/compute-CloudShell?path=/src/images/agent/env/envconfig.PROD.json
21-
"https://management.core.windows.net/",
22-
"https://management.azure.com/",
23-
"https://graph.windows.net/",
24-
"https://vault.azure.net",
25-
"https://datalake.azure.net/",
26-
"https://outlook.office365.com/",
27-
"https://graph.microsoft.com/",
28-
"https://batch.core.windows.net/",
29-
"https://analysis.windows.net/powerbi/api",
30-
"https://storage.azure.com/",
31-
"https://rest.media.azure.net",
32-
"https://api.loganalytics.io",
33-
"https://ossrdbms-aad.database.windows.net",
34-
"https://www.yammer.com",
35-
"https://digitaltwins.azure.net",
36-
"0b07f429-9f4b-4714-9392-cc5e8e80c8b0",
37-
"822c8694-ad95-4735-9c55-256f7db2f9b4",
38-
"https://dev.azuresynapse.net",
39-
"https://database.windows.net",
40-
"https://quantum.microsoft.com",
41-
"https://iothubs.azure.net",
42-
"2ff814a6-3304-4ab8-85cb-cd0e6f879c1d",
43-
"https://azuredatabricks.net/",
44-
"ce34e7e5-485f-4d76-964f-b3d2b16d1e4f",
45-
"https://azure-devices-provisioning.net"
46-
] # TODO: Cloud Shell IMDS will remove that list soon. What shall we do then?
23+
def _scope_to_resource(scope): # This is an experimental reasonable-effort approach
24+
cloud_shell_supported_audiences = [
25+
"https://analysis.windows.net/powerbi/api", # Came from https://msazure.visualstudio.com/One/_git/compute-CloudShell?path=/src/images/agent/env/envconfig.PROD.json
26+
"https://pas.windows.net/CheckMyAccess/Linux/.default", # Cloud Shell accepts it as-is
27+
]
4728
for a in cloud_shell_supported_audiences:
48-
if scope.startswith(a): # This is an experimental approach
29+
if scope.startswith(a):
4930
return a
50-
return scope # Some scope would work as-is, such as the SSH Cert scope
31+
u = urlparse(scope)
32+
if u.scheme:
33+
return "{}://{}".format(u.scheme, u.netloc)
34+
return scope # There is no much else we can do here
5135

5236

5337
def _acquire_token(http_client, scopes, **kwargs):

0 commit comments

Comments
 (0)