Skip to content

Instantly share code, notes, and snippets.

@etse
Last active March 20, 2018 15:12
Show Gist options
  • Save etse/93805eaa695c12faaeefdb78cf2e2a3d to your computer and use it in GitHub Desktop.
Save etse/93805eaa695c12faaeefdb78cf2e2a3d to your computer and use it in GitHub Desktop.
AAD with unleash example
passport.use(new OIDCStrategy(config,
function(profile, done) {
console.log("OIDC-Callback:", profile, done);
if (!profile.oid) {
console.log("missing oid");
return done(new Error("No oid found"), null);
}
// asynchronous verification, for effect...
process.nextTick(function () {
console.log("userverification?", profile.oid);
});
}
));
passport.serializeUser((user, done) => done(null, user));
passport.deserializeUser((user, done) => done(null, user));
app.use(passport.initialize());
app.use(passport.session());
app.post(
'/api/auth/callback',
(req: Request, res: Response) => {
console.log("callback!!!", req.body);
res.status(200).end();
}
);
app.get(
'/api/admin/login',
passport.authenticate('azuread-openidconnect',{
failureRedirect: '/api/admin/error-login'
}),
(req: Request, res: Response) => {
console.log("loginpage!!!");
res.redirect('/');
}
);
app.use('/api/admin/', (req: Request, res: Response, next: NextFunction) => {
if (req.user) {
next();
} else {
// Instruct unleash-frontend to pop-up auth dialog
return res
.status(401)
.json({
path: '/api/admin/login',
type: 'custom',
message: `You have to identify yourself in order to use Unleash.
Click the button and follow the instructions.`,
}
)
.end();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment