Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Auth Yandex Laravel Package

baks-dev/auth-yandex

Laravel/PHP пакет для авторизации пользователей через Yandex ID. Установка через Composer, настройка redirect URL и переменных окружения YANDEX_CLIENT_ID/YANDEX_CLIENT_SECRET. Включает установку ассетов, миграции Doctrine и тесты PHPUnit.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Laravel Compatibility: The package is Symfony-centric (uses Symfony’s DI, console commands, and asset pipeline), requiring abstraction layers or forking to integrate with Laravel. Key dependencies like baks-dev/core and Doctrine ORM introduce friction with Laravel’s Eloquent and Artisan ecosystems.
  • OAuth2 Implementation: Leverages Yandex’s OAuth2 flow (authorization code + PKCE), aligning with Laravel’s socialiteproviders/yandex but offering customized database schema and asset management. Risk: Laravel’s default users table may conflict with the package’s schema assumptions.
  • Database Schema: Introduces migrations via Doctrine, which Laravel’s Eloquent does not natively support. Requires manual migration translation or Doctrine DBAL integration.
  • Asset Pipeline: 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.

Integration Feasibility

  • High-Level: Feasible but non-trivial due to Symfony-Laravel divergence. Options:
    1. Symfony Bridge: Use symfony/http-client and symfony/process for OAuth/console logic.
    2. Fork & Adapt: Replace Symfony-specific code (e.g., console commands) with Laravel Artisan equivalents.
    3. Hybrid Approach: Use the package’s OAuth logic via service containers while handling routes/assets natively.
  • Middleware/Routes: Requires custom Laravel middleware to manage:
    • Yandex OAuth state/CSRF.
    • Session handling (Symfony’s session vs. Laravel’s session).
  • Event System: No native Laravel event hooks, but can wrap auth logic in Laravel’s Authenticating/Authenticated events.

Technical Risk

  • PHP 8.4+ Dependency: Laravel 10+ supports PHP 8.2+, but 8.4 features (e.g., typed properties) may require:
    • Laravel updates or polyfills (e.g., laravel/pint for attribute parsing).
  • Doctrine vs. Eloquent: Schema migrations must be translated or handled via Doctrine DBAL, adding complexity.
  • Asset Pipeline: baks:assets:install is incompatible with Laravel’s Vite. Workarounds:
    • Manually copy assets to public/js/ and register in Blade.
    • Replace with Laravel Mix/Vite builds.
  • Testing: Symfony’s PHPUnit tests (group auth-yandex) require adaptation to Laravel’s testing stack (Pest/PHPUnit).
  • Future-Proofing: Last release in 2026 (future date) suggests unproven long-term support. Risk of breaking changes if BaksDev updates core.

Key Questions

  1. Database Schema:
    • Does the package modify Laravel’s users table or create a separate table? How to reconcile with Eloquent models?
    • Example: Should yandex_id be added to users or a yandex_identities pivot table?
  2. Authentication Flow:
    • How are failed logins or token refreshes handled? Are exceptions Laravel-compatible (e.g., App\Exceptions\Handler)?
    • Does it support Laravel’s session driver (e.g., database, redis) or require Symfony’s session?
  3. Asset Integration:
    • Are the installed assets (JS/CSS) critical for Yandex’s OAuth UI? If so, how to integrate with Laravel’s frontend (Blade/Vue/React)?
  4. Error Handling:
    • What exceptions are thrown for Yandex API failures (e.g., rate limits, invalid scopes)? How to log them in Laravel?
  5. Multi-Tenant:
    • Does the package support tenant-aware auth (e.g., per-tenant YANDEX_CLIENT_ID)? If not, how to scope credentials?
  6. Performance:
    • Does the package introduce blocking calls to Yandex’s API? How to implement queue-based auth (e.g., Laravel Queues)?
  7. Symfony Dependencies:
    • Which Symfony components are critical (e.g., CacheInterface)? How to replace them with Laravel equivalents?
  8. Localization:
    • Does the package include Russian-language error messages? How to customize them for Laravel’s localization system?

Integration Approach

Stack Fit

  • Laravel + Symfony Interop:
    • Use symfony/http-client for OAuth2 requests.
    • Leverage laravel/symfony for DI compatibility (e.g., Symfony\Component\HttpFoundation).
    • Alternative: Fork the package and replace Symfony-specific code with Laravel equivalents (e.g., Illuminate\Support\Facades\Cache).
  • Database:
    • Option 1: Extend Laravel’s 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();
      });
      
    • Option 2: Create a 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();
      });
      
  • Frontend:
    • Replace baks:assets:install with Laravel Mix/Vite:
      1. Copy Yandex’s OAuth JS assets to resources/js/yandex-auth.js.
      2. Register in app.blade.php:
        <script src="{{ mix('js/yandex-auth.js') }}"></script>
        
    • Use Blade directives to inject Yandex’s auth button:
      @auth
          <button onclick="YandexAuth.login()">Login with Yandex</button>
      @endauth
      

Migration Path

  1. Phase 1: Dependency Setup

    • Install the package and Symfony interop tools:
      composer require baks-dev/auth-yandex symfony/http-client symfony/process
      
    • Configure .env:
      YANDEX_CLIENT_ID=your_client_id
      YANDEX_CLIENT_SECRET=your_secret
      YANDEX_REDIRECT_URI=https://your-app.test/auth/yandex/callback
      
  2. Phase 2: Core Integration

    • Create a Laravel service provider to bridge Symfony components:
      // 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());
          }
      }
      
    • Implement a custom controller for the OAuth callback:
      // 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
          }
      }
      
  3. Phase 3: Database Schema

    • Run a Laravel migration to add Yandex fields:
      php artisan make:migration add_yandex_to_users_table
      
    • Update the users table or create a pivot table (as shown above).
  4. Phase 4: Asset Handling

    • Manually copy assets from vendor/baks-dev/auth-yandex/resources/assets to resources/js/ and resources/css/.
    • Compile with Laravel Mix:
      // mix.js
      mix.js('resources/js/yandex-auth.js', 'public/js')
           .postCss('resources/css/yandex-auth.css', 'public/css', []);
      
  5. Phase 5: Testing

    • Adapt Symfony’s tests to Laravel’s testing environment:
      // 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
          }
      }
      

Compatibility

  • **Symfony
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
nasirkhan/laravel-sharekit
directorytree/privacy-filter-classifier
directorytree/privacy-filter
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin
splash/metadata
splash/openapi
splash/scopes
splash/toolkit
testo/output-teamcity
testo/bridge-symfony