From d25f02ea4592ea8ec98b912ac25650834c91a48a Mon Sep 17 00:00:00 2001 From: Bowden Date: Wed, 3 Jan 2018 14:15:04 -0800 Subject: [PATCH] remove facebook stuff --- README.md | 4 +-- package-lock.json | 55 ---------------------------------- package.json | 3 -- src/app.ts | 8 ----- src/config/passport.ts | 63 --------------------------------------- src/controllers/api.ts | 16 ---------- src/models/User.ts | 4 --- src/types/fbgraph.d.ts | 55 ---------------------------------- views/account/login.pug | 8 ----- views/account/profile.pug | 10 ------- views/api/facebook.pug | 31 ------------------- views/api/index.pug | 5 ++-- 12 files changed, 3 insertions(+), 259 deletions(-) delete mode 100644 src/types/fbgraph.d.ts delete mode 100644 views/api/facebook.pug diff --git a/README.md b/README.md index 09c4c0b..04f2f9e 100644 --- a/README.md +++ b/README.md @@ -383,16 +383,14 @@ In that file you'll find two sections: | dotenv | Loads environment variables from .env file. | | errorhandler | Express 4 middleware. | | express | Node.js web framework. | -| express-flash | Provides flash messages for Express. | +| express-flash | Provides flash messages for Express. | | express-session | Express 4 middleware. | | express-validator | Easy form validation for Express. | -| fbgraph | Facebook Graph API library. | | lusca | CSRF middleware. | | mongoose | MongoDB ODM. | | morgan | Express 4 middleware. | | nodemailer | Node.js library for sending emails. | | passport | Simple and elegant authentication library for node.js | -| passport-facebook | Sign-in with Facebook plugin. | | passport-local | Sign-in with Username and Password plugin. | | pug (jade) | Template engine for Express. | | request | Simplified HTTP request library. | diff --git a/package-lock.json b/package-lock.json index 04782e0..c9d3418 100644 --- a/package-lock.json +++ b/package-lock.json @@ -282,16 +282,6 @@ "@types/express": "4.0.39" } }, - "@types/passport-facebook": { - "version": "2.1.7", - "resolved": "https://registry.npmjs.org/@types/passport-facebook/-/passport-facebook-2.1.7.tgz", - "integrity": "sha512-XSupHXfFnWEMWVK0DJwDNnVMMHIXXT5TL4ig5ilQawoPHilw0sYydyM87tU4ht5G71rnc+IG+OT+zWYHvhmzUw==", - "dev": true, - "requires": { - "@types/express": "4.0.39", - "@types/passport": "0.3.5" - } - }, "@types/request": { "version": "2.0.7", "resolved": "https://registry.npmjs.org/@types/request/-/request-2.0.7.tgz", @@ -1938,22 +1928,6 @@ "bser": "2.0.0" } }, - "fbgraph": { - "version": "1.4.1", - "resolved": "https://registry.npmjs.org/fbgraph/-/fbgraph-1.4.1.tgz", - "integrity": "sha1-sqo4D5732jApeNB0n61pn7l0wQQ=", - "requires": { - "qs": "1.2.2", - "request": "2.83.0" - }, - "dependencies": { - "qs": { - "version": "1.2.2", - "resolved": "https://registry.npmjs.org/qs/-/qs-1.2.2.tgz", - "integrity": "sha1-GbV/8k3CqZzh+L32r82ln472H4g=" - } - } - }, "filename-regex": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/filename-regex/-/filename-regex-2.0.1.tgz", @@ -5688,11 +5662,6 @@ "integrity": "sha512-IKdSTiDWCarf2JTS5e9e2+5tPZGdkRJ79XjYV0pzK8Q9BpsFyBq1RGKxzs7Q8UBushGw7m6TzVKz6fcY99iSWw==", "dev": true }, - "oauth": { - "version": "0.9.15", - "resolved": "https://registry.npmjs.org/oauth/-/oauth-0.9.15.tgz", - "integrity": "sha1-vR/vr2hslrdUda7VGWQS/2DPucE=" - }, "oauth-sign": { "version": "0.8.2", "resolved": "https://registry.npmjs.org/oauth-sign/-/oauth-sign-0.8.2.tgz", @@ -5880,14 +5849,6 @@ "pause": "0.0.1" } }, - "passport-facebook": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/passport-facebook/-/passport-facebook-2.1.1.tgz", - "integrity": "sha1-w50LUq5NWRYyRaTiGnubYyEwMxE=", - "requires": { - "passport-oauth2": "1.4.0" - } - }, "passport-local": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/passport-local/-/passport-local-1.0.0.tgz", @@ -5896,17 +5857,6 @@ "passport-strategy": "1.0.0" } }, - "passport-oauth2": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/passport-oauth2/-/passport-oauth2-1.4.0.tgz", - "integrity": "sha1-9i+BWDy+EmCb585vFguTlaJ7hq0=", - "requires": { - "oauth": "0.9.15", - "passport-strategy": "1.0.0", - "uid2": "0.0.3", - "utils-merge": "1.0.1" - } - }, "passport-strategy": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/passport-strategy/-/passport-strategy-1.0.0.tgz", @@ -7529,11 +7479,6 @@ "random-bytes": "1.0.0" } }, - "uid2": { - "version": "0.0.3", - "resolved": "https://registry.npmjs.org/uid2/-/uid2-0.0.3.tgz", - "integrity": "sha1-SDEm4Rd03y9xuLY53NeZw3YWK4I=" - }, "undefsafe": { "version": "0.0.3", "resolved": "https://registry.npmjs.org/undefsafe/-/undefsafe-0.0.3.tgz", diff --git a/package.json b/package.json index e6471cc..4eed40f 100644 --- a/package.json +++ b/package.json @@ -53,14 +53,12 @@ "express-flash": "0.0.2", "express-session": "^1.15.6", "express-validator": "^4.2.1", - "fbgraph": "^1.4.1", "lodash": "^4.17.4", "lusca": "^1.5.2", "mongoose": "^4.13.7", "morgan": "^1.9.0", "nodemailer": "^2.7.2", "passport": "^0.4.0", - "passport-facebook": "^2.1.1", "passport-local": "^1.0.0", "pug": "^2.0.0-rc.4", "request": "^2.83.0" @@ -85,7 +83,6 @@ "@types/node": "^7.0.12", "@types/nodemailer": "^1.3.32", "@types/passport": "^0.3.3", - "@types/passport-facebook": "^2.1.3", "@types/request": "^2.0.7", "@types/supertest": "^2.0.0", "concurrently": "^3.4.0", diff --git a/src/app.ts b/src/app.ts index 8f2150a..0e91813 100644 --- a/src/app.ts +++ b/src/app.ts @@ -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; \ No newline at end of file diff --git a/src/config/passport.ts b/src/config/passport.ts index 2f97871..958fd36 100644 --- a/src/config/passport.ts +++ b/src/config/passport.ts @@ -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((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. */ diff --git a/src/controllers/api.ts b/src/controllers/api.ts index 2638130..0707d61 100644 --- a/src/controllers/api.ts +++ b/src/controllers/api.ts @@ -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 - }); - }); -}; diff --git a/src/models/User.ts b/src/models/User.ts index 22cc542..046bda9 100644 --- a/src/models/User.ts +++ b/src/models/User.ts @@ -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: { diff --git a/src/types/fbgraph.d.ts b/src/types/fbgraph.d.ts deleted file mode 100644 index 7fb1724..0000000 --- a/src/types/fbgraph.d.ts +++ /dev/null @@ -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 -}; - diff --git a/views/account/login.pug b/views/account/login.pug index ccfc7c0..2f5407a 100644 --- a/views/account/login.pug +++ b/views/account/login.pug @@ -19,11 +19,3 @@ block content i.fa.fa-user | Login a.btn.btn-link(href='/forgot') Forgot your password? - .form-group - .col-sm-offset-3.col-sm-7 - hr - .form-group - .col-sm-offset-3.col-sm-7 - a.btn.btn-block.btn-facebook.btn-social(href='/auth/facebook') - i.fa.fa-facebook - | Sign in with Facebook diff --git a/views/account/profile.pug b/views/account/profile.pug index 77c37cc..07929ca 100644 --- a/views/account/profile.pug +++ b/views/account/profile.pug @@ -75,13 +75,3 @@ block content i.fa.fa-trash | Delete my account - .page-header - h3 Linked Accounts - .form-horizontal - .form-group - .col-sm-offset-3.col-sm-4 - if user.facebook - p: a.text-danger(href='/account/unlink/facebook') Unlink your Facebook account - else - p: a(href='/auth/facebook') Link your Facebook account - diff --git a/views/api/facebook.pug b/views/api/facebook.pug deleted file mode 100644 index 9eb21c2..0000000 --- a/views/api/facebook.pug +++ /dev/null @@ -1,31 +0,0 @@ -extends ../layout - -block content - .page-header - h2 - i.fa.fa-facebook-square(style='color: #335397') - | Facebook API - .btn-group.btn-group-justified - a.btn.btn-primary(href='https://developers.facebook.com/docs/graph-api/quickstart/', target='_blank') - i.fa.fa-check-square-o - | Quickstart - a.btn.btn-primary(href='https://developers.facebook.com/tools/explorer', target='_blank') - i.fa.fa-facebook - | Graph API Explorer - a.btn.btn-primary(href='https://developers.facebook.com/docs/graph-api/reference/', target='_blank') - i.fa.fa-code-fork - | API Reference - - h3 - i.fa.fa-user - | My Profile - img.thumbnail(src=`https://graph.facebook.com/${profile.id}/picture?type=large`, width='90', height='90') - h4= profile.name - h6 First Name: #{profile.first_name} - h6 Last Name: #{profile.last_name} - h6 Gender: #{profile.gender} - h6 Username: #{profile.username} - h6 Link: #{profile.link} - h6 Email: #{profile.email} - h6 Locale: #{profile.locale} - h6 Timezone: #{profile.timezone} diff --git a/views/api/index.pug b/views/api/index.pug index 41e3fb0..f59390a 100644 --- a/views/api/index.pug +++ b/views/api/index.pug @@ -6,8 +6,7 @@ block content .row .col-sm-4 - a(href='/api/facebook', style='color: #fff') + a(href='/api/', style='color: #fff') .panel.panel-default(style='background-color: #3b5998') .panel-body - img(src='http://i.imgur.com/jiztYCH.png', height=40) - | Facebook + | twitter (TODO)