title: Set Expiry time for laravel passport
body: <p>so i am using password grant access using laravel passport to make my backend (laravel) work with vue.js, i finally can make the authentication works thanks to this <a href="http://voerro.com/blog/building-spas-with-laravel-5.5-and-vue.js-2-pt.4" rel="nofollow noreferrer">awesome tutorial</a> but i just don't like the way he handle the token, he save the token to the browser local storage and don't provide a way to make the token expired (ask for login) even when i close the browser.</p>
  
  <p>What i want is a way to make the application to ask for login again after a few minutes off idle (no get or post to the backend) and when the user close the browser (not the tab) then when the user open browser again then need to reenter login data (username and password)</p>
  
  <p>so here is how i handle the way it works according to the tutorial</p>
  
  <p>first this is my login function on AuthController</p>
  
  <pre><code>public function login()
  {
      // check username
      $user = User::where('username',request('username'))-&gt;first();
      if (!$user) {
          return response()-&gt;json([
              'message' =&gt; 'Maaf username salah.',
              'status' =&gt; 422
          ], 422);
      }
  
      // check password
      if (!Hash::check(request('password'), $user-&gt;password)) {
          return response()-&gt;json([
              'message' =&gt; 'Maaf password salah.',
              'status' =&gt; 422
          ], 422);
      }
  
      Auth::attempt(array('username' =&gt; request('username'), 'password' =&gt; request('password')));
  
      $client = DB::table('oauth_clients')
          -&gt;where('password_client', true)
          -&gt;first();
  
      if (!$client) {
          return response()-&gt;json([
                  'message' =&gt; 'Maaf terjadi kesalahan konfigurasi.',
                  'status' =&gt; 500
          ], 500);
      }   
  
      // Send an internal API request to get an access token
      $data = [
          'grant_type' =&gt; 'password',
          'client_id' =&gt; $client-&gt;id,
          'client_secret' =&gt; $client-&gt;secret,
          'username' =&gt; request('username'),
          'password' =&gt; request('password'),
      ];
  
      $request = Request::create('/oauth/token', 'POST', $data);
  
      $response = app()-&gt;handle($request);
  
      // Check if the request was successful
      if ($response-&gt;getStatusCode() != 200) {
          return response()-&gt;json([
              'message' =&gt; 'Maaf terjadi kesalahan login, mohon ulangi lagi.',
              'status' =&gt; 422
          ], 422);
      }
  
      // Get the data from the response
      $data = json_decode($response-&gt;getContent());
  
      // Format the final response in a desirable format
      return response()-&gt;json([
          'token' =&gt; $data-&gt;access_token,
          'user' =&gt; $user,
          'status' =&gt; 200
          ], 200);
  
  }
  </code></pre>
  
  <p>and then on the frontend (vuejs) i create this function on auth.js files to take the returned <code>access_token</code> and store it into local storage</p>
  
  <pre><code>login (token, user) {        
    window.localStorage.setItem('token', token);
  
    axios.defaults.headers.common['Authorization'] = 'Bearer ' + token;
  
    this.token = token;
  
    Event.$emit('userLoggedIn');
  }
  </code></pre>
  
  <p>next for verifying the user each request then there is check function on auth.js file</p>
  
  <pre><code>check () {
    return !! this.token;
  }
  </code></pre>
  
  <p>and on app.js i call this <code>check()</code> function inside <code>router.beforeEach</code></p>
  
  <pre><code>router.beforeEach((to, from, next) =&gt; {
      window.scrollTo(0, 0);
      if (to.matched.some(record =&gt; record.meta.loggedIn)) {         
          if (!auth.check()) {
                  next({
                          path: '/login',
                          query: { redirect: to.fullPath }
                  });
                  return;
          }
      }
      if (to.matched.some(record =&gt; record.meta.notLoggedIn)) {         
          if (auth.check()) {
                  next({
                          path: '/'
                  });
                  return;
          }
      }
      next();
  });
  </code></pre>