Write a custom OmniAuth strategy

I have a Rail 4 app with Devise. I am trying to configure OmniAuth to use our Enterprise Ping OpenID Connect IdP. It looks like I need to write an OmniAuth strategy in Rack middleware.

I took the "omniauth-digitalocean" gem (which has its own strategy) and carefully replaced all "digitalocean" links with a different name. I was careful to respect all cases in order to comply with the convention.

The problem I'm currently running into is that I seem to have a private gem. I added it to my Gemfile with:

gem 'omniauth-private', :path => "/var/lib/gems/2.0.0/gems/omniauth-private-0.1.0"

      

I get no error when running 'bundle install'.

I was getting this error with "rake db: migrate":

fatal: Not a git repository (or any of the parent directories): .git

      

I believe this is caused by the .gitignore file in my own gem. I deleted the .gitignore file and now I get:

Devise::OmniAuth::StrategyNotFound: Could not find a strategy with name `Private'. Please ensure it is required or explicitly set it using the :strategy_class option.

      

This is the same error message I was getting before it turned out that I needed to write n Omniuth, so I believe my gem is not recognized.

So I don't know exactly what's going on. I think I am struggling with this private gem. But that could be an OmniAuth issue.

Has anyone ever gotten a private OpenID Connect IdP working with OmniAuth?

+4


source to share


4 answers


I had the same "Failed to find strategy named ..." with my own Omniauth OAuth2 strategy.

I created a custom strategy according to these instructions https://github.com/intridea/omniauth-oauth2 and saved my file in config / initializers - this then loads the module onto the ruby ​​boot.



I feel like I should be able to store this in the lib / folder, but can't figure out what should be in the filename or folder structure!

+2


source


The "fatal" error "No git repository" occurs because stones are using "git ls". Just running "git init" should fix it. I did this and then pushed to github.

"Failed to find strategy named ..." error is fixed by loading the custom gem correctly. I did it by adding this line to my Gemfile:



gem 'omniauth-private', :path => "/var/lib/gems/2.0.0/gems/omniauth-private-0.1.0

      

+1


source


You need to add:

require 'strategies/private'

      

at the top of config / devise.rb. This points your strategy file to / lib / strategies / private.rb

+1


source


In your devise / initializers file, check and make sure you have the correct name of the authenticator you want to configure, e.g .:

 config.omniauth :facebook, 'APP_ID', 'APP_SECRET', scope: 'user,public_repo' 
 config.omniauth :private, 'APP_ID', 'APP_SECRET', scope: 'user,public_repo' 
 config.omniauth :github, 'APP_ID', 'APP_SECRET', scope: 'user,public_repo' 

      

0


source







All Articles