BryceBy
BryceBy

Reputation: 319

Azure - Create App Registration with replyUrlsWithType

We quite simply want to run a command to create an app registration within our Azure AD. It is a SPA and obviously we need to set a redirect URL to send users back to our app after they authenticate.

I tried

az ad app create --display-name appName --reply-urls '[{\"url\":\"http://localhost:3000\",\"type\":\"Spa\"}]',

but this fails with

Invalid value specified for property 'replyUrls' of resource 'Application'.

Seems like this would be a very common operation to perform, but I can not locate docs on achieving this. These are the az ad app create docs.

Upvotes: 1

Views: 1943

Answers (2)

Benjamin Xue
Benjamin Xue

Reputation: 46

Thanks, @BryceBy. I did a quick test of your script and it worked well.

In my case, I need to get both app id and object id and create the scripts below.

clientid=$(az ad app create --display-name $appregname --query appId --output tsv)
objectid=$(az ad app show --id $clientid --query objectId --output tsv)

Upvotes: 0

BryceBy
BryceBy

Reputation: 319

For anyone else who comes across this, this is the solution I came up with after trying to accomplish this in several different ways (Thanks for the mentioning az rest Gaurav Mantri).

I created the following bash script

create-app-registration.sh

#Create App Registration
response=$(az ad app create --display-name $appName)

#Get the ObjectId of the newly created app registration
objectId=$(echo $response| cut -d'/' -f 3)

# Update app for SPA redirect
az rest --method PATCH --uri 'https://graph.microsoft.com/v1.0/applications/'$objectId \
    --headers 'Content-Type=application/json' \
    --body '{"spa":{"redirectUris":["'$redirectUri'"]}}'

Upvotes: 2

Related Questions