tastyigniter/ti-ext-socialite
TastyIgniter Socialite extension adds social login/registration for customers via Laravel Socialite. Supports Facebook, Google, Twitter and more, with an extensible adapter-based approach and customizable integration for your TastyIgniter site.
Install the Package
composer require tastyigniter/ti-ext-socialite
Publish the configuration and migrations:
php artisan vendor:publish --provider="TastyIgniter\Socialite\SocialiteServiceProvider"
php artisan migrate
Configure Providers
Add your OAuth credentials to .env:
SOCIALITE_FACEBOOK_CLIENT_ID=your_app_id
SOCIALITE_FACEBOOK_CLIENT_SECRET=your_app_secret
SOCIALITE_GOOGLE_CLIENT_ID=your_client_id
SOCIALITE_GOOGLE_CLIENT_SECRET=your_client_secret
Add Routes
Include the package routes in routes/web.php:
Route::socialite();
Add Login Buttons Use the provided Blade components in your login view:
@socialiteButton('facebook')
@socialiteButton('google')
Handle User Creation
Override the default user mapping in app/Providers/SocialiteServiceProvider.php:
public function mapFacebookUserToModel(User $user, array $attributes)
{
$user->name = $attributes['name'];
$user->email = $attributes['email'] ?? $attributes['email_verified'] ? $attributes['email'] : null;
$user->save();
}
Test the Flow
For a TastyIgniter-based e-commerce site, implement social login on the checkout page to reduce cart abandonment:
@socialiteButton('google', ['class' => 'btn btn-primary'])
// In SocialiteServiceProvider.php
public function handleSuccessfulLogin(User $user)
{
return redirect()->route('cart.show');
}
// In EventServiceProvider.php
public function boot()
{
SocialiteEvents::registered(function ($user) {
$user->assignRole('customer');
});
}
Socialite facade to handle OAuth flows:
use TastyIgniter\Socialite\Facades\Socialite;
$user = Socialite::driver('facebook')->stateless()->user();
SocialiteServiceProvider:
public function mapGoogleUserToModel(User $user, array $attributes)
{
$user->name = $attributes['name'];
$user->email = $attributes['email'];
$user->avatar = $attributes['picture'] ?? null;
$user->save();
}
User model.SocialiteEvents::registered(function ($user) {
// Send welcome email
Mail::to($user->email)->send(new WelcomeEmail($user));
});
SocialiteEvents::failed(function ($exception) {
Log::error('Socialite failed: ' . $exception->getMessage());
});
map*UserToModel methods:
public function mapFacebookUserToModel(User $user, array $attributes)
{
$tenant = Tenant::find(request('tenant_id'));
$user->tenant_id = $tenant->id;
$user->save();
}
composer require socialiteproviders/manager
composer require socialiteproviders/github
Then register the provider in config/socialite.php:
'providers' => [
'github' => [
'client_id' => env('GITHUB_CLIENT_ID'),
'client_secret' => env('GITHUB_CLIENT_SECRET'),
'redirect' => env('GITHUB_REDIRECT_URI'),
],
],
@socialiteButton('twitter', [
'class' => 'btn btn-twitter',
'title' => 'Login with Twitter'
])
resources/views/vendor/socialite/button.blade.php.php artisan route:cache
SocialiteTestCase trait for unit tests:
use TastyIgniter\Socialite\Tests\SocialiteTestCase;
class SocialiteTest extends SocialiteTestCase
{
public function testGoogleLogin()
{
$response = $this->get('/auth/google');
$response->assertRedirect();
}
}
.env:
SOCIALITE_DEBUG=true
TokenMismatchException if CSRF protection is too strict.app/Http/Middleware/VerifyCsrfToken.php:
protected $except = [
'socialite/*',
];
email_verified instead of email. Unverified emails may cause registration failures.map*UserToModel:
$user->email = $attributes['email_verified'] ? $attributes['email'] : null;
state parameter for CSRF protection, but custom implementations may break this.state parameter:
Route::get('/auth/{provider}/callback', [SocialiteController::class, 'handleProviderCallback']);
users table extensions.// In SocialiteServiceProvider.php
protected $userModel = App\Models\CustomUser::class;
--mock flag in tests:
$this->mockGoogle();
/auth/google-oauth2 may fail if not configured properly.config/socialite.php uses the correct provider name:
'google' => [
'client_id' => env('GOOGLE_CLIENT_ID'),
'client_secret' => env('GOOGLE_CLIENT_SECRET'),
'redirect' => env('GOOGLE_REDIRECT_URI'),
],
Add to config/logging.php:
'socialite' => [
'driver' => 'single',
'path' => storage_path('logs/socialite.log'),
'level' => 'debug',
],
redirect URI in .env matches exactly what the provider expects (e.g., https://your-app.com/auth/google/callback).SOCIALITE_DEBUG=true to log the full redirect URL.Use the SocialiteTestCase trait to mock providers:
public function testFacebookLogin()
{
$this->mockFacebook();
$response = $this->get('/auth/facebook');
$response->assert
How can I help you explore Laravel packages today?