当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript passport.Passport类代码示例

本文整理汇总了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;未经允许,请勿转载。