Devise with Omniauth for multiple models without STI

前端 未结 4 1999
情深已故
情深已故 2021-01-17 21:06

Is there any way to configure Devise Omniauth for multiple models without STI?

We have the models Students and Professors and we didn\'t want to use STI but now we r

4条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-17 21:54

    Currently, Devise's Omniauthable module does not work with multiple models. (https://github.com/plataformatec/devise/wiki/OmniAuth-with-multiple-models) In a nutshell you need to stop relying on devise to do its magic via "omniauthable" and do this by hand. It is not complicated and once you get first model to work over middelware then it's obvious how to extent for multiple models as it boils down to exactly same code with just different model name.

    Steps needed:

    1. Remove omniauthable and devise omniauth setup from devise.rb and model used
    2. Include oauth as middelware(so you catch request before it hits Rails)
    3. Write manual routes - easy peasy
    4. Handle response - amlost the same code you have right now
    5. Handle failure scenario (rejected on oauth provider) - one more block in middelware setup

    I solved similar problem and I have detailed explanation here: https://blog.kodius.io/2016/12/20/devise-omniauth-multiple-models/ Code for middleware oauth setup is here: https://github.com/kodius/oauth-example-multiple-models

提交回复
热议问题