Skip to content

Commit fd20fac

Browse files
committed
finish authentication
1 parent 700d332 commit fd20fac

File tree

6 files changed

+40
-14
lines changed

6 files changed

+40
-14
lines changed

phpunit.xml.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@
1515
</testsuite>
1616
</testsuites>
1717
<php>
18-
<env name="CONNECTION" value="neo4j://neo4j:testtest@localhost" />
18+
<env name="CONNECTION" value="neo4j://neo4j:testtest@localhost:11687" />
1919
</php>
2020
</phpunit>

src/Authentication/BasicAuth.php

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,13 @@
1515

1616
use function base64_encode;
1717

18-
use Bolt\helpers\Auth;
19-
use Bolt\protocol\Response;
18+
use Bolt\enum\Signature;
2019
use Bolt\protocol\V4_4;
2120
use Bolt\protocol\V5;
21+
use Bolt\protocol\V5_1;
22+
use Bolt\protocol\V5_2;
23+
use Bolt\protocol\V5_3;
24+
use Bolt\protocol\V5_4;
2225
use Exception;
2326
use Laudis\Neo4j\Contracts\AuthenticateInterface;
2427
use Laudis\Neo4j\Exception\Neo4jException;
@@ -57,15 +60,34 @@ public function authenticateHttp(RequestInterface $request, UriInterface $uri, s
5760
/**
5861
* @throws Exception
5962
*/
60-
public function authenticateBolt(V4_4|V5 $bolt, string $userAgent): array
63+
public function authenticateBolt(V4_4|V5|V5_1|V5_2|V5_3|V5_4 $protocol, string $userAgent): array
6164
{
62-
$response = $bolt->hello(Auth::basic($this->username, $this->password, $userAgent));
63-
if ($response->getSignature() === Response::SIGNATURE_FAILURE) {
65+
if (method_exists($protocol, 'logon')) {
66+
$response = $protocol->hello(['user_agent' => $userAgent])->getResponse();
67+
if ($response->signature === Signature::FAILURE) {
68+
throw Neo4jException::fromBoltResponse($response);
69+
}
70+
71+
$response = $protocol->logon([
72+
'scheme' => 'basic',
73+
'principal' => $this->username,
74+
'credentials' => $this->password,
75+
])->getResponse();
76+
} else {
77+
$response = $protocol->hello([
78+
'user_agent' => $userAgent,
79+
'scheme' => 'basic',
80+
'principal' => $this->username,
81+
'credentials' => $this->password,
82+
])->getResponse();
83+
}
84+
85+
if ($response->signature === Signature::FAILURE) {
6486
throw Neo4jException::fromBoltResponse($response);
6587
}
6688

6789
/** @var array{server: string, connection_id: string, hints: list} */
68-
return $response->getContent();
90+
return $response->content;
6991
}
7092

7193
public function toString(UriInterface $uri): string

src/Authentication/KerberosAuth.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ public function authenticateHttp(RequestInterface $request, UriInterface $uri, s
5050
->withHeader('User-Agent', $userAgent);
5151
}
5252

53-
public function authenticateBolt(V4_4|V5 $bolt, string $userAgent): array
53+
public function authenticateBolt(V4_4|V5 $protocol, string $userAgent): array
5454
{
55-
$response = $bolt->hello(Auth::kerberos($this->token, $userAgent));
55+
$response = $protocol->hello(Auth::kerberos($this->token, $userAgent));
5656
if ($response->getSignature() === Response::SIGNATURE_FAILURE) {
5757
throw Neo4jException::fromBoltResponse($response);
5858
}

src/Authentication/NoAuth.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ public function authenticateHttp(RequestInterface $request, UriInterface $uri, s
4242
return $request->withHeader('User-Agent', $userAgent);
4343
}
4444

45-
public function authenticateBolt(V4_4|V5 $bolt, string $userAgent): array
45+
public function authenticateBolt(V4_4|V5 $protocol, string $userAgent): array
4646
{
47-
$response = $bolt->hello(Auth::none($userAgent));
47+
$response = $protocol->hello(Auth::none($userAgent));
4848
if ($response->getSignature() === Response::SIGNATURE_FAILURE) {
4949
throw Neo4jException::fromBoltResponse($response);
5050
}

src/Authentication/OpenIDConnectAuth.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ public function authenticateHttp(RequestInterface $request, UriInterface $uri, s
4747
->withHeader('User-Agent', $userAgent);
4848
}
4949

50-
public function authenticateBolt(V4_4|V5 $bolt, string $userAgent): array
50+
public function authenticateBolt(V4_4|V5 $protocol, string $userAgent): array
5151
{
52-
$response = $bolt->hello(Auth::bearer($this->token, $userAgent));
52+
$response = $protocol->hello(Auth::bearer($this->token, $userAgent));
5353
if ($response->getSignature() === Response::SIGNATURE_FAILURE) {
5454
throw Neo4jException::fromBoltResponse($response);
5555
}

src/Contracts/AuthenticateInterface.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515

1616
use Bolt\protocol\V4_4;
1717
use Bolt\protocol\V5;
18+
use Bolt\protocol\V5_1;
19+
use Bolt\protocol\V5_2;
20+
use Bolt\protocol\V5_3;
21+
use Bolt\protocol\V5_4;
1822
use Psr\Http\Message\RequestInterface;
1923
use Psr\Http\Message\UriInterface;
2024

@@ -32,7 +36,7 @@ public function authenticateHttp(RequestInterface $request, UriInterface $uri, s
3236
*
3337
* @return array{server: string, connection_id: string, hints: list}
3438
*/
35-
public function authenticateBolt(V4_4|V5 $bolt, string $userAgent): array;
39+
public function authenticateBolt(V4_4|V5|V5_1|V5_2|V5_3|V5_4 $protocol, string $userAgent): array;
3640

3741
/**
3842
* Returns a string representation of the authentication.

0 commit comments

Comments
 (0)