I have a scenario where my pipeline should update the app registration with an additional redirectUrl.
I have managed to extract the current web.redirectUris with the following:
existing_urls=$(az ad app show --id '<client-id>' --query "[web.redirectUris]" --output tsv)
I would like to achieve something like this
existing_urls=$(az ad app show --id '<client-id>' --query "[web.redirectUris]" --output tsv)
az ad app update --id '<client-id>' --web-redirect-uris "$existing_urls https://hostname.com/newCallback"
I have tried updating the web.redirectUris in two ways and both of them have failed when I pass multiple redirect URIs.
Attempt 1
az ad app update --id '<client-id>' --web-redirect-uris "https://hostname.com/callbackx https://hostname.com/callbacky"
One or more properties contains invalid values.
However when having only one uri this worked fine
az ad app update --id '<client-id>' --web-redirect-uris "https://hostname.com/callbackx"
Attempt 2
This one fails regardless of number of redirectUris that are passed
az ad app update --id '<client-id>' --set "web.redirectUris=['https://hostname.com/callbackx', 'https://hostname.com/callbacky']"
Couldn't find 'web' in ''. Available options: []
Tried as shown :But got the same error:
az ad app show --id 1e7bxxx7830
existing_urls=$(az ad app show --id 1e7b8fxxxx830 --query "[web.redirectUris]")
az ad app update --id 1e7xxx0a7830 --web-redirect-uris "$existing_urls https://hostname.com/newCallback"
$updated_urls="$existing_urls https://hostname.com/newCallback"
az ad app update --id 1e7b8xxx0a7830 --set "web.redirectUris='$updated_urls'"
az ad app update --id 1e7b8fxxxd0a7830 --set "web.redirectUris='$updated_urls'"
Error:
Couldn't find 'web' in ''. Available options: []
Following command worked foe me in azure cli in updating multiple Redirect Urls:
az ad app update --id '1e7bxxxa7830' --web-redirect-uris "https://hostname.com/callback" "https://jwt.ms" "https://myexampleapp.com"
here –id is clientId
.
So give the command with required urls as
az ad app update –id ‘1e7bxxxa7830’ –web-redirect-uris “<url1>
” “<url2>
” “<url3>
“
upon az ad app show --id 1e7b8xxxx830
I also wanted to automate this as part of the DevOps pipeline so got this working with the following bash script:
#!/bin/bash
new_uri="<your_new_redirect_uri>" # or take from parameter with $1
client_id="<your_client_id>"
# Get string array of existing redirect URIs
existing_redirect_uris=$(az ad app show --id $client_id --query "[web.redirectUris]" --output tsv)
echo $existing_redirect_uris
# Check if the new URI is already in the list
if [[ $existing_redirect_uris == *$new_uri* ]]; then
echo "The URI $new_uri is already in the list"
else
echo "Adding the URI $new_uri to the list"
az ad app update --id $client_id --web-redirect-uris $existing_redirect_uris $new_uri
fi
And other script to remove redirect URI from the list:
#!/bin/bash
remove_uri="<remove_redirect_uri>" # or take from parameter with $1
client_id="<your_client_id>"
# Get list of existing redirect URIs and already remove selected with sed from that list
remaining_redirect_uris=$(az ad app show --id $client_id --query "[web.redirectUris]" --output tsv | sed "s|$remove_uri||g")
echo $remaining_redirect_uris
az ad app update --id $client_id --web-redirect-uris $remaining_redirect_uris