#170 OpenID with Authlogic
Jul 13, 2009 | 11 minutes | Plugins, Authentication
Learn how to apply OpenID to an existing Authlogic setup as I show in this episode. This builds upon the app from episode 160.
- Download:
- source code
- mp4
- m4v
- webm
- ogv
Hi Ryan,
Amazing video... Keep it up.
Thanks,
Madan Kumar Rajan
Awesome as always.
Keep rocking.
email fetch works with yahoo openid?
Hi, Ryan
Thank you for another one god screencast!
Had you any experience with single sign on with Shibboleth? Is it makes sense to do screencast about it?
Thanks,
Igor
Your timing couldn't have been better as I was just about to play around with OpenID for Authlogic today. Thanks a lot ;)
We've seen quite a few episodes about authentication, I think that authorization is an important followup (it's a little daunting to me).
Great information. I had to migrate in something like this:
change_column :users, :crypted_password, :string, :default => nil, :null => true
change_column :users, :password_salt, :string, :default => nil, :null => true
If I didn't, mysql would complain about a blank password.
Wonderful wonderful screencast!
I would also like to see a screen cast on being an openID provider
Hey Ryan, great video once again. Thanks a lot for doing this, this has helped me out tremendously with answering questions and helping people get started.
Perfect timing!!
Thanks Ryan
Yep, very good and very useful.
I second the request for some authorization casts!
Preferably using one of the frameworks like acl9 (which works quite nicely with authlogic)
Another great thing would be to include how to test an openid login ( using cucumber for example )
Is the openid_identifier field also required on the UserSession table? I'm getting an error when I add the field to the login view.
http://gist.github.com/147267
@brett same here, I get:
undefined method `openid_identifier' for #<UserSession: no credentials provided>
I got it working 50% - but after returning from the OpenID provider I'm shown the registration form with two validation errors for login and email (too short) - they are empty. There is an OpenID URL for the user (https://me.yahoo.com/a/RXqidPob1_KpF0cfyeR.cycJcHax9.s). I cannot see anything wrong, views, models, controllers, are all simple enough after all... any ideas?
Follow-up: in map_openid_registration(registration) "registration" is an empty hash - so THAT's the problem. But why???
Very nice, Ryan. I recently started working on Skeletor, a skeletal Rails 2.3 app that uses Authlogic with OpenID and other common plugins/gems.
It's not polished yet, but I think it's a good start and I'm looking for feedback from the community.
http://github.com/jeremyw/skeletor/tree/master
OK, fixed - need to set config.action_controller.session in the environment.rb
Hi Ryan,
Do you plan to cover ldap authentication through Authlogic too?
Ahh, i figured something important out, and this may help a few of you, many of the openid providers require you to explicitly choose to have openid make a username and email address available. By default most of them only return the a valid credentials response and the token.
For myopenid, got into your profile
Nice. Requesting railscasts on Facebook Connect and Sign in with Twitter.
@arie until Ryan gets time, here's a slideshow: http://www.slideshare.net/mbleigh/twitter-on-rails-1396030
or for those who don't want to copy and paste: <a href="http://www.slideshare.net/mbleigh/twitter-on-rails-1396030">http://www.slideshare.net/mbleigh/twitter-on-rails-1396030</a>
Awesome tutorial as usual.
However, I can't get it to work with Yahoo, Google (and blogspot), etc.
It works with AOL (once I told it to export username/email). It works with myid.net. Etc.
But even though Yahoo and Google ask if I want to allow it (and I do), they won't return the nickname and email back so I am still getting a "Username/Email Required" error.
Any clues?
Thanks
Ryan,
How about an episode that goes over a simple single sign-on system built in rails for multiple rails apps.
Thanks for all the great screencasts!
Thank you for the scast.
Setting "background: url(http://openid.net/images/login-bg.gif) no-repeat;" as a direct link on openid server may lead to overload. Think about using a local picture.
Oauth and authlogic are covered really well in the documentation at http://github.com/jrallison/authlogic_oauth/tree/master. Ryan tends to plug gaps of stuff that you can't find anywhere else, I can't see the point in him reading the documentation there out into a screen cast myself.
@Brett, set config.action_controller.session to what? I'm getting the same error as Bret and Joe. And I'm a rails noob :(
Quitting script/server and relaunching seemed to fix this problem. I also did sudo gem install rails just in case, but I'm not sure if that's what did it. Also, you can find the proper config.action_controller.session codes in the source code linked above.
I've tried setting this up on a test site using Authlogic but keep getting the following error once I return from myopenid.com:
------
Openid identifier did not match any users in our database, have you set up your account to use OpenID?
-----
I've looked at the README for the plugin, on Google and here but I'm stumped.
Any ideas?
Thanks.
Scratch that last comment...figured it out.
(1) I was trying to "login" using my OpenID credentials before "registering". Gotta register first, then you can use OpenID to login during subsequent visits to the site.
(2) For registration, I had the crypted_password and password_salt columns in the user model set to :null => false. But using OpenID, those don't get created which throws a database error. A simple migration using the following fixed that:
http://pastie.org/607719
Once I fixed that and registered for the site FIRST, it worked just fine.
Just so you know the plugin command that you have supplied doesn't seem to work any more. Rails says that the plugin installs but when you try to run the rake command rails can't find it. I located another plugin from Google Code that seems to work
script/plugin install http://open-id-authentication.googlecode.com/svn/trunk/open_id_authentication/
Hi Ryan, I'm getting error when i run rake open_id_authentication:db:create. The error is :
undefined method `add_acts_as_authentic_module' for ActiveRecord::Base:Class
Anyone help me?
I followed you guide and its amazing, thank you very much.
But i found some problems when trying to loggin in.
If I choose an openid that doesnt exists, it fails for "Template is missing" in the user_sessions/create.erb.
And if I try to login with a wrong username/password, it no longer shows the error message about it, just reloads the view.
Any idea how could I fix this?
hrm, a bit stuck here, the rake task open_id_authentication:db:create doesn't appear to exist.
I have the authlogic, authlogic-oid and ruby-openid gems installed.
If anyone comes across the error "llformed requirement ["=>0.2.1"]", there's a typo in the latest version of open_id_authentication.
Change
:version => '=>0.2.1'
to
:version => '>=0.2.1'
It looks like rails/open_id_authentication no longer provides a rakefile or the model generators. The repo in your video had 38 files, but the current version only has 11.
Any thoughts on where these have gone?
i'm confused by your routes. you say that builds upon screencast 160. but in 160, you haven't used "session" but "user_session". is this the same?
@kit that's the problem when using gem in environment.rb. i also wondered about this.
install the plugin and gem by hand like you see in the video and they appear.
a little bit ugly since you enter it in environment.rb and install it with rake gems:install, but you still have to set up them manually.
The rakefile and model generators are no longer part of the plugin. They were removed several versions ago.
You can find the "missing" files here: http://github.com/rails/open_id_authentication/commit/16e40d2ee73f8f10c2cb77234b6f5f4816c94547#diff-0
It appears they are just a bunch of tests, so you can skip "rake open_id_authentication:db:create"
Maybe not. Looking at the migrations and the schema, there's a lot more going on than just the tests I see in the missing rakefile.
You can find the old files Ryan uses here: http://github.com/ryanb/railscasts-episodes/tree/master/episode-170/blog/vendor/plugins/open_id_authentication/
@Marc Luzietti: I'm going crazy trying to set this up. Why is that rake file missing from the main repository. Even in the homepage for the project it says that you need that particular task "rake open_id_authentication:db:create".
The following commit seems to indicate the database migrations are no longer needed.
http://github.com/rails/open_id_authentication/commit/ee5be2f26c37049f6c37e113627a34c1ef6d35cd
replacing the open_id_authentication with another solved the rake problem.
script/plugin install git://github.com/senthilnambi/open-id.git
It may be an old version of open_id_authentication.
I'm getting the exact same problems. Ryan should look into this and maybe suggest a possible solution.
Instead of "gem install authlogic-oid", better use
script/plugin install git://github.com/mreinsch/authlogic_openid.git
to avoid errors. Remove 'config.gem "authlogic-oid' in your environment.rb.
It works with official updated open_id_authentication plugin
Hi there,
Great tutorial:)
I just tried it, but cause an error on mine:
"undefined method `normalize_identifier' for OpenIdAuthentication:Module
"
Am I miss something here?
Thanks
while executing
rake open_id_authentication:db:create
I am getting an error:
rake aborted!
Don't know how to build task 'open_id_authentication:db:create'
(See full trace by running task with --trace)
Please take a look on the issue. Using rails 2.3.5
This tutorial is outdated, plugins and gems no longer working. Don't follow it...
Pls use this migration for user
class CreateUsers < ActiveRecord::Migration
def self.up
create_table :users do |t|
t.string :username
t.string :email
t.string :crypted_password
t.string :password_salt
t.string :persistence_token
t.timestamps
end
end
def self.down
drop_table :users
end
end
else you will get a undefined method 'password_confirmation' for method foo error.....
hey guys please what tmbundle or snippet allows you to type in 2 place at the same time...for instance when you open a p tag, if you change the opening tag to strong, the closing ta automatically changes too. He used something like that around 2:45 - 2:50