{"id":20054320,"url":"https://github.com/onedrive/onedrive-webhooks-aspnet","last_synced_at":"2025-07-24T06:40:58.353Z","repository":{"id":54198820,"uuid":"53878605","full_name":"OneDrive/onedrive-webhooks-aspnet","owner":"OneDrive","description":"Sample ASP.NET MVC application that receives webhooks from OneDrive and OneDrive for Business","archived":false,"fork":false,"pushed_at":"2023-05-31T18:12:27.000Z","size":892,"stargazers_count":19,"open_issues_count":11,"forks_count":12,"subscribers_count":20,"default_branch":"master","last_synced_at":"2025-04-08T23:14:40.443Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://dev.onedrive.com","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/OneDrive.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-03-14T17:52:16.000Z","updated_at":"2023-03-03T11:36:39.000Z","dependencies_parsed_at":"2024-11-13T12:49:56.207Z","dependency_job_id":null,"html_url":"https://github.com/OneDrive/onedrive-webhooks-aspnet","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OneDrive%2Fonedrive-webhooks-aspnet","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OneDrive%2Fonedrive-webhooks-aspnet/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OneDrive%2Fonedrive-webhooks-aspnet/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OneDrive%2Fonedrive-webhooks-aspnet/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/OneDrive","download_url":"https://codeload.github.com/OneDrive/onedrive-webhooks-aspnet/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252506389,"owners_count":21759041,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-13T12:39:47.482Z","updated_at":"2025-05-05T13:31:11.268Z","avatar_url":"https://github.com/OneDrive.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"---\r\npage_type: sample\r\nproducts:\r\n- office-onedrive\r\nlanguages:\r\n- javascript\r\nextensions:\r\n  contentType: samples\r\n  createdDate: 3/14/2016 10:52:16 AM\r\n---\r\n# OneDrive Webhooks ASP.NET Sample\r\n\r\nThis ASP.NET MVC sample shows how to receive notifications from OneDrive\r\nand OneDrive for Business when changes occur to files. The following are common\r\ntasks that a web application performs with OneDrive webhooks.\r\n\r\n* Sign-in your users with their Microsoft account, or a work or school account to get an access token.\r\n* Use the access token to create a webhook subscription.\r\n* Send back a validation token to confirm the notification URL.\r\n* Listen for notifications from OneDrive.\r\n* Request for more information using data in the notification.\r\n\r\nThis sample subscribes to notification on the signed in user's OneDrive and\r\ndisplays the name of the files that were added, modified, or deleted when a\r\nnotification is received.\r\n\r\n**Note:** Webhooks are still being enabled as a _preview only_ on OneDrive for Business. Webhooks functionality may not be available for your tenant yet. You can use a OneDrive Personal account to test functionality if this is the case.\r\n\r\n## Prerequisites\r\n\r\nTo use the OneDrive Webhooks sample, you need the following:\r\n\r\n* Visual Studio 2015 with Update 1 installed on your development computer.\r\n\r\n* A public HTTPS endpoint to receive and send HTTP requests. You can use\r\n  Microsoft Azure or another service to host your endpoint. If you prefer, you\r\n  can use ngrok (or a similar tool) while testing to temporarily allow messages\r\n  from Microsoft Graph to tunnel to a port on your local computer.\r\n  [Instructions for setting up ngrok](#set-up-the-ngrok-proxy-optional-) are included below.\r\n\r\n* A client ID and key for two applications:\r\n  * To enable OneDrive Personal support, you need to register an application at the [Microsoft registration portal](account.live.com/developers/applications).\r\n  * To enable OneDrive for Business support, you need to register an application\r\n    through a Microsoft Azure Active Directory tenant. You can use the\r\n    [Office 365 app registration tool](https://dev.office.com/app-registration),\r\n    which simplifies the process. Use the following parameters:\r\n\r\n    | Parameter       | Value                   |\r\n    |:----------------|:------------------------|\r\n    |        App type | Web App                 |\r\n    |     Sign on URL | http://localhost:52026/ |\r\n    |    Redirect URI | http://localhost:52026/ |\r\n    | App permissions | Files.ReadWrite         |\r\n\r\n   Copy and store the returned **Client ID** and **Client Secret** values.\r\n\r\n### Set up the ngrok proxy (optional)\r\n\r\nYou must expose a public HTTPS endpoint to create a subscription and receive\r\nnotifications from OneDrive. While testing, you can use ngrok to\r\ntemporarily allow messages from OneDrive to tunnel to a *localhost* port\r\non your computer. To learn more about using ngrok, see the [ngrok website](https://ngrok.com/).  \r\n\r\n1. In Solution Explorer, select the **OneDriveWebhooks** project.\r\n\r\n2. Copy the **URL** port number from the **Properties** window.  If the **Properties** window isn't showing, choose **View/Properties Window**.\r\n\r\n   ![The URL port number in the Properties window](readme-images/PortNumber.png)\r\n\r\n3. [Download ngrok](https://ngrok.com/download) for Windows.  \r\n\r\n4. Unzip the package and run ngrok.exe.\r\n\r\n5. Replace the two *\u003cport-number\u003e* placeholder values in the following command with the port number you copied, and then run the command in the ngrok console.\r\n\r\n   ```\r\n   ngrok http \u003cport-number\u003e -host-header=localhost:\u003cport-number\u003e\r\n   ```\r\n\r\n   ![Example command to run in the ngrok console](readme-images/ngrok1.png)\r\n\r\n6. Copy the HTTPS URL that's shown in the console.\r\n\r\n   ![The forwarding HTTPS URL in the ngrok console](readme-images/ngrok2.png)\r\n\r\n   \u003eKeep the console open while testing. If you close it, the tunnel also closes\r\n   \u003eand you'll need to generate a new URL and update the sample.\r\n\r\n## Configure and run the sample\r\n\r\n1. Create a public HTTPS notification endpoint. It can run on a service such as\r\n   Microsoft Azure, or you can create a proxy web server by [using ngrok](#ngrok)\r\n   or a similar tool.\r\n\r\n2. Open **onedrive-webhooks-aspnet.sln** in the sample files.\r\n\r\n3. In Solution Explorer, open the **Web.config** file in the root directory of the project.\r\n  a. Enter the values for your registered applications client ID into **ida:AppId**.\r\n  b. Enter the values for your registered applications client secret / password into **ida:AppSecret**.\r\n  c. For the **ida:NotificationUrl** key, replace *ENTER_YOUR_URL* with your\r\n     HTTPS URL. Keep the */notification/listen* portion. If you're using ngrok, the\r\n     value will look something like this:\r\n\r\n  ```xml\r\n  \u003cadd key=\"ida:NotificationUrl\" value=\"https://0f6fd138.ngrok.io/notification/listen\" /\u003e\r\n  ```\r\n\r\n4. Make sure that the ngrok console is still running, then press F5 to build and\r\n   run the solution in debug mode.\r\n\r\n\r\n### Use the app\r\n\r\n1. Sign in with your Office 365 work or school account.\r\n\r\n2. Choose the **Create subscription** button. The **Subscription** page loads\r\n   with information about the subscription.\r\n\r\n   ![App page showing properties of the new subscription](readme-images/Page4.png)\r\n\r\n3. Choose the **Watch for notifications** button.\r\n\r\n4. Add or modify a file in your OneDrive account. The **Notification** page\r\n   displays some message properties. It may take several seconds for the page to update.\r\n\r\n   ![App page showing properties of the new message](readme-images/Page6.png)\r\n\r\n5. Choose the **Delete subscription and sign out** button.\r\n\r\n\r\n## Key components of the sample\r\n\r\nThe following files contain code that shows how to work with OneDrive webhooks.\r\n\r\n**Controllers**  \r\n- [`NotificationController.cs`](OneDriveWebhooks/Controllers/NotificationController.cs) Receives notifications.  \r\n- [`SubscriptionContoller.cs`](OneDriveWebhooks/Controllers/SubscriptionController.cs) Creates and receives webhook subscriptions.\r\n\r\n**Models**  \r\n- [`OneDriveNotification.cs`](OneDriveWebhooks/Models/OneDriveNotification.cs) Represents a change notification.\r\n- [`OneDriveSubscription.cs`](OneDriveWebhooks/Models/OneDriveSubscription.cs) Represents a webhook subscription. Also defines the **SubscriptionViewModel** that represents the data displayed in the Subscription view.\r\n\r\n**Views**  \r\n- [`Notification/Notification.cshtml`](OneDriveWebhooks/Views/Notification/Notification.cshtml) Displays information about received messages, and contains the **Delete subscription and sign out** button.\r\n- [`Subscription/Index.cshtml`](OneDriveWebhooks/Views/Subscription/Index.cshtml) Landing page that contains the **Create subscription** button.\r\n- [`Subscription/CreateSubscription.cshtml```](OneDriveWebhooks/Views/Subscription/Subscription.cshtml) Displays subscription properties, and contains the **Watch for notifications** button.\r\n\r\n**Other**  \r\n- [`Web.config`](OneDriveWebhooks/Web.config) Contains values used for authentication and authorization.\r\n- [`Startup.cs`](OneDriveWebhooks/App_Start/Startup.cs) Contains code used for authentication and authorization when the app starts. The sample uses [OpenID Connect](https://msdn.microsoft.com/en-us/library/azure/jj573266.aspx) to authenticate and authorize the user.\r\n\r\n## Troubleshooting\r\n\r\n| Issue                                                                                             | Resolution                                                                                      |\r\n|:--------------------------------------------------------------------------------------------------|:------------------------------------------------------------------------------------------------|\r\n| The app opens to a *Server Error in '/' Application. The resource cannot be found.* browser page. | Make sure that a CSHTML view file isn't the active tab when you run the app from Visual Studio. |\r\n\r\n\r\n## Questions and comments\r\n\r\nWe'd love to get your feedback about OneDrive Webhooks ASP.NET\r\nsample. You can send your questions and suggestions to us in the [Issues](https://github.com/OneDrive/onedrive-webhooks-aspnet)\r\nsection of this repository.\r\n\r\nQuestions about OneDrive or Office 365 in general should be posted to [Stack Overflow](http://stackoverflow.com/questions/tagged/OneDrive+Office365).\r\nMake sure that your questions or comments are tagged with *OneDrive* or *Office365*.\r\n\r\nYou can suggest changes for OneDrive on [UserVoice](onedrive.uservoice.com/forums/262982-onedrive/category/89523-developer).\r\n\r\n\r\n## Additional resources\r\n\r\n* [OneDrive API Reference](https://dev.onedrive.com/README.htm)\r\n* [Office 365 Developer Portal](https://dev.office.com)\r\n\r\n## License\r\n\r\nSee [LICENSE](LICENSE.md) for the license for this sample code.\r\n\r\nThis project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fonedrive%2Fonedrive-webhooks-aspnet","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fonedrive%2Fonedrive-webhooks-aspnet","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fonedrive%2Fonedrive-webhooks-aspnet/lists"}