當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。