You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
*[Configure a tunnel for your localhost](#Configure-a-tunnel-for-your-localhost)
28
-
29
-
*[Configure and run the web app](#Configure-and-run-the-web-app)
30
-
31
-
*[Contributing](#contributing)
32
-
33
-
*[Questions and Comments](#Questions-and-Comments)
34
-
35
-
*[Additional resources](#Additional-resources)
36
-
37
-
38
-
## Introduction
39
-
<aname="introduction"></a>
40
-
41
-
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.
42
-
43
-
- Sign-in your users with their work or school account to get an access token.
44
-
- Use the access token to create a webhook subscription.
45
-
- Send back a validation token to confirm the notification URL.
46
-
- Listen for notifications from Microsoft Graph.
47
-
- Request for more information in Microsoft Office 365 using data in the notification.
To use the Webhook sample, you need the following:
68
-
69
-
-[Node.js](https://nodejs.org/) version 4 or 5.
70
-
- A [work or school account](http://dev.office.com/devprogram).
71
-
72
-
## Register the app
73
-
<aname="Register-the-app"></a>
74
-
75
-
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).
76
-
77
-
1. Sign in to the Azure portal using either a work or school account or a personal Microsoft account.
78
-
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).
79
-
1. In the left-hand navigation pane, select the **Azure Active Directory service** , and then select **App registrations.**
80
-

81
-
82
-
1. Choose **New application registration**.
83
-
84
-
1. Enter a friendly name for the application.
85
-
1. Choose 'Web app/API' as the **Application Type**.
86
-
1. Enter `http://localhost:3000/callback` for the **Sign-on URL**.
87
-
1. In the Supported account types section, select Accounts in any organizational directory and personal Microsoft accounts (e.g. Skype, Xbox, Outlook.com).
88
-
1. Click **Create**.
89
-
90
-
1. Choose your new application from the list of registered applications.
91
-
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.
1. Choose **Select an API** > **Microsoft Graph**, and then click **Select**.
97
-
1. Choose **Select permissions**, scroll down to **Delegated Permissions**, choose **Mail.Read**, and then click **Select**.
98
-
1. Click **Done**.
99
-

100
-
101
-
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.**
102
-
103
-

104
-
105
-
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.
106
-
107
-
You'll use the **application ID** and **secret** to configure the app.
108
-
109
-
## Configure a tunnel for your localhost
110
-
111
-
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)
112
-
113
-
For this sample, we use [ngrok](https://ngrok.com/) to create the tunnel. To configure ngrok:
114
-
115
-
1.[Download](https://ngrok.com/download) and unzip the ngrok binaries for your platform.
116
-
1. Type the following command:
117
-
118
-
```Shell
119
-
ngrok http 3000
120
-
```
121
-
122
-
1. Take note of the *https public URL* that ngrok provides for you. This is an example:
123
-
124
-
```http
125
-
https://{NGROK_ID}.ngrok.io
126
-
```
127
-
128
-
You'll need the `NGROK_ID` value in the next section.
129
-
130
-
## Configure and run the web app
131
-
132
-
1. Use a text editor to open `constants.js`.
133
-
1. Replace `ENTER_YOUR_CLIENT_ID` with the client ID of your registered Azure application.
134
-
1. Replace `ENTER_YOUR_SECRET` with the client secret of your registered Azure application.
135
-
1. Replace `NGROK_ID` with the value in *https public URL* from the previous section.
136
-

137
-
1. Install the dependencies running the following command:
138
-
139
-
```Shell
140
-
npm install
141
-
```
142
-
143
-
1. Start the application with the following command:
144
-
145
-
```Shell
146
-
npm start
147
-
```
148
-
> **Note:** You can also make the application wait for a debugger. To wait for a debugger, use the following command instead:
149
-
>
150
-
> ```Shell
151
-
> npm run debug
152
-
> ```
153
-
> 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).
154
-
155
-
1. Open a browser and go to [http://localhost:3000](http://localhost:3000).
156
-
157
-
## Contributing
158
-
159
-
If you'd like to contribute to this sample, see [CONTRIBUTING.MD](/CONTRIBUTING.md).
160
-
161
-
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.
162
-
163
-
## Questions and comments
164
-
165
-
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.
166
-
167
-
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].
168
-
169
-
## Additional resources
170
-
171
-
- [Overview of Microsoft Graph](http://graph.microsoft.io/)
*[Configure a tunnel for your localhost](#Configure-a-tunnel-for-your-localhost)
28
+
29
+
*[Configure and run the web app](#Configure-and-run-the-web-app)
30
+
31
+
*[Contributing](#contributing)
32
+
33
+
*[Questions and Comments](#Questions-and-Comments)
34
+
35
+
*[Additional resources](#Additional-resources)
36
+
37
+
38
+
## Introduction
39
+
<aname="introduction"></a>
40
+
41
+
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.
42
+
43
+
- Sign-in your users with their work or school account to get an access token.
44
+
- Use the access token to create a webhook subscription.
45
+
- Send back a validation token to confirm the notification URL.
46
+
- Listen for notifications from Microsoft Graph.
47
+
- Request for more information in Microsoft Office 365 using data in the notification.
To use the Webhook sample, you need the following:
68
+
69
+
-[Node.js](https://nodejs.org/) version 4 or 5.
70
+
- A [work or school account](http://dev.office.com/devprogram).
71
+
72
+
## Register the app
73
+
<aname="Register-the-app"></a>
74
+
75
+
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).
76
+
77
+
1. Sign in to the Azure portal using either a work or school account or a personal Microsoft account.
78
+
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).
79
+
1. In the left-hand navigation pane, select the **Azure Active Directory service** , and then select **App registrations.**
80
+

81
+
82
+
1. Choose **New application registration**.
83
+
84
+
1. Enter a friendly name for the application.
85
+
1. Choose 'Web app/API' as the **Application Type**.
86
+
1. Enter `http://localhost:3000/callback` for the **Sign-on URL**.
87
+
1. In the Supported account types section, select Accounts in any organizational directory and personal Microsoft accounts (e.g. Skype, Xbox, Outlook.com).
88
+
1. Click **Create**.
89
+
90
+
1. Choose your new application from the list of registered applications.
91
+
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.
1. Choose **Select an API** > **Microsoft Graph**, and then click **Select**.
97
+
1. Choose **Select permissions**, scroll down to **Delegated Permissions**, choose **Mail.Read**, and then click **Select**.
98
+
1. Click **Done**.
99
+

100
+
101
+
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.**
102
+
103
+

104
+
105
+
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.
106
+
107
+
You'll use the **application ID** and **secret** to configure the app.
108
+
109
+
## Configure a tunnel for your localhost
110
+
111
+
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)
112
+
113
+
For this sample, we use [ngrok](https://ngrok.com/) to create the tunnel. To configure ngrok:
114
+
115
+
1.[Download](https://ngrok.com/download) and unzip the ngrok binaries for your platform.
116
+
1. Type the following command:
117
+
118
+
```Shell
119
+
ngrok http 3000
120
+
```
121
+
122
+
1. Take note of the *https public URL* that ngrok provides for you. This is an example:
123
+
124
+
```http
125
+
https://{NGROK_ID}.ngrok.io
126
+
```
127
+
128
+
You'll need the `NGROK_ID` value in the next section.
129
+
130
+
## Configure and run the web app
131
+
132
+
1. Use a text editor to open `constants.js`.
133
+
1. Replace `ENTER_YOUR_CLIENT_ID` with the client ID of your registered Azure application.
134
+
1. Replace `ENTER_YOUR_SECRET` with the client secret of your registered Azure application.
135
+
1. Replace `NGROK_ID` with the value in *https public URL* from the previous section.
136
+

137
+
1. Install the dependencies running the following command:
138
+
139
+
```Shell
140
+
npm install
141
+
```
142
+
143
+
1. Start the application with the following command:
144
+
145
+
```Shell
146
+
npm start
147
+
```
148
+
> **Note:** You can also make the application wait for a debugger. To wait for a debugger, use the following command instead:
149
+
>
150
+
> ```Shell
151
+
> npm run debug
152
+
> ```
153
+
> 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).
154
+
155
+
1. Open a browser and go to [http://localhost:3000](http://localhost:3000).
156
+
157
+
## Contributing
158
+
159
+
If you'd like to contribute to this sample, see [CONTRIBUTING.MD](/CONTRIBUTING.md).
160
+
161
+
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.
162
+
163
+
## Questions and comments
164
+
165
+
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.
166
+
167
+
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].
168
+
169
+
## Additional resources
170
+
171
+
- [Overview of Microsoft Graph](http://graph.microsoft.io/)
0 commit comments