Skip to content

Commit f7f4545

Browse files
authored
Merge pull request #3619 from Cory-Kramer/main
fix(docs): Set the assessment.event.expected_action when sending a CreateAssessm…
2 parents c7ae7d6 + 8e7102e commit f7f4545

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

recaptcha_enterprise/demosite/app/controllers/controller.js

+10-5
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ const onHomepageLoad = async (req, res) => {
7474
const assessmentResponse = await createAssessment(
7575
context.project_id,
7676
context.site_key,
77-
req.body.token
77+
req.body.token,
78+
recaptchaAction
7879
);
7980

8081
// Check if the token is valid, score is above threshold score and the action equals expected.
@@ -117,7 +118,8 @@ const onSignup = async (req, res) => {
117118
const assessmentResponse = await createAssessment(
118119
context.project_id,
119120
context.site_key,
120-
req.body.token
121+
req.body.token,
122+
recaptchaAction
121123
);
122124

123125
// Check if the token is valid, score is above threshold score and the action equals expected.
@@ -162,7 +164,8 @@ const onLogin = async (req, res) => {
162164
const assessmentResponse = await createAssessment(
163165
context.project_id,
164166
context.site_key,
165-
req.body.token
167+
req.body.token,
168+
recaptchaAction
166169
);
167170

168171
// Check if the token is valid, score is above threshold score and the action equals expected.
@@ -207,7 +210,8 @@ const onStoreCheckout = async (req, res) => {
207210
const assessmentResponse = await createAssessment(
208211
context.project_id,
209212
context.site_key,
210-
req.body.token
213+
req.body.token,
214+
recaptchaAction
211215
);
212216

213217
// Check if the token is valid, score is above threshold score and the action equals expected.
@@ -251,7 +255,8 @@ const onCommentSubmit = async (req, res) => {
251255
const assessmentResponse = await createAssessment(
252256
context.project_id,
253257
context.site_key,
254-
req.body.token
258+
req.body.token,
259+
recaptchaAction
255260
);
256261

257262
// Check if the token is valid, score is above threshold score and the action equals expected.

recaptcha_enterprise/demosite/app/recaptcha/createAssessment.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,15 @@ const {RecaptchaEnterpriseServiceClient} =
2020
* @param projectId: GCloud Project ID
2121
* @param recaptchaSiteKey: Site key obtained by registering a domain/app to use recaptcha services.
2222
* @param token: The token obtained from the client on passing the recaptchaSiteKey.
23+
* @param expectedAction: The expected action for this type of event.
2324
* @returns Assessment
2425
*/
25-
async function createAssessment(projectId, recaptchaSiteKey, token) {
26+
async function createAssessment(
27+
projectId,
28+
recaptchaSiteKey,
29+
token,
30+
expectedAction
31+
) {
2632
// <!-- ATTENTION: reCAPTCHA Example (Server Part 2/2) Starts -->
2733
const client = new RecaptchaEnterpriseServiceClient();
2834

@@ -34,6 +40,7 @@ async function createAssessment(projectId, recaptchaSiteKey, token) {
3440
event: {
3541
siteKey: recaptchaSiteKey,
3642
token: token,
43+
expectedAction: expectedAction,
3744
},
3845
},
3946
});

0 commit comments

Comments
 (0)