0

Using Rails 4 and ruby 2.1.2

I need to implement a few informative pages, but there is a form in one of the pages. Only if the form is submit an authentication kicks in. There is only one authentication method desired: OpenID, with one existing provider.

I did a simple prototype, and I get redirected to login at the OpenID provider. However, when coming back, I get the InvalidAuthenticityToken error.

Reading for example this question: ActionController::InvalidAuthenticityToken in RegistrationsController#create I suspect it has to do with the redirect. I actually submit the form, but get redirected to the OpenID provider first, and then back to the POST action URL of the form. On these redirections I guess the form token, which I build in the form with form_for, gets lost.

How could I do this correctly? My next attempt will probably be trying to catch the submit event, doing a XHR request for the OpenID authentication, and only after coming back from there that I'd truly submit the form. But I foresee trouble here, as for an effective OpenID login, I probably need to open a new window in order to effectively perform the redirects, and I am not sure how to not get lost in the process...;)

Here's what I have so far (hey it's a prototype, I just used url: sites_path as options for form_for, thus going to the /sites URL, mapping to create ;) )

class SitesController < ApplicationController

  @@openid_url_base  = "myprovider.org"
  def create    
    openid_url = @@openid_url_base + login
    openid_authentication(openid_url)
  end
Community
  • 1
  • 1
transient_loop
  • 5,984
  • 15
  • 58
  • 117
  • @MichalSzyndel no, I don't. I considered it but as I really only need OpenID I thought it'd be overkill. I use ruby-openid with open_id_authentication – transient_loop Jul 28 '14 at 21:17
  • Ok, then I'm not able to help really. – Mike Szyndel Jul 29 '14 at 09:13
  • Well if you have a suggestion using Devise I might consider it...better a working solution with an overkill-tool than a non-working one with a light tool – transient_loop Jul 29 '14 at 09:45
  • I asked of devise, because devise resets session upon login. I have no experience with the gem you're using, nor can guarantee that using Devise will resolve your problem. – Mike Szyndel Jul 29 '14 at 13:43

0 Answers0