baks-dev/auth-yandex
Laravel/PHP пакет для авторизации пользователей через Yandex ID. Установка через Composer, настройка redirect URL и переменных окружения YANDEX_CLIENT_ID/YANDEX_CLIENT_SECRET. Включает установку ассетов, миграции Doctrine и тесты PHPUnit.
baks-dev/core and Doctrine ORM introduce friction with Laravel’s Eloquent and Artisan ecosystems.socialiteproviders/yandex but offering customized database schema and asset management. Risk: Laravel’s default users table may conflict with the package’s schema assumptions.baks:assets:install assumes Symfony’s Webpack Encore, incompatible with Laravel’s Vite/Mix. Assets (e.g., Yandex OAuth UI) must be manually integrated or replaced.symfony/http-client and symfony/process for OAuth/console logic.session vs. Laravel’s session).Authenticating/Authenticated events.laravel/pint for attribute parsing).baks:assets:install is incompatible with Laravel’s Vite. Workarounds:
public/js/ and register in Blade.auth-yandex) require adaptation to Laravel’s testing stack (Pest/PHPUnit).core.users table or create a separate table? How to reconcile with Eloquent models?yandex_id be added to users or a yandex_identities pivot table?App\Exceptions\Handler)?database, redis) or require Symfony’s session?YANDEX_CLIENT_ID)? If not, how to scope credentials?CacheInterface)? How to replace them with Laravel equivalents?Symfony\Component\HttpFoundation).Illuminate\Support\Facades\Cache).users table with yandex_id, yandex_email_verified_at via a migration:
Schema::table('users', function (Blueprint $table) {
$table->string('yandex_id')->nullable()->unique();
$table->timestamp('yandex_last_login')->nullable();
});
yandex_identities pivot table:
Schema::create('yandex_identities', function (Blueprint $table) {
$table->id();
$table->foreignId('user_id')->constrained()->onDelete('cascade');
$table->string('yandex_id')->unique();
$table->timestamps();
});
baks:assets:install with Laravel Mix/Vite:
resources/js/yandex-auth.js.app.blade.php:
<script src="{{ mix('js/yandex-auth.js') }}"></script>
@auth
<button onclick="YandexAuth.login()">Login with Yandex</button>
@endauth
Phase 1: Dependency Setup
composer require baks-dev/auth-yandex symfony/http-client symfony/process
.env:
YANDEX_CLIENT_ID=your_client_id
YANDEX_CLIENT_SECRET=your_secret
YANDEX_REDIRECT_URI=https://your-app.test/auth/yandex/callback
Phase 2: Core Integration
// app/Providers/YandexAuthServiceProvider.php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Symfony\Component\HttpClient\HttpClient;
class YandexAuthServiceProvider extends ServiceProvider {
public function register() {
$this->app->singleton('yandex.http_client', fn() => HttpClient::create());
}
}
// app/Http/Controllers/Auth/YandexController.php
namespace App\Http\Controllers\Auth;
use Illuminate\Http\Request;
use Symfony\Component\HttpClient\HttpClient;
class YandexController extends Controller {
public function handleCallback(Request $request) {
$client = $this->app->make('yandex.http_client');
// Implement token exchange and user creation/login
}
}
Phase 3: Database Schema
php artisan make:migration add_yandex_to_users_table
users table or create a pivot table (as shown above).Phase 4: Asset Handling
vendor/baks-dev/auth-yandex/resources/assets to resources/js/ and resources/css/.// mix.js
mix.js('resources/js/yandex-auth.js', 'public/js')
.postCss('resources/css/yandex-auth.css', 'public/css', []);
Phase 5: Testing
// tests/Feature/YandexAuthTest.php
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class YandexAuthTest extends TestCase {
use RefreshDatabase;
public function test_yandex_login() {
// Mock Yandex API responses
Http::fake([
'https://oauth.yandex.ru/*' => Http::response(['access_token' => 'mock_token']),
]);
// Test auth flow
}
}
How can I help you explore Laravel packages today?