First time posting here, so please let me know if I need to make any changes to my question or add more details. I am unable to add API permissions as configured.
I am following the post/answer here: https://stackoverflow.com/a/78951253/12567070
But when running the bicep, I get permissions added to my app registration. However, they are only added as "other permissions granted" – I believe this is because "Admin consent required" for the permissions I am trying to add. Is it possible to do the admin consent with bicep?
Example code used:
targetScope = 'tenant'
// entra-external-setup.bicep
extension microsoftGraph
param appName string = 'cspm'
param deployEnvironment string = 'lb'
var applicationRegistrationName = '${appName}-${deployEnvironment}-app-01'
var redirectUris = deployEnvironment == 'prod'
? ['https://app.${appName}.io']
: ['https://${applicationRegistrationName}.azurewebsites.net', 'https://localhost:44305']
resource microsoftGraphServicePrincipal 'Microsoft.Graph/[email protected]' existing = {
appId: '00000003-0000-0000-c000-000000000000'
}
resource applicationRegistration 'Microsoft.Graph/[email protected]' = {
uniqueName: applicationRegistrationName
displayName: applicationRegistrationName
web: {
redirectUris: [for item in redirectUris: '${item}/sigin-oidc']
implicitGrantSettings: {
enableIdTokenIssuance: true
}
}
requiredResourceAccess: [
{
resourceAppId: microsoftGraphServicePrincipal.appId
resourceAccess: [
{
id: '246dd0d5-5bd0-4def-940b-0421030a5b68', type: 'Scope'
}
]
}
]
}
resource applicationRegistrationServicePrincipal 'Microsoft.Graph/[email protected]' = {
appId: applicationRegistration.appId
}
resource grants 'Microsoft.Graph/[email protected]' = {
clientId: applicationRegistrationServicePrincipal.id
resourceId: microsoftGraphServicePrincipal.id
consentType: 'AllPrincipals'
scope: 'Policy.Read.All'
}
My goal is to use Bicep to add the API permissions, granted here:
What am I missing?
2
Answers
In you bicep file, you are using
246dd0d5-5bd0-4def-940b-0421030a5b68
which is the id of the App role. you need to use the id of the oauth scope which is572fea84-0151-49b2-9301-11cb16974376
.To make sure to have it right, you can retrieve the values from the MS Graph SP:
Simply follow my code. After deployment complete,
admin consent
auto shows.