本文整理匯總了TypeScript中passport.Passport.use方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Passport.use方法的具體用法?TypeScript Passport.use怎麽用?TypeScript Passport.use使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類passport.Passport
的用法示例。
在下文中一共展示了Passport.use方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: localSignin
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);
});
});
}));
}
示例2: localSignup
localSignup() {
this.passport.use("local-signup", 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("signup", "email|Email address already exists"));
} else {
let newUser = new User();
newUser.local.email = email;
newUser.local.password = newUser.generateHash(password);
newUser.userImage = "http://localhost:3000/public/images/ninjaicon.png";
newUser.save((saveErr: any) => {
if (saveErr) {
throw saveErr;
}
return done(null, newUser);
});
}
});
});
}));
}
示例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
));
};
示例4: 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)
}
示例5: setStrategy
private setStrategy() {
this._passport.use("local-signup", new localStrategy({
// by default, local strategy uses username and password, we will override with email
usernameField : "email",
passwordField : "password",
passReqToCallback : true // allows us to pass back the entire request to the callback
},
function(req, email, password, done) {
// asynchronous
// user.findOne wont fire unless data is sent back
process.nextTick(function() {
// find a user whose email is the same as the forms email
// we are checking to see if the user trying to login already exists
user.findOne({ "local.email" : email }, function(err, user) {
// if there are any errors, return the error
if (err) {
return done(err);
}
// check to see if theres already a user with that email
if (user) {
return done(null, false, req.flash("signupMessage", "That email is already taken."));
} else {
// if there is no user with that email
// create the user
var newUser = new user();
// set the user's local credentials
newUser.local.email = email;
newUser.local.password = newUser.generateHash(password);
// save the user
newUser.save(function(err) {
if (err) {
throw err;
}
return done(null, newUser);
});
}
});
});
}));
}