本文整理匯總了TypeScript中passport.Passport.authenticate方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Passport.authenticate方法的具體用法?TypeScript Passport.authenticate怎麽用?TypeScript Passport.authenticate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類passport.Passport
的用法示例。
在下文中一共展示了Passport.authenticate方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: config
config(app: Application, passport: Passport){
app.get("/", function(req: Request, res: Response){
res.sendFile("index.html", {"root": "pages/"});
});
app.get("/ping", passport.authenticate("bearer", { session: false }), this.serialize, this.generateToken, function(req: Request, res: Response){
res.status(200).json({hello: "world"});
});
app.get("/google", passport.authenticate("google", { session: false }), function(req: Request, res: Response){
res.status(200).json({google: "success"});
});
// app.get("/login", function(req: Request, res: Response){
// res.sendFile("login.html", {"root": "pages/"});
// });
// app.get("/signup", function(req: Request, res: Response){
// res.sendFile("signup.html", {"root": "pages/"});
// });
// app.get("/finance", function(req: Request, res: Response){
// res.sendFile("finance.html", {"root": "pages/"});
// });
// app.post('/login', passport.authenticate('local-login', {
// successRedirect : '/finance', // redirect to the secure profile section
// failureRedirect : '/login', // redirect back to the signup page if there is an error
// failureFlash : true // allow flash messages
// }));
// // process the signup form
// app.post('/signup', passport.authenticate('local-signup', {
// successRedirect : '/finance', // redirect to the secure profile section
// failureRedirect : '/signup', // redirect back to the signup page if there is an error
// failureFlash : true // allow flash messages
// }));
// // =====================================
// // LOGOUT ==============================
// // =====================================
// app.get('/logout', function(req, res) {
// req.logout();
// res.redirect('/');
// });
}
示例2: function
app.get('/auth/google/callback', function(req:Request, res:Response, next:NextFunction) {
passport.authenticate('google', { session:false}, function(err, token:string, info) {
if (!token) {
res.json({ success: false, message: 'Google authentication failed.' });
} else {
authSuccessRedirect(res, token);
}
})(req, res, next);
});
示例3:
this.router.post("/signin", (req: any, res: any, next: NextFunction) => {
this.passport.authenticate("local-signin", (err: any, user: any, info: any) => {
let messages = req.flash("signin");
if (messages.length > 0) {
res.status(401).send(messages);
}
if (user) {
let response = { "token": this.createToken(user) };
res.status(200).send(JSON.stringify(response));
}
})(req, res, next);
});
示例4: setupAuthRoutes
function setupAuthRoutes(app: Application, passport:Passport){
app.get('/login', function(req, res){ res.render("login"); });
app.get('/signup', function(req, res){ res.render("signup"); });
app.post('/auth/signup', authFunction.localSignup);
app.post('/auth/login', authFunction.localLogin);
app.get('/auth/facebook', passport.authenticate('facebook', {scope: ['email']}));
app.get('/auth/google', passport.authenticate('google', {scope: ['profile', 'email']}));
app.get('/auth/facebook/callback', function(req:Request, res:Response, next:NextFunction) {
passport.authenticate('facebook', {session:false}, function(err, token:string, info) {
if (!token) {
res.json({ success: false, message: 'Facebook authentication failed.' });
} else {
authSuccessRedirect(res, token);
}
})(req, res, next);
});
app.get('/auth/google/callback', function(req:Request, res:Response, next:NextFunction) {
passport.authenticate('google', { session:false}, function(err, token:string, info) {
if (!token) {
res.json({ success: false, message: 'Google authentication failed.' });
} else {
authSuccessRedirect(res, token);
}
})(req, res, next);
});
app.get('/logout', function(req, res){
req.logout();
res.redirect('/');
}) ;
}
示例5: function
app.post("/login", function (req, res, next) {
passport.authenticate("local-login", function (err, user, info) {
if (err)
{
return res.json({ "message": err.message });
}
if (!user)
{
return res.json({ "message": info.message });
}
req.login(user, err => {
if (err) { return next(err); }
return res.json({ "username": user.username, "authenticated": req.isAuthenticated()});
});
})(req, res, next);
});