diff --git a/app/assets/javascripts/auth_providers.js b/app/assets/javascripts/auth_providers.js index 35da7b5e4..975c57a9b 100644 --- a/app/assets/javascripts/auth_providers.js +++ b/app/assets/javascripts/auth_providers.js @@ -12,7 +12,7 @@ $(document).ready(function () { $("#openid_open_url").click(function (e) { e.preventDefault(); $("#openid_url").val("http://"); - $("#login_auth_buttons").hide(); + $("#login_auth_buttons").hide().removeClass("d-flex"); $("#login_openid_url").show(); $("#openid_login_button").show(); }); diff --git a/app/controllers/concerns/session_methods.rb b/app/controllers/concerns/session_methods.rb index cebe932fc..5dcddb82d 100644 --- a/app/controllers/concerns/session_methods.rb +++ b/app/controllers/concerns/session_methods.rb @@ -3,6 +3,18 @@ module SessionMethods private + ## + # Read @preferred_auth_provider and @client_app_name from oauth2 authorization request's referer + def parse_oauth_referer(referer) + referer_query = URI(referer).query if referer + return unless referer_query + + ref_params = CGI.parse referer_query + preferred = ref_params["preferred_auth_provider"].first + @preferred_auth_provider = preferred if preferred && Settings.key?(:"#{preferred}_auth_id") + @client_app_name = Oauth2Application.where(:uid => ref_params["client_id"].first).pick(:name) + end + ## # return the URL to use for authentication def auth_url(provider, uid, referer = nil) diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index e57ffc06a..fdf2df6a7 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -15,6 +15,8 @@ class SessionsController < ApplicationController override_content_security_policy_directives(:form_action => []) if Settings.csp_enforce || Settings.key?(:csp_report_url) session[:referer] = safe_referer(params[:referer]) if params[:referer] + + parse_oauth_referer session[:referer] end def create diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 74ec5c0ec..e022ff0c1 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -60,6 +60,8 @@ class UsersController < ApplicationController session[:referer] end + parse_oauth_referer @referer + append_content_security_policy_directives( :form_action => %w[accounts.google.com *.facebook.com login.live.com github.com meta.wikimedia.org] ) diff --git a/app/helpers/user_helper.rb b/app/helpers/user_helper.rb index d0b2f0be5..0a68e608e 100644 --- a/app/helpers/user_helper.rb +++ b/app/helpers/user_helper.rb @@ -60,11 +60,25 @@ module UserHelper link_to( image_tag("#{name}.svg", :alt => t("application.auth_providers.#{name}.alt"), - :class => "rounded-3", - :size => "36"), + :class => "rounded-1", + :size => "24"), auth_path(options.merge(:provider => provider)), :method => :post, - :class => "auth_button", + :class => "auth_button p-2 d-block", + :title => t("application.auth_providers.#{name}.title") + ) + end + + def auth_button_preferred(name, provider, options = {}) + link_to( + image_tag("#{name}.svg", + :alt => t("application.auth_providers.#{name}.alt"), + :class => "rounded-1 me-3", + :width => "24px", + :height => "24px") + t("application.auth_providers.#{name}.title"), + auth_path(options.merge(:provider => provider)), + :method => :post, + :class => "auth_button fs-6 border rounded text-muted text-decoration-none py-2 px-4 d-flex justify-content-center align-items-center", :title => t("application.auth_providers.#{name}.title") ) end diff --git a/app/views/application/_auth_providers.html.erb b/app/views/application/_auth_providers.html.erb index 9c72d7aa0..a79e7b5ce 100644 --- a/app/views/application/_auth_providers.html.erb +++ b/app/views/application/_auth_providers.html.erb @@ -1,33 +1,44 @@
<%= t(".login_to_authorize_html", :client_app_name => @client_app_name) %>
+ <% end %> +<%= t(".by_signing_up_html", - :tou_link => link_to(t("layouts.tou"), - "https://wiki.osmfoundation.org/wiki/Terms_of_Use", - :target => :new), - :privacy_policy_link => link_to(t(".privacy_policy"), - t(".privacy_policy_url"), - :title => t(".privacy_policy_title"), - :target => :new), - :contributor_terms_link => link_to(t(".contributor_terms"), - t(".contributor_terms_url"), - :target => :new)) %>
- +<%= t(".by_signing_up_html", + :tou_link => link_to(t("layouts.tou"), + "https://wiki.osmfoundation.org/wiki/Terms_of_Use", + :target => :new), + :privacy_policy_link => link_to(t(".privacy_policy"), + t(".privacy_policy_url"), + :title => t(".privacy_policy_title"), + :target => :new), + :contributor_terms_link => link_to(t(".contributor_terms"), + t(".contributor_terms_url"), + :target => :new)) %>
<%= f.form_group do %> <%= f.check_box :consider_pd, :tabindex => 5, @@ -84,8 +96,12 @@