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

use generate_random_string from e-mission-common #1194

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.serve.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"chartjs-adapter-luxon": "^1.3.1",
"chartjs-plugin-annotation": "^3.0.1",
"core-js": "^2.5.7",
"e-mission-common": "github:JGreenlee/e-mission-common#semver:0.6.2",
"e-mission-common": "github:JGreenlee/e-mission-common#semver:0.6.4",
"enketo-core": "^6.1.7",
"enketo-transformer": "^4.0.0",
"fast-xml-parser": "^4.2.2",
Expand Down
16 changes: 2 additions & 14 deletions www/js/config/opcode.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,7 @@
import i18next from 'i18next';
import { logDebug } from '../plugin/logger';
import AppConfig from '../types/appConfigTypes';

/**
* Adapted from https://stackoverflow.com/a/63363662/4040267
* made available under a CC BY-SA 4.0 license
*/
function generateRandomString(length: number) {
const randomInts = window.crypto.getRandomValues(new Uint8Array(length * 2));
const randomChars = Array.from(randomInts).map((b) => String.fromCharCode(b));
const randomString = randomChars.join('');
const validRandomString = window.btoa(randomString).replace(/[+/]/g, '');
const truncatedRandomString = validRandomString.substring(0, length);
return truncatedRandomString;
}
import { opcode } from 'e-mission-common';

/*
* We want to support both old style and new style tokens.
Expand Down Expand Up @@ -111,7 +99,7 @@ export function getStudyNameFromUrl(url) {
function generateOpcodeFromUrl(url: URL) {
const studyName = getStudyNameFromUrl(url);
const subgroup = url.searchParams.get('sub_group') || 'default';
const randomString = generateRandomString(32);
const randomString = opcode.generate_random_string(32, undefined);
return url.searchParams.get('tester') == 'true'
? `nrelop_${studyName}_${subgroup}_test_${randomString}`
: `nrelop_${studyName}_${subgroup}_${randomString}`;
Expand Down
Loading