PHPackages                             hitrov/oci-api-php-request-sign - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. hitrov/oci-api-php-request-sign

ActiveLibrary[API Development](/categories/api)

hitrov/oci-api-php-request-sign
===============================

This package generates proper HTTP headers to sign Oracle Cloud Infrastructure API requests

v1.2.6(4mo ago)261.6M↑154.6%11[1 issues](https://github.com/hitrov/oci-api-php-request-sign/issues)4MITPHPPHP &gt;=7.4 &lt;9.0CI passing

Since Feb 11Pushed 4mo ago3 watchersCompare

[ Source](https://github.com/hitrov/oci-api-php-request-sign)[ Packagist](https://packagist.org/packages/hitrov/oci-api-php-request-sign)[ Docs](https://github.com/hitrov/oci-api-php-request-sign)[ RSS](/packages/hitrov-oci-api-php-request-sign/feed)WikiDiscussions main Synced 3d ago

READMEChangelogDependencies (2)Versions (13)Used By (4)

Oracle Cloud Infrastructure API requests sign with PHP
======================================================

[](#oracle-cloud-infrastructure-api-requests-sign-with-php)

 [![Latest Stable Version](https://camo.githubusercontent.com/5a8144126cea5825bfa36fef6c3d7131aec6dbbe2112e8e5f3ce51df998b856c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f686974726f762f6f63692d6170692d7068702d726571756573742d7369676e)](https://packagist.org/packages/hitrov/oci-api-php-request-sign) [![Test](https://github.com/hitrov/oci-api-php-request-sign/workflows/Tests/badge.svg)](https://github.com/hitrov/oci-api-php-request-sign/actions)

- [Installation](#installation)
- [Preparing credentials](#preparing-credentials)
- [Basic usage](#basic-usage)
- [Alternatives for providing credentials](#alternatives-for-providing-credentials)
    - [Constructor arguments](#constructor-arguments)
    - [Separate credentials class](#separate-credentials-class)
- [Manual generation steps](#manual-generation-steps)
- [Inspiration](#inspiration)

If you prefer article style, here's a link to [Medium](https://hitrov.medium.com/creating-mini-php-sdk-to-sign-oracle-cloud-infrastructure-api-requests-d91a224c7008?sk=5b4405c1124bfeac30a370630fd94126)

Installation
------------

[](#installation)

```
composer require hitrov/oci-api-php-request-sign
```

Import classes autoloader

```
require 'vendor/autoload.php';
use Hitrov\OCI\Signer;
```

Preparing credentials
---------------------

[](#preparing-credentials)

`Signer` expects a list of environment variables available:

```
OCI_TENANCY_ID=ocid1.tenancy.oc1..aaaaaaaaba3pv6wkcr4jqae5f15p2b2m2yt2j6rx32uzr4h25vqstifsfdsq
OCI_USER_ID=ocid1.user.oc1..aaaaaaaat5nvwcna5j6aqzjcaty5eqbb6qt2jvpkanghtgdaqedqw3rynjq
OCI_KEY_FINGERPRINT=20:3b:97:13:55:1c:5b:0d:d3:37:d8:50:4e:c5:3a:34
OCI_PRIVATE_KEY_FILENAME=/path/to/privatekey.pem
```

There are few more ways to expose/pass them, please refer to [this](#alternatives-for-providing-credentials) section.

Basic usage
-----------

[](#basic-usage)

Here's the example of PHP script on how to [CreatePreauthenticatedRequest](https://docs.oracle.com/en-us/iaas/api/#/en/objectstorage/20160918/PreauthenticatedRequest/CreatePreauthenticatedRequest) for Object Storage Service API.

```
$signer = new Signer();

$curl = curl_init();

$url = 'https://objectstorage.eu-frankfurt-1.oraclecloud.com/n/{namespaceName}/b/{bucketName}/p/';
$method = 'POST';
$body = '{"accessType": "ObjectRead", "name": "read-access-to-image.png", "objectName": "path/to/image.png", "timeExpires": "2021-03-01T00:00:00-00:00"}';

$headers = $signer->getHeaders($url, $method, $body, 'application/json');
var_dump($headers);

$curlOptions = [
    CURLOPT_URL => $url,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_ENCODING => '',
    CURLOPT_MAXREDIRS => 10,
    CURLOPT_TIMEOUT => 5,
    CURLOPT_FOLLOWLOCATION => true,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST => $method,
    CURLOPT_HTTPHEADER => $headers,
];

if ($body) {
    // not needed for GET or HEAD requests
    $curlOptions[CURLOPT_POSTFIELDS] = $body;
}

curl_setopt_array($curl, $curlOptions);

$response = curl_exec($curl);
echo $response;
curl_close($curl);
```

```
array(6) {
  [0]=>
  string(35) "date: Mon, 08 Feb 2021 20:49:22 GMT"
  [1]=>
  string(50) "host: objectstorage.eu-frankfurt-1.oraclecloud.com"
  [2]=>
  string(18) "content-length: 76"
  [3]=>
  string(30) "content-type: application/json"
  [4]=>
  string(62) "x-content-sha256: X48E9qOokqqrvdts8nOJRJN3OWDUoyWxBf7kbu9DBPE="
  [5]=>
  string(538) "Authorization: Signature version=\"1\",keyId=\"ocid1.tenancy.oc1..aaaaaaaaba3pv6wkcr4jqae5f15p2b2m2yt2j6rx32uzr4h25vqstifsfdsq/ocid1.user.oc1..aaaaaaaat5nvwcna5j6aqzjcaty5eqbb6qt2jvpkanghtgdaqedqw3rynjq/20:3b:97:13:55:1c:5b:0d:d3:37:d8:50:4e:c5:3a:34\",algorithm=\"rsa-sha256\",headers=\"date (request-target) host content-length content-type x-content-sha256\",signature=\"LXWXDA8VmXXc1NRbMmXtW61IS97DfIOMAnlj+Gm+oBPNc2svXYdhcXNJ+oFPoi9qJHLnoUiHqotTzuVPXSG5iyXzFntvkAn3lFIAja52iwwwcJflEIXj/b39eG2dCsOTmmUJguut0FsLhCRSX0eylTSLgxTFGoQi7K/m18nafso=\""
}

```

```
{
  "accessUri": "/p/AlIlOEsMok7oE7YkN30KJUDjDKQjk493BKbuM-ANUNGdBBAHzHT_5lFlzYC9CQiA/n/{namespaceName}/b/{bucketName}/o/path/to/image.png",
  "id": "oHJQWGxpD+2PhDqtoewvLCf8/lYNlaIpbZHYx+mBryAad/q0LnFy37Me/quKhxEi:path/to/image.png",
  "name": "read-access-to-image.png",
  "accessType": "ObjectRead",
  "objectName": "path/to/image.png",
  "timeCreated": "2021-02-09T11:52:45.053Z",
  "timeExpires": "2021-03-01T00:00:00Z"
}
```

That's it!

Alternatives for providing credentials
--------------------------------------

[](#alternatives-for-providing-credentials)

### Constructor arguments

[](#constructor-arguments)

```
$signer = new Signer(
    $ociTenancyId,
    $ociUserId,
    $ociKeyFingerPrint,
    $privateKeyFilename
);
```

### Separate credentials class

[](#separate-credentials-class)

Implement `Hitrov\OCI\KeyProvider\KeyProviderInterface` methods

- `public function getPrivateKey(): string;` // must return a string (contents of privatekey.pem)
- `public function getKeyId(): string;` // must return a string like `"{OCI_TENANCY_ID}/{OCI_USER_ID}/{OCI_KEY_FINGERPRINT}"`

Force `Signer` to use it instead of constructor arguments and environment variables:

```
$keyProvider = new MockKeyProvider() // implements KeyProviderInterface;
$signer = new Signer();
$signer->setKeyProvider($keyProvider);
```

There's such an example covered in Unit tests `tests\Hitrov\Test\MockKeyProvider.php`

Manual generation steps
-----------------------

[](#manual-generation-steps)

There are more public methods exposed for all the stuff generated behind the scenes if you need it or just curious how it works:

```
$signingHeadersNames = $signer->getSigningHeadersNames('POST');
var_dump($signingHeadersNames);
```

```
array(6) {
  [0]=>
  string(4) "date"
  [1]=>
  string(16) "(request-target)"
  [2]=>
  string(4) "host"
  [3]=>
  string(14) "content-length"
  [4]=>
  string(12) "content-type"
  [5]=>
  string(16) "x-content-sha256"
}

```

```
// the value of `x-content-sha256` HTTP header
$bodyHashBase64 = $signer->getBodyHashBase64($body);
// X48E9qOokqqrvdts8nOJRJN3OWDUoyWxBf7kbu9DBPE=
```

```
$signingString = $signer->getSigningString($url, $method, $body, 'application/json');
```

```
date: Mon, 08 Feb 2021 20:51:33 GMT
(request-target): post /n/{namespaceName}/b/{bucketName}/p/
host: objectstorage.eu-frankfurt-1.oraclecloud.com
content-length: 76
content-type: application/json
x-content-sha256: X48E9qOokqqrvdts8nOJRJN3OWDUoyWxBf7kbu9DBPE=

```

```
// part of `authorization` HTTP header value
$signature = $signer->calculateSignature($signingString, $privateKeyString);
// LXWXDA8VmXXc1NRbMmXtW61IS97DfIOMAnlj+Gm+oBPNc2svXYdhcXNJ+oFPoi9qJHLnoUiHqotTzuVPXSG5iyXzFntvkAn3lFIAja52iwwwcJflEIXj/b39eG2dCsOTmmUJguut0FsLhCRSX0eylTSLgxTFGoQi7K/m18nafso=
```

```
// part of `authorization` HTTP header value
$keyId = $signer->getKeyId(); // "{OCI_TENANCY_ID}/{OCI_USER_ID}/{OCI_KEY_FINGERPRINT}"
// ocid1.tenancy.oc1..aaaaaaaaba3pv6wkcr4jqae5f15p2b2m2yt2j6rx32uzr4h25vqstifsfdsq/ocid1.user.oc1..aaaaaaaat5nvwcna5j6aqzjcaty5eqbb6qt2jvpkanghtgdaqedqw3rynjq/20:3b:97:13:55:1c:5b:0d:d3:37:d8:50:4e:c5:3a:34
```

Authorization header is being generated this way (version is always `1` for this signing procedure):

`Authorization: Signature version=\"1\",keyId=\"{KEY_ID}\",algorithm=\"rsa-sha256\",headers=\"{SIGNING_HEADERS_NAMES_STRING}\",signature=\"{SIGNATURE}\"`

```
$signingHeadersNamesString = implode(' ', $signingHeadersNames);
$authorizationHeader = $signer->getAuthorizationHeader($keyId, $signingHeadersNamesString, $signature);
// Authorization: Signature version=\"1\",keyId=\"ocid1.tenancy.oc1..aaaaaaaaba3pv6wkcr4jqae5f15p2b2m2yt2j6rx32uzr4h25vqstifsfdsq/ocid1.user.oc1..aaaaaaaat5nvwcna5j6aqzjcaty5eqbb6qt2jvpkanghtgdaqedqw3rynjq/20:3b:97:13:55:1c:5b:0d:d3:37:d8:50:4e:c5:3a:34\",algorithm=\"rsa-sha256\",headers=\"date (request-target) host content-length content-type x-content-sha256\",signature=\"LXWXDA8VmXXc1NRbMmXtW61IS97DfIOMAnlj+Gm+oBPNc2svXYdhcXNJ+oFPoi9qJHLnoUiHqotTzuVPXSG5iyXzFntvkAn3lFIAja52iwwwcJflEIXj/b39eG2dCsOTmmUJguut0FsLhCRSX0eylTSLgxTFGoQi7K/m18nafso=\"
```

Inspiration
-----------

[](#inspiration)

-
- [Official GoLang SDK http\_signer](https://github.com/oracle/oci-go-sdk/blob/master/common/http_signer.go)
- [Official GoLang SDK http\_signer\_test](https://github.com/oracle/oci-go-sdk/blob/master/common/http_signer_test.go)

###  Health Score

61

—

FairBetter than 98% of packages

Maintenance75

Regular maintenance activity

Popularity52

Moderate usage in the ecosystem

Community20

Small or concentrated contributor base

Maturity78

Established project with proven stability

 Bus Factor1

Top contributor holds 93.3% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~184 days

Recently: every ~307 days

Total

11

Last Release

128d ago

PHP version history (7 changes)1.0PHP ^7.4

1.1PHP ^7.4 || ^8.0

1.2.1PHP ^7.4 || ^8.0 || ^8.1

1.2.2PHP ^7.4 || ^8.0 || ^8.1 || ^8.2

1.2.3PHP ^7.4 || ^8.0 || ^8.1 || ^8.2 || ^8.3

v1.2.4PHP &gt;=7.4 &lt;8.5

v1.2.5PHP &gt;=7.4 &lt;9.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/46f27ad6c4dad7f027863eb49b2a89be6d1c606b0a6744231971c3284744071a?d=identicon)[hitrov](/maintainers/hitrov)

---

Top Contributors

[![hitrov](https://avatars.githubusercontent.com/u/26094610?v=4)](https://github.com/hitrov "hitrov (14 commits)")[![browner12](https://avatars.githubusercontent.com/u/5232313?v=4)](https://github.com/browner12 "browner12 (1 commits)")

---

Tags

ocioracle-cloudoracle-cloud-infrastructurephpsdk-phprequestapisignatureoci

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/hitrov-oci-api-php-request-sign/health.svg)

```
[![Health](https://phpackages.com/badges/hitrov-oci-api-php-request-sign/health.svg)](https://phpackages.com/packages/hitrov-oci-api-php-request-sign)
```

###  Alternatives

[agungsugiarto/codeigniter4-cors

Send CORS Headers in a CodeIgniter 4 application.

6525.8k2](/packages/agungsugiarto-codeigniter4-cors)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
