Browse Source

Remove need for bridge URL.

pull/897/head
James Cole 3 months ago
parent
commit
2d893f6a97
  1. 10
      app/Http/Controllers/Import/UploadController.php
  2. 1
      app/Services/Session/Constants.php
  3. 4
      app/Services/SimpleFIN/Conversion/RoutineManager.php
  4. 7
      app/Services/SimpleFIN/Request/SimpleFINRequest.php
  5. 21
      app/Services/SimpleFIN/SimpleFINService.php
  6. 28
      resources/views/v2/import/003-upload/index.blade.php

10
app/Http/Controllers/Import/UploadController.php

@ -307,23 +307,17 @@ class UploadController extends Controller
Log::debug('UploadController::handleSimpleFINFlow() INVOKED'); // Unique entry marker
$setupToken = (string)$request->get('simplefin_token');
$bridgeUrl = (string)$request->get('simplefin_bridge_url');
$isDemo = $request->boolean('use_demo');
$accessToken = $configuration->getAccessToken();
Log::debug(sprintf('handleSimpleFINFlow("%s", "%s")', $bridgeUrl, $setupToken));
Log::debug(sprintf('handleSimpleFINFlow("%s")', $setupToken));
if ($isDemo) {
Log::debug('Overrule info with demo info.');
$setupToken = (string)config('simplefin.demo_token');
$bridgeUrl = (string)config('simplefin.demo_url');
}
if ('' === $setupToken && '' === $accessToken) {
$errors->add('simplefin_token', 'SimpleFIN token is required.');
}
if ('' !== $bridgeUrl && false === filter_var($bridgeUrl, FILTER_VALIDATE_URL) && '' === $accessToken) {
$errors->add('simplefin_bridge_url', 'Bridge URL must be a valid URL.');
}
if ($errors->count() > 0) {
Log::debug('Errors in SimpleFIN flow, return to upload form.');
@ -331,13 +325,11 @@ class UploadController extends Controller
}
// Store data in session (may be empty).
session()->put(Constants::SIMPLEFIN_BRIDGE_URL, $bridgeUrl);
session()->put(Constants::SIMPLEFIN_TOKEN, $setupToken);
// create service:
/** @var SimpleFINService $simpleFINService */
$simpleFINService = app(SimpleFINService::class);
$simpleFINService->setBridgeUrl($bridgeUrl);
$simpleFINService->setSetupToken($setupToken);
$simpleFINService->setConfiguration($configuration);
$simpleFINService->setAccessToken($accessToken);

1
app/Services/Session/Constants.php

@ -93,7 +93,6 @@ class Constants
// SimpleFIN specific constants
public const string SIMPLEFIN_TOKEN = 'simplefin_token';
public const string SIMPLEFIN_BRIDGE_URL = 'simplefin_bridge_url';
public const string SIMPLEFIN_ACCOUNTS_DATA = 'simplefin_accounts_data';
public const string SIMPLEFIN_IS_DEMO = 'simplefin_is_demo';
public const string SIMPLEFIN_ACCESS_TOKEN = 'simplefin_access_token';

4
app/Services/SimpleFIN/Conversion/RoutineManager.php

@ -92,17 +92,15 @@ class RoutineManager implements RoutineManagerInterface
Log::debug(sprintf('[%s] Now in %s', config('importer.version'), __METHOD__));
$token = (string)session()->get(Constants::SIMPLEFIN_TOKEN); // Retained for general session validation
$bridgeUrl = (string)session()->get(Constants::SIMPLEFIN_BRIDGE_URL); // Retained for general session validation
$allAccountsSimpleFINData = session()->get(Constants::SIMPLEFIN_ACCOUNTS_DATA, []);
$accessToken = $this->configuration->getAccessToken();
if ('' === $accessToken && ('' === $token || '' === $bridgeUrl || 0 === count($allAccountsSimpleFINData))) {
if ('' === $accessToken && ('' === $token || 0 === count($allAccountsSimpleFINData))) {
Log::error(
'SimpleFIN session data incomplete for conversion.',
[
'access_token' => '' !== $accessToken,
'has_token' => '' !== $token,
'has_bridge_url' => '' !== $bridgeUrl,
'has_accounts_data' => 0 !== count($allAccountsSimpleFINData),
]
);

7
app/Services/SimpleFIN/Request/SimpleFINRequest.php

@ -45,7 +45,6 @@ abstract class SimpleFINRequest
private array $parameters = [];
private float $timeOut;
private string $bridgeUrl = '';
private string $accessToken = '';
/**
@ -86,7 +85,6 @@ abstract class SimpleFINRequest
'headers' => [
'Accept' => 'application/json',
'Content-Type' => 'application/json',
'Origin' => $this->bridgeUrl,
],
];
@ -160,11 +158,6 @@ abstract class SimpleFINRequest
return $this->timeOut;
}
public function setBridgeUrl(string $bridgeUrl): void
{
$this->bridgeUrl = $bridgeUrl;
}
public function setAccessToken(string $accessToken): void
{
Log::debug(sprintf('Access token is now: %s', $accessToken));

21
app/Services/SimpleFIN/SimpleFINService.php

@ -44,7 +44,6 @@ class SimpleFINService
{
private string $accessToken = '';
private string $accessUrl = '';
private string $bridgeUrl = '';
private string $setupToken = '';
private Configuration $configuration;
@ -66,11 +65,9 @@ class SimpleFINService
Log::debug(sprintf('Successfully exchanged claim URL for access token: %s', $this->accessToken));
}
if (!$isValid) {
Log::debug('Token is not a base64-encoded claim URL, using provided bridge URL');
Log::error('Token is not a base64-encoded claim URL.');
// Token is not a base64 claim URL, we need an API URL
if ('' === $this->bridgeUrl) {
throw new ImporterErrorException('SimpleFIN API URL is required when token is not a base64-encoded claim URL');
}
throw new ImporterErrorException('Token is not a base64-encoded claim URL.');
}
}
@ -81,7 +78,6 @@ class SimpleFINService
Log::debug(sprintf('SimpleFIN fetching transactions from: %s for account %s', $this->accessToken, $accountId));
$request = new AccountsRequest();
$request->setBridgeUrl($this->bridgeUrl);
$request->setAccessToken($this->accessToken);
$request->setTimeOut($this->getTimeout());
@ -132,7 +128,6 @@ class SimpleFINService
Log::debug(sprintf('SimpleFIN fetching accounts from: %s', $this->accessToken));
$request = new AccountsRequest();
$request->setBridgeUrl($this->bridgeUrl);
$request->setAccessToken($this->accessToken);
$request->setTimeOut($this->getTimeout());
@ -298,7 +293,6 @@ class SimpleFINService
Log::debug(sprintf('SimpleFIN download transactions for account ID: "%s" from provided data structure.', $accountId));
$request = new AccountsRequest();
$request->setBridgeUrl($this->bridgeUrl);
$request->setAccessToken($this->accessToken);
$request->setTimeOut($this->getTimeout());
@ -423,12 +417,6 @@ class SimpleFINService
'verify' => config('importer.connection.verify'),
]);
// Make POST request to claim URL with empty body
// Use user-provided bridge URL as Origin header for CORS
if ('' === $this->bridgeUrl) {
// throw new ImporterErrorException('SimpleFIN bridge URL not found. Please provide a valid bridge URL.');
}
Log::debug(sprintf('SimpleFIN using user-provided origin: "%s"', $this->bridgeUrl));
$parts = parse_url($claimUrl);
Log::debug(sprintf('Parsed $claimUrl parts: %s', json_encode($parts)));
@ -436,7 +424,6 @@ class SimpleFINService
'headers' => [
'Content-Length' => '0',
'Origin' => sprintf('%s://%s', $parts['scheme'] ?? 'https', $parts['host'] ?? 'localhost'),
// 'Origin' => $this->bridgeUrl,
],
]);
@ -511,10 +498,6 @@ class SimpleFINService
return $this->accessToken;
}
public function setBridgeUrl(string $bridgeUrl): void
{
$this->bridgeUrl = $bridgeUrl;
}
public function setSetupToken(string $setupToken): void
{

28
resources/views/v2/import/003-upload/index.blade.php

@ -93,43 +93,15 @@
</div>
</div>
<!-- SimpleFIN CORS Origin URL (Additional Options) -->
<div class="form-group row mb-3" id="bridge-url-group">
<label for="simplefin_bridge_url" class="col-sm-4 col-form-label">
CORS Origin URL
<small class="text-muted">(optional)</small>
</label>
<div class="col-sm-8">
<input type="url"
class="form-control
@if($errors->has('simplefin_bridge_url')) is-invalid @endif"
id="simplefin_bridge_url" name="simplefin_bridge_url"
value="{{ $simpleFinOriginUrl }}"
autocomplete="off"
placeholder="https://your-app.example.com"/>
<small class="form-text text-muted">
Enter the URL where you access this Firefly III Data Importer (e.g., https://your-domain.com). Leave blank if unsure.
</small>
@if($errors->has('simplefin_bridge_url'))
<div class="invalid-feedback">
{{ $errors->first('simplefin_bridge_url') }}
</div>
@endif
</div>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
const demoCheckbox = document.getElementById('use_demo');
const bridgeUrlGroup = document.getElementById('bridge-url-group');
const tokenGroup = document.getElementById('token-group');
function toggleSimpleFINFields() {
if (demoCheckbox.checked) {
bridgeUrlGroup.style.display = 'none';
tokenGroup.style.display = 'none';
} else {
bridgeUrlGroup.style.display = 'flex';
tokenGroup.style.display = 'flex';
}
}

Loading…
Cancel
Save