-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaad.js
32 lines (28 loc) · 916 Bytes
/
aad.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
const config = require('./aad-config.json');
const express = require('express');
const passport = require('passport');
const BearerStrategy = require('passport-azure-ad').BearerStrategy;
const app = express();
const port = process.env.PORT || '53002';
app.set('port', port);
const bearerOptions = {
identityMetadata: config.aadMetadata,
clientID: config.aadClientId,
audience: config.aadClientId,
validateIssuer: false
};
passport.use(new BearerStrategy(bearerOptions,
function(token, done) {
console.log("a");
if (token.roles && token.roles.includes(config.aadRole)) {
return done(null, token.roles);
}
return done(null,false);
}
));
app.get('/aad', passport.authenticate('oauth-bearer', {session: false}), (req, res) => {
res.end("Call success with AAD auth!");
});
app.listen(port,"localhost", () => {
console.log(`Start server at ${port}`);
});