krisanalfa / lumen-jwt

Lumen with JWT Authentication, Dingo API and CORS Support
258 stars 80 forks source link

How to refresh token? #33

Closed pmventura closed 7 years ago

pmventura commented 7 years ago

@krisanalfa I tried access to access api/auth/refresh from Postman collection you provided. But it says "Token has expired". Do I still need to configure something?

krisanalfa commented 7 years ago

Could you please copy-paste your cURL request + response here?

pmventura commented 7 years ago

Here it is man @krisanalfa

screen shot 2017-05-31 at 3 46 06 pm
krisanalfa commented 7 years ago

Have you done any authentication request before accessing refresh endpoint?

pmventura commented 7 years ago

@krisanalfa Yes. Else, i will be receiving different error if not authenticated right?

I've tried to take out this route outside the middleware and it works fine. But will it be the best practice?

$api->patch('/auth/refresh', [ 'uses' => 'App\Http\Controllers\Auth\AuthController@patchRefresh', 'as' => 'api.auth.refresh']);

krisanalfa commented 7 years ago

No. You should use auth middleware for refresh endpoint. Because any refreshed token should be a valid token, it represents a single session for a user. Mine is working here.

After you logged in, can you access /api/auth/user endpoint?

pmventura commented 7 years ago

Yeah, all endpoints are working fine so long as token still valid. But the moment it expired, I can't able to refresh the token.

pmventura commented 7 years ago

Let me know if you want the steps to reproduce this

pmventura commented 7 years ago

@krisanalfa does the refresh endpoint is working on your end when you pass an expired token?

krisanalfa commented 7 years ago

No. Refreshed token should be a valid token. Which is expired token would be rejected.

pmventura commented 7 years ago

Hmm, i see. But I believe you don't want the user to re-authenticate(bring back to login) if the token expired right? Should just refresh and you'll get a new access token.

krisanalfa commented 7 years ago

Yeah, you need to re-login before refreshing the token (only if you got token expired).