samedi 27 mai 2017

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

i am facing the JWT error which says "'The token could not be parsed from the request"

  exception 'Tymon\JWTAuth\Exceptions\JWTException' with message 'The token could not be parsed from the request' in F:\Projectname\web\vendor\tymon\jwt-auth\src\JWTAuth.php:204

My jwt auth file :

 /**
     * Parse the token from the request.
     *
     * @param string $query
     *
     * @return JWTAuth
     */
    public function parseToken($method = 'bearer', $header = 'authorization', $query = 'token')
    {
        if (! $token = $this->parseAuthHeader($header, $method)) {
            if (! $token = $this->request->query($query, false)) {
               //error is on this line  throw new JWTException('The token could not be parsed from the request', 400);
            }
        }

        return $this->setToken($token);
    }

    /**
     * Parse token from the authorization header.
     *
     * @param string $header
     * @param string $method
     *
     * @return false|string
     */
    protected function parseAuthHeader($header = 'authorization', $method = 'bearer')
    {
        $header = $this->request->headers->get($header);

        if (! starts_with(strtolower($header), $method)) {
            return false;
        }

        return trim(str_ireplace($method, '', $header));
    }

i had tried to include the following lines in my httpd.conf file of xamp - apache

DocumentRoot "C:/xampp/htdocs"
<Directory "C:/xampp/htdocs">
    #
    # Possible values for the Options directive are "None", "All",
    # or any combination of:
    #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
    #
    # Note that "MultiViews" must be named *explicitly* --- "Options All"
    # doesn't give it to you.
    #
    # The Options directive is both complicated and important.  Please see
    # http://ift.tt/1a2wcFq
    # for more information.
    #
    Options Indexes FollowSymLinks Includes ExecCGI

    #
    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be "All", "None", or any combination of the keywords:
    #   AllowOverride FileInfo AuthConfig Limit
    #
    AllowOverride All

    #
    # Controls who can get stuff from this server.
    #
    Allow from all
RewriteEngine On
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule .* - [e=HTTP_AUTHORIZATION:%1]
</Directory>

Also, i have CORS enabled in my chrome.

Please my cors.php is below :

return [
    /*
      |--------------------------------------------------------------------------
      | Laravel CORS
      |--------------------------------------------------------------------------
      |

      | allowedOrigins, allowedHeaders and allowedMethods can be set to array('*')
      | to accept any value.
      |
     */
    'supportsCredentials' => true,
    'allowedOrigins' => ['http://192.168.0.2:8080'],
    'allowedHeaders' => ['*'],
    'allowedMethods' => ['*'],
    'exposedHeaders' => [],
    'maxAge' => 3600,
    'hosts' => [],
];

how do i solve this error ??

Using : Laravel version 5.2.43



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

Aucun commentaire:

Enregistrer un commentaire