Skip to content

Commit 426040e

Browse files
committed
Store key contents instead of Key object
1 parent c1f2e0e commit 426040e

File tree

4 files changed

+16
-18
lines changed

4 files changed

+16
-18
lines changed

src/AuthorizationValidators/BearerTokenValidator.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,10 @@ private function initJwtConfiguration()
7777
\class_exists(StrictValidAt::class)
7878
? new StrictValidAt(new SystemClock(new DateTimeZone(\date_default_timezone_get())))
7979
: new ValidAt(new SystemClock(new DateTimeZone(\date_default_timezone_get()))),
80-
new SignedWith(new Sha256(), $this->publicKey->getKey())
80+
new SignedWith(
81+
new Sha256(),
82+
InMemory::plainText($this->publicKey->getKeyContents(), $this->publicKey->getPassPhrase() ?? ''),
83+
)
8184
);
8285
}
8386

src/CryptKey.php

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@
1111

1212
namespace League\OAuth2\Server;
1313

14-
use Lcobucci\JWT\Signer\Key;
15-
use Lcobucci\JWT\Signer\Key\InMemory;
16-
use Lcobucci\JWT\Signer\Key\LocalFileReference;
1714
use LogicException;
1815

1916
class CryptKey
@@ -25,9 +22,9 @@ class CryptKey
2522
private const FILE_PREFIX = 'file://';
2623

2724
/**
28-
* @var Key
25+
* @var string Key contents
2926
*/
30-
protected $key;
27+
protected $keyContents;
3128

3229
/**
3330
* @var string
@@ -49,8 +46,7 @@ public function __construct($keyPath, $passPhrase = null, $keyPermissionsCheck =
4946
$this->passPhrase = $passPhrase;
5047

5148
if (\strpos($keyPath, self::FILE_PREFIX) !== 0 && $this->isValidKey($keyPath, $this->passPhrase ?? '')) {
52-
$contents = $keyPath;
53-
$this->key = InMemory::plainText($keyPath, $this->passPhrase ?? '');
49+
$this->keyContents = $keyPath;
5450
$this->keyPath = '';
5551
// There's no file, so no need for permission check.
5652
$keyPermissionsCheck = false;
@@ -62,10 +58,9 @@ public function __construct($keyPath, $passPhrase = null, $keyPermissionsCheck =
6258
if (!\is_readable($keyPath)) {
6359
throw new LogicException(\sprintf('Key path "%s" does not exist or is not readable', $keyPath));
6460
}
65-
$contents = \file_get_contents($keyPath);
61+
$this->keyContents = \file_get_contents($keyPath);
6662
$this->keyPath = $keyPath;
67-
$this->key = LocalFileReference::file($this->keyPath, $this->passPhrase ?? '');
68-
if (!$this->isValidKey($contents, $this->passPhrase ?? '')) {
63+
if (!$this->isValidKey($this->keyContents, $this->passPhrase ?? '')) {
6964
throw new LogicException('Unable to read key from file ' . $keyPath);
7065
}
7166
} else {
@@ -89,13 +84,13 @@ public function __construct($keyPath, $passPhrase = null, $keyPermissionsCheck =
8984
}
9085

9186
/**
92-
* Get key
87+
* Get key contents
9388
*
94-
* @return Key
89+
* @return string Key contents
9590
*/
96-
public function getKey(): Key
91+
public function getKeyContents(): string
9792
{
98-
return $this->key;
93+
return $this->keyContents;
9994
}
10095

10196
/**

src/Entities/Traits/AccessTokenTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function initJwtConfiguration()
4545
{
4646
$this->jwtConfiguration = Configuration::forAsymmetricSigner(
4747
new Sha256(),
48-
$this->privateKey->getKey(),
48+
InMemory::plainText($this->privateKey->getKeyContents(), $this->privateKey->getPassPhrase() ?? ''),
4949
InMemory::plainText('')
5050
);
5151
}

tests/Utils/CryptKeyTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function testKeyString()
3535

3636
$this->assertEquals(
3737
$keyContent,
38-
$key->getKey()->contents()
38+
$key->getKeyContents()
3939
);
4040

4141
$keyContent = \file_get_contents(__DIR__ . '/../Stubs/private.key.crlf');
@@ -48,7 +48,7 @@ public function testKeyString()
4848

4949
$this->assertEquals(
5050
$keyContent,
51-
$key->getKey()->contents()
51+
$key->getKeyContents()
5252
);
5353
}
5454

0 commit comments

Comments
 (0)