core.bones.captcha¶
Classes¶
The CaptchaBone is used to ensure that a user is not a bot. |
Module Contents¶
- class core.bones.captcha.CaptchaBone(*, publicKey=None, privateKey=None, score_threshold=0.5, **kwargs)¶
Bases:
viur.core.bones.base.BaseBoneThe CaptchaBone is used to ensure that a user is not a bot.
The Captcha bone uses the Google reCAPTCHA API to perform the Captcha validation and supports v2 and v3.
See also
Option
core.config.Security.captcha_default_credentialsfor global security settings.Option
core.config.Security.captcha_enforce_alwaysfor developing.Initializes a new CaptchaBone.
publicKey and privateKey can be omitted, if they are set globally in
core.config.Security.captcha_default_credentials.- Parameters:
publicKey (str) – The public key for the Captcha validation.
privateKey (str) – The private key for the Captcha validation.
score_threshold (float)
kwargs (Any)
- Score_threshold:
If reCAPTCHA v3 is used, the score must be at least this threshold. For reCAPTCHA v2 this property will be ignored.
- type = 'captcha'¶
- privateKey = None¶
- score_threshold = 0.5¶
- required = True¶
- serialize(skel, name, parentIndexed)¶
Serializing the Captcha bone is not possible so it return False
- Parameters:
skel (viur.core.skeleton.SkeletonInstance)
name (str)
parentIndexed (bool)
- Return type:
bool
- unserialize(skel, name)¶
Stores the publicKey in the SkeletonInstance
- Parameters:
skel (viur.core.skeleton.SkeletonInstance) – The target
SkeletonInstance.name – The name of the CaptchaBone in the
SkeletonInstance.
- Returns:
boolean, that is true, as the Captcha bone is always unserialized successfully.
- Return type:
Literal[True]
- fromClient(skel, name, data)¶
Load the reCAPTCHA token from the provided data and validate it with the help of the API.
reCAPTCHA provides the token via callback usually as “g-recaptcha-response”, but to fit into the skeleton logic, we support both names. So the token can be provided as “g-recaptcha-response” or the name of the CaptchaBone in the Skeleton. While the latter one is the preferred name.
- Parameters:
skel (viur.core.skeleton.SkeletonInstance)
name (str)
data (dict)
- Return type:
None | list[viur.core.bones.base.ReadFromClientError]