mirror of
https://github.com/discourse/discourse.git
synced 2026-08-04 10:23:17 -05:00
DEV: Do not show auth_redirect note for discourse://auth_redirect (#37212)
This is an internal protocol used by the Discourse mobile app, and showing the note with host/port info is not useful in this case.
This commit is contained in:
@@ -45,11 +45,24 @@ class UserApiKeysController < ApplicationController
|
||||
@client_id = params[:client_id]
|
||||
@auth_redirect = params[:auth_redirect]
|
||||
@redirect_uri =
|
||||
begin
|
||||
URI.parse(@auth_redirect)
|
||||
rescue StandardError
|
||||
if @auth_redirect.present?
|
||||
begin
|
||||
if @auth_redirect == "discourse://auth_redirect"
|
||||
nil
|
||||
else
|
||||
uri = URI.parse(@auth_redirect)
|
||||
if [80, 443].include?(uri.port)
|
||||
uri.host
|
||||
else
|
||||
uri.host + ":" + uri.port.to_s
|
||||
end
|
||||
end
|
||||
rescue StandardError
|
||||
nil
|
||||
end
|
||||
else
|
||||
nil
|
||||
end if @auth_redirect.present?
|
||||
end
|
||||
@push_url = params[:push_url]
|
||||
@localized_scopes = params[:scopes].split(",").map { |s| I18n.t("user_api_key.scopes.#{s}") }
|
||||
@scopes = params[:scopes]
|
||||
|
||||
@@ -23,7 +23,10 @@
|
||||
|
||||
<% if @redirect_uri %>
|
||||
<div class='authorize-api-key__redirect'>
|
||||
<p class="authorize-api-key__redirect-url"><%= t("user_api_key.redirect_warning") %> <strong><%= @redirect_uri.host %><%= ":#{@redirect_uri.port}" if @redirect_uri.port && ![80, 443].include?(@redirect_uri.port) %></strong></p>
|
||||
<p class="authorize-api-key__redirect-url">
|
||||
<%= t("user_api_key.redirect_warning") %>
|
||||
<strong><%= @redirect_uri %></strong>
|
||||
</p>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
|
||||
@@ -56,6 +56,20 @@ RSpec.describe UserApiKeysController do
|
||||
get "/user-api-key/new", params: args.merge(padding: "invalid")
|
||||
expect(response.status).to eq(400)
|
||||
end
|
||||
|
||||
it "does not show redirect warning when auth_redirect is discourse://auth_redirect" do
|
||||
sign_in(Fabricate(:user, refresh_auto_groups: true))
|
||||
|
||||
get "/user-api-key/new", params: args.merge(auth_redirect: "discourse://auth_redirect")
|
||||
expect(response.body).not_to include(I18n.t("user_api_key.redirect_warning"))
|
||||
end
|
||||
|
||||
it "shows redirect warning when auth_redirect is not discourse://auth_redirect" do
|
||||
sign_in(Fabricate(:user, refresh_auto_groups: true))
|
||||
|
||||
get "/user-api-key/new", params: args
|
||||
expect(response.body).to include(I18n.t("user_api_key.redirect_warning"))
|
||||
end
|
||||
end
|
||||
|
||||
describe "#create" do
|
||||
|
||||
Reference in New Issue
Block a user