Make API key auth togglable [SCI-6968]

This commit is contained in:
Martin Artnik 2024-05-24 14:55:48 +02:00
parent 2781295325
commit eae0587699
4 changed files with 9 additions and 1 deletions

View file

@ -21,6 +21,8 @@ module TokenAuthentication
end
def authenticate_with_api_key
return unless Rails.configuration.x.core_api_key_enabled
@api_key = request.headers['Api-Key']
return unless @api_key

View file

@ -629,6 +629,10 @@ class User < ApplicationRecord
%w(id due_date age results status archived assigned tags comments)
end
def api_key_enabled?
Rails.configuration.x.core_api_key_enabled
end
protected
def confirmation_required?

View file

@ -36,7 +36,7 @@
</div>
<%= render partial: 'users/registrations/edit_partials/2fa' %>
<% if Rails.application.config.x.core_api_v1_enabled %>
<% if current_user.api_key_enabled? %>
<%= render partial: 'users/registrations/edit_partials/api_key' %>
<% end %>
</div>

View file

@ -12,4 +12,6 @@ Rails.application.configure do
config.x.core_api_v1_enabled = ENV['CORE_API_V1_ENABLED'] || false
config.x.core_api_v2_enabled = ENV['CORE_API_V2_ENABLED'] || false
config.x.core_api_key_enabled = ENV['CORE_API_KEY_ENABLED'] || false
end