AsyncIO client for the hCaptcha service.
Project description
aiohcaptcha
AsyncIO client for the hCaptcha service
Secure your forms using a captcha.
Install
pip install aiohcaptcha
Usage
Configuration
You can define the secret key HCAPTCHA_SECRET_KEY
in the environment or directly pass it to the HCaptchaClient
model as a parameter.
Get the secret and public keys from the hcaptcha.com.
Template
<div class="h-captcha" data-sitekey="your_site_key"></div>
<script src="https://hcaptcha.com/1/api.js" async defer></script>
Check hCaptcha docs for more details on the HTML widget.
View
from aiohcaptcha import HCaptchaClient
response_token = request.POST["h-captcha-response"]
client = HCaptchaClient(secret_key)
verified = await client.verify(response_token) # a boolean
You can adjust it to any Python Web framework that has async view support.
If you are sending the form data using an AJAX request, use $('textarea[name=h-captcha-response]').val();
for the captcha key.
Response details
Response details are stored in client.response
,
details of the HCaptchaResponse
model is same as the JSON response provided in the hCaptcha documentation.
Extra arguments
You can also add remote_ip
and sitekey
(expected key) to the client.verify
function.
These parameters are explained in the hCaptcha docs.
For unit testing, you can create the Client HCaptchaClient
with debug=True
parameter.
In this mode, the verify
function will return True
if the user_response
token and sitekey
parameters do match, otherwise it will return False
:
client = HCaptchaClient("<SECRET_KEY>", debug=True)
assert await client.verify("<USER_TOKEN>", sitekey="<SAME_TOKEN>")
assert await client.verify("<USER_TOKEN>", sitekey="<DIFFERENT_TOKEN>") is False
© 2020 Emin Mastizada. MIT Licenced.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file aiohcaptcha-0.1.2.tar.gz
.
File metadata
- Download URL: aiohcaptcha-0.1.2.tar.gz
- Upload date:
- Size: 4.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.4 CPython/3.8.6 Linux/5.9.2-arch1-1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ed1fa0cee963b5678145b1881de082445c0b6047a58d031855b41f38f37a07ea |
|
MD5 | 850666f0055aa79d37cfe3db078dfee0 |
|
BLAKE2b-256 | 6ebc3ca08e718e042316bf8c3428a16a7971944f33490dd934694dcf9f7879b9 |
File details
Details for the file aiohcaptcha-0.1.2-py3-none-any.whl
.
File metadata
- Download URL: aiohcaptcha-0.1.2-py3-none-any.whl
- Upload date:
- Size: 4.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.4 CPython/3.8.6 Linux/5.9.2-arch1-1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f7baa58ed3207bad52fb6bc61ccc4e4929cde5c6739bfc26dd385d0637355467 |
|
MD5 | 25bf8989a1159229e97d355e921c16ac |
|
BLAKE2b-256 | 16f236fd3078175aefc481279f73fd5f66bdcc97be30e4978a7879600dd2ad4c |