Skip to content

Commit 14f7ffe

Browse files
committed
revise configs
1 parent 81c432a commit 14f7ffe

File tree

6 files changed

+47
-37
lines changed

6 files changed

+47
-37
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# CHANGELOG
22

3+
## 10/01/2020
4+
5+
* Token validation logic revised.
6+
37
## 08/05/2020
48

59
* Added issue & PR templates.

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ You will need a **client** application for calling the Web API. Choose:
4949
|:---------------------|:----------------------------------------------------------|
5050
| `.gitignore` | Defines what to ignore at commit time. |
5151
| `CHANGELOG.md` | List of changes to the sample. |
52-
| `CODE_OF_CONDUCT.md` | Code of Conduct information. |
5352
| `config.js` | Contains configuration parameters for the sample. |
5453
| `CONTRIBUTING.md` | Guidelines for contributing to the sample. |
5554
| `index.js` | Main application logic resides here. |
@@ -142,7 +141,7 @@ Open the project in your IDE (like Visual Studio or Visual Studio Code) to confi
142141

143142
> In the steps below, "ClientID" is the same as "Application ID" or "AppId".
144143
145-
1. Open the `auth.json` file.
144+
1. Open the `config.json` file.
146145
1. Find the key `clientID` and replace the existing value with the application ID (clientId) of the `active-directory-b2c-javascript-nodejs-webapi` application copied from the Azure portal.
147146
1. Find the key `tenantID` and replace the existing value with your Azure AD tenant ID.
148147
1. Find the key `audience` and replace the existing value with the application ID (clientId) of the `active-directory-b2c-javascript-nodejs-webapi` application copied from the Azure portal.

auth.json

Lines changed: 0 additions & 14 deletions
This file was deleted.

config.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"credentials": {
3+
"tenantID": "Enter_the_Tenant_ID",
4+
"clientID": "93733604-cc77-4a3c-a604-87084dd55348",
5+
"audience": "93733604-cc77-4a3c-a604-87084dd55348"
6+
},
7+
"policies": {
8+
"policyName": "B2C_1_SUSI"
9+
},
10+
"resource": {
11+
"scope": ["demo.read"]
12+
},
13+
"metadata": {
14+
"b2cDomain": "fabrikamb2c.b2clogin.com",
15+
"authority": "login.microsoftonline.com",
16+
"discovery": ".well-known/openid-configuration",
17+
"version": "v2.0"
18+
},
19+
"settings": {
20+
"isB2C": true,
21+
"validateIssuer": false,
22+
"passReqToCallback": false,
23+
"loggingLevel": "info"
24+
}
25+
}

index.js

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
1-
const express = require("express");
2-
const morgan = require("morgan");
3-
const passport = require("passport");
4-
const auth = require('./auth');
5-
const session = require('express-session');
1+
const express = require('express');
2+
const morgan = require('morgan');
3+
const passport = require('passport');
4+
const config = require('./config.json');
65

76
const BearerStrategy = require('passport-azure-ad').BearerStrategy;
87

98
const options = {
10-
identityMetadata: "https://" + b2cDomainHost + "/" + tenantId + "/" + policyName + "/v2.0/.well-known/openid-configuration/",
11-
clientID: clientID,
12-
policyName: policyName,
13-
isB2C: true,
14-
validateIssuer: false,
15-
loggingLevel: 'info',
16-
loggingNoPII: false,
17-
passReqToCallback: false
9+
identityMetadata: `https://${config.metadata.b2cDomain}/${config.credentials.tenantID}/${config.policies.policyName}/${config.metadata.version}/${config.metadata.discovery}`,
10+
clientID: config.credentials.clientID,
11+
policyName: config.policies.policyName,
12+
isB2C: config.settings.isB2C,
13+
validateIssuer: config.settings.validateIssuer,
14+
loggingLevel: config.settings.loggingLevel,
15+
passReqToCallback: config.settings.passReqToCallback
1816
}
1917

2018
const bearerStrategy = new BearerStrategy(options, (token, done) => {
@@ -26,21 +24,20 @@ const bearerStrategy = new BearerStrategy(options, (token, done) => {
2624
const app = express();
2725

2826
app.use(morgan('dev'));
29-
app.use(session({ secret: 'randomly-generated_secret' }));
27+
3028
app.use(passport.initialize());
31-
app.use(passport.session());
3229

3330
passport.use(bearerStrategy);
3431

35-
//enable CORS
32+
//enable CORS (for testing only -remove in production/deployment)
3633
app.use((req, res, next) => {
37-
res.header("Access-Control-Allow-Origin", "*");
38-
res.header("Access-Control-Allow-Headers", "Authorization, Origin, X-Requested-With, Content-Type, Accept");
34+
res.header('Access-Control-Allow-Origin', '*');
35+
res.header('Access-Control-Allow-Headers', 'Authorization, Origin, X-Requested-With, Content-Type, Accept');
3936
next();
4037
});
4138

4239
// API endpoint
43-
app.get("/hello",
40+
app.get('/hello',
4441
passport.authenticate('oauth-bearer', {session: false}),
4542
(req, res) => {
4643
console.log('Validated claims: ', req.authInfo);
@@ -53,5 +50,5 @@ app.get("/hello",
5350
const port = process.env.PORT || 5000;
5451

5552
app.listen(port, () => {
56-
console.log("Listening on port " + port);
53+
console.log('Listening on port ' + port);
5754
});

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
},
1414
"dependencies": {
1515
"express": "^4.14.0",
16-
"express-session": "^1.17.1",
1716
"morgan": "^1.7.0",
1817
"passport": "^0.3.2",
1918
"passport-azure-ad": "^4.2.1"

0 commit comments

Comments
 (0)