Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/434 bearer authentication #435

Merged
merged 12 commits into from
Jul 3, 2023
15 changes: 14 additions & 1 deletion core/app/controllers/concerns/uffizzi_core/auth_management.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,20 @@ def signed_in?
end

def current_user
@current_user ||= UffizziCore::User.find_by(id: session[:user_id])
@current_user ||= UffizziCore::User.find_by(id: current_user_id)
end

def auth_token
header = request.headers['Authorization']
header&.split(' ')&.last
end

def current_user_id
return session[:user_id] if session[:user_id].present?
return unless auth_token.present?

decoded_token = UffizziCore::TokenService.decode(auth_token)
decoded_token&.first&.dig('user_id')
end

def authenticate_request!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ def domain_module
module_class(:domain_module)
end

def access_token_module
return unless module_exists?(:token_module)

module_class(:token_module)
end

private

def module_exists?(module_name)
Expand Down