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.

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 pop-auth

pop-auth

Build Status Coverage Status

Join the chat at https://discord.gg/TZjgT74U7E

Overview

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

pop-auth is a component of the Pop PHP Framework.

Database-backed authentication (matching a username/password against a Pop\Db\Record-backed table) has moved to the pop-db component, in favor of a tighter coupling with the DB layer it depends on. See pop-db's documentation for the replacement.

Remote/delegated authentication (forwarding credentials to a remote HTTP endpoint and checking the response) is no longer a dedicated adapter here — use pop-http's Client and Auth classes directly.

Install

Install pop-auth using Composer.

composer require popphp/pop-auth

Or, require it in your composer.json file

"require": {
    "popphp/pop-auth" : "^5.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

Handling Exceptions

authenticate() returning 0 means the credentials were checked and didn't match — that's a normal, expected outcome, not an error. It can also throw Pop\Auth\Exception, but only when the adapter can't perform the check at all: a missing or unreadable file, or malformed/unusable key material for the JWT adapter. Wrap authenticate() in a try/catch to handle both cases:

Top

Using a File

Using the file adapter, you need to create a file containing a colon-delimited list of usernames and passwords or, preferably, password hashes:

The file adapter also supports realm-scoped entries and a custom field delimiter. When a realm is set, matching lines must have 3 fields (username:realm:hash) with both the username and the realm matching:

A different delimiter can be set as the third constructor argument, e.g. new Auth\File('/path/to/.htmyauth', 'example.com', '|') for pipe-delimited entries.

Top

Using a JWT

Using the JWT adapter, you authenticate a bearer token by verifying its signature and claims — there's no network call and no stored username/password, just the token itself and the key material to check it against.

The algorithm is fixed at construction and is never read from the token — pass the shared secret for HS256, or a PEM-encoded public key for RS256/ES256:

exp and nbf claims, when present on the token, are always checked (with an optional leeway, in seconds, to absorb clock skew between issuer and verifier). aud and iss are opt-in — only checked if you configure them:

Top

Getting the User

The JWT adapter has a method that allows you to get the decoded claims from a successfully verified token. That method is getUser():

This allows you access to the token's claims without decoding it yourself.

Top

Rehashing Passwords

After a successful authentication, you can check whether the stored hash should be upgraded (e.g. it was stored as plaintext, or was hashed at a now-outdated cost):

This is only meaningful for the File adapter, since it's the one that compares a submitted password against a stored hash. The JWT adapter verifies a signature instead of a hash — needsRehash() is always false on it.

Top


All versions of pop-auth with dependencies

PHP Build Version
Package Version
Requires php Version >=8.4.0
popphp/pop-crypt Version ^4.0.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 popphp/pop-auth contains the following files

Loading the files please wait ...