2

I am authenticating users with JWTAuth OctoberCMS API plugin. When I register user or login with postman, the request return a token. However when I try to access authenticated routes like:

Route::get('api/v1/todos',
    'Wafush\Maswali\Controllers\Todos@index')->middleware('\Tymon\JWTAuth\Middleware\GetUserFromToken');

I am getting {"error":"token_not_provided"} exception yet the user is authenticated.

Again when I attempt to return signed in user object like:

$user = JWTAuth::authenticate();
        return $user;

I get the following error:

A token is required
C:\xampp\htdocs\myapp\plugins\vdomah\jwtauth\vendor\tymon\jwt-auth\src\JWTAuth.php line 299

Type
Undefined

Exception
Tymon\JWTAuth\Exceptions\JWTException

    {
        if ($token) {
            return $this->setToken($token);
        } elseif ($this->token) {
            return $this;
        } else {
            throw new JWTException('A token is required', 400);
        }
    }

    /**
     * Set the request instance.
     *

What I am missing. Kindly guide. Its like the token is not getting set.

wafutech
  • 481
  • 10
  • 30

1 Answers1

2

I got to your question because I was facing the same problem and I've just solved it by adding below code to my .htaccess

# Authorization header
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule .* - [e=HTTP_AUTHORIZATION:%1]
Susana Santos
  • 312
  • 1
  • 6
  • 18
  • Found a one-liner: ```# make Authorization header available in october Request headers RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] ``` – psycho brm Jul 15 '18 at 22:51
  • Hi! I think october is blocking all PHP files so the token is not work in the system. so write a couple of lines in htdocs file. so the authorization header is allow token. RewriteCond %{HTTP:Authorization} ^(.*) RewriteRule .* - [e=HTTP_AUTHORIZATION:%1] – Kaushik shrimali Apr 29 '19 at 10:21