OpenID Enabled plugin

Plugin details

openid_enabled is a plugin to ease the development of openid authentication. Currently, the identification proces of a user can be done through this system.

Websitehttp://github.com/madnificent/openid_enabled/wikis Repositorygit://github.com/madnificent/openid_enabled.git Author MADnificent Tags OpenId LicenseMIT

Documentation

Install the plugin:
ruby script/plugin install git://github.com/madnificent/openid_enabled.git

Create a new rails project
======================

rails stereo -d mysql



Setup the database
================

> mysql -u root -p
>> create schema stereo_development;
>> grant all on stereo_development.* to 'stereodev'@'localhost' identified by 'password';
> edit config/database.yml to reflect this user



Get the sweetest plugin in the world
=========================

> gem install 'ruby-openid' # credit should actually go to the guys that made this ruby gem ^_^
> cd vendor/plugins/
> git clone git://github.com/madnificent/openid_enabled.git



Use the generators
===============

script/generate scaffold User name:string
script/generate openid_support User UsersController



This last command is where the magic happens, this generates everything we’ll need to be able to do OpenID authentication. You may remove the stuff it generated by running script/destroy openid_support User UsersController. What is not noted elsewhere in this tutorial are the named paths. You can see how to do your own login form in the _login_form.html.erb partial that has been generated too.

Update the index view
===================
In the index view, we’ll add some output and a login form:

< h1>Login here< /h1>
<% if session[:user_openid_url] -%>
You are currently identified by <%= session[:user_openid_url] %>.
<% if @logged_in_user -%>
Which belongs to <%= @logged_in_user.name %>
<% end -%>
<% end -%>

<%= render :partial => 'login_form' %>


Update the controllers
==================
index
--------
We need to give access to the @logged_in_user variable through the controller to get our index-view to work again. In the index-action we add:

@logged_in_user = logged_in_user


The method logged_in_user is given, because the controller calls the openid_enabled “User” method at the top.

create
------------
set the openid_url for the currently logged-in user:

@user = User.new(params[:user])
@user.openid_url = session[:user_openid_url]



You should do some validations in the model to ensure that the openid_url is there AND that a user only has a single openid_url. (Perhaps the task generator should do that too?)

update
-----------
ensure users can only update their own user

if @user.openid_url != session[:user_openid_url]
  flash[:notice] = "Not your user!" 
  redirect_to users_url
  return
end


destroy
------------
Only destroy yourself!

@user.destroy unless @user.openid_url != session[:user_openid_url]

Further Documentation

There is currently no advanced documentation for this plugin.

New documentation

Edit plugin | Back in time (1 older version) | Last edited by: hardway, 5 months ago