Skip to content

Instantly share code, notes, and snippets.

View ps-ruby's full-sized avatar
💭
I may be slow to respond.

Prakash Sanyasi ps-ruby

💭
I may be slow to respond.
  • JTF
  • Thimphu, Bhutan
View GitHub Profile
@jesster2k10
jesster2k10 / README.md
Last active February 11, 2025 17:25
JWT Auth + Refresh Tokens in Rails

JWT Auth + Refresh Tokens in Rails

This is just some code I recently used in my development application in order to add token-based authentication for my api-only rails app. The api-client was to be consumed by a mobile application, so I needed an authentication solution that would keep the user logged in indefinetly and the only way to do this was either using refresh tokens or sliding sessions.

I also needed a way to both blacklist and whitelist tokens based on a unique identifier (jti)

Before trying it out DIY, I considered using:

# config/routes.rb
resources :documents do
scope module: 'documents' do
resources :versions do
post :restore, on: :member
end
resource :lock
end
end