Skip to content

Commit

Permalink
Ensure allowed algorithms list is overwritten instead of merged.
Browse files Browse the repository at this point in the history
Closes #52, #54.
  • Loading branch information
ADmad committed May 31, 2017
1 parent b49fbc9 commit a9c7317
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/Auth/JwtAuthenticate.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,16 @@ public function __construct(ComponentRegistry $registry, $config)
'header' => 'authorization',
'prefix' => 'bearer',
'parameter' => 'token',
'allowedAlgs' => ['HS256'],
'queryDatasource' => true,
'fields' => ['username' => 'id'],
'unauthenticatedException' => '\Cake\Network\Exception\UnauthorizedException',
'key' => null,
]);

if (empty($config['allowedAlgs'])) {
$config['allowedAlgs'] = ['HS256'];
}

parent::__construct($registry, $config);
}

Expand Down
14 changes: 14 additions & 0 deletions tests/TestCase/Auth/JwtAuthenticateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,20 @@ public function setUp()
->getMock();
}

/**
* testConfig.
*
* @return void
*/
public function testConfig()
{
$auth = new JwtAuthenticate($this->Registry, [
'allowedAlgs' => ['RS256']
]);

$this->assertEquals(['RS256'], $auth->config('allowedAlgs'));
}

/**
* test authenticate token as query parameter.
*
Expand Down

0 comments on commit a9c7317

Please sign in to comment.