-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathNoAuth.php
More file actions
73 lines (57 loc) · 2.27 KB
/
NoAuth.php
File metadata and controls
73 lines (57 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
declare(strict_types=1);
/*
* This file is part of the Neo4j PHP Client and Driver package.
*
* (c) Nagels <https://nagels.tech>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Laudis\Neo4j\Authentication;
use Exception;
use Laudis\Neo4j\Bolt\BoltConnection;
use Laudis\Neo4j\Bolt\BoltMessageFactory;
use Laudis\Neo4j\Common\Neo4jLogger;
use Laudis\Neo4j\Contracts\AuthenticateInterface;
use Laudis\Neo4j\Enum\ConnectionProtocol;
use Psr\Http\Message\UriInterface;
use function sprintf;
final class NoAuth implements AuthenticateInterface
{
public function __construct(
private readonly ?Neo4jLogger $logger,
) {
}
/**
* @throws Exception
*
* @return array{server: string, connection_id: string, hints: list, patch_bolt?: list<string>}
*/
public function authenticateBolt(BoltConnection $connection, string $userAgent): array
{
$factory = $this->createMessageFactory($connection);
if ($connection->getProtocol()->compare(ConnectionProtocol::BOLT_V5_1()) >= 0) {
$helloMetadata = BoltHelloMetadata::withUtcPatchIfSupported($connection, ['user_agent' => $userAgent]);
$factory->createHelloMessage($helloMetadata)->send()->getResponse();
$response = $factory->createLogonMessage(['scheme' => 'none'])->send()->getResponse();
/** @var array{server: string, connection_id: string, hints: list, patch_bolt?: list<string>} */
return $response->content;
}
$helloMetadata = BoltHelloMetadata::withUtcPatchIfSupported($connection, [
'user_agent' => $userAgent,
'scheme' => 'none',
]);
$response = $factory->createHelloMessage($helloMetadata)->send()->getResponse();
/** @var array{server: string, connection_id: string, hints: list, patch_bolt?: list<string>} */
return $response->content;
}
public function toString(UriInterface $uri): string
{
return sprintf('No Auth %s:%s', $uri->getHost(), $uri->getPort() ?? '');
}
private function createMessageFactory(BoltConnection $connection): BoltMessageFactory
{
return new BoltMessageFactory($connection, $this->logger);
}
}