Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/controllers/api/v1/sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ def refresh
if current_user.present?
token = payload(current_user)
set_response_cookie(token)
participants = adminset_permissions(user)
user_type = user_roles(user)
participants = adminset_permissions(current_user)
user_type = user_roles(current_user)
render json: current_user.slice(:email).merge({participants: participants, type: user_type })
else
user_error
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
module Ubiquity
module DeviseHykuApiSessionIntegration
extend ActiveSupport::Concern

included do
after_action :set_api_token , only: [:create]
after_action :clear_jwt_token, only: [:destroy]
end

private

def set_api_token
shared_login = helpers.check_for_setting_value_in_tenant_settings("shared_login")
if current_user && shared_login.present?
expire = 1.hour.from_now
token = Ubiquity::Api::JwtGenerator.encode({id: current_user.id, exp: expire})
domain = ('.' + request.host)

response.set_cookie(
:jwt,
{
value: token, expires: expire, path: '/', same_site: :none,
domain: domain, secure: true, httponly: true
}
)
end
end

def clear_jwt_token
shared_login = helpers.check_for_setting_value_in_tenant_settings("shared_login")
if shared_login.present?
domain = ('.' + request.host)
response.set_cookie(
:jwt,
{
value: '', expires: 10000.hours.ago, path: '/', same_site: :none,
domain: domain, secure: true, httponly: true
}
)
end
end

end
end
1 change: 1 addition & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class Application < Rails::Application
Hyrax::UsersController.include(::Ubiquity::UserShowConcern)
Hyrax::WorksControllerBehavior.prepend(::Ubiquity::WorksControllerBehaviourOverride)
Hyrax::FileSetsController.prepend(::Ubiquity::FileSetsControllerOverride)
Devise::SessionsController.include(::Ubiquity::DeviseHykuApiSessionIntegration)
end

config.before_initialize do
Expand Down