Evernote / evernote-oauth-ruby

Evernote OAuth / Thrift API client library for Ruby
Other
74 stars 36 forks source link

Request token object serialization in Rails 4 #20

Closed hugofloss closed 10 years ago

hugofloss commented 10 years ago

In my Rails 4.1.7 application I'm trying to connect with Evernote through this Oauth gem. I have the following code to connect: (of course with the callback URL specific to my installation)

def evernote_web_auth
    client = EvernoteOAuth::Client.new
    request_token = client.request_token(oauth_callback: 'YOUR CALLBACK URL')

    session[:request_token] = request_token

    request_token
  end

In need to put the request_token in the session because I need it later when I return on the callback url that processes the rest. From Rails 4.1 it's not possible anymore to save entire objects in a session, so I have to serialize it. The size of the Oauth object was to large to put in a session as JSON or Hash (Rails has a maximum of 4kb). So I tried to serialize the object with Marshal or MessagePack, but that gave me an encoding error: Encoding::UndefinedConversionError "\x9C" from ASCII-8BIT to UTF-8

Then I tried to force UTF-8/ISO-8859-1 encoding:

session[:request_token] = Marshal.dump(request_token).force_encoding('ISO-8859-1')

That worked, but resulted in a ArgumentError: dump format error for symbol(0x45) error. I tried everything, but nothing seems to work. Any ideas how to solve this?

hugofloss commented 10 years ago

Never mind, I didn't have to pass any objects to the session whatsoever. I'll file another issue for the real one.