yumemi-inc/google-iap-laravel

Authentication guard on Laravel for verifying requests from Google IAP (Identity-Aware Proxy).

v1.3.1 2024-03-13 02:24 UTC

README

php

Warning
This is not an official product of YUMEMI Inc.

Authentication guard on Laravel for verifying requests from Google IAP (Identity-Aware Proxy).

Prerequisites

  • PHP 8.1 or later
    • ext-gmp for JWT verification
  • Laravel 9, 10, or 11 (dev)

Getting Started

  1. Require this package as a dependency.

    composer require yumemi-inc/google-iap-laravel
  2. Implement GoogleUserResolver as you need.

    <?php // app/Security/AppGoogleUserResolver.php (new)
    
    use Illuminate\Contracts\Auth\Authenticatable;
    use Illuminate\Contracts\Auth\UserProvider;
    use YumemiInc\GoogleIapLaravel\Claims;
    use YumemiInc\GoogleIapLaravel\GoogleUserResolver;
    
    class AppGoogleUserResolver implements GoogleUserResolver
    {
        public function provide(Claims $claims, UserProvider $userProvider): ?Authenticatable
        {
            return $userProvider->retrieveByCredentials([
                'google_user_id' => $claims->id(),
            ]);
        }
    }
  3. Register the user resolver as a service.

    <?php // app/Providers/AppServiceProvider.php
    
    use YumemiInc\GoogleIapLaravel\GoogleUserResolver;
    
    public function register(): void
    {
        $this->app->bind(GoogleUserProvider::class, AppGoogleUserProvider::class);
    }
  4. Use the guard provided in this package.

    <?php // config/auth.php
    
    'guards' => [
        'google-iap' => [
             'driver' => 'google-iap',
             'provider' => 'users',
         ],
    ]