Skip to content

Commit

Permalink
FFWEB-3114: Introduce API key authorisation
Browse files Browse the repository at this point in the history
Introduce API key authorisation
  • Loading branch information
Rayn93 authored Jul 18, 2024
1 parent 91fb8a9 commit 55b10df
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 1 deletion.
3 changes: 3 additions & 0 deletions spec/Subscriber/ConfigurationSubscriberSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public function it_will_return_factfinderchannel_for_specific_sales_channel_id(
$salesChannel->getId()->willReturn('main_sales_channel');
$communication->getVersion()->willReturn(Version::NG);
$communication->getApiVersion()->willReturn('v5');
$communication->getApiKey()->willReturn('abc-123');
$communication->isSsrActive()->willReturn(false);
$communication->isProxyEnabled()->willReturn(false);
$communication->getChannel('main_sales_channel')->willReturn('some_ff_channel');
Expand Down Expand Up @@ -109,6 +110,7 @@ public function it_will_add_page_extension_for_storefront_render_event(
$communication->getFieldRoles(Argument::any())->willReturn([]);
$communication->getVersion()->willReturn(Version::NG);
$communication->getApiVersion()->willReturn('v5');
$communication->getApiKey()->willReturn('abc-123');
$communication->isSsrActive()->willReturn(false);
$communication->isProxyEnabled()->willReturn(false);
$event->getRequest()->willReturn($request);
Expand Down Expand Up @@ -150,6 +152,7 @@ public function it_will_throw_exception_when_event_does_not_have_page(
$communication->getFieldRoles(Argument::any())->willReturn([]);
$communication->getVersion()->willReturn(Version::NG);
$communication->getApiVersion()->willReturn('v5');
$communication->getApiKey()->willReturn('abc-123');
$communication->isSsrActive()->willReturn(false);
$communication->isProxyEnabled()->willReturn(false);
$event->getRequest()->willReturn($request);
Expand Down
5 changes: 5 additions & 0 deletions src/Config/Communication.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ public function getCredentials(): array
];
}

public function getApiKey(): string
{
return (string) $this->config('apiKey');
}

public function isSsrActive(): bool
{
return (bool) $this->config('useSsr');
Expand Down
7 changes: 7 additions & 0 deletions src/Resources/config/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@
<required>true</required>
</input-field>

<input-field>
<name>apiKey</name>
<label>API key</label>
<label lang="de-DE">API-Schlüssel</label>
<required>true</required>
</input-field>

<input-field type="single-select">
<name>apiVersion</name>
<options>
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/views/storefront/base.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
ff: {
url: `{{page.extensions.factfinder.communication.url}}`,
channel: `{{page.extensions.factfinder.communication.channel}}`,
apiKey: `ffng-kwU8a6Sv.aCt0sDZbBLqTerkuuHLG8fhstllFXF`,
apiKey: `{{page.extensions.factfinder.communication.apiKey}}`,
},
appConfig: {
debug: true,
Expand Down
1 change: 1 addition & 0 deletions src/Subscriber/ConfigurationSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public function onPageLoaded(ShopwareSalesChannelEvent $event): void
$communication = [
'url' => $this->getServerUrl(),
'channel' => $this->config->getChannel($salesChannelId),
'apiKey' => $this->config->getApiKey(),
'version' => $this->config->getVersion(),
'api' => $this->config->getApiVersion(),
'currencyCode' => $event->getSalesChannelContext()->getCurrency()->getIsoCode(),
Expand Down

0 comments on commit 55b10df

Please sign in to comment.