lundi 29 août 2016

Laravel - JWT Auth The token could not be parsed from the request

I have added following code in my middleware for user authentication with JWT Auth, which works fine for all the routes handled by the middleware.

public function handle($request, Closure $next)
{
    if ($request->has('token')) {
        try {
            $this->auth = JWTAuth::parseToken()->authenticate();
            return $next($request);
        } catch (JWTException $e) {
            return redirect()->guest('user/login');
        }
    }
}

But for one route with Post Method where the token is getting passed properly but still I am getting JWTException - The token could not be parsed from the request, on the same route when I tried

public function handle($request, Closure $next)
{
    if ($request->has('token')) {
        try {
            dd($request->input('token'));
            $this->auth = JWTAuth::parseToken()->authenticate();
            return $next($request);
        } catch (JWTException $e) {
            return redirect()->guest('user/login');
        }
    }
}

output:

"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9iaXNzIjoiaHR0cDpcL1wvbG9jYWxob3N0OjgwMDFcL2F1dGhcL2xvZ2luIiwiaWF0IjoxNDcyNTI4NDU0LCJleHAiOjE0NzI1MzIwNTQsIm5iZiI6MTQ3MjUyODQ1NCwianRpIjoiM2E0M2ExYTZlNmM5NjUxZDgxYjZhNDcxMzkxODJlYjAifQ.CH8ES2ADTCrVWeIO8uU31bGDnH7h-ZVTWxrdXraLw8s"

I am able to see the Valid Token which I am using to access another routes and which is working flawlessly for all other routes.

Thanks in advance!!!



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

Aucun commentaire:

Enregistrer un commentaire