added passport-facebook

This commit is contained in:
staticfunction
2014-04-19 06:58:14 +08:00
parent 93b01da4f3
commit 0e0e9511a8
2 changed files with 56 additions and 0 deletions

View File

@@ -0,0 +1,25 @@
/**
* Created by jcabresos on 4/19/2014.
*/
import passport = require('passport');
import facebook = require('passport-facebook');
// just some test model
var User = {
findOrCreate(id:string, provider:string, callback:(err:any, user:any) => void): void {
callback(null, {username:'james'});
}
}
passport.use(new facebook.Strategy({
clientID: process.env.PASSPORT_FACEBOOK_CLIENT_ID,
clientSecret: process.env.PASSPORT_FACEBOOK_CLIENT_SECRET,
callbackURL: process.env.PASSPORT_FACEBOOK_CALLBACK_URL
},
function(accessToken:string, refreshToken:string, profile:facebook.Profile, done:(error:any, user?:any) => void) {
User.findOrCreate(profile.id, profile.provider, function(err, user) {
if (err) { return done(err); }
done(null, user);
});
})
);

View File

@@ -0,0 +1,31 @@
// Type definitions for passport-facebook 1.0.3
// Project: https://github.com/jaredhanson/passport-facebook
// Definitions by: James Roland Cabresos <https://github.com/staticfunction>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
/// <reference path="../passport/passport.d.ts"/>
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 User<T> {
}
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);
name: string;
authenticate:(req: express.Request, options?: Object) => void;
}
}