Put restrictions to authentication to avoid abusing Prolific API

This commit is contained in:
HoshinoKoji 2024-10-01 17:41:18 +08:00
parent 682ac67664
commit 471226574a

View File

@ -1,13 +1,15 @@
import getAccessTokenDispatcher from "./getAccessToken";
// test data: 6697e96f70b84092deb6132b, 61381e32f27ab4fbed1ec26e
// test data: 6697e435d3561e6fab4a95cf, 61381e32f27ab4fbed1ec26e
export async function authSubject(request, env, ctx) {
const headers = request.headers;
const studyId = headers.get('x-study-id');
const subjectId = headers.get('x-subject-id');
const prolificApiKey = env.PROLIFIC_API_KEY;
if (!studyId || !subjectId || !subjectId.match(/^[a-zA-Z0-9]{1,32}$/))
if (studyId === env.TEST_STUDY_ID && subjectId === env.TEST_SUBJECT_ID)
return true;
if (!subjectId.match(/^[a-f0-9]{1,32}$/) || !studyId.match(/^[a-f0-9]{1,32}$/))
return false;
try {