Giter Site home page Giter Site logo

simple-passport-github-oauth2's Introduction

express-4.x-google-oauth2-example

This example illustrates how to use Express 4.x and Passport to sign users in with Google. 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-google-oauth2-example.git
$ cd express-4.x-google-oauth2-example
$ npm install

This example requires credentials from Google, which can be obtained by setting up a project in Google APIs console. The redirect URI of the OAuth client should be set to: http://localhost:3000/auth/github/callback

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

GOOGLE_CLIENT_ID={{INSERT_CLIENT_ID_HERE}}
GOOGLE_CLIENT_SECRET={{INSERT_CLIENT_SECRET_HERE}}

Start the server.

$ npm start

Navigate to http://localhost:3000.

Overview

This example illustrates how to use Passport and the passport-google-oauth20 strategy within an Express application to sign users in with Google.

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-google-oauth2-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 Google 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 Google:

    • GET /login

      This route renders a page that prompts the user to sign in with Google.

    • GET /login/federated/accounts.google.com

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

    • POST /auth/github/callback

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

License

The Unlicense

simple-passport-github-oauth2's People

Contributors

torranca avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.