toolmantim

Mocking OpenID authentication for offline development

December 04, 2007 09:54 (Sydney Australia)

From a situation that arose at Railscamp ‘07 v2...

Have an OpenID app that you’re wanting to develop offline but you can’t because the open_id_authentication plugin needs to perform the remote authentication? It’s simply a matter of redefining, aka mocking, the authenticate_with_open_id method.

In your config/environments/development.rb append:

config.after_initialize do
  require 'openid_auth_mock'
end

and create the corresponding lib/openid_auth_mock.rb file containing:

# Mocks the OpenID auth to always return :successful
OpenIdAuthentication.module_eval do
  protected
    def authenticate_with_open_id(identity_url, fields)
      yield OpenIdAuthentication::Result[:successful], identity_url, nil
    end
end

Voilà!

Comments

Lachlan Hardy

Simple, cool goodness. Nice one!

Now if only we’d done any work on that project past that stage… ;)

Tim Lucas

If I only I wasn’t totally burnt out from the overnighters leading up to railscamp :\

Lachlan Hardy

Here here!

To comment on this article you must have javascript enabled.