• Stars
    star
    357
  • Rank 119,149 (Top 3 %)
  • Language
    CSS
  • License
    The Unlicense
  • Created over 9 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Todo app using Express and Passport for log in with Facebook.

This example demonstrates how to use Express 4.x and Passport to log users in with Facebook. Use this example as a starting point for your own web applications.

Quick Start

To get started with this example, clone the repository and install the dependencies.

$ git clone [email protected]:passport/express-4.x-facebook-example.git
$ cd express-4.x-facebook-example
$ npm install

This example requires credentials from Facebook, which can be obtained by creating an app in the App Dashboard. The OAuth redirect URI of the app should be set to: http://localhost:3000/oauth2/redirect/www.facebook.com

Once credentials have been obtained, create a .env file and add the following environment variables:

FACEBOOK_CLIENT_ID={{INSERT_APP_ID_HERE}}
FACEBOOK_CLIENT_SECRET={{INSERT_APP_SECRET_HERE}}

Start the server.

$ npm start

Navigate to http://localhost:3000.

Overview

This example illustrates how to use Passport and the passport-facebook strategy within an Express application to log users in with Facebook.

The example builds upon the scaffolding created by Express generator, and uses EJS as a view engine and plain CSS for styling. This scaffolding was generated by executing:

$ express --view ejs express-4.x-facebook-example

The example uses SQLite for storing user accounts. SQLite is a lightweight database that works well for development, including this example.

Added to the scaffolding are files which add authentication to the application.

  • boot/db.js

    This file initializes the database by creating the tables used to store user accounts and credentials.

  • boot/auth.js

    This file initializes Passport. It configures the Facebook strategy and supplies the serialization functions used for session management.

  • routes/auth.js

    This file defines the routes used for authentication. In particular, there are three routes used to authenticate with Facebook:

    • GET /login

      This route renders a page that prompts the user to login with Facebook.

    • GET /login/federated/www.facebook.com

      This route begins the authentication sequence by redirecting the user to Facebook.

    • POST /oauth2/redirect/www.facebook.com

      This route completes the authentication sequence when Facebook redirects the user back to the application. When a new user logs in, a user account is automatically created and their Facebook account is linked. When an existing user returns, they are logged in to their linked account.

License

The Unlicense

More Repositories

1

todos-express-password

Todo app using Express and Passport for sign in with username and password.
JavaScript
847
star
2

express-4.x-http-bearer-example

Express 4.x app using Passport for authentication via HTTP Bearer scheme.
JavaScript
118
star
3

todos-express-twitter

Express 4.x app using Passport for sign in with Twitter.
CSS
106
star
4

www.passportjs.org

The official website of Passport.js.
Stylus
45
star
5

todos-express-webauthn

Todo app using Express and Passport for passwordless sign in with passkeys or security keys.
JavaScript
34
star
6

todos-express-google

Todo app using Express and Passport for sign in with Google.
CSS
33
star
7

todos-express-google-oauth2

Todo app using Express, Passport, and SQLite for sign in with Google.
CSS
31
star
8

todos-express-starter

Starter todo app using Express, Passport, and SQLite for sign in.
CSS
29
star
9

express-3.x-http-basic-example

Express 3.x app using Passport for authentication via HTTP Basic scheme.
JavaScript
19
star
10

todos-express-openidconnect

Todo app using Express, Passport, and SQLite for sign in via OpenID Connect.
CSS
17
star
11

todos-express-email

Todo app using Express, Passport, and SendGrid for sign in with email.
CSS
14
star
12

express-3.x-http-digest-example

Express 3.x app using Passport for authentication via HTTP Digest scheme.
JavaScript
10
star
13

develop

A forum for discussing topics related to the development of Passport.js.
7
star
14

todos-react-express-password

Todo app using React, Express and Passport for sign in with username and password.
JavaScript
6
star
15

express-3.x-http-basic-and-digest-example

Express 3.x app using Passport for authentication via HTTP Basic and Digest schemes.
JavaScript
6
star
16

passport-stripe

A Passport Strategy for Stripe Connect
JavaScript
5
star
17

todos-express-oauth2-userinfo

Todo app using Express, Passport, and SQLite for sign in via OAuth 2.0.
CSS
5
star
18

todos-express-social

Todo app using Express and Passport for sign in with Google, Facebook, and Twitter.
CSS
5
star
19

todos-express-auth0

Todo app using Express, Passport, and Auth0 for sign in via OpenID Connect.
CSS
4
star
20

todos-express-social-credential-management

Todo app using Express, Passport, and Credential Management API for sign in with Google, Facebook, and Twitter.
JavaScript
4
star
21

todos-express-ethereum

Todo app using Express and Passport for sign in with Ethereum.
CSS
3
star
22

express-4.x-oauth1-userinfo-example

Express 4.x app using Passport for authentication via OAuth 1.0.
JavaScript
3
star
23

todos-express-password-flash

Todo app using Express, Passport, and SQLite for sign in with username and password.
CSS
2
star
24

express-4.x-openid-client-example

CSS
2
star
25

express-4.x-saml2-example

Express 4.x app using Passport for authentication via SAML 2.0.
JavaScript
2
star
26

express-3.x-local-with-flash-example

Express 3.x app using Passport for authentication with username and password.
JavaScript
2
star
27

express-4.x-wsfederation-example

Express 4.x app using Passport for authentication via WS-Federation.
JavaScript
1
star
28

passport-wsfed-saml2

Passport module for ws-federation and SAML2 tokens for Windows Azure Active Directory and ADFS
JavaScript
1
star
29

todos-express-password-credential-management

Todo app using Express, Passport, and Credential Management API for sign in with username and password.
JavaScript
1
star
30

todos-express-apple

Todo app using Express and Passport for sign in with Apple.
CSS
1
star
31

express-3.x-http-bearer-example

Express 3.x app using Passport for authentication via HTTP Bearer scheme.
JavaScript
1
star
32

express-3.x-local-example

Express 3.x app using Passport for authentication with username and password.
JavaScript
1
star
33

discuss

A forum for discussing topics related to the usage of Passport.js.
1
star
34

todos-express-google-onetap

Todo app using Express and Passport for sign in with Google One Tap.
CSS
1
star