Closed digerata closed 13 years ago
Unless the OAuth gem has some clever way of injecting a prior-known access token (not sure if it does), I think the best way would be to use the deserialize
method. A serialized Dropbox::Session
is a YAML array of the following: The consumer key, the consumer secret, a boolean indicating whether authorization is complete, the access token, the the token secret, a boolean indicating whether to use SSL, and the session mode as symbol (:dropbox
or :sandbox
).
So, you could just generate, e.g., the following YAML:
---
- abc123
- bca235
- true
- 123abc
- 321bca
- false
- :sandbox
And pass it to the Dropbox::Session.deserialize
method.
oauth-plugin stores the access token in the database, that is how we can inject prior-known access tokens...
To make this work, I added:
attr_accessor :consumer
attr_accessor :access_token
To session.rb and then in my controller:
dropbox_session.access_token = OAuth::AccessToken.new(dropbox_session.consumer, [stored oauth.token], [stored oauth.secret])
And everything works. Is the attr_accessors on @consumer and @access_token something you would accept as a patch?
No, I've thought about making attr_accessor
s for those in the past, but I decided that the means of authentication should be opaque; especially if I want to switch OAuth providers in the future.
What about adding a method to set the secret and token? Those two are part of the spec and won't depend on OAuth providers.
You got it. bef75b9e6ad3186e12eaee9ee143ea526cbafd37
That's awesome, thanks!
I'm plugging in this great gem with our existing app. It uses oauth-plugin for integrating with other oauth sites besides dropbox. The whole authentication bit is provided by oauth-plugin.
Can API be added so that if I already have a user token and secret, I can manually add it to the session? Is this already possible? I've looked through the code but nothing jumps out at me.