Akamai EdgeGrid Authentication for PHP
This library requires PHP 8+ and implements the Akamai EdgeGrid Authentication scheme for PHP.
To install, use composer
:
$ composer require akamai-open/edgegrid-auth
Download the PHAR file from the releases page and include it inside your code:
```php
include 'akamai-open-edgegrid-auth.phar';
// Library is ready to use
```
-
Either clone or download to pull down a copy of this repository.
- Clone the repository using git or subversion.
- Download the latest ZIP archive or specific release ZIP archive.
-
Use the composer autoloader and install the dependencies.
$ composer install
-
Include the autoloader.
require_once 'vendor/autoload.php';
If you don't use the autoloader, include all the required classes manually in your code.
require_once 'src/Authentication.php'; require_once 'src/Authentication/Timestamp.php'; require_once 'src/Authentication/Nonce.php'; require_once 'src/Authentication/Exception.php'; require_once 'src/Authentication/Exception/ConfigException.php'; require_once 'src/Authentication/Exception/SignerException.php'; require_once 'src/Authentication/Exception/SignerException/InvalidSignDataException.php';
Once you have installed the library, you can create the header value by calling the appropriate \Akamai\Open\Edgegrid\Authentication::set*()
methods.
For example, using it with the built-in streams HTTP client might look like the following:
$auth = \Akamai\Open\EdgeGrid\Authentication::createFromEdgeRcFile('default', '/.edgerc');
$auth->setHttpMethod('GET');
$auth->setPath('/identity-management/v3/user-profile');
$context = array(
'http' => array(
'header' => array(
'Authorization: ' . $auth->createAuthHeader(),
'Content-Type: application/json'
)
)
);
$context = stream_context_create($context);
$response = json_decode(file_get_contents('https://' . $auth->getHost() . $auth->getPath(), null, $context));
Copyright © 2022 Akamai Technologies, Inc. All rights reserved
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.