title: Laravel Passport - Passing access token to requests
body: <p>I'm working with Laravel Passport for the first time. I'm building an API that will be consumed by a mobile application.</p>
  
  <p>For the authentication, this is what i'm doing:</p>
  
  <pre><code>public function login(Request $request)
  { 
      $loginData = Validator::make($request-&gt;all(), [
          'email' =&gt; 'required|email',
          'password' =&gt; 'required',
      ]);
  
      if( $loginData-&gt;fails() )
      {
          return response()-&gt;json(['error' =&gt; $loginData-&gt;errors()], 401);
      }
  
      if( Auth::attempt(['email' =&gt; request('email'), 'password' =&gt; request('password')]) )
      { 
          $data = [
              'grant_type' =&gt; 'password',
              'client_id' =&gt; $this-&gt;client-&gt;id,
              'client_secret' =&gt; $this-&gt;client-&gt;secret,
              'username' =&gt; $request-&gt;email,
              'password' =&gt; $request-&gt;password,
              'scope' =&gt; '',
          ];
  
          $request = Request::create('/oauth/token', 'POST', $data);
          return app()-&gt;handle($request);
      } 
      else
      { 
          return response()-&gt;json(['error' =&gt; 'Invalid credentials'], 401); 
      } 
  }
  </code></pre>
  
  <p>Successful login returns the access token as such:</p>
  
  <pre><code>{
  "token_type": "Bearer",
  "expires_in": 31622400,
  "access_token": "access_token",
  "refresh_token": "refresh_token"
  }
  </code></pre>
  
  <p>Now the aim is to use this access token by passing it to the header of all routes that need authentication.</p>
  
  <p>For example in my <code>routes/api.php</code> file, i have this route:</p>
  
  <pre><code>Route::post('/login', 'API\AuthController@login');
  Route::apiResource('/tasks', 'API\TaskController')-&gt;middleware('auth:api');
  </code></pre>
  
  <p>In my <code>TaskController</code>, all the methods in it need to be passed a header that contains the access token so as to authenticate the request. This is where my question is. I can't seem to find a resource so far that explains how to do this. So in every request i need to pass something like this to the header of the request:</p>
  
  <pre><code>Accept: application/json
  Authorization: Bearer access_token
  </code></pre>
  
  <p>This is my <code>TaskController</code> <code>index</code> method. How do i pass the access token in here?</p>
  
  <pre><code>public function index()
  {
      //how do i capture the access token in here so that i can pass it to the request header?
      return TaskResource::collection(auth()-&gt;user()-&gt;tasks()-&gt;latest()-&gt;paginate(4));
  }
  </code></pre>
  
  <p>Is there a default Passport method that can be used to pass the access token to required requests or how can it be done?</p>