discogs
discogs copied to clipboard
Session storing was not storing objects so example in ReadMe was not working.
Hey, first of all, thank for your gem! I'm a beginner but I encountered an issue while trying it so this might help someone with the same issue. I had an error "Invalid Token" from OAuth when trying to authenticate with the consummer key to Discogs API. I encountered an issue using this code from ReadMe.
# Add an action to initiate the process.
def authenticate
@discogs = Discogs::Wrapper.new("Test OAuth")
request_data = @discogs.get_request_token("YOUR_APP_KEY", "YOUR_APP_SECRET", "http://127.0.0.1:3000/callback")
session[:request_token] = request_data[:request_token]
redirect_to request_data[:authorize_url]
end
# And an action that Discogs will redirect back to.
def callback
@discogs = Discogs::Wrapper.new("Test OAuth")
request_token = session[:request_token]
verifier = params[:oauth_verifier]
access_token = @discogs.authenticate(request_token, verifier)
session[:request_token] = nil
session[:access_token] = access_token
@discogs.access_token = access_token
# You can now perform authenticated requests.
end
# Once you have it, you can also pass your access_token into the constructor.
def another_action
@discogs = Discogs::Wrapper.new("Test OAuth", access_token: session[:access_token])
# You can now perform authenticated requests.
end
To resolve this, I had to follow the procedure and install the gem activerecord-sessions-store Turns out when you were passing objects through sessions, it was rendered no more as an instance but as JSON data. Using this gem, I was able to log and made it to the end of the callback.
I'm sure it's a common issue, and maybe you had a better solution to this issue.