/nodejs-oauth20-example

Example of implementation Google and Github Authentication with OAuth 2.0 and MongoDB to NodeJS.

Primary LanguageTypeScript

Example of implementation Google and Github Authentication with OAuth 2.0 and MongoDB to NodeJS.

Features:

  • It was created with Node.js and Express.js
  • MongoDB was used as database. And Mongoose.js for Object Data Modelling
  • Developed with Typescript
  • OAuth 2.0 was used for the authorization protocol. (with Google and Github)
  • Passport.js library was used, which provides convenience in the authentication process
  • Helmet.js for security of HTTP headers.
  • Cookie-Session, Nodemon, Dotenv and more...

Installation:

  • Create file named .env in main directory (not src).
PORT = YOUR_PORT
GOOGLE_CLIENT_ID = YOUR_GOOGLE_CLIENT_ID 
GOOGLE_CLIENT_SECRET = YOUR_GOOGLE_CLIENT_SECRET
GITHUB_CLIENT_ID = YOUR_GITHUB_CLIENT_ID
GITHUB_CLIENT_SECRET = YOUR_CLIENT_SECRET
COOKIE_KEY_1 = YOUR_SECRET_KEY_1_FOR_COOKIE
COOKIE_KEY_2 =  YOUR_SECRET_KEY_2_FOR_COOKIE
MONGODB_URL = YOUR_MONGODB_URL
  • On main directory run this command npm run dev or npm run start

API Routes:

/auth - localhost:8000/auth

GET

/user - localhost:8000/user

GET

POST