Skip to content

Commit 7bb9078

Browse files
authored
Merge pull request #74 from neo4j-php/authentication
Small authentication improvements
2 parents 13827ed + e9edff3 commit 7bb9078

File tree

4 files changed

+12
-12
lines changed

4 files changed

+12
-12
lines changed

src/Bolt.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,14 +200,14 @@ private function packProtocolVersions(): string
200200
*
201201
* @return bool
202202
* @throws Exception
203-
* @deprecated The usage of $user, $password, $routing and $metadata is deprecated. Please use helpers\Auth to generate an authentication strategy as an array.
203+
* @note The usage of $user, $password, $routing and $metadata is deprecated. Please use helpers\Auth to generate an authentication strategy as an array.
204204
*
205205
* @version <3
206206
*/
207207
public function init($userAgentOrExtra, string $user = '', string $password = '', $routing = false, array &$metadata = []): bool
208208
{
209209
if (is_string($userAgentOrExtra)) {
210-
Auth::$userAgent = $userAgentOrExtra;
210+
Auth::$defaultUserAgent = $userAgentOrExtra;
211211
$userAgentOrExtra = empty($user) && empty($password) ? Auth::none() : Auth::basic($user, $password);
212212
if ($routing !== false)
213213
$userAgentOrExtra['routing'] = $routing;
@@ -235,7 +235,7 @@ public function init($userAgentOrExtra, string $user = '', string $password = ''
235235
*
236236
* @return bool
237237
* @throws Exception
238-
* @deprecated The usage of $user, $password, $routing and $metadata is deprecated. Please use helpers\Auth to generate an authentication strategy as an array.
238+
* @note The usage of $user, $password, $routing and $metadata is deprecated. Please use helpers\Auth to generate an authentication strategy as an array.
239239
*
240240
* @version >=3
241241
*/

src/helpers/Auth.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@ class Auth
1515
/**
1616
* @var string
1717
*/
18-
public static $userAgent = 'bolt-php';
18+
public static $defaultUserAgent = 'bolt-php';
1919

2020
/**
2121
* None authorization
2222
* @return array
2323
*/
24-
public static function none(): array
24+
public static function none(?string $userAgent = null): array
2525
{
2626
return [
27-
'user_agent' => self::$userAgent,
27+
'user_agent' => $userAgent ?? self::$defaultUserAgent,
2828
'scheme' => 'none'
2929
];
3030
}
@@ -35,10 +35,10 @@ public static function none(): array
3535
* @param string $password
3636
* @return array
3737
*/
38-
public static function basic(string $username, string $password): array
38+
public static function basic(string $username, string $password, ?string $userAgent = null): array
3939
{
4040
return [
41-
'user_agent' => self::$userAgent,
41+
'user_agent' => $userAgent ?? self::$defaultUserAgent,
4242
'scheme' => 'basic',
4343
'principal' => $username,
4444
'credentials' => $password
@@ -50,10 +50,10 @@ public static function basic(string $username, string $password): array
5050
* @param string $token
5151
* @return array
5252
*/
53-
public static function bearer(string $token): array
53+
public static function bearer(string $token, ?string $userAgent = null): array
5454
{
5555
return [
56-
'user_agent' => self::$userAgent,
56+
'user_agent' => $userAgent ?? self::$defaultUserAgent,
5757
'scheme' => 'bearer',
5858
'credentials' => $token
5959
];

tests/protocol/V1Test.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class V1Test extends \Bolt\tests\ATest
2727
*/
2828
public function test__construct()
2929
{
30-
\Bolt\helpers\Auth::$userAgent = 'Test/1.0';
30+
\Bolt\helpers\Auth::$defaultUserAgent = 'Test/1.0';
3131
$cls = new V1(new \Bolt\PackStream\v1\Packer, new \Bolt\PackStream\v1\Unpacker, $this->mockConnection());
3232
$this->assertInstanceOf(V1::class, $cls);
3333
return $cls;

tests/protocol/V4_1Test.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class V4_1Test extends \Bolt\tests\ATest
2424
*/
2525
public function test__construct()
2626
{
27-
\Bolt\helpers\Auth::$userAgent = 'Test/1.0';
27+
\Bolt\helpers\Auth::$defaultUserAgent = 'Test/1.0';
2828
$cls = new V4_1(new \Bolt\PackStream\v1\Packer, new \Bolt\PackStream\v1\Unpacker, $this->mockConnection());
2929
$this->assertInstanceOf(V4_1::class, $cls);
3030
return $cls;

0 commit comments

Comments
 (0)