PHP code example of geocodio / laravel-tailscale-identity

1. Go to this page and download the library: Download geocodio/laravel-tailscale-identity library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

geocodio / laravel-tailscale-identity example snippets


// routes/web.php
Route::middleware('tailscale.identity')->group(function () {
    Route::get('/dashboard', DashboardController::class);

    // Gate on a raw capability value: passes iff some capability object
    // has ['role' => 'admin'].
    Route::middleware('tailscale.capability:role,admin')->group(function () {
        Route::get('/admin', AdminController::class);
    });
});

use Geocodio\TailscaleIdentity\Middleware\ResolveTailscaleIdentity;
use Geocodio\TailscaleIdentity\TailscaleIdentity;

$identity = $request->attributes->get(ResolveTailscaleIdentity::ATTRIBUTE);

$identity->email;        // "[email protected]" (lowercased login)
$identity->displayName;  // "Person Example"
$identity->nodeName;     // "laptop.example.ts.net."
$identity->peerAddress;  // "100.101.102.103"
$identity->capabilities; // [["role" => "admin"], ...] — raw grant values

$user = User::firstOrCreate(['email' => $identity->email], ['name' => $identity->displayName]);
Auth::setUser($user);

// In tests:
config()->set('tailscale-identity.driver', 'fake');
config()->set('tailscale-identity.fake.email', '[email protected]');
config()->set('tailscale-identity.fake.capabilities', [['role' => 'admin']]);
nginx
# Container nginx — in front of php-fpm.
server {
    listen 127.0.0.1:8080;             # loopback only; fail closed if unset

    set_real_ip_from 127.0.0.1;        # trust X-Real-IP from the host proxy ONLY
    real_ip_header   X-Real-IP;

    # ... fastcgi_pass to php-fpm; REMOTE_ADDR is now the tailnet peer
}
bash
php artisan tailscale-identity:verify-topology