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


TypeScript passport.deserializeUser函数代码示例

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


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

示例1: initialize

 public initialize(router: express.Router): void {
     router.use(passport.initialize());
     const useSession = _.get(this.options, 'authOptions.session', true);
     if (useSession) {
         router.use(passport.session());
         if (this.options.serializeUser && this.options.deserializeUser) {
             passport.serializeUser((user: any, done: (a: any, b: string) => void) => {
                 Promise.resolve(this.options.serializeUser(user))
                     .then((result: string) => {
                         done(null, result);
                     }).catch((err: Error) => {
                         done(err, null);
                     });
             });
             passport.deserializeUser((user: string, done: (a: any, b: any) => void) => {
                 Promise.resolve(this.options.deserializeUser(user))
                     .then((result: any) => {
                         done(null, result);
                     }).catch((err: Error) => {
                         done(err, null);
                     });
             });
         }
     }
 }
开发者ID:thiagobustamante,项目名称:typescript-rest,代码行数:25,代码来源:passport.ts

示例2: enableSessionSelialization

function enableSessionSelialization() {
  passport.serializeUser( (user: any, callback: any) => {
    callback(undefined, user);
  });
  passport.deserializeUser( (obj: any, callback: any) => {
    callback(undefined, obj);
  });
}
开发者ID:toannvbk93,项目名称:goemon,代码行数:8,代码来源:passport.ts

示例3: LocalStategy

 container.resolve((authDirector: IAuthDirector) => {
   passport.use(new LocalStategy(authDirector.verifyUser.bind(authDirector)));
   passport.serializeUser((user: IUserModel, next) => {
     authDirector.serializeUser(user, next);
   });
   passport.deserializeUser((username: string, next) => {
     authDirector.deserializeUser(username, next);
   });
 });
开发者ID:sebthieti,项目名称:jogplayer-online,代码行数:9,代码来源:router.module.ts

示例4: load

    @InitPhase
    @Inject(['logger', 'config', 'express', 'passport-impl'])
    @After(['ExpressSession:load', 'Passport:load'])
    load(logger, config, app, PassportImpl) {
        logger.debug('load Passport-local');

        config.defaults({
            passportLocal: {
                loginPostRoute: '/auth/login',
                tokenPostRoute: '/auth/token',

                enableTokenLogin: true,

                postLoginUrl: '/admin/',
                postLogoutUrl: '/',
                postErrorUrl: '/login',

                // after this many tries, start locks
                maxFailTries: 5,

                // maximum amount of a time an account may be locked for
                maxLockTime: 1 * 3600 * 1000
            }
        });

        const settings = config.get('passportLocal');

        passport.serializeUser(function serializeUser(user, done) {
            const info = PassportImpl.serializeUserToSession(user);
            done(null, info);
        });

        passport.deserializeUser(function deserializeUser(req, info, done) {
            PassportImpl.deserializeUserFromSession(info).then((user) => {
                done(null, user);
            }).catch(done);
        });

        configureLocal(app, PassportImpl, settings);

        if (settings.enableTokenLogin) {
            configureToken(app, PassportImpl, settings);
        }

        app.get('/logout', function(req, res) {
            res.clearCookie('remember_me');
            req.logout();
            req.session.destroy(function() {
                res.okRedirect(settings.postLogoutUrl, {status: true});
            });
        });
    }
开发者ID:HallM,项目名称:poc-fw2,代码行数:52,代码来源:index.ts

示例5: initPassport

export function initPassport(appUrl: string) {
  passport.serializeUser(async (user: any, done) => done(null, user._id))
  passport.deserializeUser(async (_id, done) => done(null, await User.findOne({_id})))

  // Get facebook authentication values from environment variables
  const facebookClientId = process.env.MajavashakkiFbClientId
  const facebookSecret = process.env.MajavashakkiFbSecret
  const isFacebookAuthEnabled = facebookClientId && facebookSecret

  if (isFacebookAuthEnabled) {
    passport.use(new FbStrategy({
        clientID: facebookClientId,
        clientSecret: facebookSecret,
        callbackURL: appUrl + "/authFacebook",
      },
      async (accessToken, refreshToken, profile, done) => {
          console.log(`User '${profile.displayName}' logged in successfully.`)
          try {
            const user = await User.findOrCreate(profile.id)
            done(null, user)
          } catch (err) {
            done(err)
          }
      },
    ))
  } else {
      console.warn("[WARNING] Facebook authentication was not enabled. Missing environment variables 'MajavashakkiFbClientId' or 'MajavashakkiFbSecret'")
  }

  passport.use(new LocalStrategy({ usernameField: "email" }, async (email, password, done) => {
    try {
      const user = await User.findByLoginEmail(email)

      if (!user) {
        console.log(`User '${email}' tried to log in with invalid email`)
        return done(null, false, { message: "There is no account with this email. :O" });
      }

      const isValidPassword = await user.isCorrectPassword(password)

      if (!isValidPassword) {
        console.log(`User '${email}' tried to log in with invalid password`)
        return done(null, false, { message: "Invalid password, did you try 'salasana1'?" });
      }

      console.log(`User '${email}' logged in successfully`)
      return done(null, user);
    } catch (error) {
      return done(error)
    }
  }));
}
开发者ID:Majavapaja,项目名称:Mursushakki,代码行数:52,代码来源:auth.ts

示例6: run

export default function run(app) {
    passport.serializeUser(function(user, callback) {
        callback(undefined, user);
    });

    passport.deserializeUser(function(user, callback) {
        callback(undefined, user);
    });

    passport.use(new LocalStrategy(function(username, password, callback) {
        userGateway.login(username, password, callback);
    }));
}
开发者ID:sjohnsonaz,项目名称:build-launchpad,代码行数:13,代码来源:authentication.ts

示例7: function

exports.setup = function(User) {

    // serialize sessions
    passport.serializeUser((user, cb) => cb(null, user));
    passport.deserializeUser((id, cb) => User.load({ criteria: { _id: id } }, cb));

    // // used to serialize the user for the session
    // passport.serializeUser(function(user, done) {
    //     done(null, user); 
    //     "user.id"" saved to session req.session.passport.user = {id:'..'}
    // });
    // 
    // // used to deserialize the user
    // passport.deserializeUser(function(id, done) {
    //     User.findById(id, function(err, user) {
    //         done(err, user);
    //         //"user"" object attaches to the request as req.user.
    //     });
    // });

    passport.use(new FacebookStrategy({
        clientID: config.facebook.clientID,
        clientSecret: config.facebook.clientSecret,
        callbackURL: config.facebook.callbackURL
    }, function(accessToken, refreshToken, profile, done) {

        User.findOne({ 'facebook.id': profile.id }, function(err, user) {
            if (err)
                return done(err);

            if (!user) {
                var data = {
                    name: profile.displayName,
                    email: profile.emails[0].value,
                    username: profile.username,
                    provider_id: profile.id,
                    provider: 'facebook',
                    facebook: profile._json
                };

                user = new User(data);
                user.save(function(err) {
                    return done(err, user);
                });

            } else
                return done(err, user);
        });
    }));
};
开发者ID:SaurabhLpRocks,项目名称:Team-Stack,代码行数:50,代码来源:passport.ts

示例8: PassportInitialize

export function PassportInitialize() {
    Passport.use(new Strategy(jwtConfig, (payload: JwtUserPayload, done: (a: null, b: JwtUser) => void) => {
        const user: JwtUser = {
            username: payload.sub,
            roles: payload.auth.split(','),
        };
        done(null, user);
    }));

    Passport.serializeUser((user: JwtUser, done: (a: null, b: string) => void) => {
        done(null, JSON.stringify(user));
    });

    Passport.deserializeUser((user: string, done: (a: null, b: JwtUser) => void) => {
        done(null, JSON.parse(user));
    });
}
开发者ID:garyevari,项目名称:typescript-rest,代码行数:17,代码来源:test.spec.ts

示例9: function

export var passportFunction = function() {
    var User = mongoose.model('User');

    passport.serializeUser(function(user, done) {
        done(null, user.id);
    });

    passport.deserializeUser(function(id, done) {
        User.findOne(
            {_id: id},
            '-password',
            function(err, user) {
                done(err, user);
            }
        );
    });

    require('./strategies/local.js')();
};
开发者ID:nmobregon,项目名称:node-express-mongodb,代码行数:19,代码来源:passport.ts

示例10: serializeDeserialize

    private serializeDeserialize() {
        passport.serializeUser((user, cb) => {
            cb(null, user._id);
        });


        passport.deserializeUser((id, cb) => {
            this.userDetailService.loadUserById(id).
                then(
                (user) => {
                    cb(null, user.getUserObject());
                },
                (err) => {
                    return cb(err);
                }
                );

        });
    }
开发者ID:Azizou,项目名称:Node-Data,代码行数:19,代码来源:auth-service.ts


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