Skip to content

Commit 2e58c43

Browse files
author
Roman Bylbas
committed
Replaced bearer token by headers property at RPC client
Signed-off-by: Roman Bylbas <romka.bulbas@gmail.com>
1 parent 8b7dc9e commit 2e58c43

3 files changed

Lines changed: 13 additions & 13 deletions

File tree

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ extension=secp256k1.so
3131

3232
## Usage
3333
### Creating RpcClient
34-
Create `RpcClient` by passing node url and authorization token (optional) to constructor
34+
Create `RpcClient` by passing node url and headers (optional) to constructor
3535
```php
3636
$nodeUrl = 'http://127.0.0.1:7777';
37-
$bearerToken = '6ae6c8b31f09df244019ffef60c274e4'; // Optional
37+
$headers = array('Authorization' => 'Bearer 6ae6c8b31f09df244019ffef60c274e4'); // Optional
3838

39-
$client = new Casper\Rpc\RpcClient($nodeUrl, $bearerToken);
39+
$client = new Casper\Rpc\RpcClient($nodeUrl, $headers);
4040
```
4141

4242
### RPC call examples

docs/API/RpcClientAPI.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ Class for interacting with the network via RPC
44
---
55
## Constructor
66
```php
7-
__constructor(string $nodeUrl, string $bearerToken = null)
7+
__constructor(string $nodeUrl, string $headers = null)
88
```
99
### Parameters
10-
| Name | Type | Description | Required |
11-
|----------------|---|----------------------------|----------|
12-
| `$nodeUrl` | `string` | Full node url string | Yes |
13-
| `$bearerToken` | `string` | Authorization bearer token | No |
10+
| Name | Type | Description | Required |
11+
|------------|----------|----------------------|----------|
12+
| `$nodeUrl` | `string` | Full node url string | Yes |
13+
| `$headers` | `array` | Additional headers | No |
1414

1515
---
1616
## Put deploy

src/Rpc/RpcClient.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,14 @@ class RpcClient
6767

6868
private string $nodeUrl;
6969

70-
private ?string $bearerToken = null;
70+
private array $headers;
7171

7272
private ?string $lastApiVersion = null;
7373

74-
public function __construct(string $nodeUrl, string $bearerToken = null)
74+
public function __construct(string $nodeUrl, array $headers = array())
7575
{
7676
$this->nodeUrl = $nodeUrl;
77-
$this->bearerToken = $bearerToken;
77+
$this->headers = $headers;
7878
}
7979

8080
public function getLastApiVersion(): ?string
@@ -466,8 +466,8 @@ private function rpcCallMethod(string $method, array $params = array()): array
466466
$curl = curl_init($url);
467467

468468
$headers = ['Accept: application/json', 'Content-type: application/json'];
469-
if ($this->bearerToken !== null) {
470-
$headers[] = 'Authorization: Bearer ' . $this->bearerToken;
469+
foreach ($this->headers as $name => $value) {
470+
$headers[] = "$name: $value";
471471
}
472472

473473
curl_setopt($curl, CURLOPT_URL, $url);

0 commit comments

Comments
 (0)