Skip to navigation

Mocking OpenID authentication for offline development

Published December 03, 2007

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à!

Archived comments

Comments were previously allowed on articles. Though no new comments are being accepted you can see the old comments below.

  1. Lachlan Hardy

    Simple, cool goodness. Nice one!

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

  2. Tim Lucas

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

  3. Lachlan Hardy

    Here here!

Thoughts

toolmantim

I’m Tim Lucas, a user experience developer currently in Sydney Australia.

I occasionally write, snap photos, present on various technical topics, tweet my going-ons, share teh codes and post tidbits to the scrapbook.

Most recently I published Simplifying ticket sales on sydneyoperahouse.com (February 16, 2010)

Work with me via Agency Rainford, or shoot an email to and say hello.

Powered by procrastination