Module: Wor::Authentication::SessionsController
- Defined in:
- lib/wor/authentication/sessions_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #generate_access_token(entity) ⇒ Object
- #invalidate_all ⇒ Object
- #renew ⇒ Object
- #renew_access_token(entity) ⇒ Object
Instance Method Details
#create ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 |
# File 'lib/wor/authentication/sessions_controller.rb', line 4 def create entity = authenticate_entity(authenticate_params) if entity token_data = generate_access_token(entity) render json: { access_token: token_data[:token], renew_id: token_data[:renew_id] }, status: :ok else render_error('Invalid authentication credentials', :unauthorized) end end |
#generate_access_token(entity) ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/wor/authentication/sessions_controller.rb', line 31 def generate_access_token(entity) renew_id = token_renew_id payload = entity_payload(entity).merge( entity_custom_validation: entity_custom_validation_value(entity), expiration_date: new_token_expiration_date, maximum_useful_date: token_maximum_useful_date, renew_id: renew_id ) access_token_object(token_key, payload, renew_id) end |
#invalidate_all ⇒ Object
24 25 26 27 28 29 |
# File 'lib/wor/authentication/sessions_controller.rb', line 24 def invalidate_all # should we rescue anything here ? # if invalidating uses db and fails, or something like that entity_custom_validation_invalidate_all_value(current_entity) head :ok end |
#renew ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/wor/authentication/sessions_controller.rb', line 16 def renew if !decoded_token.valid_renew_id?(renew_token_params[:renew_id]) render_error('Invalid renew_id', :unauthorized) else render json: { access_token: renew_access_token(current_entity) }, status: :ok end end |
#renew_access_token(entity) ⇒ Object
42 43 44 45 46 47 |
# File 'lib/wor/authentication/sessions_controller.rb', line 42 def renew_access_token(entity) payload = decoded_token.payload payload[:expiration_date] = new_token_expiration_date payload[:entity_custom_validation] = entity_custom_validation_renew_value(entity) Wor::Authentication::TokenManager.new(token_key).encode(payload) end |