2017 © Pedro PelĂĄez
 

library guardian

Simple and flexible authentication framework

image

indigophp/guardian

Simple and flexible authentication framework

  • Monday, April 20, 2015
  • by mark.sagikazar
  • Repository
  • 0 Watchers
  • 0 Stars
  • 139 Installations
  • 4 Dependents
  • 1 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Guardian

Latest Version Software License Build Status Code Coverage Quality Score HHVM Status Total Downloads, (*1)

Simple and flexible authentication framework., (*2)

Install

Via Composer, (*3)

``` bash $ composer require indigophp/guardian, (*4)


## Usage This library provides an easy way to authenticate any entity with OR without persisting and calling it "login". A simple login example: ``` php use Indigo\Guardian\Identifier\InMemory; use Indigo\Guardian\Authenticator\UserPassword; use Indigo\Guardian\Hasher\Plaintext; use Indigo\Guardian\SessionAuth; use Indigo\Guardian\Session\Native; $identifier = new InMemory([ 1 => [ 'username' => 'john.doe', 'password' => 'secret', 'name' => 'John Doe', ], ]); $authenticator = new UserPassword(new Plaintext); $session = new Native; $auth = new SessionAuth($identifier, $authenticator, $session); // returns true to indicate success $auth->login([ 'username' => 'john.doe', 'password' => 'secret', ]);

Later, when login succeeds, check for the current login:, (*5)

``` php // returns true/false $auth->check();, (*6)

// returns the current caller $caller = $auth->getCurrentCaller();, (*7)


And logout at the end: ``` php // returns true/false $auth->logout();

API Authentication

Since Guardian is an authentication library, you can easily use it to authenticate API requests without persistence. To achieve this, see the following simple authentication service:, (*8)

``` php use Indigo\Guardian\Identifier\InMemory; use Indigo\Guardian\Authenticator\UserPassword; use Indigo\Guardian\Hasher\Plaintext; use Indigo\Guardian\RequestAuth;, (*9)

$identifier = new InMemory([ 1 => [ 'username' => 'john.doe', 'password' => 'secret', 'name' => 'John Doe', ], ]);, (*10)

$authenticator = new UserPassword(new Plaintext);, (*11)

$auth = new RequestAuth($identifier, $authenticator);, (*12)

$subject = [ 'username' => 'john.doe', 'password' => 'secret', ];, (*13)

// returns true to indicate success $auth->authenticate($subject);, (*14)

// returns the caller object if identify succeeds $caller = $auth->authenticateAndReturn($subject);, (*15)



## Testing ``` bash $ phpspec run

Contributing

Please see CONTRIBUTING for details., (*16)

Credits

License

The MIT License (MIT). Please see License File for more information., (*17)

The Versions

20/04 2015

dev-master

9999999-dev https://indigophp.com

Simple and flexible authentication framework

  Sources   Download

MIT

The Requires

 

The Development Requires

by MĂĄrk SĂĄgi-KazĂĄr

authentication