ReCaptchaEnterpriseCallback
public class ReCaptchaEnterpriseCallback : AbstractCallback, @unchecked Sendable
A callback implementation for executing Google reCAPTCHA Enterprise verification.
This callback is used within the Ping Identity journey framework to perform bot detection and fraud prevention using Google’s reCAPTCHA Enterprise service. It extends AbstractCallback for modern Swift callback handling and provides a streamlined interface for reCAPTCHA execution.
Usage in Journey Flow
- Server sends callback with reCAPTCHA site key and input field configuration
- Callback receives configuration via
initValuecalls - Client calls
verify()to obtain reCAPTCHA token - Token and action are submitted back to server for verification
Security Considerations
- Never expose site keys in client code
- Handle errors gracefully without exposing implementation details
- Use appropriate actions for different user flows
-
The reCAPTCHA Enterprise site key provided by the server. This key identifies your site to Google’s reCAPTCHA service.
Declaration
Swift
private(set) public var recaptchaSiteKey: String { get } -
The name of the input field for the reCAPTCHA token. This is determined from the server configuration.
Declaration
Swift
private(set) public var tokenKey: String { get } -
The name of the input field for the action. This is determined from the server configuration.
Declaration
Swift
private(set) public var actionKey: String { get } -
The name of the input field for client errors. This is determined from the server configuration.
Declaration
Swift
private(set) public var clientErrorKey: String { get } -
The name of the input field for additional payload. This is determined from the server configuration.
Declaration
Swift
private(set) public var payloadKey: String { get }
-
initialize(with:Asynchronous) Initializes a new instance of
ReCaptchaEnterpriseCallbackwith the provided JSON.Declaration
Swift
public override func initialize(with json: [String : Any]) async -> any Callback -
Initializes callback properties based on server-provided configuration.
This method is called automatically during callback initialization to set up the callback based on the server’s requirements for reCAPTCHA verification.
Supported Properties
recaptchaSiteKey: String containing the reCAPTCHA site key- Input field names are detected from input keys containing specific keywords
Declaration
Swift
public override func initValue(name: String, value: Any)Parameters
nameThe name of the property being initialized
valueThe value containing the property configuration
-
verify(configBlock:Asynchronous) Executes reCAPTCHA Enterprise verification and submits the result to the server.
This method orchestrates the complete reCAPTCHA verification process, allowing for custom configuration of the execution parameters.
Execution Process
- Creates ReCaptchaEnterpriseConfig with default settings
- Applies custom configuration via configBlock
- Fetches reCAPTCHA client with site key
- Executes reCAPTCHA action with specified timeout
- Submits token and action to server
Configuration Example
let result = await callback.verify { config in config.action = "signup" config.timeout = 20000 config.provider = CustomRecaptchaProvider() }Error Handling
- Automatically submits successful results to server
- Client errors are captured and submitted to server
Declaration
Swift
public func verify( configBlock: @escaping @Sendable (ReCaptchaEnterpriseConfig) -> Void = {_ in } ) async -> Result<String, Error>Parameters
configBlockConfiguration block for customizing reCAPTCHA execution
Return Value
Result containing the reCAPTCHA token or an error
-
Sets the reCAPTCHA token value in the callback response. - Parameter value: String value of the reCAPTCHA token
Declaration
Swift
public func setToken(_ value: String) -
Sets the client error value in the callback response.
Declaration
Swift
public func setClientError(_ value: String)Parameters
valueString value of the error message
-
Sets additional payload value for the reCAPTCHA in callback response.
Declaration
Swift
public func setPayload(_ value: [String : Any]? = nil)Parameters
valueDictionary value of additional data
-
Returns the payload for the callback submission.
Declaration
Swift
public override func payload() -> [String : Any]Return Value
JSON dictionary for server submission
View on GitHub