Download the PHP package popphp/pop-auth without Composer
On this page you can find all versions of the php package popphp/pop-auth. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download popphp/pop-auth
More information about popphp/pop-auth
Files in popphp/pop-auth
Package pop-auth
Short Description Pop Auth Component for Pop PHP Framework
License BSD-3-Clause
Homepage http://www.popphp.org/
Informations about the package pop-auth
pop-auth
- Overview
- Install
- Quickstart
- Using a File
- Using a Database
- Using HTTP
- Using LDAP
- Getting the User
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:
- File
- Database
- HTTP
- LDAP
pop-auth
is a component of the Pop PHP Framework.
Install
Install pop-auth
using Composer.
composer require popphp/pop-auth
Or, require it in your composer.json file
"require": {
"popphp/pop-auth" : "^4.0.0"
}
Top
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.
If you need to reference the same authentication attempt result at a later time in the application,
you can call isAuthenticated()
:
Top
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:
Top
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.)
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.
If the username/password fields are called something different in the table, that can be changed:
Top
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.
The following example will use a basic authorization header:
The following example will use a bearer token authorization header:
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:
Top
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.
Top
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()
:
This allows you access to the authenticated user's data without having to make an additional request.
Top