1

I can't find any documentation or a way to find if a user belongs to an AD group with Javascript neither with the REST API or with the client model JSOM.

I have a page in a Sharepoint site and I want to show/hide a link if the user belongs to an active directory group.

It's Sharepoint 2013 Online in an Office 365 Server so there was a synchronization with the on-premises server

I have tried to use the Rest API _api/web/sitegroups or _api/web/GetUserById(32)/groups

but it just returns the Sharepoint Groups of that user, not the AD groups, is there something I have to do to make for the AD groups appear in the rest api or am I totally wrong, should I use a webservice or something like that?

Any help would be really appreciated

2

I am afraid you are out of luck.

  1. there is no api to check if user belongs to a group in AD in sharepoint. But sharepoint does have a notion of Audiences

  2. Sadly, i dont think there is no REST api for audiences either.

  3. Via code here.

From here

The behavior is by design. SharePoint will not unwind AD groups for audience feature to work as this will cause performance issue.

The workarounds are:

  1. Directly add the user to the SharePoint group or use role provider (form based authentication) and then use this for targeting.

  2. Create Audience through SSP admin site -->Audiences link and add a rule to get the users only from a particular AD group.

1

I know this question is old but it might help someone doing Research on this.

I recently wrote a script to figure out access rights and found something that might help.

Here is a simplified Version from the object model to illustrate what i mean:

Web

-----> RoleAssignments

               -----> Member

                        -------> PrincipalType

So starting from the web you can check in the roleassignments member the principaltype (enum). Going from here you can check for a member that has equal Access rights to the page (equal to the user ones). And see which type it is. Or just check all to see if the user is in any listed SharePoint Group / listed directly. Basically checking if he comes from an ad group by exclusion.

Not really a pretty way but could work.

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.