diff --git a/app/controllers/users/associate_accounts_controller.rb b/app/controllers/users/associate_accounts_controller.rb index 2cb04a5d451..905e18a56f0 100644 --- a/app/controllers/users/associate_accounts_controller.rb +++ b/app/controllers/users/associate_accounts_controller.rb @@ -27,6 +27,7 @@ class Users::AssociateAccountsController < ApplicationController authenticator = Discourse.enabled_authenticators.find { |a| a.name == provider_name } raise Discourse::InvalidAccess.new(I18n.t('authenticator_not_found')) if authenticator.nil? + DiscourseEvent.trigger(:before_auth, authenticator, auth) auth_result = authenticator.after_authenticate(auth, existing_account: current_user) DiscourseEvent.trigger(:after_auth, authenticator, auth_result) diff --git a/app/controllers/users/omniauth_callbacks_controller.rb b/app/controllers/users/omniauth_callbacks_controller.rb index 854acb4cc57..bbbd839f428 100644 --- a/app/controllers/users/omniauth_callbacks_controller.rb +++ b/app/controllers/users/omniauth_callbacks_controller.rb @@ -34,6 +34,7 @@ class Users::OmniauthCallbacksController < ApplicationController Discourse.redis.setex "#{Users::AssociateAccountsController::REDIS_PREFIX}_#{current_user.id}_#{token}", 10.minutes, auth.to_json return redirect_to "#{Discourse.base_path}/associate/#{token}" else + DiscourseEvent.trigger(:before_auth, authenticator, auth) @auth_result = authenticator.after_authenticate(auth) DiscourseEvent.trigger(:after_auth, authenticator, @auth_result) end diff --git a/spec/requests/associate_accounts_controller_spec.rb b/spec/requests/associate_accounts_controller_spec.rb index 3b06878f6c2..b0eea12990b 100644 --- a/spec/requests/associate_accounts_controller_spec.rb +++ b/spec/requests/associate_accounts_controller_spec.rb @@ -69,6 +69,7 @@ RSpec.describe Users::AssociateAccountsController do # Make the connection events = DiscourseEvent.track_events { post "#{uri.path}.json" } + expect(events.any? { |e| e[:event_name] == :before_auth }).to eq(true) expect(events.any? { |e| e[:event_name] === :after_auth && Auth::GoogleOAuth2Authenticator === e[:params][0] && !e[:params][1].failed? }).to eq(true) expect(response.status).to eq(200) diff --git a/spec/requests/omniauth_callbacks_controller_spec.rb b/spec/requests/omniauth_callbacks_controller_spec.rb index bb18d3492da..e34271c263e 100644 --- a/spec/requests/omniauth_callbacks_controller_spec.rb +++ b/spec/requests/omniauth_callbacks_controller_spec.rb @@ -196,6 +196,7 @@ RSpec.describe Users::OmniauthCallbacksController do Rails.application.env_config["omniauth.origin"] = destination_url events = DiscourseEvent.track_events { get "/auth/google_oauth2/callback.json" } + expect(events.any? { |e| e[:event_name] == :before_auth }).to eq(true) expect(events.any? { |e| e[:event_name] === :after_auth && Auth::GoogleOAuth2Authenticator === e[:params][0] && !e[:params][1].failed? }).to eq(true) expect(response.status).to eq(302)