> Portal Navigation: > > - Append `.md` to any URL under `https://dev.wix.com/docs/` to get its markdown version. > - Pages are either content pages (article or reference text) or menu pages (a list of links to child pages). > - To get a menu page, truncate any URL to a parent path and append `.md` (e.g. `https://dev.wix.com/docs/sdk.md`, `https://dev.wix.com/docs/sdk/core-modules.md`). > - Top-level index of all portals: https://dev.wix.com/docs/llms.txt > - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt # Method name: authorize(token: string) # Method package: wixCaptchaBackend # Method menu location: wixCaptchaBackend --> authorize # Method Link: https://dev.wix.com/docs/velo/apis/wix-captcha-backend/authorize.md # Method Description: Authorizes the CAPTCHA token. Following CAPTCHA verification on the client side, you must authorize the generated CAPTCHA token in the backend. `authorize()` checks if the token is valid, making sure it was not tampered with or timed out. The `authorize()` function returns a Promise that resolves to a `Success` object when the token is authorized and to an `Error` object when authorization fails. To understand how `authorize()` is used in a typical CAPTCHA validation lifecycle, click [here](/$w/captcha/introduction). If CAPTCHA token authorization fails, an error message containing a status code is returned. The following table lists the possible HTTP error status codes, based on [RFC 2616](https://tools.ietf.org/html/rfc2616#section-10): | Status Code | Name | Description | |---|---|---| | 400 | Bad Request | The request could not be understood by the server. This could occur for a number of reasons, such as: The request was sent without a token. The token is invalid. The token has timed out. | | 401 | Unauthenticated | No user identity found in passed request. | | 500 | Internal Server Error | The server encountered an unexpected condition, such as a missing or invalid private CAPTCHA key. | | 503 | Unavailable | The service is unavailable due to one of the following: Throttled error: Server overload due to more than the allowed requests in a given time frame. Request failed: No response following 10 retries with a 1-second interval. | # Method Code Examples: *** Note: do not assume any prop names or enum values other than the ones in the example. ## Full CAPTCHA lifecycle scenario ```javascript /************************************ * Backend code - submitHandler.web.js * ************************************/ import { Permissions, webMethod } from 'wix-web-module'; import wixCaptchaBackend from 'wix-captcha-backend'; import wixData from 'wix-data'; export const processSubmission = webMethod(Permissions.Anyone, (submitRequestData) => { return wixCaptchaBackend.authorize(submitRequestData.token) .then(() => { return wixData.insert("MyCollection", submitRequestData.data) .then(() => ({ "type": "success" })) .catch((error) => ({ "type": "insertion error", "message": "Error: collection insertion failed: " + error })); }) .catch((error) => ({ "type": "authorization error", "message": "Error: CAPTCHA authorization failed: " + error })); }); /******************** * Client-side code * ********************/ import { processSubmission } from 'backend/submitHandler.web'; $w.onReady(function () { // When user clicks submit button $w("#submitDataButton").onClick(() => { let submitRequestData = { token: $w("#myCaptcha").token, data: $w("#myInput").value, } processSubmission(submitRequestData) // Call backend function .then((response) => { // Display a different message depending on response from backend function switch (response.type) { case "success": $w("#messageText").text = "Data successfully submitted"; break; case "authorization error": $w("#messageText").text = "CAPTCHA authorization failed. Redo the CAPTCHA challenge."; break; case "insertion error": $w("#messageText").text = "Database error. Redo the CAPTCHA challenge."; break; } $w("#myCaptcha").reset(); $w("#submitDataButton").disable(); $w("#messageText").show(); }); }); // Error handler $w("#myCaptcha").onError(() => { $w("#messageText").text = "The reCAPTCHA element lost connection with the CAPTCHA provider. Try again later."; $w("#messageText").show() .then(() => { $w("#messageText").hide("fade", { "delay": 10000 }); }); }) // Verification handler $w("#myCaptcha").onVerified(() => { $w("#submitDataButton").enable(); $w("#messageText").hide(); }) // Timeout handler $w("#myCaptcha").onTimeout(() => { $w("#submitDataButton").disable(); $w("#messageText").text = "The CAPTCHA has timed out. Please redo the CAPTCHA challenge."; $w("#messageText").show(); }); }); ``` ---