I have been using the devise gem with rails to implement user authentication for may applications. When implementing authentication though API requests, then I turn to the devise-jwt gem. I faced an issue when implementing refresh tokens with devise, as devise does not support access tokens. I still needed the superior authentication that devise provides, but needed to manually work with fresh tokens. After looking around the web, here is how I was able to modify the code to implement refresh tokens with devise-jwt.
Take for the example a user model to sore the user email and password.
I created a blacklist model that will hold information of refresh tokens that have been decoded.
I generated refresh tokens with the generate_refresh_token method in the user module example below. I also added a decode frefresh token method as a class method on the user class, this will decode a refresh token passed and return the user object.
I created a refresh_tokens controller that will return an access token and refresh token as header values once accesed.
In the refresh token controller, I included the include Devise::Controllers::Helpers
helper in the refresh token controller.
This allows me to access the sing_in method provided by devise.