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

Features/cross origin credentials #172

Merged
merged 2 commits into from Apr 15, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion phpunit.xml.dist
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
bootstrap="vendor/autoload.php"
bootstrap="tests/autoload.php"
colors="true"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
cacheDirectory=".phpunit.cache"
Expand Down
3 changes: 3 additions & 0 deletions src/Dto/Manifest.php
Expand Up @@ -11,6 +11,9 @@ final class Manifest
{
use TranslatableTrait;

#[SerializedName('use_credentials')]
public bool $useCredentials = true;

#[SerializedName('background_color')]
public null|string $backgroundColor = null;

Expand Down
4 changes: 4 additions & 0 deletions src/Resources/config/definition/manifest.php
Expand Up @@ -27,6 +27,10 @@
->info('The public URL of the manifest file.')
->example('/site.manifest')
->end()
->booleanNode('use_credentials')
->defaultTrue()
->info('Indicates whether the manifest should be fetched with credentials.')
->end()
->scalarNode('background_color')
->info(
'The background color of the application. It should match the background-color CSS property in the sites stylesheet for a smooth transition between launching the web application and loading the site\'s content.'
Expand Down
2 changes: 2 additions & 0 deletions src/Subscriber/ManifestCompileEventListener.php
Expand Up @@ -10,6 +10,7 @@
use Symfony\Component\DependencyInjection\Attribute\Autowire;
use Symfony\Component\EventDispatcher\Attribute\AsEventListener;
use Symfony\Component\Serializer\Encoder\JsonEncode;
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
use Symfony\Component\Serializer\Normalizer\AbstractObjectNormalizer;
use Symfony\Component\Serializer\SerializerInterface;
use const JSON_PRETTY_PRINT;
Expand Down Expand Up @@ -40,6 +41,7 @@ public function __construct(
$options = [
AbstractObjectNormalizer::SKIP_UNINITIALIZED_VALUES => true,
AbstractObjectNormalizer::SKIP_NULL_VALUES => true,
AbstractNormalizer::IGNORED_ATTRIBUTES => ['useCredentials'],
JsonEncode::OPTIONS => JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_THROW_ON_ERROR,
];
if ($debug === true) {
Expand Down
2 changes: 2 additions & 0 deletions src/Subscriber/PwaDevServerSubscriber.php
Expand Up @@ -16,6 +16,7 @@
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\HttpKernel\Profiler\Profiler;
use Symfony\Component\Serializer\Encoder\JsonEncode;
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
use Symfony\Component\Serializer\Normalizer\AbstractObjectNormalizer;
use Symfony\Component\Serializer\SerializerInterface;
use function assert;
Expand Down Expand Up @@ -69,6 +70,7 @@ public function __construct(
$options = [
AbstractObjectNormalizer::SKIP_UNINITIALIZED_VALUES => true,
AbstractObjectNormalizer::SKIP_NULL_VALUES => true,
AbstractNormalizer::IGNORED_ATTRIBUTES => ['useCredentials'],
JsonEncode::OPTIONS => JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_THROW_ON_ERROR,
];
if ($debug === true) {
Expand Down
6 changes: 5 additions & 1 deletion src/Twig/PwaRuntime.php
Expand Up @@ -56,8 +56,12 @@ public function load(
private function injectManifestFile(string $output): string
{
$url = $this->assetMapper->getPublicPath($this->manifestPublicUrl) ?? $this->manifestPublicUrl;
$useCredentials = '';
if ($this->manifest->useCredentials === true) {
$useCredentials = ' crossorigin="use-credentials"';
}

return $output . sprintf('%s<link rel="manifest" href="%s">', PHP_EOL, $url);
return $output . sprintf('%s<link rel="manifest"%s href="%s">', PHP_EOL, $useCredentials, $url);
}

private function injectThemeColor(string $output, bool $themeColor): string
Expand Down
9 changes: 9 additions & 0 deletions tests/autoload.php
@@ -0,0 +1,9 @@
<?php

declare(strict_types=1);

use Symfony\Component\ErrorHandler\ErrorHandler;

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

ErrorHandler::register(null, false);