Browse Source

Can remember spectre data in cookie.

pull/20/head
James Cole 4 years ago
parent
commit
c156b9411e
  1. 1
      app/Services/Nordigen/Authentication/SecretManager.php
  2. 60
      app/Services/Spectre/Authentication/SecretManager.php
  3. 19
      app/Services/Spectre/AuthenticationValidator.php

1
app/Services/Nordigen/Authentication/SecretManager.php

@ -35,6 +35,7 @@ class SecretManager
/**
* Will return the Nordigen ID. From a cookie if its there, otherwise from configuration.
* TODO is a cookie the best place?
*
* @return string
*/

60
app/Services/Spectre/Authentication/SecretManager.php

@ -23,7 +23,67 @@ declare(strict_types=1);
namespace App\Services\Spectre\Authentication;
/**
* Class SecretManager
*/
class SecretManager
{
public const APP_ID = 'spectre_app_id';
public const SECRET = 'spectre_secret';
/**
* Will return the Nordigen ID. From a cookie if its there, otherwise from configuration.
* TODO is a cookie the best place?
*
* @return string
*/
public static function getAppId(): string
{
if (!self::hasAppId()) {
app('log')->debug('No Spectre App ID in hasAppId(), will return config variable.');
return (string) config('spectre.app_id');
}
return request()->cookie(self::APP_ID);
}
/**
* Will verify if the user has a Spectre App ID (in a cookie)
* TODO is a cookie the best place?
*
* @return bool
*/
private static function hasAppId(): bool
{
return '' !== (string) request()->cookie(self::APP_ID);
}
/**
* Will return the Nordigen ID. From a cookie if its there, otherwise from configuration.
* TODO is a cookie the best place?
*
* @return string
*/
public static function getSecret(): string
{
if (!self::hasSecret()) {
app('log')->debug('No Spectre secret in hasSecret(), will return config variable.');
return (string) config('spectre.secret');
}
return request()->cookie(self::SECRET);
}
/**
* Will verify if the user has a Spectre App ID (in a cookie)
* TODO is a cookie the best place?
*
* @return bool
*/
private static function hasSecret(): bool
{
return '' !== (string) request()->cookie(self::SECRET);
}
}

19
app/Services/Spectre/AuthenticationValidator.php

@ -27,11 +27,11 @@ namespace App\Services\Spectre;
use App\Exceptions\ImporterHttpException;
use App\Services\Enums\AuthenticationStatus;
use App\Services\Session\Constants;
use App\Services\Shared\Authentication\AuthenticationValidatorInterface;
use App\Services\Shared\Authentication\IsRunningCli;
use App\Services\Spectre\Request\ListCustomersRequest;
use App\Services\Spectre\Response\ErrorResponse;
use App\Services\Spectre\Authentication\SecretManager;
/**
* Class AuthenticationValidator
@ -45,26 +45,17 @@ class AuthenticationValidator implements AuthenticationValidatorInterface
*/
public function validate(): AuthenticationStatus
{
die('must validate nordigen using secret manager');
// SecretManager::getUrl();
app('log')->debug(sprintf('Now at %s', __METHOD__));
$url = config('spectre.url');
$appId = config('spectre.app_id');
$secret = config('spectre.secret');
if ('' === $appId && !$this->isCli()) {
$appId = (string) session()->get(Constants::SESSION_SPECTRE_APP_ID);
}
if ('' === $secret && !$this->isCli()) {
$secret = (string) session()->get(Constants::SESSION_SPECTRE_SECRET);
}
$appId = SecretManager::getAppId();
$secret = SecretManager::getSecret();
if ('' === $appId || '' === $secret) {
return AuthenticationStatus::nodata();
}
$request = new ListCustomersRequest($url, $appId, $secret);
$request = new ListCustomersRequest($url, $appId, $secret);
$request->setTimeOut(config('importer.connection.timeout'));
try {

Loading…
Cancel
Save