Skip to content

Commit

Permalink
Replaced bearer token by headers property at RPC client
Browse files Browse the repository at this point in the history
Signed-off-by: Roman Bylbas <[email protected]>
  • Loading branch information
Roman Bylbas committed Nov 29, 2023
1 parent 8b7dc9e commit 2e58c43
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ extension=secp256k1.so

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

$client = new Casper\Rpc\RpcClient($nodeUrl, $bearerToken);
$client = new Casper\Rpc\RpcClient($nodeUrl, $headers);
```

### RPC call examples
Expand Down
10 changes: 5 additions & 5 deletions docs/API/RpcClientAPI.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ Class for interacting with the network via RPC
---
## Constructor
```php
__constructor(string $nodeUrl, string $bearerToken = null)
__constructor(string $nodeUrl, string $headers = null)
```
### Parameters
| Name | Type | Description | Required |
|----------------|---|----------------------------|----------|
| `$nodeUrl` | `string` | Full node url string | Yes |
| `$bearerToken` | `string` | Authorization bearer token | No |
| Name | Type | Description | Required |
|------------|----------|----------------------|----------|
| `$nodeUrl` | `string` | Full node url string | Yes |
| `$headers` | `array` | Additional headers | No |

---
## Put deploy
Expand Down
10 changes: 5 additions & 5 deletions src/Rpc/RpcClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,14 @@ class RpcClient

private string $nodeUrl;

private ?string $bearerToken = null;
private array $headers;

private ?string $lastApiVersion = null;

public function __construct(string $nodeUrl, string $bearerToken = null)
public function __construct(string $nodeUrl, array $headers = array())
{
$this->nodeUrl = $nodeUrl;
$this->bearerToken = $bearerToken;
$this->headers = $headers;
}

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

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

curl_setopt($curl, CURLOPT_URL, $url);
Expand Down

0 comments on commit 2e58c43

Please sign in to comment.