Office 365 gives You a chance to host SharePoint in the cloud. You can use SandBox(legacy) or new App infrastructure to write custom applications running in SharePoint Online environment. If You want to connect to SP Online from external environment, then You have to use CSOM – Client Side Object Model.
Office 365 uses claims-based authentication which caused many problems in the previous SP 2010 version. To connect to the service, user had to first log in to SP Online web site directly from the browser to acquire cookies that were later on used by the application to authenticate in the cloud. More about this trick You can read here.
With SP 2013 Micorosft introduces a new object – SharePointOnlineCredentials. Now authentication is fully ‘automatic’ and it does not require any user action. Below is the code that reads the web site title using new SharePointOnlineCredentials object: