diff --git a/passport-facebook/passport-facebook.d.ts b/passport-facebook/passport-facebook.d.ts index 76a3041a9..855b033f5 100644 --- a/passport-facebook/passport-facebook.d.ts +++ b/passport-facebook/passport-facebook.d.ts @@ -10,18 +10,25 @@ declare module 'passport-facebook' { import passport = require('passport'); import express = require('express'); - interface Profile { - id:string; - provider:string; - displayName:string; - name:{familyName:string; givenName:string; middleName:string}; - profileUrl:string; + interface Profile extends passport.Profile { + gender: string; + profileUrl: string; } - class Strategy implements passport.Strategy{ - constructor(options:{clientID:string; clientSecret:string; callbackURL:string}, - verify:(accessToken:string, refreshToken:string, profile:Profile, done:(error:any, user?:any) => void) => void); + interface IStrategyOption { + clientID: string; + clientSecret: string; + callbackURL: string; + + scopeSeparator?: string; + enableProof?: boolean; + profileFields?: string[]; + } + + class Strategy implements passport.Strategy { + constructor(options: IStrategyOption, + verify: (accessToken: string, refreshToken: string, profile: Profile, done: (error: any, user?: any) => void) => void); name: string; - authenticate:(req: express.Request, options?: Object) => void; + authenticate: (req: express.Request, options?: Object) => void; } } diff --git a/passport/passport-test.ts b/passport/passport-tests.ts similarity index 61% rename from passport/passport-test.ts rename to passport/passport-tests.ts index e3ee9d4f2..7542e2e0e 100644 --- a/passport/passport-test.ts +++ b/passport/passport-tests.ts @@ -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()) { diff --git a/passport/passport.d.ts b/passport/passport.d.ts index 6ce6089b7..37d4035a0 100644 --- a/passport/passport.d.ts +++ b/passport/passport.d.ts @@ -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; @@ -42,6 +42,24 @@ declare module 'passport' { name?: string; authenticate(req: express.Request, options?: Object): void; } + + interface Profile { + provider: string; + id: string; + displayName: string; + name? : { + familyName: string; + givenName: string; + middleName?: string; + }; + emails?: { + value: string; + type?: string; + }[]; + photos?: { + value: string; + }[]; + } } declare module Express { @@ -60,3 +78,4 @@ declare module Express { isUnauthenticated(): boolean; } } +