Installation
Add the bundle to composer.json:
composer require gnuckorg/da-oauth-server-bundle
Register the bundle in config/bundles.php:
return [
// ...
Gnuckorg\DaOAuthServerBundle\GnuckorgDaOAuthServerBundle::class => ['all' => true],
];
Configuration Publish the default config:
php bin/console da:oauth:init
Update config/packages/da_oauth_server.yaml to define authspaces (e.g., admin, user, partner).
First Use Case: Authspace-Specific OAuth
Configure a route to trigger OAuth for a specific authspace (e.g., user):
# config/routes.yaml
da_oauth_authorize:
path: /oauth/authorize/{authspace}
methods: [GET]
defaults:
_controller: 'GnuckorgDaOAuthServerBundle:Security:authorize'
authspace: 'user'
Multi-Authspace OAuth Flow
/oauth/authorize/{authspace} with client_id, redirect_uri, and response_type.authorization_code for tokens via /oauth/token/{authspace}./api/{authspace}/resource).Authspace-Specific Clients
Define clients per authspace in config/packages/da_oauth_server.yaml:
da_oauth_server:
authspaces:
user:
clients:
my_web_app:
random_id: '...'
secret: '...'
redirect_uri: 'https://myapp.com/callback'
admin:
clients:
dashboard:
random_id: '...'
secret: '...'
Protected Routes Secure routes with authspace-aware annotations or attributes:
use Gnuckorg\DaOAuthServerBundle\Annotation\OAuth;
class UserController {
/**
* @OAuth(authspace="user")
*/
public function profile() { ... }
}
Token Validation Middleware Validate tokens in controllers or middleware:
use Gnuckorg\DaOAuthServerBundle\Security\OAuthToken;
public function secureAction(OAuthToken $token) {
if (!$token->isValid()) {
throw new \RuntimeException('Invalid token');
}
// Proceed with authspace-specific logic
}
Gnuckorg\DaOAuthServerBundle\Security\AuthspaceProviderInterface to add authspace-specific user providers or token storage.DaOAuthClientBundle for seamless client-server OAuth interactions.da:oauth:create-client command to generate test clients:
php bin/console da:oauth:create-client --authspace=user --name=test_client
Authspace Mismatch
authspace in routes or token requests causes 404 or 403 errors.{authspace} in routes and validate it in token requests.Token Storage
doctrine or session) may not persist across authspaces.da_oauth_server.yaml:
token_storage: 'Gnuckorg\DaOAuthServerBundle\Storage\RedisTokenStorage'
Deprecated Bundle
league/oauth2-server for Laravel.CSRF in Authorize Flow
csrf_token in forms or use middleware like Symfony\Component\HttpFoundation\Session\Session.debug: true in da_oauth_server.yaml to log OAuth events.dump() to inspect the current authspace in controllers:
use Gnuckorg\DaOAuthServerBundle\Security\AuthspaceContext;
public function debugAuthspace(AuthspaceContext $context) {
dump($context->getAuthspace());
}
Custom Token Storage
Implement Gnuckorg\DaOAuthServerBundle\Storage\TokenStorageInterface for custom storage (e.g., database).
Authspace-Specific Scopes
Extend Gnuckorg\DaOAuthServerBundle\Security\ScopeManager to validate scopes per authspace.
Event Listeners
Subscribe to OAuth events (e.g., oauth.authorize.success) for logging or analytics:
services:
App\EventListener\OAuthListener:
tags:
- { name: kernel.event_listener, event: oauth.authorize.success, method: onAuthorizeSuccess }
API Integration
Use DaApiServerBundle to expose authspace-specific APIs with OAuth validation:
da_api_server:
authspaces:
user: { route_prefix: '/api/user' }
admin: { route_prefix: '/api/admin' }
How can I help you explore Laravel packages today?