本文整理汇总了TypeScript中passport.session函数的典型用法代码示例。如果您正苦于以下问题:TypeScript session函数的具体用法?TypeScript session怎么用?TypeScript session使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了session函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: start
start() {
let app: express.Express = express();
app.use('/', express.static('public'));
var upload: multer.Instance = multer(); // for parsing multipart/form-data
//Server Middlewares configuration part
app.use(allowCrossDomain);
app.use(cookieParser()); // read cookies (needed for auth)
app.use(bodyParser.json()); // for parsing application/json
app.use(bodyParser.urlencoded({ extended: true })); // for parsing application/x-www-form-urlencoded
app.use(expressSession({secret: 'swcmi'}));
//To use passport
app.use(passport.initialize());
app.use(passport.session()); // persistent login sessions
//start router
this.apiRouter.init(app);
//port
app.listen(10000, function () {
console.log('SuWon church API Server listening on port 10000!')
});
}
示例2: 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);
});
});
}
}
}
示例3: express
return new Promise<void>((resolve, reject) => {
let app: express.Application = express();
app.set('env', 'test');
PassportInitialize();
app.use(Passport.initialize());
app.use(Passport.session());
Server.passportAuth('jwt', 'roles');
Server.setFileLimits({
fieldSize: 1024 * 1024
});
Server.loadControllers(app, ['test/data/*', '!**/*.yaml'], `${__dirname}/../..`);
Server.setParamConverter((value, type) => {
if (type.name === 'Person' && value['salary'] === 424242) {
value['salary'] = 434343;
}
return value;
});
Server.swagger(app, './test/data/swagger.yaml', 'api-docs', 'localhost:5674', ['http']);
server = app.listen(5674, (err: any) => {
if (err) {
return reject(err);
}
resolve();
});
});
示例4: async
export const start = async (port: string) => {
await MongooseClient.InitMongoConnection();
const app = express();
const appRootUrl = siteName ? `https://${siteName}.azurewebsites.net` : `http://localhost:${port}`;
initPassport(appRootUrl);
enableSessions(app, SocketServer);
initSockets();
app.use(json())
app.use(passport.initialize());
app.use(passport.session());
const server = createServer(app);
SocketServer.attach(server);
app.use(Routes);
await new Promise(resolve => {
server.listen(port, () => {
console.log(`Server listening at port ${port}`);
resolve()
});
})
return async function close() {
await new Promise(resolve => server.close(resolve))
await MongooseClient.disconnect()
}
};
示例5: require
app.configure(function(){
app.engine('html', require('ejs').renderFile);
app.set('view engine', 'html');
app.use(express.logger('dev'));
app.use(express.json());
app.use(express.urlencoded());
app.use(express.methodOverride());
app.use(express.cookieParser());
// Persist sessions with mongoStore
app.use(express.session({
secret: 'angular-fullstack secret',
/*
store: new mongoStore({
url: config.mongo.uri,
collection: 'sessions'
}, function () {
console.log("db connection open");
})
*/
}));
//use passport session
app.use(passport.initialize());
app.use(passport.session());
// Router (only error handlers should come after this)
app.use(app.router);
});
示例6: constructor
constructor() {
var session = require('cookie-session');
var flash = require('flash');
var app = express();
app.use(express.static('build/client'));
app.use('/server', express.static('server'));
app.use('/client', express.static('client'));
app.use('/bower_components', express.static('bower_components'));
app.use('/node_modules', express.static('node_modules'));
app.use(cookieParser());
app.use(session({ secret: 'victoriasecret', resave: true, saveUninitialized: true }));
app.use(passport.initialize());
app.use(passport.session());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use('/api/auth', Auth());
Database.init('test');
Passport.init();
app.listen(3000);
}
示例7:
app.configure(function () {
app.use(express.static('public'));
app.use(express.cookieParser());
app.use(express.bodyParser());
app.use(express.session({ secret: 'keyboard cat' }));
app.use(passport.initialize());
app.use(passport.session());
app.use(app.router);
});
示例8: initAuth
function initAuth() {
const flash = require('connect-flash');
app.use(flash());
const passport = require('passport');
auth(passport);
app.use(passport.initialize());
app.use(passport.session()); // persistent login sessions
return passport;
}
示例9: enableSessionSelialization
module.exports = (app: express.Express) => {
// Initialize passport
app.use(passport.initialize());
app.use(passport.session());
enableSessionSelialization();
// Load strategies
let strategiesPath = path.normalize(__dirname + '/passport/strategy');
let auth = glob.sync(strategiesPath + '/*.+(js|ts|jsx|tsx)');
auth.forEach(function (routes) {
require(routes)(app);
});
};
示例10: expressConfig
function expressConfig(app) {
app.use(compress({
filter: function (req, res) {
return (/json|text|javascript|css/).test(res.getHeader('Content-Type'));
},
level: 9
}));
app.set('views', path.join(__dirname, '../app/views'));
app.set('view engine', 'jade');
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded());
app.use(cookieParser());
app.use(express.static(path.join(__dirname, '../public')));
// express/mongo session storage
app.use(session({
secret: 'd@s !t m@n#',
store: new mongoStore({
url: config.db,
collection: 'sessions'
})
}));
// use passport session
app.use(passport.initialize());
app.use(passport.session());
app.use(flash());
app.use('/', routes);
app.use(function (req, res, next) {
var err = new Error('Not Found');
//err.status = 404;
next(err);
});
// production error handler
// no stacktraces leaked to user
app.use(function (err, req, res, next) {
res.status(err.status || 500);
res.render('error', {
message: err.message,
error: {}
});
});
}