Download the PHP package jeffersongoncalves/laravel-zero-credentials without Composer
On this page you can find all versions of the php package jeffersongoncalves/laravel-zero-credentials. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download jeffersongoncalves/laravel-zero-credentials
More information about jeffersongoncalves/laravel-zero-credentials
Files in jeffersongoncalves/laravel-zero-credentials
Package laravel-zero-credentials
Short Description Reusable base for storing CLI authentication credentials locally in JSON (~/.
License MIT
Homepage https://github.com/jeffersongoncalves/laravel-zero-credentials
Informations about the package laravel-zero-credentials
laravel-zero-credentials
Reusable base for storing CLI authentication credentials locally in JSON, with secure file permissions and a typed credentials contract.
Extracted from the bb-cli and jira-cli Laravel Zero tools, whose
AuthService classes were ~90% identical. This package provides the shared
persistence pipeline so each CLI only declares its own credential fields.
Why
Every CLI that authenticates against an API needs to:
- resolve the user's home directory across platforms,
- write credentials to
~/.<app>/config.json(or a custom/XDG path), - create the directory
0700and the file0600, - cache the loaded credentials in memory,
- validate stored data before trusting it.
This package does all of that. The CLI supplies only a typed DTO and two small methods.
Installation
Requires PHP ^8.2. No other dependencies.
Usage
1. Implement the credentials contract
2. Extend the abstract auth service
3. Use it
Guarding commands
Custom / XDG config directory
Override configDir() to change where credentials live (the default is
~/.<appName>):
Public API
| Class | Description |
|---|---|
CredentialsContract |
Interface for a typed credentials DTO: fromArray(), toArray(), isValid(). |
AbstractAuthService |
Template method base: save(), load(), isAuthenticated(), forget(), getConfigPath(), getConfigDir(), getHomeDir(). Subclass defines appName() and fromArray(); override configDir() to customize the path. |
AuthenticationException |
RuntimeException with a parametrizable message (default "Not authenticated."). |
License
MIT