Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
58 lines (47 sloc) 1.76 KB
#!/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}"
"