Module: Henlo::Refreshable

Defined in:
lib/henlo/refreshable.rb

Overview

Module for generating refresh tokens

Class Method Summary collapse

Class Method Details

.generate_refreshable(options = {}) ⇒ Object

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



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# 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) ⇒ Object

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



29
30
31
# File 'lib/henlo/refreshable.rb', line 29

def self.store_jti(resource, jti)
  resource.update_attribute(:refresh_token_jti, jti)
end