bugfix & rename test file

This commit is contained in:
Horiuchi_H
2014-06-18 19:12:08 +09:00
parent 39c44eb49c
commit ae9f9a2707
2 changed files with 30 additions and 3 deletions
@@ -34,7 +34,7 @@ app.post('/login',
});
app.post('/login', function(req, res, next) {
passport.authenticate('local', function(err, user, info) {
passport.authenticate('local', function(err: any, user: { username: string; }, info: { message: string; }) {
if (err) { return next(err) }
if (!user) {
req.session.error = info.message;
@@ -52,6 +52,33 @@ app.get('/logout', function(req, res) {
res.redirect('/');
});
function authSetting(): void {
var authOption = {
successRedirect: '/',
failureRedirect: '/login',
};
var successCallback = (req: express.Request, res: express.Response) => {
res.redirect('/');
};
app.get('/auth/facebook',
passport.authenticate('facebook'));
app.get('/auth/facebook/callback',
passport.authenticate('facebook', authOption), successCallback);
app.get('/auth/twitter',
passport.authenticate('twitter'));
app.get('/auth/twitter/callback',
passport.authenticate('twitter', authOption));
app.get('/auth/google',
passport.authenticate('google', { scope:
[ 'https://www.googleapis.com/auth/userinfo.profile' ] }));
app.get('/auth/google/callback',
passport.authenticate('google', authOption), successCallback);
}
function ensureAuthenticated(req: express.Request, res: express.Response, next: (err?: any) => void) {
if (req.isAuthenticated()) { return next(); }
if (req.isUnauthenticated()) {
+2 -2
View File
@@ -15,8 +15,8 @@ declare module 'passport' {
function initialize(options?: { userProperty: string; }): express.Handler;
function session(options?: { pauseStream: boolean; }): express.Handler;
function authenticate(strategy: string, options: Object, callback?: express.Handler): express.Handler;
function authenticate(strategy: string, callback2: (err: any, user: any, info: any) => void): express.Handler;
function authenticate(strategy: string, callback?: Function): express.Handler;
function authenticate(strategy: string, options: Object, callback?: Function): express.Handler;
function authorize(strategy: string, options: Object, callback?: express.Handler): express.Handler;
function serializeUser(fn: (user: any, done: (err: any, id: any) => void) => void): void;
function deserializeUser(fn: (id: any, done: (err: any, user: any) => void) => void): void;