acat/jwt

Validates, decodes, and authorizes tokens (e.g. JWT)

Maintainers

Package info

github.com/f-3-l-i-x/acat-jwt

pkg:composer/acat/jwt

Transparency log

Statistics

Installs: 18

Dependents: 1

Suggesters: 0

Stars: 0

dev-main 2026-07-24 11:36 UTC

This package is auto-updated.

Last update: 2026-07-24 11:37:07 UTC


README

Decodes and verifies RSA-signed JWTs (e.g. from a Keycloak realm) and authorizes them against a required issuer, resource and role.

Requirements

PHP 8.4 and later.

Installation

You can install the library via Composer. Run the following command:

composer require acat/jwt

Usage

use ACAT\JWT\TokenDecoder;
use ACAT\JWT\TokenAuthorizer;

$decoder = new TokenDecoder('https://auth.example.com', 'my-realm');
$token = $decoder->decodeToken($jwt); // verifies signature, exp/nbf/iat via the realm's JWKS

$authorizer = new TokenAuthorizer();
$authorizer->authorize($token, 'my-client', 'https://auth.example.com/realms/my-realm', 'admin');

decodeToken() fetches the signing key from the realm's JWKS endpoint (matched by the token's kid header), verifies the signature and validates exp/nbf/iat. authorize() additionally checks the token's issuer and, if a role is given, that the role is present under resource_access.<resourceName>.roles. Both throw ACAT\JWT\Exception\TokenException on failure.

Testing

composer install
vendor/bin/phpunit