Download the PHP package gomes81/guzzlehttp-cookie-auth-subscriber without Composer

On this page you can find all versions of the php package gomes81/guzzlehttp-cookie-auth-subscriber. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package guzzlehttp-cookie-auth-subscriber


Guzzle CookieAuth Subscriber

Signs HTTP requests using cookies. Requests are signed using a login form, containing a username and password (and / or any other fields you wish to include). The credentials are then send to the provided url using the specified HTTP method (usually POST) and the returned cookies are saved for later use.

This version only works with Guzzle 6.0 and up!

Installing

This project can be installed using Composer. Add the following to your composer.json:

{
    "require": {
        "gomes81/guzzlehttp-cookie-auth-subscriber": "0.1.*"
    }
}


Using the Subscriber

Here's an example showing how to send an authenticated request:

use GuzzleHttp\Client;
use GuzzleHttp\HandlerStack;
use Gomes81\GuzzleHttp\Subscriber\CookieAuth;

$stack = HandlerStack::create();

$middleware = new CookieAuth(
    '/login_simple_url_or_path',
    [
        'username'    => 'my_username',
        'password'    => 'my_password',
        'other_field' => 'my_field_value'
    ],
    'POST',// GET, POST or JSON (will JSON encode fields array and send it inside the POST request body)
    'you can also pass a cookie string to use in here');
$stack->push($middleware);

$client = new Client([
    'base_uri' => 'http://simple_url.com',
    'handler'  => $stack
]);

// Set the "auth" request option to "cookie" to sign the request using a cookie
// Before calling the given url the subscriber will check if there's a valid cookie
// to be injected in the current request, if a valid cookie could not be found an
// additional request is made to obtain it
$res = $client->get('statuses/home_timeline.json', ['auth' => 'cookie']);

You can set the auth request option to cookie for all requests sent by the client by extending the array you feed to new Client with auth => cookie.

use GuzzleHttp\Client;
use GuzzleHttp\HandlerStack;
use Gomes81\GuzzleHttp\Subscriber\CookieAuth;

$stack = HandlerStack::create();

$middleware = new CookieAuth(
    '/login_simple_url_or_path', [
        'username'    => 'my_username',
        'password'    => 'my_password',
        'other_field' => 'my_field_value'],
    'POST',// GET, POST or JSON (will JSON encode fields array and send it inside the POST request body)
    'you can also pass a cookie string to use in here');
$stack->push($middleware);

$client = new Client([
    'base_uri' => 'http://simple_url.com',
    'handler'  => $stack,
    'auth'     => 'cookie'
]);

// Now you don't need to add the auth parameter
$res = $client->get('statuses/home_timeline.json');

You can also save cookies to a file by passing a FileCookieJar object instance in the forth parameter.

use GuzzleHttp\Client;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Cookie\FileCookieJar;
use Gomes81\GuzzleHttp\Subscriber\CookieAuth;

$stack = HandlerStack::create();

$middleware = new CookieAuth(
    '/login_simple_url_or_path', [
        'username'    => 'my_username',
        'password'    => 'my_password',
        'other_field' => 'my_field_value'],
    'POST',// GET, POST or JSON (will JSON encode fields array and send it inside the POST request body)
    new FileCookieJar('./cookies_folder/cookie_file_name', true));
$stack->push($middleware);

All versions of guzzlehttp-cookie-auth-subscriber with dependencies

PHP Build Version
Package Version
Requires php Version >=5.5.0
guzzlehttp/guzzle Version ~6.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package gomes81/guzzlehttp-cookie-auth-subscriber contains the following files

Loading the files please wait ....