Skip to content

Instantly share code, notes, and snippets.

@jsiegmund
Created June 23, 2025 13:33
Show Gist options
  • Save jsiegmund/09edfa39e5a9ce77bd3f59c64878b4c9 to your computer and use it in GitHub Desktop.
Save jsiegmund/09edfa39e5a9ce77bd3f59c64878b4c9 to your computer and use it in GitHub Desktop.
Add static webapp preview URL to app registration
- name: Add Preview URL to App Registration
if: github.event_name == 'pull_request' && github.event.action != 'closed'
env:
PREVIEW_URL: ${{ steps.builddeploy.outputs.static_web_app_url }}
run: |
# Login to Azure
az login --service-principal -u ${{ vars.AZURE_CLIENT_ID }} -p ${{ secrets.AZURE_CLIENT_SECRET }} --tenant ${{ vars.AZURE_TENANT_ID }} --allow-no-subscriptions
APP_ID=${{ vars.APP_REGISTRATION_ID }}
NEW_URI="${{steps.builddeploy.outputs.static_web_app_url}}/login-redirect"
# Get current SPA redirect URIs
CURRENT_URIS=$(az rest --method GET --url "https://graph.microsoft.com/v1.0/applications/$APP_ID" --query "spa.redirectUris" -o tsv)
# Build updated list (add if not present)
if [[ "$CURRENT_URIS" == *"$NEW_URI"* ]]; then
UPDATED_URIS=$(echo "$CURRENT_URIS" | grep -v '^$' | jq -R . | jq -s .)
else
UPDATED_URIS=$(echo -e "$CURRENT_URIS\n$NEW_URI" | awk '!a[$0]++' | grep -v '^$' | jq -R . | jq -s .)
fi
# Update SPA redirect URIs using Microsoft Graph
az rest --method PATCH \
--url $GRAPH_URL "https://graph.microsoft.com/v1.0/applications/$APP_ID" \
--headers 'Content-Type=application/json' \
--body "{\"spa\": {\"redirectUris\": $UPDATED_URIS }}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment