Skip to content

Commit 096a6c0

Browse files
authored
modified Login logic (#12)
* updated login logic * Remove .php-cs-fixer.cache from tracking and add to .gitignore * Re-add test folder and update .gitignore
1 parent da0472d commit 096a6c0

15 files changed

+374
-135
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ test
1111

1212
#PHP-CS-FIXER
1313
.php-cs-fixer.php
14-
.php-cs-fixer.cache
14+
.php-cs-fixer.cache

.php-cs-fixer.cache

Lines changed: 0 additions & 1 deletion
This file was deleted.

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Query API
2+
3+
Usage example:
4+
5+
```php
6+
use Neo4j\QueryAPI\Neo4jQueryAPI;
7+
use Neo4j\QueryAPI\Objects\Authentication;
8+
9+
$client = Neo4jQueryAPI::login('https://myaddress.com', Authentication::bearer('mytokken'))
10+
```

src/AuthenticateInterface.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace Neo4j\QueryAPI;
4+
5+
use Psr\Http\Message\RequestInterface;
6+
7+
interface AuthenticateInterface
8+
{
9+
/**
10+
* Authenticates the request by returning a new instance of the request with the authentication information attached.
11+
*/
12+
public function authenticate(RequestInterface $request): RequestInterface;
13+
}

src/BasicAuthentication.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace Neo4j\QueryAPI;
4+
5+
use Psr\Http\Message\RequestInterface;
6+
use Psr\Http\Message\ResponseInterface;
7+
8+
class BasicAuthentication implements AuthenticateInterface
9+
{
10+
public function __construct(private string $username, private string $password)
11+
{
12+
$this->username = $username;
13+
$this->password = $password;
14+
}
15+
16+
public function authenticate(RequestInterface $request): RequestInterface
17+
{
18+
$authHeader = 'Basic ' . base64_encode($this->username . ':' . $this->password);
19+
return $request->withHeader('Authorization', $authHeader);
20+
}
21+
public function getHeader(): string
22+
{
23+
return 'Basic ' . base64_encode($this->username . ':' . $this->password);
24+
}
25+
26+
public function getType(): string
27+
{
28+
return 'Basic';
29+
}
30+
31+
}

src/BearerAuthentication.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace Neo4j\QueryAPI;
4+
5+
use Psr\Http\Message\RequestInterface;
6+
7+
class BearerAuthentication implements AuthenticateInterface
8+
{
9+
public function __construct(private string $token)
10+
{
11+
}
12+
13+
public function authenticate(RequestInterface $request): RequestInterface
14+
{
15+
$authHeader = 'Bearer ' . $this->token;
16+
return $request->withHeader('Authorization', $authHeader);
17+
}
18+
public function getHeader(): string
19+
{
20+
return 'Bearer ' . $this->token;
21+
}
22+
23+
public function getType(): string
24+
{
25+
return 'Bearer';
26+
}
27+
}

0 commit comments

Comments
 (0)