InvalidIdentifierUri on creating AAD application

606 views Asked by At

I'm trying to create an azure ad application using powershell script:

        $appIdGuid = New-Guid
        $graphApp = New-AzureADApplication  -DisplayName $graphAppDisplayName `
                                                -IdentifierUris "api://$appIDGuid" `
                                                -ReplyUrls $replyUrls `
                                                -RequiredResourceAccess $requiredResourceAccess `
                                                -AvailableToOtherTenants $false `
                                                -Oauth2AllowImplicitFlow $false `
                                                -PublicClient $false

On running the above script, I get the error:

New-AzureADApplication : Error occurred while executing NewApplication 
Code: Request_BadRequest
Message: The application identifier uri '[api://b0129570-1d70-4c1a-8eb8-6301c0f4dc2f]' is invalid.
RequestId: aaaccbaa-bab2-4ff0-bb4b-aeacfa3863c5
DateTimeStamp: Tue, 04 Jan 2022 01:11:57 GMT
Details: PropertyName  - identifierUris, PropertyErrorCode  - InvalidIdentifierUri
HttpStatusCode: BadRequest
HttpStatusDescription: Bad Request
HttpResponseStatus: Completed
At C:\Scripts\Set-GraphCredentialsAzureADApplication.ps1:142 char:21
+ ... $graphApp = New-AzureADApplication    -DisplayName $graphAppDisplayNa ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [New-AzureADApplication], ApiException
    + FullyQualifiedErrorId : Microsoft.Open.AzureAD16.Client.ApiException,Microsoft.Open.AzureAD16.PowerShell.NewApplication

What am I missing?

1

There are 1 answers

1
Ansuman Bal On BEST ANSWER

As AdminOfThings has already mentioned in the comments , you can only put the clientId of the new app registration or the tenantid as the identifierUri in AAD with Premium License.

So , as a solution you can use something like below :

$graphAppDisplayName = "testapp"
$App=New-AzureADApplication -DisplayName $graphAppDisplayName -AvailableToOtherTenants $false -Oauth2AllowImplicitFlow $false -PublicClient $false
$id=$App.AppId
Set-AzureADApplication -ObjectId $App.objectId -IdentifierUris "api://$id"

Output:

enter image description here

enter image description here