Allow user to access shared mailbox using Graph api in c#

Viewed 47

Currently we are adding users to requested shared mail box using PowerShell in c#. Due to basic AUTH going to disable, now we are planning implement using Graph api.

This how I thought to implement,

  1. Get the requested user details using Graph api
  2. Get the requested shared mail box details from Graph api
  3. Add the user to requested mail box.

Here I am able to get user and requested mail box but not sure how to add the user to shared mail box.

I am accessing all the details using service account and following App permission method.

Below are the code to get user and mail box,

 var options = new TokenCredentialOptions
            {
                AuthorityHost = AzureAuthorityHosts.AzurePublicCloud
            };

var clientSecretCredential = new ClientSecretCredential(
                tenantId, clientId, clientSecret, options);

var graphClient = new GraphServiceClient(clientSecretCredential, scopes);
var requestedDetails = await graphClient.Users["emailaddress"].Request().GetAsync();

Is it possible to achieve this using Graph api? if yes then which endpoint I should call?

1 Answers

You can't modify the Mailbox permission using the Graph API and there is currently no roadmap for that feature to exist at any point in the future there is a feature request portal for the Graph at https://feedbackportal.microsoft.com/feedback/search/ebe2edae-97d1-ec11-a7b5-0022481f3c80?q=shared+mailbox where you can ask for it.

Options for adding mailbox permission would be to use the exoV2 powershell module and certificate authentication https://learn.microsoft.com/en-us/powershell/exchange/app-only-auth-powershell-v2?view=exchange-ps that's the best option. You can modify you existing code to use modern Auth https://gsexdev.blogspot.com/2020/07/modifying-your-exchange-online.html but you still have user creds so heading toward certificate authentication is where you want to be.

Related