2017 © Pedro Peláez
 

library pop-auth

Pop Auth Component for Pop PHP Framework

image

popphp/pop-auth

Pop Auth Component for Pop PHP Framework

  • Monday, January 29, 2018
  • by nicksagona
  • Repository
  • 1 Watchers
  • 2 Stars
  • 1,140 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 15 Versions
  • 5 % Grown

The README.md

pop-auth

Build Status Coverage Status, (*1)

Join the chat at https://discord.gg/TZjgT74U7E, (*2)

Overview

pop-auth provides adapters to authenticate users via different authentication sources. The adapters share the same interface and are interchangeable. The available available adapters are:, (*3)

  • File
  • Database
  • HTTP
  • LDAP

pop-auth is a component of the Pop PHP Framework., (*4)

Install

Install pop-auth using Composer., (*5)

composer require popphp/pop-auth

Or, require it in your composer.json file, (*6)

"require": {
    "popphp/pop-auth" : "^4.0.2"
}

Top, (*7)

Quickstart

To verify an authentication attempt, create a new auth object pointed at its authentication source. From there, you can attempt to call the authenticate() with a username and password., (*8)

use Pop\Auth;

$auth = new Auth\File('/path/to/.htmyauth');

if ($auth->authenticate('admin', 'password')) {
    // User is authenticated
} else {
    // Handle failed authentication attempt
}

If you need to reference the same authentication attempt result at a later time in the application, you can call isAuthenticated():, (*9)

var_dump($auth->isAuthenticated()); // bool

Top, (*10)

Using a File

Using the file adapter, you would need to create we use a file containing a colon-delimited list of usernames and passwords or, preferably, password hashes:, (*11)

testuser1:PASSWORD_HASH1
testuser2:PASSWORD_HASH2
testuser3:PASSWORD_HASH3
use Pop\Auth;

$auth = new Auth\File('/path/to/.htmyauth');
$auth->authenticate('testuser1', 'password'); // Return int

if ($auth->isAuthenticated()) { } // Returns bool

Top, (*12)

Using a Database

Using the table adapter, you would need to create a table in a database that stores the users. There would need to be a correlating table class that extends Pop\Db\Record (for more on this, visit the pop-db component.), (*13)

For simplicity, the table class has been named MyApp\Table\Users and has a column called username and a column called password, but those column names can be changed., (*14)

use Pop\Auth;

$auth = new Auth\Table('MyApp\Table\Users');
$auth->authenticate('admin', 'password'); // int

if ($auth->isAuthenticated()) { } // bool

If the username/password fields are called something different in the table, that can be changed:, (*15)

use Pop\Auth;

$auth = new Auth\Table('MyApp\Table\Users');
$auth->setUsernameField('user_name')
    ->setPasswordField('password_hash');

$auth->authenticate('admin', 'password'); // int

if ($auth->isAuthenticated()) { } // bool

Top, (*16)

Using HTTP

Using the HTTP adapter, the user can send an authentication request over HTTP to a remote server. It will utilize the Pop\Http\Client and its supporting classes from the pop-http component. The following example will set the username and password as POST data in the payload., (*17)

use Pop\Auth\Http;
use Pop\Http\Client;

$auth = new Http(new Client('https://www.domain.com/auth', ['method' => 'post']));
$auth->authenticate('admin', 'password'); // Returns int

if ($auth->isAuthenticated()) { } // Returns bool

The following example will use a basic authorization header:, (*18)

use Pop\Auth\Http;
use Pop\Http\Client;
use Pop\Http\Auth;

$client = new Client(
    'https://www.domain.com/auth', ['method' => 'post'],
    Auth::createBasic('admin', 'password')
); 

$auth = new Http($client);
$auth->authenticate('admin', 'password'); // Returns int

if ($auth->isAuthenticated()) { } // Returns bool

The following example will use a bearer token authorization header:, (*19)

use Pop\Auth\Http;
use Pop\Http\Client;
use Pop\Http\Auth;

$client = new Client(
    'https://www.domain.com/auth', ['method' => 'post'],
    Auth::createBearer('AUTH_TOKEN')
);

$auth = new Http($client);
$auth->authenticate('admin', 'password');

if ($auth->isAuthenticated()) { } // Returns true

Like the Table adapter, if the username/password fields need to be set to something different to meet the requirements of the HTTP server, you can do that:, (*20)

use Pop\Auth\Http;
use Pop\Http\Client;

$auth = new Http(new Client('https://www.domain.com/auth', ['method' => 'post']));
$auth->setUsernameField('user_name')
    ->setPasswordField('password_hash');

$auth->authenticate('admin', 'password'); // Returns int

if ($auth->isAuthenticated()) { } // Returns bool

Top, (*21)

Using LDAP

Using the LDAP adapter, the user can send an authentication request using LDAP to a remote server. The user can set the port and other various options that may be necessary to communicate with the LDAP server., (*22)

use Pop\Auth;

$auth = new Auth\Ldap('ldap.domain', 389, [LDAP_OPT_PROTOCOL_VERSION => 3]);
$auth->authenticate('admin', 'password');

if ($auth->isAuthenticated()) { } // Returns true

Top, (*23)

Getting the User

Both the table and HTTP adapters have a method that allow you to get any possible user data that may have been returned. That method is getUser():, (*24)

use Pop\Auth;

$auth = new Auth\Table('MyApp\Table\Users');
$auth->authenticate('admin', 'password'); // int

if ($auth->isAuthenticated()) {
    $user = $auth->getUser();
}

This allows you access to the authenticated user's data without having to make an additional request., (*25)

Top, (*26)

The Versions

29/01 2018

v2.x-dev

2.9999999.9999999.9999999-dev http://www.popphp.org/

Pop Auth Component for Pop PHP Framework

  Sources   Download

BSD-3-Clause New BSD

The Requires

 

The Development Requires

authentication authorization php pop pop php

29/01 2018

dev-master

9999999-dev http://www.popphp.org/

Pop Auth Component for Pop PHP Framework

  Sources   Download

BSD-3-Clause New BSD

The Requires

 

The Development Requires

authentication authorization php pop pop php

29/01 2018

dev-v3-dev

dev-v3-dev http://www.popphp.org/

Pop Auth Component for Pop PHP Framework

  Sources   Download

BSD-3-Clause New BSD

The Requires

 

The Development Requires

authentication authorization php pop pop php

29/01 2018

3.0.5

3.0.5.0 http://www.popphp.org/

Pop Auth Component for Pop PHP Framework

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

authentication authorization php pop pop php

18/10 2017

3.0.4

3.0.4.0 http://www.popphp.org/

Pop Auth Component for Pop PHP Framework

  Sources   Download

New BSD

The Requires

 

The Development Requires

authentication authorization php pop pop php

17/10 2017

3.0.3

3.0.3.0 http://www.popphp.org/

Pop Auth Component for Pop PHP Framework

  Sources   Download

New BSD

The Requires

 

The Development Requires

authentication authorization php pop pop php

17/10 2017

3.0.2

3.0.2.0 http://www.popphp.org/

Pop Auth Component for Pop PHP Framework

  Sources   Download

New BSD

The Requires

 

The Development Requires

authentication authorization php pop pop php

18/05 2017

3.0.1

3.0.1.0 http://www.popphp.org/

Pop Auth Component for Pop PHP Framework

  Sources   Download

New BSD

The Requires

 

The Development Requires

authentication authorization php pop pop php

22/02 2017

3.0.0

3.0.0.0 http://www.popphp.org/

Pop Auth Component for Pop PHP Framework

  Sources   Download

New BSD

The Requires

 

The Development Requires

authentication authorization php pop pop php

03/10 2016

2.2.1

2.2.1.0 http://www.popphp.org/

Pop Auth Component for Pop PHP Framework

  Sources   Download

New BSD

The Requires

 

The Development Requires

authentication authorization php pop pop php

10/07 2016

2.2.0

2.2.0.0 http://www.popphp.org/

Pop Auth Component for Pop PHP Framework

  Sources   Download

New BSD

The Requires

 

The Development Requires

authentication authorization php pop pop php

01/07 2016

2.1.0

2.1.0.0 http://www.popphp.org/

Pop Auth Component for Pop PHP Framework

  Sources   Download

New BSD

The Requires

 

The Development Requires

authentication authorization php pop pop php

10/05 2016

2.0.0p2

2.0.0.0-patch2 http://www.popphp.org/

Pop Auth Component for Pop PHP Framework

  Sources   Download

New BSD

The Requires

 

The Development Requires

authentication authorization php pop pop php

19/02 2016

2.0.0p1

2.0.0.0-patch1 http://www.popphp.org/

Pop Auth Component for Pop PHP Framework

  Sources   Download

New BSD

The Requires

 

The Development Requires

authentication authorization php pop pop php

16/07 2015

2.0.0

2.0.0.0 http://www.popphp.org/

Pop Auth Component for Pop PHP Framework

  Sources   Download

New BSD

The Requires

 

The Development Requires

authentication authorization php pop pop php