本文整理汇总了TypeScript中passport.authenticate函数的典型用法代码示例。如果您正苦于以下问题:TypeScript authenticate函数的具体用法?TypeScript authenticate怎么用?TypeScript authenticate使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了authenticate函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: configureLocal
private configureLocal() {
// show the login form
this.app.get("/login", (req: any, res: any) => {
res.render("frontoffice/login", { message: req.flash("loginMessage") });
});
// process the login form
this.app.post("/login", passport.authenticate("local-login", {
successRedirect: "/profile", // redirect to the secure profile section
failureRedirect: "/login", // redirect back to the signup page if there is an error
failureFlash: true, // allow flash messages
}));
// show the signup form
this.app.get("/signup", (req: any, res: any) => {
res.render("frontoffice/singup", { message: req.flash("signupMessage") });
});
// process the signup form
this.app.post("/signup", passport.authenticate("local-signup", {
successRedirect: "/profile", // redirect to the secure profile section
failureRedirect: "/signup", // redirect back to the signup page if there is an error
failureFlash: true, // allow flash messages
}));
}
示例2: function
var router = function () {
// GET /auth/linkedin
// Use passport.authenticate() as route middleware to authenticate the
// request. The first step in LinkedIn authentication will involve
// redirecting the user to linkedin.com. After authorization, LinkedIn will
// redirect the user back to this application at /auth/linkedin/callback
linkedInRouter.route('/linkedin').get(
passport.authenticate('linkedin'),
function (req, res) {
// The request will be redirected to LinkedIn for authentication, so this
// function will not be called.
});
// GET /auth/linkedin/callback
// Use passport.authenticate() as route middleware to authenticate the
// request. If authentication fails, the user will be redirected back to the
// login page. Otherwise, the primary route function function will be called,
// which, in this example, will redirect the user to the home page.
linkedInRouter.route('/linkedin/callback').get(
passport.authenticate('linkedin', { failureRedirect: '/login' }),
function (req, res) {
res.redirect('/');
});
linkedInRouter.route('/linkedin/logout').get(
function(req, res) {
req.logout();
res.redirect('/');
});
return linkedInRouter;
}
示例3: Auth
export default function Auth(): express.Router {
var router = express.Router();
router.get('/', (req, res) => {
if (req.user) {
res.json(req.user);
}
else {
res.status(401);
}
});
router.post('/signup', passport.authenticate('local-signup'), (req, res) => { res.json(req.user) });
router.post('/login', passport.authenticate('local-login'), (req, res) => { res.json(req.user); });
router.get('/logout', (req, res) => {
req.logout();
res.redirect('/');
});
router.get('/twitter', passport.authenticate('twitter'));
// handle the callback after twitter has authenticated the user
router.get('/twitter/callback', passport.authenticate('twitter', { successRedirect: '/', failureRedirect: '/' }));
return router;
}
示例4: init
export function init(app: Express) {
// Rutas del controlador
app.route("/province")
.get(province.list)
.put(passport.authenticate("jwt", { session: false }), security.validateAdminRole, province.validateUpdate, province.update);
app.route("/province/:provinceId")
.get(province.findByID, province.read)
.delete(passport.authenticate("jwt", { session: false }), security.validateAdminRole, province.findByID, province.validateUpdate, province.remove);
}
示例5: configureGoogle
private configureGoogle(): void {
// send to google to do the authentication
this.app.get("/auth/google", passport.authenticate("google", { scope: ["profile", "email"] }));
// the callback after google has authenticated the user
this.app.get("/auth/google/callback",
passport.authenticate("google", {
failureRedirect: "/",
successRedirect: "/auth/userInfo",
}));
}
示例6: configureTwitter
private configureTwitter(): void {
// send to twitter to do the authentication
this.app.get("/auth/twitter", passport.authenticate("twitter", { scope: "email" }));
// handle the callback after twitter has authenticated the user
this.app.get("/auth/twitter/callback",
passport.authenticate("twitter", {
failureRedirect: "/",
successRedirect: "/auth/userInfo",
}));
}
示例7: configureFacebook
private configureFacebook(): void {
// send to facebook to do the authentication
this.app.get("/auth/facebook", passport.authenticate("facebook", { scope: "email" }));
// handle the callback after facebook has authenticated the user
this.app.get("/auth/facebook/callback",
passport.authenticate("facebook", {
failureRedirect: "/",
successRedirect: "/auth/userInfo",
}));
}
示例8: addRoutes
private addRoutes() {
this.facebookAuthentication();
// route for facebook authentication and login
router.get('/auth/facebook', passport.authenticate('facebook', { scope: 'email' }));
// handle the callback after facebook has authenticated the user
router.get('/auth/facebook/callback',
passport.authenticate('facebook'), (req, res) => this.facebookResponse(req, res)
);
}