crowdvalley/crowdentials-api-wrapper
PHP wrapper for the CrowdValley (Crowdentials) API, simplifying authentication and common requests so Laravel/PHP apps can integrate CrowdValley services with a cleaner, reusable client.
Installation
composer require crowdvalley/crowdentials-api-wrapper
Add the service provider to config/app.php under providers:
CrowdValley\CrowdentialsApiWrapper\CrowdentialsServiceProvider::class,
Publish Config
php artisan vendor:publish --provider="CrowdValley\CrowdentialsApiWrapper\CrowdentialsServiceProvider"
Configure .env with your Crowdentials API credentials:
CROWDENTIALS_API_KEY=your_api_key_here
CROWDENTIALS_API_SECRET=your_api_secret_here
CROWDENTIALS_API_URL=https://api.crowdentials.com
First Use Case: Fetching a User’s Credentials
use CrowdValley\CrowdentialsApiWrapper\Facades\Crowdentials;
$userCredentials = Crowdentials::user()->get('user_id_here');
User Management
$user = Crowdentials::user()->find('user_id');
$user = Crowdentials::user()->createOrUpdate([
'email' => '[email protected]',
'password' => 'secure_password123',
'metadata' => ['role' => 'admin']
]);
Crowdentials::user()->delete('user_id');
Authentication
$token = Crowdentials::auth()->login('[email protected]', 'password');
Crowdentials::auth()->logout($token);
Credential Rotation
Crowdentials::user()->rotatePassword('user_id', 'new_secure_password');
Bulk Operations
$users = Crowdentials::user()->all(['id' => ['user1', 'user2']]);
Authenticatable to use Crowdentials tokens:
public function getAuthIdentifier()
{
return $this->crowdentials_token;
}
Crowdentials::auth()->validateToken($request->bearerToken());
Crowdentials::events()->listen('user.created', function ($user) {
// Handle new user
});
Rate Limiting
$user = Cache::remember("crowdentials_user_{$userId}", now()->addMinutes(5), function () use ($userId) {
return Crowdentials::user()->find($userId);
});
429 Too Many Requests responses and implement exponential backoff.Token Expiry
if (Crowdentials::auth()->isTokenExpired($token)) {
$token = Crowdentials::auth()->refreshToken($token);
}
Sensitive Data
\Log::debug('Crowdentials response', ['data' => $response->sanitize()]);
Enable Debug Mode:
CROWDENTIALS_DEBUG=true
Logs API requests/responses to storage/logs/crowdentials.log.
Mock API Calls (for testing):
$this->partialMock(Crowdentials::class, function ($mock) {
$mock->shouldReceive('get')->andReturn(['id' => 'test_user']);
});
Custom Endpoints Override the base client to add endpoints:
Crowdentials::extend('custom', function ($app) {
return new CustomCrowdentialsClient($app['http.client']);
});
Response Transformers Modify responses before they’re returned:
Crowdentials::user()->transformer(function ($response) {
return collect($response)->merge(['formatted_at' => now()->toDateTimeString()]);
});
Webhook Handling Validate signatures in your webhook endpoint:
$payload = Crowdentials::events()->validateWebhook($request->getContent(), $request->header('X-Signature'));
How can I help you explore Laravel packages today?