rluders / wn-jwtauth-plugin

JWTAuth Plugin for WinterCMS
GNU General Public License v3.0
29 stars 28 forks source link

Refresh Token #2

Closed rluders closed 5 years ago

rluders commented 5 years ago

The endpoint /refresh-token is returning this error.

A token is required
/var/www/public/plugins/rluders/jwtauth/vendor/tymon/jwt-auth/src/JWT.php line 331
khorashadi666 commented 5 years ago

hi I posted 4 requests for you. Next in the JWT class, do the following:

1- public function refresh($token = false, $forceForever = false, $resetClaims = false) {
$this->requireToken($token);
return $this->manager->customClaims($this->getCustomClaims()) ->refresh($this->token, $forceForever, $resetClaims) ->get(); }

2- protected function requireToken($token = false) { if ($token) { return $this->setToken($token); } elseif (! $this->token) { throw new JWTException('A token is required', 400); } }

rluders commented 5 years ago

Hey, @khorashadi666

Thank you. I'll test and review your PR this weekend. But, so far, looks good.

rluders commented 5 years ago

@khorashadi666 looks like your commit didn't solve the issue. I tested it and it is returning the following error:

image

The CURL request that I used to test it:

curl -X POST \
  http://octobercms.localhost/api/auth/refresh-token \
  -H 'Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC9vY3RvYmVyY21zLmxvY2FsaG9zdFwvYXBpXC9hdXRoXC9sb2dpbiIsImlhdCI6MTU0MDY0ODkzOSwiZXhwIjoxNTQwNjUyNTM5LCJuYmYiOjE1NDA2NDg5MzksImp0aSI6IkE5M3JqNEpsUEFZdWpHQWYiLCJzdWIiOjEsInBydiI6IjQxMWM5MTdhMGZiNTFlMGE0MjdhN2UzZGVhYTVhNDllMjkyZGRiOWIifQ.UGZvkAqqwWT4-oRUxIFinlNJ-2E8lI8bON7-AtLDKdo' \
  -H 'Cache-Control: no-cache' \
  -H 'Postman-Token: 6cdface7-2824-4b71-8389-f4a33d171345' \
  -H 'content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW' \
  -F token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC9vY3RvYmVyY21zLmxvY2FsaG9zdFwvYXBpXC9hdXRoXC9sb2dpbiIsImlhdCI6MTU0MDY0ODkzOSwiZXhwIjoxNTQwNjUyNTM5LCJuYmYiOjE1NDA2NDg5MzksImp0aSI6IkE5M3JqNEpsUEFZdWpHQWYiLCJzdWIiOjEsInBydiI6IjQxMWM5MTdhMGZiNTFlMGE0MjdhN2UzZGVhYTVhNDllMjkyZGRiOWIifQ.UGZvkAqqwWT4-oRUxIFinlNJ-2E8lI8bON7-AtLDKdo

Any idea?

SebastiaanKloos commented 5 years ago

For some reason the JWT library can't find the token in the request. Quick fix for this will be to add the following on line 368 in the rluders/jwtauth/http/controllers/AuthController.php:

$this->auth->setToken(input('token'));
rluders commented 5 years ago

I'll try to investigate this issue a little bit more before the end of this year...

rluders commented 5 years ago

Fixed with https://github.com/rluders/oc-jwtauth-plugin/commit/220501d2ee7c4b7d5d1f864ffe90a7919c507a1d