DEV: Add session to before_auth and after_auth hooks (#13123)

This allows plugins to store/modify things in the session (e.g. the destination_url). This change is backwards compatible with existing plugins. If they do not specify a third argument, they will just be passed the first two.
This commit is contained in:
David Taylor 2021-05-24 17:35:51 +01:00 committed by GitHub
parent 93ae1b2b1c
commit fc6e7dd3f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -33,10 +33,10 @@ 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)
DiscourseEvent.trigger(:before_auth, authenticator, auth, session)
@auth_result = authenticator.after_authenticate(auth)
@auth_result.user = nil if @auth_result&.user&.staged # Treat staged users the same as unregistered users
DiscourseEvent.trigger(:after_auth, authenticator, @auth_result)
DiscourseEvent.trigger(:after_auth, authenticator, @auth_result, session)
end
preferred_origin = request.env['omniauth.origin']