Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrieve NTLM Active Directory user data to Rails w/o IIS

I believe that we can allow Firefox to sent NTLM data to SharePoint sites to do automatic authentication, and I think that this is doable with IIS.

I'd like to do the same thing with an internal Rails site.

Does anyone know of way that I could authenticate NTLM type user information through a Apache/mongrel setup (provided of course that it's already running on a Windows box inside of an Active Directory domain)?

like image 550
Nick Ryberg Avatar asked Sep 29 '08 20:09

Nick Ryberg


4 Answers

I created tutorial on how to install patched mod_ntlm module for Apache on Linux and how to pass NTLM authenticated username to Rails and how create Rails session from that. So as a result you do not need Windows server for running Rails application.

There you can find also how to enable automatic NTLM authentication in Firefox — enter "about:config" in location field and then search for "network.automatic-ntlm-auth.trusted-uris". There you can enter servers for which you would like to use automatic NTLM authentication.

like image 173
Raimonds Simanovskis Avatar answered Nov 14 '22 22:11

Raimonds Simanovskis


Bit of extra info in case anyone stumbles across this.

I wanted to do something which I thought should be pretty simple - extract the users windows username using NTLM from a Rails app running on Mongrel/Windows (InstantRails actually). Having written the basic code manage the various handshaking operations (using the great NTLMRuby library at http://rubyforge.org/projects/rubyntlm/) and having got it to work wonderfully in Firefox I was somewhat frustrated to find IE not working.

Mongrel doesn't support keep-alives during the type1/2/3 message exchange (at least natively, I believe there's a hack/fix for it), which IE demands and Firefox gets by without.

So authenticating a Rails server running on Windows against a remote NTLM service (e.g. Sharepoint or another web site) is reasonably straight forward, but authenticating an IE browser against a Rails server running on Windows not so much with Mongrel. IIS would be an option, as might be basic Apache with FastCGI. The former feels a bit clunky and the latter won't be as fast as Mongrel.

like image 23
Julian Browne Avatar answered Nov 14 '22 20:11

Julian Browne


I'm assuming you've already worked out which HTTP headers you need to send in order to get firefox and IE to send back the NTLM authentication stuff, and are just needing to handle that on the server side?

You could use some of ruby's win32 libraries to access the underlying windows authentication functions which handle the NTLM.

I'd suggest the path of least resistance might be to see if there is a COM component which can do the authentication for you, and if so, to use it using the Win32OLE ruby library.

If there's no COM component, you might be able to find something in one of those other libraries which can invoke the native win32 methods for you.

If you can't find that, you'd have to write a ruby C extension. I've done this on linux, and extending ruby is pretty easy, but you may find the microsoft authentication API's a bit painful.

Hope that gets you started on the right track :-)

like image 23
Orion Edwards Avatar answered Nov 14 '22 22:11

Orion Edwards


You could also use the Apache ntlm module, which should pass a header onwards to your application with the username of the authenticated user. That module looks a bit old, but suggests some other modules that may suit your needs.

like image 29
tomtaylor Avatar answered Nov 14 '22 22:11

tomtaylor