Last active
March 20, 2018 15:12
-
-
Save etse/93805eaa695c12faaeefdb78cf2e2a3d to your computer and use it in GitHub Desktop.
AAD with unleash example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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