mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-11-02 20:25:28 +00:00
Upgrade spectre to v4
This commit is contained in:
@@ -52,7 +52,7 @@ class CreateTokenRequest extends SpectreRequest
|
||||
$data = [
|
||||
'data' => [
|
||||
'customer_id' => $this->customer->getId(),
|
||||
'fetch_type' => 'recent',
|
||||
'fetch_scopes' => ['accounts', 'transactions'],
|
||||
'daily_refresh' => true,
|
||||
'include_fake_providers' => true,
|
||||
'show_consent_confirmation' => true,
|
||||
|
||||
@@ -23,6 +23,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Services\Spectre\Request;
|
||||
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Services\Spectre\Object\Customer;
|
||||
use FireflyIII\Services\Spectre\Object\Login;
|
||||
use Log;
|
||||
@@ -39,9 +40,7 @@ class ListLoginsRequest extends SpectreRequest
|
||||
private $logins = [];
|
||||
|
||||
/**
|
||||
*
|
||||
* @throws \FireflyIII\Services\Spectre\Exception\SpectreException
|
||||
* @throws \FireflyIII\Exceptions\FireflyException
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function call(): void
|
||||
{
|
||||
@@ -54,7 +53,7 @@ class ListLoginsRequest extends SpectreRequest
|
||||
$response = $this->sendSignedSpectreGet($uri, []);
|
||||
|
||||
// count entries:
|
||||
Log::debug(sprintf('Found %d entries in data-array', count($response['data'])));
|
||||
Log::debug(sprintf('Found %d entries in data-array', \count($response['data'])));
|
||||
|
||||
// extract next ID
|
||||
$hasNextPage = false;
|
||||
|
||||
@@ -34,17 +34,15 @@ use Requests_Response;
|
||||
*/
|
||||
abstract class SpectreRequest
|
||||
{
|
||||
/** @var string */
|
||||
protected $clientId = '';
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
/** @var int */
|
||||
protected $expiresAt = 0;
|
||||
/** @var string */
|
||||
protected $serviceSecret = '';
|
||||
private $appId;
|
||||
/** @var string */
|
||||
private $privateKey;
|
||||
/** @var string */
|
||||
private $secret;
|
||||
/** @var string */
|
||||
private $server;
|
||||
/** @var User */
|
||||
private $user;
|
||||
@@ -67,12 +65,12 @@ abstract class SpectreRequest
|
||||
$this->privateKey = $privateKey->data;
|
||||
|
||||
// set client ID
|
||||
$clientId = app('preferences')->get('spectre_client_id', null);
|
||||
$this->clientId = $clientId->data;
|
||||
$appId = app('preferences')->get('spectre_app_id', null);
|
||||
$this->appId = $appId->data;
|
||||
|
||||
// set service secret
|
||||
$serviceSecret = app('preferences')->get('spectre_service_secret', null);
|
||||
$this->serviceSecret = $serviceSecret->data;
|
||||
$secret = app('preferences')->get('spectre_secret', null);
|
||||
$this->secret = $secret->data;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -83,17 +81,33 @@ abstract class SpectreRequest
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getClientId(): string
|
||||
public function getAppId(): string
|
||||
{
|
||||
return $this->clientId;
|
||||
return $this->appId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $clientId
|
||||
* @param string $appId
|
||||
*/
|
||||
public function setClientId(string $clientId): void
|
||||
public function setAppId(string $appId): void
|
||||
{
|
||||
$this->clientId = $clientId;
|
||||
$this->appId = $appId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getSecret(): string
|
||||
{
|
||||
return $this->secret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $secret
|
||||
*/
|
||||
public function setSecret(string $secret): void
|
||||
{
|
||||
$this->secret = $secret;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -104,26 +118,10 @@ abstract class SpectreRequest
|
||||
return $this->server;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getServiceSecret(): string
|
||||
{
|
||||
return $this->serviceSecret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $serviceSecret
|
||||
*/
|
||||
public function setServiceSecret(string $serviceSecret): void
|
||||
{
|
||||
$this->serviceSecret = $serviceSecret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $privateKey
|
||||
*/
|
||||
public function setPrivateKey(string $privateKey)
|
||||
public function setPrivateKey(string $privateKey): void
|
||||
{
|
||||
$this->privateKey = $privateKey;
|
||||
}
|
||||
@@ -139,10 +137,11 @@ abstract class SpectreRequest
|
||||
*/
|
||||
protected function generateSignature(string $method, string $uri, string $data): string
|
||||
{
|
||||
if (0 === strlen($this->privateKey)) {
|
||||
if ('' === $this->privateKey) {
|
||||
throw new FireflyException('No private key present.');
|
||||
}
|
||||
if ('get' === strtolower($method) || 'delete' === strtolower($method)) {
|
||||
$method = strtolower($method);
|
||||
if ('get' === $method || 'delete' === $method) {
|
||||
$data = '';
|
||||
}
|
||||
$toSign = $this->expiresAt . '|' . strtoupper($method) . '|' . $uri . '|' . $data . ''; // no file so no content there.
|
||||
@@ -150,7 +149,7 @@ abstract class SpectreRequest
|
||||
$signature = '';
|
||||
|
||||
// Sign the data
|
||||
openssl_sign($toSign, $signature, $this->privateKey, OPENSSL_ALGO_SHA1);
|
||||
openssl_sign($toSign, $signature, $this->privateKey, OPENSSL_ALGO_SHA256);
|
||||
$signature = base64_encode($signature);
|
||||
|
||||
return $signature;
|
||||
@@ -164,13 +163,13 @@ abstract class SpectreRequest
|
||||
$userAgent = sprintf('FireflyIII v%s', config('firefly.version'));
|
||||
|
||||
return [
|
||||
'Client-Id' => $this->getClientId(),
|
||||
'Service-Secret' => $this->getServiceSecret(),
|
||||
'Accept' => 'application/json',
|
||||
'Content-type' => 'application/json',
|
||||
'Cache-Control' => 'no-cache',
|
||||
'User-Agent' => $userAgent,
|
||||
'Expires-at' => $this->expiresAt,
|
||||
'App-id' => $this->getAppId(),
|
||||
'Secret' => $this->getSecret(),
|
||||
'Accept' => 'application/json',
|
||||
'Content-type' => 'application/json',
|
||||
'Cache-Control' => 'no-cache',
|
||||
'User-Agent' => $userAgent,
|
||||
'Expires-at' => $this->expiresAt,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -184,7 +183,7 @@ abstract class SpectreRequest
|
||||
*/
|
||||
protected function sendSignedSpectreGet(string $uri, array $data): array
|
||||
{
|
||||
if (0 === strlen($this->server)) {
|
||||
if ('' === $this->server) {
|
||||
throw new FireflyException('No Spectre server defined');
|
||||
}
|
||||
|
||||
@@ -227,7 +226,7 @@ abstract class SpectreRequest
|
||||
*/
|
||||
protected function sendSignedSpectrePost(string $uri, array $data): array
|
||||
{
|
||||
if (0 === strlen($this->server)) {
|
||||
if ('' === $this->server) {
|
||||
throw new FireflyException('No Spectre server defined');
|
||||
}
|
||||
|
||||
@@ -277,7 +276,5 @@ abstract class SpectreRequest
|
||||
if (200 !== $statusCode) {
|
||||
throw new FireflyException(sprintf('Status code %d: %s', $statusCode, $response->body));
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user