Skip to content

Commit 6a9dccf

Browse files
authored
Merge pull request #39 from microsoftgraph/feature/platform-upgrade
Feature/platform upgrade
2 parents 9d3256b + e318e40 commit 6a9dccf

File tree

3 files changed

+5566
-3834
lines changed

3 files changed

+5566
-3834
lines changed

README.md

Lines changed: 177 additions & 177 deletions
Original file line numberDiff line numberDiff line change
@@ -1,177 +1,177 @@
1-
---
2-
page_type: sample
3-
products:
4-
- ms-graph
5-
languages:
6-
- nodejs
7-
- javascript
8-
description: "Create Microsoft Graph webhook subscriptions for a Node.js app, so that it can receive notifications of changes in a user’s Microsoft account data."
9-
extensions:
10-
contentType: samples
11-
technologies:
12-
- Microsoft Graph
13-
createdDate: 3/9/2016 4:12:18 PM
14-
---
15-
# Microsoft Graph Webhooks Sample for Node.js
16-
17-
[![Build Status](https://travis-ci.org/microsoftgraph/nodejs-webhooks-rest-sample.svg)](https://travis-ci.org/microsoftgraph/nodejs-webhooks-rest-sample)
18-
19-
## Table Of Contents. ##
20-
* [Introduction](#introduction)
21-
22-
* [Screenshots](#screenshots)
23-
24-
* [Prerequisites](#prerequisites)
25-
26-
* [Register the app](#Register-the-app)
27-
28-
* [Configure a tunnel for your localhost](#Configure-a-tunnel-for-your-localhost)
29-
30-
* [Configure and run the web app](#Configure-and-run-the-web-app)
31-
32-
* [Contributing](#contributing)
33-
34-
* [Questions and Comments](#Questions-and-Comments)
35-
36-
* [Additional resources](#Additional-resources)
37-
38-
39-
## Introduction
40-
<a name="introduction"></a>
41-
42-
This Node.js sample shows how to start getting notifications from Microsoft Graph. The following are common tasks that a web application performs with Microsoft Graph webhooks.
43-
44-
- Sign-in your users with their work or school account to get an access token.
45-
- Use the access token to create a webhook subscription.
46-
- Send back a validation token to confirm the notification URL.
47-
- Listen for notifications from Microsoft Graph.
48-
- Request for more information in Microsoft Office 365 using data in the notification.
49-
50-
## Screenshots
51-
<a name="screenshots"></a>
52-
53-
1. First you need sign in.
54-
55-
![sign in](https://user-images.githubusercontent.com/3375461/31968683-c373ad30-b8c6-11e7-9d01-413fab9fd6d5.png)
56-
57-
1. Once signing in, the app will listen to the incoming emails.
58-
59-
![listening](https://user-images.githubusercontent.com/3375461/31968718-e19696c4-b8c6-11e7-91f2-f1806be0b134.png)
60-
61-
1. After sending the email to the address, you will see the email in the app.
62-
63-
![email](https://user-images.githubusercontent.com/3375461/31968754-0ce4dafc-b8c7-11e7-8458-8152d598228e.png)
64-
65-
## Prerequisites
66-
<a name="prerequisites"></a>
67-
68-
To use the Webhook sample, you need the following:
69-
70-
- [Node.js](https://nodejs.org/) version 4 or 5.
71-
- A [work or school account](http://dev.office.com/devprogram).
72-
73-
## Register the app
74-
<a name="Register-the-app"></a>
75-
76-
This app uses the Azure AD endpoint, so you'll register it in the [Azure Portal](https://ms.portal.azure.com/#blade/Microsoft_AAD_IAM/ApplicationsListBlade).
77-
78-
1. Sign in to the Azure portal using either a work or school account or a personal Microsoft account.
79-
1. If your account gives you access to more than one tenant, select your account in the top right corner, and set your portal session to the desired Azure AD tenant (using Switch Directory).
80-
1. In the left-hand navigation pane, select the **Azure Active Directory service** , and then select **App registrations.**
81-
![](readme-images/registrations.png)
82-
83-
1. Choose **New application registration**.
84-
85-
1. Enter a friendly name for the application.
86-
1. Choose 'Web app/API' as the **Application Type**.
87-
1. Enter `http://localhost:3000/callback` for the **Sign-on URL**.
88-
1. In the Supported account types section, select Accounts in any organizational directory and personal Microsoft accounts (e.g. Skype, Xbox, Outlook.com).
89-
1. Click **Create**.
90-
91-
1. Choose your new application from the list of registered applications.
92-
On the app **Overview** page, find the **Application (client) ID** value and record it for later. You'll need it to configure the Visual Studio configuration file for this project.
93-
![](readme-images/client.png)
94-
1. Configure permissions for your application:
95-
96-
1. Choose **Settings** > **Required permissions** > **Add**.
97-
1. Choose **Select an API** > **Microsoft Graph**, and then click **Select**.
98-
1. Choose **Select permissions**, scroll down to **Delegated Permissions**, choose **Mail.Read**, and then click **Select**.
99-
1. Click **Done**.
100-
![](readme-images/permissions.png)
101-
102-
1. Select **Certificates & secrets** under **Manage**. Select the **New client secret** button. Enter a value in Description and select one of the options for Expires and choose **Add.**
103-
104-
![](readme-images/secrets.png)
105-
106-
1. **Important**: Copy the key value--this is your app's secret. You won't be able to access this value again after you leave this blade.
107-
108-
You'll use the **application ID** and **secret** to configure the app.
109-
110-
## Configure a tunnel for your localhost
111-
112-
The sample uses localhost as the development server. For this reason, we need a tunnel that can forward requests from a URL on the Internet to your localhost. If for any reason, you don't want to use a tunnel, see [Hosting without a tunnel](https://github.com/OfficeDev/Microsoft-Graph-Nodejs-Webhooks/wiki/Hosting-the-sample-without-a-tunnel). If you want a detailed explanation about why to use a tunnel, see [Why do I have to use a tunnel?](https://github.com/OfficeDev/Microsoft-Graph-Nodejs-Webhooks/wiki/Why-do-I-have-to-use-a-tunnel)
113-
114-
For this sample, we use [ngrok](https://ngrok.com/) to create the tunnel. To configure ngrok:
115-
116-
1. [Download](https://ngrok.com/download) and unzip the ngrok binaries for your platform.
117-
1. Type the following command:
118-
119-
```Shell
120-
ngrok http 3000
121-
```
122-
123-
1. Take note of the *https public URL* that ngrok provides for you. This is an example:
124-
125-
```http
126-
https://{NGROK_ID}.ngrok.io
127-
```
128-
129-
You'll need the `NGROK_ID` value in the next section.
130-
131-
## Configure and run the web app
132-
133-
1. Use a text editor to open `constants.js`.
134-
1. Replace `ENTER_YOUR_CLIENT_ID` with the client ID of your registered Azure application.
135-
1. Replace `ENTER_YOUR_SECRET` with the client secret of your registered Azure application.
136-
1. Replace `NGROK_ID` with the value in *https public URL* from the previous section.
137-
![](const)
138-
1. Install the dependencies running the following command:
139-
140-
```Shell
141-
npm install
142-
```
143-
144-
1. Start the application with the following command:
145-
146-
```Shell
147-
npm start
148-
```
149-
> **Note:** You can also make the application wait for a debugger. To wait for a debugger, use the following command instead:
150-
>
151-
> ```Shell
152-
> npm run debug
153-
> ```
154-
> You can also attach the debugger included in Microsoft Visual Studio Code. For more information, see [Debugging in Visual Studio Code](https://code.visualstudio.com/Docs/editor/debugging).
155-
156-
1. Open a browser and go to [http://localhost:3000](http://localhost:3000).
157-
158-
## Contributing
159-
160-
If you'd like to contribute to this sample, see [CONTRIBUTING.MD](/CONTRIBUTING.md).
161-
162-
This 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 [[email protected]](mailto:[email protected]) with any additional questions or comments.
163-
164-
## Questions and comments
165-
166-
We'd love to get your feedback about the Microsoft Graph Webhook sample. You can send your questions and suggestions to us in the [Issues](https://github.com/OfficeDev/Microsoft-Graph-NodeJs-Webhooks/issues) section of this repository.
167-
168-
Office 365 development questions? Post them to [Stack Overflow](http://stackoverflow.com/questions/tagged/Office365+API). Make sure to tag your questions or comments with [Office365] and [API].
169-
170-
## Additional resources
171-
172-
- [Overview of Microsoft Graph](http://graph.microsoft.io/)
173-
- [Subscription reference documentation](https://graph.microsoft.io/en-us/docs/api-reference/beta/resources/subscription)
174-
175-
## Copyright
176-
177-
Copyright (c) 2019 Microsoft. All rights reserved.
1+
---
2+
page_type: sample
3+
products:
4+
- ms-graph
5+
languages:
6+
- nodejs
7+
- javascript
8+
description: "Create Microsoft Graph webhook subscriptions for a Node.js app, so that it can receive notifications of changes in a user’s Microsoft account data."
9+
extensions:
10+
contentType: samples
11+
technologies:
12+
- Microsoft Graph
13+
createdDate: 3/9/2016 4:12:18 PM
14+
---
15+
# Microsoft Graph Webhooks Sample for Node.js
16+
17+
[![Build Status](https://travis-ci.org/microsoftgraph/nodejs-webhooks-rest-sample.svg)](https://travis-ci.org/microsoftgraph/nodejs-webhooks-rest-sample)
18+
19+
## Table Of Contents. ##
20+
* [Introduction](#introduction)
21+
22+
* [Screenshots](#screenshots)
23+
24+
* [Prerequisites](#prerequisites)
25+
26+
* [Register the app](#Register-the-app)
27+
28+
* [Configure a tunnel for your localhost](#Configure-a-tunnel-for-your-localhost)
29+
30+
* [Configure and run the web app](#Configure-and-run-the-web-app)
31+
32+
* [Contributing](#contributing)
33+
34+
* [Questions and Comments](#Questions-and-Comments)
35+
36+
* [Additional resources](#Additional-resources)
37+
38+
39+
## Introduction
40+
<a name="introduction"></a>
41+
42+
This Node.js sample shows how to start getting notifications from Microsoft Graph. The following are common tasks that a web application performs with Microsoft Graph webhooks.
43+
44+
- Sign-in your users with their work or school account to get an access token.
45+
- Use the access token to create a webhook subscription.
46+
- Send back a validation token to confirm the notification URL.
47+
- Listen for notifications from Microsoft Graph.
48+
- Request for more information in Microsoft Office 365 using data in the notification.
49+
50+
## Screenshots
51+
<a name="screenshots"></a>
52+
53+
1. First you need sign in.
54+
55+
![sign in](https://user-images.githubusercontent.com/3375461/31968683-c373ad30-b8c6-11e7-9d01-413fab9fd6d5.png)
56+
57+
1. Once signing in, the app will listen to the incoming emails.
58+
59+
![listening](https://user-images.githubusercontent.com/3375461/31968718-e19696c4-b8c6-11e7-91f2-f1806be0b134.png)
60+
61+
1. After sending the email to the address, you will see the email in the app.
62+
63+
![email](https://user-images.githubusercontent.com/3375461/31968754-0ce4dafc-b8c7-11e7-8458-8152d598228e.png)
64+
65+
## Prerequisites
66+
<a name="prerequisites"></a>
67+
68+
To use the Webhook sample, you need the following:
69+
70+
- [Node.js](https://nodejs.org/) version 10 or 12.
71+
- A [work or school account](http://dev.office.com/devprogram).
72+
73+
## Register the app
74+
<a name="Register-the-app"></a>
75+
76+
This app uses the Azure AD endpoint, so you'll register it in the [Azure Portal](https://ms.portal.azure.com/#blade/Microsoft_AAD_IAM/ApplicationsListBlade).
77+
78+
1. Sign in to the Azure portal using either a work or school account or a personal Microsoft account.
79+
1. If your account gives you access to more than one tenant, select your account in the top right corner, and set your portal session to the desired Azure AD tenant (using Switch Directory).
80+
1. In the left-hand navigation pane, select the **Azure Active Directory service** , and then select **App registrations.**
81+
![](readme-images/registrations.png)
82+
83+
1. Choose **New application registration**.
84+
85+
1. Enter a friendly name for the application.
86+
1. Choose 'Web app/API' as the **Application Type**.
87+
1. Enter `http://localhost:3000/callback` for the **Sign-on URL**.
88+
1. In the Supported account types section, select Accounts in any organizational directory and personal Microsoft accounts (e.g. Skype, Xbox, Outlook.com).
89+
1. Click **Create**.
90+
91+
1. Choose your new application from the list of registered applications.
92+
On the app **Overview** page, find the **Application (client) ID** value and record it for later. You'll need it to configure the Visual Studio configuration file for this project.
93+
![](readme-images/client.png)
94+
1. Configure permissions for your application:
95+
96+
1. Choose **Settings** > **Required permissions** > **Add**.
97+
1. Choose **Select an API** > **Microsoft Graph**, and then click **Select**.
98+
1. Choose **Select permissions**, scroll down to **Delegated Permissions**, choose **Mail.Read**, and then click **Select**.
99+
1. Click **Done**.
100+
![](readme-images/permissions.png)
101+
102+
1. Select **Certificates & secrets** under **Manage**. Select the **New client secret** button. Enter a value in Description and select one of the options for Expires and choose **Add.**
103+
104+
![](readme-images/secrets.png)
105+
106+
1. **Important**: Copy the key value--this is your app's secret. You won't be able to access this value again after you leave this blade.
107+
108+
You'll use the **application ID** and **secret** to configure the app.
109+
110+
## Configure a tunnel for your localhost
111+
112+
The sample uses localhost as the development server. For this reason, we need a tunnel that can forward requests from a URL on the Internet to your localhost. If for any reason, you don't want to use a tunnel, see [Hosting without a tunnel](https://github.com/OfficeDev/Microsoft-Graph-Nodejs-Webhooks/wiki/Hosting-the-sample-without-a-tunnel). If you want a detailed explanation about why to use a tunnel, see [Why do I have to use a tunnel?](https://github.com/OfficeDev/Microsoft-Graph-Nodejs-Webhooks/wiki/Why-do-I-have-to-use-a-tunnel)
113+
114+
For this sample, we use [ngrok](https://ngrok.com/) to create the tunnel. To configure ngrok:
115+
116+
1. [Download](https://ngrok.com/download) and unzip the ngrok binaries for your platform.
117+
1. Type the following command:
118+
119+
```Shell
120+
ngrok http 3000
121+
```
122+
123+
1. Take note of the *https public URL* that ngrok provides for you. This is an example:
124+
125+
```http
126+
https://{NGROK_ID}.ngrok.io
127+
```
128+
129+
You'll need the `NGROK_ID` value in the next section.
130+
131+
## Configure and run the web app
132+
133+
1. Use a text editor to open `constants.js`.
134+
1. Replace `ENTER_YOUR_CLIENT_ID` with the client ID of your registered Azure application.
135+
1. Replace `ENTER_YOUR_SECRET` with the client secret of your registered Azure application.
136+
1. Replace `NGROK_ID` with the value in *https public URL* from the previous section.
137+
![](const)
138+
1. Install the dependencies running the following command:
139+
140+
```Shell
141+
npm install
142+
```
143+
144+
1. Start the application with the following command:
145+
146+
```Shell
147+
npm start
148+
```
149+
> **Note:** You can also make the application wait for a debugger. To wait for a debugger, use the following command instead:
150+
>
151+
> ```Shell
152+
> npm run debug
153+
> ```
154+
> You can also attach the debugger included in Microsoft Visual Studio Code. For more information, see [Debugging in Visual Studio Code](https://code.visualstudio.com/Docs/editor/debugging).
155+
156+
1. Open a browser and go to [http://localhost:3000](http://localhost:3000).
157+
158+
## Contributing
159+
160+
If you'd like to contribute to this sample, see [CONTRIBUTING.MD](/CONTRIBUTING.md).
161+
162+
This 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 [[email protected]](mailto:[email protected]) with any additional questions or comments.
163+
164+
## Questions and comments
165+
166+
We'd love to get your feedback about the Microsoft Graph Webhook sample. You can send your questions and suggestions to us in the [Issues](https://github.com/OfficeDev/Microsoft-Graph-NodeJs-Webhooks/issues) section of this repository.
167+
168+
Office 365 development questions? Post them to [Stack Overflow](http://stackoverflow.com/questions/tagged/Office365+API). Make sure to tag your questions or comments with [Office365] and [API].
169+
170+
## Additional resources
171+
172+
- [Overview of Microsoft Graph](http://graph.microsoft.io/)
173+
- [Subscription reference documentation](https://graph.microsoft.io/en-us/docs/api-reference/beta/resources/subscription)
174+
175+
## Copyright
176+
177+
Copyright (c) 2019 Microsoft. All rights reserved.

0 commit comments

Comments
 (0)