Saturday, July 26, 2014

SharePoint Online Cookies Cookie365 - mount SharePoint online share

I was looking for a solution being able to mount a OneDrive for Business share in a ADFS federated environment. So I started googling around to find a way to mount transparently the OneDrive4Business space as a disk drive or a share on terminal server as a logon script.

Unfortunately I found out that the only option seemed to be a manual login to share point before using the usual "net use * \\\DavWWWRoot" which would not be an option for my users...

So I went through reading many articles and blogs, and overnight (I'm not a programmer :-) I decided to adapt and enrich code chunks and C# samples, to build an utility to set the cookies needed to mount the OneDrive share without user intervention.

The following resources were fundamental:
How to Use Fiddler Web Debugger to Analyze a WS-Federation Passive Sign-In
- Troubleshooting Federation, ADFS and more

To make a long story short... I produced an utility, baptized Cookie365, able to set the "FedAuth" and "rtFA" cookies needed to seamlessly mount a SharePoint share from the command line or from a script.

From a domain PC or Domain Server, just launch

Cookie365 -s

and the utility will logon to Office365 using the domain credentials, generating all the SAML tokens and cookies needed to mount the share (e.g. "net use * \\\DavWWWRoot". Beware, in order to use it, you have to have the WebClient service running and your sharepoint site added to the trusted sites inside Internet Explorer).

The utility is also able to manage non-domain PCs, so you can specify the user ("") and password:
Cookie365 -s -user -p password

I was able to test it on Windows server 2012R2 and Windows7SP1, both from domain joined and from workgroup machines, but I don't have extensive test cases, so any feedback is welcome.

I also added the support for NTLM proxy (like ISA and TMG). I have not tried with other proxies... so I don't know if it will work.

Here you can find the source code (VisualStudio2013 solution).
Here you can download the compiled version of Cookie365 (prerequisite = .NET 4.5)

As stated before... I am not a professional programmer.
My last programming was back in 1998 with Java... So.. any suggestion to ameliorate the code will be welcome !

Fabio Cuneaz

PS Just a legal statement.... The source code and the exe version are provide "AS IS" without warranty of any kind, either expressed or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose.