2017 © Pedro Peláez
 

library macaroons

image

mvieira/macaroons

  • Wednesday, September 20, 2017
  • by mickaelvieira
  • Repository
  • 1 Watchers
  • 0 Stars
  • 51 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 2 % Grown

The README.md

Macaroons

Software License Latest Stable Version Build Status Coverage Status, (*1)

A php implementation of Macaroons: Cookies with Contextual Caveats for Decentralized Authorization, (*2)

Specification - https://research.google.com/pubs/pub41892.html - https://github.com/rescrv/libmacaroons, (*3)

Resources - http://hackingdistributed.com/2014/05/21/my-first-macaroon/ - https://air.mozilla.org/macaroons-cookies-with-contextual-caveats-for-decentralized-authorization-in-the-cloud/ - https://evancordell.com/2015/09/27/macaroons-101-contextual-confinement.html, (*4)

Installation

Requirements - php >= 7.0 - libsodium-php >= 1.0, (*5)

About libsodium - The libsodium library will be distributed with PHP >= 7.2) - The libsodium library is not required in composer.json because the versions 1 (ext-libsodium) and 2 (ext-sodium) have different names. Nevertheless, this package should work with both once installed., (*6)

Installation, (*7)

Add the library as a requirement in your composer.json, (*8)

{
    "require": {
        "mvieira/macaroons": "dev-master"
    }
}

or with command line, (*9)

$ composer require mvieira/macaroons

Documentation

Here is a simple example with a third party macaroon:, (*10)

On the target service server, produce the macaroon authorizing the user to access the service., (*11)

use Macaroons\Macaroon;

use function Macaroons\Crypto\crypto_gen_nonce;

$macaroon = Macaroon::create('secret random number', crypto_gen_nonce(), 'https://unicorn.co');
$macaroon = $macaroon
    ->withThirdPartyCaveat('third party secret', 'user_auth', 'https://auth.unicorn.co');

On the identification provider server, produce the discharge macaroon that will verified the third party caveat, (*12)

use Macaroons\Macaroon;

// user login happens beforehand...
// once the user manages to log in to the service

// Deserialize the root macaroon
$macaroon  = Macaroon::deserialize('@#!?$');

// prepare the discharge macaroon that will satisfied the third party caveat
$discharge = Macaroon::create('third party secret', 'user_auth', 'https://auth.unicorn.co')
    ->withFirstPartyCaveat('user_id = 12345678'); // add the requested first party caveat

// bind the discharge macaroon to the root macaroon
$discharge = $macaroon->bind($discharge);

Back on the target service server, (*13)

use Macaroons\Macaroon;
use Macaroons\Verifier;
use Macaroons\Serialization\V1\Serializer;

// deserialize both macaroons
$macaroon  = Macaroon::deserialize('@#!?$', new Serializer());
$discharge = Macaroon::deserialize('#?@$!', new Serializer());

// prepare the verifier
$verifier = (new Verifier())
    ->satisfyExact('user_id = 12345678')
    ->withDischargeMacaroon($discharge);


try {
    $verified = $macaroon->verify('secret random number', $verifier);
} catch (\DomainException $e) {
    // Catch verification errors
    echo $e->getMessage() . "\n";
}

Examples

Examples are available in the directory ./examples/, (*14)

$ php ./examples/1-target-service.php
$ php ./examples/2-identity-provider.php
$ php ./examples/3-verification.php

Contributing

Please see CONTRIBUTING for details., (*15)

License

The MIT License (MIT). Please see LICENSE for more information., (*16)

The Versions

20/09 2017

0.0.2.x-dev

0.0.2.9999999-dev https://github.com/mickaelvieira/macaroons

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

authentication authorization cookie macaroon caveats decentralization

04/08 2017

dev-master

9999999-dev https://github.com/mickaelvieira/macaroons

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

authentication authorization cookie macaroon caveats decentralization

04/08 2017

v0.0.1

0.0.1.0 https://github.com/mickaelvieira/macaroons

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

authentication authorization cookie macaroon caveats decentralization