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
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.
5
6
6
-
* Sign-in your users with their work or school account to get an access token.
7
-
* Use the access token to create a webhook subscription.
8
-
* Send back a validation token to confirm the notification URL.
9
-
* Listen for notifications from Microsoft Graph.
10
-
* Request for more information in Microsoft Office 365 using data in the notification.
7
+
- Sign-in your users with their work or school account to get an access token.
8
+
- Use the access token to create a webhook subscription.
9
+
- Send back a validation token to confirm the notification URL.
10
+
- Listen for notifications from Microsoft Graph.
11
+
- Request for more information in Microsoft Office 365 using data in the notification.
To use the Webhook sample, you need the following:
29
30
30
-
*[Node.js](https://nodejs.org/) version 4 or 5.
31
-
* A [work or school account](http://dev.office.com/devprogram).
31
+
-[Node.js](https://nodejs.org/) version 4 or 5.
32
+
- A [work or school account](http://dev.office.com/devprogram).
32
33
33
34
## Register the app
34
35
35
36
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).
36
37
37
38
1. Sign in to the portal using your work or school account.
38
39
39
-
2. Choose **New application registration**.
40
-
41
-
a. Enter a friendly name for the application.
40
+
1. Choose **New application registration**.
42
41
43
-
b. Choose 'Web app/API' as the **Application Type**.
42
+
1. Enter a friendly name for the application.
43
+
1. Choose 'Web app/API' as the **Application Type**.
44
+
1. Enter `http://localhost:3000/callback` for the **Sign-on URL**.
45
+
1. Click **Create**.
44
46
45
-
c. Enter *http://localhost:3000/callback* for the **Sign-on URL**.
46
-
47
-
d. Click **Create**.
47
+
1. Choose your new application from the list of registered applications.
48
48
49
-
3. Choose your new application from the list of registered applications.
49
+
1. Copy and store the Application ID. This value is shown in the **Essentials** pane or in **Settings** > **Properties**.
50
50
51
-
4. Copy and store the Application ID. This value is shown in the **Essentials**pane or in **Settings**>**Properties**.
51
+
1. To enable multi-tenanted support for the app, choose **Settings** > **Properties**and set **Multi-tenanted**to**Yes**.
52
52
53
-
5. To enable multi-tenanted support for the app, choose **Settings** > **Properties** and set **Multi-tenanted** to **Yes**.
1. Choose **Select an API** > **Microsoft Graph**, and then click **Select**.
57
+
1. Choose **Select permissions**, scroll down to **Delegated Permissions**, choose **Read user mail**, and then click **Select**.
58
+
1. Click **Done**.
56
59
57
-
a. Choose **Settings** > **Required permissions** > **Add**.
58
-
59
-
b. Choose **Select an API** > **Microsoft Graph**, and then click **Select**.
60
-
61
-
c. Choose **Select permissions**, scroll down to **Delegated Permissions**, choose **Read user mail**, and then click **Select**.
62
-
63
-
d. Click **Done**.
60
+
1. Choose **Settings** > **Keys**. Enter a description, choose a duration for the key, and then click **Save**.
64
61
65
-
7. Choose **Settings** > **Keys**. Enter a description, choose a duration for the key, and then click **Save**.
66
-
67
-
8.**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.
62
+
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.
68
63
69
64
You'll use the application ID and secret to configure the app.
70
65
71
66
## Configure a tunnel for your localhost
72
67
73
-
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 our *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)
68
+
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)
74
69
75
70
For this sample, we use [ngrok](https://ngrok.com/) to create the tunnel. To configure ngrok:
76
71
77
72
1.[Download](https://ngrok.com/download) and unzip the ngrok binaries for your platform.
78
-
2. Type the following command:
79
-
80
-
`ngrok http 3000`
81
-
82
-
3. Take note of the *https public URL* that ngrok provides for you. This is an example:
73
+
1. Type the following command:
74
+
75
+
```Shell
76
+
ngrok http 3000
77
+
```
78
+
79
+
1. Take note of the *https public URL* that ngrok provides for you. This is an example:
83
80
84
-
`https://NGROK_ID.ngrok.io`
81
+
```http
82
+
https://{NGROK_ID}.ngrok.io
83
+
```
85
84
86
-
You'll need the *NGROK_ID* value in the next section.
85
+
You'll need the `NGROK_ID` value in the next section.
87
86
88
87
## Configure and run the web app
89
88
90
89
1. Use a text editor to open `constants.js`.
91
-
2. Replace *ENTER_YOUR_CLIENT_ID* with the client ID of your registered Azure application.
92
-
3. Replace *ENTER_YOUR_SECRET* with the client secret of your registered Azure application.
93
-
4. Replace *NGROK_ID* with the value in *https public URL* from the previous section.
94
-
5. Install the dependencies running the following command:
95
-
```
90
+
1. Replace `ENTER_YOUR_CLIENT_ID` with the client ID of your registered Azure application.
91
+
1. Replace `ENTER_YOUR_SECRET` with the client secret of your registered Azure application.
92
+
1. Replace `NGROK_ID` with the value in *https public URL* from the previous section.
93
+
1. Install the dependencies running the following command:
94
+
95
+
```Shell
96
96
npm install
97
97
```
98
98
99
-
6. Start the application with the following command:
100
-
```
99
+
1. Start the application with the following command:
100
+
101
+
```Shell
101
102
npm start
102
103
```
103
-
> Note: You can also make the application wait for a debugger. To wait for a debugger, use the following command instead:
104
-
```
105
-
npm run debug
106
-
```
107
-
You can 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).
108
-
109
-
7. Open a browser and go to http://localhost:3000.
104
+
> **Note:** You can also make the application wait for a debugger. To wait for a debugger, use the following command instead:
105
+
>
106
+
> ```Shell
107
+
> npm run debug
108
+
> ```
109
+
> 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).
110
+
111
+
1. Open a browser and go to [http://localhost:3000](http://localhost:3000).
110
112
111
-
<a name="contributing"></a>
112
-
## Contributing ##
113
+
## Contributing
113
114
114
115
If you'd like to contribute to this sample, see [CONTRIBUTING.MD](/CONTRIBUTING.md).
115
116
@@ -120,11 +121,12 @@ This project has adopted the [Microsoft Open Source Code of Conduct](https://ope
120
121
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.
121
122
122
123
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].
123
-
124
+
124
125
## Additional resources
125
126
126
-
* [Overview of Microsoft Graph](http://graph.microsoft.io/)
0 commit comments