mercredi 30 septembre 2015

Laravel Refreshing JWT tokens

I have a small Lumen / Laravel app that is just used as an API. I am able to sign in and set JWT tokens but after a period of time they timeout, I was expecting them to refresh each time an Endpoint was hit.

I've been looking at the docs for Tymon's JWT-AUTH but I cannot seem to get it to work.

Below is an example of one of my end points which return an array of all the users in the db. But when the token timesout the endpoint returns the error You don't have previleges to view all users

I'd be very grateful if someone was able to advise me or show me how to make my code refresh a token when someone is hitting an endpoint.

Inside Controller

public function index(Request $request)
    {

        $user = JWTAuth::parseToken()->authenticate();

        if(! $user->isAdmin() ) {
            return $this->error_respond(['error' => "You don't have previleges to view all users"]);
        }

        $users = $this->repository->findAllWithPlan();
        return $this->respond(['users' => $users]);
     }

Inside Routes.php

$app->group(['middleware' => 'jwt.auth'], function ($app) {


            /**
             * Show All users
             */
            $app->get('users', ['as' => 'user.all', 'middleware' => 'cors', 'uses' => 'App\Http\Controllers\UserController@index']);



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1N0lbg8
via IFTTT

Aucun commentaire:

Enregistrer un commentaire