Skip to content

v2.4.0

Latest

Choose a tag to compare

@ovx ovx released this 17 Nov 06:39

Remote verification with Sentinel::verify() now works with ALTCHA Sentinel v2 (POST /v2/verify/signature), and Sentinel v1 (POST /v1/verify/signature) is still supported.

Highlights

Sentinel v2 support

Sentinel v2 requires the request to be authenticated with a restricted or full API key of the account that owns the payload's API key. Pass it with the new apiKey option; it is sent as Authorization: Basic base64(id:secret):

use AltchaOrg\Altcha\Sentinel;
use AltchaOrg\Altcha\VerifyServerApiKey;
use AltchaOrg\Altcha\VerifyServerOptions;

$result = Sentinel::verify(new VerifyServerOptions(
    payload: $_POST['altcha'],
    url: 'https://sentinel.example.com/v2/verify/signature',
    apiKey: new VerifyServerApiKey('key_...', 'sec_...'),
    retries: 2,
));

When apiKey is set, the request body is {"payload": …} only: secret is not sent, because Sentinel v2 rejects it.

Sentinel v1 unchanged

Without apiKey, requests are sent as before. secret stays optional and goes in the request body, where Sentinel checks it against the payload's API key. This also covers the /v1/verify/signature alias that Sentinel v2 serves with [server] v1_compat = true.

$result = Sentinel::verify(new VerifyServerOptions(
    payload: $_POST['altcha'],
    url: 'https://sentinel.example.com/v1/verify/signature',
    secret: 'sec_...', // optional
));

Breaking changes

These match altcha-lib (JS) and ship in a minor release, per this project's versioning policy.

  • 4xx responses are no longer retried. Before, only HTTP 400 was terminal; now every 4xx (e.g. v2's 401/403 for missing, wrong or public credentials, 429) returns verified: false immediately. Network errors, 5xx responses and unparseable bodies are still retried up to retries times.
  • Error reason comes from Sentinel's error body. It is the body's code (Sentinel v2, e.g. API_KEY_REQUIRED), else its error (Sentinel v1), else HTTP_<status>. A 5xx that outlasts all retries now reports this reason too, instead of HTTP_<status> only.
  • verificationData is flattened. Sentinel v2 returns it nested ({"device": {"browser": …}}); VerifyServerResult::$verificationData now holds the signed dotted keys ($result->verificationData['device.browser']). Lists such as fields and reasons stay arrays. Flat data from Sentinel v1 is unchanged.

Upgrading

  1. Moving to Sentinel v2: change url to /v2/verify/signature, create a restricted or full API key in the account that owns your widget's key, and pass it as apiKey: new VerifyServerApiKey($id, $secret). Drop secret; it is ignored when apiKey is set.
  2. If you read nested verificationData ($data['device']['browser']), switch to the dotted keys ($data['device.browser']).
  3. If you relied on 4xx responses being retried, handle them as final failures and check $result->reason.

VerifyServerOptions::$apiKey is the last constructor parameter, so existing positional and named calls keep working.

Other

  • README documents both Sentinel versions, the options table and the error/retry behavior.
  • examples/server_sentinel.php defaults to Sentinel v2 (ALTCHA_SENTINEL_API_KEY + ALTCHA_SENTINEL_SECRET) and falls back to Sentinel v1 when ALTCHA_SENTINEL_API_KEY is unset.

See CHANGELOG.md for the full list.