-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from HDRUK/dev
Build for Sprint 2
- Loading branch information
Showing
27 changed files
with
1,346 additions
and
624 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,26 +26,35 @@ npm i -S mongoose express body-parser morgan cors | |
Create a .env file in the root of the project with this content: | ||
|
||
``` | ||
# db user | ||
# MongoDB connection parameters | ||
user= | ||
# db password | ||
password= | ||
# db cluster | ||
cluster= | ||
# db name | ||
database= | ||
homeURL=http://localhost:3000 | ||
# Auth parameters | ||
googleClientID= | ||
googleClientSecret= | ||
JWTSecret= | ||
homeURL=http://localhost:3000 | ||
PORT=3001 | ||
AUTH_PROVIDER_URI= | ||
openidClientID= | ||
openidClientSecret= | ||
linkedinClientID= | ||
linkedinClientSecret= | ||
# Sendgrid API Key | ||
SENDGRID_API_KEY= | ||
# Datacustodian email address used for testing data access request locally, place with your email! | ||
[email protected] | ||
# Discourse integration | ||
DISCOURSE_API_KEY= | ||
DISCOURSE_URL= | ||
DISCOURSE_CATEGORY_TOOLS_ID= | ||
DISCOURSE_SSO_SECRET= | ||
``` | ||
|
||
#### Step 4 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,17 @@ | ||
steps: | ||
- name: 'gcr.io/cloud-builders/docker' | ||
args: ['build', '-t', 'gcr.io/hdrukrdt-tonyespley/hdruk-rdt-api:latest', '.'] | ||
args: ['build', '-t', 'gcr.io/$PROJECT_ID/${_APP_NAME}:latest', '.'] | ||
- name: 'gcr.io/cloud-builders/docker' | ||
args: ['push', 'gcr.io/hdrukrdt-tonyespley/hdruk-rdt-api:latest'] | ||
args: ['push', 'gcr.io/$PROJECT_ID/${_APP_NAME}:latest'] | ||
- name: 'gcr.io/cloud-builders/gcloud' | ||
args: ['run', 'deploy', 'latest-api', '--image', 'gcr.io/hdrukrdt-tonyespley/hdruk-rdt-api:latest', '--platform', 'managed', '--region', 'europe-west1', '--allow-unauthenticated'] | ||
- name: 'gcr.io/cloud-builders/gcloud' | ||
args: ['run', 'deploy', 'uatbeta-api', '--image', 'gcr.io/hdrukrdt-tonyespley/hdruk-rdt-api:latest', '--platform', 'managed', '--region', 'europe-west1', '--allow-unauthenticated'] | ||
- name: 'gcr.io/cloud-builders/npm' | ||
args: ['install'] | ||
- name: 'gcr.io/cloud-builders/npm' | ||
args: ['test'] | ||
args: ['run', 'deploy', 'latest-api', '--image', 'gcr.io/$PROJECT_ID/${_APP_NAME}:latest', '--platform', 'managed', '--region', '${_REGION}', '--allow-unauthenticated'] | ||
- name: 'node' | ||
args: ['npm','install'] | ||
- name: 'node' | ||
args: ['npm','test'] | ||
env: | ||
- 'URL=https://latest-api.healthresearch.tools' | ||
- 'URL=https://${_TEST_URL}' | ||
- name: 'gcr.io/cloud-builders/gcloud' | ||
args: ['run', 'deploy', 'uatbeta-api', '--image', 'gcr.io/$PROJECT_ID/${_APP_NAME}:latest', '--platform', 'managed', '--region', '${_REGION}', '--allow-unauthenticated'] | ||
images: | ||
- gcr.io/hdrukrdt-tonyespley/hdruk-rdt-api:latest | ||
- gcr.io/$PROJECT_ID/${_APP_NAME}:latest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import express from 'express'; | ||
import passport from 'passport'; | ||
import { signToken } from '../utils'; | ||
import { discourseLogin } from './sso.discourse.service'; | ||
|
||
const router = express.Router(); | ||
|
||
// @router GET /api/v1/auth/soo/discourse | ||
// @desc Single Sign On for Discourse forum | ||
// @access Private | ||
router.get( | ||
'/', | ||
passport.authenticate('jwt'), | ||
async (req, res) => { | ||
let redirectUrl = null; | ||
|
||
if (req.query.sso && req.query.sig) { | ||
try { | ||
redirectUrl = discourseLogin(req.query.sso, req.query.sig, req.user); | ||
} catch (err) { | ||
console.error(err); | ||
return res.status(500).send('Error authenticating the user.'); | ||
} | ||
} | ||
|
||
return res | ||
.status(200) | ||
.cookie('jwt', signToken(req.user), { | ||
httpOnly: true, | ||
}) | ||
.json({redirectUrl: redirectUrl}); | ||
} | ||
); | ||
|
||
module.exports = router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import discourse_sso from 'discourse-sso'; | ||
|
||
export function discourseLogin(payload, sig, user) { | ||
const sso = new discourse_sso(process.env.DISCOURSE_SSO_SECRET); | ||
|
||
if (!sso.validate(payload, sig)) { | ||
throw Error(`Error validating Discourse SSO payload for user with id: ${user.id}.`); | ||
} | ||
|
||
const nonce = sso.getNonce(payload); | ||
const userparams = { | ||
nonce: nonce, | ||
external_id: user.id, | ||
email: user.email, | ||
username: `${user.firstname.toLowerCase()}.${user.lastname.toLowerCase()}`, | ||
name: `${user.firstname} ${user.lastname}`, | ||
}; | ||
|
||
const q = sso.buildLoginString(userparams); | ||
|
||
return `${process.env.DISCOURSE_URL}/session/sso_login?${q}`; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.