Install the Bundle
composer require akuma/social-bundle
Enable in AppKernel.php:
new Akuma\SocialBundle\AkumaSocialBundle(),
Configure Credentials
Update parameters.yml with your Facebook/Google/Microsoft app credentials:
facebook_id: "your_facebook_app_id"
facebook_secret: "your_facebook_app_secret"
google_id: "your_google_client_id"
google_secret: "your_google_client_secret"
Update config.yml
Reference the parameters:
akuma_social:
facebook:
app_id: %facebook_id%
app_secret: %facebook_secret%
app_scopes: [email, public_profile]
google:
app_id: %google_id%
app_secret: %google_secret%
app_scopes: [email]
Register Routing
Include in routing.yml:
akuma_social:
resource: "@AkumaSocialBundle/Resources/config/routing-all.yml"
prefix: /
First Use Case: Facebook Login Add a button in your template:
<a href="{{ path('akuma_social_facebook_login') }}">Login with Facebook</a>
Redirects to /facebook/connect (auto-configured).
User Clicks "Login with X"
Redirects to /[provider]/connect (e.g., /facebook/connect).
Bundle handles OAuth2 flow internally.
Post-Authentication
fos_userbundle), logs them in.default_target_path (configurable in security.yml).Custom User Data Handling
Override AkumaSocialBundle:User:SocialUserListener to extend user creation:
// src/AkumaSocialBundle/EventListener/SocialUserListener.php
public function onSocialAuthSuccess(SocialAuthSuccessEvent $event) {
$user = $event->getUser();
$user->setCustomField($event->getProvider()); // Example
}
FOSUserBundle Compatibility
Ensure FOS\UserBundle is installed and configured. The bundle extends its user provider.
# security.yml
providers:
akuma_social_facebook:
id: akuma_social.user_provider.facebook
Custom Scopes
Extend scopes in config.yml:
akuma_social:
facebook:
app_scopes: [email, public_profile, user_birthday]
Post-Auth Redirects
Override default_target_path per provider in security.yml:
akuma_social_facebook:
default_target_path: /dashboard
Microsoft-Specific Setup Ensure redirect URIs in Microsoft Dev Portal match:
https://yourdomain.com/microsoft/connect
Redirect URI Mismatches
Allowed Domains in their dev consoles./[provider]/connect (e.g., /microsoft/connect).security.yml check_path if custom routes are used.FOSUserBundle Conflicts
User entity differs from FOS\UserBundle, override the provider:
// src/AkumaSocialBundle/DependencyInjection/AkumaSocialExtension.php
$provider = new \Akuma\SocialBundle\Security\User\SocialUserProvider(
$container->get('fos_user.user_manager'),
'Akuma\SocialBundle\Entity\User' // Your custom user class
);
Scope Permissions
public_profile requires app review for production.State Parameter Issues
AkumaSocialBundle:Security:Authenticator if needed.OAuth Errors
Check league/oauth2-client logs for token failures. Common causes:
client_id/client_secret.User Not Created
Verify fos_user.user_manager is properly configured and the bundle’s listener is subscribed:
// config.yml
services:
akuma_social.user_listener:
class: Akuma\SocialBundle\EventListener\SocialUserListener
tags:
- { name: kernel.event_listener, event: akuma.social.auth.success, method: onSocialAuthSuccess }
Custom Providers Extend the bundle by creating a new provider class:
// src/AkumaSocialBundle/Security/Provider/TwitterProvider.php
class TwitterProvider extends AbstractSocialProvider {
protected $providerName = 'twitter';
// Implement OAuth2 logic for Twitter
}
Register in services.yml and update security.yml.
Post-Auth Events
Listen for akuma.social.auth.success to modify user data:
$event->getUser()->setLastSocialLogin(new \DateTime());
Template Overrides
Override Twig templates in Resources/views/AkumaSocialBundle/ to customize login buttons or error messages.
Configuration Validation
Add validation to parameters.yml to catch misconfigurations early:
# app/config/validation.yml
Akuma\SocialBundle\Validator\Constraints\ValidSocialConfig:
parameters:
facebook_id: "Not blank"
google_id: "Not blank"
How can I help you explore Laravel packages today?