Skip to content

Commit

Permalink
Merge branch 'UAT' into v1.9.0
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/config/configuration.js
#	src/resources/collections/collections.model.js
#	src/resources/collections/collections.route.js
#	src/resources/course/course.model.js
#	src/resources/datarequest/datarequest.controller.js
#	src/resources/dataset/dataset.route.js
#	src/resources/dataset/dataset.service.js
#	src/resources/relatedobjects/relatedobjects.route.js
#	src/resources/stats/stats.router.js
#	src/resources/tool/data.model.js
#	src/resources/utilities/emailGenerator.util.js
  • Loading branch information
Paul McCafferty committed Feb 9, 2021
2 parents 01d2f66 + a0cb309 commit c0ab7e0
Show file tree
Hide file tree
Showing 111 changed files with 14,825 additions and 10,103 deletions.
11 changes: 11 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"arrowParens": "avoid",
"bracketSpacing": true,
"trailingComma": "es5",
"useTabs": true,
"semi": true,
"singleQuote": true,
"jsxSingleQuote": true,
"jsxBracketSameLine": true,
"printWidth": 140
}
7 changes: 6 additions & 1 deletion cloudbuild.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
steps:
- name: 'gcr.io/cloud-builders/docker'
args: ['build', '-t', 'gcr.io/$PROJECT_ID/${_APP_NAME}:latest', '.']
entrypoint: 'bash'
args: ['-c', 'docker pull gcr.io/$PROJECT_ID/${_APP_NAME}:latest || exit 0']
- name: 'gcr.io/cloud-builders/docker'
args: ['build', '-t', 'gcr.io/$PROJECT_ID/${_APP_NAME}:latest', '--cache-from', 'gcr.io/$PROJECT_ID/${_APP_NAME}:latest', '.']
- name: 'gcr.io/cloud-builders/docker'
args: ['push', 'gcr.io/$PROJECT_ID/${_APP_NAME}:latest']
- name: 'gcr.io/cloud-builders/gcloud'
Expand All @@ -15,3 +18,5 @@ steps:
args: ['run', 'deploy', 'uatbeta-api', '--image', 'gcr.io/$PROJECT_ID/${_APP_NAME}:latest', '--platform', 'managed', '--region', '${_REGION}', '--allow-unauthenticated']
images:
- gcr.io/$PROJECT_ID/${_APP_NAME}:latest
options:
machineType: 'E2_HIGHCPU_8'
19 changes: 19 additions & 0 deletions cloudbuild_dynamic.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
steps:
- name: 'gcr.io/cloud-builders/docker'
entrypoint: 'bash'
args: ['-c', 'docker pull gcr.io/$PROJECT_ID/${_APP_NAME}:${_ENVIRONMENT} || exit 0']
- name: 'gcr.io/cloud-builders/docker'
args: [
'build',
'-t', 'gcr.io/$PROJECT_ID/${_APP_NAME}:${_ENVIRONMENT}',
'--cache-from', 'gcr.io/$PROJECT_ID/${_APP_NAME}:${_ENVIRONMENT}',
'.'
]
- name: 'gcr.io/cloud-builders/docker'
args: ['push', 'gcr.io/$PROJECT_ID/${_APP_NAME}:${_ENVIRONMENT}']
- name: 'gcr.io/cloud-builders/gcloud'
args: ['run', 'deploy', '${_ENVIRONMENT}-api', '--image', 'gcr.io/$PROJECT_ID/${_APP_NAME}:${_ENVIRONMENT}', '--platform', 'managed', '--region', '${_REGION}', '--allow-unauthenticated']
images:
- gcr.io/$PROJECT_ID/${_APP_NAME}:${_ENVIRONMENT}
options:
machineType: 'E2_HIGHCPU_8'
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"btoa": "^1.2.1",
"cookie-parser": "^1.4.5",
"cors": "^2.8.5",
"crypto": "^1.0.1",
"crypto-js": "^4.0.0",
"discourse-sso": "^1.0.3",
"dotenv": "^8.2.0",
Expand All @@ -41,7 +42,9 @@
"passport-jwt": "^4.0.0",
"passport-linkedin-oauth2": "^2.0.0",
"passport-openidconnect": "0.0.2",
"prettier": "^2.2.1",
"query-string": "^6.12.1",
"randomstring": "^1.1.5",
"snyk": "^1.334.0",
"swagger-ui-express": "^4.1.4",
"test": "^0.6.0",
Expand All @@ -65,7 +68,9 @@
"test": "jest --runInBand",
"eject": "",
"snyk-protect": "snyk protect",
"prepublish": "npm run snyk-protect"
"prepublish": "npm run snyk-protect",
"prettify": "prettier --write \"src/**/*.{scss,js,jsx}\"",
"prettify-test": "prettier --write \"test/**/*.js\""
},
"proxy": "http://localhost:3001",
"snyk": true
Expand Down
103 changes: 52 additions & 51 deletions src/config/account.js
Original file line number Diff line number Diff line change
@@ -1,67 +1,68 @@
import { getUserByUserId } from '../resources/user/user.repository';
import { to } from 'await-to-js'
import { to } from 'await-to-js';

const store = new Map();
const logins = new Map();
const { nanoid } = require('nanoid');


class Account {
constructor(id, profile) {
this.accountId = id || nanoid();
this.profile = profile;
store.set(this.accountId, this);
}
constructor(id, profile) {
this.accountId = id || nanoid();
this.profile = profile;
store.set(this.accountId, this);
}

/**
* @param use - can either be "id_token" or "userinfo", depending on
* where the specific claims are intended to be put in.
* @param scope - the intended scope, while oidc-provider will mask
* claims depending on the scope automatically you might want to skip
* loading some claims from external resources etc. based on this detail
* or not return them in id tokens but only userinfo and so on.
*/
async claims(use, scope) { // eslint-disable-line no-unused-vars
if (this.profile) {
return {
sub: this.accountId, // it is essential to always return a sub claim
email: this.profile.email,
firstname: this.profile.firstname,
lastname: this.profile.lastname
};
}
/**
* @param use - can either be "id_token" or "userinfo", depending on
* where the specific claims are intended to be put in.
* @param scope - the intended scope, while oidc-provider will mask
* claims depending on the scope automatically you might want to skip
* loading some claims from external resources etc. based on this detail
* or not return them in id tokens but only userinfo and so on.
*/
async claims(use, scope) {
// eslint-disable-line no-unused-vars
if (this.profile) {
return {
sub: this.accountId, // it is essential to always return a sub claim
email: this.profile.email,
firstname: this.profile.firstname,
lastname: this.profile.lastname,
};
}

return {
sub: this.accountId, // it is essential to always return a sub claim
};
}
return {
sub: this.accountId, // it is essential to always return a sub claim
};
}

static async findByFederated(provider, claims) {
const id = `${provider}.${claims.sub}`;
if (!logins.get(id)) {
logins.set(id, new Account(id, claims));
}
return logins.get(id);
}
static async findByFederated(provider, claims) {
const id = `${provider}.${claims.sub}`;
if (!logins.get(id)) {
logins.set(id, new Account(id, claims));
}
return logins.get(id);
}

static async findByLogin(login) {
if (!logins.get(login)) {
logins.set(login, new Account(login));
}
static async findByLogin(login) {
if (!logins.get(login)) {
logins.set(login, new Account(login));
}

return logins.get(login);
}
return logins.get(login);
}

static async findAccount(ctx, id, token) { // eslint-disable-line no-unused-vars
// token is a reference to the token used for which a given account is being loaded,
// it is undefined in scenarios where account claims are returned from authorization endpoint
// ctx is the koa request context
if (!store.get(id)) {
let [err, user] = await to(getUserByUserId(parseInt(id)))
new Account(id, user); // eslint-disable-line no-new
}
return store.get(id);
}
static async findAccount(ctx, id, token) {
// eslint-disable-line no-unused-vars
// token is a reference to the token used for which a given account is being loaded,
// it is undefined in scenarios where account claims are returned from authorization endpoint
// ctx is the koa request context
if (!store.get(id)) {
let [err, user] = await to(getUserByUserId(parseInt(id)));
new Account(id, user); // eslint-disable-line no-new
}
return store.get(id);
}
}

module.exports = Account;
120 changes: 61 additions & 59 deletions src/config/configuration.js
Original file line number Diff line number Diff line change
@@ -1,90 +1,92 @@
import oidcProvider from 'oidc-provider';

const { interactionPolicy: { Prompt, base: policy } } = oidcProvider;
const {
interactionPolicy: { Prompt, base: policy },
} = oidcProvider;

// copies the default policy, already has login and consent prompt policies
const interactions2 = policy();

// create a requestable prompt with no implicit checks
const selectAccount = new Prompt({
name: 'select_account',
requestable: true,
name: 'select_account',
requestable: true,
});

// add to index 0, order goes select_account > login > consent
interactions2.add(selectAccount, 0);

export const clients = [
{
//Metadata works
client_id: process.env.MDWClientID || '',
client_secret: process.env.MDWClientSecret || '',
grant_types: ['authorization_code'],
response_types: ['code'],
//grant_types: ['authorization_code', 'implicit'],
//response_types: ['code id_token'],
redirect_uris: process.env.MDWRedirectURI.split(",") || [''],
id_token_signed_response_alg: 'HS256',
post_logout_redirect_uris: ['https://hdruk-auth.metadata.works/auth/logout']
},
{
//BC Platforms
client_id: process.env.BCPClientID || '',
client_secret: process.env.BCPClientSecret || '',
grant_types: ['authorization_code', 'implicit'],
response_types: ['code id_token'],
redirect_uris: process.env.BCPRedirectURI.split(",") || [''],
id_token_signed_response_alg: 'HS256',
post_logout_redirect_uris: ['https://web.uatbeta.healthdatagateway.org/search?search=&logout=true']
}
{
//Metadata works
client_id: process.env.MDWClientID || '',
client_secret: process.env.MDWClientSecret || '',
grant_types: ['authorization_code'],
response_types: ['code'],
//grant_types: ['authorization_code', 'implicit'],
//response_types: ['code id_token'],
redirect_uris: process.env.MDWRedirectURI.split(',') || [''],
id_token_signed_response_alg: 'HS256',
post_logout_redirect_uris: ['https://hdruk-auth.metadata.works/auth/logout'],
},
{
//BC Platforms
client_id: process.env.BCPClientID || '',
client_secret: process.env.BCPClientSecret || '',
grant_types: ['authorization_code', 'implicit'],
response_types: ['code id_token'],
redirect_uris: process.env.BCPRedirectURI.split(',') || [''],
id_token_signed_response_alg: 'HS256',
post_logout_redirect_uris: ['https://web.uatbeta.healthdatagateway.org/search?search=&logout=true'],
},
];

export const interactions = {
policy: interactions2,
url(ctx, interaction) {
return `/api/v1/openid/interaction/${ctx.oidc.uid}`;
},
policy: interactions2,
url(ctx, interaction) {
return `/api/v1/openid/interaction/${ctx.oidc.uid}`;
},
};

export const cookies = {
long: { signed: true, maxAge: (1 * 24 * 60 * 60) * 1000 },
short: { signed: true },
keys: ['some secret key', 'and also the old rotated away some time ago', 'and one more'],
long: { signed: true, maxAge: 1 * 24 * 60 * 60 * 1000 },
short: { signed: true },
keys: ['some secret key', 'and also the old rotated away some time ago', 'and one more'],
};

export const claims = {
email: ['email'],
profile: ['firstname', 'lastname'],
email: ['email'],
profile: ['firstname', 'lastname'],
};

export const features = {
devInteractions: { enabled: false },
deviceFlow: { enabled: true },
introspection: { enabled: true },
revocation: { enabled: true },
encryption: { enabled: true },
rpInitiatedLogout: {
enabled: true,
logoutSource,
postLogoutSuccessSource
}
devInteractions: { enabled: false },
deviceFlow: { enabled: true },
introspection: { enabled: true },
revocation: { enabled: true },
encryption: { enabled: true },
rpInitiatedLogout: {
enabled: true,
logoutSource,
postLogoutSuccessSource,
},
};

export const jwks = require('./jwks.json');

export const ttl = {
AccessToken: 1 * 60 * 60,
AuthorizationCode: 10 * 60,
IdToken: 1 * 60 * 60,
DeviceCode: 10 * 60,
RefreshToken: 1 * 24 * 60 * 60,
AccessToken: 1 * 60 * 60,
AuthorizationCode: 10 * 60,
IdToken: 1 * 60 * 60,
DeviceCode: 10 * 60,
RefreshToken: 1 * 24 * 60 * 60,
};

async function logoutSource(ctx, form) {
// @param ctx - koa request context
// @param form - form source (id="op.logoutForm") to be embedded in the page and submitted by
// the End-User
ctx.body = `<!DOCTYPE html>
// @param ctx - koa request context
// @param form - form source (id="op.logoutForm") to be embedded in the page and submitted by
// the End-User
ctx.body = `<!DOCTYPE html>
<head>
<title>Logout Request</title>
<style>/* css and html classes omitted for brevity, see lib/helpers/defaults.js */</style>
Expand All @@ -98,10 +100,10 @@ async function logoutSource(ctx, form) {
</div>
</body>
</html>`;
}
}

async function postLogoutSuccessSource(ctx) {
// @param ctx - koa request context
ctx.res.clearCookie('jwt');
ctx.res.status(200).redirect(process.env.homeURL+'/search?search=');
}
async function postLogoutSuccessSource(ctx) {
// @param ctx - koa request context
ctx.res.clearCookie('jwt');
ctx.res.status(200).redirect(process.env.homeURL + '/search?search=');
}
Loading

0 comments on commit c0ab7e0

Please sign in to comment.