Download the PHP package whilesmart/eloquent-client-credentials without Composer
On this page you can find all versions of the php package whilesmart/eloquent-client-credentials. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download whilesmart/eloquent-client-credentials
More information about whilesmart/eloquent-client-credentials
Files in whilesmart/eloquent-client-credentials
Package eloquent-client-credentials
Short Description Add client credentials authentication to any Eloquent model
License MIT
Informations about the package eloquent-client-credentials
Eloquent Client Credentials
Add OAuth2 client credentials authentication to any Eloquent model.
Installation
Publish the config file:
Run migrations:
Configuration
Usage
Using the Default Client Model
Enable routes in your config:
This registers the following routes:
| Method | URI | Description |
|---|---|---|
| POST | /api/oauth/token |
Issue access token |
| POST | /api/oauth/revoke |
Revoke access token |
| GET | /api/clients |
List clients |
| POST | /api/clients |
Create client |
| GET | /api/clients/{slug} |
Get client |
| PUT | /api/clients/{slug} |
Update client |
| DELETE | /api/clients/{slug} |
Delete client |
| POST | /api/clients/{slug}/regenerate-secret |
Regenerate secret |
Adding Client Credentials to Your Own Model
Use the HasClientCredentials trait:
The trait provides:
setSecret(string $plainSecret)- Hash and store a secretverifySecret(string $secret)- Verify a plain secret against stored hashregenerateSecret()- Generate and store a new random secretplainSecret- Access the plain secret (only available immediately after creation/regeneration)
Owner Resolver
Configure how the owner is resolved for client operations. Create a custom resolver:
Register in config:
You can also pass an owner directly when using the controller programmatically:
OAuth2 Token Flow
Issuing Tokens
Client Credentials Grant:
Response:
Refresh Token Grant (when enabled):
Revoking Tokens
Middleware
Bearer Token Authentication
Authenticate requests using OAuth2 bearer tokens:
Basic Auth
Authenticate using HTTP Basic Authentication:
Credentials: client_id:client_secret base64 encoded.
Header-Based Authentication
Authenticate using custom headers:
Headers required:
X-Client-ID: your-client-idX-Client-Secret: your-client-secret
Registering Middleware
In your bootstrap/app.php or service provider:
Hook System
Add custom logic before/after controller actions:
Create a hook class:
Available hook actions (from HookAction enum):
CLIENT_STORECLIENT_UPDATECLIENT_DELETECLIENT_REGENERATE_SECRETTOKEN_ISSUETOKEN_REVOKE
Models
Client
Default client model with:
- UUID primary key
- Sluggable name
- Polymorphic owner relationship
- Revocation support
AccessToken
OAuth2 access tokens with:
- UUID primary key
- Polymorphic client relationship
- Scopes support
- Expiration and revocation
RefreshToken
Refresh tokens with:
- UUID primary key
- Linked to access token (cascades on delete)
- Expiration and revocation
Publishing Assets
Testing
License
MIT
All versions of eloquent-client-credentials with dependencies
illuminate/database Version ^11.0|^12.0
illuminate/support Version ^11.0|^12.0
cviebrock/eloquent-sluggable Version ^11.0|^12.0