In Bicep, I am attempting to create a User Assigned Identity, and then assigning that identity a few scopes using the new Microsoft.Graph bicep capabilities:
resource sqlIdentity 'Microsoft.ManagedIdentity/userAssignedIdentities@2023-01-31' = {
location: location
name: 'id-sqlserver-${environment}'
}
//https://learn.microsoft.com/en-us/graph/templates/reference/oauth2permissiongrants?view=graph-bicep-1.0
resource graphPermissions 'Microsoft.Graph/[email protected]' = {
clientId: sqlIdentity.properties.clientId
consentType: 'Principal'
resourceId: sqlIdentity.id
scope: 'User.Read.All GroupMember.Read.All Application.Read.All'
}
However, I get the following error message: The identity of the calling application could not be established. Another user tried that has elevated permissions but got the same error. How can I assign Microsoft Graph permissions using Bicep?
2
Answers
Not the matter of
Insufficient permissions
, It’s aboutoauth2PermissionGrants
conception. Remember it is representing delegated permissions which have been granted for client applications toaccess APIs
onbehalf of signed-in users
. So yourresourceId
in the bicep should be theAPIs
which your want to access, not the identity itself. theAPIs
resourceId such as ‘Microsoft Graph’ can be found in AADEnterprise Application
with copy its objectId.So your bicep should something like below:
main.bicep
After deployment complete, which means the
sqlIdentity
can on behalf of your to access themicrosoft graph api
withRead permission
.It is a bit confusing but:
clientId
represents the objectid of the client application: in your case the managed identityresourceId
represents the objectid of the target resource: in your case the service principal of MS Graph in your tenant.This should work: