Giter Site home page Giter Site logo

akamai / akamaiopen-edgegrid-php-client Goto Github PK

View Code? Open in Web Editor NEW
44.0 25.0 62.0 1.25 MB

PHP client library for Akamai {OPEN} EdgeGrid Authentication scheme (based on Guzzle)

Home Page: https://techdocs.akamai.com/home

License: Apache License 2.0

PHP 98.27% Shell 1.01% XSLT 0.71%
akamai php guzzle client edgegrid php-library middleware edgegrid-client open authentication

akamaiopen-edgegrid-php-client's Introduction

akamai-open/edgegrid-client

Akamai EdgeGrid Authentication for PHP

This library requires PHP 8+ and implements the Akamai EdgeGrid Authentication scheme on top of Guzzle as both a drop-in replacement client and middleware.

Installation

To install, use composer:

$ composer require akamai-open/edgegrid-client

Alternative installation method

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
```

Use

The Akamai\Open\EdgeGrid\Client extends \GuzzleHttp\Client as a drop-in replacement. It works transparently to sign API requests without changing other ways you use Guzzle.

To use the client, call \Akamai\Open\EdgeGrid\Client->setAuth() or provide an instance of \Akamai\Open\EdgeGrid\Authentication to the constructor prior to making a request to an API.

$client = new Akamai\Open\EdgeGrid\Client([
  'base_uri' => 'https://akab-h05tnam3wl42son7nktnlnnx-kbob3i3v.luna.akamaiapis.net'
]);

$client->setAuth($client_token, $client_secret, $access_token);

// use $client just as you would \Guzzle\Http\Client
$response = $client->get('/identity-management/v3/user-profile');

Authentication

To generate your credentials, see Create authentication credentials.

We recommend using a local .edgerc authentication file. Place your credentials under a heading of [default] at your local home directory or the home directory of a web-server user.

[default]
client_secret = C113nt53KR3TN6N90yVuAgICxIRwsObLi0E67/N8eRN=
host = akab-h05tnam3wl42son7nktnlnnx-kbob3i3v.luna.akamaiapis.net
access_token = akab-acc35t0k3nodujqunph3w7hzp7-gtm6ij
client_token = akab-c113ntt0k3n4qtari252bfxxbsl-yvsdj

You can call your .edgerc file one of two ways:

  • Use the factory method \Akamai\Open\EdgeGrid\Client::createFromEdgeRcFile().

    $client = \Akamai\Open\EdgeGrid\Client::createFromEdgeRcFile();
    
    // use $client just as you would \Guzzle\Http\Client
    $response = $client->get('/identity-management/v3/user-profile');
  • Specify a credentials section and/or .edgerc location:

    $client = \Akamai\Open\EdgeGrid\Client::createFromEdgeRcFile('example', '../config/.edgerc');
    
    // use $client just as you would \Guzzle\Http\Client
    $response = $client->get('/identity-management/v3/user-profile');

Command line interface

This library provides a command line interface (CLI) with a limited set of capabilities that mimic httpie.

Install

Install the CLI with composer vendor/bin/http or execute the PHAR file.

# Composer installed
$ ./vendor/bin/http --help

# For Windows
> php ./vendor/bin/http --help

# PHAR download
php akamai-open-edgegrid-client.phar --help

Arguments

You can set authentication and specify an HTTP method (case insensitive), its headers, and any JSON body fields.

Note: Our CLI shows all HTTP and body data. JSON is formated.

Argument Description
--auth-type={edgegrid,basic,digest} Set the authentication type. The default is none.
--auth user: or --a user: Set the .edgerc section to use. Unlike httpie-edgegrid, the colon (:) is optional.
Header-Name:value Headers and values are colon (:) separated.
jsonKey=value Sends {"jsonKey": "value"} in the POST or PUT body. This will also automatically set the Content-Type and Accept headers to application/json.
jsonKey:=[1,2,3] Allows you to specify raw JSON data, sending {"jsonKey": [1, 2, 3]} in the body.

Limitations

  • You cannot send multipart/mime (file upload) data.
  • Client certs are not supported.
  • Server certs cannot be verified.
  • Output cannot be customized.
  • Responses are not syntax highlighted.

Guzzle Middleware

This package provides three different middleware handlers you can add transparently when using the Client, to a standard \GuzzleHttp\Client or as a handler.

  • The \Akamai\Open\EdgeGrid\Handler\Authentication for transparent API request signing.
  • The \Akamai\Open\EdgeGrid\Handler\Verbose for output (or log) responses.
  • The \Akamai\Open\EdgeGrid\Handler\Debug for output (or log) errors.

Transparent Use

Handler Call
Authentication Client->setAuthentication() or pass in an instance of \Akamai\EdgeGrid\Authentication to Client->__construct().
Verbose Client->setInstanceVerbose() or Client::setVerbose() passing in on of `true
Debug Client->setInstanceDebug(), Client::setDebug(), or set the debug config option with `true

Middleware

Handler Example
Authentication
// Create the Authentication Handler
$auth = \Akamai\Open\EdgeGrid\Handler\Authentication::createFromEdgeRcFile();
// or:
$auth = new \Akamai\Open\EdgeGrid\Handler\Authentication;
$auth->setAuth($client_token, $client_secret, $access_token);
// Create the handler stack
$handlerStack = \GuzzleHttp\HandlerStack::create();
// Add the Auth handler to the stack
$handlerStack->push($auth);
// Add the handler to a regular \GuzzleHttp\Client
$guzzle = new \GuzzleHttp\Client([
"handler" => $handlerStack
]);
Verbose

// Create the handler stack
$handlerStack = HandlerStack::create();

// Add the Auth handler to the stack
$handlerStack->push(new \Akamai\Open\EdgeGrid\Handler\Verbose());

// Add the handler to a regular \GuzzleHttp\Client
$guzzle = new \GuzzleHttp\Client([
    "handler" => $handlerStack
]);
  </td>
</tr>
<tr>
  <td>Debug</td>
  <td>
// Create the handler stack
$handlerStack = HandlerStack::create();

// Add the Auth handler to the stack
$handlerStack->push(new \Akamai\Open\EdgeGrid\Handler\Debug());

// Add the handler to a regular \GuzzleHttp\Client
$guzzle = new \GuzzleHttp\Client([
    "handler" => $handlerStack
]);
  </td>
</tr>

License

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.

akamaiopen-edgegrid-php-client's People

Contributors

dshafik avatar dstopka avatar hokamoto avatar lkowalsk-akamai-com avatar mgwoj avatar siwinski avatar skearney-akamai avatar synedra avatar wzagrajcz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

akamaiopen-edgegrid-php-client's Issues

InvalidArgumentException: Middleware not found exception when creating client

I am building an integration module for Drupal 8. Instead of using an .edgrec file, I am managing configuration using Drupal's configuration API.

When I instantiate the client, I get this exception:

InvalidArgumentException: Middleware not found: history in /Users/cameron.tod/Sites/drupal/vendor/guzzlehttp/guzzle/src/HandlerStack.php on line 220

Here's the code I use to create the client: https://github.com/cam8001/akamai/blob/16/integrate-akamai-library/src/AkamaiClient.php#L44

And here's the line that trips the Exception:

https://github.com/akamai-open/AkamaiOPEN-edgegrid-php/blob/master/src/Client.php#L445

I dont think I'm doing anything wrong. Is this a bug? Is it likely to cause issues down the line?

Release 0.3.0

To Do

  • Merge #5
  • Update examples (akamai-open/api-kickstart#21)
  • Update Docs
  • Tag release
  • Create PHAR
  • Finalize release on github (also updates packagist)

Bin script rename?

Would you be open to renaming the bin script from http to something like akamai-open-edgegrid or akamai-edgegrid? I would like to package this project for Fedora but bin script http is too generic to provide at the system level so I will need to rename it when packaging it downstream anyway. I was just wondering if you would be interested in a pull request with a bin script rename as well?

Please change default timeout

There is no timeout in the .edgerc, and the default SLA for our APIs is 300 seconds. Please increase the default timeout appropriately.

This is very important, as I'm getting Travis set up to run our code.

Thanks,
Kirsten

Change SSL Curl options

Hi!
I'm working with Akamai, but I have a SSL issue with the requests. Normally when doing cURL requests I need to set CURLOPT_SSL_VERIFYPEER to false. My code looks like this:

$client = new Akamai\Open\EdgeGrid\Client([     
        'base_uri' => "https://".$host
    ]);
    $client->setAuth($client_token, $client_secret, $access_token);
    $response = $client->get($options);

And I get the following error message:
Fatal error: Uncaught exception 'GuzzleHttp\Exception\RequestException' with message 'cURL error 60: SSL certificate problem: unable to get local issuer certificate (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)' in phar://....../akamai-open-edgegrid-client-0.4.3.phar/vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php:187

I noticed that this comes from CurlFactory from your Guzzle library, so I checked the project and saw the possibility to do something like this:

$res = $this->client->request('GET', 'https://host', [ 'curl' => [ CURLOPT_SSL_VERIFYPEER => false ], ]);

Is setting CURL options like this possible to do with Akamai-Open?
Or how can I go around this?

Thank you very much for your help! :)

Kind regards,
Juan

Will this Library receive any Update again?

We are not able to use this Library since years due to various completely outdated Dependencies and Requirements, so we have to deal with some Tricks in Composer and/or Forks. Nevertheless, we do need some APIs from Akamai, but we are thinking now it would make more sense to just write our own Code for this.

It looks a little sad, that Akamai cannot support this small Library with even one Update in four Years though, so I would like to ask - is there any chance you are updating this Library, so we can use it with PHP8+, Monolog 2+, Guzzle7+ etc again?

Thanks!

Inquiry - support of TLS 1.2

Just a question - will the PHP client currently support connections via TLS 1.2 out of the box? Thanks very much for your response.

Minor bug in the readme file.

In the Middleware > Authentication Handler section there is an example with a reference to HandlerStack:

// Create the handler stack
$handlerStack = HandlerStack::create();

This should either reference a namespace import on top, or have a full path to the class name, eg:

// Create the handler stack
$handlerStack =  \GuzzleHttp\HandlerStack::create();

[PLAN] Release 0.4.0

This ticket outlines the plan for release 0.4.0

  • Move away from using \Exception to more appropriate, and package specific exceptions (See #13)
  • Add support for PSR-7 requests (e.g. ->send() and ->sendAsync())
  • Add CLI interface to PHAR release file (See #8)
  • Use a custom User-Agent (See #10)

Other Changes

  • Fix issue with string query args (See #12)
  • Show request body when using the verbose handler (See #11)

I wish the composer package supported psr/log 3.0 or higher

  Problem 1
    - Root composer.json requires akamai-open/edgegrid-client 2.0.0 -> satisfiable by akamai-open/edgegrid-client[2.0.0].
    - akamai-open/edgegrid-client 2.0.0 requires psr/log ^1.0 -> found psr/log[1.0.0, ..., 1.1.4] but it conflicts with your root composer.json require (3.0.0).

Many packages these days use psr/log 3.0, but the current package cannot be used because it does not support psr/log 3.0.

Compatibility with guzzlehttp/guzzle 7.X

My project uses Guzzle 7.2. So I got this error.

$ composer require akamai-open/edgegrid-client
Using version ^1.0 for akamai-open/edgegrid-client
./composer.json has been updated
Running composer update akamai-open/edgegrid-client
Loading composer repositories with package information
Updating dependencies
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Root composer.json requires akamai-open/edgegrid-client ^1.0 -> satisfiable by akamai-open/edgegrid-client[1.0.0].
    - akamai-open/edgegrid-client 1.0.0 requires guzzlehttp/guzzle ^6.1.1 -> found guzzlehttp/guzzle[6.1.1, ..., 6.5.5] but the package is fixed to 7.2.0 (lock file version) by a partial update and that version does not match. Make sure you list it as an argument for the update command.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.