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
1. Update the application to use the `connect-flash` and `express-session` middleware. Open the `./app.js` file and add the following `require` statement to the top of the file.
75
+
1. Update the application to use the `connect-flash` and `express-session` middleware. Open **./app.js** and add the following `require` statement to the top of the file.
76
76
77
77
```javascript
78
78
const session = require('express-session');
@@ -88,21 +88,21 @@ Before moving on, install some additional packages that you will use later:
88
88
89
89
In this section you will implement the UI for the app.
90
90
91
-
1. Open the `./views/layout.hbs` file and replace the entire contents with the following code.
91
+
1. Open **./views/layout.hbs** and replace the entire contents with the following code.
This code adds [Bootstrap](http://getbootstrap.com/) for simple styling, and [Font Awesome](https://fontawesome.com/) for some simple icons. It also defines a global layout with a nav bar.
96
96
97
-
1. Open `./public/stylesheets/style.css` and replace its entire contents with the following.
97
+
1. Open **./public/stylesheets/style.css** and replace its entire contents with the following.
Copy file name to clipboardExpand all lines: tutorial/04-add-aad-auth.md
+9-9Lines changed: 9 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,30 +2,30 @@
2
2
3
3
In this exercise you will extend the application from the previous exercise to support authentication with Azure AD. This is required to obtain the necessary OAuth access token to call the Microsoft Graph. In this step you will integrate the [msal-node](https://github.com/AzureAD/microsoft-authentication-library-for-js/tree/dev/lib/msal-node) library into the application.
4
4
5
-
1. Create a new file named `.env` file in the root of your application, and add the following code.
5
+
1. Create a new file named **.env** in the root of your application, and add the following code.
Replace `YOUR_APP_ID_HERE` with the application ID from the Application Registration Portal, and replace `YOUR_APP_SECRET_HERE` with the client secret you generated.
10
10
11
11
> [!IMPORTANT]
12
-
> If you're using source control such as git, now would be a good time to exclude the `.env` file from source control to avoid inadvertently leaking your app ID and password.
12
+
> If you're using source control such as git, now would be a good time to exclude the **.env** file from source control to avoid inadvertently leaking your app ID and password.
13
13
14
-
1. Open `./app.js` and add the following line to the top of the file to load the `.env` file.
14
+
1. Open **./app.js** and add the following line to the top of the file to load the **.env** file.
15
15
16
16
```javascript
17
17
require('dotenv').config();
18
18
```
19
19
20
20
## Implement sign-in
21
21
22
-
1. Locate the line `var indexRouter = require('./routes/index');`in`./app.js`. Insert the following code **before** that line.
22
+
1. Locate the line `var indexRouter = require('./routes/index');`in**./app.js**. Insert the following code **before** that line.
This code initializes the msal-node library with the app ID and password for the app.
27
27
28
-
1. Create a newfilein the `./routes` directory named `auth.js` and add the following code.
28
+
1. Create a newfilein the **./routes** directory named **auth.js** and add the following code.
29
29
30
30
```javascript
31
31
var router = require('express-promise-router')();
@@ -116,11 +116,11 @@ In this exercise you will extend the application from the previous exercise to s
116
116
117
117
The `signin` route calls the `getAuthCodeUrl`function to generate the login URL, then redirects the browser to that URL.
118
118
119
-
The `callback` route is where Azure redirects after the signin is complete. The code calls the `acquireTokenByCode` function to exchange the authorization code for an access token. Once the token is obtained, it redirects back to the home page with the access token in the temporary error value. We'll use this to verify that our sign-in is working before moving on. Before we test, we need to configure the Express app to use the new router from `./routes/auth.js`.
119
+
The `callback` route is where Azure redirects after the signin is complete. The code calls the `acquireTokenByCode` function to exchange the authorization code for an access token. Once the token is obtained, it redirects back to the home page with the access token in the temporary error value. We'll use this to verify that our sign-in is working before moving on. Before we test, we need to configure the Express app to use the new router from **./routes/auth.js**.
120
120
121
121
The `signout` method logs the user out and destroys the session.
122
122
123
-
1. Open `./app.js` and insert the following code **before** the `var app = express();` line.
123
+
1. Open **./app.js** and insert the following code **before** the `var app = express();` line.
124
124
125
125
```javascript
126
126
var authRouter = require('./routes/auth');
@@ -136,7 +136,7 @@ Start the server and browse to `https://localhost:3000`. Click the sign-in butto
136
136
137
137
### Get user details
138
138
139
-
1. Create a new file in the root of the project named `graph.js` and add the following code.
139
+
1. Create a new file in the root of the project named **graph.js** and add the following code.
140
140
141
141
```javascript
142
142
var graph = require('@microsoft/microsoft-graph-client');
@@ -170,7 +170,7 @@ Start the server and browse to `https://localhost:3000`. Click the sign-in butto
170
170
171
171
This exports the `getUserDetails`function, which uses the Microsoft Graph SDK to call the `/me` endpoint and return the result.
172
172
173
-
1. Open `/auth.js` and add the following `require` statements to the top of the file.
173
+
1. Open **./routes/auth.js** and add the following `require` statements to the top of the file.
This implements a [Handlebars helper](http://handlebarsjs.com/#helpers) to format the ISO 8601 date returned by Microsoft Graph into something more human-friendly.
128
128
129
-
1. Create a new file in the `./views` directory named `calendar.hbs` and add the following code.
129
+
1. Create a new file in the **./views** directory named **calendar.hbs** and add the following code.
0 commit comments