0

In SharePoint Provider-hosted App with CSOM, I am trying to get some code related to fetching deleted users from Office 365 online and not from SharePoint site collection.

In Visual Studio, I added Tenant related permission (Full control) in App and below code for fetching users from Tenant but got 403 Forbidden.

using Microsoft.Online.SharePoint.TenantAdministration;

  ClientContext adminContext = new ClientContext(new Uri("https://testsitename.sharepoint.com"));
  var tenant = new Tenant(adminContext);
  var tntCtx = tenant.Context;

  var loginResult = tenant.EncodeClaim(userName);
  tntCtx.ExecuteQuery();

  var encLoginName = loginResult.Value;

  var rootWeb = tenant.GetSiteByUrl(adminContext.Site.Url).RootWeb;
  var siteUsers = rootWeb.SiteUsers;
  var usersResult = tntCtx.LoadQuery(siteUsers.Include(u => u.LoginName).Where(u => u.LoginName == encLoginName));
  tntCtx.ExecuteQuery();

Anybody have some info or way to do this? as tried to research hard but in vain.

  • Last resort? Webjob which lists all users from Azure AD, then lists all users in SharePoint site collections, and the diff is deleted users. – Gil Roitto Feb 14 '18 at 7:59
  • Thanks for the input @Gil but that shall be a time-consuming process, maybe not suitable for which I need to integrate. – Kaushal15 Feb 21 '18 at 7:27
2

In my opinion, this is still not available. My initial idea would be to use Azure AD Graph API to achieve this, the same way that the Azure AD PowerShell allows you to do this by executing:

  Get-MsolUser –ReturnDeletedUsers

A research revealed though that the functionality is not available in the current release of Graph API Azure AD, check this .

What I would do to be 100% sure is to take a look at all properties available in the user object returned by the graph API searching for some that can indicate if the user is deleted or not, but I think the capability is not there. Check this

  • Thank you @Xavi. I shall research on this Azure AD Graph ADI as per your last suggestions. – Kaushal15 Feb 21 '18 at 7:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.