hanklords/flickraw

Stack level too deep when authenticating from rails

Closed this issue · 1 comments

Hello,

I've been trying to follow the readme's Authentication chapter precisely, for a rails site, and noticed that on the following circumstances:

  1. Controller A displays auth link
  2. User clicks the link, approves a web-app
  3. Gets redirected to Controller B

flickraw falls with "stack level too deep" when trying to fetch a token (flickr.auth.getToken :frob => params[:frob]). Changing the call to FlickRaw::Flickr.new.auth.getToken works as expected (authentication passes).

Though I am not sure if this is indeed flickraw issue, I'd like to ask for a bit more clarification on how to use flickraw for rails, if that's possible?

What I am doing now for rails 2.3.4 is:

environment.rb:
config.gem "flickraw", :version => '>= 0.7.1', :source => "http://gems.github.com"

initialisers/flickraw.rb:
FlickRaw.api_key = 'blah'
FlickRaw.shared_secret = 'blah'

controllers/application_controller.rb

require 'flickraw' # this is actually the only place where it is declared

def get_flickr
FlickRaw::Flickr.new
end

And anywhere I need an API call:
get_flickr.make.a.call()

And I feel that I am doing something wrong... Especially assuming that library lazy loading should be utilised somehow somewhere... But for me this configuration at least works. Again, could someone please provide a short clarification on using flickraw with current production rails? Many thanks in advance!

Hi,

You need the library lazy loading in the case you don't wan't flickraw to fetch the methods from flickr website on require 'flickraw'. It wil fetch them on the first call to flickr in your controller. This way if flickr website is not responding, your application can still be launched but you get an exception when trying to load a page (if it make use of flickraw).

It should work when you call flickr.auth.getToken. is it possible that you send me a backtrace ?

As for you other questions: flickraw keeps the token when you do one of

flickr.auth.getFullToken
flickr.auth.getToken
flickr.auth.checkToken

so the next calls are authenticated with this particular user. This doesn't work in a multiuser environment. So you have several solutions:

  • you create a new FlickRaw::Flickr object per user which will keep the token and you make your calls authenticated as this particular user like you would do with the top level flickr method.
  • With flickr top level method, you pass the token you get in getToken with each call as :auth_token => token parameter so it bypasses the saved token. (Maybe it is a good idea to add an option so it doesn't save the token, I will think about it)

I hope this clarifies everything.