-
Notifications
You must be signed in to change notification settings - Fork 14
/
index.php
87 lines (68 loc) · 2.32 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
require 'vendor/autoload.php';
use Hitrov\OCI\Signer;
use Hitrov\Test\MockKeyFileProvider;
use Hitrov\Test\MockKeyProvider;
$filename = implode(DIRECTORY_SEPARATOR, ['tests', 'resources', 'privatekey.pem']);
$signer = new Signer(
MockKeyProvider::OCI_TENANCY_ID,
MockKeyProvider::OCI_USER_ID,
MockKeyProvider::OCI_KEY_FINGERPRINT,
$filename
);
// Alternatively:
//$signer = new Signer();
//$keyProvider = new MockKeyFileProvider(); // or
//$keyProvider = new MockKeyProvider();
//$signer->setKeyProvider($keyProvider);
$namespaceName = 'frepgpx8ftrx';
$bucketName = 'test20210130';
$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);
$bodyHashBase64 = $signer->getBodyHashBase64($body);
var_dump($bodyHashBase64);
$signingHeadersNames = $signer->getSigningHeadersNames('POST');
var_dump($signingHeadersNames);
$signingString = $signer->getSigningString($url, $method, $body, 'application/json');
var_dump($signingString);
$signature = $signer->calculateSignature($signingString, MockKeyProvider::OCI_PRIVATE_KEY);
var_dump($signature);
$keyId = $signer->getKeyId();
var_dump($keyId);
$authorizationHeader = $signer->getAuthorizationHeader($keyId, implode(' ', $signingHeadersNames), $signature);
var_dump($authorizationHeader);
// real request example.
// 1. provide credentials to Signer
$signer = new Signer;
// 2. adjust path to file (objectName) in body JSON above
// 3. comment `die;` below
die;
$curl = curl_init();
$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) {
$curlOptions[CURLOPT_POSTFIELDS] = $body;
}
curl_setopt_array($curl, $curlOptions);
$response = curl_exec($curl);
echo $response;
curl_close($curl);