Skip to content

Commit

Permalink
Fix arkose API
Browse files Browse the repository at this point in the history
  • Loading branch information
claabs committed Dec 21, 2020
1 parent 093758c commit a73ac73
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 18 deletions.
13 changes: 13 additions & 0 deletions src/site/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,19 @@ router.post<any, any, CompleteBody, any>('/complete', async (req, res) => {
res.status(200).send();
});

interface ArkoseBody {
sessionData: string;
id: string;
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
router.post<any, any, ArkoseBody, any>('/arkose', async (req, res) => {
L.debug({ body: req.body }, 'incoming /arkose POST body');
const { id, sessionData } = req.body;
await responseManualCaptcha({ id, sessionData });
res.status(200).send();
});

app.use(basePath, router);

app.listen(config.serverPort);
29 changes: 11 additions & 18 deletions src/site/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,23 +114,16 @@ function setupArkoseEnforcement(enforcement: Arkose): void {
Arkose.setConfig({
async onCompleted(t: ArkoseCompleteEvent) {
console.log('Captcha sessionData:', t);
const postPath = `${window.location.pathname}/solve`.replace(/\/+/g, '/');
const resp = await fetch(postPath, {
method: 'post',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
sessionData: t.token,
id,
}),
});
if (resp.ok) {
console.log('Successfully sent Captcha token');
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
document.getElementById('success-text')!.hidden = false;
success = true;
} else console.error('Failed sending Captcha token');
const postPath = `${apiRoot}/arkose`;
const body = {
sessionData: t.token,
id,
};
await axios.post(postPath, body);
console.log('Successfully sent Captcha token');
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
document.getElementById('success-text')!.hidden = false;
success = true;
},
onReady() {
console.log('ready');
Expand All @@ -148,7 +141,7 @@ function createArkoseScript(): void {
const script = document.createElement('script');
script.type = 'text/javascript';
script.src = `https://client-api.arkoselabs.com/v2/${pkey}/api.js`;
script.setAttribute('data-callback', 'setupEnforcement');
script.setAttribute('data-callback', 'setupArkoseEnforcement');
script.async = true;
script.defer = true;
script.id = 'arkosescript';
Expand Down

0 comments on commit a73ac73

Please sign in to comment.