Rack OpenID : forcing for new session in google authentication

20 Aug 2011

             Currently Rack::OpenID didn't support for forcing a new session in Google authentication. So if you need that functionality, you can easily add via Monkey patching/Duck punching. By monkey patching we are going to pass PAPE  (Provider Authentication Policy Extension) as a parameter. For further information you can get the Google documentation.
          If you wonder what I meant by Monkey patching/Duck punching, then you have to read wikipedia first. The best definition I heard about  Monkey patching/Duck punching is by  Patrick Ewing in RailsConf 2007.
...if it walks like a duck and talks like a duck, it's a duck, right? So if this duck is not giving you the noise that you want, you’ve got to just punch that duck until it returns what you expect.
Now the patch.
For rails : 
             Copy the following code to a file and save it in config/initializers/ directory. Eg:  config/initializers/rack_openid_patch.rb

Now you need to add the pape option to the Rack::OpenID.build_header

Now You can force for new session in google authentication with Rack::OpenID.But make sure you set max_auth_age = 0
If you particularly enjoy my work, I appreciate donations given with Gittip.