Skip to content

Commit

Permalink
Merge pull request #501 from cakephp/jwt-auth-algos
Browse files Browse the repository at this point in the history
Overwrite "algorithms" config instead of merging.
  • Loading branch information
markstory committed Nov 25, 2021
2 parents 1623daf + e8af975 commit 9dc2d73
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Authenticator/JwtAuthenticator.php
Expand Up @@ -54,6 +54,10 @@ public function __construct(IdentifierInterface $identifier, array $config = [])
{
parent::__construct($identifier, $config);

if (isset($config['algorithms'])) {
$this->setConfig('algorithms', $config['algorithms'], false);
}

if (empty($this->_config['secretKey'])) {
if (!class_exists(Security::class)) {
throw new RuntimeException('You must set the `secretKey` config key for JWT authentication.');
Expand Down
14 changes: 14 additions & 0 deletions tests/TestCase/Authenticator/JwtAuthenticatorTest.php
Expand Up @@ -70,6 +70,20 @@ public function setUp(): void
$this->identifiers = new IdentifierCollection([]);
}

/**
* Test that "algorithms" config overwrites the default value instead of merging.
*
* @return void
*/
public function testAlgorithmsOverwrite()
{
$authenticator = new JwtAuthenticator($this->identifiers, [
'algorithms' => ['RS256'],
]);

$this->assertSame(['RS256'], $authenticator->getConfig('algorithms'));
}

/**
* testAuthenticateViaHeaderToken
*
Expand Down

0 comments on commit 9dc2d73

Please sign in to comment.