-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathcreate-azure-ad-client-app.sh
57 lines (47 loc) · 1.76 KB
/
create-azure-ad-client-app.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/bin/bash
set -e
# load environment variables
export RBAC_AZURE_TENANT_ID="801dc5e8-3f2d-4070-ab27-a7497e430784"
export RBAC_CLIENT_APP_NAME="AKSAADClient3"
export RBAC_CLIENT_APP_URL="http://aksaadclient3"
export RBAC_SERVER_APP_ID="COMPLETE_AFTER_SERVER_APP_CREATION"
export RBAC_SERVER_APP_OAUTH2PERMISSIONS_ID="COMPLETE_AFTER_SERVER_APP_CREATION"
export RBAC_SERVER_APP_SECRET="COMPLETE_AFTER_SERVER_APP_CREATION"
# generate manifest for client application
cat > ./manifest-client.json << EOF
[
{
"resourceAppId": "${RBAC_SERVER_APP_ID}",
"resourceAccess": [
{
"id": "${RBAC_SERVER_APP_OAUTH2PERMISSIONS_ID}",
"type": "Scope"
}
]
}
]
EOF
# create client application
az ad app create --display-name ${RBAC_CLIENT_APP_NAME} \
--native-app \
--reply-urls "${RBAC_CLIENT_APP_URL}" \
--homepage "${RBAC_CLIENT_APP_URL}" \
--required-resource-accesses @manifest-client.json
RBAC_CLIENT_APP_ID=$(az ad app list --display-name ${RBAC_CLIENT_APP_NAME} --query [].appId -o tsv)
# create service principal for the client application
az ad sp create --id ${RBAC_CLIENT_APP_ID}
# remove manifest-client.json
rm ./manifest-client.json
# grant permissions to server application
RBAC_CLIENT_APP_RESOURCES_API_IDS=$(az ad app permission list --id $RBAC_CLIENT_APP_ID --query [].resourceAppId --out tsv | xargs echo)
for RESOURCE_API_ID in $RBAC_CLIENT_APP_RESOURCES_API_IDS;
do
az ad app permission grant --api $RESOURCE_API_ID --id $RBAC_CLIENT_APP_ID
done
# Output terraform variables
echo "
export TF_VAR_rbac_server_app_id="${RBAC_SERVER_APP_ID}"
export TF_VAR_rbac_server_app_secret="${RBAC_SERVER_APP_SECRET}"
export TF_VAR_rbac_client_app_id="${RBAC_CLIENT_APP_ID}"
export TF_VAR_tenant_id="${RBAC_AZURE_TENANT_ID}"
"