Skip to content

Commit 979cb52

Browse files
committed
Add query parameter that to suppress display of signup UI elements
This adds support for a query paramater "allow_signup" that will suppress the rendering of signup UI elements during the OAuth2 authorisation flow. This is the same solution as github implements for their "webflow" OAuth2 process. Resolves #5118
1 parent 5a7e994 commit 979cb52

5 files changed

Lines changed: 59 additions & 14 deletions

File tree

app/controllers/concerns/session_methods.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ def parse_oauth_referer(referer)
1515
preferred = ref_params["preferred_auth_provider"].first
1616
@preferred_auth_provider = preferred if preferred && Settings.key?(:"#{preferred}_auth_id")
1717
@client_app_name = Oauth2Application.where(:uid => ref_params["client_id"].first).pick(:name)
18+
19+
@allow_signup = ref_params["allow_signup"].first != "false"
1820
end
1921

2022
##

app/views/layouts/_header.html.erb

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<%# locals: () %>
1+
<%# locals: (allow_signup:) %>
22

33
<header class="d-flex bg-body flex-column flex-md-row h-auto position-relative text-nowrap closed z-3">
44
<h1 class="d-flex m-0 align-items-center fw-semibold">
@@ -75,10 +75,12 @@
7575
</div>
7676
</div>
7777
<% else %>
78-
<div class="d-inline-flex btn-group login-menu">
79-
<%= link_to t(".log_in"), login_path(:referer => request.fullpath), :class => "geolink btn btn-outline-secondary" %>
80-
<%= link_to t(".sign_up"), new_user_path, :class => "btn btn-outline-secondary" %>
81-
</div>
78+
<% unless allow_signup == false %>
79+
<div class="d-inline-flex btn-group login-menu">
80+
<%= link_to t(".log_in"), login_path(:referer => request.fullpath), :class => "geolink btn btn-outline-secondary" %>
81+
<%= link_to t(".sign_up"), new_user_path, :class => "btn btn-outline-secondary" %>
82+
</div>
83+
<% end %>
8284
<% end %>
8385
</nav>
8486
</header>

app/views/layouts/site.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<%= render "layouts/head", :title => @title, :opengraph_properties => @opengraph_properties %>
66
<%= tag.body :class => body_class,
77
:data => { :map_theme => current_user&.preferred_color_scheme(:map, :site) } do %>
8-
<%= render :partial => "layouts/header" %>
8+
<%= render :partial => "layouts/header", :locals => { :allow_signup => @allow_signup } %>
99
<%= render :partial => "layouts/content" %>
1010
<% if defined?(Settings.matomo) -%>
1111
<noscript><p><%= image_tag "#{request.protocol}#{Settings.matomo['location']}/matomo.php?idsite=#{Settings.matomo['site']}", :class => "matomo", :alt => "" %></p></noscript>

app/views/sessions/new.html.erb

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,16 @@
1111
<% end %>
1212

1313
<div class="d-flex align-items-end">
14-
<ul class="nav nav-tabs fs-6">
15-
<li class="nav-item">
16-
<%= link_to t("sessions.new.tab_title"), "#", :class => "nav-link active" %>
17-
</li>
18-
<li class="nav-item">
19-
<%= link_to t("users.new.tab_title"), url_for(:action => :new, :controller => :users, :referer => params[:referer]), :class => "nav-link" %>
20-
</li>
21-
</ul>
14+
<% unless @allow_signup == false %>
15+
<ul class="nav nav-tabs fs-6">
16+
<li class="nav-item">
17+
<%= link_to t("sessions.new.tab_title"), "#", :class => "nav-link active" %>
18+
</li>
19+
<li class="nav-item">
20+
<%= link_to t("users.new.tab_title"), url_for(:action => :new, :controller => :users, :referer => params[:referer]), :class => "nav-link" %>
21+
</li>
22+
</ul>
23+
<% end %>
2224
<div class="flex-grow-1 header-illustration new-user-main"></div>
2325
</div>
2426
<% end %>

test/integration/oauth2_test.rb

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,45 @@ def test_openid_key
148148
assert_equal Doorkeeper::OpenidConnect.signing_key.kid, key_info["keys"][0]["kid"]
149149
end
150150

151+
def test_allow_signup_not_set
152+
client = create(:oauth_application, :redirect_uri => "https://some.web.app.example.org/callback", :scopes => "read_prefs write_api read_gpx")
153+
154+
options = {
155+
:client_id => client.uid,
156+
:redirect_uri => client.redirect_uri,
157+
:response_type => "code",
158+
:scope => "read_prefs"
159+
}
160+
161+
oauth_path = oauth_authorization_path(options)
162+
login_for_oauth_path = login_path(:referer => oauth_path)
163+
cookies["_osm_session"] = "reassure the backend that cookies are enabled"
164+
get oauth_path
165+
assert_redirected_to login_for_oauth_path
166+
get login_for_oauth_path
167+
assert_match "Sign Up", response.body
168+
end
169+
170+
def test_allow_signup_false
171+
client = create(:oauth_application, :redirect_uri => "https://some.web.app.example.org/callback", :scopes => "read_prefs write_api read_gpx")
172+
173+
options = {
174+
:client_id => client.uid,
175+
:redirect_uri => client.redirect_uri,
176+
:response_type => "code",
177+
:scope => "read_prefs",
178+
:allow_signup => "false"
179+
}
180+
181+
oauth_path = oauth_authorization_path(options)
182+
login_for_oauth_path = login_path(:referer => oauth_path)
183+
cookies["_osm_session"] = "reassure the backend that cookies are enabled"
184+
get oauth_path
185+
assert_redirected_to login_for_oauth_path
186+
get login_for_oauth_path
187+
assert_no_match "Sign Up", response.body
188+
end
189+
151190
private
152191

153192
def authorize_client(user, client, options = {})

0 commit comments

Comments
 (0)