Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UHN-BS-34 #82

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules/**/*
npm-debug.*
.env
*.csv
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,40 @@ To fill database with example data, uncomment bottom statements in data.sql and
For help with DATABASE_URL fields, go to root directory, connect to postgres with `psql --username=metric UHN-metrics` and enter `\conninfo`


### Set Up OAuth + Gmail for Data Analytics
#### Getting credentials.json
1. Go to the [Google Developer Console](https://developers.google.com/gmail/api/quickstart/nodejs) and click "Enable the Gmail API".

2. Select `Web Server` from the dropdown.

3. Enter this link `https://developers.google.com/oauthplayground` in the "Authorized Redirect URIs" field.

4. Download the client configuration to get `credentials.json`

#### Getting OAuth Tokens

1. Go to https://developers.google.com/oauthplayground and open the settings menu on the right.

2. Check the box labelled `Use your own OAuth credentials` and enter the OAuth Client ID and OAuth Client Secret provided in the saved `credentials.json` file.

3. Go to the `Step 1: Select and authorize APIs` section on the left. Enter the URL `https://mail.google.com` in the field below and click `Authorize APIs`.

4. Go to `Step 2: Exchange authorization code for tokens` and click the button labelled `Exchange authorization code for tokens`.

5. Save the Refresh and Access tokens.

#### Setting Up The .env File

Create the following variables:

METRIC_DATA_SERVICE="gmail"
METRIC_DATA_USER="Gmail account used from the setup above"
METRIC_DATA_CLIENTID="Provided in credentials.json"
METRIC_DATA_CLIENT_SECRET="Provided in credentials.json"
METRIC_DATA_REFRESH_TOKEN="Saved from OAuth playground"
METRIC_DATA_ACCESS_TOKEN="Saved from OAuth playground"
METRIC_DATA_RECEIVER="Account to receive analytics"

## Run tests

Make sure you are in project directory and run
Expand Down
139 changes: 103 additions & 36 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@
"expo-server-sdk": "^3.4.0",
"express": "^4.17.1",
"express-validator": "^6.3.0",
"json-2-csv": "^3.7.0",
"jsonwebtoken": "^8.5.1",
"knex": "^0.20.8",
"mongodb": "^3.3.3",
"mongoose": "^5.7.6",
"morgan": "^1.9.1",
"nodemailer": "^6.4.6",
"pg": "^7.18.1",
"rand-token": "^0.4.0",
"redis": "^2.8.0"
Expand Down
2 changes: 2 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
require("dotenv").config({ path: __dirname + "/.env" });
const InitializationService = require("./services/initialization.service");
InitializationService.initialize();
const metricDataDumpService = require("./Services/metricsDataDump");
metricDataDumpService.sendPeriodicEmail();
const { validateSignup, validateLogin, validateUseRefreshToken, validateDeleteRefreshToken } = require("./utils/error_handling");
const user = require("./controllers/user");
const auth = require("./controllers/auth");
Expand Down
Loading