Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Write a custom OmniAuth strategy

I've got a Rail 4 app with Devise. I'm trying to configure OmniAuth to use our corporate Ping OpenID Connect IdP. It appears that I have to write an OmniAuth strategy in Rack Middleware.

I took the 'omniauth-digitalocean' gem (which has their strategy) and carefully replaced all references of 'digitalocean' with another name. I was careful to respect all case to conform to convention.

The problem I'm having now is that I appear 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 errors when I run '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 was caused by a .gitignore file in my custom gem. I deleted the .gitignore file and now I'm getting:

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 I figure out I needed to write n Omniuth strategy, so I think it means my gem is not being recognized.

So I'm not sure exactly what's going on. I think I'm struggling with this private gem. But it could be an OmniAuth problem too.

Anyone ever gotten a private OpenID Connect IdP working with OmniAuth?

like image 671
Paul Ericson Avatar asked Jun 26 '15 20:06

Paul Ericson


2 Answers

I had the same "Could not find a strategy with the name..." with my custom Omniauth OAuth2 strategy.

I created a custom strategy as per these instructions https://github.com/intridea/omniauth-oauth2, and saved my file in config/initializers - this then loads the module on ruby boot.

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

like image 120
phil-tee Avatar answered Oct 26 '22 23:10

phil-tee


You need to add:

require 'strategies/private'

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

like image 42
fnllc Avatar answered Oct 27 '22 00:10

fnllc