Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find loaded providers for OmniAuth

Tags:

ruby

omniauth

I'd like to know which providers have been loaded for use by the OmniAuth gem. I've tried this:

OmniAuth::Strategies.constants  # a method provided by the standard lib Module class
# => [:Developer, :OAuth, :Twitter]

and this:

OmniAuth.strategies.inspect # a method provided by the OmniAuth class, but which has no documentation or comments around it.
# => [OmniAuth::Strategies::OAuth]

The answer I'd expect (or want) is [:Developer, :Twitter] as in my test code I've only loaded twitter explicitly, and the developer provided is loaded by default.

(This is all so a different library can load the correct things for it to work, dependent on what OmniAuth is running.)

If there is a way and you know of it, please let me know. Otherwise I'll be pragmatic and knock OAuth out of the list from the first example.

Ruby is 1.9.3 and OmniAuth is v1.1.1

like image 871
ian Avatar asked Oct 28 '12 19:10

ian


1 Answers

Adding this here for Devise users, as I needed the same list as iain.

I tried using the accepted answer at the top of my devise initializer in a Rails project, but I got an error (@@providers was not defined).

After looking into the Devise source code, I used the following to get an array of symbols:

Devise.omniauth_configs.keys # => [:facebook, :twitter]
like image 172
One Giant Leap AB Avatar answered Oct 21 '22 08:10

One Giant Leap AB