Google authentication in rails app….steps

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’


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:

<%- 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>
<label for=”username”>Google Username</label>
<%= text_field_tag ‘username’ %>
<label for=”password”>Google Password</label>
<%= password_field_tag ‘password’ %>
<%= submit_tag ‘Login’ %>
<%- 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.

      Leave a Reply

      Fill in your details below or click an icon to log in: Logo

      You are commenting using your account. Log Out /  Change )

      Google photo

      You are commenting using your Google account. Log Out /  Change )

      Twitter picture

      You are commenting using your Twitter account. Log Out /  Change )

      Facebook photo

      You are commenting using your Facebook account. Log Out /  Change )

      Connecting to %s