# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------
import subprocess
import json
import re

# Endpoints
p = subprocess.Popen("az cloud show -o json --query '{managementURI: endpoints.management, baseURL: endpoints.resourceManager, authURL: endpoints.activeDirectory, graphURL: endpoints.activeDirectoryGraphResourceId}'", shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
p.wait()
cloud = json.loads(p.stdout.read())
# Subscription
p = subprocess.Popen('az account show -o json --query "{subscription: id}"', shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
p.wait()
account = json.loads(p.stdout.read())
# Service principal
p = subprocess.Popen('az ad sp create-for-rbac -o json --query "{client: appId, key: password, tenant: tenant}"', shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
p.wait()
out = p.stdout.read()
out = re.sub(b"[^.]*{", b"{", out)
sp = json.loads(out)
for key,value in sp.items():
    print(key + "=" + value)
for key,value in account.items():
    print(key + "=" + value)
for key,value in cloud.items():
    if (not value.endswith("/")):
        value = value + "/"
    print(key + "=" + value.replace("https://", r"https\://"))

@@ -412,17 +412,17 @@
 s.Popen(
-%22
+'
 az cloud
@@ -443,17 +443,17 @@
 --query 
-'
+%22
 %7Bmanagem
@@ -609,10 +609,10 @@
 eId%7D
-'
 %22
+'
 , sh
@@ -710,24 +710,39 @@
 tdout.read()
+.decode(%22utf8%22)
 )%0A# Subscrip
@@ -930,16 +930,31 @@
 t.read()
+.decode(%22utf8%22)
 )%0A# Serv
@@ -1228,16 +1228,31 @@
 oads(out
+.decode(%22utf8%22)
 )%0Afor ke

Make auth script more robust on Windows (#1637)