All Projects → akamai → AkamaiOPEN-edgegrid-php-client

akamai / AkamaiOPEN-edgegrid-php-client

Licence: Apache-2.0 License
PHP client library for Akamai {OPEN} EdgeGrid Authentication scheme (based on Guzzle)

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to AkamaiOPEN-edgegrid-php-client

Guzzle Cache Middleware
A HTTP Cache for Guzzle 6. It's a simple Middleware to be added in the HandlerStack.
Stars: ✭ 325 (+755.26%)
Mutual labels:  middleware, guzzle
AkamaiOPEN-edgegrid-C-Sharp
No description or website provided.
Stars: ✭ 13 (-65.79%)
Mutual labels:  open, akamai
Guzzle retry middleware
Middleware for Guzzle v6+ that automatically retries HTTP requests on 429, 503 responses.
Stars: ✭ 90 (+136.84%)
Mutual labels:  middleware, guzzle
AkamaiOPEN-edgegrid-java
Java library for Akamai OPEN EdgeGrid Client Authentication
Stars: ✭ 37 (-2.63%)
Mutual labels:  open, akamai
Guzzle Advanced Throttle
A Guzzle middleware that can throttle requests according to (multiple) defined rules. It is also possible to define a caching strategy, e.g. get the response from cache when the rate limit is exceeded or always get a cached value to spare your rate limits. Using wildcards in host names is also supported.
Stars: ✭ 120 (+215.79%)
Mutual labels:  middleware, guzzle
AkamaiOPEN-edgegrid-ruby
This library implements the Akamai OPEN EdgeGrid Authentication scheme for the ruby net/http library.
Stars: ✭ 19 (-50%)
Mutual labels:  open, akamai
node-uploadx
Node.js middleware for handling resumable uploads
Stars: ✭ 17 (-55.26%)
Mutual labels:  middleware
think-trace
Error trace for ThinkJS 3.x
Stars: ✭ 12 (-68.42%)
Mutual labels:  middleware
falcon-policy
Policy Middleware for Falcon APIs
Stars: ✭ 30 (-21.05%)
Mutual labels:  middleware
idoc
📒📚Generate beautiful interactive documentation and Open-API 3.0 spec file from your existing Laravel app.
Stars: ✭ 95 (+150%)
Mutual labels:  open
throttle
Throttling Middleware for Martini
Stars: ✭ 63 (+65.79%)
Mutual labels:  middleware
ReSwiftMonitor
ReSwift+redeux dev tools
Stars: ✭ 13 (-65.79%)
Mutual labels:  middleware
http-authentication
PSR-15 middleware to implement Basic and Digest Http authentication
Stars: ✭ 29 (-23.68%)
Mutual labels:  middleware
esi-test-server-docker
A dockerized version of Akamai's Edge Side Includes Test Server (ETS).
Stars: ✭ 30 (-21.05%)
Mutual labels:  akamai
react-redux-api-tools
A set of tools to facilitate react-redux development and decouple logic from compontents
Stars: ✭ 37 (-2.63%)
Mutual labels:  middleware
koa-rest-router
Most powerful, flexible and composable router for building enterprise RESTful APIs easily!
Stars: ✭ 67 (+76.32%)
Mutual labels:  middleware
polix
🚀 Node.js Web Framework
Stars: ✭ 32 (-15.79%)
Mutual labels:  middleware
fjage
Framework for Java and Groovy Agents
Stars: ✭ 19 (-50%)
Mutual labels:  middleware
geggleto-acl
PSR-7 Zend ACL implementation - Permission Library [ slim, psr7, acl, permissions, zend ]
Stars: ✭ 33 (-13.16%)
Mutual labels:  middleware
redux-tools
Redux tools to speed up development.
Stars: ✭ 16 (-57.89%)
Mutual labels:  middleware

akamai-open/edgegrid-client

License Build Status Code Coverage API Docs

Akamai {OPEN} EdgeGrid Authentication Client for PHP

Note: in version 0.6.0 the \Akamai\Open\EdgeGrid\Authentication library itself has been moved to a seperate akamai-open/edgegrid-auth package.

This library implements the Akamai {OPEN} EdgeGrid Authentication scheme on top of Guzzle, as both a drop-in replacement client, and middleware.

For more information visit the Akamai {OPEN} Developer Community.

Installation

This library requires PHP 5.5+, or HHVM 3.5+ to be used with the built-in Guzzle HTTP client.

To install, use composer:

$ composer require akamai-open/edgegrid-client

Alternative (single file) Install

Alternatively, download the PHAR file from the releases page.

To use it, you just include it inside your code:

include 'akamai-open-edgegrid-client.phar';

// Library is ready to use

Client Usage

The Akamai\Open\EdgeGrid\Client extends \GuzzleHttp\Client and transparently enables you to sign API requests, without interfering with other usage - this makes it a drop-in replacement, with the exception that you must 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://akaa-baseurl-xxxxxxxxxxx-xxxxxxxxxxxxx.luna.akamaiapis.net'
]);

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

// use $client just as you would \Guzzle\Http\Client
$response = $client->get('/billing-usage/v1/products');

Using a Credentials File

We recommend using a .edgerc credentials file. Credentials can be generated using information on the developer site at: https://developer.akamai.com/introduction/Prov_Creds.html

Your .edgerc should look something like this:

[default]
client_secret = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=
host = xxxxx.luna.akamaiapis.net/
access_token = xxxxx
client_token = xxxxx

To utilize this use the factory method \Akamai\Open\EdgeGrid\Client::createFromEdgeRcFile().

To create a client using the default credentials, in an .edgerc file that exists inside the HOME directory of the web server user, or in the current working directory:

$client = \Akamai\Open\EdgeGrid\Client::createFromEdgeRcFile();

// use $client just as you would \Guzzle\Http\Client
$response = $client->get('/billing-usage/v1/products');

Or, 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('/billing-usage/v1/products');

Command Line Interface

To aid in testing, exploration, and debugging, this library features a CLI that mimics httpie and provides a limited facsimile of it's capabilities as documented here.

If you install via composer, the CLI tool is available as vendor/bin/http, or you can simply 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

Arguments are similar to httpie:

  • --auth-type={edgegrid,basic,digest} — Set the authentication type (default: none)
  • --auth user: or --a user: — Set the .edgerc section to use. Unlike httpie-edgegrid the : is optional

You can also specify an HTTP method (HEAD|GET|POST|PUT|DELETE - case-insensitive).

Finally, you can easily specify headers and JSON body fields, using the following syntaxes:

  • Header-Name:value — Headers and values are : 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, all HTTP and body data (request and response) is shown
  • Responses are not syntax highlighted (although JSON is formatted)

Guzzle Middleware

This package provides three different middleware handlers:

  • \Akamai\Open\EdgeGrid\Handler\Authentication - provides transparent API request signing
  • \Akamai\Open\EdgeGrid\Handler\Verbose - easily output (or log) responses
  • \Akamai\Open\EdgeGrid\Handler\Debug - easily output (or log) errors

All three can be added transparently when using the Client, or added to a standard \GuzzleHttp\Client, or by adding them as a handler.

Transparent Usage

To enable Authentication call Client->setAuthentication(), or pass in an instance of \Akamai\EdgeGrid\Authentication to Client->__construct().

To enable Verbose call Client->setInstanceVerbose() or Client::setVerbose() passing in on of true|resource|[resource output, resource error]. Defaults to [STDOUT, STDERR]`.

To enable Debug call Client->setInstanceDebug(), Client::setDebug(), or set the debug config option with true|resource. Defaults to STDERR.

Middleware

Authentication Handler

// 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 Handler

// 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
]);

Debug Handler

// 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
]);

Using PHP 5.3 (not recommended)

PHP 5.3 has been EOL since August 14th, 2014, and has known security vulnerabilities, therefore we do not recommend using it. However, we understand that many actively supported LTS distributions are still shipping with PHP 5.3, and therefore we are providing the following information.

The signer itself is PHP 5.3 compatible and has been moved to the akamai-open/edgegrid-auth package.

Author

Davey Shafik [email protected]

License

Copyright 2016 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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].