Class: TokenHash
- Inherits:
-
Object
- Object
- TokenHash
- Defined in:
- lib/generators/horse_power/user/templates/tokenhash.rb
Class Method Summary collapse
- .decode(params, request) ⇒ Object
-
.encode(auth_token_hash, user_id) ⇒ Object
Ideally, the expiration for the jwt token would be less than the db token, and we would return a new jwt token to the user if the current jwt token expired but the db token was not yet expired.
Class Method Details
.decode(params, request) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/generators/horse_power/user/templates/tokenhash.rb', line 17 def self.decode(params,request) instance_hash = nil auth_token_obj = ::Arcadex::Header.grab_param_header(params,request,::Settings.token_header,false) begin # Try JWT token jwt = ::JWT.decode(auth_token_obj,::Rails.application.secrets.secret_key_base) token = jwt[0] user = ::User.find_by(id: token["user_id"]) instance_hash = {} instance_hash["current_owner"] = user instance_hash["current_token"] = nil instance_hash["auth_token"] = token["auth_token"] return instance_hash rescue ::JWT::DecodeError, ::JWT::ExpiredSignature # Try Arcadex token instance_hash = ::Arcadex::Authentication.get_instance(params,request,::Settings.token_header) if !instance_hash.nil? instance_hash["auth_token"] = nil end return instance_hash end end |
.encode(auth_token_hash, user_id) ⇒ Object
Ideally, the expiration for the jwt token would be less than the db token, and we would return a new jwt token to the user if the current jwt token expired but the db token was not yet expired.
9 10 11 12 13 14 15 |
# File 'lib/generators/horse_power/user/templates/tokenhash.rb', line 9 def self.encode(auth_token_hash,user_id) obj = {} obj["auth_token"] = auth_token_hash obj["user_id"] = user_id obj["exp"] = ::Time.now.to_i() + ::Settings.expire_time*60 return ::JWT.encode(obj,::Rails.application.secrets.secret_key_base) end |