-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_captcha.html
52 lines (46 loc) · 2.6 KB
/
test_captcha.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<!DOCTYPE html>
<html>
<head>
<title>Captcha JS API</title>
<script type="text/javascript" src="https://ae19887525f8.eu-west-3.captcha-sdk.awswaf.com/ae19887525f8/jsapi.js" defer></script>
</head>
<body>
<button id="render-captcha-btn" onClick="onClickRenderCaptcha()">Render Captcha</button>
<div id="captcha-container"></div>
<button id="fetch-data-btn" style="display: none" onClick="fetchProtectedData()">Fetch data</button>
<div id="pets-container"></div>
<div id="error-container"></div>
<script>
/* This is a captcha example provided by AWS; have set up in AWS console as follows:
Under "application integration":
- copy the captcha integration JS tag, and put it in the page head
- generate an apiKey for the relevant domain, and paste into the JS code below
NB: can also do a direct GET to the protected endpoint: it returns a 405 code and
provides an amazon captcha page, which redirects to the endpoint if solved correctly.
*/
function setError(error) {
document.getElementById("error-container").innerHTML = error.message;
}
function onClickRenderCaptcha() {
const container = document.getElementById('captcha-container');
AwsWafCaptcha.renderCaptcha(container, {
apiKey: "oZyii2zxgIIPxCGev3ctXSPZ78/C/ofVPaDTeX93zTXgX5eak5go59tnfVaRkjqbmyl1DM0kL4kPxevgBfhOIvvmZybujnbrWtfmnbizBhkoEGU908TZDT5tdVWLeH8nOjOII98ADCy3FgWuEmziqLBlSF4ErOkHGZ09TeY32d8iXp+72m1iSHMIr/CT+f3tfv8ESYqv/IiNLUG7qKD/fbuiL5JdW06s6JWqhp1Q2kBGkBbJ+4+G6kPBEiVwuHYg+GNB+xxvbDogLtVzJNi2Zgt87v6x+EkQ7m+z6IfIDsSLYZiDBsoMoOHa+9nAXntjVa2jZ362x1Pl7IDAAjGe2kFtHwMWRss1tvaRRXTdwfSILA/C+nEeKwVSm6IjdlN3B/qaJLk6WUOnfz+F9G8VkO4c+PoCiPXaCFQ8rKGzQFT4tVYrFMcWHcyycnLpYzGtxrnr3p64fZFHsH9C2OOUZck5giV2ddFJ1I9ErEqzlkRz4mDhOrVDZSelM+mz1716u5WIfWdRhTbJzQb0zaG7ZsmlppEhZuRIMTAi51K0RAk+BdfmgFFlSwchxcS//d2hXSv8toDV9kA3W0U1lqMphBZfvL0NQMQ1oiz1LD7+X2hNex9rO6GAixxUavHV4Qw+tHcPDlDW+gaRjYUNa4+XPUVNUJ+k2Tu2yE+WLdlLhDk=_0_1",
onSuccess: () => {
document.getElementById("fetch-data-btn").style.display = 'block';
},
onError: setError,
});
}
function fetchProtectedData() {
AwsWafIntegration.fetch('../api/captcha', {
method: 'GET'
})
.then((response) => response.json())
.then((data) => {
document.getElementById('pets-container').textContent = JSON.stringify(data);
})
.catch(setError);
}
</script>
</body>
</html>