Installation
composer require develit-ab/grand-id-bundle
Enable the bundle in config/bundles.php:
return [
// ...
DevelitAB\GrandIDBundle\GrandIDBundle::class => ['all' => true],
];
Configuration Publish the default config:
php bin/console grandid:install
Update config/packages/grandid.yaml with your Grand ID API credentials:
grandid:
api_key: '%env(GRANDID_API_KEY)%'
mock_mode: false # Set to true for testing
First Use Case Authenticate a user via Grand ID:
use DevelitAB\GrandIDBundle\Service\GrandIDService;
class AuthController extends AbstractController
{
public function login(GrandIDService $grandid): Response
{
$session = $grandid->authenticate('user@example.com', 'password123');
// Handle session response
}
}
Authentication Flow
GrandIDService to handle login/logout:
$session = $grandid->authenticate($email, $password);
$grandid->logout($sessionId);
authorize() and exchangeCode() methods.Session Management
$userData = $grandid->getUserData($sessionId);
$grandid->updateUser($sessionId, ['custom_field' => 'value']);
Mock Mode for Testing
mock_mode: true in config to bypass API calls.GrandIDService::mockAuthenticate() to simulate sessions in DB.Event Listeners
Bind to grandid.session.created or grandid.session.updated events for post-auth hooks:
# config/services.yaml
services:
App\EventListener\GrandIDListener:
tags:
- { name: kernel.event_listener, event: grandid.session.created, method: onSessionCreated }
Twig Integration Pass the service to templates:
{% if grandid.isAuthenticated(sessionId) %}
Welcome, {{ grandid.getUserData(sessionId).name }}
{% endif %}
Database Schema
The bundle auto-creates a grandid_sessions table. Customize via migrations if needed.
API Key Misconfiguration
GRANDID_API_KEY is set in .env and matches the config.mock_mode: true to isolate issues.Session Expiry
refreshSession() to extend:
$grandid->refreshSession($sessionId);
Mock Mode Quirks
php bin/console doctrine:fixtures:load --append --env=test
Enable Verbose Logging
Add to config/packages/grandid.yaml:
grandid:
debug: true
Logs appear in var/log/dev.log.
API Response Inspection
Use GrandIDService::getLastResponse() to debug raw API calls:
$response = $grandid->authenticate($email, $password);
error_log($grandid->getLastResponse());
Custom Session Storage Override the default Doctrine repository by binding your own:
# config/services.yaml
services:
App\Repository\CustomGrandIDSessionRepository:
arguments:
- '@doctrine.orm.entity_manager'
tags: ['grandid.session_repository']
Webhook Handling
Extend GrandIDWebhookEvent to process custom payloads:
class CustomWebhookSubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents()
{
return [
'grandid.webhook.received' => 'onWebhookReceived',
];
}
}
Rate Limiting Implement a decorator for API rate limits:
$grandid->setRateLimiter(new CustomRateLimiter());
How can I help you explore Laravel packages today?