cfx-laravel-auth maintained by mbvanderleest
CFX.re Laravel Auth
A simple Laravel 12 package for logging in with CFX.re (FiveM/RedM) using Socialite.
Requirements
- PHP 8.2+
- Laravel 12.x
- Laravel Socialite 5.5+
Installation
composer require mbvanderleest/cfx-laravel-auth
php artisan cfx:generate-keys
Add this to your .env:
CFX_APP_NAME="My App"
CFX_CLIENT_ID=your_client_id
CFX_REDIRECT_URL=http://your-domain.com/auth/cfx/callback
CFX_AVATAR_SIZE=128
Basic Setup
Add these routes in routes/web.php:
use Laravel\Socialite\Facades\Socialite;
Route::get('/auth/cfx', fn() => Socialite::driver('cfx')->redirect());
Route::get('/auth/cfx/callback', function () {
$user = Socialite::driver('cfx')->user();
return $user; // $user->getId(), $user->getNickname(), etc.
});
Optional Controller
class AuthController extends Controller
{
public function redirectToCfx()
{
return Socialite::driver('cfx')->redirect();
}
public function handleCfxCallback()
{
$cfx = Socialite::driver('cfx')->user();
$user = User::firstOrCreate(['cfx_id' => $cfx->getId()], [
'name' => $cfx->getNickname(),
'email' => $cfx->getEmail(),
'avatar' => $cfx->getAvatar(),
]);
auth()->login($user);
return redirect('/dashboard');
}
}
Notes
- Keep your private key safe
- HTTPS is required in production
- Email may not always be available
License
MIT License