A platform for community discussion. Free, open, simple.
UX: Minor improvements to user api key flow (#39640)
Penar Musaraj82c182ddb94a
diff --git a/app/views/user_api_keys/new.html.erb b/app/views/user_api_keys/new.html.erbindex 5854f445217..f901cd1c89b 100644--- a/app/views/user_api_keys/new.html.erb+++ b/app/views/user_api_keys/new.html.erb@@ -21,6 +21,12 @@</ul></div>+ <% if @scopes&.split(",")&.include?("write") %>+ <div class='authorize-api-key__write-warning alert alert-warning'>+ <p><%= t("user_api_key.write_scope_warning") %></p>+ </div>+ <% end %>+<% if @redirect_uri %><div class='authorize-api-key__redirect'><p class="authorize-api-key__redirect-url">diff --git a/app/views/user_api_keys/show.html.erb b/app/views/user_api_keys/show.html.erbindex fdf331a13a9..74faa9be1a8 100644--- a/app/views/user_api_keys/show.html.erb+++ b/app/views/user_api_keys/show.html.erb@@ -1,4 +1,4 @@-<p><%= t("user_api_key.instructions", application_name: @application_name) %></p>+<p><%= t("user_api_key.instructions", application_name: @client.application_name) %></p><div class="user-api-key-display"><code id="user-api-key-payload"><%= @payload %></code></div>diff --git a/config/locales/server.en.yml b/config/locales/server.en.ymlindex 45621c01083..78512c820c2 100644--- a/config/locales/server.en.yml+++ b/config/locales/server.en.yml@@ -1274,6 +1274,7 @@ en:logged_in_as: "Logged in as"permissions_header: 'This will allow "%{application_name}" to:'redirect_warning: "Authorizing will redirect you to"+ write_scope_warning: "Full write access requested — this application will be able to post, edit, and delete content. Proceed only if you fully trust it."instructions: 'We just generated a new user API key for you to use with "%{application_name}", please paste the following key into your application:'copy_key: "Copy Key"copied: "Copied!"diff --git a/spec/requests/user_api_keys_controller_spec.rb b/spec/requests/user_api_keys_controller_spec.rbindex 628d4726d8d..db06b2f5a17 100644--- a/spec/requests/user_api_keys_controller_spec.rb+++ b/spec/requests/user_api_keys_controller_spec.rb@@ -61,6 +61,16 @@ RSpec.describe UserApiKeysController doexpect(response.status).to eq(400)end+ it "shows write scope warning when write scope is requested" do+ get "/user-api-key/new", params: args.merge(scopes: "write")+ expect(response.body).to include(I18n.t("user_api_key.write_scope_warning"))+ end++ it "does not show write scope warning for read-only scopes" do+ get "/user-api-key/new", params: args+ expect(response.body).not_to include(I18n.t("user_api_key.write_scope_warning"))+ end+it "does not show redirect warning when auth_redirect is discourse://auth_redirect" doSiteSetting.allowed_user_api_auth_redirects = "discourse://auth_redirect"@@ -193,6 +203,16 @@ RSpec.describe UserApiKeysController doexpect(UserApiKey.with_key(parsed["key"]).first.user_id).to eq(user.id)end+ it "renders show template with application_name when no auth_redirect provided" do+ SiteSetting.user_api_key_allowed_groups = Group::AUTO_GROUPS[:trust_level_0]+ user = Fabricate(:user, trust_level: TrustLevel[0])+ sign_in(user)++ post "/user-api-key", params: args.except(:auth_redirect)+ expect(response.status).to eq(200)+ expect(response.body).to include(args[:application_name])+ end+it "encrypts payload with OAEP padding when requested" doSiteSetting.user_api_key_allowed_groups = Group::AUTO_GROUPS[:trust_level_0]user = Fabricate(:user, trust_level: TrustLevel[0])