Hooking into after_authenticate for all authentication methods


(Leo McArdle) #1

I’m wanting to call an API every time a user logs in, to assign them to (or remove them from) various groups. The way I’m currently doing it is with a fork of the Persona authentication plugin, by tacking it on to the end of the existing after_authenticate function.

Is it possible to do this after authentication no matter what login method a user uses? Or is there some other way to achieve the same effect?

Any help will be greatly appreciated :smile:


(Kane York) #2

You could do it for every user on a weekly job, instead. Check out app/jobs/scheduled. Define a class in your plugin.rb that extends Jobs::Base.


(Leo McArdle) #3

How does the jobs system work? Could I potentially crash the server, or slow it down completely?


(Kane York) #4

It runs in a separate process, but I think you probably could. Eating up all the memory will get sidekiq killed, though, at which point you will no longer be sending emails.

So… Test locally, and try to avoid that?

If all else fails, you can remove the code from app.yml and rebuild.