Coder Social home page Coder Social logo

-google-oauth2's Introduction

Google OAuth2.0 with Express, PostgreSQL & Passport Template

This is a template for using Google OAuth2.0 with Express and Passport.js.

  1. Clone the repo, cd into it, and run npm install.

  2. Make sure you have PostgreSQL installed and run createdb in your command line. Name your db whatever you'd like

  3. Open up knexfile.js and under development > connection replace your-database-name, replace with the name of the db you just created.

  4. Run 'knex migrate:latest' in the command line

  5. Go to https://console.developers.google.com/ and create a new project then 'create credentials' for 'OAuth ClientId'.

  6. Select 'Web Application' and give it a name.

  7. Set 'Authorized JavaScript origins' to whatever local port you are running the app on (in this template it's set to http://127.0.0.1:1337)

  8. Set Authorized redirect URIs' to http://127.0.0.1:1337/auth/google/callback

  9. It will show you clientId and you can click okay. When you get back to the credentials page you can click on your app name and it will give you Client ID and Client secret which you can access at any time. Leave this page open, as we need to put it into our app in step 8.

  10. Find the button to enable google apis > find the Google+ api > Enable that api.

  11. Go back into editor and create a .env file. Add into that file 3 new environment variables:

    GOOGLE_CLIENT_ID= <your client id>
    GOOGLE_CLIENT_SECRET= <your client secret>
    SESSION_KEY= <whatever you want>
    
  12. Make certain your .env file is included in your .gitignore - it should already be.

  13. Run npm start or nodemon and visit http://localhost:1337

  14. As is, the only thing saved into your database after logging in via Google is the user's googleId. I wanted to set up the db to a basic level. There are many Mongo examples, but not many others... I also left a console.log in on the auth.js file in the GoogleStrategy so that you can view what's coming back from Google and use the info however you'd like!

  15. :)

-google-oauth2's People

Contributors

bradford-hamilton avatar

Stargazers

 avatar

Watchers

 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.