PHP code example of hadefication / simple-token-auth

1. Go to this page and download the library: Download hadefication/simple-token-auth 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/ */

    

hadefication / simple-token-auth example snippets


return [
    'tokens' => [
        'service-name' => env('API_TOKEN_SERVICE_NAME'),
        'another-service' => env('API_TOKEN_ANOTHER_SERVICE'),
    ],

    'fallback_token' => env('API_TOKEN'),

    'rate_limiting' => [
        'enabled' => env('API_RATE_LIMITING_ENABLED', true),
        'max_attempts' => env('API_RATE_LIMITING_MAX_ATTEMPTS', 60),
        'lockout_duration' => env('API_RATE_LIMITING_LOCKOUT_DURATION', 60),
    ],

    'log_failed_attempts' => env('API_LOG_FAILED_ATTEMPTS', true),
];

// Using the middleware class directly
Route::middleware(\Hadefication\SimpleTokenAuth\Http\Middleware\SimpleTokenAuthMiddleware::class)
    ->group(function () {
        Route::get('/api/protected', function () {
            return response()->json(['message' => 'Authenticated!']);
        });
    });

// Using the registered middleware alias
Route::middleware('simple-token-auth')
    ->group(function () {
        Route::get('/api/protected', function () {
            return response()->json(['message' => 'Authenticated!']);
        });
    });

Route::middleware('simple-token-auth:service-name')
    ->group(function () {
        Route::get('/api/service-specific', function () {
            return response()->json(['message' => 'Service authenticated!']);
        });
    });

Route::middleware('simple-token-auth:service-name')
    ->get('/api/service-data', function (Request $request) {
        $service = $request->attributes->get('authenticated_service');
        return response()->json(['service' => $service]);
    });

return [
    'tokens' => [
        'my-service' => env('API_TOKEN_MY_SERVICE'),
        // Add other service tokens here
    ],
    
    'fallback_token' => env('API_TOKEN'),
    // ... rest of configuration
];
bash
php artisan vendor:publish --provider="Hadefication\SimpleTokenAuth\SimpleTokenAuthServiceProvider"
bash
php artisan config:clear
bash
php artisan simple-token:info
bash
php artisan simple-token:info