azurepowershellazure-cli

Can I set the redirectUris for publicClient or spa from PowerShell?


When creating a new application in Azure from PowerShell using the command New-AzureADApplication, how can I set the redirect URIs if the application is a spa or publicClient, without using the Azure portal?


Solution

  • Updated answer 2024-08:

    With the Microsoft.Graph module (successor to the AzureAD module) this is now a bit simpler:

    $appId = '81c8ba62-b8f3-4570-8ca3-45b8ad050568'
    $app = Get-MgApplication -ApplicationId $appId
    $redirectUris = @("https://address1.com", "https://address2.com")
    Update-MgApplication -ApplicationId $app.Id -Spa @{ RedirectUris = $redirectUris }
    

    Previous answer:

    You can do this by using the Azure CLI (or other tool able to make rest requests) and making a PATCH-request to Microsoft Graph to update that specific part of the application manifest:

    az rest `
        --method PATCH `
        --uri 'https://graph.microsoft.com/v1.0/applications/{id}' `
        --headers 'Content-Type=application/json' `
        --body "{spa:{redirectUris:['http://localhost:3000']}}"
    

    Microsoft Docs about az rest