Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: introduce async method and wip inline types #100

Merged
merged 15 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ You can use below code to verify signature:
```php
<?php

use Fingerprint\ServerAPI\Webhook\WebhookVerifier;

// Your webhook signing secret.
$webhookSecret = "secret";

Expand All @@ -191,7 +193,7 @@ $webhookData = "data";
// Value of the "fpjs-event-signature" header.
$webhookHeader = "v1=1b2c16b75bd2a870c114153ccda5bcfca63314bc722fa160d690de133ccbb9db";

$isValidWebhookSign = \Fingerprint\ServerAPI\Webhook\WebhookVerifier::IsValidWebhookSignature($webhookHeader, $webhookData, $webhookSecret);
$isValidWebhookSign = WebhookVerifier::IsValidWebhookSignature($webhookHeader, $webhookData, $webhookSecret);

if(!$isValidWebhookSign) {
fwrite(STDERR, sprintf("Webhook signature verification failed\n"));
Expand Down
34 changes: 33 additions & 1 deletion run_checks.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Fingerprint\ServerAPI\Api\FingerprintApi;
use Fingerprint\ServerAPI\Configuration;
use GuzzleHttp\Client;
use Fingerprint\ServerAPI\Webhook\WebhookVerifier;

$dotenv = Dotenv\Dotenv::createImmutable(__DIR__);

Expand Down Expand Up @@ -43,24 +44,55 @@

try {
list($result, $response) = $client->getVisits($visitor_id);
if($result->getVisitorId() !== $visitor_id) {
throw new Exception('Argument visitorId is not equal to deserialized getVisitorId');
}
fwrite(STDOUT, sprintf("Got visits: %s \n", $response->getBody()->getContents()));
} catch (Exception $e) {
fwrite(STDERR, sprintf("Exception when calling FingerprintApi->getVisits: %s\n", $e->getMessage()));
exit(1);
}

try {
/** @var $result \Fingerprint\ServerAPI\Model\EventResponse */
list($result, $response) = $client->getEvent($request_id);
if($result->getProducts()->getIdentification()->getData()->getRequestId() !== $request_id) {
throw new Exception('Argument requestId is not equal to deserialized getRequestId');
}
fwrite(STDOUT, sprintf("\n\nGot event: %s \n", $response->getBody()->getContents()));
} catch (Exception $e) {
fwrite(STDERR, sprintf("\n\nException when calling FingerprintApi->getVisits: %s\n", $e->getMessage()));
exit(1);
}

$eventPromise = $client->getEventAsync($request_id);
$eventPromise->then(function ($tuple) use($request_id) {
list($result, $response) = $tuple;
if($result->getProducts()->getIdentification()->getData()->getRequestId() !== $request_id) {
throw new Exception('Argument requestId is not equal to deserialized getRequestId');
}
fwrite(STDOUT, sprintf("\n\nGot async event: %s \n", $response->getBody()->getContents()));
}, function($exception) {
fwrite(STDERR, sprintf("\n\nException when calling FingerprintApi->getVisits: %s\n", $exception->getMessage()));
exit(1);
})->wait();

$visitsPromise = $client->getVisitsAsync($visitor_id);
$visitsPromise->then(function($tuple) use($visitor_id) {
list($result, $response) = $tuple;
if($result->getVisitorId() !== $visitor_id) {
throw new Exception('Argument visitorId is not equal to deserialized getVisitorId');
}
fwrite(STDOUT, sprintf("\n\nGot async visits: %s \n", $response->getBody()->getContents()));
}, function ($exception) {
fwrite(STDERR, sprintf("\n\nException when calling FingerprintApi->getVisits: %s\n", $exception->getMessage()));
exit(1);
})->wait();

$webhookSecret = "secret";
$webhookData = "data";
$webhookHeader = "v1=1b2c16b75bd2a870c114153ccda5bcfca63314bc722fa160d690de133ccbb9db";
$isValidWebhookSign = \Fingerprint\ServerAPI\Webhook\WebhookVerifier::IsValidWebhookSignature($webhookHeader, $webhookData, $webhookSecret);
$isValidWebhookSign = WebhookVerifier::IsValidWebhookSignature($webhookHeader, $webhookData, $webhookSecret);
if($isValidWebhookSign) {
fwrite(STDOUT, sprintf("\n\nVerified webhook signature\n"));
} else {
Expand Down
20 changes: 16 additions & 4 deletions scripts/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ rm -f ./src/Model/*

java -jar ./bin/swagger-codegen-cli.jar generate -t ./template -l php -i ./res/fingerprint-server-api.yaml -o ./ -c config.json

if [ -z "$GITHUB_ACTIONS" ]; then
docker-compose run --rm lint
fi

# fix invalid code generated for structure with additionalProperties
(
# Model file fix
Expand All @@ -50,6 +54,18 @@ java -jar ./bin/swagger-codegen-cli.jar generate -t ./template -l php -i ./res/f
fi
)

# fix invalid code generated for SignalResponseRawDeviceAttributes
(
# Model file fix
if [ "$platform" = "Darwin" ]; then
sed -i '' 's/public function setData(?RawDeviceAttributesResult $data): self/public function setData(?array $data): self/' ./src/Model/SignalResponseRawDeviceAttributes.php
sed -i '' 's/public function getData(): ?RawDeviceAttributesResult/public function getData(): array/' ./src/Model/SignalResponseRawDeviceAttributes.php
else
sed -i 's/public function setData(?RawDeviceAttributesResult $data): self/public function setData(?array $data): self/' ./src/Model/SignalResponseRawDeviceAttributes.php
sed -i 's/public function getData(): ?RawDeviceAttributesResult/public function getData(): array/' ./src/Model/SignalResponseRawDeviceAttributes.php
fi
)

TheUnderScorer marked this conversation as resolved.
Show resolved Hide resolved
(
# Readme file fix
replacement=$(printf 'The rawAttributes object follows this general shape: `{ value: any } | { error: { name: string; message: string; } }`\n')
Expand All @@ -67,7 +83,3 @@ mv -f src/README.md ./README.md
mv -f src/composer.json composer.json
find ./docs -type f ! -name "DecryptionKey.md" ! -name "Sealed.md" ! -name "Webhook.md" -exec rm {} +
mv -f src/docs/* ./docs

if [ -z "$GITHUB_ACTIONS" ]; then
docker-compose run --rm lint
fi
3 changes: 3 additions & 0 deletions sealed_results_example.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

require_once(__DIR__ . '/vendor/autoload.php');

$dotenv = Dotenv\Dotenv::createImmutable(__DIR__);
$dotenv->safeLoad();

$sealed_result = base64_decode($_ENV['BASE64_SEALED_RESULT'] ?? getenv('BASE64_SEALED_RESULT') ?? "");
$sealed_key = base64_decode($_ENV['BASE64_KEY'] ?? getenv('BASE64_KEY') ?? "");

Expand Down
Loading
Loading