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!

Articles

toolmantim

I'm Tim Lucas, a user experience designer and developer currently in Sydney Australia.

I run a web application design and development company Agency Rainford, present on various technical topics, snap the occasional photo, tweet my going-ons, share teh codes and post other tid-bits to the tumble.

Most recently I published LAN hacking with Bananajour (June 11, 2009)

Shoot an email to and say hello.

Powered by procrastination