module Henlo::Refreshable

Module for generating refresh tokens

Public Class Methods

generate_refreshable(options={}) click to toggle source

Generate refreshable token with a unix time for expiry, the type of token and the jwt identifier (a random string) encoded in the payload in addition to whatever was passed as payload when `generate_henlos` was called

# File lib/henlo/refreshable.rb, line 12
def self.generate_refreshable(options={})
  claim = options || nil 
  
  claim.merge!({
    exp: Time.now.utc.to_i + Henlo.refresh_token_lifetime, 
    jti: Henlo::Helpers::Util.generate_jti,
    type: "refresh"
  })
  
  Hash[
    token: Knock::AuthToken.new(payload: claim).token, 
    jti: claim[:jti]       
  ]
end
store_jti(resource, jti) click to toggle source

Store jwt identifier in the app's database, in the table of the resource

# File lib/henlo/refreshable.rb, line 29
def self.store_jti(resource, jti)
  resource.update_attribute(:refresh_token_jti, jti)
end