taufik-t/uauth-rest-client

OpenID Connect OAuth2 Provider for Laravel Socialite

0.0.7 2025-07-28 09:38 UTC

This package is auto-updated.

Last update: 2025-08-28 09:53:42 UTC


README

Laravel Support: v9, v10, v11 PHP Support: 8.1, 8.2, 8.3

Installation & Basic Usage

composer require taufik-t/uauth-rest-client

Add configuration to config/uauth.php

'api' => [
    'base_url' => env('UAUTH_API_BASE_URL', null),
    'ssl_verify' => env('UAUTH_API_SSL_VERIFY', true),
    'timeout' => env('UAUTH_API_TIMEOUT', 30),
    'connect_timeout' => env('UAUTH_API_CONNECT_TIMEOUT', 10),
    'provider_id' => env('UAUTH_API_PROVIDER_ID', null),
  ],

.env

UAUTH_API_BASE_URL="https://auth.application.com/api/v1"
UAUTH_API_PROVIDER_ID="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"

// optional
UAUTH_API_SSL_VERIFY=true // ubah `false` untuk development atau local
UAUTH_API_TIMEOUT=30
UAUTH_API_CONNECT_TIMEOUT=10

Edit middleware app/Http/Middleware/TrustProxies.php

<?php

namespace App\Http\Middleware;

use Illuminate\Http\Middleware\TrustProxies as Middleware;
use Illuminate\Http\Request;

class TrustProxies extends Middleware
{
  /**
   * The trusted proxies for this application.
   *
   * @var array<int, string>|string|null
   */
  protected $proxies;

  /**
   * The headers that should be used to detect proxies.
   *
   * @var int
   */
  protected $headers =
  Request::HEADER_X_FORWARDED_FOR |
    Request::HEADER_X_FORWARDED_HOST |
    Request::HEADER_X_FORWARDED_PORT |
    Request::HEADER_X_FORWARDED_PROTO |
    Request::HEADER_X_FORWARDED_AWS_ELB;

  // add this line
  public function __construct()
  {
    $this->proxies = config('uauth.proxies');
  }
}

Usage

Tambahkan middleware sso.api untuk memproteksi resource api:

routes/api.php

Route::group(['middleware' => ['sso.api']], function () {
    // tempatkan route resource yang ingin di proteksi disini
});

Hapus default middleware pada route api di app\Providers\RouteServiceProvider.php

public function boot(): void
{
  $this->routes(function () {
    Route::middleware('api') // hapus default middleware
      ->prefix('api')
      ->group(base_path('routes/api.php'));

      // menjadi

    Route::prefix('api')
      ->group(base_path('routes/api.php'));
  })
}