This is a NodeJS application which uses Google OAuth to authenticate users and fetches attachments from their Gmail account based on the search query. The attachments are downloaded on the server and the unique attachment id is stored in the MongoDB database. We can then download the attachment by providing the attachment id.
- Create a new cluster in MongoDB to store user and email data. Copy the connection string and add the
MONGO_URIto the.envfile
- Go to Google Cloud Console and create a new project
- Enabling Google API
- In sidemenu options, select
APIs and Services->Library-> Search forGmail APIand enable it
- In sidemenu options, select
- Setting up the OAuth Screen
- Inside
APIs and Services->OAuth Consent Screen-> SelectUser Type(SelectExternalfor testing) and click onCreate - Now enter all the application details and click
Save and Continue - Inside
Scopessection ->Add Scopes-> Seach forGmail APIand select the/auth/gmail.readonlyscope. This gives our app access to read the user's emails ->Save and Continue - If your application is still in
Testingphase and you selectedExternaluser type in Step 1, you'll have to provide email ids of all the users who can access your app ->Save and Continue - Check the app summary and click
Save
- Inside
- Generating Credentials
- Again in
APIs and Services, selectCredentials->Create Credentials->oAuth Client ID - Select
Application Type(Web Application), add authorized origin (Usehttp://localhost:3000if you don't have a Domain) and a callback URL where Google will send the response after OAuth (http://localhost:3000/auth/google/callbackin our case). Also add this asCALLBACK_URLin the.envfile - Save you client id and secret as
GOOGLE_CLIENT_IDandGOOGLE_CLIENT_SECRETin the.envfile
- Again in
- Clone the github repo
- Open terminal, go to the directory and run
npm i - Make sure followed all the above steps and added all the variable as specified in the
.sample.envinside the.envfile - Run
npm run devwhich will start a Nodejs server atlocalhost:3000
Please feel free to reach out to me at [email protected] in case you have any queries.
