8 Steps to your first OpenID enabled app

openid_login_generator isn’t the only game in town for creating an OpenID-enabled Rails application, and it’s certainly not the best for real-world apps. But it is the simplest. The generator doesn’t even generate migrations for you, yet it’s only 8 steps to your first OpenID enabled app (ok, you had to install ruby, rails and sqlite3 first). Here’s a cheat sheet length tutorial.

$ rails your_app -d sqlite3; cd your_app
$ sudo gem install openid_login_generator -y
$ script/generate openid_login openid_account
$ ${EDITOR} app/controllers/application.rb
  require_dependency "openid_login_system"

  class ApplicationController < ActionController::Base
    include OpenidLoginSystem
    model :user
$ script/generate migration create_user_model
$ ${EDITOR} db/migrate/001_create_user_model.rb
  def self.up
    create_table :users do |t|
         t.column :o penid_url, :string
    end
  end

  def self.down
    drop_table :users
  end
$ rake db:migrate
$ script/server

Now browse to http://localhost:3000/openid_account/login and test your new openid login-enabled app. You’re good and ready to add “before_filter :login_required” to controllers to limit access. See the readme for more.

Comments (4) to “8 Steps to your first OpenID enabled app”

  1. [...] Leancode » 8 Steps to your first OpenID enabled app openid_login_generator isn’t the only game in town for creating an OpenID-enabled Rails application, and it’s certainly not the best for real-world apps. But it is the simplest. The generator doesn’t even generate migrations for you, yet it’s only [...]

  2. “rails your_app -d sqlite3; cd your_app”
    ^ That’s cheating, it’s two steps… ;-)

    Thanks, I look forward to trying this.

  3. Thanks. This is just what I needed. However, I’m having problems with Simple Registration Extension. My code executes without errors; but only returns the sreg.email field, and none of the others (e.g., sreg.gender, sreg.postcode, etc). I’m using MyOpenID.com as the provider as they’ve announced support for sreg. Here’s the code segment openid_account_controller/complete method:

    # create user object if one does not exist
    if @user.nil?
    registration_info = response.extension_response(‘sreg’)
    @user = User.new(:openid_url => response.identity_url)
    @user.email = registration_info['email']
    @user.gender = registration_info['gender']
    @user.save
    end

    Any idea what’s causing the problem? Thx.

  4. Hi Donovan,

    I’ve only been using the nickname & email sreg info, so I’m not sure whether all providers handle the others.

    Do you have a test account on the openid provider, with the data you’re looking for in the profile?
    Are you (2) letting the provider who which sreg params are optional/requred in your begin() method?

    def add_simple_registration_fields(open_id_response, fields) 
      open_id_response.add_extension_arg('sreg', 'required', [ fields[:required] ].flatten * ',') if fields[:required]  
      open_id_response.add_extension_arg('sreg', 'optional', [ fields[:optional] ].flatten * ',') if fields[:optional]
    end
    

Post a Comment
(Never published)