I'm having issues with setting up a custom OmniAuth strategy to use with Devise. Im using the following gem here but im unsure on how to properly load this file and use it.
https://github.com/aereal/omniauth-xauth
Based on the README, i created a subclass specific for my provider, i didn't know really where to place this file, so i placed it here lib/strategies/myauth.rb
based on this article . The file looks something like this. Removing the provider specific code.
module OmniAuth
module Strategies
class Myauth < OmniAuth::Strategies::XAuth
...
end
end
end
Based on this article i added the following code to my config/initializers/omniauth.rb
module OmniAuth
module Strategies
module XAuth
autoload :myauth, Rails.root.join('lib', 'strategies', 'myauth')
end
end
end
I did not add the following code, since i've read that by adding the config.omniauth :myauth
in my config/initializers/devise.rb
will take care of loading it. ??
Rails.application.config.middleware.use OmniAuth::Builder do
provider :myauth
end
I also added the following to my user.rb
devise :database_authenticatable, :omniauthable, :omniauth_providers => [:myauth]
I've also updated my config/initializers/devise.rb
config.omniauth :myauth, 'CKEY', 'CSEC', strategy_class => OmniAuth::Strategies::XAuth::Myauth
So when i try and run rails s
i get the following error output.
`load_missing_constant': Unable to autoload constant Myauth, expected ...../PROJECT/lib/strategies/myauth.rb to define it (LoadError)
Any ideas on what im missing? Thanks for your time
You don't need config/initializers/omniauth.rb file as you already have myauth.rb.
Your strategy class should contain the following:
config.omniauth :myauth, 'CKEY', 'CSEC', strategy_class => OmniAuth::Strategies::Myauth
Rest should work as long as the content of Myauth class is right.
Please let me know if i have misunderstood your question and answered incorrectly.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.