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

TypeScript passport.use函数代码示例

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

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



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

示例1: FacebookStrategy

});

passport.use(new FacebookStrategy({
    clientID: process.env.FACEBOOK_APP_ID,
    clientSecret: process.env.FACEBOOK_APP_SECRET,
    callbackURL: process.env.FACEBOOK_CALLBACK_URL,
    profileFields: ['id', 'displayName', 'email'],
    passReqToCallback: true
  },
  function(req, accessToken, refreshToken, profile, next) {
    User.findOne({ 'facebook.id': profile.id }).exec((err, user) => {
      if (err) return next(err);
      if (user) {
        req['tempUser'] = user;
        next(null, user);
      } else {
        let u = new User();
        u.name = profile.displayName;
        u.email = profile.emails[0].value;
        u.resetPasswordToken = Math.random().toString(36).substring(7);
        u.facebook.id = profile.id;
        u.facebook.token = accessToken;
        u.save((err, user) => {
          if (err) return next(err);
          req['tempUser'] = user;
          next(null, user);
        });
      }
    });
}));

passport.use(new GoogleStrategy({
开发者ID:Jeremy-Doucet,项目名称:March-7-Group-Project,代码行数:32,代码来源:passport.ts


示例2: JwtStrategy

import * as passport from 'passport';

let opts: StrategyOptions = {
    jwtFromRequest: ExtractJwt.fromAuthHeader(),
    secretOrKey: 'secret',
    issuer: "accounts.example.com",
    audience: "example.org"
};

passport.use(new JwtStrategy(opts, function(jwt_payload, done) {
    findUser({id: jwt_payload.sub}, function(err, user) {
        if (err) {
            return done(err, false);
        }
        if (user) {
            done(null, user);
        } else {
            done(null, false, {message: 'foo'});
            // or you could create a new account
        }
    });
}));

opts.jwtFromRequest = ExtractJwt.fromHeader('x-api-key');
opts.jwtFromRequest = ExtractJwt.fromBodyField('field_name');
opts.jwtFromRequest = ExtractJwt.fromUrlQueryParameter('param_name');
opts.jwtFromRequest = ExtractJwt.fromAuthHeaderWithScheme('param_name');
opts.jwtFromRequest = ExtractJwt.fromExtractors([ExtractJwt.fromHeader('x-api-key'), ExtractJwt.fromBodyField('field_name'), ExtractJwt.fromUrlQueryParameter('param_name')]);
opts.jwtFromRequest = ExtractJwt.fromAuthHeaderAsBearerToken();
opts.jwtFromRequest = (req: Request) => { return req.query.token; };
opts.secretOrKey = new Buffer('secret');
开发者ID:AbraaoAlves,项目名称:DefinitelyTyped,代码行数:31,代码来源:passport-jwt-tests.ts


示例3: function

let app = server.build();

// passport configuration
let passportManagement = kernel.get<PassportMiddleware>(PassportMiddleware.name);

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

passport.deserializeUser(async function(id, done) {
    await passportManagement.deserializeUser(id, done);
});

passport.use(new Strategy(
    {
        passReqToCallback: true,
        usernameField: 'email'
    },
    async function(req, email, password, done) {
        await passportManagement.localStrategy(req, email, password, done);
    }
));

// 404 Error Handler
app.use(notFoundHandler);

app.listen(3000);
console.log('Server started on port 3000 :)');

exports = module.exports = app;
开发者ID:Uter1007,项目名称:sumobase.core,代码行数:30,代码来源:app.ts


示例4:

}));

app.use(bodyParser.json({
    limit: '5kb',
}));

app.use(noBlanks);

app.param('count', validateCount);

db.connect(nconf.get('NOTIFIER_DB_DSN'));

/**
 * Routes
 */
passport.use(authLocal());

passport.use(authBasic());

passport.use(authCookie());

app.use(passport.initialize());

router = express.Router();

router.use(asset(nconf.get('NOTIFIER_PUBLIC_DIR')));

router.use(/^\/(login|logout)?$/, index);

router.use('/deauth', deauth);
开发者ID:lovett,项目名称:notifier,代码行数:30,代码来源:server.ts


示例5: done

    done(undefined, user.id);
});

passport.deserializeUser((id: any, done: Function): void => {
    UserDao.findById(id)
        .then((user: User) => {
            done(undefined, user);
        })
        .catch((error: Error) => {
            done(error);
        });
});

passport.use(new passportLocal.Strategy(
    {
        passwordField: 'password',
        usernameField: 'email',
    },
    (email: string, password: string, done: Function) => {
        AuthController.login(email, password)
            .then((user: User) => {
                return done(undefined, user);
            })
            .catch((error: Error) => {
                return done(undefined, false, { message: 'Wrong email/password.' });
            });
    }
));

export = passport;
开发者ID:BCotrim,项目名称:chocobo-api,代码行数:30,代码来源:auth.config.ts


示例6: Strategy

app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));

app.use('/' + apiVersion + '/user', users);
app.use('/' + apiVersion + '/notes', notes);

// Configure passport js
let opts : StrategyOptions = {
    jwtFromRequest: ExtractJwt.fromAuthHeader(),
    secretOrKey: 'secret'
}

let passport = passportModule.use(new Strategy(opts, (jwtPayload, done) => {
    let user = UserService.findById(jwtPayload.sub);
    if(!user) {
        return done(null, false);
    } else {
        done(null, user);
    }
}))

// catch 404 and forward to error handler
app.use((req: Request, res: Response, next: Function) => {
  var err: any = new Error('Not Found');
  err.status = 404;
  next(err);
});

// error handlers
app.use(function(err: any, req: Request, res: Response, next: Function) {
    console.log(err.message);
    res.sendStatus(err.status || 500);
开发者ID:DaniOtero,项目名称:jwt-express-demo,代码行数:32,代码来源:app.ts


示例7: Strategy

import * as passport from "passport";
import  { Strategy } from "passport-anonymous";

passport.use(new Strategy());
开发者ID:ArtemZag,项目名称:DefinitelyTyped,代码行数:4,代码来源:passport-anonymous-tests.ts


示例8: use

// @filename: passport.d.ts
declare module 'passport' {
    namespace passport {
        interface Passport {
            use(): this;
        }

        interface PassportStatic extends Passport {
            Passport: {new(): Passport};
        }
    }

    const passport: passport.PassportStatic;
    export = passport;
}

//@filename: test.ts
import * as passport from "passport";
import { Passport } from "passport";

let p: Passport = passport.use();
开发者ID:01alchemist,项目名称:TypeScript,代码行数:21,代码来源:mergedDeclarations7.ts


示例9: ClientCertStrategy

import * as passport from "passport";
import {ClientCert, PkiVerifiedCallback, Strategy as ClientCertStrategy} from "passport-client-cert";

passport.use(new ClientCertStrategy( (clientCert: ClientCert, done: PkiVerifiedCallback) => {
    let cn = clientCert.subject.cn;
    let user = null;

    // The CN will typically be checked against a database
    if (cn === 'test-cn') {
        user = { name: 'Test User' };
    }

    done(null, user);
}));
开发者ID:Crevil,项目名称:DefinitelyTyped,代码行数:14,代码来源:passport-client-cert-tests.ts


示例10: Strategy

    // secure: true,    // requires https
    httpOnly: true
  }
}))
// passport init
app.use(passport.initialize())
// cuz I use sessions
app.use(passport.session())

// setup strategy
passport.use(new Strategy((username, password, done) => {
  User.findOneByUsername(username, (err, user) => {
    if (err || !user)
      return done(err, null, {message: 'Not such user!'})
    else if (password !== user.password)
      return done(new Error(Auth.Messages.WrongPassword),
                  null,
                  { message: Auth.Messages.WrongPassword})
    else
      return done(null, user)
  })
}))
passport.serializeUser((user, done) => {
  done(null, user.username)
})
passport.deserializeUser((username, done) => {
  User.findOneByUsername(username, (err, user) => {
    done(err, user)
  })
})

开发者ID:merzak7,项目名称:LearnBlog,代码行数:30,代码来源:go.ts



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
TypeScript passport.Passport类代码示例发布时间:2022-05-25
下一篇:
TypeScript passport.session函数代码示例发布时间: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