• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript passport.Passport类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中passport.Passport的典型用法代码示例。如果您正苦于以下问题:TypeScript Passport类的具体用法?TypeScript Passport怎么用?TypeScript Passport使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Passport类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: setupPassport

  setupPassport() {
    this.passport.serializeUser((user: any, done: Function) => {
      done(null, user);
    });

    this.passport.deserializeUser((id: any, done: Function) => {
      User.findById(id, (err: any, user: any) => {
        done(err, user);
      });
    });
  }
开发者ID:snyderjk,项目名称:TheCodeJo,代码行数:11,代码来源:passport.config.ts


示例2: 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('/');
    // });
  }
开发者ID:kongbb,项目名称:MyFinance,代码行数:46,代码来源:index.route.ts


示例3: setupPassport

function setupPassport(passport:Passport) {
	
	passport.use(new FacebookStrategy({
	    clientID: providers['facebook'].clientID,
	    clientSecret: providers['facebook'].clientSecret,
	    callbackURL: providers['facebook'].callbackURL
	  },facebookLogin
	));
	
    passport.use(new GoogleStrategy({
	    clientID: providers['google'].clientID,
	    clientSecret: providers['google'].clientSecret,
	    callbackURL: providers['google'].callbackURL
	  }
      , googleLogin
	));
};
开发者ID:ychebotarev,项目名称:InColUn-v0,代码行数:17,代码来源:setupPassport.ts


示例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('/');
	}) ;
}
开发者ID:ychebotarev,项目名称:InColUn-v0,代码行数:36,代码来源:auth.ts


示例5: function

function (model: DatabaseObject, passport: Passport): void {
  let opts: any = {}
  opts.secretOrKey = model.tokenSalt
  opts.jwtFromRequest = ExtractJwt.fromHeader('token')

  let strategy = new Strategy(opts, (jwtPayload, done) => {
    model.user.findOne({ _id: jwtPayload._doc._id }).exec()
    .then((account) => {
      account === undefined ? done(undefined, false) : done(undefined, account)
    }, (err) => {
      done(err, false)
    })
  })

  passport.use(strategy)
}
开发者ID:chipp972,项目名称:stock_manager_api,代码行数:16,代码来源:auth.ts


示例6: done

  localSignin() {
    this.passport.use("local-signin", new passportLocal.Strategy({
      usernameField: "email",
      passwordField: "password",
      passReqToCallback: true
    }, (req: any, email: string, password: string, done: Function) => {
      process.nextTick(() => {
        User.findOne({ "local.email": email }, (err: any, user: any) => {
          if (err) {
            return done(err);
          }

          if (!user) {
            return done(null, false, req.flash("signin", "email|Couldn't find user"));
          }

          if (!user.verifyPassword(password)) {
            return done(null, false, req.flash("signin", "password|Invalid password"));
          }

          return done(null, user);
        });
      });
    }));
  }
开发者ID:snyderjk,项目名称:TheCodeJo,代码行数:25,代码来源:passport.config.ts


示例7: deserializeUser

 deserializeUser(id, done) {
     this._passport.deserializeUser(function(id, done) {
         user.findById(id, function(err, user) {
             done(err, user);
         });
     });
 }
开发者ID:kongbb,项目名称:MyFinance,代码行数:7,代码来源:passport.ts


示例8: 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);
	});
开发者ID:ychebotarev,项目名称:InColUn-v0,代码行数:9,代码来源:auth.ts


示例9:

 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);
 });
开发者ID:snyderjk,项目名称:TheCodeJo,代码行数:12,代码来源:auth.router.ts



注:本文中的passport.Passport类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript passport-jwt.ExtractJwt类代码示例发布时间:2022-05-25
下一篇:
TypeScript passport.use函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap