diff options
author | HombreLaser <sebastian-440@live.com> | 2023-03-03 20:34:06 -0600 |
---|---|---|
committer | HombreLaser <sebastian-440@live.com> | 2023-03-03 20:34:06 -0600 |
commit | 41a17f47ae275f8e84de03115e142cc23526bacc (patch) | |
tree | 2fb62f78685698a7c55bf5cff8456d24b7a78361 /app/controllers/services/token_generation_service.rb | |
parent | 094ee717f710ea4cf81d221c5bf9660b805da9b1 (diff) |
Añade refactorizaciones
Diffstat (limited to 'app/controllers/services/token_generation_service.rb')
-rw-r--r-- | app/controllers/services/token_generation_service.rb | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/app/controllers/services/token_generation_service.rb b/app/controllers/services/token_generation_service.rb index 94f9907..8edce9c 100644 --- a/app/controllers/services/token_generation_service.rb +++ b/app/controllers/services/token_generation_service.rb @@ -6,17 +6,22 @@ module Services def initialize(params) @email = params[:email] @role = params[:role] - @session_key = params[:session_key] + @user_account = UserAccount.find_by(email: @email) end - def call(expiration) - JWT.encode(payload.merge({ exp: expiration.to_i }), ENV['HMAC_SECRET_KEY'], 'HS512') + def call(refresh_token_expiration) + @user_account.update_attribute(:session_key, SecureRandom.hex(16)) + { token: generate_token(DateTime.current + 30.minutes), refresh: generate_token(refresh_token_expiration.to_i) } end private + def generate_token(expiration) + JWT.encode(payload.merge({ exp: expiration.to_i }), ENV['HMAC_SECRET_KEY'], 'HS512') + end + def payload - { data: @email, aud: @role, jti: @session_key } + { data: @email, aud: @role, jti: @user_account.session_key } end end end |