Skip to content

Commit b3ad5e0

Browse files
authored
Merge pull request #10 from Azure-Samples/jennyf/b2clogin
updates to b2clogin to run on local host
2 parents fddbb60 + 6ae185c commit b3ad5e0

File tree

2 files changed

+68
-68
lines changed

2 files changed

+68
-68
lines changed

index.js

Lines changed: 67 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,67 @@
1-
// Authors:
2-
// Shane Oatman https://github.com/shoatman
3-
// Sunil Bandla https://github.com/sunilbandla
4-
// Daniel Dobalian https://github.com/danieldobalian
5-
6-
var express = require("express");
7-
var morgan = require("morgan");
8-
var passport = require("passport");
9-
var BearerStrategy = require('passport-azure-ad').BearerStrategy;
10-
11-
// TODO: Update the first 3 variables
12-
var tenantName = "fabrikamb2c"
13-
var tenantID = tenantName + ".onmicrosoft.com";
14-
var clientID = "25eef6e4-c905-4a07-8eb4-0d08d5df8b3f";
15-
var policyName = "B2C_1_SUSI";
16-
var domain = "login.microsoftonline.com"
17-
18-
var options = {
19-
identityMetadata: "https://" + domain + "/" + tenantID + "/v2.0/.well-known/openid-configuration/",
20-
clientID: clientID,
21-
policyName: policyName,
22-
isB2C: true,
23-
validateIssuer: true,
24-
loggingLevel: 'info',
25-
passReqToCallback: false
26-
};
27-
28-
var bearerStrategy = new BearerStrategy(options,
29-
function (token, done) {
30-
// Send user info using the second argument
31-
done(null, {}, token);
32-
}
33-
);
34-
35-
var app = express();
36-
app.use(morgan('dev'));
37-
38-
app.use(passport.initialize());
39-
passport.use(bearerStrategy);
40-
41-
app.use(function (req, res, next) {
42-
res.header("Access-Control-Allow-Origin", "*");
43-
res.header("Access-Control-Allow-Headers", "Authorization, Origin, X-Requested-With, Content-Type, Accept");
44-
next();
45-
});
46-
47-
app.get("/hello",
48-
passport.authenticate('oauth-bearer', {session: false}),
49-
function (req, res) {
50-
var claims = req.authInfo;
51-
console.log('User info: ', req.user);
52-
console.log('Validated claims: ', claims);
53-
54-
if (claims['scp'].split(" ").indexOf("demo.read") >= 0) {
55-
// Service relies on the name claim.
56-
res.status(200).json({'name': claims['name']});
57-
} else {
58-
console.log("Invalid Scope, 403");
59-
res.status(403).json({'error': 'insufficient_scope'});
60-
}
61-
}
62-
);
63-
64-
var port = process.env.PORT || 5000;
65-
app.listen(port, function () {
66-
console.log("Listening on port " + port);
67-
});
1+
// Authors:
2+
// Shane Oatman https://github.com/shoatman
3+
// Sunil Bandla https://github.com/sunilbandla
4+
// Daniel Dobalian https://github.com/danieldobalian
5+
6+
var express = require("express");
7+
var morgan = require("morgan");
8+
var passport = require("passport");
9+
var BearerStrategy = require('passport-azure-ad').BearerStrategy;
10+
11+
// TODO: Update the first 3 variables
12+
var clientID = "93733604-cc77-4a3c-a604-87084dd55348";
13+
var b2cDomainHost = "fabrikamb2c.b2clogin.com";
14+
var tenantIdGuid = "775527ff-9a37-4307-8b3d-cc311f58d925";
15+
var policyName = "B2C_1_SUSI";
16+
var options = {
17+
identityMetadata: "https://" + b2cDomainHost + "/" + tenantIdGuid + "/" + policyName + "/v2.0/.well-known/openid-configuration/",
18+
19+
clientID: clientID,
20+
policyName: policyName,
21+
isB2C: true,
22+
validateIssuer: false,
23+
loggingLevel: 'info',
24+
loggingNoPII: false,
25+
passReqToCallback: false
26+
};
27+
28+
var bearerStrategy = new BearerStrategy(options,
29+
function (token, done) {
30+
// Send user info using the second argument
31+
done(null, {}, token);
32+
}
33+
);
34+
35+
var app = express();
36+
app.use(morgan('dev'));
37+
38+
app.use(passport.initialize());
39+
passport.use(bearerStrategy);
40+
41+
app.use(function (req, res, next) {
42+
res.header("Access-Control-Allow-Origin", "*");
43+
res.header("Access-Control-Allow-Headers", "Authorization, Origin, X-Requested-With, Content-Type, Accept");
44+
next();
45+
});
46+
47+
app.get("/hello",
48+
passport.authenticate('oauth-bearer', {session: false}),
49+
function (req, res) {
50+
var claims = req.authInfo;
51+
console.log('User info: ', req.user);
52+
console.log('Validated claims: ', claims);
53+
54+
if (claims['scp'].split(" ").indexOf("demo.read") >= 0) {
55+
// Service relies on the name claim.
56+
res.status(200).json({'name': claims['name']});
57+
} else {
58+
console.log("Invalid Scope, 403");
59+
res.status(403).json({'error': 'insufficient_scope'});
60+
}
61+
}
62+
);
63+
64+
var port = process.env.PORT || 5000;
65+
app.listen(port, function () {
66+
console.log("Listening on port " + port);
67+
});

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@
1414
"express": "^4.14.0",
1515
"morgan": "^1.7.0",
1616
"passport": "^0.3.2",
17-
"passport-azure-ad": "^3.0.4"
17+
"passport-azure-ad": "^3.0.12"
1818
}
1919
}

0 commit comments

Comments
 (0)