Download the PHP package clavia/authzen without Composer

On this page you can find all versions of the php package clavia/authzen. 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 authzen

clavia/authzen

An OpenID AuthZEN 1.0 client on PSR-18, and a PSR-15 middleware that enforces its decisions. Your API asks a policy decision point, at request time, whether the caller may do what it asks, and refuses anything but a true:

The decision point says Your API answers
{"decision": true} your handler runs
{"decision": false} 403, your handler never runs
nothing usable: unreachable, too slow, failing, refusing the request, answering nonsense 503, never a pass-through

It works with any AuthZEN decision point. With Clavia, the decisions come from OpenFGA, behind Clavia's Authorization API, and the client obtains and caches its own access token.

Install

PHP 8.3 or later. Bring a PSR-18 client and PSR-17 factories (Guzzle has both), and a PSR-16 cache for the token and the metadata.

Protect a route

For GET /documents/q3-report, by a person whose validated token says "sub": "3f8e…", the decision point is asked:

Put the middleware after your authentication (which validates the token and leaves its claims in the token_claims attribute) and after routing (which leaves the route's id).

Who, what, on what

The middleware takes three resolvers, and a fourth for the context, each a class or a closure fn (ServerRequestInterface $request): …:

Parameter Gives Provided
subject a Subject TokenSubject::fromClaims($attribute): the token's sub as a user, or, for an application acting for itself (no sub, or a sub equal to its client_id, RFC 9068 §2.2), its client_id as a client. TokenSubject::fromAttributes() reads league/oauth2-server's attributes.
action an Action Action::named('viewer') for a route with one action; MethodAction::map([...]) by HTTP method
resource a Resource new AttributeResource($type, $attribute): a route parameter as the identifier
context an array none by default: what your policies read beyond the three (the time, the network)

A resolver that cannot answer throws Unresolvable: the request is refused (403) and the decision point is not asked. A method MethodAction does not map, a request without a subject, a route without its parameter: all refused.

On a permit, your handler finds the decision in the request attribute Clavia\AuthZen\Decision, its context holding whatever the decision point added (obligations, hints).

The refusals

ProblemResponder answers RFC 9457 problem documents, never cached, that say nothing of the decision's context or of the failure. Implement Responder to answer otherwise; keep 403 and 503. Every failure is logged (pass a PSR-3 logger as logger:), by kind and status, never with a token.

Fail closed

There is no decision without the decision point's answer, and the middleware never invents one. What you configure decides how fast "no answer" comes:

Any AuthZEN decision point

discover() reads the decision point's metadata from /.well-known/authzen-configuration (AuthZEN §9) the first time it is needed, checks that it names the decision point it was fetched from, and keeps it in the cache for an hour. An API the metadata does not name is not offered (§9.1.1): asking for it throws UnsupportedOperation, which the middleware answers 503.

A decision point that publishes no metadata has every API at its default path:

Credentials are ClientCredentials (an OAuth 2.0 token by the client credentials grant, RFC 6749 §4.4), StaticCredentials::bearer($token) or ::header($value), or NoCredentials. A 401 from the decision point renews the credentials and asks once more.

With Clavia

What the operator sets up is in Clavia's fine-grained authorization guide: a model for your API, your API's machine client named as the one that speaks for it, and its grant on the Authorization API (evaluate:access, and search:access to search). Then:

The client on its own

The middleware asks one question per request. Ask more, or search, with the client:

searchSubjects() and searchActions() work the same way. A search says what would be permitted; it is not a decision. Enforce with an evaluation.

Every method gives the decision point's answer or throws an AuthZenException:

Exception When
DecisionPointUnavailable no connection, a timeout, a 5xx, a redirect, a malformed answer, metadata for another decision point, an X-Request-ID that is not the one sent
TokenUnavailable (a DecisionPointUnavailable) the token endpoint refused the client, or could not be reached
RequestRejected a 4xx: a question the decision point cannot ask, credentials it does not take (after a renewal). detail() holds its words, for your logs
UnsupportedOperation the decision point does not offer that API
InvalidValue a value the information model cannot hold

Caching

The cache holds two things: the metadata document (an hour), and the access token, until thirty seconds before it expires, so that every PHP process of your API shares one. The token is a secret: give a cache that only your API can read. Nothing else is cached: decisions never are.

Development

The tests play the AuthZEN working group's recorded Todo interoperability scenario (test/Interop/fixtures), and run against a real Clavia and a live interoperability decision point when told where they are: see CONTRIBUTING.md.

Specifications

AuthZEN Authorization API 1.0 · RFC 6749 (OAuth 2.0) · RFC 6750 (bearer tokens) · RFC 8707 (resource indicators) · RFC 9068 (JWT access tokens) · RFC 9457 (problem details) · PSR-7, PSR-15, PSR-16, PSR-17, PSR-18, PSR-20

License

BSD-3-Clause. See LICENSE.


All versions of authzen with dependencies

PHP Build Version
Package Version
Requires php Version ~8.3.0 || ~8.4.0 || ~8.5.0
fig/http-message-util Version ^1.1
psr/clock Version ^1.0
psr/http-client Version ^1.0
psr/http-factory Version ^1.1
psr/http-message Version ^1.1 || ^2.0
psr/http-server-handler Version ^1.0
psr/http-server-middleware Version ^1.0
psr/log Version ^2.0 || ^3.0
psr/simple-cache Version ^2.0 || ^3.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 clavia/authzen contains the following files

Loading the files please wait ...