Javascript active user / group directory request

Is it possible to request AD from javascript?

I work from SharePoint and I can get current information about the SharePoint user using some js that I found on the blog.

But I am wondering if I can then query AD to find out if the current user is in a specific AD group.

+6
javascript sharepoint active-directory
source share
3 answers

I think you'd better write a quick asp.net page that you could call through AJAX and return the JSON back. The .NET directory services class will talk a lot better with Active Directory than with javascript if you cannot find the js library specifically for this (which I could not find).

+4
source share

This is a bit late, but for future visitors from Google I had to write something in JavaScript to fix a scheduled task that runs using cscript:

var conn = WScript.CreateObject("ADODB.Connection") var rootDSE = GetObject("LDAP://RootDSE"); var context = rootDSE.Get("defaultNamingContext"); conn.Provider = "ADsDSOObject"; conn.Open("ADs Provider"); var query = "<LDAP://" + context + ">;(&(objectCategory=person)(objectClass=user));samAccountName;subtree"; var cmd = WScript.CreateObject("ADODB.Command"); cmd.ActiveConnection = conn; cmd.CommandText = query; cmd.Properties.Item("SearchScope") = 2; cmd.Properties.Item("Page Size") = 500; var r = cmd.Execute(); while(!r.EOF) { for (var e=new Enumerator(r.Fields);!e.atEnd();e.moveNext()) { WScript.Stdout.Write(e.Item().name + "=" + e.Item().value + " "); } WScript.Stdout.WriteLine(""); r.MoveNext(); } 
+3
source share

I donโ€™t know how to access AD from a client script. I could only think of some ActiveX control that does this job, however 1) it will work only in IE 2) it will also be limited by zone settings in IE.

So the reason is why you need it. Most likely, to show the user something or hide something from the user. If so, you might want to consider applying a โ€œtarget audienceโ€ solution on your page (see here http://office.microsoft.com/en-us/sharepointserver/HA101690531033.aspx ). For example, add two versions of your web page to a page, one for users who are in a group and one for users who do not.

If you really need this information on the client side in JS, you can create the AD helper web service on your server and call this service using AJAX, according to @squillman.

0
source share

All Articles