adachsoft / oidc-provider-json-file
JSON file repository adapters for OIDC provider contracts.
Package info
gitlab.com/a.adach/oidc-provider-json-file
pkg:composer/adachsoft/oidc-provider-json-file
Requires
- php: ^8.3
- adachsoft/access-control-contracts: ^0.1
- adachsoft/auth-contracts: ^0.2
- adachsoft/json-file-storage: ^0.1
- adachsoft/oidc-provider-contracts: ^0.1
Requires (Dev)
- adachsoft/php-code-style: ^0.7.4
- friendsofphp/php-cs-fixer: ^3.95
- phpstan/phpstan: ^2.3
- phpunit/phpunit: ^13.4
- rector/rector: ^2.9
- symplify/phpstan-rules: ^14.19
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
This package provides local JSON-file adapters for the OIDC provider client, authorization-code, refresh-token, device-authorization, and signing-key repository contracts. It targets small deployments that need durable storage on a local filesystem without a database service.
Requirements
- PHP 8.3 or newer.
- Composer.
Installation
composer require adachsoft/oidc-provider-json-file
Usage
Construct each repository with the path of its own JSON document:
use AdachSoft\OidcProviderJsonFile\Repository\JsonAuthorizationCodeRepository;
use AdachSoft\OidcProviderJsonFile\Repository\JsonClientRepository;
use AdachSoft\OidcProviderJsonFile\Repository\JsonDeviceAuthorizationRepository;
use AdachSoft\OidcProviderJsonFile\Repository\JsonRefreshTokenRepository;
use AdachSoft\OidcProviderJsonFile\Repository\JsonSigningKeyRepository;
$clients = new JsonClientRepository(__DIR__ . '/var/oidc/clients.json');
$authorizationCodes = new JsonAuthorizationCodeRepository(__DIR__ . '/var/oidc/authorization-codes.json');
$refreshTokens = new JsonRefreshTokenRepository(__DIR__ . '/var/oidc/refresh-tokens.json');
$deviceAuthorizations = new JsonDeviceAuthorizationRepository(__DIR__ . '/var/oidc/device-authorizations.json');
$signingKeys = new JsonSigningKeyRepository(__DIR__ . '/var/oidc/signing-keys.json');
Each repository implements the corresponding interface from adachsoft/oidc-provider-contracts. Use these adapters through the repository interfaces in application services.
File layout
Each repository owns one document and indexes records by client ID, token hash, device-code hash, or key ID:
var/oidc/
├── clients.json {"clients": {"<clientId>": {...}}}
├── authorization-codes.json {"authorizationCodes": {"<tokenHash>": {...}}}
├── refresh-tokens.json {"refreshTokens": {"<tokenHash>": {...}}}
├── device-authorizations.json {"deviceAuthorizations": {"<deviceCodeHash>": {...}}}
└── signing-keys.json {"signingKeys": {"<keyId>": {...}}}
adachsoft/json-file-storage creates a sidecar .lock file for each document. The repository documents contain client-secret hashes and authorization-code, refresh-token, and device-code hashes only; callers must supply a hash in ClientDto::secretHash. Plaintext client secrets, authorization codes, refresh tokens, and device codes are never persisted by these adapters.
The signing-key document contains private key material. Keep it outside the web root, owned by the application user, and restricted to file mode 0600. JsonFileStorage creates the temporary replacement file with mode 0600; the atomic rename preserves that permission.
Guarantees and limits
- Each repository operation that checks and changes state runs in one
JsonFileStorage::transaction()call. This provides atomic per-repository operations across cooperating processes, including single-use authorization-code and device-authorization consumption, refresh-token rotation and family revocation, optimistic client/device-authorization/signing-key version checks, active signing-key uniqueness, and expiration or retired-key cleanup. adachsoft/json-file-storageuses sidecarflock()locks and atomic file replacement. Locks are advisory, and every process accessing these documents must use the same storage implementation.- Storage is for a local filesystem only. Network filesystems such as NFS are not supported. Each write rewrites its repository document, so these adapters are intended for small- and medium-sized data sets.