Good news is Microsoft has released APIs for both CSOM (https://msdn.microsoft.com/en-us/library/office/microsoft.sharepoint.client.web.shareobject.aspx) and REST to share an OBJECT (Could be web or document) with external users. Instead of I writing much I will let my code talk much for me :)
This blog post is concentrated around sharing object using CSOM. I will later publish a blog about how to share files using REST APIs for MS and other platform users. Till then sorry for non MS platforms!
You must first enable external sharing to your site collection from your office 365 SharePoint Admin Console. Follow this article to do so;
Lets get started
Take reference to latest SharePoint client libra…