Skip to content

garethj-msft/Microsoft-Graph-WebHooks-Build-2016

Repository files navigation

Using webhooks on the Microsoft Graph to drive simple business logic.

Webhooks provide a powerful way to recieve notifications of change for data accessed through the Microsoft Graph. This sample shows how to connect and use Microsoft Graph to subscribe to a user's calendar and respond to notifications generated by that subscription.

Microsoft Graph webhooks require validation when a subscription is created. This sample shows how to handle that validation.

Microsoft Graph webhooks use a poke/pull model, where notifications carry minimal data, and richer data must be pulled from the Graph. In this way, outdated information is never used if a notification is missed. This sample shows how to store the subscription information and tokens necessary to make the callback when a notification arrives.

This sample allows users to get their calendar event titles translated to one of a range of languages. After users sign in, they are presented with a choice of languages, and when they commit to a language, a webhook subscription is registered that handles the translation for them. The translation is performed on the front end web server, which is not a realistic deployment topology. Typically, translation would be handled by queing a job on some back-end service in order to maximise the front end's ability to handle a high volume of incoming notifications. Microsoft Graph webhooks require that the notification endpoint responds within 30 seconds.

To connect to the Microsoft Graph, an application must first authenticate its users. This sample uses Active Directory Authentication Library to make OAuth2 call.

Note: To understand the code for calling the Microsoft Graph API in an ASP.NET MVC app, see Call Microsoft Graph in an ASP.NET MVC app.

![Office 365 ASP.NET MVC sample screenshot](./README assets/O365AspNetMVCSendMailPageScreenshot.png)

Prerequisites

Try out the Get started with Office 365 APIs page which simplifies registration so you can get this sample running faster.

To use the Office 365 ASP.NET MVC Connect sample, you need the following:

  • Visual Studio 2015 with Update 1 installed and working on your development computer.

  • An Office 365 account. You can sign up for an Office 365 Developer subscription that includes the resources that you need to start building Office 365 apps.

    Note: If you already have a subscription, the previous link sends you to a page with the message Sorry, you can’t add that to your current account. In that case use an account from your current Office 365 subscription.

  • A Microsoft Azure tenant to register your application. Azure Active Directory (AD) provides identity services that applications use for authentication and authorization. A trial subscription can be acquired here: Microsoft Azure.

    Important: You also need to make sure your Azure subscription is bound to your Office 365 tenant. To do this, see the Active Directory team's blog post, Creating and Managing Multiple Windows Azure Active Directories. The section Adding a new directory will explain how to do this. You can also see Set up your Office 365 development environment and the section Associate your Office 365 account with Azure AD to create and manage apps for more information.

  • A client ID and redirect URI values of an application registered in Azure. This sample application must be granted the Read the signed-in user's calendar permission for the Microsoft Graph. Add a web application in Azure and grant the proper permissions to it.

    Note: During the app registration process, make sure to specify http://localhost:55065 as the Sign-on URL.

Configure and run the app

  1. Open GraphWebHooksTranslator.sln file.

  2. In Solution Explorer, open the Web.config file.

  3. Replace ENTER_YOUR_CLIENT_ID with the client ID of your registered Azure application.

  4. Replace ENTER_YOUR_SECRET with the key of your registered Azure application.

  5. Press F5 to build and debug. Run the solution and sign in to Office 365 with your organizational account.

    Note: Copy and paste the start page URL address http://localhost:55065/home/index, to a different browser if you get the following error during sign in:AADSTS70001: Application with identifier ad533dcf-ccad-469a-abed-acd1c8cc0d7d was not found in the directory.

Questions and comments

We'd love to get your feedback about the Office 365 365 ASP.NET MVC Connect sample. You can send your questions and suggestions to us in the Issues section of this repository.

Questions about Office 365 development in general should be posted to Stack Overflow. Make sure that your questions or comments are tagged with [Office365] and [MicrosoftGraph].

Additional resources

Copyright

Copyright (c) 2015 Microsoft. All rights reserved.

About

Build 2016 demo

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages