PHPackages                             hunomina/http-auth-router-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. hunomina/http-auth-router-php

ActiveLibrary[HTTP &amp; Networking](/categories/http)

hunomina/http-auth-router-php
=============================

Http Auth Router for PHP 7.1 or higher

1.2.0(6y ago)085proprietaryPHPPHP ^7.1CI failing

Since Mar 7Pushed 6y ago1 watchersCompare

[ Source](https://github.com/hunomina/http-auth-router-php)[ Packagist](https://packagist.org/packages/hunomina/http-auth-router-php)[ RSS](/packages/hunomina-http-auth-router-php/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependencies (2)Versions (9)Used By (0)

Http Authentication Router PHP
==============================

[](#http-authentication-router-php)

[![Build Status](https://camo.githubusercontent.com/af0b0f88696327e96fe2ad61b294af1ab686c591b566e6c084f9f47405891904/68747470733a2f2f7472617669732d63692e636f6d2f68756e6f6d696e612f687474702d617574682d726f757465722d7068702e7376673f6272616e63683d6d6173746572)](https://travis-ci.com/hunomina/http-auth-router-php)[![codecov](https://camo.githubusercontent.com/3510dc9358a1742f708470253c89761d0004df73d27c404e911dfc962e53d871/68747470733a2f2f636f6465636f762e696f2f67682f68756e6f6d696e612f687474702d617574682d726f757465722d7068702f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/hunomina/http-auth-router-php)

Description : Implementation of Http Router classes for PHP7.1 or higher with authentication.

This library is mainly composed of 8 classes.

### AuthRouter

[](#authrouter)

The *[AuthRouter](https://github.com/hunomina/http-auth-router-php/blob/master/src/AuthRouter.php)* class extends from the *hunomina\\Routing\\Router* class.

Therefore it can handle request by calling the *request(string $method, string $url)* method which must return a route action response.

> Read [this documentation](https://github.com/hunomina/http-router-php/blob/master/README.md) in order to understand how the base routing system works.

This class can be instantiated by passing a route file, an *[AuthenticationCheckerInterface](https://github.com/hunomina/http-auth-router-php/blob/master/src/Firewall/Checker/AuthenticationCheckerInterface.php)* instance and a type (json, yaml... extend if you want to add new ones).

The route file syntax is identical to the *[hunomina\\Routing\\Router](https://github.com/hunomina/http-router-php/blob/master/src/Routing/Router.php)* route file syntax.

> Examples [here](https://github.com/hunomina/http-auth-router-php/tree/master/tests/conf).

### AuthenticationCheckerInterface

[](#authenticationcheckerinterface)

The *[AuthenticationCheckerInterface](https://github.com/hunomina/http-auth-router-php/blob/master/src/Firewall/Checker/AuthenticationCheckerInterface.php)* has three methods :

- *bool* isAuthenticated() : Returns true if an user is connected to your application. You can whatever you want : cookies, sessions, headers...
- *?UserInterface* getAuthenticatedUser() : Returns the authenticated user for session, cookie, headers...
- *bool* checkAuthorization(*?UserInterface* $user, *SecurityContext* $securityContext, *string* $method, *string* $url) : Returns true if a specific user can access to a route (method + url) based on a security context

In order for the AuthRouter to work with your application, you have to create a class that implements the *[AuthenticationCheckerInterface](https://github.com/hunomina/http-auth-router-php/blob/master/src/Firewall/Checker/AuthenticationCheckerInterface.php)* interface and her methods.

You absolutely can add some methods if needed.

### UserInterface

[](#userinterface)

The *[UserInterface](https://github.com/hunomina/http-auth-router-php/blob/master/src/UserInterface.php)* must be implemented by all user entities that will log into your application.

This interface has two methods :

- *string\[\]* getRoles() : Returns a string list of all the user's security context roles
- *string* getUsername() : Returns the username used to authenticate the user

### SecurityContext

[](#securitycontext)

Allow to define role based rules for specific routes.

This class loads the security context from a configuration file, check his validity and instantiate multiple *[Role](https://github.com/hunomina/http-auth-router-php/blob/master/src/Firewall/SecurityContext/Role.php)* and *[Rule](https://github.com/hunomina/http-auth-router-php/blob/master/src/Firewall/SecurityContext/Rule.php)* objects according to the configuration file.

You can then use the security context object in your AuthenticationChecker application instance to check users rights.

This class is abstract and has two methods that you have to implement :

- *void* load(): Once the configuration file has been validated, loads it and instantiates *[Role](https://github.com/hunomina/http-auth-router-php/blob/master/src/Firewall/SecurityContext/Role.php)* and *[Rule](https://github.com/hunomina/http-auth-router-php/blob/master/src/Firewall/SecurityContext/Rule.php)* object to feet the configuration
- *bool* isSecurityContextValid() : Returns true if the configuration file syntax is valid

This package comes with two built-in SecurityContext implementation :

- *[YamlSecurityContext](https://github.com/hunomina/http-auth-router-php/blob/master/src/Firewall/SecurityContext/YamlSecurityContext.php)*
- *[JsonSecurityContext](https://github.com/hunomina/http-auth-router-php/blob/master/src/Firewall/SecurityContext/JsonSecurityContext.php)*

If you want to add a new SecurityConext type, you'll have to create two classes :

- A class extending the AuthRouter class in order to be able to use the new SecurityContext type
- A class extending the SecurityContext class in order to create a new configuration file parser

### Role

[](#role)

A *[Role](https://github.com/hunomina/http-auth-router-php/blob/master/src/Firewall/SecurityContext/Role.php)* is just a name with child roles.

This class has two properties :

- *string* $\_name : The name of the role
- *Role\[\]* $\_children : A list of child roles. Allow to define a role hierarchy

And one method :

- *bool* contains(*Role* $role) : Returns true if the Role instance is $role or has $role as a child

### Rule

[](#rule)

A *[Rule](https://github.com/hunomina/http-auth-router-php/blob/master/src/Firewall/SecurityContext/Rule.php)* has 3 properties :

- *string* $\_path : Pseudo regular expression matching the urls the rule must apply to. "Pseudo regular expression" means that it's a regular expression without "/" escaped
- *string\[\]* $\_methods : List of http methods. Restrict the http methods on which the rule can match
- *Role\[\]* $\_roles : List of Role who can access to the $\_path with the $methods http methods

Those three properties are passed to the constructor. Make sure all of them are valid (e.g. valid pseudo regular expression for $\_path property)

### YamlSecurityContext

[](#yamlsecuritycontext)

The *[YamlSecurityContext](https://github.com/hunomina/http-auth-router-php/blob/master/src/Firewall/SecurityContext/YamlSecurityContext.php)* is a built-in *[SecurityContext](https://github.com/hunomina/http-auth-router-php/blob/master/src/Firewall/SecurityContext/SecurityContext.php)* implementation.

It allow you to use Yaml configuration file for your application AuthRouter SecurityContext. If you use this SecurityContext class you must follow this simple configuration file syntax :

- Have a root element `security`.
- Have two children element : `auth_firewall` and `role_hierarchy`.
- `auth_firewall` contains the list of all the application firewall rules.
- `role_hierarchy` contains the list of all the application roles and their hierarchy.

Each rule is composed of :

- `path` : Pseudo regular expression for the *[Rule](https://github.com/hunomina/http-auth-router-php/blob/master/src/Firewall/SecurityContext/Rule.php)* object.
- `roles` : A string or a string list of the roles the rule uses. If empty, nothing can validate the rule.
- `methods` : An optional list of http methods to use to match the rule

Each role is composed of :

- A key : The role name
- A value : A string or a string list of child roles

> Example [here](https://github.com/hunomina/http-auth-router-php/blob/master/tests/conf/security.yml) (Yaml)

### JsonSecurityContext

[](#jsonsecuritycontext)

The *[JsonSecurityContext](https://github.com/hunomina/http-auth-router-php/blob/master/src/Firewall/SecurityContext/JsonSecurityContext.php)* is a built-in *[SecurityContext](https://github.com/hunomina/http-auth-router-php/blob/master/src/Firewall/SecurityContext/SecurityContext.php)* implementation too.

It allow you to use Json configuration file for your application AuthRouter SecurityContext.

For this SecurityContext class, the configuration file syntax is the same as the *[YamlSecurityContext](https://github.com/hunomina/http-auth-router-php/blob/master/src/Firewall/SecurityContext/YamlSecurityContext.php)*.

> Example [here](https://github.com/hunomina/http-auth-router-php/blob/master/tests/conf/security.json) (Json)

### Examples

[](#examples)

For more examples, check those [here](https://github.com/hunomina/http-auth-router-php/blob/master/tests/)

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~30 days

Recently: every ~52 days

Total

8

Last Release

2419d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/37975d851f2946e4fab563ba4558e2b81908d933a4a550da65d1ac8a15a207e0?d=identicon)[hunomina972](/maintainers/hunomina972)

---

Top Contributors

[![hunomina](https://avatars.githubusercontent.com/u/16224681?v=4)](https://github.com/hunomina "hunomina (37 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/hunomina-http-auth-router-php/health.svg)

```
[![Health](https://phpackages.com/badges/hunomina-http-auth-router-php/health.svg)](https://phpackages.com/packages/hunomina-http-auth-router-php)
```

###  Alternatives

[friendsofsymfony/rest-bundle

This Bundle provides various tools to rapidly develop RESTful API's with Symfony

2.8k73.3M319](/packages/friendsofsymfony-rest-bundle)[php-http/discovery

Finds and installs PSR-7, PSR-17, PSR-18 and HTTPlug implementations

1.3k309.5M1.2k](/packages/php-http-discovery)[pusher/pusher-php-server

Library for interacting with the Pusher REST API

1.5k94.8M293](/packages/pusher-pusher-php-server)[react/http

Event-driven, streaming HTTP client and server implementation for ReactPHP

78026.4M414](/packages/react-http)[php-http/curl-client

PSR-18 and HTTPlug Async client with cURL

48347.0M384](/packages/php-http-curl-client)[smi2/phpclickhouse

PHP ClickHouse Client

84310.1M71](/packages/smi2-phpclickhouse)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
