Simple Google Sign-in MVC app with Node.JS and MongoDB as Database
You can Use this Application as a default starting for your own backend applications for web or mobile apps.
To run this app, clone the repository and install dependencies:
git clone https://github.com/mahdyarmojtahed/google-oauth20-simple-app.git cd google-oauth20-simple-app npm install
This app requires OAuth 20 credentials from Google, which can be obtained by
a project in Google API console.
The redirect URI of the OAuth client should be set to
Once credentials have been obtained, create a
.env file and add the following
PORT=3000 || __ANY_OTHER_PORT__ MONGO_URI=mongodb://localhost:27017/__DB_NAME__ GOOGLE_CLIENT_ID=__INSERT_CLIENT_ID_HERE__ GOOGLE_CLIENT_SECRET=__INSERT_CLIENT_SECRET_HERE__
Then Start the server.
npm run watch
After users sign in, a login session is established and maintained between the server and the browser with a cookie. As authenticated users interact with the app, the login state is restored by authenticating the session. Also you may want to edit Session maxAge from app.js which now set to 1 Minute for Testing Purposes
All the codes broken into serveral little parts so the application can easily scale up and add any other sing-in methods Routes :
/auth for generic user purposes /auth/google for google sign-in purposes
/auth/facebook can be next step to implement
Created by Mahdyar Mojtahed