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 :openid_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.
links for 2007-03-07 » OpenID Planet wrote:
[...] 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 [...]
Posted on 07-Mar-07 at 3:23 pm | Permalink
Daryl Fritz wrote:
“rails your_app -d sqlite3; cd your_app”
^ That’s cheating, it’s two steps…
Thanks, I look forward to trying this.
Posted on 07-Mar-07 at 6:53 pm | Permalink
Donovan Dillon wrote:
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.
Posted on 19-Mar-07 at 1:06 am | Permalink
Bernie Thompson wrote:
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] endPosted on 19-Mar-07 at 4:31 am | Permalink