title: Laravel 8 with external UserProvider and JWT: Unauthenticated
body: <p>I have tried to combine JWT custom UserProvider. Users are stored in external DB, accessed with API.</p>
  <p><em>config/auth.php</em></p>
  <pre><code>   'defaults' =&gt; [
          'guard' =&gt; 'api',
          'passwords' =&gt; 'users',
      ],
     'guards' =&gt; [
          'web' =&gt; [
              'driver' =&gt; 'jwt',
              'provider' =&gt; 'shopAPI',
          ],
          'api' =&gt; [
              'driver' =&gt; 'jwt',
              'provider' =&gt; 'shopAPI',
          ],
      ],
      'providers' =&gt; [
          'shopAPI' =&gt; [
              'driver' =&gt; 'shopAPI',
          ],
      ],
  </code></pre>
  <p><em>routes/api.php</em></p>
  <pre><code>Route::group([
      'middleware' =&gt; 'api',
  ], function ($router) {
      Route::post('login', [AuthController::class, 'login']);
      Route::post('me', [AuthController::class, 'me']);
  });
  </code></pre>
  <p><em>app/Http/Controllers/AuthController.php</em></p>
  <pre><code>
  namespace App\Http\Controllers;
  use Illuminate\Http\Request;
  use Illuminate\Support\Facades\Auth;
  
  class AuthController extends Controller
  {
      public function __construct()
      {
          $this-&gt;middleware('auth:api', ['except' =&gt; 'login']);
      }
  
      /**
       * Get the guard to be used during authentication.
       *
       * @return \Illuminate\Contracts\Auth\Guard
       */
      public function guard()
      {
          return Auth::guard();
      }
  
      /**
       * @param  Request  $request
       *
       * @return \Illuminate\Http\JsonResponse
       * @throws \Illuminate\Validation\ValidationException
       */
      public function login(Request $request) {
          $credentials = $request-&gt;only('login', 'password');
  
          if ($token = $this-&gt;guard()-&gt;attempt($credentials)) {
              return $this-&gt;respondWithToken($token);
          }
  
          return response()-&gt;json(['error' =&gt; 'Unauthorized'], 401);
      }
  
  
      /**
       * Get the token array structure.
       *
       * @param  string $token
       *
       * @return \Illuminate\Http\JsonResponse
       */
      protected function respondWithToken($token){
          return response()-&gt;json([
              'access_token' =&gt; $token,
              'token_type' =&gt; 'bearer',
              'expires_in' =&gt; $this-&gt;guard()-&gt;factory()-&gt;getTTL() * 60,
              'user' =&gt; $this-&gt;guard()-&gt;user()
          ]);
      }
  
      public function me()
      {
          return response()-&gt;json($this-&gt;guard()-&gt;user());
      }
  
  }
  </code></pre>
  <p>Getting user from API is OK because I always get success on authorization and <code>$this-&gt;guard()-&gt;user()</code> inside <code>responseWithToken()</code> returns correct data. I use postman to test it and when I post <em>access_token</em> in <code>me</code> request then I get <strong>Unauthenticated</strong></p>
  <pre><code>Content-Type: application/json
  X-Requested-With: XMLHttpRequest
  Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczpcL1wvc2hvcC5sb2NhbFwvYXBpXC9sb2dpbiIsImlhdCI6MTYzNDIxODU1MywiZXhwIjoxNjM0MjIyMTUzLCJuYmYiOjE2MzQyMTg1NTMsImp0aSI6IkFIbHU0SHkxcHI3UGNKakQiLCJzdWIiOm51bGwsInBydiI6IjZiMjQ5ZWRhMDQ1YmUwMmJhNWRkMDU1Nzc1NTM0Y2QyYzMxOTE4MzIifQ.pZVfvIddxIpcjlmkk-xYrLPWdt_zON0eTN_oiZHWeK0
  User-Agent: PostmanRuntime/7.28.4
  </code></pre>
  <p>Did I miss something?</p>