Skip to content

Instantly share code, notes, and snippets.

@premchandpl
Created November 24, 2014 13:32
Show Gist options
  • Select an option

  • Save premchandpl/de541f31e86c4c8039df to your computer and use it in GitHub Desktop.

Select an option

Save premchandpl/de541f31e86c4c8039df to your computer and use it in GitHub Desktop.
public static CookieContainer GetO365CookieContainer(SharePointOnlineCredentials credentials, string targetSiteUrl)
{
Uri targetSite = new Uri(targetSiteUrl);
string cookieString = credentials.GetAuthenticationCookie(targetSite);
CookieContainer container = new CookieContainer();
string trimmedCookie = cookieString.TrimStart("SPOIDCRL=".ToCharArray());
container.Add(new Cookie("SPOIDCRL", trimmedCookie, string.Empty, targetSite.Authority));
return container;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment