Re: authenticity_token sent, still InvalidAuthenticityToken

Matteo Parmi
2009-04-10T07:48:43Z

Hi
I had the same problem. After some digging and http sniffing I found
this repo on github that solves the problem:
http://github.com/lardawge/swfupload-rails-authentication/tree/master


The workaround is to use a rack file to filter the request from flex:

require ''rack/utils''

class FlashSessionCookieMiddleware
  def initialize(app, session_key = ''_session_id'')
    @app = app
    @session_key = session_key
  end

  def call(env)
    if env[''HTTP_USER_AGENT''] =~ /^(Adobe|Shockwave) Flash/
      params = ::Rack::Utils.parse_query(env[''QUERY_STRING''])
      env[''HTTP_COOKIE''] = [ @session_key,
params[@session_key]
].join(''='').freeze unless params[@session_key].nil?
    end
    @app.call(env)
  end
end