PHP code example of jorgemudry / laravel-remote-token-auth
1. Go to this page and download the library: Download jorgemudry/laravel-remote-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/ */
jorgemudry / laravel-remote-token-auth example snippets
Route::get('/users', function (Request $request) {
return $request->user();
})->middleware('auth:rta');
namespace App\Adapters;
use JorgeMudry\LaravelRemoteTokenAuth\Contracts\AdapterInterface;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Http\Request;
class MyAdapter implements AdapterInterface
{
public function authorize(Request $request): Authenticatable
{
// your custom implementation logic
}
}
namespace App\Providers;
use App\Adapters\MyAdapter;
use JorgeMudry\LaravelRemoteTokenAuth\Contracts\AdapterInterface;
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
class AuthServiceProvider extends ServiceProvider
{
/**
* The model to policy mappings for the application.
*
* @var array<class-string, class-string>
*/
protected $policies = [
// 'App\Models\Model' => 'App\Policies\ModelPolicy',
];
/**
* Register any authentication / authorization services.
*/
public function boot(): void
{
}
/**
* Register any application services.
*/
public function register(): void
{
$this->app->bind(AdapterInterface::class, MyAdapter::class);
}
}
namespace App\Auth;
use Illuminate\Auth\GenericUser;
class AuthenticatedUser extends GenericUser
{
/**
* Create a new generic User object.
*
* @param array<string, mixed> $attributes
* @return void
*/
public function __construct(array $attributes)
{
parent::__construct($attributes);
}
}