Skip to content

Commit 3bce18f

Browse files
committed
patch sample
1 parent fc8d925 commit 3bce18f

File tree

9 files changed

+1601
-62
lines changed

9 files changed

+1601
-62
lines changed

README.md

+25-19
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
---
22
page_type: sample
33
languages:
4-
- nodejs
4+
- javascript
55
products:
6-
- azure
6+
- nodejs
7+
- passport-azure-ad
78
- azure-active-directory
89
description: "This sample demonstrates how to set up OpenId Connect authentication in a web application built using Node.js with Express."
910
---
1011

11-
# Azure Active Directory OIDC Node.js Web Sample
12+
# Azure Active Directory OIDC Node.js web app sample
1213

13-
| [Library](https://github.com/AzureAD/passport-azure-ad) | [Docs](https://aka.ms/aadv2) | [Support](README.md#community-help-and-support) | [Protocol](https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-v2-protocols-oidc)
14+
| [Library](https://github.com/AzureAD/passport-azure-ad) | [Docs](https://aka.ms/aadv2) | [Support](README.md#community-help-and-support) | [Protocol](https://docs.microsoft.com/azure/active-directory/develop/active-directory-v2-protocols-oidc)
1415
| --- | --- | --- | --- |
1516

1617
This sample demonstrates how to set up OpenId Connect authentication in a web application built using Node.js with Express. The sample is designed to run on any platform.
@@ -21,7 +22,7 @@ To run this sample you will need the following:
2122

2223
* Install Node.js from http://nodejs.org/
2324

24-
* Either a [Microsoft account](https://www.outlook.com) or [Office 365 for business account](https://msdn.microsoft.com/en-us/office/office365/howto/setup-development-environment#bk_Office365Account)
25+
* Either a [Microsoft account](https://www.outlook.com) or [Office 365 for business account](https://msdn.microsoft.com/office/office365/howto/setup-development-environment#bk_Office365Account)
2526

2627
## Register the sample
2728

@@ -47,9 +48,17 @@ To run this sample you will need the following:
4748

4849
1. In the list of pages for the app, select **Authentication**.
4950
- In the **Redirect URIs** section, select **Web** in the combo-box and enter the following redirect URI:
50-
`http://localhost:3000/auth/openid/return`
51-
- In the **Advanced settings** section, set **Logout URL** to `http://localhost:3000`.
52-
- In the **Advanced settings > Implicit grant** section, check **ID tokens** as this sample requires the [Implicit grant flow](https://docs.microsoft.com/azure/active-directory/develop/v2-oauth2-implicit-grant-flow) to be enabled to sign-in the user.
51+
`http://localhost:3000/auth/openid/return` (:warning:)
52+
- In the **Advanced settings > Implicit grant and hybrid flows** section, check **ID tokens** as this sample requires the [hybrid flow](https://docs.microsoft.com/azure/active-directory/develop/v2-oauth2-implicit-grant-flow) to be enabled to sign-in the user.
53+
- Select **Save**.
54+
55+
> :warning: In this tutorial sample, we use HTTP schemes as the application runs on locahost only. However, HTTP schemes are insecure and should not be used in production.
56+
57+
1. In the list of pages for the app, select **Manifest**.
58+
- Find the key `logoutUrl` and replace its value with `http://localhost:3000/logout` (:warning:)
59+
- Select **Save**
60+
61+
> :warning: In this tutorial sample, we use HTTP schemes as the application runs on locahost only. However, HTTP schemes are insecure and should not be used in production.
5362
5463
1. Select **Save**.
5564

@@ -60,7 +69,6 @@ To run this sample you will need the following:
6069

6170
You'll need this key later to configure the application. This key value will not be displayed again, nor retrievable by any other means, so record it as soon as it is visible from the Azure portal.
6271

63-
6472
## Download the sample application and modules
6573

6674
Next, clone the sample repo and install the NPM modules.
@@ -73,10 +81,9 @@ or
7381

7482
* `$ git clone https://github.com/AzureADQuickStarts/AppModelv2-WebApp-OpenIDConnect-nodejs.git`
7583

76-
7784
From the project root directory, run the command:
7885

79-
* `$ npm install`
86+
* `$ npm install`
8087

8188

8289
## Configure the application
@@ -105,16 +112,15 @@ The default session store in this sample is `express-session`. Note that the def
105112

106113
* Run the app using the following command from your command line.
107114

108-
```
109-
$ node app.js
115+
```console
116+
node app.js
110117
```
111118

112119
**Is the server output hard to understand?:** We use `bunyan` for logging in this sample. The console won't make much sense to you unless you also install bunyan and run the server like above but pipe it through the bunyan binary:
113120

114-
```
115-
$ npm install -g bunyan
116-
117-
$ node app.js | bunyan
121+
```console
122+
npm install -g bunyan
123+
node app.js | bunyan
118124
```
119125

120126
### You're done!
@@ -133,15 +139,15 @@ For issues with the passport-azure-ad library, please raise the issue on the lib
133139

134140
If you'd like to contribute to this sample, please follow the [GitHub Fork and Pull request model](https://help.github.com/articles/fork-a-repo/).
135141

136-
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.
142+
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.
137143

138144
## Security Library
139145

140146
This library controls how users sign-in and access services. We recommend you always take the latest version of our library in your app when possible.
141147

142148
## Security Reporting
143149

144-
If you find a security issue with our libraries or services please report it to [[email protected]](mailto:[email protected]) with as much detail as possible. Your submission may be eligible for a bounty through the [Microsoft Bounty](http://aka.ms/bugbounty) program. Please do not post security issues to GitHub Issues or any other public site. We will contact you shortly upon receiving the information. We encourage you to get notifications of when security incidents occur by visiting [this page](https://technet.microsoft.com/en-us/security/dd252948) and subscribing to Security Advisory Alerts.
150+
If you find a security issue with our libraries or services please report it to [[email protected]](mailto:[email protected]) with as much detail as possible. Your submission may be eligible for a bounty through the [Microsoft Bounty](http://aka.ms/bugbounty) program. Please do not post security issues to GitHub Issues or any other public site. We will contact you shortly upon receiving the information. We encourage you to get notifications of when security incidents occur by visiting [this page](https://technet.microsoft.com/security/dd252948) and subscribing to Security Advisory Alerts.
145151

146152
Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT License (the "License");
147153

app.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@
3030
var express = require('express');
3131
var cookieParser = require('cookie-parser');
3232
var expressSession = require('express-session');
33-
var bodyParser = require('body-parser');
3433
var methodOverride = require('method-override');
3534
var passport = require('passport');
36-
var util = require('util');
3735
var bunyan = require('bunyan');
36+
var morgan = require('morgan');
37+
3838
var config = require('./config');
3939

4040
// set up database for express session
@@ -149,7 +149,7 @@ var app = express();
149149

150150
app.set('views', __dirname + '/views');
151151
app.set('view engine', 'ejs');
152-
app.use(express.logger());
152+
app.use(morgan('dev'));
153153
app.use(methodOverride());
154154
app.use(cookieParser());
155155

@@ -168,13 +168,12 @@ if (config.useMongoDBSessionStore) {
168168
app.use(expressSession({ secret: 'keyboard cat', resave: true, saveUninitialized: false }));
169169
}
170170

171-
app.use(bodyParser.urlencoded({ extended : true }));
171+
app.use(express.urlencoded({ extended : true }));
172172

173173
// Initialize Passport! Also use passport.session() middleware, to support
174174
// persistent login sessions (recommended).
175175
app.use(passport.initialize());
176176
app.use(passport.session());
177-
app.use(app.router);
178177
app.use(express.static(__dirname + '/../../public'));
179178

180179
//-----------------------------------------------------------------------------
@@ -199,6 +198,7 @@ app.get('/', function(req, res) {
199198

200199
// '/account' is only available to logged in user
201200
app.get('/account', ensureAuthenticated, function(req, res) {
201+
console.log(req.user);
202202
res.render('account', { user: req.user });
203203
});
204204

@@ -226,7 +226,7 @@ app.get('/auth/openid/return',
226226
function(req, res, next) {
227227
passport.authenticate('azuread-openidconnect',
228228
{
229-
response: res, // required
229+
response: res, // required
230230
failureRedirect: '/'
231231
}
232232
)(req, res, next);
@@ -244,7 +244,7 @@ app.post('/auth/openid/return',
244244
function(req, res, next) {
245245
passport.authenticate('azuread-openidconnect',
246246
{
247-
response: res, // required
247+
response: res, // required
248248
failureRedirect: '/'
249249
}
250250
)(req, res, next);

config.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ exports.creds = {
1010
// Required, the client ID of your app in AAD
1111
clientID: '<your_client_id>',
1212

13+
// Required if `responseType` is 'code', 'id_token code' or 'code id_token'.
14+
// If app key contains '\', replace it with '\\'.
15+
clientSecret: '<your_client_secret>',
16+
1317
// Required, must be 'code', 'code id_token', 'id_token code' or 'id_token'
1418
// If you want to get access_token, you must use 'code', 'code id_token' or 'id_token code'
1519
responseType: 'code id_token',
@@ -23,10 +27,6 @@ exports.creds = {
2327
// Required if we use http for redirectUrl
2428
allowHttpForRedirectUrl: true,
2529

26-
// Required if `responseType` is 'code', 'id_token code' or 'code id_token'.
27-
// If app key contains '\', replace it with '\\'.
28-
clientSecret: '<your_client_secret>',
29-
3030
// Required to set to false if you don't want to validate issuer
3131
validateIssuer: false,
3232

0 commit comments

Comments
 (0)