1
0
mirror of https://github.com/microsoft/TypeScript-Node-Starter.git synced 2026-03-22 17:39:43 +00:00

remove facebook stuff

This commit is contained in:
Bowden
2018-01-03 14:15:04 -08:00
parent 3c83449953
commit d25f02ea45
12 changed files with 3 additions and 259 deletions

View File

@@ -109,14 +109,6 @@ app.get("/account/unlink/:provider", passportConfig.isAuthenticated, userControl
* API examples routes.
*/
app.get("/api", apiController.getApi);
app.get("/api/facebook", passportConfig.isAuthenticated, passportConfig.isAuthorized, apiController.getFacebook);
/**
* OAuth authentication routes. (Sign in)
*/
app.get("/auth/facebook", passport.authenticate("facebook", { scope: ["email", "public_profile"] }));
app.get("/auth/facebook/callback", passport.authenticate("facebook", { failureRedirect: "/login" }), (req, res) => {
res.redirect(req.session.returnTo || "/");
});
module.exports = app;

View File

@@ -1,7 +1,6 @@
import * as passport from "passport";
import * as request from "request";
import * as passportLocal from "passport-local";
import * as passportFacebook from "passport-facebook";
import * as _ from "lodash";
// import { User, UserType } from '../models/User';
@@ -9,7 +8,6 @@ import { default as User } from "../models/User";
import { Request, Response, NextFunction } from "express";
const LocalStrategy = passportLocal.Strategy;
const FacebookStrategy = passportFacebook.Strategy;
passport.serializeUser<any, any>((user, done) => {
done(undefined, user.id);
@@ -57,67 +55,6 @@ passport.use(new LocalStrategy({ usernameField: "email" }, (email, password, don
* - Else create a new account.
*/
/**
* Sign in with Facebook.
*/
passport.use(new FacebookStrategy({
clientID: process.env.FACEBOOK_ID,
clientSecret: process.env.FACEBOOK_SECRET,
callbackURL: "/auth/facebook/callback",
profileFields: ["name", "email", "link", "locale", "timezone"],
passReqToCallback: true
}, (req: any, accessToken, refreshToken, profile, done) => {
if (req.user) {
User.findOne({ facebook: profile.id }, (err, existingUser) => {
if (err) { return done(err); }
if (existingUser) {
req.flash("errors", { msg: "There is already a Facebook account that belongs to you. Sign in with that account or delete it, then link it with your current account." });
done(err);
} else {
User.findById(req.user.id, (err, user: any) => {
if (err) { return done(err); }
user.facebook = profile.id;
user.tokens.push({ kind: "facebook", accessToken });
user.profile.name = user.profile.name || `${profile.name.givenName} ${profile.name.familyName}`;
user.profile.gender = user.profile.gender || profile._json.gender;
user.profile.picture = user.profile.picture || `https://graph.facebook.com/${profile.id}/picture?type=large`;
user.save((err: Error) => {
req.flash("info", { msg: "Facebook account has been linked." });
done(err, user);
});
});
}
});
} else {
User.findOne({ facebook: profile.id }, (err, existingUser) => {
if (err) { return done(err); }
if (existingUser) {
return done(undefined, existingUser);
}
User.findOne({ email: profile._json.email }, (err, existingEmailUser) => {
if (err) { return done(err); }
if (existingEmailUser) {
req.flash("errors", { msg: "There is already an account using this email address. Sign in to that account and link it with Facebook manually from Account Settings." });
done(err);
} else {
const user: any = new User();
user.email = profile._json.email;
user.facebook = profile.id;
user.tokens.push({ kind: "facebook", accessToken });
user.profile.name = `${profile.name.givenName} ${profile.name.familyName}`;
user.profile.gender = profile._json.gender;
user.profile.picture = `https://graph.facebook.com/${profile.id}/picture?type=large`;
user.profile.location = (profile._json.location) ? profile._json.location.name : "";
user.save((err: Error) => {
done(err, user);
});
}
});
});
}
}));
/**
* Login Required middleware.
*/

View File

@@ -2,7 +2,6 @@
import * as async from "async";
import * as request from "request";
import * as graph from "fbgraph";
import { Response, Request, NextFunction } from "express";
@@ -16,18 +15,3 @@ export let getApi = (req: Request, res: Response) => {
});
};
/**
* GET /api/facebook
* Facebook API example.
*/
export let getFacebook = (req: Request, res: Response, next: NextFunction) => {
const token = req.user.tokens.find((token: any) => token.kind === "facebook");
graph.setAccessToken(token.accessToken);
graph.get(`${req.user.facebook}?fields=id,name,email,first_name,last_name,gender,link,locale,timezone`, (err: Error, results: graph.FacebookUser) => {
if (err) { return next(err); }
res.render("api/facebook", {
title: "Facebook API",
profile: results
});
});
};

View File

@@ -8,7 +8,6 @@ export type UserModel = mongoose.Document & {
passwordResetToken: string,
passwordResetExpires: Date,
facebook: string,
tokens: AuthToken[],
profile: {
@@ -34,9 +33,6 @@ const userSchema = new mongoose.Schema({
passwordResetToken: String,
passwordResetExpires: Date,
facebook: String,
twitter: String,
google: String,
tokens: Array,
profile: {

View File

@@ -1,55 +0,0 @@
/** Declaration file generated by dts-gen */
export const version: string;
export function authorize(params: any, callback: any): any;
export function batch(reqs: any, additionalData: any, callback: any): any;
export function del(url: any, postData: any, callback: any): any;
export function extendAccessToken(params: any, callback: any): any;
export function fql(query: any, params: any, callback: any): any;
export function get(url: any, params?: any, callback?: any): any;
export function getAccessToken(): any;
export function getAppSecret(): any;
export function getGraphUrl(): any;
export function getOauthUrl(params: any, opts: any): any;
export function getOptions(): any;
export function post(url: any, postData: any, callback: any): any;
export function search(options: any, callback: any): any;
export function setAccessToken(token: any): any;
export function setAppSecret(token: any): any;
export function setGraphUrl(url: any): any;
export function setOptions(options: any): any;
export function setVersion(version: any): any;
/**
* Fairly incomplete. I only added some commonly used fields.
*/
export type FacebookUser = {
id: string,
name: string,
email: string,
first_name: string,
last_name: string,
gender: string,
link: string,
locale: string,
timezone: number
};