Google authentication in rails app….steps

Posted on July 9, 2010

0


Just implemented Google authentication in my rails app.
Here are the steps.

1)gem install googlebase
2)rails sample
3)script/generate controller sessions
4)In the sessions controller the code must be…

class SessionsController ‘Sorry…wrong username – password combination’
end

end

5)in the routes.rb file:
map.resources :sessions
map.login “/login” ,:controller=>’sessions’,:action=>’new’
map.logout “/logout”,:controller=>’sessions’,:action=>’destroy’

6)Create a new.html.erb file in /RAILS_ROOT/app/views/sessions/ and insert the code:

<h1>Login</h1>
<%- form_tag sessions_path do -%>
<p>We promise not to log or store your password in any way. It will be used only to authenticate with Google.</p>
<ul>
<li>
<label for=”username”>Google Username</label>
<%= text_field_tag ‘username’ %>
</li>
<li>
<label for=”password”>Google Password</label>
<%= password_field_tag ‘password’ %>
</li>
<li>
<%= submit_tag ‘Login’ %>
</li>
</ul>
<%- end -%>

7)start the server as script/server.
8)In the browser type http://localhost:3000/login.
9)You will get login form and if password username are wrong…u’ll get a message and if they are right….then u’ll get a template missing error.

These were the basic steps and one can do the redirection and rendering as per his/her own app.

      Advertisements
      Posted in: Rails app