I have an application where I want to send and read emails for a specific list of users assigned to an Azure Enterprise Application using the MS Graph API and the Confidential Client Credential flow. I do not know which users these will be initially, but I can query them through the service principals endpoint for the application and let the application user pick which one(s) to use.
I understand that I need to add the Application level User.Read.All, Mail.Send, and Mail.Read API permissions to the App registration and grant admin consent for them, however after retrieving the confidential client token and calling the https://graph.microsoft.com/v1.0/users/{user}/sendMail endpoint with it, I find it will still let me send from any user in the domain and not just the ones assigned to the application. The Assignment required setting in the enterprise application properties doesn’t appear to affect this.
Is there a way to ensure the endpoint cannot be used to send/read user emails that are not assigned to the enterprise application?
2
Answers
I would prefer another way than assigning users to the enterprise application.
There is an endpoint for role assignment (currently only in beta) for Exchange provider.
With this endpoint you can define that your specific enterprise app will be able to send emails for a group of users.
Prerequisite is to create an administrative unit and add those users as members of this administrative unit.
It can take from 30 minutes to 2 hours until the role is applied in Azure.
Repeat point 3. and 4. for
Mail.Read
(orMail.ReadBasic
)The advantages:
Mail.Send
,Mail.Read
permissions for the app in Azure (Entra) portalResource:
RBAC for Exchange Provider Preview
I created an Azure AD application and granted API permissions like below:
And set Assignment required as YES in the Enterprise application:
For sample added
ruk
user:Now I generated access token using Client Credentials flow by using below parameters via Postman:
By using the above access token, I tried to send mail by another user which is not assigned to the Enterprise application. And I am able to send mail successfully:
For Client Credential Flow/Application identity scenario, you must configure Application Access Policy like below:
You can test the policy against other users:
Now only the
ruk
user will be able to send mail using the access token generated by Client Credential flow for the application.References:
How to allow Azure Ad App to access information only for certain users? – Microsoft Q&A by krish-gh
New-ApplicationAccessPolicy (ExchangePowerShell) | Microsoft