PHP code example of imunew / tymon-jwt-auth

1. Go to this page and download the library: Download imunew/tymon-jwt-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/ */

    

imunew / tymon-jwt-auth example snippets


// App\Http\Controllers\Auth\Login

    public function __invoke(LoginRequest $request)
    {
        $credentials = $request->only(['login_id', 'password']);
        if (! $token = $this->jwtGuard->attempt($credentials)) {
            throw new AuthenticationException();
        }

        return new AuthResource(new JwtToken($token, $this->factory->getTTL() * 60));
    }

// App\Http\Kernel

    protected $middlewarePriority = [
        \Illuminate\Session\Middleware\StartSession::class,
        \Illuminate\View\Middleware\ShareErrorsFromSession::class,
        \Imunew\JWTAuth\Middleware\RefreshJwtToken::class,
        \App\Http\Middleware\Authenticate::class,
        \Illuminate\Routing\Middleware\ThrottleRequests::class,
        \Illuminate\Session\Middleware\AuthenticateSession::class,
        \Illuminate\Routing\Middleware\SubstituteBindings::class,
        \Illuminate\Auth\Middleware\Authorize::class,
    ];

// App\Http\Kernel

    protected $middlewareGroups = [
        'web' => [
            // ...
        ],

        'api' => [
            'throttle:60,1',
            \Illuminate\Routing\Middleware\SubstituteBindings::class,
            \Imunew\JWTAuth\Middleware\RefreshJwtToken::class,
        ]
    ];
bash
$ php artisan vendor:publish --provider="Imunew\JWTAuth\Providers\ServiceProvider"