{"action":"created","issue":{"url":"https://api.github.com/repos/tymondesigns/jwt-auth/issues/127","labels_url":"https://api.github.com/repos/tymondesigns/jwt-auth/issues/127/labels{/name}","comments_url":"https://api.github.com/repos/tymondesigns/jwt-auth/issues/127/comments","events_url":"https://api.github.com/repos/tymondesigns/jwt-auth/issues/127/events","html_url":"https://github.com/tymondesigns/jwt-auth/issues/127","id":81432899,"number":127,"title":"Using refresh middleware, token is invalid","user":{"login":"mattmcdonald-uk","id":1255436,"avatar_url":"https://avatars.githubusercontent.com/u/1255436?v=3","gravatar_id":"","url":"https://api.github.com/users/mattmcdonald-uk","html_url":"https://github.com/mattmcdonald-uk","followers_url":"https://api.github.com/users/mattmcdonald-uk/followers","following_url":"https://api.github.com/users/mattmcdonald-uk/following{/other_user}","gists_url":"https://api.github.com/users/mattmcdonald-uk/gists{/gist_id}","starred_url":"https://api.github.com/users/mattmcdonald-uk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mattmcdonald-uk/subscriptions","organizations_url":"https://api.github.com/users/mattmcdonald-uk/orgs","repos_url":"https://api.github.com/users/mattmcdonald-uk/repos","events_url":"https://api.github.com/users/mattmcdonald-uk/events{/privacy}","received_events_url":"https://api.github.com/users/mattmcdonald-uk/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":8,"created_at":"2015-05-27T12:49:22Z","updated_at":"2015-06-03T09:49:22Z","closed_at":null,"body":"On my route I'm using the jwt.refresh middleware.\r\n\r\nI set the ttl to 1 to make sure refresh was working correctly, and encountered an issue.\r\n\r\nWhen I try to get the current user (JWTAuth::parseToken() -> toUser()) in my controller, because the token hasn't yet been refreshed the token is invalid and it throws an exception.\r\n\r\nAnother issue I encountered here was that instead of it throwing an exception that I could catch, it seems to throw an exception I can't catch - not sure why. But my error log shows: local.ERROR: exception 'Tymon\\JWTAuth\\Exceptions\\TokenExpiredException' with message 'Token has expired\r\n\r\nAttempts to catch TokenExpiredException don't work.\r\n\r\nThis issue occurs in 0.5.3 and in the latest dev version.\r\n\r\nMy workaround has been to modify RefreshToken so that the token is refresh before calling $next. Not sure whether this is a correct fix, or whether this might have an unwanted impact elsewhere."},"comment":{"url":"https://api.github.com/repos/tymondesigns/jwt-auth/issues/comments/108278003","html_url":"https://github.com/tymondesigns/jwt-auth/issues/127#issuecomment-108278003","issue_url":"https://api.github.com/repos/tymondesigns/jwt-auth/issues/127","id":108278003,"user":{"login":"mattmcdonald-uk","id":1255436,"avatar_url":"https://avatars.githubusercontent.com/u/1255436?v=3","gravatar_id":"","url":"https://api.github.com/users/mattmcdonald-uk","html_url":"https://github.com/mattmcdonald-uk","followers_url":"https://api.github.com/users/mattmcdonald-uk/followers","following_url":"https://api.github.com/users/mattmcdonald-uk/following{/other_user}","gists_url":"https://api.github.com/users/mattmcdonald-uk/gists{/gist_id}","starred_url":"https://api.github.com/users/mattmcdonald-uk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mattmcdonald-uk/subscriptions","organizations_url":"https://api.github.com/users/mattmcdonald-uk/orgs","repos_url":"https://api.github.com/users/mattmcdonald-uk/repos","events_url":"https://api.github.com/users/mattmcdonald-uk/events{/privacy}","received_events_url":"https://api.github.com/users/mattmcdonald-uk/received_events","type":"User","site_admin":false},"created_at":"2015-06-03T09:49:22Z","updated_at":"2015-06-03T09:49:22Z","body":"@osteel But I'm just using a single middleware. I originally presumed both middleware should be used together - but then they're an either/or. Happy for them to be either/or - BUT even when using just the RefreshToken middleware, there's a problem because it's not refreshing the token until after your controller logic has run.\r\n\r\nSo the flow that I presume should be there (and the way I've modified it to work for me for now) is to re-arrange the RefreshToken middleware so that `$response = $next($request);` is called after the token has been refreshed."}}