Skip to content

Commit c87d7c4

Browse files
committed
Ensure allowed algorithms list is overwritten instead of merged.
Closes #52, #54.
1 parent b49fbc9 commit c87d7c4

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/Auth/JwtAuthenticate.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,16 @@ public function __construct(ComponentRegistry $registry, $config)
9191
'header' => 'authorization',
9292
'prefix' => 'bearer',
9393
'parameter' => 'token',
94-
'allowedAlgs' => ['HS256'],
9594
'queryDatasource' => true,
9695
'fields' => ['username' => 'id'],
9796
'unauthenticatedException' => '\Cake\Network\Exception\UnauthorizedException',
9897
'key' => null,
9998
]);
10099

100+
if (empty($config['allowedAlgs'])) {
101+
$config['allowedAlgs'] = ['HS256'];
102+
}
103+
101104
parent::__construct($registry, $config);
102105
}
103106

tests/TestCase/Auth/JwtAuthenticateTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,22 @@ public function setUp()
4444
->getMock();
4545
}
4646

47+
/**
48+
* testConfig.
49+
*
50+
* @return void
51+
*/
52+
public function testConfig()
53+
{
54+
$auth = new JwtAuthenticate($this->Registry, []);
55+
$this->assertEquals(['HS256'], $auth->config('allowedAlgs'));
56+
57+
$auth = new JwtAuthenticate($this->Registry, [
58+
'allowedAlgs' => ['RS256']
59+
]);
60+
$this->assertEquals(['RS256'], $auth->config('allowedAlgs'));
61+
}
62+
4763
/**
4864
* test authenticate token as query parameter.
4965
*

0 commit comments

Comments
 (0)