-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Description
File can not be loaded when using a relative path.
I would suggest to add base_path()
around $path
when the $path
does not start with /
.
$keys[] = JWKFactory::createFromKeyFile($path); |
Related code in other projects:
<?php
declare(strict_types=1);
namespace App\Attributes;
use Attribute;
use Illuminate\Container\Attributes\Config;
use Illuminate\Container\Container;
use Illuminate\Contracts\Container\BindingResolutionException;
use Illuminate\Contracts\Container\ContextualAttribute;
use Illuminate\Support\Str;
use Jose\Component\KeyManagement\JWKFactory;
#[Attribute(Attribute::TARGET_PARAMETER)]
class JWKFromConfig implements ContextualAttribute
{
/**
* Create a new attribute instance.
*/
public function __construct(public string $key, public mixed $default = null)
{
}
/**
* Resolve the configuration value.
*
* @param self $attribute
* @param Container $container
* @return mixed
* @throws BindingResolutionException
*/
public static function resolve(self $attribute, Container $container): mixed
{
$privateKeyPath = Config::resolve(new Config($attribute->key, $attribute->default), $container);
if (empty($privateKeyPath)) {
throw new BindingResolutionException('Configuration value not found for key: ' . $attribute->key);
}
$absolutePrivateKeyPath = Str::startsWith($privateKeyPath, DIRECTORY_SEPARATOR) ?
$privateKeyPath :
base_path($privateKeyPath);
if (!file_exists($absolutePrivateKeyPath)) {
throw new BindingResolutionException('Private key file not found at path: ' . $privateKeyPath);
}
return JWKFactory::createFromKeyFile($absolutePrivateKeyPath);
}
}
thomas-samoht
Metadata
Metadata
Assignees
Labels
No labels