summaryrefslogtreecommitdiff
path: root/app/controllers/services/token_generation_service.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/controllers/services/token_generation_service.rb')
-rw-r--r--app/controllers/services/token_generation_service.rb13
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