-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Retain session and make it portable across instances (Android compatibility) #5
Comments
I actually started working on this a little bit before you opened your ticket. |
It should always have an issue for the records. |
The following commit adds support for viewing messages from inbox (limited) and sessions. |
I was actually working on the comment call last night and kept getting USER_REQUIRED error from the Reddit API. I was trying to pass in a modhash retrieved from logging in as an URL encoded form parameter as well as the X-Modhash header which seems to be preferred. It appears as if I misinterpreted the API docs, and that the reddit_cookie is used to authenticate between each call as opposed to the modhash? Or is the modhash used for something else entirely? genericyjay - So if your commit addresses this issue, please submit a pull request so we can see the Travis CI build results. |
@corydissinger The modhash, according to the API docs, is just a secondary verification to prevent CSRF (cross-site request forgery) attacks, which happen after the user is authenticated. It is there to make sure that the user was the one who submitted the request, and not a hidden script on the third-party page they just accessed. The Wikipedia article explains it pretty clearly. Basically, since the modhash is sent in the HTTP response header, it isn't retained by the browser, unlike the session cookie, which the browser would send (with all good intentions) in a request initiated by a CSRF attack. The modhash is accessible by the caller only, since they were (or should have been) the only one to get it, so only the caller can retain the modhash to use it to verify the legitimacy of their next request. The |
Could @genericjay's solution not be improved by making the |
I'm curious to know why you would need multiple Admittedly it's been a while since I've worked on raw4j myself, but the Then again, due to the rate-limiting nature (30 requests per minute maximum) being able to make many requests simultaneously could be a moot point. |
In the OP, @cybergeek94 made it sound like it's useful to have multiple instances in Android applications, although I've never done any Android dev myself. |
Ah, we never really addressed @cybergeek94 concern. I've done a bit of Android development, and IMO I'm not quite sure why you would want multiple |
That sort of ties into a feature I was thinking about: having multiple users logged in to the same |
Currently, RAW4J does not retain session, which means that it needs a call to
Reddit.login()
for every instance of the class before any action can be taken. This can lead to a lot of superfluous requests.The API returns a
reddit_session
cookie which should be passed in later requests. There is a system-wide cookie handler that should be holding onto this, but it may or may not get destroyed at an arbitrary time by the system.Different components in an Android application cannot share instances of a class unless it is a singleton.
The session cookie should be accessible as a
String
which can then be passed to differentReddit
instances, perhaps with arestoreSession(String)
method.The text was updated successfully, but these errors were encountered: