1313
1414namespace Laudis \Neo4j \Authentication ;
1515
16- use Bolt \protocol \V4_4 ;
17- 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 ;
2216use Exception ;
17+ use Laudis \Neo4j \Bolt \BoltConnection ;
2318use Laudis \Neo4j \Bolt \BoltMessageFactory ;
2419use Laudis \Neo4j \Common \Neo4jLogger ;
25- use Laudis \Neo4j \Common \ResponseHelper ;
2620use Laudis \Neo4j \Contracts \AuthenticateInterface ;
2721use Psr \Http \Message \UriInterface ;
2822
@@ -43,27 +37,26 @@ public function __construct(
4337 *
4438 * @return array{server: string, connection_id: string, hints: list}
4539 */
46- public function authenticateBolt (V4_4 | V5 | V5_1 | V5_2 | V5_3 | V5_4 $ protocol , string $ userAgent ): array
40+ public function authenticateBolt (BoltConnection $ connection , string $ userAgent ): array
4741 {
48- $ factory = $ this ->createMessageFactory ($ protocol );
42+ $ factory = $ this ->createMessageFactory ($ connection );
4943
44+ $ protocol = $ connection ->protocol ();
5045 if (method_exists ($ protocol , 'logon ' )) {
5146 $ helloMetadata = ['user_agent ' => $ userAgent ];
5247
53- $ factory ->createHelloMessage ($ helloMetadata )->send ();
54- $ response = ResponseHelper::getResponse ($ protocol );
48+ $ responseHello = $ factory ->createHelloMessage ($ helloMetadata )->send ()->getResponse ();
5549
5650 $ credentials = [
5751 'scheme ' => 'basic ' ,
5852 'principal ' => $ this ->username ,
5953 'credentials ' => $ this ->password ,
6054 ];
6155
62- $ factory ->createLogonMessage ($ credentials )->send ();
63- ResponseHelper::getResponse ($ protocol );
56+ $ response = $ factory ->createLogonMessage ($ credentials )->send ()->getResponse ();
6457
6558 /** @var array{server: string, connection_id: string, hints: list} */
66- return $ response ->content ;
59+ return array_merge ( $ responseHello -> content , $ response ->content ) ;
6760 }
6861
6962 $ helloMetadata = [
@@ -73,22 +66,15 @@ public function authenticateBolt(V4_4|V5|V5_1|V5_2|V5_3|V5_4 $protocol, string $
7366 'credentials ' => $ this ->password ,
7467 ];
7568
76- $ factory ->createHelloMessage ($ helloMetadata )->send ();
69+ $ response = $ factory ->createHelloMessage ($ helloMetadata )->send ()-> getResponse ();
7770
7871 /** @var array{server: string, connection_id: string, hints: list} */
79- return ResponseHelper:: getResponse ( $ protocol ) ->content ;
72+ return $ response ->content ;
8073 }
8174
8275 /**
8376 * @throws Exception
8477 */
85- public function logoff (V4_4 |V5 |V5_1 |V5_2 |V5_3 |V5_4 $ protocol ): void
86- {
87- $ factory = $ this ->createMessageFactory ($ protocol );
88- $ factory ->createLogoffMessage ()->send ();
89- ResponseHelper::getResponse ($ protocol );
90- }
91-
9278 public function toString (UriInterface $ uri ): string
9379 {
9480 return sprintf ('Basic %s:%s@%s:%s ' , $ this ->username , '###### ' , $ uri ->getHost (), $ uri ->getPort () ?? '' );
@@ -97,8 +83,8 @@ public function toString(UriInterface $uri): string
9783 /**
9884 * Helper to create message factory.
9985 */
100- private function createMessageFactory (V4_4 | V5 | V5_1 | V5_2 | V5_3 | V5_4 $ protocol ): BoltMessageFactory
86+ private function createMessageFactory (BoltConnection $ connection ): BoltMessageFactory
10187 {
102- return new BoltMessageFactory ($ protocol , $ this ->logger );
88+ return new BoltMessageFactory ($ connection , $ this ->logger );
10389 }
10490}
0 commit comments