LLMS_REST_Webhook_Data::get_delivery_signature( string $payload )
Generate a delivery signature from a delivery payload.
Parameters Parameters
- $payload
-
(string) (Required) JSON-encoded payload.
Return Return
(string)
Source Source
File: libraries/lifterlms-rest/includes/abstracts/class-llms-rest-webhook-data.php
public function get_delivery_signature( $payload ) {
/**
* Allow overriding of signature generation.
*
* @since 1.0.0-beta.1
*
* @param string $signature Custom signature. Return a string to replace the default signature.
* @param string $payload JSON-encoded body to be delivered.
* @param int $id Webhook id.
*/
$signature = apply_filters( 'llms_rest_webhook_signature_pre', null, $payload, $this->get( 'id' ) );
if ( $signature && is_string( $signature ) ) {
return $signature;
}
/**
* Customize the hash algorithm used to generate the webhook delivery signature.
*
* @since 1.0.0-beta.1
*
* @param string $algo Hash algorithm. Defaults to 'sha256'. List of supported algorithms available at https://www.php.net/manual/en/function.hash-hmac-algos.php.
* @param string $payload JSON-encoded body to be delivered.
* @param int $id Webhook ID.
*/
$hash_algo = apply_filters( 'llms_rest_webhook_hash_algorithm', 'sha256', $payload, $this->get( 'id' ) );
$ts = llms_current_time( 'timestamp' );
$message = $ts . '.' . $payload;
$hash = hash_hmac( $hash_algo, $message, $this->get( 'secret' ) );
return sprintf( 't=%1$d,v1=%2$s', $ts, $hash );
}
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
| Version | Description |
|---|---|
| 1.0.0-beta.1 | Introduced. |