-
npm install
-
create a folder -> config
-
in the config folder create a file and name it keys.js
-
in keys.js add this code
module.exports = { googleClientID: '', googleClientSecret: '', mongoURI: '', cookieKey: 'WHATEVER_YOU_WANT_YOUR_COOKIE_TO_BE', };
-
create a google cloud project and give it a name.
- in the menu go to APIs & Services -> OAuth Consent Screen; select external
- give it an application name and save
- on the left go to credentials; click create credentials at the top; select OAuth option
- this is a web app so select web app
- authorized javascript origins : http://localhost:5000
- authorized redirect: http://localhost:5000/auth/google/callback
- press create and then copy your clientID and clientSecret into the keys.js file
-
create your mongoDB
- set up a cluster
- name your cluster and create
- after a minute your cluster will be up and you will click connect in the sandbox
- click Add your current IP address
- in the next section fill in a username and password (copy your password into keys.js) and click create mongoDB user button
- then click choose a connection method and select connect your application
- copy the connection string into keys.js and paste it into the mongoURI
-
You're all set! Save your keys.js file. In your terminal run
npm run dev
and go tohttp://localhost:5000/auth/google
to start the authentication flow. If you get "Cannot GET auth/google/callback" then it worked! check by going to/api/current_user
curreythomas/ExpressServer-Google-OAuth
Quickly get going with a server hooked up using Google OAuth, PassportJS and a mongoDB schema.
JavaScript