Getting Started with Office365 Development – session recording, slides and demo resources

In October and November 2014 I presented session „Getting Started with Office365 Development“ on two conferences: TechEd Europe 2014 and Office365 Saturday Europe 2014. Both sessions are recorded, and recordings are available online:

Slides for TechEd session are available on Channel9 and slides for Office 365 Saturday session can be downloaded from my SlideShare profile. As I'm currently using Markdown for editing my blog posts, I'm currently not able to embed the presentation directly in a blog post.

Session demos

During the session, I had total of 4 coding demos:

  1. How to create Office App with Visual Studio
  2. How to create SharePoint App with Visual Studio
  3. Using Windows Store App to access Files and Calendar data stored on Office 365
  4. Using ASP.NET MVC website to access Files and Contacts data stored on Office 365

For first two demos, source code of completed apps and code snippets for all steps can be downloaded from OneDrive. Third demo is based on Windows Store App Starter Project available on GitHub Office Dev repository. Last demo is based on ITUnity tutorial written by Scot Hillier, but extended to cover "Files" capability scenario. As I had problems preparing this demo, I had huge help from Andrew Byrne (Microsoft), who helped me to solve the issue which I had with Access Denied, caused by unsuccessful token acquisition for SharePointClient object, literally at 2AM in the morning. The trick was to use UserAssertion object in AcquireTokenAsync call.

Below is the code for MVC Controller that reads Files from OneDrive for Business in Office 365 for current user:

public class FilesController : Controller
{
    private const string CLIENT_ID = "[Your Client ID]";
    private const string CLIENT_SECRET = "[Your Client Secret]";
    private const string AUTHORITY = "https://login.windows.net/[Insert Tenant GUID Here]";
    const string DISCOVERY_ENDPOINT = "https://api.office.com/discovery/v1.0/me/";
    const string DISCOVERY_RESOURCE = "https://api.office.com/discovery/";
    const string FILES_CAPABILITY = "MyFiles";

    // GET: Files
    [Authorize]
    public async Task<ActionResult> Index()
    {
        var signInUserId = ClaimsPrincipal.Current.FindFirst(
 ClaimTypes.NameIdentifier).Value;
        var userObjectId = ClaimsPrincipal.Current.FindFirst(
            "http://schemas.microsoft.com/identity/claims/objectidentifier").Value;

        AuthenticationContext authContext = new AuthenticationContext(
AUTHORITY,
new NaiveSessionCache(signInUserId));
        string refreshToken = string.Empty;
        string accessToken = string.Empty;

        //Discover contacts endpoint
        DiscoveryClient discClient = new DiscoveryClient(new Uri(DISCOVERY_ENDPOINT),
            async () =>
            {
                var authResult =
                    await authContext.AcquireTokenSilentAsync(DISCOVERY_RESOURCE,
                    new ClientCredential(CLIENT_ID,
                    CLIENT_SECRET),
                    new UserIdentifier(userObjectId,
                    UserIdentifierType.UniqueId));
                refreshToken = authResult.RefreshToken;
                accessToken = authResult.AccessToken;
                return authResult.AccessToken;

            });

        var dcr = await discClient.DiscoverCapabilityAsync(FILES_CAPABILITY);

        SharePointClient client = new SharePointClient(
            dcr.ServiceEndpointUri,
            async () =>                
            {
                var authResult = await authContext.AcquireTokenAsync(dcr.ServiceResourceId,                     
                new ClientCredential(CLIENT_ID, CLIENT_SECRET), new UserAssertion(signInUserId));                 
                return authResult.AccessToken;   
        });

        var filesResult = await client.Files.Take(10).ExecuteAsync();
        //Show the files
        return View(filesResult);
    }
}

Feel free to download sample code, or use this code block above in your apps. Any questions or comments you can post here, or reach me on twitter: https://twitter.com/panjkov/.

Thanks for reading :)