Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

[#65505] Show plaintext tokens in ScimClient UI.

Pavel Balashou02d2624e40f6
diff --git a/app/components/admin/scim_clients/created_client_credentials_dialog_component.html.erb b/app/components/admin/scim_clients/created_client_credentials_dialog_component.html.erb
index b5f65d89161..5c617cc0573 100644
--- a/app/components/admin/scim_clients/created_client_credentials_dialog_component.html.erb
+++ b/app/components/admin/scim_clients/created_client_credentials_dialog_component.html.erb
@@ -55,10 +55,10 @@ See COPYRIGHT and LICENSE files for more details.
name: :client_secret,
label: Doorkeeper::Application.human_attribute_name(:secret),
visually_hide_label: false,
- value: model.oauth_application.secret
+ value: @plaintext_secret
)
input_group.with_trailing_action_clipboard_copy_button(
- value: model.oauth_application.secret,
+ value: @plaintext_secret,
aria: { label: I18n.t("button_copy_to_clipboard") }
)
end
diff --git a/app/components/admin/scim_clients/created_client_credentials_dialog_component.rb b/app/components/admin/scim_clients/created_client_credentials_dialog_component.rb
index 73d753d5ff9..9c8ec4d2453 100644
--- a/app/components/admin/scim_clients/created_client_credentials_dialog_component.rb
+++ b/app/components/admin/scim_clients/created_client_credentials_dialog_component.rb
@@ -35,6 +35,11 @@ module Admin
TEST_SELECTOR = "op-scim-clients--created-client-credentials-dialog"
+ def initialize(model = nil, **options)
+ super
+ @plaintext_secret = options.fetch(:plaintext_secret)
+ end
+
def system_arguments
options
end
diff --git a/app/components/admin/scim_clients/created_token_dialog_component.html.erb b/app/components/admin/scim_clients/created_token_dialog_component.html.erb
index 0d0487df0ba..c506d272271 100644
--- a/app/components/admin/scim_clients/created_token_dialog_component.html.erb
+++ b/app/components/admin/scim_clients/created_token_dialog_component.html.erb
@@ -39,10 +39,10 @@ See COPYRIGHT and LICENSE files for more details.
name: :token,
label: t(".label_token"),
visually_hide_label: false,
- value: model.token
+ value: model.plaintext_token
)
input_group.with_trailing_action_clipboard_copy_button(
- value: model.token,
+ value: model.plaintext_token,
aria: { label: I18n.t("button_copy_to_clipboard") }
)
end
diff --git a/app/controllers/admin/scim_clients_controller.rb b/app/controllers/admin/scim_clients_controller.rb
index 1611d00db2b..bd41d18fb7c 100644
--- a/app/controllers/admin/scim_clients_controller.rb
+++ b/app/controllers/admin/scim_clients_controller.rb
@@ -63,7 +63,9 @@ module Admin
result.on_success do
flash[:notice] = t(:notice_successful_create)
- redirect_to edit_admin_scim_client_path(result.result, first_time_setup: true)
+ plaintext_secret = result.result.oauth_application&.plaintext_secret
+ session[:oauth_secret] = plaintext_secret if plaintext_secret.present?
+ redirect_to(edit_admin_scim_client_path(result.result, first_time_setup: true))
end
end
@@ -112,14 +114,13 @@ module Admin
case scim_client.authentication_method
when "oauth2_token"
if scim_client.access_tokens.empty?
- ::ScimClients::GenerateStaticTokenService.new(scim_client).call
- @setup_token = true
+ @setup_token = ::ScimClients::GenerateStaticTokenService.new(scim_client).call.result
end
when "oauth2_client"
# Ensuring that the client secret can't infinitely be accessed by calling with ?first_time_setup=true long after
# the initial setup (there is no other persisted marker showing us, that this is the first time)
if scim_client.oauth_application.created_at > 1.minute.ago
- @setup_client_credentials = true
+ @setup_client_secret = session.delete(:oauth_secret)
end
end
end
diff --git a/app/views/admin/scim_clients/edit.html.erb b/app/views/admin/scim_clients/edit.html.erb
index 243c2de6787..52f2b437dd4 100644
--- a/app/views/admin/scim_clients/edit.html.erb
+++ b/app/views/admin/scim_clients/edit.html.erb
@@ -60,7 +60,7 @@ See COPYRIGHT and LICENSE files for more details.
<%= render(Admin::ScimClients::TokenListComponent.new(@scim_client)) if @scim_client.authentication_method_oauth2_token? %>
<% if @setup_token %>
- <%= render(Admin::ScimClients::CreatedTokenDialogComponent.new(@scim_client.access_tokens.first, data: { controller: "auto-show-dialog" })) %>
-<% elsif @setup_client_credentials %>
- <%= render(Admin::ScimClients::CreatedClientCredentialsDialogComponent.new(@scim_client, data: { controller: "auto-show-dialog" })) %>
+ <%= render(Admin::ScimClients::CreatedTokenDialogComponent.new(@setup_token, data: { controller: "auto-show-dialog" })) %>
+<% elsif @setup_client_secret %>
+ <%= render(Admin::ScimClients::CreatedClientCredentialsDialogComponent.new(@scim_client, plaintext_secret: @setup_client_secret, data: { controller: "auto-show-dialog" })) %>
<% end %>
diff --git a/spec/features/admin/scim_clients/create_spec.rb b/spec/features/admin/scim_clients/create_spec.rb
index 234b28d58d2..1123aeded17 100644
--- a/spec/features/admin/scim_clients/create_spec.rb
+++ b/spec/features/admin/scim_clients/create_spec.rb
@@ -79,7 +79,9 @@ RSpec.describe "Creating a SCIM client", :js, :selenium, driver: :firefox_de do
page.within_modal("Client credentials created") do
expect(page).to have_field("Client ID", with: created_client.oauth_application.uid)
- expect(page).to have_field("Client secret", with: created_client.oauth_application.secret)
+ plaintext_secret = page.find_field("Client secret").value
+ hashed_secret = created_client.oauth_application.secret
+ expect(Digest::SHA256.hexdigest(plaintext_secret)).to eq(hashed_secret)
end
end
@@ -97,7 +99,10 @@ RSpec.describe "Creating a SCIM client", :js, :selenium, driver: :firefox_de do
expect(page).to have_current_path(edit_admin_scim_client_path(created_client, first_time_setup: true))
page.within_modal("Token created") do
- expect(page).to have_field("Token", with: created_client.oauth_application.access_tokens.last.token)
+ plaintext_token = page.find_field("Token").value
+ hashed_token = created_client.oauth_application.access_tokens.last.token
+ expect(plaintext_token).to be_present
+ expect(Digest::SHA256.hexdigest(plaintext_token)).to eq(hashed_token)
end
end
end
diff --git a/spec/features/admin/scim_clients/update_spec.rb b/spec/features/admin/scim_clients/update_spec.rb
index 83b035f6f9b..2b5c2f13083 100644
--- a/spec/features/admin/scim_clients/update_spec.rb
+++ b/spec/features/admin/scim_clients/update_spec.rb
@@ -148,7 +148,10 @@ RSpec.describe "Updating a SCIM client", :js, :selenium, driver: :firefox_de do
page.find_test_selector("op-scim-clients--add-token-button").click
within_modal("Token created") do
- expect(page).to have_field("Token", with: Doorkeeper::AccessToken.last.token)
+ plaintext_token = page.find_field("Token").value
+ hashed_token = Doorkeeper::AccessToken.last.token
+ expect(plaintext_token).to be_present
+ expect(Digest::SHA256.hexdigest(plaintext_token)).to eq(hashed_token)
click_on("Close")
end
within_test_selector("Admin::ScimClients::TokenTableComponent") do